@chainrails/react 0.0.12 → 0.0.13

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,19 +1,19 @@
1
- import { useState as O, useEffect as J } from "react";
2
- import { jsxs as k, jsx as b } from "react/jsx-runtime";
3
- import './index.css';function I(t) {
1
+ import { useState as M, useRef as W, useEffect as G } from "react";
2
+ import { jsxs as O, jsx as w } from "react/jsx-runtime";
3
+ import './index.css';function B(t) {
4
4
  var e, s, r = "";
5
5
  if (typeof t == "string" || typeof t == "number") r += t;
6
6
  else if (typeof t == "object") if (Array.isArray(t)) {
7
7
  var n = t.length;
8
- for (e = 0; e < n; e++) t[e] && (s = I(t[e])) && (r && (r += " "), r += s);
8
+ for (e = 0; e < n; e++) t[e] && (s = B(t[e])) && (r && (r += " "), r += s);
9
9
  } else for (s in t) t[s] && (r && (r += " "), r += s);
10
10
  return r;
11
11
  }
12
- function K() {
13
- for (var t, e, s = 0, r = "", n = arguments.length; s < n; s++) (t = arguments[s]) && (e = I(t)) && (r && (r += " "), r += e);
12
+ function X() {
13
+ for (var t, e, s = 0, r = "", n = arguments.length; s < n; s++) (t = arguments[s]) && (e = B(t)) && (r && (r += " "), r += e);
14
14
  return r;
15
15
  }
16
- class P extends Error {
16
+ class C extends Error {
17
17
  response;
18
18
  request;
19
19
  options;
@@ -22,7 +22,7 @@ class P extends Error {
22
22
  super(`Request failed with ${u}: ${s.method} ${s.url}`), this.name = "HTTPError", this.response = e, this.request = s, this.options = r;
23
23
  }
24
24
  }
25
- class L extends Error {
25
+ class D extends Error {
26
26
  name = "NonError";
27
27
  value;
28
28
  constructor(e) {
@@ -34,17 +34,17 @@ class L extends Error {
34
34
  super(s), this.value = e;
35
35
  }
36
36
  }
37
- class A extends Error {
37
+ class S extends Error {
38
38
  name = "ForceRetryError";
39
39
  customDelay;
40
40
  code;
41
41
  customRequest;
42
42
  constructor(e) {
43
- const s = e?.cause ? e.cause instanceof Error ? e.cause : new L(e.cause) : void 0;
43
+ const s = e?.cause ? e.cause instanceof Error ? e.cause : new D(e.cause) : void 0;
44
44
  super(e?.code ? `Forced retry: ${e.code}` : "Forced retry", s ? { cause: s } : void 0), this.customDelay = e?.delay, this.code = e?.code, this.customRequest = e?.request;
45
45
  }
46
46
  }
47
- const v = (() => {
47
+ const I = (() => {
48
48
  let t = !1, e = !1;
49
49
  const s = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
50
50
  if (s && r)
@@ -63,7 +63,7 @@ const v = (() => {
63
63
  throw n;
64
64
  }
65
65
  return t && !e;
66
- })(), V = typeof globalThis.AbortController == "function", M = typeof globalThis.AbortSignal == "function" && typeof globalThis.AbortSignal.any == "function", W = typeof globalThis.ReadableStream == "function", G = typeof globalThis.FormData == "function", B = ["get", "post", "put", "patch", "head", "delete"], X = {
66
+ })(), Z = typeof globalThis.AbortController == "function", H = typeof globalThis.AbortSignal == "function" && typeof globalThis.AbortSignal.any == "function", Y = typeof globalThis.ReadableStream == "function", Q = typeof globalThis.FormData == "function", _ = ["get", "post", "put", "patch", "head", "delete"], ee = {
67
67
  json: "application/json",
68
68
  text: "text/*",
69
69
  formData: "multipart/form-data",
@@ -72,14 +72,14 @@ const v = (() => {
72
72
  // Supported in modern Fetch implementations (for example, browsers and recent Node.js/undici).
73
73
  // We still feature-check at runtime before exposing the shortcut.
74
74
  bytes: "*/*"
75
- }, C = 2147483647, Z = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length, D = Symbol("stop");
76
- class H {
75
+ }, A = 2147483647, te = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length, $ = Symbol("stop");
76
+ class F {
77
77
  options;
78
78
  constructor(e) {
79
79
  this.options = e;
80
80
  }
81
81
  }
82
- const Y = (t) => new H(t), Q = {
82
+ const se = (t) => new F(t), re = {
83
83
  json: !0,
84
84
  parseJson: !0,
85
85
  stringifyJson: !0,
@@ -93,10 +93,10 @@ const Y = (t) => new H(t), Q = {
93
93
  onUploadProgress: !0,
94
94
  fetch: !0,
95
95
  context: !0
96
- }, ee = {
96
+ }, ne = {
97
97
  next: !0
98
98
  // Next.js cache revalidation (revalidate, tags)
99
- }, te = {
99
+ }, oe = {
100
100
  method: !0,
101
101
  headers: !0,
102
102
  body: !0,
@@ -111,13 +111,13 @@ const Y = (t) => new H(t), Q = {
111
111
  signal: !0,
112
112
  window: !0,
113
113
  duplex: !0
114
- }, se = (t) => {
114
+ }, ie = (t) => {
115
115
  if (!t)
116
116
  return 0;
117
117
  if (t instanceof FormData) {
118
118
  let e = 0;
119
119
  for (const [s, r] of t)
120
- e += Z, e += new TextEncoder().encode(`Content-Disposition: form-data; name="${s}"`).length, e += typeof r == "string" ? new TextEncoder().encode(r).length : r.size;
120
+ e += te, e += new TextEncoder().encode(`Content-Disposition: form-data; name="${s}"`).length, e += typeof r == "string" ? new TextEncoder().encode(r).length : r.size;
121
121
  return e;
122
122
  }
123
123
  if (t instanceof Blob)
@@ -138,7 +138,7 @@ const Y = (t) => new H(t), Q = {
138
138
  return 0;
139
139
  }
140
140
  return 0;
141
- }, $ = (t, e, s) => {
141
+ }, z = (t, e, s) => {
142
142
  let r, n = 0;
143
143
  return t.pipeThrough(new TransformStream({
144
144
  transform(o, i) {
@@ -153,7 +153,7 @@ const Y = (t) => new H(t), Q = {
153
153
  r && (n += r.byteLength, s?.({ percent: 1, totalBytes: Math.max(e, n), transferredBytes: n }, r));
154
154
  }
155
155
  }));
156
- }, re = (t, e) => {
156
+ }, ae = (t, e) => {
157
157
  if (!t.body)
158
158
  return t;
159
159
  if (t.status === 204)
@@ -163,40 +163,40 @@ const Y = (t) => new H(t), Q = {
163
163
  headers: t.headers
164
164
  });
165
165
  const s = Math.max(0, Number(t.headers.get("content-length")) || 0);
166
- return new Response($(t.body, s, e), {
166
+ return new Response(z(t.body, s, e), {
167
167
  status: t.status,
168
168
  statusText: t.statusText,
169
169
  headers: t.headers
170
170
  });
171
- }, ne = (t, e, s) => {
171
+ }, ue = (t, e, s) => {
172
172
  if (!t.body)
173
173
  return t;
174
- const r = se(s ?? t.body);
174
+ const r = ie(s ?? t.body);
175
175
  return new Request(t, {
176
176
  // @ts-expect-error - Types are outdated.
177
177
  duplex: "half",
178
- body: $(t.body, r, e)
178
+ body: z(t.body, r, e)
179
179
  });
180
- }, d = (t) => t !== null && typeof t == "object", T = (...t) => {
180
+ }, f = (t) => t !== null && typeof t == "object", b = (...t) => {
181
181
  for (const e of t)
182
- if ((!d(e) || Array.isArray(e)) && e !== void 0)
182
+ if ((!f(e) || Array.isArray(e)) && e !== void 0)
183
183
  throw new TypeError("The `options` argument must be an object");
184
- return N({}, ...t);
185
- }, _ = (t = {}, e = {}) => {
184
+ return j({}, ...t);
185
+ }, J = (t = {}, e = {}) => {
186
186
  const s = new globalThis.Headers(t), r = e instanceof globalThis.Headers, n = new globalThis.Headers(e);
187
187
  for (const [o, i] of n.entries())
188
188
  r && i === "undefined" || i === void 0 ? s.delete(o) : s.set(o, i);
189
189
  return s;
190
190
  };
191
- function R(t, e, s) {
192
- return Object.hasOwn(e, s) && e[s] === void 0 ? [] : N(t[s] ?? [], e[s] ?? []);
191
+ function T(t, e, s) {
192
+ return Object.hasOwn(e, s) && e[s] === void 0 ? [] : j(t[s] ?? [], e[s] ?? []);
193
193
  }
194
- const F = (t = {}, e = {}) => ({
195
- beforeRequest: R(t, e, "beforeRequest"),
196
- beforeRetry: R(t, e, "beforeRetry"),
197
- afterResponse: R(t, e, "afterResponse"),
198
- beforeError: R(t, e, "beforeError")
199
- }), oe = (t, e) => {
194
+ const K = (t = {}, e = {}) => ({
195
+ beforeRequest: T(t, e, "beforeRequest"),
196
+ beforeRetry: T(t, e, "beforeRetry"),
197
+ afterResponse: T(t, e, "afterResponse"),
198
+ beforeError: T(t, e, "beforeError")
199
+ }), ce = (t, e) => {
200
200
  const s = new URLSearchParams();
201
201
  for (const r of [t, e])
202
202
  if (r !== void 0)
@@ -209,7 +209,7 @@ const F = (t = {}, e = {}) => ({
209
209
  throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
210
210
  s.append(String(n[0]), String(n[1]));
211
211
  }
212
- else if (d(r))
212
+ else if (f(r))
213
213
  for (const [n, o] of Object.entries(r))
214
214
  o !== void 0 && s.append(n, String(o));
215
215
  else {
@@ -218,20 +218,20 @@ const F = (t = {}, e = {}) => ({
218
218
  s.append(o, i);
219
219
  }
220
220
  return s;
221
- }, N = (...t) => {
221
+ }, j = (...t) => {
222
222
  let e = {}, s = {}, r = {}, n;
223
223
  const o = [];
224
224
  for (const i of t)
225
225
  if (Array.isArray(i))
226
226
  Array.isArray(e) || (e = []), e = [...e, ...i];
227
- else if (d(i)) {
227
+ else if (f(i)) {
228
228
  for (let [u, a] of Object.entries(i)) {
229
229
  if (u === "signal" && a instanceof globalThis.AbortSignal) {
230
230
  o.push(a);
231
231
  continue;
232
232
  }
233
233
  if (u === "context") {
234
- if (a != null && (!d(a) || Array.isArray(a)))
234
+ if (a != null && (!f(a) || Array.isArray(a)))
235
235
  throw new TypeError("The `context` option must be an object");
236
236
  e = {
237
237
  ...e,
@@ -240,28 +240,28 @@ const F = (t = {}, e = {}) => ({
240
240
  continue;
241
241
  }
242
242
  if (u === "searchParams") {
243
- a == null ? n = void 0 : n = n === void 0 ? a : oe(n, a);
243
+ a == null ? n = void 0 : n = n === void 0 ? a : ce(n, a);
244
244
  continue;
245
245
  }
246
- d(a) && u in e && (a = N(e[u], a)), e = { ...e, [u]: a };
246
+ f(a) && u in e && (a = j(e[u], a)), e = { ...e, [u]: a };
247
247
  }
248
- d(i.hooks) && (r = F(r, i.hooks), e.hooks = r), d(i.headers) && (s = _(s, i.headers), e.headers = s);
248
+ f(i.hooks) && (r = K(r, i.hooks), e.hooks = r), f(i.headers) && (s = J(s, i.headers), e.headers = s);
249
249
  }
250
- return n !== void 0 && (e.searchParams = n), o.length > 0 && (o.length === 1 ? e.signal = o[0] : M ? e.signal = AbortSignal.any(o) : e.signal = o.at(-1)), e.context === void 0 && (e.context = {}), e;
251
- }, ie = (t) => B.includes(t) ? t.toUpperCase() : t, ae = ["get", "put", "head", "delete", "options", "trace"], ue = [408, 413, 429, 500, 502, 503, 504], ce = [413, 429, 503], U = {
250
+ return n !== void 0 && (e.searchParams = n), o.length > 0 && (o.length === 1 ? e.signal = o[0] : H ? e.signal = AbortSignal.any(o) : e.signal = o.at(-1)), e.context === void 0 && (e.context = {}), e;
251
+ }, he = (t) => _.includes(t) ? t.toUpperCase() : t, le = ["get", "put", "head", "delete", "options", "trace"], fe = [408, 413, 429, 500, 502, 503, 504], de = [413, 429, 503], L = {
252
252
  limit: 2,
253
- methods: ae,
254
- statusCodes: ue,
255
- afterStatusCodes: ce,
253
+ methods: le,
254
+ statusCodes: fe,
255
+ afterStatusCodes: de,
256
256
  maxRetryAfter: Number.POSITIVE_INFINITY,
257
257
  backoffLimit: Number.POSITIVE_INFINITY,
258
258
  delay: (t) => 0.3 * 2 ** (t - 1) * 1e3,
259
259
  jitter: void 0,
260
260
  retryOnTimeout: !1
261
- }, le = (t = {}) => {
261
+ }, pe = (t = {}) => {
262
262
  if (typeof t == "number")
263
263
  return {
264
- ...U,
264
+ ...L,
265
265
  limit: t
266
266
  };
267
267
  if (t.methods && !Array.isArray(t.methods))
@@ -269,27 +269,27 @@ const F = (t = {}, e = {}) => ({
269
269
  if (t.statusCodes && !Array.isArray(t.statusCodes))
270
270
  throw new Error("retry.statusCodes must be an array");
271
271
  return {
272
- ...U,
272
+ ...L,
273
273
  ...t
274
274
  };
275
275
  };
276
- class x extends Error {
276
+ class P extends Error {
277
277
  request;
278
278
  constructor(e) {
279
279
  super(`Request timed out: ${e.method} ${e.url}`), this.name = "TimeoutError", this.request = e;
280
280
  }
281
281
  }
282
- async function he(t, e, s, r) {
282
+ async function ye(t, e, s, r) {
283
283
  return new Promise((n, o) => {
284
284
  const i = setTimeout(() => {
285
- s && s.abort(), o(new x(t));
285
+ s && s.abort(), o(new P(t));
286
286
  }, r.timeout);
287
287
  r.fetch(t, e).then(n).catch(o).then(() => {
288
288
  clearTimeout(i);
289
289
  });
290
290
  });
291
291
  }
292
- async function fe(t, { signal: e }) {
292
+ async function ge(t, { signal: e }) {
293
293
  return new Promise((s, r) => {
294
294
  e && (e.throwIfAborted(), e.addEventListener("abort", n, { once: !0 }));
295
295
  function n() {
@@ -300,35 +300,35 @@ async function fe(t, { signal: e }) {
300
300
  }, t);
301
301
  });
302
302
  }
303
- const de = (t, e) => {
303
+ const me = (t, e) => {
304
304
  const s = {};
305
305
  for (const r in e)
306
- Object.hasOwn(e, r) && !(r in te) && !(r in Q) && (!(r in t) || r in ee) && (s[r] = e[r]);
306
+ Object.hasOwn(e, r) && !(r in oe) && !(r in re) && (!(r in t) || r in ne) && (s[r] = e[r]);
307
307
  return s;
308
- }, pe = (t) => t === void 0 ? !1 : Array.isArray(t) ? t.length > 0 : t instanceof URLSearchParams ? t.size > 0 : typeof t == "object" ? Object.keys(t).length > 0 : typeof t == "string" ? t.trim().length > 0 : !!t;
309
- function ye(t) {
310
- return t instanceof P || t?.name === P.name;
308
+ }, we = (t) => t === void 0 ? !1 : Array.isArray(t) ? t.length > 0 : t instanceof URLSearchParams ? t.size > 0 : typeof t == "object" ? Object.keys(t).length > 0 : typeof t == "string" ? t.trim().length > 0 : !!t;
309
+ function be(t) {
310
+ return t instanceof C || t?.name === C.name;
311
311
  }
312
- function me(t) {
313
- return t instanceof x || t?.name === x.name;
312
+ function Te(t) {
313
+ return t instanceof P || t?.name === P.name;
314
314
  }
315
- class m {
315
+ class p {
316
316
  static create(e, s) {
317
- const r = new m(e, s), n = async () => {
318
- if (typeof r.#e.timeout == "number" && r.#e.timeout > C)
319
- throw new RangeError(`The \`timeout\` option cannot be greater than ${C}`);
317
+ const r = new p(e, s), n = async () => {
318
+ if (typeof r.#e.timeout == "number" && r.#e.timeout > A)
319
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${A}`);
320
320
  await Promise.resolve();
321
321
  let i = await r.#y();
322
322
  for (const u of r.#e.hooks.afterResponse) {
323
- const a = r.#l(i.clone()), h = await u(r.request, r.#a(), a, { retryCount: r.#s });
324
- if (h instanceof globalThis.Response && (i = h), h instanceof H)
323
+ const a = r.#h(i.clone()), l = await u(r.request, r.#a(), a, { retryCount: r.#s });
324
+ if (l instanceof globalThis.Response && (i = l), l instanceof F)
325
325
  throw await Promise.all([
326
326
  a.body?.cancel(),
327
327
  i.body?.cancel()
328
- ]), new A(h.options);
328
+ ]), new S(l.options);
329
329
  }
330
- if (r.#l(i), !i.ok && (typeof r.#e.throwHttpErrors == "function" ? r.#e.throwHttpErrors(i.status) : r.#e.throwHttpErrors)) {
331
- let u = new P(i, r.request, r.#a());
330
+ if (r.#h(i), !i.ok && (typeof r.#e.throwHttpErrors == "function" ? r.#e.throwHttpErrors(i.status) : r.#e.throwHttpErrors)) {
331
+ let u = new C(i, r.request, r.#a());
332
332
  for (const a of r.#e.hooks.beforeError)
333
333
  u = await a(u, { retryCount: r.#s });
334
334
  throw u;
@@ -336,24 +336,24 @@ class m {
336
336
  if (r.#e.onDownloadProgress) {
337
337
  if (typeof r.#e.onDownloadProgress != "function")
338
338
  throw new TypeError("The `onDownloadProgress` option must be a function");
339
- if (!W)
339
+ if (!Y)
340
340
  throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
341
- return re(i.clone(), r.#e.onDownloadProgress);
341
+ return ae(i.clone(), r.#e.onDownloadProgress);
342
342
  }
343
343
  return i;
344
- }, o = r.#h(n).finally(async () => {
344
+ }, o = r.#l(n).finally(async () => {
345
345
  const i = r.#o, u = [];
346
346
  i && !i.bodyUsed && u.push(i.body?.cancel()), r.request.bodyUsed || u.push(r.request.body?.cancel()), await Promise.all(u);
347
347
  });
348
- for (const [i, u] of Object.entries(X))
348
+ for (const [i, u] of Object.entries(ee))
349
349
  i === "bytes" && typeof globalThis.Response?.prototype?.bytes != "function" || (o[i] = async () => {
350
350
  r.request.headers.set("accept", r.request.headers.get("accept") || u);
351
351
  const a = await o;
352
352
  if (i === "json") {
353
353
  if (a.status === 204)
354
354
  return "";
355
- const h = await a.text();
356
- return h === "" ? "" : s.parseJson ? s.parseJson(h) : JSON.parse(h);
355
+ const l = await a.text();
356
+ return l === "" ? "" : s.parseJson ? s.parseJson(l) : JSON.parse(l);
357
357
  }
358
358
  return a[i]();
359
359
  });
@@ -376,17 +376,17 @@ class m {
376
376
  constructor(e, s = {}) {
377
377
  if (this.#t = e, this.#e = {
378
378
  ...s,
379
- headers: _(this.#t.headers, s.headers),
380
- hooks: F({
379
+ headers: J(this.#t.headers, s.headers),
380
+ hooks: K({
381
381
  beforeRequest: [],
382
382
  beforeRetry: [],
383
383
  beforeError: [],
384
384
  afterResponse: []
385
385
  }, s.hooks),
386
- method: ie(s.method ?? this.#t.method ?? "GET"),
386
+ method: he(s.method ?? this.#t.method ?? "GET"),
387
387
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
388
388
  prefixUrl: String(s.prefixUrl || ""),
389
- retry: le(s.retry),
389
+ retry: pe(s.retry),
390
390
  throwHttpErrors: s.throwHttpErrors ?? !0,
391
391
  timeout: s.timeout ?? 1e4,
392
392
  fetch: s.fetch ?? globalThis.fetch.bind(globalThis),
@@ -398,16 +398,16 @@ class m {
398
398
  throw new Error("`input` must not begin with a slash when using `prefixUrl`");
399
399
  this.#e.prefixUrl.endsWith("/") || (this.#e.prefixUrl += "/"), this.#t = this.#e.prefixUrl + this.#t;
400
400
  }
401
- V && M && (this.#n = this.#e.signal ?? this.#t.signal, this.#r = new globalThis.AbortController(), this.#e.signal = this.#n ? AbortSignal.any([this.#n, this.#r.signal]) : this.#r.signal), v && (this.#e.duplex = "half"), this.#e.json !== void 0 && (this.#e.body = this.#e.stringifyJson?.(this.#e.json) ?? JSON.stringify(this.#e.json), this.#e.headers.set("content-type", this.#e.headers.get("content-type") ?? "application/json"));
401
+ Z && H && (this.#n = this.#e.signal ?? this.#t.signal, this.#r = new globalThis.AbortController(), this.#e.signal = this.#n ? AbortSignal.any([this.#n, this.#r.signal]) : this.#r.signal), I && (this.#e.duplex = "half"), this.#e.json !== void 0 && (this.#e.body = this.#e.stringifyJson?.(this.#e.json) ?? JSON.stringify(this.#e.json), this.#e.headers.set("content-type", this.#e.headers.get("content-type") ?? "application/json"));
402
402
  const r = s.headers && new globalThis.Headers(s.headers).has("content-type");
403
- if (this.#t instanceof globalThis.Request && (G && this.#e.body instanceof globalThis.FormData || this.#e.body instanceof URLSearchParams) && !r && this.#e.headers.delete("content-type"), this.request = new globalThis.Request(this.#t, this.#e), pe(this.#e.searchParams)) {
404
- const o = "?" + (typeof this.#e.searchParams == "string" ? this.#e.searchParams.replace(/^\?/, "") : new URLSearchParams(m.#d(this.#e.searchParams)).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, o);
403
+ if (this.#t instanceof globalThis.Request && (Q && this.#e.body instanceof globalThis.FormData || this.#e.body instanceof URLSearchParams) && !r && this.#e.headers.delete("content-type"), this.request = new globalThis.Request(this.#t, this.#e), we(this.#e.searchParams)) {
404
+ const o = "?" + (typeof this.#e.searchParams == "string" ? this.#e.searchParams.replace(/^\?/, "") : new URLSearchParams(p.#d(this.#e.searchParams)).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, o);
405
405
  this.request = new globalThis.Request(i, this.#e);
406
406
  }
407
407
  if (this.#e.onUploadProgress) {
408
408
  if (typeof this.#e.onUploadProgress != "function")
409
409
  throw new TypeError("The `onUploadProgress` option must be a function");
410
- if (!v)
410
+ if (!I)
411
411
  throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
412
412
  this.request = this.#f(this.request, this.#e.body ?? void 0);
413
413
  }
@@ -420,8 +420,8 @@ class m {
420
420
  async #p(e) {
421
421
  if (this.#s++, this.#s > this.#e.retry.limit)
422
422
  throw e;
423
- const s = e instanceof Error ? e : new L(e);
424
- if (s instanceof A)
423
+ const s = e instanceof Error ? e : new D(e);
424
+ if (s instanceof S)
425
425
  return s.customDelay ?? this.#u();
426
426
  if (!this.#e.retry.methods.includes(this.request.method.toLowerCase()))
427
427
  throw e;
@@ -432,9 +432,9 @@ class m {
432
432
  if (r === !0)
433
433
  return this.#u();
434
434
  }
435
- if (me(e) && !this.#e.retry.retryOnTimeout)
435
+ if (Te(e) && !this.#e.retry.retryOnTimeout)
436
436
  throw e;
437
- if (ye(e)) {
437
+ if (be(e)) {
438
438
  if (!this.#e.retry.statusCodes.includes(e.response.status))
439
439
  throw e;
440
440
  const r = e.response.headers.get("Retry-After") ?? e.response.headers.get("RateLimit-Reset") ?? e.response.headers.get("X-RateLimit-Retry-After") ?? e.response.headers.get("X-RateLimit-Reset") ?? e.response.headers.get("X-Rate-Limit-Reset");
@@ -449,17 +449,17 @@ class m {
449
449
  }
450
450
  return this.#u();
451
451
  }
452
- #l(e) {
452
+ #h(e) {
453
453
  return this.#e.parseJson && (e.json = async () => this.#e.parseJson(await e.text())), e;
454
454
  }
455
- async #h(e) {
455
+ async #l(e) {
456
456
  try {
457
457
  return await e();
458
458
  } catch (s) {
459
- const r = Math.min(await this.#p(s), C);
459
+ const r = Math.min(await this.#p(s), A);
460
460
  if (this.#s < 1)
461
461
  throw s;
462
- if (await fe(r, this.#n ? { signal: this.#n } : {}), s instanceof A && s.customRequest) {
462
+ if (await ge(r, this.#n ? { signal: this.#n } : {}), s instanceof S && s.customRequest) {
463
463
  const n = this.#e.signal ? new globalThis.Request(s.customRequest, { signal: this.#e.signal }) : new globalThis.Request(s.customRequest);
464
464
  this.#c(n);
465
465
  }
@@ -476,10 +476,10 @@ class m {
476
476
  }
477
477
  if (o instanceof globalThis.Response)
478
478
  return o;
479
- if (o === D)
479
+ if (o === $)
480
480
  return;
481
481
  }
482
- return this.#h(e);
482
+ return this.#l(e);
483
483
  }
484
484
  }
485
485
  async #y() {
@@ -493,8 +493,8 @@ class m {
493
493
  break;
494
494
  }
495
495
  }
496
- const e = de(this.request, this.#e);
497
- return this.#o = this.request, this.request = this.#o.clone(), this.#e.timeout === !1 ? this.#e.fetch(this.#o, e) : he(this.#o, e, this.#r, this.#e);
496
+ const e = me(this.request, this.#e);
497
+ return this.#o = this.request, this.request = this.#o.clone(), this.#e.timeout === !1 ? this.#e.fetch(this.#o, e) : ye(this.#o, e, this.#r, this.#e);
498
498
  }
499
499
  #a() {
500
500
  if (!this.#i) {
@@ -507,20 +507,20 @@ class m {
507
507
  this.#i = void 0, this.request = this.#f(e);
508
508
  }
509
509
  #f(e, s) {
510
- return !this.#e.onUploadProgress || !e.body ? e : ne(e, this.#e.onUploadProgress, s ?? this.#e.body ?? void 0);
510
+ return !this.#e.onUploadProgress || !e.body ? e : ue(e, this.#e.onUploadProgress, s ?? this.#e.body ?? void 0);
511
511
  }
512
512
  }
513
513
  /*! MIT License © Sindre Sorhus */
514
- const q = (t) => {
515
- const e = (s, r) => m.create(s, T(t, r));
516
- for (const s of B)
517
- e[s] = (r, n) => m.create(r, T(t, n, { method: s }));
518
- return e.create = (s) => q(T(s)), e.extend = (s) => (typeof s == "function" && (s = s(t ?? {})), q(T(t, s))), e.stop = D, e.retry = Y, e;
519
- }, ge = q();
520
- var we = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.BSC = "BSC_MAINNET", t.ETHEREUM = "ETHEREUM_MAINNET", t.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", t.STARKNET = "STARKNET_MAINNET", t))(we || {}), be = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(be || {}), z = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(z || {});
514
+ const x = (t) => {
515
+ const e = (s, r) => p.create(s, b(t, r));
516
+ for (const s of _)
517
+ e[s] = (r, n) => p.create(r, b(t, n, { method: s }));
518
+ return e.create = (s) => x(b(s)), e.extend = (s) => (typeof s == "function" && (s = s(t ?? {})), x(b(t, s))), e.stop = $, e.retry = se, e;
519
+ }, Re = x();
520
+ var Ee = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.BSC = "BSC_MAINNET", t.ETHEREUM = "ETHEREUM_MAINNET", t.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", t.STARKNET = "STARKNET_MAINNET", t))(Ee || {}), Se = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(Se || {}), N = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(N || {});
521
521
  class c {
522
522
  constructor({ api_key: e, env: s }) {
523
- this.api_key = e, this.env = s ?? z.PRODUCTION;
523
+ this.api_key = e, this.jwt = "", this.env = s ?? N.PRODUCTION;
524
524
  }
525
525
  static config(e) {
526
526
  if (!c.app) {
@@ -528,27 +528,35 @@ class c {
528
528
  throw new Error("Please provide an api_key");
529
529
  c.app = new c(e);
530
530
  }
531
- return e && (c.app.api_key = e.api_key, e.env !== void 0 && (c.app.env = e.env)), c.app;
531
+ return e && (c.app.api_key = e.api_key, e.env !== void 0 && (c.app.env = e.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), c.app;
532
+ }
533
+ static async updateJWT() {
534
+ try {
535
+ const e = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
536
+ body: JSON.stringify({
537
+ apiKey: c.app.api_key
538
+ })
539
+ })).json();
540
+ this.app.jwt = e.token;
541
+ } catch {
542
+ }
532
543
  }
533
544
  static getApiKey() {
534
545
  if (!c.app)
535
- throw new Error(
536
- "Chainrails SDK not configured. Please call Chainrails.config() first."
537
- );
546
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
538
547
  return c.app.api_key;
539
548
  }
549
+ static getSessionKey() {
550
+ return c.app.jwt;
551
+ }
540
552
  static getEnv() {
541
553
  if (!c.app)
542
- throw new Error(
543
- "Chainrails SDK not configured. Please call Chainrails.config() first."
544
- );
554
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
545
555
  return c.app.env;
546
556
  }
547
557
  static getBaseUrl() {
548
558
  if (!c.app)
549
- throw new Error(
550
- "Chainrails SDK not configured. Please call Chainrails.config() first."
551
- );
559
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
552
560
  switch (c.app.env) {
553
561
  case "production":
554
562
  return "https://api.chainrails.io/api/v1";
@@ -559,9 +567,9 @@ class c {
559
567
  }
560
568
  }
561
569
  }
562
- let j = null;
563
- function Te() {
564
- j = ge.create({
570
+ let q = null;
571
+ function Ae() {
572
+ q = Re.create({
565
573
  prefixUrl: c.getBaseUrl(),
566
574
  headers: {
567
575
  "Content-Type": "application/json"
@@ -569,7 +577,7 @@ function Te() {
569
577
  hooks: {
570
578
  beforeRequest: [
571
579
  (t) => {
572
- const e = c.getApiKey();
580
+ const e = c.getSessionKey();
573
581
  t.headers.set("Authorization", `Bearer ${e}`);
574
582
  }
575
583
  ],
@@ -580,78 +588,78 @@ function Te() {
580
588
  }
581
589
  });
582
590
  }
583
- function l() {
584
- return j || Te(), j;
591
+ function h() {
592
+ return q || Ae(), q;
585
593
  }
586
- class Re {
594
+ class Ce {
587
595
  async getById(e) {
588
- return await l().get("intents/" + e).json();
596
+ return await h().get("intents/" + e).json();
589
597
  }
590
598
  async getForSender(e) {
591
- return await l().get("intents/user/" + e).json();
599
+ return await h().get("intents/user/" + e).json();
592
600
  }
593
601
  async getForAddress(e) {
594
- return await l().get("intents/address/" + e).json();
602
+ return await h().get("intents/address/" + e).json();
595
603
  }
596
604
  async getAll(e) {
597
- return await l().get("intents", { searchParams: e }).json();
605
+ return await h().get("intents", { searchParams: e }).json();
598
606
  }
599
607
  async create(e) {
600
- return await l().post("intents", { json: e }).json();
608
+ return await h().post("intents", { json: e }).json();
601
609
  }
602
610
  async update(e, s) {
603
- return await l().post("intents", { json: s }).json();
611
+ return await h().post("intents", { json: s }).json();
604
612
  }
605
613
  async triggerProcessing(e) {
606
- return await l().post(`intents/${e}/trigger-processing`).json();
614
+ return await h().post(`intents/${e}/trigger-processing`).json();
607
615
  }
608
616
  }
609
- class Ee {
617
+ class Pe {
610
618
  async getFromSpecificBridge(e) {
611
- return await l().get("quotes/single", { searchParams: e }).json();
619
+ return await h().get("quotes/single", { searchParams: e }).json();
612
620
  }
613
621
  async getFromAllBridges(e) {
614
- return await l().get("quotes/multiple", { searchParams: e }).json();
622
+ return await h().get("quotes/multiple", { searchParams: e }).json();
615
623
  }
616
624
  async getBestAcrossBridges(e) {
617
- return await l().get("quotes/best", { searchParams: e }).json();
625
+ return await h().get("quotes/best", { searchParams: e }).json();
618
626
  }
619
627
  async getAll(e) {
620
- return await l().get("quotes/multi-source", { searchParams: e }).json();
628
+ return await h().get("quotes/multi-source", { searchParams: e }).json();
621
629
  }
622
630
  }
623
- class Se {
631
+ class xe {
624
632
  async getOptimalRoutes(e) {
625
- return await l().get("router/optimal-route", { searchParams: e }).json();
633
+ return await h().get("router/optimal-route", { searchParams: e }).json();
626
634
  }
627
635
  async getAllSupportedBridges() {
628
- return await l().get("router/supported-bridges/all").json();
636
+ return await h().get("router/supported-bridges/all").json();
629
637
  }
630
638
  async getSupportedBridges(e) {
631
- return await l().get("router/supported-bridges/route", { searchParams: e }).json();
639
+ return await h().get("router/supported-bridges/route", { searchParams: e }).json();
632
640
  }
633
641
  async getSupportedRoutes(e, s) {
634
- return await l().get("router/supported-bridges/bridge/" + e, { searchParams: s }).json();
642
+ return await h().get("router/supported-bridges/bridge/" + e, { searchParams: s }).json();
635
643
  }
636
644
  }
637
- class Ae {
645
+ class qe {
638
646
  async getSupported(e) {
639
- return await l().get("chains", { searchParams: e }).json();
647
+ return await h().get("chains", { searchParams: e }).json();
640
648
  }
641
649
  }
642
- class Ce {
650
+ class je {
643
651
  async getClientInfo() {
644
- return await l().get("client/auth/client-info").json();
652
+ return await h().get("client/auth/client-info").json();
645
653
  }
646
654
  }
647
- const qe = {
648
- router: new Se(),
649
- quotes: new Ee(),
650
- intents: new Re(),
651
- chains: new Ae(),
652
- client: new Ce()
655
+ const ve = {
656
+ router: new xe(),
657
+ quotes: new Pe(),
658
+ intents: new Ce(),
659
+ chains: new qe(),
660
+ client: new je()
653
661
  };
654
- function je(t) {
662
+ function Ue(t) {
655
663
  const {
656
664
  to: e,
657
665
  token: s,
@@ -661,96 +669,103 @@ function je(t) {
661
669
  close: i,
662
670
  complete: u,
663
671
  cancel: a,
664
- chainSelected: h,
665
- intentCreated: g,
666
- ...E
667
- } = t, [y, S] = O(!0);
668
- return J(() => {
669
- const w = document.body.style.overflow;
670
- o ? document.body.style.overflow = "hidden" : document.body.style.overflow = w || "";
671
- const p = (f) => {
672
- f.data === "closed" && a(), f.data === "completed" && u(), f.data === "chainSelected" && h(), f.data === "intentCreated" && g();
672
+ chainSelected: l,
673
+ intentCreated: y,
674
+ ...R
675
+ } = t, [d, E] = M(!0), k = W(null);
676
+ G(() => {
677
+ v();
678
+ const g = document.body.style.overflow;
679
+ o ? (document.body.style.overflow = "hidden", document.body.style.overflow = "hidden") : document.body.style.overflow = g || "";
680
+ const U = (m) => {
681
+ m.data === "closed" && a(), m.data === "completed" && u(), m.data === "chainSelected" && l(), m.data === "intentCreated" && y();
673
682
  };
674
- return window.addEventListener("message", p), () => {
675
- document.body.style.overflow = w || "", window.removeEventListener("message", p);
683
+ return window.addEventListener("message", U), () => {
684
+ document.body.style.overflow = g || "", window.removeEventListener("message", U);
676
685
  };
677
- }, [o, a, u, h, g]), /* @__PURE__ */ k("div", {
678
- ...E,
679
- className: K("payment-modal-wrapper", y ? "loading" : "not-loading", o ? "open" : "closed"),
680
- children: [y && /* @__PURE__ */ b("div", {
686
+ }, [o, a, u, l, y]);
687
+ function V() {
688
+ E(!1), v();
689
+ }
690
+ function v() {
691
+ const g = {
692
+ type: "sessionKey",
693
+ sessionKey: c.getSessionKey(),
694
+ environment: c.getEnv() || N.PRODUCTION
695
+ };
696
+ k.current?.contentWindow?.postMessage(g, "https://app.chainrails.io");
697
+ }
698
+ return /* @__PURE__ */ O("div", {
699
+ ...R,
700
+ className: X("payment-modal-wrapper", d ? "loading" : "not-loading", o ? "open" : "closed"),
701
+ children: [d && /* @__PURE__ */ w("div", {
681
702
  role: "status",
682
703
  className: "payment-modal-loader",
683
- children: /* @__PURE__ */ k("svg", {
704
+ children: /* @__PURE__ */ O("svg", {
684
705
  "aria-hidden": "true",
685
706
  className: "icon",
686
707
  viewBox: "0 0 100 101",
687
708
  fill: "none",
688
709
  xmlns: "http://www.w3.org/2000/svg",
689
- children: [/* @__PURE__ */ b("path", {
710
+ children: [/* @__PURE__ */ w("path", {
690
711
  d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
691
712
  fill: "currentColor"
692
- }), /* @__PURE__ */ b("path", {
713
+ }), /* @__PURE__ */ w("path", {
693
714
  d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
694
715
  fill: "currentFill"
695
716
  })]
696
717
  })
697
- }), /* @__PURE__ */ b("iframe", {
718
+ }), /* @__PURE__ */ w("iframe", {
698
719
  allow: "clipboard-read *; clipboard-write *",
699
- src: (() => {
700
- const w = `https://app.chainrails.io/pay/_chain_/${encodeURIComponent(r)}/_token_/${encodeURIComponent(s)}/_to_/${encodeURIComponent(e)}/_amount_/${n * 100}`, p = new URLSearchParams();
701
- p.append("id", c.getApiKey());
702
- const f = c.getEnv();
703
- return f !== "production" && p.append("env", f), `${w}?${p.toString()}`;
704
- })(),
705
- onLoad: () => {
706
- S(!1);
707
- },
708
- className: `payment-modal ${y ? "invisible" : "visible"}`
720
+ src: `https://app.chainrails.io/pay/_chain_/${r}/_token_/${s}/_to_/${e}/_amount_/${n * 100}`,
721
+ onLoad: V,
722
+ className: `payment-modal ${d ? "invisible" : "visible"}`,
723
+ ref: k
709
724
  })]
710
725
  });
711
726
  }
712
- function Ne(t) {
727
+ function Oe(t) {
713
728
  const {
714
729
  onCancel: e,
715
730
  onSuccess: s,
716
731
  onChainSelect: r,
717
732
  onIntentCreate: n,
718
733
  ...o
719
- } = t, [i, u] = O(!1);
734
+ } = t, [i, u] = M(!1);
720
735
  function a() {
721
736
  u(!0);
722
737
  }
723
- function h() {
738
+ function l() {
724
739
  u(!1);
725
740
  }
726
- function g() {
727
- h(), e?.();
741
+ function y() {
742
+ l(), e?.();
728
743
  }
729
- function E() {
730
- window.setTimeout(h, 2e3), s?.();
744
+ function R() {
745
+ window.setTimeout(l, 2e3), s?.();
731
746
  }
732
- function y() {
747
+ function d() {
733
748
  r?.();
734
749
  }
735
- function S() {
750
+ function E() {
736
751
  n?.();
737
752
  }
738
753
  return {
739
754
  open: a,
740
- close: h,
741
- complete: E,
742
- cancel: g,
743
- chainSelected: y,
744
- intentCreated: S,
755
+ close: l,
756
+ complete: R,
757
+ cancel: y,
758
+ chainSelected: d,
759
+ intentCreated: E,
745
760
  isOpen: i,
746
761
  ...o
747
762
  };
748
763
  }
749
764
  export {
750
765
  c as Chainrails,
751
- je as PaymentModal,
752
- we as chains,
753
- qe as crapi,
754
- be as tokens,
755
- Ne as usePaymentModal
766
+ Ue as PaymentModal,
767
+ Ee as chains,
768
+ ve as crapi,
769
+ Se as tokens,
770
+ Oe as usePaymentModal
756
771
  };