@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,43 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { BILLING_INVOICE_HISTORY_REFERENCES_TABLE as e, invoiceHistoryJournalInTransaction as t } from "./invoiceHistoryJournal.js";
|
|
2
|
+
import { dataStoreInvoiceStore as n } from "./invoiceStore.js";
|
|
3
|
+
import { captureProviderAccount as r, exactProviderIdentifier as i, sameProviderAccount as a } from "./providerIdentity.js";
|
|
4
|
+
import { BillingError as o } from "./types.js";
|
|
5
5
|
import { Effect as s, Schema as c } from "effect";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { and as l, eq as u, gt as d, id as f, inSet as p, integer as m, lte as h, notInSubquery as g, table as _, text as v, timestamp as y } from "@voltro/database";
|
|
7
|
+
import { dataStoreIdempotencyStore as b } from "@voltro/runtime";
|
|
8
|
+
import { DEFAULT_IN_FLIGHT_LEASE_MS as x, beginIdempotent as S, finishIdempotent as C, holdIdempotentClaim as w, prepareIdempotentInput as T, systemSubject as E } from "@voltro/protocol";
|
|
9
9
|
// src/invoiceHistoryWork.ts
|
|
10
|
-
var D = "_voltro_billing_invoice_history_work", O =
|
|
11
|
-
id:
|
|
12
|
-
tenantId:
|
|
13
|
-
provider:
|
|
14
|
-
providerAccountId:
|
|
15
|
-
livemode:
|
|
16
|
-
providerCustomerId:
|
|
17
|
-
custodyId:
|
|
18
|
-
walkId:
|
|
19
|
-
referenceId:
|
|
20
|
-
providerInvoiceId:
|
|
21
|
-
revision:
|
|
22
|
-
attempt:
|
|
23
|
-
executions:
|
|
24
|
-
state:
|
|
25
|
-
activeClaimId:
|
|
26
|
-
nextAttemptAt:
|
|
27
|
-
lastOutcome:
|
|
28
|
-
observationId:
|
|
29
|
-
observationRevision:
|
|
30
|
-
updatedAt:
|
|
10
|
+
var D = "_voltro_billing_invoice_history_work", O = _(D, {
|
|
11
|
+
id: f({ prefix: "bihwork" }),
|
|
12
|
+
tenantId: v().maxLength(191),
|
|
13
|
+
provider: v().maxLength(64),
|
|
14
|
+
providerAccountId: v().maxLength(191),
|
|
15
|
+
livemode: m(),
|
|
16
|
+
providerCustomerId: v().maxLength(191),
|
|
17
|
+
custodyId: v().maxLength(191),
|
|
18
|
+
walkId: v().maxLength(191),
|
|
19
|
+
referenceId: v().maxLength(191),
|
|
20
|
+
providerInvoiceId: v().maxLength(191),
|
|
21
|
+
revision: m(),
|
|
22
|
+
attempt: m(),
|
|
23
|
+
executions: m(),
|
|
24
|
+
state: v().maxLength(32),
|
|
25
|
+
activeClaimId: v().maxLength(191).nullable(),
|
|
26
|
+
nextAttemptAt: y(),
|
|
27
|
+
lastOutcome: v().maxLength(32),
|
|
28
|
+
observationId: v().maxLength(191).nullable(),
|
|
29
|
+
observationRevision: m().nullable(),
|
|
30
|
+
updatedAt: y()
|
|
31
31
|
}).unique("byBillingInvoiceHistoryWorkReference", ["referenceId"]).index("byBillingInvoiceHistoryWorkDue", [
|
|
32
32
|
"walkId",
|
|
33
33
|
"state",
|
|
34
34
|
"nextAttemptAt"
|
|
35
|
-
]).index("byBillingInvoiceHistoryWorkTenant", ["tenantId"]), k = 2147483647, A = 6e4, j = 864e5, M =
|
|
35
|
+
]).index("byBillingInvoiceHistoryWorkTenant", ["tenantId"]), k = 2147483647, A = 6e4, j = 864e5, M = E("billing.invoice-history-work", []), N = (e = "Invoice reference work remains unconfirmed and requires reconciliation.", t = !0) => new o({
|
|
36
36
|
source: "invoiceHistoryWork",
|
|
37
|
-
message:
|
|
38
|
-
transient:
|
|
37
|
+
message: e,
|
|
38
|
+
transient: t
|
|
39
39
|
}), P = (e, t = 191) => {
|
|
40
|
-
if (!
|
|
40
|
+
if (!i(e) || e.length > t || !e.isWellFormed()) throw N();
|
|
41
41
|
return e;
|
|
42
42
|
}, F = (e, t = 0) => {
|
|
43
43
|
if (typeof e != "number" || !Number.isInteger(e) || e < t || e > k) throw N();
|
|
@@ -46,12 +46,12 @@ var D = "_voltro_billing_invoice_history_work", O = C(D, {
|
|
|
46
46
|
let t = e instanceof Date ? new Date(e) : new Date(typeof e == "string" ? e : NaN);
|
|
47
47
|
if (!Number.isFinite(t.getTime())) throw N();
|
|
48
48
|
return t;
|
|
49
|
-
}, L = (e, t) => I(new Date(e.getTime() + t)), R = (
|
|
50
|
-
try:
|
|
51
|
-
catch: (
|
|
49
|
+
}, L = (e, t) => I(new Date(e.getTime() + t)), R = (e) => s.tryPromise({
|
|
50
|
+
try: e,
|
|
51
|
+
catch: (e) => e instanceof o ? e : N()
|
|
52
52
|
}), z = (e, t = !1) => ({
|
|
53
53
|
table: D,
|
|
54
|
-
predicate:
|
|
54
|
+
predicate: u("referenceId", e),
|
|
55
55
|
order: [],
|
|
56
56
|
take: 2,
|
|
57
57
|
skip: void 0,
|
|
@@ -73,31 +73,31 @@ var D = "_voltro_billing_invoice_history_work", O = C(D, {
|
|
|
73
73
|
...e.account,
|
|
74
74
|
providerCustomerId: e.providerCustomerId,
|
|
75
75
|
providerInvoiceId: e.providerInvoiceId
|
|
76
|
-
}), H = (e,
|
|
76
|
+
}), H = (e, t) => {
|
|
77
77
|
if (e.livemode !== 0 && e.livemode !== 1) throw N();
|
|
78
|
-
let
|
|
78
|
+
let n = r({
|
|
79
79
|
providerAccountId: P(e.providerAccountId),
|
|
80
80
|
livemode: e.livemode === 1
|
|
81
81
|
});
|
|
82
|
-
if (e.tenantId !==
|
|
83
|
-
let
|
|
84
|
-
if (
|
|
82
|
+
if (e.tenantId !== t.tenantId || e.provider !== t.provider || e.providerCustomerId !== t.providerCustomerId || e.custodyId !== t.custodyId || e.walkId !== t.walkId || e.referenceId !== t.id || e.providerInvoiceId !== t.providerInvoiceId || !a(n, t.account)) throw N();
|
|
83
|
+
let i = e.state, o = e.lastOutcome, s = e.activeClaimId;
|
|
84
|
+
if (i !== "queued" && i !== "working" && i !== "retry" && i !== "deferred" && i !== "observed" || o !== "unconfirmed" && o !== "open" && o !== "observed") throw N();
|
|
85
85
|
let c = e.observationId === null ? null : P(e.observationId), l = e.observationRevision === null ? null : F(e.observationRevision, 1);
|
|
86
|
-
if (c === null != (l === null) ||
|
|
86
|
+
if (c === null != (l === null) || i === "working" != (s !== null) || (i === "observed" || i === "deferred") && c === null || i === "observed" && o !== "observed" || i === "deferred" && o !== "open") throw N();
|
|
87
87
|
let u = {
|
|
88
88
|
id: P(e.id),
|
|
89
|
-
tenantId:
|
|
90
|
-
provider:
|
|
91
|
-
account:
|
|
92
|
-
providerCustomerId:
|
|
93
|
-
custodyId:
|
|
94
|
-
walkId:
|
|
95
|
-
referenceId:
|
|
96
|
-
providerInvoiceId:
|
|
89
|
+
tenantId: t.tenantId,
|
|
90
|
+
provider: t.provider,
|
|
91
|
+
account: n,
|
|
92
|
+
providerCustomerId: t.providerCustomerId,
|
|
93
|
+
custodyId: t.custodyId,
|
|
94
|
+
walkId: t.walkId,
|
|
95
|
+
referenceId: t.id,
|
|
96
|
+
providerInvoiceId: t.providerInvoiceId,
|
|
97
97
|
revision: F(e.revision, 1),
|
|
98
98
|
attempt: F(e.attempt),
|
|
99
99
|
executions: F(e.executions),
|
|
100
|
-
state:
|
|
100
|
+
state: i,
|
|
101
101
|
activeClaimId: s === null ? null : P(s),
|
|
102
102
|
nextAttemptAt: I(e.nextAttemptAt),
|
|
103
103
|
lastOutcome: o,
|
|
@@ -105,9 +105,9 @@ var D = "_voltro_billing_invoice_history_work", O = C(D, {
|
|
|
105
105
|
observationRevision: l,
|
|
106
106
|
updatedAt: I(e.updatedAt)
|
|
107
107
|
};
|
|
108
|
-
if (
|
|
108
|
+
if (i === "working" && (u.attempt === 0 || u.executions === 0)) throw N();
|
|
109
109
|
return u;
|
|
110
|
-
}, U = (e) => "billing.invoice-history-work.v1:" + e.walkId, W = (e, t) => e.id + ":" + t, G = async (e, t) => (await
|
|
110
|
+
}, U = (e) => "billing.invoice-history-work.v1:" + e.walkId, W = (e, t) => e.id + ":" + t, G = async (e, t) => (await T(c.Unknown, [
|
|
111
111
|
e.id,
|
|
112
112
|
e.tenantId,
|
|
113
113
|
e.provider,
|
|
@@ -131,124 +131,126 @@ var D = "_voltro_billing_invoice_history_work", O = C(D, {
|
|
|
131
131
|
work: Object.freeze(t),
|
|
132
132
|
claim: n
|
|
133
133
|
});
|
|
134
|
-
}, q = (e) => {
|
|
135
|
-
let
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
}, q = async (e, t) => {
|
|
135
|
+
let r = n(e), i = V(t), a = await s.runPromise(r.currentPaymentEpoch(i, { forUpdate: !0 }));
|
|
136
|
+
if (a === null) return null;
|
|
137
|
+
let o = await s.runPromise(r.get(i, { forUpdate: !0 }));
|
|
138
|
+
return o?.paymentEpoch?.headId === a.headId && o.paymentEpoch.epoch === a.epoch ? o : null;
|
|
139
|
+
}, J = (n) => {
|
|
140
|
+
let r = b(n), i = async (e, n, r) => {
|
|
141
|
+
let i = await s.runPromise(t(e).reference(n, r));
|
|
142
|
+
if (i === null) throw N("The original owned invoice history reference is missing.", !1);
|
|
143
|
+
return i;
|
|
144
|
+
}, a = async (e, t, n = !1) => {
|
|
140
145
|
let r = await e.query(z(t.id, n));
|
|
141
146
|
if (r.length > 1) throw N();
|
|
142
147
|
return r[0] ? H(r[0], t) : null;
|
|
143
|
-
},
|
|
148
|
+
}, o = async (e, t, n, r, i) => {
|
|
144
149
|
if (n.revision >= k) throw N("The invoice reference work revision is exhausted.", !1);
|
|
145
150
|
if (await e.updateMany("_voltro_billing_invoice_history_work", {
|
|
146
|
-
...
|
|
151
|
+
...r,
|
|
147
152
|
revision: n.revision + 1,
|
|
148
|
-
updatedAt:
|
|
149
|
-
}, { where:
|
|
150
|
-
let o = await
|
|
151
|
-
if (o === null || o.id !== n.id || o.revision !== n.revision + 1 || o.updatedAt.getTime() !==
|
|
152
|
-
for (let [e, t] of Object.entries(
|
|
153
|
+
updatedAt: i
|
|
154
|
+
}, { where: l(u("id", n.id), u("referenceId", t.id), u("revision", n.revision), u("custodyId", t.custodyId), u("walkId", t.walkId)) }) !== 1) throw N();
|
|
155
|
+
let o = await a(e, t, !0);
|
|
156
|
+
if (o === null || o.id !== n.id || o.revision !== n.revision + 1 || o.updatedAt.getTime() !== i.getTime()) throw N();
|
|
157
|
+
for (let [e, t] of Object.entries(r)) {
|
|
153
158
|
let n = Object.getOwnPropertyDescriptor(o, e)?.value;
|
|
154
159
|
if (t instanceof Date ? !(n instanceof Date) || n.getTime() !== t.getTime() : n !== t) throw N("The invoice work acknowledgement was not read back exactly.");
|
|
155
160
|
}
|
|
156
161
|
return o;
|
|
157
|
-
},
|
|
158
|
-
let
|
|
159
|
-
return
|
|
162
|
+
}, c = async (e, t, n) => {
|
|
163
|
+
let r = await a(e, t, !0), i = n.work;
|
|
164
|
+
return r === null || r.id !== i.id || r.referenceId !== i.referenceId || r.state !== "working" || r.attempt !== i.attempt || r.activeClaimId !== n.claim.id || n.claim.inputHash !== await G(r, r.attempt) ? null : r;
|
|
160
165
|
};
|
|
161
166
|
return {
|
|
162
|
-
pending: (
|
|
163
|
-
let
|
|
167
|
+
pending: (r, a, o, c) => R(async () => {
|
|
168
|
+
let f = structuredClone(r), m = I(o), _ = c?.limit ?? 25;
|
|
164
169
|
if (![
|
|
165
170
|
"unprepared",
|
|
166
171
|
"ready",
|
|
167
|
-
"working"
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
"working",
|
|
173
|
+
"observed"
|
|
174
|
+
].includes(a) || !Number.isInteger(_) || _ < 1 || _ > 100) throw N();
|
|
175
|
+
let v = c?.cursor === void 0 ? null : {
|
|
170
176
|
lane: c.cursor.lane,
|
|
171
177
|
walkId: P(c.cursor.walkId),
|
|
172
178
|
afterId: P(c.cursor.afterId)
|
|
173
179
|
};
|
|
174
|
-
if (
|
|
175
|
-
return
|
|
176
|
-
let
|
|
180
|
+
if (v !== null && v.lane !== a) throw N("Invoice work cursors belong to one selection lane.", !1);
|
|
181
|
+
return n.transactional(async (n) => {
|
|
182
|
+
let r = t(n), o = await s.runPromise(r.read(f));
|
|
177
183
|
if (o === null) throw N("No retained owned invoice history walk exists.");
|
|
178
|
-
let c = await s.runPromise(
|
|
179
|
-
if (c.id !== o.id ||
|
|
180
|
-
let
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
let c = await s.runPromise(r.begin(f));
|
|
185
|
+
if (c.id !== o.id || v !== null && v.walkId !== c.id) throw N("Invoice work cursor differs from the retained walk.", !1);
|
|
186
|
+
let y = l(u("tenantId", c.tenantId), u("provider", c.provider), u("providerAccountId", c.account.providerAccountId), u("livemode", +!!c.account.livemode), u("providerCustomerId", c.providerCustomerId), u("custodyId", c.custodyId), u("walkId", c.id)), b = a === "unprepared", x = a === "working" ? ["working"] : a === "observed" ? ["observed"] : [
|
|
187
|
+
"queued",
|
|
188
|
+
"retry",
|
|
189
|
+
"deferred"
|
|
190
|
+
], S = b ? e : D;
|
|
191
|
+
if (v !== null) {
|
|
192
|
+
let e = await n.query({
|
|
193
|
+
...z(v.afterId),
|
|
194
|
+
table: S,
|
|
195
|
+
predicate: l(y, u("id", v.afterId))
|
|
186
196
|
});
|
|
187
|
-
if (
|
|
188
|
-
let
|
|
189
|
-
|
|
197
|
+
if (e.length !== 1 || e[0]?.id !== v.afterId) throw N("Invoice work cursor is no longer retained.", !0);
|
|
198
|
+
let t = await i(n, f, b ? v.afterId : P(e[0]?.referenceId));
|
|
199
|
+
b || H(e[0], t);
|
|
190
200
|
}
|
|
191
|
-
let
|
|
192
|
-
|
|
201
|
+
let C = [y];
|
|
202
|
+
v !== null && C.push(d("id", v.afterId)), b ? C.push(h("pageOrdinal", c.pageOrdinal), g("id", {
|
|
193
203
|
...z(c.id),
|
|
194
|
-
predicate:
|
|
204
|
+
predicate: y,
|
|
195
205
|
projection: ["referenceId"],
|
|
196
206
|
take: void 0
|
|
197
|
-
})) :
|
|
198
|
-
|
|
199
|
-
"retry",
|
|
200
|
-
"deferred"
|
|
201
|
-
]));
|
|
202
|
-
let C = await e.query({
|
|
207
|
+
})) : C.push(h("nextAttemptAt", m), p("state", x));
|
|
208
|
+
let w = await n.query({
|
|
203
209
|
...z(c.id),
|
|
204
|
-
table:
|
|
205
|
-
predicate:
|
|
210
|
+
table: S,
|
|
211
|
+
predicate: l(...C),
|
|
206
212
|
order: [{
|
|
207
213
|
column: "id",
|
|
208
214
|
direction: "asc"
|
|
209
215
|
}],
|
|
210
|
-
take:
|
|
216
|
+
take: _ + 1
|
|
211
217
|
});
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
214
|
-
if (
|
|
218
|
+
if (w.length > _ + 1) throw N();
|
|
219
|
+
let T = await s.runPromise(r.referencesByIds(f, w.map((e) => P(b ? e.id : e.referenceId))));
|
|
220
|
+
if (b && w.length > 0 && (await n.query({
|
|
215
221
|
...z(c.id),
|
|
216
|
-
predicate:
|
|
222
|
+
predicate: p("referenceId", T.map((e) => e.id)),
|
|
217
223
|
take: 1
|
|
218
224
|
})).length > 0) throw N("An unprepared invoice reference already has native work.", !0);
|
|
219
|
-
let
|
|
220
|
-
for (let [e, t] of
|
|
225
|
+
let E = v?.afterId ?? null, O = [];
|
|
226
|
+
for (let [e, t] of w.entries()) {
|
|
221
227
|
let n = P(t.id);
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
if (
|
|
226
|
-
let
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
].includes(a.state)))) throw N("Invoice work changed while selecting its lane.", !0);
|
|
232
|
-
E.push({
|
|
233
|
-
reference: i,
|
|
234
|
-
work: a
|
|
228
|
+
if (E !== null && n <= E) throw N("Invoice work selection is not strictly ordered.");
|
|
229
|
+
E = n;
|
|
230
|
+
let r = T[e];
|
|
231
|
+
if (r === void 0 || r.walkId !== c.id || r.pageOrdinal > c.pageOrdinal) throw N();
|
|
232
|
+
let i = b ? null : H(t, r);
|
|
233
|
+
if (i !== null && (i.id !== n || i.nextAttemptAt.getTime() > m.getTime() || !x.includes(i.state))) throw N("Invoice work changed while selecting its lane.", !0);
|
|
234
|
+
O.push({
|
|
235
|
+
reference: r,
|
|
236
|
+
work: i
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
239
|
return {
|
|
238
|
-
entries:
|
|
239
|
-
nextCursor:
|
|
240
|
-
lane:
|
|
240
|
+
entries: O.slice(0, _),
|
|
241
|
+
nextCursor: w.length > _ ? {
|
|
242
|
+
lane: a,
|
|
241
243
|
walkId: c.id,
|
|
242
|
-
afterId: P(
|
|
244
|
+
afterId: P(w[_ - 1]?.id)
|
|
243
245
|
} : null,
|
|
244
246
|
walkRevision: c.revision
|
|
245
247
|
};
|
|
246
248
|
});
|
|
247
249
|
}),
|
|
248
|
-
claim: (
|
|
249
|
-
let
|
|
250
|
-
return
|
|
251
|
-
let t = await
|
|
250
|
+
claim: (e, t, r) => R(async () => {
|
|
251
|
+
let s = structuredClone(e), c = P(t), l = I(r);
|
|
252
|
+
return n.transactional(async (e) => {
|
|
253
|
+
let t = await i(e, s, c);
|
|
252
254
|
await e.insertIgnore(D, {
|
|
253
255
|
id: "bihwork_" + globalThis.crypto.randomUUID(),
|
|
254
256
|
...B(t),
|
|
@@ -257,106 +259,106 @@ var D = "_voltro_billing_invoice_history_work", O = C(D, {
|
|
|
257
259
|
executions: 0,
|
|
258
260
|
state: "queued",
|
|
259
261
|
activeClaimId: null,
|
|
260
|
-
nextAttemptAt:
|
|
262
|
+
nextAttemptAt: l,
|
|
261
263
|
lastOutcome: "unconfirmed",
|
|
262
264
|
observationId: null,
|
|
263
265
|
observationRevision: null,
|
|
264
|
-
updatedAt:
|
|
266
|
+
updatedAt: l
|
|
265
267
|
}, { conflictColumns: ["referenceId"] });
|
|
266
|
-
let
|
|
267
|
-
if (
|
|
268
|
-
if (
|
|
269
|
-
let
|
|
270
|
-
if (
|
|
268
|
+
let n = await a(e, t, !0);
|
|
269
|
+
if (n === null) throw N();
|
|
270
|
+
if (n.state === "observed") {
|
|
271
|
+
let r = await q(e, t);
|
|
272
|
+
if (r !== null && r.id === n.observationId && r.revision >= n.observationRevision && r.snapshot.status !== "open") return {
|
|
271
273
|
kind: "observed",
|
|
272
|
-
work:
|
|
274
|
+
work: n
|
|
273
275
|
};
|
|
274
|
-
|
|
276
|
+
n = await o(e, t, n, {
|
|
275
277
|
state: "queued",
|
|
276
278
|
activeClaimId: null,
|
|
277
279
|
lastOutcome: "unconfirmed",
|
|
278
|
-
nextAttemptAt:
|
|
279
|
-
},
|
|
280
|
+
nextAttemptAt: l
|
|
281
|
+
}, l);
|
|
280
282
|
}
|
|
281
|
-
if (
|
|
283
|
+
if (n.state !== "working" && n.nextAttemptAt.getTime() > l.getTime()) return {
|
|
282
284
|
kind: "busy",
|
|
283
|
-
work:
|
|
285
|
+
work: n
|
|
284
286
|
};
|
|
285
|
-
let
|
|
286
|
-
if (
|
|
287
|
-
let
|
|
288
|
-
if (
|
|
289
|
-
attempt:
|
|
287
|
+
let r = n.state === "working" ? n.attempt : n.attempt + 1;
|
|
288
|
+
if (r > k || n.executions >= k) throw N("The invoice reference attempt counter is exhausted.", !1);
|
|
289
|
+
let u = await G(n, r), d = await S(b(e), U(n), W(n, r), u, j, l.getTime());
|
|
290
|
+
if (d.kind === "replay") return n = await o(e, t, n, {
|
|
291
|
+
attempt: r,
|
|
290
292
|
state: "queued",
|
|
291
293
|
activeClaimId: null,
|
|
292
|
-
nextAttemptAt:
|
|
294
|
+
nextAttemptAt: l,
|
|
293
295
|
lastOutcome: "unconfirmed"
|
|
294
|
-
},
|
|
296
|
+
}, l), {
|
|
295
297
|
kind: "busy",
|
|
296
|
-
work:
|
|
298
|
+
work: n
|
|
297
299
|
};
|
|
298
|
-
if (
|
|
300
|
+
if (d.kind === "conflict") return {
|
|
299
301
|
kind: "busy",
|
|
300
|
-
work:
|
|
302
|
+
work: n
|
|
301
303
|
};
|
|
302
|
-
if (
|
|
303
|
-
return
|
|
304
|
-
attempt:
|
|
305
|
-
executions:
|
|
304
|
+
if (d.kind !== "fresh") throw N("The retained invoice attempt has a different input binding.", !1);
|
|
305
|
+
return n = await o(e, t, n, {
|
|
306
|
+
attempt: r,
|
|
307
|
+
executions: n.executions + 1,
|
|
306
308
|
state: "working",
|
|
307
|
-
activeClaimId:
|
|
308
|
-
nextAttemptAt: L(
|
|
309
|
+
activeClaimId: d.claim.id,
|
|
310
|
+
nextAttemptAt: L(l, x),
|
|
309
311
|
lastOutcome: "unconfirmed"
|
|
310
|
-
},
|
|
312
|
+
}, l), {
|
|
311
313
|
kind: "claimed",
|
|
312
|
-
work:
|
|
314
|
+
work: n,
|
|
313
315
|
attempt: Object.freeze({
|
|
314
|
-
work:
|
|
315
|
-
claim:
|
|
316
|
+
work: n,
|
|
317
|
+
claim: d.claim
|
|
316
318
|
})
|
|
317
319
|
};
|
|
318
320
|
});
|
|
319
321
|
}),
|
|
320
|
-
observed: (t, r,
|
|
321
|
-
let
|
|
322
|
-
return
|
|
323
|
-
let t = await
|
|
324
|
-
if (
|
|
325
|
-
let
|
|
326
|
-
if (
|
|
327
|
-
let a =
|
|
328
|
-
return await
|
|
322
|
+
observed: (e, t, r, a) => R(async () => {
|
|
323
|
+
let s = structuredClone(e), l = K(t), u = I(a), d = P(r.id), f = F(r.revision, 1);
|
|
324
|
+
return n.transactional(async (e) => {
|
|
325
|
+
let t = await i(e, s, l.work.referenceId), n = await c(e, t, l);
|
|
326
|
+
if (n === null) return null;
|
|
327
|
+
let r = await q(e, t);
|
|
328
|
+
if (r === null || r.id !== d || r.revision < f) throw N("The qualified native invoice observation is missing or older than the offered acknowledgement.");
|
|
329
|
+
let a = r.snapshot.status === "open";
|
|
330
|
+
return await C(b(e), l.claim, {
|
|
329
331
|
status: a ? 202 : 204,
|
|
330
332
|
body: null
|
|
331
|
-
},
|
|
333
|
+
}, u.getTime()) ? o(e, t, n, {
|
|
332
334
|
state: a ? "deferred" : "observed",
|
|
333
335
|
activeClaimId: null,
|
|
334
|
-
observationId:
|
|
335
|
-
observationRevision:
|
|
336
|
+
observationId: r.id,
|
|
337
|
+
observationRevision: r.revision,
|
|
336
338
|
lastOutcome: a ? "open" : "observed",
|
|
337
|
-
nextAttemptAt: a ? L(
|
|
338
|
-
},
|
|
339
|
+
nextAttemptAt: a ? L(u, A) : u
|
|
340
|
+
}, u) : null;
|
|
339
341
|
});
|
|
340
342
|
}),
|
|
341
|
-
failed: (t, r
|
|
342
|
-
let a = structuredClone(
|
|
343
|
-
return
|
|
344
|
-
let t = await
|
|
345
|
-
return
|
|
343
|
+
failed: (e, t, r) => R(async () => {
|
|
344
|
+
let a = structuredClone(e), s = K(t), l = I(r);
|
|
345
|
+
return n.transactional(async (e) => {
|
|
346
|
+
let t = await i(e, a, s.work.referenceId), n = await c(e, t, s);
|
|
347
|
+
return n === null || !await C(b(e), s.claim, {
|
|
346
348
|
status: 503,
|
|
347
349
|
body: null
|
|
348
|
-
},
|
|
350
|
+
}, l.getTime()) ? null : o(e, t, n, {
|
|
349
351
|
state: "retry",
|
|
350
352
|
activeClaimId: null,
|
|
351
353
|
lastOutcome: "unconfirmed",
|
|
352
|
-
nextAttemptAt: L(
|
|
353
|
-
},
|
|
354
|
+
nextAttemptAt: L(l, A)
|
|
355
|
+
}, l);
|
|
354
356
|
});
|
|
355
357
|
}),
|
|
356
|
-
hold: (e,
|
|
357
|
-
let
|
|
358
|
-
return
|
|
358
|
+
hold: (e, t) => {
|
|
359
|
+
let n = K(e);
|
|
360
|
+
return w(r, n.claim, x, t);
|
|
359
361
|
}
|
|
360
362
|
};
|
|
361
363
|
};
|
|
362
|
-
export { D as BILLING_INVOICE_HISTORY_WORK_TABLE, O as billingInvoiceHistoryWorkTable,
|
|
364
|
+
export { D as BILLING_INVOICE_HISTORY_WORK_TABLE, O as billingInvoiceHistoryWorkTable, J as dataStoreInvoiceHistoryWorkStore };
|