@openrails/billing-ui 0.237.0 → 0.239.0

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.
@@ -88,7 +88,49 @@ var s = {
88
88
  USDG: 6,
89
89
  USDT: 6,
90
90
  ZAR: 6
91
- }, c = e.object({
91
+ };
92
+ //#endregion
93
+ //#region src/client/token-source.ts
94
+ function c({ fetchToken: e, skew: t = 60 }) {
95
+ let n, r, a = () => n && Date.now() < n.staleAt ? Promise.resolve(n.token) : (r ??= e().then((e) => {
96
+ if (typeof e?.access_token != "string" || !e.access_token || !Number.isFinite(e.expires_in)) throw i("invalid_response", "fetchToken answered no access_token and expires_in");
97
+ return n = {
98
+ token: e.access_token,
99
+ staleAt: Date.now() + (e.expires_in - t) * 1e3
100
+ }, e.access_token;
101
+ }).finally(() => {
102
+ r = void 0;
103
+ }), r);
104
+ return a.invalidate = (e) => {
105
+ (e === void 0 || n?.token === e) && (n = void 0);
106
+ }, a;
107
+ }
108
+ var ee = (e) => typeof e == "function" && typeof e.invalidate == "function";
109
+ async function l(e) {
110
+ let t = await (e.fetch ?? ((e, t) => fetch(e, t)))(e.tokenEndpoint, {
111
+ method: "POST",
112
+ headers: {
113
+ Accept: "application/json",
114
+ "Content-Type": "application/x-www-form-urlencoded"
115
+ },
116
+ body: new URLSearchParams({
117
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
118
+ assertion: e.assertion,
119
+ scope: "openrails:self"
120
+ }).toString()
121
+ });
122
+ if (!t.ok) throw await a(t);
123
+ let n = await t.json().catch(() => null);
124
+ if (typeof n?.access_token != "string" || typeof n.expires_in != "number") throw i("invalid_response", "the token endpoint answered no access_token and expires_in");
125
+ return {
126
+ access_token: n.access_token,
127
+ expires_in: n.expires_in,
128
+ token_type: typeof n.token_type == "string" ? n.token_type : "Bearer"
129
+ };
130
+ }
131
+ //#endregion
132
+ //#region src/psp.ts
133
+ var u = e.object({
92
134
  psp_id: e.string().min(1),
93
135
  key: e.string().min(1),
94
136
  rail: e.string(),
@@ -99,41 +141,41 @@ var s = {
99
141
  checkout: e.boolean().nullish(),
100
142
  status: e.string().nullish(),
101
143
  retry_after: e.number().int().nullish()
102
- }), l = (e) => e.filter((e) => e.checkout !== !1), u = /* @__PURE__ */ new Set([
144
+ }), d = (e) => e.filter((e) => e.checkout !== !1), f = /* @__PURE__ */ new Set([
103
145
  "tokenize",
104
146
  "card",
105
147
  "elements"
106
148
  ]);
107
- function d(e) {
108
- let t = e.filter((e) => !!e.status && e.custodian === "psp" && u.has(e.flow)).map((e) => e.retry_after ?? 30);
149
+ function p(e) {
150
+ let t = e.filter((e) => !!e.status && e.custodian === "psp" && f.has(e.flow)).map((e) => e.retry_after ?? 30);
109
151
  return t.length > 0 ? Math.min(...t) : null;
110
152
  }
111
- var f = (e) => !!e && !e.startsWith("preview_"), p = (e) => e.rail === "stripe" && !!e.config?.publishable_key?.startsWith("pk_");
112
- function m(e) {
113
- return e.custodian !== "psp" || e.status ? null : e.flow === "card" && e.rail === "nmi" ? "card" : e.flow === "tokenize" && f(e.config?.tokenization_key) && e.config?.tokenization_url ? "collect_js" : p(e) ? "stripe_elements" : null;
153
+ var m = (e) => !!e && !e.startsWith("preview_"), h = (e) => e.rail === "stripe" && !!e.config?.publishable_key?.startsWith("pk_");
154
+ function g(e) {
155
+ return e.custodian !== "psp" || e.status ? null : e.flow === "card" && e.rail === "nmi" ? "card" : e.flow === "tokenize" && m(e.config?.tokenization_key) && e.config?.tokenization_url ? "collect_js" : h(e) ? "stripe_elements" : null;
114
156
  }
115
- var h = (e) => m(e) !== null, g = (e) => m(e) === "stripe_elements", _ = -(1n << 63n), v = (1n << 63n) - 1n;
116
- function y(e) {
157
+ var _ = (e) => g(e) !== null, v = (e) => g(e) === "stripe_elements", y = -(1n << 63n), b = (1n << 63n) - 1n;
158
+ function x(e) {
117
159
  if (typeof e != "string" || !/^-?\d{1,19}$/.test(e)) return null;
118
160
  let t = BigInt(e);
119
- return t < _ || t > v ? null : t;
161
+ return t < y || t > b ? null : t;
120
162
  }
121
- function b(e) {
122
- return y(e) !== null;
163
+ function S(e) {
164
+ return x(e) !== null;
123
165
  }
124
- function x(e) {
166
+ function C(e) {
125
167
  return typeof e == "number" && Number.isInteger(e) && e >= 0 && e <= 18;
126
168
  }
127
- function S(...e) {
169
+ function te(...e) {
128
170
  let t = 0n;
129
171
  for (let n of e) {
130
- let e = y(n);
172
+ let e = x(n);
131
173
  if (e === null) return null;
132
174
  t += e;
133
175
  }
134
- return t < _ || t > v ? null : t.toString();
176
+ return t < y || t > b ? null : t.toString();
135
177
  }
136
- var C = (() => {
178
+ var ne = (() => {
137
179
  try {
138
180
  return new Intl.NumberFormat("en", { useGrouping: !1 }).format("9007199254740993") === "9007199254740993";
139
181
  } catch {
@@ -144,31 +186,31 @@ function T(e, t) {
144
186
  let n = e < 0n ? -e : e, r = 10n ** BigInt(t), i = (n % r).toString().padStart(t, "0").replace(/0+$/, "");
145
187
  return `${e < 0n ? "-" : ""}${n / r}${i ? `.${i}` : ""}`;
146
188
  }
147
- function E(e, t) {
148
- let n = y(e);
149
- return n === null || !x(t) ? null : T(n, t);
189
+ function re(e, t) {
190
+ let n = x(e);
191
+ return n === null || !C(t) ? null : T(n, t);
150
192
  }
151
- function ee(e, t, n) {
152
- let r = y(e);
153
- if (r === null || !x(t) || !x(n) || n > t) return null;
193
+ function E(e, t, n) {
194
+ let r = x(e);
195
+ if (r === null || !C(t) || !C(n) || n > t) return null;
154
196
  let i = 10n ** BigInt(t - n);
155
197
  if (r % i !== 0n) return null;
156
198
  let a = r / i;
157
199
  return a > BigInt(2 ** 53 - 1) || a < -BigInt(2 ** 53 - 1) ? null : Number(a);
158
200
  }
159
- function te(e, t) {
160
- if (!x(t) || e.length > 40) return null;
201
+ function ie(e, t) {
202
+ if (!C(t) || e.length > 40) return null;
161
203
  let n = /^(-?)(\d+)(?:\.(\d+))?$/.exec(e);
162
204
  if (!n) return null;
163
205
  let r = n[3] ?? "";
164
206
  if (r.length > t) return null;
165
207
  let i = BigInt(n[2]) * 10n ** BigInt(t) + BigInt(r.padEnd(t, "0") || "0"), a = n[1] ? -i : i;
166
- return a < _ || a > v ? null : a.toString();
208
+ return a < y || a > b ? null : a.toString();
167
209
  }
168
- function ne(e, t, n, r) {
169
- let i = t.trim().toUpperCase(), a = y(e);
170
- if (a === null || !x(n)) return `${i} amount exceeds the exact display range`;
171
- if (!C && (a >= w || a <= -w)) return `${i} amount exceeds this browser's exact display range`;
210
+ function ae(e, t, n, r) {
211
+ let i = t.trim().toUpperCase(), a = x(e);
212
+ if (a === null || !C(n)) return `${i} amount exceeds the exact display range`;
213
+ if (!ne && (a >= w || a <= -w)) return `${i} amount exceeds this browser's exact display range`;
172
214
  let o = T(a, n);
173
215
  try {
174
216
  return new Intl.NumberFormat(r, {
@@ -182,7 +224,7 @@ function ne(e, t, n, r) {
182
224
  }
183
225
  //#endregion
184
226
  //#region src/client/types.ts
185
- var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(), k = (t) => e.object({
227
+ var D = e.string().refine(S, "amount must be an int64 string"), O = e.string(), k = (t) => e.object({
186
228
  data: e.array(t).nullish().transform((e) => e ?? []),
187
229
  total: e.number().nullish(),
188
230
  limit: e.number().nullish(),
@@ -192,11 +234,11 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
192
234
  }), A = (t) => e.object({
193
235
  data: e.array(t).nullish().transform((e) => e ?? []),
194
236
  next_cursor: e.string().nullish().transform((e) => e ?? null)
195
- }), j = e.string(), re = e.object({
237
+ }), j = e.string(), M = e.object({
196
238
  status: e.string(),
197
239
  ids: e.record(e.string(), e.string()).nullish(),
198
240
  sync_status: e.string().nullish()
199
- }), M = e.object({
241
+ }), N = e.object({
200
242
  id: e.string(),
201
243
  key: e.string(),
202
244
  revision: e.number().int().nonnegative().optional(),
@@ -213,10 +255,10 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
213
255
  billing_interval_hours: e.number().nullable(),
214
256
  trial_unit_amount: D.nullable(),
215
257
  trial_duration_hours: e.number().nullable(),
216
- psps: e.record(e.string(), re).nullish(),
258
+ psps: e.record(e.string(), M).nullish(),
217
259
  created_at: O,
218
260
  updated_at: O
219
- }), N = e.object({
261
+ }), P = e.object({
220
262
  id: e.string(),
221
263
  key: e.string().nullish(),
222
264
  revision: e.number().int().nonnegative().optional(),
@@ -224,32 +266,30 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
224
266
  description: e.string().nullish(),
225
267
  tier_group: e.string().nullish(),
226
268
  tier_rank: e.number().nullish()
227
- }), P = e.object({
269
+ }), F = e.object({
228
270
  brand: e.string().nullish(),
229
271
  last4: e.string().nullish(),
230
272
  exp_month: e.number().nullish(),
231
273
  exp_year: e.number().nullish()
232
- }), ie = e.object({
233
- id: e.string(),
234
- status: e.string()
235
- }), ae = e.object({
274
+ }), oe = e.object({
236
275
  last_failure_reason: e.string().nullish(),
237
276
  retryable: e.boolean(),
238
277
  blocked_reason: e.string().nullish(),
239
- operation: ie.nullish(),
240
278
  order_id: e.string().nullish()
241
- }), F = e.object({
242
- type: e.string(),
243
- redirect_to_url: e.object({ url: e.string().nullish() }).nullish(),
244
- transactions: e.array(e.string()).nullish()
245
279
  }), I = e.object({
280
+ type: e.string(),
281
+ url: e.string().nullish(),
282
+ psp_id: e.string().nullish(),
283
+ transactions: e.array(e.string()).nullish(),
284
+ payload: e.record(e.string(), e.string()).nullish()
285
+ }), L = e.object({
246
286
  attempts: e.number(),
247
287
  retries_left: e.number().nullish(),
248
288
  next_retry_at: O.nullish(),
249
289
  final_retry_at: O.nullish(),
250
290
  waiting_for_new_card: e.boolean(),
251
291
  last_failure_reason: e.string().nullish()
252
- }), L = e.object({
292
+ }), R = e.object({
253
293
  id: e.string(),
254
294
  status: j,
255
295
  rail: e.string().nullish(),
@@ -273,23 +313,23 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
273
313
  starts_at: O,
274
314
  ends_at: O.nullish()
275
315
  }).nullish(),
276
- dunning: I.nullish(),
277
- price: M.nullish(),
278
- product: N.nullish(),
316
+ dunning: L.nullish(),
317
+ price: N.nullish(),
318
+ product: P.nullish(),
279
319
  scheduled_change: e.object({
280
320
  price_id: e.string(),
281
321
  quantity: e.number().nullish(),
282
322
  effective_at: O,
283
323
  source: e.string(),
284
- price: M.nullish(),
285
- product: N.nullish()
324
+ price: N.nullish(),
325
+ product: P.nullish()
286
326
  }).nullish(),
287
- card: P.nullish(),
288
- recovery: ae.nullish(),
289
- next_action: F.nullish(),
327
+ card: F.nullish(),
328
+ recovery: oe.nullish(),
329
+ next_action: I.nullish(),
290
330
  created_at: O.nullish(),
291
331
  updated_at: O.nullish()
292
- }), R = e.object({
332
+ }), z = e.object({
293
333
  name: e.string().nullish(),
294
334
  email: e.string().nullish(),
295
335
  phone: e.string().nullish(),
@@ -301,7 +341,7 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
301
341
  postal_code: e.string().nullish(),
302
342
  country: e.string().nullish()
303
343
  }).nullish()
304
- }), z = e.object({
344
+ }), B = e.object({
305
345
  id: e.string(),
306
346
  status: e.string().nullish(),
307
347
  next_action: e.object({
@@ -311,8 +351,8 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
311
351
  }).nullish(),
312
352
  rail: e.string().nullish(),
313
353
  psp_id: e.string().nullish(),
314
- card: P.nullish(),
315
- billing_details: R.nullish(),
354
+ card: F.nullish(),
355
+ billing_details: z.nullish(),
316
356
  reusable: e.boolean().nullish(),
317
357
  health: e.object({
318
358
  expiry_status: e.string().nullish(),
@@ -326,16 +366,10 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
326
366
  })).nullish(),
327
367
  default_currencies: e.array(e.string()).nullish(),
328
368
  created_at: O.nullish()
329
- }), B = e.object({
369
+ }), V = e.object({
330
370
  reason: e.string(),
331
371
  message: e.string(),
332
372
  field: e.string().nullish()
333
- }), V = e.object({
334
- type: e.string(),
335
- url: e.string().nullish(),
336
- psp_id: e.string().nullish(),
337
- transactions: e.array(e.string()).nullish(),
338
- payload: e.record(e.string(), e.string()).nullish()
339
373
  }), H = e.object({
340
374
  id: e.string(),
341
375
  price_id: e.string().nullish(),
@@ -360,8 +394,8 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
360
394
  lines: e.array(H),
361
395
  payment: e.object({
362
396
  status: e.string(),
363
- next_action: V.nullish(),
364
- last_payment_error: B.nullish(),
397
+ next_action: I.nullish(),
398
+ last_payment_error: V.nullish(),
365
399
  payment_method_id: e.string().nullish(),
366
400
  payment_id: e.string().nullish()
367
401
  }),
@@ -442,10 +476,10 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
442
476
  tier_group: e.string().nullable(),
443
477
  tier_rank: e.number(),
444
478
  archived: e.boolean(),
445
- prices: e.array(M).nullish().transform((e) => e ?? []),
479
+ prices: e.array(N).nullish().transform((e) => e ?? []),
446
480
  created_at: O,
447
481
  updated_at: O
448
- }), J = e.object({
482
+ }), se = e.object({
449
483
  id: e.string(),
450
484
  kind: e.string(),
451
485
  status: e.string(),
@@ -457,15 +491,15 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
457
491
  channel: e.string().nullish(),
458
492
  rail: e.string().nullish(),
459
493
  created_at: O,
460
- price: M.nullish(),
461
- product: N.nullish(),
462
- card: P.nullish(),
494
+ price: N.nullish(),
495
+ product: P.nullish(),
496
+ card: F.nullish(),
463
497
  failure: e.object({
464
498
  reason: e.string(),
465
499
  message: e.string(),
466
500
  field: e.string().nullish()
467
501
  }).nullish()
468
- }), oe = e.object({
502
+ }), ce = e.object({
469
503
  currency: e.string(),
470
504
  billing_mode: e.string(),
471
505
  balance_amount: D,
@@ -476,19 +510,32 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
476
510
  accrual_rate_per_hour: D,
477
511
  as_of: e.string(),
478
512
  depletes_at: e.string().nullable()
479
- }), se = e.object({
513
+ }), le = e.object({
480
514
  id: e.string(),
481
- balances: e.array(oe),
515
+ balances: e.array(ce),
482
516
  default_payment_methods: e.array(e.object({
483
517
  currency: e.string(),
484
518
  payment_method_id: e.string()
485
519
  })),
486
520
  unread_notifications: e.number()
487
- }), ce = e.object({
521
+ }), ue = e.object({
522
+ key: e.string(),
523
+ event_count: e.number(),
524
+ amount: D,
525
+ dimensions: e.record(e.string(), e.number()).nullish()
526
+ }), de = e.object({
527
+ customer_id: e.string(),
528
+ currency: e.string(),
529
+ from: O,
530
+ to: O,
531
+ group_by: e.string(),
532
+ rows: e.array(ue),
533
+ next_cursor: e.string().nullish().transform((e) => e ?? null)
534
+ }), fe = e.object({
488
535
  code: e.string(),
489
536
  decimals: e.number(),
490
537
  minor_decimals: e.number().nullish()
491
- }), le = e.object({
538
+ }), pe = e.object({
492
539
  price_id: e.string(),
493
540
  quantity: e.number().nullish(),
494
541
  rail: e.string().nullish(),
@@ -499,22 +546,21 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
499
546
  effective: e.string(),
500
547
  is_estimate: e.boolean().nullish(),
501
548
  message: e.string().nullish()
502
- }), ue = e.object({
549
+ }), J = e.object({
503
550
  status: e.string(),
504
551
  effective: e.string().nullish(),
505
552
  price_id: e.string().nullish(),
506
553
  quantity: e.number().nullish(),
507
554
  subscription_id: e.string().nullish(),
508
- next_action: F.nullish(),
555
+ next_action: I.nullish(),
509
556
  delayed_start: O.nullish(),
510
557
  currency: e.string().nullish(),
511
558
  amount_due_now: D.nullish(),
512
559
  next_charge_amount: D.nullish(),
513
560
  next_charge_date: O.nullish(),
514
- message: e.string().nullish(),
515
- operation_id: e.string().nullish()
516
- }), de = e.object({
517
- psps: e.array(c).nullish().transform((e) => e ?? []),
561
+ message: e.string().nullish()
562
+ }), me = e.object({
563
+ psps: e.array(u).nullish().transform((e) => e ?? []),
518
564
  solana: e.object({
519
565
  network: e.string(),
520
566
  chain: e.string(),
@@ -528,35 +574,36 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
528
574
  recurring_eligible: e.boolean().nullish()
529
575
  })).nullish().transform((e) => e ?? [])
530
576
  }).nullish()
531
- }), fe = e.object({
577
+ }), he = e.object({
532
578
  provider: e.string(),
533
579
  site_key: e.string(),
534
580
  script_url: e.string(),
535
581
  action: e.string(),
536
582
  token_header: e.string()
537
- }), pe = e.object({
583
+ }), ge = e.object({
538
584
  display_name: e.string(),
539
585
  logo_url: e.string().nullish(),
540
586
  support_url: e.string().nullish(),
541
587
  embed_origins: e.array(e.string()).nullish().transform((e) => e ?? [])
542
- }), me = e.object({
588
+ }), _e = e.object({
543
589
  capabilities: e.object({
544
590
  route_groups: e.record(e.string(), e.boolean()),
545
591
  features: e.record(e.string(), e.boolean())
546
592
  }),
547
- currencies: e.array(ce).nullish().transform((e) => e ?? []),
548
- payment: de.nullish(),
549
- merchant: pe.nullish(),
550
- captcha: fe.nullish(),
593
+ currencies: e.array(fe).nullish().transform((e) => e ?? []),
594
+ captcha: he.nullish(),
551
595
  network: e.object({
552
596
  issuer: e.string(),
553
597
  client_id: e.string()
554
598
  }).nullish()
555
- }), he = e.object({
599
+ }), ve = e.object({
600
+ payment: me,
601
+ merchant: ge
602
+ }), ye = e.object({
556
603
  id: e.string(),
557
604
  nonce: e.string(),
558
605
  expires_at: O
559
- }), ge = e.object({
606
+ }), be = e.object({
560
607
  id: e.string(),
561
608
  merchant_id: e.string(),
562
609
  customer_id: e.string(),
@@ -566,12 +613,12 @@ var D = e.string().refine(b, "amount must be an int64 string"), O = e.string(),
566
613
  linked_at: O,
567
614
  revoked_at: O.nullish(),
568
615
  revoked_by: e.string().nullish()
569
- }), _e = e.object({ client_secret: e.string().nullish() }), Y = class extends Error {
616
+ }), Y = class extends Error {
570
617
  constructor(e = "The wallet request was declined.") {
571
618
  super(e), this.name = "WalletRejectedError";
572
619
  }
573
- }, ve = 4, ye = 500, be = (e) => e?.type === "solana_sign_transactions" && !!e.transactions?.length;
574
- async function xe(e, t) {
620
+ }, xe = 4, Se = 500, Ce = (e) => e?.type === "solana_sign_transactions" && !!e.transactions?.length;
621
+ async function X(e, t) {
575
622
  let n = "";
576
623
  for (let r of e.transactions ?? []) {
577
624
  try {
@@ -584,18 +631,18 @@ async function xe(e, t) {
584
631
  if (!n) throw i("wallet_no_signature", "The wallet returned no signature.");
585
632
  return n;
586
633
  }
587
- var Se = 2e3, X = 300;
588
- function Z(e) {
589
- let t = Ce(e.headers.get("Retry-After"));
634
+ var we = 2e3, Z = 300;
635
+ function Te(e) {
636
+ let t = Ee(e.headers.get("Retry-After"));
590
637
  switch (e.status) {
591
638
  case 429: return t;
592
- case 503: return t ?? X;
639
+ case 503: return t ?? Z;
593
640
  case 502:
594
- case 504: return X;
641
+ case 504: return Z;
595
642
  default: return null;
596
643
  }
597
644
  }
598
- function Ce(e) {
645
+ function Ee(e) {
599
646
  if (!e) return null;
600
647
  if (/^\d+$/.test(e.trim())) return Number(e.trim()) * 1e3;
601
648
  let t = Date.parse(e);
@@ -612,8 +659,8 @@ function Q(e, t) {
612
659
  t?.addEventListener("abort", a, { once: !0 });
613
660
  });
614
661
  }
615
- function we(e = {}) {
616
- let t = (e.baseUrl ?? "/billing/v1").replace(/\/+$/, ""), r = e.fetch ?? ((e, t) => fetch(e, t)), o = Te({
662
+ function De(e = {}) {
663
+ let t = (e.baseUrl ?? "/billing/v1").replace(/\/+$/, ""), r = e.fetch ?? ((e, t) => fetch(e, t)), o = Oe({
617
664
  ...s,
618
665
  ...e.currencies
619
666
  });
@@ -630,7 +677,7 @@ function we(e = {}) {
630
677
  ...n.headers
631
678
  });
632
679
  n.body !== void 0 && i.set("Content-Type", "application/json");
633
- let o = n.anonymous ? void 0 : await e.getToken?.();
680
+ let o = n.public ? void 0 : await e.getToken?.();
634
681
  o && i.set("Authorization", `Bearer ${o}`);
635
682
  let s = e.language?.();
636
683
  s && i.set("Accept-Language", s);
@@ -639,21 +686,27 @@ function we(e = {}) {
639
686
  headers: i,
640
687
  body: n.body === void 0 ? void 0 : JSON.stringify(n.body),
641
688
  signal: n.signal
642
- }, d = +(l === "GET"), f = 0;
643
- for (let e = 0;; e++) {
644
- let i;
689
+ }, d = +(l === "GET"), f = 0, p = !1;
690
+ for (let s = 0;; s++) {
691
+ let l;
645
692
  try {
646
- i = await r(c(t, n.query), u);
647
- } catch (t) {
648
- let r = X;
649
- if (e >= d || n.signal?.aborted || !(t instanceof TypeError) || f + r > 2e3) throw t;
650
- f += await Q(r, n.signal);
693
+ l = await r(c(t, n.query), u);
694
+ } catch (e) {
695
+ let t = Z;
696
+ if (s >= d || n.signal?.aborted || !(e instanceof TypeError) || f + t > 2e3) throw e;
697
+ f += await Q(t, n.signal);
698
+ continue;
699
+ }
700
+ if (l.ok) return l;
701
+ if (l.status === 401 && o && !p && ee(e.getToken)) {
702
+ let t = await a(l);
703
+ if (t.code !== "credential_expired") throw t;
704
+ e.getToken.invalidate(o), o = await e.getToken(), i.set("Authorization", `Bearer ${o}`), p = !0, s--;
651
705
  continue;
652
706
  }
653
- if (i.ok) return i;
654
- let o = Z(i);
655
- if (e >= d || o === null || f + o > 2e3) throw await a(i);
656
- await i.body?.cancel().catch(() => void 0), f += await Q(o, n.signal);
707
+ let m = Te(l);
708
+ if (s >= d || m === null || f + m > 2e3) throw await a(l);
709
+ await l.body?.cancel().catch(() => void 0), f += await Q(m, n.signal);
657
710
  }
658
711
  }
659
712
  async function u(e, t, n) {
@@ -667,7 +720,7 @@ function we(e = {}) {
667
720
  if (!o.success) throw i("invalid_response", `${t}: ${o.error.issues[0]?.path.join(".")} ${o.error.issues[0]?.message}`);
668
721
  return o.data;
669
722
  }
670
- let d = (e) => encodeURIComponent(e), f = A(L), p = A(z), m = A(J), h = A(U), g = (e, t) => ({
723
+ let d = (e) => encodeURIComponent(e), f = A(R), p = A(B), m = A(se), h = A(U), g = (e, t) => ({
671
724
  limit: e.limit ?? t,
672
725
  cursor: e.cursor ?? void 0
673
726
  }), _ = k(q);
@@ -697,10 +750,10 @@ function we(e = {}) {
697
750
  });
698
751
  },
699
752
  getSubscription(e, t) {
700
- return u(L, `/me/subscriptions/${d(e)}`, { signal: t });
753
+ return u(R, `/me/subscriptions/${d(e)}`, { signal: t });
701
754
  },
702
755
  cancelSubscription(e, t) {
703
- return u(L, `/me/subscriptions/${d(e)}/cancel`, {
756
+ return u(R, `/me/subscriptions/${d(e)}/cancel`, {
704
757
  method: "POST",
705
758
  body: {
706
759
  reason: t.reason.trim(),
@@ -709,19 +762,19 @@ function we(e = {}) {
709
762
  });
710
763
  },
711
764
  resumeSubscription(e) {
712
- return u(L, `/me/subscriptions/${d(e)}/resume`, {
765
+ return u(R, `/me/subscriptions/${d(e)}/resume`, {
713
766
  method: "POST",
714
767
  body: {}
715
768
  });
716
769
  },
717
770
  setSubscriptionPaymentMethod(e, t) {
718
- return u(L, `/me/subscriptions/${d(e)}/payment-method`, {
771
+ return u(R, `/me/subscriptions/${d(e)}/payment-method`, {
719
772
  method: "PUT",
720
773
  body: { payment_method_id: t }
721
774
  });
722
775
  },
723
776
  previewSubscriptionChange(e, t, n) {
724
- return u(le, `/me/subscriptions/${d(e)}/change/preview`, {
777
+ return u(pe, `/me/subscriptions/${d(e)}/change/preview`, {
725
778
  method: "POST",
726
779
  body: {
727
780
  price_id: t.priceId,
@@ -730,8 +783,14 @@ function we(e = {}) {
730
783
  signal: n
731
784
  });
732
785
  },
786
+ confirmSubscriptionChange(e) {
787
+ return u(J, `/me/subscriptions/${d(e)}/confirm`, {
788
+ method: "POST",
789
+ body: {}
790
+ });
791
+ },
733
792
  changeSubscription(e, t) {
734
- return u(ue, `/me/subscriptions/${d(e)}/change`, {
793
+ return u(J, `/me/subscriptions/${d(e)}/change`, {
735
794
  method: "POST",
736
795
  body: {
737
796
  price_id: t.priceId,
@@ -748,7 +807,7 @@ function we(e = {}) {
748
807
  });
749
808
  },
750
809
  addPaymentMethod(e) {
751
- return u(z, "/me/payment-methods", {
810
+ return u(B, "/me/payment-methods", {
752
811
  method: "POST",
753
812
  body: e
754
813
  });
@@ -810,16 +869,7 @@ function we(e = {}) {
810
869
  });
811
870
  },
812
871
  confirmPaymentMethod(e) {
813
- return u(z, `/me/payment-methods/${d(e)}/confirm`, {
814
- method: "POST",
815
- body: {}
816
- });
817
- },
818
- getPaymentAuthentication(e) {
819
- return u(_e, `/me/payment-operations/${d(e)}/authentication`);
820
- },
821
- async confirmPaymentAuthentication(e) {
822
- await l(`/me/payment-operations/${d(e)}/authentication/confirm`, {
872
+ return u(B, `/me/payment-methods/${d(e)}/confirm`, {
823
873
  method: "POST",
824
874
  body: {}
825
875
  });
@@ -843,25 +893,42 @@ function we(e = {}) {
843
893
  });
844
894
  },
845
895
  getAccount(e) {
846
- return u(se, "/me", { signal: e });
896
+ return u(le, "/me", { signal: e });
897
+ },
898
+ getUsage(e) {
899
+ return u(de, "/me/usage", {
900
+ query: {
901
+ currency: e.currency,
902
+ group_by: e.groupBy,
903
+ from: e.from,
904
+ to: e.to,
905
+ limit: e.limit,
906
+ cursor: e.cursor ?? void 0
907
+ },
908
+ signal: e.signal
909
+ });
847
910
  },
848
911
  async listProducts(e) {
849
912
  return e.keys.length === 0 ? {
850
913
  data: [],
851
914
  next_cursor: null
852
- } : u(_, "/catalog/products", {
853
- query: { keys: e.keys },
854
- signal: e.signal
915
+ } : u(_, "/products", {
916
+ query: {
917
+ merchant: e.merchant,
918
+ keys: e.keys
919
+ },
920
+ signal: e.signal,
921
+ public: !0
855
922
  });
856
923
  },
857
924
  createNetworkLinkChallenge() {
858
- return u(he, "/me/network-link/challenges", {
925
+ return u(ye, "/me/network-link/challenges", {
859
926
  method: "POST",
860
927
  body: {}
861
928
  });
862
929
  },
863
930
  createNetworkLink(e) {
864
- return u(ge, "/me/network-link", {
931
+ return u(be, "/me/network-link", {
865
932
  method: "POST",
866
933
  body: {
867
934
  challenge_id: e.challengeId,
@@ -870,19 +937,22 @@ function we(e = {}) {
870
937
  });
871
938
  },
872
939
  getConfig(e) {
873
- return u(me, "/config", {
940
+ return u(_e, "/config", {
874
941
  signal: e,
875
- anonymous: !0
942
+ public: !0
876
943
  });
877
944
  },
945
+ getCustomerConfig(e) {
946
+ return u(ve, "/me/config", { signal: e });
947
+ },
878
948
  currencies: o
879
949
  };
880
950
  }
881
- function Te(e) {
951
+ function Oe(e) {
882
952
  return Object.fromEntries(Object.entries(e).map(([e, t]) => [e.toUpperCase(), t]));
883
953
  }
884
954
  var $ = (e) => e instanceof Y || e instanceof Error && e.name === "WalletRejectedError" || e instanceof t && e.code === "wallet_rejected";
885
955
  //#endregion
886
- export { r as C, o as E, n as S, a as T, d as _, we as a, c as b, xe as c, ee as d, te as f, h as g, g as h, Y as i, S as l, b as m, ve as n, be as o, ne as p, Se as r, $ as s, ye as t, E as u, m as v, i as w, t as x, l as y };
956
+ export { t as C, a as D, i as E, o as O, c as S, r as T, p as _, De as a, u as b, X as c, E as d, ie as f, _ as g, v as h, Y as i, te as l, S as m, xe as n, Ce as o, ae as p, we as r, $ as s, Se as t, re as u, g as v, n as w, l as x, d as y };
887
957
 
888
- //# sourceMappingURL=client-D9G1Tgox.js.map
958
+ //# sourceMappingURL=client-DgIsTx7x.js.map