@coinbase/cdp-sdk 1.44.1 → 1.45.0
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 +14 -0
- package/README.md +117 -0
- package/_cjs/accounts/evm/toEvmDelegatedAccount.js +27 -0
- package/_cjs/accounts/evm/toEvmDelegatedAccount.js.map +1 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js +127 -55
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +111 -45
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +49 -19
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/waitForEvmEip7702DelegationStatus.js +37 -0
- package/_cjs/actions/evm/waitForEvmEip7702DelegationStatus.js.map +1 -0
- package/_cjs/analytics.js +10 -228
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +0 -6
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +482 -227
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/policies.js +41 -11
- package/_cjs/client/policies/policies.js.map +1 -1
- package/_cjs/client/solana/solana.js +177 -106
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +137 -5
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +30 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js +15 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_cjs/policies/evmSchema.js +127 -1
- package/_cjs/policies/evmSchema.js.map +1 -1
- package/_cjs/policies/solanaSchema.js +102 -1
- package/_cjs/policies/solanaSchema.js.map +1 -1
- package/_cjs/policies/types.js +7 -0
- package/_cjs/policies/types.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmDelegatedAccount.js +24 -0
- package/_esm/accounts/evm/toEvmDelegatedAccount.js.map +1 -0
- package/_esm/accounts/evm/toEvmServerAccount.js +127 -55
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +111 -45
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +49 -19
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/waitForEvmEip7702DelegationStatus.js +34 -0
- package/_esm/actions/evm/waitForEvmEip7702DelegationStatus.js.map +1 -0
- package/_esm/analytics.js +9 -227
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +0 -6
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +482 -227
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/policies.js +41 -11
- package/_esm/client/policies/policies.js.map +1 -1
- package/_esm/client/solana/solana.js +177 -106
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +134 -3
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +27 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/onramp/onramp.js +13 -0
- package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_esm/policies/evmSchema.js +126 -0
- package/_esm/policies/evmSchema.js.map +1 -1
- package/_esm/policies/solanaSchema.js +101 -0
- package/_esm/policies/solanaSchema.js.map +1 -1
- package/_esm/policies/types.js +9 -2
- package/_esm/policies/types.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmDelegatedAccount.d.ts +13 -0
- package/_types/accounts/evm/toEvmDelegatedAccount.d.ts.map +1 -0
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/waitForEvmEip7702DelegationStatus.d.ts +32 -0
- package/_types/actions/evm/waitForEvmEip7702DelegationStatus.d.ts.map +1 -0
- package/_types/analytics.d.ts +5 -38
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +54 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +29 -2
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/policies.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +436 -10
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +21 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +8 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +4 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +2717 -601
- package/_types/policies/evmSchema.d.ts.map +1 -1
- package/_types/policies/solanaSchema.d.ts +1411 -47
- package/_types/policies/solanaSchema.d.ts.map +1 -1
- package/_types/policies/types.d.ts +8427 -2942
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmDelegatedAccount.ts +26 -0
- package/accounts/evm/toEvmServerAccount.ts +115 -67
- package/accounts/evm/toEvmSmartAccount.ts +100 -56
- package/accounts/solana/toSolanaAccount.ts +44 -24
- package/actions/evm/waitForEvmEip7702DelegationStatus.ts +57 -0
- package/analytics.ts +8 -294
- package/client/cdp.ts +0 -7
- package/client/evm/evm.ts +517 -282
- package/client/evm/evm.types.ts +41 -0
- package/client/policies/policies.ts +41 -16
- package/client/solana/solana.ts +195 -141
- package/index.ts +5 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +580 -11
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +49 -0
- package/openapi-client/generated/onramp/onramp.ts +24 -0
- package/package.json +1 -1
- package/policies/evmSchema.ts +164 -0
- package/policies/solanaSchema.ts +130 -0
- package/policies/types.ts +14 -0
- package/version.ts +1 -1
|
@@ -43,22 +43,30 @@ export function toSolanaAccount(
|
|
|
43
43
|
action: "request_faucet",
|
|
44
44
|
accountType: "solana",
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
try {
|
|
47
|
+
return requestFaucet(apiClient, {
|
|
48
|
+
...options,
|
|
49
|
+
address: account.address,
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
Analytics.trackError(error, "requestFaucet");
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
51
55
|
},
|
|
52
56
|
async signMessage(options: Omit<SignMessageOptions, "address">): Promise<SignatureResult> {
|
|
53
57
|
Analytics.trackAction({
|
|
54
58
|
action: "sign_message",
|
|
55
59
|
accountType: "solana",
|
|
56
60
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
try {
|
|
62
|
+
return signMessage(apiClient, {
|
|
63
|
+
...options,
|
|
64
|
+
address: account.address,
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
Analytics.trackError(error, "signMessage");
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
62
70
|
},
|
|
63
71
|
async signTransaction(
|
|
64
72
|
options: Omit<SignTransactionOptions, "address">,
|
|
@@ -67,11 +75,15 @@ export function toSolanaAccount(
|
|
|
67
75
|
action: "sign_transaction",
|
|
68
76
|
accountType: "solana",
|
|
69
77
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
try {
|
|
79
|
+
return signTransaction(apiClient, {
|
|
80
|
+
...options,
|
|
81
|
+
address: account.address,
|
|
82
|
+
});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
Analytics.trackError(error, "signTransaction");
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
75
87
|
},
|
|
76
88
|
async sendTransaction(
|
|
77
89
|
options: Omit<SendTransactionOptions, "address">,
|
|
@@ -80,10 +92,14 @@ export function toSolanaAccount(
|
|
|
80
92
|
action: "send_transaction",
|
|
81
93
|
accountType: "solana",
|
|
82
94
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
try {
|
|
96
|
+
return sendTransaction(apiClient, {
|
|
97
|
+
...options,
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
Analytics.trackError(error, "sendTransaction");
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
87
103
|
},
|
|
88
104
|
async transfer(options: Omit<TransferOptions, "from">): Promise<SignatureResult> {
|
|
89
105
|
Analytics.trackAction({
|
|
@@ -93,11 +109,15 @@ export function toSolanaAccount(
|
|
|
93
109
|
network: options.network,
|
|
94
110
|
},
|
|
95
111
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
try {
|
|
113
|
+
return transfer(apiClient, {
|
|
114
|
+
...options,
|
|
115
|
+
from: account.address,
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
Analytics.trackError(error, "transfer");
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
101
121
|
},
|
|
102
122
|
};
|
|
103
123
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CdpOpenApiClientType,
|
|
3
|
+
EvmEip7702DelegationOperation,
|
|
4
|
+
EvmEip7702DelegationOperationStatus,
|
|
5
|
+
} from "../../openapi-client/index.js";
|
|
6
|
+
import { wait, WaitOptions } from "../../utils/wait.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for waiting for an EIP-7702 delegation operation to complete.
|
|
10
|
+
*/
|
|
11
|
+
export type WaitForEvmEip7702DelegationOperationStatusOptions = {
|
|
12
|
+
/** The delegation operation ID returned by createEvmEip7702Delegation. */
|
|
13
|
+
delegationOperationId: string;
|
|
14
|
+
/** Optional options for the wait operation. */
|
|
15
|
+
waitOptions?: WaitOptions;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Polls getEvmEip7702DelegationOperationById until the status is COMPLETED or FAILED, or a timeout occurs.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { waitForEvmEip7702DelegationOperationStatus } from "@coinbase/cdp-sdk";
|
|
24
|
+
*
|
|
25
|
+
* const operation = await waitForEvmEip7702DelegationOperationStatus(client, {
|
|
26
|
+
* delegationOperationId: "delegation-op-123",
|
|
27
|
+
* waitOptions: {
|
|
28
|
+
* timeoutSeconds: 60,
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param {CdpOpenApiClientType} client - The client to use.
|
|
34
|
+
* @param {WaitForEvmEip7702DelegationOperationStatusOptions} options - The options for the wait operation.
|
|
35
|
+
* @returns {Promise<EvmEip7702DelegationOperation>} The delegation operation once it reaches a terminal status.
|
|
36
|
+
*/
|
|
37
|
+
export async function waitForEvmEip7702DelegationOperationStatus(
|
|
38
|
+
client: CdpOpenApiClientType,
|
|
39
|
+
options: WaitForEvmEip7702DelegationOperationStatusOptions,
|
|
40
|
+
): Promise<EvmEip7702DelegationOperation> {
|
|
41
|
+
const { delegationOperationId } = options;
|
|
42
|
+
|
|
43
|
+
const reload = async () => {
|
|
44
|
+
return client.getEvmEip7702DelegationOperationById(delegationOperationId);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const isTerminal = (operation: EvmEip7702DelegationOperation): boolean => {
|
|
48
|
+
return (
|
|
49
|
+
operation.status === EvmEip7702DelegationOperationStatus.COMPLETED ||
|
|
50
|
+
operation.status === EvmEip7702DelegationOperationStatus.FAILED
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const waitOptions = options.waitOptions ?? { timeoutSeconds: 60 };
|
|
55
|
+
|
|
56
|
+
return await wait(reload, isTerminal, s => s, waitOptions);
|
|
57
|
+
}
|
package/analytics.ts
CHANGED
|
@@ -50,35 +50,14 @@ type ActionEventData = {
|
|
|
50
50
|
|
|
51
51
|
type EventData = ErrorEventData | ActionEventData;
|
|
52
52
|
|
|
53
|
-
// Symbol to store the original method on wrapped functions
|
|
54
|
-
const ORIGINAL_METHOD = Symbol("originalMethod");
|
|
55
|
-
|
|
56
53
|
// This is a public client id for the analytics service
|
|
57
54
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
58
55
|
|
|
59
56
|
export const Analytics = {
|
|
60
57
|
identifier: "", // set in cdp.ts
|
|
61
|
-
wrapClassWithErrorTracking,
|
|
62
|
-
wrapObjectMethodsWithErrorTracking,
|
|
63
|
-
sendEvent,
|
|
64
|
-
trackAction,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/*
|
|
68
|
-
* Deprecated implementation - kept for test compatibility
|
|
69
|
-
* Shares the same identifier reference as Analytics
|
|
70
|
-
*/
|
|
71
|
-
export const AnalyticsDeprecated = {
|
|
72
|
-
get identifier() {
|
|
73
|
-
return Analytics.identifier;
|
|
74
|
-
},
|
|
75
|
-
set identifier(value: string) {
|
|
76
|
-
Analytics.identifier = value;
|
|
77
|
-
},
|
|
78
|
-
wrapClassWithErrorTracking: wrapClassWithErrorTrackingDeprecated,
|
|
79
|
-
wrapObjectMethodsWithErrorTracking: wrapObjectMethodsWithErrorTrackingDeprecated,
|
|
80
58
|
sendEvent,
|
|
81
59
|
trackAction,
|
|
60
|
+
trackError,
|
|
82
61
|
};
|
|
83
62
|
|
|
84
63
|
/**
|
|
@@ -171,281 +150,16 @@ function trackAction(params: {
|
|
|
171
150
|
}
|
|
172
151
|
|
|
173
152
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* @param method - The method to get the original version of.
|
|
177
|
-
* @returns The original unwrapped method, or the method itself if it's not wrapped.
|
|
178
|
-
*/
|
|
179
|
-
function getOriginalMethod(
|
|
180
|
-
method: (this: unknown, ...args: unknown[]) => Promise<unknown>,
|
|
181
|
-
): (this: unknown, ...args: unknown[]) => Promise<unknown> {
|
|
182
|
-
return (
|
|
183
|
-
(method as { [ORIGINAL_METHOD]?: (this: unknown, ...args: unknown[]) => Promise<unknown> })[
|
|
184
|
-
ORIGINAL_METHOD
|
|
185
|
-
] || method
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Creates an interceptor function that prevents recursive calls by checking if the instance is already executing.
|
|
153
|
+
* Track an error that occurred in a method
|
|
191
154
|
*
|
|
192
|
-
* @param
|
|
193
|
-
* @param
|
|
194
|
-
* @returns A function that intercepts calls and prevents recursion.
|
|
155
|
+
* @param error - The error to track
|
|
156
|
+
* @param method - The method name where the error occurred
|
|
195
157
|
*/
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
): (...args: unknown[]) => Promise<unknown> {
|
|
200
|
-
return function (this: unknown, ...callArgs: unknown[]) {
|
|
201
|
-
if (executingInstances.has(this as object)) {
|
|
202
|
-
return Promise.resolve(callArgs[0]);
|
|
203
|
-
}
|
|
204
|
-
return fallbackMethod.apply(this, callArgs);
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Handles an error that occurred in a method by sending an analytics event and rethrowing the error.
|
|
209
|
-
*
|
|
210
|
-
* @param error - The error that occurred.
|
|
211
|
-
* @param methodName - The name of the method where the error occurred.
|
|
212
|
-
*/
|
|
213
|
-
async function handleMethodError(error: unknown, methodName: string): Promise<void> {
|
|
214
|
-
if (!shouldTrackError(error)) {
|
|
215
|
-
throw error;
|
|
216
|
-
}
|
|
217
|
-
|
|
158
|
+
function trackError(error: unknown, method: string): void {
|
|
159
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") return;
|
|
160
|
+
if (!shouldTrackError(error)) return;
|
|
218
161
|
const { message, stack } = error as Error;
|
|
219
|
-
sendEvent({
|
|
220
|
-
method: methodName,
|
|
221
|
-
message,
|
|
222
|
-
stack,
|
|
223
|
-
name: "error",
|
|
224
|
-
}).catch(() => {
|
|
225
|
-
// ignore error
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
throw error;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Creates a wrapper function that adds error tracking and recursion protection to a method.
|
|
233
|
-
*
|
|
234
|
-
* The recursion protection works by temporarily replacing the method with an interceptor
|
|
235
|
-
* during the synchronous phase of execution. Any recursive calls (e.g., a method calling
|
|
236
|
-
* itself via `this.method()` or `Class.prototype.method()`) happen synchronously and will
|
|
237
|
-
* hit the interceptor. After the synchronous phase completes (i.e., `originalMethod.apply()`
|
|
238
|
-
* returns a Promise), the method is immediately restored so that concurrent calls arriving
|
|
239
|
-
* after an `await` suspension go through the full wrapper instead of being intercepted.
|
|
240
|
-
*
|
|
241
|
-
* @param originalMethod - The original method to wrap.
|
|
242
|
-
* @param methodName - The name of the method being wrapped.
|
|
243
|
-
* @param executingInstances - A WeakSet tracking instances that are currently executing.
|
|
244
|
-
* @param setMethod - A function to set the method implementation.
|
|
245
|
-
* @param getMethod - A function to get the current method implementation.
|
|
246
|
-
* @returns A wrapped version of the method with error tracking and recursion protection.
|
|
247
|
-
*/
|
|
248
|
-
function createErrorTrackingWrapper(
|
|
249
|
-
originalMethod: (this: unknown, ...args: unknown[]) => Promise<unknown>,
|
|
250
|
-
methodName: string,
|
|
251
|
-
executingInstances: WeakSet<object>,
|
|
252
|
-
setMethod: (method: (...args: unknown[]) => Promise<unknown>) => void,
|
|
253
|
-
getMethod: () => (...args: unknown[]) => Promise<unknown>,
|
|
254
|
-
): (this: unknown, ...args: unknown[]) => Promise<unknown> {
|
|
255
|
-
return async function (this: unknown, ...args: unknown[]) {
|
|
256
|
-
const previousMethod = getMethod();
|
|
257
|
-
const recursiveInterceptor = createRecursiveInterceptor(executingInstances, previousMethod);
|
|
258
|
-
setMethod(recursiveInterceptor);
|
|
259
|
-
executingInstances.add(this as object);
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
/*
|
|
263
|
-
* Start executing the original method. The synchronous portion runs immediately.
|
|
264
|
-
* Any recursive calls (e.g., this.method() or Class.prototype.method()) during
|
|
265
|
-
* this synchronous phase will hit the recursiveInterceptor.
|
|
266
|
-
*/
|
|
267
|
-
const resultPromise = originalMethod.apply(this, args);
|
|
268
|
-
|
|
269
|
-
/*
|
|
270
|
-
* Restore the method immediately after the synchronous phase completes.
|
|
271
|
-
* This ensures concurrent calls (arriving after an await suspension) go through
|
|
272
|
-
* the full wrapper chain instead of being short-circuited by the interceptor.
|
|
273
|
-
*/
|
|
274
|
-
setMethod(previousMethod);
|
|
275
|
-
executingInstances.delete(this as object);
|
|
276
|
-
|
|
277
|
-
return await resultPromise;
|
|
278
|
-
} catch (error) {
|
|
279
|
-
setMethod(previousMethod);
|
|
280
|
-
executingInstances.delete(this as object);
|
|
281
|
-
return handleMethodError(error, methodName);
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Wraps all methods of a class with error tracking.
|
|
288
|
-
*
|
|
289
|
-
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
290
|
-
*/
|
|
291
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
|
-
function wrapClassWithErrorTracking(ClassToWrap: any): void {
|
|
293
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(
|
|
298
|
-
name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function",
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
for (const method of methods) {
|
|
302
|
-
const currentMethod = ClassToWrap.prototype[method];
|
|
303
|
-
const originalMethod = getOriginalMethod(currentMethod);
|
|
304
|
-
const executingInstances = new WeakSet<object>();
|
|
305
|
-
|
|
306
|
-
const wrappedMethod = createErrorTrackingWrapper(
|
|
307
|
-
originalMethod,
|
|
308
|
-
method,
|
|
309
|
-
executingInstances,
|
|
310
|
-
newMethod => {
|
|
311
|
-
ClassToWrap.prototype[method] = newMethod as (
|
|
312
|
-
this: unknown,
|
|
313
|
-
...args: unknown[]
|
|
314
|
-
) => Promise<unknown>;
|
|
315
|
-
},
|
|
316
|
-
() => ClassToWrap.prototype[method] as (...args: unknown[]) => Promise<unknown>,
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
(wrappedMethod as unknown as { [ORIGINAL_METHOD]: unknown })[ORIGINAL_METHOD] = originalMethod;
|
|
320
|
-
ClassToWrap.prototype[method] = wrappedMethod;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Wraps all methods of an object with error tracking.
|
|
326
|
-
*
|
|
327
|
-
* @param object - The object whose methods should be wrapped.
|
|
328
|
-
*/
|
|
329
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
|
-
function wrapObjectMethodsWithErrorTracking(object: any): void {
|
|
331
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const methods = Object.getOwnPropertyNames(object).filter(
|
|
336
|
-
name => name !== "constructor" && typeof object[name] === "function",
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
for (const method of methods) {
|
|
340
|
-
const currentMethod = object[method];
|
|
341
|
-
const originalMethod = getOriginalMethod(currentMethod);
|
|
342
|
-
const executingInstances = new WeakSet<object>();
|
|
343
|
-
|
|
344
|
-
const wrappedMethod = createErrorTrackingWrapper(
|
|
345
|
-
originalMethod,
|
|
346
|
-
method,
|
|
347
|
-
executingInstances,
|
|
348
|
-
newMethod => {
|
|
349
|
-
object[method] = newMethod;
|
|
350
|
-
},
|
|
351
|
-
() => object[method] as (...args: unknown[]) => Promise<unknown>,
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
(wrappedMethod as unknown as { [ORIGINAL_METHOD]: unknown })[ORIGINAL_METHOD] = originalMethod;
|
|
355
|
-
object[method] = wrappedMethod;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Wraps all methods of a class with error tracking.
|
|
361
|
-
*
|
|
362
|
-
* @deprecated This is the old implementation that has a bug with methods calling themselves via prototype.
|
|
363
|
-
* Use Analytics.wrapClassWithErrorTracking instead.
|
|
364
|
-
* Kept for test compatibility.
|
|
365
|
-
*
|
|
366
|
-
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
367
|
-
*/
|
|
368
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
369
|
-
function wrapClassWithErrorTrackingDeprecated(ClassToWrap: any): void {
|
|
370
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(
|
|
375
|
-
name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function",
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
for (const method of methods) {
|
|
379
|
-
const originalMethod = ClassToWrap.prototype[method];
|
|
380
|
-
ClassToWrap.prototype[method] = async function (...args: unknown[]) {
|
|
381
|
-
try {
|
|
382
|
-
return await originalMethod.apply(this, args);
|
|
383
|
-
} catch (error) {
|
|
384
|
-
if (!shouldTrackError(error)) {
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const { message, stack } = error as Error;
|
|
389
|
-
|
|
390
|
-
sendEvent({
|
|
391
|
-
method,
|
|
392
|
-
message,
|
|
393
|
-
stack,
|
|
394
|
-
name: "error",
|
|
395
|
-
}).catch(() => {
|
|
396
|
-
// ignore error
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
throw error;
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Wraps all methods of an object with error tracking.
|
|
407
|
-
*
|
|
408
|
-
* @deprecated This is the old implementation that has a bug with methods calling themselves via object property.
|
|
409
|
-
* Use Analytics.wrapObjectMethodsWithErrorTracking instead.
|
|
410
|
-
* Kept for test compatibility.
|
|
411
|
-
*
|
|
412
|
-
* @param object - The object whose methods should be wrapped.
|
|
413
|
-
*/
|
|
414
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
415
|
-
function wrapObjectMethodsWithErrorTrackingDeprecated(object: any): void {
|
|
416
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const methods = Object.getOwnPropertyNames(object).filter(
|
|
421
|
-
name => name !== "constructor" && typeof object[name] === "function",
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
for (const method of methods) {
|
|
425
|
-
const originalMethod = object[method];
|
|
426
|
-
object[method] = async function (...args: unknown[]) {
|
|
427
|
-
try {
|
|
428
|
-
return await originalMethod.apply(this, args);
|
|
429
|
-
} catch (error) {
|
|
430
|
-
if (!shouldTrackError(error)) {
|
|
431
|
-
throw error;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const { message, stack } = error as Error;
|
|
435
|
-
|
|
436
|
-
sendEvent({
|
|
437
|
-
method,
|
|
438
|
-
message,
|
|
439
|
-
stack,
|
|
440
|
-
name: "error",
|
|
441
|
-
}).catch(() => {
|
|
442
|
-
// ignore error
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
}
|
|
162
|
+
sendEvent({ method, message, stack, name: "error" }).catch(() => {});
|
|
449
163
|
}
|
|
450
164
|
|
|
451
165
|
/**
|
package/client/cdp.ts
CHANGED
|
@@ -132,13 +132,6 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
|
|
|
132
132
|
Analytics.identifier = apiKeyId;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
136
|
-
Analytics.wrapClassWithErrorTracking(CdpClient);
|
|
137
|
-
Analytics.wrapClassWithErrorTracking(EvmClient);
|
|
138
|
-
Analytics.wrapClassWithErrorTracking(SolanaClient);
|
|
139
|
-
Analytics.wrapClassWithErrorTracking(PoliciesClient);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
135
|
this.evm = new EvmClient();
|
|
143
136
|
this.solana = new SolanaClient();
|
|
144
137
|
this.policies = new PoliciesClient();
|