feat(ts): allow a pre-minted JWT instead of an API key#36
Merged
Conversation
GitStorageOptions now accepts an optional `token`; `key` is optional when a token is supplied. When set, the token is sent verbatim on every request and per-call scope/ttl/refPolicy options are ignored (the token's own claims govern access). Constructor requires name plus either key or token.
fat
approved these changes
Jun 23, 2026
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.
Summary
Lets the TypeScript SDK accept a caller-supplied JWT instead of an ES256 private key. When a
tokenis provided, the client sends it verbatim on every authenticated request rather than minting a fresh JWT per call.This is the natural unit for "act as an end user our backend already minted a token for" — the token's own claims (repo, scopes, expiry) govern access.
Changes
GitStorageOptions:keyis now optional; added optionaltoken. Constructor requiresnameplus eitherkeyortoken.generateJWT: short-circuits to return the supplied token verbatim, so all existing call sites flow through unchanged. Per-callpermissions/ttl/refPoliciesare ignored in token mode (documented).requires a name,requires either a key or a token,token must be a non-empty string.GitStorageOptionsinterface + added a token-init example.Caveats
nameis still required in token mode (used to derive default API/storage base URLs).Test evidence
pnpm --filter @pierre/storage build— success (incl. DTS).pnpm --filter @pierre/storage exec vitest --run— 196 passed.Added tests: construct-with-token, empty-token rejection, and an end-to-end check that the supplied token is sent verbatim as the
Authorization: Bearerheader. Updated existing constructor-validation assertions for the new error messages.