@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.
@@ -1,179 +1,4 @@
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
- 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
- };
1
+ const o = "0.0.56";
175
2
  export {
176
- $ as cdpApiClient,
177
- x as configureCdpApiClient,
178
- C as setAuthManager
3
+ o as VERSION
179
4
  };
@@ -1,76 +1,239 @@
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
- }
1
+ import { cdpApiClient as s } from "./index7.js";
2
+ const d = (e, t, n) => s(
3
+ {
4
+ url: `/v2/embedded-wallet-api/projects/${e}/auth/init`,
5
+ method: "POST",
6
+ headers: { "Content-Type": "application/json" },
7
+ data: t
8
+ },
9
+ n
10
+ ), i = (e, t, n) => s(
11
+ {
12
+ url: `/v2/embedded-wallet-api/projects/${e}/auth/verify/email`,
13
+ method: "POST",
14
+ headers: { "Content-Type": "application/json" },
15
+ data: t
16
+ },
17
+ n
18
+ ), c = (e, t, n) => s(
19
+ {
20
+ url: `/v2/embedded-wallet-api/projects/${e}/auth/verify/sms`,
21
+ method: "POST",
22
+ headers: { "Content-Type": "application/json" },
23
+ data: t
24
+ },
25
+ n
26
+ ), p = (e, t, n, a) => s(
27
+ {
28
+ url: `/v2/embedded-wallet-api/projects/${e}/auth/verify/oauth/${t}`,
29
+ method: "POST",
30
+ headers: { "Content-Type": "application/json" },
31
+ data: n
32
+ },
33
+ a
34
+ ), l = (e, t, n) => s(
35
+ {
36
+ url: `/v2/embedded-wallet-api/projects/${e}/auth/refresh`,
37
+ method: "POST",
38
+ headers: { "Content-Type": "application/json" },
39
+ data: t
40
+ },
41
+ n
42
+ ), u = (e, t, n) => s(
43
+ {
44
+ url: `/v2/embedded-wallet-api/projects/${e}/auth/logout`,
45
+ method: "POST",
46
+ headers: { "Content-Type": "application/json" },
47
+ data: t
48
+ },
49
+ n
50
+ ), m = (e, t, n) => s(
51
+ { url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}`, method: "GET" },
52
+ n
53
+ ), h = (e, t, n, a) => s(
54
+ {
55
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/wallet-secrets`,
56
+ method: "PUT",
57
+ headers: { "Content-Type": "application/json" },
58
+ data: n
59
+ },
60
+ a
61
+ ), T = (e, t, n, a) => s(
62
+ {
63
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm`,
64
+ method: "POST",
65
+ headers: { "Content-Type": "application/json" },
66
+ data: n
67
+ },
68
+ a
69
+ ), v = (e, t, n, a) => s(
70
+ {
71
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/sign`,
72
+ method: "POST",
73
+ headers: { "Content-Type": "application/json" },
74
+ data: n
75
+ },
76
+ a
77
+ ), $ = (e, t, n, a) => s(
78
+ {
79
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/sign/transaction`,
80
+ method: "POST",
81
+ headers: { "Content-Type": "application/json" },
82
+ data: n
83
+ },
84
+ a
85
+ ), j = (e, t, n, a) => s(
86
+ {
87
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/send/transaction`,
88
+ method: "POST",
89
+ headers: { "Content-Type": "application/json" },
90
+ data: n
91
+ },
92
+ a
93
+ ), S = (e, t, n, a) => s(
94
+ {
95
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/sign/message`,
96
+ method: "POST",
97
+ headers: { "Content-Type": "application/json" },
98
+ data: n
99
+ },
100
+ a
101
+ ), y = (e, t, n, a) => s(
102
+ {
103
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/sign/typed-data`,
104
+ method: "POST",
105
+ headers: { "Content-Type": "application/json" },
106
+ data: n
107
+ },
108
+ a
109
+ ), E = (e, t, n, a) => s(
110
+ {
111
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/export`,
112
+ method: "POST",
113
+ headers: { "Content-Type": "application/json" },
114
+ data: n
115
+ },
116
+ a
117
+ ), w = (e, t, n, a) => s(
118
+ {
119
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/smart-accounts`,
120
+ method: "POST",
121
+ headers: { "Content-Type": "application/json" },
122
+ data: n
123
+ },
124
+ a
125
+ ), b = (e, t, n, a, r) => s(
126
+ {
127
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/smart-accounts/${n}/user-operations/${a}`,
128
+ method: "GET"
129
+ },
130
+ r
131
+ ), O = (e, t, n, a, r) => s(
132
+ {
133
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/smart-accounts/${n}/send`,
134
+ method: "POST",
135
+ headers: { "Content-Type": "application/json" },
136
+ data: a
137
+ },
138
+ r
139
+ ), P = (e, t, n, a, r) => s(
140
+ {
141
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/smart-accounts/${n}/spend-permissions`,
142
+ method: "POST",
143
+ headers: { "Content-Type": "application/json" },
144
+ data: a
145
+ },
146
+ r
147
+ ), A = (e, t, n, a, r) => s(
148
+ {
149
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/smart-accounts/${n}/spend-permissions/list`,
150
+ method: "GET",
151
+ params: a
152
+ },
153
+ r
154
+ ), C = (e, t, n, a, r) => s(
155
+ {
156
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/evm/smart-accounts/${n}/spend-permissions/revoke`,
157
+ method: "POST",
158
+ headers: { "Content-Type": "application/json" },
159
+ data: a
160
+ },
161
+ r
162
+ ), U = (e, t, n, a) => s(
163
+ {
164
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/solana`,
165
+ method: "POST",
166
+ headers: { "Content-Type": "application/json" },
167
+ data: n
168
+ },
169
+ a
170
+ ), g = (e, t, n, a) => s(
171
+ {
172
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/solana/export`,
173
+ method: "POST",
174
+ headers: { "Content-Type": "application/json" },
175
+ data: n
176
+ },
177
+ a
178
+ ), W = (e, t, n, a) => s(
179
+ {
180
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/solana/sign`,
181
+ method: "POST",
182
+ headers: { "Content-Type": "application/json" },
183
+ data: n
184
+ },
185
+ a
186
+ ), f = (e, t, n, a) => s(
187
+ {
188
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/solana/sign/message`,
189
+ method: "POST",
190
+ headers: { "Content-Type": "application/json" },
191
+ data: n
192
+ },
193
+ a
194
+ ), x = (e, t, n, a) => s(
195
+ {
196
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/solana/sign/transaction`,
197
+ method: "POST",
198
+ headers: { "Content-Type": "application/json" },
199
+ data: n
200
+ },
201
+ a
202
+ ), k = (e, t, n, a) => s(
203
+ {
204
+ url: `/v2/embedded-wallet-api/projects/${e}/end-users/${t}/solana/send/transaction`,
205
+ method: "POST",
206
+ headers: { "Content-Type": "application/json" },
207
+ data: n
208
+ },
209
+ a
210
+ );
70
211
  export {
71
- a as APIError,
72
- u as HttpErrorType,
73
- d as UnknownApiError,
74
- c as UnknownError,
75
- p as isOpenAPIError
212
+ T as createEndUserEvmAccount,
213
+ w as createEndUserEvmSmartAccount,
214
+ U as createEndUserSolanaAccount,
215
+ P as createSpendPermissionWithEndUserAccount,
216
+ E as exportEndUserEvmAccount,
217
+ g as exportEndUserSolanaAccount,
218
+ m as getAuthenticatedEndUser,
219
+ b as getUserOperationWithEndUserAccount,
220
+ d as initiateAuthentication,
221
+ A as listSpendPermissionsWithEndUserAccount,
222
+ u as logOutEndUser,
223
+ l as refreshAccessToken,
224
+ h as registerTemporaryWalletSecret,
225
+ C as revokeSpendPermissionWithEndUserAccount,
226
+ j as sendEvmTransactionWithEndUserAccount,
227
+ k as sendSolanaTransactionWithEndUserAccount,
228
+ O as sendUserOperationWithEndUserAccount,
229
+ v as signEvmHashWithEndUserAccount,
230
+ S as signEvmMessageWithEndUserAccount,
231
+ $ as signEvmTransactionWithEndUserAccount,
232
+ y as signEvmTypedDataWithEndUserAccount,
233
+ W as signSolanaHashWithEndUserAccount,
234
+ f as signSolanaMessageWithEndUserAccount,
235
+ x as signSolanaTransactionWithEndUserAccount,
236
+ i as verifyEmailAuthentication,
237
+ p as verifyOAuthCode,
238
+ c as verifySmsAuthentication
76
239
  };