@coinbase/cdp-api-client 0.0.93 → 0.0.94
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 +136 -121
- 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/index21.js +2 -2
- package/dist/esm/index22.js +2 -2
- package/dist/esm/index23.js +2 -2
- package/dist/esm/index3.js +1 -1
- package/dist/esm/index4.js +1 -1
- package/dist/esm/index5.js +21 -22
- package/dist/esm/index6.js +288 -232
- package/dist/esm/index7.js +126 -115
- package/dist/types/index.d.ts +271 -46
- package/package.json +1 -1
package/dist/esm/index7.js
CHANGED
|
@@ -2,88 +2,102 @@ import { Analytics as o } from "./index2.js";
|
|
|
2
2
|
import "./index3.js";
|
|
3
3
|
import l from "axios";
|
|
4
4
|
import { ERROR_DOCS_PAGE_URL as c } from "./index9.js";
|
|
5
|
-
import { UnknownApiError as
|
|
5
|
+
import { UnknownApiError as y, HttpErrorType as u, isOpenAPIError as g, APIError as d, UnknownError as k } from "./index8.js";
|
|
6
6
|
const w = () => typeof window < "u" && typeof document < "u";
|
|
7
7
|
let n = l.create({
|
|
8
8
|
baseURL: "https://api.cdp.coinbase.com/platform"
|
|
9
9
|
}), i = null;
|
|
10
|
-
const
|
|
11
|
-
n = l.create({
|
|
12
|
-
baseURL:
|
|
10
|
+
const O = (t) => {
|
|
11
|
+
if (n = l.create({
|
|
12
|
+
baseURL: t.basePath || "https://api.cdp.coinbase.com/platform",
|
|
13
13
|
// Only enable cookies in browser environments where they're supported
|
|
14
14
|
withCredentials: w()
|
|
15
|
-
}), n.interceptors.request.use(async (
|
|
16
|
-
const
|
|
17
|
-
if (!i || v(s.pathname) || A(s.pathname) && !await i.isSignedIn() ||
|
|
18
|
-
return
|
|
15
|
+
}), n.interceptors.request.use(async (r) => {
|
|
16
|
+
const e = U(r), s = f(r);
|
|
17
|
+
if (!i || v(s.pathname) || A(s.pathname) && !await i.isSignedIn() || !I(s.pathname))
|
|
18
|
+
return r;
|
|
19
19
|
const a = await i.getXWalletAuth({
|
|
20
|
-
requestMethod:
|
|
20
|
+
requestMethod: e,
|
|
21
21
|
requestHost: s.host,
|
|
22
22
|
requestPath: s.pathname,
|
|
23
|
-
requestData:
|
|
23
|
+
requestData: r.data
|
|
24
24
|
});
|
|
25
|
-
return a && (
|
|
26
|
-
}), n.interceptors.request.use(async (
|
|
27
|
-
const
|
|
28
|
-
if (!i || v(
|
|
29
|
-
return
|
|
25
|
+
return a && (r.headers["X-Wallet-Auth"] = a), r;
|
|
26
|
+
}), n.interceptors.request.use(async (r) => {
|
|
27
|
+
const e = f(r);
|
|
28
|
+
if (!i || v(e.pathname) || A(e.pathname) && !await i.isSignedIn())
|
|
29
|
+
return r;
|
|
30
30
|
const s = await i.getToken();
|
|
31
|
-
return s && s !== "" && (
|
|
32
|
-
}), w()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
}
|
|
31
|
+
return s && s !== "" && (r.headers.Authorization = `Bearer ${s}`), r;
|
|
32
|
+
}), !w()) {
|
|
33
|
+
const r = t.platform ? `CDP/reactnative/${t.platform}` : "CDP/reactnative";
|
|
34
|
+
n.interceptors.request.use(async (e) => {
|
|
35
|
+
let s = e.headers["User-Agent"];
|
|
36
|
+
return s = s ? `${s} ${r}` : r, e.headers["User-Agent"] = s, e;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
t.refreshTokenStorage && P(t.refreshTokenStorage), t.appAttestation && E(t.appAttestation, t.platform), t.debugging && (n.interceptors.request.use((r) => (console.log("Request:", r), r)), n.interceptors.response.use((r) => (console.log("Response:", r), r)));
|
|
40
|
+
}, D = (t) => {
|
|
41
|
+
i = t;
|
|
42
|
+
}, E = (t, r) => {
|
|
39
43
|
n.interceptors.request.use(async (e) => {
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
44
|
+
const s = f(e);
|
|
45
|
+
if (!q(s.pathname) || !t.isEnabled())
|
|
42
46
|
return e;
|
|
43
47
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
if (r === "ios") {
|
|
49
|
+
const a = s.pathname.match(/\/projects\/([^/]+)\//);
|
|
50
|
+
if (!a || !a[1])
|
|
51
|
+
return e;
|
|
52
|
+
const R = `/v2/embedded-wallet-api/projects/${a[1]}/attestation/challenge`, h = (await n.post(R)).data.challenge;
|
|
53
|
+
if (!h)
|
|
54
|
+
return console.warn("Failed to fetch assertion challenge"), e;
|
|
55
|
+
const p = await t.generateAssertion(h);
|
|
56
|
+
if (!p)
|
|
57
|
+
return e;
|
|
58
|
+
e.headers["X-App-Attestation-Assertion"] = p.assertion, e.headers["X-App-Attestation-Key-ID"] = p.keyId, e.headers["X-App-Attestation-Challenge"] = h;
|
|
59
|
+
} else {
|
|
60
|
+
const a = await t.generateAssertion(JSON.stringify(e.data));
|
|
61
|
+
if (!a)
|
|
62
|
+
return e;
|
|
63
|
+
e.headers["X-Integrity-Token"] = a.assertion, e.headers["X-Package-Name"] = t.appIdentifier;
|
|
64
|
+
}
|
|
65
|
+
return e;
|
|
66
|
+
} catch (a) {
|
|
53
67
|
throw new Error(
|
|
54
|
-
`App attestation required but assertion generation failed: ${
|
|
68
|
+
`App attestation required but assertion generation failed: ${a instanceof Error ? a.message : String(a)}`
|
|
55
69
|
);
|
|
56
70
|
}
|
|
57
71
|
});
|
|
58
|
-
},
|
|
59
|
-
...
|
|
72
|
+
}, _ = (t, r) => ({
|
|
73
|
+
...t,
|
|
60
74
|
headers: {
|
|
61
|
-
...
|
|
62
|
-
"X-Idempotency-Key":
|
|
75
|
+
...t.headers || {},
|
|
76
|
+
"X-Idempotency-Key": r
|
|
63
77
|
}
|
|
64
|
-
}),
|
|
65
|
-
S(
|
|
78
|
+
}), z = async (t, r) => {
|
|
79
|
+
S(t), r && r !== "" && (t = _(t, r));
|
|
66
80
|
try {
|
|
67
|
-
return (await n(
|
|
68
|
-
} catch (
|
|
69
|
-
if (l.isAxiosError(
|
|
70
|
-
throw new
|
|
81
|
+
return (await n(t)).data;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
if (l.isAxiosError(e) && !e.response)
|
|
84
|
+
throw new y(
|
|
71
85
|
u.unknown,
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
e.cause instanceof Error ? e.cause.message : e.message,
|
|
87
|
+
e.cause
|
|
74
88
|
);
|
|
75
|
-
if (l.isAxiosError(
|
|
76
|
-
if (
|
|
89
|
+
if (l.isAxiosError(e) && e.response) {
|
|
90
|
+
if (g(e.response.data))
|
|
77
91
|
throw new d(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
e.response.status,
|
|
93
|
+
e.response.data.errorType,
|
|
94
|
+
e.response.data.errorMessage,
|
|
95
|
+
e.response.data.correlationId,
|
|
96
|
+
e.response.data.errorLink,
|
|
97
|
+
e.cause
|
|
84
98
|
);
|
|
85
99
|
{
|
|
86
|
-
const s =
|
|
100
|
+
const s = e.response.status;
|
|
87
101
|
switch (s) {
|
|
88
102
|
case 401:
|
|
89
103
|
throw new d(
|
|
@@ -92,7 +106,7 @@ const X = (r) => {
|
|
|
92
106
|
"Unauthorized.",
|
|
93
107
|
void 0,
|
|
94
108
|
`${c}#unauthorized`,
|
|
95
|
-
|
|
109
|
+
e.cause
|
|
96
110
|
);
|
|
97
111
|
case 404:
|
|
98
112
|
throw new d(
|
|
@@ -101,7 +115,7 @@ const X = (r) => {
|
|
|
101
115
|
"API not found.",
|
|
102
116
|
void 0,
|
|
103
117
|
`${c}#not_found`,
|
|
104
|
-
|
|
118
|
+
e.cause
|
|
105
119
|
);
|
|
106
120
|
case 502:
|
|
107
121
|
throw new d(
|
|
@@ -110,7 +124,7 @@ const X = (r) => {
|
|
|
110
124
|
"Bad gateway.",
|
|
111
125
|
void 0,
|
|
112
126
|
`${c}`,
|
|
113
|
-
|
|
127
|
+
e.cause
|
|
114
128
|
);
|
|
115
129
|
case 503:
|
|
116
130
|
throw new d(
|
|
@@ -119,47 +133,44 @@ const X = (r) => {
|
|
|
119
133
|
"Service unavailable. Please try again later.",
|
|
120
134
|
void 0,
|
|
121
135
|
`${c}`,
|
|
122
|
-
|
|
136
|
+
e.cause
|
|
123
137
|
);
|
|
124
138
|
default: {
|
|
125
139
|
let a = "";
|
|
126
|
-
if (
|
|
140
|
+
if (e.response.data)
|
|
127
141
|
try {
|
|
128
|
-
a = JSON.stringify(
|
|
142
|
+
a = JSON.stringify(e.response.data);
|
|
129
143
|
} catch {
|
|
130
|
-
a = String(
|
|
144
|
+
a = String(e.response.data);
|
|
131
145
|
}
|
|
132
|
-
const
|
|
146
|
+
const m = a ? `An unexpected error occurred: ${a}` : "An unexpected error occurred.";
|
|
133
147
|
throw new d(
|
|
134
148
|
s,
|
|
135
149
|
u.unexpected_error,
|
|
136
|
-
|
|
150
|
+
m,
|
|
137
151
|
void 0,
|
|
138
152
|
`${c}`,
|
|
139
|
-
|
|
153
|
+
e.cause
|
|
140
154
|
);
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
}
|
|
144
158
|
}
|
|
145
|
-
throw new
|
|
146
|
-
"Something went wrong. Please reach out at https://discord.com/channels/1220414409550336183/1271495764580896789 for help.",
|
|
147
|
-
t instanceof Error ? t : void 0
|
|
148
|
-
);
|
|
159
|
+
throw new k("Something went wrong.", e instanceof Error ? e : void 0);
|
|
149
160
|
}
|
|
150
|
-
},
|
|
161
|
+
}, P = (t) => {
|
|
151
162
|
n.interceptors.response.use(
|
|
152
|
-
async (
|
|
163
|
+
async (r) => {
|
|
153
164
|
try {
|
|
154
|
-
if (
|
|
165
|
+
if ($(r)) {
|
|
155
166
|
o.sendSessionRefreshEvent({
|
|
156
167
|
name: "refresh_token_response"
|
|
157
168
|
});
|
|
158
|
-
const
|
|
159
|
-
|
|
169
|
+
const e = r.data?.refreshToken;
|
|
170
|
+
e && (o.sendSessionRefreshEvent({
|
|
160
171
|
name: "refresh_token_received"
|
|
161
172
|
}), await Promise.race([
|
|
162
|
-
|
|
173
|
+
t.setRefreshToken(e),
|
|
163
174
|
new Promise(
|
|
164
175
|
(s, a) => setTimeout(() => a(new Error("setRefreshToken timed out after 5000ms")), 5e3)
|
|
165
176
|
)
|
|
@@ -167,71 +178,71 @@ const X = (r) => {
|
|
|
167
178
|
name: "refresh_token_stored"
|
|
168
179
|
}));
|
|
169
180
|
}
|
|
170
|
-
} catch (
|
|
171
|
-
const s =
|
|
181
|
+
} catch (e) {
|
|
182
|
+
const s = e instanceof Error ? e.message : String(e);
|
|
172
183
|
o.sendSessionRefreshEvent({
|
|
173
184
|
name: "refresh_token_store_failed",
|
|
174
185
|
error_message: s
|
|
175
|
-
}), console.warn("Failed to store refresh token:",
|
|
186
|
+
}), console.warn("Failed to store refresh token:", e);
|
|
176
187
|
}
|
|
177
|
-
return
|
|
188
|
+
return r;
|
|
178
189
|
},
|
|
179
|
-
(
|
|
180
|
-
), n.interceptors.request.use(async (
|
|
190
|
+
(r) => Promise.reject(r)
|
|
191
|
+
), n.interceptors.request.use(async (r) => {
|
|
181
192
|
try {
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
184
|
-
|
|
193
|
+
if (T(r.url)) {
|
|
194
|
+
const e = await t.getRefreshToken();
|
|
195
|
+
e ? (o.sendSessionRefreshEvent({
|
|
185
196
|
name: "refresh_token_retrieved"
|
|
186
|
-
}),
|
|
187
|
-
...
|
|
188
|
-
refreshToken:
|
|
197
|
+
}), r.data = {
|
|
198
|
+
...r.data,
|
|
199
|
+
refreshToken: e
|
|
189
200
|
}) : o.sendSessionRefreshEvent({
|
|
190
201
|
name: "refresh_token_missing"
|
|
191
202
|
});
|
|
192
203
|
}
|
|
193
|
-
|
|
194
|
-
} catch (
|
|
195
|
-
const s =
|
|
204
|
+
b(r.url) && await t.removeRefreshToken();
|
|
205
|
+
} catch (e) {
|
|
206
|
+
const s = e instanceof Error ? e.message : String(e);
|
|
196
207
|
o.sendSessionRefreshEvent({
|
|
197
208
|
name: "refresh_token_retrieve_failed",
|
|
198
209
|
error_message: s
|
|
199
|
-
}), console.warn("Failed to retrieve refresh token:",
|
|
210
|
+
}), console.warn("Failed to retrieve refresh token:", e);
|
|
200
211
|
}
|
|
201
|
-
return
|
|
212
|
+
return r;
|
|
202
213
|
});
|
|
203
|
-
},
|
|
204
|
-
const
|
|
205
|
-
return
|
|
206
|
-
|
|
214
|
+
}, b = (t) => t ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/logout$/.test(t) : !1, T = (t) => t ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(refresh|logout)$/.test(t) : !1, $ = (t) => {
|
|
215
|
+
const r = t.config.url;
|
|
216
|
+
return r ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(verify\/(email|sms|oauth\/.*)|refresh)$/.test(
|
|
217
|
+
r
|
|
207
218
|
) : !1;
|
|
208
|
-
}, S = (
|
|
219
|
+
}, S = (t) => {
|
|
209
220
|
if (!n.getUri() || n.getUri() === "")
|
|
210
221
|
throw new Error("CDP client URI not configured. Call configure() first.");
|
|
211
|
-
if (!
|
|
222
|
+
if (!t.url || t.url === "")
|
|
212
223
|
throw new Error("AxiosRequestConfig URL is empty. This should never happen.");
|
|
213
|
-
if (!
|
|
224
|
+
if (!t.method || t.method === "")
|
|
214
225
|
throw new Error("AxiosRequestConfig method is empty. This should never happen.");
|
|
215
|
-
}, U = (
|
|
216
|
-
if (!
|
|
226
|
+
}, U = (t) => t.method?.toString().toUpperCase() || "GET", f = (t) => {
|
|
227
|
+
if (!t.url)
|
|
217
228
|
throw new Error("URL is required for authentication");
|
|
218
|
-
const
|
|
219
|
-
return new URL(
|
|
220
|
-
}, v = (
|
|
221
|
-
const
|
|
222
|
-
return
|
|
223
|
-
},
|
|
224
|
-
const
|
|
225
|
-
return
|
|
226
|
-
},
|
|
229
|
+
const r = n.getUri() + t.url;
|
|
230
|
+
return new URL(r);
|
|
231
|
+
}, v = (t) => {
|
|
232
|
+
const r = /^\/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$/, a = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/attestation\/(challenge|register)$/;
|
|
233
|
+
return r.test(t) || e.test(t) || s.test(t) || a.test(t);
|
|
234
|
+
}, I = (t) => !/^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/custom\/authenticate$/.test(t), A = (t) => {
|
|
235
|
+
const r = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(init)$/, e = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/verify\//;
|
|
236
|
+
return r.test(t) || e.test(t);
|
|
237
|
+
}, q = (t) => [
|
|
227
238
|
// Auth flows: prevent account takeover on mobile clients
|
|
228
239
|
/\/auth\/verify\//,
|
|
229
240
|
// VerifyEmailAuthentication, VerifySmsAuthentication, VerifyOAuthCode, VerifyOAuthEndUserIdentity
|
|
230
241
|
/\/auth\/refresh$/
|
|
231
242
|
// RefreshAccessToken
|
|
232
|
-
].some((
|
|
243
|
+
].some((e) => e.test(t));
|
|
233
244
|
export {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
245
|
+
z as cdpApiClient,
|
|
246
|
+
O as configureCdpApiClient,
|
|
247
|
+
D as setAuthManager
|
|
237
248
|
};
|