feat!: enforce headers parameter on setAll cookie method#205
Open
feat!: enforce headers parameter on setAll cookie method#205
Conversation
4cdbd38 to
b861c72
Compare
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
Adds a runtime check that throws at client creation time if the user-provided
setAllcallback declares fewer than two parameters. This enforces that users accept theheaderssecond argument introduced in v0.10.0, which carries cache-control headers (Cache-Control,Expires,Pragma) that must be forwarded to the HTTP response after token refreshes.Without this enforcement, TypeScript silently allows
setAll(cookies) { ... }to satisfy the(cookies, headers) => voidtype, so users who copy an outdated snippet or skip the changelog never apply the cache headers. CDNs can then cache authenticated responses and serve one user's session token to another.What changed
src/cookies.ts-- AddedFunction.lengtharity check at the single point where user-providedsetAllenters the system. IfsetAll.length < 2, an error with a clear message and docs link is thrown immediately. Library-controlledsetAllimplementations (deprecatedget/set/removewrapper, warning stubs,document.cookieadapter) are not checked.src/cookies.spec.ts-- Updated 14 test mocks to declare both parameters. Added 5 new tests covering: zero-param throws (server), one-param throws (server), zero-param throws (browser), two-param passes, deprecatedget/set/removepath is unaffected.src/createServerClient.spec.ts-- Updated 10 test mocks to declare both parameters.Breaking change
setAllmust now declare two parameters(cookies, headers). Existing implementations that only declare one parameter will throw on upgrade. Since the package is on 0.x, this ships as a minor bump (0.11.0) per semver conventions.Context