-
-
Notifications
You must be signed in to change notification settings - Fork 302
feat(ramps-controller): send client identity as query params on on-ramp API requests #9983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4b37525
feat(ramps-controller): send client identity metadata headers on on-r…
amitabh94 f42a461
feat(ramps-controller): send client identity as query params for CDN …
amitabh94 ad42c53
refactor(ramps-controller): drop clientEnvironment from client identity
amitabh94 619d07f
refactor(ramps-controller): send client identity as query params only
amitabh94 37dad9c
style: fix prettier indentation in TransakService
amitabh94 f83881d
docs(ramps-controller): link changelog entry to PR
amitabh94 a13c1e2
refactor(ramps-controller): fix stale comments referencing headers an…
amitabh94 3bfe703
chore(ramps-controller): merge main and keep client-identity changelo…
amitabh94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { addRampsClientIdentityParams } from './client-identity.js'; | ||
|
|
||
| describe('addRampsClientIdentityParams', () => { | ||
| it('appends all identity fields as query params', () => { | ||
| const url = new URL('https://on-ramp.api.cx.metamask.io/regions/countries'); | ||
|
|
||
| addRampsClientIdentityParams(url, { | ||
| clientProduct: 'metamask-mobile', | ||
| clientVersion: '8.9.0', | ||
| }); | ||
|
|
||
| expect(url.searchParams.get('clientProduct')).toBe('metamask-mobile'); | ||
| expect(url.searchParams.get('clientVersion')).toBe('8.9.0'); | ||
| }); | ||
|
|
||
| it('leaves the URL untouched when no identity is provided', () => { | ||
| const url = new URL('https://on-ramp.api.cx.metamask.io/regions/countries'); | ||
|
|
||
| addRampsClientIdentityParams(url, {}); | ||
|
|
||
| expect(url.search).toBe(''); | ||
| }); | ||
|
|
||
| it('omits empty string values', () => { | ||
| const url = new URL('https://on-ramp.api.cx.metamask.io/regions/countries'); | ||
|
|
||
| addRampsClientIdentityParams(url, { | ||
| clientProduct: '', | ||
| clientVersion: '8.9.0', | ||
| }); | ||
|
|
||
| expect(url.searchParams.has('clientProduct')).toBe(false); | ||
| expect(url.searchParams.get('clientVersion')).toBe('8.9.0'); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** Host-supplied MetaMask client identity. All fields optional. */ | ||
| export type RampsClientIdentity = { | ||
| /** Product id, e.g. `metamask-mobile` or `metamask-extension`. */ | ||
| clientProduct?: string; | ||
| /** App SemVer, e.g. `8.9.0` (not the ramps-controller package version). */ | ||
| clientVersion?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Query-param names for the client identity, sent on every on-ramp API | ||
| * request. Identity travels in the URL (not headers) because the on-ramp CDN | ||
| * cache key is the URL — the API's version-gated feature flags evaluate these | ||
| * params so cached responses always match the requesting cohort. | ||
| */ | ||
| export const RAMPS_CLIENT_PRODUCT_PARAM = 'clientProduct'; | ||
| export const RAMPS_CLIENT_VERSION_PARAM = 'clientVersion'; | ||
|
|
||
| /** | ||
| * Appends the identity as query params (CDN cache-key friendly), omitting | ||
| * empty values. See {@link RAMPS_CLIENT_PRODUCT_PARAM}. | ||
| * | ||
| * @param url - URL to mutate. | ||
| * @param identity - Optional product and version. | ||
| */ | ||
| export function addRampsClientIdentityParams( | ||
| url: URL, | ||
| identity: RampsClientIdentity, | ||
| ): void { | ||
| if (identity.clientProduct) { | ||
| url.searchParams.set(RAMPS_CLIENT_PRODUCT_PARAM, identity.clientProduct); | ||
| } | ||
| if (identity.clientVersion) { | ||
| url.searchParams.set(RAMPS_CLIENT_VERSION_PARAM, identity.clientVersion); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.