Skip to content

Commit

Permalink
feat: Add URLSearchParams as a default endowment (#3047)
Browse files Browse the repository at this point in the history
Add `URLSearchParams` as a default global to allow for easy modification
of query strings for API calls. This was already somewhat available
through `URL.searchParams`.

Closes #3044
  • Loading branch information
FrederikBolding authored Jan 29, 2025
1 parent cc563af commit 362208e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const commonEndowments: CommonEndowmentSpecification[] = [
{ endowment: Uint16Array, name: 'Uint16Array' },
{ endowment: Uint32Array, name: 'Uint32Array' },
{ endowment: URL, name: 'URL' },
{ endowment: URLSearchParams, name: 'URLSearchParams' },
{ endowment: WebAssembly, name: 'WebAssembly' },
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ describe('endowments', () => {
endowments: { URL },
factory: () => new URL('https://metamask.io/snaps/'),
},
URLSearchParams: {
endowments: { URLSearchParams },
factory: () => new URLSearchParams('https://metamask.io/snaps?foo=bar'),
},
Int8Array: {
endowments: { Int8Array },
factory: () => new Int8Array(),
Expand Down Expand Up @@ -384,6 +388,7 @@ describe('endowments', () => {
{ factory: expect.any(Function), names: ['Uint16Array'] },
{ factory: expect.any(Function), names: ['Uint32Array'] },
{ factory: expect.any(Function), names: ['URL'] },
{ factory: expect.any(Function), names: ['URLSearchParams'] },
{ factory: expect.any(Function), names: ['WebAssembly'] },
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ describe('getEndowments', () => {
"TextDecoder",
"TextEncoder",
"URL",
"URLSearchParams",
"setInterval",
"clearInterval",
"Int8Array",
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-utils/src/default-endowments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([
'TextDecoder',
'TextEncoder',
'URL',
'URLSearchParams',
'setInterval',
'clearInterval',
'Int8Array',
Expand Down

0 comments on commit 362208e

Please sign in to comment.