@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.
- package/CHANGELOG.md +1835 -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
package/dist/index.js
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
1
|
+
import { BillingClosurePending as e, BillingError as t, BillingRequestStale as n, BillingService as r, DEFAULT_PLAN as i, EntitlementExceeded as a, SubscriptionLocked as o } from "./types.js";
|
|
2
|
+
import { billingInvoicePaymentCorrectionsTable as s, billingInvoicePaymentHeadsTable as ee } from "./invoicePaymentEpoch.js";
|
|
3
|
+
import { BILLING_SUBSCRIPTION_WRITES_TABLE as te, BILLING_SUBSCRIPTION_WRITE_HEADS_TABLE as ne, billingSubscriptionWriteHeadsTable as re, billingSubscriptionWritesTable as ie, dataStoreSubscriptionWriteStore as c, isTerminalSubscriptionWrite as l } from "./subscriptionWriteStore.js";
|
|
4
|
+
import { BILLING_DUNNING_NOTICES_TABLE as ae, DEFAULT_DUNNING_STEPS as oe, DEFAULT_GRACE_HOURS as u, DEFAULT_LOCKOUT as se, DUNNING_LOCK_STEP_ID as ce, billingDunningNoticesTable as le, dataStoreDunningNoticeStore as ue, defaultDunningEmail as de, dueSteps as d, dunningMailNotifier as f, episodeKeyOf as fe, evaluateBillingEntitlement as pe, graceEndOf as me, memoryDunningNoticeStore as he, resolveDunningConfig as ge } from "./dunning.js";
|
|
5
|
+
import { BILLING_CHECKOUT_OPERATIONS_TABLE as p, billingCheckoutOperationsTable as _e, dataStoreCheckoutOperationStore as m, memoryCheckoutOperationStore as h } from "./checkoutStore.js";
|
|
6
|
+
import { BILLING_CLOSE_OPERATIONS_TABLE as g, billingCloseOperationsTable as _, dataStoreBillingCloseStore as ve, memoryBillingCloseStore as v } from "./closeStore.js";
|
|
7
|
+
import { BILLING_USAGE_EVENTS_TABLE as y, billingUsageEventsTable as b } from "./usageEvents.js";
|
|
8
|
+
import { InvoicePaymentObservationSchema as x, assertInvoicePaymentObservation as ye } from "./invoicePaymentObservation.js";
|
|
9
|
+
import { BILLING_INVOICE_OBSERVATIONS_TABLE as be, billingInvoiceObservationsTable as S, billingRetainedInvoiceObservationsTable as C } from "./invoiceStore.js";
|
|
10
|
+
import { BILLING_ACCOUNT_CUSTODY_INVENTORY_TABLES as w, BILLING_CUSTODY_INVENTORY_TABLES as T, inspectBillingAccountCustody as xe, inspectBillingCustody as Se } from "./custodyInventory.js";
|
|
11
|
+
import { BILLING_CUSTOMER_ACCOUNTS_TABLE as E, BILLING_CUSTOMER_CUSTODY_TABLE as D, billingCustomerAccountsTable as Ce, billingCustomerCustodyTable as O } from "./customerStore.js";
|
|
12
|
+
import { BILLING_INVOICE_HISTORY_PAGES_TABLE as we, BILLING_INVOICE_HISTORY_REFERENCES_TABLE as Te, BILLING_INVOICE_HISTORY_WALKS_TABLE as k, billingInvoiceHistoryPagesTable as A, billingInvoiceHistoryReferencesTable as j, billingInvoiceHistoryWalksTable as M, dataStoreInvoiceHistoryJournal as N } from "./invoiceHistoryJournal.js";
|
|
13
|
+
import { BILLING_INVOICE_HISTORY_WORK_TABLE as Ee, billingInvoiceHistoryWorkTable as P, dataStoreInvoiceHistoryWorkStore as F } from "./invoiceHistoryWork.js";
|
|
14
|
+
import { BILLING_INVOICE_HISTORY_DISPATCH_TABLE as I, BILLING_INVOICE_HISTORY_SCAN_ACCOUNTS_TABLE as L, billingInvoiceHistoryDispatchTable as R, billingInvoiceHistoryScanAccountsTable as z, dataStoreInvoiceHistoryProgressStore as B } from "./invoiceHistoryProgress.js";
|
|
15
|
+
import { BILLING_CUSTOMERS_TABLE as V, BILLING_INVOICES_TABLE as H, BILLING_SUBSCRIPTIONS_TABLE as U, BILLING_USAGE_TABLE as De, billingCustomersTable as W, billingInvoicesTable as G, billingSubscriptionsTable as K, billingTables as Oe, billingUsageTable as q } from "./table.js";
|
|
16
|
+
import { captureSubscriptionObservation as J } from "./subscriptionObservation.js";
|
|
17
|
+
import { paidInvoiceCoverageInTransaction as ke } from "./paidInvoiceCoverage.js";
|
|
18
|
+
import { makeBillingEventDelivery as Ae } from "./eventDelivery.js";
|
|
19
|
+
import { buildEnforceInterceptor as je, evaluateEntitlement as Me, requireEntitled as Ne, requireEntitlement as Pe } from "./entitlement.js";
|
|
20
|
+
import { dataStoreStores as Fe, isStaleStatusEvent as Ie, memoryStores as Le, selectCurrentSubscription as Re } from "./stores.js";
|
|
21
|
+
import { billingServiceLayer as ze, buildBillingService as Be, periodKey as Ve } from "./service.js";
|
|
22
|
+
import { buildMeteringChangeTap as He, buildMeteringInterceptor as Ue, hasCdcMeters as We, runAutopilotFlush as Ge, validateMeteringConfig as Ke } from "./metering.js";
|
|
23
|
+
import { buildPlanRegistry as qe, emptyPlanRegistry as Je } from "./plans.js";
|
|
24
|
+
import { BILLING_FLUSH_CLAIMS_TABLE as Ye, billingFlushClaimsTable as Xe, claimFlushWindow as Ze, flushWindowKey as Qe } from "./flushClaim.js";
|
|
25
|
+
import { STRIPE_API_VERSION as $e, STRIPE_DASHBOARD_REMINDERS as et, diffMeter as tt, diffPortal as nt, diffPrice as rt, diffProduct as it, diffRetiredMeter as at, diffRetiredPrice as ot, diffRetiredProduct as st, diffTaxSettings as ct, diffWebhook as lt, portalParams as ut, sellingReadiness as dt } from "./catalog.js";
|
|
26
|
+
import { StripeRestError as ft, formEncode as pt, redactStripeKeys as mt, stripeRest as ht } from "./stripeRest.js";
|
|
27
|
+
import { STRIPE_WEBHOOK_EVENTS as gt, normalizeStripeEvent as _t, stripeProvider as vt } from "./stripeProvider.js";
|
|
28
|
+
import { assertBillingProductionReady as yt, billingEgressOf as bt, isProductionBoot as xt, mockProvider as St, resolveProvider as Ct } from "./providers.js";
|
|
29
|
+
import { BILLING_WEBHOOK_ID as wt, BILLING_WEBHOOK_PATH as Y, billingWebhookDescriptor as Tt, mountBillingWebhook as Et } from "./webhook.js";
|
|
30
|
+
import { billingRpcClientImports as Dt, cancelSubscriptionDescriptor as Ot, changePlanDescriptor as kt, changeSeatsDescriptor as At, entitlementStatusDescriptor as jt, invoicesDescriptor as Mt, operationStatusDescriptor as Nt, pendingOperationDescriptor as Pt, portalUrlDescriptor as Ft, previewChangeDescriptor as It, reportUsageDescriptor as Lt, resumeSubscriptionDescriptor as Rt, startCheckoutDescriptor as zt, subscriptionDescriptor as Bt, syncDescriptor as Vt } from "./rpc.js";
|
|
31
|
+
import { envOutRefusal as Ht, mergeEnvFile as Ut, openFindings as Wt, parseProvisionArgs as Gt, provisionStripeCatalog as Kt, resolveProvisionKey as qt, runStripeProvision as Jt } from "./provision.js";
|
|
32
|
+
import { Effect as X } from "effect";
|
|
33
|
+
import { and as Yt, eq as Xt, registerRetention as Zt, retentionTtlMsFromEnv as Qt } from "@voltro/database";
|
|
34
|
+
import { dataStoreIdempotencyStore as $t } from "@voltro/runtime";
|
|
35
|
+
import { composeRpcInterceptors as en, definePlugin as tn, pluginInstanceName as Z, recheckGuardsEffect as nn } from "@voltro/protocol";
|
|
36
|
+
import { pluginEnv as rn } from "@voltro/env";
|
|
37
|
+
import { replicaId as an } from "@voltro/protocol/identity";
|
|
33
38
|
// src/index.ts
|
|
34
39
|
var Q = (e) => e === null ? null : {
|
|
35
40
|
plan: e.plan,
|
|
@@ -37,7 +42,7 @@ var Q = (e) => e === null ? null : {
|
|
|
37
42
|
quantity: e.quantity,
|
|
38
43
|
currentPeriodEnd: e.currentPeriodEnd ? e.currentPeriodEnd.toISOString() : null,
|
|
39
44
|
cancelAt: e.cancelAt ? e.cancelAt.toISOString() : null
|
|
40
|
-
},
|
|
45
|
+
}, on = rn([{
|
|
41
46
|
name: "STRIPE_SECRET_KEY",
|
|
42
47
|
required: !1,
|
|
43
48
|
secret: !0,
|
|
@@ -47,82 +52,82 @@ var Q = (e) => e === null ? null : {
|
|
|
47
52
|
required: !1,
|
|
48
53
|
secret: !0,
|
|
49
54
|
description: "Stripe webhook signing secret (whsec_…) for verifying webhook payloads."
|
|
50
|
-
}]), $ = "@voltro/plugin-billing",
|
|
51
|
-
let
|
|
52
|
-
...
|
|
53
|
-
...
|
|
54
|
-
planForPriceId:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
env:
|
|
59
|
-
providerOption:
|
|
55
|
+
}]), $ = "@voltro/plugin-billing", sn = (e = {}) => {
|
|
56
|
+
let r = process.env, i = qe(e.plans ?? {}), s = Ct({
|
|
57
|
+
...e.provider === void 0 ? {} : { provider: e.provider },
|
|
58
|
+
...e.apiKey === void 0 ? {} : { apiKey: e.apiKey },
|
|
59
|
+
planForPriceId: i.planForPriceId,
|
|
60
|
+
seatPricingForPriceId: i.seatPricingForPriceId,
|
|
61
|
+
env: r
|
|
62
|
+
}), ee = e.webhookSecret ?? on.read("STRIPE_WEBHOOK_SECRET") ?? null, re = {
|
|
63
|
+
env: r,
|
|
64
|
+
providerOption: e.provider,
|
|
60
65
|
resolvedName: s.name,
|
|
61
|
-
webhookSecret:
|
|
62
|
-
redirectOrigins:
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
X({
|
|
66
|
+
webhookSecret: ee,
|
|
67
|
+
redirectOrigins: e.redirectOrigins
|
|
68
|
+
}, ie = ge(e.dunning, r);
|
|
69
|
+
Zt({
|
|
66
70
|
source: "plugin",
|
|
67
|
-
table:
|
|
71
|
+
table: De,
|
|
68
72
|
timeColumn: "updatedAt",
|
|
69
|
-
where:
|
|
70
|
-
ttlMs:
|
|
73
|
+
where: Yt(Xt("used", 0), Xt("reportedToProvider", 0)),
|
|
74
|
+
ttlMs: Qt(process.env.VOLTRO_BILLING_USAGE_TTL_HOURS, 9600),
|
|
71
75
|
label: "unused billing usage counters"
|
|
72
|
-
}),
|
|
76
|
+
}), Zt({
|
|
73
77
|
source: "plugin",
|
|
74
|
-
table:
|
|
78
|
+
table: Ye,
|
|
75
79
|
timeColumn: "claimedAt",
|
|
76
|
-
ttlMs:
|
|
80
|
+
ttlMs: Qt(process.env.VOLTRO_BILLING_FLUSH_CLAIM_TTL_HOURS, 1),
|
|
77
81
|
label: "billing flush claims"
|
|
78
|
-
}),
|
|
82
|
+
}), Zt({
|
|
79
83
|
source: "plugin",
|
|
80
|
-
table:
|
|
84
|
+
table: ae,
|
|
81
85
|
timeColumn: "sentAt",
|
|
82
|
-
ttlMs:
|
|
86
|
+
ttlMs: Qt(process.env.VOLTRO_BILLING_DUNNING_TTL_HOURS, 9600),
|
|
83
87
|
label: "billing dunning notices"
|
|
84
88
|
});
|
|
85
|
-
let { service:
|
|
89
|
+
let { service: c, holder: l } = Be({
|
|
86
90
|
provider: s,
|
|
87
|
-
plans:
|
|
88
|
-
...
|
|
89
|
-
...
|
|
90
|
-
...
|
|
91
|
-
...
|
|
92
|
-
...
|
|
93
|
-
...
|
|
94
|
-
...
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
plans: i,
|
|
92
|
+
...e.attempts === void 0 ? {} : { attempts: e.attempts },
|
|
93
|
+
...e.checkout === void 0 ? {} : { checkout: e.checkout },
|
|
94
|
+
...e.admit === void 0 ? {} : { admit: e.admit },
|
|
95
|
+
...e.redirectOrigins === void 0 ? {} : { redirectOrigins: e.redirectOrigins },
|
|
96
|
+
...e.isTenantClosed === void 0 ? {} : { isTenantClosed: e.isTenantClosed },
|
|
97
|
+
...e.onEvent === void 0 ? {} : { onEvent: e.onEvent },
|
|
98
|
+
...e.resolveEntitlementLimit === void 0 ? {} : { resolveEntitlementLimit: e.resolveEntitlementLimit },
|
|
99
|
+
...e.invoiceHistoryHeadRescanMs === void 0 ? {} : { invoiceHistoryHeadRescanMs: e.invoiceHistoryHeadRescanMs },
|
|
100
|
+
dunning: ie
|
|
101
|
+
}), oe = ze(c), u, se = {
|
|
102
|
+
scope: Z({
|
|
98
103
|
base: $,
|
|
99
|
-
alias:
|
|
100
|
-
instance:
|
|
104
|
+
alias: e.alias,
|
|
105
|
+
instance: e.name
|
|
101
106
|
}),
|
|
102
107
|
store: () => {
|
|
103
|
-
if (
|
|
104
|
-
return
|
|
108
|
+
if (u === void 0) throw Error("Billing delivery requires the bound native store.");
|
|
109
|
+
return u;
|
|
105
110
|
}
|
|
106
|
-
},
|
|
111
|
+
}, ce = Ae({
|
|
107
112
|
provider: s,
|
|
108
|
-
service:
|
|
109
|
-
receipts:
|
|
110
|
-
...
|
|
111
|
-
}),
|
|
113
|
+
service: c,
|
|
114
|
+
receipts: se,
|
|
115
|
+
...e.onEvent === void 0 ? {} : { onEvent: e.onEvent }
|
|
116
|
+
}), le = Et({
|
|
112
117
|
provider: s,
|
|
113
|
-
service:
|
|
114
|
-
receipts:
|
|
115
|
-
webhookSecret:
|
|
116
|
-
...
|
|
118
|
+
service: c,
|
|
119
|
+
receipts: se,
|
|
120
|
+
webhookSecret: ee,
|
|
121
|
+
...e.onEvent === void 0 ? {} : { onEvent: e.onEvent },
|
|
117
122
|
onLateDelivery: () => {
|
|
118
|
-
|
|
123
|
+
q();
|
|
119
124
|
}
|
|
120
|
-
}),
|
|
125
|
+
}), ue = {
|
|
121
126
|
method: "POST",
|
|
122
|
-
path:
|
|
127
|
+
path: Y,
|
|
123
128
|
originGuard: "exempt",
|
|
124
129
|
handle: async (e) => {
|
|
125
|
-
let t = await
|
|
130
|
+
let t = await le({
|
|
126
131
|
method: e.method,
|
|
127
132
|
path: e.path,
|
|
128
133
|
headers: e.headers,
|
|
@@ -135,59 +140,63 @@ var Q = (e) => e === null ? null : {
|
|
|
135
140
|
...t.headers === void 0 ? {} : { headers: { ...t.headers } }
|
|
136
141
|
};
|
|
137
142
|
}
|
|
138
|
-
},
|
|
139
|
-
...
|
|
143
|
+
}, de = (e) => ({
|
|
144
|
+
...e,
|
|
140
145
|
execute: (n, r) => {
|
|
141
146
|
let i = r.request.subject;
|
|
142
|
-
return i.type === "anonymous" || typeof i.tenantId != "string" || i.tenantId === "" ?
|
|
147
|
+
return i.type === "anonymous" || typeof i.tenantId != "string" || i.tenantId === "" ? X.fail(new t({
|
|
143
148
|
source: "billing",
|
|
144
149
|
message: "billing routes answer only a signed-in caller that belongs to a tenant",
|
|
145
150
|
transient: !1
|
|
146
|
-
})) :
|
|
151
|
+
})) : e.execute(n, r);
|
|
147
152
|
}
|
|
148
|
-
}),
|
|
153
|
+
}), d = (e, t, n, r) => e.pipe(X.flatMap((e) => nn(r.request.subject, t.guards, n).pipe(X.flatMap((t) => t === null ? X.succeed(e) : X.fail(t))))), f = (e, n, r) => () => nn(r.request.subject, e.guards, n).pipe(X.flatMap((e) => e === null ? X.void : X.fail(new t({
|
|
154
|
+
source: "billing",
|
|
155
|
+
message: "Current billing authority is required.",
|
|
156
|
+
transient: !1
|
|
157
|
+
})))), fe = [
|
|
149
158
|
{
|
|
150
|
-
...
|
|
151
|
-
execute: (
|
|
152
|
-
let r =
|
|
153
|
-
return
|
|
159
|
+
...zt,
|
|
160
|
+
execute: (e, n) => {
|
|
161
|
+
let r = e;
|
|
162
|
+
return d(c.startCheckout({
|
|
154
163
|
tenantId: n.request.subject.tenantId ?? "",
|
|
155
164
|
plan: r.plan,
|
|
156
165
|
successUrl: r.successUrl,
|
|
157
166
|
cancelUrl: r.cancelUrl,
|
|
158
167
|
...r.quantity === void 0 ? {} : { quantity: r.quantity },
|
|
159
|
-
authorize: () =>
|
|
168
|
+
authorize: () => nn(n.request.subject, zt.guards, e).pipe(X.flatMap((e) => e === null ? X.void : X.fail(new t({
|
|
160
169
|
source: "billing",
|
|
161
170
|
message: "Current checkout authority could not be confirmed.",
|
|
162
171
|
transient: !1
|
|
163
172
|
}))))
|
|
164
|
-
}),
|
|
173
|
+
}), zt, e, n);
|
|
165
174
|
}
|
|
166
175
|
},
|
|
167
176
|
{
|
|
168
|
-
...
|
|
177
|
+
...Ft,
|
|
169
178
|
execute: (e, t) => {
|
|
170
179
|
let n = e;
|
|
171
|
-
return
|
|
180
|
+
return d(c.portalUrl(t.request.subject.tenantId ?? "", n.returnUrl), Ft, e, t);
|
|
172
181
|
}
|
|
173
182
|
},
|
|
174
183
|
{
|
|
175
|
-
...
|
|
184
|
+
...Bt,
|
|
176
185
|
source: [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
186
|
+
U,
|
|
187
|
+
E,
|
|
188
|
+
D
|
|
180
189
|
],
|
|
181
|
-
execute: (e, t) =>
|
|
190
|
+
execute: (e, t) => c.subscription(t.request.subject.tenantId ?? "").pipe(X.map((e) => ({ subscription: Q(e) })))
|
|
182
191
|
},
|
|
183
192
|
{
|
|
184
|
-
...
|
|
193
|
+
...jt,
|
|
185
194
|
source: [
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
195
|
+
U,
|
|
196
|
+
E,
|
|
197
|
+
D
|
|
189
198
|
],
|
|
190
|
-
execute: (e, t) =>
|
|
199
|
+
execute: (e, t) => c.entitlementStatus(t.request.subject.tenantId ?? "").pipe(X.map((e) => ({
|
|
191
200
|
plan: e.plan,
|
|
192
201
|
billedPlan: e.billedPlan,
|
|
193
202
|
status: e.status,
|
|
@@ -199,13 +208,13 @@ var Q = (e) => e === null ? null : {
|
|
|
199
208
|
})))
|
|
200
209
|
},
|
|
201
210
|
{
|
|
202
|
-
...
|
|
211
|
+
...It,
|
|
203
212
|
execute: (e, t) => {
|
|
204
213
|
let n = e;
|
|
205
|
-
return
|
|
214
|
+
return c.previewChange(t.request.subject.tenantId ?? "", {
|
|
206
215
|
...n.plan === void 0 ? {} : { plan: n.plan },
|
|
207
216
|
...n.quantity === void 0 ? {} : { quantity: n.quantity }
|
|
208
|
-
}).pipe(
|
|
217
|
+
}).pipe(X.map((e) => ({
|
|
209
218
|
plan: e.plan,
|
|
210
219
|
quantity: e.quantity,
|
|
211
220
|
prorationMinor: e.prorationMinor,
|
|
@@ -214,77 +223,86 @@ var Q = (e) => e === null ? null : {
|
|
|
214
223
|
}
|
|
215
224
|
},
|
|
216
225
|
{
|
|
217
|
-
...
|
|
226
|
+
...Mt,
|
|
218
227
|
source: [
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
228
|
+
be,
|
|
229
|
+
D,
|
|
230
|
+
E
|
|
222
231
|
],
|
|
223
|
-
execute: (e, t) =>
|
|
232
|
+
execute: (e, t) => c.invoices(t.request.subject.tenantId ?? "").pipe(X.map((e) => ({ invoices: e.map((e) => ({
|
|
224
233
|
...e,
|
|
225
234
|
createdAt: e.createdAt?.toISOString() ?? null
|
|
226
235
|
})) })))
|
|
227
236
|
},
|
|
228
237
|
{
|
|
229
|
-
...
|
|
238
|
+
...Lt,
|
|
230
239
|
execute: (e, t) => {
|
|
231
240
|
let n = e;
|
|
232
|
-
return
|
|
241
|
+
return c.reportUsage(t.request.subject.tenantId ?? "", n.key, n.quantity).pipe(X.map(() => ({ ok: !0 })));
|
|
233
242
|
}
|
|
234
243
|
},
|
|
235
244
|
{
|
|
236
|
-
...
|
|
245
|
+
...kt,
|
|
237
246
|
execute: (e, t) => {
|
|
238
247
|
let n = e;
|
|
239
|
-
return d.changePlan(t.request.subject.tenantId ?? "", n.plan).pipe(
|
|
248
|
+
return d(c.changePlan(t.request.subject.tenantId ?? "", n.plan, void 0, f(kt, e, t), n.requestId).pipe(X.map((e) => ({
|
|
240
249
|
plan: e.plan,
|
|
241
250
|
quantity: e.quantity,
|
|
242
251
|
prorationMinor: e.prorationMinor,
|
|
243
252
|
currency: e.currency
|
|
244
|
-
})));
|
|
253
|
+
}))), kt, e, t);
|
|
245
254
|
}
|
|
246
255
|
},
|
|
247
256
|
{
|
|
248
|
-
...
|
|
257
|
+
...At,
|
|
249
258
|
execute: (e, t) => {
|
|
250
259
|
let n = e;
|
|
251
|
-
return d.changeSeats(t.request.subject.tenantId ?? "", n.quantity).pipe(
|
|
260
|
+
return d(c.changeSeats(t.request.subject.tenantId ?? "", n.quantity, void 0, f(At, e, t), n.requestId).pipe(X.map((e) => ({
|
|
252
261
|
plan: e.plan,
|
|
253
262
|
quantity: e.quantity,
|
|
254
263
|
prorationMinor: e.prorationMinor,
|
|
255
264
|
currency: e.currency
|
|
256
|
-
})));
|
|
265
|
+
}))), At, e, t);
|
|
257
266
|
}
|
|
258
267
|
},
|
|
259
268
|
{
|
|
260
|
-
...
|
|
261
|
-
execute: (e, t) => d.cancelSubscription(t.request.subject.tenantId ?? "").pipe(
|
|
269
|
+
...Ot,
|
|
270
|
+
execute: (e, t) => d(c.cancelSubscription(t.request.subject.tenantId ?? "", f(Ot, e, t), e.requestId).pipe(X.map((e) => ({ subscription: Q(e) }))), Ot, e, t)
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
...Nt,
|
|
274
|
+
execute: (e, t) => d(c.subscriptionWriteStatus(t.request.subject.tenantId ?? "", e.requestId), Nt, e, t)
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
...Pt,
|
|
278
|
+
source: [ne, te],
|
|
279
|
+
execute: (e, t) => d(c.pendingSubscriptionWrite(t.request.subject.tenantId ?? "").pipe(X.map((e) => ({ operation: e }))), Pt, e, t)
|
|
262
280
|
},
|
|
263
281
|
{
|
|
264
|
-
...
|
|
265
|
-
execute: (e, t) =>
|
|
282
|
+
...Vt,
|
|
283
|
+
execute: (e, t) => c.syncTenant(t.request.subject.tenantId ?? "").pipe(X.map((e) => ({ subscription: e === null ? null : Q(e) })))
|
|
266
284
|
},
|
|
267
285
|
{
|
|
268
|
-
...
|
|
269
|
-
execute: (e, t) => d.resumeSubscription(t.request.subject.tenantId ?? "").pipe(
|
|
286
|
+
...Rt,
|
|
287
|
+
execute: (e, t) => d(c.resumeSubscription(t.request.subject.tenantId ?? "", f(Rt, e, t), e.requestId).pipe(X.map((e) => ({ subscription: Q(e) }))), Rt, e, t)
|
|
270
288
|
}
|
|
271
|
-
].map(
|
|
289
|
+
].map(de), pe = (e, t) => ({
|
|
272
290
|
kind: "json",
|
|
273
291
|
status: e,
|
|
274
292
|
data: { error: t }
|
|
275
|
-
}),
|
|
293
|
+
}), me = [{
|
|
276
294
|
method: "GET",
|
|
277
295
|
path: "/stats",
|
|
278
296
|
scope: "declaration",
|
|
279
297
|
description: "Billing config: provider, declared plans, enforced tags",
|
|
280
|
-
handler: () =>
|
|
298
|
+
handler: () => X.succeed({
|
|
281
299
|
kind: "json",
|
|
282
300
|
data: {
|
|
283
301
|
provider: s.name,
|
|
284
302
|
supportsMeteredUsage: s.supportsMeteredUsage,
|
|
285
|
-
plans:
|
|
286
|
-
enforce:
|
|
287
|
-
webhookPath:
|
|
303
|
+
plans: i.planIds(),
|
|
304
|
+
enforce: e.enforce ? Object.keys(e.enforce) : [],
|
|
305
|
+
webhookPath: Y
|
|
288
306
|
}
|
|
289
307
|
})
|
|
290
308
|
}, {
|
|
@@ -292,164 +310,267 @@ var Q = (e) => e === null ? null : {
|
|
|
292
310
|
path: "/usage",
|
|
293
311
|
scope: "process",
|
|
294
312
|
description: "Pending (un-flushed) metered usage counters",
|
|
295
|
-
handler: () =>
|
|
313
|
+
handler: () => l.stores.usage.pending().pipe(X.map((e) => ({
|
|
296
314
|
kind: "json",
|
|
297
315
|
data: { usage: e }
|
|
298
|
-
})),
|
|
299
|
-
}],
|
|
316
|
+
})), X.catch((e) => X.succeed(pe(500, `${e.source} failed`))))
|
|
317
|
+
}], he = [
|
|
300
318
|
{
|
|
301
|
-
schema:
|
|
319
|
+
schema: t,
|
|
302
320
|
import: {
|
|
303
321
|
module: "@voltro/plugin-billing/errors",
|
|
304
322
|
name: "BillingError"
|
|
305
323
|
}
|
|
306
324
|
},
|
|
307
325
|
{
|
|
308
|
-
schema:
|
|
326
|
+
schema: a,
|
|
309
327
|
import: {
|
|
310
328
|
module: "@voltro/plugin-billing/errors",
|
|
311
329
|
name: "EntitlementExceeded"
|
|
312
330
|
}
|
|
313
331
|
},
|
|
314
332
|
{
|
|
315
|
-
schema:
|
|
333
|
+
schema: o,
|
|
316
334
|
import: {
|
|
317
335
|
module: "@voltro/plugin-billing/errors",
|
|
318
336
|
name: "SubscriptionLocked"
|
|
319
337
|
}
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
schema: n,
|
|
341
|
+
import: {
|
|
342
|
+
module: "@voltro/plugin-billing/errors",
|
|
343
|
+
name: "BillingRequestStale"
|
|
344
|
+
}
|
|
320
345
|
}
|
|
321
|
-
],
|
|
322
|
-
|
|
323
|
-
let
|
|
324
|
-
claimChange: () =>
|
|
346
|
+
], p = e.enforce, _e = p !== void 0 && Object.keys(p).length > 0 ? je(p, c) : void 0, m = e.metering;
|
|
347
|
+
m !== void 0 && Ke(m);
|
|
348
|
+
let h = m !== void 0 && Object.keys(m).length > 0 ? Ue(c, m) : void 0, g = m !== void 0 && We(m), _ = { claim: void 0 }, ve = m === void 0 ? void 0 : He(c, m, {
|
|
349
|
+
claimChange: () => _.claim,
|
|
325
350
|
onUngated: () => {
|
|
326
|
-
|
|
351
|
+
X.runSync(X.logWarning("metering: CDC meters are accruing PER PROCESS — with N replicas a tenant is billed N times. The framework did not hand this plugin a change claimer (expected on the memory store; on a SQL store this is a bug worth reporting).").pipe(X.annotateLogs({ scope: "voltro:billing" })));
|
|
327
352
|
}
|
|
328
|
-
}),
|
|
353
|
+
}), v = en([h, _e].filter((e) => e !== void 0)), y, b = e.invoiceHistoryRecoveryIntervalMs ?? 6e4;
|
|
354
|
+
if (!Number.isSafeInteger(b) || b < 0 || b !== 0 && (b < 1e3 || b > 864e5)) throw TypeError("Invoice-history recovery requires 0 or a whole interval from one second through one day");
|
|
355
|
+
let x = s.listInvoiceHistory !== void 0 && s.fetchInvoiceSnapshot !== void 0, ye = Z({
|
|
356
|
+
base: $,
|
|
357
|
+
alias: e.alias,
|
|
358
|
+
instance: e.name
|
|
359
|
+
}) + ".invoiceHistoryRecovery", S, C, w, T = 0, xe = () => {
|
|
360
|
+
if (!L || y === void 0 || !x) return Promise.resolve();
|
|
361
|
+
if (w !== void 0) return w;
|
|
362
|
+
let e = l.stores, n = T, r = Promise.resolve().then(async () => {
|
|
363
|
+
let r = performance.now() + 3e4, i = {
|
|
364
|
+
passes: 0,
|
|
365
|
+
admittedPages: 0,
|
|
366
|
+
observed: 0,
|
|
367
|
+
deferred: 0,
|
|
368
|
+
busy: 0,
|
|
369
|
+
unconfirmed: 0
|
|
370
|
+
};
|
|
371
|
+
try {
|
|
372
|
+
for (let t = 0; t < 8 && performance.now() < r; t++) {
|
|
373
|
+
if (!L || T !== n || l.stores !== e) return;
|
|
374
|
+
let t = await X.runPromise(c.reconcileInvoiceHistory());
|
|
375
|
+
if (i.passes++, i.admittedPages += t.admittedPages, i.observed += t.observed, i.deferred += t.deferred, i.busy += t.busy, i.unconfirmed += t.unconfirmed, t.kind === "idle" || t.kind === "contended") break;
|
|
376
|
+
}
|
|
377
|
+
if (i.unconfirmed > 0) throw Error("Original invoice observations remain unconfirmed");
|
|
378
|
+
L && T === n && (i.admittedPages > 0 || i.observed > 0 || i.deferred > 0) && G.info("billing invoice-history recovery", i);
|
|
379
|
+
} catch {
|
|
380
|
+
throw G.error("Billing invoice-history recovery remains retryable; native custody is retained.", i), new t({
|
|
381
|
+
source: "invoiceHistoryRecovery",
|
|
382
|
+
transient: !0,
|
|
383
|
+
message: "The bounded invoice-history recovery pass remains unconfirmed."
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
return w = r, r.then(() => {
|
|
388
|
+
w === r && (w = void 0);
|
|
389
|
+
}, () => {
|
|
390
|
+
w === r && (w = void 0);
|
|
391
|
+
}), r;
|
|
392
|
+
}, Se = async () => {
|
|
393
|
+
let e = C;
|
|
394
|
+
C = void 0, S = void 0, T++;
|
|
395
|
+
let t = (await Promise.allSettled([Promise.resolve().then(() => e?.stop()), w ?? Promise.resolve()])).flatMap((e) => e.status === "rejected" ? [e.reason] : []);
|
|
396
|
+
if (t.length > 0) throw AggregateError(t, "Billing invoice-history work did not drain cleanly");
|
|
397
|
+
}, Ce = () => {
|
|
398
|
+
if (!L || y === void 0 || C !== void 0 || b === 0 || !x) return;
|
|
399
|
+
let e = S;
|
|
400
|
+
if (e?.workloads === void 0 || e.workloads.includes("schedules")) {
|
|
401
|
+
if (e?.scheduleCoordinated === void 0) throw Error("Automatic invoice-history recovery requires native coordinated schedule binding; configure 0 only with an explicit recovery driver");
|
|
402
|
+
C = e.scheduleCoordinated(ye, b, xe);
|
|
403
|
+
}
|
|
404
|
+
}, O = e.subscriptionWriteRecoveryIntervalMs ?? 6e4;
|
|
405
|
+
if (!Number.isSafeInteger(O) || O < 0 || O !== 0 && (O < 1e3 || O > 864e5)) throw TypeError("Subscription-write recovery requires 0 or a whole interval from one second through one day");
|
|
406
|
+
let we = s.supportsNativeSubscriptionWrites === !0, Te = Z({
|
|
407
|
+
base: $,
|
|
408
|
+
alias: e.alias,
|
|
409
|
+
instance: e.name
|
|
410
|
+
}) + ".subscriptionWriteRecovery", k, A, j, M = 0, N = null, Ee = () => {
|
|
411
|
+
if (!L || y === void 0 || !we) return Promise.resolve();
|
|
412
|
+
if (j !== void 0) return j;
|
|
413
|
+
let e = l.stores, n = M, r = Promise.resolve().then(async () => {
|
|
414
|
+
let t = await X.runPromise(c.recoverSubscriptionWrites({
|
|
415
|
+
limit: 25,
|
|
416
|
+
afterTenantId: N
|
|
417
|
+
}));
|
|
418
|
+
M === n && l.stores === e && (N = t.nextAfter, (t.completed > 0 || t.withdrawn > 0 || t.pending > 0) && G.info("billing subscription-write recovery", { ...t }));
|
|
419
|
+
}).catch(() => {
|
|
420
|
+
throw G.error("Billing subscription-write recovery remains retryable; native intents are retained.", {}), new t({
|
|
421
|
+
source: "subscriptionWriteRecovery",
|
|
422
|
+
transient: !0,
|
|
423
|
+
message: "The bounded subscription-write recovery pass remains unconfirmed."
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
return j = r, r.then(() => {
|
|
427
|
+
j === r && (j = void 0);
|
|
428
|
+
}, () => {
|
|
429
|
+
j === r && (j = void 0);
|
|
430
|
+
}), r;
|
|
431
|
+
}, P = async () => {
|
|
432
|
+
let e = A;
|
|
433
|
+
A = void 0, k = void 0, M++, N = null;
|
|
434
|
+
let t = (await Promise.allSettled([Promise.resolve().then(() => e?.stop()), j ?? Promise.resolve()])).flatMap((e) => e.status === "rejected" ? [e.reason] : []);
|
|
435
|
+
if (t.length > 0) throw AggregateError(t, "Billing subscription-write recovery did not drain cleanly");
|
|
436
|
+
}, F = () => {
|
|
437
|
+
if (!L || y === void 0 || A !== void 0 || O === 0 || !we) return;
|
|
438
|
+
let e = k;
|
|
439
|
+
if (e?.workloads === void 0 || e.workloads.includes("schedules")) {
|
|
440
|
+
if (e?.scheduleCoordinated === void 0) throw Error("Automatic subscription-write recovery requires native coordinated schedule binding; configure 0 only with an explicit recovery driver");
|
|
441
|
+
A = e.scheduleCoordinated(Te, O, Ee);
|
|
442
|
+
}
|
|
443
|
+
}, I, L = !1, R = !1, z, B, V = null, H = !1, W, G = {
|
|
329
444
|
info: (e, t) => {
|
|
330
445
|
console.info(e, t ?? {});
|
|
331
446
|
},
|
|
332
447
|
error: (e, t) => {
|
|
333
448
|
console.error(e, t ?? {});
|
|
334
449
|
}
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}, e),
|
|
339
|
-
},
|
|
450
|
+
}, K = (e) => {
|
|
451
|
+
L && B === void 0 && (B = setTimeout(() => {
|
|
452
|
+
B = void 0, q();
|
|
453
|
+
}, e), B.unref?.());
|
|
454
|
+
}, q = () => {
|
|
340
455
|
let e = s.listUndeliveredEvents;
|
|
341
|
-
if (!
|
|
342
|
-
if (
|
|
343
|
-
let t =
|
|
344
|
-
return t > 0 ? (
|
|
456
|
+
if (!L || y === void 0 || e === void 0) return Promise.resolve();
|
|
457
|
+
if (z !== void 0) return z;
|
|
458
|
+
let t = W === void 0 ? 0 : 6e4 - (performance.now() - W);
|
|
459
|
+
return t > 0 ? (K(t), Promise.resolve()) : (z = Promise.resolve().then(async () => {
|
|
345
460
|
let t = !1, n = 0, r = 0, i = 0, a = /* @__PURE__ */ new Set();
|
|
346
461
|
try {
|
|
347
|
-
for (let o = 0; o < 10 &&
|
|
348
|
-
let o =
|
|
462
|
+
for (let o = 0; o < 10 && L; o++) {
|
|
463
|
+
let o = V;
|
|
349
464
|
if (o !== null) {
|
|
350
465
|
if (a.has(o)) throw Error("The provider event cursor repeated.");
|
|
351
466
|
a.add(o);
|
|
352
467
|
}
|
|
353
|
-
let s = await
|
|
468
|
+
let s = await X.runPromise(e({
|
|
354
469
|
cursor: o,
|
|
355
470
|
limit: 100
|
|
356
471
|
}));
|
|
357
472
|
if (!Array.isArray(s.events) || s.events.length > 100 || s.nextCursor !== null && (typeof s.nextCursor != "string" || !s.nextCursor || s.nextCursor !== s.events.at(-1)?.id || s.nextCursor === o)) throw Error("The provider event page did not supply a bounded advancing cursor.");
|
|
358
473
|
for (let e of s.events) {
|
|
359
|
-
if (!
|
|
474
|
+
if (!L) return;
|
|
360
475
|
try {
|
|
361
|
-
await
|
|
476
|
+
await X.runPromise(ce(e)) === "processed" ? n++ : r++;
|
|
362
477
|
} catch {
|
|
363
|
-
i++,
|
|
478
|
+
i++, H = !0, G.error("billing catch-up: delivery remains retryable", { eventId: e.id });
|
|
364
479
|
}
|
|
365
480
|
}
|
|
366
|
-
if (
|
|
367
|
-
t =
|
|
481
|
+
if (V = s.nextCursor, V === null) {
|
|
482
|
+
t = H, H = !1;
|
|
368
483
|
break;
|
|
369
484
|
}
|
|
370
485
|
t = !0;
|
|
371
486
|
}
|
|
372
|
-
|
|
487
|
+
G.info("billing catch-up", {
|
|
373
488
|
processed: n,
|
|
374
489
|
replayed: r,
|
|
375
490
|
failed: i,
|
|
376
|
-
continuation:
|
|
491
|
+
continuation: V !== null
|
|
377
492
|
});
|
|
378
493
|
} catch {
|
|
379
|
-
t = !0,
|
|
494
|
+
t = !0, G.error("billing catch-up failed; the current page will be retried");
|
|
380
495
|
} finally {
|
|
381
|
-
|
|
496
|
+
W = performance.now(), z = void 0, t && K(6e4);
|
|
382
497
|
}
|
|
383
|
-
}),
|
|
384
|
-
},
|
|
385
|
-
e !== void 0 && (
|
|
386
|
-
},
|
|
498
|
+
}), z);
|
|
499
|
+
}, J = (e) => {
|
|
500
|
+
e !== void 0 && (G = e), !R && L && y !== void 0 && (R = !0, q());
|
|
501
|
+
}, ke = [
|
|
387
502
|
"store:write",
|
|
388
503
|
"inspect:read",
|
|
389
504
|
"inspect:write",
|
|
390
505
|
"network:outbound:*",
|
|
391
|
-
...
|
|
506
|
+
...v === void 0 ? [] : [
|
|
392
507
|
"rpc:intercept:mutation",
|
|
393
508
|
"rpc:intercept:action",
|
|
394
509
|
"rpc:intercept:workflow"
|
|
395
510
|
],
|
|
396
|
-
...
|
|
397
|
-
...
|
|
511
|
+
...h === void 0 ? [] : ["rpc:intercept:query"],
|
|
512
|
+
...g ? ["store:changes:read"] : []
|
|
398
513
|
];
|
|
399
|
-
return
|
|
400
|
-
name:
|
|
514
|
+
return tn({
|
|
515
|
+
name: Z({
|
|
401
516
|
base: $,
|
|
402
|
-
alias:
|
|
403
|
-
instance:
|
|
517
|
+
alias: e.alias,
|
|
518
|
+
instance: e.name
|
|
404
519
|
}),
|
|
405
520
|
baseName: $,
|
|
406
521
|
description: "Billing — subscriptions, plans, entitlements + usage metering over a pluggable BillingProvider (Stripe + mock). Ships the BillingService, the requireEntitlement() in-handler guard + the enforce-map interceptor, the /billing/webhook receiver (riding @voltro/plugin-webhooks for signature + idempotency), and the _voltro_billing_* tables. Money is integer minor units.",
|
|
407
|
-
permissions:
|
|
408
|
-
declaredEnv:
|
|
409
|
-
egress:
|
|
410
|
-
services:
|
|
411
|
-
routes:
|
|
412
|
-
rpcClientDescriptors:
|
|
413
|
-
httpRoutes: [
|
|
414
|
-
inspectEndpoints:
|
|
415
|
-
extendSchema: { tables: [...
|
|
416
|
-
errorSchemas:
|
|
417
|
-
...
|
|
418
|
-
interceptMutation:
|
|
419
|
-
interceptAction:
|
|
420
|
-
interceptWorkflow:
|
|
522
|
+
permissions: ke,
|
|
523
|
+
declaredEnv: on.declared,
|
|
524
|
+
egress: bt(s),
|
|
525
|
+
services: oe,
|
|
526
|
+
routes: fe,
|
|
527
|
+
rpcClientDescriptors: Dt,
|
|
528
|
+
httpRoutes: [ue],
|
|
529
|
+
inspectEndpoints: me,
|
|
530
|
+
extendSchema: { tables: [...Oe(), Xe] },
|
|
531
|
+
errorSchemas: he,
|
|
532
|
+
...v === void 0 ? {} : {
|
|
533
|
+
interceptMutation: v,
|
|
534
|
+
interceptAction: v,
|
|
535
|
+
interceptWorkflow: v
|
|
421
536
|
},
|
|
422
|
-
...
|
|
423
|
-
...
|
|
424
|
-
bindDataStore: (e, t) => {
|
|
425
|
-
|
|
537
|
+
...h === void 0 ? {} : { interceptQuery: h },
|
|
538
|
+
...g ? { onChangeEvent: ve } : {},
|
|
539
|
+
bindDataStore: async (e, t) => {
|
|
540
|
+
await Promise.all([Se(), P()]), S = t, k = t, l.stores = Fe(e), y = e, u = $t(e), J(), _.claim = t?.claimChange, Ce(), F();
|
|
426
541
|
},
|
|
427
|
-
onActivate: (
|
|
428
|
-
|
|
542
|
+
onActivate: (t) => (yt(re), X.sync(() => {
|
|
543
|
+
t.logger.info("billing active", {
|
|
429
544
|
provider: s.name,
|
|
430
|
-
plans:
|
|
431
|
-
enforce:
|
|
432
|
-
metering:
|
|
433
|
-
webhook:
|
|
434
|
-
redirectOrigins:
|
|
435
|
-
}), s.name === "stripe" &&
|
|
436
|
-
let n =
|
|
545
|
+
plans: i.planIds().length,
|
|
546
|
+
enforce: p ? Object.keys(p).length : 0,
|
|
547
|
+
metering: m ? Object.keys(m).length : 0,
|
|
548
|
+
webhook: Y,
|
|
549
|
+
redirectOrigins: e.redirectOrigins?.length ?? "any"
|
|
550
|
+
}), s.name === "stripe" && e.redirectOrigins === void 0 && t.logger.warn("billing: no redirectOrigins — checkout and portal accept any return URL; set billingPlugin({ redirectOrigins })", {});
|
|
551
|
+
let n = e.flushIntervalMs ?? 6e4, r = m, a = r !== void 0 && Object.keys(r).length > 0;
|
|
437
552
|
if (n > 0) {
|
|
438
|
-
let e =
|
|
439
|
-
|
|
440
|
-
let t =
|
|
553
|
+
let e = an();
|
|
554
|
+
I = setInterval(() => {
|
|
555
|
+
let t = y;
|
|
441
556
|
if (t === void 0) return;
|
|
442
|
-
let
|
|
557
|
+
let i = Date.now();
|
|
443
558
|
(async () => {
|
|
444
|
-
await
|
|
559
|
+
await Ze(t, Qe(i, n), e, i) && await X.runPromise((a ? Ge(c, t, r) : c.flushUsage()).pipe(X.catch(() => X.void)));
|
|
445
560
|
})();
|
|
446
|
-
}, n),
|
|
561
|
+
}, n), I.unref?.();
|
|
447
562
|
}
|
|
448
|
-
|
|
449
|
-
}),
|
|
450
|
-
onDeactivate: () =>
|
|
451
|
-
|
|
563
|
+
L = !0, J(t.logger), Ce(), F();
|
|
564
|
+
})),
|
|
565
|
+
onDeactivate: () => X.promise(async () => {
|
|
566
|
+
L = !1, R = !1, B !== void 0 && (clearTimeout(B), B = void 0), I !== void 0 && (clearInterval(I), I = void 0);
|
|
567
|
+
let e = (await Promise.allSettled([
|
|
568
|
+
Se(),
|
|
569
|
+
P(),
|
|
570
|
+
z ?? Promise.resolve()
|
|
571
|
+
])).flatMap((e) => e.status === "rejected" ? [e.reason] : []);
|
|
572
|
+
if (e.length > 0) throw AggregateError(e, "Billing recovery shutdown requires reconciliation");
|
|
452
573
|
})
|
|
453
574
|
});
|
|
454
575
|
};
|
|
455
|
-
export {
|
|
576
|
+
export { w as BILLING_ACCOUNT_CUSTODY_INVENTORY_TABLES, p as BILLING_CHECKOUT_OPERATIONS_TABLE, g as BILLING_CLOSE_OPERATIONS_TABLE, T as BILLING_CUSTODY_INVENTORY_TABLES, V as BILLING_CUSTOMERS_TABLE, E as BILLING_CUSTOMER_ACCOUNTS_TABLE, D as BILLING_CUSTOMER_CUSTODY_TABLE, ae as BILLING_DUNNING_NOTICES_TABLE, Ye as BILLING_FLUSH_CLAIMS_TABLE, H as BILLING_INVOICES_TABLE, I as BILLING_INVOICE_HISTORY_DISPATCH_TABLE, we as BILLING_INVOICE_HISTORY_PAGES_TABLE, Te as BILLING_INVOICE_HISTORY_REFERENCES_TABLE, L as BILLING_INVOICE_HISTORY_SCAN_ACCOUNTS_TABLE, k as BILLING_INVOICE_HISTORY_WALKS_TABLE, Ee as BILLING_INVOICE_HISTORY_WORK_TABLE, be as BILLING_INVOICE_OBSERVATIONS_TABLE, U as BILLING_SUBSCRIPTIONS_TABLE, te as BILLING_SUBSCRIPTION_WRITES_TABLE, ne as BILLING_SUBSCRIPTION_WRITE_HEADS_TABLE, y as BILLING_USAGE_EVENTS_TABLE, De as BILLING_USAGE_TABLE, wt as BILLING_WEBHOOK_ID, Y as BILLING_WEBHOOK_PATH, e as BillingClosurePending, t as BillingError, n as BillingRequestStale, r as BillingService, oe as DEFAULT_DUNNING_STEPS, u as DEFAULT_GRACE_HOURS, se as DEFAULT_LOCKOUT, i as DEFAULT_PLAN, ce as DUNNING_LOCK_STEP_ID, a as EntitlementExceeded, x as InvoicePaymentObservationSchema, $e as STRIPE_API_VERSION, et as STRIPE_DASHBOARD_REMINDERS, gt as STRIPE_WEBHOOK_EVENTS, ft as StripeRestError, o as SubscriptionLocked, yt as assertBillingProductionReady, ye as assertInvoicePaymentObservation, _e as billingCheckoutOperationsTable, _ as billingCloseOperationsTable, Ce as billingCustomerAccountsTable, O as billingCustomerCustodyTable, W as billingCustomersTable, le as billingDunningNoticesTable, bt as billingEgressOf, Xe as billingFlushClaimsTable, R as billingInvoiceHistoryDispatchTable, A as billingInvoiceHistoryPagesTable, j as billingInvoiceHistoryReferencesTable, z as billingInvoiceHistoryScanAccountsTable, M as billingInvoiceHistoryWalksTable, P as billingInvoiceHistoryWorkTable, S as billingInvoiceObservationsTable, s as billingInvoicePaymentCorrectionsTable, ee as billingInvoicePaymentHeadsTable, G as billingInvoicesTable, sn as billingPlugin, C as billingRetainedInvoiceObservationsTable, ze as billingServiceLayer, re as billingSubscriptionWriteHeadsTable, ie as billingSubscriptionWritesTable, K as billingSubscriptionsTable, Oe as billingTables, b as billingUsageEventsTable, q as billingUsageTable, Tt as billingWebhookDescriptor, Be as buildBillingService, je as buildEnforceInterceptor, qe as buildPlanRegistry, J as captureSubscriptionObservation, Ze as claimFlushWindow, ve as dataStoreBillingCloseStore, m as dataStoreCheckoutOperationStore, ue as dataStoreDunningNoticeStore, N as dataStoreInvoiceHistoryJournal, B as dataStoreInvoiceHistoryProgressStore, F as dataStoreInvoiceHistoryWorkStore, Fe as dataStoreStores, c as dataStoreSubscriptionWriteStore, de as defaultDunningEmail, tt as diffMeter, nt as diffPortal, rt as diffPrice, it as diffProduct, at as diffRetiredMeter, ot as diffRetiredPrice, st as diffRetiredProduct, ct as diffTaxSettings, lt as diffWebhook, d as dueSteps, f as dunningMailNotifier, Je as emptyPlanRegistry, Ht as envOutRefusal, fe as episodeKeyOf, pe as evaluateBillingEntitlement, Me as evaluateEntitlement, Qe as flushWindowKey, pt as formEncode, me as graceEndOf, xe as inspectBillingAccountCustody, Se as inspectBillingCustody, xt as isProductionBoot, Ie as isStaleStatusEvent, l as isTerminalSubscriptionWrite, v as memoryBillingCloseStore, h as memoryCheckoutOperationStore, he as memoryDunningNoticeStore, Le as memoryStores, Ut as mergeEnvFile, St as mockProvider, Et as mountBillingWebhook, _t as normalizeStripeEvent, Wt as openFindings, ke as paidInvoiceCoverageInTransaction, Gt as parseProvisionArgs, Ve as periodKey, ut as portalParams, Kt as provisionStripeCatalog, mt as redactStripeKeys, Ne as requireEntitled, Pe as requireEntitlement, ge as resolveDunningConfig, Ct as resolveProvider, qt as resolveProvisionKey, Jt as runStripeProvision, Re as selectCurrentSubscription, dt as sellingReadiness, vt as stripeProvider, ht as stripeRest };
|