@voltro/plugin-billing 0.89.2 → 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/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 };