@voltro/plugin-billing 0.90.0 → 0.91.1
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 +131 -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,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { dataStoreCustomerStore as e } from "./customerStore.js";
|
|
2
|
+
import { captureInvoiceHistoryInput as t, captureInvoiceHistoryPage as n, historyError as r } from "./invoiceHistory.js";
|
|
3
|
+
import { captureProviderAccount as i, exactProviderIdentifier as a, sameProviderAccount as o } from "./providerIdentity.js";
|
|
4
|
+
import { BillingError as s } from "./types.js";
|
|
5
5
|
import { Effect as c } from "effect";
|
|
6
6
|
import { and as l, count as u, eq as d, gt as f, id as p, inSet as m, integer as h, lt as g, lte as _, neq as v, or as y, sum as b, table as x, text as S, timestamp as C } from "@voltro/database";
|
|
7
7
|
// src/invoiceHistoryJournal.ts
|
|
@@ -51,7 +51,7 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
51
51
|
"pageOrdinal",
|
|
52
52
|
"position"
|
|
53
53
|
]).index("byBillingInvoiceHistoryReferenceInvoice", ["walkId", "providerInvoiceId"]).index("byBillingInvoiceHistoryReferenceTenant", ["tenantId"]), j = 2147483647, M = (e, t = 191) => {
|
|
54
|
-
if (!
|
|
54
|
+
if (!a(e) || e.length > t || !e.isWellFormed()) throw F();
|
|
55
55
|
return e;
|
|
56
56
|
}, N = (e, t = 0) => {
|
|
57
57
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < t || e > j) throw F();
|
|
@@ -60,18 +60,18 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
60
60
|
let t = e instanceof Date ? new Date(e) : new Date(typeof e == "string" ? e : NaN);
|
|
61
61
|
if (!Number.isFinite(t.getTime())) throw F();
|
|
62
62
|
return t;
|
|
63
|
-
}, F = (e = "The durable invoice history journal requires reconciliation.", t = !1) =>
|
|
64
|
-
try:
|
|
65
|
-
catch: (
|
|
63
|
+
}, F = (e = "The durable invoice history journal requires reconciliation.", t = !1) => r(e, t), I = (e) => c.tryPromise({
|
|
64
|
+
try: e,
|
|
65
|
+
catch: (e) => e instanceof s ? e : F("The native invoice history transaction could not be confirmed.", !0)
|
|
66
66
|
}), L = async (e) => {
|
|
67
67
|
let t = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(e)));
|
|
68
68
|
return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
69
69
|
}, R = (e) => {
|
|
70
|
-
let
|
|
71
|
-
return M(
|
|
70
|
+
let t = i(e.account);
|
|
71
|
+
return M(t.providerAccountId), Object.freeze({
|
|
72
72
|
tenantId: M(e.tenantId),
|
|
73
73
|
provider: M(e.provider, 64),
|
|
74
|
-
account: Object.freeze(
|
|
74
|
+
account: Object.freeze(t),
|
|
75
75
|
providerCustomerId: M(e.providerCustomerId),
|
|
76
76
|
custodyId: M(e.custodyId ?? e.id)
|
|
77
77
|
});
|
|
@@ -95,25 +95,25 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
95
95
|
custodyId: M(e.custodyId)
|
|
96
96
|
});
|
|
97
97
|
}, V = (e, t) => {
|
|
98
|
-
if (e.tenantId !== t.tenantId || e.provider !== t.provider || e.custodyId !== t.custodyId || e.providerCustomerId !== t.providerCustomerId || !
|
|
98
|
+
if (e.tenantId !== t.tenantId || e.provider !== t.provider || e.custodyId !== t.custodyId || e.providerCustomerId !== t.providerCustomerId || !o(e.account, t.account)) throw F();
|
|
99
99
|
}, H = (e) => {
|
|
100
|
-
let
|
|
100
|
+
let n = R(e);
|
|
101
101
|
if (typeof e.exhausted != "boolean" || e.exhausted && e.cursor !== null) throw F();
|
|
102
|
-
let
|
|
103
|
-
account:
|
|
104
|
-
providerCustomerId:
|
|
102
|
+
let r = e.headCheckedAt === null ? null : P(e.headCheckedAt), i = e.cursor === null ? null : t({
|
|
103
|
+
account: n.account,
|
|
104
|
+
providerCustomerId: n.providerCustomerId,
|
|
105
105
|
cursor: e.cursor
|
|
106
106
|
}).cursor;
|
|
107
|
-
if (
|
|
107
|
+
if (i === void 0 || e.revision !== e.pageOrdinal + e.round || e.pageOrdinal === 0 && (e.cursor !== null || e.exhausted)) throw F();
|
|
108
108
|
return Object.freeze({
|
|
109
|
-
...
|
|
109
|
+
...n,
|
|
110
110
|
id: M(e.id),
|
|
111
111
|
revision: N(e.revision, 1),
|
|
112
112
|
round: N(e.round, 1),
|
|
113
113
|
pageOrdinal: N(e.pageOrdinal),
|
|
114
|
-
cursor:
|
|
114
|
+
cursor: i,
|
|
115
115
|
exhausted: e.exhausted,
|
|
116
|
-
headCheckedAt:
|
|
116
|
+
headCheckedAt: r
|
|
117
117
|
});
|
|
118
118
|
}, U = (e) => {
|
|
119
119
|
let t = B(e), n = e.cursorAfter, r = e.headCheckedAt;
|
|
@@ -146,15 +146,15 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
146
146
|
skip: void 0,
|
|
147
147
|
projection: void 0,
|
|
148
148
|
...r ? { lock: "update" } : {}
|
|
149
|
-
}), K = (e, t) => e.id === t.id && e.revision === t.revision && e.round === t.round && e.pageOrdinal === t.pageOrdinal && e.exhausted === t.exhausted && e.cursor?.afterInvoiceId === t.cursor?.afterInvoiceId && (e.headCheckedAt?.getTime() ?? null) === (t.headCheckedAt?.getTime() ?? null), q = (
|
|
150
|
-
let
|
|
151
|
-
let
|
|
152
|
-
if (
|
|
153
|
-
V(R(
|
|
154
|
-
},
|
|
155
|
-
for (let
|
|
156
|
-
let
|
|
157
|
-
if ((await e.query(G(
|
|
149
|
+
}), K = (e, t) => e.id === t.id && e.revision === t.revision && e.round === t.round && e.pageOrdinal === t.pageOrdinal && e.exhausted === t.exhausted && e.cursor?.afterInvoiceId === t.cursor?.afterInvoiceId && (e.headCheckedAt?.getTime() ?? null) === (t.headCheckedAt?.getTime() ?? null), q = (r) => {
|
|
150
|
+
let i = async (t, n) => {
|
|
151
|
+
let r = await c.runPromise(e(t).getByProviderCustomerId(n.providerCustomerId, n));
|
|
152
|
+
if (r === null) throw F("Positive retained customer custody is required before invoice history admission.");
|
|
153
|
+
V(R(r), n);
|
|
154
|
+
}, a = (e) => l(d("provider", e.provider), d("providerAccountId", e.account.providerAccountId), d("livemode", +!!e.account.livemode), d("providerCustomerId", e.providerCustomerId)), o = async (e, t) => {
|
|
155
|
+
for (let n of [T, E]) {
|
|
156
|
+
let r = y(v("walkId", t.id), v("custodyId", t.custodyId), v("tenantId", t.tenantId), f("pageOrdinal", t.pageOrdinal), f("round", t.round), g("pageOrdinal", 1), g("round", 1)), i = y(v("provider", t.provider), v("providerAccountId", t.account.providerAccountId), v("livemode", +!!t.account.livemode), v("providerCustomerId", t.providerCustomerId)), o = y(l(a(t), r), l(d("walkId", t.id), y(r, i)));
|
|
157
|
+
if ((await e.query(G(n, o, 1))).length) throw F("Invoice history receipts do not belong to the retained walk checkpoint; explicit reconciliation is required.", !0);
|
|
158
158
|
}
|
|
159
159
|
}, s = (e) => {
|
|
160
160
|
if (typeof e == "bigint") {
|
|
@@ -184,13 +184,13 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
184
184
|
let r = N(n[0].round, 1), i = n[0].nextCursorAfter;
|
|
185
185
|
if (i !== null && typeof i != "string" || r > t.round || r === t.round && (i !== (t.cursor?.afterInvoiceId ?? null) || t.exhausted !== (i === null)) || r < t.round && (t.cursor !== null || t.exhausted)) throw F("The retained provider cursor does not match the admitted history head.");
|
|
186
186
|
}
|
|
187
|
-
}, h = async (e, t, n,
|
|
188
|
-
let
|
|
189
|
-
if (
|
|
190
|
-
if (!
|
|
191
|
-
let
|
|
192
|
-
if (V(
|
|
193
|
-
return await
|
|
187
|
+
}, h = async (e, t, n, r = !1) => {
|
|
188
|
+
let i = await e.query(G(w, d("identityKey", n), 2, r));
|
|
189
|
+
if (i.length > 1) throw F();
|
|
190
|
+
if (!i[0]) return null;
|
|
191
|
+
let a = U(i[0]);
|
|
192
|
+
if (V(a, t), i[0].identityKey !== n || await W(a) !== n) throw F();
|
|
193
|
+
return await o(e, a), await p(e, a), a;
|
|
194
194
|
}, x = async (e, t, n, r) => {
|
|
195
195
|
if (t.revision >= j) throw F("The invoice history revision is exhausted.");
|
|
196
196
|
if (await e.updateMany("_voltro_billing_invoice_history_walks", {
|
|
@@ -283,19 +283,19 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
283
283
|
let t = s.get(M(e.pageId));
|
|
284
284
|
if (t === void 0 || !t.some((t) => t.id === e.id && t.referenceKey === e.referenceKey)) throw F();
|
|
285
285
|
}
|
|
286
|
-
}, D = async (e,
|
|
287
|
-
if (
|
|
288
|
-
await
|
|
289
|
-
let
|
|
290
|
-
if (
|
|
291
|
-
if (
|
|
292
|
-
let a = await e.query(G(E, m("id",
|
|
293
|
-
if (a.length >
|
|
294
|
-
await C(e,
|
|
286
|
+
}, D = async (e, t, n) => {
|
|
287
|
+
if (n.length > 101 || new Set(n).size !== n.length) throw F();
|
|
288
|
+
await i(e, t);
|
|
289
|
+
let r = await h(e, t, await W(t), !0);
|
|
290
|
+
if (r === null) throw F("No retained owned invoice history walk exists.");
|
|
291
|
+
if (n.length === 0) return /* @__PURE__ */ new Map();
|
|
292
|
+
let a = await e.query(G(E, m("id", n), n.length + 1));
|
|
293
|
+
if (a.length > n.length) throw F();
|
|
294
|
+
await C(e, r, a);
|
|
295
295
|
let o = /* @__PURE__ */ new Map();
|
|
296
296
|
for (let e of a) {
|
|
297
|
-
let t = S(e,
|
|
298
|
-
if (!
|
|
297
|
+
let t = S(e, r);
|
|
298
|
+
if (!n.includes(t.id) || o.has(t.id)) throw F();
|
|
299
299
|
o.set(t.id, t);
|
|
300
300
|
}
|
|
301
301
|
return o;
|
|
@@ -385,10 +385,10 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
385
385
|
}), x(e, t, v, i);
|
|
386
386
|
};
|
|
387
387
|
return {
|
|
388
|
-
referencesByIds: (
|
|
389
|
-
let
|
|
390
|
-
return
|
|
391
|
-
let t = await D(e,
|
|
388
|
+
referencesByIds: (e, t) => I(async () => {
|
|
389
|
+
let n = R(e), i = t.map((e) => M(e));
|
|
390
|
+
return r(async (e) => {
|
|
391
|
+
let t = await D(e, n, i);
|
|
392
392
|
return i.map((e) => {
|
|
393
393
|
let n = t.get(e);
|
|
394
394
|
if (n === void 0) throw F("A selected invoice history reference is missing.");
|
|
@@ -396,17 +396,17 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
396
396
|
});
|
|
397
397
|
});
|
|
398
398
|
}),
|
|
399
|
-
begin: (
|
|
400
|
-
let
|
|
401
|
-
return
|
|
402
|
-
await
|
|
403
|
-
let r = await h(e,
|
|
399
|
+
begin: (e) => I(async () => {
|
|
400
|
+
let t = R(e), n = await W(t);
|
|
401
|
+
return r(async (e) => {
|
|
402
|
+
await i(e, t);
|
|
403
|
+
let r = await h(e, t, n, !0);
|
|
404
404
|
if (r !== null) return r;
|
|
405
|
-
for (let
|
|
405
|
+
for (let n of [T, E]) if ((await e.query(G(n, a(t), 1))).length) throw F("Retained invoice history receipts require their original walk root; no replacement root is fabricated.");
|
|
406
406
|
await e.insertIgnore(w, {
|
|
407
407
|
id: "bihwalk_" + globalThis.crypto.randomUUID(),
|
|
408
|
-
...z(
|
|
409
|
-
identityKey:
|
|
408
|
+
...z(t),
|
|
409
|
+
identityKey: n,
|
|
410
410
|
revision: 1,
|
|
411
411
|
round: 1,
|
|
412
412
|
pageOrdinal: 0,
|
|
@@ -414,65 +414,65 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
414
414
|
exhausted: 0,
|
|
415
415
|
headCheckedAt: null
|
|
416
416
|
}, { conflictColumns: ["identityKey"] });
|
|
417
|
-
let o = await h(e,
|
|
417
|
+
let o = await h(e, t, n, !0);
|
|
418
418
|
if (o === null) throw F("The invoice history owner reservation was not read back.", !0);
|
|
419
419
|
return o;
|
|
420
420
|
});
|
|
421
421
|
}),
|
|
422
|
-
read: (
|
|
423
|
-
let
|
|
424
|
-
return
|
|
422
|
+
read: (e) => I(async () => {
|
|
423
|
+
let t = R(e), n = await W(t);
|
|
424
|
+
return r(async (e) => (await i(e, t), h(e, t, n)));
|
|
425
425
|
}),
|
|
426
|
-
commitPage: (
|
|
427
|
-
let
|
|
428
|
-
account:
|
|
429
|
-
providerCustomerId:
|
|
430
|
-
...
|
|
431
|
-
}), c =
|
|
432
|
-
if (
|
|
433
|
-
let l = await W(
|
|
434
|
-
return
|
|
435
|
-
await
|
|
436
|
-
let
|
|
437
|
-
return
|
|
426
|
+
commitPage: (e, a) => I(async () => {
|
|
427
|
+
let o = H(e), s = t({
|
|
428
|
+
account: o.account,
|
|
429
|
+
providerCustomerId: o.providerCustomerId,
|
|
430
|
+
...o.cursor === null ? {} : { cursor: o.cursor }
|
|
431
|
+
}), c = n(s, a);
|
|
432
|
+
if (o.exhausted || o.revision >= j || o.pageOrdinal >= j) throw F();
|
|
433
|
+
let l = await W(o);
|
|
434
|
+
return r(async (e) => {
|
|
435
|
+
await i(e, o);
|
|
436
|
+
let t = await h(e, o, l, !0);
|
|
437
|
+
return t === null || !K(t, o) ? null : k(e, t, t.round, c, l);
|
|
438
438
|
});
|
|
439
439
|
}),
|
|
440
|
-
scanHead: (
|
|
441
|
-
let
|
|
442
|
-
account:
|
|
443
|
-
providerCustomerId:
|
|
444
|
-
}),
|
|
445
|
-
if (!
|
|
446
|
-
let c = await W(
|
|
447
|
-
return
|
|
448
|
-
await
|
|
449
|
-
let
|
|
450
|
-
if (
|
|
451
|
-
let
|
|
452
|
-
return s.invoices.some((e) => !
|
|
453
|
-
...
|
|
440
|
+
scanHead: (e, a) => I(async () => {
|
|
441
|
+
let o = H(e), s = n(t({
|
|
442
|
+
account: o.account,
|
|
443
|
+
providerCustomerId: o.providerCustomerId
|
|
444
|
+
}), a);
|
|
445
|
+
if (!o.exhausted || o.round >= j || o.revision >= 2147483646 || o.pageOrdinal >= j) throw F();
|
|
446
|
+
let c = await W(o);
|
|
447
|
+
return r(async (e) => {
|
|
448
|
+
await i(e, o);
|
|
449
|
+
let t = await h(e, o, c, !0);
|
|
450
|
+
if (t === null || !K(t, o)) return null;
|
|
451
|
+
let n = await O(e, t, t.round + 1, s);
|
|
452
|
+
return s.invoices.some((e) => !n.has(e.providerInvoiceId)) ? k(e, t, t.round + 1, s, c, n) : t.headCheckedAt?.getTime() === s.observedAt.getTime() ? t : x(e, t, H({
|
|
453
|
+
...t,
|
|
454
454
|
headCheckedAt: s.observedAt
|
|
455
455
|
}), c);
|
|
456
456
|
});
|
|
457
457
|
}),
|
|
458
|
-
reference: (
|
|
459
|
-
let
|
|
460
|
-
return
|
|
458
|
+
reference: (e, t) => I(async () => {
|
|
459
|
+
let n = R(e), i = M(t);
|
|
460
|
+
return r(async (e) => (await D(e, n, [i])).get(i) ?? null);
|
|
461
461
|
}),
|
|
462
|
-
references: (
|
|
463
|
-
let
|
|
462
|
+
references: (e, t) => I(async () => {
|
|
463
|
+
let n = R(e), a = t?.limit ?? 100, o = t?.afterReferenceId === void 0 ? null : M(t.afterReferenceId);
|
|
464
464
|
if (!Number.isSafeInteger(a) || a < 1 || a > 100) throw F();
|
|
465
|
-
let s = await W(
|
|
466
|
-
return
|
|
467
|
-
await
|
|
468
|
-
let
|
|
469
|
-
if (
|
|
470
|
-
let r = [d("walkId",
|
|
465
|
+
let s = await W(n);
|
|
466
|
+
return r(async (e) => {
|
|
467
|
+
await i(e, n);
|
|
468
|
+
let t = await h(e, n, s);
|
|
469
|
+
if (t === null) throw F("No owned invoice history walk exists.");
|
|
470
|
+
let r = [d("walkId", t.id), _("pageOrdinal", t.pageOrdinal)];
|
|
471
471
|
if (o !== null) {
|
|
472
|
-
let
|
|
473
|
-
if (
|
|
474
|
-
await C(e,
|
|
475
|
-
let i = S(
|
|
472
|
+
let n = await e.query(G(E, d("id", o), 2));
|
|
473
|
+
if (n.length !== 1 || n[0]?.id !== o) throw F("The invoice reference cursor is not retained by this walk.");
|
|
474
|
+
await C(e, t, n);
|
|
475
|
+
let i = S(n[0], t);
|
|
476
476
|
r.push(y(f("pageOrdinal", i.pageOrdinal), l(d("pageOrdinal", i.pageOrdinal), f("position", i.position))));
|
|
477
477
|
}
|
|
478
478
|
let c = await e.query({
|
|
@@ -485,13 +485,13 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
485
485
|
direction: "asc"
|
|
486
486
|
}]
|
|
487
487
|
});
|
|
488
|
-
await C(e,
|
|
489
|
-
let u = c.map((e) => S(e,
|
|
488
|
+
await C(e, t, c);
|
|
489
|
+
let u = c.map((e) => S(e, t)), p = u.slice(0, a);
|
|
490
490
|
return {
|
|
491
491
|
references: p,
|
|
492
492
|
nextReferenceId: u.length > a ? p.at(-1).id : null,
|
|
493
|
-
watermarkPageOrdinal:
|
|
494
|
-
walkRevision:
|
|
493
|
+
watermarkPageOrdinal: t.pageOrdinal,
|
|
494
|
+
walkRevision: t.revision
|
|
495
495
|
};
|
|
496
496
|
});
|
|
497
497
|
})
|
|
@@ -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
|
|
@@ -29,12 +29,12 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
29
29
|
afterReadyId: h().maxLength(191).nullable(),
|
|
30
30
|
afterWorkingId: h().maxLength(191).nullable(),
|
|
31
31
|
afterObservedId: h().maxLength(191).nullable()
|
|
32
|
-
}).unique("byBillingHistoryDispatchCustody", ["identityKey"]).index("byBillingHistoryDispatchTenant", ["tenantId"]), S = 2147483647, C = () => new
|
|
32
|
+
}).unique("byBillingHistoryDispatchCustody", ["identityKey"]).index("byBillingHistoryDispatchTenant", ["tenantId"]), S = 2147483647, C = () => new s({
|
|
33
33
|
source: "invoiceHistoryProgress",
|
|
34
34
|
message: "Invoice-history traversal requires fresh owned native state.",
|
|
35
35
|
transient: !0
|
|
36
36
|
}), w = (e, t = 191) => {
|
|
37
|
-
if (!
|
|
37
|
+
if (!a(e) || e.length > t || !e.isWellFormed()) throw C();
|
|
38
38
|
return e;
|
|
39
39
|
}, T = (e, t) => w(d({
|
|
40
40
|
kind: "typeid",
|
|
@@ -47,10 +47,10 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
47
47
|
if (typeof e != "number" || !Number.isInteger(e) || e < 1 || e > S) throw C();
|
|
48
48
|
return e;
|
|
49
49
|
}, k = (e) => {
|
|
50
|
-
let
|
|
51
|
-
return w(
|
|
50
|
+
let t = i(e.account);
|
|
51
|
+
return w(t.providerAccountId), {
|
|
52
52
|
provider: w(e.provider, 64),
|
|
53
|
-
account:
|
|
53
|
+
account: t
|
|
54
54
|
};
|
|
55
55
|
}, A = (e) => ({
|
|
56
56
|
provider: e.provider,
|
|
@@ -70,38 +70,38 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
70
70
|
skip: void 0,
|
|
71
71
|
projection: void 0,
|
|
72
72
|
...n ? { lock: "update" } : {}
|
|
73
|
-
}), N = (
|
|
74
|
-
try:
|
|
75
|
-
catch: (
|
|
73
|
+
}), N = (e) => c.tryPromise({
|
|
74
|
+
try: e,
|
|
75
|
+
catch: (e) => e instanceof s ? e : C()
|
|
76
76
|
}), P = [
|
|
77
77
|
"unprepared",
|
|
78
78
|
"ready",
|
|
79
79
|
"working",
|
|
80
80
|
"observed"
|
|
81
|
-
], F = (
|
|
82
|
-
let
|
|
83
|
-
let
|
|
84
|
-
if (l === null || l.id !== i || l.tenantId !==
|
|
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();
|
|
85
85
|
return l;
|
|
86
|
-
},
|
|
87
|
-
let
|
|
88
|
-
...M(
|
|
89
|
-
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))
|
|
90
90
|
});
|
|
91
|
-
if (
|
|
92
|
-
let o = await c.runPromise(
|
|
93
|
-
if (o === null || o.id !==
|
|
94
|
-
}, d = async (
|
|
95
|
-
let r = await
|
|
96
|
-
...M(
|
|
97
|
-
predicate: l(u("provider",
|
|
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
98
|
order: [{
|
|
99
99
|
column: "id",
|
|
100
100
|
direction: "desc"
|
|
101
101
|
}],
|
|
102
102
|
take: 1
|
|
103
|
-
}),
|
|
104
|
-
return
|
|
103
|
+
}), i = r[0] === void 0 ? null : w(r[0].id);
|
|
104
|
+
return i !== null && await s(t, n, i), i;
|
|
105
105
|
}, f = async (e, t, n, r, i = !0) => {
|
|
106
106
|
let a = await e.query(M(t, r, i));
|
|
107
107
|
if (a.length > 1) throw C();
|
|
@@ -109,53 +109,53 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
109
109
|
if (!o) return null;
|
|
110
110
|
if (o.identityKey !== r || o.provider !== n.provider || o.providerAccountId !== n.account.providerAccountId || o.livemode !== +!!n.account.livemode) throw C();
|
|
111
111
|
return w(o.id), O(o.revision), D(o.updatedAt), o;
|
|
112
|
-
}, p = async (e, t,
|
|
113
|
-
let
|
|
114
|
-
return
|
|
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), {
|
|
115
115
|
...t,
|
|
116
|
-
id: w(
|
|
117
|
-
revision: O(
|
|
118
|
-
afterCustodyId:
|
|
119
|
-
cycleEndCustodyId:
|
|
120
|
-
updatedAt: D(
|
|
116
|
+
id: w(n.id),
|
|
117
|
+
revision: O(n.revision),
|
|
118
|
+
afterCustodyId: r,
|
|
119
|
+
cycleEndCustodyId: i,
|
|
120
|
+
updatedAt: D(n.updatedAt)
|
|
121
121
|
};
|
|
122
|
-
}, m = async (e, t,
|
|
123
|
-
if (
|
|
124
|
-
let
|
|
125
|
-
unprepared: E(
|
|
126
|
-
ready: E(
|
|
127
|
-
working: E(
|
|
128
|
-
observed: 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)
|
|
129
129
|
};
|
|
130
|
-
if (
|
|
131
|
-
if (
|
|
132
|
-
let
|
|
133
|
-
if (
|
|
134
|
-
for (let
|
|
135
|
-
let
|
|
136
|
-
if (
|
|
137
|
-
let l =
|
|
138
|
-
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") {
|
|
139
139
|
let n = await e.query({
|
|
140
|
-
...M(
|
|
141
|
-
predicate: u("id",
|
|
140
|
+
...M(r, s),
|
|
141
|
+
predicate: u("id", s)
|
|
142
142
|
});
|
|
143
|
-
if (n.length !== 1 || n[0]?.id !==
|
|
143
|
+
if (n.length !== 1 || n[0]?.id !== s) throw C();
|
|
144
144
|
let i = n[0];
|
|
145
|
-
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();
|
|
146
146
|
l = w(i.referenceId);
|
|
147
147
|
}
|
|
148
|
-
let d = await c.runPromise(
|
|
149
|
-
if (d === null || d.walkId !==
|
|
148
|
+
let d = await c.runPromise(i.reference(t, l));
|
|
149
|
+
if (d === null || d.walkId !== a) throw C();
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
return {
|
|
153
|
-
id: w(
|
|
154
|
-
revision: O(
|
|
153
|
+
id: w(i.id),
|
|
154
|
+
revision: O(i.revision),
|
|
155
155
|
owner: t,
|
|
156
|
-
walkId:
|
|
157
|
-
cursors:
|
|
158
|
-
updatedAt: D(
|
|
156
|
+
walkId: a,
|
|
157
|
+
cursors: o,
|
|
158
|
+
updatedAt: D(i.updatedAt)
|
|
159
159
|
};
|
|
160
160
|
}, h = async (e, t, n, r, i, a, o) => {
|
|
161
161
|
let s = await f(e, t, n, r);
|
|
@@ -175,82 +175,82 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
175
175
|
return p;
|
|
176
176
|
};
|
|
177
177
|
return {
|
|
178
|
-
account: (
|
|
179
|
-
let
|
|
180
|
-
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) => {
|
|
181
181
|
await e.insertIgnore(_, {
|
|
182
182
|
id: T(_, "bihscan"),
|
|
183
|
-
...A(
|
|
183
|
+
...A(n),
|
|
184
184
|
identityKey: a,
|
|
185
185
|
revision: 1,
|
|
186
186
|
afterCustodyId: null,
|
|
187
|
-
cycleEndCustodyId: await d(e,
|
|
188
|
-
updatedAt:
|
|
187
|
+
cycleEndCustodyId: await d(e, n),
|
|
188
|
+
updatedAt: r
|
|
189
189
|
}, { conflictColumns: ["identityKey"] });
|
|
190
|
-
let t = await f(e, _,
|
|
190
|
+
let t = await f(e, _, n, a);
|
|
191
191
|
if (t === null) throw C();
|
|
192
|
-
return p(e,
|
|
192
|
+
return p(e, n, t);
|
|
193
193
|
});
|
|
194
194
|
}),
|
|
195
|
-
advanceAccount: (
|
|
196
|
-
let
|
|
197
|
-
return
|
|
198
|
-
|
|
199
|
-
let t =
|
|
200
|
-
t !== null && await
|
|
201
|
-
let
|
|
202
|
-
afterCustodyId:
|
|
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
203
|
cycleEndCustodyId: t
|
|
204
204
|
}, c);
|
|
205
|
-
return
|
|
205
|
+
return n === null ? null : p(e, a, n);
|
|
206
206
|
});
|
|
207
207
|
}),
|
|
208
|
-
customer: (
|
|
209
|
-
let
|
|
210
|
-
return
|
|
211
|
-
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);
|
|
212
212
|
await e.insertIgnore(v, {
|
|
213
213
|
id: T(v, "bihdispatch"),
|
|
214
|
-
...A(
|
|
215
|
-
tenantId:
|
|
216
|
-
providerCustomerId:
|
|
217
|
-
custodyId:
|
|
218
|
-
identityKey:
|
|
214
|
+
...A(t),
|
|
215
|
+
tenantId: t.tenantId,
|
|
216
|
+
providerCustomerId: t.providerCustomerId,
|
|
217
|
+
custodyId: t.id,
|
|
218
|
+
identityKey: i,
|
|
219
219
|
revision: 1,
|
|
220
220
|
walkId: null,
|
|
221
221
|
afterUnpreparedId: null,
|
|
222
222
|
afterReadyId: null,
|
|
223
223
|
afterWorkingId: null,
|
|
224
224
|
afterObservedId: null,
|
|
225
|
-
updatedAt:
|
|
225
|
+
updatedAt: r
|
|
226
226
|
}, { conflictColumns: ["identityKey"] });
|
|
227
|
-
let o = await f(e, v,
|
|
227
|
+
let o = await f(e, v, t, i);
|
|
228
228
|
if (o === null) throw C();
|
|
229
|
-
return m(e,
|
|
229
|
+
return m(e, t, o);
|
|
230
230
|
});
|
|
231
231
|
}),
|
|
232
|
-
advanceCustomer: (
|
|
233
|
-
let
|
|
234
|
-
return
|
|
235
|
-
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 = {
|
|
236
236
|
walkId: E(o.walkId),
|
|
237
237
|
afterUnpreparedId: E(o.cursors.unprepared),
|
|
238
238
|
afterReadyId: E(o.cursors.ready),
|
|
239
239
|
afterWorkingId: E(o.cursors.working),
|
|
240
240
|
afterObservedId: E(o.cursors.observed)
|
|
241
241
|
};
|
|
242
|
-
await m(e,
|
|
243
|
-
id:
|
|
244
|
-
revision:
|
|
245
|
-
...A(
|
|
246
|
-
tenantId:
|
|
247
|
-
providerCustomerId:
|
|
248
|
-
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,
|
|
249
249
|
...i,
|
|
250
250
|
updatedAt: s
|
|
251
251
|
});
|
|
252
|
-
let c = await h(e, v, n, r,
|
|
253
|
-
return c === null ? null : m(e,
|
|
252
|
+
let c = await h(e, v, t, n, r, i, s);
|
|
253
|
+
return c === null ? null : m(e, t, c);
|
|
254
254
|
});
|
|
255
255
|
})
|
|
256
256
|
};
|