@voltro/plugin-billing 0.90.0 → 0.91.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.
@@ -1,7 +1,7 @@
1
- import { BillingError as e } from "./types.js";
1
+ import { stripeInvoicePayments as e } from "./stripeInvoicePayments.js";
2
2
  import { assertInvoiceSnapshot as t, invoiceSnapshotError as n } from "./invoiceSnapshot.js";
3
3
  import { stripeCall as r } from "./stripeClient.js";
4
- import { stripeInvoicePayments as i } from "./stripeInvoicePayments.js";
4
+ import { BillingError as i } from "./types.js";
5
5
  import { Effect as a } from "effect";
6
6
  // src/stripeInvoiceSnapshot.ts
7
7
  var o = (e) => typeof e == "string" ? e : e?.id ?? null, s = (e) => {
@@ -9,9 +9,9 @@ var o = (e) => typeof e == "string" ? e : e?.id ?? null, s = (e) => {
9
9
  let t = /* @__PURE__ */ new Date(e * 1e3);
10
10
  if (!Number.isFinite(t.getTime())) throw n("The invoice timestamp is outside the supported range.");
11
11
  return t;
12
- }, c = (t) => a.try({
13
- try: t,
14
- catch: (t) => t instanceof e ? t : n("The provider invoice observation could not be confirmed.")
12
+ }, c = (e) => a.try({
13
+ try: e,
14
+ catch: (e) => e instanceof i ? e : n("The provider invoice observation could not be confirmed.")
15
15
  }), l = (e, t) => {
16
16
  if (e.id !== t.providerInvoiceId || o(e.customer) !== t.providerCustomerId) throw n("The invoice does not belong to the linked billing customer.");
17
17
  let r = e.status;
@@ -53,32 +53,32 @@ var o = (e) => typeof e == "string" ? e : e?.id ?? null, s = (e) => {
53
53
  periodEnd: s(e.period.end),
54
54
  proration: i?.proration ?? a?.proration ?? null
55
55
  };
56
- }, d = (e, o) => {
56
+ }, d = (i, o) => {
57
57
  let s = Object.freeze({
58
58
  providerCustomerId: o.providerCustomerId,
59
59
  providerInvoiceId: o.providerInvoiceId
60
60
  });
61
61
  return [s.providerCustomerId, s.providerInvoiceId].every((e) => typeof e == "string" && e.length > 0 && e.trim() === e) ? a.gen(function* () {
62
- let o = yield* r("stripe.invoices.retrieve", () => e.invoices.retrieve(s.providerInvoiceId)), d = yield* c(() => l(o, s)), f = [], p = /* @__PURE__ */ new Set(), m, h = !1;
63
- for (let t = 0; t < 100; t++) {
64
- let t = yield* r("stripe.invoices.listLineItems", () => e.invoices.listLineItems(s.providerInvoiceId, {
62
+ let o = yield* r("stripe.invoices.retrieve", () => i.invoices.retrieve(s.providerInvoiceId)), d = yield* c(() => l(o, s)), f = [], p = /* @__PURE__ */ new Set(), m, h = !1;
63
+ for (let e = 0; e < 100; e++) {
64
+ let e = yield* r("stripe.invoices.listLineItems", () => i.invoices.listLineItems(s.providerInvoiceId, {
65
65
  limit: 100,
66
66
  ...m === void 0 ? {} : { starting_after: m }
67
67
  }));
68
68
  if (yield* c(() => {
69
- if (!Array.isArray(t.data) || t.data.length > 100 || typeof t.has_more != "boolean" || (t.has_more || m !== void 0) && t.data.length === 0) throw n("The invoice line page is incomplete.");
70
- for (let e of t.data) {
71
- if (typeof e.id != "string" || e.id.length === 0 || p.has(e.id)) throw n("The invoice line cursor repeated an identity.", !0);
72
- p.add(e.id), f.push(u(e, s.providerInvoiceId));
69
+ if (!Array.isArray(e.data) || e.data.length > 100 || typeof e.has_more != "boolean" || (e.has_more || m !== void 0) && e.data.length === 0) throw n("The invoice line page is incomplete.");
70
+ for (let t of e.data) {
71
+ if (typeof t.id != "string" || t.id.length === 0 || p.has(t.id)) throw n("The invoice line cursor repeated an identity.", !0);
72
+ p.add(t.id), f.push(u(t, s.providerInvoiceId));
73
73
  }
74
- }), !t.has_more) {
74
+ }), !e.has_more) {
75
75
  h = !0;
76
76
  break;
77
77
  }
78
- m = t.data[t.data.length - 1]?.id;
78
+ m = e.data[e.data.length - 1]?.id;
79
79
  }
80
80
  if (!h) return yield* a.fail(n("The invoice exceeds the complete observation bound."));
81
- let g = yield* i(e, {
81
+ let g = yield* e(i, {
82
82
  providerInvoiceId: d.providerInvoiceId,
83
83
  providerCustomerId: d.providerCustomerId,
84
84
  currency: d.currency,
@@ -88,7 +88,7 @@ var o = (e) => typeof e == "string" ? e : e?.id ?? null, s = (e) => {
88
88
  invoiceTotalMinor: d.invoiceTotalMinor,
89
89
  startingBalanceMinor: d.startingBalanceMinor,
90
90
  endingBalanceMinor: d.endingBalanceMinor
91
- }), _ = yield* r("stripe.invoices.retrieve", () => e.invoices.retrieve(s.providerInvoiceId)), v = yield* c(() => l(_, s));
91
+ }), _ = yield* r("stripe.invoices.retrieve", () => i.invoices.retrieve(s.providerInvoiceId)), v = yield* c(() => l(_, s));
92
92
  if (JSON.stringify(d) !== JSON.stringify(v)) return yield* a.fail(n("The invoice changed during observation; retry the complete read.", !0));
93
93
  let { prePaymentCreditNotesMinor: y, postPaymentCreditNotesMinor: b, invoiceTotalMinor: x, startingBalanceMinor: S, endingBalanceMinor: C, ...w } = v;
94
94
  if (y !== g.prePaymentCreditNotesMinor || b !== g.postPaymentCreditNotesMinor) return yield* a.fail(n("Invoice credit-note totals changed during payment observation.", !0));
@@ -1,9 +1,9 @@
1
1
  import { BillingError as e } from "./types.js";
2
- import { invoiceHistoryPreview as t } from "./invoiceHistory.js";
3
- import { Stripe as n, makeStripeClient as r, periodOf as i, quantityOf as a, stripeCall as o, unixToDate as s } from "./stripeClient.js";
4
- import { stripeInvoiceSnapshot as c } from "./stripeInvoiceSnapshot.js";
5
- import { stripeAccountIdentity as l, stripeCustomerSnapshot as u } from "./stripeIdentity.js";
6
- import { stripeInvoiceHistory as d } from "./stripeInvoiceHistory.js";
2
+ import { Stripe as t, makeStripeClient as n, periodOf as r, quantityOf as i, stripeCall as a, unixToDate as o } from "./stripeClient.js";
3
+ import { stripeInvoiceSnapshot as s } from "./stripeInvoiceSnapshot.js";
4
+ import { stripeInvoiceHistory as c } from "./stripeInvoiceHistory.js";
5
+ import { invoiceHistoryPreview as l } from "./invoiceHistory.js";
6
+ import { stripeAccountIdentity as u, stripeCustomerSnapshot as d } from "./stripeIdentity.js";
7
7
  import { verifyStripeBillingEvent as f } from "./stripeVerifiedEvent.js";
8
8
  import { Effect as p } from "effect";
9
9
  // src/stripeProvider.ts
@@ -26,9 +26,9 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
26
26
  expiresAt: n
27
27
  };
28
28
  }, _ = (e) => {
29
- if (!(e instanceof n.errors.StripeInvalidRequestError || e instanceof n.errors.StripeCardError || e instanceof n.errors.StripePermissionError || e instanceof n.errors.StripeAuthenticationError)) return null;
30
- let t = typeof e.code == "string" && /^[a-z0-9_]{1,80}$/.test(e.code) ? ` (${e.code})` : "";
31
- return (/^[A-Za-z_]{1,80}$/.test(e.type) ? e.type : "StripeError") + t;
29
+ if (!(e instanceof t.errors.StripeInvalidRequestError || e instanceof t.errors.StripeCardError || e instanceof t.errors.StripePermissionError || e instanceof t.errors.StripeAuthenticationError)) return null;
30
+ let n = typeof e.code == "string" && /^[a-z0-9_]{1,80}$/.test(e.code) ? ` (${e.code})` : "";
31
+ return (/^[A-Za-z_]{1,80}$/.test(e.type) ? e.type : "StripeError") + n;
32
32
  }, v = {
33
33
  active: "active",
34
34
  trialing: "trialing",
@@ -60,7 +60,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
60
60
  };
61
61
  }, w = (e, t) => {
62
62
  let { pricing: n, item: r } = C(e, t);
63
- return n === null ? a(e) : n.includedSeats + (r?.quantity ?? 0);
63
+ return n === null ? i(e) : n.includedSeats + (r?.quantity ?? 0);
64
64
  }, T = (e) => typeof e == "string" ? e : typeof e?.id == "string" ? e.id : null, E = (e, t, n) => {
65
65
  let r = S(e, n), i = r !== null && t ? t(r) : null;
66
66
  if (i !== null) return i;
@@ -98,26 +98,26 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
98
98
  "invoice.paid",
99
99
  "invoice.payment_failed",
100
100
  ...D
101
- ], k = (t, n, r) => {
102
- let a = s(t.created);
101
+ ], k = (t, n, i) => {
102
+ let a = o(t.created);
103
103
  switch (t.type) {
104
104
  case "customer.subscription.created":
105
105
  case "customer.subscription.updated":
106
106
  case "customer.subscription.resumed":
107
107
  case "customer.subscription.paused": {
108
- let e = t.data.object, o = y(e), c = E(e, n, r), l = v[e.status];
109
- if (o === null || c === null || l === void 0) return null;
110
- let u = i(e);
108
+ let e = t.data.object, s = y(e), c = E(e, n, i), l = v[e.status];
109
+ if (s === null || c === null || l === void 0) return null;
110
+ let u = r(e);
111
111
  return {
112
112
  _tag: "subscriptionUpserted",
113
- tenantId: o,
113
+ tenantId: s,
114
114
  providerSubscriptionId: e.id,
115
115
  plan: c,
116
116
  status: l,
117
- quantity: w(e, r),
117
+ quantity: w(e, i),
118
118
  currentPeriodStart: u.start,
119
119
  currentPeriodEnd: u.end,
120
- cancelAt: s(e.cancel_at),
120
+ cancelAt: o(e.cancel_at),
121
121
  occurredAt: a
122
122
  };
123
123
  }
@@ -198,7 +198,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
198
198
  occurredAt: n
199
199
  };
200
200
  }, j = (t, n, r, i) => p.gen(function* () {
201
- let a = yield* p.try({
201
+ let s = yield* p.try({
202
202
  try: () => k(n, r, i),
203
203
  catch: (t) => t instanceof e ? t : new e({
204
204
  source: "stripe.normalizeEvent",
@@ -206,14 +206,14 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
206
206
  transient: !1
207
207
  })
208
208
  });
209
- if (a !== null || !D.includes(n.type)) return a;
210
- let c = yield* l(t);
209
+ if (s !== null || !D.includes(n.type)) return s;
210
+ let c = yield* u(t);
211
211
  if (n.livemode !== c.livemode || n.account !== void 0 && n.account !== null && n.account !== c.providerAccountId) return yield* p.fail(new e({
212
212
  source: "stripe.normalizeEvent",
213
213
  message: "The payment correction belongs to another Stripe account or mode.",
214
214
  transient: !1
215
215
  }));
216
- let u = null;
216
+ let l = null;
217
217
  switch (n.type) {
218
218
  case "charge.dispute.created":
219
219
  case "charge.dispute.updated":
@@ -229,13 +229,13 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
229
229
  message: "The payment correction has no original charge identity.",
230
230
  transient: !1
231
231
  }));
232
- let i = yield* o("stripe.charges.retrieve", () => t.charges.retrieve(r));
232
+ let i = yield* a("stripe.charges.retrieve", () => t.charges.retrieve(r));
233
233
  if (i.id !== r || i.livemode !== c.livemode) return yield* p.fail(new e({
234
234
  source: "stripe.normalizeEvent",
235
235
  message: "The original correction charge could not be confirmed.",
236
236
  transient: !1
237
237
  }));
238
- u = T(i.customer);
238
+ l = T(i.customer);
239
239
  break;
240
240
  }
241
241
  case "invoice_payment.paid": {
@@ -245,13 +245,13 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
245
245
  message: "The payment allocation has no invoice identity.",
246
246
  transient: !1
247
247
  }));
248
- let i = yield* o("stripe.invoices.retrieve", () => t.invoices.retrieve(r));
248
+ let i = yield* a("stripe.invoices.retrieve", () => t.invoices.retrieve(r));
249
249
  if (i.id !== r || i.livemode !== c.livemode) return yield* p.fail(new e({
250
250
  source: "stripe.normalizeEvent",
251
251
  message: "The payment allocation invoice could not be confirmed.",
252
252
  transient: !1
253
253
  }));
254
- u = T(i.customer);
254
+ l = T(i.customer);
255
255
  break;
256
256
  }
257
257
  default: return yield* p.fail(new e({
@@ -260,13 +260,13 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
260
260
  transient: !1
261
261
  }));
262
262
  }
263
- let d = yield* l(t);
263
+ let d = yield* u(t);
264
264
  return d.providerAccountId !== c.providerAccountId || d.livemode !== c.livemode ? yield* p.fail(new e({
265
265
  source: "stripe.normalizeEvent",
266
266
  message: "The Stripe account changed during payment correction discovery.",
267
267
  transient: !0
268
268
  })) : yield* p.try({
269
- try: () => A(u, s(n.created)),
269
+ try: () => A(l, o(n.created)),
270
270
  catch: (t) => t instanceof e ? t : new e({
271
271
  source: "stripe.normalizeEvent",
272
272
  message: "The correction customer could not be confirmed.",
@@ -299,16 +299,16 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
299
299
  interval: P(e.recurring?.interval),
300
300
  usageType: I(e.recurring?.usage_type)
301
301
  };
302
- }, U = (a) => {
303
- let b = r(a), D = a.planForPriceId, k = a.seatPricingForPriceId, A = (e) => {
304
- let t = i(e);
302
+ }, U = (i) => {
303
+ let b = n(i), D = i.planForPriceId, k = i.seatPricingForPriceId, A = (e) => {
304
+ let t = r(e);
305
305
  return {
306
306
  status: v[e.status] ?? "incomplete",
307
307
  plan: E(e, D, k),
308
308
  quantity: w(e, k),
309
309
  currentPeriodStart: t.start,
310
310
  currentPeriodEnd: t.end,
311
- cancelAt: s(e.cancel_at)
311
+ cancelAt: o(e.cancel_at)
312
312
  };
313
313
  }, N = (e) => {
314
314
  let t = x(e, k), n = C(e, k);
@@ -332,7 +332,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
332
332
  })(),
333
333
  priceIds: (e.items?.data ?? []).map((e) => e.price?.id).filter((e) => typeof e == "string")
334
334
  };
335
- }, P = a.closeSettleSeconds ?? 600;
335
+ }, P = i.closeSettleSeconds ?? 600;
336
336
  if (!Number.isSafeInteger(P) || P < 0) throw TypeError("closeSettleSeconds must be a nonnegative integer.");
337
337
  let F = (e) => {
338
338
  let t = e.lastResponse.headers.date, n = typeof t == "string" ? Date.parse(t) : NaN;
@@ -360,12 +360,12 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
360
360
  expand: ["items.data.price"]
361
361
  }, { idempotencyKey: a + ":schedule" });
362
362
  }, U = (e) => b.subscriptions.retrieve(e, { expand: ["items.data.price"] }), q = (e, t) => {
363
- let n = i(e), r = x(e, k)?.price;
363
+ let n = r(e), i = x(e, k)?.price;
364
364
  return {
365
365
  plan: E(e, D, k) ?? "free",
366
366
  quantity: w(e, k),
367
367
  prorationMinor: t,
368
- currency: (r?.currency ?? "usd").toLowerCase(),
368
+ currency: (i?.currency ?? "usd").toLowerCase(),
369
369
  currentPeriodStart: n.start,
370
370
  currentPeriodEnd: n.end
371
371
  };
@@ -477,9 +477,9 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
477
477
  return {
478
478
  name: "stripe",
479
479
  supportsNativeSubscriptionWrites: !0,
480
- fetchAccountIdentity: () => l(b),
481
- fetchCustomerSnapshot: (e) => u(b, e),
482
- fetchPrices: (e) => o("stripe.prices.retrieve", async () => {
480
+ fetchAccountIdentity: () => u(b),
481
+ fetchCustomerSnapshot: (e) => d(b, e),
482
+ fetchPrices: (e) => a("stripe.prices.retrieve", async () => {
483
483
  let t = [...new Set(e)].filter((e) => e.length > 0), n = [];
484
484
  for (let e = 0; e < t.length; e += R) {
485
485
  let r = await Promise.all(t.slice(e, e + R).map(async (e) => {
@@ -494,7 +494,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
494
494
  }
495
495
  return n;
496
496
  }),
497
- fetchPriceVersions: (e) => o("stripe.prices.list", async () => {
497
+ fetchPriceVersions: (e) => a("stripe.prices.list", async () => {
498
498
  let t;
499
499
  try {
500
500
  t = await b.prices.retrieve(e);
@@ -524,7 +524,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
524
524
  }
525
525
  throw Error("price history exceeds the bounded read");
526
526
  }),
527
- fetchPriceMeters: (e) => o("stripe.billing.meters.retrieve", async () => {
527
+ fetchPriceMeters: (e) => a("stripe.billing.meters.retrieve", async () => {
528
528
  let t = /* @__PURE__ */ new Map(), n = [];
529
529
  for (let r of [...new Set(e)].filter((e) => e.length > 0)) {
530
530
  let e;
@@ -544,18 +544,18 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
544
544
  }
545
545
  return n;
546
546
  }),
547
- ensureInvoiceItem: (e) => o("stripe.invoiceItems.create", async () => {
548
- let t = { gte: Math.floor(e.notBefore.getTime() / 1e3) }, r;
549
- for (let n = 0; n < z; n++) {
547
+ ensureInvoiceItem: (e) => a("stripe.invoiceItems.create", async () => {
548
+ let n = { gte: Math.floor(e.notBefore.getTime() / 1e3) }, r;
549
+ for (let t = 0; t < z; t++) {
550
550
  let i = await b.invoiceItems.list({
551
551
  customer: e.providerCustomerId,
552
- created: t,
552
+ created: n,
553
553
  limit: 100,
554
554
  ...r === void 0 ? {} : { starting_after: r }
555
555
  }), a = i.data.find((t) => t.metadata?.[B] === e.idempotencyKey);
556
556
  if (a !== void 0) return { providerInvoiceItemId: a.id };
557
557
  if (!i.has_more || (r = i.data.at(-1)?.id, r === void 0)) break;
558
- if (n === 9) throw Error("invoice item lookup exceeds the bounded read");
558
+ if (t === 9) throw Error("invoice item lookup exceeds the bounded read");
559
559
  }
560
560
  return { providerInvoiceItemId: (await b.invoiceItems.create({
561
561
  customer: e.providerCustomerId,
@@ -563,7 +563,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
563
563
  price_data: {
564
564
  currency: e.currency,
565
565
  product: e.productId,
566
- unit_amount_decimal: n.Decimal.from(e.unitAmountDecimal),
566
+ unit_amount_decimal: t.Decimal.from(e.unitAmountDecimal),
567
567
  ...e.taxBehavior === null ? {} : { tax_behavior: e.taxBehavior }
568
568
  },
569
569
  quantity: e.quantity,
@@ -575,9 +575,9 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
575
575
  metadata: { [B]: e.idempotencyKey }
576
576
  }, { idempotencyKey: e.idempotencyKey })).id };
577
577
  }),
578
- supportsMeteredUsage: a.supportsMeteredUsage ?? !0,
578
+ supportsMeteredUsage: i.supportsMeteredUsage ?? !0,
579
579
  usageRequiresCustomer: !0,
580
- createCheckoutSession: (e) => o("stripe.checkout.sessions.create", async () => g(await b.checkout.sessions.create({
580
+ createCheckoutSession: (e) => a("stripe.checkout.sessions.create", async () => g(await b.checkout.sessions.create({
581
581
  mode: "subscription",
582
582
  integration_identifier: await h(e.idempotencyKey),
583
583
  line_items: [...Q(e), ...(e.meteredPriceIds ?? []).map((e) => ({ price: e }))],
@@ -602,7 +602,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
602
602
  } },
603
603
  allow_promotion_codes: !0
604
604
  }, e.idempotencyKey === void 0 ? void 0 : { idempotencyKey: e.idempotencyKey }))),
605
- findCheckoutSession: (e) => o("stripe.checkout.sessions.find", async () => {
605
+ findCheckoutSession: (e) => a("stripe.checkout.sessions.find", async () => {
606
606
  let t = null, n = 0, r, i = null;
607
607
  do {
608
608
  let a = await b.checkout.sessions.list({
@@ -630,7 +630,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
630
630
  r = o;
631
631
  } while (1);
632
632
  }),
633
- createPortalSession: (e) => o("stripe.billingPortal.sessions.create", async () => ({ url: (await b.billingPortal.sessions.create({
633
+ createPortalSession: (e) => a("stripe.billingPortal.sessions.create", async () => ({ url: (await b.billingPortal.sessions.create({
634
634
  customer: e.providerCustomerId,
635
635
  return_url: e.returnUrl
636
636
  })).url })),
@@ -640,7 +640,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
640
640
  source: "stripe.billing.meterEvents.create",
641
641
  message: `no Stripe customer linked for tenant '${t.tenantId}'`,
642
642
  transient: !1
643
- })) : o("stripe.billing.meterEvents.create", async () => {
643
+ })) : a("stripe.billing.meterEvents.create", async () => {
644
644
  try {
645
645
  await b.billing.meterEvents.create({
646
646
  event_name: t.entitlementKey,
@@ -656,11 +656,11 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
656
656
  }
657
657
  });
658
658
  },
659
- updateSubscription: (e) => o("stripe.subscriptions.update", async () => {
659
+ updateSubscription: (e) => a("stripe.subscriptions.update", async () => {
660
660
  let t = await Z(e.providerSubscriptionId, e.operation, (t) => X(t, e));
661
661
  return q(t, null);
662
662
  }),
663
- previewSubscriptionChange: (e) => o("stripe.invoices.createPreview", async () => {
663
+ previewSubscriptionChange: (e) => a("stripe.invoices.createPreview", async () => {
664
664
  let t = await U(e.providerSubscriptionId), n = await X(t, e), r = (await b.invoices.createPreview({
665
665
  subscription: e.providerSubscriptionId,
666
666
  subscription_details: {
@@ -675,23 +675,23 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
675
675
  ...e.priceId !== void 0 && D ? { plan: D(e.priceId) ?? "free" } : {}
676
676
  };
677
677
  }),
678
- fetchSubscriptionSnapshot: (e) => o("stripe.subscriptions.retrieve", async () => {
678
+ fetchSubscriptionSnapshot: (e) => a("stripe.subscriptions.retrieve", async () => {
679
679
  try {
680
680
  return N(await U(e));
681
681
  } catch (e) {
682
- if (e instanceof n.errors.StripeInvalidRequestError && e.statusCode === 404) return null;
682
+ if (e instanceof t.errors.StripeInvalidRequestError && e.statusCode === 404) return null;
683
683
  throw e;
684
684
  }
685
685
  }),
686
- fetchSubscription: (e) => o("stripe.subscriptions.retrieve", async () => {
686
+ fetchSubscription: (e) => a("stripe.subscriptions.retrieve", async () => {
687
687
  try {
688
688
  return A(await U(e));
689
689
  } catch (e) {
690
- if (e instanceof n.errors.StripeInvalidRequestError && e.statusCode === 404) return null;
690
+ if (e instanceof t.errors.StripeInvalidRequestError && e.statusCode === 404) return null;
691
691
  throw e;
692
692
  }
693
693
  }),
694
- listSubscriptions: (e) => o("stripe.subscriptions.list", async () => {
694
+ listSubscriptions: (e) => a("stripe.subscriptions.list", async () => {
695
695
  let t = [];
696
696
  for await (let n of b.subscriptions.list({
697
697
  limit: 100,
@@ -700,23 +700,23 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
700
700
  })) t.push(N(n));
701
701
  return t;
702
702
  }),
703
- prepareSubscriptionClose: (e) => o("stripe.subscriptions.closeQuote", async () => {
703
+ prepareSubscriptionClose: (e) => a("stripe.subscriptions.closeQuote", async () => {
704
704
  let t = await b.subscriptions.retrieve(e, { expand: ["items.data.price"] });
705
705
  return { cancelAt: new Date(F(t) + P * 1e3) };
706
706
  }),
707
- cancelSubscription: (e) => o("stripe.subscriptions.cancel", async () => A(await I(e))),
708
- resumeSubscription: (e, t) => o("stripe.subscriptions.update", async () => A(await Z(e, t, () => ({
707
+ cancelSubscription: (e) => a("stripe.subscriptions.cancel", async () => A(await I(e))),
708
+ resumeSubscription: (e, t) => a("stripe.subscriptions.update", async () => A(await Z(e, t, () => ({
709
709
  cancel_at_period_end: !1,
710
710
  expand: ["items.data.price"]
711
711
  })))),
712
- ensureCustomer: (e) => o("stripe.customers.create", async () => {
712
+ ensureCustomer: (e) => a("stripe.customers.create", async () => {
713
713
  let t = (await b.customers.search({
714
714
  query: `metadata['tenantId']:'${e.tenantId.replace(/['\\]/g, "")}'`,
715
715
  limit: 2
716
716
  })).data.find((t) => t.metadata?.tenantId === e.tenantId);
717
717
  return t === void 0 ? (await b.customers.create({ metadata: { tenantId: e.tenantId } }, { idempotencyKey: `voltro-billing-customer:${e.tenantId}` })).id : t.id;
718
718
  }),
719
- expireOpenCheckouts: (e) => o("stripe.checkout.sessions.expire", async () => {
719
+ expireOpenCheckouts: (e) => a("stripe.checkout.sessions.expire", async () => {
720
720
  let t = 0;
721
721
  for await (let n of b.checkout.sessions.list({
722
722
  customer: e.providerCustomerId,
@@ -725,7 +725,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
725
725
  })) (e.exceptOperationId === void 0 || n.metadata?.voltroBillingOperation !== e.exceptOperationId) && (await b.checkout.sessions.expire(n.id), t += 1);
726
726
  return t;
727
727
  }),
728
- addSubscriptionPrices: (e) => o("stripe.subscriptionItems.create", async () => {
728
+ addSubscriptionPrices: (e) => a("stripe.subscriptionItems.create", async () => {
729
729
  let t = e.providerSubscriptionId, n = async () => {
730
730
  let e = [];
731
731
  for await (let n of b.subscriptionItems.list({
@@ -754,21 +754,21 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
754
754
  }
755
755
  }
756
756
  }),
757
- customerEmail: (e) => o("stripe.customers.retrieve", async () => {
757
+ customerEmail: (e) => a("stripe.customers.retrieve", async () => {
758
758
  let t = await b.customers.retrieve(e);
759
759
  return t.deleted === !0 ? null : typeof t.email == "string" && t.email.length > 0 ? t.email : null;
760
760
  }),
761
- fetchInvoiceSnapshot: (e) => c(b, e),
762
- listInvoiceHistory: (e) => d(b, e),
763
- listInvoices: (e) => l(b).pipe(p.flatMap((t) => d(b, {
761
+ fetchInvoiceSnapshot: (e) => s(b, e),
762
+ listInvoiceHistory: (e) => c(b, e),
763
+ listInvoices: (e) => u(b).pipe(p.flatMap((t) => c(b, {
764
764
  account: t,
765
765
  providerCustomerId: e.providerCustomerId,
766
766
  limit: e.limit ?? 20
767
- })), p.map((e) => e.invoices.map(t))),
767
+ })), p.map((e) => e.invoices.map(l))),
768
768
  verifyWebhook: (e) => f(b, e),
769
769
  eventContext: (e) => K(e) ? {
770
770
  providerCustomerId: G(e.data.object),
771
- createdAt: s(e.created)
771
+ createdAt: o(e.created)
772
772
  } : {
773
773
  providerCustomerId: null,
774
774
  createdAt: null
@@ -784,7 +784,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
784
784
  transient: !1
785
785
  })
786
786
  });
787
- let n = yield* l(b), r = yield* o("stripe.events.list", () => b.events.list({
787
+ let n = yield* u(b), r = yield* a("stripe.events.list", () => b.events.list({
788
788
  delivery_success: !1,
789
789
  limit: t.limit,
790
790
  ...t.cursor === null ? {} : { starting_after: t.cursor }
@@ -803,7 +803,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
803
803
  let t = {
804
804
  id: e.id,
805
805
  providerCustomerId: G(e.data.object),
806
- createdAt: s(e.created)
806
+ createdAt: o(e.created)
807
807
  };
808
808
  return O.includes(e.type) ? e.livemode !== n.livemode || e.account !== void 0 && e.account !== null && e.account !== n.providerAccountId ? p.succeed({
809
809
  ...t,
@@ -822,8 +822,8 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
822
822
  providerCustomerId: null,
823
823
  event: null
824
824
  });
825
- }), a = yield* l(b);
826
- if (a.providerAccountId !== n.providerAccountId || a.livemode !== n.livemode) return yield* p.fail(new e({
825
+ }), s = yield* u(b);
826
+ if (s.providerAccountId !== n.providerAccountId || s.livemode !== n.livemode) return yield* p.fail(new e({
827
827
  source: "stripe.events.list",
828
828
  message: "The Stripe account changed during event recovery.",
829
829
  transient: !0
@@ -840,7 +840,7 @@ var m = async (e) => [...new Uint8Array(await globalThis.crypto.subtle.digest("S
840
840
  }),
841
841
  normalizeEvent: (e) => K(e) ? j(b, e, D, k) : p.succeed(null)
842
842
  };
843
- }, W = (e) => e instanceof n.errors.StripeInvalidRequestError && typeof e.message == "string" && e.message.startsWith("An event already exists with identifier"), G = (e) => {
843
+ }, W = (e) => e instanceof t.errors.StripeInvalidRequestError && typeof e.message == "string" && e.message.startsWith("An event already exists with identifier"), G = (e) => {
844
844
  let t = e;
845
845
  return t.object === "customer" ? typeof t.id == "string" ? t.id : null : T(t.customer ?? null);
846
846
  }, K = (e) => typeof e == "object" && !!e && typeof e.type == "string" && typeof e.data == "object";
@@ -1,6 +1,6 @@
1
- import { STRIPE_API_VERSION as e } from "./catalog.js";
1
+ import e from "stripe";
2
2
  // src/stripeRest.ts
3
- var t = (e) => {
3
+ var t = e.API_VERSION, n = (e) => {
4
4
  let t = [], n = (e, r) => {
5
5
  if (r !== void 0) {
6
6
  if (r === null) t.push(`${encodeURIComponent(e)}=`);
@@ -11,24 +11,24 @@ var t = (e) => {
11
11
  };
12
12
  for (let [t, r] of Object.entries(e)) n(t, r);
13
13
  return t.join("&");
14
- }, n = (e) => e.replace(/\b(sk|rk|rkcs|pk)_(test|live)_[A-Za-z0-9*]+/g, "$1_$2_[REDACTED]").replace(/\bwhsec_[A-Za-z0-9]+/g, "whsec_[REDACTED]"), r = class extends Error {
14
+ }, r = (e) => e.replace(/\b(sk|rk|rkcs|pk)_(test|live)_[A-Za-z0-9*]+/g, "$1_$2_[REDACTED]").replace(/\bwhsec_[A-Za-z0-9]+/g, "whsec_[REDACTED]"), i = class extends Error {
15
15
  status;
16
16
  constructor(e, t) {
17
17
  super(t), this.status = e;
18
18
  }
19
- }, i = (i, a = fetch) => {
19
+ }, a = (e, a = fetch) => {
20
20
  let o = async (o, s, c = {}) => {
21
- if (!/^\/v[12]\/[A-Za-z0-9_/.-]+$/.test(s)) throw new r(0, `refusing request path ${JSON.stringify(s)}`);
22
- let l = t(c), u = await a(`https://api.stripe.com${s}${o === "GET" && l.length > 0 ? `?${l}` : ""}`, {
21
+ if (!/^\/v[12]\/[A-Za-z0-9_/.-]+$/.test(s)) throw new i(0, `refusing request path ${JSON.stringify(s)}`);
22
+ let l = n(c), u = await a(`https://api.stripe.com${s}${o === "GET" && l.length > 0 ? `?${l}` : ""}`, {
23
23
  method: o,
24
24
  headers: {
25
- authorization: `Bearer ${i}`,
26
- "stripe-version": e,
25
+ authorization: `Bearer ${e}`,
26
+ "stripe-version": t,
27
27
  ...o === "POST" ? { "content-type": "application/x-www-form-urlencoded" } : {}
28
28
  },
29
29
  ...o === "POST" ? { body: l } : {}
30
30
  }), d = await u.json();
31
- if (!u.ok) throw new r(u.status, n(d.error?.message ?? `HTTP ${u.status}`));
31
+ if (!u.ok) throw new i(u.status, r(d.error?.message ?? `HTTP ${u.status}`));
32
32
  return d;
33
33
  };
34
34
  return {
@@ -48,4 +48,4 @@ var t = (e) => {
48
48
  }
49
49
  };
50
50
  };
51
- export { r as StripeRestError, t as formEncode, n as redactStripeKeys, i as stripeRest };
51
+ export { t as STRIPE_API_VERSION, i as StripeRestError, n as formEncode, r as redactStripeKeys, a as stripeRest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-billing",
3
- "version": "0.90.0",
3
+ "version": "0.91.0",
4
4
  "description": "Billing on the official Stripe SDK — subscriptions, plans, entitlements and usage metering. Proration, failed-payment retries, tax, promotion codes, trials and the checkout seat stepper are Stripe's own; the plugin adds the entitlement engine, the enforce interceptor, typed BillingError/EntitlementExceeded, the /billing/webhook mount with Stripe's signature verification, the BillingService Tag, requireEntitlement(), and a browser-safe useStartCheckout() hook. Money is integer minor units end-to-end.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -53,18 +53,18 @@
53
53
  "node": ">=24.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@voltro/database": "0.90.0",
57
- "@voltro/env": "0.90.0",
58
- "@voltro/logger": "0.90.0",
59
- "@voltro/plugin-webhooks": "0.90.0",
60
- "@voltro/protocol": "0.90.0",
61
- "@voltro/runtime": "0.90.0"
56
+ "@voltro/database": "0.91.0",
57
+ "@voltro/env": "0.91.0",
58
+ "@voltro/logger": "0.91.0",
59
+ "@voltro/plugin-webhooks": "0.91.0",
60
+ "@voltro/protocol": "0.91.0",
61
+ "@voltro/runtime": "0.91.0"
62
62
  },
63
63
  "peerDependencies": {
64
- "effect": "4.1.2",
64
+ "effect": "4.1.4",
65
65
  "react": "^19.0.0",
66
66
  "stripe": "^22.6.1 || ^23.0.1",
67
- "@voltro/plugin-economy": "0.90.0"
67
+ "@voltro/plugin-economy": "0.91.0"
68
68
  },
69
69
  "peerDependenciesMeta": {
70
70
  "react": {