fix(fetch): preserve __sapiom metadata across internal Request cloning - #747
Open
ygd58 wants to merge 1 commit into
Open
fix(fetch): preserve __sapiom metadata across internal Request cloning#747ygd58 wants to merge 1 commit into
ygd58 wants to merge 1 commit into
Conversation
Fixes sapiom#690 sapiomFetch reconstructs the request via new Request(input, init) before reading __sapiom. Native Request cloning does not preserve custom properties, so a __sapiom override set on the original Request was dropped before it could be read - the documented per-request bypass (e.g. request.__sapiom = { enabled: false }) silently had no effect. __sapiom is now captured from the original input before cloning and re-attached to the clone, including after the identity-header re-wrap later in the same function (the same class of loss, one function down). Deliberately scoped to the reported reproduction and this identical pattern within sapiomFetch itself. handleAuthorization (interceptors.ts) does its own internal Request re-wrap before returning, which could still drop __sapiom for a caller relying on it past the authorization step (e.g. at payment-retry time) - left as a separate, deeper propagation concern rather than folded into this fix. Added a regression test verifying the enabled:false bypass calls globalThis.fetch directly (skipping authorization) when __sapiom is set on a Request input. Verified it fails against the pre-fix code (hits the unmocked authorization path and throws) and passes against the fix. pnpm --filter @sapiom/fetch test - 44/44 passing (full package). Changeset added (patch, @sapiom/fetch).
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.
Fixes #690
sapiomFetchreconstructs the request vianew Request(input, init)before reading__sapiom. NativeRequestcloning does not preserve custom properties, so a__sapiomoverride set on the originalRequestwas dropped before it could be read - the documented per-request bypass (e.g.request.__sapiom = { enabled: false }) silently had no effect.Fix:
__sapiomis now captured from the originalinputbefore cloning and re-attached to the clone, including after the identity-header re-wrap later in the same function (the same class of loss, one function down).Scope: deliberately limited to the reported reproduction and this identical pattern within
sapiomFetchitself.handleAuthorization(interceptors.ts) does its own internalRequestre-wrap before returning, which could still drop__sapiomfor a caller relying on it past the authorization step (e.g. at payment-retry time) - left as a separate, deeper propagation concern rather than folded into this fix, since it wasn't part of the reported repro.Tests: added a regression test verifying the
enabled:falsebypass callsglobalThis.fetchdirectly (skipping authorization) when__sapiomis set on aRequestinput. Verified it fails against the pre-fix code (hits the unmocked authorization path and throws) and passes against the fix.Changeset: added (
@sapiom/fetch, patch).Verified locally:
pnpm --filter @sapiom/fetch test- 44/44 passing (full package),eslintclean (the one pre-existing warning infetch.tsis unrelated to this diff).