@voltro/plugin-billing 0.89.2 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +1943 -0
  2. package/README.md +0 -435
  3. package/THIRD-PARTY-NOTICES.md +22 -646
  4. package/dist/catalog.js +169 -70
  5. package/dist/custodyInventory.js +101 -65
  6. package/dist/dunning.js +14 -6
  7. package/dist/eventDelivery.js +14 -5
  8. package/dist/historicalUsage.js +94 -0
  9. package/dist/index.d.ts +777 -68
  10. package/dist/index.js +354 -233
  11. package/dist/invoiceHistoryJournal.js +204 -179
  12. package/dist/invoiceHistoryProgress.js +130 -106
  13. package/dist/invoiceHistoryWork.js +188 -186
  14. package/dist/invoicePaymentEpoch.js +145 -0
  15. package/dist/invoicePaymentObservation.js +64 -0
  16. package/dist/invoiceSnapshot.js +56 -46
  17. package/dist/invoiceStore.js +124 -90
  18. package/dist/paidInvoiceCoverage.js +84 -0
  19. package/dist/plans.js +15 -2
  20. package/dist/providers.js +149 -92
  21. package/dist/provision.js +84 -73
  22. package/dist/rpc.d.ts +53 -13
  23. package/dist/rpc.js +141 -78
  24. package/dist/service.js +1208 -722
  25. package/dist/stores.js +240 -148
  26. package/dist/stripeIdentity.js +17 -17
  27. package/dist/stripeInvoiceHistory.js +21 -21
  28. package/dist/stripeInvoicePayments.js +129 -0
  29. package/dist/stripeInvoiceSnapshot.js +65 -46
  30. package/dist/stripeProvider.js +570 -201
  31. package/dist/stripeRest.js +10 -10
  32. package/dist/subscriptionObservation.js +93 -0
  33. package/dist/subscriptionWriteStore.js +325 -0
  34. package/dist/table.js +75 -66
  35. package/dist/types.d.ts +415 -27
  36. package/dist/types.js +21 -4
  37. package/dist/web/index.d.ts +93 -3
  38. package/dist/web/index.js +76 -33
  39. package/dist/web/writeRequest.js +65 -0
  40. package/package.json +9 -9
package/dist/provision.js CHANGED
@@ -1,81 +1,92 @@
1
- import { diffMeter as e, diffPortal as t, diffPrice as n, diffProduct as r, diffTaxSettings as i, diffWebhook as a, sellingReadiness as o } from "./catalog.js";
2
- import { redactStripeKeys as s, stripeRest as c } from "./stripeRest.js";
3
- import { execFileSync as l } from "node:child_process";
4
- import { chmodSync as u, existsSync as d, readFileSync as f, realpathSync as p, writeFileSync as m } from "node:fs";
5
- import { dirname as h, resolve as g } from "node:path";
1
+ import { diffMeter as e, diffPortal as t, diffPrice as n, diffProduct as r, diffRetiredMeter as i, diffRetiredPrice as a, diffRetiredProduct as o, diffTaxSettings as s, diffWebhook as c, retiredConflicts as l, sellingReadiness as u } from "./catalog.js";
2
+ import { redactStripeKeys as d, stripeRest as f } from "./stripeRest.js";
3
+ import { execFileSync as p } from "node:child_process";
4
+ import { chmodSync as m, existsSync as h, readFileSync as g, realpathSync as _, writeFileSync as v } from "node:fs";
5
+ import { dirname as y, resolve as b } from "node:path";
6
6
  // src/provision.ts
7
- var _ = (e) => e.filter((e) => e.applied !== !0 && (e.kind === "create" || e.kind === "update" || e.kind === "adopt" || e.kind === "drift")), v = async (s, c, l) => {
8
- let u = c.environments[l.env], d = await s.get("/v1/tax/settings"), f = l.env === "live";
9
- if (d.livemode !== f) throw Error(`the key reaches a ${d.livemode ? "LIVE" : "test"} account, not ${l.env}`);
10
- let p = [], m = {}, h = async (e, t) => {
7
+ var x = (e) => e.filter((e) => e.applied !== !0 && (e.kind === "create" || e.kind === "update" || e.kind === "adopt" || e.kind === "drift")), S = async (d, f, p) => {
8
+ let m = f.environments[p.env], h = l(f);
9
+ if (h.length > 0) throw Error(`the catalog both sells and retires: ${h.join(", ")}`);
10
+ let g = await d.get("/v1/tax/settings"), _ = p.env === "live";
11
+ if (g.livemode !== _) throw Error(`the key reaches a ${g.livemode ? "LIVE" : "test"} account, not ${p.env}`);
12
+ let v = [], y = {}, b = async (e, t) => {
11
13
  let n = "apply" in e ? e.apply : void 0;
12
- if (l.apply && n !== void 0) {
13
- let r = await s.post(n.path, n.params);
14
- t?.(r), p.push({
14
+ if (p.apply && n !== void 0) {
15
+ let r = await d.post(n.path, n.params);
16
+ t?.(r), v.push({
15
17
  ...e,
16
18
  applied: !0
17
19
  });
18
- } else p.push(e);
19
- }, g = await s.list("/v1/billing/meters"), _ = /* @__PURE__ */ new Map();
20
- for (let t of c.meters) {
21
- let n = e(t, g);
22
- _.set(t.eventName, n.id), await h(n.finding, (e) => {
23
- _.set(t.eventName, e.id);
20
+ } else v.push(e);
21
+ }, x = await d.list("/v1/billing/meters"), S = /* @__PURE__ */ new Map();
22
+ for (let t of f.meters) {
23
+ let n = e(t, x);
24
+ S.set(t.eventName, n.id), await b(n.finding, (e) => {
25
+ S.set(t.eventName, e.id);
24
26
  });
25
27
  }
26
- let v = await s.list("/v1/products"), y = [];
27
- for (let e of c.products) {
28
- let t = r(e, v), n = {
29
- inPortal: e.inPortal,
28
+ let C = await d.list("/v1/products"), w = [];
29
+ for (let e of f.products) {
30
+ let t = r(e, C), n = {
30
31
  productId: t.id,
31
32
  priceId: null
32
33
  };
33
- await h(t.finding, (e) => {
34
+ await b(t.finding, (e) => {
34
35
  n.productId = e.id;
35
- }), y.push(n);
36
+ }), w.push(n);
36
37
  }
37
- for (let [e, t] of c.products.entries()) {
38
- let r = y[e], i = t.price.meter;
39
- if (t.price.usageType === "metered" && (i === void 0 || !_.has(i))) {
40
- p.push({
38
+ for (let [e, t] of f.products.entries()) {
39
+ let r = w[e], i = t.price.meter;
40
+ if (t.price.usageType === "metered" && (i === void 0 || !S.has(i))) {
41
+ v.push({
41
42
  kind: "manual",
42
43
  object: `price ${t.price.lookupKey}`,
43
44
  detail: `metered, but names no catalog meter (${i ?? "none"})`
44
45
  });
45
46
  continue;
46
47
  }
47
- let a = i === void 0 ? null : _.get(i) ?? null, o = r.productId ?? (l.apply ? null : `pending:${t.key}`), c = a ?? (l.apply || t.price.usageType !== "metered" ? a : `pending:${i}`), u = (await s.list("/v1/prices", { lookup_keys: [t.price.lookupKey] }))[0] ?? null, d = r.productId === null ? [] : await s.list("/v1/prices", { product: r.productId }), f = n(t.price, o, c, u, d, l.allowPriceChange);
48
- r.priceId = f.id, await h(f.finding, (e) => {
48
+ let a = i === void 0 ? null : S.get(i) ?? null, o = r.productId ?? (p.apply ? null : `pending:${t.key}`), s = a ?? (p.apply || t.price.usageType !== "metered" ? a : `pending:${i}`), c = (await d.list("/v1/prices", {
49
+ lookup_keys: [t.price.lookupKey],
50
+ expand: ["data.tiers"]
51
+ }))[0] ?? null, l = r.productId === null ? [] : await d.list("/v1/prices", {
52
+ product: r.productId,
53
+ expand: ["data.tiers"]
54
+ }), u = n(t.price, o, s, c, l, p.allowPriceChange);
55
+ r.priceId = u.id, await b(u.finding, (e) => {
49
56
  r.priceId = e.id;
50
- }), r.priceId !== null && (m[t.price.envName] = r.priceId);
57
+ }), r.priceId !== null && (y[t.price.envName] = r.priceId);
51
58
  }
52
- await h(i(c.tax, d));
53
- let b = y.filter((e) => e.inPortal), x = b.every((e) => e.productId !== null && e.priceId !== null) ? b.map((e) => ({
54
- productId: e.productId,
55
- priceId: e.priceId
56
- })) : null, S = await s.list("/v1/billing_portal/configurations", { expand: ["data.features.subscription_update.products"] });
57
- for (let e of t(c.portal, u, x, S)) await h(e);
58
- let C = a(u, await s.list("/v1/webhook_endpoints"));
59
- C.kind === "create" && l.apply && l.envOut === null ? p.push({
59
+ let T = f.retired ?? {}, E = T.prices ?? [];
60
+ for (let e = 0; e < E.length; e += 10) {
61
+ let t = E.slice(e, e + 10), n = await d.list("/v1/prices", { lookup_keys: t });
62
+ for (let e of t) await b(a(e, n));
63
+ }
64
+ for (let e of T.products ?? []) await b(o(e, C));
65
+ for (let e of T.meters ?? []) await b(i(e, x));
66
+ await b(s(f.tax, g));
67
+ let D = await d.list("/v1/billing_portal/configurations");
68
+ for (let e of t(f.portal, m, D)) await b(e);
69
+ let O = c(m, await d.list("/v1/webhook_endpoints"));
70
+ O.kind === "create" && p.apply && p.envOut === null ? v.push({
60
71
  kind: "manual",
61
- object: C.object,
72
+ object: O.object,
62
73
  detail: "not created: pass --env-out so its signing secret is captured (Stripe shows it once)"
63
- }) : await h(C, (e) => {
64
- typeof e.secret == "string" && (m.STRIPE_WEBHOOK_SECRET = e.secret);
74
+ }) : await b(O, (e) => {
75
+ typeof e.secret == "string" && (y.STRIPE_WEBHOOK_SECRET = e.secret);
65
76
  });
66
- let w = await s.get("/v1/account").catch(() => null), T = await s.list("/v1/tax_ids", { owner: { type: "account" } }).catch(() => null), E = await s.list("/v1/tax/registrations", { status: "active" }).catch(() => []);
67
- return p.push(...o({
68
- catalog: c,
69
- env: u,
70
- chargesEnabled: w === null ? null : w.charges_enabled === !0,
71
- accountTaxIds: T === null ? null : T.length,
72
- activeRegistrations: E.map((e) => e.country)
77
+ let k = await d.get("/v1/account").catch(() => null), A = await d.list("/v1/tax_ids", { owner: { type: "account" } }).catch(() => null), j = await d.list("/v1/tax/registrations", { status: "active" }).catch(() => []);
78
+ return v.push(...u({
79
+ catalog: f,
80
+ env: m,
81
+ chargesEnabled: k === null ? null : k.charges_enabled === !0,
82
+ accountTaxIds: A === null ? null : A.length,
83
+ activeRegistrations: j.map((e) => e.country)
73
84
  })), {
74
- livemode: d.livemode,
75
- findings: p,
76
- envOut: m
85
+ livemode: g.livemode,
86
+ findings: v,
87
+ envOut: y
77
88
  };
78
- }, y = (e, t) => {
89
+ }, C = (e, t) => {
79
90
  let n = new Set(Object.keys(t)), r = e.split("\n").filter((e) => !n.has(e.split("=")[0] ?? ""));
80
91
  for (; r.length > 0 && r[r.length - 1] === "";) r.pop();
81
92
  return [
@@ -83,18 +94,18 @@ var _ = (e) => e.filter((e) => e.applied !== !0 && (e.kind === "create" || e.kin
83
94
  ...Object.entries(t).map(([e, t]) => `${e}=${t}`),
84
95
  ""
85
96
  ].join("\n");
86
- }, b = (e, t) => {
97
+ }, w = (e, t) => {
87
98
  try {
88
- return l("git", [...e], {
99
+ return p("git", [...e], {
89
100
  cwd: t,
90
101
  stdio: "ignore"
91
102
  }), !0;
92
103
  } catch {
93
104
  return !1;
94
105
  }
95
- }, x = (e, t = b, n = (e) => d(e) ? p(e) : e) => {
96
- for (let r of /* @__PURE__ */ new Set([g(e), g(n(g(e)))])) {
97
- let n = h(r);
106
+ }, T = (e, t = w, n = (e) => h(e) ? _(e) : e) => {
107
+ for (let r of /* @__PURE__ */ new Set([b(e), b(n(b(e)))])) {
108
+ let n = y(r);
98
109
  if (t(["rev-parse", "--is-inside-work-tree"], n) && !t([
99
110
  "check-ignore",
100
111
  "-q",
@@ -102,7 +113,7 @@ var _ = (e) => e.filter((e) => e.applied !== !0 && (e.kind === "create" || e.kin
102
113
  ], n)) return `${e} is inside a git work tree and not ignored — write it to a gitignored file or outside the repo`;
103
114
  }
104
115
  return null;
105
- }, S = (e) => {
116
+ }, E = (e) => {
106
117
  let t = (t) => {
107
118
  let n = e.indexOf(t);
108
119
  return n < 0 ? null : e[n + 1];
@@ -119,34 +130,34 @@ var _ = (e) => e.filter((e) => e.applied !== !0 && (e.kind === "create" || e.kin
119
130
  envOut: r
120
131
  };
121
132
  return i.env === "live" && i.apply && !i.confirmLive ? "writing to LIVE needs --confirm-live (run without --apply first to see the plan)" : i;
122
- }, C = (e, t, n) => {
133
+ }, D = (e, t, n) => {
123
134
  let r = t.STRIPE_PROVISION_KEY?.trim() || (e === "sandbox" ? n?.trim() : void 0);
124
135
  return r === void 0 || r.length === 0 ? { refusal: "set STRIPE_PROVISION_KEY (a sandbox run also reads STRIPE_SECRET_KEY from the dotenv file)" } : e === "live" && !/^(sk|rk)_live_/.test(r) ? { refusal: "--env live needs a live key (sk_live_/rk_live_)" } : e === "sandbox" && !/^(sk|rk)_test_/.test(r) ? { refusal: "--env sandbox needs a test key (sk_test_/rk_test_)" } : { key: r };
125
- }, w = (e, t) => d(e) ? f(e, "utf8").split("\n").find((e) => e.startsWith(`${t}=`))?.slice(t.length + 1).trim() : void 0, T = async (e, t, n = {}) => {
126
- let r = n.vars ?? process.env, i = (e) => (console.error(`stripe provision: ${e}`), 2), a = S(t);
136
+ }, O = (e, t) => h(e) ? g(e, "utf8").split("\n").find((e) => e.startsWith(`${t}=`))?.slice(t.length + 1).trim() : void 0, k = async (e, t, n = {}) => {
137
+ let r = n.vars ?? process.env, i = (e) => (console.error(`stripe provision: ${e}`), 2), a = E(t);
127
138
  if (typeof a == "string") return i(a);
128
139
  if (a.envOut !== null) {
129
- let e = x(a.envOut);
140
+ let e = T(a.envOut);
130
141
  if (e !== null) return i(e);
131
142
  }
132
- let o = C(a.env, r, n.dotenv === void 0 ? void 0 : w(n.dotenv, "STRIPE_SECRET_KEY"));
143
+ let o = D(a.env, r, n.dotenv === void 0 ? void 0 : O(n.dotenv, "STRIPE_SECRET_KEY"));
133
144
  if ("refusal" in o) return i(o.refusal);
134
- let l;
145
+ let s;
135
146
  try {
136
- l = await v((n.rest ?? c)(o.key), e, a);
147
+ s = await S((n.rest ?? f)(o.key), e, a);
137
148
  } catch (e) {
138
- return console.error(`stripe provision: ${s(e instanceof Error ? e.message : String(e))}`), 1;
149
+ return console.error(`stripe provision: ${d(e instanceof Error ? e.message : String(e))}`), 1;
139
150
  }
140
- console.log(`Stripe ${a.env} (${l.livemode ? "LIVE" : "test mode"}) — ${a.apply ? "apply" : "check"}`);
141
- for (let e of l.findings) {
151
+ console.log(`Stripe ${a.env} (${s.livemode ? "LIVE" : "test mode"}) — ${a.apply ? "apply" : "check"}`);
152
+ for (let e of s.findings) {
142
153
  let t = e.applied === !0 ? `${e.kind} ✓` : e.kind;
143
154
  console.log(` ${t.padEnd(10)} ${e.object}${"detail" in e ? ` — ${e.detail}` : ""}`);
144
155
  }
145
156
  if (a.envOut !== null) {
146
157
  let e = a.envOut;
147
- m(e, y(d(e) ? f(e, "utf8") : "", l.envOut), { mode: 384 }), u(e, 384), console.log(` wrote ${Object.keys(l.envOut).sort().join(", ")} to ${e}`);
158
+ v(e, C(h(e) ? g(e, "utf8") : "", s.envOut), { mode: 384 }), m(e, 384), console.log(` wrote ${Object.keys(s.envOut).sort().join(", ")} to ${e}`);
148
159
  }
149
- let p = _(l.findings), h = l.findings.filter((e) => e.kind === "manual");
150
- return console.log(` ${p.length} open, ${h.length} manual`), p.length > 0 || a.strict && h.length > 0 ? 1 : 0;
160
+ let c = x(s.findings), l = s.findings.filter((e) => e.kind === "manual");
161
+ return console.log(` ${c.length} open, ${l.length} manual`), c.length > 0 || a.strict && l.length > 0 ? 1 : 0;
151
162
  };
152
- export { x as envOutRefusal, y as mergeEnvFile, _ as openFindings, S as parseProvisionArgs, v as provisionStripeCatalog, C as resolveProvisionKey, T as runStripeProvision };
163
+ export { T as envOutRefusal, C as mergeEnvFile, x as openFindings, E as parseProvisionArgs, S as provisionStripeCatalog, D as resolveProvisionKey, k as runStripeProvision };
package/dist/rpc.d.ts CHANGED
@@ -22,13 +22,33 @@ declare const BillingError_base: Schema.Class<BillingError, Schema.TaggedStruct<
22
22
  readonly transient: Schema.Boolean;
23
23
  }>, YieldableError>;
24
24
 
25
+ /**
26
+ * Raised when a subscription write reuses a `requestId` that can no longer
27
+ * execute. `superseded`: the request completed, but a later write on the same
28
+ * tenant followed it, so its old receipt is not an answer for a new intention.
29
+ * `withdrawn`: it was positively never dispatched and was withdrawn.
30
+ * `rejected`: the provider definitively refused it. A true retry of a lost
31
+ * response (no later write) still answers idempotently. Mint a fresh
32
+ * `requestId` for a new intention; the `/web` request helper does this.
33
+ */
34
+ declare class BillingRequestStale extends BillingRequestStale_base {
35
+ }
36
+
37
+ declare const BillingRequestStale_base: Schema.Class<BillingRequestStale, Schema.TaggedStruct<"BillingRequestStale", {
38
+ readonly requestId: Schema.String;
39
+ readonly reason: Schema.Literals<readonly ["superseded", "withdrawn", "rejected"]>;
40
+ readonly message: Schema.String;
41
+ }>, YieldableError>;
42
+
25
43
  /** Declared for the codegen (`VoltroPlugin.rpcClientDescriptors`) so each tag is
26
44
  * emitted into the generated client group. Kept in lockstep with the exports. */
27
45
  export declare const billingRpcClientImports: ReadonlyArray<PluginRpcClientDescriptor>;
28
46
 
29
47
  /** The customer's own cancellation: active until the paid period ends, then
30
48
  * ended. `cancelAt` on the answer is when. */
31
- export declare const cancelSubscriptionDescriptor: ActionProcedureDescriptor<"billing.cancel", Schema.Struct<{}>, Schema.Struct<{
49
+ export declare const cancelSubscriptionDescriptor: ActionProcedureDescriptor<"billing.cancel", Schema.Struct<{
50
+ readonly requestId: Schema.NonEmptyString;
51
+ }>, Schema.Struct<{
32
52
  readonly subscription: Schema.Struct<{
33
53
  readonly plan: Schema.String;
34
54
  readonly status: Schema.String;
@@ -36,27 +56,27 @@ export declare const cancelSubscriptionDescriptor: ActionProcedureDescriptor<"bi
36
56
  readonly currentPeriodEnd: Schema.NullOr<Schema.String>;
37
57
  readonly cancelAt: Schema.NullOr<Schema.String>;
38
58
  }>;
39
- }>, typeof BillingError>;
59
+ }>, Schema.Union<readonly [typeof BillingError, typeof BillingRequestStale]>>;
40
60
 
41
61
  export declare const changePlanDescriptor: ActionProcedureDescriptor<"billing.changePlan", Schema.Struct<{
42
62
  readonly plan: Schema.String;
63
+ readonly requestId: Schema.NonEmptyString;
43
64
  }>, Schema.Struct<{
44
65
  readonly plan: Schema.String;
45
66
  readonly quantity: Schema.Number;
46
- /** Integer minor-unit settlement: > 0 charge, < 0 credit, 0 at boundary. */
47
- readonly prorationMinor: Schema.Number;
67
+ readonly prorationMinor: Schema.NullOr<Schema.Number>;
48
68
  readonly currency: Schema.String;
49
- }>, typeof BillingError>;
69
+ }>, Schema.Union<readonly [typeof BillingError, typeof BillingRequestStale]>>;
50
70
 
51
71
  export declare const changeSeatsDescriptor: ActionProcedureDescriptor<"billing.changeSeats", Schema.Struct<{
52
72
  readonly quantity: Schema.Number;
73
+ readonly requestId: Schema.NonEmptyString;
53
74
  }>, Schema.Struct<{
54
75
  readonly plan: Schema.String;
55
76
  readonly quantity: Schema.Number;
56
- /** Integer minor-unit settlement: > 0 charge, < 0 credit, 0 at boundary. */
57
- readonly prorationMinor: Schema.Number;
77
+ readonly prorationMinor: Schema.NullOr<Schema.Number>;
58
78
  readonly currency: Schema.String;
59
- }>, typeof BillingError>;
79
+ }>, Schema.Union<readonly [typeof BillingError, typeof BillingRequestStale]>>;
60
80
 
61
81
  /**
62
82
  * "Is this tenant entitled right now?" — the dunning-aware answer a billing
@@ -90,6 +110,27 @@ export declare const invoicesDescriptor: QueryProcedureDescriptor<"billing.invoi
90
110
  }>>;
91
111
  }>, typeof BillingError>;
92
112
 
113
+ /** Native operation status; not-found is never proof of non-execution. */
114
+ export declare const operationStatusDescriptor: ActionProcedureDescriptor<"billing.operationStatus", Schema.Struct<{
115
+ readonly requestId: Schema.NonEmptyString;
116
+ }>, Schema.Struct<{
117
+ readonly phase: Schema.Literals<readonly ["not-found", "prepared", "claimed", "dispatched", "acknowledged", "completed", "withdrawn", "rejected"]>;
118
+ }>, typeof BillingError>;
119
+
120
+ /** The tenant's outstanding subscription write, so another tab or device can
121
+ * find it: re-send the same intention under `requestId` to resume it, or call
122
+ * `billing.sync` to reconcile. Guarded: the id drives a write. Live on the
123
+ * journal tables. */
124
+ export declare const pendingOperationDescriptor: QueryProcedureDescriptor<"billing.pendingOperation", Schema.Struct<{}>, Schema.Struct<{
125
+ readonly operation: Schema.NullOr<Schema.Struct<{
126
+ readonly requestId: Schema.String;
127
+ readonly kind: Schema.Literals<readonly ["change", "cancel", "resume"]>;
128
+ readonly plan: Schema.NullOr<Schema.String>;
129
+ readonly quantity: Schema.NullOr<Schema.Number>;
130
+ readonly phase: Schema.Literals<readonly ["prepared", "claimed", "dispatched", "acknowledged"]>;
131
+ }>>;
132
+ }>, typeof BillingError>;
133
+
93
134
  export declare const portalUrlDescriptor: ActionProcedureDescriptor<"billing.portalUrl", Schema.Struct<{
94
135
  readonly returnUrl: Schema.String;
95
136
  }>, Schema.Struct<{
@@ -118,7 +159,9 @@ export declare const reportUsageDescriptor: ActionProcedureDescriptor<"billing.r
118
159
  }>, typeof BillingError>;
119
160
 
120
161
  /** Take back a cancellation before the period ends. */
121
- export declare const resumeSubscriptionDescriptor: ActionProcedureDescriptor<"billing.resume", Schema.Struct<{}>, Schema.Struct<{
162
+ export declare const resumeSubscriptionDescriptor: ActionProcedureDescriptor<"billing.resume", Schema.Struct<{
163
+ readonly requestId: Schema.NonEmptyString;
164
+ }>, Schema.Struct<{
122
165
  readonly subscription: Schema.Struct<{
123
166
  readonly plan: Schema.String;
124
167
  readonly status: Schema.String;
@@ -126,7 +169,7 @@ export declare const resumeSubscriptionDescriptor: ActionProcedureDescriptor<"bi
126
169
  readonly currentPeriodEnd: Schema.NullOr<Schema.String>;
127
170
  readonly cancelAt: Schema.NullOr<Schema.String>;
128
171
  }>;
129
- }>, typeof BillingError>;
172
+ }>, Schema.Union<readonly [typeof BillingError, typeof BillingRequestStale]>>;
130
173
 
131
174
  export declare const startCheckoutDescriptor: ActionProcedureDescriptor<"billing.startCheckout", Schema.Struct<{
132
175
  readonly plan: Schema.String;
@@ -148,9 +191,6 @@ export declare const subscriptionDescriptor: QueryProcedureDescriptor<"billing.s
148
191
  }>>;
149
192
  }>, typeof BillingError>;
150
193
 
151
- /** The checkpoint: sync the caller's tenant from the provider and answer with
152
- * its current subscription. Call it on the return from checkout or the
153
- * portal, and when a billing page loads. */
154
194
  export declare const syncDescriptor: ActionProcedureDescriptor<"billing.sync", Schema.Struct<{}>, Schema.Struct<{
155
195
  readonly subscription: Schema.NullOr<Schema.Struct<{
156
196
  readonly plan: Schema.String;
package/dist/rpc.js CHANGED
@@ -1,119 +1,166 @@
1
- import { BillingError as e } from "./types.js";
2
- import { Schema as t } from "effect";
3
- import { defineAction as n, defineQuery as r } from "@voltro/protocol";
1
+ import { BillingError as e, BillingRequestStale as t } from "./types.js";
2
+ import { Schema as n } from "effect";
3
+ import { defineAction as r, defineQuery as i } from "@voltro/protocol";
4
4
  // src/rpc.ts
5
- var i = n({
5
+ var a = r({
6
6
  name: "billing.startCheckout",
7
- input: t.Struct({
8
- plan: t.String,
9
- successUrl: t.String,
10
- cancelUrl: t.String,
11
- quantity: t.optional(t.Number)
7
+ input: n.Struct({
8
+ plan: n.String,
9
+ successUrl: n.String,
10
+ cancelUrl: n.String,
11
+ quantity: n.optional(n.Number)
12
12
  }),
13
- output: t.Struct({ url: t.String }),
13
+ output: n.Struct({ url: n.String }),
14
14
  error: e,
15
15
  guards: [{ scope: "billing:manage" }]
16
- }), a = n({
16
+ }), o = r({
17
17
  name: "billing.portalUrl",
18
- input: t.Struct({ returnUrl: t.String }),
19
- output: t.Struct({ url: t.String }),
18
+ input: n.Struct({ returnUrl: n.String }),
19
+ output: n.Struct({ url: n.String }),
20
20
  error: e,
21
21
  guards: [{ scope: "billing:manage" }]
22
- }), o = t.Struct({
23
- plan: t.String,
24
- status: t.String,
25
- quantity: t.Number,
26
- currentPeriodEnd: t.NullOr(t.String),
27
- cancelAt: t.NullOr(t.String)
28
- }), s = r({
22
+ }), s = n.Struct({
23
+ plan: n.String,
24
+ status: n.String,
25
+ quantity: n.Number,
26
+ currentPeriodEnd: n.NullOr(n.String),
27
+ cancelAt: n.NullOr(n.String)
28
+ }), c = i({
29
29
  name: "billing.subscription",
30
- input: t.Struct({}),
31
- output: t.Struct({ subscription: t.NullOr(o) }),
30
+ input: n.Struct({}),
31
+ output: n.Struct({ subscription: n.NullOr(s) }),
32
32
  error: e,
33
33
  openAccess: "tenant-scoped read of the caller's own tenant's plan/seat state for account UI every member renders; carries no payment credentials"
34
- }), c = r({
34
+ }), l = i({
35
35
  name: "billing.entitlementStatus",
36
- input: t.Struct({}),
37
- output: t.Struct({
38
- plan: t.String,
39
- billedPlan: t.String,
40
- status: t.String,
41
- entitled: t.Boolean,
42
- inGrace: t.Boolean,
43
- graceEndsAt: t.NullOr(t.String),
44
- lockedSince: t.NullOr(t.String),
45
- lockout: t.String
36
+ input: n.Struct({}),
37
+ output: n.Struct({
38
+ plan: n.String,
39
+ billedPlan: n.String,
40
+ status: n.String,
41
+ entitled: n.Boolean,
42
+ inGrace: n.Boolean,
43
+ graceEndsAt: n.NullOr(n.String),
44
+ lockedSince: n.NullOr(n.String),
45
+ lockout: n.String
46
46
  }),
47
47
  error: e,
48
48
  openAccess: "tenant-scoped read of the caller's own tenant's entitlement/grace state — the banner every signed-in member renders on payment failure"
49
- }), l = n({
49
+ }), u = r({
50
50
  name: "billing.reportUsage",
51
- input: t.Struct({
52
- key: t.String,
53
- quantity: t.Number
51
+ input: n.Struct({
52
+ key: n.String,
53
+ quantity: n.Number
54
54
  }),
55
- output: t.Struct({ ok: t.Boolean }),
55
+ output: n.Struct({ ok: n.Boolean }),
56
56
  error: e,
57
57
  guards: [{ scope: "billing:report" }]
58
- }), u = t.Struct({
59
- plan: t.String,
60
- quantity: t.Number,
61
- prorationMinor: t.Number,
62
- currency: t.String
63
- }), d = n({
58
+ }), d = n.Struct({
59
+ plan: n.String,
60
+ quantity: n.Number,
61
+ prorationMinor: n.Number,
62
+ currency: n.String
63
+ }), f = n.Union([e, t]), p = n.Struct({
64
+ plan: n.String,
65
+ quantity: n.Number,
66
+ prorationMinor: n.NullOr(n.Number),
67
+ currency: n.String
68
+ }), m = r({
64
69
  name: "billing.previewChange",
65
- input: t.Struct({
66
- plan: t.optional(t.String),
67
- quantity: t.optional(t.Number)
70
+ input: n.Struct({
71
+ plan: n.optional(n.String),
72
+ quantity: n.optional(n.Number)
68
73
  }),
69
- output: u,
74
+ output: d,
70
75
  error: e,
71
76
  guards: [{ scope: "billing:manage" }]
72
- }), f = r({
77
+ }), h = i({
73
78
  name: "billing.invoices",
74
- input: t.Struct({}),
75
- output: t.Struct({ invoices: t.Array(t.Struct({
76
- providerInvoiceId: t.String,
77
- amountMinor: t.Number,
78
- currency: t.String,
79
- status: t.String,
80
- createdAt: t.NullOr(t.String),
81
- hostedUrl: t.NullOr(t.String),
82
- pdfUrl: t.NullOr(t.String)
79
+ input: n.Struct({}),
80
+ output: n.Struct({ invoices: n.Array(n.Struct({
81
+ providerInvoiceId: n.String,
82
+ amountMinor: n.Number,
83
+ currency: n.String,
84
+ status: n.String,
85
+ createdAt: n.NullOr(n.String),
86
+ hostedUrl: n.NullOr(n.String),
87
+ pdfUrl: n.NullOr(n.String)
83
88
  })) }),
84
89
  error: e,
85
90
  guards: [{ scope: "billing:manage" }]
86
- }), p = n({
91
+ }), g = r({
87
92
  name: "billing.changePlan",
88
- input: t.Struct({ plan: t.String }),
89
- output: u,
90
- error: e,
93
+ input: n.Struct({
94
+ plan: n.String,
95
+ requestId: n.NonEmptyString
96
+ }),
97
+ output: p,
98
+ error: f,
91
99
  guards: [{ scope: "billing:manage" }]
92
- }), m = n({
100
+ }), _ = r({
93
101
  name: "billing.changeSeats",
94
- input: t.Struct({ quantity: t.Number }),
95
- output: u,
96
- error: e,
102
+ input: n.Struct({
103
+ quantity: n.Number,
104
+ requestId: n.NonEmptyString
105
+ }),
106
+ output: p,
107
+ error: f,
97
108
  guards: [{ scope: "billing:manage" }]
98
- }), h = n({
109
+ }), v = r({
99
110
  name: "billing.cancel",
100
- input: t.Struct({}),
101
- output: t.Struct({ subscription: o }),
111
+ input: n.Struct({ requestId: n.NonEmptyString }),
112
+ output: n.Struct({ subscription: s }),
113
+ error: f,
114
+ guards: [{ scope: "billing:manage" }]
115
+ }), y = r({
116
+ name: "billing.operationStatus",
117
+ input: n.Struct({ requestId: n.NonEmptyString }),
118
+ output: n.Struct({ phase: n.Literals([
119
+ "not-found",
120
+ "prepared",
121
+ "claimed",
122
+ "dispatched",
123
+ "acknowledged",
124
+ "completed",
125
+ "withdrawn",
126
+ "rejected"
127
+ ]) }),
102
128
  error: e,
103
129
  guards: [{ scope: "billing:manage" }]
104
- }), g = n({
130
+ }), b = i({
131
+ name: "billing.pendingOperation",
132
+ input: n.Struct({}),
133
+ output: n.Struct({ operation: n.NullOr(n.Struct({
134
+ requestId: n.String,
135
+ kind: n.Literals([
136
+ "change",
137
+ "cancel",
138
+ "resume"
139
+ ]),
140
+ plan: n.NullOr(n.String),
141
+ quantity: n.NullOr(n.Number),
142
+ phase: n.Literals([
143
+ "prepared",
144
+ "claimed",
145
+ "dispatched",
146
+ "acknowledged"
147
+ ])
148
+ })) }),
149
+ error: e,
150
+ guards: [{ scope: "billing:manage" }]
151
+ }), x = r({
105
152
  name: "billing.sync",
106
- input: t.Struct({}),
107
- output: t.Struct({ subscription: t.NullOr(o) }),
153
+ input: n.Struct({}),
154
+ output: n.Struct({ subscription: n.NullOr(s) }),
108
155
  error: e,
109
156
  guards: [{ scope: "billing:manage" }]
110
- }), _ = n({
157
+ }), S = r({
111
158
  name: "billing.resume",
112
- input: t.Struct({}),
113
- output: t.Struct({ subscription: o }),
114
- error: e,
159
+ input: n.Struct({ requestId: n.NonEmptyString }),
160
+ output: n.Struct({ subscription: s }),
161
+ error: f,
115
162
  guards: [{ scope: "billing:manage" }]
116
- }), v = [
163
+ }), C = [
117
164
  {
118
165
  tag: "billing.startCheckout",
119
166
  kind: "action",
@@ -170,6 +217,22 @@ var i = n({
170
217
  name: "changeSeatsDescriptor"
171
218
  }
172
219
  },
220
+ {
221
+ tag: "billing.operationStatus",
222
+ kind: "action",
223
+ import: {
224
+ module: "@voltro/plugin-billing/rpc",
225
+ name: "operationStatusDescriptor"
226
+ }
227
+ },
228
+ {
229
+ tag: "billing.pendingOperation",
230
+ kind: "query",
231
+ import: {
232
+ module: "@voltro/plugin-billing/rpc",
233
+ name: "pendingOperationDescriptor"
234
+ }
235
+ },
173
236
  {
174
237
  tag: "billing.cancel",
175
238
  kind: "action",
@@ -211,4 +274,4 @@ var i = n({
211
274
  }
212
275
  }
213
276
  ];
214
- export { v as billingRpcClientImports, h as cancelSubscriptionDescriptor, p as changePlanDescriptor, m as changeSeatsDescriptor, c as entitlementStatusDescriptor, f as invoicesDescriptor, a as portalUrlDescriptor, d as previewChangeDescriptor, l as reportUsageDescriptor, _ as resumeSubscriptionDescriptor, i as startCheckoutDescriptor, s as subscriptionDescriptor, g as syncDescriptor };
277
+ export { C as billingRpcClientImports, v as cancelSubscriptionDescriptor, g as changePlanDescriptor, _ as changeSeatsDescriptor, l as entitlementStatusDescriptor, h as invoicesDescriptor, y as operationStatusDescriptor, b as pendingOperationDescriptor, o as portalUrlDescriptor, m as previewChangeDescriptor, u as reportUsageDescriptor, S as resumeSubscriptionDescriptor, a as startCheckoutDescriptor, c as subscriptionDescriptor, x as syncDescriptor };