@qcobro/common 1.13.0 → 1.14.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/billing/evaluate.d.ts +36 -0
- package/dist/billing/evaluate.d.ts.map +1 -0
- package/dist/billing/evaluate.js +136 -0
- package/dist/billing/evaluate.js.map +1 -0
- package/dist/billing/index.d.ts +7 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +7 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing/ledger.d.ts +70 -0
- package/dist/billing/ledger.d.ts.map +1 -0
- package/dist/billing/ledger.js +59 -0
- package/dist/billing/ledger.js.map +1 -0
- package/dist/billing/money.d.ts +26 -0
- package/dist/billing/money.d.ts.map +1 -0
- package/dist/billing/money.js +58 -0
- package/dist/billing/money.js.map +1 -0
- package/dist/billing/pricing.d.ts +58 -0
- package/dist/billing/pricing.d.ts.map +1 -0
- package/dist/billing/pricing.js +68 -0
- package/dist/billing/pricing.js.map +1 -0
- package/dist/billing/proration.d.ts +8 -0
- package/dist/billing/proration.d.ts.map +1 -0
- package/dist/billing/proration.js +17 -0
- package/dist/billing/proration.js.map +1 -0
- package/dist/billing/rates.d.ts +108 -0
- package/dist/billing/rates.d.ts.map +1 -0
- package/dist/billing/rates.js +56 -0
- package/dist/billing/rates.js.map +1 -0
- package/dist/config.d.ts +139 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +62 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas/billing.d.ts +74 -0
- package/dist/schemas/billing.d.ts.map +1 -0
- package/dist/schemas/billing.js +68 -0
- package/dist/schemas/billing.js.map +1 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/types/billing.d.ts +134 -0
- package/dist/types/billing.d.ts.map +1 -0
- package/dist/types/billing.js +8 -0
- package/dist/types/billing.js.map +1 -0
- package/dist/types/engine.d.ts +8 -2
- package/dist/types/engine.d.ts.map +1 -1
- package/dist/types/engine.js +12 -1
- package/dist/types/engine.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The billable-meter catalog and per-meter rate schemas.
|
|
4
|
+
*
|
|
5
|
+
* The catalog is closed-world: exactly seven meters, one per dispatchable
|
|
6
|
+
* channel/mode. Message meters bill per message; voice meters bill answered
|
|
7
|
+
* duration under a telecom increment pair. Each meter kind has its own strict
|
|
8
|
+
* schema so a rate object with fields from the wrong kind (e.g. `increments`
|
|
9
|
+
* on `sms`) fails validation instead of being silently ignored.
|
|
10
|
+
*
|
|
11
|
+
* The two WhatsApp voice meters are reserved: they must be priced in every
|
|
12
|
+
* plan, but no dispatch path produces them until Fonoster ships that transport.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MESSAGE_METERS: readonly ["sms", "email", "whatsappMessage"];
|
|
15
|
+
export declare const VOICE_METERS: readonly ["voicePrerecorded", "voiceAi", "whatsappVoicePrerecorded", "whatsappVoiceAi"];
|
|
16
|
+
export declare const BILLING_METERS: readonly ["sms", "email", "whatsappMessage", "voicePrerecorded", "voiceAi", "whatsappVoicePrerecorded", "whatsappVoiceAi"];
|
|
17
|
+
export type MessageMeter = (typeof MESSAGE_METERS)[number];
|
|
18
|
+
export type VoiceMeter = (typeof VOICE_METERS)[number];
|
|
19
|
+
export type BillingMeter = (typeof BILLING_METERS)[number];
|
|
20
|
+
export declare const billingMeterSchema: z.ZodEnum<{
|
|
21
|
+
sms: "sms";
|
|
22
|
+
email: "email";
|
|
23
|
+
whatsappMessage: "whatsappMessage";
|
|
24
|
+
voicePrerecorded: "voicePrerecorded";
|
|
25
|
+
voiceAi: "voiceAi";
|
|
26
|
+
whatsappVoicePrerecorded: "whatsappVoicePrerecorded";
|
|
27
|
+
whatsappVoiceAi: "whatsappVoiceAi";
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Telecom billing-increment notation `"initial/subsequent"` in seconds — the
|
|
31
|
+
* industry standard (15/15 rounds every call up to 15s blocks; 60/6 bills a
|
|
32
|
+
* full first minute then 6s steps).
|
|
33
|
+
*/
|
|
34
|
+
export declare const incrementNotationSchema: z.ZodString;
|
|
35
|
+
/** A message meter's rate: decimal currency units per message. */
|
|
36
|
+
export declare const messageRateSchema: z.ZodObject<{
|
|
37
|
+
perMessage: z.ZodNumber;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type MessageRate = z.infer<typeof messageRateSchema>;
|
|
40
|
+
/** A voice meter's rate: decimal currency units per minute + increment pair. */
|
|
41
|
+
export declare const voiceRateSchema: z.ZodObject<{
|
|
42
|
+
perMinute: z.ZodNumber;
|
|
43
|
+
increments: z.ZodString;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
export type VoiceRate = z.infer<typeof voiceRateSchema>;
|
|
46
|
+
/** A complete rate card: all seven meters, each with its kind's schema. */
|
|
47
|
+
export declare const ratesSchema: z.ZodObject<{
|
|
48
|
+
sms: z.ZodObject<{
|
|
49
|
+
perMessage: z.ZodNumber;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
email: z.ZodObject<{
|
|
52
|
+
perMessage: z.ZodNumber;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
whatsappMessage: z.ZodObject<{
|
|
55
|
+
perMessage: z.ZodNumber;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
voicePrerecorded: z.ZodObject<{
|
|
58
|
+
perMinute: z.ZodNumber;
|
|
59
|
+
increments: z.ZodString;
|
|
60
|
+
}, z.core.$strict>;
|
|
61
|
+
voiceAi: z.ZodObject<{
|
|
62
|
+
perMinute: z.ZodNumber;
|
|
63
|
+
increments: z.ZodString;
|
|
64
|
+
}, z.core.$strict>;
|
|
65
|
+
whatsappVoicePrerecorded: z.ZodObject<{
|
|
66
|
+
perMinute: z.ZodNumber;
|
|
67
|
+
increments: z.ZodString;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
whatsappVoiceAi: z.ZodObject<{
|
|
70
|
+
perMinute: z.ZodNumber;
|
|
71
|
+
increments: z.ZodString;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
export type Rates = z.infer<typeof ratesSchema>;
|
|
75
|
+
/**
|
|
76
|
+
* Per-workspace enterprise overrides: any subset of the rate card, validated
|
|
77
|
+
* with the same per-meter schemas. Stored on workspace billing state (DB),
|
|
78
|
+
* never in configuration.
|
|
79
|
+
*/
|
|
80
|
+
export declare const rateOverridesSchema: z.ZodObject<{
|
|
81
|
+
sms: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
perMessage: z.ZodNumber;
|
|
83
|
+
}, z.core.$strict>>;
|
|
84
|
+
email: z.ZodOptional<z.ZodObject<{
|
|
85
|
+
perMessage: z.ZodNumber;
|
|
86
|
+
}, z.core.$strict>>;
|
|
87
|
+
whatsappMessage: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
perMessage: z.ZodNumber;
|
|
89
|
+
}, z.core.$strict>>;
|
|
90
|
+
voicePrerecorded: z.ZodOptional<z.ZodObject<{
|
|
91
|
+
perMinute: z.ZodNumber;
|
|
92
|
+
increments: z.ZodString;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
voiceAi: z.ZodOptional<z.ZodObject<{
|
|
95
|
+
perMinute: z.ZodNumber;
|
|
96
|
+
increments: z.ZodString;
|
|
97
|
+
}, z.core.$strict>>;
|
|
98
|
+
whatsappVoicePrerecorded: z.ZodOptional<z.ZodObject<{
|
|
99
|
+
perMinute: z.ZodNumber;
|
|
100
|
+
increments: z.ZodString;
|
|
101
|
+
}, z.core.$strict>>;
|
|
102
|
+
whatsappVoiceAi: z.ZodOptional<z.ZodObject<{
|
|
103
|
+
perMinute: z.ZodNumber;
|
|
104
|
+
increments: z.ZodString;
|
|
105
|
+
}, z.core.$strict>>;
|
|
106
|
+
}, z.core.$strict>;
|
|
107
|
+
export type RateOverrides = z.infer<typeof rateOverridesSchema>;
|
|
108
|
+
//# sourceMappingURL=rates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rates.d.ts","sourceRoot":"","sources":["../../src/billing/rates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,cAAc,8CAA+C,CAAC;AAC3E,eAAO,MAAM,YAAY,yFAKf,CAAC;AACX,eAAO,MAAM,cAAc,4HAAgD,CAAC;AAE5E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,eAAO,MAAM,kBAAkB;;;;;;;;EAAyB,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,aAKjC,CAAC;AAEJ,kEAAkE;AAClE,eAAO,MAAM,iBAAiB;;kBAE5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,gFAAgF;AAChF,eAAO,MAAM,eAAe;;;kBAG1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,2EAA2E;AAC3E,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;kBAQtB,CAAC;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAwB,CAAC;AACzD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The billable-meter catalog and per-meter rate schemas.
|
|
4
|
+
*
|
|
5
|
+
* The catalog is closed-world: exactly seven meters, one per dispatchable
|
|
6
|
+
* channel/mode. Message meters bill per message; voice meters bill answered
|
|
7
|
+
* duration under a telecom increment pair. Each meter kind has its own strict
|
|
8
|
+
* schema so a rate object with fields from the wrong kind (e.g. `increments`
|
|
9
|
+
* on `sms`) fails validation instead of being silently ignored.
|
|
10
|
+
*
|
|
11
|
+
* The two WhatsApp voice meters are reserved: they must be priced in every
|
|
12
|
+
* plan, but no dispatch path produces them until Fonoster ships that transport.
|
|
13
|
+
*/
|
|
14
|
+
export const MESSAGE_METERS = ["sms", "email", "whatsappMessage"];
|
|
15
|
+
export const VOICE_METERS = [
|
|
16
|
+
"voicePrerecorded",
|
|
17
|
+
"voiceAi",
|
|
18
|
+
"whatsappVoicePrerecorded",
|
|
19
|
+
"whatsappVoiceAi"
|
|
20
|
+
];
|
|
21
|
+
export const BILLING_METERS = [...MESSAGE_METERS, ...VOICE_METERS];
|
|
22
|
+
export const billingMeterSchema = z.enum(BILLING_METERS);
|
|
23
|
+
/**
|
|
24
|
+
* Telecom billing-increment notation `"initial/subsequent"` in seconds — the
|
|
25
|
+
* industry standard (15/15 rounds every call up to 15s blocks; 60/6 bills a
|
|
26
|
+
* full first minute then 6s steps).
|
|
27
|
+
*/
|
|
28
|
+
export const incrementNotationSchema = z
|
|
29
|
+
.string()
|
|
30
|
+
.regex(/^[1-9]\d*\/[1-9]\d*$/, 'increments must be "initial/subsequent" in positive whole seconds (e.g. "15/15")');
|
|
31
|
+
/** A message meter's rate: decimal currency units per message. */
|
|
32
|
+
export const messageRateSchema = z.strictObject({
|
|
33
|
+
perMessage: z.number().positive()
|
|
34
|
+
});
|
|
35
|
+
/** A voice meter's rate: decimal currency units per minute + increment pair. */
|
|
36
|
+
export const voiceRateSchema = z.strictObject({
|
|
37
|
+
perMinute: z.number().positive(),
|
|
38
|
+
increments: incrementNotationSchema
|
|
39
|
+
});
|
|
40
|
+
/** A complete rate card: all seven meters, each with its kind's schema. */
|
|
41
|
+
export const ratesSchema = z.strictObject({
|
|
42
|
+
sms: messageRateSchema,
|
|
43
|
+
email: messageRateSchema,
|
|
44
|
+
whatsappMessage: messageRateSchema,
|
|
45
|
+
voicePrerecorded: voiceRateSchema,
|
|
46
|
+
voiceAi: voiceRateSchema,
|
|
47
|
+
whatsappVoicePrerecorded: voiceRateSchema,
|
|
48
|
+
whatsappVoiceAi: voiceRateSchema
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Per-workspace enterprise overrides: any subset of the rate card, validated
|
|
52
|
+
* with the same per-meter schemas. Stored on workspace billing state (DB),
|
|
53
|
+
* never in configuration.
|
|
54
|
+
*/
|
|
55
|
+
export const rateOverridesSchema = ratesSchema.partial();
|
|
56
|
+
//# sourceMappingURL=rates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rates.js","sourceRoot":"","sources":["../../src/billing/rates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,iBAAiB,CAAU,CAAC;AAC3E,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,kBAAkB;IAClB,SAAS;IACT,0BAA0B;IAC1B,iBAAiB;CACT,CAAC;AACX,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,cAAc,EAAE,GAAG,YAAY,CAAU,CAAC;AAM5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,EAAE;KACR,KAAK,CACJ,sBAAsB,EACtB,kFAAkF,CACnF,CAAC;AAEJ,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,YAAY,CAAC;IAC9C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAGH,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,YAAY,CAAC;IAC5C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,UAAU,EAAE,uBAAuB;CACpC,CAAC,CAAC;AAGH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,YAAY,CAAC;IACxC,GAAG,EAAE,iBAAiB;IACtB,KAAK,EAAE,iBAAiB;IACxB,eAAe,EAAE,iBAAiB;IAClC,gBAAgB,EAAE,eAAe;IACjC,OAAO,EAAE,eAAe;IACxB,wBAAwB,EAAE,eAAe;IACzC,eAAe,EAAE,eAAe;CACjC,CAAC,CAAC;AAGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -186,6 +186,102 @@ export declare const announcementConfigSchema: z.ZodOptional<z.ZodObject<{
|
|
|
186
186
|
message: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
187
187
|
}, z.core.$strip>>;
|
|
188
188
|
export type AnnouncementConfig = z.infer<typeof announcementConfigSchema>;
|
|
189
|
+
/**
|
|
190
|
+
* One sellable plan. Plans are quoted in the deployment's billing currency;
|
|
191
|
+
* `monthlyPrice` (what the card is charged) and `monthlyAllowance` (the usage
|
|
192
|
+
* credit granted each cycle) are separate on purpose — "pay 29, get 35" is a
|
|
193
|
+
* config edit, not a schema change. `stripePriceId` joins the catalog to the
|
|
194
|
+
* Stripe price backing the subscription item.
|
|
195
|
+
*/
|
|
196
|
+
export declare const billingPlanSchema: z.ZodObject<{
|
|
197
|
+
key: z.ZodString;
|
|
198
|
+
name: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
199
|
+
monthlyPrice: z.ZodNumber;
|
|
200
|
+
monthlyAllowance: z.ZodNumber;
|
|
201
|
+
stripePriceId: z.ZodString;
|
|
202
|
+
rates: z.ZodObject<{
|
|
203
|
+
sms: z.ZodObject<{
|
|
204
|
+
perMessage: z.ZodNumber;
|
|
205
|
+
}, z.core.$strict>;
|
|
206
|
+
email: z.ZodObject<{
|
|
207
|
+
perMessage: z.ZodNumber;
|
|
208
|
+
}, z.core.$strict>;
|
|
209
|
+
whatsappMessage: z.ZodObject<{
|
|
210
|
+
perMessage: z.ZodNumber;
|
|
211
|
+
}, z.core.$strict>;
|
|
212
|
+
voicePrerecorded: z.ZodObject<{
|
|
213
|
+
perMinute: z.ZodNumber;
|
|
214
|
+
increments: z.ZodString;
|
|
215
|
+
}, z.core.$strict>;
|
|
216
|
+
voiceAi: z.ZodObject<{
|
|
217
|
+
perMinute: z.ZodNumber;
|
|
218
|
+
increments: z.ZodString;
|
|
219
|
+
}, z.core.$strict>;
|
|
220
|
+
whatsappVoicePrerecorded: z.ZodObject<{
|
|
221
|
+
perMinute: z.ZodNumber;
|
|
222
|
+
increments: z.ZodString;
|
|
223
|
+
}, z.core.$strict>;
|
|
224
|
+
whatsappVoiceAi: z.ZodObject<{
|
|
225
|
+
perMinute: z.ZodNumber;
|
|
226
|
+
increments: z.ZodString;
|
|
227
|
+
}, z.core.$strict>;
|
|
228
|
+
}, z.core.$strict>;
|
|
229
|
+
}, z.core.$strip>;
|
|
230
|
+
export type BillingPlan = z.infer<typeof billingPlanSchema>;
|
|
231
|
+
/**
|
|
232
|
+
* Usage-based billing. The plan catalog is deployment config (this section);
|
|
233
|
+
* all billing STATE — workspace→plan assignment, balances, ledger, Stripe ids,
|
|
234
|
+
* enterprise rate overrides — lives in the database. `plans` is ORDERED: array
|
|
235
|
+
* index defines the upgrade path shown in the console. When `enabled` is false,
|
|
236
|
+
* dispatch paths neither meter usage nor enforce credit gates (pre-billing
|
|
237
|
+
* behavior, and the rollback switch). Stripe credentials are optional so
|
|
238
|
+
* metering-only and self-hosted deployments can run without payment; checkout
|
|
239
|
+
* and webhook surfaces error clearly when they're absent.
|
|
240
|
+
*/
|
|
241
|
+
export declare const billingConfigSchema: z.ZodOptional<z.ZodObject<{
|
|
242
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
243
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
244
|
+
stripe: z.ZodOptional<z.ZodObject<{
|
|
245
|
+
secretKey: z.ZodString;
|
|
246
|
+
webhookSigningSecret: z.ZodString;
|
|
247
|
+
}, z.core.$strip>>;
|
|
248
|
+
voiceDebitEstimateSeconds: z.ZodDefault<z.ZodNumber>;
|
|
249
|
+
plans: z.ZodArray<z.ZodObject<{
|
|
250
|
+
key: z.ZodString;
|
|
251
|
+
name: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
252
|
+
monthlyPrice: z.ZodNumber;
|
|
253
|
+
monthlyAllowance: z.ZodNumber;
|
|
254
|
+
stripePriceId: z.ZodString;
|
|
255
|
+
rates: z.ZodObject<{
|
|
256
|
+
sms: z.ZodObject<{
|
|
257
|
+
perMessage: z.ZodNumber;
|
|
258
|
+
}, z.core.$strict>;
|
|
259
|
+
email: z.ZodObject<{
|
|
260
|
+
perMessage: z.ZodNumber;
|
|
261
|
+
}, z.core.$strict>;
|
|
262
|
+
whatsappMessage: z.ZodObject<{
|
|
263
|
+
perMessage: z.ZodNumber;
|
|
264
|
+
}, z.core.$strict>;
|
|
265
|
+
voicePrerecorded: z.ZodObject<{
|
|
266
|
+
perMinute: z.ZodNumber;
|
|
267
|
+
increments: z.ZodString;
|
|
268
|
+
}, z.core.$strict>;
|
|
269
|
+
voiceAi: z.ZodObject<{
|
|
270
|
+
perMinute: z.ZodNumber;
|
|
271
|
+
increments: z.ZodString;
|
|
272
|
+
}, z.core.$strict>;
|
|
273
|
+
whatsappVoicePrerecorded: z.ZodObject<{
|
|
274
|
+
perMinute: z.ZodNumber;
|
|
275
|
+
increments: z.ZodString;
|
|
276
|
+
}, z.core.$strict>;
|
|
277
|
+
whatsappVoiceAi: z.ZodObject<{
|
|
278
|
+
perMinute: z.ZodNumber;
|
|
279
|
+
increments: z.ZodString;
|
|
280
|
+
}, z.core.$strict>;
|
|
281
|
+
}, z.core.$strict>;
|
|
282
|
+
}, z.core.$strip>>;
|
|
283
|
+
}, z.core.$strip>>;
|
|
284
|
+
export type BillingConfig = z.infer<typeof billingConfigSchema>;
|
|
189
285
|
export declare const qcobroConfigSchema: z.ZodObject<{
|
|
190
286
|
database: z.ZodObject<{
|
|
191
287
|
url: z.ZodString;
|
|
@@ -287,6 +383,49 @@ export declare const qcobroConfigSchema: z.ZodObject<{
|
|
|
287
383
|
title: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
288
384
|
message: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
289
385
|
}, z.core.$strip>>;
|
|
386
|
+
billing: z.ZodOptional<z.ZodObject<{
|
|
387
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
388
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
389
|
+
stripe: z.ZodOptional<z.ZodObject<{
|
|
390
|
+
secretKey: z.ZodString;
|
|
391
|
+
webhookSigningSecret: z.ZodString;
|
|
392
|
+
}, z.core.$strip>>;
|
|
393
|
+
voiceDebitEstimateSeconds: z.ZodDefault<z.ZodNumber>;
|
|
394
|
+
plans: z.ZodArray<z.ZodObject<{
|
|
395
|
+
key: z.ZodString;
|
|
396
|
+
name: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
397
|
+
monthlyPrice: z.ZodNumber;
|
|
398
|
+
monthlyAllowance: z.ZodNumber;
|
|
399
|
+
stripePriceId: z.ZodString;
|
|
400
|
+
rates: z.ZodObject<{
|
|
401
|
+
sms: z.ZodObject<{
|
|
402
|
+
perMessage: z.ZodNumber;
|
|
403
|
+
}, z.core.$strict>;
|
|
404
|
+
email: z.ZodObject<{
|
|
405
|
+
perMessage: z.ZodNumber;
|
|
406
|
+
}, z.core.$strict>;
|
|
407
|
+
whatsappMessage: z.ZodObject<{
|
|
408
|
+
perMessage: z.ZodNumber;
|
|
409
|
+
}, z.core.$strict>;
|
|
410
|
+
voicePrerecorded: z.ZodObject<{
|
|
411
|
+
perMinute: z.ZodNumber;
|
|
412
|
+
increments: z.ZodString;
|
|
413
|
+
}, z.core.$strict>;
|
|
414
|
+
voiceAi: z.ZodObject<{
|
|
415
|
+
perMinute: z.ZodNumber;
|
|
416
|
+
increments: z.ZodString;
|
|
417
|
+
}, z.core.$strict>;
|
|
418
|
+
whatsappVoicePrerecorded: z.ZodObject<{
|
|
419
|
+
perMinute: z.ZodNumber;
|
|
420
|
+
increments: z.ZodString;
|
|
421
|
+
}, z.core.$strict>;
|
|
422
|
+
whatsappVoiceAi: z.ZodObject<{
|
|
423
|
+
perMinute: z.ZodNumber;
|
|
424
|
+
increments: z.ZodString;
|
|
425
|
+
}, z.core.$strict>;
|
|
426
|
+
}, z.core.$strict>;
|
|
427
|
+
}, z.core.$strip>>;
|
|
428
|
+
}, z.core.$strip>>;
|
|
290
429
|
security: z.ZodOptional<z.ZodObject<{
|
|
291
430
|
cloakEncryptionKey: z.ZodOptional<z.ZodString>;
|
|
292
431
|
}, z.core.$strip>>;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB;;;iBAK/B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;iBAMlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkEpB,CAAC;AAEd,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAG1F;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;kBAYlB,CAAC;AAEd,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;kBAqBlB,CAAC;AAEd,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;EAAoD,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqF7B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { ratesSchema } from "./billing/rates.js";
|
|
2
3
|
/**
|
|
3
4
|
* QCobro service configuration — the shape of `qcobro.json`.
|
|
4
5
|
*
|
|
@@ -245,6 +246,66 @@ export const announcementConfigSchema = z
|
|
|
245
246
|
message: localizedStringSchema
|
|
246
247
|
})
|
|
247
248
|
.optional();
|
|
249
|
+
/**
|
|
250
|
+
* One sellable plan. Plans are quoted in the deployment's billing currency;
|
|
251
|
+
* `monthlyPrice` (what the card is charged) and `monthlyAllowance` (the usage
|
|
252
|
+
* credit granted each cycle) are separate on purpose — "pay 29, get 35" is a
|
|
253
|
+
* config edit, not a schema change. `stripePriceId` joins the catalog to the
|
|
254
|
+
* Stripe price backing the subscription item.
|
|
255
|
+
*/
|
|
256
|
+
export const billingPlanSchema = z.object({
|
|
257
|
+
key: z.string().regex(/^[a-z][a-z0-9-]*$/, "plan key must be kebab-case (e.g. 'starter')"),
|
|
258
|
+
name: localizedStringSchema,
|
|
259
|
+
monthlyPrice: z.number().nonnegative(),
|
|
260
|
+
monthlyAllowance: z.number().nonnegative(),
|
|
261
|
+
stripePriceId: z.string().min(1),
|
|
262
|
+
rates: ratesSchema
|
|
263
|
+
});
|
|
264
|
+
/**
|
|
265
|
+
* Usage-based billing. The plan catalog is deployment config (this section);
|
|
266
|
+
* all billing STATE — workspace→plan assignment, balances, ledger, Stripe ids,
|
|
267
|
+
* enterprise rate overrides — lives in the database. `plans` is ORDERED: array
|
|
268
|
+
* index defines the upgrade path shown in the console. When `enabled` is false,
|
|
269
|
+
* dispatch paths neither meter usage nor enforce credit gates (pre-billing
|
|
270
|
+
* behavior, and the rollback switch). Stripe credentials are optional so
|
|
271
|
+
* metering-only and self-hosted deployments can run without payment; checkout
|
|
272
|
+
* and webhook surfaces error clearly when they're absent.
|
|
273
|
+
*/
|
|
274
|
+
export const billingConfigSchema = z
|
|
275
|
+
.object({
|
|
276
|
+
enabled: z.boolean().default(false),
|
|
277
|
+
/** Billing currency (ISO 4217) — distinct from WorkspaceSettings.currency. */
|
|
278
|
+
currency: z.string().length(3).default("USD"),
|
|
279
|
+
stripe: z
|
|
280
|
+
.object({
|
|
281
|
+
secretKey: z.string().min(1),
|
|
282
|
+
webhookSigningSecret: z.string().min(1)
|
|
283
|
+
})
|
|
284
|
+
.optional(),
|
|
285
|
+
/**
|
|
286
|
+
* Seconds of answered time the engine's credit bucket debits per voice
|
|
287
|
+
* dispatch before the call settles to its actual duration (never less than
|
|
288
|
+
* the meter's initial increment).
|
|
289
|
+
*/
|
|
290
|
+
voiceDebitEstimateSeconds: z.number().int().positive().default(60),
|
|
291
|
+
plans: z
|
|
292
|
+
.array(billingPlanSchema)
|
|
293
|
+
.min(1)
|
|
294
|
+
.superRefine((plans, ctx) => {
|
|
295
|
+
const seen = new Set();
|
|
296
|
+
for (const [index, plan] of plans.entries()) {
|
|
297
|
+
if (seen.has(plan.key)) {
|
|
298
|
+
ctx.addIssue({
|
|
299
|
+
code: z.ZodIssueCode.custom,
|
|
300
|
+
path: [index, "key"],
|
|
301
|
+
message: `Duplicate plan key "${plan.key}" — plan keys must be unique`
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
seen.add(plan.key);
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
.optional();
|
|
248
309
|
export const qcobroConfigSchema = z.object({
|
|
249
310
|
/** Application (apiserver) database. */
|
|
250
311
|
database: z.object({ url: z.string().min(1) }),
|
|
@@ -272,6 +333,7 @@ export const qcobroConfigSchema = z.object({
|
|
|
272
333
|
ai: aiConfigSchema,
|
|
273
334
|
tts: ttsConfigSchema,
|
|
274
335
|
announcement: announcementConfigSchema,
|
|
336
|
+
billing: billingConfigSchema,
|
|
275
337
|
/**
|
|
276
338
|
* Secret-at-rest. `cloakEncryptionKey` is a versioned AES-GCM-256 key
|
|
277
339
|
* (`k1.aesgcm256.<base64-32-byte>`) used by `prisma-field-encryption` (the Fonoster/Routr
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,gFAAgF;IAChF,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC;IAC/C,oEAAoE;IACpE,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,uBAAuB,CAAC;CAC3D,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,MAAM,EAAE,CAAC,CAAC,I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C,CAAC,CAAC,QAAQ,EAAE;QACvC;;;WAGG;QACH,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;KAC7D,CAAC;SACD,OAAO,CAAC;QACP,UAAU,EAAE,4BAA4B;QACxC,UAAU,EAAE,OAAO;QACnB,oBAAoB,EAAE,EAAE;QACxB,iBAAiB,EAAE,CAAC;KACrB,CAAC;IACJ;;;;;OAKG;IACH,MAAM,EAAE,CAAC;SACN,MAAM,CAAC;QACN,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACnC,oCAAoC;QACpC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD;;;;WAIG;QACH,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;KAChE,CAAC;SACD,QAAQ,CAAC,EAAE,CAAC;CAChB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./utils/index.js";
|
|
|
4
4
|
export * from "./schemas/index.js";
|
|
5
5
|
export * from "./types/index.js";
|
|
6
6
|
export * from "./evaluation/index.js";
|
|
7
|
+
export * from "./billing/index.js";
|
|
7
8
|
export * from "./config.js";
|
|
8
9
|
/**
|
|
9
10
|
* Placeholder contract proving the shared-schema pattern.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;iBAEpB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;iBAEpB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./utils/index.js";
|
|
|
4
4
|
export * from "./schemas/index.js";
|
|
5
5
|
export * from "./types/index.js";
|
|
6
6
|
export * from "./evaluation/index.js";
|
|
7
|
+
export * from "./billing/index.js";
|
|
7
8
|
export * from "./config.js";
|
|
8
9
|
/**
|
|
9
10
|
* Placeholder contract proving the shared-schema pattern.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;CACpC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;CACpC,CAAC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schemas for the billing service functions (usage-ledger capability).
|
|
4
|
+
* The client interfaces they pair with live in `../types/billing.ts`.
|
|
5
|
+
*/
|
|
6
|
+
/** Meters one billable dispatch (priced at write time from the workspace's plan). */
|
|
7
|
+
export declare const meterDispatchSchema: z.ZodObject<{
|
|
8
|
+
workspaceRef: z.ZodString;
|
|
9
|
+
meter: z.ZodEnum<{
|
|
10
|
+
sms: "sms";
|
|
11
|
+
email: "email";
|
|
12
|
+
whatsappMessage: "whatsappMessage";
|
|
13
|
+
voicePrerecorded: "voicePrerecorded";
|
|
14
|
+
voiceAi: "voiceAi";
|
|
15
|
+
whatsappVoicePrerecorded: "whatsappVoicePrerecorded";
|
|
16
|
+
whatsappVoiceAi: "whatsappVoiceAi";
|
|
17
|
+
}>;
|
|
18
|
+
at: z.ZodString;
|
|
19
|
+
campaignId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
portfolioAccountId: z.ZodOptional<z.ZodString>;
|
|
21
|
+
providerRef: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export type MeterDispatchInput = z.infer<typeof meterDispatchSchema>;
|
|
24
|
+
/** Settles a voice usage record to its actual answered duration (idempotent per ref). */
|
|
25
|
+
export declare const settleVoiceUsageSchema: z.ZodObject<{
|
|
26
|
+
providerRef: z.ZodString;
|
|
27
|
+
answeredSeconds: z.ZodNumber;
|
|
28
|
+
at: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type SettleVoiceUsageInput = z.infer<typeof settleVoiceUsageSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Turns a workspace's billing cycle over (close previous, open next): voids the
|
|
33
|
+
* unused remainder and grants the new allowance. Idempotent per
|
|
34
|
+
* `(workspaceRef, stripeInvoiceId)` — a replayed webhook no-ops.
|
|
35
|
+
*/
|
|
36
|
+
export declare const cycleTurnoverSchema: z.ZodObject<{
|
|
37
|
+
workspaceRef: z.ZodString;
|
|
38
|
+
stripeInvoiceId: z.ZodString;
|
|
39
|
+
grantMicro: z.ZodNumber;
|
|
40
|
+
cycleStart: z.ZodString;
|
|
41
|
+
cycleEnd: z.ZodString;
|
|
42
|
+
at: z.ZodString;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type CycleTurnoverInput = z.infer<typeof cycleTurnoverSchema>;
|
|
45
|
+
/** Reads a workspace's billing status (balance, plan, cycle). */
|
|
46
|
+
export declare const getWorkspaceBillingStatusSchema: z.ZodObject<{
|
|
47
|
+
workspaceRef: z.ZodString;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export type GetWorkspaceBillingStatusInput = z.infer<typeof getWorkspaceBillingStatusSchema>;
|
|
50
|
+
/**
|
|
51
|
+
* Puts a workspace on a paid plan. First paid workspace for a payer → a
|
|
52
|
+
* Stripe-hosted Checkout session (collects the card, creates customer +
|
|
53
|
+
* subscription); subsequent workspaces → a prorated subscription item on the
|
|
54
|
+
* existing subscription, no card entry.
|
|
55
|
+
*/
|
|
56
|
+
export declare const subscribeWorkspaceSchema: z.ZodObject<{
|
|
57
|
+
workspaceRef: z.ZodString;
|
|
58
|
+
planKey: z.ZodString;
|
|
59
|
+
ownerUserRef: z.ZodString;
|
|
60
|
+
successUrl: z.ZodString;
|
|
61
|
+
cancelUrl: z.ZodString;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export type SubscribeWorkspaceInput = z.infer<typeof subscribeWorkspaceSchema>;
|
|
64
|
+
/**
|
|
65
|
+
* Changes a workspace's plan. Upgrades apply immediately (prorated charge +
|
|
66
|
+
* prorated allowance replacing the remainder); downgrades take effect at
|
|
67
|
+
* period end via a subscription schedule.
|
|
68
|
+
*/
|
|
69
|
+
export declare const changePlanSchema: z.ZodObject<{
|
|
70
|
+
workspaceRef: z.ZodString;
|
|
71
|
+
targetPlanKey: z.ZodString;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
export type ChangePlanInput = z.infer<typeof changePlanSchema>;
|
|
74
|
+
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/schemas/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AAEH,qFAAqF;AACrF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;iBAS9B,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAErE,yFAAyF;AACzF,eAAO,MAAM,sBAAsB;;;;iBAMjC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE3E;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;iBAU9B,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAErE,iEAAiE;AACjE,eAAO,MAAM,+BAA+B;;iBAE1C,CAAC;AACH,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAE7F;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;;;;iBAMnC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;iBAG3B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { billingMeterSchema } from "../billing/rates.js";
|
|
3
|
+
/**
|
|
4
|
+
* Input schemas for the billing service functions (usage-ledger capability).
|
|
5
|
+
* The client interfaces they pair with live in `../types/billing.ts`.
|
|
6
|
+
*/
|
|
7
|
+
/** Meters one billable dispatch (priced at write time from the workspace's plan). */
|
|
8
|
+
export const meterDispatchSchema = z.object({
|
|
9
|
+
workspaceRef: z.string().min(1),
|
|
10
|
+
meter: billingMeterSchema,
|
|
11
|
+
/** Dispatch instant, ISO. */
|
|
12
|
+
at: z.string().min(1),
|
|
13
|
+
campaignId: z.string().min(1).optional(),
|
|
14
|
+
portfolioAccountId: z.string().min(1).optional(),
|
|
15
|
+
/** Provider ref of the dispatch — the settlement correlation key for voice. */
|
|
16
|
+
providerRef: z.string().min(1).optional()
|
|
17
|
+
});
|
|
18
|
+
/** Settles a voice usage record to its actual answered duration (idempotent per ref). */
|
|
19
|
+
export const settleVoiceUsageSchema = z.object({
|
|
20
|
+
providerRef: z.string().min(1),
|
|
21
|
+
/** Answered seconds (answer → hang-up; 0 = never answered, ring time excluded). */
|
|
22
|
+
answeredSeconds: z.number().int().nonnegative(),
|
|
23
|
+
/** Settlement instant, ISO. */
|
|
24
|
+
at: z.string().min(1)
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Turns a workspace's billing cycle over (close previous, open next): voids the
|
|
28
|
+
* unused remainder and grants the new allowance. Idempotent per
|
|
29
|
+
* `(workspaceRef, stripeInvoiceId)` — a replayed webhook no-ops.
|
|
30
|
+
*/
|
|
31
|
+
export const cycleTurnoverSchema = z.object({
|
|
32
|
+
workspaceRef: z.string().min(1),
|
|
33
|
+
stripeInvoiceId: z.string().min(1),
|
|
34
|
+
/** The (possibly prorated) allowance to grant, integer micro-units. */
|
|
35
|
+
grantMicro: z.number().int().nonnegative(),
|
|
36
|
+
/** New cycle bounds, ISO. */
|
|
37
|
+
cycleStart: z.string().min(1),
|
|
38
|
+
cycleEnd: z.string().min(1),
|
|
39
|
+
/** Turnover instant, ISO. */
|
|
40
|
+
at: z.string().min(1)
|
|
41
|
+
});
|
|
42
|
+
/** Reads a workspace's billing status (balance, plan, cycle). */
|
|
43
|
+
export const getWorkspaceBillingStatusSchema = z.object({
|
|
44
|
+
workspaceRef: z.string().min(1)
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Puts a workspace on a paid plan. First paid workspace for a payer → a
|
|
48
|
+
* Stripe-hosted Checkout session (collects the card, creates customer +
|
|
49
|
+
* subscription); subsequent workspaces → a prorated subscription item on the
|
|
50
|
+
* existing subscription, no card entry.
|
|
51
|
+
*/
|
|
52
|
+
export const subscribeWorkspaceSchema = z.object({
|
|
53
|
+
workspaceRef: z.string().min(1),
|
|
54
|
+
planKey: z.string().min(1),
|
|
55
|
+
ownerUserRef: z.string().min(1),
|
|
56
|
+
successUrl: z.string().url(),
|
|
57
|
+
cancelUrl: z.string().url()
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Changes a workspace's plan. Upgrades apply immediately (prorated charge +
|
|
61
|
+
* prorated allowance replacing the remainder); downgrades take effect at
|
|
62
|
+
* period end via a subscription schedule.
|
|
63
|
+
*/
|
|
64
|
+
export const changePlanSchema = z.object({
|
|
65
|
+
workspaceRef: z.string().min(1),
|
|
66
|
+
targetPlanKey: z.string().min(1)
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/schemas/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;GAGG;AAEH,qFAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,KAAK,EAAE,kBAAkB;IACzB,6BAA6B;IAC7B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACxC,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAChD,+EAA+E;IAC/E,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAC;AAGH,yFAAyF;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,C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