@coinbase/cdp-api-client 0.0.90 → 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/index14.js +1 -1
- package/dist/esm/index19.js +1 -1
- package/dist/esm/index20.js +1 -1
- package/dist/esm/index21.js +2 -2
- package/dist/esm/index22.js +2 -2
- package/dist/esm/index23.js +2 -2
- package/dist/esm/index4.js +1 -1
- package/dist/esm/index7.js +61 -51
- package/package.json +1 -1
package/dist/esm/index14.js
CHANGED
package/dist/esm/index19.js
CHANGED
package/dist/esm/index20.js
CHANGED
package/dist/esm/index21.js
CHANGED
package/dist/esm/index22.js
CHANGED
package/dist/esm/index23.js
CHANGED
package/dist/esm/index4.js
CHANGED
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
|
};
|