@voltro/plugin-billing 0.89.2 → 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 +1943 -0
- package/README.md +0 -435
- package/THIRD-PARTY-NOTICES.md +22 -646
- package/dist/catalog.js +169 -70
- package/dist/custodyInventory.js +101 -65
- package/dist/dunning.js +14 -6
- package/dist/eventDelivery.js +14 -5
- package/dist/historicalUsage.js +94 -0
- package/dist/index.d.ts +777 -68
- package/dist/index.js +354 -233
- package/dist/invoiceHistoryJournal.js +204 -179
- package/dist/invoiceHistoryProgress.js +130 -106
- package/dist/invoiceHistoryWork.js +188 -186
- package/dist/invoicePaymentEpoch.js +145 -0
- package/dist/invoicePaymentObservation.js +64 -0
- package/dist/invoiceSnapshot.js +56 -46
- package/dist/invoiceStore.js +124 -90
- package/dist/paidInvoiceCoverage.js +84 -0
- package/dist/plans.js +15 -2
- package/dist/providers.js +149 -92
- package/dist/provision.js +84 -73
- package/dist/rpc.d.ts +53 -13
- package/dist/rpc.js +141 -78
- package/dist/service.js +1208 -722
- package/dist/stores.js +240 -148
- package/dist/stripeIdentity.js +17 -17
- package/dist/stripeInvoiceHistory.js +21 -21
- package/dist/stripeInvoicePayments.js +129 -0
- package/dist/stripeInvoiceSnapshot.js +65 -46
- package/dist/stripeProvider.js +570 -201
- package/dist/stripeRest.js +10 -10
- package/dist/subscriptionObservation.js +93 -0
- package/dist/subscriptionWriteStore.js +325 -0
- package/dist/table.js +75 -66
- package/dist/types.d.ts +415 -27
- package/dist/types.js +21 -4
- package/dist/web/index.d.ts +93 -3
- package/dist/web/index.js +76 -33
- package/dist/web/writeRequest.js +65 -0
- package/package.json +9 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { BILLING_CUSTOMER_CUSTODY_TABLE as e, dataStoreCustomerStore as t } from "./customerStore.js";
|
|
2
|
+
import { invoiceHistoryJournalInTransaction as n } from "./invoiceHistoryJournal.js";
|
|
3
|
+
import { BILLING_INVOICE_HISTORY_WORK_TABLE as r } from "./invoiceHistoryWork.js";
|
|
4
|
+
import { captureProviderAccount as i, exactProviderIdentifier as a, sameProviderAccount as o } from "./providerIdentity.js";
|
|
5
|
+
import { BillingError as s } from "./types.js";
|
|
6
6
|
import { Effect as c } from "effect";
|
|
7
7
|
import { and as l, eq as u, generateId as d, id as f, integer as p, table as m, text as h, timestamp as g } from "@voltro/database";
|
|
8
8
|
// src/invoiceHistoryProgress.ts
|
|
@@ -16,7 +16,8 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
16
16
|
}), b = m(_, {
|
|
17
17
|
id: f({ prefix: "bihscan" }),
|
|
18
18
|
...y(),
|
|
19
|
-
afterCustodyId: h().maxLength(191).nullable()
|
|
19
|
+
afterCustodyId: h().maxLength(191).nullable(),
|
|
20
|
+
cycleEndCustodyId: h().maxLength(191).nullable()
|
|
20
21
|
}).unique("byBillingHistoryScanAccount", ["identityKey"]), x = m(v, {
|
|
21
22
|
id: f({ prefix: "bihdispatch" }),
|
|
22
23
|
...y(),
|
|
@@ -26,13 +27,14 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
26
27
|
walkId: h().maxLength(191).nullable(),
|
|
27
28
|
afterUnpreparedId: h().maxLength(191).nullable(),
|
|
28
29
|
afterReadyId: h().maxLength(191).nullable(),
|
|
29
|
-
afterWorkingId: h().maxLength(191).nullable()
|
|
30
|
-
|
|
30
|
+
afterWorkingId: h().maxLength(191).nullable(),
|
|
31
|
+
afterObservedId: h().maxLength(191).nullable()
|
|
32
|
+
}).unique("byBillingHistoryDispatchCustody", ["identityKey"]).index("byBillingHistoryDispatchTenant", ["tenantId"]), S = 2147483647, C = () => new s({
|
|
31
33
|
source: "invoiceHistoryProgress",
|
|
32
34
|
message: "Invoice-history traversal requires fresh owned native state.",
|
|
33
35
|
transient: !0
|
|
34
36
|
}), w = (e, t = 191) => {
|
|
35
|
-
if (!
|
|
37
|
+
if (!a(e) || e.length > t || !e.isWellFormed()) throw C();
|
|
36
38
|
return e;
|
|
37
39
|
}, T = (e, t) => w(d({
|
|
38
40
|
kind: "typeid",
|
|
@@ -45,10 +47,10 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
45
47
|
if (typeof e != "number" || !Number.isInteger(e) || e < 1 || e > S) throw C();
|
|
46
48
|
return e;
|
|
47
49
|
}, k = (e) => {
|
|
48
|
-
let
|
|
49
|
-
return w(
|
|
50
|
+
let t = i(e.account);
|
|
51
|
+
return w(t.providerAccountId), {
|
|
50
52
|
provider: w(e.provider, 64),
|
|
51
|
-
account:
|
|
53
|
+
account: t
|
|
52
54
|
};
|
|
53
55
|
}, A = (e) => ({
|
|
54
56
|
provider: e.provider,
|
|
@@ -68,81 +70,95 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
68
70
|
skip: void 0,
|
|
69
71
|
projection: void 0,
|
|
70
72
|
...n ? { lock: "update" } : {}
|
|
71
|
-
}), N = (
|
|
72
|
-
try:
|
|
73
|
-
catch: (
|
|
73
|
+
}), N = (e) => c.tryPromise({
|
|
74
|
+
try: e,
|
|
75
|
+
catch: (e) => e instanceof s ? e : C()
|
|
74
76
|
}), P = [
|
|
75
77
|
"unprepared",
|
|
76
78
|
"ready",
|
|
77
|
-
"working"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
"working",
|
|
80
|
+
"observed"
|
|
81
|
+
], F = (i) => {
|
|
82
|
+
let a = async (e, n) => {
|
|
83
|
+
let r = k(n), i = w(n.id), a = w(n.tenantId), s = w(n.providerCustomerId), l = await c.runPromise(t(e).getByProviderCustomerId(s, r));
|
|
84
|
+
if (l === null || l.id !== i || l.tenantId !== a || l.provider !== r.provider || !o(l.account, r.account)) throw C();
|
|
82
85
|
return l;
|
|
83
|
-
},
|
|
84
|
-
let
|
|
85
|
-
...M(
|
|
86
|
-
predicate: l(u("id",
|
|
86
|
+
}, s = async (n, r, i) => {
|
|
87
|
+
let a = await n.query({
|
|
88
|
+
...M(e, i),
|
|
89
|
+
predicate: l(u("id", i), u("provider", r.provider), u("providerAccountId", r.account.providerAccountId), u("livemode", +!!r.account.livemode))
|
|
87
90
|
});
|
|
88
|
-
if (
|
|
89
|
-
let o = await c.runPromise(
|
|
90
|
-
if (o === null || o.id !==
|
|
91
|
-
}, d = async (
|
|
91
|
+
if (a.length !== 1 || a[0]?.id !== i) throw C();
|
|
92
|
+
let o = await c.runPromise(t(n).getByProviderCustomerId(w(a[0].providerCustomerId), r));
|
|
93
|
+
if (o === null || o.id !== i || o.tenantId !== w(a[0].tenantId)) throw C();
|
|
94
|
+
}, d = async (t, n) => {
|
|
95
|
+
let r = await t.query({
|
|
96
|
+
...M(e, ""),
|
|
97
|
+
predicate: l(u("provider", n.provider), u("providerAccountId", n.account.providerAccountId), u("livemode", +!!n.account.livemode)),
|
|
98
|
+
order: [{
|
|
99
|
+
column: "id",
|
|
100
|
+
direction: "desc"
|
|
101
|
+
}],
|
|
102
|
+
take: 1
|
|
103
|
+
}), i = r[0] === void 0 ? null : w(r[0].id);
|
|
104
|
+
return i !== null && await s(t, n, i), i;
|
|
105
|
+
}, f = async (e, t, n, r, i = !0) => {
|
|
92
106
|
let a = await e.query(M(t, r, i));
|
|
93
107
|
if (a.length > 1) throw C();
|
|
94
108
|
let o = a[0];
|
|
95
109
|
if (!o) return null;
|
|
96
110
|
if (o.identityKey !== r || o.provider !== n.provider || o.providerAccountId !== n.account.providerAccountId || o.livemode !== +!!n.account.livemode) throw C();
|
|
97
111
|
return w(o.id), O(o.revision), D(o.updatedAt), o;
|
|
98
|
-
},
|
|
99
|
-
let
|
|
100
|
-
return i !== null && await
|
|
112
|
+
}, p = async (e, t, n) => {
|
|
113
|
+
let r = E(n.afterCustodyId), i = E(n.cycleEndCustodyId ?? null);
|
|
114
|
+
return r !== null && await s(e, t, r), i !== null && await s(e, t, i), {
|
|
101
115
|
...t,
|
|
102
|
-
id: w(
|
|
103
|
-
revision: O(
|
|
104
|
-
afterCustodyId:
|
|
105
|
-
|
|
116
|
+
id: w(n.id),
|
|
117
|
+
revision: O(n.revision),
|
|
118
|
+
afterCustodyId: r,
|
|
119
|
+
cycleEndCustodyId: i,
|
|
120
|
+
updatedAt: D(n.updatedAt)
|
|
106
121
|
};
|
|
107
|
-
},
|
|
108
|
-
if (
|
|
109
|
-
let
|
|
110
|
-
unprepared: E(
|
|
111
|
-
ready: E(
|
|
112
|
-
working: E(
|
|
122
|
+
}, m = async (e, t, i) => {
|
|
123
|
+
if (i.tenantId !== t.tenantId || i.providerCustomerId !== t.providerCustomerId || i.custodyId !== t.id) throw C();
|
|
124
|
+
let a = E(i.walkId), o = {
|
|
125
|
+
unprepared: E(i.afterUnpreparedId),
|
|
126
|
+
ready: E(i.afterReadyId),
|
|
127
|
+
working: E(i.afterWorkingId),
|
|
128
|
+
observed: E(i.afterObservedId)
|
|
113
129
|
};
|
|
114
|
-
if (
|
|
115
|
-
if (
|
|
116
|
-
let
|
|
117
|
-
if (
|
|
118
|
-
for (let
|
|
119
|
-
let
|
|
120
|
-
if (
|
|
121
|
-
let l =
|
|
122
|
-
if (
|
|
130
|
+
if (a === null && P.some((e) => o[e] !== null)) throw C();
|
|
131
|
+
if (a !== null) {
|
|
132
|
+
let i = n(e), s = await c.runPromise(i.read(t));
|
|
133
|
+
if (s === null || s.id !== a) throw C();
|
|
134
|
+
for (let n of P) {
|
|
135
|
+
let s = o[n];
|
|
136
|
+
if (s === null) continue;
|
|
137
|
+
let l = s;
|
|
138
|
+
if (n !== "unprepared") {
|
|
123
139
|
let n = await e.query({
|
|
124
|
-
...M(
|
|
125
|
-
predicate: u("id",
|
|
140
|
+
...M(r, s),
|
|
141
|
+
predicate: u("id", s)
|
|
126
142
|
});
|
|
127
|
-
if (n.length !== 1 || n[0]?.id !==
|
|
143
|
+
if (n.length !== 1 || n[0]?.id !== s) throw C();
|
|
128
144
|
let i = n[0];
|
|
129
|
-
if (i.walkId !==
|
|
145
|
+
if (i.walkId !== a || i.custodyId !== t.id || i.tenantId !== t.tenantId || i.providerCustomerId !== t.providerCustomerId || i.provider !== t.provider || i.providerAccountId !== t.account.providerAccountId || i.livemode !== +!!t.account.livemode) throw C();
|
|
130
146
|
l = w(i.referenceId);
|
|
131
147
|
}
|
|
132
|
-
let d = await c.runPromise(
|
|
133
|
-
if (d === null || d.walkId !==
|
|
148
|
+
let d = await c.runPromise(i.reference(t, l));
|
|
149
|
+
if (d === null || d.walkId !== a) throw C();
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
152
|
return {
|
|
137
|
-
id: w(
|
|
138
|
-
revision: O(
|
|
153
|
+
id: w(i.id),
|
|
154
|
+
revision: O(i.revision),
|
|
139
155
|
owner: t,
|
|
140
|
-
walkId:
|
|
141
|
-
cursors:
|
|
142
|
-
updatedAt: D(
|
|
156
|
+
walkId: a,
|
|
157
|
+
cursors: o,
|
|
158
|
+
updatedAt: D(i.updatedAt)
|
|
143
159
|
};
|
|
144
|
-
},
|
|
145
|
-
let s = await
|
|
160
|
+
}, h = async (e, t, n, r, i, a, o) => {
|
|
161
|
+
let s = await f(e, t, n, r);
|
|
146
162
|
if (s === null || s.id !== w(i.id) || s.revision !== O(i.revision)) return null;
|
|
147
163
|
if (Object.entries(a).every(([e, t]) => t instanceof Date ? D(s[e]).getTime() === t.getTime() : s[e] === t)) return s;
|
|
148
164
|
if (i.revision >= S) throw C();
|
|
@@ -150,83 +166,91 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
150
166
|
...a,
|
|
151
167
|
revision: i.revision + 1,
|
|
152
168
|
updatedAt: o
|
|
153
|
-
},
|
|
154
|
-
if (
|
|
155
|
-
if (
|
|
156
|
-
let p = await
|
|
169
|
+
}, d = await e.updateMany(t, c, { where: l(u("id", i.id), u("identityKey", r), u("revision", i.revision)) });
|
|
170
|
+
if (d === 0) return null;
|
|
171
|
+
if (d !== 1) throw C();
|
|
172
|
+
let p = await f(e, t, n, r);
|
|
157
173
|
if (p === null || p.id !== i.id) throw C();
|
|
158
174
|
for (let [e, t] of Object.entries(c)) if (t instanceof Date ? D(p[e]).getTime() !== t.getTime() : p[e] !== t) throw C();
|
|
159
175
|
return p;
|
|
160
176
|
};
|
|
161
177
|
return {
|
|
162
|
-
account: (
|
|
163
|
-
let
|
|
164
|
-
return
|
|
178
|
+
account: (e, t) => N(async () => {
|
|
179
|
+
let n = k(e), r = D(t), a = await j(n, null);
|
|
180
|
+
return i.transactional(async (e) => {
|
|
165
181
|
await e.insertIgnore(_, {
|
|
166
182
|
id: T(_, "bihscan"),
|
|
167
|
-
...A(
|
|
183
|
+
...A(n),
|
|
168
184
|
identityKey: a,
|
|
169
185
|
revision: 1,
|
|
170
186
|
afterCustodyId: null,
|
|
171
|
-
|
|
187
|
+
cycleEndCustodyId: await d(e, n),
|
|
188
|
+
updatedAt: r
|
|
172
189
|
}, { conflictColumns: ["identityKey"] });
|
|
173
|
-
let t = await
|
|
190
|
+
let t = await f(e, _, n, a);
|
|
174
191
|
if (t === null) throw C();
|
|
175
|
-
return
|
|
192
|
+
return p(e, n, t);
|
|
176
193
|
});
|
|
177
194
|
}),
|
|
178
|
-
advanceAccount: (
|
|
179
|
-
let
|
|
180
|
-
return
|
|
181
|
-
|
|
182
|
-
let t =
|
|
183
|
-
|
|
195
|
+
advanceAccount: (e, t, n) => N(async () => {
|
|
196
|
+
let r = structuredClone(e), a = k(r), o = E(t), c = D(n), l = await j(a, null);
|
|
197
|
+
return i.transactional(async (e) => {
|
|
198
|
+
o !== null && await s(e, a, o);
|
|
199
|
+
let t = o === null || (r.cycleEndCustodyId ?? null) === null ? await d(e, a) : E(r.cycleEndCustodyId);
|
|
200
|
+
t !== null && await s(e, a, t);
|
|
201
|
+
let n = await h(e, _, a, l, r, {
|
|
202
|
+
afterCustodyId: o,
|
|
203
|
+
cycleEndCustodyId: t
|
|
204
|
+
}, c);
|
|
205
|
+
return n === null ? null : p(e, a, n);
|
|
184
206
|
});
|
|
185
207
|
}),
|
|
186
|
-
customer: (
|
|
187
|
-
let
|
|
188
|
-
return
|
|
189
|
-
let
|
|
208
|
+
customer: (e, t) => N(async () => {
|
|
209
|
+
let n = structuredClone(e), r = D(t);
|
|
210
|
+
return i.transactional(async (e) => {
|
|
211
|
+
let t = await a(e, n), i = await j(t, t.id);
|
|
190
212
|
await e.insertIgnore(v, {
|
|
191
213
|
id: T(v, "bihdispatch"),
|
|
192
|
-
...A(
|
|
193
|
-
tenantId:
|
|
194
|
-
providerCustomerId:
|
|
195
|
-
custodyId:
|
|
196
|
-
identityKey:
|
|
214
|
+
...A(t),
|
|
215
|
+
tenantId: t.tenantId,
|
|
216
|
+
providerCustomerId: t.providerCustomerId,
|
|
217
|
+
custodyId: t.id,
|
|
218
|
+
identityKey: i,
|
|
197
219
|
revision: 1,
|
|
198
220
|
walkId: null,
|
|
199
221
|
afterUnpreparedId: null,
|
|
200
222
|
afterReadyId: null,
|
|
201
223
|
afterWorkingId: null,
|
|
202
|
-
|
|
224
|
+
afterObservedId: null,
|
|
225
|
+
updatedAt: r
|
|
203
226
|
}, { conflictColumns: ["identityKey"] });
|
|
204
|
-
let o = await
|
|
227
|
+
let o = await f(e, v, t, i);
|
|
205
228
|
if (o === null) throw C();
|
|
206
|
-
return
|
|
229
|
+
return m(e, t, o);
|
|
207
230
|
});
|
|
208
231
|
}),
|
|
209
|
-
advanceCustomer: (
|
|
210
|
-
let
|
|
211
|
-
return
|
|
212
|
-
let
|
|
232
|
+
advanceCustomer: (e, t, n) => N(async () => {
|
|
233
|
+
let r = structuredClone(e), o = structuredClone(t), s = D(n);
|
|
234
|
+
return i.transactional(async (e) => {
|
|
235
|
+
let t = await a(e, r.owner), n = await j(t, t.id), i = {
|
|
213
236
|
walkId: E(o.walkId),
|
|
214
237
|
afterUnpreparedId: E(o.cursors.unprepared),
|
|
215
238
|
afterReadyId: E(o.cursors.ready),
|
|
216
|
-
afterWorkingId: E(o.cursors.working)
|
|
239
|
+
afterWorkingId: E(o.cursors.working),
|
|
240
|
+
afterObservedId: E(o.cursors.observed)
|
|
217
241
|
};
|
|
218
|
-
await
|
|
219
|
-
id:
|
|
220
|
-
revision:
|
|
221
|
-
...A(
|
|
222
|
-
tenantId:
|
|
223
|
-
providerCustomerId:
|
|
224
|
-
custodyId:
|
|
242
|
+
await m(e, t, {
|
|
243
|
+
id: r.id,
|
|
244
|
+
revision: r.revision,
|
|
245
|
+
...A(t),
|
|
246
|
+
tenantId: t.tenantId,
|
|
247
|
+
providerCustomerId: t.providerCustomerId,
|
|
248
|
+
custodyId: t.id,
|
|
225
249
|
...i,
|
|
226
250
|
updatedAt: s
|
|
227
251
|
});
|
|
228
|
-
let c = await
|
|
229
|
-
return c === null ? null :
|
|
252
|
+
let c = await h(e, v, t, n, r, i, s);
|
|
253
|
+
return c === null ? null : m(e, t, c);
|
|
230
254
|
});
|
|
231
255
|
})
|
|
232
256
|
};
|