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