@metamask-previews/network-controller 34.0.0-preview-e0e795054 → 34.0.0-preview-0d2cbf546

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,8 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Add required `analyticsOptions` constructor option that makes `NetworkController` emit `RPC Service Unavailable` and `RPC Service Degraded` analytics events via the `AnalyticsController:trackEvent` action when an RPC endpoint becomes unavailable or degraded ([#9270](https://github.com/MetaMask/core/pull/9270))
13
+ - The option takes `isRpcEndpointUrlPublic` (decides whether an endpoint URL is safe to report verbatim or as `'custom'`) and `rpcServiceEventsSampleRate` (the proportion of events to emit, between `0` and `1`).
14
+ - Adds the `NetworkControllerAnalyticsOptions` and `RpcServiceEventName` types.
15
+
10
16
  ### Changed
11
17
 
18
+ - **BREAKING:** `NetworkControllerMessenger` now requires the `AnalyticsController:getState` and `AnalyticsController:trackEvent` actions ([#9270](https://github.com/MetaMask/core/pull/9270))
19
+ - Consumers must delegate these actions to the network controller messenger and pass the new required `analyticsOptions` constructor option.
20
+
12
21
  - **BREAKING:** `BuiltInNetworkClientId` is now `string` instead of `InfuraNetworkType` ([#9432](https://github.com/MetaMask/core/pull/9432))
13
22
  - This type was previously constrained to known Infura network names (e.g. `"mainnet"`, `"sepolia"`). It is now `string` to allow dynamically configured Infura networks whose names are not bundled into the package.
14
23
  - If you have code that narrows on `BuiltInNetworkClientId`, you will need to remove the narrowing or check the network client type via `NetworkClientType` instead.
@@ -30,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
39
  - **BREAKING:** Drive RPC failover from the single `corePlatformRpcFailoverMode` remote feature flag ([#9175](https://github.com/MetaMask/core/pull/9175))
31
40
  - The flag is a string with three values: `disabled` (failover off), `enabled` (divert to failover URLs when the primary endpoint is unavailable), and `forced` (Infura endpoints that have failover URLs route all traffic to those URLs, bypassing Infura entirely). Custom endpoints are unaffected, and the value defaults to `disabled` when the flag is absent or unrecognized.
32
41
  - `NetworkController` no longer reads the `walletFrameworkRpcFailoverEnabled` flag; the `enabled` mode replaces it. Update your remote feature flag configuration to set `corePlatformRpcFailoverMode`.
42
+ - **BREAKING:** The `NetworkControllerMessenger` now allows the `AnalyticsController:getState` and `AnalyticsController:trackEvent` actions ([#9270](https://github.com/MetaMask/core/pull/9270))
43
+ - Consumers that pass the `analytics` option must delegate these actions to the network controller messenger.
33
44
 
34
45
  ### Removed
35
46
 
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_failoverUrls, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_rpcFailoverMode, _NetworkController_updateRpcFailover, _NetworkController_refreshNetwork, _NetworkController_determineNetworkMetadata, _NetworkController_lookupGivenNetwork, _NetworkController_lookupSelectedNetwork, _NetworkController_updateMetadataForNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
39
+ var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_failoverUrls, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_analyticsOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_rpcFailoverMode, _NetworkController_updateRpcFailover, _NetworkController_refreshNetwork, _NetworkController_determineNetworkMetadata, _NetworkController_lookupGivenNetwork, _NetworkController_lookupSelectedNetwork, _NetworkController_updateMetadataForNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.NetworkController = exports.selectAvailableNetworkClientIds = exports.getAvailableNetworkClientIds = exports.selectNetworkConfigurations = exports.getNetworkConfigurations = exports.getDefaultNetworkControllerState = exports.knownKeysOf = exports.RpcEndpointType = void 0;
42
42
  const base_controller_1 = require("@metamask/base-controller");
@@ -54,6 +54,7 @@ const uuid_1 = require("uuid");
54
54
  const constants_1 = require("./constants.cjs");
55
55
  const create_auto_managed_network_client_1 = require("./create-auto-managed-network-client.cjs");
56
56
  const logger_1 = require("./logger.cjs");
57
+ const rpc_service_analytics_1 = require("./rpc-service-analytics.cjs");
57
58
  const selectors_1 = require("./selectors.cjs");
58
59
  const types_1 = require("./types.cjs");
59
60
  const debugLog = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'NetworkController');
@@ -387,7 +388,7 @@ class NetworkController extends base_controller_1.BaseController {
387
388
  * @param options - The options; see {@link NetworkControllerOptions}.
388
389
  */
389
390
  constructor(options) {
390
- const { messenger, state, infuraProjectId, failoverUrls, log, getRpcServiceOptions, getBlockTrackerOptions, } = options;
391
+ const { messenger, state, infuraProjectId, failoverUrls, log, getRpcServiceOptions, getBlockTrackerOptions, analyticsOptions, } = options;
391
392
  const initialState = {
392
393
  ...getDefaultNetworkControllerState(),
393
394
  ...state,
@@ -434,6 +435,7 @@ class NetworkController extends base_controller_1.BaseController {
434
435
  _NetworkController_log.set(this, void 0);
435
436
  _NetworkController_getRpcServiceOptions.set(this, void 0);
436
437
  _NetworkController_getBlockTrackerOptions.set(this, void 0);
438
+ _NetworkController_analyticsOptions.set(this, void 0);
437
439
  _NetworkController_networkConfigurationsByNetworkClientId.set(this, void 0);
438
440
  _NetworkController_rpcFailoverMode.set(this, 'disabled');
439
441
  __classPrivateFieldSet(this, _NetworkController_infuraProjectId, infuraProjectId, "f");
@@ -441,6 +443,7 @@ class NetworkController extends base_controller_1.BaseController {
441
443
  __classPrivateFieldSet(this, _NetworkController_log, log, "f");
442
444
  __classPrivateFieldSet(this, _NetworkController_getRpcServiceOptions, getRpcServiceOptions, "f");
443
445
  __classPrivateFieldSet(this, _NetworkController_getBlockTrackerOptions, getBlockTrackerOptions, "f");
446
+ __classPrivateFieldSet(this, _NetworkController_analyticsOptions, analyticsOptions, "f");
444
447
  __classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
445
448
  __classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
446
449
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
@@ -459,6 +462,8 @@ class NetworkController extends base_controller_1.BaseController {
459
462
  networkStatus: constants_1.NetworkStatus.Available,
460
463
  });
461
464
  });
465
+ this.messenger.subscribe(`${this.name}:rpcEndpointUnavailable`, (payload) => (0, rpc_service_analytics_1.trackRpcServiceUnavailable)(this.messenger, __classPrivateFieldGet(this, _NetworkController_analyticsOptions, "f"), payload));
466
+ this.messenger.subscribe(`${this.name}:rpcEndpointDegraded`, (payload) => (0, rpc_service_analytics_1.trackRpcServiceDegraded)(this.messenger, __classPrivateFieldGet(this, _NetworkController_analyticsOptions, "f"), payload));
462
467
  this.messenger.subscribe(
463
468
  // eslint-disable-next-line no-restricted-syntax
464
469
  'RemoteFeatureFlagController:stateChange', (rpcFailoverMode) => {
@@ -1037,7 +1042,7 @@ class NetworkController extends base_controller_1.BaseController {
1037
1042
  }
1038
1043
  }
1039
1044
  exports.NetworkController = NetworkController;
1040
- _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId = new WeakMap(), _NetworkController_failoverUrls = new WeakMap(), _NetworkController_previouslySelectedNetworkClientId = new WeakMap(), _NetworkController_providerProxy = new WeakMap(), _NetworkController_blockTrackerProxy = new WeakMap(), _NetworkController_autoManagedNetworkClientRegistry = new WeakMap(), _NetworkController_autoManagedNetworkClient = new WeakMap(), _NetworkController_log = new WeakMap(), _NetworkController_getRpcServiceOptions = new WeakMap(), _NetworkController_getBlockTrackerOptions = new WeakMap(), _NetworkController_networkConfigurationsByNetworkClientId = new WeakMap(), _NetworkController_rpcFailoverMode = new WeakMap(), _NetworkController_instances = new WeakSet(), _NetworkController_updateRpcFailover = function _NetworkController_updateRpcFailover(newMode) {
1045
+ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId = new WeakMap(), _NetworkController_failoverUrls = new WeakMap(), _NetworkController_previouslySelectedNetworkClientId = new WeakMap(), _NetworkController_providerProxy = new WeakMap(), _NetworkController_blockTrackerProxy = new WeakMap(), _NetworkController_autoManagedNetworkClientRegistry = new WeakMap(), _NetworkController_autoManagedNetworkClient = new WeakMap(), _NetworkController_log = new WeakMap(), _NetworkController_getRpcServiceOptions = new WeakMap(), _NetworkController_getBlockTrackerOptions = new WeakMap(), _NetworkController_analyticsOptions = new WeakMap(), _NetworkController_networkConfigurationsByNetworkClientId = new WeakMap(), _NetworkController_rpcFailoverMode = new WeakMap(), _NetworkController_instances = new WeakSet(), _NetworkController_updateRpcFailover = function _NetworkController_updateRpcFailover(newMode) {
1041
1046
  if (__classPrivateFieldGet(this, _NetworkController_rpcFailoverMode, "f") === newMode) {
1042
1047
  return;
1043
1048
  }