@metamask-previews/config-registry-controller 0.0.0-preview-32ed9958c

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/ConfigRegistryController.cjs +132 -0
  5. package/dist/ConfigRegistryController.cjs.map +1 -0
  6. package/dist/ConfigRegistryController.d.cts +134 -0
  7. package/dist/ConfigRegistryController.d.cts.map +1 -0
  8. package/dist/ConfigRegistryController.d.mts +134 -0
  9. package/dist/ConfigRegistryController.d.mts.map +1 -0
  10. package/dist/ConfigRegistryController.mjs +128 -0
  11. package/dist/ConfigRegistryController.mjs.map +1 -0
  12. package/dist/config-registry-api-service/config-registry-api-service.cjs +123 -0
  13. package/dist/config-registry-api-service/config-registry-api-service.cjs.map +1 -0
  14. package/dist/config-registry-api-service/config-registry-api-service.d.cts +56 -0
  15. package/dist/config-registry-api-service/config-registry-api-service.d.cts.map +1 -0
  16. package/dist/config-registry-api-service/config-registry-api-service.d.mts +56 -0
  17. package/dist/config-registry-api-service/config-registry-api-service.d.mts.map +1 -0
  18. package/dist/config-registry-api-service/config-registry-api-service.mjs +119 -0
  19. package/dist/config-registry-api-service/config-registry-api-service.mjs.map +1 -0
  20. package/dist/config-registry-api-service/filters.cjs +30 -0
  21. package/dist/config-registry-api-service/filters.cjs.map +1 -0
  22. package/dist/config-registry-api-service/filters.d.cts +15 -0
  23. package/dist/config-registry-api-service/filters.d.cts.map +1 -0
  24. package/dist/config-registry-api-service/filters.d.mts +15 -0
  25. package/dist/config-registry-api-service/filters.d.mts.map +1 -0
  26. package/dist/config-registry-api-service/filters.mjs +26 -0
  27. package/dist/config-registry-api-service/filters.mjs.map +1 -0
  28. package/dist/config-registry-api-service/index.cjs +8 -0
  29. package/dist/config-registry-api-service/index.cjs.map +1 -0
  30. package/dist/config-registry-api-service/index.d.cts +6 -0
  31. package/dist/config-registry-api-service/index.d.cts.map +1 -0
  32. package/dist/config-registry-api-service/index.d.mts +6 -0
  33. package/dist/config-registry-api-service/index.d.mts.map +1 -0
  34. package/dist/config-registry-api-service/index.mjs +3 -0
  35. package/dist/config-registry-api-service/index.mjs.map +1 -0
  36. package/dist/config-registry-api-service/types.cjs +69 -0
  37. package/dist/config-registry-api-service/types.cjs.map +1 -0
  38. package/dist/config-registry-api-service/types.d.cts +476 -0
  39. package/dist/config-registry-api-service/types.d.cts.map +1 -0
  40. package/dist/config-registry-api-service/types.d.mts +476 -0
  41. package/dist/config-registry-api-service/types.d.mts.map +1 -0
  42. package/dist/config-registry-api-service/types.mjs +65 -0
  43. package/dist/config-registry-api-service/types.mjs.map +1 -0
  44. package/dist/index.cjs +15 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +7 -0
  47. package/dist/index.d.cts.map +1 -0
  48. package/dist/index.d.mts +7 -0
  49. package/dist/index.d.mts.map +1 -0
  50. package/dist/index.mjs +5 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/dist/selectors.cjs +34 -0
  53. package/dist/selectors.cjs.map +1 -0
  54. package/dist/selectors.d.cts +314 -0
  55. package/dist/selectors.d.cts.map +1 -0
  56. package/dist/selectors.d.mts +314 -0
  57. package/dist/selectors.d.mts.map +1 -0
  58. package/dist/selectors.mjs +30 -0
  59. package/dist/selectors.mjs.map +1 -0
  60. package/dist/utils/feature-flags.cjs +27 -0
  61. package/dist/utils/feature-flags.cjs.map +1 -0
  62. package/dist/utils/feature-flags.d.cts +9 -0
  63. package/dist/utils/feature-flags.d.cts.map +1 -0
  64. package/dist/utils/feature-flags.d.mts +9 -0
  65. package/dist/utils/feature-flags.d.mts.map +1 -0
  66. package/dist/utils/feature-flags.mjs +23 -0
  67. package/dist/utils/feature-flags.mjs.map +1 -0
  68. package/package.json +81 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController.mjs","sourceRoot":"","sources":["../src/ConfigRegistryController.ts"],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,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC3B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,aAAa,GACjB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAE5D,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type {\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport { Duration, inMilliseconds } from '@metamask/utils';\n\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryNetworkConfig,\n} from './config-registry-api-service';\nimport { isConfigRegistryApiEnabled as defaultIsConfigRegistryApiEnabled } from './utils/feature-flags';\n\nconst controllerName = 'ConfigRegistryController';\n\nexport const DEFAULT_POLLING_INTERVAL = inMilliseconds(1, Duration.Day);\n\n/**\n * State for the ConfigRegistryController.\n *\n * Tracks network configurations fetched from the config registry API,\n * along with metadata about the fetch status and caching.\n */\nexport type ConfigRegistryControllerState = {\n /**\n * Network configurations organized by chain ID.\n * Stores the full API response including isFeatured, isTestnet, etc.\n * Use selectors (e.g. selectFeaturedNetworks) to filter when needed.\n */\n configs: {\n networks: Record<string, RegistryNetworkConfig>;\n };\n /**\n * Semantic version string of the configuration data from the API.\n * Indicates the version/schema of the configuration structure itself\n * (e.g., \"v1.0.0\", \"1.0.0\").\n * This is different from `etag` which is used for HTTP cache validation.\n */\n version: string | null;\n /**\n * Timestamp (milliseconds since epoch) of when the configuration\n * was last successfully fetched from the API.\n */\n lastFetched: number | null;\n /**\n * HTTP entity tag (ETag) used for cache validation.\n * Sent as `If-None-Match` header in subsequent requests to check\n * if the content has changed. If the server returns 304 Not Modified,\n * the full response body is not downloaded, improving efficiency.\n * This is different from `version` which is a semantic version string\n * indicating the schema/version of the configuration data itself.\n */\n etag: string | null;\n};\n\nconst stateMetadata = {\n configs: {\n persist: true,\n includeInStateLogs: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n version: {\n persist: true,\n includeInStateLogs: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n lastFetched: {\n persist: true,\n includeInStateLogs: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n etag: {\n persist: true,\n includeInStateLogs: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n} satisfies StateMetadata<ConfigRegistryControllerState>;\n\n/**\n * Default fallback configuration when no configs are available.\n */\nconst DEFAULT_FALLBACK_CONFIG: Record<string, RegistryNetworkConfig> = {};\n\n/**\n * Published when the state of {@link ConfigRegistryController} changes.\n */\nexport type ConfigRegistryControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n ConfigRegistryControllerState\n >;\n\n/**\n * Retrieves the state of the {@link ConfigRegistryController}.\n */\nexport type ConfigRegistryControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConfigRegistryControllerState\n>;\n\n/**\n * Starts polling the config registry API. Returns a polling token that can be\n * used to stop this polling session.\n */\nexport type ConfigRegistryControllerStartPollingAction = {\n type: `${typeof controllerName}:startPolling`;\n handler: (input: null) => string;\n};\n\n/**\n * Stops all config registry polling.\n */\nexport type ConfigRegistryControllerStopPollingAction = {\n type: `${typeof controllerName}:stopPolling`;\n handler: () => void;\n};\n\n/**\n * Actions that {@link ConfigRegistryControllerMessenger} exposes to other consumers.\n */\nexport type ConfigRegistryControllerActions =\n | ConfigRegistryControllerGetStateAction\n | ConfigRegistryControllerStartPollingAction\n | ConfigRegistryControllerStopPollingAction;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryControllerMessenger}\n * calls.\n */\ntype AllowedActions =\n | RemoteFeatureFlagControllerGetStateAction\n | {\n type: 'ConfigRegistryApiService:fetchConfig';\n handler: (options?: FetchConfigOptions) => Promise<FetchConfigResult>;\n };\n\n/**\n * Events that {@link ConfigRegistryControllerMessenger} exposes to other consumers.\n */\nexport type ConfigRegistryControllerEvents =\n ConfigRegistryControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConfigRegistryControllerMessenger}\n * subscribes to.\n */\ntype AllowedEvents = KeyringControllerUnlockEvent | KeyringControllerLockEvent;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConfigRegistryController}.\n */\nexport type ConfigRegistryControllerMessenger = Messenger<\n typeof controllerName,\n ConfigRegistryControllerActions | AllowedActions,\n ConfigRegistryControllerEvents | AllowedEvents\n>;\n\n/** @deprecated Use {@link ConfigRegistryControllerMessenger} instead. */\nexport type ConfigRegistryMessenger = ConfigRegistryControllerMessenger;\n\nexport type ConfigRegistryControllerOptions = {\n messenger: ConfigRegistryMessenger;\n state?: Partial<ConfigRegistryControllerState>;\n pollingInterval?: number;\n fallbackConfig?: Record<string, RegistryNetworkConfig>;\n isConfigRegistryApiEnabled?: (messenger: ConfigRegistryMessenger) => boolean;\n};\n\nexport class ConfigRegistryController extends StaticIntervalPollingController<null>()<\n typeof controllerName,\n ConfigRegistryControllerState,\n ConfigRegistryMessenger\n> {\n readonly #isConfigRegistryApiEnabled: (\n messenger: ConfigRegistryMessenger,\n ) => boolean;\n\n /**\n * @param options - The controller options.\n * @param options.messenger - The controller messenger. Must have\n * `ConfigRegistryApiService:fetchConfig` action handler registered.\n * @param options.state - Initial state.\n * @param options.pollingInterval - Polling interval in milliseconds.\n * @param options.fallbackConfig - Fallback configuration.\n * @param options.isConfigRegistryApiEnabled - Function to check if the config\n * registry API is enabled. Defaults to checking the remote feature flag.\n */\n constructor({\n messenger,\n state = {},\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n fallbackConfig = DEFAULT_FALLBACK_CONFIG,\n isConfigRegistryApiEnabled = defaultIsConfigRegistryApiEnabled,\n }: ConfigRegistryControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: {\n configs: {\n networks: state.configs?.networks ?? { ...fallbackConfig },\n },\n version: state.version ?? null,\n lastFetched: state.lastFetched ?? null,\n etag: state.etag ?? null,\n },\n });\n\n this.setIntervalLength(pollingInterval);\n this.#isConfigRegistryApiEnabled = isConfigRegistryApiEnabled;\n\n this.messenger.registerActionHandler(\n `${controllerName}:startPolling`,\n this.startPolling.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:stopPolling`,\n this.stopAllPolling.bind(this),\n );\n\n this.messenger.subscribe('KeyringController:unlock', () =>\n this.startPolling(null),\n );\n\n this.messenger.subscribe('KeyringController:lock', () =>\n this.stopAllPolling(),\n );\n }\n\n async _executePoll(_input: null): Promise<void> {\n const isApiEnabled = this.#isConfigRegistryApiEnabled(this.messenger);\n\n // Skip fetch when API is disabled; client uses static config.\n if (!isApiEnabled) {\n return;\n }\n\n const interval = this.getIntervalLength() ?? DEFAULT_POLLING_INTERVAL;\n if (\n this.state.lastFetched !== null &&\n Date.now() - this.state.lastFetched < interval\n ) {\n return;\n }\n\n try {\n const result: FetchConfigResult = await this.messenger.call(\n 'ConfigRegistryApiService:fetchConfig',\n {\n etag: this.state.etag ?? undefined,\n },\n );\n\n if (!result.modified) {\n this.update((state) => {\n state.lastFetched = Date.now();\n if (result.etag !== undefined) {\n state.etag = result.etag ?? null;\n }\n });\n return;\n }\n\n const apiChains = result.data.data.chains;\n const newConfigs: Record<string, RegistryNetworkConfig> = {};\n // duplicate chainIds from API response are not expected\n apiChains.forEach((chainConfig) => {\n const { chainId } = chainConfig;\n newConfigs[chainId] = chainConfig;\n });\n\n this.update((state) => {\n state.configs.networks = newConfigs;\n state.version = result.data.data.version;\n state.lastFetched = Date.now();\n if (result.etag !== undefined) {\n state.etag = result.etag;\n }\n });\n } catch (error) {\n const errorInstance =\n error instanceof Error ? error : new Error(String(error));\n\n this.messenger.captureException?.(errorInstance);\n }\n }\n}\n"]}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _ConfigRegistryApiService_policy, _ConfigRegistryApiService_url, _ConfigRegistryApiService_fetch, _ConfigRegistryApiService_cachedResponse;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ConfigRegistryApiService = void 0;
16
+ const controller_utils_1 = require("@metamask/controller-utils");
17
+ const profile_sync_controller_1 = require("@metamask/profile-sync-controller");
18
+ const types_1 = require("./types.cjs");
19
+ const ENDPOINT_PATH = '/config/networks';
20
+ /**
21
+ * Returns the base URL for the config registry API for the given environment.
22
+ *
23
+ * @param env - The environment to get the URL for.
24
+ * @returns The base URL for the environment.
25
+ */
26
+ function getConfigRegistryUrl(env) {
27
+ const envPrefix = env === profile_sync_controller_1.SDK.Env.PRD ? '' : `${env}-`;
28
+ return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;
29
+ }
30
+ class ConfigRegistryApiService {
31
+ /**
32
+ * Construct a Config Registry API Service.
33
+ *
34
+ * @param options - The options for constructing the service.
35
+ * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.
36
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
37
+ * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.
38
+ */
39
+ constructor({ env = profile_sync_controller_1.SDK.Env.UAT, fetch: customFetch = globalThis.fetch, policyOptions = {}, } = {}) {
40
+ _ConfigRegistryApiService_policy.set(this, void 0);
41
+ _ConfigRegistryApiService_url.set(this, void 0);
42
+ _ConfigRegistryApiService_fetch.set(this, void 0);
43
+ /** Cached response from the last successful fetch. Used when server returns 304. */
44
+ _ConfigRegistryApiService_cachedResponse.set(this, null);
45
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_url, getConfigRegistryUrl(env), "f");
46
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_fetch, customFetch, "f");
47
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
48
+ }
49
+ /**
50
+ * Registers a handler that will be called after a set number of retry rounds
51
+ * prove that requests to the API endpoint consistently return a 5xx response.
52
+ *
53
+ * @param args - The arguments passed to the underlying policy's onBreak method
54
+ * (e.g. the listener to be called).
55
+ * @returns An object that can be used to unregister the handler. See
56
+ * {@link CockatielEvent}.
57
+ * @see {@link createServicePolicy}
58
+ */
59
+ onBreak(...args) {
60
+ return __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").onBreak(...args);
61
+ }
62
+ /**
63
+ * Registers a handler that will be called under one of two circumstances:
64
+ *
65
+ * 1. After a set number of retries prove that requests to the API
66
+ * consistently result in one of the following failures:
67
+ * 1. A connection initiation error
68
+ * 2. A connection reset error
69
+ * 3. A timeout error
70
+ * 4. A non-JSON response
71
+ * 5. A 502, 503, or 504 response
72
+ * 2. After a successful request is made to the API, but the response takes
73
+ * longer than a set duration to return.
74
+ *
75
+ * @param args - The arguments passed to the underlying policy's onDegraded
76
+ * method (e.g. the listener to be called).
77
+ * @returns An object that can be used to unregister the handler. See
78
+ * {@link CockatielEvent}.
79
+ */
80
+ onDegraded(...args) {
81
+ return __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").onDegraded(...args);
82
+ }
83
+ async fetchConfig(options = {}) {
84
+ const headers = {
85
+ 'Cache-Control': 'no-cache',
86
+ };
87
+ if (options.etag) {
88
+ headers['If-None-Match'] = options.etag;
89
+ }
90
+ const response = await __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").execute(async () => {
91
+ const res = await __classPrivateFieldGet(this, _ConfigRegistryApiService_fetch, "f").call(this, __classPrivateFieldGet(this, _ConfigRegistryApiService_url, "f"), {
92
+ headers,
93
+ });
94
+ if (res.status === 304) {
95
+ return res;
96
+ }
97
+ if (!res.ok) {
98
+ throw new Error(`Failed to fetch config: ${res.status} ${res.statusText}`);
99
+ }
100
+ return res;
101
+ });
102
+ if (response.status === 304) {
103
+ const etag = response.headers.get('ETag') ?? undefined;
104
+ return {
105
+ modified: false,
106
+ etag,
107
+ ...(__classPrivateFieldGet(this, _ConfigRegistryApiService_cachedResponse, "f") !== null && { data: __classPrivateFieldGet(this, _ConfigRegistryApiService_cachedResponse, "f") }),
108
+ };
109
+ }
110
+ const etag = response.headers.get('ETag') ?? undefined;
111
+ const jsonData = await response.json();
112
+ (0, types_1.validateRegistryConfigApiResponse)(jsonData);
113
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_cachedResponse, jsonData, "f");
114
+ return {
115
+ data: jsonData,
116
+ etag,
117
+ modified: true,
118
+ };
119
+ }
120
+ }
121
+ exports.ConfigRegistryApiService = ConfigRegistryApiService;
122
+ _ConfigRegistryApiService_policy = new WeakMap(), _ConfigRegistryApiService_url = new WeakMap(), _ConfigRegistryApiService_fetch = new WeakMap(), _ConfigRegistryApiService_cachedResponse = new WeakMap();
123
+ //# sourceMappingURL=config-registry-api-service.cjs.map
@@ -0,0 +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,iEAAiE;AAKjE,+EAAwD;AAOxD,uCAA4D;AAE5D,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,GAAY;IACxC,MAAM,SAAS,GAAG,GAAG,KAAK,6BAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;IACvD,OAAO,yBAAyB,SAAS,wBAAwB,aAAa,EAAE,CAAC;AACnF,CAAC;AAYD,MAAa,wBAAwB;IAUnC;;;;;;;OAOG;IACH,YAAY,EACV,GAAG,GAAG,6BAAG,CAAC,GAAG,CAAC,GAAG,EACjB,KAAK,EAAE,WAAW,GAAG,UAAU,CAAC,KAAK,EACrC,aAAa,GAAG,EAAE,MACiB,EAAE;QArB9B,mDAAuB;QAEvB,gDAAa;QAEb,kDAAqB;QAE9B,oFAAoF;QACpF,mDAAoD,IAAI,EAAC;QAevD,uBAAA,IAAI,iCAAQ,oBAAoB,CAAC,GAAG,CAAC,MAAA,CAAC;QACtC,uBAAA,IAAI,mCAAU,WAAW,MAAA,CAAC;QAE1B,uBAAA,IAAI,oCAAW,IAAA,sCAAmB,EAAC,aAAa,CAAC,MAAA,CAAC;IACpD,CAAC;IAED;;;;;;;;;OASG;IACH,OAAO,CACL,GAAG,IAA0C;QAE7C,OAAO,uBAAA,IAAI,wCAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,UAAU,CACR,GAAG,IAA6C;QAEhD,OAAO,uBAAA,IAAI,wCAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1C,CA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yCAAiC,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;AAxHD,4DAwHC","sourcesContent":["import { createServicePolicy } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { SDK } from '@metamask/profile-sync-controller';\n\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './types';\nimport { validateRegistryConfigApiResponse } from './types';\n\nconst ENDPOINT_PATH = '/config/networks';\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 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 #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.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 env = SDK.Env.UAT,\n fetch: customFetch = globalThis.fetch,\n policyOptions = {},\n }: ConfigRegistryApiServiceOptions = {}) {\n this.#url = getConfigRegistryUrl(env);\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy(policyOptions);\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 Error(\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"]}
@@ -0,0 +1,56 @@
1
+ import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
2
+ import { SDK } from "@metamask/profile-sync-controller";
3
+ import type { FetchConfigOptions, FetchConfigResult } from "./types.cjs";
4
+ export type ConfigRegistryApiServiceOptions = {
5
+ env?: SDK.Env;
6
+ fetch?: typeof fetch;
7
+ /**
8
+ * Options to pass to `createServicePolicy`, which wraps each request.
9
+ * See {@link CreateServicePolicyOptions}.
10
+ */
11
+ policyOptions?: CreateServicePolicyOptions;
12
+ };
13
+ export declare class ConfigRegistryApiService {
14
+ #private;
15
+ /**
16
+ * Construct a Config Registry API Service.
17
+ *
18
+ * @param options - The options for constructing the service.
19
+ * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.
20
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
21
+ * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.
22
+ */
23
+ constructor({ env, fetch: customFetch, policyOptions, }?: ConfigRegistryApiServiceOptions);
24
+ /**
25
+ * Registers a handler that will be called after a set number of retry rounds
26
+ * prove that requests to the API endpoint consistently return a 5xx response.
27
+ *
28
+ * @param args - The arguments passed to the underlying policy's onBreak method
29
+ * (e.g. the listener to be called).
30
+ * @returns An object that can be used to unregister the handler. See
31
+ * {@link CockatielEvent}.
32
+ * @see {@link createServicePolicy}
33
+ */
34
+ onBreak(...args: Parameters<ServicePolicy['onBreak']>): ReturnType<ServicePolicy['onBreak']>;
35
+ /**
36
+ * Registers a handler that will be called under one of two circumstances:
37
+ *
38
+ * 1. After a set number of retries prove that requests to the API
39
+ * consistently result in one of the following failures:
40
+ * 1. A connection initiation error
41
+ * 2. A connection reset error
42
+ * 3. A timeout error
43
+ * 4. A non-JSON response
44
+ * 5. A 502, 503, or 504 response
45
+ * 2. After a successful request is made to the API, but the response takes
46
+ * longer than a set duration to return.
47
+ *
48
+ * @param args - The arguments passed to the underlying policy's onDegraded
49
+ * method (e.g. the listener to be called).
50
+ * @returns An object that can be used to unregister the handler. See
51
+ * {@link CockatielEvent}.
52
+ */
53
+ onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): ReturnType<ServicePolicy['onDegraded']>;
54
+ fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;
55
+ }
56
+ //# sourceMappingURL=config-registry-api-service.d.cts.map
@@ -0,0 +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":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AACpC,OAAO,EAAE,GAAG,EAAE,0CAA0C;AAExD,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAElB,oBAAgB;AAgBjB,MAAM,MAAM,+BAA+B,GAAG;IAC5C,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;;IAUnC;;;;;;;OAOG;gBACS,EACV,GAAiB,EACjB,KAAK,EAAE,WAA8B,EACrC,aAAkB,GACnB,GAAE,+BAAoC;IAOvC;;;;;;;;;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;CAiD9B"}
@@ -0,0 +1,56 @@
1
+ import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
2
+ import { SDK } from "@metamask/profile-sync-controller";
3
+ import type { FetchConfigOptions, FetchConfigResult } from "./types.mjs";
4
+ export type ConfigRegistryApiServiceOptions = {
5
+ env?: SDK.Env;
6
+ fetch?: typeof fetch;
7
+ /**
8
+ * Options to pass to `createServicePolicy`, which wraps each request.
9
+ * See {@link CreateServicePolicyOptions}.
10
+ */
11
+ policyOptions?: CreateServicePolicyOptions;
12
+ };
13
+ export declare class ConfigRegistryApiService {
14
+ #private;
15
+ /**
16
+ * Construct a Config Registry API Service.
17
+ *
18
+ * @param options - The options for constructing the service.
19
+ * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.
20
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
21
+ * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.
22
+ */
23
+ constructor({ env, fetch: customFetch, policyOptions, }?: ConfigRegistryApiServiceOptions);
24
+ /**
25
+ * Registers a handler that will be called after a set number of retry rounds
26
+ * prove that requests to the API endpoint consistently return a 5xx response.
27
+ *
28
+ * @param args - The arguments passed to the underlying policy's onBreak method
29
+ * (e.g. the listener to be called).
30
+ * @returns An object that can be used to unregister the handler. See
31
+ * {@link CockatielEvent}.
32
+ * @see {@link createServicePolicy}
33
+ */
34
+ onBreak(...args: Parameters<ServicePolicy['onBreak']>): ReturnType<ServicePolicy['onBreak']>;
35
+ /**
36
+ * Registers a handler that will be called under one of two circumstances:
37
+ *
38
+ * 1. After a set number of retries prove that requests to the API
39
+ * consistently result in one of the following failures:
40
+ * 1. A connection initiation error
41
+ * 2. A connection reset error
42
+ * 3. A timeout error
43
+ * 4. A non-JSON response
44
+ * 5. A 502, 503, or 504 response
45
+ * 2. After a successful request is made to the API, but the response takes
46
+ * longer than a set duration to return.
47
+ *
48
+ * @param args - The arguments passed to the underlying policy's onDegraded
49
+ * method (e.g. the listener to be called).
50
+ * @returns An object that can be used to unregister the handler. See
51
+ * {@link CockatielEvent}.
52
+ */
53
+ onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): ReturnType<ServicePolicy['onDegraded']>;
54
+ fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;
55
+ }
56
+ //# sourceMappingURL=config-registry-api-service.d.mts.map
@@ -0,0 +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,EAAE,GAAG,EAAE,0CAA0C;AAExD,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAElB,oBAAgB;AAgBjB,MAAM,MAAM,+BAA+B,GAAG;IAC5C,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;;IAUnC;;;;;;;OAOG;gBACS,EACV,GAAiB,EACjB,KAAK,EAAE,WAA8B,EACrC,aAAkB,GACnB,GAAE,+BAAoC;IAOvC;;;;;;;;;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;CAiD9B"}
@@ -0,0 +1,119 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _ConfigRegistryApiService_policy, _ConfigRegistryApiService_url, _ConfigRegistryApiService_fetch, _ConfigRegistryApiService_cachedResponse;
13
+ import { createServicePolicy } from "@metamask/controller-utils";
14
+ import { SDK } from "@metamask/profile-sync-controller";
15
+ import { validateRegistryConfigApiResponse } from "./types.mjs";
16
+ const ENDPOINT_PATH = '/config/networks';
17
+ /**
18
+ * Returns the base URL for the config registry API for the given environment.
19
+ *
20
+ * @param env - The environment to get the URL for.
21
+ * @returns The base URL for the environment.
22
+ */
23
+ function getConfigRegistryUrl(env) {
24
+ const envPrefix = env === SDK.Env.PRD ? '' : `${env}-`;
25
+ return `https://client-config.${envPrefix}api.cx.metamask.io/v1${ENDPOINT_PATH}`;
26
+ }
27
+ export class ConfigRegistryApiService {
28
+ /**
29
+ * Construct a Config Registry API Service.
30
+ *
31
+ * @param options - The options for constructing the service.
32
+ * @param options.env - The environment to determine the correct API endpoints. Defaults to UAT.
33
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
34
+ * @param options.policyOptions - Options to pass to `createServicePolicy`, which wraps each request. See {@link CreateServicePolicyOptions}.
35
+ */
36
+ constructor({ env = SDK.Env.UAT, fetch: customFetch = globalThis.fetch, policyOptions = {}, } = {}) {
37
+ _ConfigRegistryApiService_policy.set(this, void 0);
38
+ _ConfigRegistryApiService_url.set(this, void 0);
39
+ _ConfigRegistryApiService_fetch.set(this, void 0);
40
+ /** Cached response from the last successful fetch. Used when server returns 304. */
41
+ _ConfigRegistryApiService_cachedResponse.set(this, null);
42
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_url, getConfigRegistryUrl(env), "f");
43
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_fetch, customFetch, "f");
44
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_policy, createServicePolicy(policyOptions), "f");
45
+ }
46
+ /**
47
+ * Registers a handler that will be called after a set number of retry rounds
48
+ * prove that requests to the API endpoint consistently return a 5xx response.
49
+ *
50
+ * @param args - The arguments passed to the underlying policy's onBreak method
51
+ * (e.g. the listener to be called).
52
+ * @returns An object that can be used to unregister the handler. See
53
+ * {@link CockatielEvent}.
54
+ * @see {@link createServicePolicy}
55
+ */
56
+ onBreak(...args) {
57
+ return __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").onBreak(...args);
58
+ }
59
+ /**
60
+ * Registers a handler that will be called under one of two circumstances:
61
+ *
62
+ * 1. After a set number of retries prove that requests to the API
63
+ * consistently result in one of the following failures:
64
+ * 1. A connection initiation error
65
+ * 2. A connection reset error
66
+ * 3. A timeout error
67
+ * 4. A non-JSON response
68
+ * 5. A 502, 503, or 504 response
69
+ * 2. After a successful request is made to the API, but the response takes
70
+ * longer than a set duration to return.
71
+ *
72
+ * @param args - The arguments passed to the underlying policy's onDegraded
73
+ * method (e.g. the listener to be called).
74
+ * @returns An object that can be used to unregister the handler. See
75
+ * {@link CockatielEvent}.
76
+ */
77
+ onDegraded(...args) {
78
+ return __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").onDegraded(...args);
79
+ }
80
+ async fetchConfig(options = {}) {
81
+ const headers = {
82
+ 'Cache-Control': 'no-cache',
83
+ };
84
+ if (options.etag) {
85
+ headers['If-None-Match'] = options.etag;
86
+ }
87
+ const response = await __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").execute(async () => {
88
+ const res = await __classPrivateFieldGet(this, _ConfigRegistryApiService_fetch, "f").call(this, __classPrivateFieldGet(this, _ConfigRegistryApiService_url, "f"), {
89
+ headers,
90
+ });
91
+ if (res.status === 304) {
92
+ return res;
93
+ }
94
+ if (!res.ok) {
95
+ throw new Error(`Failed to fetch config: ${res.status} ${res.statusText}`);
96
+ }
97
+ return res;
98
+ });
99
+ if (response.status === 304) {
100
+ const etag = response.headers.get('ETag') ?? undefined;
101
+ return {
102
+ modified: false,
103
+ etag,
104
+ ...(__classPrivateFieldGet(this, _ConfigRegistryApiService_cachedResponse, "f") !== null && { data: __classPrivateFieldGet(this, _ConfigRegistryApiService_cachedResponse, "f") }),
105
+ };
106
+ }
107
+ const etag = response.headers.get('ETag') ?? undefined;
108
+ const jsonData = await response.json();
109
+ validateRegistryConfigApiResponse(jsonData);
110
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_cachedResponse, jsonData, "f");
111
+ return {
112
+ data: jsonData,
113
+ etag,
114
+ modified: true,
115
+ };
116
+ }
117
+ }
118
+ _ConfigRegistryApiService_policy = new WeakMap(), _ConfigRegistryApiService_url = new WeakMap(), _ConfigRegistryApiService_fetch = new WeakMap(), _ConfigRegistryApiService_cachedResponse = new WeakMap();
119
+ //# sourceMappingURL=config-registry-api-service.mjs.map
@@ -0,0 +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,mCAAmC;AAKjE,OAAO,EAAE,GAAG,EAAE,0CAA0C;AAOxD,OAAO,EAAE,iCAAiC,EAAE,o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ServicePolicy } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { SDK } from '@metamask/profile-sync-controller';\n\nimport type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './types';\nimport { validateRegistryConfigApiResponse } from './types';\n\nconst ENDPOINT_PATH = '/config/networks';\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 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 #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.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 env = SDK.Env.UAT,\n fetch: customFetch = globalThis.fetch,\n policyOptions = {},\n }: ConfigRegistryApiServiceOptions = {}) {\n this.#url = getConfigRegistryUrl(env);\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy(policyOptions);\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 Error(\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"]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterNetworks = void 0;
4
+ const FILTER_KEYS = [
5
+ 'isFeatured',
6
+ 'isTestnet',
7
+ 'isActive',
8
+ 'isDeprecated',
9
+ 'isDefault',
10
+ ];
11
+ /**
12
+ * @param networks - Array of chain configurations to filter.
13
+ * @param options - Filter options (matched against config.*).
14
+ * @returns Filtered array of chain configurations.
15
+ */
16
+ function filterNetworks(networks, options = {}) {
17
+ return networks.filter((network) => {
18
+ const { config } = network;
19
+ for (const key of FILTER_KEYS) {
20
+ const optionValue = options[key];
21
+ if (optionValue !== undefined &&
22
+ config[key] !== optionValue) {
23
+ return false;
24
+ }
25
+ }
26
+ return true;
27
+ });
28
+ }
29
+ exports.filterNetworks = filterNetworks;
30
+ //# sourceMappingURL=filters.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.cjs","sourceRoot":"","sources":["../../src/config-registry-api-service/filters.ts"],"names":[],"mappings":";;;AAUA,MAAM,WAAW,GAAmC;IAClD,YAAY;IACZ,WAAW;IACX,UAAU;IACV,cAAc;IACd,WAAW;CACZ,CAAC;AAEF;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,QAAiC,EACjC,UAAgC,EAAE;IAElC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QACjC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YACjC,IACE,WAAW,KAAK,SAAS;gBACzB,MAAM,CAAC,GAA0B,CAAC,KAAK,WAAW,EAClD,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAjBD,wCAiBC","sourcesContent":["import type { RegistryNetworkConfig } from './types';\n\nexport type NetworkFilterOptions = {\n isFeatured?: boolean;\n isTestnet?: boolean;\n isActive?: boolean;\n isDeprecated?: boolean;\n isDefault?: boolean;\n};\n\nconst FILTER_KEYS: (keyof NetworkFilterOptions)[] = [\n 'isFeatured',\n 'isTestnet',\n 'isActive',\n 'isDeprecated',\n 'isDefault',\n];\n\n/**\n * @param networks - Array of chain configurations to filter.\n * @param options - Filter options (matched against config.*).\n * @returns Filtered array of chain configurations.\n */\nexport function filterNetworks(\n networks: RegistryNetworkConfig[],\n options: NetworkFilterOptions = {},\n): RegistryNetworkConfig[] {\n return networks.filter((network) => {\n const { config } = network;\n for (const key of FILTER_KEYS) {\n const optionValue = options[key];\n if (\n optionValue !== undefined &&\n config[key as keyof typeof config] !== optionValue\n ) {\n return false;\n }\n }\n return true;\n });\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { RegistryNetworkConfig } from "./types.cjs";
2
+ export type NetworkFilterOptions = {
3
+ isFeatured?: boolean;
4
+ isTestnet?: boolean;
5
+ isActive?: boolean;
6
+ isDeprecated?: boolean;
7
+ isDefault?: boolean;
8
+ };
9
+ /**
10
+ * @param networks - Array of chain configurations to filter.
11
+ * @param options - Filter options (matched against config.*).
12
+ * @returns Filtered array of chain configurations.
13
+ */
14
+ export declare function filterNetworks(networks: RegistryNetworkConfig[], options?: NetworkFilterOptions): RegistryNetworkConfig[];
15
+ //# sourceMappingURL=filters.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.d.cts","sourceRoot":"","sources":["../../src/config-registry-api-service/filters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAUF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,qBAAqB,EAAE,EACjC,OAAO,GAAE,oBAAyB,GACjC,qBAAqB,EAAE,CAczB"}
@@ -0,0 +1,15 @@
1
+ import type { RegistryNetworkConfig } from "./types.mjs";
2
+ export type NetworkFilterOptions = {
3
+ isFeatured?: boolean;
4
+ isTestnet?: boolean;
5
+ isActive?: boolean;
6
+ isDeprecated?: boolean;
7
+ isDefault?: boolean;
8
+ };
9
+ /**
10
+ * @param networks - Array of chain configurations to filter.
11
+ * @param options - Filter options (matched against config.*).
12
+ * @returns Filtered array of chain configurations.
13
+ */
14
+ export declare function filterNetworks(networks: RegistryNetworkConfig[], options?: NetworkFilterOptions): RegistryNetworkConfig[];
15
+ //# sourceMappingURL=filters.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.d.mts","sourceRoot":"","sources":["../../src/config-registry-api-service/filters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAUF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,qBAAqB,EAAE,EACjC,OAAO,GAAE,oBAAyB,GACjC,qBAAqB,EAAE,CAczB"}
@@ -0,0 +1,26 @@
1
+ const FILTER_KEYS = [
2
+ 'isFeatured',
3
+ 'isTestnet',
4
+ 'isActive',
5
+ 'isDeprecated',
6
+ 'isDefault',
7
+ ];
8
+ /**
9
+ * @param networks - Array of chain configurations to filter.
10
+ * @param options - Filter options (matched against config.*).
11
+ * @returns Filtered array of chain configurations.
12
+ */
13
+ export function filterNetworks(networks, options = {}) {
14
+ return networks.filter((network) => {
15
+ const { config } = network;
16
+ for (const key of FILTER_KEYS) {
17
+ const optionValue = options[key];
18
+ if (optionValue !== undefined &&
19
+ config[key] !== optionValue) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ });
25
+ }
26
+ //# sourceMappingURL=filters.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.mjs","sourceRoot":"","sources":["../../src/config-registry-api-service/filters.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,GAAmC;IAClD,YAAY;IACZ,WAAW;IACX,UAAU;IACV,cAAc;IACd,WAAW;CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAiC,EACjC,UAAgC,EAAE;IAElC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QACjC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YACjC,IACE,WAAW,KAAK,SAAS;gBACzB,MAAM,CAAC,GAA0B,CAAC,KAAK,WAAW,EAClD,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { RegistryNetworkConfig } from './types';\n\nexport type NetworkFilterOptions = {\n isFeatured?: boolean;\n isTestnet?: boolean;\n isActive?: boolean;\n isDeprecated?: boolean;\n isDefault?: boolean;\n};\n\nconst FILTER_KEYS: (keyof NetworkFilterOptions)[] = [\n 'isFeatured',\n 'isTestnet',\n 'isActive',\n 'isDeprecated',\n 'isDefault',\n];\n\n/**\n * @param networks - Array of chain configurations to filter.\n * @param options - Filter options (matched against config.*).\n * @returns Filtered array of chain configurations.\n */\nexport function filterNetworks(\n networks: RegistryNetworkConfig[],\n options: NetworkFilterOptions = {},\n): RegistryNetworkConfig[] {\n return networks.filter((network) => {\n const { config } = network;\n for (const key of FILTER_KEYS) {\n const optionValue = options[key];\n if (\n optionValue !== undefined &&\n config[key as keyof typeof config] !== optionValue\n ) {\n return false;\n }\n }\n return true;\n });\n}\n"]}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterNetworks = exports.ConfigRegistryApiService = void 0;
4
+ var config_registry_api_service_1 = require("./config-registry-api-service.cjs");
5
+ Object.defineProperty(exports, "ConfigRegistryApiService", { enumerable: true, get: function () { return config_registry_api_service_1.ConfigRegistryApiService; } });
6
+ var filters_1 = require("./filters.cjs");
7
+ Object.defineProperty(exports, "filterNetworks", { enumerable: true, get: function () { return filters_1.filterNetworks; } });
8
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/config-registry-api-service/index.ts"],"names":[],"mappings":";;;AAOA,iFAAyE;AAAhE,uIAAA,wBAAwB,OAAA;AAKjC,yCAA2C;AAAlC,yGAAA,cAAc,OAAA","sourcesContent":["export type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryNetworkConfig,\n RegistryConfigApiResponse,\n} from './types';\n\nexport { ConfigRegistryApiService } from './config-registry-api-service';\n\nexport type { ConfigRegistryApiServiceOptions } from './config-registry-api-service';\n\nexport type { NetworkFilterOptions } from './filters';\nexport { filterNetworks } from './filters';\n"]}
@@ -0,0 +1,6 @@
1
+ export type { FetchConfigOptions, FetchConfigResult, RegistryNetworkConfig, RegistryConfigApiResponse, } from "./types.cjs";
2
+ export { ConfigRegistryApiService } from "./config-registry-api-service.cjs";
3
+ export type { ConfigRegistryApiServiceOptions } from "./config-registry-api-service.cjs";
4
+ export type { NetworkFilterOptions } from "./filters.cjs";
5
+ export { filterNetworks } from "./filters.cjs";
6
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/config-registry-api-service/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,GAC1B,oBAAgB;AAEjB,OAAO,EAAE,wBAAwB,EAAE,0CAAsC;AAEzE,YAAY,EAAE,+BAA+B,EAAE,0CAAsC;AAErF,YAAY,EAAE,oBAAoB,EAAE,sBAAkB;AACtD,OAAO,EAAE,cAAc,EAAE,sBAAkB"}
@@ -0,0 +1,6 @@
1
+ export type { FetchConfigOptions, FetchConfigResult, RegistryNetworkConfig, RegistryConfigApiResponse, } from "./types.mjs";
2
+ export { ConfigRegistryApiService } from "./config-registry-api-service.mjs";
3
+ export type { ConfigRegistryApiServiceOptions } from "./config-registry-api-service.mjs";
4
+ export type { NetworkFilterOptions } from "./filters.mjs";
5
+ export { filterNetworks } from "./filters.mjs";
6
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/config-registry-api-service/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,GAC1B,oBAAgB;AAEjB,OAAO,EAAE,wBAAwB,EAAE,0CAAsC;AAEzE,YAAY,EAAE,+BAA+B,EAAE,0CAAsC;AAErF,YAAY,EAAE,oBAAoB,EAAE,sBAAkB;AACtD,OAAO,EAAE,cAAc,EAAE,sBAAkB"}
@@ -0,0 +1,3 @@
1
+ export { ConfigRegistryApiService } from "./config-registry-api-service.mjs";
2
+ export { filterNetworks } from "./filters.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/config-registry-api-service/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,0CAAsC;AAKzE,OAAO,EAAE,cAAc,EAAE,sBAAkB","sourcesContent":["export type {\n FetchConfigOptions,\n FetchConfigResult,\n RegistryNetworkConfig,\n RegistryConfigApiResponse,\n} from './types';\n\nexport { ConfigRegistryApiService } from './config-registry-api-service';\n\nexport type { ConfigRegistryApiServiceOptions } from './config-registry-api-service';\n\nexport type { NetworkFilterOptions } from './filters';\nexport { filterNetworks } from './filters';\n"]}