@coinbase/cdp-api-client 0.0.89 → 0.0.91
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/dist/esm/index.js +203 -200
- package/dist/esm/index10.js +1 -1
- package/dist/esm/index12.js +38 -7
- package/dist/esm/index14.js +67 -375
- package/dist/esm/index15.js +34 -835
- package/dist/esm/index16.js +20 -38
- package/dist/esm/index17.js +8 -2
- package/dist/esm/index18.js +2 -70
- package/dist/esm/index19.js +373 -30
- package/dist/esm/index20.js +835 -20
- package/dist/esm/index3.js +1 -1
- package/dist/esm/index4.js +1 -1
- package/dist/esm/index5.js +58 -50
- package/dist/esm/index6.js +288 -273
- package/dist/esm/index7.js +61 -51
- package/dist/types/index.d.ts +38 -15
- package/package.json +1 -1
package/dist/esm/index7.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { Analytics as
|
|
1
|
+
import { Analytics as o } from "./index2.js";
|
|
2
2
|
import "./index3.js";
|
|
3
3
|
import h from "axios";
|
|
4
4
|
import { ERROR_DOCS_PAGE_URL as c } from "./index9.js";
|
|
5
|
-
import { UnknownApiError as v, HttpErrorType as
|
|
5
|
+
import { UnknownApiError as v, HttpErrorType as u, isOpenAPIError as R, APIError as d, UnknownError as g } from "./index8.js";
|
|
6
6
|
const l = () => typeof window < "u" && typeof document < "u";
|
|
7
|
-
let
|
|
7
|
+
let n = h.create({
|
|
8
8
|
baseURL: "https://api.cdp.coinbase.com/platform"
|
|
9
|
-
}),
|
|
9
|
+
}), i = null;
|
|
10
10
|
const x = (r) => {
|
|
11
|
-
|
|
11
|
+
n = h.create({
|
|
12
12
|
baseURL: r.basePath || "https://api.cdp.coinbase.com/platform",
|
|
13
13
|
// Only enable cookies in browser environments where they're supported
|
|
14
14
|
withCredentials: l()
|
|
15
|
-
}),
|
|
16
|
-
const e =
|
|
17
|
-
if (!
|
|
15
|
+
}), n.interceptors.request.use(async (t) => {
|
|
16
|
+
const e = T(t), s = p(t);
|
|
17
|
+
if (!i || f(s.pathname) || m(s.pathname) && !await i.isSignedIn() || !S(s.pathname))
|
|
18
18
|
return t;
|
|
19
|
-
const
|
|
19
|
+
const a = await i.getXWalletAuth({
|
|
20
20
|
requestMethod: e,
|
|
21
21
|
requestHost: s.host,
|
|
22
22
|
requestPath: s.pathname,
|
|
23
23
|
requestData: t.data
|
|
24
24
|
});
|
|
25
|
-
return
|
|
26
|
-
}),
|
|
25
|
+
return a && (t.headers["X-Wallet-Auth"] = a), t;
|
|
26
|
+
}), n.interceptors.request.use(async (t) => {
|
|
27
27
|
const e = p(t);
|
|
28
|
-
if (!
|
|
28
|
+
if (!i || f(e.pathname) || m(e.pathname) && !await i.isSignedIn())
|
|
29
29
|
return t;
|
|
30
|
-
const s = await
|
|
30
|
+
const s = await i.getToken();
|
|
31
31
|
return s && s !== "" && (t.headers.Authorization = `Bearer ${s}`), t;
|
|
32
|
-
}), l() ||
|
|
32
|
+
}), l() || n.interceptors.request.use(async (t) => {
|
|
33
33
|
let e = t.headers["User-Agent"];
|
|
34
34
|
return e = e ? `${e} CDP/reactnative` : "CDP/reactnative", t.headers["User-Agent"] = e, t;
|
|
35
|
-
}), r.refreshTokenStorage &&
|
|
35
|
+
}), r.refreshTokenStorage && _(r.refreshTokenStorage), r.debugging && (n.interceptors.request.use((t) => (console.log("Request:", t), t)), n.interceptors.response.use((t) => (console.log("Response:", t), t)));
|
|
36
36
|
}, j = (r) => {
|
|
37
|
-
|
|
38
|
-
},
|
|
37
|
+
i = r;
|
|
38
|
+
}, k = (r, t) => ({
|
|
39
39
|
...r,
|
|
40
40
|
headers: {
|
|
41
41
|
...r.headers || {},
|
|
42
42
|
"X-Idempotency-Key": t
|
|
43
43
|
}
|
|
44
44
|
}), I = async (r, t) => {
|
|
45
|
-
P(r), t && t !== "" && (r =
|
|
45
|
+
P(r), t && t !== "" && (r = k(r, t));
|
|
46
46
|
try {
|
|
47
|
-
return (await
|
|
47
|
+
return (await n(r)).data;
|
|
48
48
|
} catch (e) {
|
|
49
49
|
if (h.isAxiosError(e) && !e.response)
|
|
50
50
|
throw new v(
|
|
51
|
-
|
|
51
|
+
u.unknown,
|
|
52
52
|
e.cause instanceof Error ? e.cause.message : e.message,
|
|
53
53
|
e.cause
|
|
54
54
|
);
|
|
55
55
|
if (h.isAxiosError(e) && e.response) {
|
|
56
56
|
if (R(e.response.data))
|
|
57
|
-
throw new
|
|
57
|
+
throw new d(
|
|
58
58
|
e.response.status,
|
|
59
59
|
e.response.data.errorType,
|
|
60
60
|
e.response.data.errorMessage,
|
|
@@ -66,53 +66,53 @@ const x = (r) => {
|
|
|
66
66
|
const s = e.response.status;
|
|
67
67
|
switch (s) {
|
|
68
68
|
case 401:
|
|
69
|
-
throw new
|
|
69
|
+
throw new d(
|
|
70
70
|
s,
|
|
71
|
-
|
|
71
|
+
u.unauthorized,
|
|
72
72
|
"Unauthorized.",
|
|
73
73
|
void 0,
|
|
74
74
|
`${c}#unauthorized`,
|
|
75
75
|
e.cause
|
|
76
76
|
);
|
|
77
77
|
case 404:
|
|
78
|
-
throw new
|
|
78
|
+
throw new d(
|
|
79
79
|
s,
|
|
80
|
-
|
|
80
|
+
u.not_found,
|
|
81
81
|
"API not found.",
|
|
82
82
|
void 0,
|
|
83
83
|
`${c}#not_found`,
|
|
84
84
|
e.cause
|
|
85
85
|
);
|
|
86
86
|
case 502:
|
|
87
|
-
throw new
|
|
87
|
+
throw new d(
|
|
88
88
|
s,
|
|
89
|
-
|
|
89
|
+
u.bad_gateway,
|
|
90
90
|
"Bad gateway.",
|
|
91
91
|
void 0,
|
|
92
92
|
`${c}`,
|
|
93
93
|
e.cause
|
|
94
94
|
);
|
|
95
95
|
case 503:
|
|
96
|
-
throw new
|
|
96
|
+
throw new d(
|
|
97
97
|
s,
|
|
98
|
-
|
|
98
|
+
u.service_unavailable,
|
|
99
99
|
"Service unavailable. Please try again later.",
|
|
100
100
|
void 0,
|
|
101
101
|
`${c}`,
|
|
102
102
|
e.cause
|
|
103
103
|
);
|
|
104
104
|
default: {
|
|
105
|
-
let
|
|
105
|
+
let a = "";
|
|
106
106
|
if (e.response.data)
|
|
107
107
|
try {
|
|
108
|
-
|
|
108
|
+
a = JSON.stringify(e.response.data);
|
|
109
109
|
} catch {
|
|
110
|
-
|
|
110
|
+
a = String(e.response.data);
|
|
111
111
|
}
|
|
112
|
-
const w =
|
|
113
|
-
throw new
|
|
112
|
+
const w = a ? `An unexpected error occurred: ${a}` : "An unexpected error occurred.";
|
|
113
|
+
throw new d(
|
|
114
114
|
s,
|
|
115
|
-
|
|
115
|
+
u.unexpected_error,
|
|
116
116
|
w,
|
|
117
117
|
void 0,
|
|
118
118
|
`${c}`,
|
|
@@ -127,19 +127,29 @@ const x = (r) => {
|
|
|
127
127
|
e instanceof Error ? e : void 0
|
|
128
128
|
);
|
|
129
129
|
}
|
|
130
|
-
},
|
|
131
|
-
|
|
130
|
+
}, _ = (r) => {
|
|
131
|
+
n.interceptors.response.use(
|
|
132
132
|
async (t) => {
|
|
133
133
|
try {
|
|
134
|
-
if (
|
|
134
|
+
if (E(t)) {
|
|
135
|
+
o.sendSessionRefreshEvent({
|
|
136
|
+
name: "refresh_token_response"
|
|
137
|
+
});
|
|
135
138
|
const e = t.data?.refreshToken;
|
|
136
|
-
e && (
|
|
139
|
+
e && (o.sendSessionRefreshEvent({
|
|
140
|
+
name: "refresh_token_received"
|
|
141
|
+
}), await Promise.race([
|
|
142
|
+
r.setRefreshToken(e),
|
|
143
|
+
new Promise(
|
|
144
|
+
(s, a) => setTimeout(() => a(new Error("setRefreshToken timed out after 5000ms")), 5e3)
|
|
145
|
+
)
|
|
146
|
+
]), o.sendSessionRefreshEvent({
|
|
137
147
|
name: "refresh_token_stored"
|
|
138
148
|
}));
|
|
139
149
|
}
|
|
140
150
|
} catch (e) {
|
|
141
151
|
const s = e instanceof Error ? e.message : String(e);
|
|
142
|
-
|
|
152
|
+
o.sendSessionRefreshEvent({
|
|
143
153
|
name: "refresh_token_store_failed",
|
|
144
154
|
error_message: s
|
|
145
155
|
}), console.warn("Failed to store refresh token:", e);
|
|
@@ -147,50 +157,50 @@ const x = (r) => {
|
|
|
147
157
|
return t;
|
|
148
158
|
},
|
|
149
159
|
(t) => Promise.reject(t)
|
|
150
|
-
),
|
|
160
|
+
), n.interceptors.request.use(async (t) => {
|
|
151
161
|
try {
|
|
152
|
-
if (
|
|
162
|
+
if (A(t.url)) {
|
|
153
163
|
const e = await r.getRefreshToken();
|
|
154
|
-
e ? (
|
|
164
|
+
e ? (o.sendSessionRefreshEvent({
|
|
155
165
|
name: "refresh_token_retrieved"
|
|
156
166
|
}), t.data = {
|
|
157
167
|
...t.data,
|
|
158
168
|
refreshToken: e
|
|
159
|
-
}) :
|
|
169
|
+
}) : o.sendSessionRefreshEvent({
|
|
160
170
|
name: "refresh_token_missing"
|
|
161
171
|
});
|
|
162
172
|
}
|
|
163
|
-
|
|
173
|
+
y(t.url) && await r.removeRefreshToken();
|
|
164
174
|
} catch (e) {
|
|
165
175
|
const s = e instanceof Error ? e.message : String(e);
|
|
166
|
-
|
|
176
|
+
o.sendSessionRefreshEvent({
|
|
167
177
|
name: "refresh_token_retrieve_failed",
|
|
168
178
|
error_message: s
|
|
169
179
|
}), console.warn("Failed to retrieve refresh token:", e);
|
|
170
180
|
}
|
|
171
181
|
return t;
|
|
172
182
|
});
|
|
173
|
-
},
|
|
183
|
+
}, y = (r) => r ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/logout$/.test(r) : !1, A = (r) => r ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(refresh|logout)$/.test(r) : !1, E = (r) => {
|
|
174
184
|
const t = r.config.url;
|
|
175
185
|
return t ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(verify\/(email|sms|oauth\/.*)|refresh)$/.test(
|
|
176
186
|
t
|
|
177
187
|
) : !1;
|
|
178
188
|
}, P = (r) => {
|
|
179
|
-
if (!
|
|
189
|
+
if (!n.getUri() || n.getUri() === "")
|
|
180
190
|
throw new Error("CDP client URI not configured. Call configure() first.");
|
|
181
191
|
if (!r.url || r.url === "")
|
|
182
192
|
throw new Error("AxiosRequestConfig URL is empty. This should never happen.");
|
|
183
193
|
if (!r.method || r.method === "")
|
|
184
194
|
throw new Error("AxiosRequestConfig method is empty. This should never happen.");
|
|
185
|
-
},
|
|
195
|
+
}, T = (r) => r.method?.toString().toUpperCase() || "GET", p = (r) => {
|
|
186
196
|
if (!r.url)
|
|
187
197
|
throw new Error("URL is required for authentication");
|
|
188
|
-
const t =
|
|
198
|
+
const t = n.getUri() + r.url;
|
|
189
199
|
return new URL(t);
|
|
190
200
|
}, f = (r) => {
|
|
191
201
|
const t = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(refresh|logout)$/, e = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(mfa)$/, s = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/config$/;
|
|
192
202
|
return t.test(r) || e.test(r) || s.test(r);
|
|
193
|
-
},
|
|
203
|
+
}, S = (r) => !/^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/custom\/authenticate$/.test(r), m = (r) => {
|
|
194
204
|
const t = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(init)$/, e = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/verify\//;
|
|
195
205
|
return t.test(r) || e.test(r);
|
|
196
206
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -868,6 +868,8 @@ export declare const ErrorType: {
|
|
|
868
868
|
readonly malformed_transaction: "malformed_transaction";
|
|
869
869
|
readonly not_found: "not_found";
|
|
870
870
|
readonly payment_method_required: "payment_method_required";
|
|
871
|
+
readonly payment_required: "payment_required";
|
|
872
|
+
readonly settlement_failed: "settlement_failed";
|
|
871
873
|
readonly rate_limit_exceeded: "rate_limit_exceeded";
|
|
872
874
|
readonly request_canceled: "request_canceled";
|
|
873
875
|
readonly service_unavailable: "service_unavailable";
|
|
@@ -1030,6 +1032,21 @@ export declare const EvmEip7702DelegationNetwork: {
|
|
|
1030
1032
|
readonly "ethereum-sepolia": "ethereum-sepolia";
|
|
1031
1033
|
};
|
|
1032
1034
|
|
|
1035
|
+
export declare interface EvmEip7702DelegationStatus {
|
|
1036
|
+
status: EvmEip7702DelegationStatusStatus;
|
|
1037
|
+
delegateAddress?: string;
|
|
1038
|
+
network: EvmEip7702DelegationNetwork;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
export declare type EvmEip7702DelegationStatusStatus = (typeof EvmEip7702DelegationStatusStatus)[keyof typeof EvmEip7702DelegationStatusStatus];
|
|
1042
|
+
|
|
1043
|
+
export declare const EvmEip7702DelegationStatusStatus: {
|
|
1044
|
+
readonly CURRENT: "CURRENT";
|
|
1045
|
+
readonly NOT_DELEGATED: "NOT_DELEGATED";
|
|
1046
|
+
readonly WRONG_PROXY: "WRONG_PROXY";
|
|
1047
|
+
readonly NOT_INITIALIZED: "NOT_INITIALIZED";
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1033
1050
|
export declare interface EvmMessageCriterion {
|
|
1034
1051
|
type: EvmMessageCriterionType;
|
|
1035
1052
|
match: string;
|
|
@@ -1110,6 +1127,7 @@ export declare const EvmSwapsNetwork: {
|
|
|
1110
1127
|
readonly ethereum: "ethereum";
|
|
1111
1128
|
readonly arbitrum: "arbitrum";
|
|
1112
1129
|
readonly optimism: "optimism";
|
|
1130
|
+
readonly polygon: "polygon";
|
|
1113
1131
|
};
|
|
1114
1132
|
|
|
1115
1133
|
export declare interface EvmTypedAddressCondition {
|
|
@@ -1273,6 +1291,15 @@ export declare const getAuthenticatedEndUser: (projectId: string, userId: string
|
|
|
1273
1291
|
|
|
1274
1292
|
export declare type GetAuthenticatedEndUserResult = NonNullable<Awaited<ReturnType<typeof getAuthenticatedEndUser>>>;
|
|
1275
1293
|
|
|
1294
|
+
export declare const getEvmEip7702DelegationStatusWithEndUserAccount: (projectId: string, userId: string, params: GetEvmEip7702DelegationStatusWithEndUserAccountParams, options?: SecondParameter<typeof cdpApiClient>) => Promise<EvmEip7702DelegationStatus>;
|
|
1295
|
+
|
|
1296
|
+
export declare type GetEvmEip7702DelegationStatusWithEndUserAccountParams = {
|
|
1297
|
+
address: string;
|
|
1298
|
+
network: EvmEip7702DelegationNetwork;
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
export declare type GetEvmEip7702DelegationStatusWithEndUserAccountResult = NonNullable<Awaited<ReturnType<typeof getEvmEip7702DelegationStatusWithEndUserAccount>>>;
|
|
1302
|
+
|
|
1276
1303
|
export declare const getMfaConfig: (projectId: string, options?: SecondParameter<typeof cdpApiClient>) => Promise<MfaConfig>;
|
|
1277
1304
|
|
|
1278
1305
|
export declare type GetMfaConfigResult = NonNullable<Awaited<ReturnType<typeof getMfaConfig>>>;
|
|
@@ -2023,11 +2050,21 @@ export declare interface Order {
|
|
|
2023
2050
|
executedAt?: string;
|
|
2024
2051
|
completedAt?: string;
|
|
2025
2052
|
canceledAt?: string;
|
|
2026
|
-
|
|
2053
|
+
failureCode?: OrderFailureCode;
|
|
2054
|
+
failureMessage?: string;
|
|
2027
2055
|
createdAt: string;
|
|
2028
2056
|
updatedAt: string;
|
|
2029
2057
|
}
|
|
2030
2058
|
|
|
2059
|
+
export declare type OrderFailureCode = (typeof OrderFailureCode)[keyof typeof OrderFailureCode];
|
|
2060
|
+
|
|
2061
|
+
export declare const OrderFailureCode: {
|
|
2062
|
+
readonly insufficient_balance: "insufficient_balance";
|
|
2063
|
+
readonly no_liquidity: "no_liquidity";
|
|
2064
|
+
readonly market_unavailable: "market_unavailable";
|
|
2065
|
+
readonly internal_error: "internal_error";
|
|
2066
|
+
};
|
|
2067
|
+
|
|
2031
2068
|
export declare interface OrderFee {
|
|
2032
2069
|
type: OrderFeeType;
|
|
2033
2070
|
amount: string;
|
|
@@ -3346,7 +3383,6 @@ export declare interface Transfer {
|
|
|
3346
3383
|
fees?: TransferFees;
|
|
3347
3384
|
completedAt?: string;
|
|
3348
3385
|
failureReason?: string;
|
|
3349
|
-
lastError?: TransferLastError;
|
|
3350
3386
|
expiresAt?: string;
|
|
3351
3387
|
executedAt?: string;
|
|
3352
3388
|
createdAt?: string;
|
|
@@ -3446,19 +3482,6 @@ export declare interface TransferFilters {
|
|
|
3446
3482
|
destinationAmountMax?: string;
|
|
3447
3483
|
}
|
|
3448
3484
|
|
|
3449
|
-
export declare type TransferLastError = {
|
|
3450
|
-
code?: string;
|
|
3451
|
-
message?: string;
|
|
3452
|
-
param?: string;
|
|
3453
|
-
details?: TransferLastErrorDetails;
|
|
3454
|
-
};
|
|
3455
|
-
|
|
3456
|
-
export declare type TransferLastErrorDetails = {
|
|
3457
|
-
availableBalance?: string;
|
|
3458
|
-
requiredAmount?: string;
|
|
3459
|
-
retryAfter?: number;
|
|
3460
|
-
};
|
|
3461
|
-
|
|
3462
3485
|
export declare interface TransferRequest {
|
|
3463
3486
|
source: CreateTransferSource;
|
|
3464
3487
|
target: TransferTarget;
|