@voltro/plugin-billing 0.90.0 → 0.91.1

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