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