@oxyhq/contracts 0.26.0 → 0.28.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 (52) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +4 -3
  3. package/dist/cjs/index.js +186 -1
  4. package/dist/cjs/inference/accountBilling.js +334 -0
  5. package/dist/cjs/inference/attribution.js +106 -0
  6. package/dist/cjs/inference/catalogue.js +482 -0
  7. package/dist/cjs/inference/entitlement.js +217 -0
  8. package/dist/cjs/inference/errors.js +210 -0
  9. package/dist/cjs/inference/identifiers.js +197 -0
  10. package/dist/cjs/inference/money.js +188 -0
  11. package/dist/cjs/inference/priceVersion.js +110 -0
  12. package/dist/cjs/inference/providerConnection.js +142 -0
  13. package/dist/cjs/inference/request.js +288 -0
  14. package/dist/cjs/inference/routingPolicy.js +213 -0
  15. package/dist/cjs/inference/streamEvents.js +219 -0
  16. package/dist/cjs/inference/usage.js +297 -0
  17. package/dist/cjs/inference/version.js +85 -0
  18. package/dist/esm/.tsbuildinfo +1 -1
  19. package/dist/esm/accountGraph.js +4 -3
  20. package/dist/esm/index.js +54 -0
  21. package/dist/esm/inference/accountBilling.js +331 -0
  22. package/dist/esm/inference/attribution.js +103 -0
  23. package/dist/esm/inference/catalogue.js +479 -0
  24. package/dist/esm/inference/entitlement.js +214 -0
  25. package/dist/esm/inference/errors.js +207 -0
  26. package/dist/esm/inference/identifiers.js +194 -0
  27. package/dist/esm/inference/money.js +185 -0
  28. package/dist/esm/inference/priceVersion.js +107 -0
  29. package/dist/esm/inference/providerConnection.js +139 -0
  30. package/dist/esm/inference/request.js +285 -0
  31. package/dist/esm/inference/routingPolicy.js +210 -0
  32. package/dist/esm/inference/streamEvents.js +216 -0
  33. package/dist/esm/inference/usage.js +294 -0
  34. package/dist/esm/inference/version.js +82 -0
  35. package/dist/types/.tsbuildinfo +1 -1
  36. package/dist/types/accountGraph.d.ts +6 -5
  37. package/dist/types/index.d.ts +27 -0
  38. package/dist/types/inference/accountBilling.d.ts +738 -0
  39. package/dist/types/inference/attribution.d.ts +176 -0
  40. package/dist/types/inference/catalogue.d.ts +1612 -0
  41. package/dist/types/inference/entitlement.d.ts +519 -0
  42. package/dist/types/inference/errors.d.ts +206 -0
  43. package/dist/types/inference/identifiers.d.ts +157 -0
  44. package/dist/types/inference/money.d.ts +185 -0
  45. package/dist/types/inference/priceVersion.d.ts +182 -0
  46. package/dist/types/inference/providerConnection.d.ts +297 -0
  47. package/dist/types/inference/request.d.ts +2364 -0
  48. package/dist/types/inference/routingPolicy.d.ts +426 -0
  49. package/dist/types/inference/streamEvents.d.ts +906 -0
  50. package/dist/types/inference/usage.d.ts +1139 -0
  51. package/dist/types/inference/version.d.ts +82 -0
  52. package/package.json +1 -1
@@ -0,0 +1,738 @@
1
+ /**
2
+ * The account-scoped billing surface: who pays, what they hold, what bounds
3
+ * them, and how it reconciles against the payment processor.
4
+ *
5
+ * Every shape here is denominated in {@link exactDecimalSchema} — an exact
6
+ * decimal string — for the reason `money.ts` gives at length: a JS `number`
7
+ * cannot represent `0.1 + 0.2`, and a balance is the last place a rounding error
8
+ * should be allowed to accumulate silently.
9
+ *
10
+ * ## What is NOT here, and where it is instead
11
+ *
12
+ * The BALANCE and the BUDGETS both live at `/inference/reporting` (#972
13
+ * workstream 8), which owns the customer's view of what they hold and what
14
+ * bounds them, stamped `{source, consistency}` so a reader can always tell which
15
+ * kind of number they are looking at. This file declares who PAYS and on what
16
+ * TERMS, plus the records that sit behind those numbers — invoices, processor
17
+ * payments, auto-recharge attempts and reconciliation.
18
+ *
19
+ * The split is not cosmetic. A second balance shape here would be a second
20
+ * answer to one question, and the pair would disagree the day one of them stops
21
+ * accounting for an invoiced account's unused credit line — which is exactly the
22
+ * kind of drift a customer discovers before we do.
23
+ *
24
+ * ## Product entitlements are NOT here
25
+ *
26
+ * Alia plans, their monthly allowances and the API-credit product live in
27
+ * `entitlement.ts`, in a shape that cannot be added to a balance. #972 is
28
+ * explicit that confusing a product subscription with pay-as-you-go inference
29
+ * spend is the failure mode, so the two are separate types that share no field
30
+ * and no unit.
31
+ *
32
+ * ## Stripe appears only as a REFERENCE
33
+ *
34
+ * `externalRef` names a record in the processor's database; nothing in this file
35
+ * is derived from Stripe, and no shape here can carry a processor-computed
36
+ * balance. The epic's invariant is that Stripe is a payment and invoicing
37
+ * processor and not the authoritative usage ledger, so the reconciliation shapes
38
+ * below describe a COMPARISON between two independent records rather than an
39
+ * import of one into the other.
40
+ *
41
+ * Decided in: docs/adr/0014-account-billing-and-entitlements.md,
42
+ * docs/adr/0009-usage-reservation-and-settlement.md.
43
+ */
44
+ import { z } from 'zod';
45
+ /**
46
+ * How an account pays.
47
+ *
48
+ * `prepaid` spends money it topped up in advance. `invoiced` draws against a
49
+ * credit limit and is billed in arrears — the enterprise shape. Both settle
50
+ * through the same ledger; the difference is only which bucket a reservation
51
+ * draws from once the prepaid and granted balances are exhausted.
52
+ */
53
+ export declare const BILLING_MODES: readonly ["prepaid", "invoiced"];
54
+ export declare const billingModeSchema: z.ZodEnum<["prepaid", "invoiced"]>;
55
+ /** Whether the profile may currently spend at all. */
56
+ export declare const BILLING_PROFILE_STATUSES: readonly ["active", "suspended", "closed"];
57
+ export declare const billingProfileStatusSchema: z.ZodEnum<["active", "suspended", "closed"]>;
58
+ /**
59
+ * Automatic top-up settings.
60
+ *
61
+ * An IMPLICATION rather than a biconditional, matching the column CHECK: the
62
+ * two amounts may be configured before the feature is switched on, but an
63
+ * `enabled` recharge with either missing is a setting that reads as "on" and can
64
+ * never fire — the shape a customer discovers only when their traffic stops.
65
+ */
66
+ export declare const autoRechargeSchema: z.ZodEffects<z.ZodObject<{
67
+ enabled: z.ZodBoolean;
68
+ /** Recharge when the spendable balance falls below this. */
69
+ threshold: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
70
+ /** How much to add. */
71
+ amount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
72
+ }, "strict", z.ZodTypeAny, {
73
+ enabled: boolean;
74
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
75
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
76
+ }, {
77
+ enabled: boolean;
78
+ amount?: string | undefined;
79
+ threshold?: string | undefined;
80
+ }>, {
81
+ enabled: boolean;
82
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
83
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
84
+ }, {
85
+ enabled: boolean;
86
+ amount?: string | undefined;
87
+ threshold?: string | undefined;
88
+ }>;
89
+ /**
90
+ * Which account pays for a workload, and on what terms.
91
+ *
92
+ * `accountId` is an Oxy account of ANY kind — personal, organization, project,
93
+ * bot or channel — because `Application.ownerAccountId` may be any of them. It
94
+ * is branded (`oxyAccountIdSchema`), so a delegated end-user id cannot be
95
+ * substituted for it anywhere in this contract.
96
+ */
97
+ export declare const billingProfileSchema: z.ZodObject<{
98
+ /** See `version.ts`: this shape is served to Console and to Alia. */
99
+ schemaVersion: z.ZodLiteral<1>;
100
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
101
+ currency: z.ZodString;
102
+ billingMode: z.ZodEnum<["prepaid", "invoiced"]>;
103
+ status: z.ZodEnum<["active", "suspended", "closed"]>;
104
+ /**
105
+ * How far an `invoiced` account may draw before a reservation is refused.
106
+ * Always `'0'` for a `prepaid` account, where it is not consulted at all.
107
+ */
108
+ creditLimit: z.ZodBranded<z.ZodString, "ExactDecimal">;
109
+ autoRecharge: z.ZodEffects<z.ZodObject<{
110
+ enabled: z.ZodBoolean;
111
+ /** Recharge when the spendable balance falls below this. */
112
+ threshold: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
113
+ /** How much to add. */
114
+ amount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
115
+ }, "strict", z.ZodTypeAny, {
116
+ enabled: boolean;
117
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
118
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
119
+ }, {
120
+ enabled: boolean;
121
+ amount?: string | undefined;
122
+ threshold?: string | undefined;
123
+ }>, {
124
+ enabled: boolean;
125
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
126
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
127
+ }, {
128
+ enabled: boolean;
129
+ amount?: string | undefined;
130
+ threshold?: string | undefined;
131
+ }>;
132
+ createdAt: z.ZodString;
133
+ updatedAt: z.ZodString;
134
+ }, "strict", z.ZodTypeAny, {
135
+ status: "active" | "suspended" | "closed";
136
+ accountId: string & z.BRAND<"OxyAccountId">;
137
+ updatedAt: string;
138
+ createdAt: string;
139
+ currency: string;
140
+ schemaVersion: 1;
141
+ billingMode: "prepaid" | "invoiced";
142
+ creditLimit: string & z.BRAND<"ExactDecimal">;
143
+ autoRecharge: {
144
+ enabled: boolean;
145
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
146
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
147
+ };
148
+ }, {
149
+ status: "active" | "suspended" | "closed";
150
+ accountId: string;
151
+ updatedAt: string;
152
+ createdAt: string;
153
+ currency: string;
154
+ schemaVersion: 1;
155
+ billingMode: "prepaid" | "invoiced";
156
+ creditLimit: string;
157
+ autoRecharge: {
158
+ enabled: boolean;
159
+ amount?: string | undefined;
160
+ threshold?: string | undefined;
161
+ };
162
+ }>;
163
+ /**
164
+ * WHO pays for an account and on what TERMS. Deliberately not how much they
165
+ * have.
166
+ *
167
+ * The balance lives at `GET /inference/reporting/accounts/:accountId/balance`
168
+ * (#972 workstream 8), which reads `account_balances` and stamps every response
169
+ * with `{source: 'financial_ledger', consistency: 'authoritative'}`. Restating
170
+ * those amounts here would be a second answer to one question, and the failure
171
+ * mode of two balance endpoints is the pair disagreeing on the day one of them
172
+ * stops accounting for the credit line.
173
+ *
174
+ * What this shape adds, and what nothing else carries: `billingAccountId` and
175
+ * `inherited`. A project draws on the nearest ancestor that has a profile
176
+ * (ADR 0014), so a Console page has to be able to say "this project spends the
177
+ * organization's balance" — showing somebody else's money under a project's name
178
+ * with no indication whose it is would be worse than showing nothing.
179
+ */
180
+ export declare const accountBillingStateSchema: z.ZodObject<{
181
+ /** See `version.ts`: this shape is served to Console and to Alia. */
182
+ schemaVersion: z.ZodLiteral<1>;
183
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
184
+ billingAccountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
185
+ inherited: z.ZodBoolean;
186
+ profile: z.ZodObject<{
187
+ /** See `version.ts`: this shape is served to Console and to Alia. */
188
+ schemaVersion: z.ZodLiteral<1>;
189
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
190
+ currency: z.ZodString;
191
+ billingMode: z.ZodEnum<["prepaid", "invoiced"]>;
192
+ status: z.ZodEnum<["active", "suspended", "closed"]>;
193
+ /**
194
+ * How far an `invoiced` account may draw before a reservation is refused.
195
+ * Always `'0'` for a `prepaid` account, where it is not consulted at all.
196
+ */
197
+ creditLimit: z.ZodBranded<z.ZodString, "ExactDecimal">;
198
+ autoRecharge: z.ZodEffects<z.ZodObject<{
199
+ enabled: z.ZodBoolean;
200
+ /** Recharge when the spendable balance falls below this. */
201
+ threshold: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
202
+ /** How much to add. */
203
+ amount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
204
+ }, "strict", z.ZodTypeAny, {
205
+ enabled: boolean;
206
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
207
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
208
+ }, {
209
+ enabled: boolean;
210
+ amount?: string | undefined;
211
+ threshold?: string | undefined;
212
+ }>, {
213
+ enabled: boolean;
214
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
215
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
216
+ }, {
217
+ enabled: boolean;
218
+ amount?: string | undefined;
219
+ threshold?: string | undefined;
220
+ }>;
221
+ createdAt: z.ZodString;
222
+ updatedAt: z.ZodString;
223
+ }, "strict", z.ZodTypeAny, {
224
+ status: "active" | "suspended" | "closed";
225
+ accountId: string & z.BRAND<"OxyAccountId">;
226
+ updatedAt: string;
227
+ createdAt: string;
228
+ currency: string;
229
+ schemaVersion: 1;
230
+ billingMode: "prepaid" | "invoiced";
231
+ creditLimit: string & z.BRAND<"ExactDecimal">;
232
+ autoRecharge: {
233
+ enabled: boolean;
234
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
235
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
236
+ };
237
+ }, {
238
+ status: "active" | "suspended" | "closed";
239
+ accountId: string;
240
+ updatedAt: string;
241
+ createdAt: string;
242
+ currency: string;
243
+ schemaVersion: 1;
244
+ billingMode: "prepaid" | "invoiced";
245
+ creditLimit: string;
246
+ autoRecharge: {
247
+ enabled: boolean;
248
+ amount?: string | undefined;
249
+ threshold?: string | undefined;
250
+ };
251
+ }>;
252
+ }, "strict", z.ZodTypeAny, {
253
+ accountId: string & z.BRAND<"OxyAccountId">;
254
+ profile: {
255
+ status: "active" | "suspended" | "closed";
256
+ accountId: string & z.BRAND<"OxyAccountId">;
257
+ updatedAt: string;
258
+ createdAt: string;
259
+ currency: string;
260
+ schemaVersion: 1;
261
+ billingMode: "prepaid" | "invoiced";
262
+ creditLimit: string & z.BRAND<"ExactDecimal">;
263
+ autoRecharge: {
264
+ enabled: boolean;
265
+ amount?: (string & z.BRAND<"ExactDecimal">) | undefined;
266
+ threshold?: (string & z.BRAND<"ExactDecimal">) | undefined;
267
+ };
268
+ };
269
+ schemaVersion: 1;
270
+ billingAccountId: string & z.BRAND<"OxyAccountId">;
271
+ inherited: boolean;
272
+ }, {
273
+ accountId: string;
274
+ profile: {
275
+ status: "active" | "suspended" | "closed";
276
+ accountId: string;
277
+ updatedAt: string;
278
+ createdAt: string;
279
+ currency: string;
280
+ schemaVersion: 1;
281
+ billingMode: "prepaid" | "invoiced";
282
+ creditLimit: string;
283
+ autoRecharge: {
284
+ enabled: boolean;
285
+ amount?: string | undefined;
286
+ threshold?: string | undefined;
287
+ };
288
+ };
289
+ schemaVersion: 1;
290
+ billingAccountId: string;
291
+ inherited: boolean;
292
+ }>;
293
+ export declare const BILLING_INVOICE_STATUSES: readonly ["draft", "open", "paid", "void"];
294
+ export declare const billingInvoiceStatusSchema: z.ZodEnum<["draft", "open", "paid", "void"]>;
295
+ /**
296
+ * A period's charges, aggregated — the invoiced-enterprise settlement document.
297
+ *
298
+ * `subtotalAmount` is the EXACT sum of the receipts on the invoice, at full
299
+ * scale; `totalAmount` is the rounded figure actually charged. The difference is
300
+ * booked as an `invoice_rounding` ledger entry rather than discarded, because a
301
+ * discarded remainder is money that exists in one system and not the other.
302
+ *
303
+ * `minorUnitExponent` is carried rather than derived from the currency code:
304
+ * USD is 2, JPY is 0, BHD is 3, and that is not a property this platform's
305
+ * database knows. Storing what was used keeps the invoice reproducible.
306
+ */
307
+ export declare const billingInvoiceSchema: z.ZodObject<{
308
+ /** See `version.ts`: this shape is served to Console and to Alia. */
309
+ schemaVersion: z.ZodLiteral<1>;
310
+ id: z.ZodString;
311
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
312
+ currency: z.ZodString;
313
+ periodStart: z.ZodString;
314
+ periodEnd: z.ZodString;
315
+ status: z.ZodEnum<["draft", "open", "paid", "void"]>;
316
+ subtotalAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
317
+ totalAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
318
+ minorUnitExponent: z.ZodNumber;
319
+ /** The processor's own invoice id, for reconciliation. Never an authority. */
320
+ externalInvoiceRef: z.ZodOptional<z.ZodString>;
321
+ issuedAt: z.ZodOptional<z.ZodString>;
322
+ paidAt: z.ZodOptional<z.ZodString>;
323
+ receiptCount: z.ZodNumber;
324
+ }, "strict", z.ZodTypeAny, {
325
+ status: "void" | "open" | "draft" | "paid";
326
+ accountId: string & z.BRAND<"OxyAccountId">;
327
+ id: string;
328
+ periodEnd: string;
329
+ currency: string;
330
+ schemaVersion: 1;
331
+ periodStart: string;
332
+ subtotalAmount: string & z.BRAND<"ExactDecimal">;
333
+ totalAmount: string & z.BRAND<"ExactDecimal">;
334
+ minorUnitExponent: number;
335
+ receiptCount: number;
336
+ issuedAt?: string | undefined;
337
+ externalInvoiceRef?: string | undefined;
338
+ paidAt?: string | undefined;
339
+ }, {
340
+ status: "void" | "open" | "draft" | "paid";
341
+ accountId: string;
342
+ id: string;
343
+ periodEnd: string;
344
+ currency: string;
345
+ schemaVersion: 1;
346
+ periodStart: string;
347
+ subtotalAmount: string;
348
+ totalAmount: string;
349
+ minorUnitExponent: number;
350
+ receiptCount: number;
351
+ issuedAt?: string | undefined;
352
+ externalInvoiceRef?: string | undefined;
353
+ paidAt?: string | undefined;
354
+ }>;
355
+ /** The processors this platform records payments from. */
356
+ export declare const EXTERNAL_PAYMENT_PROVIDERS: readonly ["stripe"];
357
+ export declare const externalPaymentProviderSchema: z.ZodEnum<["stripe"]>;
358
+ /**
359
+ * What kind of processor record `externalRef` names.
360
+ *
361
+ * Kept explicit because reconciliation compares like with like: a payment intent
362
+ * and the invoice it paid are two records of one movement of money, and counting
363
+ * both would double the external total.
364
+ */
365
+ export declare const EXTERNAL_PAYMENT_KINDS: readonly ["payment_intent", "invoice"];
366
+ export declare const externalPaymentKindSchema: z.ZodEnum<["payment_intent", "invoice"]>;
367
+ /**
368
+ * A processor payment that funded an Oxy balance.
369
+ *
370
+ * This is the reconciliation ANCHOR: one row per charge that landed in the
371
+ * ledger, carrying both the processor's reference and the ledger entry it
372
+ * produced. Without it, matching a Stripe charge back to a ledger entry means
373
+ * parsing an idempotency key, and a parser is not a foreign key.
374
+ */
375
+ export declare const externalPaymentSchema: z.ZodObject<{
376
+ id: z.ZodString;
377
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
378
+ provider: z.ZodEnum<["stripe"]>;
379
+ externalKind: z.ZodEnum<["payment_intent", "invoice"]>;
380
+ externalRef: z.ZodString;
381
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
382
+ currency: z.ZodString;
383
+ ledgerEntryId: z.ZodString;
384
+ occurredAt: z.ZodString;
385
+ createdAt: z.ZodString;
386
+ }, "strict", z.ZodTypeAny, {
387
+ accountId: string & z.BRAND<"OxyAccountId">;
388
+ id: string;
389
+ occurredAt: string;
390
+ createdAt: string;
391
+ amount: string & z.BRAND<"ExactDecimal">;
392
+ currency: string;
393
+ provider: "stripe";
394
+ externalKind: "payment_intent" | "invoice";
395
+ externalRef: string;
396
+ ledgerEntryId: string;
397
+ }, {
398
+ accountId: string;
399
+ id: string;
400
+ occurredAt: string;
401
+ createdAt: string;
402
+ amount: string;
403
+ currency: string;
404
+ provider: "stripe";
405
+ externalKind: "payment_intent" | "invoice";
406
+ externalRef: string;
407
+ ledgerEntryId: string;
408
+ }>;
409
+ /** Lifecycle of one automatic top-up. */
410
+ export declare const AUTO_RECHARGE_STATUSES: readonly ["pending", "succeeded", "failed"];
411
+ export declare const autoRechargeStatusSchema: z.ZodEnum<["pending", "succeeded", "failed"]>;
412
+ /**
413
+ * One attempt to top an account up automatically.
414
+ *
415
+ * Recorded BEFORE the processor is called and keyed on the account, currency and
416
+ * the window it fired in, so a sweep that runs twice — or two instances of it —
417
+ * charges a customer's card once. An off-session charge is the one operation on
418
+ * this surface where a duplicate is not merely a wrong number in a report.
419
+ */
420
+ export declare const autoRechargeAttemptSchema: z.ZodObject<{
421
+ /** See `version.ts`: this shape is served to Console and to Alia. */
422
+ schemaVersion: z.ZodLiteral<1>;
423
+ id: z.ZodString;
424
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
425
+ currency: z.ZodString;
426
+ requestedAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
427
+ /** The spendable balance that triggered it — why this attempt exists. */
428
+ balanceAtTrigger: z.ZodBranded<z.ZodString, "ExactDecimal">;
429
+ status: z.ZodEnum<["pending", "succeeded", "failed"]>;
430
+ externalRef: z.ZodOptional<z.ZodString>;
431
+ /** The processor's own decline code. Never a free-form message. */
432
+ failureCode: z.ZodOptional<z.ZodString>;
433
+ createdAt: z.ZodString;
434
+ updatedAt: z.ZodString;
435
+ }, "strict", z.ZodTypeAny, {
436
+ status: "pending" | "failed" | "succeeded";
437
+ accountId: string & z.BRAND<"OxyAccountId">;
438
+ updatedAt: string;
439
+ id: string;
440
+ createdAt: string;
441
+ currency: string;
442
+ schemaVersion: 1;
443
+ requestedAmount: string & z.BRAND<"ExactDecimal">;
444
+ balanceAtTrigger: string & z.BRAND<"ExactDecimal">;
445
+ failureCode?: string | undefined;
446
+ externalRef?: string | undefined;
447
+ }, {
448
+ status: "pending" | "failed" | "succeeded";
449
+ accountId: string;
450
+ updatedAt: string;
451
+ id: string;
452
+ createdAt: string;
453
+ currency: string;
454
+ schemaVersion: 1;
455
+ requestedAmount: string;
456
+ balanceAtTrigger: string;
457
+ failureCode?: string | undefined;
458
+ externalRef?: string | undefined;
459
+ }>;
460
+ /**
461
+ * How an Oxy record and a processor record fail to agree.
462
+ *
463
+ * A closed set, and every member is a DIFFERENT operational problem:
464
+ *
465
+ * - `missing_in_ledger` — the processor took money Oxy never credited. The
466
+ * customer paid and has no balance. This is the one that costs a customer.
467
+ * - `missing_in_external` — Oxy credited a balance with no processor charge
468
+ * behind it. This is the one that costs Oxy.
469
+ * - `amount_mismatch` — both exist and disagree.
470
+ * - `account_unresolved` — a processor charge whose customer maps to no Oxy
471
+ * account. Money arrived and nobody owns it.
472
+ *
473
+ * Collapsing them into a single "discrepancy" count is what makes a
474
+ * reconciliation report a number nobody acts on.
475
+ */
476
+ export declare const RECONCILIATION_DISCREPANCY_KINDS: readonly ["missing_in_ledger", "missing_in_external", "amount_mismatch", "account_unresolved"];
477
+ export declare const reconciliationDiscrepancyKindSchema: z.ZodEnum<["missing_in_ledger", "missing_in_external", "amount_mismatch", "account_unresolved"]>;
478
+ export declare const RECONCILIATION_RUN_STATUSES: readonly ["running", "completed", "failed"];
479
+ export declare const reconciliationRunStatusSchema: z.ZodEnum<["running", "completed", "failed"]>;
480
+ export declare const reconciliationDiscrepancySchema: z.ZodObject<{
481
+ /** See `version.ts`: this shape is served to Console and to Alia. */
482
+ schemaVersion: z.ZodLiteral<1>;
483
+ id: z.ZodString;
484
+ runId: z.ZodString;
485
+ kind: z.ZodEnum<["missing_in_ledger", "missing_in_external", "amount_mismatch", "account_unresolved"]>;
486
+ accountId: z.ZodOptional<z.ZodBranded<z.ZodString, "OxyAccountId">>;
487
+ externalRef: z.ZodOptional<z.ZodString>;
488
+ ledgerEntryId: z.ZodOptional<z.ZodString>;
489
+ /** What Oxy recorded. Absent for `missing_in_ledger`. */
490
+ ledgerAmount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
491
+ /** What the processor recorded. Absent for `missing_in_external`. */
492
+ externalAmount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
493
+ currency: z.ZodString;
494
+ createdAt: z.ZodString;
495
+ }, "strict", z.ZodTypeAny, {
496
+ kind: "missing_in_ledger" | "missing_in_external" | "amount_mismatch" | "account_unresolved";
497
+ id: string;
498
+ createdAt: string;
499
+ currency: string;
500
+ schemaVersion: 1;
501
+ runId: string;
502
+ accountId?: (string & z.BRAND<"OxyAccountId">) | undefined;
503
+ externalRef?: string | undefined;
504
+ ledgerEntryId?: string | undefined;
505
+ ledgerAmount?: (string & z.BRAND<"ExactDecimal">) | undefined;
506
+ externalAmount?: (string & z.BRAND<"ExactDecimal">) | undefined;
507
+ }, {
508
+ kind: "missing_in_ledger" | "missing_in_external" | "amount_mismatch" | "account_unresolved";
509
+ id: string;
510
+ createdAt: string;
511
+ currency: string;
512
+ schemaVersion: 1;
513
+ runId: string;
514
+ accountId?: string | undefined;
515
+ externalRef?: string | undefined;
516
+ ledgerEntryId?: string | undefined;
517
+ ledgerAmount?: string | undefined;
518
+ externalAmount?: string | undefined;
519
+ }>;
520
+ /**
521
+ * One reconciliation pass over a window.
522
+ *
523
+ * The totals are carried beside the discrepancy list on purpose: two totals that
524
+ * agree while the lists differ is a real and common state (a charge recorded
525
+ * against the wrong account), and a report that only published a difference
526
+ * would call it clean.
527
+ */
528
+ export declare const reconciliationRunSchema: z.ZodObject<{
529
+ /** See `version.ts`: this shape is served to Console and to Alia. */
530
+ schemaVersion: z.ZodLiteral<1>;
531
+ id: z.ZodString;
532
+ provider: z.ZodEnum<["stripe"]>;
533
+ /** Absent for a platform-wide pass. */
534
+ accountId: z.ZodOptional<z.ZodBranded<z.ZodString, "OxyAccountId">>;
535
+ currency: z.ZodString;
536
+ periodStart: z.ZodString;
537
+ periodEnd: z.ZodString;
538
+ status: z.ZodEnum<["running", "completed", "failed"]>;
539
+ ledgerTotal: z.ZodBranded<z.ZodString, "ExactDecimal">;
540
+ externalTotal: z.ZodBranded<z.ZodString, "ExactDecimal">;
541
+ discrepancyCount: z.ZodNumber;
542
+ startedAt: z.ZodString;
543
+ completedAt: z.ZodOptional<z.ZodString>;
544
+ }, "strict", z.ZodTypeAny, {
545
+ status: "completed" | "failed" | "running";
546
+ id: string;
547
+ periodEnd: string;
548
+ currency: string;
549
+ provider: "stripe";
550
+ schemaVersion: 1;
551
+ startedAt: string;
552
+ periodStart: string;
553
+ ledgerTotal: string & z.BRAND<"ExactDecimal">;
554
+ externalTotal: string & z.BRAND<"ExactDecimal">;
555
+ discrepancyCount: number;
556
+ accountId?: (string & z.BRAND<"OxyAccountId">) | undefined;
557
+ completedAt?: string | undefined;
558
+ }, {
559
+ status: "completed" | "failed" | "running";
560
+ id: string;
561
+ periodEnd: string;
562
+ currency: string;
563
+ provider: "stripe";
564
+ schemaVersion: 1;
565
+ startedAt: string;
566
+ periodStart: string;
567
+ ledgerTotal: string;
568
+ externalTotal: string;
569
+ discrepancyCount: number;
570
+ accountId?: string | undefined;
571
+ completedAt?: string | undefined;
572
+ }>;
573
+ export declare const reconciliationReportSchema: z.ZodObject<{
574
+ /** See `version.ts`: this shape is served to Console and to Alia. */
575
+ schemaVersion: z.ZodLiteral<1>;
576
+ run: z.ZodObject<{
577
+ /** See `version.ts`: this shape is served to Console and to Alia. */
578
+ schemaVersion: z.ZodLiteral<1>;
579
+ id: z.ZodString;
580
+ provider: z.ZodEnum<["stripe"]>;
581
+ /** Absent for a platform-wide pass. */
582
+ accountId: z.ZodOptional<z.ZodBranded<z.ZodString, "OxyAccountId">>;
583
+ currency: z.ZodString;
584
+ periodStart: z.ZodString;
585
+ periodEnd: z.ZodString;
586
+ status: z.ZodEnum<["running", "completed", "failed"]>;
587
+ ledgerTotal: z.ZodBranded<z.ZodString, "ExactDecimal">;
588
+ externalTotal: z.ZodBranded<z.ZodString, "ExactDecimal">;
589
+ discrepancyCount: z.ZodNumber;
590
+ startedAt: z.ZodString;
591
+ completedAt: z.ZodOptional<z.ZodString>;
592
+ }, "strict", z.ZodTypeAny, {
593
+ status: "completed" | "failed" | "running";
594
+ id: string;
595
+ periodEnd: string;
596
+ currency: string;
597
+ provider: "stripe";
598
+ schemaVersion: 1;
599
+ startedAt: string;
600
+ periodStart: string;
601
+ ledgerTotal: string & z.BRAND<"ExactDecimal">;
602
+ externalTotal: string & z.BRAND<"ExactDecimal">;
603
+ discrepancyCount: number;
604
+ accountId?: (string & z.BRAND<"OxyAccountId">) | undefined;
605
+ completedAt?: string | undefined;
606
+ }, {
607
+ status: "completed" | "failed" | "running";
608
+ id: string;
609
+ periodEnd: string;
610
+ currency: string;
611
+ provider: "stripe";
612
+ schemaVersion: 1;
613
+ startedAt: string;
614
+ periodStart: string;
615
+ ledgerTotal: string;
616
+ externalTotal: string;
617
+ discrepancyCount: number;
618
+ accountId?: string | undefined;
619
+ completedAt?: string | undefined;
620
+ }>;
621
+ discrepancies: z.ZodArray<z.ZodObject<{
622
+ /** See `version.ts`: this shape is served to Console and to Alia. */
623
+ schemaVersion: z.ZodLiteral<1>;
624
+ id: z.ZodString;
625
+ runId: z.ZodString;
626
+ kind: z.ZodEnum<["missing_in_ledger", "missing_in_external", "amount_mismatch", "account_unresolved"]>;
627
+ accountId: z.ZodOptional<z.ZodBranded<z.ZodString, "OxyAccountId">>;
628
+ externalRef: z.ZodOptional<z.ZodString>;
629
+ ledgerEntryId: z.ZodOptional<z.ZodString>;
630
+ /** What Oxy recorded. Absent for `missing_in_ledger`. */
631
+ ledgerAmount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
632
+ /** What the processor recorded. Absent for `missing_in_external`. */
633
+ externalAmount: z.ZodOptional<z.ZodBranded<z.ZodString, "ExactDecimal">>;
634
+ currency: z.ZodString;
635
+ createdAt: z.ZodString;
636
+ }, "strict", z.ZodTypeAny, {
637
+ kind: "missing_in_ledger" | "missing_in_external" | "amount_mismatch" | "account_unresolved";
638
+ id: string;
639
+ createdAt: string;
640
+ currency: string;
641
+ schemaVersion: 1;
642
+ runId: string;
643
+ accountId?: (string & z.BRAND<"OxyAccountId">) | undefined;
644
+ externalRef?: string | undefined;
645
+ ledgerEntryId?: string | undefined;
646
+ ledgerAmount?: (string & z.BRAND<"ExactDecimal">) | undefined;
647
+ externalAmount?: (string & z.BRAND<"ExactDecimal">) | undefined;
648
+ }, {
649
+ kind: "missing_in_ledger" | "missing_in_external" | "amount_mismatch" | "account_unresolved";
650
+ id: string;
651
+ createdAt: string;
652
+ currency: string;
653
+ schemaVersion: 1;
654
+ runId: string;
655
+ accountId?: string | undefined;
656
+ externalRef?: string | undefined;
657
+ ledgerEntryId?: string | undefined;
658
+ ledgerAmount?: string | undefined;
659
+ externalAmount?: string | undefined;
660
+ }>, "many">;
661
+ }, "strict", z.ZodTypeAny, {
662
+ schemaVersion: 1;
663
+ run: {
664
+ status: "completed" | "failed" | "running";
665
+ id: string;
666
+ periodEnd: string;
667
+ currency: string;
668
+ provider: "stripe";
669
+ schemaVersion: 1;
670
+ startedAt: string;
671
+ periodStart: string;
672
+ ledgerTotal: string & z.BRAND<"ExactDecimal">;
673
+ externalTotal: string & z.BRAND<"ExactDecimal">;
674
+ discrepancyCount: number;
675
+ accountId?: (string & z.BRAND<"OxyAccountId">) | undefined;
676
+ completedAt?: string | undefined;
677
+ };
678
+ discrepancies: {
679
+ kind: "missing_in_ledger" | "missing_in_external" | "amount_mismatch" | "account_unresolved";
680
+ id: string;
681
+ createdAt: string;
682
+ currency: string;
683
+ schemaVersion: 1;
684
+ runId: string;
685
+ accountId?: (string & z.BRAND<"OxyAccountId">) | undefined;
686
+ externalRef?: string | undefined;
687
+ ledgerEntryId?: string | undefined;
688
+ ledgerAmount?: (string & z.BRAND<"ExactDecimal">) | undefined;
689
+ externalAmount?: (string & z.BRAND<"ExactDecimal">) | undefined;
690
+ }[];
691
+ }, {
692
+ schemaVersion: 1;
693
+ run: {
694
+ status: "completed" | "failed" | "running";
695
+ id: string;
696
+ periodEnd: string;
697
+ currency: string;
698
+ provider: "stripe";
699
+ schemaVersion: 1;
700
+ startedAt: string;
701
+ periodStart: string;
702
+ ledgerTotal: string;
703
+ externalTotal: string;
704
+ discrepancyCount: number;
705
+ accountId?: string | undefined;
706
+ completedAt?: string | undefined;
707
+ };
708
+ discrepancies: {
709
+ kind: "missing_in_ledger" | "missing_in_external" | "amount_mismatch" | "account_unresolved";
710
+ id: string;
711
+ createdAt: string;
712
+ currency: string;
713
+ schemaVersion: 1;
714
+ runId: string;
715
+ accountId?: string | undefined;
716
+ externalRef?: string | undefined;
717
+ ledgerEntryId?: string | undefined;
718
+ ledgerAmount?: string | undefined;
719
+ externalAmount?: string | undefined;
720
+ }[];
721
+ }>;
722
+ export type BillingMode = z.infer<typeof billingModeSchema>;
723
+ export type BillingProfileStatus = z.infer<typeof billingProfileStatusSchema>;
724
+ export type AutoRecharge = z.infer<typeof autoRechargeSchema>;
725
+ export type BillingProfile = z.infer<typeof billingProfileSchema>;
726
+ export type AccountBillingState = z.infer<typeof accountBillingStateSchema>;
727
+ export type BillingInvoiceStatus = z.infer<typeof billingInvoiceStatusSchema>;
728
+ export type BillingInvoice = z.infer<typeof billingInvoiceSchema>;
729
+ export type ExternalPaymentProvider = z.infer<typeof externalPaymentProviderSchema>;
730
+ export type ExternalPaymentKind = z.infer<typeof externalPaymentKindSchema>;
731
+ export type ExternalPayment = z.infer<typeof externalPaymentSchema>;
732
+ export type AutoRechargeStatus = z.infer<typeof autoRechargeStatusSchema>;
733
+ export type AutoRechargeAttempt = z.infer<typeof autoRechargeAttemptSchema>;
734
+ export type ReconciliationDiscrepancyKind = z.infer<typeof reconciliationDiscrepancyKindSchema>;
735
+ export type ReconciliationRunStatus = z.infer<typeof reconciliationRunStatusSchema>;
736
+ export type ReconciliationDiscrepancy = z.infer<typeof reconciliationDiscrepancySchema>;
737
+ export type ReconciliationRun = z.infer<typeof reconciliationRunSchema>;
738
+ export type ReconciliationReport = z.infer<typeof reconciliationReportSchema>;