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