utils: Smart CDN URL grammar — parse, unsigned build, strip auth, trusted baseUrl - #479
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
@transloadit/utils4.6.0 shipsgetSignedSmartCdnUrl, 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 sharedprepareSmartCdnUrl/finishSmartCdnUrlcore 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: stricthttps://{workspace}.tlcdn.com/{template}/{input}anchoring (or the configuredbaseUrl), percent-decodes path segments exactly once,URLSearchParamssemantics for the query, repeated params as arrays,auth_key/exp/sigreturned asauth, clearTypeErrors for everything else.stripSmartCdnAuth(url)— removesauth_key,exp,sig(and api2'shsh) leaving every other byte untouched; idempotent.baseUrloption 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
./nodeentry;PreparedSmartCdnUrl.partsgains the resolvedbaseUrl.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 verifygreen (changesets guard, publish check, knip, biome, tsc, transloadit-sync, unit suites).packages/utils/test/smartCdnGrammar.test.ts: round trips build → parse → build for unsigned, signed (both signers) andbaseUrlURLs; repeated params, sorting, encoded slashes/spaces,@in template names, non-ASCII, the api2 URL Transform format withcdn=required, double-encoded input decoded once,stripSmartCdnAuthidempotence; 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