Skip to content

utils: Smart CDN URL grammar — parse, unsigned build, strip auth, trusted baseUrl - #479

Merged
kvz merged 1 commit into
mainfrom
utils-smartcdn-grammar
Aug 30, 2026
Merged

utils: Smart CDN URL grammar — parse, unsigned build, strip auth, trusted baseUrl#479
kvz merged 1 commit into
mainfrom
utils-smartcdn-grammar

Conversation

@kvz

@kvz kvz commented Aug 30, 2026

Copy link
Copy Markdown
Member

What

@transloadit/utils 4.6.0 ships getSignedSmartCdnUrl, but the rest of the Smart CDN URL grammar lived in application code: the Console carries four copies (parseSmartCdnUrl, nonSignedSmartCDNUrl, removeAuthParams, convertToDevelopmentUrl) and Uppy's storage plugin had a fifth (origin rewrite). This adds the missing pieces on the same shared prepareSmartCdnUrl/finishSmartCdnUrl core so they cannot drift:

  • getSmartCdnUrl(options) — unsigned builder (same options minus credentials/expiry; no ? when there are no params).
  • parseSmartCdnUrl(url, { baseUrl?, workspace? }) — inverse of the builders: strict https://{workspace}.tlcdn.com/{template}/{input} anchoring (or the configured baseUrl), percent-decodes path segments exactly once, URLSearchParams semantics for the query, repeated params as arrays, auth_key/exp/sig returned as auth, clear TypeErrors for everything else.
  • stripSmartCdnAuth(url) — removes auth_key, exp, sig (and api2's hsh) leaving every other byte untouched; idempotent.
  • baseUrl option on both builders (root and ./node), e.g. https://api2-devdock.transloadit.dev/file/{workspace} for a local api2. Documented as trusted configuration: the signature does not cover the host.

Exported from the root and the ./node entry; PreparedSmartCdnUrl.parts gains the resolved baseUrl.

Why

Converged round-3 refactor item for the Transloadit Storage prototype (transloadit/content#5810, transloadit/uppy#6506): one Smart CDN grammar instead of five, so the Console and Uppy can delete their copies once this ships.

Verified

  • yarn verify green (changesets guard, publish check, knip, biome, tsc, transloadit-sync, unit suites).
  • New packages/utils/test/smartCdnGrammar.test.ts: round trips build → parse → build for unsigned, signed (both signers) and baseUrl URLs; repeated params, sorting, encoded slashes/spaces, @ in template names, non-ASCII, the api2 URL Transform format with cdn=required, double-encoded input decoded once, stripSmartCdnAuth idempotence; error cases (foreign host, http, missing segments, malformed percent-encoding, incomplete/invalid signature params). The 4.6.0 known-answer vector is unchanged.

🤖 Generated with Claude Code

…sted baseUrl

getSignedSmartCdnUrl already lived here; the rest of the grammar did not,
so the Console carried four copies (parser, unsigned builder, auth
stripper, dev-origin rewrite) and Uppy a fifth. Add getSmartCdnUrl,
parseSmartCdnUrl and stripSmartCdnAuth on the shared prepare/finish
core, plus a trusted baseUrl option on both builders (documented: the
host is not signed, so it must come from configuration). Round-trip and
edge-case vectors; the 4.6.0 known answer is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kvz
kvz marked this pull request as ready for review August 30, 2026 10:38
@kvz
kvz merged commit 7597b78 into main Aug 30, 2026
12 checks passed
@kvz
kvz deleted the utils-smartcdn-grammar branch August 30, 2026 10:39
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.

1 participant