@coinbase/cdp-api-client 0.0.90 → 0.0.91

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