@metamask-previews/config-registry-controller 0.0.1-preview-ab102d86

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 (60) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/ConfigRegistryController.cjs +205 -0
  5. package/dist/ConfigRegistryController.cjs.map +1 -0
  6. package/dist/ConfigRegistryController.d.cts +95 -0
  7. package/dist/ConfigRegistryController.d.cts.map +1 -0
  8. package/dist/ConfigRegistryController.d.mts +95 -0
  9. package/dist/ConfigRegistryController.d.mts.map +1 -0
  10. package/dist/ConfigRegistryController.mjs +201 -0
  11. package/dist/ConfigRegistryController.mjs.map +1 -0
  12. package/dist/config-registry-api-service/abstract-config-registry-api-service.cjs +3 -0
  13. package/dist/config-registry-api-service/abstract-config-registry-api-service.cjs.map +1 -0
  14. package/dist/config-registry-api-service/abstract-config-registry-api-service.d.cts +47 -0
  15. package/dist/config-registry-api-service/abstract-config-registry-api-service.d.cts.map +1 -0
  16. package/dist/config-registry-api-service/abstract-config-registry-api-service.d.mts +47 -0
  17. package/dist/config-registry-api-service/abstract-config-registry-api-service.d.mts.map +1 -0
  18. package/dist/config-registry-api-service/abstract-config-registry-api-service.mjs +2 -0
  19. package/dist/config-registry-api-service/abstract-config-registry-api-service.mjs.map +1 -0
  20. package/dist/config-registry-api-service/config-registry-api-service.cjs +124 -0
  21. package/dist/config-registry-api-service/config-registry-api-service.cjs.map +1 -0
  22. package/dist/config-registry-api-service/config-registry-api-service.d.cts +36 -0
  23. package/dist/config-registry-api-service/config-registry-api-service.d.cts.map +1 -0
  24. package/dist/config-registry-api-service/config-registry-api-service.d.mts +36 -0
  25. package/dist/config-registry-api-service/config-registry-api-service.d.mts.map +1 -0
  26. package/dist/config-registry-api-service/config-registry-api-service.mjs +120 -0
  27. package/dist/config-registry-api-service/config-registry-api-service.mjs.map +1 -0
  28. package/dist/config-registry-api-service/index.cjs +14 -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/transformers.cjs +254 -0
  37. package/dist/config-registry-api-service/transformers.cjs.map +1 -0
  38. package/dist/config-registry-api-service/transformers.d.cts +42 -0
  39. package/dist/config-registry-api-service/transformers.d.cts.map +1 -0
  40. package/dist/config-registry-api-service/transformers.d.mts +42 -0
  41. package/dist/config-registry-api-service/transformers.d.mts.map +1 -0
  42. package/dist/config-registry-api-service/transformers.mjs +247 -0
  43. package/dist/config-registry-api-service/transformers.mjs.map +1 -0
  44. package/dist/index.cjs +18 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +6 -0
  47. package/dist/index.d.cts.map +1 -0
  48. package/dist/index.d.mts +6 -0
  49. package/dist/index.d.mts.map +1 -0
  50. package/dist/index.mjs +4 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/dist/utils/feature-flags.cjs +27 -0
  53. package/dist/utils/feature-flags.cjs.map +1 -0
  54. package/dist/utils/feature-flags.d.cts +9 -0
  55. package/dist/utils/feature-flags.d.cts.map +1 -0
  56. package/dist/utils/feature-flags.d.mts +9 -0
  57. package/dist/utils/feature-flags.d.mts.map +1 -0
  58. package/dist/utils/feature-flags.mjs +23 -0
  59. package/dist/utils/feature-flags.mjs.map +1 -0
  60. package/package.json +79 -0
@@ -0,0 +1,201 @@
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 _ConfigRegistryController_instances, _ConfigRegistryController_fallbackConfig, _ConfigRegistryController_apiService, _ConfigRegistryController_useFallbackConfig, _ConfigRegistryController_handleFetchError;
13
+ import { StaticIntervalPollingController } from "@metamask/polling-controller";
14
+ import { ConfigRegistryApiService, filterNetworks } from "./config-registry-api-service/index.mjs";
15
+ import { isConfigRegistryApiEnabled } from "./utils/feature-flags.mjs";
16
+ const controllerName = 'ConfigRegistryController';
17
+ export const DEFAULT_POLLING_INTERVAL = 24 * 60 * 60 * 1000;
18
+ const stateMetadata = {
19
+ configs: {
20
+ persist: true,
21
+ anonymous: false,
22
+ includeInStateLogs: false,
23
+ includeInDebugSnapshot: true,
24
+ usedInUi: true,
25
+ },
26
+ version: {
27
+ persist: true,
28
+ anonymous: false,
29
+ includeInStateLogs: true,
30
+ includeInDebugSnapshot: true,
31
+ usedInUi: false,
32
+ },
33
+ lastFetched: {
34
+ persist: true,
35
+ anonymous: false,
36
+ includeInStateLogs: true,
37
+ includeInDebugSnapshot: true,
38
+ usedInUi: false,
39
+ },
40
+ fetchError: {
41
+ persist: true,
42
+ anonymous: false,
43
+ includeInStateLogs: true,
44
+ includeInDebugSnapshot: true,
45
+ usedInUi: false,
46
+ },
47
+ etag: {
48
+ persist: true,
49
+ anonymous: false,
50
+ includeInStateLogs: false,
51
+ includeInDebugSnapshot: false,
52
+ usedInUi: false,
53
+ },
54
+ };
55
+ const DEFAULT_FALLBACK_CONFIG = {};
56
+ export class ConfigRegistryController extends StaticIntervalPollingController() {
57
+ /**
58
+ * @param options - The controller options.
59
+ * @param options.messenger - The controller messenger.
60
+ * @param options.state - Initial state.
61
+ * @param options.pollingInterval - Polling interval in milliseconds.
62
+ * @param options.fallbackConfig - Fallback configuration.
63
+ * @param options.apiService - The API service.
64
+ */
65
+ constructor({ messenger, state = {}, pollingInterval = DEFAULT_POLLING_INTERVAL, fallbackConfig = DEFAULT_FALLBACK_CONFIG, apiService = new ConfigRegistryApiService(), }) {
66
+ super({
67
+ name: controllerName,
68
+ metadata: stateMetadata,
69
+ messenger,
70
+ state: {
71
+ configs: { networks: {} },
72
+ version: null,
73
+ lastFetched: null,
74
+ fetchError: null,
75
+ etag: null,
76
+ ...state,
77
+ },
78
+ });
79
+ _ConfigRegistryController_instances.add(this);
80
+ _ConfigRegistryController_fallbackConfig.set(this, void 0);
81
+ _ConfigRegistryController_apiService.set(this, void 0);
82
+ this.setIntervalLength(pollingInterval);
83
+ __classPrivateFieldSet(this, _ConfigRegistryController_fallbackConfig, fallbackConfig, "f");
84
+ __classPrivateFieldSet(this, _ConfigRegistryController_apiService, apiService, "f");
85
+ this.messenger.registerActionHandler(`${controllerName}:getConfig`, (key) => this.getConfig(key));
86
+ this.messenger.registerActionHandler(`${controllerName}:setConfig`, (key, value, metadata) => this.setConfig(key, value, metadata));
87
+ this.messenger.registerActionHandler(`${controllerName}:getAllConfigs`, () => this.getAllConfigs());
88
+ this.messenger.registerActionHandler(`${controllerName}:startPolling`, (input) => this.startPolling(input));
89
+ this.messenger.registerActionHandler(`${controllerName}:stopPolling`, () => this.stopPolling());
90
+ }
91
+ async _executePoll(_input) {
92
+ const isApiEnabled = isConfigRegistryApiEnabled(this.messenger);
93
+ if (!isApiEnabled) {
94
+ __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_useFallbackConfig).call(this, 'Feature flag disabled - using fallback configuration');
95
+ return;
96
+ }
97
+ try {
98
+ const result = await __classPrivateFieldGet(this, _ConfigRegistryController_apiService, "f").fetchConfig({
99
+ etag: this.state.etag ?? undefined,
100
+ });
101
+ if (result.notModified) {
102
+ this.update((state) => {
103
+ state.fetchError = null;
104
+ });
105
+ return;
106
+ }
107
+ // Filter networks: only featured, active, non-testnet networks
108
+ const filteredNetworks = filterNetworks(result.data.data.networks, {
109
+ isFeatured: true,
110
+ isActive: true,
111
+ isTestnet: false,
112
+ });
113
+ const newConfigs = {};
114
+ for (const network of filteredNetworks) {
115
+ newConfigs[network.chainId] = {
116
+ key: network.chainId,
117
+ value: network,
118
+ };
119
+ }
120
+ this.update((state) => {
121
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
+ state.configs = { networks: newConfigs };
123
+ state.version = result.data.data.version;
124
+ state.lastFetched = Date.now();
125
+ state.fetchError = null;
126
+ state.etag = result.etag ?? null;
127
+ });
128
+ }
129
+ catch (error) {
130
+ __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_handleFetchError).call(this, error);
131
+ }
132
+ }
133
+ getConfig(key) {
134
+ return this.state.configs?.networks?.[key];
135
+ }
136
+ getAllConfigs() {
137
+ return { ...(this.state.configs?.networks ?? {}) };
138
+ }
139
+ getConfigValue(key) {
140
+ const entry = this.state.configs?.networks?.[key];
141
+ return entry?.value;
142
+ }
143
+ setConfig(key, value, metadata) {
144
+ this.update((state) => {
145
+ if (!state.configs) {
146
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
+ state.configs = { networks: {} };
148
+ }
149
+ if (!state.configs.networks) {
150
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
+ state.configs.networks = {};
152
+ }
153
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
+ state.configs.networks[key] = {
155
+ key,
156
+ value,
157
+ metadata,
158
+ };
159
+ });
160
+ }
161
+ removeConfig(key) {
162
+ this.update((state) => {
163
+ if (state.configs?.networks) {
164
+ delete state.configs.networks[key];
165
+ }
166
+ });
167
+ }
168
+ clearConfigs() {
169
+ this.update((state) => {
170
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
+ state.configs = { networks: {} };
172
+ });
173
+ }
174
+ startPolling(input = {}) {
175
+ return super.startPolling(input);
176
+ }
177
+ stopPolling() {
178
+ super.stopAllPolling();
179
+ }
180
+ }
181
+ _ConfigRegistryController_fallbackConfig = new WeakMap(), _ConfigRegistryController_apiService = new WeakMap(), _ConfigRegistryController_instances = new WeakSet(), _ConfigRegistryController_useFallbackConfig = function _ConfigRegistryController_useFallbackConfig(errorMessage) {
182
+ this.update((state) => {
183
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
184
+ state.configs = { networks: { ...__classPrivateFieldGet(this, _ConfigRegistryController_fallbackConfig, "f") } };
185
+ state.fetchError =
186
+ errorMessage ?? 'Using fallback configuration - API unavailable';
187
+ state.etag = null;
188
+ });
189
+ }, _ConfigRegistryController_handleFetchError = function _ConfigRegistryController_handleFetchError(error) {
190
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
191
+ const hasNoConfigs = Object.keys(this.state.configs?.networks ?? {}).length === 0;
192
+ if (hasNoConfigs) {
193
+ __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_useFallbackConfig).call(this, errorMessage);
194
+ }
195
+ else {
196
+ this.update((state) => {
197
+ state.fetchError = errorMessage;
198
+ });
199
+ }
200
+ };
201
+ //# sourceMappingURL=ConfigRegistryController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController.mjs","sourceRoot":"","sources":["../src/ConfigRegistryController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAQ/E,OAAO,EACL,wBAAwB,EACxB,cAAc,EACf,gDAAsC;AACvC,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AAEnE,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,MAAM,CAAC,MAAM,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AC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,UAAU,GAAG,YAAY,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\nimport type { Json } from '@metamask/utils';\n\nimport type {\n AbstractConfigRegistryApiService,\n FetchConfigResult,\n} from './config-registry-api-service';\nimport {\n ConfigRegistryApiService,\n filterNetworks,\n} from './config-registry-api-service';\nimport { isConfigRegistryApiEnabled } from './utils/feature-flags';\n\nconst controllerName = 'ConfigRegistryController';\n\nexport const DEFAULT_POLLING_INTERVAL = 24 * 60 * 60 * 1000;\n\nexport type RegistryConfigEntry = {\n key: string;\n value: Json;\n metadata?: Json;\n};\n\nexport type ConfigRegistryState = {\n configs: {\n networks?: Record<string, RegistryConfigEntry>;\n };\n version: string | null;\n lastFetched: number | null;\n fetchError: string | null;\n etag: string | null;\n};\n\nconst stateMetadata = {\n configs: {\n persist: true,\n anonymous: false,\n includeInStateLogs: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n version: {\n persist: true,\n anonymous: false,\n includeInStateLogs: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n lastFetched: {\n persist: true,\n anonymous: false,\n includeInStateLogs: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n fetchError: {\n persist: true,\n anonymous: false,\n includeInStateLogs: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n etag: {\n persist: true,\n anonymous: false,\n includeInStateLogs: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nconst DEFAULT_FALLBACK_CONFIG: Record<string, RegistryConfigEntry> = {};\n\ntype ConfigRegistryPollingInput = Record<string, never>;\n\nexport type ConfigRegistryControllerStateChangeEvent =\n ControllerStateChangeEvent<typeof controllerName, ConfigRegistryState>;\n\nexport type ConfigRegistryControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConfigRegistryState\n>;\n\nexport type ConfigRegistryControllerGetConfigAction = {\n type: `${typeof controllerName}:getConfig`;\n handler: ConfigRegistryController['getConfig'];\n};\n\nexport type ConfigRegistryControllerSetConfigAction = {\n type: `${typeof controllerName}:setConfig`;\n handler: ConfigRegistryController['setConfig'];\n};\n\nexport type ConfigRegistryControllerGetAllConfigsAction = {\n type: `${typeof controllerName}:getAllConfigs`;\n handler: ConfigRegistryController['getAllConfigs'];\n};\n\nexport type ConfigRegistryControllerStartPollingAction = {\n type: `${typeof controllerName}:startPolling`;\n handler: (input: ConfigRegistryPollingInput) => string;\n};\n\nexport type ConfigRegistryControllerStopPollingAction = {\n type: `${typeof controllerName}:stopPolling`;\n handler: () => void;\n};\n\nexport type ConfigRegistryControllerActions =\n | ConfigRegistryControllerGetStateAction\n | ConfigRegistryControllerGetConfigAction\n | ConfigRegistryControllerSetConfigAction\n | ConfigRegistryControllerGetAllConfigsAction\n | ConfigRegistryControllerStartPollingAction\n | ConfigRegistryControllerStopPollingAction\n | {\n type: 'RemoteFeatureFlagController:getState';\n handler: () => RemoteFeatureFlagControllerState;\n };\n\nexport type ConfigRegistryControllerEvents =\n ConfigRegistryControllerStateChangeEvent;\n\nexport type ConfigRegistryMessenger = Messenger<\n typeof controllerName,\n ConfigRegistryControllerActions,\n ConfigRegistryControllerEvents\n>;\n\nexport type ConfigRegistryControllerOptions = {\n messenger: ConfigRegistryMessenger;\n state?: Partial<ConfigRegistryState>;\n pollingInterval?: number;\n fallbackConfig?: Record<string, RegistryConfigEntry>;\n apiService?: AbstractConfigRegistryApiService;\n};\n\nexport class ConfigRegistryController extends StaticIntervalPollingController<ConfigRegistryPollingInput>()<\n typeof controllerName,\n ConfigRegistryState,\n ConfigRegistryMessenger\n> {\n readonly #fallbackConfig: Record<string, RegistryConfigEntry>;\n\n readonly #apiService: AbstractConfigRegistryApiService;\n\n /**\n * @param options - The controller options.\n * @param options.messenger - The controller messenger.\n * @param options.state - Initial state.\n * @param options.pollingInterval - Polling interval in milliseconds.\n * @param options.fallbackConfig - Fallback configuration.\n * @param options.apiService - The API service.\n */\n constructor({\n messenger,\n state = {},\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n fallbackConfig = DEFAULT_FALLBACK_CONFIG,\n apiService = new ConfigRegistryApiService(),\n }: ConfigRegistryControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: {\n configs: { networks: {} },\n version: null,\n lastFetched: null,\n fetchError: null,\n etag: null,\n ...state,\n },\n });\n\n this.setIntervalLength(pollingInterval);\n this.#fallbackConfig = fallbackConfig;\n this.#apiService = apiService;\n\n this.messenger.registerActionHandler(\n `${controllerName}:getConfig`,\n (key: string) => this.getConfig(key),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:setConfig`,\n (key: string, value: Json, metadata?: Json) =>\n this.setConfig(key, value, metadata),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:getAllConfigs`,\n () => this.getAllConfigs(),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:startPolling`,\n (input: ConfigRegistryPollingInput) => this.startPolling(input),\n );\n\n this.messenger.registerActionHandler(`${controllerName}:stopPolling`, () =>\n this.stopPolling(),\n );\n }\n\n async _executePoll(_input: ConfigRegistryPollingInput): Promise<void> {\n const isApiEnabled = isConfigRegistryApiEnabled(this.messenger);\n\n if (!isApiEnabled) {\n this.#useFallbackConfig(\n 'Feature flag disabled - using fallback configuration',\n );\n return;\n }\n\n try {\n const result: FetchConfigResult = await this.#apiService.fetchConfig({\n etag: this.state.etag ?? undefined,\n });\n\n if (result.notModified) {\n this.update((state) => {\n state.fetchError = null;\n });\n return;\n }\n\n // Filter networks: only featured, active, non-testnet networks\n const filteredNetworks = filterNetworks(result.data.data.networks, {\n isFeatured: true,\n isActive: true,\n isTestnet: false,\n });\n\n const newConfigs: Record<string, RegistryConfigEntry> = {};\n for (const network of filteredNetworks) {\n newConfigs[network.chainId] = {\n key: network.chainId,\n value: network as unknown as Json,\n };\n }\n\n this.update((state) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (state.configs as any) = { networks: newConfigs };\n state.version = result.data.data.version;\n state.lastFetched = Date.now();\n state.fetchError = null;\n state.etag = result.etag ?? null;\n });\n } catch (error) {\n this.#handleFetchError(error);\n }\n }\n\n #useFallbackConfig(errorMessage?: string): void {\n this.update((state) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (state.configs as any) = { networks: { ...this.#fallbackConfig } };\n state.fetchError =\n errorMessage ?? 'Using fallback configuration - API unavailable';\n state.etag = null;\n });\n }\n\n #handleFetchError(error: unknown): void {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error occurred';\n\n const hasNoConfigs =\n Object.keys(this.state.configs?.networks ?? {}).length === 0;\n\n if (hasNoConfigs) {\n this.#useFallbackConfig(errorMessage);\n } else {\n this.update((state) => {\n state.fetchError = errorMessage;\n });\n }\n }\n\n getConfig(key: string): RegistryConfigEntry | undefined {\n return this.state.configs?.networks?.[key];\n }\n\n getAllConfigs(): Record<string, RegistryConfigEntry> {\n return { ...(this.state.configs?.networks ?? {}) };\n }\n\n getConfigValue<TValue = Json>(key: string): TValue | undefined {\n const entry = this.state.configs?.networks?.[key];\n return entry?.value as TValue | undefined;\n }\n\n setConfig(key: string, value: Json, metadata?: Json): void {\n this.update((state) => {\n if (!state.configs) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (state.configs as any) = { networks: {} };\n }\n if (!state.configs.networks) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (state.configs.networks as any) = {};\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (state.configs.networks as any)[key] = {\n key,\n value,\n metadata,\n };\n });\n }\n\n removeConfig(key: string): void {\n this.update((state) => {\n if (state.configs?.networks) {\n delete state.configs.networks[key];\n }\n });\n }\n\n clearConfigs(): void {\n this.update((state) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (state.configs as any) = { networks: {} };\n });\n }\n\n startPolling(input: ConfigRegistryPollingInput = {}): string {\n return super.startPolling(input);\n }\n\n stopPolling(): void {\n super.stopAllPolling();\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=abstract-config-registry-api-service.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-config-registry-api-service.cjs","sourceRoot":"","sources":["../../src/config-registry-api-service/abstract-config-registry-api-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\n\nexport type NetworkConfig = {\n chainId: string;\n name: string;\n nativeCurrency: string;\n rpcEndpoints: {\n url: string;\n type: string;\n networkClientId: string;\n failoverUrls: string[];\n }[];\n blockExplorerUrls: string[];\n defaultRpcEndpointIndex: number;\n defaultBlockExplorerUrlIndex: number;\n lastUpdatedAt?: number;\n networkImageUrl?: string;\n nativeTokenImageUrl?: string;\n isActive: boolean;\n isTestnet: boolean;\n isDefault: boolean;\n isFeatured: boolean;\n isDeprecated: boolean;\n priority: number;\n isDeletable: boolean;\n};\n\nexport type RegistryConfigApiResponse = {\n data: {\n version: string;\n timestamp: number;\n networks: NetworkConfig[];\n };\n};\n\nexport type FetchConfigOptions = {\n etag?: string;\n};\n\nexport type FetchConfigResult =\n | {\n notModified: true;\n etag?: string;\n }\n | {\n notModified: false;\n data: RegistryConfigApiResponse;\n etag?: string;\n };\n\nexport type AbstractConfigRegistryApiService = Partial<\n Pick<ServicePolicy, 'onBreak' | 'onDegraded'>\n> & {\n fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;\n};\n"]}
@@ -0,0 +1,47 @@
1
+ import type { ServicePolicy } from "@metamask/controller-utils";
2
+ export type NetworkConfig = {
3
+ chainId: string;
4
+ name: string;
5
+ nativeCurrency: string;
6
+ rpcEndpoints: {
7
+ url: string;
8
+ type: string;
9
+ networkClientId: string;
10
+ failoverUrls: string[];
11
+ }[];
12
+ blockExplorerUrls: string[];
13
+ defaultRpcEndpointIndex: number;
14
+ defaultBlockExplorerUrlIndex: number;
15
+ lastUpdatedAt?: number;
16
+ networkImageUrl?: string;
17
+ nativeTokenImageUrl?: string;
18
+ isActive: boolean;
19
+ isTestnet: boolean;
20
+ isDefault: boolean;
21
+ isFeatured: boolean;
22
+ isDeprecated: boolean;
23
+ priority: number;
24
+ isDeletable: boolean;
25
+ };
26
+ export type RegistryConfigApiResponse = {
27
+ data: {
28
+ version: string;
29
+ timestamp: number;
30
+ networks: NetworkConfig[];
31
+ };
32
+ };
33
+ export type FetchConfigOptions = {
34
+ etag?: string;
35
+ };
36
+ export type FetchConfigResult = {
37
+ notModified: true;
38
+ etag?: string;
39
+ } | {
40
+ notModified: false;
41
+ data: RegistryConfigApiResponse;
42
+ etag?: string;
43
+ };
44
+ export type AbstractConfigRegistryApiService = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
45
+ fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;
46
+ };
47
+ //# sourceMappingURL=abstract-config-registry-api-service.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-config-registry-api-service.d.cts","sourceRoot":"","sources":["../../src/config-registry-api-service/abstract-config-registry-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,EAAE,CAAC;IACJ,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,uBAAuB,EAAE,MAAM,CAAC;IAChC,4BAA4B,EAAE,MAAM,CAAC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,aAAa,EAAE,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IACE,WAAW,EAAE,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GACD;IACE,WAAW,EAAE,KAAK,CAAC;IACnB,IAAI,EAAE,yBAAyB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,gCAAgC,GAAG,OAAO,CACpD,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,CAAC,CAC9C,GAAG;IACF,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACvE,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { ServicePolicy } from "@metamask/controller-utils";
2
+ export type NetworkConfig = {
3
+ chainId: string;
4
+ name: string;
5
+ nativeCurrency: string;
6
+ rpcEndpoints: {
7
+ url: string;
8
+ type: string;
9
+ networkClientId: string;
10
+ failoverUrls: string[];
11
+ }[];
12
+ blockExplorerUrls: string[];
13
+ defaultRpcEndpointIndex: number;
14
+ defaultBlockExplorerUrlIndex: number;
15
+ lastUpdatedAt?: number;
16
+ networkImageUrl?: string;
17
+ nativeTokenImageUrl?: string;
18
+ isActive: boolean;
19
+ isTestnet: boolean;
20
+ isDefault: boolean;
21
+ isFeatured: boolean;
22
+ isDeprecated: boolean;
23
+ priority: number;
24
+ isDeletable: boolean;
25
+ };
26
+ export type RegistryConfigApiResponse = {
27
+ data: {
28
+ version: string;
29
+ timestamp: number;
30
+ networks: NetworkConfig[];
31
+ };
32
+ };
33
+ export type FetchConfigOptions = {
34
+ etag?: string;
35
+ };
36
+ export type FetchConfigResult = {
37
+ notModified: true;
38
+ etag?: string;
39
+ } | {
40
+ notModified: false;
41
+ data: RegistryConfigApiResponse;
42
+ etag?: string;
43
+ };
44
+ export type AbstractConfigRegistryApiService = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
45
+ fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;
46
+ };
47
+ //# sourceMappingURL=abstract-config-registry-api-service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-config-registry-api-service.d.mts","sourceRoot":"","sources":["../../src/config-registry-api-service/abstract-config-registry-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,EAAE,CAAC;IACJ,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,uBAAuB,EAAE,MAAM,CAAC;IAChC,4BAA4B,EAAE,MAAM,CAAC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,aAAa,EAAE,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IACE,WAAW,EAAE,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GACD;IACE,WAAW,EAAE,KAAK,CAAC;IACnB,IAAI,EAAE,yBAAyB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,gCAAgC,GAAG,OAAO,CACpD,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,CAAC,CAC9C,GAAG;IACF,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACvE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=abstract-config-registry-api-service.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-config-registry-api-service.mjs","sourceRoot":"","sources":["../../src/config-registry-api-service/abstract-config-registry-api-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\n\nexport type NetworkConfig = {\n chainId: string;\n name: string;\n nativeCurrency: string;\n rpcEndpoints: {\n url: string;\n type: string;\n networkClientId: string;\n failoverUrls: string[];\n }[];\n blockExplorerUrls: string[];\n defaultRpcEndpointIndex: number;\n defaultBlockExplorerUrlIndex: number;\n lastUpdatedAt?: number;\n networkImageUrl?: string;\n nativeTokenImageUrl?: string;\n isActive: boolean;\n isTestnet: boolean;\n isDefault: boolean;\n isFeatured: boolean;\n isDeprecated: boolean;\n priority: number;\n isDeletable: boolean;\n};\n\nexport type RegistryConfigApiResponse = {\n data: {\n version: string;\n timestamp: number;\n networks: NetworkConfig[];\n };\n};\n\nexport type FetchConfigOptions = {\n etag?: string;\n};\n\nexport type FetchConfigResult =\n | {\n notModified: true;\n etag?: string;\n }\n | {\n notModified: false;\n data: RegistryConfigApiResponse;\n etag?: string;\n };\n\nexport type AbstractConfigRegistryApiService = Partial<\n Pick<ServicePolicy, 'onBreak' | 'onDegraded'>\n> & {\n fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;\n};\n"]}
@@ -0,0 +1,124 @@
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_apiBaseUrl, _ConfigRegistryApiService_endpointPath, _ConfigRegistryApiService_timeout, _ConfigRegistryApiService_fetch;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ConfigRegistryApiService = exports.DEFAULT_TIMEOUT = exports.DEFAULT_ENDPOINT_PATH = exports.DEFAULT_API_BASE_URL = void 0;
16
+ const controller_utils_1 = require("@metamask/controller-utils");
17
+ exports.DEFAULT_API_BASE_URL = 'https://client-config.uat-api.cx.metamask.io/v1';
18
+ exports.DEFAULT_ENDPOINT_PATH = '/config/networks';
19
+ exports.DEFAULT_TIMEOUT = 10 * 1000;
20
+ class ConfigRegistryApiService {
21
+ /**
22
+ * Construct a Config Registry API Service.
23
+ *
24
+ * @param options - The options for constructing the service.
25
+ * @param options.apiBaseUrl - The base URL for the API. Defaults to the UAT API URL.
26
+ * @param options.endpointPath - The endpoint path. Defaults to '/config/networks'.
27
+ * @param options.timeout - Timeout for HTTP requests in milliseconds. Defaults to 10 seconds.
28
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
29
+ * @param options.degradedThreshold - The length of time (in milliseconds) that governs when the service is regarded as degraded. Defaults to 5 seconds.
30
+ * @param options.retries - Number of retry attempts for each fetch request. Defaults to 3.
31
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures allowed before breaking the circuit. Defaults to 3.
32
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks from too many consecutive failures. Defaults to 2 minutes.
33
+ */
34
+ constructor({ apiBaseUrl = exports.DEFAULT_API_BASE_URL, endpointPath = exports.DEFAULT_ENDPOINT_PATH, timeout = exports.DEFAULT_TIMEOUT, fetch: customFetch = globalThis.fetch, degradedThreshold = controller_utils_1.DEFAULT_DEGRADED_THRESHOLD, retries = controller_utils_1.DEFAULT_MAX_RETRIES, maximumConsecutiveFailures = controller_utils_1.DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = controller_utils_1.DEFAULT_CIRCUIT_BREAK_DURATION, } = {}) {
35
+ _ConfigRegistryApiService_policy.set(this, void 0);
36
+ _ConfigRegistryApiService_apiBaseUrl.set(this, void 0);
37
+ _ConfigRegistryApiService_endpointPath.set(this, void 0);
38
+ _ConfigRegistryApiService_timeout.set(this, void 0);
39
+ _ConfigRegistryApiService_fetch.set(this, void 0);
40
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_apiBaseUrl, apiBaseUrl, "f");
41
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_endpointPath, endpointPath, "f");
42
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_timeout, timeout, "f");
43
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_fetch, customFetch, "f");
44
+ __classPrivateFieldSet(this, _ConfigRegistryApiService_policy, (0, controller_utils_1.createServicePolicy)({
45
+ maxRetries: retries,
46
+ maxConsecutiveFailures: maximumConsecutiveFailures,
47
+ circuitBreakDuration,
48
+ degradedThreshold,
49
+ }), "f");
50
+ }
51
+ onBreak(...args) {
52
+ return __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").onBreak(...args);
53
+ }
54
+ onDegraded(...args) {
55
+ return __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").onDegraded(...args);
56
+ }
57
+ async fetchConfig(options = {}) {
58
+ const baseUrl = __classPrivateFieldGet(this, _ConfigRegistryApiService_apiBaseUrl, "f").endsWith('/')
59
+ ? __classPrivateFieldGet(this, _ConfigRegistryApiService_apiBaseUrl, "f").slice(0, -1)
60
+ : __classPrivateFieldGet(this, _ConfigRegistryApiService_apiBaseUrl, "f");
61
+ const endpointPath = __classPrivateFieldGet(this, _ConfigRegistryApiService_endpointPath, "f").startsWith('/')
62
+ ? __classPrivateFieldGet(this, _ConfigRegistryApiService_endpointPath, "f")
63
+ : `/${__classPrivateFieldGet(this, _ConfigRegistryApiService_endpointPath, "f")}`;
64
+ const url = new URL(`${baseUrl}${endpointPath}`);
65
+ const headers = {
66
+ 'Cache-Control': 'no-cache',
67
+ };
68
+ if (options.etag) {
69
+ headers['If-None-Match'] = options.etag;
70
+ }
71
+ const fetchWithTimeout = async () => {
72
+ const controller = new AbortController();
73
+ const timeoutId = setTimeout(() => controller.abort(), __classPrivateFieldGet(this, _ConfigRegistryApiService_timeout, "f"));
74
+ try {
75
+ const response = await __classPrivateFieldGet(this, _ConfigRegistryApiService_fetch, "f").call(this, url.toString(), {
76
+ headers,
77
+ signal: controller.signal,
78
+ });
79
+ clearTimeout(timeoutId);
80
+ return response;
81
+ }
82
+ catch (error) {
83
+ clearTimeout(timeoutId);
84
+ if (error instanceof Error && error.name === 'AbortError') {
85
+ throw new Error(`Request timeout after ${__classPrivateFieldGet(this, _ConfigRegistryApiService_timeout, "f")}ms`);
86
+ }
87
+ throw error;
88
+ }
89
+ };
90
+ const response = await __classPrivateFieldGet(this, _ConfigRegistryApiService_policy, "f").execute(async () => {
91
+ const res = await fetchWithTimeout();
92
+ if (res.status === 304) {
93
+ return {
94
+ status: 304,
95
+ headers: res.headers,
96
+ };
97
+ }
98
+ if (!res.ok) {
99
+ throw new Error(`Failed to fetch config: ${res.status} ${res.statusText}`);
100
+ }
101
+ return res;
102
+ });
103
+ if (response.status === 304) {
104
+ const etag = response.headers.get('ETag') ?? undefined;
105
+ return {
106
+ notModified: true,
107
+ etag,
108
+ };
109
+ }
110
+ const etag = response.headers.get('ETag') ?? undefined;
111
+ const data = (await response.json());
112
+ if (!data?.data || !Array.isArray(data.data.networks)) {
113
+ throw new Error('Invalid response structure from config registry API');
114
+ }
115
+ return {
116
+ data,
117
+ etag,
118
+ notModified: false,
119
+ };
120
+ }
121
+ }
122
+ exports.ConfigRegistryApiService = ConfigRegistryApiService;
123
+ _ConfigRegistryApiService_policy = new WeakMap(), _ConfigRegistryApiService_apiBaseUrl = new WeakMap(), _ConfigRegistryApiService_endpointPath = new WeakMap(), _ConfigRegistryApiService_timeout = new WeakMap(), _ConfigRegistryApiService_fetch = new WeakMap();
124
+ //# 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,iEAMoC;AAUvB,QAAA,oBAAoB,GAC/B,iDAAiD,CAAC;AAEvC,QAAA,qBAAqB,GAAG,kBAAkB,CAAC;AAE3C,QAAA,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;AAazC,MAAa,wBAAwB;IAanC;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,UAAU,GAAG,4BAAoB,EACjC,YAAY,GAAG,6BAAqB,EACpC,OAAO,GAAG,uBAAe,EACzB,KAAK,EAAE,WAAW,GAAG,UAAU,CAAC,KAAK,EACrC,iBAAiB,GAAG,6CAA0B,EAC9C,OAAO,GAAG,sCAAmB,EAC7B,0BAA0B,GAAG,mDAAgC,EAC7D,oBAAoB,GAAG,iDAA8B,MAClB,EAAE;QAhC9B,mDAAuB;QAEvB,uDAAoB;QAEpB,yDAAsB;QAEtB,oDAAiB;QAEjB,kDAAqB;QAyB5B,uBAAA,IAAI,wCAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,0CAAiB,YAAY,MAAA,CAAC;QAClC,uBAAA,IAAI,qCAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,mCAAU,WAAW,MAAA,CAAC;QAE1B,uBAAA,IAAI,oCAAW,IAAA,sCAAmB,EAAC;YACjC,UAAU,EAAE,OAAO;YACnB,sBAAsB,EAAE,0BAA0B;YAClD,oBAAoB;YACpB,iBAAiB;SAClB,CAAC,MAAA,CAAC;IACL,CAAC;IAED,OAAO,CACL,GAAG,IAA0C;QAE7C,OAAO,uBAAA,IAAI,wCAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,UA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IAAI,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,OAAO;YACL,IAAI;YACJ,IAAI;YACJ,WAAW,EAAE,KAAK;SACnB,CAAC;IACJ,CAAC;CACF;AA5ID,4DA4IC","sourcesContent":["import {\n createServicePolicy,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\n\nimport type {\n AbstractConfigRegistryApiService,\n FetchConfigOptions,\n FetchConfigResult,\n RegistryConfigApiResponse,\n} from './abstract-config-registry-api-service';\n\nexport const DEFAULT_API_BASE_URL =\n 'https://client-config.uat-api.cx.metamask.io/v1';\n\nexport const DEFAULT_ENDPOINT_PATH = '/config/networks';\n\nexport const DEFAULT_TIMEOUT = 10 * 1000;\n\nexport type ConfigRegistryApiServiceOptions = {\n apiBaseUrl?: string;\n endpointPath?: string;\n timeout?: number;\n fetch?: typeof fetch;\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n};\n\nexport class ConfigRegistryApiService\n implements AbstractConfigRegistryApiService\n{\n readonly #policy: ServicePolicy;\n\n readonly #apiBaseUrl: string;\n\n readonly #endpointPath: string;\n\n readonly #timeout: number;\n\n readonly #fetch: typeof fetch;\n\n /**\n * Construct a Config Registry API Service.\n *\n * @param options - The options for constructing the service.\n * @param options.apiBaseUrl - The base URL for the API. Defaults to the UAT API URL.\n * @param options.endpointPath - The endpoint path. Defaults to '/config/networks'.\n * @param options.timeout - Timeout for HTTP requests in milliseconds. Defaults to 10 seconds.\n * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.\n * @param options.degradedThreshold - The length of time (in milliseconds) that governs when the service is regarded as degraded. Defaults to 5 seconds.\n * @param options.retries - Number of retry attempts for each fetch request. Defaults to 3.\n * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures allowed before breaking the circuit. Defaults to 3.\n * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks from too many consecutive failures. Defaults to 2 minutes.\n */\n constructor({\n apiBaseUrl = DEFAULT_API_BASE_URL,\n endpointPath = DEFAULT_ENDPOINT_PATH,\n timeout = DEFAULT_TIMEOUT,\n fetch: customFetch = globalThis.fetch,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n }: ConfigRegistryApiServiceOptions = {}) {\n this.#apiBaseUrl = apiBaseUrl;\n this.#endpointPath = endpointPath;\n this.#timeout = timeout;\n this.#fetch = customFetch;\n\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n degradedThreshold,\n });\n }\n\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\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 baseUrl = this.#apiBaseUrl.endsWith('/')\n ? this.#apiBaseUrl.slice(0, -1)\n : this.#apiBaseUrl;\n const endpointPath = this.#endpointPath.startsWith('/')\n ? this.#endpointPath\n : `/${this.#endpointPath}`;\n const url = new URL(`${baseUrl}${endpointPath}`);\n\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 fetchWithTimeout = async (): Promise<Response> => {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.#timeout);\n\n try {\n const response = await this.#fetch(url.toString(), {\n headers,\n signal: controller.signal,\n });\n clearTimeout(timeoutId);\n return response;\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof Error && error.name === 'AbortError') {\n throw new Error(`Request timeout after ${this.#timeout}ms`);\n }\n throw error;\n }\n };\n\n const response = await this.#policy.execute(async () => {\n const res = await fetchWithTimeout();\n\n if (res.status === 304) {\n return {\n status: 304,\n headers: res.headers,\n } as unknown as Response;\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 as unknown as { status?: number }).status === 304) {\n const etag = response.headers.get('ETag') ?? undefined;\n return {\n notModified: true,\n etag,\n };\n }\n\n const etag = response.headers.get('ETag') ?? undefined;\n const data = (await response.json()) as RegistryConfigApiResponse;\n\n if (!data?.data || !Array.isArray(data.data.networks)) {\n throw new Error('Invalid response structure from config registry API');\n }\n\n return {\n data,\n etag,\n notModified: false,\n };\n }\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import type { ServicePolicy } from "@metamask/controller-utils";
2
+ import type { AbstractConfigRegistryApiService, FetchConfigOptions, FetchConfigResult } from "./abstract-config-registry-api-service.cjs";
3
+ export declare const DEFAULT_API_BASE_URL = "https://client-config.uat-api.cx.metamask.io/v1";
4
+ export declare const DEFAULT_ENDPOINT_PATH = "/config/networks";
5
+ export declare const DEFAULT_TIMEOUT: number;
6
+ export type ConfigRegistryApiServiceOptions = {
7
+ apiBaseUrl?: string;
8
+ endpointPath?: string;
9
+ timeout?: number;
10
+ fetch?: typeof fetch;
11
+ degradedThreshold?: number;
12
+ retries?: number;
13
+ maximumConsecutiveFailures?: number;
14
+ circuitBreakDuration?: number;
15
+ };
16
+ export declare class ConfigRegistryApiService implements AbstractConfigRegistryApiService {
17
+ #private;
18
+ /**
19
+ * Construct a Config Registry API Service.
20
+ *
21
+ * @param options - The options for constructing the service.
22
+ * @param options.apiBaseUrl - The base URL for the API. Defaults to the UAT API URL.
23
+ * @param options.endpointPath - The endpoint path. Defaults to '/config/networks'.
24
+ * @param options.timeout - Timeout for HTTP requests in milliseconds. Defaults to 10 seconds.
25
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
26
+ * @param options.degradedThreshold - The length of time (in milliseconds) that governs when the service is regarded as degraded. Defaults to 5 seconds.
27
+ * @param options.retries - Number of retry attempts for each fetch request. Defaults to 3.
28
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures allowed before breaking the circuit. Defaults to 3.
29
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks from too many consecutive failures. Defaults to 2 minutes.
30
+ */
31
+ constructor({ apiBaseUrl, endpointPath, timeout, fetch: customFetch, degradedThreshold, retries, maximumConsecutiveFailures, circuitBreakDuration, }?: ConfigRegistryApiServiceOptions);
32
+ onBreak(...args: Parameters<ServicePolicy['onBreak']>): ReturnType<ServicePolicy['onBreak']>;
33
+ onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): ReturnType<ServicePolicy['onDegraded']>;
34
+ fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;
35
+ }
36
+ //# 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":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EACV,gCAAgC,EAChC,kBAAkB,EAClB,iBAAiB,EAElB,mDAA+C;AAEhD,eAAO,MAAM,oBAAoB,oDACkB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD,eAAO,MAAM,eAAe,QAAY,CAAC;AAEzC,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,qBAAa,wBACX,YAAW,gCAAgC;;IAY3C;;;;;;;;;;;;OAYG;gBACS,EACV,UAAiC,EACjC,YAAoC,EACpC,OAAyB,EACzB,KAAK,EAAE,WAA8B,EACrC,iBAA8C,EAC9C,OAA6B,EAC7B,0BAA6D,EAC7D,oBAAqD,GACtD,GAAE,+BAAoC;IAcvC,OAAO,CACL,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAC5C,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIvC,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;CA6E9B"}
@@ -0,0 +1,36 @@
1
+ import type { ServicePolicy } from "@metamask/controller-utils";
2
+ import type { AbstractConfigRegistryApiService, FetchConfigOptions, FetchConfigResult } from "./abstract-config-registry-api-service.mjs";
3
+ export declare const DEFAULT_API_BASE_URL = "https://client-config.uat-api.cx.metamask.io/v1";
4
+ export declare const DEFAULT_ENDPOINT_PATH = "/config/networks";
5
+ export declare const DEFAULT_TIMEOUT: number;
6
+ export type ConfigRegistryApiServiceOptions = {
7
+ apiBaseUrl?: string;
8
+ endpointPath?: string;
9
+ timeout?: number;
10
+ fetch?: typeof fetch;
11
+ degradedThreshold?: number;
12
+ retries?: number;
13
+ maximumConsecutiveFailures?: number;
14
+ circuitBreakDuration?: number;
15
+ };
16
+ export declare class ConfigRegistryApiService implements AbstractConfigRegistryApiService {
17
+ #private;
18
+ /**
19
+ * Construct a Config Registry API Service.
20
+ *
21
+ * @param options - The options for constructing the service.
22
+ * @param options.apiBaseUrl - The base URL for the API. Defaults to the UAT API URL.
23
+ * @param options.endpointPath - The endpoint path. Defaults to '/config/networks'.
24
+ * @param options.timeout - Timeout for HTTP requests in milliseconds. Defaults to 10 seconds.
25
+ * @param options.fetch - Custom fetch function for testing or custom implementations. Defaults to the global fetch.
26
+ * @param options.degradedThreshold - The length of time (in milliseconds) that governs when the service is regarded as degraded. Defaults to 5 seconds.
27
+ * @param options.retries - Number of retry attempts for each fetch request. Defaults to 3.
28
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures allowed before breaking the circuit. Defaults to 3.
29
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks from too many consecutive failures. Defaults to 2 minutes.
30
+ */
31
+ constructor({ apiBaseUrl, endpointPath, timeout, fetch: customFetch, degradedThreshold, retries, maximumConsecutiveFailures, circuitBreakDuration, }?: ConfigRegistryApiServiceOptions);
32
+ onBreak(...args: Parameters<ServicePolicy['onBreak']>): ReturnType<ServicePolicy['onBreak']>;
33
+ onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): ReturnType<ServicePolicy['onDegraded']>;
34
+ fetchConfig(options?: FetchConfigOptions): Promise<FetchConfigResult>;
35
+ }
36
+ //# 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":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EACV,gCAAgC,EAChC,kBAAkB,EAClB,iBAAiB,EAElB,mDAA+C;AAEhD,eAAO,MAAM,oBAAoB,oDACkB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD,eAAO,MAAM,eAAe,QAAY,CAAC;AAEzC,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,qBAAa,wBACX,YAAW,gCAAgC;;IAY3C;;;;;;;;;;;;OAYG;gBACS,EACV,UAAiC,EACjC,YAAoC,EACpC,OAAyB,EACzB,KAAK,EAAE,WAA8B,EACrC,iBAA8C,EAC9C,OAA6B,EAC7B,0BAA6D,EAC7D,oBAAqD,GACtD,GAAE,+BAAoC;IAcvC,OAAO,CACL,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAC5C,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIvC,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;CA6E9B"}