@openrails/billing-ui 0.236.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 (44) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +37 -67
  3. package/dist/account/account-billing.d.ts +1 -1
  4. package/dist/account/payment-methods-panel.d.ts +1 -1
  5. package/dist/buy-button.d.ts +14 -9
  6. package/dist/client/client.d.ts +25 -13
  7. package/dist/client/generated/error-codes.d.ts +1 -1
  8. package/dist/client/generated/routes.d.ts +1 -199
  9. package/dist/client/generated/wire.d.ts +34 -185
  10. package/dist/client/index.d.ts +1 -1
  11. package/dist/client/types.d.ts +72 -141
  12. package/dist/client-D9G1Tgox.js +888 -0
  13. package/dist/client-D9G1Tgox.js.map +1 -0
  14. package/dist/client.js +2 -2
  15. package/dist/components/eyebrow.d.ts +5 -0
  16. package/dist/embedded-checkout.d.ts +22 -0
  17. package/dist/{hooks-2d-XjpuI.js → hooks-DYepYVMX.js} +2 -2
  18. package/dist/{hooks-2d-XjpuI.js.map → hooks-DYepYVMX.js.map} +1 -1
  19. package/dist/index.d.ts +3 -7
  20. package/dist/index.js +1131 -2150
  21. package/dist/index.js.map +1 -1
  22. package/dist/modal.d.ts +3 -9
  23. package/dist/offers.d.ts +4 -5
  24. package/dist/psp.d.ts +0 -8
  25. package/dist/react.js +1 -1
  26. package/dist/styles.css +1 -1
  27. package/dist/tokenized-card-form.d.ts +5 -1
  28. package/dist/types.d.ts +12 -250
  29. package/docs/payment-form-contract.md +31 -74
  30. package/package.json +1 -2
  31. package/dist/checkout-frame.d.ts +0 -17
  32. package/dist/checkout-page.d.ts +0 -21
  33. package/dist/checkout.d.ts +0 -22
  34. package/dist/client/checkout.d.ts +0 -28
  35. package/dist/client-BuvolBPT.js +0 -1092
  36. package/dist/client-BuvolBPT.js.map +0 -1
  37. package/dist/components/ccbill-fields.d.ts +0 -8
  38. package/dist/components/methods.d.ts +0 -13
  39. package/dist/components/summary.d.ts +0 -12
  40. package/dist/fixtures.d.ts +0 -9
  41. package/dist/frame.d.ts +0 -47
  42. package/dist/lib/rail-meta.d.ts +0 -15
  43. package/dist/lib/redirect.d.ts +0 -2
  44. package/dist/source.d.ts +0 -5
@@ -1,1092 +0,0 @@
1
- import { z as e } from "zod";
2
- //#region src/client/checkout.ts
3
- var t = /* @__PURE__ */ new WeakMap();
4
- function n(e, n) {
5
- t.set(e, n);
6
- }
7
- function r(e) {
8
- let n = t.get(e);
9
- if (!n) throw Error("billing-ui: the client must come from createBillingClient");
10
- return n;
11
- }
12
- //#endregion
13
- //#region src/lib/money.ts
14
- var i = -(1n << 63n), a = (1n << 63n) - 1n;
15
- function o(e) {
16
- if (typeof e != "string" || !/^-?\d{1,19}$/.test(e)) return null;
17
- let t = BigInt(e);
18
- return t < i || t > a ? null : t;
19
- }
20
- function s(e) {
21
- return o(e) !== null;
22
- }
23
- function c(e) {
24
- return typeof e == "number" && Number.isInteger(e) && e >= 0 && e <= 18;
25
- }
26
- function l(...e) {
27
- let t = 0n;
28
- for (let n of e) {
29
- let e = o(n);
30
- if (e === null) return null;
31
- t += e;
32
- }
33
- return t < i || t > a ? null : t.toString();
34
- }
35
- var u = (() => {
36
- try {
37
- return new Intl.NumberFormat("en", { useGrouping: !1 }).format("9007199254740993") === "9007199254740993";
38
- } catch {
39
- return !1;
40
- }
41
- })(), d = 10n ** 15n;
42
- function f(e, t) {
43
- let n = e < 0n ? -e : e, r = 10n ** BigInt(t), i = (n % r).toString().padStart(t, "0").replace(/0+$/, "");
44
- return `${e < 0n ? "-" : ""}${n / r}${i ? `.${i}` : ""}`;
45
- }
46
- function p(e, t) {
47
- let n = o(e);
48
- return n === null || !c(t) ? null : f(n, t);
49
- }
50
- function m(e, t, n) {
51
- let r = o(e);
52
- if (r === null || !c(t) || !c(n) || n > t) return null;
53
- let i = 10n ** BigInt(t - n);
54
- if (r % i !== 0n) return null;
55
- let a = r / i;
56
- return a > BigInt(2 ** 53 - 1) || a < -BigInt(2 ** 53 - 1) ? null : Number(a);
57
- }
58
- function h(e, t) {
59
- if (!c(t) || e.length > 40) return null;
60
- let n = /^(-?)(\d+)(?:\.(\d+))?$/.exec(e);
61
- if (!n) return null;
62
- let r = n[3] ?? "";
63
- if (r.length > t) return null;
64
- let o = BigInt(n[2]) * 10n ** BigInt(t) + BigInt(r.padEnd(t, "0") || "0"), s = n[1] ? -o : o;
65
- return s < i || s > a ? null : s.toString();
66
- }
67
- function g(e, t, n, r) {
68
- let i = t.trim().toUpperCase(), a = o(e);
69
- if (a === null || !c(n)) return `${i} amount exceeds the exact display range`;
70
- if (!u && (a >= d || a <= -d)) return `${i} amount exceeds this browser's exact display range`;
71
- let s = f(a, n);
72
- try {
73
- return new Intl.NumberFormat(r, {
74
- style: "currency",
75
- currency: i,
76
- maximumFractionDigits: n
77
- }).format(s);
78
- } catch {
79
- return `${s} ${i}`;
80
- }
81
- }
82
- //#endregion
83
- //#region src/types.ts
84
- var _ = (e) => e.nullish().transform((e) => e ?? void 0).optional(), v = e.string().refine(s, "amount must be an int64 decimal string"), y = e.number().refine(c, "unit_decimals must be an integer from 0 to 18"), ee = e.string().url().refine((e) => {
85
- try {
86
- let t = new URL(e);
87
- return t.protocol === "https:" && !t.username && !t.password;
88
- } catch {
89
- return !1;
90
- }
91
- }, "redirect URL must be HTTPS"), te = e.string().url().refine((e) => {
92
- try {
93
- let t = new URL(e);
94
- return (t.protocol === "https:" || t.protocol === "http:") && !t.username && !t.password;
95
- } catch {
96
- return !1;
97
- }
98
- }, "return URL must be HTTP(S)"), b = e.enum([
99
- "created",
100
- "requires_action",
101
- "processing",
102
- "succeeded",
103
- "failed",
104
- "blocked",
105
- "expired",
106
- "canceled"
107
- ]), x = e.object({
108
- reason: e.string(),
109
- message: e.string(),
110
- field: e.string().nullish()
111
- }), S = e.object({
112
- id: e.string(),
113
- status: e.string()
114
- }), C = e.object({
115
- id: e.string().min(1),
116
- psp_id: _(e.string()),
117
- rail: e.string(),
118
- mode: e.enum(["one_off", "subscription"]),
119
- driver: e.enum([
120
- "collect_js",
121
- "card",
122
- "stripe_elements",
123
- "redirect",
124
- "solana_pay"
125
- ]),
126
- psp_key: _(e.string()),
127
- public_config: _(e.record(e.string(), e.string()))
128
- }), w = e.discriminatedUnion("type", [e.object({
129
- type: e.literal("redirect_to_url"),
130
- url: ee
131
- }), e.object({
132
- type: e.literal("solana_pay"),
133
- url: e.string().startsWith("solana:")
134
- })]), T = e.object({
135
- id: e.string(),
136
- option_id: e.string(),
137
- rail: e.string(),
138
- card: e.object({
139
- brand: e.string().nullish(),
140
- last4: e.string().nullish(),
141
- exp_month: e.number().nullish(),
142
- exp_year: e.number().nullish()
143
- }).nullish()
144
- }), E = e.object({
145
- label: e.string(),
146
- sublabel: _(e.string()),
147
- amount: v
148
- }), D = e.object({
149
- auto_renew: e.boolean(),
150
- display_name: e.string(),
151
- unit_amount: v,
152
- currency: e.string().min(1),
153
- unit_decimals: y,
154
- billing_interval_hours: _(e.number()),
155
- access_duration_hours: _(e.number())
156
- }), O = e.object({
157
- id: e.string(),
158
- status: b,
159
- merchant: e.object({ display_name: e.string() }),
160
- plan: D,
161
- line_items: _(e.array(E)),
162
- tax: _(v),
163
- due_today: _(v),
164
- options: e.array(C),
165
- saved_methods: _(e.array(T)),
166
- next_action: w.nullish(),
167
- payment_id: _(e.string()),
168
- subscription_id: _(e.string()),
169
- failure_message: _(e.string()),
170
- failure: x.nullish(),
171
- operation: S.nullish(),
172
- success_url: _(te),
173
- embed_origin: _(e.string().url()),
174
- expires_at: _(e.string())
175
- }), ne = e.object({
176
- option_id: e.string(),
177
- payment_token: e.string().optional(),
178
- payment_method_id: e.string().optional(),
179
- card: e.object({
180
- number: e.string(),
181
- exp_month: e.number(),
182
- exp_year: e.number(),
183
- cvc: e.string()
184
- }).optional(),
185
- billing_details: e.object({
186
- name: e.string().optional(),
187
- email: e.string().optional(),
188
- phone: e.string().optional(),
189
- address: e.object({
190
- line1: e.string().optional(),
191
- line2: e.string().optional(),
192
- city: e.string().optional(),
193
- state: e.string().optional(),
194
- postal_code: e.string().optional(),
195
- country: e.string().optional()
196
- }).optional()
197
- }).optional(),
198
- token_symbol: e.string().optional()
199
- }), k = e.object({
200
- status: b,
201
- next_action: w.nullish(),
202
- operation: S.nullish(),
203
- payment_id: _(e.string()),
204
- subscription_id: _(e.string()),
205
- failure_message: _(e.string()),
206
- failure: x.nullish()
207
- }), A = class extends Error {
208
- status;
209
- type;
210
- code;
211
- param;
212
- requestId;
213
- metadata;
214
- order;
215
- constructor(e, t) {
216
- 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;
217
- }
218
- }, j = (e) => e instanceof A, re = (e) => {
219
- let t = e?.status;
220
- return typeof t == "number" && t >= 500 && t < 600;
221
- };
222
- function M(e, t) {
223
- return new A(0, {
224
- type: "local",
225
- code: e,
226
- message: t
227
- });
228
- }
229
- async function N(e) {
230
- let t;
231
- try {
232
- t = await e.json();
233
- } catch {
234
- t = void 0;
235
- }
236
- let n = t?.error;
237
- if (n && typeof n == "object") {
238
- let t = n;
239
- if (typeof t.code == "string" && t.code) return new A(e.status, {
240
- type: typeof t.type == "string" ? t.type : "",
241
- code: t.code,
242
- message: typeof t.message == "string" ? t.message : t.code,
243
- request_id: typeof t.request_id == "string" ? t.request_id : e.headers.get("X-Request-ID") ?? void 0,
244
- param: typeof t.param == "string" ? t.param : void 0,
245
- metadata: t.metadata && typeof t.metadata == "object" ? t.metadata : void 0,
246
- order: t.order
247
- });
248
- }
249
- return new A(e.status, {
250
- type: e.status >= 500 ? "api_error" : "",
251
- code: typeof n == "string" && n ? n : e.status >= 500 ? "server_error" : "unknown_error",
252
- message: `HTTP ${e.status}`
253
- });
254
- }
255
- function ie(e) {
256
- return e instanceof A ? e : e instanceof TypeError ? M("network_error", e.message) : M("unknown_error", e instanceof Error ? e.message : String(e));
257
- }
258
- //#endregion
259
- //#region src/client/generated/currencies.ts
260
- var ae = {
261
- AED: 6,
262
- AUD: 6,
263
- BRL: 6,
264
- CAD: 6,
265
- CHF: 6,
266
- CNY: 6,
267
- CZK: 6,
268
- DKK: 6,
269
- EUR: 6,
270
- GBP: 6,
271
- HKD: 6,
272
- ILS: 6,
273
- INR: 6,
274
- JPY: 4,
275
- KRW: 4,
276
- MXN: 6,
277
- MYR: 6,
278
- NOK: 6,
279
- NZD: 6,
280
- PHP: 6,
281
- PLN: 6,
282
- PYUSD: 6,
283
- SAR: 6,
284
- SEK: 6,
285
- SGD: 6,
286
- SOL: 9,
287
- THB: 6,
288
- TRY: 6,
289
- USD: 6,
290
- USD1: 6,
291
- USDC: 6,
292
- USDG: 6,
293
- USDT: 6,
294
- ZAR: 6
295
- }, P = e.object({
296
- psp_id: e.string().min(1),
297
- key: e.string().min(1),
298
- rail: e.string(),
299
- custodian: e.string(),
300
- display_name: e.string(),
301
- flow: e.string(),
302
- config: e.record(e.string(), e.string()).nullish(),
303
- checkout: e.boolean().nullish(),
304
- status: e.string().nullish(),
305
- retry_after: e.number().int().nullish()
306
- }), oe = /* @__PURE__ */ new Set([
307
- "collect_js",
308
- "card",
309
- "stripe_elements"
310
- ]), F = (e) => oe.has(e.driver), se = (e) => e.filter((e) => e.checkout !== !1), ce = /* @__PURE__ */ new Set([
311
- "tokenize",
312
- "card",
313
- "elements"
314
- ]);
315
- function le(e) {
316
- let t = e.filter((e) => !!e.status && e.custodian === "psp" && ce.has(e.flow)).map((e) => e.retry_after ?? 30);
317
- return t.length > 0 ? Math.min(...t) : null;
318
- }
319
- function ue(e, t) {
320
- return [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? "")).flatMap((e) => {
321
- let n = t.find((t) => (t.psp_id ?? t.id) === e.psp_id && F(t));
322
- return !n || e.health?.active === !1 ? [] : [{
323
- id: e.id,
324
- option_id: n.id,
325
- rail: n.rail,
326
- card: e.card ?? null
327
- }];
328
- });
329
- }
330
- var de = (e) => !!e && !e.startsWith("preview_"), fe = (e) => e.rail === "stripe" && !!e.config?.publishable_key?.startsWith("pk_");
331
- function I(e) {
332
- return e.custodian !== "psp" || e.status ? null : e.flow === "card" && e.rail === "nmi" ? "card" : e.flow === "tokenize" && de(e.config?.tokenization_key) && e.config?.tokenization_url ? "collect_js" : fe(e) ? "stripe_elements" : null;
333
- }
334
- var pe = (e) => I(e) !== null, me = (e) => I(e) === "stripe_elements";
335
- function he(e) {
336
- return {
337
- psp_id: e.psp_id ?? e.id,
338
- key: e.psp_key ?? e.rail,
339
- rail: e.rail,
340
- custodian: "psp",
341
- display_name: "",
342
- flow: e.driver === "stripe_elements" ? "elements" : e.driver === "card" ? "card" : "tokenize",
343
- config: e.public_config ?? null
344
- };
345
- }
346
- //#endregion
347
- //#region src/client/types.ts
348
- var L = e.string().refine(s, "amount must be an int64 string"), R = e.string(), ge = (t) => e.object({
349
- data: e.array(t).nullish().transform((e) => e ?? []),
350
- total: e.number().nullish(),
351
- limit: e.number().nullish(),
352
- offset: e.number().nullish(),
353
- has_more: e.boolean().nullish(),
354
- next_cursor: e.string().nullish()
355
- }), z = (t) => e.object({
356
- data: e.array(t).nullish().transform((e) => e ?? []),
357
- next_cursor: e.string().nullish().transform((e) => e ?? null)
358
- }), _e = e.string(), ve = e.object({
359
- status: e.string(),
360
- ids: e.record(e.string(), e.string()).nullish(),
361
- sync_status: e.string().nullish()
362
- }), B = e.object({
363
- id: e.string(),
364
- key: e.string(),
365
- revision: e.number().int().nonnegative().optional(),
366
- version: e.number().int().nonnegative().optional(),
367
- product_id: e.string(),
368
- archived: e.boolean(),
369
- unit_amount: L,
370
- customer_amount: e.object({
371
- min_amount: L,
372
- max_amount: L
373
- }).nullish(),
374
- currency: e.string(),
375
- access_duration_hours: e.number().nullable(),
376
- billing_interval_hours: e.number().nullable(),
377
- trial_unit_amount: L.nullable(),
378
- trial_duration_hours: e.number().nullable(),
379
- psps: e.record(e.string(), ve).nullish(),
380
- created_at: R,
381
- updated_at: R
382
- }), V = e.object({
383
- id: e.string(),
384
- key: e.string().nullish(),
385
- revision: e.number().int().nonnegative().optional(),
386
- display_name: e.string().nullish(),
387
- description: e.string().nullish(),
388
- tier_group: e.string().nullish(),
389
- tier_rank: e.number().nullish()
390
- }), H = e.object({
391
- brand: e.string().nullish(),
392
- last4: e.string().nullish(),
393
- exp_month: e.number().nullish(),
394
- exp_year: e.number().nullish()
395
- }), ye = e.object({
396
- id: e.string(),
397
- status: e.string()
398
- }), U = e.object({
399
- last_failure_reason: e.string().nullish(),
400
- retryable: e.boolean(),
401
- blocked_reason: e.string().nullish(),
402
- operation: ye.nullish(),
403
- order_id: e.string().nullish()
404
- }), W = e.object({
405
- type: e.string(),
406
- redirect_to_url: e.object({ url: e.string().nullish() }).nullish(),
407
- transactions: e.array(e.string()).nullish()
408
- }), be = e.object({
409
- attempts: e.number(),
410
- retries_left: e.number().nullish(),
411
- next_retry_at: R.nullish(),
412
- final_retry_at: R.nullish(),
413
- waiting_for_new_card: e.boolean(),
414
- last_failure_reason: e.string().nullish()
415
- }), G = e.object({
416
- id: e.string(),
417
- status: _e,
418
- rail: e.string().nullish(),
419
- product_id: e.string().nullish(),
420
- price_id: e.string().nullish(),
421
- quantity: e.number().nullish(),
422
- psp_id: e.string().nullish(),
423
- collection_policy: e.string().nullish(),
424
- payment_method_id: e.string().nullish(),
425
- started_at: R.nullish(),
426
- ended_at: R.nullish(),
427
- current_period_starts_at: R.nullish(),
428
- current_period_ends_at: R.nullish(),
429
- canceled_at: R.nullish(),
430
- cancel_type: e.string().nullish(),
431
- resumable: e.boolean().nullish(),
432
- cancel_scheduled: e.boolean().nullish(),
433
- cancel_mode: e.string().nullish(),
434
- cancel_portal_url: e.string().nullish(),
435
- access: e.object({
436
- starts_at: R,
437
- ends_at: R.nullish()
438
- }).nullish(),
439
- dunning: be.nullish(),
440
- price: B.nullish(),
441
- product: V.nullish(),
442
- scheduled_change: e.object({
443
- price_id: e.string(),
444
- quantity: e.number().nullish(),
445
- effective_at: R,
446
- source: e.string(),
447
- price: B.nullish(),
448
- product: V.nullish()
449
- }).nullish(),
450
- card: H.nullish(),
451
- recovery: U.nullish(),
452
- next_action: W.nullish(),
453
- created_at: R.nullish(),
454
- updated_at: R.nullish()
455
- }), xe = e.object({
456
- name: e.string().nullish(),
457
- email: e.string().nullish(),
458
- phone: e.string().nullish(),
459
- address: e.object({
460
- line1: e.string().nullish(),
461
- line2: e.string().nullish(),
462
- city: e.string().nullish(),
463
- state: e.string().nullish(),
464
- postal_code: e.string().nullish(),
465
- country: e.string().nullish()
466
- }).nullish()
467
- }), K = e.object({
468
- id: e.string(),
469
- status: e.string().nullish(),
470
- next_action: e.object({
471
- type: e.string(),
472
- psp_id: e.string().nullish(),
473
- payload: e.record(e.string(), e.string()).nullish()
474
- }).nullish(),
475
- rail: e.string().nullish(),
476
- psp_id: e.string().nullish(),
477
- card: H.nullish(),
478
- billing_details: xe.nullish(),
479
- reusable: e.boolean().nullish(),
480
- health: e.object({
481
- expiry_status: e.string().nullish(),
482
- last_charged_at: R.nullish(),
483
- last_charge_outcome: e.string().nullish(),
484
- active: e.boolean().nullish()
485
- }).nullish(),
486
- subscriptions: e.array(e.object({
487
- id: e.string(),
488
- display_name: e.string().nullish()
489
- })).nullish(),
490
- default_currencies: e.array(e.string()).nullish(),
491
- created_at: R.nullish()
492
- }), Se = e.object({
493
- reason: e.string(),
494
- message: e.string(),
495
- field: e.string().nullish()
496
- }), Ce = e.object({
497
- type: e.string(),
498
- url: e.string().nullish(),
499
- psp_id: e.string().nullish(),
500
- transactions: e.array(e.string()).nullish(),
501
- payload: e.record(e.string(), e.string()).nullish()
502
- }), we = e.object({
503
- id: e.string(),
504
- price_id: e.string(),
505
- product_id: e.string(),
506
- description: e.string(),
507
- quantity: e.number().nullish(),
508
- unit_amount: L,
509
- amount: L,
510
- billing_interval_hours: e.number().nullish(),
511
- access_duration_hours: e.number().nullish(),
512
- subscription_id: e.string().nullish(),
513
- product_access_id: e.string().nullish()
514
- }), q = e.object({
515
- id: e.string(),
516
- customer_id: e.string(),
517
- origin: e.string(),
518
- status: e.string(),
519
- number: e.string().nullish(),
520
- currency: e.string(),
521
- total: L,
522
- lines: e.array(we),
523
- payment: e.object({
524
- status: e.string(),
525
- next_action: Ce.nullish(),
526
- last_payment_error: Se.nullish(),
527
- payment_method_id: e.string().nullish(),
528
- payment_id: e.string().nullish()
529
- }),
530
- payment_options: e.array(e.object({
531
- psp_id: e.string(),
532
- rail: e.string(),
533
- accepts: e.array(e.string())
534
- })).nullish().transform((e) => e ?? []),
535
- checkout: e.object({
536
- url: e.string().nullish(),
537
- success_url: e.string(),
538
- cancel_url: e.string().nullish(),
539
- saved_payment_methods: e.boolean()
540
- }).nullish(),
541
- renewal: e.object({
542
- subscription_id: e.string(),
543
- period_starts_at: R,
544
- period_ends_at: R,
545
- due_at: R
546
- }).nullish(),
547
- expires_at: R.nullish(),
548
- completed_at: R.nullish(),
549
- canceled_at: R.nullish(),
550
- expired_at: R.nullish(),
551
- voided_at: R.nullish(),
552
- created_at: R
553
- }), Te = e.object({
554
- code: e.string(),
555
- message: e.string(),
556
- owned_by: e.string().nullish(),
557
- hint: e.string().nullish()
558
- }), Ee = e.object({
559
- price_id: e.string(),
560
- product_id: e.string(),
561
- description: e.string(),
562
- quantity: e.number().nullish(),
563
- unit_amount: L,
564
- amount: L,
565
- ownership: e.string(),
566
- billing_interval_hours: e.number().nullish(),
567
- access_duration_hours: e.number().nullish(),
568
- refusal: Te.nullish()
569
- }), J = e.object({
570
- currency: e.string(),
571
- total: L,
572
- lines: e.array(Ee),
573
- payment_options: q.shape.payment_options,
574
- last_changed_at: R.nullish(),
575
- expires_at: R.nullish()
576
- }), De = e.object({
577
- id: e.string(),
578
- key: e.string(),
579
- revision: e.number().int().nonnegative().optional(),
580
- display_name: e.string(),
581
- description: e.string(),
582
- entitlements: e.array(e.string()),
583
- credit_grant: e.object({
584
- currency: e.string(),
585
- amount: L.nullish(),
586
- from_payment: e.boolean().optional(),
587
- expires_after_days: e.number().int().positive().nullish()
588
- }).nullish(),
589
- tier_group: e.string().nullable(),
590
- tier_rank: e.number(),
591
- archived: e.boolean(),
592
- prices: e.array(B).nullish().transform((e) => e ?? []),
593
- created_at: R,
594
- updated_at: R
595
- }), Oe = e.object({
596
- id: e.string(),
597
- kind: e.string(),
598
- status: e.string(),
599
- amount: L,
600
- amount_refunded: L.nullish(),
601
- currency: e.string(),
602
- subscription_id: e.string().nullish(),
603
- price_id: e.string().nullish(),
604
- channel: e.string().nullish(),
605
- rail: e.string().nullish(),
606
- created_at: R,
607
- price: B.nullish(),
608
- product: V.nullish(),
609
- card: H.nullish(),
610
- failure: e.object({
611
- reason: e.string(),
612
- message: e.string(),
613
- field: e.string().nullish()
614
- }).nullish()
615
- }), ke = e.object({
616
- currency: e.string(),
617
- billing_mode: e.string(),
618
- balance_amount: L,
619
- held_amount: L,
620
- available_amount: L,
621
- owed_amount: L
622
- }), Ae = e.object({
623
- id: e.string(),
624
- balances: e.array(ke),
625
- default_payment_methods: e.array(e.object({
626
- currency: e.string(),
627
- payment_method_id: e.string()
628
- })),
629
- unread_notifications: e.number()
630
- }), Y = e.object({
631
- id: e.string(),
632
- currency: e.string(),
633
- invoice_number: e.string().nullish(),
634
- period_starts_at: R,
635
- period_ends_at: R,
636
- total_amount: L,
637
- amount_paid: L,
638
- amount_due: L,
639
- status: e.string(),
640
- issued_at: R.nullish(),
641
- due_at: R.nullish(),
642
- delinquent: e.boolean().nullish(),
643
- paid_at: R.nullish(),
644
- recovery: U.nullish(),
645
- created_at: R
646
- }), je = e.object({
647
- code: e.string(),
648
- decimals: e.number(),
649
- minor_decimals: e.number().nullish()
650
- }), Me = e.object({
651
- price_id: e.string(),
652
- quantity: e.number().nullish(),
653
- rail: e.string().nullish(),
654
- currency: e.string(),
655
- amount_due_now: L,
656
- next_charge_amount: L,
657
- next_charge_date: R.nullish(),
658
- effective: e.string(),
659
- is_estimate: e.boolean().nullish(),
660
- message: e.string().nullish()
661
- }), Ne = e.object({
662
- status: e.string(),
663
- effective: e.string().nullish(),
664
- price_id: e.string().nullish(),
665
- quantity: e.number().nullish(),
666
- subscription_id: e.string().nullish(),
667
- next_action: W.nullish(),
668
- delayed_start: R.nullish(),
669
- currency: e.string().nullish(),
670
- amount_due_now: L.nullish(),
671
- next_charge_amount: L.nullish(),
672
- next_charge_date: R.nullish(),
673
- message: e.string().nullish(),
674
- operation_id: e.string().nullish()
675
- }), X = e.string().regex(/^\d+$/, "units must be a uint64 string"), Pe = e.object({
676
- symbol: e.string(),
677
- name: e.string().nullish(),
678
- mint: e.string(),
679
- decimals: e.number(),
680
- price: e.string().nullish(),
681
- preferred: e.boolean().nullish(),
682
- recurring_eligible: e.boolean().nullish(),
683
- quote: e.object({
684
- amount: e.string(),
685
- units: X,
686
- token_price_usd: e.string().nullish(),
687
- fx_rate: e.string().nullish(),
688
- fx_currency: e.string().nullish(),
689
- quoted_at: R.nullish(),
690
- expires_at: R.nullish()
691
- }).nullish(),
692
- balance: e.object({
693
- amount: e.string(),
694
- units: X,
695
- sufficient: e.boolean().nullish()
696
- }).nullish()
697
- }), Fe = e.object({ tokens: e.array(Pe).nullish().transform((e) => e ?? []) }), Ie = e.object({
698
- psps: e.array(P).nullish().transform((e) => e ?? []),
699
- solana: e.object({
700
- network: e.string(),
701
- chain: e.string(),
702
- preferred_token: e.string().nullish(),
703
- tokens: e.array(e.object({
704
- symbol: e.string(),
705
- name: e.string().nullish(),
706
- mint: e.string(),
707
- decimals: e.number().int(),
708
- preferred: e.boolean().nullish(),
709
- recurring_eligible: e.boolean().nullish()
710
- })).nullish().transform((e) => e ?? [])
711
- }).nullish()
712
- }), Le = e.object({
713
- provider: e.string(),
714
- site_key: e.string(),
715
- script_url: e.string(),
716
- action: e.string(),
717
- token_header: e.string()
718
- }), Re = e.object({
719
- display_name: e.string(),
720
- logo_url: e.string().nullish(),
721
- support_url: e.string().nullish()
722
- }), ze = e.object({
723
- capabilities: e.object({
724
- route_groups: e.record(e.string(), e.boolean()),
725
- features: e.record(e.string(), e.boolean())
726
- }),
727
- currencies: e.array(je).nullish().transform((e) => e ?? []),
728
- payment: Ie.nullish(),
729
- merchant: Re.nullish(),
730
- captcha: Le.nullish()
731
- }), Be = e.object({ client_secret: e.string().nullish() }), Ve = e.object({
732
- id: e.string().startsWith("ocs_"),
733
- url: e.string().url().nullish(),
734
- expires_at: R
735
- }), Z = class extends Error {
736
- constructor(e = "The wallet request was declined.") {
737
- super(e), this.name = "WalletRejectedError";
738
- }
739
- }, He = 4, Ue = 500, We = (e) => e?.type === "solana_sign_transactions" && !!e.transactions?.length;
740
- async function Ge(e, t) {
741
- let n = "";
742
- for (let r of e.transactions ?? []) {
743
- try {
744
- n = await t(r);
745
- } catch (e) {
746
- throw Ze(e) ? M("wallet_rejected", "The wallet request was declined.") : e;
747
- }
748
- if (!n) throw M("wallet_no_signature", "The wallet returned no signature.");
749
- }
750
- if (!n) throw M("wallet_no_signature", "The wallet returned no signature.");
751
- return n;
752
- }
753
- var Ke = 2e3, Q = 300;
754
- function qe(e) {
755
- let t = Je(e.headers.get("Retry-After"));
756
- switch (e.status) {
757
- case 429: return t;
758
- case 503: return t ?? Q;
759
- case 502:
760
- case 504: return Q;
761
- default: return null;
762
- }
763
- }
764
- function Je(e) {
765
- if (!e) return null;
766
- if (/^\d+$/.test(e.trim())) return Number(e.trim()) * 1e3;
767
- let t = Date.parse(e);
768
- return Number.isNaN(t) ? null : Math.max(0, t - Date.now());
769
- }
770
- function $(e, t) {
771
- return new Promise((n, r) => {
772
- if (t?.aborted) return r(t.reason);
773
- let i = setTimeout(() => {
774
- t?.removeEventListener("abort", a), n(e);
775
- }, e), a = () => {
776
- clearTimeout(i), r(t?.reason);
777
- };
778
- t?.addEventListener("abort", a, { once: !0 });
779
- });
780
- }
781
- function Ye(e = {}) {
782
- let t = (e.baseUrl ?? "/billing/v1").replace(/\/+$/, ""), r = e.fetch ?? ((e, t) => fetch(e, t)), i = Xe({
783
- ...ae,
784
- ...e.currencies
785
- });
786
- function a(e, n, r = t) {
787
- let i = new URLSearchParams();
788
- for (let [e, t] of Object.entries(n ?? {})) if (Array.isArray(t)) for (let n of t) i.append(e, n);
789
- else t !== void 0 && t !== "" && i.set(e, String(t));
790
- let a = i.toString();
791
- return `${r}${e}${a ? `?${a}` : ""}`;
792
- }
793
- async function o(t, n = {}) {
794
- let i = new Headers({
795
- Accept: "application/json",
796
- ...n.headers
797
- });
798
- n.body !== void 0 && i.set("Content-Type", "application/json");
799
- let o = n.anonymous ? void 0 : await e.getToken?.();
800
- o && i.set("Authorization", `Bearer ${o}`);
801
- let s = e.language?.();
802
- s && i.set("Accept-Language", s);
803
- let c = n.method ?? "GET", l = {
804
- method: c,
805
- headers: i,
806
- body: n.body === void 0 ? void 0 : JSON.stringify(n.body),
807
- signal: n.signal
808
- }, u = +(c === "GET"), d = 0;
809
- for (let e = 0;; e++) {
810
- let i;
811
- try {
812
- i = await r(a(t, n.query, n.root), l);
813
- } catch (t) {
814
- let r = Q;
815
- if (e >= u || n.signal?.aborted || !(t instanceof TypeError) || d + r > 2e3) throw t;
816
- d += await $(r, n.signal);
817
- continue;
818
- }
819
- if (i.ok) return i;
820
- let o = qe(i);
821
- if (e >= u || o === null || d + o > 2e3) throw await N(i);
822
- await i.body?.cancel().catch(() => void 0), d += await $(o, n.signal);
823
- }
824
- }
825
- async function s(e, t, n) {
826
- let r = await o(t, n), i;
827
- try {
828
- i = await r.json();
829
- } catch {
830
- throw M("invalid_response", `${t}: body is not JSON`);
831
- }
832
- let a = e.safeParse(i);
833
- if (!a.success) throw M("invalid_response", `${t}: ${a.error.issues[0]?.path.join(".")} ${a.error.issues[0]?.message}`);
834
- return a.data;
835
- }
836
- let c = (e) => encodeURIComponent(e), l = z(G), u = z(K), d = z(Oe), f = z(Y), p = (e, t) => ({
837
- limit: e.limit ?? t,
838
- cursor: e.cursor ?? void 0
839
- }), m = ge(De);
840
- async function h(e, t) {
841
- try {
842
- return { order: await s(q, e, t) };
843
- } catch (e) {
844
- if (j(e) && e.status === 402 && e.order) {
845
- let t = q.safeParse(e.order);
846
- if (t.success) return {
847
- order: t.data,
848
- error: e
849
- };
850
- }
851
- throw e;
852
- }
853
- }
854
- let g = {
855
- baseUrl: t,
856
- listSubscriptions(e = {}) {
857
- return s(l, "/me/subscriptions", {
858
- query: {
859
- status: e.status ?? "all",
860
- ...p(e, 100)
861
- },
862
- signal: e.signal
863
- });
864
- },
865
- getSubscription(e, t) {
866
- return s(G, `/me/subscriptions/${c(e)}`, { signal: t });
867
- },
868
- cancelSubscription(e, t) {
869
- return s(G, `/me/subscriptions/${c(e)}/cancel`, {
870
- method: "POST",
871
- body: {
872
- reason: t.reason.trim(),
873
- signature: t.signature
874
- }
875
- });
876
- },
877
- resumeSubscription(e) {
878
- return s(G, `/me/subscriptions/${c(e)}/resume`, {
879
- method: "POST",
880
- body: {}
881
- });
882
- },
883
- setSubscriptionPaymentMethod(e, t) {
884
- return s(G, `/me/subscriptions/${c(e)}/payment-method`, {
885
- method: "PUT",
886
- body: { payment_method_id: t }
887
- });
888
- },
889
- previewSubscriptionChange(e, t, n) {
890
- return s(Me, `/me/subscriptions/${c(e)}/change/preview`, {
891
- method: "POST",
892
- body: {
893
- price_id: t.priceId,
894
- quantity: t.quantity
895
- },
896
- signal: n
897
- });
898
- },
899
- changeSubscription(e, t) {
900
- return s(Ne, `/me/subscriptions/${c(e)}/change`, {
901
- method: "POST",
902
- body: {
903
- price_id: t.priceId,
904
- quantity: t.quantity,
905
- signature: t.signature
906
- },
907
- headers: { "Idempotency-Key": t.idempotencyKey }
908
- });
909
- },
910
- listPaymentMethods(e = {}) {
911
- return s(u, "/me/payment-methods", {
912
- query: p(e, 100),
913
- signal: e.signal
914
- });
915
- },
916
- addPaymentMethod(e) {
917
- return s(K, "/me/payment-methods", {
918
- method: "POST",
919
- body: e
920
- });
921
- },
922
- getCart(e) {
923
- return s(J, "/me/cart", { signal: e });
924
- },
925
- setCartLine(e, t = {}) {
926
- return s(J, `/me/cart/lines/${c(e)}`, {
927
- method: "PUT",
928
- body: t
929
- });
930
- },
931
- async clearCart() {
932
- await o("/me/cart", { method: "DELETE" });
933
- },
934
- createOrder(e) {
935
- return h("/me/orders", {
936
- method: "POST",
937
- body: {
938
- ...e.cart ? { cart: !0 } : { lines: e.lines ?? [] },
939
- ...e.expectedTotal === void 0 ? {} : { expected_total: e.expectedTotal },
940
- ...e.payment === void 0 ? {} : { payment: e.payment },
941
- ...e.reusable === void 0 ? {} : { reusable: e.reusable }
942
- },
943
- headers: { "Idempotency-Key": e.idempotencyKey }
944
- });
945
- },
946
- getOrder(e, t) {
947
- return s(q, `/me/orders/${c(e)}`, { signal: t });
948
- },
949
- payOrder(e, t) {
950
- return h(`/me/orders/${c(e)}/pay`, {
951
- method: "POST",
952
- body: {
953
- payment: t.payment,
954
- expected_total: t.expectedTotal,
955
- ...t.reusable === void 0 ? {} : { reusable: t.reusable }
956
- },
957
- headers: { "Idempotency-Key": t.idempotencyKey }
958
- });
959
- },
960
- confirmOrder(e) {
961
- return h(`/me/orders/${c(e)}/confirm`, {
962
- method: "POST",
963
- body: {}
964
- });
965
- },
966
- confirmPaymentMethod(e) {
967
- return s(K, `/me/payment-methods/${c(e)}/confirm`, {
968
- method: "POST",
969
- body: {}
970
- });
971
- },
972
- getPaymentAuthentication(e) {
973
- return s(Be, `/me/payment-operations/${c(e)}/authentication`);
974
- },
975
- async confirmPaymentAuthentication(e) {
976
- await o(`/me/payment-operations/${c(e)}/authentication/confirm`, {
977
- method: "POST",
978
- body: {}
979
- });
980
- },
981
- async removePaymentMethod(e) {
982
- return (await o(`/me/payment-methods/${c(e)}`, { method: "DELETE" })).status === 202 ? "pending" : "removed";
983
- },
984
- async setDefaultPaymentMethod(e) {
985
- await o(`/me/default-payment-methods/${c(e.currency.toUpperCase())}`, {
986
- method: "PUT",
987
- body: { payment_method_id: e.paymentMethodId }
988
- });
989
- },
990
- listPayments(e = {}) {
991
- return s(d, "/me/payments", {
992
- query: {
993
- ...p(e, 20),
994
- rail: e.rail
995
- },
996
- signal: e.signal
997
- });
998
- },
999
- listInvoices(e = {}) {
1000
- return s(f, "/me/invoices", {
1001
- query: p(e, 20),
1002
- signal: e.signal
1003
- });
1004
- },
1005
- getAccount(e) {
1006
- return s(Ae, "/me", { signal: e });
1007
- },
1008
- getInvoice(e, t) {
1009
- return s(Y, `/me/invoices/${c(e)}`, { signal: t });
1010
- },
1011
- async listProducts(e) {
1012
- return e.keys.length === 0 ? {
1013
- data: [],
1014
- next_cursor: null
1015
- } : s(m, "/catalog/products", {
1016
- query: { keys: e.keys },
1017
- signal: e.signal
1018
- });
1019
- },
1020
- getConfig(e) {
1021
- return s(ze, "/config", {
1022
- signal: e,
1023
- anonymous: !0
1024
- });
1025
- },
1026
- async listSolanaTokens(e = {}) {
1027
- let { tokens: t } = await s(Fe, "/solana/tokens", {
1028
- query: {
1029
- price_id: e.priceId,
1030
- wallet: e.wallet
1031
- },
1032
- signal: e.signal
1033
- });
1034
- return t;
1035
- },
1036
- currencies: i
1037
- };
1038
- return n(g, {
1039
- createCheckoutSession(e) {
1040
- return !e.priceKey == !e.priceId || !!e.priceKey != !!e.productKey ? Promise.reject(M("invalid_request", "Pass priceId, or both productKey and priceKey.")) : s(Ve, "/me/checkout-sessions", {
1041
- method: "POST",
1042
- body: {
1043
- price_key: e.priceKey,
1044
- product_key: e.productKey,
1045
- price_id: e.priceId,
1046
- auto_renew: e.autoRenew,
1047
- amount: e.amount,
1048
- success_url: e.successUrl
1049
- }
1050
- });
1051
- },
1052
- checkoutSource(e, t = {}) {
1053
- let n = `/checkout-sessions/${c(e)}`, r = t.customerBase?.replace(/\/+$/, ""), i = r === void 0 ? { anonymous: !0 } : { root: r };
1054
- return {
1055
- getSession: () => s(O, n, i),
1056
- async pay(e) {
1057
- try {
1058
- return await s(k, `${n}/pay`, {
1059
- ...i,
1060
- method: "POST",
1061
- body: e
1062
- });
1063
- } catch (e) {
1064
- if (!j(e)) throw e;
1065
- switch (e.status) {
1066
- case 404:
1067
- case 410: return { status: "expired" };
1068
- case 403: return {
1069
- status: "blocked",
1070
- failure_message: e.message
1071
- };
1072
- case 422:
1073
- case 429: return {
1074
- status: "failed",
1075
- failure_message: e.message
1076
- };
1077
- }
1078
- throw e;
1079
- }
1080
- }
1081
- };
1082
- }
1083
- }), g;
1084
- }
1085
- function Xe(e) {
1086
- return Object.fromEntries(Object.entries(e).map(([e, t]) => [e.toUpperCase(), t]));
1087
- }
1088
- var Ze = (e) => e instanceof Z || e instanceof Error && e.name === "WalletRejectedError" || e instanceof A && e.code === "wallet_rejected";
1089
- //#endregion
1090
- export { ne as A, g as B, ie as C, O as D, D as E, y as F, r as H, l as I, p as L, x as M, C as N, b as O, T as P, m as R, N as S, E as T, s as V, ue as _, Ye as a, re as b, Ge as c, le as d, I as f, he as g, P as h, Z as i, k as j, w as k, me as l, F as m, He as n, We as o, se as p, Ke as r, Ze as s, Ue as t, pe as u, A as v, v as w, M as x, j as y, h as z };
1091
-
1092
- //# sourceMappingURL=client-BuvolBPT.js.map