@metamask-previews/config-registry-controller 3.1.0-preview-4f4c98e → 3.1.0-preview-eb263b0ee

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 (83) hide show
  1. package/CHANGELOG.md +0 -5
  2. package/dist/ConfigRegistryController-method-action-types.cjs +7 -0
  3. package/dist/ConfigRegistryController-method-action-types.cjs.map +1 -0
  4. package/dist/{ConfigRegistryController-method-action-types.d.ts → ConfigRegistryController-method-action-types.d.cts} +2 -2
  5. package/dist/ConfigRegistryController-method-action-types.d.cts.map +1 -0
  6. package/dist/ConfigRegistryController-method-action-types.d.mts +31 -0
  7. package/dist/ConfigRegistryController-method-action-types.d.mts.map +1 -0
  8. package/dist/{ConfigRegistryController-method-action-types.js → ConfigRegistryController-method-action-types.mjs} +1 -1
  9. package/dist/ConfigRegistryController-method-action-types.mjs.map +1 -0
  10. package/dist/ConfigRegistryController.cjs +160 -0
  11. package/dist/ConfigRegistryController.cjs.map +1 -0
  12. package/dist/{ConfigRegistryController.d.ts → ConfigRegistryController.d.cts} +18 -18
  13. package/dist/ConfigRegistryController.d.cts.map +1 -0
  14. package/dist/ConfigRegistryController.d.mts +128 -0
  15. package/dist/ConfigRegistryController.d.mts.map +1 -0
  16. package/dist/{ConfigRegistryController.js → ConfigRegistryController.mjs} +3 -3
  17. package/dist/ConfigRegistryController.mjs.map +1 -0
  18. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.cjs +7 -0
  19. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.cjs.map +1 -0
  20. package/dist/config-registry-api-service/{config-registry-api-service-method-action-types.d.ts → config-registry-api-service-method-action-types.d.cts} +2 -2
  21. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.d.cts.map +1 -0
  22. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.d.mts +14 -0
  23. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.d.mts.map +1 -0
  24. package/dist/config-registry-api-service/{config-registry-api-service-method-action-types.js → config-registry-api-service-method-action-types.mjs} +1 -1
  25. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.mjs.map +1 -0
  26. package/dist/config-registry-api-service/config-registry-api-service.cjs +154 -0
  27. package/dist/config-registry-api-service/config-registry-api-service.cjs.map +1 -0
  28. package/dist/config-registry-api-service/{config-registry-api-service.d.ts → config-registry-api-service.d.cts} +6 -6
  29. package/dist/config-registry-api-service/config-registry-api-service.d.cts.map +1 -0
  30. package/dist/config-registry-api-service/config-registry-api-service.d.mts +108 -0
  31. package/dist/config-registry-api-service/config-registry-api-service.d.mts.map +1 -0
  32. package/dist/config-registry-api-service/{config-registry-api-service.js → config-registry-api-service.mjs} +3 -3
  33. package/dist/config-registry-api-service/config-registry-api-service.mjs.map +1 -0
  34. package/dist/config-registry-api-service/filters.cjs +30 -0
  35. package/dist/config-registry-api-service/filters.cjs.map +1 -0
  36. package/dist/config-registry-api-service/{filters.d.ts → filters.d.cts} +2 -2
  37. package/dist/config-registry-api-service/filters.d.cts.map +1 -0
  38. package/dist/config-registry-api-service/filters.d.mts +15 -0
  39. package/dist/config-registry-api-service/filters.d.mts.map +1 -0
  40. package/dist/config-registry-api-service/{filters.js → filters.mjs} +1 -1
  41. package/dist/config-registry-api-service/filters.mjs.map +1 -0
  42. package/dist/config-registry-api-service/types.cjs +75 -0
  43. package/dist/config-registry-api-service/types.cjs.map +1 -0
  44. package/dist/config-registry-api-service/{types.d.ts → types.d.cts} +49 -49
  45. package/dist/config-registry-api-service/types.d.cts.map +1 -0
  46. package/dist/config-registry-api-service/types.d.mts +510 -0
  47. package/dist/config-registry-api-service/types.d.mts.map +1 -0
  48. package/dist/config-registry-api-service/{types.js → types.mjs} +3 -3
  49. package/dist/config-registry-api-service/types.mjs.map +1 -0
  50. package/dist/index.cjs +16 -0
  51. package/dist/index.cjs.map +1 -0
  52. package/dist/{index.d.ts → index.d.cts} +11 -11
  53. package/dist/index.d.cts.map +1 -0
  54. package/dist/index.d.mts +11 -0
  55. package/dist/index.d.mts.map +1 -0
  56. package/dist/index.mjs +5 -0
  57. package/dist/index.mjs.map +1 -0
  58. package/dist/selectors.cjs +54 -0
  59. package/dist/selectors.cjs.map +1 -0
  60. package/dist/{selectors.d.ts → selectors.d.cts} +63 -63
  61. package/dist/selectors.d.cts.map +1 -0
  62. package/dist/selectors.d.mts +466 -0
  63. package/dist/selectors.d.mts.map +1 -0
  64. package/dist/{selectors.js → selectors.mjs} +4 -4
  65. package/dist/selectors.mjs.map +1 -0
  66. package/package.json +17 -13
  67. package/dist/ConfigRegistryController-method-action-types.d.ts.map +0 -1
  68. package/dist/ConfigRegistryController-method-action-types.js.map +0 -1
  69. package/dist/ConfigRegistryController.d.ts.map +0 -1
  70. package/dist/ConfigRegistryController.js.map +0 -1
  71. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.d.ts.map +0 -1
  72. package/dist/config-registry-api-service/config-registry-api-service-method-action-types.js.map +0 -1
  73. package/dist/config-registry-api-service/config-registry-api-service.d.ts.map +0 -1
  74. package/dist/config-registry-api-service/config-registry-api-service.js.map +0 -1
  75. package/dist/config-registry-api-service/filters.d.ts.map +0 -1
  76. package/dist/config-registry-api-service/filters.js.map +0 -1
  77. package/dist/config-registry-api-service/types.d.ts.map +0 -1
  78. package/dist/config-registry-api-service/types.js.map +0 -1
  79. package/dist/index.d.ts.map +0 -1
  80. package/dist/index.js +0 -5
  81. package/dist/index.js.map +0 -1
  82. package/dist/selectors.d.ts.map +0 -1
  83. package/dist/selectors.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,11 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Changed
11
-
12
- - **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
13
- - Bump `@metamask/remote-feature-flag-controller` from `^6.0.0` to `^6.1.0` ([#9980](https://github.com/MetaMask/core/pull/9980))
14
-
15
10
  ## [3.1.0]
16
11
 
17
12
  ### Added
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=ConfigRegistryController-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController-method-action-types.cjs","sourceRoot":"","sources":["../src/ConfigRegistryController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ConfigRegistryController } from './ConfigRegistryController.js';\n\n/**\n * Get the network configuration for a given CAIP-2 chain ID.\n *\n * @param caip2ChainId - The CAIP-2 chain ID (e.g., \"eip155:1\").\n * @returns The network configuration if found, otherwise undefined.\n */\nexport type ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction = {\n type: `ConfigRegistryController:getNetworkConfigByCaip2ChainId`;\n handler: ConfigRegistryController['getNetworkConfigByCaip2ChainId'];\n};\n\n/**\n * Stop all polling.\n */\nexport type ConfigRegistryControllerStopPollingAction = {\n type: `ConfigRegistryController:stopPolling`;\n handler: ConfigRegistryController['stopPolling'];\n};\n\nexport type ConfigRegistryControllerStartPollingAction = {\n type: `ConfigRegistryController:startPolling`;\n handler: ConfigRegistryController['startPolling'];\n};\n\n/**\n * Union of all ConfigRegistryController action types.\n */\nexport type ConfigRegistryControllerMethodActions =\n | ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction\n | ConfigRegistryControllerStopPollingAction\n | ConfigRegistryControllerStartPollingAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { ConfigRegistryController } from './ConfigRegistryController.js';
5
+ import type { ConfigRegistryController } from "./ConfigRegistryController.cjs";
6
6
  /**
7
7
  * Get the network configuration for a given CAIP-2 chain ID.
8
8
  *
@@ -28,4 +28,4 @@ export type ConfigRegistryControllerStartPollingAction = {
28
28
  * Union of all ConfigRegistryController action types.
29
29
  */
30
30
  export type ConfigRegistryControllerMethodActions = ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction | ConfigRegistryControllerStopPollingAction | ConfigRegistryControllerStartPollingAction;
31
- //# sourceMappingURL=ConfigRegistryController-method-action-types.d.ts.map
31
+ //# sourceMappingURL=ConfigRegistryController-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController-method-action-types.d.cts","sourceRoot":"","sources":["../src/ConfigRegistryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAsC;AAE9E;;;;;GAKG;AACH,MAAM,MAAM,4DAA4D,GAAG;IACzE,IAAI,EAAE,yDAAyD,CAAC;IAChE,OAAO,EAAE,wBAAwB,CAAC,gCAAgC,CAAC,CAAC;CACrE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,wBAAwB,CAAC,aAAa,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,wBAAwB,CAAC,cAAc,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC7C,4DAA4D,GAC5D,yCAAyC,GACzC,0CAA0C,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ConfigRegistryController } from "./ConfigRegistryController.mjs";
6
+ /**
7
+ * Get the network configuration for a given CAIP-2 chain ID.
8
+ *
9
+ * @param caip2ChainId - The CAIP-2 chain ID (e.g., "eip155:1").
10
+ * @returns The network configuration if found, otherwise undefined.
11
+ */
12
+ export type ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction = {
13
+ type: `ConfigRegistryController:getNetworkConfigByCaip2ChainId`;
14
+ handler: ConfigRegistryController['getNetworkConfigByCaip2ChainId'];
15
+ };
16
+ /**
17
+ * Stop all polling.
18
+ */
19
+ export type ConfigRegistryControllerStopPollingAction = {
20
+ type: `ConfigRegistryController:stopPolling`;
21
+ handler: ConfigRegistryController['stopPolling'];
22
+ };
23
+ export type ConfigRegistryControllerStartPollingAction = {
24
+ type: `ConfigRegistryController:startPolling`;
25
+ handler: ConfigRegistryController['startPolling'];
26
+ };
27
+ /**
28
+ * Union of all ConfigRegistryController action types.
29
+ */
30
+ export type ConfigRegistryControllerMethodActions = ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction | ConfigRegistryControllerStopPollingAction | ConfigRegistryControllerStartPollingAction;
31
+ //# sourceMappingURL=ConfigRegistryController-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController-method-action-types.d.mts","sourceRoot":"","sources":["../src/ConfigRegistryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAsC;AAE9E;;;;;GAKG;AACH,MAAM,MAAM,4DAA4D,GAAG;IACzE,IAAI,EAAE,yDAAyD,CAAC;IAChE,OAAO,EAAE,wBAAwB,CAAC,gCAAgC,CAAC,CAAC;CACrE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,wBAAwB,CAAC,aAAa,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,wBAAwB,CAAC,cAAc,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC7C,4DAA4D,GAC5D,yCAAyC,GACzC,0CAA0C,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=ConfigRegistryController-method-action-types.js.map
6
+ //# sourceMappingURL=ConfigRegistryController-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController-method-action-types.mjs","sourceRoot":"","sources":["../src/ConfigRegistryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ConfigRegistryController } from './ConfigRegistryController.js';\n\n/**\n * Get the network configuration for a given CAIP-2 chain ID.\n *\n * @param caip2ChainId - The CAIP-2 chain ID (e.g., \"eip155:1\").\n * @returns The network configuration if found, otherwise undefined.\n */\nexport type ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction = {\n type: `ConfigRegistryController:getNetworkConfigByCaip2ChainId`;\n handler: ConfigRegistryController['getNetworkConfigByCaip2ChainId'];\n};\n\n/**\n * Stop all polling.\n */\nexport type ConfigRegistryControllerStopPollingAction = {\n type: `ConfigRegistryController:stopPolling`;\n handler: ConfigRegistryController['stopPolling'];\n};\n\nexport type ConfigRegistryControllerStartPollingAction = {\n type: `ConfigRegistryController:startPolling`;\n handler: ConfigRegistryController['startPolling'];\n};\n\n/**\n * Union of all ConfigRegistryController action types.\n */\nexport type ConfigRegistryControllerMethodActions =\n | ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction\n | ConfigRegistryControllerStopPollingAction\n | ConfigRegistryControllerStartPollingAction;\n"]}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _ConfigRegistryController_instances, _ConfigRegistryController_setupEventListeners, _ConfigRegistryController_onUnlock, _ConfigRegistryController_onLock, _ConfigRegistryController_onFeatureFlagChange, _ConfigRegistryController_isFeatureFlagEnabled;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ConfigRegistryController = exports.DEFAULT_POLLING_INTERVAL = void 0;
10
+ const polling_controller_1 = require("@metamask/polling-controller");
11
+ const utils_1 = require("@metamask/utils");
12
+ const controllerName = 'ConfigRegistryController';
13
+ exports.DEFAULT_POLLING_INTERVAL = (0, utils_1.inMilliseconds)(1, utils_1.Duration.Day);
14
+ const FEATURE_FLAG_KEY = 'configRegistryApiEnabled';
15
+ const stateMetadata = {
16
+ configs: {
17
+ persist: true,
18
+ includeInStateLogs: false,
19
+ includeInDebugSnapshot: true,
20
+ usedInUi: true,
21
+ },
22
+ version: {
23
+ persist: true,
24
+ includeInStateLogs: true,
25
+ includeInDebugSnapshot: true,
26
+ usedInUi: false,
27
+ },
28
+ lastFetched: {
29
+ persist: true,
30
+ includeInStateLogs: true,
31
+ includeInDebugSnapshot: true,
32
+ usedInUi: false,
33
+ },
34
+ etag: {
35
+ persist: true,
36
+ includeInStateLogs: false,
37
+ includeInDebugSnapshot: false,
38
+ usedInUi: false,
39
+ },
40
+ };
41
+ /**
42
+ * Default fallback configuration when no configs are available.
43
+ */
44
+ const DEFAULT_FALLBACK_CONFIG = {};
45
+ const MESSENGER_EXPOSED_METHODS = [
46
+ 'startPolling',
47
+ 'stopPolling',
48
+ 'getNetworkConfigByCaip2ChainId',
49
+ ];
50
+ class ConfigRegistryController extends (0, polling_controller_1.StaticIntervalPollingController)() {
51
+ /**
52
+ * @param options - The controller options.
53
+ * @param options.messenger - The controller messenger. Must have
54
+ * `ConfigRegistryApiService:fetchConfig` action handler registered
55
+ * (e.g. by instantiating {@link ConfigRegistryApiService} with the same
56
+ * messenger).
57
+ * @param options.state - Initial state.
58
+ * @param options.pollingInterval - Polling interval in milliseconds.
59
+ * @param options.fallbackConfig - Fallback configuration.
60
+ */
61
+ constructor({ messenger, state = {}, pollingInterval = exports.DEFAULT_POLLING_INTERVAL, fallbackConfig = DEFAULT_FALLBACK_CONFIG, }) {
62
+ super({
63
+ name: controllerName,
64
+ metadata: stateMetadata,
65
+ messenger,
66
+ state: {
67
+ configs: {
68
+ networks: state.configs?.networks ?? { ...fallbackConfig },
69
+ },
70
+ version: state.version ?? null,
71
+ lastFetched: state.lastFetched ?? null,
72
+ etag: state.etag ?? null,
73
+ },
74
+ });
75
+ _ConfigRegistryController_instances.add(this);
76
+ this.setIntervalLength(pollingInterval);
77
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
78
+ __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_setupEventListeners).call(this);
79
+ }
80
+ /**
81
+ * Get the network configuration for a given CAIP-2 chain ID.
82
+ *
83
+ * @param caip2ChainId - The CAIP-2 chain ID (e.g., "eip155:1").
84
+ * @returns The network configuration if found, otherwise undefined.
85
+ */
86
+ getNetworkConfigByCaip2ChainId(caip2ChainId) {
87
+ return this.state.configs.networks[caip2ChainId];
88
+ }
89
+ async _executePoll(_input) {
90
+ try {
91
+ const result = await this.messenger.call('ConfigRegistryApiService:fetchConfig', {
92
+ etag: this.state.etag ?? undefined,
93
+ });
94
+ if (!result.modified) {
95
+ this.update((state) => {
96
+ state.lastFetched = Date.now();
97
+ if (result.etag !== undefined) {
98
+ state.etag = result.etag ?? null;
99
+ }
100
+ });
101
+ return;
102
+ }
103
+ const apiChains = result.data.data.chains;
104
+ const newConfigs = {};
105
+ // duplicate chainIds from API response are not expected
106
+ apiChains.forEach((chainConfig) => {
107
+ const { chainId } = chainConfig;
108
+ newConfigs[chainId] = chainConfig;
109
+ });
110
+ this.update((state) => {
111
+ state.configs.networks = newConfigs;
112
+ state.version = result.data.data.version;
113
+ state.lastFetched = Date.now();
114
+ state.etag = result.etag ?? null;
115
+ });
116
+ }
117
+ catch (error) {
118
+ const errorInstance = error instanceof Error ? error : new Error(String(error));
119
+ this.messenger.captureException?.(errorInstance);
120
+ }
121
+ }
122
+ /**
123
+ * Stop all polling.
124
+ */
125
+ stopPolling() {
126
+ // This is a wrapper around `super.stopAllPolling()` for backwards
127
+ // compatibility, while allowing this method to be exposed via the messenger
128
+ // using the `MESSENGER_EXPOSED_METHODS` array.
129
+ super.stopAllPolling();
130
+ }
131
+ }
132
+ exports.ConfigRegistryController = ConfigRegistryController;
133
+ _ConfigRegistryController_instances = new WeakSet(), _ConfigRegistryController_setupEventListeners = function _ConfigRegistryController_setupEventListeners() {
134
+ this.messenger.subscribe('KeyringController:unlock', __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_onUnlock).bind(this));
135
+ this.messenger.subscribe('KeyringController:lock', __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_onLock).bind(this));
136
+ this.messenger.subscribe('RemoteFeatureFlagController:stateChange', __classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_onFeatureFlagChange).bind(this), (stateSelector) => stateSelector.remoteFeatureFlags[FEATURE_FLAG_KEY]);
137
+ }, _ConfigRegistryController_onUnlock = function _ConfigRegistryController_onUnlock() {
138
+ if (__classPrivateFieldGet(this, _ConfigRegistryController_instances, "m", _ConfigRegistryController_isFeatureFlagEnabled).call(this)) {
139
+ this.startPolling(null);
140
+ }
141
+ }, _ConfigRegistryController_onLock = function _ConfigRegistryController_onLock() {
142
+ this.stopAllPolling();
143
+ }, _ConfigRegistryController_onFeatureFlagChange = function _ConfigRegistryController_onFeatureFlagChange(featureFlagValue) {
144
+ const { isUnlocked } = this.messenger.call('KeyringController:getState');
145
+ if (typeof featureFlagValue === 'boolean' &&
146
+ featureFlagValue &&
147
+ isUnlocked) {
148
+ this.startPolling(null);
149
+ }
150
+ else {
151
+ this.stopAllPolling();
152
+ }
153
+ }, _ConfigRegistryController_isFeatureFlagEnabled = function _ConfigRegistryController_isFeatureFlagEnabled() {
154
+ const featureFlagValue = this.messenger.call('RemoteFeatureFlagController:getState').remoteFeatureFlags[FEATURE_FLAG_KEY];
155
+ if (typeof featureFlagValue !== 'boolean') {
156
+ return false;
157
+ }
158
+ return featureFlagValue;
159
+ };
160
+ //# sourceMappingURL=ConfigRegistryController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController.cjs","sourceRoot":"","sources":["../src/ConfigRegistryController.ts"],"names":[],"mappings":";;;;;;;;;AAWA,qEAA+E;AAG/E,2CAA8E;AAM9E,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAErC,QAAA,wBAAwB,GAAG,IAAA,sBAAc,EAAC,CAAC,EAAE,gBAAQ,CAAC,GAAG,CAAC,CAAC;AAExE,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAwCpD,MAAM,aAAa,GAAG;IACpB,OAAO,EAAE;QACP,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,KAAK;QACzB,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,OAAO,EAAE;QACP,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,IAAI;QACxB,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,IAAI;QACxB,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,KAAK;QACzB,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;CACqD,CAAC;AAEzD;;GAEG;AACH,MAAM,uBAAuB,GAA0C,EAAE,CAAC;AAE1E,MAAM,yBAAyB,GAAG;IAChC,cAAc;IACd,aAAa;IACb,gCAAgC;CACxB,CAAC;AAmEX,MAAa,wBAAyB,SAAQ,IAAA,oDAA+B,GAI5E;I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ateMetadata,\n} from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { RemoteFeatureFlagControllerStateChangeEvent } from '@metamask/remote-feature-flag-controller';\nimport { CaipChainId, Duration, inMilliseconds, Json } from '@metamask/utils';\n\nimport type { ConfigRegistryApiServiceFetchConfigAction } from './config-registry-api-service/config-registry-api-service-method-action-types.js';\nimport type { RegistryNetworkConfig } from './config-registry-api-service/types.js';\nimport type { ConfigRegistryControllerMethodActions } from './ConfigRegistryController-method-action-types.js';\n\nconst controllerName = 'ConfigRegistryController';\n\nexport const DEFAULT_POLLING_INTERVAL = inMilliseconds(1, Duration.Day);\n\nconst FEATURE_FLAG_KEY = 'configRegistryApiEnabled';\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<CaipChainId, 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\nconst MESSENGER_EXPOSED_METHODS = [\n 'startPolling',\n 'stopPolling',\n 'getNetworkConfigByCaip2ChainId',\n] as const;\n\n/**\n * Published when the state of {@link ConfigRegistryController} changes.\n */\nexport type ConfigRegistryControllerStateChangedEvent =\n ControllerStateChangedEvent<\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 * Actions that {@link ConfigRegistryControllerMessenger} exposes to other consumers.\n */\nexport type ConfigRegistryControllerActions =\n | ConfigRegistryControllerGetStateAction\n | ConfigRegistryControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryControllerMessenger}\n * calls.\n */\ntype AllowedActions =\n | KeyringControllerGetStateAction\n | RemoteFeatureFlagControllerGetStateAction\n | ConfigRegistryApiServiceFetchConfigAction;\n\n/**\n * Events that {@link ConfigRegistryControllerMessenger} exposes to other consumers.\n */\nexport type ConfigRegistryControllerEvents =\n ConfigRegistryControllerStateChangedEvent;\n\n/**\n * Events from other messengers that {@link ConfigRegistryControllerMessenger}\n * subscribes to.\n */\ntype AllowedEvents =\n | KeyringControllerUnlockEvent\n | KeyringControllerLockEvent\n | RemoteFeatureFlagControllerStateChangeEvent;\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\nexport type ConfigRegistryControllerOptions = {\n messenger: ConfigRegistryControllerMessenger;\n state?: Partial<ConfigRegistryControllerState>;\n pollingInterval?: number;\n fallbackConfig?: Record<string, RegistryNetworkConfig>;\n};\n\nexport class ConfigRegistryController extends StaticIntervalPollingController<null>()<\n typeof controllerName,\n ConfigRegistryControllerState,\n ConfigRegistryControllerMessenger\n> {\n /**\n * @param options - The controller options.\n * @param options.messenger - The controller messenger. Must have\n * `ConfigRegistryApiService:fetchConfig` action handler registered\n * (e.g. by instantiating {@link ConfigRegistryApiService} with the same\n * messenger).\n * @param options.state - Initial state.\n * @param options.pollingInterval - Polling interval in milliseconds.\n * @param options.fallbackConfig - Fallback configuration.\n */\n constructor({\n messenger,\n state = {},\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n fallbackConfig = DEFAULT_FALLBACK_CONFIG,\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\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n this.#setupEventListeners();\n }\n\n /**\n * Get the network configuration for a given CAIP-2 chain ID.\n *\n * @param caip2ChainId - The CAIP-2 chain ID (e.g., \"eip155:1\").\n * @returns The network configuration if found, otherwise undefined.\n */\n getNetworkConfigByCaip2ChainId(\n caip2ChainId: CaipChainId,\n ): RegistryNetworkConfig | undefined {\n return this.state.configs.networks[caip2ChainId];\n }\n\n async _executePoll(_input: null): Promise<void> {\n try {\n const result = 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 state.etag = result.etag ?? null;\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 /**\n * Stop all polling.\n */\n stopPolling(): void {\n // This is a wrapper around `super.stopAllPolling()` for backwards\n // compatibility, while allowing this method to be exposed via the messenger\n // using the `MESSENGER_EXPOSED_METHODS` array.\n super.stopAllPolling();\n }\n\n /**\n * Setup messenger event listeners necessary for the controller lifecycle\n */\n #setupEventListeners(): void {\n this.messenger.subscribe(\n 'KeyringController:unlock',\n this.#onUnlock.bind(this),\n );\n\n this.messenger.subscribe('KeyringController:lock', this.#onLock.bind(this));\n\n this.messenger.subscribe(\n 'RemoteFeatureFlagController:stateChange',\n this.#onFeatureFlagChange.bind(this),\n (stateSelector) => stateSelector.remoteFeatureFlags[FEATURE_FLAG_KEY],\n );\n }\n\n /**\n * Handle wallet unlock event by starting polling if the config registry API is enabled.\n */\n #onUnlock(): void {\n if (this.#isFeatureFlagEnabled()) {\n this.startPolling(null);\n }\n }\n\n /**\n * Handle wallet lock event by stopping all polling to prevent unnecessary API calls.\n */\n #onLock(): void {\n this.stopAllPolling();\n }\n\n /**\n * Handle changes to the config registry API feature flag by\n * starting or stopping polling accordingly.\n *\n * @param featureFlagValue - The new value of the feature flag.\n */\n #onFeatureFlagChange(featureFlagValue: Json): void {\n const { isUnlocked } = this.messenger.call('KeyringController:getState');\n\n if (\n typeof featureFlagValue === 'boolean' &&\n featureFlagValue &&\n isUnlocked\n ) {\n this.startPolling(null);\n } else {\n this.stopAllPolling();\n }\n }\n\n /**\n * Get the current status of the config registry feature flag.\n *\n * @returns Whether the config registry API is enabled.\n */\n #isFeatureFlagEnabled(): boolean {\n const featureFlagValue = this.messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags[FEATURE_FLAG_KEY];\n\n if (typeof featureFlagValue !== 'boolean') {\n return false;\n }\n\n return featureFlagValue;\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
- import type { ControllerGetStateAction, ControllerStateChangedEvent } from '@metamask/base-controller';
2
- import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from '@metamask/keyring-controller';
3
- import type { Messenger } from '@metamask/messenger';
4
- import type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';
5
- import type { RemoteFeatureFlagControllerStateChangeEvent } from '@metamask/remote-feature-flag-controller';
6
- import { CaipChainId } from '@metamask/utils';
7
- import type { ConfigRegistryApiServiceFetchConfigAction } from './config-registry-api-service/config-registry-api-service-method-action-types.js';
8
- import type { RegistryNetworkConfig } from './config-registry-api-service/types.js';
9
- import type { ConfigRegistryControllerMethodActions } from './ConfigRegistryController-method-action-types.js';
1
+ import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
2
+ import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
5
+ import type { RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller";
6
+ import { CaipChainId } from "@metamask/utils";
7
+ import type { ConfigRegistryApiServiceFetchConfigAction } from "./config-registry-api-service/config-registry-api-service-method-action-types.cjs";
8
+ import type { RegistryNetworkConfig } from "./config-registry-api-service/types.cjs";
9
+ import type { ConfigRegistryControllerMethodActions } from "./ConfigRegistryController-method-action-types.cjs";
10
10
  declare const controllerName = "ConfigRegistryController";
11
11
  export declare const DEFAULT_POLLING_INTERVAL: number;
12
12
  /**
@@ -84,18 +84,18 @@ export type ConfigRegistryControllerOptions = {
84
84
  fallbackConfig?: Record<string, RegistryNetworkConfig>;
85
85
  };
86
86
  declare const ConfigRegistryController_base: (abstract new (...args: any[]) => {
87
- readonly _callbacks: Map<string, Set<(input: null) => void>>;
87
+ readonly "__#6@#intervalIds": Record<string, NodeJS.Timeout>;
88
+ "__#6@#intervalLength": number | undefined;
89
+ setIntervalLength(intervalLength: number): void;
90
+ getIntervalLength(): number | undefined;
91
+ _startPolling(input: null): void;
92
+ _stopPollingByPollingTokenSetId(key: string): void;
93
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
94
+ readonly "__#3@#callbacks": Map<string, Set<(input: null) => void>>;
88
95
  _executePoll(input: null): Promise<void>;
89
96
  startPolling(input: null): string;
90
97
  stopAllPolling(): void;
91
98
  stopPollingByPollingToken(pollingToken: string): void;
92
- readonly _intervalIds: Record<import("@metamask/polling-controller").PollingTokenSetId, NodeJS.Timeout>;
93
- _intervalLength: number | undefined;
94
- setIntervalLength(intervalLength: number): void;
95
- getIntervalLength(): number | undefined;
96
- _startPolling(input: null): void;
97
- _stopPollingByPollingTokenSetId(key: import("@metamask/polling-controller").PollingTokenSetId): void;
98
- readonly _pollingTokenSets: Map<import("@metamask/polling-controller").PollingTokenSetId, Set<string>>;
99
99
  onPollingComplete(input: null, callback: (input: null) => void): void;
100
100
  }) & typeof import("@metamask/base-controller").BaseController;
101
101
  export declare class ConfigRegistryController extends ConfigRegistryController_base<typeof controllerName, ConfigRegistryControllerState, ConfigRegistryControllerMessenger> {
@@ -125,4 +125,4 @@ export declare class ConfigRegistryController extends ConfigRegistryController_b
125
125
  stopPolling(): void;
126
126
  }
127
127
  export {};
128
- //# sourceMappingURL=ConfigRegistryController.d.ts.map
128
+ //# sourceMappingURL=ConfigRegistryController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController.d.cts","sourceRoot":"","sources":["../src/ConfigRegistryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,yCAAyC,EAAE,iDAAiD;AAC1G,OAAO,KAAK,EAAE,2CAA2C,EAAE,iDAAiD;AAC5G,OAAO,EAAE,WAAW,EAAkC,wBAAwB;AAE9E,OAAO,KAAK,EAAE,yCAAyC,EAAE,0FAAyF;AAClJ,OAAO,KAAK,EAAE,qBAAqB,EAAE,gDAA+C;AACpF,OAAO,KAAK,EAAE,qCAAqC,EAAE,2DAA0D;AAE/G,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAElD,eAAO,MAAM,wBAAwB,QAAkC,CAAC;AAIxE;;;;;GAKG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;;OAIG;IACH,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC;KACtD,CAAC;IACF;;;;;OAKG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;OAGG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAC;AAwCF;;GAEG;AACH,MAAM,MAAM,yCAAyC,GACnD,2BAA2B,CACzB,OAAO,cAAc,EACrB,6BAA6B,CAC9B,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,wBAAwB,CAC3E,OAAO,cAAc,EACrB,6BAA6B,CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACvC,sCAAsC,GACtC,qCAAqC,CAAC;AAE1C;;;GAGG;AACH,KAAK,cAAc,GACf,+BAA+B,GAC/B,yCAAyC,GACzC,yCAAyC,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACxC,yCAAyC,CAAC;AAE5C;;;GAGG;AACH,KAAK,aAAa,GACd,4BAA4B,GAC5B,0BAA0B,GAC1B,2CAA2C,CAAC;AAEhD;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,cAAc,EACrB,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,SAAS,EAAE,iCAAiC,CAAC;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAC/C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CACxD,CAAC;;;;;;;;;;;;;;;;AAEF,qBAAa,wBAAyB,SAAQ,8BAC5C,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;IACC;;;;;;;;;OASG;gBACS,EACV,SAAS,EACT,KAAU,EACV,eAA0C,EAC1C,cAAwC,GACzC,EAAE,+BAA+B;IAwBlC;;;;;OAKG;IACH,8BAA8B,CAC5B,YAAY,EAAE,WAAW,GACxB,qBAAqB,GAAG,SAAS;IAI9B,YAAY,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAyC/C;;OAEG;IACH,WAAW,IAAI,IAAI;CA6EpB"}
@@ -0,0 +1,128 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
2
+ import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
5
+ import type { RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller";
6
+ import { CaipChainId } from "@metamask/utils";
7
+ import type { ConfigRegistryApiServiceFetchConfigAction } from "./config-registry-api-service/config-registry-api-service-method-action-types.mjs";
8
+ import type { RegistryNetworkConfig } from "./config-registry-api-service/types.mjs";
9
+ import type { ConfigRegistryControllerMethodActions } from "./ConfigRegistryController-method-action-types.mjs";
10
+ declare const controllerName = "ConfigRegistryController";
11
+ export declare const DEFAULT_POLLING_INTERVAL: number;
12
+ /**
13
+ * State for the ConfigRegistryController.
14
+ *
15
+ * Tracks network configurations fetched from the config registry API,
16
+ * along with metadata about the fetch status and caching.
17
+ */
18
+ export type ConfigRegistryControllerState = {
19
+ /**
20
+ * Network configurations organized by chain ID.
21
+ * Stores the full API response including isFeatured, isTestnet, etc.
22
+ * Use selectors (e.g. selectFeaturedNetworks) to filter when needed.
23
+ */
24
+ configs: {
25
+ networks: Record<CaipChainId, RegistryNetworkConfig>;
26
+ };
27
+ /**
28
+ * Semantic version string of the configuration data from the API.
29
+ * Indicates the version/schema of the configuration structure itself
30
+ * (e.g., "v1.0.0", "1.0.0").
31
+ * This is different from `etag` which is used for HTTP cache validation.
32
+ */
33
+ version: string | null;
34
+ /**
35
+ * Timestamp (milliseconds since epoch) of when the configuration
36
+ * was last successfully fetched from the API.
37
+ */
38
+ lastFetched: number | null;
39
+ /**
40
+ * HTTP entity tag (ETag) used for cache validation.
41
+ * Sent as `If-None-Match` header in subsequent requests to check
42
+ * if the content has changed. If the server returns 304 Not Modified,
43
+ * the full response body is not downloaded, improving efficiency.
44
+ * This is different from `version` which is a semantic version string
45
+ * indicating the schema/version of the configuration data itself.
46
+ */
47
+ etag: string | null;
48
+ };
49
+ /**
50
+ * Published when the state of {@link ConfigRegistryController} changes.
51
+ */
52
+ export type ConfigRegistryControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, ConfigRegistryControllerState>;
53
+ /**
54
+ * Retrieves the state of the {@link ConfigRegistryController}.
55
+ */
56
+ export type ConfigRegistryControllerGetStateAction = ControllerGetStateAction<typeof controllerName, ConfigRegistryControllerState>;
57
+ /**
58
+ * Actions that {@link ConfigRegistryControllerMessenger} exposes to other consumers.
59
+ */
60
+ export type ConfigRegistryControllerActions = ConfigRegistryControllerGetStateAction | ConfigRegistryControllerMethodActions;
61
+ /**
62
+ * Actions from other messengers that {@link ConfigRegistryControllerMessenger}
63
+ * calls.
64
+ */
65
+ type AllowedActions = KeyringControllerGetStateAction | RemoteFeatureFlagControllerGetStateAction | ConfigRegistryApiServiceFetchConfigAction;
66
+ /**
67
+ * Events that {@link ConfigRegistryControllerMessenger} exposes to other consumers.
68
+ */
69
+ export type ConfigRegistryControllerEvents = ConfigRegistryControllerStateChangedEvent;
70
+ /**
71
+ * Events from other messengers that {@link ConfigRegistryControllerMessenger}
72
+ * subscribes to.
73
+ */
74
+ type AllowedEvents = KeyringControllerUnlockEvent | KeyringControllerLockEvent | RemoteFeatureFlagControllerStateChangeEvent;
75
+ /**
76
+ * The messenger restricted to actions and events accessed by
77
+ * {@link ConfigRegistryController}.
78
+ */
79
+ export type ConfigRegistryControllerMessenger = Messenger<typeof controllerName, ConfigRegistryControllerActions | AllowedActions, ConfigRegistryControllerEvents | AllowedEvents>;
80
+ export type ConfigRegistryControllerOptions = {
81
+ messenger: ConfigRegistryControllerMessenger;
82
+ state?: Partial<ConfigRegistryControllerState>;
83
+ pollingInterval?: number;
84
+ fallbackConfig?: Record<string, RegistryNetworkConfig>;
85
+ };
86
+ declare const ConfigRegistryController_base: (abstract new (...args: any[]) => {
87
+ readonly "__#6@#intervalIds": Record<string, NodeJS.Timeout>;
88
+ "__#6@#intervalLength": number | undefined;
89
+ setIntervalLength(intervalLength: number): void;
90
+ getIntervalLength(): number | undefined;
91
+ _startPolling(input: null): void;
92
+ _stopPollingByPollingTokenSetId(key: string): void;
93
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
94
+ readonly "__#3@#callbacks": Map<string, Set<(input: null) => void>>;
95
+ _executePoll(input: null): Promise<void>;
96
+ startPolling(input: null): string;
97
+ stopAllPolling(): void;
98
+ stopPollingByPollingToken(pollingToken: string): void;
99
+ onPollingComplete(input: null, callback: (input: null) => void): void;
100
+ }) & typeof import("@metamask/base-controller").BaseController;
101
+ export declare class ConfigRegistryController extends ConfigRegistryController_base<typeof controllerName, ConfigRegistryControllerState, ConfigRegistryControllerMessenger> {
102
+ #private;
103
+ /**
104
+ * @param options - The controller options.
105
+ * @param options.messenger - The controller messenger. Must have
106
+ * `ConfigRegistryApiService:fetchConfig` action handler registered
107
+ * (e.g. by instantiating {@link ConfigRegistryApiService} with the same
108
+ * messenger).
109
+ * @param options.state - Initial state.
110
+ * @param options.pollingInterval - Polling interval in milliseconds.
111
+ * @param options.fallbackConfig - Fallback configuration.
112
+ */
113
+ constructor({ messenger, state, pollingInterval, fallbackConfig, }: ConfigRegistryControllerOptions);
114
+ /**
115
+ * Get the network configuration for a given CAIP-2 chain ID.
116
+ *
117
+ * @param caip2ChainId - The CAIP-2 chain ID (e.g., "eip155:1").
118
+ * @returns The network configuration if found, otherwise undefined.
119
+ */
120
+ getNetworkConfigByCaip2ChainId(caip2ChainId: CaipChainId): RegistryNetworkConfig | undefined;
121
+ _executePoll(_input: null): Promise<void>;
122
+ /**
123
+ * Stop all polling.
124
+ */
125
+ stopPolling(): void;
126
+ }
127
+ export {};
128
+ //# sourceMappingURL=ConfigRegistryController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController.d.mts","sourceRoot":"","sources":["../src/ConfigRegistryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,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BAA4B,GAC5B,0BAA0B,GAC1B,2CAA2C,CAAC;AAEhD;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,cAAc,EACrB,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,SAAS,EAAE,iCAAiC,CAAC;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAC/C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CACxD,CAAC;;;;;;;;;;;;;;;;AAEF,qBAAa,wBAAyB,SAAQ,8BAC5C,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;IACC;;;;;;;;;OASG;gBACS,EACV,SAAS,EACT,KAAU,EACV,eAA0C,EAC1C,cAAwC,GACzC,EAAE,+BAA+B;IAwBlC;;;;;OAKG;IACH,8BAA8B,CAC5B,YAAY,EAAE,WAAW,GACxB,qBAAqB,GAAG,SAAS;IAI9B,YAAY,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAyC/C;;OAEG;IACH,WAAW,IAAI,IAAI;CA6EpB"}
@@ -4,8 +4,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _ConfigRegistryController_instances, _ConfigRegistryController_setupEventListeners, _ConfigRegistryController_onUnlock, _ConfigRegistryController_onLock, _ConfigRegistryController_onFeatureFlagChange, _ConfigRegistryController_isFeatureFlagEnabled;
7
- import { StaticIntervalPollingController } from '@metamask/polling-controller';
8
- import { Duration, inMilliseconds } from '@metamask/utils';
7
+ import { StaticIntervalPollingController } from "@metamask/polling-controller";
8
+ import { Duration, inMilliseconds } from "@metamask/utils";
9
9
  const controllerName = 'ConfigRegistryController';
10
10
  export const DEFAULT_POLLING_INTERVAL = inMilliseconds(1, Duration.Day);
11
11
  const FEATURE_FLAG_KEY = 'configRegistryApiEnabled';
@@ -153,4 +153,4 @@ _ConfigRegistryController_instances = new WeakSet(), _ConfigRegistryController_s
153
153
  }
154
154
  return featureFlagValue;
155
155
  };
156
- //# sourceMappingURL=ConfigRegistryController.js.map
156
+ //# sourceMappingURL=ConfigRegistryController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigRegistryController.mjs","sourceRoot":"","sources":["../src/ConfigRegistryController.ts"],"names":[],"mappings":";;;;;;AAWA,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAG/E,OAAO,EAAe,QAAQ,EAAE,cAAc,EAAQ,wBAAwB;AAM9E,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;AAExE,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAwCpD,MAAM,aAAa,GAAG;IACpB,OAAO,EAAE;QACP,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,KAAK;QACzB,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,OAAO,EAAE;QACP,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,IAAI;QACxB,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,IAAI;QACxB,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,KAAK;QACzB,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;CACqD,CAAC;AAEzD;;GAEG;AACH,MAAM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AS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { RemoteFeatureFlagControllerStateChangeEvent } from '@metamask/remote-feature-flag-controller';\nimport { CaipChainId, Duration, inMilliseconds, Json } from '@metamask/utils';\n\nimport type { ConfigRegistryApiServiceFetchConfigAction } from './config-registry-api-service/config-registry-api-service-method-action-types.js';\nimport type { RegistryNetworkConfig } from './config-registry-api-service/types.js';\nimport type { ConfigRegistryControllerMethodActions } from './ConfigRegistryController-method-action-types.js';\n\nconst controllerName = 'ConfigRegistryController';\n\nexport const DEFAULT_POLLING_INTERVAL = inMilliseconds(1, Duration.Day);\n\nconst FEATURE_FLAG_KEY = 'configRegistryApiEnabled';\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<CaipChainId, 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\nconst MESSENGER_EXPOSED_METHODS = [\n 'startPolling',\n 'stopPolling',\n 'getNetworkConfigByCaip2ChainId',\n] as const;\n\n/**\n * Published when the state of {@link ConfigRegistryController} changes.\n */\nexport type ConfigRegistryControllerStateChangedEvent =\n ControllerStateChangedEvent<\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 * Actions that {@link ConfigRegistryControllerMessenger} exposes to other consumers.\n */\nexport type ConfigRegistryControllerActions =\n | ConfigRegistryControllerGetStateAction\n | ConfigRegistryControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ConfigRegistryControllerMessenger}\n * calls.\n */\ntype AllowedActions =\n | KeyringControllerGetStateAction\n | RemoteFeatureFlagControllerGetStateAction\n | ConfigRegistryApiServiceFetchConfigAction;\n\n/**\n * Events that {@link ConfigRegistryControllerMessenger} exposes to other consumers.\n */\nexport type ConfigRegistryControllerEvents =\n ConfigRegistryControllerStateChangedEvent;\n\n/**\n * Events from other messengers that {@link ConfigRegistryControllerMessenger}\n * subscribes to.\n */\ntype AllowedEvents =\n | KeyringControllerUnlockEvent\n | KeyringControllerLockEvent\n | RemoteFeatureFlagControllerStateChangeEvent;\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\nexport type ConfigRegistryControllerOptions = {\n messenger: ConfigRegistryControllerMessenger;\n state?: Partial<ConfigRegistryControllerState>;\n pollingInterval?: number;\n fallbackConfig?: Record<string, RegistryNetworkConfig>;\n};\n\nexport class ConfigRegistryController extends StaticIntervalPollingController<null>()<\n typeof controllerName,\n ConfigRegistryControllerState,\n ConfigRegistryControllerMessenger\n> {\n /**\n * @param options - The controller options.\n * @param options.messenger - The controller messenger. Must have\n * `ConfigRegistryApiService:fetchConfig` action handler registered\n * (e.g. by instantiating {@link ConfigRegistryApiService} with the same\n * messenger).\n * @param options.state - Initial state.\n * @param options.pollingInterval - Polling interval in milliseconds.\n * @param options.fallbackConfig - Fallback configuration.\n */\n constructor({\n messenger,\n state = {},\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n fallbackConfig = DEFAULT_FALLBACK_CONFIG,\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\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n this.#setupEventListeners();\n }\n\n /**\n * Get the network configuration for a given CAIP-2 chain ID.\n *\n * @param caip2ChainId - The CAIP-2 chain ID (e.g., \"eip155:1\").\n * @returns The network configuration if found, otherwise undefined.\n */\n getNetworkConfigByCaip2ChainId(\n caip2ChainId: CaipChainId,\n ): RegistryNetworkConfig | undefined {\n return this.state.configs.networks[caip2ChainId];\n }\n\n async _executePoll(_input: null): Promise<void> {\n try {\n const result = 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 state.etag = result.etag ?? null;\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 /**\n * Stop all polling.\n */\n stopPolling(): void {\n // This is a wrapper around `super.stopAllPolling()` for backwards\n // compatibility, while allowing this method to be exposed via the messenger\n // using the `MESSENGER_EXPOSED_METHODS` array.\n super.stopAllPolling();\n }\n\n /**\n * Setup messenger event listeners necessary for the controller lifecycle\n */\n #setupEventListeners(): void {\n this.messenger.subscribe(\n 'KeyringController:unlock',\n this.#onUnlock.bind(this),\n );\n\n this.messenger.subscribe('KeyringController:lock', this.#onLock.bind(this));\n\n this.messenger.subscribe(\n 'RemoteFeatureFlagController:stateChange',\n this.#onFeatureFlagChange.bind(this),\n (stateSelector) => stateSelector.remoteFeatureFlags[FEATURE_FLAG_KEY],\n );\n }\n\n /**\n * Handle wallet unlock event by starting polling if the config registry API is enabled.\n */\n #onUnlock(): void {\n if (this.#isFeatureFlagEnabled()) {\n this.startPolling(null);\n }\n }\n\n /**\n * Handle wallet lock event by stopping all polling to prevent unnecessary API calls.\n */\n #onLock(): void {\n this.stopAllPolling();\n }\n\n /**\n * Handle changes to the config registry API feature flag by\n * starting or stopping polling accordingly.\n *\n * @param featureFlagValue - The new value of the feature flag.\n */\n #onFeatureFlagChange(featureFlagValue: Json): void {\n const { isUnlocked } = this.messenger.call('KeyringController:getState');\n\n if (\n typeof featureFlagValue === 'boolean' &&\n featureFlagValue &&\n isUnlocked\n ) {\n this.startPolling(null);\n } else {\n this.stopAllPolling();\n }\n }\n\n /**\n * Get the current status of the config registry feature flag.\n *\n * @returns Whether the config registry API is enabled.\n */\n #isFeatureFlagEnabled(): boolean {\n const featureFlagValue = this.messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags[FEATURE_FLAG_KEY];\n\n if (typeof featureFlagValue !== 'boolean') {\n return false;\n }\n\n return featureFlagValue;\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=config-registry-api-service-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-registry-api-service-method-action-types.cjs","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ConfigRegistryApiService } from './config-registry-api-service.js';\n\nexport type ConfigRegistryApiServiceFetchConfigAction = {\n type: `ConfigRegistryApiService:fetchConfig`;\n handler: ConfigRegistryApiService['fetchConfig'];\n};\n\n/**\n * Union of all ConfigRegistryApiService action types.\n */\nexport type ConfigRegistryApiServiceMethodActions =\n ConfigRegistryApiServiceFetchConfigAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { ConfigRegistryApiService } from './config-registry-api-service.js';
5
+ import type { ConfigRegistryApiService } from "./config-registry-api-service.cjs";
6
6
  export type ConfigRegistryApiServiceFetchConfigAction = {
7
7
  type: `ConfigRegistryApiService:fetchConfig`;
8
8
  handler: ConfigRegistryApiService['fetchConfig'];
@@ -11,4 +11,4 @@ export type ConfigRegistryApiServiceFetchConfigAction = {
11
11
  * Union of all ConfigRegistryApiService action types.
12
12
  */
13
13
  export type ConfigRegistryApiServiceMethodActions = ConfigRegistryApiServiceFetchConfigAction;
14
- //# sourceMappingURL=config-registry-api-service-method-action-types.d.ts.map
14
+ //# sourceMappingURL=config-registry-api-service-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-registry-api-service-method-action-types.d.cts","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAAyC;AAEjF,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,wBAAwB,CAAC,aAAa,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,yCAAyC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ConfigRegistryApiService } from "./config-registry-api-service.mjs";
6
+ export type ConfigRegistryApiServiceFetchConfigAction = {
7
+ type: `ConfigRegistryApiService:fetchConfig`;
8
+ handler: ConfigRegistryApiService['fetchConfig'];
9
+ };
10
+ /**
11
+ * Union of all ConfigRegistryApiService action types.
12
+ */
13
+ export type ConfigRegistryApiServiceMethodActions = ConfigRegistryApiServiceFetchConfigAction;
14
+ //# sourceMappingURL=config-registry-api-service-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-registry-api-service-method-action-types.d.mts","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAAyC;AAEjF,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,wBAAwB,CAAC,aAAa,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,yCAAyC,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=config-registry-api-service-method-action-types.js.map
6
+ //# sourceMappingURL=config-registry-api-service-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-registry-api-service-method-action-types.mjs","sourceRoot":"","sources":["../../src/config-registry-api-service/config-registry-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ConfigRegistryApiService } from './config-registry-api-service.js';\n\nexport type ConfigRegistryApiServiceFetchConfigAction = {\n type: `ConfigRegistryApiService:fetchConfig`;\n handler: ConfigRegistryApiService['fetchConfig'];\n};\n\n/**\n * Union of all ConfigRegistryApiService action types.\n */\nexport type ConfigRegistryApiServiceMethodActions =\n ConfigRegistryApiServiceFetchConfigAction;\n"]}