@voltro/plugin-billing 0.89.2 → 0.90.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 +1822 -0
- package/README.md +0 -435
- package/dist/catalog.js +175 -76
- 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 +773 -67
- package/dist/index.js +340 -219
- package/dist/invoiceHistoryJournal.js +115 -90
- package/dist/invoiceHistoryProgress.js +49 -25
- package/dist/invoiceHistoryWork.js +162 -160
- package/dist/invoicePaymentEpoch.js +145 -0
- package/dist/invoicePaymentObservation.js +64 -0
- package/dist/invoiceSnapshot.js +52 -42
- package/dist/invoiceStore.js +122 -88
- package/dist/paidInvoiceCoverage.js +84 -0
- package/dist/plans.js +15 -2
- package/dist/providers.js +124 -67
- package/dist/provision.js +84 -73
- package/dist/rpc.d.ts +53 -13
- package/dist/rpc.js +141 -78
- package/dist/service.js +1159 -673
- package/dist/stores.js +231 -139
- package/dist/stripeInvoicePayments.js +129 -0
- package/dist/stripeInvoiceSnapshot.js +59 -40
- package/dist/stripeProvider.js +542 -173
- 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 +8 -8
|
@@ -20,7 +20,8 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
20
20
|
round: h(),
|
|
21
21
|
pageOrdinal: h(),
|
|
22
22
|
cursorAfter: S().maxLength(191).nullable(),
|
|
23
|
-
exhausted: h()
|
|
23
|
+
exhausted: h(),
|
|
24
|
+
headCheckedAt: C().nullable()
|
|
24
25
|
}).unique("byBillingInvoiceHistoryOwner", ["identityKey"]).index("byBillingInvoiceHistoryTenant", ["tenantId"]), k = x(T, {
|
|
25
26
|
id: p({ prefix: "bihpage" }),
|
|
26
27
|
...D(),
|
|
@@ -49,7 +50,7 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
49
50
|
"walkId",
|
|
50
51
|
"pageOrdinal",
|
|
51
52
|
"position"
|
|
52
|
-
]).index("byBillingInvoiceHistoryReferenceTenant", ["tenantId"]), j = 2147483647, M = (e, t = 191) => {
|
|
53
|
+
]).index("byBillingInvoiceHistoryReferenceInvoice", ["walkId", "providerInvoiceId"]).index("byBillingInvoiceHistoryReferenceTenant", ["tenantId"]), j = 2147483647, M = (e, t = 191) => {
|
|
53
54
|
if (!n(e) || e.length > t || !e.isWellFormed()) throw F();
|
|
54
55
|
return e;
|
|
55
56
|
}, N = (e, t = 0) => {
|
|
@@ -98,23 +99,24 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
98
99
|
}, H = (e) => {
|
|
99
100
|
let t = R(e);
|
|
100
101
|
if (typeof e.exhausted != "boolean" || e.exhausted && e.cursor !== null) throw F();
|
|
101
|
-
let n = e.cursor === null ? null : a({
|
|
102
|
+
let n = e.headCheckedAt === null ? null : P(e.headCheckedAt), r = e.cursor === null ? null : a({
|
|
102
103
|
account: t.account,
|
|
103
104
|
providerCustomerId: t.providerCustomerId,
|
|
104
105
|
cursor: e.cursor
|
|
105
106
|
}).cursor;
|
|
106
|
-
if (
|
|
107
|
+
if (r === void 0 || e.revision !== e.pageOrdinal + e.round || e.pageOrdinal === 0 && (e.cursor !== null || e.exhausted)) throw F();
|
|
107
108
|
return Object.freeze({
|
|
108
109
|
...t,
|
|
109
110
|
id: M(e.id),
|
|
110
111
|
revision: N(e.revision, 1),
|
|
111
112
|
round: N(e.round, 1),
|
|
112
113
|
pageOrdinal: N(e.pageOrdinal),
|
|
113
|
-
cursor:
|
|
114
|
-
exhausted: e.exhausted
|
|
114
|
+
cursor: r,
|
|
115
|
+
exhausted: e.exhausted,
|
|
116
|
+
headCheckedAt: n
|
|
115
117
|
});
|
|
116
118
|
}, U = (e) => {
|
|
117
|
-
let t = B(e), n = e.cursorAfter;
|
|
119
|
+
let t = B(e), n = e.cursorAfter, r = e.headCheckedAt;
|
|
118
120
|
if (e.exhausted !== 0 && e.exhausted !== 1 || n !== null && typeof n != "string") throw F();
|
|
119
121
|
return H({
|
|
120
122
|
...t,
|
|
@@ -123,6 +125,7 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
123
125
|
round: N(e.round, 1),
|
|
124
126
|
pageOrdinal: N(e.pageOrdinal),
|
|
125
127
|
exhausted: e.exhausted === 1,
|
|
128
|
+
headCheckedAt: r == null ? null : P(r),
|
|
126
129
|
cursor: n === null ? null : {
|
|
127
130
|
...t.account,
|
|
128
131
|
providerCustomerId: t.providerCustomerId,
|
|
@@ -143,7 +146,7 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
143
146
|
skip: void 0,
|
|
144
147
|
projection: void 0,
|
|
145
148
|
...r ? { lock: "update" } : {}
|
|
146
|
-
}), 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, q = (e) => {
|
|
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 = (e) => {
|
|
147
150
|
let t = async (e, t) => {
|
|
148
151
|
let n = await c.runPromise(i(e).getByProviderCustomerId(t.providerCustomerId, t));
|
|
149
152
|
if (n === null) throw F("Positive retained customer custody is required before invoice history admission.");
|
|
@@ -195,7 +198,8 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
195
198
|
round: n.round,
|
|
196
199
|
pageOrdinal: n.pageOrdinal,
|
|
197
200
|
cursorAfter: n.cursor?.afterInvoiceId ?? null,
|
|
198
|
-
exhausted: +!!n.exhausted
|
|
201
|
+
exhausted: +!!n.exhausted,
|
|
202
|
+
headCheckedAt: n.headCheckedAt
|
|
199
203
|
}, { where: l(d("id", t.id), d("identityKey", r), d("revision", t.revision), d("custodyId", t.custodyId)) }) !== 1) throw F("Invoice history changed during the native page transaction.", !0);
|
|
200
204
|
let i = await h(e, n, r, !0);
|
|
201
205
|
if (i === null || !K(i, n)) throw F("The invoice history checkpoint was not read back.", !0);
|
|
@@ -295,6 +299,90 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
295
299
|
o.set(t.id, t);
|
|
296
300
|
}
|
|
297
301
|
return o;
|
|
302
|
+
}, O = async (e, t, n, r) => {
|
|
303
|
+
let i = r.invoices.map((e) => e.providerInvoiceId);
|
|
304
|
+
if (i.length === 0) return /* @__PURE__ */ new Set();
|
|
305
|
+
let a = await e.query({
|
|
306
|
+
...G(E, l(d("walkId", t.id), m("providerInvoiceId", i)), 1),
|
|
307
|
+
take: void 0
|
|
308
|
+
}), o = /* @__PURE__ */ new Set();
|
|
309
|
+
for (let e of a) {
|
|
310
|
+
let r = S(e, t);
|
|
311
|
+
if (r.round >= n) throw F("The invoice history cursor or invoice repeated within this round; the page remains uncommitted.");
|
|
312
|
+
o.add(r.providerInvoiceId);
|
|
313
|
+
}
|
|
314
|
+
return o;
|
|
315
|
+
}, k = async (e, t, n, r, i, a) => {
|
|
316
|
+
let o = a ?? await O(e, t, n, r), s = r.invoices.filter((e) => !o.has(e.providerInvoiceId)), c = o.size > 0 ? null : r.nextCursor, l = n === t.round ? t.cursor?.afterInvoiceId ?? null : null, u = c?.afterInvoiceId ?? null, f = await L([
|
|
317
|
+
"voltro.invoice-history-page.v1",
|
|
318
|
+
t.id,
|
|
319
|
+
n,
|
|
320
|
+
l
|
|
321
|
+
]), p = await Promise.all(s.map((e) => L([
|
|
322
|
+
"voltro.invoice-history-reference.v1",
|
|
323
|
+
t.id,
|
|
324
|
+
n,
|
|
325
|
+
e.providerInvoiceId
|
|
326
|
+
]))), h = await L([
|
|
327
|
+
f,
|
|
328
|
+
u,
|
|
329
|
+
r.observedAt.toISOString(),
|
|
330
|
+
s.map((e) => [
|
|
331
|
+
e.providerInvoiceId,
|
|
332
|
+
e.status,
|
|
333
|
+
e.createdAt.toISOString()
|
|
334
|
+
])
|
|
335
|
+
]);
|
|
336
|
+
if ((await e.query(G("_voltro_billing_invoice_history_pages", d("pageKey", f), 1))).length || p.length > 0 && (await e.query(G("_voltro_billing_invoice_history_references", m("referenceKey", p), 1))).length) throw F("The invoice history cursor or invoice repeated within this round; the page remains uncommitted.");
|
|
337
|
+
let g = "bihpage_" + globalThis.crypto.randomUUID(), _ = t.pageOrdinal + 1;
|
|
338
|
+
await e.insert(T, {
|
|
339
|
+
id: g,
|
|
340
|
+
...z(t),
|
|
341
|
+
walkId: t.id,
|
|
342
|
+
round: n,
|
|
343
|
+
pageOrdinal: _,
|
|
344
|
+
pageKey: f,
|
|
345
|
+
bodyDigest: h,
|
|
346
|
+
cursorAfter: l,
|
|
347
|
+
nextCursorAfter: u,
|
|
348
|
+
referenceCount: s.length,
|
|
349
|
+
observedAt: r.observedAt
|
|
350
|
+
}), await e.insertMany(E, s.map((e, r) => ({
|
|
351
|
+
id: "bihref_" + globalThis.crypto.randomUUID(),
|
|
352
|
+
...z(t),
|
|
353
|
+
walkId: t.id,
|
|
354
|
+
round: n,
|
|
355
|
+
pageId: g,
|
|
356
|
+
pageOrdinal: _,
|
|
357
|
+
position: r,
|
|
358
|
+
referenceKey: p[r],
|
|
359
|
+
providerInvoiceId: e.providerInvoiceId,
|
|
360
|
+
discoveryStatus: e.status,
|
|
361
|
+
providerCreatedAt: e.createdAt
|
|
362
|
+
})));
|
|
363
|
+
let v = H({
|
|
364
|
+
...t,
|
|
365
|
+
revision: t.revision + 1 + (n - t.round),
|
|
366
|
+
round: n,
|
|
367
|
+
pageOrdinal: _,
|
|
368
|
+
cursor: c,
|
|
369
|
+
exhausted: c === null,
|
|
370
|
+
headCheckedAt: c === null ? r.observedAt : t.headCheckedAt
|
|
371
|
+
}), y = await e.query(G(T, d("pageKey", f), 2));
|
|
372
|
+
if (y.length !== 1 || y[0]?.id !== g || y[0]?.bodyDigest !== h || y[0]?.referenceCount !== s.length || y[0]?.walkId !== t.id || y[0]?.round !== n || y[0]?.pageOrdinal !== _ || y[0]?.cursorAfter !== l || y[0]?.nextCursorAfter !== u || P(y[0]?.observedAt).getTime() !== r.observedAt.getTime()) throw F("The admitted page receipt was not read back.", !0);
|
|
373
|
+
V(B(y[0]), t);
|
|
374
|
+
let b = await e.query({
|
|
375
|
+
...G(E, d("pageId", g), 101),
|
|
376
|
+
order: [{
|
|
377
|
+
column: "position",
|
|
378
|
+
direction: "asc"
|
|
379
|
+
}]
|
|
380
|
+
});
|
|
381
|
+
if (b.length !== s.length) throw F("Not every invoice reference was read back; the page transaction must roll back.", !0);
|
|
382
|
+
return b.forEach((e, t) => {
|
|
383
|
+
let r = S(e, v), i = s[t];
|
|
384
|
+
if (!i || r.round !== n || r.pageOrdinal !== _ || r.pageId !== g || r.position !== t || e.referenceKey !== p[t] || r.providerInvoiceId !== i.providerInvoiceId || r.discoveryStatus !== i.status || r.providerCreatedAt.getTime() !== i.createdAt.getTime()) throw F("The persisted invoice reference differs from its admitted page.", !0);
|
|
385
|
+
}), x(e, t, v, i);
|
|
298
386
|
};
|
|
299
387
|
return {
|
|
300
388
|
referencesByIds: (t, n) => I(async () => {
|
|
@@ -323,7 +411,8 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
323
411
|
round: 1,
|
|
324
412
|
pageOrdinal: 0,
|
|
325
413
|
cursorAfter: null,
|
|
326
|
-
exhausted: 0
|
|
414
|
+
exhausted: 0,
|
|
415
|
+
headCheckedAt: null
|
|
327
416
|
}, { conflictColumns: ["identityKey"] });
|
|
328
417
|
let o = await h(e, i, a, !0);
|
|
329
418
|
if (o === null) throw F("The invoice history owner reservation was not read back.", !0);
|
|
@@ -341,93 +430,29 @@ var w = "_voltro_billing_invoice_history_walks", T = "_voltro_billing_invoice_hi
|
|
|
341
430
|
...i.cursor === null ? {} : { cursor: i.cursor }
|
|
342
431
|
}), c = o(s, r);
|
|
343
432
|
if (i.exhausted || i.revision >= j || i.pageOrdinal >= j) throw F();
|
|
344
|
-
let l = await W(i)
|
|
345
|
-
"voltro.invoice-history-page.v1",
|
|
346
|
-
i.id,
|
|
347
|
-
i.round,
|
|
348
|
-
u
|
|
349
|
-
]), p = await Promise.all(c.invoices.map((e) => L([
|
|
350
|
-
"voltro.invoice-history-reference.v1",
|
|
351
|
-
i.id,
|
|
352
|
-
i.round,
|
|
353
|
-
e.providerInvoiceId
|
|
354
|
-
]))), g = await L([
|
|
355
|
-
f,
|
|
356
|
-
c.nextCursor?.afterInvoiceId ?? null,
|
|
357
|
-
c.observedAt.toISOString(),
|
|
358
|
-
c.invoices.map((e) => [
|
|
359
|
-
e.providerInvoiceId,
|
|
360
|
-
e.status,
|
|
361
|
-
e.createdAt.toISOString()
|
|
362
|
-
])
|
|
363
|
-
]);
|
|
433
|
+
let l = await W(i);
|
|
364
434
|
return e(async (e) => {
|
|
365
435
|
await t(e, i);
|
|
366
436
|
let n = await h(e, i, l, !0);
|
|
367
|
-
|
|
368
|
-
if ((await e.query(G("_voltro_billing_invoice_history_pages", d("pageKey", f), 1))).length || p.length > 0 && (await e.query(G("_voltro_billing_invoice_history_references", m("referenceKey", p), 1))).length) throw F("The invoice history cursor or invoice repeated within this round; the page remains uncommitted.");
|
|
369
|
-
let r = "bihpage_" + globalThis.crypto.randomUUID(), a = n.pageOrdinal + 1;
|
|
370
|
-
await e.insert(T, {
|
|
371
|
-
id: r,
|
|
372
|
-
...z(n),
|
|
373
|
-
walkId: n.id,
|
|
374
|
-
round: n.round,
|
|
375
|
-
pageOrdinal: a,
|
|
376
|
-
pageKey: f,
|
|
377
|
-
bodyDigest: g,
|
|
378
|
-
cursorAfter: u,
|
|
379
|
-
nextCursorAfter: c.nextCursor?.afterInvoiceId ?? null,
|
|
380
|
-
referenceCount: c.invoices.length,
|
|
381
|
-
observedAt: c.observedAt
|
|
382
|
-
}), await e.insertMany(E, c.invoices.map((e, t) => ({
|
|
383
|
-
id: "bihref_" + globalThis.crypto.randomUUID(),
|
|
384
|
-
...z(n),
|
|
385
|
-
walkId: n.id,
|
|
386
|
-
round: n.round,
|
|
387
|
-
pageId: r,
|
|
388
|
-
pageOrdinal: a,
|
|
389
|
-
position: t,
|
|
390
|
-
referenceKey: p[t],
|
|
391
|
-
providerInvoiceId: e.providerInvoiceId,
|
|
392
|
-
discoveryStatus: e.status,
|
|
393
|
-
providerCreatedAt: e.createdAt
|
|
394
|
-
})));
|
|
395
|
-
let o = H({
|
|
396
|
-
...n,
|
|
397
|
-
revision: n.revision + 1,
|
|
398
|
-
pageOrdinal: a,
|
|
399
|
-
cursor: c.nextCursor,
|
|
400
|
-
exhausted: c.nextCursor === null
|
|
401
|
-
}), s = await e.query(G(T, d("pageKey", f), 2));
|
|
402
|
-
if (s.length !== 1 || s[0]?.id !== r || s[0]?.bodyDigest !== g || s[0]?.referenceCount !== c.invoices.length || s[0]?.walkId !== n.id || s[0]?.round !== n.round || s[0]?.pageOrdinal !== a || s[0]?.cursorAfter !== u || s[0]?.nextCursorAfter !== (c.nextCursor?.afterInvoiceId ?? null) || P(s[0]?.observedAt).getTime() !== c.observedAt.getTime()) throw F("The admitted page receipt was not read back.", !0);
|
|
403
|
-
V(B(s[0]), n);
|
|
404
|
-
let _ = await e.query({
|
|
405
|
-
...G(E, d("pageId", r), 101),
|
|
406
|
-
order: [{
|
|
407
|
-
column: "position",
|
|
408
|
-
direction: "asc"
|
|
409
|
-
}]
|
|
410
|
-
});
|
|
411
|
-
if (_.length !== c.invoices.length) throw F("Not every invoice reference was read back; the page transaction must roll back.", !0);
|
|
412
|
-
return _.forEach((e, t) => {
|
|
413
|
-
let i = S(e, o), s = c.invoices[t];
|
|
414
|
-
if (!s || i.round !== n.round || i.pageOrdinal !== a || i.pageId !== r || i.position !== t || e.referenceKey !== p[t] || i.providerInvoiceId !== s.providerInvoiceId || i.discoveryStatus !== s.status || i.providerCreatedAt.getTime() !== s.createdAt.getTime()) throw F("The persisted invoice reference differs from its admitted page.", !0);
|
|
415
|
-
}), x(e, n, o, l);
|
|
437
|
+
return n === null || !K(n, i) ? null : k(e, n, n.round, c, l);
|
|
416
438
|
});
|
|
417
439
|
}),
|
|
418
|
-
|
|
419
|
-
let
|
|
420
|
-
|
|
440
|
+
scanHead: (n, r) => I(async () => {
|
|
441
|
+
let i = H(n), s = o(a({
|
|
442
|
+
account: i.account,
|
|
443
|
+
providerCustomerId: i.providerCustomerId
|
|
444
|
+
}), r);
|
|
445
|
+
if (!i.exhausted || i.round >= j || i.revision >= 2147483646 || i.pageOrdinal >= j) throw F();
|
|
446
|
+
let c = await W(i);
|
|
421
447
|
return e(async (e) => {
|
|
422
|
-
await t(e,
|
|
423
|
-
let n = await h(e,
|
|
424
|
-
|
|
448
|
+
await t(e, i);
|
|
449
|
+
let n = await h(e, i, c, !0);
|
|
450
|
+
if (n === null || !K(n, i)) return null;
|
|
451
|
+
let r = await O(e, n, n.round + 1, s);
|
|
452
|
+
return s.invoices.some((e) => !r.has(e.providerInvoiceId)) ? k(e, n, n.round + 1, s, c, r) : n.headCheckedAt?.getTime() === s.observedAt.getTime() ? n : x(e, n, H({
|
|
425
453
|
...n,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
cursor: null,
|
|
429
|
-
exhausted: !1
|
|
430
|
-
}), i);
|
|
454
|
+
headCheckedAt: s.observedAt
|
|
455
|
+
}), c);
|
|
431
456
|
});
|
|
432
457
|
}),
|
|
433
458
|
reference: (t, n) => I(async () => {
|
|
@@ -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,7 +27,8 @@ 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
|
+
afterWorkingId: h().maxLength(191).nullable(),
|
|
31
|
+
afterObservedId: h().maxLength(191).nullable()
|
|
30
32
|
}).unique("byBillingHistoryDispatchCustody", ["identityKey"]).index("byBillingHistoryDispatchTenant", ["tenantId"]), S = 2147483647, C = () => new e({
|
|
31
33
|
source: "invoiceHistoryProgress",
|
|
32
34
|
message: "Invoice-history traversal requires fresh owned native state.",
|
|
@@ -74,7 +76,8 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
74
76
|
}), P = [
|
|
75
77
|
"unprepared",
|
|
76
78
|
"ready",
|
|
77
|
-
"working"
|
|
79
|
+
"working",
|
|
80
|
+
"observed"
|
|
78
81
|
], F = (e) => {
|
|
79
82
|
let t = async (e, t) => {
|
|
80
83
|
let n = k(t), i = w(t.id), o = w(t.tenantId), s = w(t.providerCustomerId), l = await c.runPromise(a(e).getByProviderCustomerId(s, n));
|
|
@@ -88,28 +91,41 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
88
91
|
if (r.length !== 1 || r[0]?.id !== n) throw C();
|
|
89
92
|
let o = await c.runPromise(a(e).getByProviderCustomerId(w(r[0].providerCustomerId), t));
|
|
90
93
|
if (o === null || o.id !== n || o.tenantId !== w(r[0].tenantId)) throw C();
|
|
91
|
-
}, d = async (e, t
|
|
94
|
+
}, d = async (e, t) => {
|
|
95
|
+
let r = await e.query({
|
|
96
|
+
...M(i, ""),
|
|
97
|
+
predicate: l(u("provider", t.provider), u("providerAccountId", t.account.providerAccountId), u("livemode", +!!t.account.livemode)),
|
|
98
|
+
order: [{
|
|
99
|
+
column: "id",
|
|
100
|
+
direction: "desc"
|
|
101
|
+
}],
|
|
102
|
+
take: 1
|
|
103
|
+
}), a = r[0] === void 0 ? null : w(r[0].id);
|
|
104
|
+
return a !== null && await n(e, t, a), a;
|
|
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 i = E(r.afterCustodyId);
|
|
100
|
-
return i !== null && await n(e, t, i), {
|
|
112
|
+
}, p = async (e, t, r) => {
|
|
113
|
+
let i = E(r.afterCustodyId), a = E(r.cycleEndCustodyId ?? null);
|
|
114
|
+
return i !== null && await n(e, t, i), a !== null && await n(e, t, a), {
|
|
101
115
|
...t,
|
|
102
116
|
id: w(r.id),
|
|
103
117
|
revision: O(r.revision),
|
|
104
118
|
afterCustodyId: i,
|
|
119
|
+
cycleEndCustodyId: a,
|
|
105
120
|
updatedAt: D(r.updatedAt)
|
|
106
121
|
};
|
|
107
|
-
},
|
|
122
|
+
}, m = async (e, t, n) => {
|
|
108
123
|
if (n.tenantId !== t.tenantId || n.providerCustomerId !== t.providerCustomerId || n.custodyId !== t.id) throw C();
|
|
109
124
|
let r = E(n.walkId), i = {
|
|
110
125
|
unprepared: E(n.afterUnpreparedId),
|
|
111
126
|
ready: E(n.afterReadyId),
|
|
112
|
-
working: E(n.afterWorkingId)
|
|
127
|
+
working: E(n.afterWorkingId),
|
|
128
|
+
observed: E(n.afterObservedId)
|
|
113
129
|
};
|
|
114
130
|
if (r === null && P.some((e) => i[e] !== null)) throw C();
|
|
115
131
|
if (r !== null) {
|
|
@@ -141,8 +157,8 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
141
157
|
cursors: i,
|
|
142
158
|
updatedAt: D(n.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,10 +166,10 @@ 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;
|
|
@@ -168,19 +184,25 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
168
184
|
identityKey: a,
|
|
169
185
|
revision: 1,
|
|
170
186
|
afterCustodyId: null,
|
|
187
|
+
cycleEndCustodyId: await d(e, r),
|
|
171
188
|
updatedAt: i
|
|
172
189
|
}, { conflictColumns: ["identityKey"] });
|
|
173
|
-
let t = await
|
|
190
|
+
let t = await f(e, _, r, a);
|
|
174
191
|
if (t === null) throw C();
|
|
175
|
-
return
|
|
192
|
+
return p(e, r, t);
|
|
176
193
|
});
|
|
177
194
|
}),
|
|
178
195
|
advanceAccount: (t, r, i) => N(async () => {
|
|
179
196
|
let a = structuredClone(t), o = k(a), s = E(r), c = D(i), l = await j(o, null);
|
|
180
197
|
return e.transactional(async (e) => {
|
|
181
198
|
s !== null && await n(e, o, s);
|
|
182
|
-
let t =
|
|
183
|
-
|
|
199
|
+
let t = s === null || (a.cycleEndCustodyId ?? null) === null ? await d(e, o) : E(a.cycleEndCustodyId);
|
|
200
|
+
t !== null && await n(e, o, t);
|
|
201
|
+
let r = await h(e, _, o, l, a, {
|
|
202
|
+
afterCustodyId: s,
|
|
203
|
+
cycleEndCustodyId: t
|
|
204
|
+
}, c);
|
|
205
|
+
return r === null ? null : p(e, o, r);
|
|
184
206
|
});
|
|
185
207
|
}),
|
|
186
208
|
customer: (n, r) => N(async () => {
|
|
@@ -199,11 +221,12 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
199
221
|
afterUnpreparedId: null,
|
|
200
222
|
afterReadyId: null,
|
|
201
223
|
afterWorkingId: null,
|
|
224
|
+
afterObservedId: null,
|
|
202
225
|
updatedAt: a
|
|
203
226
|
}, { conflictColumns: ["identityKey"] });
|
|
204
|
-
let o = await
|
|
227
|
+
let o = await f(e, v, n, r);
|
|
205
228
|
if (o === null) throw C();
|
|
206
|
-
return
|
|
229
|
+
return m(e, n, o);
|
|
207
230
|
});
|
|
208
231
|
}),
|
|
209
232
|
advanceCustomer: (n, r, i) => N(async () => {
|
|
@@ -213,9 +236,10 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
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
|
|
242
|
+
await m(e, n, {
|
|
219
243
|
id: a.id,
|
|
220
244
|
revision: a.revision,
|
|
221
245
|
...A(n),
|
|
@@ -225,8 +249,8 @@ var _ = "_voltro_billing_invoice_history_scan_accounts", v = "_voltro_billing_in
|
|
|
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, n, r, a, i, s);
|
|
253
|
+
return c === null ? null : m(e, n, c);
|
|
230
254
|
});
|
|
231
255
|
})
|
|
232
256
|
};
|