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