Skip to content

Commit 59d8c14

Browse files
feat: Add NPM proxy support
1 parent 6f54282 commit 59d8c14

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ export class SnapController extends BaseController<
15391539
versionRange: resolvedVersion,
15401540
fetch: this.#fetchFunction,
15411541
allowLocal: false,
1542+
useNpmProxy: true,
15421543
});
15431544

15441545
await this.#updateSnap({

packages/snaps-controllers/src/snaps/location/npm.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import type { DetectSnapLocationOptions, SnapLocation } from './location';
2828

2929
export const DEFAULT_NPM_REGISTRY = new URL('https://registry.npmjs.org');
3030

31+
export const NPM_REGISTRY_PROXY = new URL(
32+
'https://npm-ota.dev-api.cx.metamask.io',
33+
);
34+
3135
type NpmMeta = {
3236
registry: URL;
3337
packageName: string;
@@ -48,6 +52,12 @@ export type NpmOptions = {
4852
* @default false
4953
*/
5054
allowCustomRegistries?: boolean;
55+
/**
56+
* Whether to use a MetaMask-owned proxy when sending requests to NPM.
57+
*
58+
* @default false
59+
*/
60+
useNpmProxy?: boolean;
5161
};
5262

5363
// Base class for NPM implementation, useful for extending with custom NPM fetching logic
@@ -74,7 +84,7 @@ export abstract class BaseNpmLocation implements SnapLocation {
7484
url.username === '' &&
7585
url.password === ''
7686
) {
77-
registry = DEFAULT_NPM_REGISTRY;
87+
registry = opts.useNpmProxy ? NPM_REGISTRY_PROXY : DEFAULT_NPM_REGISTRY;
7888
} else {
7989
registry = 'https://';
8090
if (url.username) {

0 commit comments

Comments
 (0)