@metamask-previews/network-controller 30.0.1-preview-b441b46d7 → 30.0.1-preview-5d0317d14

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
@@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
34
34
  ### Deprecated
35
35
 
36
36
  - `NetworkControllerGetNetworkConfigurationByNetworkClientId` type is deprecated in favor of `NetworkControllerGetNetworkConfigurationByNetworkClientIdAction` ([#8350](https://github.com/MetaMask/core/pull/8350))
37
+ - Deprecate `AbstractRpcService` and `RpcServiceRequestable` ([#8475](https://github.com/MetaMask/core/pull/8475))
38
+ - There are no equivalents to these interfaces. If you need to take an "RPC-service-like" argument, it's best to declare which properties you're interested in rather than accepting the entire RPC service interface.
37
39
 
38
40
  ## [30.0.1]
39
41
 
@@ -1147,9 +1149,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1147
1149
  ### Added
1148
1150
 
1149
1151
  - Initial release
1150
-
1151
1152
  - As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
1152
-
1153
1153
  - Everything in `src/network` (minus `NetworkType` and `NetworksChainId`, which were placed in `@metamask/controller-utils`)
1154
1154
 
1155
1155
  All changes listed after this point were applied to this package following the monorepo conversion.
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-rpc-service.cjs","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { RpcServiceRequestable } from './rpc-service-requestable';\n\n/**\n * The interface for a service class responsible for making a request to an RPC\n * endpoint or a group of RPC endpoints.\n */\nexport type AbstractRpcService = RpcServiceRequestable & {\n /**\n * The URL of the RPC endpoint.\n */\n endpointUrl: URL;\n};\n"]}
1
+ {"version":3,"file":"abstract-rpc-service.cjs","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { RpcServiceRequestable } from './rpc-service-requestable';\n\n/**\n * The interface for a service class responsible for making a request to an RPC\n * endpoint or a group of RPC endpoints.\n *\n * @deprecated Don't use this interface (it will be removed in an upcoming major\n * version). If you need to take an \"RPC-service-like\" argument, it's best to\n * declare which properties you're interested in rather than accepting the\n * entire RPC service interface.\n */\nexport type AbstractRpcService = RpcServiceRequestable & {\n /**\n * The URL of the RPC endpoint.\n */\n endpointUrl: URL;\n};\n"]}
@@ -2,6 +2,11 @@ import type { RpcServiceRequestable } from "./rpc-service-requestable.cjs";
2
2
  /**
3
3
  * The interface for a service class responsible for making a request to an RPC
4
4
  * endpoint or a group of RPC endpoints.
5
+ *
6
+ * @deprecated Don't use this interface (it will be removed in an upcoming major
7
+ * version). If you need to take an "RPC-service-like" argument, it's best to
8
+ * declare which properties you're interested in rather than accepting the
9
+ * entire RPC service interface.
5
10
  */
6
11
  export type AbstractRpcService = RpcServiceRequestable & {
7
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-rpc-service.d.cts","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAkC;AAEvE;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG;IACvD;;OAEG;IACH,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC"}
1
+ {"version":3,"file":"abstract-rpc-service.d.cts","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAkC;AAEvE;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG;IACvD;;OAEG;IACH,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC"}
@@ -2,6 +2,11 @@ import type { RpcServiceRequestable } from "./rpc-service-requestable.mjs";
2
2
  /**
3
3
  * The interface for a service class responsible for making a request to an RPC
4
4
  * endpoint or a group of RPC endpoints.
5
+ *
6
+ * @deprecated Don't use this interface (it will be removed in an upcoming major
7
+ * version). If you need to take an "RPC-service-like" argument, it's best to
8
+ * declare which properties you're interested in rather than accepting the
9
+ * entire RPC service interface.
5
10
  */
6
11
  export type AbstractRpcService = RpcServiceRequestable & {
7
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-rpc-service.d.mts","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAkC;AAEvE;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG;IACvD;;OAEG;IACH,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC"}
1
+ {"version":3,"file":"abstract-rpc-service.d.mts","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAkC;AAEvE;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG;IACvD;;OAEG;IACH,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-rpc-service.mjs","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { RpcServiceRequestable } from './rpc-service-requestable';\n\n/**\n * The interface for a service class responsible for making a request to an RPC\n * endpoint or a group of RPC endpoints.\n */\nexport type AbstractRpcService = RpcServiceRequestable & {\n /**\n * The URL of the RPC endpoint.\n */\n endpointUrl: URL;\n};\n"]}
1
+ {"version":3,"file":"abstract-rpc-service.mjs","sourceRoot":"","sources":["../../src/rpc-service/abstract-rpc-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { RpcServiceRequestable } from './rpc-service-requestable';\n\n/**\n * The interface for a service class responsible for making a request to an RPC\n * endpoint or a group of RPC endpoints.\n *\n * @deprecated Don't use this interface (it will be removed in an upcoming major\n * version). If you need to take an \"RPC-service-like\" argument, it's best to\n * declare which properties you're interested in rather than accepting the\n * entire RPC service interface.\n */\nexport type AbstractRpcService = RpcServiceRequestable & {\n /**\n * The URL of the RPC endpoint.\n */\n endpointUrl: URL;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service-requestable.cjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n CockatielEventToEventListenerWithData,\n ExcludeCockatielEventData,\n ExtendCockatielEventData,\n ExtractCockatielEventData,\n FetchOptions,\n} from './shared';\n\n/**\n * The interface for a service class responsible for making a request to a\n * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC\n * service chain.\n */\nexport type RpcServiceRequestable = {\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onRetry'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onRetry']>;\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(\n listener: (\n data: ExcludeCockatielEventData<\n ExtendCockatielEventData<\n ExtractCockatielEventData<ServicePolicy['onBreak']>,\n { endpointUrl: string }\n >,\n 'isolated'\n >,\n ) => void,\n ): ReturnType<ServicePolicy['onBreak']>;\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onDegraded'],\n { endpointUrl: string; rpcMethodName: string }\n >,\n ): ReturnType<ServicePolicy['onDegraded']>;\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onAvailable'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onAvailable']>;\n\n /**\n * Makes a request to the target.\n */\n request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
1
+ {"version":3,"file":"rpc-service-requestable.cjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n CockatielEventToEventListenerWithData,\n ExcludeCockatielEventData,\n ExtendCockatielEventData,\n ExtractCockatielEventData,\n FetchOptions,\n} from './shared';\n\n/**\n * The interface for a service class responsible for making a request to a\n * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC\n * service chain.\n *\n * @deprecated Don't use this interface (it will be removed in an upcoming major\n * version). If you need to take an \"RPC-service-like\" argument, it's best to\n * declare which properties you're interested in rather than accepting the\n * entire RPC service interface.\n */\nexport type RpcServiceRequestable = {\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onRetry'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onRetry']>;\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(\n listener: (\n data: ExcludeCockatielEventData<\n ExtendCockatielEventData<\n ExtractCockatielEventData<ServicePolicy['onBreak']>,\n { endpointUrl: string }\n >,\n 'isolated'\n >,\n ) => void,\n ): ReturnType<ServicePolicy['onBreak']>;\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onDegraded'],\n { endpointUrl: string; rpcMethodName: string }\n >,\n ): ReturnType<ServicePolicy['onDegraded']>;\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onAvailable'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onAvailable']>;\n\n /**\n * Makes a request to the target.\n */\n request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
@@ -5,6 +5,11 @@ import type { CockatielEventToEventListenerWithData, ExcludeCockatielEventData,
5
5
  * The interface for a service class responsible for making a request to a
6
6
  * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC
7
7
  * service chain.
8
+ *
9
+ * @deprecated Don't use this interface (it will be removed in an upcoming major
10
+ * version). If you need to take an "RPC-service-like" argument, it's best to
11
+ * declare which properties you're interested in rather than accepting the
12
+ * entire RPC service interface.
8
13
  */
9
14
  export type RpcServiceRequestable = {
10
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service-requestable.d.cts","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,OAAO,KAAK,EACV,qCAAqC,EACrC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,YAAY,EACb,qBAAiB;AAElB;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;;OAMG;IACH,OAAO,CACL,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,SAAS,CAAC,EACxB;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC;;;;;;;OAOG;IACH,OAAO,CACL,QAAQ,EAAE,CACR,IAAI,EAAE,yBAAyB,CAC7B,wBAAwB,CACtB,yBAAyB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,EACnD;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,EACD,UAAU,CACX,KACE,IAAI,GACR,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,YAAY,CAAC,EAC3B;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAC/C,GACA,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;IAE3C;;;;;;OAMG;IACH,WAAW,CACT,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,aAAa,CAAC,EAC5B;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IAE5C;;OAEG;IACH,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACvD,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAChD,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5C,CAAC"}
1
+ {"version":3,"file":"rpc-service-requestable.d.cts","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,OAAO,KAAK,EACV,qCAAqC,EACrC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,YAAY,EACb,qBAAiB;AAElB;;;;;;;;;GASG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;;OAMG;IACH,OAAO,CACL,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,SAAS,CAAC,EACxB;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC;;;;;;;OAOG;IACH,OAAO,CACL,QAAQ,EAAE,CACR,IAAI,EAAE,yBAAyB,CAC7B,wBAAwB,CACtB,yBAAyB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,EACnD;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,EACD,UAAU,CACX,KACE,IAAI,GACR,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,YAAY,CAAC,EAC3B;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAC/C,GACA,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;IAE3C;;;;;;OAMG;IACH,WAAW,CACT,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,aAAa,CAAC,EAC5B;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IAE5C;;OAEG;IACH,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACvD,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAChD,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5C,CAAC"}
@@ -5,6 +5,11 @@ import type { CockatielEventToEventListenerWithData, ExcludeCockatielEventData,
5
5
  * The interface for a service class responsible for making a request to a
6
6
  * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC
7
7
  * service chain.
8
+ *
9
+ * @deprecated Don't use this interface (it will be removed in an upcoming major
10
+ * version). If you need to take an "RPC-service-like" argument, it's best to
11
+ * declare which properties you're interested in rather than accepting the
12
+ * entire RPC service interface.
8
13
  */
9
14
  export type RpcServiceRequestable = {
10
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service-requestable.d.mts","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,OAAO,KAAK,EACV,qCAAqC,EACrC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,YAAY,EACb,qBAAiB;AAElB;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;;OAMG;IACH,OAAO,CACL,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,SAAS,CAAC,EACxB;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC;;;;;;;OAOG;IACH,OAAO,CACL,QAAQ,EAAE,CACR,IAAI,EAAE,yBAAyB,CAC7B,wBAAwB,CACtB,yBAAyB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,EACnD;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,EACD,UAAU,CACX,KACE,IAAI,GACR,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,YAAY,CAAC,EAC3B;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAC/C,GACA,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;IAE3C;;;;;;OAMG;IACH,WAAW,CACT,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,aAAa,CAAC,EAC5B;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IAE5C;;OAEG;IACH,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACvD,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAChD,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5C,CAAC"}
1
+ {"version":3,"file":"rpc-service-requestable.d.mts","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"AAAA,OAAO,K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cAAc,CAAC,MAAM,CAAC,CAAC,EAChD,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service-requestable.mjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n CockatielEventToEventListenerWithData,\n ExcludeCockatielEventData,\n ExtendCockatielEventData,\n ExtractCockatielEventData,\n FetchOptions,\n} from './shared';\n\n/**\n * The interface for a service class responsible for making a request to a\n * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC\n * service chain.\n */\nexport type RpcServiceRequestable = {\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onRetry'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onRetry']>;\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(\n listener: (\n data: ExcludeCockatielEventData<\n ExtendCockatielEventData<\n ExtractCockatielEventData<ServicePolicy['onBreak']>,\n { endpointUrl: string }\n >,\n 'isolated'\n >,\n ) => void,\n ): ReturnType<ServicePolicy['onBreak']>;\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onDegraded'],\n { endpointUrl: string; rpcMethodName: string }\n >,\n ): ReturnType<ServicePolicy['onDegraded']>;\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onAvailable'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onAvailable']>;\n\n /**\n * Makes a request to the target.\n */\n request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
1
+ {"version":3,"file":"rpc-service-requestable.mjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n CockatielEventToEventListenerWithData,\n ExcludeCockatielEventData,\n ExtendCockatielEventData,\n ExtractCockatielEventData,\n FetchOptions,\n} from './shared';\n\n/**\n * The interface for a service class responsible for making a request to a\n * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC\n * service chain.\n *\n * @deprecated Don't use this interface (it will be removed in an upcoming major\n * version). If you need to take an \"RPC-service-like\" argument, it's best to\n * declare which properties you're interested in rather than accepting the\n * entire RPC service interface.\n */\nexport type RpcServiceRequestable = {\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onRetry'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onRetry']>;\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(\n listener: (\n data: ExcludeCockatielEventData<\n ExtendCockatielEventData<\n ExtractCockatielEventData<ServicePolicy['onBreak']>,\n { endpointUrl: string }\n >,\n 'isolated'\n >,\n ) => void,\n ): ReturnType<ServicePolicy['onBreak']>;\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onDegraded'],\n { endpointUrl: string; rpcMethodName: string }\n >,\n ): ReturnType<ServicePolicy['onDegraded']>;\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onAvailable'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onAvailable']>;\n\n /**\n * Makes a request to the target.\n */\n request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service.cjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA,iEAKoC;AACpC,qDAA+D;AAC/D,2CAAyE;AAOzE,yCAAsD;AACtD,0DAAkC;AAGlC,0CAA8D;AA6C9D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,YAAY,CAAC,CAAC;AAE5D;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACU,QAAA,gCAAgC,GA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ACjD,MAAM,qCAAqC,GAAG,IAAI,CAAC,YAAY,CAC7D,SAAS,EACT,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAC7B,CAAC,MAAM,CACN,CAAC,4BAA4B,IAAI,uBAAA,IAAI,0BAAQ,CAAC,oBAAoB,CAAC;gBACjE,gBAAQ,CAAC,MAAM,CAClB,CAAC;YACF,MAAM,sBAAS,CAAC,mBAAmB,CAAC;gBAClC,OAAO,EAAE,sDAAsD,qCAAqC,oDAAoD;aACzJ,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport {\n BrokenCircuitError,\n HttpError,\n createServicePolicy,\n handleWhen,\n} from '@metamask/controller-utils';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { Duration, getErrorMessage, hasProperty } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\nimport { CircuitState, IDisposable } from 'cockatiel';\nimport deepmerge from 'deepmerge';\nimport type { Logger } from 'loglevel';\n\nimport { projectLogger, createModuleLogger } from '../logger';\nimport type { AbstractRpcService } from './abstract-rpc-service';\nimport type { FetchOptions } from './shared';\n\n/**\n * Options for the RpcService constructor.\n */\nexport type RpcServiceOptions = {\n /**\n * A function that can be used to convert a binary string into a\n * base64-encoded ASCII string. Used to encode authorization credentials.\n */\n btoa: typeof btoa;\n /**\n * The URL of the RPC endpoint to hit.\n */\n endpointUrl: URL | string;\n /**\n * A function that can be used to make an HTTP request. If your JavaScript\n * environment supports `fetch` natively, you'll probably want to pass that;\n * otherwise you can pass an equivalent (such as `fetch` via `node-fetch`).\n */\n fetch: typeof fetch;\n /**\n * A common set of options that will be used to make every request. Can be\n * overridden on the request level (e.g. to add headers).\n */\n fetchOptions?: FetchOptions;\n /**\n * A `loglevel` logger.\n */\n logger?: Pick<Logger, 'warn'>;\n /**\n * Options to pass to `createServicePolicy`. Note that `retryFilterPolicy` is\n * not accepted, as it is overwritten. See {@link createServicePolicy}.\n */\n policyOptions?: Omit<CreateServicePolicyOptions, 'retryFilterPolicy'>;\n /**\n * A function that checks if the user is currently offline. If it returns true,\n * connection errors will not be retried, preventing degraded and break\n * callbacks from being triggered.\n */\n isOffline: () => boolean;\n};\n\nconst log = createModuleLogger(projectLogger, 'RpcService');\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 4;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The list of error messages that represent a failure to connect to the network.\n *\n * This list was derived from Sindre Sorhus's `is-network-error` package:\n * <https://github.com/sindresorhus/is-network-error/blob/7bbfa8be9482ce1427a21fbff60e3ee1650dd091/index.js>\n */\nexport const CONNECTION_ERRORS = [\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /network error/u,\n },\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /Failed to fetch/u,\n },\n // Firefox\n {\n constructorName: 'TypeError',\n pattern: /NetworkError when attempting to fetch resource\\./u,\n },\n // Safari 16\n {\n constructorName: 'TypeError',\n pattern: /The Internet connection appears to be offline\\./u,\n },\n // Safari 17+\n {\n constructorName: 'TypeError',\n pattern: /Load failed/u,\n },\n // `cross-fetch`\n {\n constructorName: 'TypeError',\n pattern: /Network request failed/u,\n },\n // `node-fetch`\n {\n constructorName: 'FetchError',\n pattern: /request to (.+) failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /fetch failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /terminated/u,\n },\n];\n\n/**\n * Custom JSON-RPC error codes for specific cases.\n *\n * These should be moved to `@metamask/rpc-errors` eventually.\n */\nexport const CUSTOM_RPC_ERRORS = {\n unauthorized: -32006,\n httpClientError: -32080,\n} as const;\n\n/**\n * Determines whether the given error represents a failure to reach the network\n * after request parameters have been validated.\n *\n * This is somewhat difficult to verify because JavaScript engines (and in\n * some cases libraries) produce slightly different error messages for this\n * particular scenario, and we need to account for this.\n *\n * @param error - The error.\n * @returns True if the error indicates that the network cannot be connected to,\n * and false otherwise.\n */\nexport function isConnectionError(error: unknown): boolean {\n if (!(typeof error === 'object' && error !== null && 'message' in error)) {\n return false;\n }\n\n const { message } = error;\n\n return (\n typeof message === 'string' &&\n !isNockError(message) &&\n CONNECTION_ERRORS.some(({ constructorName, pattern }) => {\n return (\n error.constructor.name === constructorName && pattern.test(message)\n );\n })\n );\n}\n\n/**\n * Determines whether the given error message refers to a Nock error.\n *\n * It's important that if we failed to mock a request in a test, the resulting\n * error does not cause the request to be retried so that we can see it right\n * away.\n *\n * @param message - The error message to test.\n * @returns True if the message indicates a missing Nock mock, false otherwise.\n */\nfunction isNockError(message: string): boolean {\n return message.includes('Nock:');\n}\n\n/**\n * Determine whether the given error message indicates a failure to parse JSON.\n *\n * This is different in tests vs. implementation code because it may manifest as\n * a FetchError or a SyntaxError.\n *\n * @param error - The error object to test.\n * @returns True if the error indicates a JSON parse error, false otherwise.\n */\nexport function isJsonParseError(error: unknown): boolean {\n return (\n error instanceof SyntaxError ||\n /invalid json/iu.test(getErrorMessage(error))\n );\n}\n\n/**\n * Determines whether the given error represents a HTTP server error\n * (502, 503, or 504) that should be retried.\n *\n * @param error - The error object to test.\n * @returns True if the error has an httpStatus of 502, 503, or 504.\n */\nexport function isHttpServerError(error: Error): boolean {\n return (\n 'httpStatus' in error &&\n (error.httpStatus === 502 ||\n error.httpStatus === 503 ||\n error.httpStatus === 504)\n );\n}\n\n/**\n * Determines whether the given error has a `code` property of `ETIMEDOUT`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ETIMEDOUT`.\n */\nexport function isTimeoutError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ETIMEDOUT';\n}\n\n/**\n * Determines whether the given error has a `code` property of `ECONNRESET`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ECONNRESET`.\n */\nexport function isConnectionResetError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ECONNRESET';\n}\n\n/**\n * Guarantees a URL, even given a string. This is useful for checking components\n * of that URL.\n *\n * @param endpointUrlOrUrlString - Either a URL object or a string that\n * represents the URL of an endpoint.\n * @returns A URL object.\n */\nfunction getNormalizedEndpointUrl(endpointUrlOrUrlString: URL | string): URL {\n return endpointUrlOrUrlString instanceof URL\n ? endpointUrlOrUrlString\n : new URL(endpointUrlOrUrlString);\n}\n\n/**\n * Strips username and password from a URL.\n *\n * @param url - The URL to strip credentials from.\n * @returns A new URL object with credentials removed.\n */\nfunction stripCredentialsFromUrl(url: URL): URL {\n const strippedUrl = new URL(url.toString());\n strippedUrl.username = '';\n strippedUrl.password = '';\n return strippedUrl;\n}\n\n/**\n * This class is responsible for making a request to an endpoint that implements\n * the JSON-RPC protocol. It is designed to gracefully handle network and server\n * failures, retrying requests using exponential backoff. It also offers a hook\n * which can used to respond to slow requests.\n */\nexport class RpcService implements AbstractRpcService {\n /**\n * The URL of the RPC endpoint.\n */\n readonly endpointUrl: URL;\n\n /**\n * The last error that the retry policy captured (or `undefined` if the last\n * execution of the service was successful).\n */\n lastError: Error | undefined;\n\n /**\n * The RPC method name of the current request being processed. This is passed\n * to `onDegraded` event listeners.\n *\n * Initialised to `''` so the type is `string` throughout the event chain.\n * The empty string is unreachable in practice because the method name is\n * guaranteed to be set after the current request is completed but before\n * any `onDegraded` callbacks are called.\n */\n #currentRpcMethodName = '';\n\n /**\n * The function used to make an HTTP request.\n */\n readonly #fetch: typeof fetch;\n\n /**\n * A common set of options that the request options will extend.\n */\n readonly #fetchOptions: FetchOptions;\n\n /**\n * A `loglevel` logger.\n */\n readonly #logger: RpcServiceOptions['logger'];\n\n /**\n * The policy that wraps the request.\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new RpcService object.\n *\n * @param options - The options. See {@link RpcServiceOptions}.\n */\n constructor(options: RpcServiceOptions) {\n const {\n btoa: givenBtoa,\n endpointUrl,\n fetch: givenFetch,\n logger,\n fetchOptions = {},\n policyOptions = {},\n isOffline,\n } = options;\n\n this.#fetch = givenFetch;\n const normalizedUrl = getNormalizedEndpointUrl(endpointUrl);\n this.#fetchOptions = this.#getDefaultFetchOptions(\n normalizedUrl,\n fetchOptions,\n givenBtoa,\n );\n this.endpointUrl = stripCredentialsFromUrl(normalizedUrl);\n this.#logger = logger;\n\n this.#policy = createServicePolicy({\n maxRetries: DEFAULT_MAX_RETRIES,\n maxConsecutiveFailures: DEFAULT_MAX_CONSECUTIVE_FAILURES,\n ...policyOptions,\n retryFilterPolicy: handleWhen((error) => {\n // If user is offline, don't retry any errors\n // This prevents degraded/break callbacks from being triggered\n if (isOffline()) {\n return false;\n }\n\n return (\n // Ignore errors where the request failed to establish\n isConnectionError(error) ||\n // Ignore server sent HTML error pages or truncated JSON responses\n isJsonParseError(error) ||\n // Ignore server overload errors\n isHttpServerError(error) ||\n // Ignore timeout errors\n isTimeoutError(error) ||\n // Ignore connection reset errors\n isConnectionResetError(error)\n );\n }),\n });\n }\n\n /**\n * Resets the underlying composite Cockatiel policy.\n *\n * This is useful in a collection of RpcServices where some act as failovers\n * for others where you effectively want to invalidate the failovers when the\n * primary recovers.\n */\n resetPolicy(): void {\n this.#policy.reset();\n }\n\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState(): CircuitState {\n return this.#policy.getCircuitState();\n }\n\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<AbstractRpcService['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry((data) => {\n listener({ ...data, endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row, causing the underlying circuit to break.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<AbstractRpcService['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak((data) => {\n // `{ isolated: true }` is a special object that shows up when `isolate`\n // is called on the circuit breaker. Usually `isolate` is used to hold the\n // circuit open, but we (ab)use this method in `createServicePolicy` to\n // reset the circuit breaker policy. When we do this, we don't want to\n // call `onBreak` handlers, because then it causes\n // `NetworkController:rpcEndpointUnavailable` and\n // `NetworkController:rpcEndpointChainUnavailable` to be published. So we\n // have to ignore that object here. The consequence is that `isolate`\n // doesn't function the way it is intended, at least in the context of an\n // RpcService. However, we are making a bet that we won't need to use it\n // other than how we are already using it.\n if (!('isolated' in data)) {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: Parameters<AbstractRpcService['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded((data) => {\n if (data === undefined) {\n listener({\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n } else {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onAvailable} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: Parameters<AbstractRpcService['onAvailable']>[0],\n ): IDisposable {\n return this.#policy.onAvailable(() => {\n listener({ endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is specifically designed for `eth_getBlockByNumber`, which\n * can return a `result` of `null` despite an expected `Result` being\n * provided.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params> & { method: 'eth_getBlockByNumber' },\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>>;\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is designed for all RPC methods except for\n * `eth_getBlockByNumber`, which are expected to return a `result` of the\n * expected `Result`.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result>>;\n\n async request<Params extends JsonRpcParams, Result extends Json>(\n // The request object may be frozen and must not be mutated.\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions = {},\n ): Promise<JsonRpcResponse<Result | null>> {\n const completeFetchOptions = this.#getCompleteFetchOptions(\n jsonRpcRequest,\n fetchOptions,\n );\n return await this.#executeAndProcessRequest<Result>(\n completeFetchOptions,\n jsonRpcRequest.method,\n );\n }\n\n /**\n * Constructs a default set of options to `fetch`.\n *\n * If a username and password are present in the URL, they are extracted to an\n * Authorization header.\n *\n * @param endpointUrl - The endpoint URL.\n * @param fetchOptions - The options to `fetch`.\n * @param givenBtoa - An implementation of `btoa`.\n * @returns The default fetch options.\n */\n #getDefaultFetchOptions(\n endpointUrl: URL,\n fetchOptions: FetchOptions,\n givenBtoa: (stringToEncode: string) => string,\n ): FetchOptions {\n if (endpointUrl.username && endpointUrl.password) {\n const authString = `${endpointUrl.username}:${endpointUrl.password}`;\n const encodedCredentials = givenBtoa(authString);\n return deepmerge(fetchOptions, {\n headers: { Authorization: `Basic ${encodedCredentials}` },\n });\n }\n\n return fetchOptions;\n }\n\n /**\n * Constructs a final set of options to pass to `fetch`. Note that the method\n * defaults to `post`, and the JSON-RPC request is automatically JSON-encoded.\n *\n * @param jsonRpcRequest - The JSON-RPC request.\n * @param fetchOptions - Custom `fetch` options.\n * @returns The complete set of `fetch` options.\n */\n #getCompleteFetchOptions<Params extends JsonRpcParams>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions,\n ): FetchOptions {\n const defaultOptions = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n };\n const mergedOptions = deepmerge(\n defaultOptions,\n deepmerge(this.#fetchOptions, fetchOptions),\n );\n\n const { id, jsonrpc, method, params } = jsonRpcRequest;\n const body = JSON.stringify({\n id,\n jsonrpc,\n method,\n params,\n });\n\n return { ...mergedOptions, body };\n }\n\n /**\n * Makes the request using the Cockatiel policy that this service creates.\n *\n * @param fetchOptions - The options for `fetch`; will be combined with the\n * fetch options passed to the constructor\n * @param rpcMethodName - The JSON-RPC method name of the current request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async #executeAndProcessRequest<Result extends Json>(\n fetchOptions: FetchOptions,\n rpcMethodName: string,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>> {\n let response: Response | undefined;\n try {\n log(\n `[${this.endpointUrl}] Circuit state`,\n this.#policy.getCircuitState(),\n );\n const jsonDecodedResponse = await this.#policy.execute(\n async (context) => {\n try {\n log(\n 'REQUEST INITIATED:',\n this.endpointUrl.toString(),\n '::',\n fetchOptions,\n // @ts-expect-error This property _is_ here, the type of\n // ServicePolicy is just wrong.\n `(attempt ${context.attempt + 1})`,\n );\n response = await this.#fetch(this.endpointUrl, fetchOptions);\n if (!response.ok) {\n throw new HttpError(response.status);\n }\n log(\n 'REQUEST SUCCESSFUL:',\n this.endpointUrl.toString(),\n response.status,\n );\n return await response.json();\n } finally {\n // Track the RPC method for the request that has just taken place.\n // We pass this property to `onDegraded` event listeners.\n //\n // We set this property after the request completes and not before\n // the request starts to account for race conditions. That is, if\n // there are two requests that are being performed concurrently, and\n // the second request fails fast but the first request succeeds\n // slowly, when `onDegraded` is called we want it to include the\n // first request as the RPC method, not the second.\n //\n // Also, we set this property within a `finally` block inside of the\n // function passed to `policy.execute` to ensure that it is set\n // before `onDegraded` gets called, no matter the outcome of the\n // request.\n this.#currentRpcMethodName = rpcMethodName;\n }\n },\n );\n this.lastError = undefined;\n return jsonDecodedResponse;\n } catch (error) {\n log('REQUEST ERROR:', this.endpointUrl.toString(), error);\n\n this.lastError =\n error instanceof Error ? error : new Error(getErrorMessage(error));\n\n if (error instanceof HttpError) {\n const status = error.httpStatus;\n if (status === 401) {\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.unauthorized,\n 'Unauthorized.',\n {\n httpStatus: status,\n },\n );\n }\n if (status === 429) {\n throw rpcErrors.limitExceeded({\n message: 'Request is being rate limited.',\n data: {\n httpStatus: status,\n },\n });\n }\n if (status >= 500 || status === 402 || status === 404) {\n throw rpcErrors.resourceUnavailable({\n message: 'RPC endpoint not found or unavailable.',\n data: {\n httpStatus: status,\n },\n });\n }\n\n // Handle all other 4xx errors as generic HTTP client errors\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.httpClientError,\n 'RPC endpoint returned HTTP client error.',\n {\n httpStatus: status,\n },\n );\n } else if (isJsonParseError(error)) {\n throw rpcErrors.parse({\n message: 'RPC endpoint did not return JSON.',\n });\n } else if (error instanceof BrokenCircuitError) {\n this.#logger?.warn(error);\n const remainingCircuitOpenDuration =\n this.#policy.getRemainingCircuitOpenDuration();\n const formattedRemainingCircuitOpenDuration = Intl.NumberFormat(\n undefined,\n { maximumFractionDigits: 2 },\n ).format(\n (remainingCircuitOpenDuration ?? this.#policy.circuitBreakDuration) /\n Duration.Minute,\n );\n throw rpcErrors.resourceUnavailable({\n message: `RPC endpoint returned too many errors, retrying in ${formattedRemainingCircuitOpenDuration} minutes. Consider using a different RPC endpoint.`,\n });\n }\n throw error;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"rpc-service.cjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA,iEAKoC;AACpC,qDAA+D;AAC/D,2CAAyE;AAOzE,yCAAyC;AACzC,0DAAkC;AAGlC,0CAA8D;AAkD9D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,YAAY,CAAC,CAAC;AAE5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AAM,4BAA4B,GAChC,uBAAA,IAAI,0BAAQ,CAAC,+BAA+B,EAAE,CAAC;YACjD,MAAM,qCAAqC,GAAG,IAAI,CAAC,YAAY,CAC7D,SAAS,EACT,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAC7B,CAAC,MAAM,CACN,CAAC,4BAA4B,IAAI,uBAAA,IAAI,0BAAQ,CAAC,oBAAoB,CAAC;gBACjE,gBAAQ,CAAC,MAAM,CAClB,CAAC;YACF,MAAM,sBAAS,CAAC,mBAAmB,CAAC;gBAClC,OAAO,EAAE,sDAAsD,qCAAqC,oDAAoD;aACzJ,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport {\n BrokenCircuitError,\n HttpError,\n createServicePolicy,\n handleWhen,\n} from '@metamask/controller-utils';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { Duration, getErrorMessage, hasProperty } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\nimport { CircuitState } from 'cockatiel';\nimport deepmerge from 'deepmerge';\nimport type { Logger } from 'loglevel';\n\nimport { projectLogger, createModuleLogger } from '../logger';\nimport type {\n CockatielEventToEventListenerWithData,\n ExcludeCockatielEventData,\n ExtendCockatielEventData,\n ExtractCockatielEventData,\n FetchOptions,\n} from './shared';\n\n/**\n * Options for the RpcService constructor.\n */\nexport type RpcServiceOptions = {\n /**\n * A function that can be used to convert a binary string into a\n * base64-encoded ASCII string. Used to encode authorization credentials.\n */\n btoa: typeof btoa;\n /**\n * The URL of the RPC endpoint to hit.\n */\n endpointUrl: URL | string;\n /**\n * A function that can be used to make an HTTP request. If your JavaScript\n * environment supports `fetch` natively, you'll probably want to pass that;\n * otherwise you can pass an equivalent (such as `fetch` via `node-fetch`).\n */\n fetch: typeof fetch;\n /**\n * A common set of options that will be used to make every request. Can be\n * overridden on the request level (e.g. to add headers).\n */\n fetchOptions?: FetchOptions;\n /**\n * A `loglevel` logger.\n */\n logger?: Pick<Logger, 'warn'>;\n /**\n * Options to pass to `createServicePolicy`. Note that `retryFilterPolicy` is\n * not accepted, as it is overwritten. See {@link createServicePolicy}.\n */\n policyOptions?: Omit<CreateServicePolicyOptions, 'retryFilterPolicy'>;\n /**\n * A function that checks if the user is currently offline. If it returns true,\n * connection errors will not be retried, preventing degraded and break\n * callbacks from being triggered.\n */\n isOffline: () => boolean;\n};\n\nconst log = createModuleLogger(projectLogger, 'RpcService');\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 4;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The list of error messages that represent a failure to connect to the network.\n *\n * This list was derived from Sindre Sorhus's `is-network-error` package:\n * <https://github.com/sindresorhus/is-network-error/blob/7bbfa8be9482ce1427a21fbff60e3ee1650dd091/index.js>\n */\nexport const CONNECTION_ERRORS = [\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /network error/u,\n },\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /Failed to fetch/u,\n },\n // Firefox\n {\n constructorName: 'TypeError',\n pattern: /NetworkError when attempting to fetch resource\\./u,\n },\n // Safari 16\n {\n constructorName: 'TypeError',\n pattern: /The Internet connection appears to be offline\\./u,\n },\n // Safari 17+\n {\n constructorName: 'TypeError',\n pattern: /Load failed/u,\n },\n // `cross-fetch`\n {\n constructorName: 'TypeError',\n pattern: /Network request failed/u,\n },\n // `node-fetch`\n {\n constructorName: 'FetchError',\n pattern: /request to (.+) failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /fetch failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /terminated/u,\n },\n];\n\n/**\n * Custom JSON-RPC error codes for specific cases.\n *\n * These should be moved to `@metamask/rpc-errors` eventually.\n */\nexport const CUSTOM_RPC_ERRORS = {\n unauthorized: -32006,\n httpClientError: -32080,\n} as const;\n\n/**\n * Determines whether the given error represents a failure to reach the network\n * after request parameters have been validated.\n *\n * This is somewhat difficult to verify because JavaScript engines (and in\n * some cases libraries) produce slightly different error messages for this\n * particular scenario, and we need to account for this.\n *\n * @param error - The error.\n * @returns True if the error indicates that the network cannot be connected to,\n * and false otherwise.\n */\nexport function isConnectionError(error: unknown): boolean {\n if (!(typeof error === 'object' && error !== null && 'message' in error)) {\n return false;\n }\n\n const { message } = error;\n\n return (\n typeof message === 'string' &&\n !isNockError(message) &&\n CONNECTION_ERRORS.some(({ constructorName, pattern }) => {\n return (\n error.constructor.name === constructorName && pattern.test(message)\n );\n })\n );\n}\n\n/**\n * Determines whether the given error message refers to a Nock error.\n *\n * It's important that if we failed to mock a request in a test, the resulting\n * error does not cause the request to be retried so that we can see it right\n * away.\n *\n * @param message - The error message to test.\n * @returns True if the message indicates a missing Nock mock, false otherwise.\n */\nfunction isNockError(message: string): boolean {\n return message.includes('Nock:');\n}\n\n/**\n * Determine whether the given error message indicates a failure to parse JSON.\n *\n * This is different in tests vs. implementation code because it may manifest as\n * a FetchError or a SyntaxError.\n *\n * @param error - The error object to test.\n * @returns True if the error indicates a JSON parse error, false otherwise.\n */\nexport function isJsonParseError(error: unknown): boolean {\n return (\n error instanceof SyntaxError ||\n /invalid json/iu.test(getErrorMessage(error))\n );\n}\n\n/**\n * Determines whether the given error represents a HTTP server error\n * (502, 503, or 504) that should be retried.\n *\n * @param error - The error object to test.\n * @returns True if the error has an httpStatus of 502, 503, or 504.\n */\nexport function isHttpServerError(error: Error): boolean {\n return (\n 'httpStatus' in error &&\n (error.httpStatus === 502 ||\n error.httpStatus === 503 ||\n error.httpStatus === 504)\n );\n}\n\n/**\n * Determines whether the given error has a `code` property of `ETIMEDOUT`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ETIMEDOUT`.\n */\nexport function isTimeoutError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ETIMEDOUT';\n}\n\n/**\n * Determines whether the given error has a `code` property of `ECONNRESET`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ECONNRESET`.\n */\nexport function isConnectionResetError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ECONNRESET';\n}\n\n/**\n * Guarantees a URL, even given a string. This is useful for checking components\n * of that URL.\n *\n * @param endpointUrlOrUrlString - Either a URL object or a string that\n * represents the URL of an endpoint.\n * @returns A URL object.\n */\nfunction getNormalizedEndpointUrl(endpointUrlOrUrlString: URL | string): URL {\n return endpointUrlOrUrlString instanceof URL\n ? endpointUrlOrUrlString\n : new URL(endpointUrlOrUrlString);\n}\n\n/**\n * Strips username and password from a URL.\n *\n * @param url - The URL to strip credentials from.\n * @returns A new URL object with credentials removed.\n */\nfunction stripCredentialsFromUrl(url: URL): URL {\n const strippedUrl = new URL(url.toString());\n strippedUrl.username = '';\n strippedUrl.password = '';\n return strippedUrl;\n}\n\n/**\n * This class is responsible for making a request to an endpoint that implements\n * the JSON-RPC protocol. It is designed to gracefully handle network and server\n * failures, retrying requests using exponential backoff. It also offers a hook\n * which can used to respond to slow requests.\n */\nexport class RpcService {\n /**\n * The URL of the RPC endpoint.\n */\n readonly endpointUrl: URL;\n\n /**\n * The last error that the retry policy captured (or `undefined` if the last\n * execution of the service was successful).\n */\n lastError: Error | undefined;\n\n /**\n * The RPC method name of the current request being processed. This is passed\n * to `onDegraded` event listeners.\n *\n * Initialised to `''` so the type is `string` throughout the event chain.\n * The empty string is unreachable in practice because the method name is\n * guaranteed to be set after the current request is completed but before\n * any `onDegraded` callbacks are called.\n */\n #currentRpcMethodName = '';\n\n /**\n * The function used to make an HTTP request.\n */\n readonly #fetch: typeof fetch;\n\n /**\n * A common set of options that the request options will extend.\n */\n readonly #fetchOptions: FetchOptions;\n\n /**\n * A `loglevel` logger.\n */\n readonly #logger: RpcServiceOptions['logger'];\n\n /**\n * The policy that wraps the request.\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new RpcService object.\n *\n * @param options - The options. See {@link RpcServiceOptions}.\n */\n constructor(options: RpcServiceOptions) {\n const {\n btoa: givenBtoa,\n endpointUrl,\n fetch: givenFetch,\n logger,\n fetchOptions = {},\n policyOptions = {},\n isOffline,\n } = options;\n\n this.#fetch = givenFetch;\n const normalizedUrl = getNormalizedEndpointUrl(endpointUrl);\n this.#fetchOptions = this.#getDefaultFetchOptions(\n normalizedUrl,\n fetchOptions,\n givenBtoa,\n );\n this.endpointUrl = stripCredentialsFromUrl(normalizedUrl);\n this.#logger = logger;\n\n this.#policy = createServicePolicy({\n maxRetries: DEFAULT_MAX_RETRIES,\n maxConsecutiveFailures: DEFAULT_MAX_CONSECUTIVE_FAILURES,\n ...policyOptions,\n retryFilterPolicy: handleWhen((error) => {\n // If user is offline, don't retry any errors\n // This prevents degraded/break callbacks from being triggered\n if (isOffline()) {\n return false;\n }\n\n return (\n // Ignore errors where the request failed to establish\n isConnectionError(error) ||\n // Ignore server sent HTML error pages or truncated JSON responses\n isJsonParseError(error) ||\n // Ignore server overload errors\n isHttpServerError(error) ||\n // Ignore timeout errors\n isTimeoutError(error) ||\n // Ignore connection reset errors\n isConnectionResetError(error)\n );\n }),\n });\n }\n\n /**\n * Resets the underlying composite Cockatiel policy.\n *\n * This is useful in a collection of RpcServices where some act as failovers\n * for others where you effectively want to invalidate the failovers when the\n * primary recovers.\n */\n resetPolicy(): void {\n this.#policy.reset();\n }\n\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState(): CircuitState {\n return this.#policy.getCircuitState();\n }\n\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onRetry'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onRetry']> {\n return this.#policy.onRetry((data) => {\n listener({ ...data, endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row, causing the underlying circuit to break.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(\n listener: (\n data: ExcludeCockatielEventData<\n ExtendCockatielEventData<\n ExtractCockatielEventData<ServicePolicy['onBreak']>,\n { endpointUrl: string }\n >,\n 'isolated'\n >,\n ) => void,\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak((data) => {\n // `{ isolated: true }` is a special object that shows up when `isolate`\n // is called on the circuit breaker. Usually `isolate` is used to hold the\n // circuit open, but we (ab)use this method in `createServicePolicy` to\n // reset the circuit breaker policy. When we do this, we don't want to\n // call `onBreak` handlers, because then it causes\n // `NetworkController:rpcEndpointUnavailable` and\n // `NetworkController:rpcEndpointChainUnavailable` to be published. So we\n // have to ignore that object here. The consequence is that `isolate`\n // doesn't function the way it is intended, at least in the context of an\n // RpcService. However, we are making a bet that we won't need to use it\n // other than how we are already using it.\n if (!('isolated' in data)) {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onDegraded'],\n { endpointUrl: string; rpcMethodName: string }\n >,\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded((data) => {\n if (data === undefined) {\n listener({\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n } else {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onAvailable} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onAvailable'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onAvailable']> {\n return this.#policy.onAvailable(() => {\n listener({ endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is specifically designed for `eth_getBlockByNumber`, which\n * can return a `result` of `null` despite an expected `Result` being\n * provided.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params> & { method: 'eth_getBlockByNumber' },\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>>;\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is designed for all RPC methods except for\n * `eth_getBlockByNumber`, which are expected to return a `result` of the\n * expected `Result`.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result>>;\n\n async request<Params extends JsonRpcParams, Result extends Json>(\n // The request object may be frozen and must not be mutated.\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions = {},\n ): Promise<JsonRpcResponse<Result | null>> {\n const completeFetchOptions = this.#getCompleteFetchOptions(\n jsonRpcRequest,\n fetchOptions,\n );\n return await this.#executeAndProcessRequest<Result>(\n completeFetchOptions,\n jsonRpcRequest.method,\n );\n }\n\n /**\n * Constructs a default set of options to `fetch`.\n *\n * If a username and password are present in the URL, they are extracted to an\n * Authorization header.\n *\n * @param endpointUrl - The endpoint URL.\n * @param fetchOptions - The options to `fetch`.\n * @param givenBtoa - An implementation of `btoa`.\n * @returns The default fetch options.\n */\n #getDefaultFetchOptions(\n endpointUrl: URL,\n fetchOptions: FetchOptions,\n givenBtoa: (stringToEncode: string) => string,\n ): FetchOptions {\n if (endpointUrl.username && endpointUrl.password) {\n const authString = `${endpointUrl.username}:${endpointUrl.password}`;\n const encodedCredentials = givenBtoa(authString);\n return deepmerge(fetchOptions, {\n headers: { Authorization: `Basic ${encodedCredentials}` },\n });\n }\n\n return fetchOptions;\n }\n\n /**\n * Constructs a final set of options to pass to `fetch`. Note that the method\n * defaults to `post`, and the JSON-RPC request is automatically JSON-encoded.\n *\n * @param jsonRpcRequest - The JSON-RPC request.\n * @param fetchOptions - Custom `fetch` options.\n * @returns The complete set of `fetch` options.\n */\n #getCompleteFetchOptions<Params extends JsonRpcParams>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions,\n ): FetchOptions {\n const defaultOptions = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n };\n const mergedOptions = deepmerge(\n defaultOptions,\n deepmerge(this.#fetchOptions, fetchOptions),\n );\n\n const { id, jsonrpc, method, params } = jsonRpcRequest;\n const body = JSON.stringify({\n id,\n jsonrpc,\n method,\n params,\n });\n\n return { ...mergedOptions, body };\n }\n\n /**\n * Makes the request using the Cockatiel policy that this service creates.\n *\n * @param fetchOptions - The options for `fetch`; will be combined with the\n * fetch options passed to the constructor\n * @param rpcMethodName - The JSON-RPC method name of the current request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async #executeAndProcessRequest<Result extends Json>(\n fetchOptions: FetchOptions,\n rpcMethodName: string,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>> {\n let response: Response | undefined;\n try {\n log(\n `[${this.endpointUrl}] Circuit state`,\n this.#policy.getCircuitState(),\n );\n const jsonDecodedResponse = await this.#policy.execute(\n async (context) => {\n try {\n log(\n 'REQUEST INITIATED:',\n this.endpointUrl.toString(),\n '::',\n fetchOptions,\n // @ts-expect-error This property _is_ here, the type of\n // ServicePolicy is just wrong.\n `(attempt ${context.attempt + 1})`,\n );\n response = await this.#fetch(this.endpointUrl, fetchOptions);\n if (!response.ok) {\n throw new HttpError(response.status);\n }\n log(\n 'REQUEST SUCCESSFUL:',\n this.endpointUrl.toString(),\n response.status,\n );\n return await response.json();\n } finally {\n // Track the RPC method for the request that has just taken place.\n // We pass this property to `onDegraded` event listeners.\n //\n // We set this property after the request completes and not before\n // the request starts to account for race conditions. That is, if\n // there are two requests that are being performed concurrently, and\n // the second request fails fast but the first request succeeds\n // slowly, when `onDegraded` is called we want it to include the\n // first request as the RPC method, not the second.\n //\n // Also, we set this property within a `finally` block inside of the\n // function passed to `policy.execute` to ensure that it is set\n // before `onDegraded` gets called, no matter the outcome of the\n // request.\n this.#currentRpcMethodName = rpcMethodName;\n }\n },\n );\n this.lastError = undefined;\n return jsonDecodedResponse;\n } catch (error) {\n log('REQUEST ERROR:', this.endpointUrl.toString(), error);\n\n this.lastError =\n error instanceof Error ? error : new Error(getErrorMessage(error));\n\n if (error instanceof HttpError) {\n const status = error.httpStatus;\n if (status === 401) {\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.unauthorized,\n 'Unauthorized.',\n {\n httpStatus: status,\n },\n );\n }\n if (status === 429) {\n throw rpcErrors.limitExceeded({\n message: 'Request is being rate limited.',\n data: {\n httpStatus: status,\n },\n });\n }\n if (status >= 500 || status === 402 || status === 404) {\n throw rpcErrors.resourceUnavailable({\n message: 'RPC endpoint not found or unavailable.',\n data: {\n httpStatus: status,\n },\n });\n }\n\n // Handle all other 4xx errors as generic HTTP client errors\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.httpClientError,\n 'RPC endpoint returned HTTP client error.',\n {\n httpStatus: status,\n },\n );\n } else if (isJsonParseError(error)) {\n throw rpcErrors.parse({\n message: 'RPC endpoint did not return JSON.',\n });\n } else if (error instanceof BrokenCircuitError) {\n this.#logger?.warn(error);\n const remainingCircuitOpenDuration =\n this.#policy.getRemainingCircuitOpenDuration();\n const formattedRemainingCircuitOpenDuration = Intl.NumberFormat(\n undefined,\n { maximumFractionDigits: 2 },\n ).format(\n (remainingCircuitOpenDuration ?? this.#policy.circuitBreakDuration) /\n Duration.Minute,\n );\n throw rpcErrors.resourceUnavailable({\n message: `RPC endpoint returned too many errors, retrying in ${formattedRemainingCircuitOpenDuration} minutes. Consider using a different RPC endpoint.`,\n });\n }\n throw error;\n }\n }\n}\n"]}
@@ -1,9 +1,8 @@
1
- import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
1
+ import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
2
2
  import type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcResponse } from "@metamask/utils";
3
- import { CircuitState, IDisposable } from "cockatiel";
3
+ import { CircuitState } from "cockatiel";
4
4
  import type { Logger } from "loglevel";
5
- import type { AbstractRpcService } from "./abstract-rpc-service.cjs";
6
- import type { FetchOptions } from "./shared.cjs";
5
+ import type { CockatielEventToEventListenerWithData, ExcludeCockatielEventData, ExtendCockatielEventData, ExtractCockatielEventData, FetchOptions } from "./shared.cjs";
7
6
  /**
8
7
  * Options for the RpcService constructor.
9
8
  */
@@ -126,7 +125,7 @@ export declare function isConnectionResetError(error: Error): boolean;
126
125
  * failures, retrying requests using exponential backoff. It also offers a hook
127
126
  * which can used to respond to slow requests.
128
127
  */
129
- export declare class RpcService implements AbstractRpcService {
128
+ export declare class RpcService {
130
129
  #private;
131
130
  /**
132
131
  * The URL of the RPC endpoint.
@@ -162,7 +161,9 @@ export declare class RpcService implements AbstractRpcService {
162
161
  * @returns What {@link ServicePolicy.onRetry} returns.
163
162
  * @see {@link createServicePolicy}
164
163
  */
165
- onRetry(listener: Parameters<AbstractRpcService['onRetry']>[0]): IDisposable;
164
+ onRetry(listener: CockatielEventToEventListenerWithData<ServicePolicy['onRetry'], {
165
+ endpointUrl: string;
166
+ }>): ReturnType<ServicePolicy['onRetry']>;
166
167
  /**
167
168
  * Listens for when the RPC service retries the request too many times in a
168
169
  * row, causing the underlying circuit to break.
@@ -171,7 +172,9 @@ export declare class RpcService implements AbstractRpcService {
171
172
  * @returns What {@link ServicePolicy.onBreak} returns.
172
173
  * @see {@link createServicePolicy}
173
174
  */
174
- onBreak(listener: Parameters<AbstractRpcService['onBreak']>[0]): IDisposable;
175
+ onBreak(listener: (data: ExcludeCockatielEventData<ExtendCockatielEventData<ExtractCockatielEventData<ServicePolicy['onBreak']>, {
176
+ endpointUrl: string;
177
+ }>, 'isolated'>) => void): ReturnType<ServicePolicy['onBreak']>;
175
178
  /**
176
179
  * Listens for when the policy underlying this RPC service detects a slow
177
180
  * request.
@@ -180,7 +183,10 @@ export declare class RpcService implements AbstractRpcService {
180
183
  * @returns What {@link ServicePolicy.onDegraded} returns.
181
184
  * @see {@link createServicePolicy}
182
185
  */
183
- onDegraded(listener: Parameters<AbstractRpcService['onDegraded']>[0]): IDisposable;
186
+ onDegraded(listener: CockatielEventToEventListenerWithData<ServicePolicy['onDegraded'], {
187
+ endpointUrl: string;
188
+ rpcMethodName: string;
189
+ }>): ReturnType<ServicePolicy['onDegraded']>;
184
190
  /**
185
191
  * Listens for when the policy underlying this RPC service is available.
186
192
  *
@@ -188,7 +194,9 @@ export declare class RpcService implements AbstractRpcService {
188
194
  * @returns What {@link ServicePolicy.onAvailable} returns.
189
195
  * @see {@link createServicePolicy}
190
196
  */
191
- onAvailable(listener: Parameters<AbstractRpcService['onAvailable']>[0]): IDisposable;
197
+ onAvailable(listener: CockatielEventToEventListenerWithData<ServicePolicy['onAvailable'], {
198
+ endpointUrl: string;
199
+ }>): ReturnType<ServicePolicy['onAvailable']>;
192
200
  /**
193
201
  * Makes a request to the RPC endpoint.
194
202
  *
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service.d.cts","sourceRoot":"","sources":["../../src/rpc-service/rpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAE3B,mCAAmC;AASpC,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AACzB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB;AAGvC,OAAO,KAAK,EAAE,kBAAkB,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AC,CAAC;IAiB1C;;;;;;OAMG;IACH,WAAW,CACT,QAAQ,EAAE,qCAAqC,CAC7C,aAAa,CAAC,aAAa,CAAC,EAC5B;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CACxB,GACA,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;IAM3C;;;;;;;;;;;;;;;;OAgBG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG;QAAE,MAAM,EAAE,sBAAsB,CAAA;KAAE,EAC3E,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;;;OAgBG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,EACtC,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;CAiNpC"}
@@ -1,9 +1,8 @@
1
- import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
1
+ import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
2
2
  import type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcResponse } from "@metamask/utils";
3
- import { CircuitState, IDisposable } from "cockatiel";
3
+ import { CircuitState } from "cockatiel";
4
4
  import type { Logger } from "loglevel";
5
- import type { AbstractRpcService } from "./abstract-rpc-service.mjs";
6
- import type { FetchOptions } from "./shared.mjs";
5
+ import type { CockatielEventToEventListenerWithData, ExcludeCockatielEventData, ExtendCockatielEventData, ExtractCockatielEventData, FetchOptions } from "./shared.mjs";
7
6
  /**
8
7
  * Options for the RpcService constructor.
9
8
  */
@@ -126,7 +125,7 @@ export declare function isConnectionResetError(error: Error): boolean;
126
125
  * failures, retrying requests using exponential backoff. It also offers a hook
127
126
  * which can used to respond to slow requests.
128
127
  */
129
- export declare class RpcService implements AbstractRpcService {
128
+ export declare class RpcService {
130
129
  #private;
131
130
  /**
132
131
  * The URL of the RPC endpoint.
@@ -162,7 +161,9 @@ export declare class RpcService implements AbstractRpcService {
162
161
  * @returns What {@link ServicePolicy.onRetry} returns.
163
162
  * @see {@link createServicePolicy}
164
163
  */
165
- onRetry(listener: Parameters<AbstractRpcService['onRetry']>[0]): IDisposable;
164
+ onRetry(listener: CockatielEventToEventListenerWithData<ServicePolicy['onRetry'], {
165
+ endpointUrl: string;
166
+ }>): ReturnType<ServicePolicy['onRetry']>;
166
167
  /**
167
168
  * Listens for when the RPC service retries the request too many times in a
168
169
  * row, causing the underlying circuit to break.
@@ -171,7 +172,9 @@ export declare class RpcService implements AbstractRpcService {
171
172
  * @returns What {@link ServicePolicy.onBreak} returns.
172
173
  * @see {@link createServicePolicy}
173
174
  */
174
- onBreak(listener: Parameters<AbstractRpcService['onBreak']>[0]): IDisposable;
175
+ onBreak(listener: (data: ExcludeCockatielEventData<ExtendCockatielEventData<ExtractCockatielEventData<ServicePolicy['onBreak']>, {
176
+ endpointUrl: string;
177
+ }>, 'isolated'>) => void): ReturnType<ServicePolicy['onBreak']>;
175
178
  /**
176
179
  * Listens for when the policy underlying this RPC service detects a slow
177
180
  * request.
@@ -180,7 +183,10 @@ export declare class RpcService implements AbstractRpcService {
180
183
  * @returns What {@link ServicePolicy.onDegraded} returns.
181
184
  * @see {@link createServicePolicy}
182
185
  */
183
- onDegraded(listener: Parameters<AbstractRpcService['onDegraded']>[0]): IDisposable;
186
+ onDegraded(listener: CockatielEventToEventListenerWithData<ServicePolicy['onDegraded'], {
187
+ endpointUrl: string;
188
+ rpcMethodName: string;
189
+ }>): ReturnType<ServicePolicy['onDegraded']>;
184
190
  /**
185
191
  * Listens for when the policy underlying this RPC service is available.
186
192
  *
@@ -188,7 +194,9 @@ export declare class RpcService implements AbstractRpcService {
188
194
  * @returns What {@link ServicePolicy.onAvailable} returns.
189
195
  * @see {@link createServicePolicy}
190
196
  */
191
- onAvailable(listener: Parameters<AbstractRpcService['onAvailable']>[0]): IDisposable;
197
+ onAvailable(listener: CockatielEventToEventListenerWithData<ServicePolicy['onAvailable'], {
198
+ endpointUrl: string;
199
+ }>): ReturnType<ServicePolicy['onAvailable']>;
192
200
  /**
193
201
  * Makes a request to the RPC endpoint.
194
202
  *
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-service.d.mts","sourceRoot":"","sources":["../../src/rpc-service/rpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAE3B,mCAAmC;AASpC,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AACzB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB;AAGvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,mCAA+B;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,GAAG,GAAG,MAAM,CAAC;IAC1B;;;;OAIG;IACH,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B;;;OAGG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC,0BAA0B,EAAE,mBAAmB,CAAC,CAAC;IACtE;;;;OAIG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC;CAC1B,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;;;GAKG;AACH,eAAO,M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AAS,CAAC,mBAAmB,CAAC;oBAClC,OAAO,EAAE,wCAAwC;oBACjD,IAAI,EAAE;wBACJ,UAAU,EAAE,MAAM;qBACnB;iBACF,CAAC,CAAC;YACL,CAAC;YAED,4DAA4D;YAC5D,MAAM,IAAI,YAAY,CACpB,iBAAiB,CAAC,eAAe,EACjC,0CAA0C,EAC1C;gBACE,UAAU,EAAE,MAAM;aACnB,CACF,CAAC;QACJ,CAAC;aAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,SAAS,CAAC,KAAK,CAAC;gBACpB,OAAO,EAAE,mCAAmC;aAC7C,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,KAAK,YAAY,kBAAkB,EAAE,CAAC;YAC/C,uBAAA,IAAI,0BAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,4BAA4B,GAChC,uBAAA,IAAI,0BAAQ,CAAC,+BAA+B,EAAE,CAAC;YACjD,MAAM,qCAAqC,GAAG,IAAI,CAAC,YAAY,CAC7D,SAAS,EACT,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAC7B,CAAC,MAAM,CACN,CAAC,4BAA4B,IAAI,uBAAA,IAAI,0BAAQ,CAAC,oBAAoB,CAAC;gBACjE,QAAQ,CAAC,MAAM,CAClB,CAAC;YACF,MAAM,SAAS,CAAC,mBAAmB,CAAC;gBAClC,OAAO,EAAE,sDAAsD,qCAAqC,oDAAoD;aACzJ,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport {\n BrokenCircuitError,\n HttpError,\n createServicePolicy,\n handleWhen,\n} from '@metamask/controller-utils';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { Duration, getErrorMessage, hasProperty } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\nimport { CircuitState, IDisposable } from 'cockatiel';\nimport deepmerge from 'deepmerge';\nimport type { Logger } from 'loglevel';\n\nimport { projectLogger, createModuleLogger } from '../logger';\nimport type { AbstractRpcService } from './abstract-rpc-service';\nimport type { FetchOptions } from './shared';\n\n/**\n * Options for the RpcService constructor.\n */\nexport type RpcServiceOptions = {\n /**\n * A function that can be used to convert a binary string into a\n * base64-encoded ASCII string. Used to encode authorization credentials.\n */\n btoa: typeof btoa;\n /**\n * The URL of the RPC endpoint to hit.\n */\n endpointUrl: URL | string;\n /**\n * A function that can be used to make an HTTP request. If your JavaScript\n * environment supports `fetch` natively, you'll probably want to pass that;\n * otherwise you can pass an equivalent (such as `fetch` via `node-fetch`).\n */\n fetch: typeof fetch;\n /**\n * A common set of options that will be used to make every request. Can be\n * overridden on the request level (e.g. to add headers).\n */\n fetchOptions?: FetchOptions;\n /**\n * A `loglevel` logger.\n */\n logger?: Pick<Logger, 'warn'>;\n /**\n * Options to pass to `createServicePolicy`. Note that `retryFilterPolicy` is\n * not accepted, as it is overwritten. See {@link createServicePolicy}.\n */\n policyOptions?: Omit<CreateServicePolicyOptions, 'retryFilterPolicy'>;\n /**\n * A function that checks if the user is currently offline. If it returns true,\n * connection errors will not be retried, preventing degraded and break\n * callbacks from being triggered.\n */\n isOffline: () => boolean;\n};\n\nconst log = createModuleLogger(projectLogger, 'RpcService');\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 4;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The list of error messages that represent a failure to connect to the network.\n *\n * This list was derived from Sindre Sorhus's `is-network-error` package:\n * <https://github.com/sindresorhus/is-network-error/blob/7bbfa8be9482ce1427a21fbff60e3ee1650dd091/index.js>\n */\nexport const CONNECTION_ERRORS = [\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /network error/u,\n },\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /Failed to fetch/u,\n },\n // Firefox\n {\n constructorName: 'TypeError',\n pattern: /NetworkError when attempting to fetch resource\\./u,\n },\n // Safari 16\n {\n constructorName: 'TypeError',\n pattern: /The Internet connection appears to be offline\\./u,\n },\n // Safari 17+\n {\n constructorName: 'TypeError',\n pattern: /Load failed/u,\n },\n // `cross-fetch`\n {\n constructorName: 'TypeError',\n pattern: /Network request failed/u,\n },\n // `node-fetch`\n {\n constructorName: 'FetchError',\n pattern: /request to (.+) failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /fetch failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /terminated/u,\n },\n];\n\n/**\n * Custom JSON-RPC error codes for specific cases.\n *\n * These should be moved to `@metamask/rpc-errors` eventually.\n */\nexport const CUSTOM_RPC_ERRORS = {\n unauthorized: -32006,\n httpClientError: -32080,\n} as const;\n\n/**\n * Determines whether the given error represents a failure to reach the network\n * after request parameters have been validated.\n *\n * This is somewhat difficult to verify because JavaScript engines (and in\n * some cases libraries) produce slightly different error messages for this\n * particular scenario, and we need to account for this.\n *\n * @param error - The error.\n * @returns True if the error indicates that the network cannot be connected to,\n * and false otherwise.\n */\nexport function isConnectionError(error: unknown): boolean {\n if (!(typeof error === 'object' && error !== null && 'message' in error)) {\n return false;\n }\n\n const { message } = error;\n\n return (\n typeof message === 'string' &&\n !isNockError(message) &&\n CONNECTION_ERRORS.some(({ constructorName, pattern }) => {\n return (\n error.constructor.name === constructorName && pattern.test(message)\n );\n })\n );\n}\n\n/**\n * Determines whether the given error message refers to a Nock error.\n *\n * It's important that if we failed to mock a request in a test, the resulting\n * error does not cause the request to be retried so that we can see it right\n * away.\n *\n * @param message - The error message to test.\n * @returns True if the message indicates a missing Nock mock, false otherwise.\n */\nfunction isNockError(message: string): boolean {\n return message.includes('Nock:');\n}\n\n/**\n * Determine whether the given error message indicates a failure to parse JSON.\n *\n * This is different in tests vs. implementation code because it may manifest as\n * a FetchError or a SyntaxError.\n *\n * @param error - The error object to test.\n * @returns True if the error indicates a JSON parse error, false otherwise.\n */\nexport function isJsonParseError(error: unknown): boolean {\n return (\n error instanceof SyntaxError ||\n /invalid json/iu.test(getErrorMessage(error))\n );\n}\n\n/**\n * Determines whether the given error represents a HTTP server error\n * (502, 503, or 504) that should be retried.\n *\n * @param error - The error object to test.\n * @returns True if the error has an httpStatus of 502, 503, or 504.\n */\nexport function isHttpServerError(error: Error): boolean {\n return (\n 'httpStatus' in error &&\n (error.httpStatus === 502 ||\n error.httpStatus === 503 ||\n error.httpStatus === 504)\n );\n}\n\n/**\n * Determines whether the given error has a `code` property of `ETIMEDOUT`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ETIMEDOUT`.\n */\nexport function isTimeoutError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ETIMEDOUT';\n}\n\n/**\n * Determines whether the given error has a `code` property of `ECONNRESET`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ECONNRESET`.\n */\nexport function isConnectionResetError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ECONNRESET';\n}\n\n/**\n * Guarantees a URL, even given a string. This is useful for checking components\n * of that URL.\n *\n * @param endpointUrlOrUrlString - Either a URL object or a string that\n * represents the URL of an endpoint.\n * @returns A URL object.\n */\nfunction getNormalizedEndpointUrl(endpointUrlOrUrlString: URL | string): URL {\n return endpointUrlOrUrlString instanceof URL\n ? endpointUrlOrUrlString\n : new URL(endpointUrlOrUrlString);\n}\n\n/**\n * Strips username and password from a URL.\n *\n * @param url - The URL to strip credentials from.\n * @returns A new URL object with credentials removed.\n */\nfunction stripCredentialsFromUrl(url: URL): URL {\n const strippedUrl = new URL(url.toString());\n strippedUrl.username = '';\n strippedUrl.password = '';\n return strippedUrl;\n}\n\n/**\n * This class is responsible for making a request to an endpoint that implements\n * the JSON-RPC protocol. It is designed to gracefully handle network and server\n * failures, retrying requests using exponential backoff. It also offers a hook\n * which can used to respond to slow requests.\n */\nexport class RpcService implements AbstractRpcService {\n /**\n * The URL of the RPC endpoint.\n */\n readonly endpointUrl: URL;\n\n /**\n * The last error that the retry policy captured (or `undefined` if the last\n * execution of the service was successful).\n */\n lastError: Error | undefined;\n\n /**\n * The RPC method name of the current request being processed. This is passed\n * to `onDegraded` event listeners.\n *\n * Initialised to `''` so the type is `string` throughout the event chain.\n * The empty string is unreachable in practice because the method name is\n * guaranteed to be set after the current request is completed but before\n * any `onDegraded` callbacks are called.\n */\n #currentRpcMethodName = '';\n\n /**\n * The function used to make an HTTP request.\n */\n readonly #fetch: typeof fetch;\n\n /**\n * A common set of options that the request options will extend.\n */\n readonly #fetchOptions: FetchOptions;\n\n /**\n * A `loglevel` logger.\n */\n readonly #logger: RpcServiceOptions['logger'];\n\n /**\n * The policy that wraps the request.\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new RpcService object.\n *\n * @param options - The options. See {@link RpcServiceOptions}.\n */\n constructor(options: RpcServiceOptions) {\n const {\n btoa: givenBtoa,\n endpointUrl,\n fetch: givenFetch,\n logger,\n fetchOptions = {},\n policyOptions = {},\n isOffline,\n } = options;\n\n this.#fetch = givenFetch;\n const normalizedUrl = getNormalizedEndpointUrl(endpointUrl);\n this.#fetchOptions = this.#getDefaultFetchOptions(\n normalizedUrl,\n fetchOptions,\n givenBtoa,\n );\n this.endpointUrl = stripCredentialsFromUrl(normalizedUrl);\n this.#logger = logger;\n\n this.#policy = createServicePolicy({\n maxRetries: DEFAULT_MAX_RETRIES,\n maxConsecutiveFailures: DEFAULT_MAX_CONSECUTIVE_FAILURES,\n ...policyOptions,\n retryFilterPolicy: handleWhen((error) => {\n // If user is offline, don't retry any errors\n // This prevents degraded/break callbacks from being triggered\n if (isOffline()) {\n return false;\n }\n\n return (\n // Ignore errors where the request failed to establish\n isConnectionError(error) ||\n // Ignore server sent HTML error pages or truncated JSON responses\n isJsonParseError(error) ||\n // Ignore server overload errors\n isHttpServerError(error) ||\n // Ignore timeout errors\n isTimeoutError(error) ||\n // Ignore connection reset errors\n isConnectionResetError(error)\n );\n }),\n });\n }\n\n /**\n * Resets the underlying composite Cockatiel policy.\n *\n * This is useful in a collection of RpcServices where some act as failovers\n * for others where you effectively want to invalidate the failovers when the\n * primary recovers.\n */\n resetPolicy(): void {\n this.#policy.reset();\n }\n\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState(): CircuitState {\n return this.#policy.getCircuitState();\n }\n\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<AbstractRpcService['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry((data) => {\n listener({ ...data, endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row, causing the underlying circuit to break.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<AbstractRpcService['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak((data) => {\n // `{ isolated: true }` is a special object that shows up when `isolate`\n // is called on the circuit breaker. Usually `isolate` is used to hold the\n // circuit open, but we (ab)use this method in `createServicePolicy` to\n // reset the circuit breaker policy. When we do this, we don't want to\n // call `onBreak` handlers, because then it causes\n // `NetworkController:rpcEndpointUnavailable` and\n // `NetworkController:rpcEndpointChainUnavailable` to be published. So we\n // have to ignore that object here. The consequence is that `isolate`\n // doesn't function the way it is intended, at least in the context of an\n // RpcService. However, we are making a bet that we won't need to use it\n // other than how we are already using it.\n if (!('isolated' in data)) {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: Parameters<AbstractRpcService['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded((data) => {\n if (data === undefined) {\n listener({\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n } else {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onAvailable} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: Parameters<AbstractRpcService['onAvailable']>[0],\n ): IDisposable {\n return this.#policy.onAvailable(() => {\n listener({ endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is specifically designed for `eth_getBlockByNumber`, which\n * can return a `result` of `null` despite an expected `Result` being\n * provided.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params> & { method: 'eth_getBlockByNumber' },\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>>;\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is designed for all RPC methods except for\n * `eth_getBlockByNumber`, which are expected to return a `result` of the\n * expected `Result`.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result>>;\n\n async request<Params extends JsonRpcParams, Result extends Json>(\n // The request object may be frozen and must not be mutated.\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions = {},\n ): Promise<JsonRpcResponse<Result | null>> {\n const completeFetchOptions = this.#getCompleteFetchOptions(\n jsonRpcRequest,\n fetchOptions,\n );\n return await this.#executeAndProcessRequest<Result>(\n completeFetchOptions,\n jsonRpcRequest.method,\n );\n }\n\n /**\n * Constructs a default set of options to `fetch`.\n *\n * If a username and password are present in the URL, they are extracted to an\n * Authorization header.\n *\n * @param endpointUrl - The endpoint URL.\n * @param fetchOptions - The options to `fetch`.\n * @param givenBtoa - An implementation of `btoa`.\n * @returns The default fetch options.\n */\n #getDefaultFetchOptions(\n endpointUrl: URL,\n fetchOptions: FetchOptions,\n givenBtoa: (stringToEncode: string) => string,\n ): FetchOptions {\n if (endpointUrl.username && endpointUrl.password) {\n const authString = `${endpointUrl.username}:${endpointUrl.password}`;\n const encodedCredentials = givenBtoa(authString);\n return deepmerge(fetchOptions, {\n headers: { Authorization: `Basic ${encodedCredentials}` },\n });\n }\n\n return fetchOptions;\n }\n\n /**\n * Constructs a final set of options to pass to `fetch`. Note that the method\n * defaults to `post`, and the JSON-RPC request is automatically JSON-encoded.\n *\n * @param jsonRpcRequest - The JSON-RPC request.\n * @param fetchOptions - Custom `fetch` options.\n * @returns The complete set of `fetch` options.\n */\n #getCompleteFetchOptions<Params extends JsonRpcParams>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions,\n ): FetchOptions {\n const defaultOptions = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n };\n const mergedOptions = deepmerge(\n defaultOptions,\n deepmerge(this.#fetchOptions, fetchOptions),\n );\n\n const { id, jsonrpc, method, params } = jsonRpcRequest;\n const body = JSON.stringify({\n id,\n jsonrpc,\n method,\n params,\n });\n\n return { ...mergedOptions, body };\n }\n\n /**\n * Makes the request using the Cockatiel policy that this service creates.\n *\n * @param fetchOptions - The options for `fetch`; will be combined with the\n * fetch options passed to the constructor\n * @param rpcMethodName - The JSON-RPC method name of the current request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async #executeAndProcessRequest<Result extends Json>(\n fetchOptions: FetchOptions,\n rpcMethodName: string,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>> {\n let response: Response | undefined;\n try {\n log(\n `[${this.endpointUrl}] Circuit state`,\n this.#policy.getCircuitState(),\n );\n const jsonDecodedResponse = await this.#policy.execute(\n async (context) => {\n try {\n log(\n 'REQUEST INITIATED:',\n this.endpointUrl.toString(),\n '::',\n fetchOptions,\n // @ts-expect-error This property _is_ here, the type of\n // ServicePolicy is just wrong.\n `(attempt ${context.attempt + 1})`,\n );\n response = await this.#fetch(this.endpointUrl, fetchOptions);\n if (!response.ok) {\n throw new HttpError(response.status);\n }\n log(\n 'REQUEST SUCCESSFUL:',\n this.endpointUrl.toString(),\n response.status,\n );\n return await response.json();\n } finally {\n // Track the RPC method for the request that has just taken place.\n // We pass this property to `onDegraded` event listeners.\n //\n // We set this property after the request completes and not before\n // the request starts to account for race conditions. That is, if\n // there are two requests that are being performed concurrently, and\n // the second request fails fast but the first request succeeds\n // slowly, when `onDegraded` is called we want it to include the\n // first request as the RPC method, not the second.\n //\n // Also, we set this property within a `finally` block inside of the\n // function passed to `policy.execute` to ensure that it is set\n // before `onDegraded` gets called, no matter the outcome of the\n // request.\n this.#currentRpcMethodName = rpcMethodName;\n }\n },\n );\n this.lastError = undefined;\n return jsonDecodedResponse;\n } catch (error) {\n log('REQUEST ERROR:', this.endpointUrl.toString(), error);\n\n this.lastError =\n error instanceof Error ? error : new Error(getErrorMessage(error));\n\n if (error instanceof HttpError) {\n const status = error.httpStatus;\n if (status === 401) {\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.unauthorized,\n 'Unauthorized.',\n {\n httpStatus: status,\n },\n );\n }\n if (status === 429) {\n throw rpcErrors.limitExceeded({\n message: 'Request is being rate limited.',\n data: {\n httpStatus: status,\n },\n });\n }\n if (status >= 500 || status === 402 || status === 404) {\n throw rpcErrors.resourceUnavailable({\n message: 'RPC endpoint not found or unavailable.',\n data: {\n httpStatus: status,\n },\n });\n }\n\n // Handle all other 4xx errors as generic HTTP client errors\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.httpClientError,\n 'RPC endpoint returned HTTP client error.',\n {\n httpStatus: status,\n },\n );\n } else if (isJsonParseError(error)) {\n throw rpcErrors.parse({\n message: 'RPC endpoint did not return JSON.',\n });\n } else if (error instanceof BrokenCircuitError) {\n this.#logger?.warn(error);\n const remainingCircuitOpenDuration =\n this.#policy.getRemainingCircuitOpenDuration();\n const formattedRemainingCircuitOpenDuration = Intl.NumberFormat(\n undefined,\n { maximumFractionDigits: 2 },\n ).format(\n (remainingCircuitOpenDuration ?? this.#policy.circuitBreakDuration) /\n Duration.Minute,\n );\n throw rpcErrors.resourceUnavailable({\n message: `RPC endpoint returned too many errors, retrying in ${formattedRemainingCircuitOpenDuration} minutes. Consider using a different RPC endpoint.`,\n });\n }\n throw error;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"rpc-service.mjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,UAAU,EACX,mCAAmC;AACpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAC/D,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,wBAAwB;AAOzE,OAAO,EAAE,YAAY,EAAE,kBAAkB;AACzC,OAAO,UAAS,kBAAkB;;AAGlC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAkB;AAkD9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,SAAS;IACT;QACE,eAAe,EAAE,WAAW;QAC5B,OAAO,EAAE,gBAAgB;KAC1B;IACD,SAAS;IACT;QACE,eAAe,EAAE,WAAW;QAC5B,OAAO,EAAE,kBAAkB;KAC5B;IACD,UAAU;IACV;QACE,eAAe,EAAE,WAAW;QAC5B,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from '@metamask/controller-utils';\nimport {\n BrokenCircuitError,\n HttpError,\n createServicePolicy,\n handleWhen,\n} from '@metamask/controller-utils';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { Duration, getErrorMessage, hasProperty } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\nimport { CircuitState } from 'cockatiel';\nimport deepmerge from 'deepmerge';\nimport type { Logger } from 'loglevel';\n\nimport { projectLogger, createModuleLogger } from '../logger';\nimport type {\n CockatielEventToEventListenerWithData,\n ExcludeCockatielEventData,\n ExtendCockatielEventData,\n ExtractCockatielEventData,\n FetchOptions,\n} from './shared';\n\n/**\n * Options for the RpcService constructor.\n */\nexport type RpcServiceOptions = {\n /**\n * A function that can be used to convert a binary string into a\n * base64-encoded ASCII string. Used to encode authorization credentials.\n */\n btoa: typeof btoa;\n /**\n * The URL of the RPC endpoint to hit.\n */\n endpointUrl: URL | string;\n /**\n * A function that can be used to make an HTTP request. If your JavaScript\n * environment supports `fetch` natively, you'll probably want to pass that;\n * otherwise you can pass an equivalent (such as `fetch` via `node-fetch`).\n */\n fetch: typeof fetch;\n /**\n * A common set of options that will be used to make every request. Can be\n * overridden on the request level (e.g. to add headers).\n */\n fetchOptions?: FetchOptions;\n /**\n * A `loglevel` logger.\n */\n logger?: Pick<Logger, 'warn'>;\n /**\n * Options to pass to `createServicePolicy`. Note that `retryFilterPolicy` is\n * not accepted, as it is overwritten. See {@link createServicePolicy}.\n */\n policyOptions?: Omit<CreateServicePolicyOptions, 'retryFilterPolicy'>;\n /**\n * A function that checks if the user is currently offline. If it returns true,\n * connection errors will not be retried, preventing degraded and break\n * callbacks from being triggered.\n */\n isOffline: () => boolean;\n};\n\nconst log = createModuleLogger(projectLogger, 'RpcService');\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 4;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The list of error messages that represent a failure to connect to the network.\n *\n * This list was derived from Sindre Sorhus's `is-network-error` package:\n * <https://github.com/sindresorhus/is-network-error/blob/7bbfa8be9482ce1427a21fbff60e3ee1650dd091/index.js>\n */\nexport const CONNECTION_ERRORS = [\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /network error/u,\n },\n // Chrome\n {\n constructorName: 'TypeError',\n pattern: /Failed to fetch/u,\n },\n // Firefox\n {\n constructorName: 'TypeError',\n pattern: /NetworkError when attempting to fetch resource\\./u,\n },\n // Safari 16\n {\n constructorName: 'TypeError',\n pattern: /The Internet connection appears to be offline\\./u,\n },\n // Safari 17+\n {\n constructorName: 'TypeError',\n pattern: /Load failed/u,\n },\n // `cross-fetch`\n {\n constructorName: 'TypeError',\n pattern: /Network request failed/u,\n },\n // `node-fetch`\n {\n constructorName: 'FetchError',\n pattern: /request to (.+) failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /fetch failed/u,\n },\n // Undici (Node.js)\n {\n constructorName: 'TypeError',\n pattern: /terminated/u,\n },\n];\n\n/**\n * Custom JSON-RPC error codes for specific cases.\n *\n * These should be moved to `@metamask/rpc-errors` eventually.\n */\nexport const CUSTOM_RPC_ERRORS = {\n unauthorized: -32006,\n httpClientError: -32080,\n} as const;\n\n/**\n * Determines whether the given error represents a failure to reach the network\n * after request parameters have been validated.\n *\n * This is somewhat difficult to verify because JavaScript engines (and in\n * some cases libraries) produce slightly different error messages for this\n * particular scenario, and we need to account for this.\n *\n * @param error - The error.\n * @returns True if the error indicates that the network cannot be connected to,\n * and false otherwise.\n */\nexport function isConnectionError(error: unknown): boolean {\n if (!(typeof error === 'object' && error !== null && 'message' in error)) {\n return false;\n }\n\n const { message } = error;\n\n return (\n typeof message === 'string' &&\n !isNockError(message) &&\n CONNECTION_ERRORS.some(({ constructorName, pattern }) => {\n return (\n error.constructor.name === constructorName && pattern.test(message)\n );\n })\n );\n}\n\n/**\n * Determines whether the given error message refers to a Nock error.\n *\n * It's important that if we failed to mock a request in a test, the resulting\n * error does not cause the request to be retried so that we can see it right\n * away.\n *\n * @param message - The error message to test.\n * @returns True if the message indicates a missing Nock mock, false otherwise.\n */\nfunction isNockError(message: string): boolean {\n return message.includes('Nock:');\n}\n\n/**\n * Determine whether the given error message indicates a failure to parse JSON.\n *\n * This is different in tests vs. implementation code because it may manifest as\n * a FetchError or a SyntaxError.\n *\n * @param error - The error object to test.\n * @returns True if the error indicates a JSON parse error, false otherwise.\n */\nexport function isJsonParseError(error: unknown): boolean {\n return (\n error instanceof SyntaxError ||\n /invalid json/iu.test(getErrorMessage(error))\n );\n}\n\n/**\n * Determines whether the given error represents a HTTP server error\n * (502, 503, or 504) that should be retried.\n *\n * @param error - The error object to test.\n * @returns True if the error has an httpStatus of 502, 503, or 504.\n */\nexport function isHttpServerError(error: Error): boolean {\n return (\n 'httpStatus' in error &&\n (error.httpStatus === 502 ||\n error.httpStatus === 503 ||\n error.httpStatus === 504)\n );\n}\n\n/**\n * Determines whether the given error has a `code` property of `ETIMEDOUT`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ETIMEDOUT`.\n */\nexport function isTimeoutError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ETIMEDOUT';\n}\n\n/**\n * Determines whether the given error has a `code` property of `ECONNRESET`.\n *\n * @param error - The error object to test.\n * @returns True if the error code is `ECONNRESET`.\n */\nexport function isConnectionResetError(error: Error): boolean {\n return hasProperty(error, 'code') && error.code === 'ECONNRESET';\n}\n\n/**\n * Guarantees a URL, even given a string. This is useful for checking components\n * of that URL.\n *\n * @param endpointUrlOrUrlString - Either a URL object or a string that\n * represents the URL of an endpoint.\n * @returns A URL object.\n */\nfunction getNormalizedEndpointUrl(endpointUrlOrUrlString: URL | string): URL {\n return endpointUrlOrUrlString instanceof URL\n ? endpointUrlOrUrlString\n : new URL(endpointUrlOrUrlString);\n}\n\n/**\n * Strips username and password from a URL.\n *\n * @param url - The URL to strip credentials from.\n * @returns A new URL object with credentials removed.\n */\nfunction stripCredentialsFromUrl(url: URL): URL {\n const strippedUrl = new URL(url.toString());\n strippedUrl.username = '';\n strippedUrl.password = '';\n return strippedUrl;\n}\n\n/**\n * This class is responsible for making a request to an endpoint that implements\n * the JSON-RPC protocol. It is designed to gracefully handle network and server\n * failures, retrying requests using exponential backoff. It also offers a hook\n * which can used to respond to slow requests.\n */\nexport class RpcService {\n /**\n * The URL of the RPC endpoint.\n */\n readonly endpointUrl: URL;\n\n /**\n * The last error that the retry policy captured (or `undefined` if the last\n * execution of the service was successful).\n */\n lastError: Error | undefined;\n\n /**\n * The RPC method name of the current request being processed. This is passed\n * to `onDegraded` event listeners.\n *\n * Initialised to `''` so the type is `string` throughout the event chain.\n * The empty string is unreachable in practice because the method name is\n * guaranteed to be set after the current request is completed but before\n * any `onDegraded` callbacks are called.\n */\n #currentRpcMethodName = '';\n\n /**\n * The function used to make an HTTP request.\n */\n readonly #fetch: typeof fetch;\n\n /**\n * A common set of options that the request options will extend.\n */\n readonly #fetchOptions: FetchOptions;\n\n /**\n * A `loglevel` logger.\n */\n readonly #logger: RpcServiceOptions['logger'];\n\n /**\n * The policy that wraps the request.\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new RpcService object.\n *\n * @param options - The options. See {@link RpcServiceOptions}.\n */\n constructor(options: RpcServiceOptions) {\n const {\n btoa: givenBtoa,\n endpointUrl,\n fetch: givenFetch,\n logger,\n fetchOptions = {},\n policyOptions = {},\n isOffline,\n } = options;\n\n this.#fetch = givenFetch;\n const normalizedUrl = getNormalizedEndpointUrl(endpointUrl);\n this.#fetchOptions = this.#getDefaultFetchOptions(\n normalizedUrl,\n fetchOptions,\n givenBtoa,\n );\n this.endpointUrl = stripCredentialsFromUrl(normalizedUrl);\n this.#logger = logger;\n\n this.#policy = createServicePolicy({\n maxRetries: DEFAULT_MAX_RETRIES,\n maxConsecutiveFailures: DEFAULT_MAX_CONSECUTIVE_FAILURES,\n ...policyOptions,\n retryFilterPolicy: handleWhen((error) => {\n // If user is offline, don't retry any errors\n // This prevents degraded/break callbacks from being triggered\n if (isOffline()) {\n return false;\n }\n\n return (\n // Ignore errors where the request failed to establish\n isConnectionError(error) ||\n // Ignore server sent HTML error pages or truncated JSON responses\n isJsonParseError(error) ||\n // Ignore server overload errors\n isHttpServerError(error) ||\n // Ignore timeout errors\n isTimeoutError(error) ||\n // Ignore connection reset errors\n isConnectionResetError(error)\n );\n }),\n });\n }\n\n /**\n * Resets the underlying composite Cockatiel policy.\n *\n * This is useful in a collection of RpcServices where some act as failovers\n * for others where you effectively want to invalidate the failovers when the\n * primary recovers.\n */\n resetPolicy(): void {\n this.#policy.reset();\n }\n\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState(): CircuitState {\n return this.#policy.getCircuitState();\n }\n\n /**\n * Listens for when the RPC service retries the request.\n *\n * @param listener - The callback to be called when the retry occurs.\n * @returns What {@link ServicePolicy.onRetry} returns.\n * @see {@link createServicePolicy}\n */\n onRetry(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onRetry'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onRetry']> {\n return this.#policy.onRetry((data) => {\n listener({ ...data, endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Listens for when the RPC service retries the request too many times in a\n * row, causing the underlying circuit to break.\n *\n * @param listener - The callback to be called when the circuit is broken.\n * @returns What {@link ServicePolicy.onBreak} returns.\n * @see {@link createServicePolicy}\n */\n onBreak(\n listener: (\n data: ExcludeCockatielEventData<\n ExtendCockatielEventData<\n ExtractCockatielEventData<ServicePolicy['onBreak']>,\n { endpointUrl: string }\n >,\n 'isolated'\n >,\n ) => void,\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak((data) => {\n // `{ isolated: true }` is a special object that shows up when `isolate`\n // is called on the circuit breaker. Usually `isolate` is used to hold the\n // circuit open, but we (ab)use this method in `createServicePolicy` to\n // reset the circuit breaker policy. When we do this, we don't want to\n // call `onBreak` handlers, because then it causes\n // `NetworkController:rpcEndpointUnavailable` and\n // `NetworkController:rpcEndpointChainUnavailable` to be published. So we\n // have to ignore that object here. The consequence is that `isolate`\n // doesn't function the way it is intended, at least in the context of an\n // RpcService. However, we are making a bet that we won't need to use it\n // other than how we are already using it.\n if (!('isolated' in data)) {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service detects a slow\n * request.\n *\n * @param listener - The callback to be called when the request is slow.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onDegraded'],\n { endpointUrl: string; rpcMethodName: string }\n >,\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded((data) => {\n if (data === undefined) {\n listener({\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n } else {\n listener({\n ...data,\n endpointUrl: this.endpointUrl.toString(),\n rpcMethodName: this.#currentRpcMethodName,\n });\n }\n });\n }\n\n /**\n * Listens for when the policy underlying this RPC service is available.\n *\n * @param listener - The callback to be called when the request is available.\n * @returns What {@link ServicePolicy.onAvailable} returns.\n * @see {@link createServicePolicy}\n */\n onAvailable(\n listener: CockatielEventToEventListenerWithData<\n ServicePolicy['onAvailable'],\n { endpointUrl: string }\n >,\n ): ReturnType<ServicePolicy['onAvailable']> {\n return this.#policy.onAvailable(() => {\n listener({ endpointUrl: this.endpointUrl.toString() });\n });\n }\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is specifically designed for `eth_getBlockByNumber`, which\n * can return a `result` of `null` despite an expected `Result` being\n * provided.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params> & { method: 'eth_getBlockByNumber' },\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>>;\n\n /**\n * Makes a request to the RPC endpoint.\n *\n * This overload is designed for all RPC methods except for\n * `eth_getBlockByNumber`, which are expected to return a `result` of the\n * expected `Result`.\n *\n * @param jsonRpcRequest - The JSON-RPC request to send to the endpoint.\n * @param fetchOptions - An options bag for {@link fetch} which further\n * specifies the request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: FetchOptions,\n ): Promise<JsonRpcResponse<Result>>;\n\n async request<Params extends JsonRpcParams, Result extends Json>(\n // The request object may be frozen and must not be mutated.\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions = {},\n ): Promise<JsonRpcResponse<Result | null>> {\n const completeFetchOptions = this.#getCompleteFetchOptions(\n jsonRpcRequest,\n fetchOptions,\n );\n return await this.#executeAndProcessRequest<Result>(\n completeFetchOptions,\n jsonRpcRequest.method,\n );\n }\n\n /**\n * Constructs a default set of options to `fetch`.\n *\n * If a username and password are present in the URL, they are extracted to an\n * Authorization header.\n *\n * @param endpointUrl - The endpoint URL.\n * @param fetchOptions - The options to `fetch`.\n * @param givenBtoa - An implementation of `btoa`.\n * @returns The default fetch options.\n */\n #getDefaultFetchOptions(\n endpointUrl: URL,\n fetchOptions: FetchOptions,\n givenBtoa: (stringToEncode: string) => string,\n ): FetchOptions {\n if (endpointUrl.username && endpointUrl.password) {\n const authString = `${endpointUrl.username}:${endpointUrl.password}`;\n const encodedCredentials = givenBtoa(authString);\n return deepmerge(fetchOptions, {\n headers: { Authorization: `Basic ${encodedCredentials}` },\n });\n }\n\n return fetchOptions;\n }\n\n /**\n * Constructs a final set of options to pass to `fetch`. Note that the method\n * defaults to `post`, and the JSON-RPC request is automatically JSON-encoded.\n *\n * @param jsonRpcRequest - The JSON-RPC request.\n * @param fetchOptions - Custom `fetch` options.\n * @returns The complete set of `fetch` options.\n */\n #getCompleteFetchOptions<Params extends JsonRpcParams>(\n jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,\n fetchOptions: FetchOptions,\n ): FetchOptions {\n const defaultOptions = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n };\n const mergedOptions = deepmerge(\n defaultOptions,\n deepmerge(this.#fetchOptions, fetchOptions),\n );\n\n const { id, jsonrpc, method, params } = jsonRpcRequest;\n const body = JSON.stringify({\n id,\n jsonrpc,\n method,\n params,\n });\n\n return { ...mergedOptions, body };\n }\n\n /**\n * Makes the request using the Cockatiel policy that this service creates.\n *\n * @param fetchOptions - The options for `fetch`; will be combined with the\n * fetch options passed to the constructor\n * @param rpcMethodName - The JSON-RPC method name of the current request.\n * @returns The decoded JSON-RPC response from the endpoint.\n * @throws An \"authorized\" JSON-RPC error (code -32006) if the response HTTP status is 401.\n * @throws A \"rate limiting\" JSON-RPC error (code -32005) if the response HTTP status is 429.\n * @throws A \"resource unavailable\" JSON-RPC error (code -32002) if the response HTTP status is 402, 404, or any 5xx.\n * @throws A generic HTTP client JSON-RPC error (code -32050) for any other 4xx HTTP status codes.\n * @throws A \"parse\" JSON-RPC error (code -32700) if the response is not valid JSON.\n */\n async #executeAndProcessRequest<Result extends Json>(\n fetchOptions: FetchOptions,\n rpcMethodName: string,\n ): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>> {\n let response: Response | undefined;\n try {\n log(\n `[${this.endpointUrl}] Circuit state`,\n this.#policy.getCircuitState(),\n );\n const jsonDecodedResponse = await this.#policy.execute(\n async (context) => {\n try {\n log(\n 'REQUEST INITIATED:',\n this.endpointUrl.toString(),\n '::',\n fetchOptions,\n // @ts-expect-error This property _is_ here, the type of\n // ServicePolicy is just wrong.\n `(attempt ${context.attempt + 1})`,\n );\n response = await this.#fetch(this.endpointUrl, fetchOptions);\n if (!response.ok) {\n throw new HttpError(response.status);\n }\n log(\n 'REQUEST SUCCESSFUL:',\n this.endpointUrl.toString(),\n response.status,\n );\n return await response.json();\n } finally {\n // Track the RPC method for the request that has just taken place.\n // We pass this property to `onDegraded` event listeners.\n //\n // We set this property after the request completes and not before\n // the request starts to account for race conditions. That is, if\n // there are two requests that are being performed concurrently, and\n // the second request fails fast but the first request succeeds\n // slowly, when `onDegraded` is called we want it to include the\n // first request as the RPC method, not the second.\n //\n // Also, we set this property within a `finally` block inside of the\n // function passed to `policy.execute` to ensure that it is set\n // before `onDegraded` gets called, no matter the outcome of the\n // request.\n this.#currentRpcMethodName = rpcMethodName;\n }\n },\n );\n this.lastError = undefined;\n return jsonDecodedResponse;\n } catch (error) {\n log('REQUEST ERROR:', this.endpointUrl.toString(), error);\n\n this.lastError =\n error instanceof Error ? error : new Error(getErrorMessage(error));\n\n if (error instanceof HttpError) {\n const status = error.httpStatus;\n if (status === 401) {\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.unauthorized,\n 'Unauthorized.',\n {\n httpStatus: status,\n },\n );\n }\n if (status === 429) {\n throw rpcErrors.limitExceeded({\n message: 'Request is being rate limited.',\n data: {\n httpStatus: status,\n },\n });\n }\n if (status >= 500 || status === 402 || status === 404) {\n throw rpcErrors.resourceUnavailable({\n message: 'RPC endpoint not found or unavailable.',\n data: {\n httpStatus: status,\n },\n });\n }\n\n // Handle all other 4xx errors as generic HTTP client errors\n throw new JsonRpcError(\n CUSTOM_RPC_ERRORS.httpClientError,\n 'RPC endpoint returned HTTP client error.',\n {\n httpStatus: status,\n },\n );\n } else if (isJsonParseError(error)) {\n throw rpcErrors.parse({\n message: 'RPC endpoint did not return JSON.',\n });\n } else if (error instanceof BrokenCircuitError) {\n this.#logger?.warn(error);\n const remainingCircuitOpenDuration =\n this.#policy.getRemainingCircuitOpenDuration();\n const formattedRemainingCircuitOpenDuration = Intl.NumberFormat(\n undefined,\n { maximumFractionDigits: 2 },\n ).format(\n (remainingCircuitOpenDuration ?? this.#policy.circuitBreakDuration) /\n Duration.Minute,\n );\n throw rpcErrors.resourceUnavailable({\n message: `RPC endpoint returned too many errors, retrying in ${formattedRemainingCircuitOpenDuration} minutes. Consider using a different RPC endpoint.`,\n });\n }\n throw error;\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/network-controller",
3
- "version": "30.0.1-preview-b441b46d7",
3
+ "version": "30.0.1-preview-5d0317d14",
4
4
  "description": "Provides an interface to the currently selected network via a MetaMask-compatible provider object",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "devDependencies": {
78
78
  "@json-rpc-specification/meta-schema": "^1.0.6",
79
- "@metamask/auto-changelog": "^6.0.0",
79
+ "@metamask/auto-changelog": "^6.1.0",
80
80
  "@ts-bridge/cli": "^0.6.4",
81
81
  "@types/deep-freeze-strict": "^1.1.0",
82
82
  "@types/jest": "^29.5.14",