@openrails/billing-ui 0.235.0 → 0.237.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +155 -0
  2. package/README.md +103 -103
  3. package/dist/account/account-billing.d.ts +2 -4
  4. package/dist/account/payment-methods-panel.d.ts +2 -4
  5. package/dist/buy-button.d.ts +40 -0
  6. package/dist/cart.d.ts +18 -0
  7. package/dist/client/client.d.ts +95 -59
  8. package/dist/client/errors.d.ts +4 -0
  9. package/dist/client/generated/error-codes.d.ts +1 -1
  10. package/dist/client/generated/routes.d.ts +103 -272
  11. package/dist/client/generated/wire.d.ts +117 -246
  12. package/dist/client/index.d.ts +2 -2
  13. package/dist/client/types.d.ts +286 -142
  14. package/dist/client-D9G1Tgox.js +888 -0
  15. package/dist/client-D9G1Tgox.js.map +1 -0
  16. package/dist/client.js +2 -2
  17. package/dist/components/eyebrow.d.ts +5 -0
  18. package/dist/components/stripe-card.d.ts +8 -2
  19. package/dist/components/stripe-wallets.d.ts +12 -0
  20. package/dist/components/ui/badge.d.ts +1 -1
  21. package/dist/components/ui/button.d.ts +1 -1
  22. package/dist/embedded-checkout.d.ts +22 -0
  23. package/dist/hooks-DYepYVMX.js +526 -0
  24. package/dist/hooks-DYepYVMX.js.map +1 -0
  25. package/dist/i18n/context.d.ts +1 -1
  26. package/dist/index.d.ts +9 -11
  27. package/dist/index.js +1470 -2178
  28. package/dist/index.js.map +1 -1
  29. package/dist/lib/money.d.ts +1 -0
  30. package/dist/lib/offer-label.d.ts +4 -0
  31. package/dist/locales/de.js +20 -0
  32. package/dist/locales/de.js.map +1 -1
  33. package/dist/locales/en.d.ts +20 -0
  34. package/dist/locales/en.js +20 -0
  35. package/dist/locales/en.js.map +1 -1
  36. package/dist/locales/es.js +20 -0
  37. package/dist/locales/es.js.map +1 -1
  38. package/dist/locales/ja.js +11 -0
  39. package/dist/locales/ja.js.map +1 -1
  40. package/dist/locales/ko.js +11 -0
  41. package/dist/locales/ko.js.map +1 -1
  42. package/dist/locales/zh.js +11 -0
  43. package/dist/locales/zh.js.map +1 -1
  44. package/dist/modal.d.ts +3 -9
  45. package/dist/offers.d.ts +32 -0
  46. package/dist/order-checkout.d.ts +30 -0
  47. package/dist/psp.d.ts +0 -8
  48. package/dist/react/hooks.d.ts +8 -7
  49. package/dist/react/index.d.ts +1 -1
  50. package/dist/react/provider.d.ts +24 -2
  51. package/dist/react.js +2 -33
  52. package/dist/save-payment-method.d.ts +0 -6
  53. package/dist/styles.css +1 -1
  54. package/dist/tokenized-card-form.d.ts +5 -1
  55. package/dist/types.d.ts +12 -250
  56. package/docs/payment-form-contract.md +31 -74
  57. package/package.json +1 -2
  58. package/dist/checkout-frame.d.ts +0 -17
  59. package/dist/checkout-page.d.ts +0 -21
  60. package/dist/checkout.d.ts +0 -24
  61. package/dist/client-BpzCZes3.js +0 -931
  62. package/dist/client-BpzCZes3.js.map +0 -1
  63. package/dist/components/ccbill-fields.d.ts +0 -8
  64. package/dist/components/methods.d.ts +0 -13
  65. package/dist/components/summary.d.ts +0 -12
  66. package/dist/config-qLcHvK0Q.js +0 -341
  67. package/dist/config-qLcHvK0Q.js.map +0 -1
  68. package/dist/fixtures.d.ts +0 -9
  69. package/dist/frame.d.ts +0 -47
  70. package/dist/lib/rail-meta.d.ts +0 -15
  71. package/dist/lib/redirect.d.ts +0 -2
  72. package/dist/provider.d.ts +0 -18
  73. package/dist/react.js.map +0 -1
  74. package/dist/source.d.ts +0 -5
@@ -0,0 +1,888 @@
1
+ import { z as e } from "zod";
2
+ //#region src/client/errors.ts
3
+ var t = class extends Error {
4
+ status;
5
+ type;
6
+ code;
7
+ param;
8
+ requestId;
9
+ metadata;
10
+ order;
11
+ constructor(e, t) {
12
+ super(t.message), this.name = "BillingError", this.status = e, this.type = t.type, this.code = t.code, this.param = t.param, this.requestId = t.request_id, this.metadata = t.metadata ?? {}, this.order = t.order;
13
+ }
14
+ }, n = (e) => e instanceof t, r = (e) => {
15
+ let t = e?.status;
16
+ return typeof t == "number" && t >= 500 && t < 600;
17
+ };
18
+ function i(e, n) {
19
+ return new t(0, {
20
+ type: "local",
21
+ code: e,
22
+ message: n
23
+ });
24
+ }
25
+ async function a(e) {
26
+ let n;
27
+ try {
28
+ n = await e.json();
29
+ } catch {
30
+ n = void 0;
31
+ }
32
+ let r = n?.error;
33
+ if (r && typeof r == "object") {
34
+ let n = r;
35
+ if (typeof n.code == "string" && n.code) return new t(e.status, {
36
+ type: typeof n.type == "string" ? n.type : "",
37
+ code: n.code,
38
+ message: typeof n.message == "string" ? n.message : n.code,
39
+ request_id: typeof n.request_id == "string" ? n.request_id : e.headers.get("X-Request-ID") ?? void 0,
40
+ param: typeof n.param == "string" ? n.param : void 0,
41
+ metadata: n.metadata && typeof n.metadata == "object" ? n.metadata : void 0,
42
+ order: n.order
43
+ });
44
+ }
45
+ return new t(e.status, {
46
+ type: e.status >= 500 ? "api_error" : "",
47
+ code: typeof r == "string" && r ? r : e.status >= 500 ? "server_error" : "unknown_error",
48
+ message: `HTTP ${e.status}`
49
+ });
50
+ }
51
+ function o(e) {
52
+ return e instanceof t ? e : e instanceof TypeError ? i("network_error", e.message) : i("unknown_error", e instanceof Error ? e.message : String(e));
53
+ }
54
+ //#endregion
55
+ //#region src/client/generated/currencies.ts
56
+ var s = {
57
+ AED: 6,
58
+ AUD: 6,
59
+ BRL: 6,
60
+ CAD: 6,
61
+ CHF: 6,
62
+ CNY: 6,
63
+ CZK: 6,
64
+ DKK: 6,
65
+ EUR: 6,
66
+ GBP: 6,
67
+ HKD: 6,
68
+ ILS: 6,
69
+ INR: 6,
70
+ JPY: 4,
71
+ KRW: 4,
72
+ MXN: 6,
73
+ MYR: 6,
74
+ NOK: 6,
75
+ NZD: 6,
76
+ PHP: 6,
77
+ PLN: 6,
78
+ PYUSD: 6,
79
+ SAR: 6,
80
+ SEK: 6,
81
+ SGD: 6,
82
+ SOL: 9,
83
+ THB: 6,
84
+ TRY: 6,
85
+ USD: 6,
86
+ USD1: 6,
87
+ USDC: 6,
88
+ USDG: 6,
89
+ USDT: 6,
90
+ ZAR: 6
91
+ }, c = e.object({
92
+ psp_id: e.string().min(1),
93
+ key: e.string().min(1),
94
+ rail: e.string(),
95
+ custodian: e.string(),
96
+ display_name: e.string(),
97
+ flow: e.string(),
98
+ config: e.record(e.string(), e.string()).nullish(),
99
+ checkout: e.boolean().nullish(),
100
+ status: e.string().nullish(),
101
+ retry_after: e.number().int().nullish()
102
+ }), l = (e) => e.filter((e) => e.checkout !== !1), u = /* @__PURE__ */ new Set([
103
+ "tokenize",
104
+ "card",
105
+ "elements"
106
+ ]);
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);
109
+ return t.length > 0 ? Math.min(...t) : null;
110
+ }
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;
114
+ }
115
+ var h = (e) => m(e) !== null, g = (e) => m(e) === "stripe_elements", _ = -(1n << 63n), v = (1n << 63n) - 1n;
116
+ function y(e) {
117
+ if (typeof e != "string" || !/^-?\d{1,19}$/.test(e)) return null;
118
+ let t = BigInt(e);
119
+ return t < _ || t > v ? null : t;
120
+ }
121
+ function b(e) {
122
+ return y(e) !== null;
123
+ }
124
+ function x(e) {
125
+ return typeof e == "number" && Number.isInteger(e) && e >= 0 && e <= 18;
126
+ }
127
+ function S(...e) {
128
+ let t = 0n;
129
+ for (let n of e) {
130
+ let e = y(n);
131
+ if (e === null) return null;
132
+ t += e;
133
+ }
134
+ return t < _ || t > v ? null : t.toString();
135
+ }
136
+ var C = (() => {
137
+ try {
138
+ return new Intl.NumberFormat("en", { useGrouping: !1 }).format("9007199254740993") === "9007199254740993";
139
+ } catch {
140
+ return !1;
141
+ }
142
+ })(), w = 10n ** 15n;
143
+ function T(e, t) {
144
+ let n = e < 0n ? -e : e, r = 10n ** BigInt(t), i = (n % r).toString().padStart(t, "0").replace(/0+$/, "");
145
+ return `${e < 0n ? "-" : ""}${n / r}${i ? `.${i}` : ""}`;
146
+ }
147
+ function E(e, t) {
148
+ let n = y(e);
149
+ return n === null || !x(t) ? null : T(n, t);
150
+ }
151
+ function ee(e, t, n) {
152
+ let r = y(e);
153
+ if (r === null || !x(t) || !x(n) || n > t) return null;
154
+ let i = 10n ** BigInt(t - n);
155
+ if (r % i !== 0n) return null;
156
+ let a = r / i;
157
+ return a > BigInt(2 ** 53 - 1) || a < -BigInt(2 ** 53 - 1) ? null : Number(a);
158
+ }
159
+ function te(e, t) {
160
+ if (!x(t) || e.length > 40) return null;
161
+ let n = /^(-?)(\d+)(?:\.(\d+))?$/.exec(e);
162
+ if (!n) return null;
163
+ let r = n[3] ?? "";
164
+ if (r.length > t) return null;
165
+ 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();
167
+ }
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`;
172
+ let o = T(a, n);
173
+ try {
174
+ return new Intl.NumberFormat(r, {
175
+ style: "currency",
176
+ currency: i,
177
+ maximumFractionDigits: n
178
+ }).format(o);
179
+ } catch {
180
+ return `${o} ${i}`;
181
+ }
182
+ }
183
+ //#endregion
184
+ //#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({
186
+ data: e.array(t).nullish().transform((e) => e ?? []),
187
+ total: e.number().nullish(),
188
+ limit: e.number().nullish(),
189
+ offset: e.number().nullish(),
190
+ has_more: e.boolean().nullish(),
191
+ next_cursor: e.string().nullish()
192
+ }), A = (t) => e.object({
193
+ data: e.array(t).nullish().transform((e) => e ?? []),
194
+ next_cursor: e.string().nullish().transform((e) => e ?? null)
195
+ }), j = e.string(), re = e.object({
196
+ status: e.string(),
197
+ ids: e.record(e.string(), e.string()).nullish(),
198
+ sync_status: e.string().nullish()
199
+ }), M = e.object({
200
+ id: e.string(),
201
+ key: e.string(),
202
+ revision: e.number().int().nonnegative().optional(),
203
+ version: e.number().int().nonnegative().optional(),
204
+ product_id: e.string(),
205
+ archived: e.boolean(),
206
+ unit_amount: D,
207
+ customer_amount: e.object({
208
+ min_amount: D,
209
+ max_amount: D
210
+ }).nullish(),
211
+ currency: e.string(),
212
+ access_duration_hours: e.number().nullable(),
213
+ billing_interval_hours: e.number().nullable(),
214
+ trial_unit_amount: D.nullable(),
215
+ trial_duration_hours: e.number().nullable(),
216
+ psps: e.record(e.string(), re).nullish(),
217
+ created_at: O,
218
+ updated_at: O
219
+ }), N = e.object({
220
+ id: e.string(),
221
+ key: e.string().nullish(),
222
+ revision: e.number().int().nonnegative().optional(),
223
+ display_name: e.string().nullish(),
224
+ description: e.string().nullish(),
225
+ tier_group: e.string().nullish(),
226
+ tier_rank: e.number().nullish()
227
+ }), P = e.object({
228
+ brand: e.string().nullish(),
229
+ last4: e.string().nullish(),
230
+ exp_month: e.number().nullish(),
231
+ exp_year: e.number().nullish()
232
+ }), ie = e.object({
233
+ id: e.string(),
234
+ status: e.string()
235
+ }), ae = e.object({
236
+ last_failure_reason: e.string().nullish(),
237
+ retryable: e.boolean(),
238
+ blocked_reason: e.string().nullish(),
239
+ operation: ie.nullish(),
240
+ 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
+ }), I = e.object({
246
+ attempts: e.number(),
247
+ retries_left: e.number().nullish(),
248
+ next_retry_at: O.nullish(),
249
+ final_retry_at: O.nullish(),
250
+ waiting_for_new_card: e.boolean(),
251
+ last_failure_reason: e.string().nullish()
252
+ }), L = e.object({
253
+ id: e.string(),
254
+ status: j,
255
+ rail: e.string().nullish(),
256
+ product_id: e.string().nullish(),
257
+ price_id: e.string().nullish(),
258
+ quantity: e.number().nullish(),
259
+ psp_id: e.string().nullish(),
260
+ collection_policy: e.string().nullish(),
261
+ payment_method_id: e.string().nullish(),
262
+ started_at: O.nullish(),
263
+ ended_at: O.nullish(),
264
+ current_period_starts_at: O.nullish(),
265
+ current_period_ends_at: O.nullish(),
266
+ canceled_at: O.nullish(),
267
+ cancel_type: e.string().nullish(),
268
+ resumable: e.boolean().nullish(),
269
+ cancel_scheduled: e.boolean().nullish(),
270
+ cancel_mode: e.string().nullish(),
271
+ cancel_portal_url: e.string().nullish(),
272
+ access: e.object({
273
+ starts_at: O,
274
+ ends_at: O.nullish()
275
+ }).nullish(),
276
+ dunning: I.nullish(),
277
+ price: M.nullish(),
278
+ product: N.nullish(),
279
+ scheduled_change: e.object({
280
+ price_id: e.string(),
281
+ quantity: e.number().nullish(),
282
+ effective_at: O,
283
+ source: e.string(),
284
+ price: M.nullish(),
285
+ product: N.nullish()
286
+ }).nullish(),
287
+ card: P.nullish(),
288
+ recovery: ae.nullish(),
289
+ next_action: F.nullish(),
290
+ created_at: O.nullish(),
291
+ updated_at: O.nullish()
292
+ }), R = e.object({
293
+ name: e.string().nullish(),
294
+ email: e.string().nullish(),
295
+ phone: e.string().nullish(),
296
+ address: e.object({
297
+ line1: e.string().nullish(),
298
+ line2: e.string().nullish(),
299
+ city: e.string().nullish(),
300
+ state: e.string().nullish(),
301
+ postal_code: e.string().nullish(),
302
+ country: e.string().nullish()
303
+ }).nullish()
304
+ }), z = e.object({
305
+ id: e.string(),
306
+ status: e.string().nullish(),
307
+ next_action: e.object({
308
+ type: e.string(),
309
+ psp_id: e.string().nullish(),
310
+ payload: e.record(e.string(), e.string()).nullish()
311
+ }).nullish(),
312
+ rail: e.string().nullish(),
313
+ psp_id: e.string().nullish(),
314
+ card: P.nullish(),
315
+ billing_details: R.nullish(),
316
+ reusable: e.boolean().nullish(),
317
+ health: e.object({
318
+ expiry_status: e.string().nullish(),
319
+ last_charged_at: O.nullish(),
320
+ last_charge_outcome: e.string().nullish(),
321
+ active: e.boolean().nullish()
322
+ }).nullish(),
323
+ subscriptions: e.array(e.object({
324
+ id: e.string(),
325
+ display_name: e.string().nullish()
326
+ })).nullish(),
327
+ default_currencies: e.array(e.string()).nullish(),
328
+ created_at: O.nullish()
329
+ }), B = e.object({
330
+ reason: e.string(),
331
+ message: e.string(),
332
+ 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
+ }), H = e.object({
340
+ id: e.string(),
341
+ price_id: e.string().nullish(),
342
+ product_id: e.string().nullish(),
343
+ source: e.string().nullish(),
344
+ description: e.string(),
345
+ quantity: e.number().nullish(),
346
+ unit_amount: D,
347
+ amount: D,
348
+ billing_interval_hours: e.number().nullish(),
349
+ access_duration_hours: e.number().nullish(),
350
+ subscription_id: e.string().nullish(),
351
+ product_access_id: e.string().nullish()
352
+ }), U = e.object({
353
+ id: e.string(),
354
+ customer_id: e.string(),
355
+ origin: e.string(),
356
+ status: e.string(),
357
+ number: e.string().nullish(),
358
+ currency: e.string(),
359
+ total: D,
360
+ lines: e.array(H),
361
+ payment: e.object({
362
+ status: e.string(),
363
+ next_action: V.nullish(),
364
+ last_payment_error: B.nullish(),
365
+ payment_method_id: e.string().nullish(),
366
+ payment_id: e.string().nullish()
367
+ }),
368
+ payment_options: e.array(e.object({
369
+ psp_id: e.string(),
370
+ rail: e.string(),
371
+ accepts: e.array(e.string())
372
+ })).nullish().transform((e) => e ?? []),
373
+ checkout: e.object({
374
+ url: e.string().nullish(),
375
+ ui_mode: e.enum(["hosted", "embedded"]).catch("hosted"),
376
+ expires_at: O,
377
+ success_url: e.string(),
378
+ cancel_url: e.string().nullish(),
379
+ saved_payment_methods: e.boolean()
380
+ }).nullish(),
381
+ renewal: e.object({
382
+ subscription_id: e.string(),
383
+ period_starts_at: O,
384
+ period_ends_at: O,
385
+ due_at: O
386
+ }).nullish(),
387
+ usage: e.object({
388
+ period_starts_at: O,
389
+ period_ends_at: O,
390
+ due_at: O,
391
+ amount_paid: D,
392
+ amount_due: D,
393
+ collection_method: e.string(),
394
+ next_collection_attempt_at: O.nullish(),
395
+ po_number: e.string().nullish(),
396
+ memo: e.string().nullish(),
397
+ delinquent: e.boolean()
398
+ }).nullish(),
399
+ expires_at: O.nullish(),
400
+ completed_at: O.nullish(),
401
+ canceled_at: O.nullish(),
402
+ expired_at: O.nullish(),
403
+ voided_at: O.nullish(),
404
+ uncollectible_at: O.nullish(),
405
+ created_at: O
406
+ }), W = e.object({
407
+ code: e.string(),
408
+ message: e.string(),
409
+ owned_by: e.string().nullish(),
410
+ hint: e.string().nullish()
411
+ }), G = e.object({
412
+ price_id: e.string(),
413
+ product_id: e.string(),
414
+ description: e.string(),
415
+ quantity: e.number().nullish(),
416
+ unit_amount: D,
417
+ amount: D,
418
+ ownership: e.string(),
419
+ billing_interval_hours: e.number().nullish(),
420
+ access_duration_hours: e.number().nullish(),
421
+ refusal: W.nullish()
422
+ }), K = e.object({
423
+ currency: e.string(),
424
+ total: D,
425
+ lines: e.array(G),
426
+ payment_options: U.shape.payment_options,
427
+ last_changed_at: O.nullish(),
428
+ expires_at: O.nullish()
429
+ }), q = e.object({
430
+ id: e.string(),
431
+ key: e.string(),
432
+ revision: e.number().int().nonnegative().optional(),
433
+ display_name: e.string(),
434
+ description: e.string(),
435
+ entitlements: e.array(e.string()),
436
+ credit_grant: e.object({
437
+ currency: e.string(),
438
+ amount: D.nullish(),
439
+ from_payment: e.boolean().optional(),
440
+ expires_after_days: e.number().int().positive().nullish()
441
+ }).nullish(),
442
+ tier_group: e.string().nullable(),
443
+ tier_rank: e.number(),
444
+ archived: e.boolean(),
445
+ prices: e.array(M).nullish().transform((e) => e ?? []),
446
+ created_at: O,
447
+ updated_at: O
448
+ }), J = e.object({
449
+ id: e.string(),
450
+ kind: e.string(),
451
+ status: e.string(),
452
+ amount: D,
453
+ amount_refunded: D.nullish(),
454
+ currency: e.string(),
455
+ subscription_id: e.string().nullish(),
456
+ price_id: e.string().nullish(),
457
+ channel: e.string().nullish(),
458
+ rail: e.string().nullish(),
459
+ created_at: O,
460
+ price: M.nullish(),
461
+ product: N.nullish(),
462
+ card: P.nullish(),
463
+ failure: e.object({
464
+ reason: e.string(),
465
+ message: e.string(),
466
+ field: e.string().nullish()
467
+ }).nullish()
468
+ }), oe = e.object({
469
+ currency: e.string(),
470
+ billing_mode: e.string(),
471
+ balance_amount: D,
472
+ held_amount: D,
473
+ accrued_amount: D,
474
+ available_amount: D,
475
+ owed_amount: D,
476
+ accrual_rate_per_hour: D,
477
+ as_of: e.string(),
478
+ depletes_at: e.string().nullable()
479
+ }), se = e.object({
480
+ id: e.string(),
481
+ balances: e.array(oe),
482
+ default_payment_methods: e.array(e.object({
483
+ currency: e.string(),
484
+ payment_method_id: e.string()
485
+ })),
486
+ unread_notifications: e.number()
487
+ }), ce = e.object({
488
+ code: e.string(),
489
+ decimals: e.number(),
490
+ minor_decimals: e.number().nullish()
491
+ }), le = e.object({
492
+ price_id: e.string(),
493
+ quantity: e.number().nullish(),
494
+ rail: e.string().nullish(),
495
+ currency: e.string(),
496
+ amount_due_now: D,
497
+ next_charge_amount: D,
498
+ next_charge_date: O.nullish(),
499
+ effective: e.string(),
500
+ is_estimate: e.boolean().nullish(),
501
+ message: e.string().nullish()
502
+ }), ue = e.object({
503
+ status: e.string(),
504
+ effective: e.string().nullish(),
505
+ price_id: e.string().nullish(),
506
+ quantity: e.number().nullish(),
507
+ subscription_id: e.string().nullish(),
508
+ next_action: F.nullish(),
509
+ delayed_start: O.nullish(),
510
+ currency: e.string().nullish(),
511
+ amount_due_now: D.nullish(),
512
+ next_charge_amount: D.nullish(),
513
+ 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 ?? []),
518
+ solana: e.object({
519
+ network: e.string(),
520
+ chain: e.string(),
521
+ preferred_token: e.string().nullish(),
522
+ tokens: e.array(e.object({
523
+ symbol: e.string(),
524
+ name: e.string().nullish(),
525
+ mint: e.string(),
526
+ decimals: e.number().int(),
527
+ preferred: e.boolean().nullish(),
528
+ recurring_eligible: e.boolean().nullish()
529
+ })).nullish().transform((e) => e ?? [])
530
+ }).nullish()
531
+ }), fe = e.object({
532
+ provider: e.string(),
533
+ site_key: e.string(),
534
+ script_url: e.string(),
535
+ action: e.string(),
536
+ token_header: e.string()
537
+ }), pe = e.object({
538
+ display_name: e.string(),
539
+ logo_url: e.string().nullish(),
540
+ support_url: e.string().nullish(),
541
+ embed_origins: e.array(e.string()).nullish().transform((e) => e ?? [])
542
+ }), me = e.object({
543
+ capabilities: e.object({
544
+ route_groups: e.record(e.string(), e.boolean()),
545
+ features: e.record(e.string(), e.boolean())
546
+ }),
547
+ currencies: e.array(ce).nullish().transform((e) => e ?? []),
548
+ payment: de.nullish(),
549
+ merchant: pe.nullish(),
550
+ captcha: fe.nullish(),
551
+ network: e.object({
552
+ issuer: e.string(),
553
+ client_id: e.string()
554
+ }).nullish()
555
+ }), he = e.object({
556
+ id: e.string(),
557
+ nonce: e.string(),
558
+ expires_at: O
559
+ }), ge = e.object({
560
+ id: e.string(),
561
+ merchant_id: e.string(),
562
+ customer_id: e.string(),
563
+ account_id: e.string(),
564
+ method: e.string(),
565
+ status: e.string(),
566
+ linked_at: O,
567
+ revoked_at: O.nullish(),
568
+ revoked_by: e.string().nullish()
569
+ }), _e = e.object({ client_secret: e.string().nullish() }), Y = class extends Error {
570
+ constructor(e = "The wallet request was declined.") {
571
+ super(e), this.name = "WalletRejectedError";
572
+ }
573
+ }, ve = 4, ye = 500, be = (e) => e?.type === "solana_sign_transactions" && !!e.transactions?.length;
574
+ async function xe(e, t) {
575
+ let n = "";
576
+ for (let r of e.transactions ?? []) {
577
+ try {
578
+ n = await t(r);
579
+ } catch (e) {
580
+ throw $(e) ? i("wallet_rejected", "The wallet request was declined.") : e;
581
+ }
582
+ if (!n) throw i("wallet_no_signature", "The wallet returned no signature.");
583
+ }
584
+ if (!n) throw i("wallet_no_signature", "The wallet returned no signature.");
585
+ return n;
586
+ }
587
+ var Se = 2e3, X = 300;
588
+ function Z(e) {
589
+ let t = Ce(e.headers.get("Retry-After"));
590
+ switch (e.status) {
591
+ case 429: return t;
592
+ case 503: return t ?? X;
593
+ case 502:
594
+ case 504: return X;
595
+ default: return null;
596
+ }
597
+ }
598
+ function Ce(e) {
599
+ if (!e) return null;
600
+ if (/^\d+$/.test(e.trim())) return Number(e.trim()) * 1e3;
601
+ let t = Date.parse(e);
602
+ return Number.isNaN(t) ? null : Math.max(0, t - Date.now());
603
+ }
604
+ function Q(e, t) {
605
+ return new Promise((n, r) => {
606
+ if (t?.aborted) return r(t.reason);
607
+ let i = setTimeout(() => {
608
+ t?.removeEventListener("abort", a), n(e);
609
+ }, e), a = () => {
610
+ clearTimeout(i), r(t?.reason);
611
+ };
612
+ t?.addEventListener("abort", a, { once: !0 });
613
+ });
614
+ }
615
+ function we(e = {}) {
616
+ let t = (e.baseUrl ?? "/billing/v1").replace(/\/+$/, ""), r = e.fetch ?? ((e, t) => fetch(e, t)), o = Te({
617
+ ...s,
618
+ ...e.currencies
619
+ });
620
+ function c(e, n) {
621
+ let r = new URLSearchParams();
622
+ for (let [e, t] of Object.entries(n ?? {})) if (Array.isArray(t)) for (let n of t) r.append(e, n);
623
+ else t !== void 0 && t !== "" && r.set(e, String(t));
624
+ let i = r.toString();
625
+ return `${t}${e}${i ? `?${i}` : ""}`;
626
+ }
627
+ async function l(t, n = {}) {
628
+ let i = new Headers({
629
+ Accept: "application/json",
630
+ ...n.headers
631
+ });
632
+ n.body !== void 0 && i.set("Content-Type", "application/json");
633
+ let o = n.anonymous ? void 0 : await e.getToken?.();
634
+ o && i.set("Authorization", `Bearer ${o}`);
635
+ let s = e.language?.();
636
+ s && i.set("Accept-Language", s);
637
+ let l = n.method ?? "GET", u = {
638
+ method: l,
639
+ headers: i,
640
+ body: n.body === void 0 ? void 0 : JSON.stringify(n.body),
641
+ signal: n.signal
642
+ }, d = +(l === "GET"), f = 0;
643
+ for (let e = 0;; e++) {
644
+ let i;
645
+ 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);
651
+ continue;
652
+ }
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);
657
+ }
658
+ }
659
+ async function u(e, t, n) {
660
+ let r = await l(t, n), a;
661
+ try {
662
+ a = await r.json();
663
+ } catch {
664
+ throw i("invalid_response", `${t}: body is not JSON`);
665
+ }
666
+ let o = e.safeParse(a);
667
+ if (!o.success) throw i("invalid_response", `${t}: ${o.error.issues[0]?.path.join(".")} ${o.error.issues[0]?.message}`);
668
+ return o.data;
669
+ }
670
+ let d = (e) => encodeURIComponent(e), f = A(L), p = A(z), m = A(J), h = A(U), g = (e, t) => ({
671
+ limit: e.limit ?? t,
672
+ cursor: e.cursor ?? void 0
673
+ }), _ = k(q);
674
+ async function v(e, t) {
675
+ try {
676
+ return { order: await u(U, e, t) };
677
+ } catch (e) {
678
+ if (n(e) && e.status === 402 && e.order) {
679
+ let t = U.safeParse(e.order);
680
+ if (t.success) return {
681
+ order: t.data,
682
+ error: e
683
+ };
684
+ }
685
+ throw e;
686
+ }
687
+ }
688
+ return {
689
+ baseUrl: t,
690
+ listSubscriptions(e = {}) {
691
+ return u(f, "/me/subscriptions", {
692
+ query: {
693
+ status: e.status ?? "all",
694
+ ...g(e, 100)
695
+ },
696
+ signal: e.signal
697
+ });
698
+ },
699
+ getSubscription(e, t) {
700
+ return u(L, `/me/subscriptions/${d(e)}`, { signal: t });
701
+ },
702
+ cancelSubscription(e, t) {
703
+ return u(L, `/me/subscriptions/${d(e)}/cancel`, {
704
+ method: "POST",
705
+ body: {
706
+ reason: t.reason.trim(),
707
+ signature: t.signature
708
+ }
709
+ });
710
+ },
711
+ resumeSubscription(e) {
712
+ return u(L, `/me/subscriptions/${d(e)}/resume`, {
713
+ method: "POST",
714
+ body: {}
715
+ });
716
+ },
717
+ setSubscriptionPaymentMethod(e, t) {
718
+ return u(L, `/me/subscriptions/${d(e)}/payment-method`, {
719
+ method: "PUT",
720
+ body: { payment_method_id: t }
721
+ });
722
+ },
723
+ previewSubscriptionChange(e, t, n) {
724
+ return u(le, `/me/subscriptions/${d(e)}/change/preview`, {
725
+ method: "POST",
726
+ body: {
727
+ price_id: t.priceId,
728
+ quantity: t.quantity
729
+ },
730
+ signal: n
731
+ });
732
+ },
733
+ changeSubscription(e, t) {
734
+ return u(ue, `/me/subscriptions/${d(e)}/change`, {
735
+ method: "POST",
736
+ body: {
737
+ price_id: t.priceId,
738
+ quantity: t.quantity,
739
+ signature: t.signature
740
+ },
741
+ headers: { "Idempotency-Key": t.idempotencyKey }
742
+ });
743
+ },
744
+ listPaymentMethods(e = {}) {
745
+ return u(p, "/me/payment-methods", {
746
+ query: g(e, 100),
747
+ signal: e.signal
748
+ });
749
+ },
750
+ addPaymentMethod(e) {
751
+ return u(z, "/me/payment-methods", {
752
+ method: "POST",
753
+ body: e
754
+ });
755
+ },
756
+ getCart(e) {
757
+ return u(K, "/me/cart", { signal: e });
758
+ },
759
+ setCartLine(e, t = {}) {
760
+ return u(K, `/me/cart/lines/${d(e)}`, {
761
+ method: "PUT",
762
+ body: t
763
+ });
764
+ },
765
+ async clearCart() {
766
+ await l("/me/cart", { method: "DELETE" });
767
+ },
768
+ createOrder(e) {
769
+ return v("/me/orders", {
770
+ method: "POST",
771
+ body: {
772
+ ...e.cart ? { cart: !0 } : { lines: e.lines ?? [] },
773
+ ...e.expectedTotal === void 0 ? {} : { expected_total: e.expectedTotal },
774
+ ...e.payment === void 0 ? {} : { payment: e.payment },
775
+ ...e.reusable === void 0 ? {} : { reusable: e.reusable }
776
+ },
777
+ headers: { "Idempotency-Key": e.idempotencyKey }
778
+ });
779
+ },
780
+ listOrders(e = {}) {
781
+ return u(h, "/me/orders", {
782
+ query: {
783
+ ...g(e, 20),
784
+ origin: e.origin,
785
+ status: e.status,
786
+ subscription_id: e.subscriptionId,
787
+ overdue: e.overdue ? "true" : void 0
788
+ },
789
+ signal: e.signal
790
+ });
791
+ },
792
+ getOrder(e, t) {
793
+ return u(U, `/me/orders/${d(e)}`, { signal: t });
794
+ },
795
+ payOrder(e, t) {
796
+ return v(`/me/orders/${d(e)}/pay`, {
797
+ method: "POST",
798
+ body: {
799
+ payment: t.payment,
800
+ expected_total: t.expectedTotal,
801
+ ...t.reusable === void 0 ? {} : { reusable: t.reusable }
802
+ },
803
+ headers: { "Idempotency-Key": t.idempotencyKey }
804
+ });
805
+ },
806
+ confirmOrder(e) {
807
+ return v(`/me/orders/${d(e)}/confirm`, {
808
+ method: "POST",
809
+ body: {}
810
+ });
811
+ },
812
+ 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`, {
823
+ method: "POST",
824
+ body: {}
825
+ });
826
+ },
827
+ async removePaymentMethod(e) {
828
+ return (await l(`/me/payment-methods/${d(e)}`, { method: "DELETE" })).status === 202 ? "pending" : "removed";
829
+ },
830
+ async setDefaultPaymentMethod(e) {
831
+ await l(`/me/default-payment-methods/${d(e.currency.toUpperCase())}`, {
832
+ method: "PUT",
833
+ body: { payment_method_id: e.paymentMethodId }
834
+ });
835
+ },
836
+ listPayments(e = {}) {
837
+ return u(m, "/me/payments", {
838
+ query: {
839
+ ...g(e, 20),
840
+ rail: e.rail
841
+ },
842
+ signal: e.signal
843
+ });
844
+ },
845
+ getAccount(e) {
846
+ return u(se, "/me", { signal: e });
847
+ },
848
+ async listProducts(e) {
849
+ return e.keys.length === 0 ? {
850
+ data: [],
851
+ next_cursor: null
852
+ } : u(_, "/catalog/products", {
853
+ query: { keys: e.keys },
854
+ signal: e.signal
855
+ });
856
+ },
857
+ createNetworkLinkChallenge() {
858
+ return u(he, "/me/network-link/challenges", {
859
+ method: "POST",
860
+ body: {}
861
+ });
862
+ },
863
+ createNetworkLink(e) {
864
+ return u(ge, "/me/network-link", {
865
+ method: "POST",
866
+ body: {
867
+ challenge_id: e.challengeId,
868
+ id_token: e.idToken
869
+ }
870
+ });
871
+ },
872
+ getConfig(e) {
873
+ return u(me, "/config", {
874
+ signal: e,
875
+ anonymous: !0
876
+ });
877
+ },
878
+ currencies: o
879
+ };
880
+ }
881
+ function Te(e) {
882
+ return Object.fromEntries(Object.entries(e).map(([e, t]) => [e.toUpperCase(), t]));
883
+ }
884
+ var $ = (e) => e instanceof Y || e instanceof Error && e.name === "WalletRejectedError" || e instanceof t && e.code === "wallet_rejected";
885
+ //#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 };
887
+
888
+ //# sourceMappingURL=client-D9G1Tgox.js.map