@metamask-previews/config-registry-controller 2.0.1-preview-3c77cf4 → 2.0.1-preview-6b4bcdab3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,14 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add `ConfigRegistryApiEnv` enum to select the API environment for the service ([#9918](https://github.com/MetaMask/core/pull/9918))
13
-
14
10
  ### Changed
15
11
 
16
- - **BREAKING:** The `env` optional constructor option type is now `ConfigRegistryApiEnv` ([#9918](https://github.com/MetaMask/core/pull/9918))
17
- - Previously, constructor options were reusing the `SDK.Env` enum from `@metamask/profile-sync-controller`.
18
12
  - Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#9754](https://github.com/MetaMask/core/pull/9754))
19
13
  - Bump `@metamask/keyring-controller` from `^27.1.0` to `^27.1.1` ([#9791](https://github.com/MetaMask/core/pull/9791))
20
14
 
@@ -84,8 +84,8 @@ export type ConfigRegistryControllerOptions = {
84
84
  fallbackConfig?: Record<string, RegistryNetworkConfig>;
85
85
  };
86
86
  declare const ConfigRegistryController_base: (abstract new (...args: any[]) => {
87
- readonly "__#6@#intervalIds": Record<string, NodeJS.Timeout>;
88
- "__#6@#intervalLength": number | undefined;
87
+ readonly "__#20@#intervalIds": Record<string, NodeJS.Timeout>;
88
+ "__#20@#intervalLength": number | undefined;
89
89
  setIntervalLength(intervalLength: number): void;
90
90
  getIntervalLength(): number | undefined;
91
91
  _startPolling(input: null): void;
@@ -84,8 +84,8 @@ export type ConfigRegistryControllerOptions = {
84
84
  fallbackConfig?: Record<string, RegistryNetworkConfig>;
85
85
  };
86
86
  declare const ConfigRegistryController_base: (abstract new (...args: any[]) => {
87
- readonly "__#6@#intervalIds": Record<string, NodeJS.Timeout>;
88
- "__#6@#intervalLength": number | undefined;
87
+ readonly "__#20@#intervalIds": Record<string, NodeJS.Timeout>;
88
+ "__#20@#intervalLength": number | undefined;
89
89
  setIntervalLength(intervalLength: number): void;
90
90
  getIntervalLength(): number | undefined;
91
91
  _startPolling(input: null): void;
@@ -12,16 +12,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  };
13
13
  var _ConfigRegistryApiService_messenger, _ConfigRegistryApiService_policy, _ConfigRegistryApiService_url, _ConfigRegistryApiService_fetch, _ConfigRegistryApiService_cachedResponse;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ConfigRegistryApiService = exports.serviceName = exports.ConfigRegistryApiEnv = void 0;
15
+ exports.ConfigRegistryApiService = exports.serviceName = void 0;
16
16
  const controller_utils_1 = require("@metamask/controller-utils");
17
+ const profile_sync_controller_1 = require("@metamask/profile-sync-controller");
17
18
  const types_js_1 = require("./types.cjs");
18
19
  const ENDPOINT_PATH = '/config/networks';
19
- var ConfigRegistryApiEnv;
20
- (function (ConfigRegistryApiEnv) {
21
- ConfigRegistryApiEnv["DEV"] = "dev";
22
- ConfigRegistryApiEnv["UAT"] = "uat";
23
- ConfigRegistryApiEnv["PRD"] = "prod";
24
- })(ConfigRegistryApiEnv || (exports.ConfigRegistryApiEnv = ConfigRegistryApiEnv = {}));
25
20
  /**
26
21
  * The name of the {@link ConfigRegistryApiService}, used to namespace the
27
22
  * service's actions and events.
@@ -37,7 +32,7 @@ const MESSENGER_EXPOSED_METHODS = ['fetchConfig'];
37
32
  * @returns The base URL for the environment.
38
33
  */
39
34
  function getConfigRegistryUrl(env) {
40
- const envPrefix = env === ConfigRegistryApiEnv.PRD ? '' : `${env}-`;
35
+ const envPrefix = env === profile_sync_controller_1.SDK.Env.PRD ? '' : `${env}-`;
41
36
  return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;
42
37
  }
43
38
  class ConfigRegistryApiService {
@@ -50,7 +45,7 @@ class ConfigRegistryApiService {
50
45
  * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
51
46
  * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.
52
47
  */
53
- constructor({ messenger, env = ConfigRegistryApiEnv.UAT, fetch: customFetch = globalThis.fetch, policyOptions = {}, }) {
48
+ constructor({ messenger, env = profile_sync_controller_1.SDK.Env.UAT, fetch: customFetch = globalThis.fetch, policyOptions = {}, }) {
54
49
  _ConfigRegistryApiService_messenger.set(this, void 0);
55
50
  _ConfigRegistryApiService_policy.set(this, void 0);
56
51
  _ConfigRegistryApiService_url.set(this, void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"config-registry-api-service.cjs","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAA4E;AAc5E,0CAA+D;AAE/D,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,mCAAW,CAAA;IACX,mCAAW,CAAA;IACX,oCAAY,CAAA;AACd,CAAC,EAJW,oBAAoB,oCAApB,oBAAoB,QAI/B;AAED;;;GAGG;AACU,QAAA,WAAW,GAAG,0BAA0B,CAAC;AAEtD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,aAAa,CAAU,CAAC;AAiC3D,6BAA6B;AAE7B;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,GAAyB;IACrD,MAAM,SAAS,GAAG,GAAG,KAAK,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;IACpE,OAAO,yBAAyB,SAAS,wBAAwB,aAAa,EAAE,CAAC;AACnF,CAAC;AAiBD,MAAa,wBAAwB;IAcnC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,GAAG,GAAG,oBAAoB,CAAC,GAAG,EAC9B,KAAK,EAAE,WAAW,GAAG,UAAU,C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E;YACrD,MAAM,GAAG,GAAG,MAAM,uBAAA,IAAI,uCAAO,MAAX,IAAI,EAAQ,uBAAA,IAAI,qCAAK,EAAE;gBACvC,OAAO;aACR,CAAC,CAAC;YAEH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACvB,OAAO,GAAG,CAAC;YACb,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,IAAI,4BAAS,CACjB,GAAG,CAAC,MAAM,EACV,2BAA2B,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAC1D,CAAC;YACJ,CAAC;YAED,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;YACvD,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,IAAI;gBACJ,GAAG,CAAC,uBAAA,IAAI,gDAAgB,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,uBAAA,IAAI,gDAAgB,EAAE,CAAC;aACrE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;QACvD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEvC,IAAA,4CAAiC,EAAC,QAAQ,CAAC,CAAC;QAE5C,uBAAA,IAAI,4CAAmB,QAAQ,MAAA,CAAC;QAEhC,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,IAAI;YACJ,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;CACF;AApJD,4DAoJC","sourcesContent":["import { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ConfigRegistryApiServiceMethodActions } from './config-registry-api-service-method-action-types.js';\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './types.js';\nimport { validateRegistryConfigApiResponse } from './types.js';\n\nconst ENDPOINT_PATH = '/config/networks';\n\nexport enum ConfigRegistryApiEnv {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prod',\n}\n\n/**\n * The name of the {@link ConfigRegistryApiService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'ConfigRegistryApiService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['fetchConfig'] as const;\n\n/**\n * Actions that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceActions =\n ConfigRegistryApiServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryApiServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ConfigRegistryApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ConfigRegistryApiService}.\n */\nexport type ConfigRegistryApiServiceMessenger = Messenger<\n typeof serviceName,\n ConfigRegistryApiServiceActions | AllowedActions,\n ConfigRegistryApiServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Returns the base URL for the config registry API for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The base URL for the environment.\n */\nfunction getConfigRegistryUrl(env: ConfigRegistryApiEnv): string {\n const envPrefix = env === ConfigRegistryApiEnv.PRD ? '' : `${env}-`;\n return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;\n}\n\nexport type ConfigRegistryApiServiceOptions = {\n /**\n * The messenger suited for this service. Required so the service can be used\n * independently and register its actions.\n */\n messenger: ConfigRegistryApiServiceMessenger;\n env?: ConfigRegistryApiEnv;\n fetch?: typeof fetch;\n /**\n * Options to pass to `createServicePolicy`, which wraps each request.\n * See {@link CreateServicePolicyOptions}.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\nexport class ConfigRegistryApiService {\n readonly name: typeof serviceName;\n\n readonly #messenger: ConfigRegistryApiServiceMessenger;\n\n readonly #policy: ServicePolicy;\n\n readonly #url: string;\n\n readonly #fetch: typeof fetch;\n\n /** Cached response from the last successful fetch. Used when server returns 304. */\n #cachedResponse: RegistryConfigApiResponse | null = null;\n\n /**\n * Construct a Config Registry API Service.\n *\n * @param options - The options for constructing the service.\n * @param options.messenger - The messenger suited for this service.\n * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.\n * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.\n * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n env = ConfigRegistryApiEnv.UAT,\n fetch: customFetch = globalThis.fetch,\n policyOptions = {},\n }: ConfigRegistryApiServiceOptions) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#url = getConfigRegistryUrl(env);\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param args - The arguments passed to the underlying policy's onBreak method\n * (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param args - The arguments passed to the underlying policy's onDegraded\n * method (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n async fetchConfig(\n options: FetchConfigOptions = {},\n ): Promise<FetchConfigResult> {\n const headers: HeadersInit = {\n 'Cache-Control': 'no-cache',\n };\n\n if (options.etag) {\n headers['If-None-Match'] = options.etag;\n }\n\n const response = await this.#policy.execute(async () => {\n const res = await this.#fetch(this.#url, {\n headers,\n });\n\n if (res.status === 304) {\n return res;\n }\n\n if (!res.ok) {\n throw new HttpError(\n res.status,\n `Failed to fetch config: ${res.status} ${res.statusText}`,\n );\n }\n\n return res;\n });\n\n if (response.status === 304) {\n const etag = response.headers.get('ETag') ?? undefined;\n return {\n modified: false,\n etag,\n ...(this.#cachedResponse !== null && { data: this.#cachedResponse }),\n };\n }\n\n const etag = response.headers.get('ETag') ?? undefined;\n const jsonData = await response.json();\n\n validateRegistryConfigApiResponse(jsonData);\n\n this.#cachedResponse = jsonData;\n\n return {\n data: jsonData,\n etag,\n modified: true,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"config-registry-api-service.cjs","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts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AAI,SAAS,CAAC;YACvD,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,IAAI;gBACJ,GAAG,CAAC,uBAAA,IAAI,gDAAgB,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,uBAAA,IAAI,gDAAgB,EAAE,CAAC;aACrE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;QACvD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEvC,IAAA,4CAAiC,EAAC,QAAQ,CAAC,CAAC;QAE5C,uBAAA,IAAI,4CAAmB,QAAQ,MAAA,CAAC;QAEhC,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,IAAI;YACJ,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;CACF;AApJD,4DAoJC","sourcesContent":["import { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { SDK } from '@metamask/profile-sync-controller';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ConfigRegistryApiServiceMethodActions } from './config-registry-api-service-method-action-types.js';\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './types.js';\nimport { validateRegistryConfigApiResponse } from './types.js';\n\nconst ENDPOINT_PATH = '/config/networks';\n\n/**\n * The name of the {@link ConfigRegistryApiService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'ConfigRegistryApiService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['fetchConfig'] as const;\n\n/**\n * Actions that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceActions =\n ConfigRegistryApiServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryApiServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ConfigRegistryApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ConfigRegistryApiService}.\n */\nexport type ConfigRegistryApiServiceMessenger = Messenger<\n typeof serviceName,\n ConfigRegistryApiServiceActions | AllowedActions,\n ConfigRegistryApiServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Returns the base URL for the config registry API for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The base URL for the environment.\n */\nfunction getConfigRegistryUrl(env: SDK.Env): string {\n const envPrefix = env === SDK.Env.PRD ? '' : `${env}-`;\n return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;\n}\n\nexport type ConfigRegistryApiServiceOptions = {\n /**\n * The messenger suited for this service. Required so the service can be used\n * independently and register its actions.\n */\n messenger: ConfigRegistryApiServiceMessenger;\n env?: SDK.Env;\n fetch?: typeof fetch;\n /**\n * Options to pass to `createServicePolicy`, which wraps each request.\n * See {@link CreateServicePolicyOptions}.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\nexport class ConfigRegistryApiService {\n readonly name: typeof serviceName;\n\n readonly #messenger: ConfigRegistryApiServiceMessenger;\n\n readonly #policy: ServicePolicy;\n\n readonly #url: string;\n\n readonly #fetch: typeof fetch;\n\n /** Cached response from the last successful fetch. Used when server returns 304. */\n #cachedResponse: RegistryConfigApiResponse | null = null;\n\n /**\n * Construct a Config Registry API Service.\n *\n * @param options - The options for constructing the service.\n * @param options.messenger - The messenger suited for this service.\n * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.\n * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.\n * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n env = SDK.Env.UAT,\n fetch: customFetch = globalThis.fetch,\n policyOptions = {},\n }: ConfigRegistryApiServiceOptions) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#url = getConfigRegistryUrl(env);\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param args - The arguments passed to the underlying policy's onBreak method\n * (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param args - The arguments passed to the underlying policy's onDegraded\n * method (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n async fetchConfig(\n options: FetchConfigOptions = {},\n ): Promise<FetchConfigResult> {\n const headers: HeadersInit = {\n 'Cache-Control': 'no-cache',\n };\n\n if (options.etag) {\n headers['If-None-Match'] = options.etag;\n }\n\n const response = await this.#policy.execute(async () => {\n const res = await this.#fetch(this.#url, {\n headers,\n });\n\n if (res.status === 304) {\n return res;\n }\n\n if (!res.ok) {\n throw new HttpError(\n res.status,\n `Failed to fetch config: ${res.status} ${res.statusText}`,\n );\n }\n\n return res;\n });\n\n if (response.status === 304) {\n const etag = response.headers.get('ETag') ?? undefined;\n return {\n modified: false,\n etag,\n ...(this.#cachedResponse !== null && { data: this.#cachedResponse }),\n };\n }\n\n const etag = response.headers.get('ETag') ?? undefined;\n const jsonData = await response.json();\n\n validateRegistryConfigApiResponse(jsonData);\n\n this.#cachedResponse = jsonData;\n\n return {\n data: jsonData,\n etag,\n modified: true,\n };\n }\n}\n"]}
@@ -1,13 +1,9 @@
1
1
  import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
2
2
  import type { Messenger } from "@metamask/messenger";
3
+ import { SDK } from "@metamask/profile-sync-controller";
3
4
  import type { IDisposable } from "cockatiel";
4
5
  import type { ConfigRegistryApiServiceMethodActions } from "./config-registry-api-service-method-action-types.cjs";
5
6
  import type { FetchConfigOptions, FetchConfigResult } from "./types.cjs";
6
- export declare enum ConfigRegistryApiEnv {
7
- DEV = "dev",
8
- UAT = "uat",
9
- PRD = "prod"
10
- }
11
7
  /**
12
8
  * The name of the {@link ConfigRegistryApiService}, used to namespace the
13
9
  * service's actions and events.
@@ -40,7 +36,7 @@ export type ConfigRegistryApiServiceOptions = {
40
36
  * independently and register its actions.
41
37
  */
42
38
  messenger: ConfigRegistryApiServiceMessenger;
43
- env?: ConfigRegistryApiEnv;
39
+ env?: SDK.Env;
44
40
  fetch?: typeof fetch;
45
41
  /**
46
42
  * Options to pass to `createServicePolicy`, which wraps each request.
@@ -1 +1 @@
1
- {"version":3,"file":"config-registry-api-service.d.cts","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":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AAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW;IAIvE;;;;;;;;;OASG;IACH,OAAO,CACL,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAC5C,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIvC;;;;;;;;;;;;;;;;;OAiBG;IACH,UAAU,CACR,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,GAC/C,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAIpC,WAAW,CACf,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC;CAkD9B"}
1
+ {"version":3,"file":"config-registry-api-service.d.cts","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,EAAE,GAAG,EAAE,0CAA0C;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,qCAAqC,EAAE,8DAA6D;AAClH,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAElB,oBAAmB;AAKpB;;;GAGG;AACH,eAAO,MAAM,WAAW,6BAA6B,CAAC;AAMtD;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,qCAAqC,CAAC;AAExC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEnD;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,WAAW,EAClB,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAeF,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;;OAGG;IACH,SAAS,EAAE,iCAAiC,CAAC;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,0BAA0B,CAAC;CAC5C,CAAC;AAEF,qBAAa,wBAAwB;;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IAalC;;;;;;;;OAQG;gBACS,EACV,SAAS,EACT,GAAiB,EACjB,KAAK,EAAE,WAA8B,EACrC,aAAkB,GACnB,EAAE,+BAA+B;IAclC;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW;IAIvE;;;;;;;;;OASG;IACH,OAAO,CACL,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAC5C,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIvC;;;;;;;;;;;;;;;;;OAiBG;IACH,UAAU,CACR,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,GAC/C,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAIpC,WAAW,CACf,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC;CAkD9B"}
@@ -1,13 +1,9 @@
1
1
  import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
2
2
  import type { Messenger } from "@metamask/messenger";
3
+ import { SDK } from "@metamask/profile-sync-controller";
3
4
  import type { IDisposable } from "cockatiel";
4
5
  import type { ConfigRegistryApiServiceMethodActions } from "./config-registry-api-service-method-action-types.mjs";
5
6
  import type { FetchConfigOptions, FetchConfigResult } from "./types.mjs";
6
- export declare enum ConfigRegistryApiEnv {
7
- DEV = "dev",
8
- UAT = "uat",
9
- PRD = "prod"
10
- }
11
7
  /**
12
8
  * The name of the {@link ConfigRegistryApiService}, used to namespace the
13
9
  * service's actions and events.
@@ -40,7 +36,7 @@ export type ConfigRegistryApiServiceOptions = {
40
36
  * independently and register its actions.
41
37
  */
42
38
  messenger: ConfigRegistryApiServiceMessenger;
43
- env?: ConfigRegistryApiEnv;
39
+ env?: SDK.Env;
44
40
  fetch?: typeof fetch;
45
41
  /**
46
42
  * Options to pass to `createServicePolicy`, which wraps each request.
@@ -1 +1 @@
1
- {"version":3,"file":"config-registry-api-service.d.mts","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,qCAAqC,EAAE,8DAA6D;AAClH,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAElB,oBAAmB;AAKpB,oBAAY,oBAAoB;IAC9B,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,SAAS;CACb;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,6BAA6B,CAAC;AAMtD;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,qCAAqC,CAAC;AAExC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEnD;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,WAAW,EAClB,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAeF,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;;OAGG;IACH,SAAS,EAAE,iCAAiC,CAAC;IAC7C,GAAG,CAAC,EAAE,oBAAoB,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,0BAA0B,CAAC;CAC5C,CAAC;AAEF,qBAAa,wBAAwB;;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IAalC;;;;;;;;OAQG;gBACS,EACV,SAAS,EACT,GAA8B,EAC9B,KAAK,EAAE,WAA8B,EACrC,aAAkB,GACnB,EAAE,+BAA+B;IAclC;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW;IAIvE;;;;;;;;;OASG;IACH,OAAO,CACL,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAC5C,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIvC;;;;;;;;;;;;;;;;;OAiBG;IACH,UAAU,CACR,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,GAC/C,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAIpC,WAAW,CACf,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC;CAkD9B"}
1
+ {"version":3,"file":"config-registry-api-service.d.mts","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,EAAE,GAAG,EAAE,0CAA0C;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,qCAAqC,EAAE,8DAA6D;AAClH,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAElB,oBAAmB;AA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Y,CAAC,CAAC;IAIpC,WAAW,CACf,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC;CAkD9B"}
@@ -11,14 +11,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _ConfigRegistryApiService_messenger, _ConfigRegistryApiService_policy, _ConfigRegistryApiService_url, _ConfigRegistryApiService_fetch, _ConfigRegistryApiService_cachedResponse;
13
13
  import { createServicePolicy, HttpError } from "@metamask/controller-utils";
14
+ import { SDK } from "@metamask/profile-sync-controller";
14
15
  import { validateRegistryConfigApiResponse } from "./types.mjs";
15
16
  const ENDPOINT_PATH = '/config/networks';
16
- export var ConfigRegistryApiEnv;
17
- (function (ConfigRegistryApiEnv) {
18
- ConfigRegistryApiEnv["DEV"] = "dev";
19
- ConfigRegistryApiEnv["UAT"] = "uat";
20
- ConfigRegistryApiEnv["PRD"] = "prod";
21
- })(ConfigRegistryApiEnv || (ConfigRegistryApiEnv = {}));
22
17
  /**
23
18
  * The name of the {@link ConfigRegistryApiService}, used to namespace the
24
19
  * service's actions and events.
@@ -34,7 +29,7 @@ const MESSENGER_EXPOSED_METHODS = ['fetchConfig'];
34
29
  * @returns The base URL for the environment.
35
30
  */
36
31
  function getConfigRegistryUrl(env) {
37
- const envPrefix = env === ConfigRegistryApiEnv.PRD ? '' : `${env}-`;
32
+ const envPrefix = env === SDK.Env.PRD ? '' : `${env}-`;
38
33
  return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;
39
34
  }
40
35
  export class ConfigRegistryApiService {
@@ -47,7 +42,7 @@ export class ConfigRegistryApiService {
47
42
  * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
48
43
  * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.
49
44
  */
50
- constructor({ messenger, env = ConfigRegistryApiEnv.UAT, fetch: customFetch = globalThis.fetch, policyOptions = {}, }) {
45
+ constructor({ messenger, env = SDK.Env.UAT, fetch: customFetch = globalThis.fetch, policyOptions = {}, }) {
51
46
  _ConfigRegistryApiService_messenger.set(this, void 0);
52
47
  _ConfigRegistryApiService_policy.set(this, void 0);
53
48
  _ConfigRegistryApiService_url.set(this, void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"config-registry-api-service.mjs","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,mCAAmC;AAc5E,OAAO,EAAE,iCAAiC,EAAE,oBAAmB;AAE/D,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,mCAAW,CAAA;IACX,mCAAW,CAAA;IACX,oCAAY,CAAA;AACd,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAEtD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,aAAa,CAAU,CAAC;AAiC3D,6BAA6B;AAE7B;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,GAAyB;IACrD,MAAM,SAAS,GAAG,GAAG,KAAK,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;IACpE,OAAO,yBAAyB,SAAS,wBAAwB,aAAa,EAAE,CAAC;AACnF,CAAC;AAiBD,MAAM,OAAO,wBAAwB;IAcnC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,GAAG,GAAG,oBAAoB,CAAC,GAAG,EAC9B,KAAK,EAAE,WAAW,GAAG,UAAU,CAAC,KAAK,EACrC,aAAa,GAAG,EAAE,GACc;QAzBzB,sDAA8C;QAE9C,mDAAuB;QAEvB,gDAAa;QAEb,kDAAqB;QAE9B,oFAAoF;QAC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C;YAEH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACvB,OAAO,GAAG,CAAC;YACb,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,IAAI,SAAS,CACjB,GAAG,CAAC,MAAM,EACV,2BAA2B,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAC1D,CAAC;YACJ,CAAC;YAED,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;YACvD,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,IAAI;gBACJ,GAAG,CAAC,uBAAA,IAAI,gDAAgB,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,uBAAA,IAAI,gDAAgB,EAAE,CAAC;aACrE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;QACvD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEvC,iCAAiC,CAAC,QAAQ,CAAC,CAAC;QAE5C,uBAAA,IAAI,4CAAmB,QAAQ,MAAA,CAAC;QAEhC,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,IAAI;YACJ,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ConfigRegistryApiServiceMethodActions } from './config-registry-api-service-method-action-types.js';\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './types.js';\nimport { validateRegistryConfigApiResponse } from './types.js';\n\nconst ENDPOINT_PATH = '/config/networks';\n\nexport enum ConfigRegistryApiEnv {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prod',\n}\n\n/**\n * The name of the {@link ConfigRegistryApiService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'ConfigRegistryApiService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['fetchConfig'] as const;\n\n/**\n * Actions that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceActions =\n ConfigRegistryApiServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryApiServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ConfigRegistryApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ConfigRegistryApiService}.\n */\nexport type ConfigRegistryApiServiceMessenger = Messenger<\n typeof serviceName,\n ConfigRegistryApiServiceActions | AllowedActions,\n ConfigRegistryApiServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Returns the base URL for the config registry API for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The base URL for the environment.\n */\nfunction getConfigRegistryUrl(env: ConfigRegistryApiEnv): string {\n const envPrefix = env === ConfigRegistryApiEnv.PRD ? '' : `${env}-`;\n return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;\n}\n\nexport type ConfigRegistryApiServiceOptions = {\n /**\n * The messenger suited for this service. Required so the service can be used\n * independently and register its actions.\n */\n messenger: ConfigRegistryApiServiceMessenger;\n env?: ConfigRegistryApiEnv;\n fetch?: typeof fetch;\n /**\n * Options to pass to `createServicePolicy`, which wraps each request.\n * See {@link CreateServicePolicyOptions}.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\nexport class ConfigRegistryApiService {\n readonly name: typeof serviceName;\n\n readonly #messenger: ConfigRegistryApiServiceMessenger;\n\n readonly #policy: ServicePolicy;\n\n readonly #url: string;\n\n readonly #fetch: typeof fetch;\n\n /** Cached response from the last successful fetch. Used when server returns 304. */\n #cachedResponse: RegistryConfigApiResponse | null = null;\n\n /**\n * Construct a Config Registry API Service.\n *\n * @param options - The options for constructing the service.\n * @param options.messenger - The messenger suited for this service.\n * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.\n * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.\n * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n env = ConfigRegistryApiEnv.UAT,\n fetch: customFetch = globalThis.fetch,\n policyOptions = {},\n }: ConfigRegistryApiServiceOptions) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#url = getConfigRegistryUrl(env);\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param args - The arguments passed to the underlying policy's onBreak method\n * (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param args - The arguments passed to the underlying policy's onDegraded\n * method (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n async fetchConfig(\n options: FetchConfigOptions = {},\n ): Promise<FetchConfigResult> {\n const headers: HeadersInit = {\n 'Cache-Control': 'no-cache',\n };\n\n if (options.etag) {\n headers['If-None-Match'] = options.etag;\n }\n\n const response = await this.#policy.execute(async () => {\n const res = await this.#fetch(this.#url, {\n headers,\n });\n\n if (res.status === 304) {\n return res;\n }\n\n if (!res.ok) {\n throw new HttpError(\n res.status,\n `Failed to fetch config: ${res.status} ${res.statusText}`,\n );\n }\n\n return res;\n });\n\n if (response.status === 304) {\n const etag = response.headers.get('ETag') ?? undefined;\n return {\n modified: false,\n etag,\n ...(this.#cachedResponse !== null && { data: this.#cachedResponse }),\n };\n }\n\n const etag = response.headers.get('ETag') ?? undefined;\n const jsonData = await response.json();\n\n validateRegistryConfigApiResponse(jsonData);\n\n this.#cachedResponse = jsonData;\n\n return {\n data: jsonData,\n etag,\n modified: true,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"config-registry-api-service.mjs","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,mCAAmC;AAM5E,OAAO,EAAE,GAAG,EAAE,0CAA0C;AASxD,OAAO,EAAE,iCAAiC,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BACf,IAAI;gBACJ,GAAG,CAAC,uBAAA,IAAI,gDAAgB,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,uBAAA,IAAI,gDAAgB,EAAE,CAAC;aACrE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;QACvD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEvC,iCAAiC,CAAC,QAAQ,CAAC,CAAC;QAE5C,uBAAA,IAAI,4CAAmB,QAAQ,MAAA,CAAC;QAEhC,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,IAAI;YACJ,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { SDK } from '@metamask/profile-sync-controller';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ConfigRegistryApiServiceMethodActions } from './config-registry-api-service-method-action-types.js';\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './types.js';\nimport { validateRegistryConfigApiResponse } from './types.js';\n\nconst ENDPOINT_PATH = '/config/networks';\n\n/**\n * The name of the {@link ConfigRegistryApiService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'ConfigRegistryApiService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['fetchConfig'] as const;\n\n/**\n * Actions that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceActions =\n ConfigRegistryApiServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryApiServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ConfigRegistryApiService} exposes to other consumers.\n */\nexport type ConfigRegistryApiServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ConfigRegistryApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ConfigRegistryApiService}.\n */\nexport type ConfigRegistryApiServiceMessenger = Messenger<\n typeof serviceName,\n ConfigRegistryApiServiceActions | AllowedActions,\n ConfigRegistryApiServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Returns the base URL for the config registry API for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The base URL for the environment.\n */\nfunction getConfigRegistryUrl(env: SDK.Env): string {\n const envPrefix = env === SDK.Env.PRD ? '' : `${env}-`;\n return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;\n}\n\nexport type ConfigRegistryApiServiceOptions = {\n /**\n * The messenger suited for this service. Required so the service can be used\n * independently and register its actions.\n */\n messenger: ConfigRegistryApiServiceMessenger;\n env?: SDK.Env;\n fetch?: typeof fetch;\n /**\n * Options to pass to `createServicePolicy`, which wraps each request.\n * See {@link CreateServicePolicyOptions}.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\nexport class ConfigRegistryApiService {\n readonly name: typeof serviceName;\n\n readonly #messenger: ConfigRegistryApiServiceMessenger;\n\n readonly #policy: ServicePolicy;\n\n readonly #url: string;\n\n readonly #fetch: typeof fetch;\n\n /** Cached response from the last successful fetch. Used when server returns 304. */\n #cachedResponse: RegistryConfigApiResponse | null = null;\n\n /**\n * Construct a Config Registry API Service.\n *\n * @param options - The options for constructing the service.\n * @param options.messenger - The messenger suited for this service.\n * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.\n * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.\n * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n env = SDK.Env.UAT,\n fetch: customFetch = globalThis.fetch,\n policyOptions = {},\n }: ConfigRegistryApiServiceOptions) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#url = getConfigRegistryUrl(env);\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param args - The arguments passed to the underlying policy's onBreak method\n * (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param args - The arguments passed to the underlying policy's onDegraded\n * method (e.g. the listener to be called).\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n async fetchConfig(\n options: FetchConfigOptions = {},\n ): Promise<FetchConfigResult> {\n const headers: HeadersInit = {\n 'Cache-Control': 'no-cache',\n };\n\n if (options.etag) {\n headers['If-None-Match'] = options.etag;\n }\n\n const response = await this.#policy.execute(async () => {\n const res = await this.#fetch(this.#url, {\n headers,\n });\n\n if (res.status === 304) {\n return res;\n }\n\n if (!res.ok) {\n throw new HttpError(\n res.status,\n `Failed to fetch config: ${res.status} ${res.statusText}`,\n );\n }\n\n return res;\n });\n\n if (response.status === 304) {\n const etag = response.headers.get('ETag') ?? undefined;\n return {\n modified: false,\n etag,\n ...(this.#cachedResponse !== null && { data: this.#cachedResponse }),\n };\n }\n\n const etag = response.headers.get('ETag') ?? undefined;\n const jsonData = await response.json();\n\n validateRegistryConfigApiResponse(jsonData);\n\n this.#cachedResponse = jsonData;\n\n return {\n data: jsonData,\n etag,\n modified: true,\n };\n }\n}\n"]}
@@ -4,33 +4,33 @@ import type { Infer } from "@metamask/superstruct";
4
4
  * chainId is in CAIP-2 format (e.g. "eip155:1", "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp").
5
5
  */
6
6
  export declare const RegistryNetworkConfigSchema: import("@metamask/superstruct").Struct<{
7
- imageUrl: string;
8
7
  name: string;
8
+ imageUrl: string;
9
9
  chainId: `${string}:${string}`;
10
10
  coingeckoPlatformId: string;
11
11
  assets: {
12
12
  native: {
13
13
  symbol: string;
14
+ name: string;
14
15
  assetId: string;
15
16
  imageUrl: string;
16
- name: string;
17
17
  decimals: number;
18
18
  coingeckoCoinId?: string | undefined;
19
19
  };
20
20
  listUrl?: string | undefined;
21
21
  governance?: {
22
22
  symbol: string;
23
+ name: string;
23
24
  assetId: string;
24
25
  imageUrl: string;
25
- name: string;
26
26
  decimals: number;
27
27
  coingeckoCoinId?: string | undefined;
28
28
  } | undefined;
29
29
  };
30
30
  rpcProviders: {
31
31
  default: {
32
- url: string;
33
32
  type: string;
33
+ url: string;
34
34
  networkClientId: string;
35
35
  };
36
36
  fallbacks: string[];
@@ -61,18 +61,18 @@ export declare const RegistryNetworkConfigSchema: import("@metamask/superstruct"
61
61
  assets: import("@metamask/superstruct").Struct<{
62
62
  native: {
63
63
  symbol: string;
64
+ name: string;
64
65
  assetId: string;
65
66
  imageUrl: string;
66
- name: string;
67
67
  decimals: number;
68
68
  coingeckoCoinId?: string | undefined;
69
69
  };
70
70
  listUrl?: string | undefined;
71
71
  governance?: {
72
72
  symbol: string;
73
+ name: string;
73
74
  assetId: string;
74
75
  imageUrl: string;
75
- name: string;
76
76
  decimals: number;
77
77
  coingeckoCoinId?: string | undefined;
78
78
  } | undefined;
@@ -80,9 +80,9 @@ export declare const RegistryNetworkConfigSchema: import("@metamask/superstruct"
80
80
  listUrl: import("@metamask/superstruct").Struct<string | undefined, null>;
81
81
  native: import("@metamask/superstruct").Struct<{
82
82
  symbol: string;
83
+ name: string;
83
84
  assetId: string;
84
85
  imageUrl: string;
85
- name: string;
86
86
  decimals: number;
87
87
  coingeckoCoinId?: string | undefined;
88
88
  }, {
@@ -95,9 +95,9 @@ export declare const RegistryNetworkConfigSchema: import("@metamask/superstruct"
95
95
  }>;
96
96
  governance: import("@metamask/superstruct").Struct<{
97
97
  symbol: string;
98
+ name: string;
98
99
  assetId: string;
99
100
  imageUrl: string;
100
- name: string;
101
101
  decimals: number;
102
102
  coingeckoCoinId?: string | undefined;
103
103
  } | undefined, {
@@ -111,15 +111,15 @@ export declare const RegistryNetworkConfigSchema: import("@metamask/superstruct"
111
111
  }>;
112
112
  rpcProviders: import("@metamask/superstruct").Struct<{
113
113
  default: {
114
- url: string;
115
114
  type: string;
115
+ url: string;
116
116
  networkClientId: string;
117
117
  };
118
118
  fallbacks: string[];
119
119
  }, {
120
120
  default: import("@metamask/superstruct").Struct<{
121
- url: string;
122
121
  type: string;
122
+ url: string;
123
123
  networkClientId: string;
124
124
  }, {
125
125
  url: import("@metamask/superstruct").Struct<string, null>;
@@ -166,33 +166,33 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
166
166
  version: string;
167
167
  timestamp: number;
168
168
  chains: {
169
- imageUrl: string;
170
169
  name: string;
170
+ imageUrl: string;
171
171
  chainId: `${string}:${string}`;
172
172
  coingeckoPlatformId: string;
173
173
  assets: {
174
174
  native: {
175
175
  symbol: string;
176
+ name: string;
176
177
  assetId: string;
177
178
  imageUrl: string;
178
- name: string;
179
179
  decimals: number;
180
180
  coingeckoCoinId?: string | undefined;
181
181
  };
182
182
  listUrl?: string | undefined;
183
183
  governance?: {
184
184
  symbol: string;
185
+ name: string;
185
186
  assetId: string;
186
187
  imageUrl: string;
187
- name: string;
188
188
  decimals: number;
189
189
  coingeckoCoinId?: string | undefined;
190
190
  } | undefined;
191
191
  };
192
192
  rpcProviders: {
193
193
  default: {
194
- url: string;
195
194
  type: string;
195
+ url: string;
196
196
  networkClientId: string;
197
197
  };
198
198
  fallbacks: string[];
@@ -221,33 +221,33 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
221
221
  version: string;
222
222
  timestamp: number;
223
223
  chains: {
224
- imageUrl: string;
225
224
  name: string;
225
+ imageUrl: string;
226
226
  chainId: `${string}:${string}`;
227
227
  coingeckoPlatformId: string;
228
228
  assets: {
229
229
  native: {
230
230
  symbol: string;
231
+ name: string;
231
232
  assetId: string;
232
233
  imageUrl: string;
233
- name: string;
234
234
  decimals: number;
235
235
  coingeckoCoinId?: string | undefined;
236
236
  };
237
237
  listUrl?: string | undefined;
238
238
  governance?: {
239
239
  symbol: string;
240
+ name: string;
240
241
  assetId: string;
241
242
  imageUrl: string;
242
- name: string;
243
243
  decimals: number;
244
244
  coingeckoCoinId?: string | undefined;
245
245
  } | undefined;
246
246
  };
247
247
  rpcProviders: {
248
248
  default: {
249
- url: string;
250
249
  type: string;
250
+ url: string;
251
251
  networkClientId: string;
252
252
  };
253
253
  fallbacks: string[];
@@ -274,33 +274,33 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
274
274
  version: import("@metamask/superstruct").Struct<string, null>;
275
275
  timestamp: import("@metamask/superstruct").Struct<number, null>;
276
276
  chains: import("@metamask/superstruct").Struct<{
277
- imageUrl: string;
278
277
  name: string;
278
+ imageUrl: string;
279
279
  chainId: `${string}:${string}`;
280
280
  coingeckoPlatformId: string;
281
281
  assets: {
282
282
  native: {
283
283
  symbol: string;
284
+ name: string;
284
285
  assetId: string;
285
286
  imageUrl: string;
286
- name: string;
287
287
  decimals: number;
288
288
  coingeckoCoinId?: string | undefined;
289
289
  };
290
290
  listUrl?: string | undefined;
291
291
  governance?: {
292
292
  symbol: string;
293
+ name: string;
293
294
  assetId: string;
294
295
  imageUrl: string;
295
- name: string;
296
296
  decimals: number;
297
297
  coingeckoCoinId?: string | undefined;
298
298
  } | undefined;
299
299
  };
300
300
  rpcProviders: {
301
301
  default: {
302
- url: string;
303
302
  type: string;
303
+ url: string;
304
304
  networkClientId: string;
305
305
  };
306
306
  fallbacks: string[];
@@ -323,33 +323,33 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
323
323
  multicall3?: `0x${string}` | undefined;
324
324
  } | undefined;
325
325
  }[], import("@metamask/superstruct").Struct<{
326
- imageUrl: string;
327
326
  name: string;
327
+ imageUrl: string;
328
328
  chainId: `${string}:${string}`;
329
329
  coingeckoPlatformId: string;
330
330
  assets: {
331
331
  native: {
332
332
  symbol: string;
333
+ name: string;
333
334
  assetId: string;
334
335
  imageUrl: string;
335
- name: string;
336
336
  decimals: number;
337
337
  coingeckoCoinId?: string | undefined;
338
338
  };
339
339
  listUrl?: string | undefined;
340
340
  governance?: {
341
341
  symbol: string;
342
+ name: string;
342
343
  assetId: string;
343
344
  imageUrl: string;
344
- name: string;
345
345
  decimals: number;
346
346
  coingeckoCoinId?: string | undefined;
347
347
  } | undefined;
348
348
  };
349
349
  rpcProviders: {
350
350
  default: {
351
- url: string;
352
351
  type: string;
352
+ url: string;
353
353
  networkClientId: string;
354
354
  };
355
355
  fallbacks: string[];
@@ -380,18 +380,18 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
380
380
  assets: import("@metamask/superstruct").Struct<{
381
381
  native: {
382
382
  symbol: string;
383
+ name: string;
383
384
  assetId: string;
384
385
  imageUrl: string;
385
- name: string;
386
386
  decimals: number;
387
387
  coingeckoCoinId?: string | undefined;
388
388
  };
389
389
  listUrl?: string | undefined;
390
390
  governance?: {
391
391
  symbol: string;
392
+ name: string;
392
393
  assetId: string;
393
394
  imageUrl: string;
394
- name: string;
395
395
  decimals: number;
396
396
  coingeckoCoinId?: string | undefined;
397
397
  } | undefined;
@@ -399,9 +399,9 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
399
399
  listUrl: import("@metamask/superstruct").Struct<string | undefined, null>;
400
400
  native: import("@metamask/superstruct").Struct<{
401
401
  symbol: string;
402
+ name: string;
402
403
  assetId: string;
403
404
  imageUrl: string;
404
- name: string;
405
405
  decimals: number;
406
406
  coingeckoCoinId?: string | undefined;
407
407
  }, {
@@ -414,9 +414,9 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
414
414
  }>;
415
415
  governance: import("@metamask/superstruct").Struct<{
416
416
  symbol: string;
417
+ name: string;
417
418
  assetId: string;
418
419
  imageUrl: string;
419
- name: string;
420
420
  decimals: number;
421
421
  coingeckoCoinId?: string | undefined;
422
422
  } | undefined, {
@@ -430,15 +430,15 @@ export declare const RegistryConfigApiResponseSchema: import("@metamask/superstr
430
430
  }>;
431
431
  rpcProviders: import("@metamask/superstruct").Struct<{
432
432
  default: {
433
- url: string;
434
433
  type: string;
434
+ url: string;
435
435
  networkClientId: string;
436
436
  };
437
437
  fallbacks: string[];
438
438
  }, {
439
439
  default: import("@metamask/superstruct").Struct<{
440
- url: string;
441
440
  type: string;
441
+ url: string;
442
442
  networkClientId: string;
443
443
  }, {
444
444
  url: import("@metamask/superstruct").Struct<string, null>;