Skip to content

feat: public key-addressed web seam fetchWebKey(key, request) - #203

Merged
gmoon merged 4 commits into
masterfrom
feat/fetch-web-key
Nov 1, 2026
Merged

gmoon merged 4 commits into
masterfrom
feat/fetch-web-key

Conversation

@gmoon

@gmoon gmoon commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Closes #162.

Promotes the internal key-addressed path to the public web API.

fetchWebKey(key: string, request: Request): Promise<Response>

The caller names the S3 key; the Request contributes only method (GET/HEAD) and conditional/Range headers — the URL plays no role in key selection. fetchWeb() now derives the key from the URL and delegates to fetchWebKey(), so both share one HTTP↔S3 translation path (Range→206, missing/denied→typed 404/403, header mapping, HEAD, Node→Web stream).

Why

Consumers whose URL→key mapping isn't identity (a prefix, a /files/* mount) currently fabricate a synthetic Request to smuggle the key through the URL, round-tripping it key → URL-encode → Request → URL-parse → key. That's wasteful, splits ownership of path→key logic, and — the real hazard — corrupts keys containing %, +, spaces, or other reserved characters unless the consumer's encoder and s3proxy's decoder agree exactly. fetchWebKey uses the key verbatim.

Per the scope note on the issue: this is not SDK-duplication — the value is the HTTP translation. A true SDK duplicate (fetchKey(key)→stream, no HTTP) stays private.

Changes

  • src/index.ts: add public fetchWebKey; refactor fetchWeb to delegate. No behavior change to fetchWeb (identical key derivation + Response).
  • Tests: new fetchWebKey suite — verbatim key, delegation equivalence, Range→206, HEAD, typed 404, and a reserved-character (%) case that fetchWeb can't carry via the URL (asserts it throws InvalidRequest).
  • Docs: README narrative (/files/* example + the "use the SDK if you don't need a Response" decision rule) and API reference.

Verification

  • npm run type-check / build / lint clean
  • npm run test:unit → 83/83 (was 76; +7)

🤖 Generated with Claude Code

gmoon and others added 4 commits October 31, 2026 19:18
Promotes the internal key-addressed path to the public web API. The caller
names the S3 key; the Request contributes only method (GET/HEAD) and
conditional/Range headers — the request URL plays no role in key selection.
fetchWeb() now derives the key from the URL and delegates to fetchWebKey(),
so both share one HTTP <-> S3 translation path.

Lets consumers with a non-identity URL->key mapping (a prefix, a /files/*
mount) avoid round-tripping the key through URL encode/decode — which
otherwise corrupts keys containing %, +, spaces, or other reserved
characters unless the consumer's encoder and s3proxy's decoder agree exactly.
The key is used verbatim.

No behavior change to fetchWeb (same key derivation, same Response). Adds a
fetchWebKey test suite incl. the reserved-character case that fetchWeb can't
carry via the URL, plus README narrative + API-reference docs.

Closes #162.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Factor the shared { url, method, headers } lift into a private
webToHttpRequest() helper so the method/header conversion lives in one place
(clears Codacy's duplicate-block findings introduced by fetchWebKey).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
simplify:
- fetchWeb derives the key with headers:{} instead of spreading
  webToHttpRequest — parseRequest reads only the path, so the second
  header materialization per request is removed.
- trim the editorial paragraph duplicated from the README out of the
  fetchWebKey JSDoc.

code-review:
- docs claimed the Request's "conditional/Range" headers are honored, but
  fetchKey forwards only Range (no If-None-Match/If-Modified-Since anywhere
  on the fetch path). Correct the JSDoc + README to "Range" only.
- rewrite the README example to a non-URL key source: the previous one
  derived the key from Hono's c.req.path, which is already percent-decoded,
  so it was NOT verbatim and defeated the feature's own point.
- fetchWebKey now rejects a null-byte key with the typed InvalidRequest,
  matching the guard parseRequest applies on every other entry point
  (was: verbatim key -> generic 500). Adds a test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Both the fetchWeb and fetchWebKey suites used an identical
beforeEach/afterEach + `let proxy` block; adding the second suite
duplicated it (Codacy flagged the clone). Lift the setup to file scope so
it is defined once and applies to both describes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gmoon
gmoon merged commit 152c289 into master Nov 1, 2026
11 of 12 checks passed
@gmoon
gmoon deleted the feat/fetch-web-key branch November 1, 2026 15:31
gmoon added a commit that referenced this pull request Nov 1, 2026
Minor: adds the public fetchWebKey(key, request) key-addressed Web seam
(#203) plus its example route and conformance coverage (#204). Backward
compatible; fetchWeb is unchanged.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public key-addressed web seam: fetchWebKey(key, request)

1 participant