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