@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.
- package/CHANGELOG.md +121 -0
- package/THIRD-PARTY-NOTICES.md +22 -646
- package/dist/catalog.js +52 -52
- package/dist/index.d.ts +4 -1
- package/dist/index.js +251 -251
- package/dist/invoiceHistoryJournal.js +108 -108
- package/dist/invoiceHistoryProgress.js +107 -107
- package/dist/invoiceHistoryWork.js +103 -103
- package/dist/invoiceSnapshot.js +11 -11
- package/dist/invoiceStore.js +43 -43
- package/dist/paidInvoiceCoverage.js +13 -13
- package/dist/providers.js +35 -35
- package/dist/service.js +592 -592
- package/dist/stores.js +89 -89
- package/dist/stripeIdentity.js +17 -17
- package/dist/stripeInvoiceHistory.js +21 -21
- package/dist/stripeInvoicePayments.js +41 -41
- package/dist/stripeInvoiceSnapshot.js +17 -17
- package/dist/stripeProvider.js +74 -74
- package/dist/stripeRest.js +10 -10
- package/package.json +9 -9
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { BILLING_SUBSCRIPTIONS_TABLE as e } from "./table.js";
|
|
2
|
+
import { dataStoreCustomerStore as t } from "./customerStore.js";
|
|
3
|
+
import { dataStoreInvoiceStore as n } from "./invoiceStore.js";
|
|
4
|
+
import { captureSubscriptionObservation as r } from "./subscriptionObservation.js";
|
|
5
|
+
import { BillingError as i } from "./types.js";
|
|
6
6
|
import { Effect as a } from "effect";
|
|
7
7
|
import { and as o, eq as s } from "@voltro/database";
|
|
8
8
|
// src/paidInvoiceCoverage.ts
|
|
9
|
-
var c = () => new
|
|
9
|
+
var c = () => new i({
|
|
10
10
|
source: "paidInvoiceCoverage",
|
|
11
11
|
message: "Current native paid invoice coverage requires reconciliation.",
|
|
12
12
|
transient: !0
|
|
@@ -28,12 +28,12 @@ var c = () => new e({
|
|
|
28
28
|
}), n += i;
|
|
29
29
|
}
|
|
30
30
|
return n >= BigInt(e.amountDueMinor) && n === BigInt(e.amountPaidMinor);
|
|
31
|
-
}, u = async (
|
|
31
|
+
}, u = async (i, u, d) => {
|
|
32
32
|
if (!(d instanceof Date) || !Number.isSafeInteger(d.getTime()) || d.getTime() < 0) throw c();
|
|
33
|
-
let f =
|
|
33
|
+
let f = r(u.providerObservation, u);
|
|
34
34
|
if (f === null) return null;
|
|
35
|
-
let p = await
|
|
36
|
-
table:
|
|
35
|
+
let p = await i.query({
|
|
36
|
+
table: e,
|
|
37
37
|
predicate: o(s("tenantId", u.tenantId), s("provider", u.provider), s("providerSubscriptionId", u.providerSubscriptionId)),
|
|
38
38
|
order: [],
|
|
39
39
|
take: 2,
|
|
@@ -42,7 +42,7 @@ var c = () => new e({
|
|
|
42
42
|
lock: "update"
|
|
43
43
|
}), m = p[0];
|
|
44
44
|
if (p.length !== 1 || m === void 0) throw c();
|
|
45
|
-
let h = (e) => e == null ? null : e instanceof Date ? e : new Date(String(e)), g =
|
|
45
|
+
let h = (e) => e == null ? null : e instanceof Date ? e : new Date(String(e)), g = r(m.providerObservation, {
|
|
46
46
|
tenantId: String(m.tenantId),
|
|
47
47
|
provider: String(m.provider),
|
|
48
48
|
providerSubscriptionId: String(m.providerSubscriptionId),
|
|
@@ -57,7 +57,7 @@ var c = () => new e({
|
|
|
57
57
|
let _ = {
|
|
58
58
|
providerAccountId: f.providerAccountId,
|
|
59
59
|
livemode: f.livemode
|
|
60
|
-
}, v =
|
|
60
|
+
}, v = t(i), y = await a.runPromise(v.accountForTenant(u.tenantId));
|
|
61
61
|
if (y === null || y.provider !== u.provider || y.account.providerAccountId !== _.providerAccountId || y.account.livemode !== _.livemode) throw c();
|
|
62
62
|
let b = {
|
|
63
63
|
provider: u.provider,
|
|
@@ -69,7 +69,7 @@ var c = () => new e({
|
|
|
69
69
|
provider: u.provider,
|
|
70
70
|
..._,
|
|
71
71
|
providerCustomerId: f.providerCustomerId
|
|
72
|
-
}, C =
|
|
72
|
+
}, C = n(i), w = await a.runPromise(C.currentPaymentEpoch(S, { forUpdate: !0 }));
|
|
73
73
|
if (w === null || f.paymentHeadId !== w.headId || f.paymentEpoch !== w.epoch) return null;
|
|
74
74
|
let T = await a.runPromise(C.get({
|
|
75
75
|
...S,
|
package/dist/providers.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { BillingError as e } from "./types.js";
|
|
2
2
|
import { decodeInvoiceSnapshot as t, encodeInvoiceSnapshot as n, invoiceSnapshotError as r } from "./invoiceSnapshot.js";
|
|
3
3
|
import { captureProviderAccount as i, captureProviderCustomer as a, providerIdentityError as o, sameProviderAccount as s } from "./providerIdentity.js";
|
|
4
|
-
import {
|
|
4
|
+
import { STRIPE_WEBHOOK_EVENTS as c, normalizeStripeEvent as l, stripeProvider as u } from "./stripeProvider.js";
|
|
5
5
|
import "./subscriptionObservation.js";
|
|
6
|
-
import {
|
|
6
|
+
import { captureInvoiceHistoryInput as d, captureInvoiceHistoryPage as f, historyError as p, invoiceHistoryPreview as m } from "./invoiceHistory.js";
|
|
7
7
|
import { Effect as h } from "effect";
|
|
8
8
|
import { bootRefusal as g } from "@voltro/runtime/boot-refusal";
|
|
9
9
|
// src/providers.ts
|
|
10
|
-
var _ = (
|
|
11
|
-
let
|
|
12
|
-
providerAccountId:
|
|
10
|
+
var _ = (c) => {
|
|
11
|
+
let l = i({
|
|
12
|
+
providerAccountId: c?.accountId ?? "mock_" + globalThis.crypto.randomUUID(),
|
|
13
13
|
livemode: !1
|
|
14
|
-
}),
|
|
14
|
+
}), u = /* @__PURE__ */ new Map(), g = 0, _ = c?.baseUrl ?? "https://mock.billing.local", v = [], y = [], b = [], x = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), T = [], E = (t) => h.try({
|
|
15
15
|
try: () => {
|
|
16
|
-
let e =
|
|
17
|
-
if (!s(e.account,
|
|
16
|
+
let e = d(t);
|
|
17
|
+
if (!s(e.account, l)) throw p("The mock invoice history account differs.");
|
|
18
18
|
let n = T.filter((t) => t.providerCustomerId === e.providerCustomerId).slice().sort((e, t) => t.createdAt.getTime() - e.createdAt.getTime() || (e.providerInvoiceId < t.providerInvoiceId ? 1 : e.providerInvoiceId > t.providerInvoiceId ? -1 : 0)), r = e.cursor === void 0 ? -1 : n.findIndex((t) => t.providerInvoiceId === e.cursor?.afterInvoiceId);
|
|
19
|
-
if (e.cursor !== void 0 && r < 0) throw
|
|
19
|
+
if (e.cursor !== void 0 && r < 0) throw p("The mock invoice cursor does not belong to this customer.");
|
|
20
20
|
let i = n.slice(r + 1, r + 1 + e.limit), a = i[i.length - 1];
|
|
21
|
-
return
|
|
22
|
-
account:
|
|
21
|
+
return f(e, {
|
|
22
|
+
account: l,
|
|
23
23
|
providerCustomerId: e.providerCustomerId,
|
|
24
24
|
invoices: i,
|
|
25
25
|
nextCursor: r + 1 + i.length < n.length && a !== void 0 ? {
|
|
26
|
-
...
|
|
26
|
+
...l,
|
|
27
27
|
providerCustomerId: e.providerCustomerId,
|
|
28
28
|
afterInvoiceId: a.providerInvoiceId
|
|
29
29
|
} : null,
|
|
30
30
|
observedAt: j()
|
|
31
31
|
});
|
|
32
32
|
},
|
|
33
|
-
catch: (t) => t instanceof e ? t :
|
|
34
|
-
}), D = [], O = [], k = [], A = [], j =
|
|
33
|
+
catch: (t) => t instanceof e ? t : p()
|
|
34
|
+
}), D = [], O = [], k = [], A = [], j = c?.now ?? (() => /* @__PURE__ */ new Date()), M = /* @__PURE__ */ new Map(), N = (e) => e.status === "open" && e.expiresAt.getTime() <= j().getTime() ? {
|
|
35
35
|
...e,
|
|
36
36
|
status: "expired",
|
|
37
37
|
url: null
|
|
@@ -103,12 +103,12 @@ var _ = (f) => {
|
|
|
103
103
|
return {
|
|
104
104
|
name: "mock",
|
|
105
105
|
supportsNativeSubscriptionWrites: !0,
|
|
106
|
-
fetchAccountIdentity: () => h.succeed(i(
|
|
106
|
+
fetchAccountIdentity: () => h.succeed(i(l)),
|
|
107
107
|
fetchCustomerSnapshot: (e) => h.try({
|
|
108
108
|
try: () => {
|
|
109
109
|
let t = i(e.account);
|
|
110
|
-
if (!s(t,
|
|
111
|
-
let n =
|
|
110
|
+
if (!s(t, l)) throw o();
|
|
111
|
+
let n = u.get(e.providerCustomerId);
|
|
112
112
|
if (n === void 0) throw o();
|
|
113
113
|
return a({
|
|
114
114
|
...n,
|
|
@@ -119,26 +119,26 @@ var _ = (f) => {
|
|
|
119
119
|
}),
|
|
120
120
|
setCustomerSnapshot: (e) => {
|
|
121
121
|
let t = a(e);
|
|
122
|
-
if (!s(t.account,
|
|
123
|
-
|
|
122
|
+
if (!s(t.account, l)) throw o();
|
|
123
|
+
u.set(t.providerCustomerId, t);
|
|
124
124
|
},
|
|
125
125
|
setInvoiceHistory: (e) => {
|
|
126
|
-
if (!Array.isArray(e) || Object.keys(e).length !== e.length) throw
|
|
126
|
+
if (!Array.isArray(e) || Object.keys(e).length !== e.length) throw p("The mock invoice history must be complete and dense.");
|
|
127
127
|
let t = /* @__PURE__ */ new Set(), n = e.map((e) => {
|
|
128
|
-
if (t.has(e.providerInvoiceId)) throw
|
|
128
|
+
if (t.has(e.providerInvoiceId)) throw p("The mock invoice history contains duplicate identities.");
|
|
129
129
|
t.add(e.providerInvoiceId);
|
|
130
|
-
let n =
|
|
131
|
-
account:
|
|
130
|
+
let n = d({
|
|
131
|
+
account: l,
|
|
132
132
|
providerCustomerId: e.providerCustomerId,
|
|
133
133
|
limit: 1
|
|
134
|
-
}), r =
|
|
135
|
-
account:
|
|
134
|
+
}), r = f(n, {
|
|
135
|
+
account: l,
|
|
136
136
|
providerCustomerId: e.providerCustomerId,
|
|
137
137
|
invoices: [e],
|
|
138
138
|
nextCursor: null,
|
|
139
139
|
observedAt: j()
|
|
140
140
|
}).invoices[0];
|
|
141
|
-
if (r === void 0) throw
|
|
141
|
+
if (r === void 0) throw p();
|
|
142
142
|
return r;
|
|
143
143
|
});
|
|
144
144
|
T = Object.freeze(n);
|
|
@@ -159,7 +159,7 @@ var _ = (f) => {
|
|
|
159
159
|
},
|
|
160
160
|
catch: (t) => t instanceof e ? t : r("The mock invoice observation is invalid.")
|
|
161
161
|
}),
|
|
162
|
-
supportsMeteredUsage:
|
|
162
|
+
supportsMeteredUsage: c?.supportsMeteredUsage ?? !0,
|
|
163
163
|
pushed: v,
|
|
164
164
|
updates: y,
|
|
165
165
|
fetched: b,
|
|
@@ -195,14 +195,14 @@ var _ = (f) => {
|
|
|
195
195
|
}),
|
|
196
196
|
ensureCustomer: (e) => h.sync(() => {
|
|
197
197
|
let t = I.get(e.tenantId);
|
|
198
|
-
if (t !== void 0 &&
|
|
198
|
+
if (t !== void 0 && u.get(t)?.deleted === !1) return t;
|
|
199
199
|
let n = `mock_cus_${e.tenantId}`, r = t === void 0 ? n : `${n}_${++g}`, i = a({
|
|
200
|
-
account:
|
|
200
|
+
account: l,
|
|
201
201
|
providerCustomerId: r,
|
|
202
202
|
deleted: !1,
|
|
203
203
|
observedAt: j()
|
|
204
204
|
});
|
|
205
|
-
return I.set(e.tenantId, r),
|
|
205
|
+
return I.set(e.tenantId, r), u.set(r, i), P.push(e.tenantId), r;
|
|
206
206
|
}),
|
|
207
207
|
expireOpenCheckouts: (e) => h.sync(() => {
|
|
208
208
|
F.push(e.providerCustomerId);
|
|
@@ -343,7 +343,7 @@ var _ = (f) => {
|
|
|
343
343
|
previewSubscriptionChange: (e) => h.sync(() => {
|
|
344
344
|
let t = x.get(e.providerSubscriptionId);
|
|
345
345
|
return {
|
|
346
|
-
plan: e.priceId === void 0 ? t?.plan ?? "mock-plan" :
|
|
346
|
+
plan: e.priceId === void 0 ? t?.plan ?? "mock-plan" : c?.planForPriceId?.(e.priceId) ?? e.priceId,
|
|
347
347
|
quantity: e.quantity ?? t?.quantity ?? 1,
|
|
348
348
|
prorationMinor: 0,
|
|
349
349
|
currency: "usd",
|
|
@@ -353,10 +353,10 @@ var _ = (f) => {
|
|
|
353
353
|
}),
|
|
354
354
|
listInvoiceHistory: E,
|
|
355
355
|
listInvoices: (e) => E({
|
|
356
|
-
account:
|
|
356
|
+
account: l,
|
|
357
357
|
providerCustomerId: e.providerCustomerId,
|
|
358
358
|
limit: e.limit ?? 20
|
|
359
|
-
}).pipe(h.map((e) => e.invoices.map(
|
|
359
|
+
}).pipe(h.map((e) => e.invoices.map(m))),
|
|
360
360
|
normalizeEvent: (e) => h.succeed(B(e) ? e : null)
|
|
361
361
|
};
|
|
362
362
|
}, v = /* @__PURE__ */ new Set([
|
|
@@ -378,7 +378,7 @@ var _ = (f) => {
|
|
|
378
378
|
if ((t ?? (n.STRIPE_SECRET_KEY ? "stripe" : "mock")) === "stripe") {
|
|
379
379
|
let t = e.apiKey ?? n.STRIPE_SECRET_KEY;
|
|
380
380
|
if (!t) throw Error("billingPlugin: provider 'stripe' needs an apiKey (option or STRIPE_SECRET_KEY env)");
|
|
381
|
-
return
|
|
381
|
+
return u({
|
|
382
382
|
apiKey: t,
|
|
383
383
|
...e.planForPriceId ? { planForPriceId: e.planForPriceId } : {},
|
|
384
384
|
...e.seatPricingForPriceId ? { seatPricingForPriceId: e.seatPricingForPriceId } : {}
|
|
@@ -391,4 +391,4 @@ var _ = (f) => {
|
|
|
391
391
|
data: ["personal", "metadata"],
|
|
392
392
|
disable: "without STRIPE_SECRET_KEY the mock provider answers, and nothing leaves (production refuses to boot on it)"
|
|
393
393
|
}];
|
|
394
|
-
export {
|
|
394
|
+
export { c as STRIPE_WEBHOOK_EVENTS, b as assertBillingProductionReady, S as billingEgressOf, y as isProductionBoot, _ as mockProvider, l as normalizeStripeEvent, x as resolveProvider, u as stripeProvider };
|