Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ export class SnapController extends BaseController<
versionRange: resolvedVersion,
fetch: this.#fetchFunction,
allowLocal: false,
useNpmProxy: true,
});

await this.#updateSnap({
Expand Down
16 changes: 14 additions & 2 deletions packages/snaps-controllers/src/snaps/location/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import type { DetectSnapLocationOptions, SnapLocation } from './location';

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

export const NPM_REGISTRY_PROXY = new URL('https://npm-ota.api.cx.metamask.io');

type NpmMeta = {
registry: URL;
packageName: string;
Expand All @@ -48,6 +50,12 @@ export type NpmOptions = {
* @default false
*/
allowCustomRegistries?: boolean;
/**
* Whether to use a MetaMask-owned proxy when sending requests to NPM.
*
* @default false
*/
useNpmProxy?: boolean;
};

// Base class for NPM implementation, useful for extending with custom NPM fetching logic
Expand All @@ -74,7 +82,7 @@ export abstract class BaseNpmLocation implements SnapLocation {
url.username === '' &&
url.password === ''
) {
registry = DEFAULT_NPM_REGISTRY;
registry = opts.useNpmProxy ? NPM_REGISTRY_PROXY : DEFAULT_NPM_REGISTRY;
} else {
registry = 'https://';
if (url.username) {
Expand Down Expand Up @@ -341,7 +349,11 @@ export function getNpmCanonicalBasePath(registryUrl: URL, packageName: string) {
* @returns True if the registry is the NPM registry, otherwise false.
*/
function isNPM(registryUrl: URL) {
return registryUrl.toString() === DEFAULT_NPM_REGISTRY.toString();
const registryUrlString = registryUrl.toString();
return (
registryUrlString === DEFAULT_NPM_REGISTRY.toString() ||
registryUrlString === NPM_REGISTRY_PROXY.toString()
);
}

/**
Expand Down