@openrails/billing-ui 0.0.0-stage → 0.230.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 (112) hide show
  1. package/CHANGELOG.md +257 -0
  2. package/LICENSE +21 -0
  3. package/README.md +211 -2
  4. package/dist/account/account-billing.d.ts +19 -0
  5. package/dist/account/cancel-dialog.d.ts +18 -0
  6. package/dist/account/change-card-dialog.d.ts +14 -0
  7. package/dist/account/format.d.ts +25 -0
  8. package/dist/account/notice.d.ts +3 -0
  9. package/dist/account/payment-history.d.ts +8 -0
  10. package/dist/account/payment-methods-panel.d.ts +19 -0
  11. package/dist/account/section.d.ts +25 -0
  12. package/dist/account/status-badge.d.ts +8 -0
  13. package/dist/account/subscriptions-panel.d.ts +19 -0
  14. package/dist/appearance.d.ts +23 -0
  15. package/dist/authenticate.d.ts +8 -0
  16. package/dist/checkout-frame.d.ts +17 -0
  17. package/dist/checkout-page.d.ts +16 -0
  18. package/dist/checkout.d.ts +24 -0
  19. package/dist/client/client.d.ts +167 -0
  20. package/dist/client/errors.d.ts +26 -0
  21. package/dist/client/generated/openrails-routes.d.ts +2 -0
  22. package/dist/client/index.d.ts +4 -0
  23. package/dist/client/types.d.ts +754 -0
  24. package/dist/client-DhG2jv34.js +771 -0
  25. package/dist/client-DhG2jv34.js.map +1 -0
  26. package/dist/client.js +3 -0
  27. package/dist/components/billing-fields.d.ts +39 -0
  28. package/dist/components/card-brands.d.ts +6 -0
  29. package/dist/components/card-fields.d.ts +29 -0
  30. package/dist/components/ccbill-fields.d.ts +8 -0
  31. package/dist/components/methods.d.ts +13 -0
  32. package/dist/components/pay-button.d.ts +6 -0
  33. package/dist/components/qr.d.ts +6 -0
  34. package/dist/components/saved-methods.d.ts +9 -0
  35. package/dist/components/states.d.ts +10 -0
  36. package/dist/components/stripe-card.d.ts +17 -0
  37. package/dist/components/summary.d.ts +12 -0
  38. package/dist/components/ui/alert-dialog.d.ts +18 -0
  39. package/dist/components/ui/badge.d.ts +7 -0
  40. package/dist/components/ui/button.d.ts +8 -0
  41. package/dist/components/ui/card.d.ts +11 -0
  42. package/dist/components/ui/dialog.d.ts +17 -0
  43. package/dist/components/ui/input.d.ts +3 -0
  44. package/dist/components/ui/label.d.ts +3 -0
  45. package/dist/components/ui/radio-group.d.ts +5 -0
  46. package/dist/components/ui/separator.d.ts +3 -0
  47. package/dist/components/ui/skeleton.d.ts +2 -0
  48. package/dist/components/ui/spinner.d.ts +3 -0
  49. package/dist/components/ui/textarea.d.ts +3 -0
  50. package/dist/dist-CslWupfi.js +3311 -0
  51. package/dist/dist-CslWupfi.js.map +1 -0
  52. package/dist/errors-T-PRm3vV.js +54 -0
  53. package/dist/errors-T-PRm3vV.js.map +1 -0
  54. package/dist/fixtures.d.ts +9 -0
  55. package/dist/frame.d.ts +47 -0
  56. package/dist/hooks-DLFF-zx5.js +285 -0
  57. package/dist/hooks-DLFF-zx5.js.map +1 -0
  58. package/dist/i18n/context.d.ts +4 -0
  59. package/dist/i18n/index.d.ts +2 -0
  60. package/dist/i18n/messages.d.ts +58 -0
  61. package/dist/index.d.ts +29 -0
  62. package/dist/index.js +4182 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/lib/billing.d.ts +25 -0
  65. package/dist/lib/card-brands.d.ts +2 -0
  66. package/dist/lib/card-entry.d.ts +46 -0
  67. package/dist/lib/ccbill.d.ts +8 -0
  68. package/dist/lib/collect.d.ts +51 -0
  69. package/dist/lib/money.d.ts +9 -0
  70. package/dist/lib/period.d.ts +15 -0
  71. package/dist/lib/rail-meta.d.ts +15 -0
  72. package/dist/lib/redirect.d.ts +2 -0
  73. package/dist/lib/stripe-appearance.d.ts +2 -0
  74. package/dist/lib/stripe.d.ts +2 -0
  75. package/dist/locales/de.d.ts +2 -0
  76. package/dist/locales/de.js +204 -0
  77. package/dist/locales/de.js.map +1 -0
  78. package/dist/locales/en.d.ts +201 -0
  79. package/dist/locales/en.js +204 -0
  80. package/dist/locales/en.js.map +1 -0
  81. package/dist/locales/es.d.ts +2 -0
  82. package/dist/locales/es.js +204 -0
  83. package/dist/locales/es.js.map +1 -0
  84. package/dist/locales/ja.d.ts +2 -0
  85. package/dist/locales/ja.js +195 -0
  86. package/dist/locales/ja.js.map +1 -0
  87. package/dist/locales/ko.d.ts +2 -0
  88. package/dist/locales/ko.js +195 -0
  89. package/dist/locales/ko.js.map +1 -0
  90. package/dist/locales/zh.d.ts +2 -0
  91. package/dist/locales/zh.js +195 -0
  92. package/dist/locales/zh.js.map +1 -0
  93. package/dist/modal.d.ts +12 -0
  94. package/dist/provider.d.ts +18 -0
  95. package/dist/psp.d.ts +46 -0
  96. package/dist/react/context.d.ts +38 -0
  97. package/dist/react/hooks.d.ts +76 -0
  98. package/dist/react/index.d.ts +3 -0
  99. package/dist/react/provider.d.ts +18 -0
  100. package/dist/react/remote.d.ts +11 -0
  101. package/dist/react.js +37 -0
  102. package/dist/react.js.map +1 -0
  103. package/dist/save-payment-method.d.ts +26 -0
  104. package/dist/scope-context.d.ts +17 -0
  105. package/dist/scope.d.ts +6 -0
  106. package/dist/source.d.ts +14 -0
  107. package/dist/styles.css +3 -0
  108. package/dist/tokenized-card-form.d.ts +24 -0
  109. package/dist/types.d.ts +191 -0
  110. package/docs/1055-nmi-host-integration.md +28 -0
  111. package/docs/payment-form-contract.md +153 -0
  112. package/package.json +112 -3
@@ -0,0 +1,771 @@
1
+ import { a as e, i as t, n, t as r } from "./errors-T-PRm3vV.js";
2
+ import { z as i } from "zod";
3
+ //#region src/lib/money.ts
4
+ var a = -(1n << 63n), o = (1n << 63n) - 1n;
5
+ function s(e) {
6
+ if (typeof e != "string" || !/^-?\d{1,19}$/.test(e)) return null;
7
+ let t = BigInt(e);
8
+ return t < a || t > o ? null : t;
9
+ }
10
+ function c(e) {
11
+ return s(e) !== null;
12
+ }
13
+ function l(e) {
14
+ return typeof e == "number" && Number.isInteger(e) && e >= 0 && e <= 18;
15
+ }
16
+ function u(...e) {
17
+ let t = 0n;
18
+ for (let n of e) {
19
+ let e = s(n);
20
+ if (e === null) return null;
21
+ t += e;
22
+ }
23
+ return t < a || t > o ? null : t.toString();
24
+ }
25
+ var d = (() => {
26
+ try {
27
+ return new Intl.NumberFormat("en", { useGrouping: !1 }).format("9007199254740993") === "9007199254740993";
28
+ } catch {
29
+ return !1;
30
+ }
31
+ })(), f = 10n ** 15n;
32
+ function p(e, t) {
33
+ let n = e < 0n ? -e : e, r = 10n ** BigInt(t), i = (n % r).toString().padStart(t, "0").replace(/0+$/, "");
34
+ return `${e < 0n ? "-" : ""}${n / r}${i ? `.${i}` : ""}`;
35
+ }
36
+ function m(e, t) {
37
+ let n = s(e);
38
+ return n === null || !l(t) ? null : p(n, t);
39
+ }
40
+ function h(e, t, n, r) {
41
+ let i = t.trim().toUpperCase(), a = s(e);
42
+ if (a === null || !l(n)) return `${i} amount exceeds the exact display range`;
43
+ if (!d && (a >= f || a <= -f)) return `${i} amount exceeds this browser's exact display range`;
44
+ let o = p(a, n);
45
+ try {
46
+ return new Intl.NumberFormat(r, {
47
+ style: "currency",
48
+ currency: i,
49
+ maximumFractionDigits: n
50
+ }).format(o);
51
+ } catch {
52
+ return `${o} ${i}`;
53
+ }
54
+ }
55
+ //#endregion
56
+ //#region src/types.ts
57
+ var g = i.string().refine(c, "amount must be an int64 decimal string"), _ = i.number().refine(l, "unit_decimals must be an integer from 0 to 18"), ee = i.string().url().refine((e) => {
58
+ try {
59
+ let t = new URL(e);
60
+ return t.protocol === "https:" && !t.username && !t.password;
61
+ } catch {
62
+ return !1;
63
+ }
64
+ }, "redirect URL must be HTTPS"), v = i.string().url().refine((e) => {
65
+ try {
66
+ let t = new URL(e);
67
+ return (t.protocol === "https:" || t.protocol === "http:") && !t.username && !t.password;
68
+ } catch {
69
+ return !1;
70
+ }
71
+ }, "return URL must be HTTP(S)"), y = i.enum([
72
+ "created",
73
+ "requires_action",
74
+ "processing",
75
+ "succeeded",
76
+ "failed",
77
+ "blocked",
78
+ "expired",
79
+ "canceled"
80
+ ]), b = i.object({
81
+ reason: i.string(),
82
+ message: i.string(),
83
+ field: i.string().nullish()
84
+ }), te = i.object({
85
+ id: i.string(),
86
+ status: i.string()
87
+ }), x = i.object({
88
+ id: i.string().min(1),
89
+ rail: i.string(),
90
+ mode: i.enum(["one_off", "subscription"]),
91
+ driver: i.enum([
92
+ "collect_js",
93
+ "card",
94
+ "stripe_elements",
95
+ "redirect",
96
+ "solana_pay"
97
+ ]),
98
+ psp_key: i.string().optional(),
99
+ public_config: i.record(i.string(), i.string()).optional()
100
+ }), S = i.object({
101
+ id: i.string(),
102
+ option_id: i.string(),
103
+ rail: i.string(),
104
+ brand: i.string().optional(),
105
+ last_four: i.string().optional(),
106
+ exp_month: i.number().optional(),
107
+ exp_year: i.number().optional(),
108
+ default: i.boolean().optional()
109
+ }), C = i.object({
110
+ label: i.string(),
111
+ sublabel: i.string().optional(),
112
+ amount: g
113
+ }), w = i.object({
114
+ display_name: i.string(),
115
+ unit_amount: g,
116
+ currency: i.string().min(1),
117
+ unit_decimals: _,
118
+ period_hours: i.number().nullish(),
119
+ automatically_renews: i.boolean()
120
+ }), T = i.object({
121
+ id: i.string(),
122
+ status: y,
123
+ merchant: i.object({ display_name: i.string() }),
124
+ plan: w,
125
+ line_items: i.array(C).optional(),
126
+ tax: g.optional(),
127
+ due_today: g.optional(),
128
+ rails: i.array(x),
129
+ saved_methods: i.array(S).optional(),
130
+ transaction_url: i.string().startsWith("solana:").optional(),
131
+ payment_id: i.string().optional(),
132
+ subscription_id: i.string().optional(),
133
+ failure_message: i.string().optional(),
134
+ failure: b.nullish(),
135
+ operation: te.nullish(),
136
+ success_url: v.optional(),
137
+ embed_origin: i.string().url().optional(),
138
+ expires_at: i.string().nullish()
139
+ }), ne = i.object({
140
+ option_id: i.string(),
141
+ payment_token: i.string().optional(),
142
+ payment_method_id: i.string().optional(),
143
+ email: i.string().optional(),
144
+ name_on_card: i.string().optional(),
145
+ address1: i.string().optional(),
146
+ city: i.string().optional(),
147
+ state: i.string().optional(),
148
+ zip: i.string().optional(),
149
+ country: i.string().optional(),
150
+ card: i.object({
151
+ number: i.string(),
152
+ exp_month: i.number(),
153
+ exp_year: i.number(),
154
+ cvc: i.string()
155
+ }).optional(),
156
+ last_four: i.string().optional(),
157
+ card_type: i.string().optional(),
158
+ expiry_date: i.string().optional(),
159
+ token_symbol: i.string().optional()
160
+ }), E = i.object({
161
+ status: y,
162
+ redirect_url: ee.optional(),
163
+ transaction_url: i.string().startsWith("solana:").optional(),
164
+ payment_id: i.string().optional(),
165
+ subscription_id: i.string().optional(),
166
+ failure_message: i.string().optional(),
167
+ failure: b.nullish(),
168
+ operation_id: i.string().optional()
169
+ }), re = {
170
+ EUR: 6,
171
+ JPY: 4,
172
+ USD: 6
173
+ }, D = i.string().refine(c, "amount must be an int64 string"), O = i.string(), k = (e) => i.object({
174
+ data: i.array(e).nullish().transform((e) => e ?? []),
175
+ total: i.number().nullish(),
176
+ limit: i.number().nullish(),
177
+ offset: i.number().nullish(),
178
+ has_more: i.boolean().nullish()
179
+ }), A = i.string(), j = i.object({
180
+ id: i.string(),
181
+ key: i.string().nullish(),
182
+ product_id: i.string().nullish(),
183
+ unit_amount: D,
184
+ currency: i.string(),
185
+ auto_renew: i.boolean().nullish(),
186
+ access_duration_hours: i.number().nullish()
187
+ }), M = i.object({
188
+ id: i.string(),
189
+ key: i.string().nullish(),
190
+ display_name: i.string().nullish(),
191
+ description: i.string().nullish(),
192
+ tier_group: i.string().nullish(),
193
+ tier_rank: i.number().nullish()
194
+ }), N = i.object({
195
+ brand: i.string().nullish(),
196
+ last4: i.string().nullish(),
197
+ exp_month: i.number().nullish(),
198
+ exp_year: i.number().nullish()
199
+ }), P = i.object({
200
+ id: i.string(),
201
+ status: i.string()
202
+ }), F = i.object({
203
+ last_failure_reason: i.string().nullish(),
204
+ retryable: i.boolean(),
205
+ blocked_reason: i.string().nullish(),
206
+ operation: P.nullish()
207
+ }), I = i.object({
208
+ id: i.string(),
209
+ status: A,
210
+ rail: i.string().nullish(),
211
+ product_id: i.string().nullish(),
212
+ price_id: i.string().nullish(),
213
+ psp_id: i.string().nullish(),
214
+ payment_method_id: i.string().nullish(),
215
+ started_at: O.nullish(),
216
+ ended_at: O.nullish(),
217
+ current_period_starts_at: O.nullish(),
218
+ current_period_ends_at: O.nullish(),
219
+ cancelled_at: O.nullish(),
220
+ cancel_type: i.string().nullish(),
221
+ resumable: i.boolean().nullish(),
222
+ cancel_scheduled: i.boolean().nullish(),
223
+ cancel_mode: i.string().nullish(),
224
+ cancel_portal_url: i.string().nullish(),
225
+ grace_ends_at: O.nullish(),
226
+ next_retry_at: O.nullish(),
227
+ price: j.nullish(),
228
+ product: M.nullish(),
229
+ scheduled_price: j.nullish(),
230
+ scheduled_product: M.nullish(),
231
+ card: N.nullish(),
232
+ recovery: F.nullish(),
233
+ created_at: O.nullish(),
234
+ updated_at: O.nullish()
235
+ }), L = i.object({
236
+ id: i.string(),
237
+ type: i.string().nullish(),
238
+ rail: i.string().nullish(),
239
+ psp_id: i.string().nullish(),
240
+ card: N.nullish(),
241
+ billing_details: i.object({
242
+ name: i.string().nullish(),
243
+ email: i.string().nullish()
244
+ }).nullish(),
245
+ health: i.object({
246
+ expiry_status: i.string().nullish(),
247
+ last_charged_at: O.nullish(),
248
+ last_charge_outcome: i.string().nullish(),
249
+ active: i.boolean().nullish()
250
+ }).nullish(),
251
+ subscriptions: i.array(i.object({
252
+ id: i.string(),
253
+ display_name: i.string().nullish()
254
+ })).nullish(),
255
+ default: i.boolean().nullish(),
256
+ collection_default_currencies: i.array(i.string()).nullish(),
257
+ created_at: O.nullish()
258
+ }), R = i.object({
259
+ id: i.string(),
260
+ object: i.string().nullish(),
261
+ status: i.string().nullish(),
262
+ amount: D,
263
+ amount_refunded: D.nullish(),
264
+ currency: i.string(),
265
+ subscription_id: i.string().nullish(),
266
+ rail: i.string().nullish(),
267
+ refunded: i.boolean().nullish(),
268
+ created_at: O,
269
+ price: i.object({
270
+ id: i.string().nullish(),
271
+ key: i.string().nullish(),
272
+ product: i.string().nullish(),
273
+ type: i.string().nullish(),
274
+ recurring: i.object({ interval: i.string().nullish() }).nullish()
275
+ }).nullish(),
276
+ product: M.nullish(),
277
+ card: N.nullish(),
278
+ failure: i.object({
279
+ reason: i.string(),
280
+ message: i.string(),
281
+ field: i.string().nullish()
282
+ }).nullish()
283
+ }), z = i.object({
284
+ id: i.string(),
285
+ currency: i.string(),
286
+ invoice_number: i.string().nullish(),
287
+ period_from: O,
288
+ period_to: O,
289
+ total_amount: D,
290
+ amount_paid: D,
291
+ amount_due: D,
292
+ status: i.string(),
293
+ issued_at: O.nullish(),
294
+ due_at: O.nullish(),
295
+ paid_at: O.nullish(),
296
+ recovery: F.nullish(),
297
+ created_at: O
298
+ }), ie = i.object({
299
+ invoices: i.array(z).nullish().transform((e) => e ?? []),
300
+ total: i.number().nullish(),
301
+ limit: i.number().nullish(),
302
+ offset: i.number().nullish()
303
+ }), ae = i.object({
304
+ has_active_subscription: i.boolean(),
305
+ subscription: I.nullish(),
306
+ next_renewal_at: O.nullish(),
307
+ entitlements: i.array(i.object({
308
+ entitlement: i.string(),
309
+ start_at: O.nullish(),
310
+ end_at: O.nullish(),
311
+ revoked_at: O.nullish()
312
+ })).nullish()
313
+ }), B = i.object({
314
+ code: i.string(),
315
+ decimals: i.number(),
316
+ minor_decimals: i.number().nullish()
317
+ }), V = i.object({ currencies: i.array(B) }), H = i.object({
318
+ id: i.string(),
319
+ key: i.string().nullish(),
320
+ unit_amount: D,
321
+ currency: i.string(),
322
+ type: i.string().nullish(),
323
+ recurring: i.object({ interval: i.string() }).nullish(),
324
+ product: i.string().nullish(),
325
+ active: i.boolean().nullish(),
326
+ providers: i.array(i.string()).nullish(),
327
+ metadata: i.record(i.string(), i.string()).nullish(),
328
+ created_at: O.nullish()
329
+ }), U = i.object({
330
+ id: i.string(),
331
+ key: i.string().nullish(),
332
+ name: i.string(),
333
+ description: i.string().nullish(),
334
+ entitlements_spec: i.record(i.string(), i.number().nullable()).nullish(),
335
+ tier_group: i.string().nullish(),
336
+ tier_rank: i.number().nullish(),
337
+ active: i.boolean().nullish(),
338
+ metadata: i.record(i.string(), i.string()).nullish(),
339
+ created_at: O.nullish(),
340
+ updated_at: O.nullish(),
341
+ prices: i.array(H).nullish().transform((e) => e ?? [])
342
+ }), W = i.object({
343
+ action: i.string(),
344
+ price_id: i.string(),
345
+ rail: i.string().nullish(),
346
+ currency: i.string(),
347
+ amount_due_now: D,
348
+ next_charge_amount: D,
349
+ next_charge_date: O.nullish(),
350
+ effective: i.string(),
351
+ is_estimate: i.boolean().nullish(),
352
+ message: i.string().nullish()
353
+ }), G = i.object({
354
+ status: i.string(),
355
+ action: i.string().nullish(),
356
+ effective: i.string().nullish(),
357
+ price_id: i.string().nullish(),
358
+ subscription_id: i.string().nullish(),
359
+ url: i.string().nullish(),
360
+ next_action: i.object({
361
+ type: i.string(),
362
+ redirect_to_url: i.object({ url: i.string().nullish() }).nullish()
363
+ }).nullish(),
364
+ delayed_start: O.nullish(),
365
+ currency: i.string().nullish(),
366
+ amount_due_now: D.nullish(),
367
+ next_charge_amount: D.nullish(),
368
+ next_charge_date: O.nullish(),
369
+ message: i.string().nullish(),
370
+ operation_id: i.string().nullish()
371
+ }), K = i.object({
372
+ transaction: i.string().min(1),
373
+ subscription_pda: i.string().nullish()
374
+ }), q = i.string().regex(/^\d+$/, "units must be a uint64 string"), J = i.object({
375
+ symbol: i.string(),
376
+ name: i.string().nullish(),
377
+ mint: i.string(),
378
+ decimals: i.number(),
379
+ price: i.string().nullish(),
380
+ preferred: i.boolean().nullish(),
381
+ recurring_eligible: i.boolean().nullish(),
382
+ quote: i.object({
383
+ amount: i.string(),
384
+ units: q,
385
+ token_price_usd: i.string().nullish(),
386
+ fx_rate: i.string().nullish(),
387
+ fx_currency: i.string().nullish(),
388
+ quoted_at: O.nullish(),
389
+ expires_at: O.nullish()
390
+ }).nullish(),
391
+ balance: i.object({
392
+ amount: i.string(),
393
+ units: q,
394
+ sufficient: i.boolean().nullish()
395
+ }).nullish()
396
+ }), oe = i.object({ tokens: i.array(J).nullish().transform((e) => e ?? []) }), se = i.object({
397
+ network: i.string(),
398
+ chain: i.string().nullish(),
399
+ rpcUrl: i.string().nullish(),
400
+ explorerCluster: i.string().nullish(),
401
+ preferredToken: i.string().nullish(),
402
+ tokens: i.array(J).nullish().transform((e) => e ?? []),
403
+ features: i.object({
404
+ solanaPay: i.boolean().nullish(),
405
+ recurringSubscriptions: i.boolean().nullish(),
406
+ solanaPayRecurringSubscriptions: i.boolean().nullish()
407
+ }).nullish()
408
+ }), ce = i.object({
409
+ transaction: i.string().min(1),
410
+ kind: i.string().nullish(),
411
+ new_subscription_pda: i.string().nullish()
412
+ }), le = i.object({
413
+ subscription_id: i.string().nullish(),
414
+ new_subscription_id: i.string().nullish(),
415
+ kind: i.string().nullish(),
416
+ status: i.string().nullish(),
417
+ already_confirmed: i.boolean().nullish()
418
+ }), Y = i.object({
419
+ id: i.string(),
420
+ status: i.string(),
421
+ client_secret: i.string().nullish(),
422
+ payment_method_id: i.string().nullish()
423
+ }), ue = i.object({ client_secret: i.string().nullish() }), de = i.object({
424
+ id: i.string().startsWith("ocs_"),
425
+ url: i.string().url().optional(),
426
+ expires_at: O
427
+ }), X = class extends Error {
428
+ constructor(e = "The wallet request was declined.") {
429
+ super(e), this.name = "WalletRejectedError";
430
+ }
431
+ }, fe = 4, pe = 500, me = 2e3, Z = 300;
432
+ function he(e) {
433
+ let t = ge(e.headers.get("Retry-After"));
434
+ switch (e.status) {
435
+ case 429: return t;
436
+ case 503: return t ?? Z;
437
+ case 502:
438
+ case 504: return Z;
439
+ default: return null;
440
+ }
441
+ }
442
+ function ge(e) {
443
+ if (!e) return null;
444
+ if (/^\d+$/.test(e.trim())) return Number(e.trim()) * 1e3;
445
+ let t = Date.parse(e);
446
+ return Number.isNaN(t) ? null : Math.max(0, t - Date.now());
447
+ }
448
+ function Q(e, t) {
449
+ return new Promise((n, r) => {
450
+ if (t?.aborted) return r(t.reason);
451
+ let i = setTimeout(() => {
452
+ t?.removeEventListener("abort", a), n(e);
453
+ }, e), a = () => {
454
+ clearTimeout(i), r(t?.reason);
455
+ };
456
+ t?.addEventListener("abort", a, { once: !0 });
457
+ });
458
+ }
459
+ function _e(r = {}) {
460
+ let i = (r.baseUrl ?? "/billing/v1").replace(/\/+$/, ""), a = r.fetch ?? ((e, t) => fetch(e, t)), o = ve({
461
+ ...re,
462
+ ...r.currencies
463
+ });
464
+ function s(e, t) {
465
+ let n = new URLSearchParams();
466
+ for (let [e, r] of Object.entries(t ?? {})) r !== void 0 && r !== "" && n.set(e, String(r));
467
+ let r = n.toString();
468
+ return `${i}${e}${r ? `?${r}` : ""}`;
469
+ }
470
+ async function c(t, n = {}) {
471
+ let i = new Headers({
472
+ Accept: "application/json",
473
+ ...n.headers
474
+ });
475
+ n.body !== void 0 && i.set("Content-Type", "application/json");
476
+ let o = n.anonymous ? void 0 : await r.getToken?.();
477
+ o && i.set("Authorization", `Bearer ${o}`);
478
+ let c = r.language?.();
479
+ c && i.set("Accept-Language", c);
480
+ let l = n.method ?? "GET", u = {
481
+ method: l,
482
+ headers: i,
483
+ body: n.body === void 0 ? void 0 : JSON.stringify(n.body),
484
+ signal: n.signal
485
+ }, d = +(l === "GET"), f = 0;
486
+ for (let r = 0;; r++) {
487
+ let i;
488
+ try {
489
+ i = await a(s(t, n.query), u);
490
+ } catch (e) {
491
+ let t = Z;
492
+ if (r >= d || n.signal?.aborted || !(e instanceof TypeError) || f + t > 2e3) throw e;
493
+ f += await Q(t, n.signal);
494
+ continue;
495
+ }
496
+ if (i.ok) return i;
497
+ let o = he(i);
498
+ if (r >= d || o === null || f + o > 2e3) throw await e(i);
499
+ await i.body?.cancel().catch(() => void 0), f += await Q(o, n.signal);
500
+ }
501
+ }
502
+ async function l(e, n, r) {
503
+ let i = await c(n, r), a;
504
+ try {
505
+ a = await i.json();
506
+ } catch {
507
+ throw t("invalid_response", `${n}: body is not JSON`);
508
+ }
509
+ let o = e.safeParse(a);
510
+ if (!o.success) throw t("invalid_response", `${n}: ${o.error.issues[0]?.path.join(".")} ${o.error.issues[0]?.message}`);
511
+ return o.data;
512
+ }
513
+ let u = (e) => encodeURIComponent(e), d = k(I), f = k(L), p = k(R), m = k(U), h = k(H);
514
+ return {
515
+ baseUrl: i,
516
+ listSubscriptions(e = {}) {
517
+ return l(d, "/me/subscriptions", {
518
+ query: {
519
+ status: e.status ?? "all",
520
+ limit: e.limit ?? 100,
521
+ offset: e.offset
522
+ },
523
+ signal: e.signal
524
+ });
525
+ },
526
+ getSubscription(e, t) {
527
+ return l(I, `/me/subscriptions/${u(e)}`, { signal: t });
528
+ },
529
+ async cancelSubscription(e, t) {
530
+ await c(`/me/subscriptions/${u(e)}/cancel`, {
531
+ method: "POST",
532
+ body: { feedback: t.feedback.trim() }
533
+ });
534
+ },
535
+ async resumeSubscription(e) {
536
+ await c(`/me/subscriptions/${u(e)}/resume`, {
537
+ method: "POST",
538
+ body: {}
539
+ });
540
+ },
541
+ async setSubscriptionPaymentMethod(e, t) {
542
+ await c(`/me/subscriptions/${u(e)}/payment-method`, {
543
+ method: "PUT",
544
+ body: { payment_method_id: t }
545
+ });
546
+ },
547
+ previewTierChange(e, t, n) {
548
+ return l(W, `/me/subscriptions/${u(e)}/change-tier/preview`, {
549
+ method: "POST",
550
+ body: { price_id: t },
551
+ signal: n
552
+ });
553
+ },
554
+ changeTier(e, t) {
555
+ return l(G, `/me/subscriptions/${u(e)}/change-tier`, {
556
+ method: "POST",
557
+ body: { price_id: t.priceId },
558
+ headers: { "Idempotency-Key": t.idempotencyKey }
559
+ });
560
+ },
561
+ prepareSolanaTierChange(e, t) {
562
+ return l(ce, `/me/subscriptions/${u(e)}/solana-tier-change`, {
563
+ method: "POST",
564
+ body: { new_price_id: t }
565
+ });
566
+ },
567
+ confirmSolanaTierChange(e, t) {
568
+ return l(le, `/me/subscriptions/${u(e)}/solana-tier-change/confirm`, {
569
+ method: "POST",
570
+ body: {
571
+ signature: t.signature,
572
+ new_price_id: t.newPriceId
573
+ }
574
+ });
575
+ },
576
+ async cancelSubscriptionOnChain(e, n, r) {
577
+ r?.("preparing");
578
+ let { transaction: i } = await l(K, `/me/subscriptions/${u(e)}/solana-cancel-tx`, {
579
+ method: "POST",
580
+ body: {}
581
+ });
582
+ r?.("signing");
583
+ let a;
584
+ try {
585
+ a = await n(i);
586
+ } catch (e) {
587
+ throw $(e) ? t("wallet_rejected", "The wallet request was declined.") : e;
588
+ }
589
+ if (!a) throw t("wallet_no_signature", "The wallet returned no signature.");
590
+ r?.("confirming"), await c(`/me/subscriptions/${u(e)}/solana-cancel`, {
591
+ method: "POST",
592
+ body: { signature: a }
593
+ });
594
+ },
595
+ listPaymentMethods(e = {}) {
596
+ return l(f, "/me/payment-methods", {
597
+ query: {
598
+ limit: e.limit ?? 100,
599
+ offset: e.offset
600
+ },
601
+ signal: e.signal
602
+ });
603
+ },
604
+ addPaymentMethod(e) {
605
+ return l(L, "/me/payment-methods", {
606
+ method: "POST",
607
+ body: e
608
+ });
609
+ },
610
+ createCardSetup(e) {
611
+ return l(Y, "/me/payment-methods/stripe-setup", {
612
+ method: "POST",
613
+ body: {
614
+ psp_id: e.pspId,
615
+ consent: !0
616
+ },
617
+ headers: { "Idempotency-Key": e.idempotencyKey }
618
+ });
619
+ },
620
+ getCardSetup(e, t) {
621
+ return l(Y, `/me/payment-methods/stripe-setup/${u(e)}`, { signal: t });
622
+ },
623
+ confirmCardSetup(e) {
624
+ return l(Y, `/me/payment-methods/stripe-setup/${u(e)}/confirm`, {
625
+ method: "POST",
626
+ body: {}
627
+ });
628
+ },
629
+ getPaymentAuthentication(e) {
630
+ return l(ue, `/me/payment-operations/${u(e)}/authentication`);
631
+ },
632
+ async confirmPaymentAuthentication(e) {
633
+ await c(`/me/payment-operations/${u(e)}/authentication/confirm`, {
634
+ method: "POST",
635
+ body: {}
636
+ });
637
+ },
638
+ async removePaymentMethod(e) {
639
+ return (await c(`/me/payment-methods/${u(e)}`, { method: "DELETE" })).status === 202 ? "pending" : "removed";
640
+ },
641
+ async setDefaultPaymentMethod(e) {
642
+ await c("/me/collection-payment-method", {
643
+ method: "PUT",
644
+ body: {
645
+ currency: e.currency.toUpperCase(),
646
+ payment_method_id: e.paymentMethodId
647
+ }
648
+ });
649
+ },
650
+ listPayments(e = {}) {
651
+ return l(p, "/me/payments", {
652
+ query: {
653
+ limit: e.limit ?? 20,
654
+ offset: e.offset,
655
+ type: e.rail
656
+ },
657
+ signal: e.signal
658
+ });
659
+ },
660
+ async listInvoices(e = {}) {
661
+ let t = await l(ie, "/me/invoices", {
662
+ query: {
663
+ limit: e.limit ?? 20,
664
+ offset: e.offset
665
+ },
666
+ signal: e.signal
667
+ }), n = t.offset ?? e.offset ?? 0;
668
+ return {
669
+ data: t.invoices,
670
+ total: t.total,
671
+ limit: t.limit,
672
+ offset: n,
673
+ has_more: t.total == null ? null : n + t.invoices.length < t.total
674
+ };
675
+ },
676
+ getInvoice(e, t) {
677
+ return l(z, `/me/invoices/${u(e)}`, { signal: t });
678
+ },
679
+ getStatus(e) {
680
+ return l(ae, "/me/status", { signal: e });
681
+ },
682
+ listProducts(e = {}) {
683
+ return l(m, "/products", {
684
+ query: {
685
+ limit: e.limit ?? 100,
686
+ offset: e.offset
687
+ },
688
+ signal: e.signal
689
+ });
690
+ },
691
+ listPrices(e = {}) {
692
+ return l(h, "/prices", {
693
+ query: {
694
+ currency: e.currency,
695
+ product: e.product,
696
+ type: e.type,
697
+ limit: e.limit ?? 100,
698
+ offset: e.offset
699
+ },
700
+ signal: e.signal
701
+ });
702
+ },
703
+ async listCurrencies(e) {
704
+ return (await l(V, "/currencies", { signal: e })).currencies;
705
+ },
706
+ createCheckoutSession(e) {
707
+ return !e.priceKey == !e.priceId ? Promise.reject(t("invalid_request", "Pass exactly one of priceKey or priceId.")) : l(de, "/me/checkout/sessions", {
708
+ method: "POST",
709
+ body: {
710
+ price_key: e.priceKey,
711
+ price_id: e.priceId,
712
+ success_url: e.successUrl
713
+ }
714
+ });
715
+ },
716
+ checkoutSource(e) {
717
+ let t = `/checkout-sessions/${u(e)}`;
718
+ return {
719
+ getSession: () => l(T, t, { anonymous: !0 }),
720
+ async pay(e) {
721
+ try {
722
+ return await l(E, `${t}/pay`, {
723
+ method: "POST",
724
+ body: e,
725
+ anonymous: !0
726
+ });
727
+ } catch (e) {
728
+ if (!n(e)) throw e;
729
+ switch (e.status) {
730
+ case 404:
731
+ case 410: return { status: "expired" };
732
+ case 403: return {
733
+ status: "blocked",
734
+ failure_message: e.message
735
+ };
736
+ case 422:
737
+ case 429: return {
738
+ status: "failed",
739
+ failure_message: e.message
740
+ };
741
+ }
742
+ throw e;
743
+ }
744
+ }
745
+ };
746
+ },
747
+ getSolanaConfig(e) {
748
+ return l(se, "/solana/config", { signal: e });
749
+ },
750
+ async listSolanaTokens(e = {}) {
751
+ let { tokens: t } = await l(oe, "/solana/tokens", {
752
+ query: {
753
+ price_id: e.priceId,
754
+ checkout_session_id: e.checkoutSessionId,
755
+ wallet: e.wallet
756
+ },
757
+ signal: e.signal
758
+ });
759
+ return t;
760
+ },
761
+ currencies: o
762
+ };
763
+ }
764
+ function ve(e) {
765
+ return Object.fromEntries(Object.entries(e).map(([e, t]) => [e.toUpperCase(), t]));
766
+ }
767
+ var $ = (e) => e instanceof X || e instanceof Error && e.name === "WalletRejectedError" || e instanceof r && e.code === "wallet_rejected";
768
+ //#endregion
769
+ export { _, _e as a, h as b, C as c, y as d, ne as f, S as g, x as h, X as i, w as l, b as m, fe as n, $ as o, E as p, me as r, g as s, pe as t, T as u, u as v, c as x, m as y };
770
+
771
+ //# sourceMappingURL=client-DhG2jv34.js.map