@metamask-previews/network-controller 33.0.0-preview-5c294abf8 → 33.0.0-preview-e0ee14da7
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 +20 -0
- package/dist/NetworkController-method-action-types.cjs.map +1 -1
- package/dist/NetworkController-method-action-types.d.cts +1 -19
- package/dist/NetworkController-method-action-types.d.cts.map +1 -1
- package/dist/NetworkController-method-action-types.d.mts +1 -19
- package/dist/NetworkController-method-action-types.d.mts.map +1 -1
- package/dist/NetworkController-method-action-types.mjs.map +1 -1
- package/dist/NetworkController.cjs +74 -37
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +15 -15
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +15 -15
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +75 -38
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/create-auto-managed-network-client.cjs +10 -15
- package/dist/create-auto-managed-network-client.cjs.map +1 -1
- package/dist/create-auto-managed-network-client.d.cts +8 -7
- package/dist/create-auto-managed-network-client.d.cts.map +1 -1
- package/dist/create-auto-managed-network-client.d.mts +8 -7
- package/dist/create-auto-managed-network-client.d.mts.map +1 -1
- package/dist/create-auto-managed-network-client.mjs +10 -15
- package/dist/create-auto-managed-network-client.mjs.map +1 -1
- package/dist/create-network-client.cjs +54 -24
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.d.cts +7 -7
- package/dist/create-network-client.d.cts.map +1 -1
- package/dist/create-network-client.d.mts +7 -7
- package/dist/create-network-client.d.mts.map +1 -1
- package/dist/create-network-client.mjs +54 -24
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/rpc-service-events.cjs +87 -0
- package/dist/rpc-service-events.cjs.map +1 -0
- package/dist/rpc-service-events.d.cts +85 -0
- package/dist/rpc-service-events.d.cts.map +1 -0
- package/dist/rpc-service-events.d.mts +85 -0
- package/dist/rpc-service-events.d.mts.map +1 -0
- package/dist/rpc-service-events.mjs +81 -0
- package/dist/rpc-service-events.mjs.map +1 -0
- package/dist/selectors.cjs +12 -6
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +20 -1
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +20 -1
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +10 -4
- package/dist/selectors.mjs.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AnalyticsTrackingEvent } from "@metamask/analytics-controller";
|
|
2
|
+
import type { Hex, Json } from "@metamask/utils";
|
|
3
|
+
import type { DegradedEventType, RetryReason } from "./create-network-client.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* The names of the analytics events that {@link NetworkController} emits when an
|
|
6
|
+
* RPC endpoint becomes unavailable or degraded.
|
|
7
|
+
*/
|
|
8
|
+
export type RpcServiceEventName = 'RPC Service Unavailable' | 'RPC Service Degraded';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration that enables {@link NetworkController} to emit analytics events
|
|
11
|
+
* for unavailable or degraded RPC endpoints.
|
|
12
|
+
*
|
|
13
|
+
* The pieces here are client-specific and cannot be derived inside the
|
|
14
|
+
* controller: deciding whether an endpoint URL is safe to report depends on the
|
|
15
|
+
* client's lists of known networks, and the sample rate depends on the client's
|
|
16
|
+
* build environment.
|
|
17
|
+
*/
|
|
18
|
+
export type NetworkControllerAnalyticsOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Returns `true` if the given RPC endpoint URL is safe to report verbatim (a
|
|
21
|
+
* "public" endpoint), or `false` if it must be reported as the literal string
|
|
22
|
+
* `'custom'` to avoid leaking private servers.
|
|
23
|
+
*/
|
|
24
|
+
isRpcEndpointUrlPublic: (endpointUrl: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The proportion of events to emit, between 0 and 1. `1` emits every event,
|
|
27
|
+
* `0` emits none. Clients typically use a small value (e.g. `0.01`) in
|
|
28
|
+
* production to stay within their analytics quota, and `1` in development.
|
|
29
|
+
*/
|
|
30
|
+
rpcServiceEventsSampleRate: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Hides any API key contained in an RPC endpoint URL by reducing it to its
|
|
34
|
+
* host, but only when the endpoint is considered public. Non-public endpoints
|
|
35
|
+
* (and URLs that cannot be parsed) are reported as the literal string
|
|
36
|
+
* `'custom'`.
|
|
37
|
+
*
|
|
38
|
+
* @param endpointUrl - The URL of the RPC endpoint.
|
|
39
|
+
* @param isPublic - Whether the endpoint is safe to report verbatim.
|
|
40
|
+
* @returns The sanitized value to report.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sanitizeRpcEndpointUrl(endpointUrl: string, isPublic: boolean): string;
|
|
43
|
+
/**
|
|
44
|
+
* Builds the properties for an "RPC Service Unavailable" or "RPC Service
|
|
45
|
+
* Degraded" analytics event.
|
|
46
|
+
*
|
|
47
|
+
* @param args - The arguments.
|
|
48
|
+
* @param args.chainId - The chain ID that the endpoint represents.
|
|
49
|
+
* @param args.endpointUrl - The URL of the endpoint.
|
|
50
|
+
* @param args.error - The connection or response error encountered after making
|
|
51
|
+
* a request to the RPC endpoint.
|
|
52
|
+
* @param args.isRpcEndpointUrlPublic - Returns whether the endpoint URL is safe
|
|
53
|
+
* to report verbatim.
|
|
54
|
+
* @param args.duration - The policy execution time in milliseconds when the
|
|
55
|
+
* request succeeded but was slow (degraded events only).
|
|
56
|
+
* @param args.retryReason - The category of error that was retried (degraded
|
|
57
|
+
* events only).
|
|
58
|
+
* @param args.rpcMethodName - The JSON-RPC method that was being executed
|
|
59
|
+
* (degraded events only).
|
|
60
|
+
* @param args.traceId - The value of the `X-Trace-Id` response header from the
|
|
61
|
+
* last request attempt (degraded events only).
|
|
62
|
+
* @param args.type - Why the endpoint became degraded (degraded events only).
|
|
63
|
+
* @returns The analytics event properties.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildRpcServiceEventProperties({ chainId, endpointUrl, error, isRpcEndpointUrlPublic, duration, retryReason, rpcMethodName, traceId, type, }: {
|
|
66
|
+
chainId: Hex;
|
|
67
|
+
endpointUrl: string;
|
|
68
|
+
error: unknown;
|
|
69
|
+
isRpcEndpointUrlPublic: (endpointUrl: string) => boolean;
|
|
70
|
+
duration?: number;
|
|
71
|
+
retryReason?: RetryReason;
|
|
72
|
+
rpcMethodName?: string;
|
|
73
|
+
traceId?: string;
|
|
74
|
+
type?: DegradedEventType;
|
|
75
|
+
}): Record<string, Json>;
|
|
76
|
+
/**
|
|
77
|
+
* Wraps an event name and properties into the shape expected by the
|
|
78
|
+
* `AnalyticsController:trackEvent` action.
|
|
79
|
+
*
|
|
80
|
+
* @param name - The analytics event name.
|
|
81
|
+
* @param properties - The analytics event properties.
|
|
82
|
+
* @returns The analytics tracking event.
|
|
83
|
+
*/
|
|
84
|
+
export declare function toAnalyticsTrackingEvent(name: RpcServiceEventName, properties: Record<string, Json>): AnalyticsTrackingEvent;
|
|
85
|
+
//# sourceMappingURL=rpc-service-events.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-service-events.d.cts","sourceRoot":"","sources":["../src/rpc-service-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uCAAuC;AAC7E,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAQjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,oCAAgC;AAE9E;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC3B,yBAAyB,GACzB,sBAAsB,CAAC;AAE3B;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C;;;;OAIG;IACH,sBAAsB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IACzD;;;;OAIG;IACH,0BAA0B,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,GAChB,MAAM,CAUR;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,OAAO,EACP,WAAW,EACX,KAAK,EACL,sBAAsB,EACtB,QAAQ,EACR,WAAW,EACX,aAAa,EACb,OAAO,EACP,IAAI,GACL,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,sBAAsB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAsBvB;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAC/B,sBAAsB,CAQxB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AnalyticsTrackingEvent } from "@metamask/analytics-controller";
|
|
2
|
+
import type { Hex, Json } from "@metamask/utils";
|
|
3
|
+
import type { DegradedEventType, RetryReason } from "./create-network-client.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* The names of the analytics events that {@link NetworkController} emits when an
|
|
6
|
+
* RPC endpoint becomes unavailable or degraded.
|
|
7
|
+
*/
|
|
8
|
+
export type RpcServiceEventName = 'RPC Service Unavailable' | 'RPC Service Degraded';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration that enables {@link NetworkController} to emit analytics events
|
|
11
|
+
* for unavailable or degraded RPC endpoints.
|
|
12
|
+
*
|
|
13
|
+
* The pieces here are client-specific and cannot be derived inside the
|
|
14
|
+
* controller: deciding whether an endpoint URL is safe to report depends on the
|
|
15
|
+
* client's lists of known networks, and the sample rate depends on the client's
|
|
16
|
+
* build environment.
|
|
17
|
+
*/
|
|
18
|
+
export type NetworkControllerAnalyticsOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Returns `true` if the given RPC endpoint URL is safe to report verbatim (a
|
|
21
|
+
* "public" endpoint), or `false` if it must be reported as the literal string
|
|
22
|
+
* `'custom'` to avoid leaking private servers.
|
|
23
|
+
*/
|
|
24
|
+
isRpcEndpointUrlPublic: (endpointUrl: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The proportion of events to emit, between 0 and 1. `1` emits every event,
|
|
27
|
+
* `0` emits none. Clients typically use a small value (e.g. `0.01`) in
|
|
28
|
+
* production to stay within their analytics quota, and `1` in development.
|
|
29
|
+
*/
|
|
30
|
+
rpcServiceEventsSampleRate: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Hides any API key contained in an RPC endpoint URL by reducing it to its
|
|
34
|
+
* host, but only when the endpoint is considered public. Non-public endpoints
|
|
35
|
+
* (and URLs that cannot be parsed) are reported as the literal string
|
|
36
|
+
* `'custom'`.
|
|
37
|
+
*
|
|
38
|
+
* @param endpointUrl - The URL of the RPC endpoint.
|
|
39
|
+
* @param isPublic - Whether the endpoint is safe to report verbatim.
|
|
40
|
+
* @returns The sanitized value to report.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sanitizeRpcEndpointUrl(endpointUrl: string, isPublic: boolean): string;
|
|
43
|
+
/**
|
|
44
|
+
* Builds the properties for an "RPC Service Unavailable" or "RPC Service
|
|
45
|
+
* Degraded" analytics event.
|
|
46
|
+
*
|
|
47
|
+
* @param args - The arguments.
|
|
48
|
+
* @param args.chainId - The chain ID that the endpoint represents.
|
|
49
|
+
* @param args.endpointUrl - The URL of the endpoint.
|
|
50
|
+
* @param args.error - The connection or response error encountered after making
|
|
51
|
+
* a request to the RPC endpoint.
|
|
52
|
+
* @param args.isRpcEndpointUrlPublic - Returns whether the endpoint URL is safe
|
|
53
|
+
* to report verbatim.
|
|
54
|
+
* @param args.duration - The policy execution time in milliseconds when the
|
|
55
|
+
* request succeeded but was slow (degraded events only).
|
|
56
|
+
* @param args.retryReason - The category of error that was retried (degraded
|
|
57
|
+
* events only).
|
|
58
|
+
* @param args.rpcMethodName - The JSON-RPC method that was being executed
|
|
59
|
+
* (degraded events only).
|
|
60
|
+
* @param args.traceId - The value of the `X-Trace-Id` response header from the
|
|
61
|
+
* last request attempt (degraded events only).
|
|
62
|
+
* @param args.type - Why the endpoint became degraded (degraded events only).
|
|
63
|
+
* @returns The analytics event properties.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildRpcServiceEventProperties({ chainId, endpointUrl, error, isRpcEndpointUrlPublic, duration, retryReason, rpcMethodName, traceId, type, }: {
|
|
66
|
+
chainId: Hex;
|
|
67
|
+
endpointUrl: string;
|
|
68
|
+
error: unknown;
|
|
69
|
+
isRpcEndpointUrlPublic: (endpointUrl: string) => boolean;
|
|
70
|
+
duration?: number;
|
|
71
|
+
retryReason?: RetryReason;
|
|
72
|
+
rpcMethodName?: string;
|
|
73
|
+
traceId?: string;
|
|
74
|
+
type?: DegradedEventType;
|
|
75
|
+
}): Record<string, Json>;
|
|
76
|
+
/**
|
|
77
|
+
* Wraps an event name and properties into the shape expected by the
|
|
78
|
+
* `AnalyticsController:trackEvent` action.
|
|
79
|
+
*
|
|
80
|
+
* @param name - The analytics event name.
|
|
81
|
+
* @param properties - The analytics event properties.
|
|
82
|
+
* @returns The analytics tracking event.
|
|
83
|
+
*/
|
|
84
|
+
export declare function toAnalyticsTrackingEvent(name: RpcServiceEventName, properties: Record<string, Json>): AnalyticsTrackingEvent;
|
|
85
|
+
//# sourceMappingURL=rpc-service-events.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-service-events.d.mts","sourceRoot":"","sources":["../src/rpc-service-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uCAAuC;AAC7E,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAQjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,oCAAgC;AAE9E;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC3B,yBAAyB,GACzB,sBAAsB,CAAC;AAE3B;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C;;;;OAIG;IACH,sBAAsB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IACzD;;;;OAIG;IACH,0BAA0B,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,GAChB,MAAM,CAUR;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,OAAO,EACP,WAAW,EACX,KAAK,EACL,sBAAsB,EACtB,QAAQ,EACR,WAAW,EACX,aAAa,EACb,OAAO,EACP,IAAI,GACL,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,sBAAsB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAsBvB;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAC/B,sBAAsB,CAQxB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { hasProperty, hexToNumber, isObject, isValidJson } from "@metamask/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Hides any API key contained in an RPC endpoint URL by reducing it to its
|
|
4
|
+
* host, but only when the endpoint is considered public. Non-public endpoints
|
|
5
|
+
* (and URLs that cannot be parsed) are reported as the literal string
|
|
6
|
+
* `'custom'`.
|
|
7
|
+
*
|
|
8
|
+
* @param endpointUrl - The URL of the RPC endpoint.
|
|
9
|
+
* @param isPublic - Whether the endpoint is safe to report verbatim.
|
|
10
|
+
* @returns The sanitized value to report.
|
|
11
|
+
*/
|
|
12
|
+
export function sanitizeRpcEndpointUrl(endpointUrl, isPublic) {
|
|
13
|
+
if (!isPublic) {
|
|
14
|
+
return 'custom';
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
return new URL(endpointUrl).host;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return 'custom';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Builds the properties for an "RPC Service Unavailable" or "RPC Service
|
|
25
|
+
* Degraded" analytics event.
|
|
26
|
+
*
|
|
27
|
+
* @param args - The arguments.
|
|
28
|
+
* @param args.chainId - The chain ID that the endpoint represents.
|
|
29
|
+
* @param args.endpointUrl - The URL of the endpoint.
|
|
30
|
+
* @param args.error - The connection or response error encountered after making
|
|
31
|
+
* a request to the RPC endpoint.
|
|
32
|
+
* @param args.isRpcEndpointUrlPublic - Returns whether the endpoint URL is safe
|
|
33
|
+
* to report verbatim.
|
|
34
|
+
* @param args.duration - The policy execution time in milliseconds when the
|
|
35
|
+
* request succeeded but was slow (degraded events only).
|
|
36
|
+
* @param args.retryReason - The category of error that was retried (degraded
|
|
37
|
+
* events only).
|
|
38
|
+
* @param args.rpcMethodName - The JSON-RPC method that was being executed
|
|
39
|
+
* (degraded events only).
|
|
40
|
+
* @param args.traceId - The value of the `X-Trace-Id` response header from the
|
|
41
|
+
* last request attempt (degraded events only).
|
|
42
|
+
* @param args.type - Why the endpoint became degraded (degraded events only).
|
|
43
|
+
* @returns The analytics event properties.
|
|
44
|
+
*/
|
|
45
|
+
export function buildRpcServiceEventProperties({ chainId, endpointUrl, error, isRpcEndpointUrlPublic, duration, retryReason, rpcMethodName, traceId, type, }) {
|
|
46
|
+
const sanitizedUrl = sanitizeRpcEndpointUrl(endpointUrl, isRpcEndpointUrlPublic(endpointUrl));
|
|
47
|
+
// The names of analytics properties have a particular case.
|
|
48
|
+
return {
|
|
49
|
+
chain_id_caip: `eip155:${hexToNumber(chainId)}`,
|
|
50
|
+
rpc_domain: sanitizedUrl,
|
|
51
|
+
rpc_endpoint_url: sanitizedUrl, // @deprecated - Will be removed in a future release.
|
|
52
|
+
...(rpcMethodName ? { rpc_method_name: rpcMethodName } : {}),
|
|
53
|
+
...(type ? { type } : {}),
|
|
54
|
+
...(retryReason ? { retry_reason: retryReason } : {}),
|
|
55
|
+
...(duration === undefined ? {} : { duration_ms: duration }),
|
|
56
|
+
...(traceId === undefined ? {} : { trace_id: traceId }),
|
|
57
|
+
...(isObject(error) &&
|
|
58
|
+
hasProperty(error, 'httpStatus') &&
|
|
59
|
+
isValidJson(error.httpStatus)
|
|
60
|
+
? { http_status: error.httpStatus }
|
|
61
|
+
: {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Wraps an event name and properties into the shape expected by the
|
|
66
|
+
* `AnalyticsController:trackEvent` action.
|
|
67
|
+
*
|
|
68
|
+
* @param name - The analytics event name.
|
|
69
|
+
* @param properties - The analytics event properties.
|
|
70
|
+
* @returns The analytics tracking event.
|
|
71
|
+
*/
|
|
72
|
+
export function toAnalyticsTrackingEvent(name, properties) {
|
|
73
|
+
return {
|
|
74
|
+
name,
|
|
75
|
+
properties,
|
|
76
|
+
sensitiveProperties: {},
|
|
77
|
+
saveDataRecording: false,
|
|
78
|
+
hasProperties: Object.keys(properties).length > 0,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=rpc-service-events.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-service-events.mjs","sourceRoot":"","sources":["../src/rpc-service-events.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,WAAW,EACZ,wBAAwB;AAoCzB;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAAmB,EACnB,QAAiB;IAEjB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,8BAA8B,CAAC,EAC7C,OAAO,EACP,WAAW,EACX,KAAK,EACL,sBAAsB,EACtB,QAAQ,EACR,WAAW,EACX,aAAa,EACb,OAAO,EACP,IAAI,GAWL;IACC,MAAM,YAAY,GAAG,sBAAsB,CACzC,WAAW,EACX,sBAAsB,CAAC,WAAW,CAAC,CACpC,CAAC;IAEF,4DAA4D;IAC5D,OAAO;QACL,aAAa,EAAE,UAAU,WAAW,CAAC,OAAO,CAAC,EAAE;QAC/C,UAAU,EAAE,YAAY;QACxB,gBAAgB,EAAE,YAAY,EAAE,qDAAqD;QACrF,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzB,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;QAC5D,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;QACvD,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;YACnB,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC;YAChC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC;YAC3B,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,UAAU,EAAE;YACnC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAyB,EACzB,UAAgC;IAEhC,OAAO;QACL,IAAI;QACJ,UAAU;QACV,mBAAmB,EAAE,EAAE;QACvB,iBAAiB,EAAE,KAAK;QACxB,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC;KAClD,CAAC;AACJ,CAAC","sourcesContent":["import type { AnalyticsTrackingEvent } from '@metamask/analytics-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport {\n hasProperty,\n hexToNumber,\n isObject,\n isValidJson,\n} from '@metamask/utils';\n\nimport type { DegradedEventType, RetryReason } from './create-network-client';\n\n/**\n * The names of the analytics events that {@link NetworkController} emits when an\n * RPC endpoint becomes unavailable or degraded.\n */\nexport type RpcServiceEventName =\n | 'RPC Service Unavailable'\n | 'RPC Service Degraded';\n\n/**\n * Configuration that enables {@link NetworkController} to emit analytics events\n * for unavailable or degraded RPC endpoints.\n *\n * The pieces here are client-specific and cannot be derived inside the\n * controller: deciding whether an endpoint URL is safe to report depends on the\n * client's lists of known networks, and the sample rate depends on the client's\n * build environment.\n */\nexport type NetworkControllerAnalyticsOptions = {\n /**\n * Returns `true` if the given RPC endpoint URL is safe to report verbatim (a\n * \"public\" endpoint), or `false` if it must be reported as the literal string\n * `'custom'` to avoid leaking private servers.\n */\n isRpcEndpointUrlPublic: (endpointUrl: string) => boolean;\n /**\n * The proportion of events to emit, between 0 and 1. `1` emits every event,\n * `0` emits none. Clients typically use a small value (e.g. `0.01`) in\n * production to stay within their analytics quota, and `1` in development.\n */\n rpcServiceEventsSampleRate: number;\n};\n\n/**\n * Hides any API key contained in an RPC endpoint URL by reducing it to its\n * host, but only when the endpoint is considered public. Non-public endpoints\n * (and URLs that cannot be parsed) are reported as the literal string\n * `'custom'`.\n *\n * @param endpointUrl - The URL of the RPC endpoint.\n * @param isPublic - Whether the endpoint is safe to report verbatim.\n * @returns The sanitized value to report.\n */\nexport function sanitizeRpcEndpointUrl(\n endpointUrl: string,\n isPublic: boolean,\n): string {\n if (!isPublic) {\n return 'custom';\n }\n\n try {\n return new URL(endpointUrl).host;\n } catch {\n return 'custom';\n }\n}\n\n/**\n * Builds the properties for an \"RPC Service Unavailable\" or \"RPC Service\n * Degraded\" analytics event.\n *\n * @param args - The arguments.\n * @param args.chainId - The chain ID that the endpoint represents.\n * @param args.endpointUrl - The URL of the endpoint.\n * @param args.error - The connection or response error encountered after making\n * a request to the RPC endpoint.\n * @param args.isRpcEndpointUrlPublic - Returns whether the endpoint URL is safe\n * to report verbatim.\n * @param args.duration - The policy execution time in milliseconds when the\n * request succeeded but was slow (degraded events only).\n * @param args.retryReason - The category of error that was retried (degraded\n * events only).\n * @param args.rpcMethodName - The JSON-RPC method that was being executed\n * (degraded events only).\n * @param args.traceId - The value of the `X-Trace-Id` response header from the\n * last request attempt (degraded events only).\n * @param args.type - Why the endpoint became degraded (degraded events only).\n * @returns The analytics event properties.\n */\nexport function buildRpcServiceEventProperties({\n chainId,\n endpointUrl,\n error,\n isRpcEndpointUrlPublic,\n duration,\n retryReason,\n rpcMethodName,\n traceId,\n type,\n}: {\n chainId: Hex;\n endpointUrl: string;\n error: unknown;\n isRpcEndpointUrlPublic: (endpointUrl: string) => boolean;\n duration?: number;\n retryReason?: RetryReason;\n rpcMethodName?: string;\n traceId?: string;\n type?: DegradedEventType;\n}): Record<string, Json> {\n const sanitizedUrl = sanitizeRpcEndpointUrl(\n endpointUrl,\n isRpcEndpointUrlPublic(endpointUrl),\n );\n\n // The names of analytics properties have a particular case.\n return {\n chain_id_caip: `eip155:${hexToNumber(chainId)}`,\n rpc_domain: sanitizedUrl,\n rpc_endpoint_url: sanitizedUrl, // @deprecated - Will be removed in a future release.\n ...(rpcMethodName ? { rpc_method_name: rpcMethodName } : {}),\n ...(type ? { type } : {}),\n ...(retryReason ? { retry_reason: retryReason } : {}),\n ...(duration === undefined ? {} : { duration_ms: duration }),\n ...(traceId === undefined ? {} : { trace_id: traceId }),\n ...(isObject(error) &&\n hasProperty(error, 'httpStatus') &&\n isValidJson(error.httpStatus)\n ? { http_status: error.httpStatus }\n : {}),\n };\n}\n\n/**\n * Wraps an event name and properties into the shape expected by the\n * `AnalyticsController:trackEvent` action.\n *\n * @param name - The analytics event name.\n * @param properties - The analytics event properties.\n * @returns The analytics tracking event.\n */\nexport function toAnalyticsTrackingEvent(\n name: RpcServiceEventName,\n properties: Record<string, Json>,\n): AnalyticsTrackingEvent {\n return {\n name,\n properties,\n sensitiveProperties: {},\n saveDataRecording: false,\n hasProperties: Object.keys(properties).length > 0,\n };\n}\n"]}
|
package/dist/selectors.cjs
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
exports.getRpcFailoverMode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Reads the RPC failover mode from the remote feature flags, defaulting to
|
|
6
|
+
* `disabled` when the flag is absent or not a recognized value.
|
|
7
|
+
*
|
|
8
|
+
* @param state - The remote feature flag controller state.
|
|
9
|
+
* @returns The RPC failover mode.
|
|
10
|
+
*/
|
|
11
|
+
function getRpcFailoverMode(state) {
|
|
12
|
+
const mode = state.remoteFeatureFlags.corePlatformRpcFailoverMode;
|
|
13
|
+
return mode === 'enabled' || mode === 'forced' ? mode : 'disabled';
|
|
8
14
|
}
|
|
9
|
-
exports.
|
|
15
|
+
exports.getRpcFailoverMode = getRpcFailoverMode;
|
|
10
16
|
//# sourceMappingURL=selectors.cjs.map
|
package/dist/selectors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAeA;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,KAAuC;IAEvC,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC,2BAA2B,CAAC;IAClE,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;AACrE,CAAC;AALD,gDAKC","sourcesContent":["import { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\n\n/**\n * The RPC failover behavior for Infura networks, controlled by the\n * `corePlatformRpcFailoverMode` remote feature flag.\n *\n * - `disabled`: failover URLs are ignored; traffic stays on the primary\n * endpoint.\n * - `enabled`: traffic automatically diverts to failover URLs when the primary\n * endpoint is unavailable.\n * - `forced`: Infura endpoints that have failover URLs route all traffic to\n * those failover URLs, bypassing Infura entirely.\n */\nexport type RpcFailoverMode = 'disabled' | 'enabled' | 'forced';\n\n/**\n * Reads the RPC failover mode from the remote feature flags, defaulting to\n * `disabled` when the flag is absent or not a recognized value.\n *\n * @param state - The remote feature flag controller state.\n * @returns The RPC failover mode.\n */\nexport function getRpcFailoverMode(\n state: RemoteFeatureFlagControllerState,\n): RpcFailoverMode {\n const mode = state.remoteFeatureFlags.corePlatformRpcFailoverMode;\n return mode === 'enabled' || mode === 'forced' ? mode : 'disabled';\n}\n"]}
|
package/dist/selectors.d.cts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
import { RemoteFeatureFlagControllerState } from "@metamask/remote-feature-flag-controller";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The RPC failover behavior for Infura networks, controlled by the
|
|
4
|
+
* `corePlatformRpcFailoverMode` remote feature flag.
|
|
5
|
+
*
|
|
6
|
+
* - `disabled`: failover URLs are ignored; traffic stays on the primary
|
|
7
|
+
* endpoint.
|
|
8
|
+
* - `enabled`: traffic automatically diverts to failover URLs when the primary
|
|
9
|
+
* endpoint is unavailable.
|
|
10
|
+
* - `forced`: Infura endpoints that have failover URLs route all traffic to
|
|
11
|
+
* those failover URLs, bypassing Infura entirely.
|
|
12
|
+
*/
|
|
13
|
+
export type RpcFailoverMode = 'disabled' | 'enabled' | 'forced';
|
|
14
|
+
/**
|
|
15
|
+
* Reads the RPC failover mode from the remote feature flags, defaulting to
|
|
16
|
+
* `disabled` when the flag is absent or not a recognized value.
|
|
17
|
+
*
|
|
18
|
+
* @param state - The remote feature flag controller state.
|
|
19
|
+
* @returns The RPC failover mode.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getRpcFailoverMode(state: RemoteFeatureFlagControllerState): RpcFailoverMode;
|
|
3
22
|
//# sourceMappingURL=selectors.d.cts.map
|
package/dist/selectors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,iDAAiD;AAE5F,wBAAgB,
|
|
1
|
+
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,iDAAiD;AAE5F;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gCAAgC,GACtC,eAAe,CAGjB"}
|
package/dist/selectors.d.mts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
import { RemoteFeatureFlagControllerState } from "@metamask/remote-feature-flag-controller";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The RPC failover behavior for Infura networks, controlled by the
|
|
4
|
+
* `corePlatformRpcFailoverMode` remote feature flag.
|
|
5
|
+
*
|
|
6
|
+
* - `disabled`: failover URLs are ignored; traffic stays on the primary
|
|
7
|
+
* endpoint.
|
|
8
|
+
* - `enabled`: traffic automatically diverts to failover URLs when the primary
|
|
9
|
+
* endpoint is unavailable.
|
|
10
|
+
* - `forced`: Infura endpoints that have failover URLs route all traffic to
|
|
11
|
+
* those failover URLs, bypassing Infura entirely.
|
|
12
|
+
*/
|
|
13
|
+
export type RpcFailoverMode = 'disabled' | 'enabled' | 'forced';
|
|
14
|
+
/**
|
|
15
|
+
* Reads the RPC failover mode from the remote feature flags, defaulting to
|
|
16
|
+
* `disabled` when the flag is absent or not a recognized value.
|
|
17
|
+
*
|
|
18
|
+
* @param state - The remote feature flag controller state.
|
|
19
|
+
* @returns The RPC failover mode.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getRpcFailoverMode(state: RemoteFeatureFlagControllerState): RpcFailoverMode;
|
|
3
22
|
//# sourceMappingURL=selectors.d.mts.map
|
package/dist/selectors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,iDAAiD;AAE5F,wBAAgB,
|
|
1
|
+
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,iDAAiD;AAE5F;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gCAAgC,GACtC,eAAe,CAGjB"}
|
package/dist/selectors.mjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Reads the RPC failover mode from the remote feature flags, defaulting to
|
|
3
|
+
* `disabled` when the flag is absent or not a recognized value.
|
|
4
|
+
*
|
|
5
|
+
* @param state - The remote feature flag controller state.
|
|
6
|
+
* @returns The RPC failover mode.
|
|
7
|
+
*/
|
|
8
|
+
export function getRpcFailoverMode(state) {
|
|
9
|
+
const mode = state.remoteFeatureFlags.corePlatformRpcFailoverMode;
|
|
10
|
+
return mode === 'enabled' || mode === 'forced' ? mode : 'disabled';
|
|
5
11
|
}
|
|
6
12
|
//# sourceMappingURL=selectors.mjs.map
|
package/dist/selectors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAuC;IAEvC,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC,2BAA2B,CAAC;IAClE,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;AACrE,CAAC","sourcesContent":["import { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\n\n/**\n * The RPC failover behavior for Infura networks, controlled by the\n * `corePlatformRpcFailoverMode` remote feature flag.\n *\n * - `disabled`: failover URLs are ignored; traffic stays on the primary\n * endpoint.\n * - `enabled`: traffic automatically diverts to failover URLs when the primary\n * endpoint is unavailable.\n * - `forced`: Infura endpoints that have failover URLs route all traffic to\n * those failover URLs, bypassing Infura entirely.\n */\nexport type RpcFailoverMode = 'disabled' | 'enabled' | 'forced';\n\n/**\n * Reads the RPC failover mode from the remote feature flags, defaulting to\n * `disabled` when the flag is absent or not a recognized value.\n *\n * @param state - The remote feature flag controller state.\n * @returns The RPC failover mode.\n */\nexport function getRpcFailoverMode(\n state: RemoteFeatureFlagControllerState,\n): RpcFailoverMode {\n const mode = state.remoteFeatureFlags.corePlatformRpcFailoverMode;\n return mode === 'enabled' || mode === 'forced' ? mode : 'disabled';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/network-controller",
|
|
3
|
-
"version": "33.0.0-preview-
|
|
3
|
+
"version": "33.0.0-preview-e0ee14da7",
|
|
4
4
|
"description": "Provides an interface to the currently selected network via a MetaMask-compatible provider object",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
+
"@metamask/analytics-controller": "^1.2.1",
|
|
56
57
|
"@metamask/base-controller": "^9.1.0",
|
|
57
58
|
"@metamask/connectivity-controller": "^0.2.0",
|
|
58
59
|
"@metamask/controller-utils": "^12.3.0",
|