@metamask/network-controller 20.2.0 → 21.0.1

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 (110) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/dist/NetworkController.cjs +1373 -0
  3. package/dist/NetworkController.cjs.map +1 -0
  4. package/dist/NetworkController.d.cts +636 -0
  5. package/dist/NetworkController.d.cts.map +1 -0
  6. package/dist/NetworkController.d.mts +636 -0
  7. package/dist/NetworkController.d.mts.map +1 -0
  8. package/dist/NetworkController.mjs +1345 -15
  9. package/dist/NetworkController.mjs.map +1 -1
  10. package/dist/constants.cjs +32 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  13. package/dist/constants.d.cts.map +1 -0
  14. package/dist/constants.d.mts +28 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +28 -9
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/create-auto-managed-network-client.cjs +134 -0
  19. package/dist/create-auto-managed-network-client.cjs.map +1 -0
  20. package/dist/{types/create-auto-managed-network-client.d.ts → create-auto-managed-network-client.d.cts} +2 -2
  21. package/dist/create-auto-managed-network-client.d.cts.map +1 -0
  22. package/dist/create-auto-managed-network-client.d.mts +47 -0
  23. package/dist/create-auto-managed-network-client.d.mts.map +1 -0
  24. package/dist/create-auto-managed-network-client.mjs +129 -9
  25. package/dist/create-auto-managed-network-client.mjs.map +1 -1
  26. package/dist/create-network-client.cjs +146 -0
  27. package/dist/create-network-client.cjs.map +1 -0
  28. package/dist/{types/create-network-client.d.ts → create-network-client.d.cts} +2 -2
  29. package/dist/create-network-client.d.cts.map +1 -0
  30. package/dist/create-network-client.d.mts +19 -0
  31. package/dist/create-network-client.d.mts.map +1 -0
  32. package/dist/create-network-client.mjs +143 -7
  33. package/dist/create-network-client.mjs.map +1 -1
  34. package/dist/index.cjs +27 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/index.d.cts +9 -0
  37. package/dist/index.d.cts.map +1 -0
  38. package/dist/index.d.mts +9 -0
  39. package/dist/index.d.mts.map +1 -0
  40. package/dist/index.mjs +3 -24
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/logger.cjs +7 -0
  43. package/dist/logger.cjs.map +1 -0
  44. package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
  45. package/dist/logger.d.cts.map +1 -0
  46. package/dist/logger.d.mts +5 -0
  47. package/dist/logger.d.mts.map +1 -0
  48. package/dist/logger.mjs +3 -9
  49. package/dist/logger.mjs.map +1 -1
  50. package/dist/types.cjs +12 -0
  51. package/dist/types.cjs.map +1 -0
  52. package/dist/{types/types.d.ts → types.d.cts} +5 -5
  53. package/dist/types.d.cts.map +1 -0
  54. package/dist/types.d.mts +41 -0
  55. package/dist/types.d.mts.map +1 -0
  56. package/dist/types.mjs +8 -7
  57. package/dist/types.mjs.map +1 -1
  58. package/package.json +21 -13
  59. package/dist/NetworkController.js +0 -17
  60. package/dist/NetworkController.js.map +0 -1
  61. package/dist/chunk-2QJYHWIP.mjs +0 -15
  62. package/dist/chunk-2QJYHWIP.mjs.map +0 -1
  63. package/dist/chunk-AU4UVIPZ.mjs +0 -11
  64. package/dist/chunk-AU4UVIPZ.mjs.map +0 -1
  65. package/dist/chunk-BEL2VMHN.js +0 -968
  66. package/dist/chunk-BEL2VMHN.js.map +0 -1
  67. package/dist/chunk-E4V6XEBR.js +0 -125
  68. package/dist/chunk-E4V6XEBR.js.map +0 -1
  69. package/dist/chunk-KHZTS7TF.js +0 -11
  70. package/dist/chunk-KHZTS7TF.js.map +0 -1
  71. package/dist/chunk-LLMZDA4Q.js +0 -99
  72. package/dist/chunk-LLMZDA4Q.js.map +0 -1
  73. package/dist/chunk-RTMQACMX.mjs +0 -968
  74. package/dist/chunk-RTMQACMX.mjs.map +0 -1
  75. package/dist/chunk-TZA3CBEI.mjs +0 -99
  76. package/dist/chunk-TZA3CBEI.mjs.map +0 -1
  77. package/dist/chunk-U43RY4MY.mjs +0 -125
  78. package/dist/chunk-U43RY4MY.mjs.map +0 -1
  79. package/dist/chunk-VGYLDDJB.js +0 -9
  80. package/dist/chunk-VGYLDDJB.js.map +0 -1
  81. package/dist/chunk-VTLOAS2R.mjs +0 -9
  82. package/dist/chunk-VTLOAS2R.mjs.map +0 -1
  83. package/dist/chunk-XUI43LEZ.mjs +0 -30
  84. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  85. package/dist/chunk-Z4BLTVTB.js +0 -30
  86. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  87. package/dist/chunk-ZKNI7MD3.js +0 -15
  88. package/dist/chunk-ZKNI7MD3.js.map +0 -1
  89. package/dist/constants.js +0 -10
  90. package/dist/constants.js.map +0 -1
  91. package/dist/create-auto-managed-network-client.js +0 -10
  92. package/dist/create-auto-managed-network-client.js.map +0 -1
  93. package/dist/create-network-client.js +0 -9
  94. package/dist/create-network-client.js.map +0 -1
  95. package/dist/index.js +0 -25
  96. package/dist/index.js.map +0 -1
  97. package/dist/logger.js +0 -10
  98. package/dist/logger.js.map +0 -1
  99. package/dist/tsconfig.build.tsbuildinfo +0 -1
  100. package/dist/types/NetworkController.d.ts +0 -405
  101. package/dist/types/NetworkController.d.ts.map +0 -1
  102. package/dist/types/constants.d.ts.map +0 -1
  103. package/dist/types/create-auto-managed-network-client.d.ts.map +0 -1
  104. package/dist/types/create-network-client.d.ts.map +0 -1
  105. package/dist/types/index.d.ts +0 -8
  106. package/dist/types/index.d.ts.map +0 -1
  107. package/dist/types/logger.d.ts.map +0 -1
  108. package/dist/types/types.d.ts.map +0 -1
  109. package/dist/types.js +0 -8
  110. package/dist/types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,77 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [21.0.1]
11
+
12
+ ### Fixed
13
+
14
+ - Produce and export ESM-compatible TypeScript type declaration files in addition to CommonJS-compatible declaration files ([#4648](https://github.com/MetaMask/core/pull/4648))
15
+ - Previously, this package shipped with only one variant of type declaration
16
+ files, and these files were only CommonJS-compatible, and the `exports`
17
+ field in `package.json` linked to these files. This is an anti-pattern and
18
+ was rightfully flagged by the
19
+ ["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as
20
+ ["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md).
21
+ All of the ATTW checks now pass.
22
+ - Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648)).
23
+ - Previously, the build tool we used to generate JavaScript files extracted
24
+ common code to "chunk" files. While this was intended to make this package
25
+ more tree-shakeable, it also made debugging more difficult for our
26
+ development teams. These chunk files are no longer present.
27
+
28
+ ## [21.0.0]
29
+
30
+ ### Added
31
+
32
+ - **BREAKING:** Add `networkConfigurationsByChainId` to `NetworkState` (type: `Record<Hex, NetworkConfiguration>`) ([#4268](https://github.com/MetaMask/core/pull/4286))
33
+ - This property replaces `networkConfigurations`, and, as its name implies, organizes network configurations by chain ID rather than network client ID.
34
+ - If no initial state or this property is not included in initial state, the default value of this property will now include configurations for known Infura networks (Mainnet, Goerli, Sepolia, Linea Goerli, Linea Sepolia, and Linea Mainnet) by default.
35
+ - Add `getNetworkConfigurationByChainId` method, `NetworkController:getNetworkConfigurationByChainId` messenger action, and `NetworkControllerGetNetworkConfigurationByNetworkClientId` type ([#4268](https://github.com/MetaMask/core/pull/4286))
36
+ - Add `addNetwork`, which replaces one half of `upsertNetworkConfiguration` and can be used to add new network clients for a chain ([#4268](https://github.com/MetaMask/core/pull/4286))
37
+ - It's worth noting that this method now publishes a `NetworkController:networkAdded` event instead of calling a `trackMetaMetricsEvent` callback. It is expected that you will subscribe to this event and create a MetaMetrics event yourself.
38
+ - Add `updateNetwork`, which replaces one half of `upsertNetworkConfiguration` and can be used to recreate the network clients for an existing chain based on an updated configuration ([#4268](https://github.com/MetaMask/core/pull/4286))
39
+ - Note that it is not possible to remove the RPC endpoint from a network configuration that is currently represented by the globally selected network client. To prevent an error, you'll need to detect when such a removal is occurring and pass the `replacementSelectedRpcEndpointIndex` to `updateNetwork`. It will then switch to the designated RPC endpoint's network client on your behalf.
40
+ - Add `removeNetwork`, which replaces `removeNetworkConfiguration` and can be used to remove existing network clients for a chain ([#4268](https://github.com/MetaMask/core/pull/4286))
41
+ - Add `getDefaultNetworkControllerState` function, which replaces `defaultState` and matches patterns in other controllers ([#4268](https://github.com/MetaMask/core/pull/4286))
42
+ - Add `RpcEndpointType`, `AddNetworkFields`, and `UpdateNetworkFields` types ([#4268](https://github.com/MetaMask/core/pull/4286))
43
+ - Add `getNetworkConfigurations`, `getAvailableNetworkClientIds` and `selectAvailableNetworkClientIds` selectors ([#4268](https://github.com/MetaMask/core/pull/4286))
44
+ - These new selectors can be applied to messenger event subscriptions
45
+
46
+ ### Changed
47
+
48
+ - **BREAKING:** Replace `NetworkConfiguration` type with a new definition ([#4268](https://github.com/MetaMask/core/pull/4286))
49
+ - A network configuration no longer represents a single RPC endpoint but rather a collection of RPC endpoints that can all be used to interface with a single chain.
50
+ - The only property that has brought over to this type unchanged is `chainId`.
51
+ - `ticker` has been renamed to `nativeCurrency`.
52
+ - `nickname` has been renamed to `name`.
53
+ - `rpcEndpoints` has been added. This is an an array of objects, where each object has properties `name` (optional), `networkClientId` (optional), `type`, and `url`.
54
+ - `defaultRpcEndpointIndex` has been added. This must point to an entry in `rpcEndpoints`.
55
+ - The block explorer URL is no longer located in `rpcPrefs` and is no longer restricted to one: `blockExplorerUrls` has been added along with a corresponding property `defaultBlockExplorerUrlIndex`, which must point to an entry in `blockExplorerUrls`.
56
+ - `id` has been removed. Previously, this represented the ID of the network client associated with the network configuration. Since network clients are now created from RPC endpoints, the equivalent to this is the `networkClientId` property on an `RpcEndpoint`.
57
+ - **BREAKING:** The network controller messenger must now allow the action `NetworkController:getNetworkConfigurationByChainId` ([#4268](https://github.com/MetaMask/core/pull/4286))
58
+ - **BREAKING:** The network controller messenger must now allow the event `NetworkController:networkAdded` ([#4268](https://github.com/MetaMask/core/pull/4286))
59
+ - **BREAKING:** The `NetworkController` constructor will now throw if the initial state provided is invalid ([#4268](https://github.com/MetaMask/core/pull/4286))
60
+ - `networkConfigurationsByChainId` cannot be empty.
61
+ - The `chainId` of a network configuration in `networkConfigurationsByChainId` must match the chain ID it is filed under.
62
+ - The `defaultRpcEndpointIndex` of a network configuration in `networkConfigurationsByChainId` must point to an entry in its `rpcEndpoints`.
63
+ - The `defaultBlockExplorerUrlIndex` of a network configuration in `networkConfigurationsByChainId` must point to an entry in its `blockExplorerUrls`.
64
+ - `selectedNetworkClientId` must match the `networkClientId` of an RPC endpoint in `networkConfigurationsByChainId`.
65
+ - **BREAKING:** Update `getNetworkConfigurationByNetworkClientId` so that when given an Infura network name (that is, a value from `InfuraNetworkType`), it will return a masked version of the RPC endpoint URL for the associated Infura network ([#4268](https://github.com/MetaMask/core/pull/4286))
66
+ - If you want the unmasked version, you'll need the `url` property from the network _client_ configuration, which you can get by calling `getNetworkClientById` and then accessing the `configuration` property off of the network client.
67
+ - **BREAKING:** Update `loadBackup` to take and update `networkConfigurationsByChainId` instead of `networkConfigurations` ([#4268](https://github.com/MetaMask/core/pull/4286))
68
+ - Bump `@metamask/base-controller` from `^6.0.2` to `^7.0.0` ([#4625](https://github.com/MetaMask/core/pull/4625), [#4643](https://github.com/MetaMask/core/pull/4643))
69
+ - Bump `@metamask/controller-utils` from `^11.0.2` to `^11.2.0` ([#4639](https://github.com/MetaMask/core/pull/4639), [#4651](https://github.com/MetaMask/core/pull/4651))
70
+ - Bump `@metamask/eth-block-tracker` from `^9.0.3` to `^10.0.0` ([#4424](https://github.com/MetaMask/core/pull/4424))
71
+ - Bump `@metamask/eth-json-rpc-middleware` from `^12.1.1` to `^13.0.0` ([#4424](https://github.com/MetaMask/core/pull/4424))
72
+
73
+ ### Removed
74
+
75
+ - **BREAKING:** Remove `networkConfigurations` from `NetworkState`, which has been replaced with `networkConfigurationsByChainId` ([#4268](https://github.com/MetaMask/core/pull/4286))
76
+ - **BREAKING:** Remove `upsertNetworkConfiguration` and `removeNetworkConfiguration`, which have been replaced with `addNetwork`, `updateNetwork`, and `removeNetwork` ([#4268](https://github.com/MetaMask/core/pull/4286))
77
+ - **BREAKING:** Remove `defaultState` variable, which has been replaced with a `getDefaultNetworkControllerState` function ([#4268](https://github.com/MetaMask/core/pull/4286))
78
+ - **BREAKING:** Remove `trackMetaMetricsEvent` option from the NetworkController constructor ([#4268](https://github.com/MetaMask/core/pull/4286))
79
+ - Previously, this was used in `upsertNetworkConfiguration` to create a MetaMetrics event when a new network was added. This can now be achieved by subscribing to the `NetworkController:networkAdded` event and creating the event inside of the event handler.
80
+
10
81
  ## [20.2.0]
11
82
 
12
83
  ### Changed
@@ -552,7 +623,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
552
623
 
553
624
  All changes listed after this point were applied to this package following the monorepo conversion.
554
625
 
555
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@20.2.0...HEAD
626
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@21.0.1...HEAD
627
+ [21.0.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@21.0.0...@metamask/network-controller@21.0.1
628
+ [21.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@20.2.0...@metamask/network-controller@21.0.0
556
629
  [20.2.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@20.1.0...@metamask/network-controller@20.2.0
557
630
  [20.1.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@20.0.0...@metamask/network-controller@20.1.0
558
631
  [20.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@19.0.0...@metamask/network-controller@20.0.0