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