@voltro/plugin-billing 0.89.1 → 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.
@@ -0,0 +1,93 @@
1
+ import { BillingError as e } from "./types.js";
2
+ import { Schema as t } from "effect";
3
+ // src/subscriptionObservation.ts
4
+ var n = t.Struct({
5
+ protocol: t.Literal("voltro.subscription-observation.v1"),
6
+ tenantId: t.NonEmptyString,
7
+ provider: t.NonEmptyString,
8
+ providerAccountId: t.NonEmptyString,
9
+ livemode: t.Boolean,
10
+ providerCustomerId: t.NonEmptyString,
11
+ providerSubscriptionId: t.NonEmptyString,
12
+ providerSubscriptionItemId: t.NonEmptyString,
13
+ providerPriceId: t.NonEmptyString,
14
+ providerLatestInvoiceId: t.NonEmptyString,
15
+ paymentHeadId: t.NonEmptyString,
16
+ paymentEpoch: t.Number,
17
+ plan: t.NonEmptyString,
18
+ status: t.Literals([
19
+ "active",
20
+ "trialing",
21
+ "pastDue",
22
+ "canceled",
23
+ "incomplete"
24
+ ]),
25
+ quantity: t.Number,
26
+ currency: t.NonEmptyString,
27
+ currentPeriodStart: t.String,
28
+ currentPeriodEnd: t.String,
29
+ cancelAt: t.NullOr(t.String),
30
+ providerObservedAt: t.String,
31
+ observedAt: t.String
32
+ }), r = () => new e({
33
+ source: "subscriptionObservation",
34
+ message: "The native provider subscription observation requires reconciliation.",
35
+ transient: !1
36
+ }), i = (e) => {
37
+ let t = Date.parse(e);
38
+ if (!Number.isSafeInteger(t) || t < 0 || new Date(t).toISOString() !== e) throw r();
39
+ return t;
40
+ }, a = (e) => {
41
+ if (e === null) return null;
42
+ if (!(e instanceof Date) || !Number.isSafeInteger(e.getTime()) || e.getTime() < 0) throw r();
43
+ return e.toISOString();
44
+ }, o = (e, o) => {
45
+ if (e == null) return null;
46
+ try {
47
+ let s = t.decodeUnknownSync(n)(typeof e == "string" ? JSON.parse(e) : e);
48
+ for (let e of [
49
+ s.tenantId,
50
+ s.provider,
51
+ s.providerAccountId,
52
+ s.providerCustomerId,
53
+ s.providerSubscriptionId,
54
+ s.providerSubscriptionItemId,
55
+ s.providerPriceId,
56
+ s.providerLatestInvoiceId,
57
+ s.paymentHeadId,
58
+ s.plan
59
+ ]) if (e.length > 191 || e.trim() !== e || !e.isWellFormed()) throw r();
60
+ if (!Number.isInteger(s.paymentEpoch) || s.paymentEpoch < 0 || s.paymentEpoch > 2147483647 || !Number.isSafeInteger(s.quantity) || s.quantity < 1 || !/^[a-z]{3}$/.test(s.currency) || i(s.currentPeriodStart) >= i(s.currentPeriodEnd) || (i(s.observedAt), i(s.providerObservedAt), s.cancelAt !== null && i(s.cancelAt), o !== void 0 && (s.tenantId !== o.tenantId || s.provider !== o.provider || s.providerSubscriptionId !== o.providerSubscriptionId || s.plan !== o.plan || s.status !== o.status || s.quantity !== o.quantity || s.currentPeriodStart !== a(o.currentPeriodStart) || s.currentPeriodEnd !== a(o.currentPeriodEnd) || s.cancelAt !== a(o.cancelAt)))) throw r();
61
+ return Object.freeze({ ...s });
62
+ } catch {
63
+ throw r();
64
+ }
65
+ }, s = (e) => e.providerIncludedSeats == null ? e.providerPlanQuantity === e.quantity : e.providerPlanQuantity === 1 && e.providerAdditionalSeatQuantity != null && e.providerIncludedSeats + e.providerAdditionalSeatQuantity === e.quantity, c = (e) => {
66
+ let t = e.snapshot, n = t.providerAccount;
67
+ return n == null || n.providerAccountId !== e.account.providerAccountId || n.livemode !== e.account.livemode || t.paymentEpoch == null || !t.providerLatestInvoiceId || t.providerItemsComplete !== !0 || t.plan === null || !t.providerCustomerId || !t.providerPlanItemId || !t.providerPlanPriceId || t.providerPlanPriceId !== e.expectedPriceId || t.providerPlanCurrency !== e.expectedCurrency.toLowerCase() || !s(t) || !t.priceIds?.includes(t.providerPlanPriceId) || !(t.providerObservedAt instanceof Date) || t.currentPeriodStart === null || t.currentPeriodEnd === null ? null : o({
68
+ protocol: "voltro.subscription-observation.v1",
69
+ tenantId: e.tenantId,
70
+ provider: e.provider,
71
+ ...e.account,
72
+ providerCustomerId: t.providerCustomerId,
73
+ providerSubscriptionId: t.providerSubscriptionId,
74
+ providerSubscriptionItemId: t.providerPlanItemId,
75
+ providerPriceId: t.providerPlanPriceId,
76
+ providerLatestInvoiceId: t.providerLatestInvoiceId,
77
+ paymentHeadId: t.paymentEpoch.headId,
78
+ paymentEpoch: t.paymentEpoch.epoch,
79
+ plan: t.plan,
80
+ status: t.status,
81
+ quantity: t.quantity,
82
+ currency: t.providerPlanCurrency,
83
+ currentPeriodStart: a(t.currentPeriodStart),
84
+ currentPeriodEnd: a(t.currentPeriodEnd),
85
+ cancelAt: a(t.cancelAt),
86
+ providerObservedAt: a(t.providerObservedAt),
87
+ observedAt: a(e.observedAt)
88
+ });
89
+ }, l = (e, t, n) => {
90
+ let r = e[0];
91
+ return e.length !== 1 || r === void 0 ? !1 : JSON.stringify(o(r.providerObservation, r)) === JSON.stringify(t) || r.statusEventAt !== null && r.statusEventAt.getTime() > n.getTime();
92
+ };
93
+ export { o as captureSubscriptionObservation, c as observeSubscriptionProvider, l as subscriptionReadbackHolds };
@@ -0,0 +1,325 @@
1
+ import { BillingError as e, BillingRequestStale as t } from "./types.js";
2
+ import { Effect as n, Schema as r } from "effect";
3
+ import { and as i, derivedRowId as a, eq as o, gt as s, id as c, integer as l, isNotNull as u, json as d, table as f, text as p } from "@voltro/database";
4
+ import { canonicalJson as m } from "@voltro/runtime";
5
+ // src/subscriptionWriteStore.ts
6
+ var h = "_voltro_billing_subscription_write_heads", g = "_voltro_billing_subscription_writes", _ = r.Struct({
7
+ provider: r.NonEmptyString,
8
+ providerAccountId: r.NonEmptyString,
9
+ livemode: r.Boolean,
10
+ customerId: r.NonEmptyString,
11
+ subscriptionId: r.NonEmptyString,
12
+ kind: r.Literals([
13
+ "change",
14
+ "cancel",
15
+ "resume"
16
+ ]),
17
+ plan: r.NullOr(r.NonEmptyString),
18
+ priceId: r.NullOr(r.NonEmptyString),
19
+ quantity: r.NullOr(r.Number),
20
+ itemId: r.NullOr(r.NonEmptyString),
21
+ expectedPriceId: r.NullOr(r.NonEmptyString)
22
+ }), v = [
23
+ "prepared",
24
+ "claimed",
25
+ "dispatched",
26
+ "acknowledged",
27
+ "completed",
28
+ "withdrawn",
29
+ "rejected"
30
+ ], y = (e) => e === "completed" || e === "withdrawn" || e === "rejected", b = /^[A-Za-z0-9_ ().,:-]{1,200}$/, x = f(h, {
31
+ id: c({ prefix: "bwhead" }),
32
+ tenantId: p().maxLength(191),
33
+ activeId: p().nullable(),
34
+ closed: l(),
35
+ sequence: l()
36
+ }).unique("byBillingWriteTenant", ["tenantId"]), S = f(g, {
37
+ id: c({ prefix: "bwrite" }),
38
+ tenantId: p().maxLength(191),
39
+ requestId: p().maxLength(128),
40
+ sequence: l(),
41
+ intent: d().serverOnly(),
42
+ phase: p(),
43
+ claimId: p().nullable(),
44
+ receipt: d().nullable().serverOnly(),
45
+ slot: p().maxLength(191)
46
+ }).unique("byBillingWriteRequest", ["tenantId", "requestId"]).unique("byBillingWriteSlot", ["tenantId", "slot"]), C = () => new e({
47
+ source: "subscriptionWriteStore",
48
+ message: "The original subscription operation requires reconciliation. Check its status before starting another change.",
49
+ transient: !0
50
+ }), w = (e, t, n = !1) => ({
51
+ table: e,
52
+ predicate: t,
53
+ order: [],
54
+ take: void 0,
55
+ skip: void 0,
56
+ projection: void 0,
57
+ ...n ? { lock: "update" } : {}
58
+ }), T = (e) => {
59
+ let t = typeof e == "string" ? JSON.parse(e) : e;
60
+ if (typeof t != "object" || !t || Array.isArray(t)) throw C();
61
+ return t;
62
+ }, E = (e) => {
63
+ let t = r.decodeUnknownSync(_)(T(e));
64
+ if (t.quantity !== null && (!Number.isSafeInteger(t.quantity) || t.quantity < 1) || t.kind === "change" && t.priceId === null && t.quantity === null || t.kind !== "change" && (t.priceId !== null || t.quantity !== null || t.plan !== null) || t.priceId !== null && (t.itemId === null || t.plan === null)) throw C();
65
+ return Object.freeze({ ...t });
66
+ }, D = (e) => {
67
+ let t = T(e), n = E(t.intent), r = v.find((e) => e === t.phase);
68
+ if (typeof t.id != "string" || typeof t.tenantId != "string" || typeof t.requestId != "string" || !Number.isSafeInteger(t.sequence) || Number(t.sequence) < 1 || r === void 0 || t.claimId !== null && typeof t.claimId != "string") throw C();
69
+ let i = null, a = null;
70
+ if (t.receipt !== null) {
71
+ let e = T(t.receipt);
72
+ if (e.operationId !== t.id) throw C();
73
+ if (r === "rejected") {
74
+ if (typeof e.rejection != "string" || !b.test(e.rejection)) throw C();
75
+ a = e.rejection;
76
+ } else {
77
+ if (typeof e.providerObservedAt != "string" || !Number.isFinite(Date.parse(e.providerObservedAt))) throw C();
78
+ i = {
79
+ operationId: t.id,
80
+ providerObservedAt: e.providerObservedAt
81
+ };
82
+ }
83
+ }
84
+ if ((r === "acknowledged" || r === "completed") != (i !== null) || r === "rejected" != (a !== null) || (r === "claimed" || r === "dispatched") && !t.claimId || (r === "withdrawn" || r === "rejected") && t.claimId !== null || t.slot !== (y(r) ? t.id : "active")) throw C();
85
+ return {
86
+ id: t.id,
87
+ tenantId: t.tenantId,
88
+ requestId: t.requestId,
89
+ sequence: Number(t.sequence),
90
+ intent: n,
91
+ phase: r,
92
+ claimId: t.claimId,
93
+ receipt: i,
94
+ rejection: a
95
+ };
96
+ }, O = (e, n) => new t({
97
+ requestId: e,
98
+ reason: n,
99
+ message: n === "superseded" ? "This billing request already completed and a later change followed it. Start a new request for a new change." : n === "withdrawn" ? "This billing request was never sent to the provider and was withdrawn. Start a new request to try again." : "The provider refused this billing request. Start a new request after correcting the cause."
100
+ }), k = (e, t) => i(o("tenantId", e), o("requestId", t)), A = (e) => n.tryPromise({
101
+ try: e,
102
+ catch: C
103
+ }), j = (e) => n.tryPromise({
104
+ try: e,
105
+ catch: (e) => e instanceof t ? e : C()
106
+ }), M = (e) => {
107
+ let t = async (e, t, n = !1) => {
108
+ let r = await e.query(w(g, o("id", t), n));
109
+ if (r.length !== 1) throw C();
110
+ return D(r[0]);
111
+ }, n = async (e, t, n = !1) => {
112
+ if (!t || t.length > 191) throw C();
113
+ let r = await e.query(w(h, o("tenantId", t), !0));
114
+ if (r.length === 0) {
115
+ if ((await e.query({
116
+ ...w("_voltro_billing_subscription_writes", o("tenantId", t), !0),
117
+ take: 1
118
+ })).length !== 0) throw C();
119
+ n && (await e.insertIgnore(h, {
120
+ id: a("bwhead", t),
121
+ tenantId: t,
122
+ activeId: null,
123
+ closed: 0,
124
+ sequence: 0
125
+ }, { conflictColumns: ["tenantId"] }), r = await e.query(w(h, o("tenantId", t), !0)));
126
+ }
127
+ if (r.length > 1) throw C();
128
+ let i = r[0] === void 0 ? null : T(r[0]);
129
+ if (i !== null && (typeof i.id != "string" || i.tenantId !== t || i.activeId !== null && typeof i.activeId != "string" || ![0, 1].includes(Number(i.closed)) || !Number.isSafeInteger(i.sequence) || Number(i.sequence) < 0)) throw C();
130
+ return i;
131
+ }, r = async (e, n, r, i) => {
132
+ if (!await e.update("_voltro_billing_subscription_writes", n.id, r)) throw C();
133
+ let a = await t(e, n.id, !0);
134
+ if (m(a) !== m({
135
+ ...n,
136
+ ...i
137
+ })) throw C();
138
+ return a;
139
+ }, c = async (e, t, i, a, o) => {
140
+ let s = await r(e, t, {
141
+ ...a,
142
+ slot: t.id
143
+ }, o);
144
+ if (!y(s.phase) || i.activeId !== t.id || !await e.update("_voltro_billing_subscription_write_heads", String(i.id), { activeId: null }) || (await n(e, t.tenantId))?.activeId !== null) throw C();
145
+ return s;
146
+ }, l = async (r, i) => {
147
+ let a = await t(e, r);
148
+ return e.transactional(async (e) => {
149
+ let o = await n(e, a.tenantId);
150
+ if (o === null) throw C();
151
+ let s = await t(e, r, !0);
152
+ if (s.tenantId !== a.tenantId || Number(o.sequence) < s.sequence || !y(s.phase) && o.activeId !== s.id) throw C();
153
+ return i(e, s, o);
154
+ });
155
+ };
156
+ return {
157
+ reserve: (r, i, o) => j(async () => {
158
+ if (!/^[A-Za-z0-9_-]{8,128}$/.test(i)) throw C();
159
+ let s = E(o), c = a("bwrite", r, i);
160
+ return e.transactional(async (e) => {
161
+ let a = await n(e, r, !0);
162
+ if (a === null) throw C();
163
+ let o = await e.query(w(g, k(r, i), !0));
164
+ if (o.length > 1) throw C();
165
+ if (o[0] !== void 0) {
166
+ let e = D(o[0]);
167
+ if (e.tenantId !== r || e.requestId !== i || Number(a.sequence) < e.sequence || m({
168
+ ...e.intent,
169
+ itemId: null,
170
+ expectedPriceId: null
171
+ }) !== m({
172
+ ...s,
173
+ itemId: null,
174
+ expectedPriceId: null
175
+ }) || !y(e.phase) && a.activeId !== e.id) throw C();
176
+ if (e.phase === "withdrawn" || e.phase === "rejected") throw O(i, e.phase);
177
+ if (e.phase === "completed" && Number(a.sequence) > e.sequence) throw O(i, "superseded");
178
+ return e;
179
+ }
180
+ if (a.closed !== 0 || a.activeId !== null || Number(a.sequence) >= 2 ** 53 - 1) throw C();
181
+ let l = Number(a.sequence) + 1;
182
+ if (await e.insert(g, {
183
+ id: c,
184
+ tenantId: r,
185
+ requestId: i,
186
+ sequence: l,
187
+ intent: s,
188
+ phase: "prepared",
189
+ claimId: null,
190
+ receipt: null,
191
+ slot: "active"
192
+ }), !await e.update("_voltro_billing_subscription_write_heads", String(a.id), {
193
+ activeId: c,
194
+ sequence: l
195
+ })) throw C();
196
+ let u = await n(e, r);
197
+ if (u?.activeId !== c || u.sequence !== l) throw C();
198
+ let d = await t(e, c, !0);
199
+ if (d.sequence !== l || m(d.intent) !== m(s) || d.phase !== "prepared") throw C();
200
+ return d;
201
+ });
202
+ }),
203
+ getActive: (r) => A(() => e.transactional(async (e) => {
204
+ let i = await n(e, r);
205
+ if (i === null || i.activeId === null) return null;
206
+ let a = await t(e, String(i.activeId), !0);
207
+ if (a.tenantId !== r || y(a.phase) || Number(i.sequence) < a.sequence) throw C();
208
+ return a;
209
+ })),
210
+ getRequest: (t, r) => A(async () => {
211
+ if (!/^[A-Za-z0-9_-]{8,128}$/.test(r)) throw C();
212
+ return e.transactional(async (e) => {
213
+ let i = await n(e, t), a = await e.query(w(g, k(t, r), !0));
214
+ if (a.length === 0) return null;
215
+ if (a.length !== 1 || i === null) throw C();
216
+ let o = D(a[0]);
217
+ if (o.tenantId !== t || o.requestId !== r || Number(i.sequence) < o.sequence || !y(o.phase) && i.activeId !== o.id) throw C();
218
+ return o;
219
+ });
220
+ }),
221
+ claim: (e, t) => A(() => l(e, async (e, n, i) => {
222
+ if (i.closed !== 0 || !t) throw C();
223
+ return n.phase !== "prepared" && n.phase !== "claimed" ? n : r(e, n, {
224
+ phase: "claimed",
225
+ claimId: t
226
+ }, {
227
+ phase: "claimed",
228
+ claimId: t
229
+ });
230
+ })),
231
+ dispatch: (e, t) => A(() => l(e, async (e, n, i) => {
232
+ if (i.closed !== 0 || n.phase !== "claimed" || n.claimId !== t) throw C();
233
+ await r(e, n, { phase: "dispatched" }, { phase: "dispatched" });
234
+ })),
235
+ notDispatched: (e, t) => A(() => l(e, async (e, n, r) => {
236
+ n.claimId === t && (n.phase === "claimed" || n.phase === "dispatched") && await c(e, n, r, {
237
+ phase: "withdrawn",
238
+ claimId: null
239
+ }, {
240
+ phase: "withdrawn",
241
+ claimId: null
242
+ });
243
+ })),
244
+ withdraw: (e, t) => A(() => l(e, async (e, n, r) => {
245
+ if (n.phase === "withdrawn") return n;
246
+ if (n.phase !== t.phase || n.claimId !== t.claimId || n.phase !== "prepared" && n.phase !== "claimed") throw C();
247
+ return c(e, n, r, {
248
+ phase: "withdrawn",
249
+ claimId: null
250
+ }, {
251
+ phase: "withdrawn",
252
+ claimId: null
253
+ });
254
+ })),
255
+ reject: (e, t, n) => A(() => l(e, async (r, i, a) => {
256
+ if (!b.test(n)) throw C();
257
+ if (i.phase === "rejected") return i;
258
+ if (i.phase !== "dispatched" || i.claimId !== t) throw C();
259
+ return c(r, i, a, {
260
+ phase: "rejected",
261
+ claimId: null,
262
+ receipt: {
263
+ operationId: e,
264
+ rejection: n
265
+ }
266
+ }, {
267
+ phase: "rejected",
268
+ claimId: null,
269
+ rejection: n
270
+ });
271
+ })),
272
+ listActive: (t, n) => A(async () => {
273
+ if (!Number.isSafeInteger(t) || t < 1 || t > 100 || n !== null && (n.length === 0 || n.length > 191)) throw C();
274
+ return (await e.query({
275
+ table: h,
276
+ predicate: n === null ? u("activeId") : i(u("activeId"), s("tenantId", n)),
277
+ order: [{
278
+ column: "tenantId",
279
+ direction: "asc"
280
+ }],
281
+ take: t,
282
+ skip: void 0,
283
+ projection: void 0
284
+ })).map((e) => {
285
+ let t = T(e).tenantId;
286
+ if (typeof t != "string" || t.length === 0) throw C();
287
+ return t;
288
+ });
289
+ }),
290
+ acknowledge: (e, t) => A(() => l(e, async (n, i) => {
291
+ if (!Number.isFinite(t.getTime()) || i.phase === "withdrawn" || i.phase === "rejected") throw C();
292
+ if (i.phase === "acknowledged" || i.phase === "completed") return i;
293
+ let a = {
294
+ operationId: e,
295
+ providerObservedAt: t.toISOString()
296
+ };
297
+ return r(n, i, {
298
+ phase: "acknowledged",
299
+ receipt: a
300
+ }, {
301
+ phase: "acknowledged",
302
+ receipt: a
303
+ });
304
+ })),
305
+ complete: (e) => A(() => l(e, async (e, t, n) => {
306
+ if (t.phase !== "completed") {
307
+ if (t.phase !== "acknowledged" || t.receipt === null) throw C();
308
+ await c(e, t, n, { phase: "completed" }, { phase: "completed" });
309
+ }
310
+ })),
311
+ assertOpen: (r) => A(() => e.transactional(async (e) => {
312
+ let i = await n(e, r);
313
+ if (i?.closed === 1) throw C();
314
+ if (i !== null && i.activeId !== null) {
315
+ let n = await t(e, String(i.activeId), !0);
316
+ if (n.tenantId !== r || y(n.phase) || n.sequence > Number(i.sequence)) throw C();
317
+ }
318
+ })),
319
+ seal: (t) => A(() => e.transactional(async (e) => {
320
+ let r = await n(e, t, !0);
321
+ if (r === null || r.activeId !== null || r.closed === 0 && !await e.update("_voltro_billing_subscription_write_heads", String(r.id), { closed: 1 }) || (await n(e, t))?.closed !== 1) throw C();
322
+ }))
323
+ };
324
+ };
325
+ export { g as BILLING_SUBSCRIPTION_WRITES_TABLE, h as BILLING_SUBSCRIPTION_WRITE_HEADS_TABLE, O as billingRequestStale, x as billingSubscriptionWriteHeadsTable, S as billingSubscriptionWritesTable, M as dataStoreSubscriptionWriteStore, y as isTerminalSubscriptionWrite };
package/dist/table.js CHANGED
@@ -1,76 +1,85 @@
1
- import { billingCustomerAccountsTable as e, billingCustomerCustodyTable as t } from "./customerStore.js";
2
- import { billingInvoiceHistoryPagesTable as n, billingInvoiceHistoryReferencesTable as r, billingInvoiceHistoryWalksTable as i } from "./invoiceHistoryJournal.js";
3
- import { BILLING_INVOICE_OBSERVATIONS_TABLE as a, billingInvoiceObservationsTable as o, billingRetainedInvoiceObservationsTable as s } from "./invoiceStore.js";
4
- import { billingInvoiceHistoryWorkTable as c } from "./invoiceHistoryWork.js";
5
- import { billingInvoiceHistoryDispatchTable as l, billingInvoiceHistoryScanAccountsTable as u } from "./invoiceHistoryProgress.js";
6
- import { billingUsageEventsTable as d } from "./usageEvents.js";
7
- import { billingCheckoutOperationsTable as f } from "./checkoutStore.js";
8
- import { billingCloseOperationsTable as p } from "./closeStore.js";
9
- import { billingDunningNoticesTable as m } from "./dunning.js";
10
- import { id as h, integer as g, table as _, text as v, timestamp as y } from "@voltro/database";
1
+ import { billingInvoicePaymentCorrectionsTable as e, billingInvoicePaymentHeadsTable as t } from "./invoicePaymentEpoch.js";
2
+ import { billingSubscriptionWriteHeadsTable as n, billingSubscriptionWritesTable as r } from "./subscriptionWriteStore.js";
3
+ import { billingDunningNoticesTable as i } from "./dunning.js";
4
+ import { billingCheckoutOperationsTable as a } from "./checkoutStore.js";
5
+ import { billingCloseOperationsTable as o } from "./closeStore.js";
6
+ import { billingUsageEventsTable as s } from "./usageEvents.js";
7
+ import { BILLING_INVOICE_OBSERVATIONS_TABLE as c, billingInvoiceObservationsTable as l, billingRetainedInvoiceObservationsTable as u } from "./invoiceStore.js";
8
+ import { billingCustomerAccountsTable as d, billingCustomerCustodyTable as f } from "./customerStore.js";
9
+ import { billingInvoiceHistoryPagesTable as p, billingInvoiceHistoryReferencesTable as m, billingInvoiceHistoryWalksTable as h } from "./invoiceHistoryJournal.js";
10
+ import { billingInvoiceHistoryWorkTable as g } from "./invoiceHistoryWork.js";
11
+ import { billingInvoiceHistoryDispatchTable as _, billingInvoiceHistoryScanAccountsTable as v } from "./invoiceHistoryProgress.js";
12
+ import { id as y, integer as b, json as x, table as S, text as C, timestamp as w } from "@voltro/database";
11
13
  // src/table.ts
12
- var b = "_voltro_billing_customers", x = "_voltro_billing_subscriptions", S = "_voltro_billing_invoices", C = "_voltro_billing_usage", w = _(b, {
13
- id: h({ prefix: "bcust" }),
14
- tenantId: v(),
15
- provider: v(),
16
- providerCustomerId: v(),
17
- createdAt: y(),
18
- updatedAt: y()
19
- }).index("byBillingCustomerTenant", ["tenantId"]).index("byBillingProviderCustomer", ["providerCustomerId"]), T = _(x, {
20
- id: h({ prefix: "bsub" }),
21
- tenantId: v(),
22
- provider: v(),
23
- providerSubscriptionId: v(),
24
- plan: v(),
25
- status: v(),
26
- quantity: g().default(1),
27
- currentPeriodStart: y().nullable(),
28
- currentPeriodEnd: y().nullable(),
29
- cancelAt: y().nullable(),
30
- pastDueSince: y().nullable(),
31
- statusEventAt: y().nullable(),
32
- createdAt: y(),
33
- updatedAt: y()
34
- }).index("byBillingSubscriptionTenant", ["tenantId"]).index("byBillingProviderSubscription", ["providerSubscriptionId"]).index("byBillingSubscriptionStatus", ["status"]), E = _(S, {
35
- id: h({ prefix: "binv" }),
36
- tenantId: v(),
37
- provider: v(),
38
- providerInvoiceId: v(),
39
- amountMinor: g(),
40
- currency: v(),
41
- status: v(),
42
- statusEventAt: y().nullable(),
43
- createdAt: y()
44
- }).index("byBillingInvoiceTenant", ["tenantId"]).index("byBillingProviderInvoice", ["providerInvoiceId"]), D = _(C, {
45
- id: h({ prefix: "buse" }),
46
- tenantId: v().maxLength(191),
47
- entitlementKey: v().maxLength(191),
48
- period: v().maxLength(16),
49
- used: g().default(0),
50
- reportedToProvider: g().default(0),
51
- updatedAt: y()
14
+ var T = "_voltro_billing_customers", E = "_voltro_billing_subscriptions", D = "_voltro_billing_invoices", O = "_voltro_billing_usage", k = S(T, {
15
+ id: y({ prefix: "bcust" }),
16
+ tenantId: C(),
17
+ provider: C(),
18
+ providerCustomerId: C(),
19
+ createdAt: w(),
20
+ updatedAt: w()
21
+ }).index("byBillingCustomerTenant", ["tenantId"]).index("byBillingProviderCustomer", ["providerCustomerId"]), A = S(E, {
22
+ providerObservation: x().nullable().serverOnly(),
23
+ id: y({ prefix: "bsub" }),
24
+ tenantId: C(),
25
+ provider: C(),
26
+ providerSubscriptionId: C().maxLength(191).unique(),
27
+ plan: C(),
28
+ status: C(),
29
+ quantity: b().default(1),
30
+ currentPeriodStart: w().nullable(),
31
+ currentPeriodEnd: w().nullable(),
32
+ cancelAt: w().nullable(),
33
+ pastDueSince: w().nullable(),
34
+ statusEventAt: w().nullable(),
35
+ createdAt: w(),
36
+ updatedAt: w()
37
+ }).index("byBillingSubscriptionTenant", ["tenantId"]).index("byBillingSubscriptionStatus", ["status"]), j = S(D, {
38
+ id: y({ prefix: "binv" }),
39
+ tenantId: C(),
40
+ provider: C(),
41
+ providerInvoiceId: C(),
42
+ amountMinor: b(),
43
+ currency: C(),
44
+ status: C(),
45
+ statusEventAt: w().nullable(),
46
+ createdAt: w()
47
+ }).index("byBillingInvoiceTenant", ["tenantId"]).index("byBillingProviderInvoice", ["providerInvoiceId"]), M = S(O, {
48
+ id: y({ prefix: "buse" }),
49
+ tenantId: C().maxLength(191),
50
+ entitlementKey: C().maxLength(191),
51
+ period: C().maxLength(16),
52
+ used: b().default(0),
53
+ reportedToProvider: b().default(0),
54
+ meterDispatchedThrough: b().default(0),
55
+ invoiceDispatchedThrough: b().default(0),
56
+ updatedAt: w()
52
57
  }).unique("byBillingUsageWindow", [
53
58
  "tenantId",
54
59
  "entitlementKey",
55
60
  "period"
56
- ]), O = () => [
57
- m,
58
- d,
59
- p,
60
- f,
61
- w,
62
- e,
61
+ ]), N = () => [
63
62
  t,
64
- i,
63
+ e,
65
64
  n,
66
65
  r,
67
- c,
68
- u,
69
- l,
70
- T,
71
- E,
72
- o,
66
+ i,
73
67
  s,
74
- D
68
+ o,
69
+ a,
70
+ k,
71
+ d,
72
+ f,
73
+ h,
74
+ p,
75
+ m,
76
+ g,
77
+ v,
78
+ _,
79
+ A,
80
+ j,
81
+ l,
82
+ u,
83
+ M
75
84
  ];
76
- export { b as BILLING_CUSTOMERS_TABLE, S as BILLING_INVOICES_TABLE, a as BILLING_INVOICE_OBSERVATIONS_TABLE, x as BILLING_SUBSCRIPTIONS_TABLE, C as BILLING_USAGE_TABLE, w as billingCustomersTable, o as billingInvoiceObservationsTable, E as billingInvoicesTable, s as billingRetainedInvoiceObservationsTable, T as billingSubscriptionsTable, O as billingTables, D as billingUsageTable };
85
+ export { T as BILLING_CUSTOMERS_TABLE, D as BILLING_INVOICES_TABLE, c as BILLING_INVOICE_OBSERVATIONS_TABLE, E as BILLING_SUBSCRIPTIONS_TABLE, O as BILLING_USAGE_TABLE, k as billingCustomersTable, l as billingInvoiceObservationsTable, j as billingInvoicesTable, u as billingRetainedInvoiceObservationsTable, A as billingSubscriptionsTable, N as billingTables, M as billingUsageTable };