@voltro/plugin-billing 0.86.0 → 0.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +5484 -0
  2. package/README.md +428 -0
  3. package/THIRD-PARTY-NOTICES.md +1511 -276
  4. package/dist/catalog.js +1 -2
  5. package/dist/checkoutStore.js +164 -0
  6. package/dist/closeStore.js +124 -0
  7. package/dist/custodyInventory.js +154 -0
  8. package/dist/customerStore.js +258 -0
  9. package/dist/dunning.js +1 -2
  10. package/dist/economy.d.ts +30 -0
  11. package/dist/economy.js +265 -0
  12. package/dist/entitlement.js +1 -2
  13. package/dist/eventDelivery.js +71 -0
  14. package/dist/flushClaim.js +1 -2
  15. package/dist/index.d.ts +669 -65
  16. package/dist/index.js +230 -173
  17. package/dist/invoiceHistory.js +90 -0
  18. package/dist/invoiceHistoryJournal.js +475 -0
  19. package/dist/invoiceHistoryProgress.js +234 -0
  20. package/dist/invoiceHistoryWork.js +362 -0
  21. package/dist/invoiceSnapshot.js +65 -0
  22. package/dist/invoiceStore.js +132 -0
  23. package/dist/metering.js +1 -2
  24. package/dist/plans.js +1 -2
  25. package/dist/providerIdentity.js +23 -0
  26. package/dist/providers.js +271 -67
  27. package/dist/provision.js +1 -2
  28. package/dist/rpc.js +1 -2
  29. package/dist/service.js +892 -392
  30. package/dist/stores.js +125 -291
  31. package/dist/stripeClient.js +1 -2
  32. package/dist/stripeIdentity.js +55 -0
  33. package/dist/stripeInvoiceHistory.js +66 -0
  34. package/dist/stripeInvoiceSnapshot.js +85 -0
  35. package/dist/stripeProvider.js +305 -179
  36. package/dist/stripeRest.js +1 -2
  37. package/dist/stripeVerifiedEvent.js +28 -0
  38. package/dist/table.js +70 -48
  39. package/dist/types.d.ts +298 -27
  40. package/dist/types.js +1 -2
  41. package/dist/usageEvents.js +64 -0
  42. package/dist/web/index.js +1 -2
  43. package/dist/webhook.js +32 -40
  44. package/package.json +18 -8
@@ -0,0 +1,85 @@
1
+ import { BillingError as e } from "./types.js";
2
+ import { assertInvoiceSnapshot as t, invoiceSnapshotError as n } from "./invoiceSnapshot.js";
3
+ import { stripeCall as r } from "./stripeClient.js";
4
+ import { Effect as i } from "effect";
5
+ // src/stripeInvoiceSnapshot.ts
6
+ var a = (e) => typeof e == "string" ? e : e?.id ?? null, o = (e) => {
7
+ if (e === null || !Number.isSafeInteger(e) || !Number.isSafeInteger(e * 1e3)) throw n("The invoice observation contains an invalid timestamp.");
8
+ let t = /* @__PURE__ */ new Date(e * 1e3);
9
+ if (!Number.isFinite(t.getTime())) throw n("The invoice timestamp is outside the supported range.");
10
+ return t;
11
+ }, s = (t) => i.try({
12
+ try: t,
13
+ catch: (t) => t instanceof e ? t : n("The provider invoice observation could not be confirmed.")
14
+ }), c = (e, t) => {
15
+ if (e.id !== t.providerInvoiceId || a(e.customer) !== t.providerCustomerId) throw n("The invoice does not belong to the linked billing customer.");
16
+ let r = e.status;
17
+ if (r !== "open" && r !== "paid" && r !== "uncollectible" && r !== "void") throw n("Detailed invoice evidence requires a finalized invoice.");
18
+ return {
19
+ providerInvoiceId: e.id,
20
+ providerCustomerId: t.providerCustomerId,
21
+ providerSubscriptionId: a(e.parent?.subscription_details?.subscription ?? null),
22
+ providerRevisionId: a(e.latest_revision),
23
+ status: r === "open" ? "open" : r === "paid" ? "paid" : r === "void" ? "void" : "uncollectible",
24
+ livemode: e.livemode,
25
+ currency: e.currency,
26
+ amountDueMinor: e.amount_due,
27
+ amountPaidMinor: e.amount_paid,
28
+ amountRemainingMinor: e.amount_remaining,
29
+ finalizedAt: o(e.status_transitions.finalized_at),
30
+ paidAt: e.status_transitions.paid_at === null ? null : o(e.status_transitions.paid_at)
31
+ };
32
+ }, l = (e, t) => {
33
+ if (e.invoice !== t) throw n("An invoice line has a different invoice identity.");
34
+ let r = e.parent, i = r?.type === "subscription_item_details" ? r.subscription_item_details : null, s = r?.type === "invoice_item_details" ? r.invoice_item_details : null;
35
+ if (r?.type === "subscription_item_details" && i === null || r?.type === "invoice_item_details" && s === null) throw n("The invoice line origin could not be confirmed.");
36
+ let c = a(e.subscription), l = i?.subscription ?? s?.subscription ?? null;
37
+ if (c !== null && l !== null && c !== l) throw n("The invoice line contains conflicting subscription identities.");
38
+ return {
39
+ providerLineId: e.id,
40
+ providerSubscriptionId: l ?? c,
41
+ providerSubscriptionItemId: i?.subscription_item ?? null,
42
+ providerPriceId: e.pricing?.type === "price_details" ? a(e.pricing.price_details?.price ?? null) : null,
43
+ amountMinor: e.amount,
44
+ currency: e.currency,
45
+ quantityDecimal: e.quantity_decimal?.toString() ?? null,
46
+ periodStart: o(e.period.start),
47
+ periodEnd: o(e.period.end),
48
+ proration: i?.proration ?? s?.proration ?? null
49
+ };
50
+ }, u = (e, a) => {
51
+ let o = Object.freeze({
52
+ providerCustomerId: a.providerCustomerId,
53
+ providerInvoiceId: a.providerInvoiceId
54
+ });
55
+ return [o.providerCustomerId, o.providerInvoiceId].every((e) => typeof e == "string" && e.length > 0 && e.trim() === e) ? i.gen(function* () {
56
+ let a = yield* r("stripe.invoices.retrieve", () => e.invoices.retrieve(o.providerInvoiceId)), u = yield* s(() => c(a, o)), d = [], f = /* @__PURE__ */ new Set(), p, m = !1;
57
+ for (let t = 0; t < 100; t++) {
58
+ let t = yield* r("stripe.invoices.listLineItems", () => e.invoices.listLineItems(o.providerInvoiceId, {
59
+ limit: 100,
60
+ ...p === void 0 ? {} : { starting_after: p }
61
+ }));
62
+ if (yield* s(() => {
63
+ if (!Array.isArray(t.data) || t.data.length > 100 || typeof t.has_more != "boolean" || (t.has_more || p !== void 0) && t.data.length === 0) throw n("The invoice line page is incomplete.");
64
+ for (let e of t.data) {
65
+ if (typeof e.id != "string" || e.id.length === 0 || f.has(e.id)) throw n("The invoice line cursor repeated an identity.", !0);
66
+ f.add(e.id), d.push(l(e, o.providerInvoiceId));
67
+ }
68
+ }), !t.has_more) {
69
+ m = !0;
70
+ break;
71
+ }
72
+ p = t.data[t.data.length - 1]?.id;
73
+ }
74
+ if (!m) return yield* i.fail(n("The invoice exceeds the complete observation bound."));
75
+ let h = yield* r("stripe.invoices.retrieve", () => e.invoices.retrieve(o.providerInvoiceId)), g = yield* s(() => c(h, o));
76
+ if (JSON.stringify(u) !== JSON.stringify(g)) return yield* i.fail(n("The invoice changed during observation; retry the complete read.", !0));
77
+ let _ = {
78
+ ...g,
79
+ lines: d,
80
+ observedAt: /* @__PURE__ */ new Date()
81
+ };
82
+ return yield* s(() => t(_)), _;
83
+ }) : i.fail(n("An exact billing customer and invoice identity are required."));
84
+ };
85
+ export { u as stripeInvoiceSnapshot };