@coinbase/cdp-api-client 0.0.43 → 0.0.45
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 +164 -142
- package/dist/esm/index2.js +75 -62
- package/dist/esm/index3.js +411 -247
- package/dist/esm/index4.js +67 -66
- package/dist/types/index.d.ts +758 -110
- package/package.json +1 -1
package/dist/esm/index4.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ERROR_DOCS_PAGE_URL as
|
|
3
|
-
import { UnknownApiError as
|
|
4
|
-
const
|
|
5
|
-
let o =
|
|
1
|
+
import c from "axios";
|
|
2
|
+
import { ERROR_DOCS_PAGE_URL as i } from "./index6.js";
|
|
3
|
+
import { UnknownApiError as f, HttpErrorType as n, isOpenAPIError as w, APIError as u, UnknownError as m } from "./index5.js";
|
|
4
|
+
const v = () => typeof window < "u" && typeof document < "u";
|
|
5
|
+
let o = c.create({
|
|
6
6
|
baseURL: "https://api.cdp.coinbase.com/platform"
|
|
7
|
-
}),
|
|
8
|
-
const
|
|
9
|
-
o =
|
|
7
|
+
}), d = null;
|
|
8
|
+
const P = (t) => {
|
|
9
|
+
o = c.create({
|
|
10
10
|
baseURL: t.basePath || "https://api.cdp.coinbase.com/platform",
|
|
11
11
|
// Only enable cookies in browser environments where they're supported
|
|
12
|
-
withCredentials:
|
|
12
|
+
withCredentials: v()
|
|
13
13
|
}), o.interceptors.request.use(async (r) => {
|
|
14
|
-
const e =
|
|
15
|
-
if (!
|
|
14
|
+
const e = g(r), s = h(r);
|
|
15
|
+
if (!d || l(s.pathname))
|
|
16
16
|
return r;
|
|
17
|
-
const
|
|
17
|
+
const a = await d.getXWalletAuth?.({
|
|
18
18
|
requestMethod: e,
|
|
19
19
|
requestHost: s.host,
|
|
20
20
|
requestPath: s.pathname,
|
|
21
21
|
requestData: r.data
|
|
22
22
|
});
|
|
23
|
-
return
|
|
23
|
+
return a && a !== "" && (r.headers["X-Wallet-Auth"] = a), r;
|
|
24
24
|
}), o.interceptors.request.use(async (r) => {
|
|
25
|
-
const e =
|
|
26
|
-
if (!
|
|
25
|
+
const e = h(r);
|
|
26
|
+
if (!d || l(e.pathname))
|
|
27
27
|
return r;
|
|
28
|
-
const s = await
|
|
28
|
+
const s = await d.getToken();
|
|
29
29
|
return s && s !== "" && (r.headers.Authorization = `Bearer ${s}`), r;
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
|
|
30
|
+
}), t.refreshTokenStorage && R(t.refreshTokenStorage), t.debugging && (o.interceptors.request.use((r) => (console.log("Request:", r), r)), o.interceptors.response.use((r) => (console.log("Response:", r), r)));
|
|
31
|
+
}, x = (t) => {
|
|
32
|
+
d = t;
|
|
33
33
|
}, y = (t, r) => ({
|
|
34
34
|
...t,
|
|
35
35
|
headers: {
|
|
36
36
|
...t.headers || {},
|
|
37
37
|
"X-Idempotency-Key": r
|
|
38
38
|
}
|
|
39
|
-
}),
|
|
40
|
-
|
|
39
|
+
}), C = async (t, r) => {
|
|
40
|
+
U(t), r && r !== "" && (t = y(t, r));
|
|
41
41
|
try {
|
|
42
42
|
return (await o(t)).data;
|
|
43
43
|
} catch (e) {
|
|
44
|
-
if (
|
|
45
|
-
throw new
|
|
46
|
-
|
|
44
|
+
if (c.isAxiosError(e) && !e.response)
|
|
45
|
+
throw new f(
|
|
46
|
+
n.unknown,
|
|
47
47
|
e.cause instanceof Error ? e.cause.message : e.message,
|
|
48
48
|
e.cause
|
|
49
49
|
);
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
throw new
|
|
50
|
+
if (c.isAxiosError(e) && e.response) {
|
|
51
|
+
if (w(e.response.data))
|
|
52
|
+
throw new u(
|
|
53
53
|
e.response.status,
|
|
54
54
|
e.response.data.errorType,
|
|
55
55
|
e.response.data.errorMessage,
|
|
@@ -61,63 +61,63 @@ const x = (t) => {
|
|
|
61
61
|
const s = e.response.status;
|
|
62
62
|
switch (s) {
|
|
63
63
|
case 401:
|
|
64
|
-
throw new
|
|
64
|
+
throw new u(
|
|
65
65
|
s,
|
|
66
|
-
|
|
66
|
+
n.unauthorized,
|
|
67
67
|
"Unauthorized.",
|
|
68
68
|
void 0,
|
|
69
|
-
`${
|
|
69
|
+
`${i}#unauthorized`,
|
|
70
70
|
e.cause
|
|
71
71
|
);
|
|
72
72
|
case 404:
|
|
73
|
-
throw new
|
|
73
|
+
throw new u(
|
|
74
74
|
s,
|
|
75
|
-
|
|
75
|
+
n.not_found,
|
|
76
76
|
"API not found.",
|
|
77
77
|
void 0,
|
|
78
|
-
`${
|
|
78
|
+
`${i}#not_found`,
|
|
79
79
|
e.cause
|
|
80
80
|
);
|
|
81
81
|
case 502:
|
|
82
|
-
throw new
|
|
82
|
+
throw new u(
|
|
83
83
|
s,
|
|
84
|
-
|
|
84
|
+
n.bad_gateway,
|
|
85
85
|
"Bad gateway.",
|
|
86
86
|
void 0,
|
|
87
|
-
`${
|
|
87
|
+
`${i}`,
|
|
88
88
|
e.cause
|
|
89
89
|
);
|
|
90
90
|
case 503:
|
|
91
|
-
throw new
|
|
91
|
+
throw new u(
|
|
92
92
|
s,
|
|
93
|
-
|
|
93
|
+
n.service_unavailable,
|
|
94
94
|
"Service unavailable. Please try again later.",
|
|
95
95
|
void 0,
|
|
96
|
-
`${
|
|
96
|
+
`${i}`,
|
|
97
97
|
e.cause
|
|
98
98
|
);
|
|
99
99
|
default: {
|
|
100
|
-
let
|
|
100
|
+
let a = "";
|
|
101
101
|
if (e.response.data)
|
|
102
102
|
try {
|
|
103
|
-
|
|
103
|
+
a = JSON.stringify(e.response.data);
|
|
104
104
|
} catch {
|
|
105
|
-
|
|
105
|
+
a = String(e.response.data);
|
|
106
106
|
}
|
|
107
|
-
const
|
|
108
|
-
throw new
|
|
107
|
+
const p = a ? `An unexpected error occurred: ${a}` : "An unexpected error occurred.";
|
|
108
|
+
throw new u(
|
|
109
109
|
s,
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
n.unexpected_error,
|
|
111
|
+
p,
|
|
112
112
|
void 0,
|
|
113
|
-
`${
|
|
113
|
+
`${i}`,
|
|
114
114
|
e.cause
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
throw new
|
|
120
|
+
throw new m(
|
|
121
121
|
"Something went wrong. Please reach out at https://discord.com/channels/1220414409550336183/1271495764580896789 for help.",
|
|
122
122
|
e instanceof Error ? e : void 0
|
|
123
123
|
);
|
|
@@ -126,10 +126,9 @@ const x = (t) => {
|
|
|
126
126
|
o.interceptors.response.use(
|
|
127
127
|
async (r) => {
|
|
128
128
|
try {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
s && await t.setRefreshToken(s);
|
|
129
|
+
if (T(r)) {
|
|
130
|
+
const e = r.data?.refreshToken;
|
|
131
|
+
e && await t.setRefreshToken(e);
|
|
133
132
|
}
|
|
134
133
|
} catch (e) {
|
|
135
134
|
console.warn("Failed to store refresh token:", e);
|
|
@@ -141,38 +140,40 @@ const x = (t) => {
|
|
|
141
140
|
try {
|
|
142
141
|
if (A(r.url)) {
|
|
143
142
|
const e = await t.getRefreshToken();
|
|
144
|
-
e && (r.
|
|
143
|
+
e && (r.data = {
|
|
144
|
+
...r.data,
|
|
145
|
+
refreshToken: e
|
|
146
|
+
});
|
|
145
147
|
}
|
|
148
|
+
k(r.url) && await t.removeRefreshToken();
|
|
146
149
|
} catch (e) {
|
|
147
150
|
console.warn("Failed to retrieve refresh token:", e);
|
|
148
151
|
}
|
|
149
152
|
return r;
|
|
150
153
|
});
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return null;
|
|
158
|
-
}, A = (t) => t ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/refresh$/.test(t) : !1, E = (t) => {
|
|
154
|
+
}, k = (t) => t ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/logout$/.test(t) : !1, A = (t) => t ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(refresh|logout)$/.test(t) : !1, T = (t) => {
|
|
155
|
+
const r = t.config.url;
|
|
156
|
+
return r ? /^\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(verify\/(email|sms)|refresh)$/.test(
|
|
157
|
+
r
|
|
158
|
+
) : !1;
|
|
159
|
+
}, U = (t) => {
|
|
159
160
|
if (!o.getUri() || o.getUri() === "")
|
|
160
161
|
throw new Error("CDP client URI not configured. Call configure() first.");
|
|
161
162
|
if (!t.url || t.url === "")
|
|
162
163
|
throw new Error("AxiosRequestConfig URL is empty. This should never happen.");
|
|
163
164
|
if (!t.method || t.method === "")
|
|
164
165
|
throw new Error("AxiosRequestConfig method is empty. This should never happen.");
|
|
165
|
-
},
|
|
166
|
+
}, g = (t) => t.method?.toString().toUpperCase() || "GET", h = (t) => {
|
|
166
167
|
if (!t.url)
|
|
167
168
|
throw new Error("URL is required for authentication");
|
|
168
169
|
const r = o.getUri() + t.url;
|
|
169
170
|
return new URL(r);
|
|
170
|
-
},
|
|
171
|
+
}, l = (t) => {
|
|
171
172
|
const r = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/(init|refresh|logout)$/, e = /^\/platform\/v2\/embedded-wallet-api\/projects\/[^/]+\/auth\/verify\//;
|
|
172
173
|
return r.test(t) || e.test(t);
|
|
173
174
|
};
|
|
174
175
|
export {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
C as cdpApiClient,
|
|
177
|
+
P as configureCdpApiClient,
|
|
178
|
+
x as setAuthManager
|
|
178
179
|
};
|