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