@dainamite/billing 0.17.0 → 0.19.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 (206) hide show
  1. package/CHANGELOG.md +99 -19
  2. package/dist/modules/billing/acl.js +9 -1
  3. package/dist/modules/billing/acl.js.map +2 -2
  4. package/dist/modules/billing/api/accounts/[id]/balance/route.js +62 -0
  5. package/dist/modules/billing/api/accounts/[id]/balance/route.js.map +7 -0
  6. package/dist/modules/billing/api/accounts/[id]/credit-status/route.js +56 -0
  7. package/dist/modules/billing/api/accounts/[id]/credit-status/route.js.map +7 -0
  8. package/dist/modules/billing/api/accounts/[id]/topups/route.js +36 -0
  9. package/dist/modules/billing/api/accounts/[id]/topups/route.js.map +7 -0
  10. package/dist/modules/billing/api/accounts/route.js +7 -0
  11. package/dist/modules/billing/api/accounts/route.js.map +2 -2
  12. package/dist/modules/billing/api/export/account/[id]/route.js +48 -3
  13. package/dist/modules/billing/api/export/account/[id]/route.js.map +2 -2
  14. package/dist/modules/billing/api/statements/generate/route.js +68 -0
  15. package/dist/modules/billing/api/statements/generate/route.js.map +7 -0
  16. package/dist/modules/billing/api/statements/route.js +110 -0
  17. package/dist/modules/billing/api/statements/route.js.map +7 -0
  18. package/dist/modules/billing/api/topups/route.js +139 -0
  19. package/dist/modules/billing/api/topups/route.js.map +7 -0
  20. package/dist/modules/billing/api/transactions/adjust/route.js +71 -0
  21. package/dist/modules/billing/api/transactions/adjust/route.js.map +7 -0
  22. package/dist/modules/billing/api/transactions/route.js +109 -0
  23. package/dist/modules/billing/api/transactions/route.js.map +7 -0
  24. package/dist/modules/billing/api/usage/route.js +30 -6
  25. package/dist/modules/billing/api/usage/route.js.map +2 -2
  26. package/dist/modules/billing/backend/billing/accounts/[id]/page.js +16 -1
  27. package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +2 -2
  28. package/dist/modules/billing/backend/billing/accounts/create/page.js +8 -1
  29. package/dist/modules/billing/backend/billing/accounts/create/page.js.map +2 -2
  30. package/dist/modules/billing/backend/billing/accounts/page.js +26 -1
  31. package/dist/modules/billing/backend/billing/accounts/page.js.map +2 -2
  32. package/dist/modules/billing/backend/billing/statements/[id]/page.js +129 -0
  33. package/dist/modules/billing/backend/billing/statements/[id]/page.js.map +7 -0
  34. package/dist/modules/billing/backend/billing/statements/[id]/page.meta.js +21 -0
  35. package/dist/modules/billing/backend/billing/statements/[id]/page.meta.js.map +7 -0
  36. package/dist/modules/billing/backend/billing/statements/page.js +152 -0
  37. package/dist/modules/billing/backend/billing/statements/page.js.map +7 -0
  38. package/dist/modules/billing/backend/billing/statements/page.meta.js +18 -0
  39. package/dist/modules/billing/backend/billing/statements/page.meta.js.map +7 -0
  40. package/dist/modules/billing/backend/billing/topups/[id]/page.js +90 -0
  41. package/dist/modules/billing/backend/billing/topups/[id]/page.js.map +7 -0
  42. package/dist/modules/billing/backend/billing/topups/[id]/page.meta.js +21 -0
  43. package/dist/modules/billing/backend/billing/topups/[id]/page.meta.js.map +7 -0
  44. package/dist/modules/billing/backend/billing/topups/page.js +147 -0
  45. package/dist/modules/billing/backend/billing/topups/page.js.map +7 -0
  46. package/dist/modules/billing/backend/billing/topups/page.meta.js +18 -0
  47. package/dist/modules/billing/backend/billing/topups/page.meta.js.map +7 -0
  48. package/dist/modules/billing/backend/billing/transactions/[id]/page.js +114 -0
  49. package/dist/modules/billing/backend/billing/transactions/[id]/page.js.map +7 -0
  50. package/dist/modules/billing/backend/billing/transactions/[id]/page.meta.js +21 -0
  51. package/dist/modules/billing/backend/billing/transactions/[id]/page.meta.js.map +7 -0
  52. package/dist/modules/billing/backend/billing/transactions/page.js +149 -0
  53. package/dist/modules/billing/backend/billing/transactions/page.js.map +7 -0
  54. package/dist/modules/billing/backend/billing/transactions/page.meta.js +18 -0
  55. package/dist/modules/billing/backend/billing/transactions/page.meta.js.map +7 -0
  56. package/dist/modules/billing/commands/accounts.js +26 -1
  57. package/dist/modules/billing/commands/accounts.js.map +2 -2
  58. package/dist/modules/billing/commands/index.js +3 -0
  59. package/dist/modules/billing/commands/index.js.map +2 -2
  60. package/dist/modules/billing/commands/invoices.js +21 -1
  61. package/dist/modules/billing/commands/invoices.js.map +2 -2
  62. package/dist/modules/billing/commands/statements.js +74 -0
  63. package/dist/modules/billing/commands/statements.js.map +7 -0
  64. package/dist/modules/billing/commands/topups.js +139 -0
  65. package/dist/modules/billing/commands/topups.js.map +7 -0
  66. package/dist/modules/billing/commands/transactions.js +119 -0
  67. package/dist/modules/billing/commands/transactions.js.map +7 -0
  68. package/dist/modules/billing/commands/usage.js +72 -0
  69. package/dist/modules/billing/commands/usage.js.map +2 -2
  70. package/dist/modules/billing/components/AccountForm.js +53 -1
  71. package/dist/modules/billing/components/AccountForm.js.map +2 -2
  72. package/dist/modules/billing/components/PrepaidPanel.js +314 -0
  73. package/dist/modules/billing/components/PrepaidPanel.js.map +7 -0
  74. package/dist/modules/billing/components/accountNames.js +20 -0
  75. package/dist/modules/billing/components/accountNames.js.map +7 -0
  76. package/dist/modules/billing/data/entities.js +290 -0
  77. package/dist/modules/billing/data/entities.js.map +2 -2
  78. package/dist/modules/billing/data/entityIds.js +6 -1
  79. package/dist/modules/billing/data/entityIds.js.map +2 -2
  80. package/dist/modules/billing/data/validators.js +107 -2
  81. package/dist/modules/billing/data/validators.js.map +2 -2
  82. package/dist/modules/billing/events.js +52 -0
  83. package/dist/modules/billing/events.js.map +2 -2
  84. package/dist/modules/billing/i18n/en.json +112 -4
  85. package/dist/modules/billing/i18n/pl.json +112 -4
  86. package/dist/modules/billing/index.js +1 -1
  87. package/dist/modules/billing/index.js.map +2 -2
  88. package/dist/modules/billing/lib/accountStatus.js +106 -0
  89. package/dist/modules/billing/lib/accountStatus.js.map +7 -0
  90. package/dist/modules/billing/lib/balanceEvents.js +48 -0
  91. package/dist/modules/billing/lib/balanceEvents.js.map +7 -0
  92. package/dist/modules/billing/lib/balanceLedger.js +136 -0
  93. package/dist/modules/billing/lib/balanceLedger.js.map +7 -0
  94. package/dist/modules/billing/lib/balanceStatus.js +29 -0
  95. package/dist/modules/billing/lib/balanceStatus.js.map +7 -0
  96. package/dist/modules/billing/lib/billRunEngine.js +40 -2
  97. package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
  98. package/dist/modules/billing/lib/creditStatus.js +65 -0
  99. package/dist/modules/billing/lib/creditStatus.js.map +7 -0
  100. package/dist/modules/billing/lib/money.js +47 -0
  101. package/dist/modules/billing/lib/money.js.map +7 -0
  102. package/dist/modules/billing/lib/prepaidConfig.js +45 -0
  103. package/dist/modules/billing/lib/prepaidConfig.js.map +7 -0
  104. package/dist/modules/billing/lib/prepaidConsume.js +214 -0
  105. package/dist/modules/billing/lib/prepaidConsume.js.map +7 -0
  106. package/dist/modules/billing/lib/prepaidPeriodClose.js +285 -0
  107. package/dist/modules/billing/lib/prepaidPeriodClose.js.map +7 -0
  108. package/dist/modules/billing/lib/topupCapture.js +62 -0
  109. package/dist/modules/billing/lib/topupCapture.js.map +7 -0
  110. package/dist/modules/billing/lib/topupReceipt.js +97 -0
  111. package/dist/modules/billing/lib/topupReceipt.js.map +7 -0
  112. package/dist/modules/billing/lib/topupTransition.js +19 -0
  113. package/dist/modules/billing/lib/topupTransition.js.map +7 -0
  114. package/dist/modules/billing/migrations/Migration20260619000000_billing_prepaid.js +110 -0
  115. package/dist/modules/billing/migrations/Migration20260619000000_billing_prepaid.js.map +7 -0
  116. package/dist/modules/billing/setup.js +32 -1
  117. package/dist/modules/billing/setup.js.map +2 -2
  118. package/dist/modules/billing/subscribers/prepaid-topup-cancelled.js +26 -0
  119. package/dist/modules/billing/subscribers/prepaid-topup-cancelled.js.map +7 -0
  120. package/dist/modules/billing/subscribers/prepaid-topup-captured.js +87 -0
  121. package/dist/modules/billing/subscribers/prepaid-topup-captured.js.map +7 -0
  122. package/dist/modules/billing/subscribers/prepaid-topup-expired.js +26 -0
  123. package/dist/modules/billing/subscribers/prepaid-topup-expired.js.map +7 -0
  124. package/dist/modules/billing/subscribers/prepaid-topup-failed.js +26 -0
  125. package/dist/modules/billing/subscribers/prepaid-topup-failed.js.map +7 -0
  126. package/dist/modules/billing/workers/reconcile-prepaid-balances.js +50 -0
  127. package/dist/modules/billing/workers/reconcile-prepaid-balances.js.map +7 -0
  128. package/package.json +9 -9
  129. package/src/modules/billing/__tests__/commands/invoices.test.ts +3 -3
  130. package/src/modules/billing/__tests__/commands/topups.test.ts +104 -0
  131. package/src/modules/billing/__tests__/commands/transactions.test.ts +107 -0
  132. package/src/modules/billing/__tests__/helpers/prepaidMockEm.ts +235 -0
  133. package/src/modules/billing/__tests__/lib/accountStatus.test.ts +93 -0
  134. package/src/modules/billing/__tests__/lib/balanceLedger.test.ts +125 -0
  135. package/src/modules/billing/__tests__/lib/balanceStatus.test.ts +65 -0
  136. package/src/modules/billing/__tests__/lib/creditStatus.test.ts +111 -0
  137. package/src/modules/billing/__tests__/lib/money.test.ts +56 -0
  138. package/src/modules/billing/__tests__/lib/prepaidConsume.test.ts +179 -0
  139. package/src/modules/billing/__tests__/lib/prepaidPeriodClose.test.ts +232 -0
  140. package/src/modules/billing/__tests__/lib/topupCapture.test.ts +123 -0
  141. package/src/modules/billing/__tests__/lib/topupReceipt.test.ts +84 -0
  142. package/src/modules/billing/__tests__/setup.test.ts +28 -2
  143. package/src/modules/billing/acl.ts +8 -0
  144. package/src/modules/billing/api/accounts/[id]/balance/route.ts +74 -0
  145. package/src/modules/billing/api/accounts/[id]/credit-status/route.ts +71 -0
  146. package/src/modules/billing/api/accounts/[id]/topups/route.ts +49 -0
  147. package/src/modules/billing/api/accounts/route.ts +7 -0
  148. package/src/modules/billing/api/export/account/[id]/route.ts +47 -2
  149. package/src/modules/billing/api/statements/generate/route.ts +78 -0
  150. package/src/modules/billing/api/statements/route.ts +117 -0
  151. package/src/modules/billing/api/topups/route.ts +154 -0
  152. package/src/modules/billing/api/transactions/adjust/route.ts +80 -0
  153. package/src/modules/billing/api/transactions/route.ts +116 -0
  154. package/src/modules/billing/api/usage/route.ts +36 -5
  155. package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +28 -0
  156. package/src/modules/billing/backend/billing/accounts/create/page.tsx +7 -0
  157. package/src/modules/billing/backend/billing/accounts/page.tsx +32 -1
  158. package/src/modules/billing/backend/billing/statements/[id]/page.meta.ts +19 -0
  159. package/src/modules/billing/backend/billing/statements/[id]/page.tsx +198 -0
  160. package/src/modules/billing/backend/billing/statements/page.meta.ts +16 -0
  161. package/src/modules/billing/backend/billing/statements/page.tsx +190 -0
  162. package/src/modules/billing/backend/billing/topups/[id]/page.meta.ts +19 -0
  163. package/src/modules/billing/backend/billing/topups/[id]/page.tsx +151 -0
  164. package/src/modules/billing/backend/billing/topups/page.meta.ts +16 -0
  165. package/src/modules/billing/backend/billing/topups/page.tsx +182 -0
  166. package/src/modules/billing/backend/billing/transactions/[id]/page.meta.ts +19 -0
  167. package/src/modules/billing/backend/billing/transactions/[id]/page.tsx +179 -0
  168. package/src/modules/billing/backend/billing/transactions/page.meta.ts +16 -0
  169. package/src/modules/billing/backend/billing/transactions/page.tsx +187 -0
  170. package/src/modules/billing/commands/accounts.ts +42 -1
  171. package/src/modules/billing/commands/index.ts +3 -0
  172. package/src/modules/billing/commands/invoices.ts +26 -2
  173. package/src/modules/billing/commands/statements.ts +101 -0
  174. package/src/modules/billing/commands/topups.ts +181 -0
  175. package/src/modules/billing/commands/transactions.ts +152 -0
  176. package/src/modules/billing/commands/usage.ts +114 -4
  177. package/src/modules/billing/components/AccountForm.tsx +66 -0
  178. package/src/modules/billing/components/PrepaidPanel.tsx +382 -0
  179. package/src/modules/billing/components/accountNames.ts +23 -0
  180. package/src/modules/billing/data/entities.ts +383 -0
  181. package/src/modules/billing/data/entityIds.ts +5 -0
  182. package/src/modules/billing/data/validators.ts +144 -0
  183. package/src/modules/billing/events.ts +52 -0
  184. package/src/modules/billing/i18n/en.json +112 -4
  185. package/src/modules/billing/i18n/pl.json +112 -4
  186. package/src/modules/billing/index.ts +1 -1
  187. package/src/modules/billing/lib/accountStatus.ts +155 -0
  188. package/src/modules/billing/lib/balanceEvents.ts +74 -0
  189. package/src/modules/billing/lib/balanceLedger.ts +258 -0
  190. package/src/modules/billing/lib/balanceStatus.ts +78 -0
  191. package/src/modules/billing/lib/billRunEngine.ts +66 -5
  192. package/src/modules/billing/lib/creditStatus.ts +153 -0
  193. package/src/modules/billing/lib/money.ts +73 -0
  194. package/src/modules/billing/lib/prepaidConfig.ts +58 -0
  195. package/src/modules/billing/lib/prepaidConsume.ts +299 -0
  196. package/src/modules/billing/lib/prepaidPeriodClose.ts +453 -0
  197. package/src/modules/billing/lib/topupCapture.ts +117 -0
  198. package/src/modules/billing/lib/topupReceipt.ts +153 -0
  199. package/src/modules/billing/lib/topupTransition.ts +31 -0
  200. package/src/modules/billing/migrations/Migration20260619000000_billing_prepaid.ts +131 -0
  201. package/src/modules/billing/setup.ts +45 -0
  202. package/src/modules/billing/subscribers/prepaid-topup-cancelled.ts +31 -0
  203. package/src/modules/billing/subscribers/prepaid-topup-captured.ts +120 -0
  204. package/src/modules/billing/subscribers/prepaid-topup-expired.ts +31 -0
  205. package/src/modules/billing/subscribers/prepaid-topup-failed.ts +32 -0
  206. package/src/modules/billing/workers/reconcile-prepaid-balances.ts +68 -0
@@ -13,6 +13,8 @@ import { Entity, Index, PrimaryKey, Property, Unique } from "@mikro-orm/decorato
13
13
  OptionalProps;
14
14
  let BillingAccount = class {
15
15
  constructor() {
16
+ this.billingMode = "postpaid";
17
+ this.creditLimit = "0";
16
18
  this.isActive = true;
17
19
  this.createdAt = /* @__PURE__ */ new Date();
18
20
  this.updatedAt = /* @__PURE__ */ new Date();
@@ -60,6 +62,12 @@ __decorateClass([
60
62
  __decorateClass([
61
63
  Property({ name: "last_bill_date", type: "date", columnType: "date", nullable: true })
62
64
  ], BillingAccount.prototype, "lastBillDate", 2);
65
+ __decorateClass([
66
+ Property({ name: "billing_mode", type: "text", default: "postpaid" })
67
+ ], BillingAccount.prototype, "billingMode", 2);
68
+ __decorateClass([
69
+ Property({ name: "credit_limit", type: "numeric", columnType: "numeric(18, 4)", default: "0" })
70
+ ], BillingAccount.prototype, "creditLimit", 2);
63
71
  __decorateClass([
64
72
  Property({ name: "is_active", type: "boolean", default: true })
65
73
  ], BillingAccount.prototype, "isActive", 2);
@@ -349,6 +357,9 @@ __decorateClass([
349
357
  __decorateClass([
350
358
  Property({ name: "draft_invoice_id", type: "uuid", nullable: true })
351
359
  ], BillRunOutcome.prototype, "draftInvoiceId", 2);
360
+ __decorateClass([
361
+ Property({ name: "statement_id", type: "uuid", nullable: true })
362
+ ], BillRunOutcome.prototype, "statementId", 2);
352
363
  __decorateClass([
353
364
  Property({ name: "is_active", type: "boolean", default: true })
354
365
  ], BillRunOutcome.prototype, "isActive", 2);
@@ -422,12 +433,291 @@ DraftInvoiceEdit = __decorateClass([
422
433
  properties: ["organizationId", "tenantId", "userId", "createdAt"]
423
434
  })
424
435
  ], DraftInvoiceEdit);
436
+ OptionalProps;
437
+ let BillingAccountBalance = class {
438
+ constructor() {
439
+ this.balance = "0";
440
+ this.createdAt = /* @__PURE__ */ new Date();
441
+ this.updatedAt = /* @__PURE__ */ new Date();
442
+ }
443
+ };
444
+ __decorateClass([
445
+ PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
446
+ ], BillingAccountBalance.prototype, "id", 2);
447
+ __decorateClass([
448
+ Property({ name: "organization_id", type: "uuid" })
449
+ ], BillingAccountBalance.prototype, "organizationId", 2);
450
+ __decorateClass([
451
+ Property({ name: "tenant_id", type: "uuid" })
452
+ ], BillingAccountBalance.prototype, "tenantId", 2);
453
+ __decorateClass([
454
+ Property({ name: "bill_account_id", type: "uuid" })
455
+ ], BillingAccountBalance.prototype, "billAccountId", 2);
456
+ __decorateClass([
457
+ Property({ name: "currency_code", type: "text" })
458
+ ], BillingAccountBalance.prototype, "currencyCode", 2);
459
+ __decorateClass([
460
+ Property({ name: "balance", type: "numeric", columnType: "numeric(18, 4)", default: "0" })
461
+ ], BillingAccountBalance.prototype, "balance", 2);
462
+ __decorateClass([
463
+ Property({
464
+ name: "low_balance_threshold",
465
+ type: "numeric",
466
+ columnType: "numeric(18, 4)",
467
+ nullable: true
468
+ })
469
+ ], BillingAccountBalance.prototype, "lowBalanceThreshold", 2);
470
+ __decorateClass([
471
+ Property({ name: "last_movement_at", type: Date, nullable: true })
472
+ ], BillingAccountBalance.prototype, "lastMovementAt", 2);
473
+ __decorateClass([
474
+ Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
475
+ ], BillingAccountBalance.prototype, "createdAt", 2);
476
+ __decorateClass([
477
+ Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
478
+ ], BillingAccountBalance.prototype, "updatedAt", 2);
479
+ BillingAccountBalance = __decorateClass([
480
+ Entity({ tableName: "billing_account_balances" }),
481
+ Unique({
482
+ name: "billing_account_balances_account_unique",
483
+ properties: ["tenantId", "billAccountId"]
484
+ }),
485
+ Index({
486
+ name: "billing_account_balances_balance_idx",
487
+ properties: ["organizationId", "tenantId", "balance"]
488
+ })
489
+ ], BillingAccountBalance);
490
+ OptionalProps;
491
+ let BillingAccountTransaction = class {
492
+ constructor() {
493
+ this.createdAt = /* @__PURE__ */ new Date();
494
+ }
495
+ };
496
+ __decorateClass([
497
+ PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
498
+ ], BillingAccountTransaction.prototype, "id", 2);
499
+ __decorateClass([
500
+ Property({ name: "organization_id", type: "uuid" })
501
+ ], BillingAccountTransaction.prototype, "organizationId", 2);
502
+ __decorateClass([
503
+ Property({ name: "tenant_id", type: "uuid" })
504
+ ], BillingAccountTransaction.prototype, "tenantId", 2);
505
+ __decorateClass([
506
+ Property({ name: "bill_account_id", type: "uuid" })
507
+ ], BillingAccountTransaction.prototype, "billAccountId", 2);
508
+ __decorateClass([
509
+ Property({ type: "text" })
510
+ ], BillingAccountTransaction.prototype, "type", 2);
511
+ __decorateClass([
512
+ Property({ type: "numeric", columnType: "numeric(18, 4)" })
513
+ ], BillingAccountTransaction.prototype, "amount", 2);
514
+ __decorateClass([
515
+ Property({ name: "currency_code", type: "text" })
516
+ ], BillingAccountTransaction.prototype, "currencyCode", 2);
517
+ __decorateClass([
518
+ Property({ name: "balance_after", type: "numeric", columnType: "numeric(18, 4)" })
519
+ ], BillingAccountTransaction.prototype, "balanceAfter", 2);
520
+ __decorateClass([
521
+ Property({ name: "usage_id", type: "uuid", nullable: true })
522
+ ], BillingAccountTransaction.prototype, "usageId", 2);
523
+ __decorateClass([
524
+ Property({ name: "billing_item_id", type: "uuid", nullable: true })
525
+ ], BillingAccountTransaction.prototype, "billingItemId", 2);
526
+ __decorateClass([
527
+ Property({ name: "topup_id", type: "uuid", nullable: true })
528
+ ], BillingAccountTransaction.prototype, "topupId", 2);
529
+ __decorateClass([
530
+ Property({ name: "statement_id", type: "uuid", nullable: true })
531
+ ], BillingAccountTransaction.prototype, "statementId", 2);
532
+ __decorateClass([
533
+ Property({ type: "text" })
534
+ ], BillingAccountTransaction.prototype, "description", 2);
535
+ __decorateClass([
536
+ Property({ name: "source_ref", type: "text", nullable: true })
537
+ ], BillingAccountTransaction.prototype, "sourceRef", 2);
538
+ __decorateClass([
539
+ Property({ type: "jsonb", nullable: true })
540
+ ], BillingAccountTransaction.prototype, "metadata", 2);
541
+ __decorateClass([
542
+ Property({ name: "user_id", type: "uuid", nullable: true })
543
+ ], BillingAccountTransaction.prototype, "userId", 2);
544
+ __decorateClass([
545
+ Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
546
+ ], BillingAccountTransaction.prototype, "createdAt", 2);
547
+ __decorateClass([
548
+ Property({ name: "deleted_at", type: Date, nullable: true })
549
+ ], BillingAccountTransaction.prototype, "deletedAt", 2);
550
+ BillingAccountTransaction = __decorateClass([
551
+ Entity({ tableName: "billing_account_transactions" }),
552
+ Unique({
553
+ name: "billing_account_transactions_source_ref_unique",
554
+ properties: ["tenantId", "billAccountId", "sourceRef"]
555
+ }),
556
+ Index({
557
+ name: "billing_account_transactions_history_idx",
558
+ properties: ["organizationId", "tenantId", "billAccountId", "createdAt"]
559
+ }),
560
+ Index({
561
+ name: "billing_account_transactions_account_type_idx",
562
+ properties: ["billAccountId", "type", "createdAt"]
563
+ })
564
+ ], BillingAccountTransaction);
565
+ OptionalProps;
566
+ let BillingTopup = class {
567
+ constructor() {
568
+ this.createdAt = /* @__PURE__ */ new Date();
569
+ this.updatedAt = /* @__PURE__ */ new Date();
570
+ }
571
+ };
572
+ __decorateClass([
573
+ PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
574
+ ], BillingTopup.prototype, "id", 2);
575
+ __decorateClass([
576
+ Property({ name: "organization_id", type: "uuid" })
577
+ ], BillingTopup.prototype, "organizationId", 2);
578
+ __decorateClass([
579
+ Property({ name: "tenant_id", type: "uuid" })
580
+ ], BillingTopup.prototype, "tenantId", 2);
581
+ __decorateClass([
582
+ Property({ name: "bill_account_id", type: "uuid" })
583
+ ], BillingTopup.prototype, "billAccountId", 2);
584
+ __decorateClass([
585
+ Property({ type: "text" })
586
+ ], BillingTopup.prototype, "status", 2);
587
+ __decorateClass([
588
+ Property({ type: "numeric", columnType: "numeric(18, 4)" })
589
+ ], BillingTopup.prototype, "amount", 2);
590
+ __decorateClass([
591
+ Property({ name: "currency_code", type: "text" })
592
+ ], BillingTopup.prototype, "currencyCode", 2);
593
+ __decorateClass([
594
+ Property({ name: "provider_key", type: "text" })
595
+ ], BillingTopup.prototype, "providerKey", 2);
596
+ __decorateClass([
597
+ Property({ name: "payment_id", type: "uuid" })
598
+ ], BillingTopup.prototype, "paymentId", 2);
599
+ __decorateClass([
600
+ Property({ name: "gateway_transaction_id", type: "uuid", nullable: true })
601
+ ], BillingTopup.prototype, "gatewayTransactionId", 2);
602
+ __decorateClass([
603
+ Property({ name: "transaction_id", type: "uuid", nullable: true })
604
+ ], BillingTopup.prototype, "transactionId", 2);
605
+ __decorateClass([
606
+ Property({ name: "receipt_invoice_id", type: "uuid", nullable: true })
607
+ ], BillingTopup.prototype, "receiptInvoiceId", 2);
608
+ __decorateClass([
609
+ Property({ name: "source_ref", type: "text", nullable: true })
610
+ ], BillingTopup.prototype, "sourceRef", 2);
611
+ __decorateClass([
612
+ Property({ type: "jsonb", nullable: true })
613
+ ], BillingTopup.prototype, "metadata", 2);
614
+ __decorateClass([
615
+ Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
616
+ ], BillingTopup.prototype, "createdAt", 2);
617
+ __decorateClass([
618
+ Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
619
+ ], BillingTopup.prototype, "updatedAt", 2);
620
+ __decorateClass([
621
+ Property({ name: "deleted_at", type: Date, nullable: true })
622
+ ], BillingTopup.prototype, "deletedAt", 2);
623
+ BillingTopup = __decorateClass([
624
+ Entity({ tableName: "billing_topups" }),
625
+ Unique({
626
+ name: "billing_topups_payment_id_unique",
627
+ properties: ["tenantId", "paymentId"]
628
+ }),
629
+ Index({
630
+ name: "billing_topups_account_history_idx",
631
+ properties: ["organizationId", "tenantId", "billAccountId", "createdAt"]
632
+ }),
633
+ Index({
634
+ name: "billing_topups_status_idx",
635
+ properties: ["tenantId", "status"]
636
+ })
637
+ ], BillingTopup);
638
+ OptionalProps;
639
+ let BillingStatement = class {
640
+ constructor() {
641
+ this.totalAdjustments = "0";
642
+ this.createdAt = /* @__PURE__ */ new Date();
643
+ this.updatedAt = /* @__PURE__ */ new Date();
644
+ }
645
+ };
646
+ __decorateClass([
647
+ PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
648
+ ], BillingStatement.prototype, "id", 2);
649
+ __decorateClass([
650
+ Property({ name: "organization_id", type: "uuid" })
651
+ ], BillingStatement.prototype, "organizationId", 2);
652
+ __decorateClass([
653
+ Property({ name: "tenant_id", type: "uuid" })
654
+ ], BillingStatement.prototype, "tenantId", 2);
655
+ __decorateClass([
656
+ Property({ name: "bill_account_id", type: "uuid" })
657
+ ], BillingStatement.prototype, "billAccountId", 2);
658
+ __decorateClass([
659
+ Property({ name: "bill_run_id", type: "uuid", nullable: true })
660
+ ], BillingStatement.prototype, "billRunId", 2);
661
+ __decorateClass([
662
+ Property({ name: "period_start", type: "date", columnType: "date" })
663
+ ], BillingStatement.prototype, "periodStart", 2);
664
+ __decorateClass([
665
+ Property({ name: "period_end", type: "date", columnType: "date" })
666
+ ], BillingStatement.prototype, "periodEnd", 2);
667
+ __decorateClass([
668
+ Property({ name: "currency_code", type: "text" })
669
+ ], BillingStatement.prototype, "currencyCode", 2);
670
+ __decorateClass([
671
+ Property({ name: "opening_balance", type: "numeric", columnType: "numeric(18, 4)" })
672
+ ], BillingStatement.prototype, "openingBalance", 2);
673
+ __decorateClass([
674
+ Property({ name: "total_topups", type: "numeric", columnType: "numeric(18, 4)" })
675
+ ], BillingStatement.prototype, "totalTopups", 2);
676
+ __decorateClass([
677
+ Property({ name: "total_usage", type: "numeric", columnType: "numeric(18, 4)" })
678
+ ], BillingStatement.prototype, "totalUsage", 2);
679
+ __decorateClass([
680
+ Property({ name: "total_recurring", type: "numeric", columnType: "numeric(18, 4)" })
681
+ ], BillingStatement.prototype, "totalRecurring", 2);
682
+ __decorateClass([
683
+ Property({ name: "total_adjustments", type: "numeric", columnType: "numeric(18, 4)", default: "0" })
684
+ ], BillingStatement.prototype, "totalAdjustments", 2);
685
+ __decorateClass([
686
+ Property({ name: "closing_balance", type: "numeric", columnType: "numeric(18, 4)" })
687
+ ], BillingStatement.prototype, "closingBalance", 2);
688
+ __decorateClass([
689
+ Property({ name: "debit_breakdown", type: "jsonb" })
690
+ ], BillingStatement.prototype, "debitBreakdown", 2);
691
+ __decorateClass([
692
+ Property({ type: "text" })
693
+ ], BillingStatement.prototype, "status", 2);
694
+ __decorateClass([
695
+ Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
696
+ ], BillingStatement.prototype, "createdAt", 2);
697
+ __decorateClass([
698
+ Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
699
+ ], BillingStatement.prototype, "updatedAt", 2);
700
+ BillingStatement = __decorateClass([
701
+ Entity({ tableName: "billing_statements" }),
702
+ Unique({
703
+ name: "billing_statements_period_unique",
704
+ properties: ["tenantId", "billAccountId", "periodStart", "periodEnd"]
705
+ }),
706
+ Index({
707
+ name: "billing_statements_account_period_idx",
708
+ properties: ["organizationId", "tenantId", "billAccountId", "periodEnd"]
709
+ })
710
+ ], BillingStatement);
425
711
  export {
426
712
  BillRun,
427
713
  BillRunOutcome,
428
714
  BillingAccount,
715
+ BillingAccountBalance,
716
+ BillingAccountTransaction,
429
717
  BillingAccountUsage,
430
718
  BillingItem,
719
+ BillingStatement,
720
+ BillingTopup,
431
721
  DraftInvoiceEdit
432
722
  };
433
723
  //# sourceMappingURL=entities.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/billing/data/entities.ts"],
4
- "sourcesContent": ["import { OptionalProps } from '@mikro-orm/core'\nimport { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n// \u2500\u2500\u2500 BillingAccount \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A container per customer (typically one customer = one account, but the\n// engine does not enforce uniqueness \u2014 multi-account-per-customer is a\n// legitimate model for B2B with separate budgets / currencies / branches).\n//\n// The `(organization_id, tenant_id, next_bill_date)` partial index is the\n// Bill Run hot path \u2014 every nightly run filters by tenant + org and orders\n// by next_bill_date. Multi-org tenants share `tenant_id` across orgs, so a\n// `(tenant_id, next_bill_date)`-only index would scan every other org's\n// rows for each tenant \u2014 fine at 1 org / tenant, painful at 50.\n\n@Entity({ tableName: 'billing_accounts' })\n@Index({\n name: 'billing_accounts_next_bill_date_idx',\n properties: ['organizationId', 'tenantId', 'nextBillDate'],\n expression:\n 'CREATE INDEX \"billing_accounts_next_bill_date_idx\" ON \"billing_accounts\" (\"organization_id\", \"tenant_id\", \"next_bill_date\") WHERE \"deleted_at\" IS NULL',\n})\n@Index({\n name: 'billing_accounts_customer_idx',\n properties: ['organizationId', 'tenantId', 'customerId'],\n})\n@Index({\n name: 'billing_accounts_sort_idx',\n properties: ['organizationId', 'tenantId', 'deletedAt', 'createdAt'],\n})\nexport class BillingAccount {\n [OptionalProps]?:\n | 'taxId'\n | 'lastBillDate'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // String FK to customers.person.id (or any external customer system).\n // Kept as text so the package stays installable without the customers\n // module \u2014 see SPEC-001 cross-package data rule.\n @Property({ name: 'customer_id', type: 'text' })\n customerId!: string\n\n @Property({ type: 'text' })\n name!: string\n\n // ISO 4217 currency code. An account is single-currency by design \u2014\n // multi-currency = multiple accounts.\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n // 'monthly' | 'quarterly' | 'annually' | 'weekly'. Validated at API ingress.\n @Property({ name: 'bill_cycle', type: 'text' })\n billCycle!: string\n\n // Day-of-month for monthly/quarterly/annually (1\u201328), or weekday code\n // ('mon'\u2026'sun') for weekly. Text so both shapes coexist.\n @Property({ name: 'bill_cycle_anchor', type: 'text' })\n billCycleAnchor!: string\n\n @Property({ name: 'invoice_email', type: 'text' })\n invoiceEmail!: string\n\n // ISO 639-1 (`en`, `pl`, \u2026). Used by mailer / template renderer.\n @Property({ name: 'invoice_language', type: 'text' })\n invoiceLanguage!: string\n\n // NIP / VATIN / TaxID. Nullable for individuals without a registered tax ID.\n @Property({ name: 'tax_id', type: 'text', nullable: true })\n taxId?: string | null\n\n // { line1, line2?, city, postal_code, country } \u2014 JSONB because address\n // shape differs across countries and we never query by address fields.\n @Property({ name: 'invoice_address', type: 'jsonb' })\n invoiceAddress!: Record<string, unknown>\n\n // Anchor of the NEXT bill period to be processed (advanced by Bill Run\n // on success). Date-only \u2014 calendar-aware cycle arithmetic.\n @Property({ name: 'next_bill_date', type: 'date', columnType: 'date' })\n nextBillDate!: Date\n\n // Anchor of the most recently billed period; null for fresh accounts.\n @Property({ name: 'last_bill_date', type: 'date', columnType: 'date', nullable: true })\n lastBillDate?: Date | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingItem \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A single line that will appear on an invoice. Three flavours:\n// `one_time` / `recurring` / `usage` \u2014 see rate_json shape per type in\n// data/validators.ts.\n//\n// `(tenant_id, bill_account_id, source_ref)` is unique for idempotency.\n// Postgres treats NULLs as distinct, so items without a source_ref do not\n// conflict \u2014 that is intentional (CSV imports / manual entries).\n\n@Entity({ tableName: 'billing_items' })\n@Unique({\n name: 'billing_items_source_ref_unique',\n properties: ['tenantId', 'billAccountId', 'sourceRef'],\n})\n@Index({\n name: 'billing_items_account_type_idx',\n properties: ['billAccountId', 'type'],\n})\n@Index({\n name: 'billing_items_account_active_idx',\n properties: ['billAccountId', 'type', 'isActive'],\n expression:\n 'CREATE INDEX \"billing_items_account_active_idx\" ON \"billing_items\" (\"bill_account_id\", \"type\", \"is_active\") WHERE \"deleted_at\" IS NULL',\n})\n@Index({\n name: 'billing_items_subscription_idx',\n properties: ['organizationId', 'tenantId', 'subscriptionId'],\n})\nexport class BillingItem {\n [OptionalProps]?:\n | 'billEndDate'\n | 'uomCode'\n | 'subscriptionId'\n | 'subscriptionItemId'\n | 'sourceRef'\n | 'currencyMismatch'\n | 'billedToDate'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // FK string to BillingAccount.id (intra-module; no ORM relation kept to\n // avoid coupling \u2014 we resolve at runtime).\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // 'one_time' | 'recurring' | 'usage'.\n @Property({ type: 'text' })\n type!: string\n\n @Property({ name: 'bill_start_date', type: 'date', columnType: 'date' })\n billStartDate!: Date\n\n // Null = open-ended (typical for ongoing recurring items).\n @Property({ name: 'bill_end_date', type: 'date', columnType: 'date', nullable: true })\n billEndDate?: Date | null\n\n @Property({ type: 'text' })\n description!: string\n\n // Pricing definition. Shape validated by Zod per `type`; see\n // data/validators.ts.\n @Property({ name: 'rate_json', type: 'jsonb' })\n rateJson!: Record<string, unknown>\n\n // Required for type='usage' (must match a Usage record's uom_code\n // exactly \u2014 no conversion). Ignored for other types.\n @Property({ name: 'uom_code', type: 'text', nullable: true })\n uomCode?: string | null\n\n // String FK to upstream subscription (e.g. CPQ's\n // cpq_inventory_subscriptions.id). Null for CSV / manual / non-subscription\n // contexts.\n @Property({ name: 'subscription_id', type: 'text', nullable: true })\n subscriptionId?: string | null\n\n @Property({ name: 'subscription_item_id', type: 'text', nullable: true })\n subscriptionItemId?: string | null\n\n // Idempotency key \u2014 duplicate POST returns the existing row.\n @Property({ name: 'source_ref', type: 'text', nullable: true })\n sourceRef?: string | null\n\n // Set when the integrator POSTed a value in a different currency than the\n // account's currency_code. Operator sees a warning on the draft.\n @Property({ name: 'currency_mismatch', type: 'boolean', default: false })\n currencyMismatch: boolean = false\n\n // Anti-double-bill guard at the item level \u2014 see spec\n // \"Why two anti-duplicate guards\".\n @Property({ name: 'billed_to_date', type: 'date', columnType: 'date', nullable: true })\n billedToDate?: Date | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingAccountUsage \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Bucket for pre-aggregated usage uploaded by external systems. The\n// selection index `(bill_account_id, uom_code, rated_in_bill_run_id,\n// period_end)` matches the Bill Run \"find unrated records\" predicate\n// exactly \u2014 keep it in sync if that predicate changes.\n\n@Entity({ tableName: 'billing_account_usage' })\n@Unique({\n name: 'billing_account_usage_source_ref_unique',\n properties: ['tenantId', 'billAccountId', 'sourceRef'],\n})\n@Index({\n name: 'billing_account_usage_rating_idx',\n properties: ['billAccountId', 'uomCode', 'ratedInBillRunId', 'periodEnd'],\n})\nexport class BillingAccountUsage {\n [OptionalProps]?:\n | 'lineDescription'\n | 'sourceRef'\n | 'ratedInBillRunId'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // Must match the `uom_code` on a corresponding `type='usage'` Billing Item.\n @Property({ name: 'uom_code', type: 'text' })\n uomCode!: string\n\n // numeric(18,4) \u2192 string in app code (standard MikroORM numeric handling).\n @Property({ type: 'numeric', columnType: 'numeric(18, 4)' })\n quantity!: string\n\n @Property({ name: 'period_start', type: Date })\n periodStart!: Date\n\n @Property({ name: 'period_end', type: Date })\n periodEnd!: Date\n\n // Optional per-record description. When set, Bill Run emits one invoice\n // line per Usage record with this description. When null, the run\n // aggregates all matching Usage records into a single line using the\n // Billing Item's `description`.\n @Property({ name: 'line_description', type: 'text', nullable: true })\n lineDescription?: string | null\n\n @Property({ name: 'source_ref', type: 'text', nullable: true })\n sourceRef?: string | null\n\n // Set when consumed; prevents double-rating on retry.\n @Property({ name: 'rated_in_bill_run_id', type: 'uuid', nullable: true })\n ratedInBillRunId?: string | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillRun \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A single execution of the engine \u2014 one row per trigger (schedule or\n// manual). The concurrency lock is a Postgres transaction-scoped advisory\n// lock keyed by hash(tenant_id || 'billing-run'); it is NOT stored on this\n// row. Crash recovery for zombie `status='running'` rows is handled by\n// workers/reap-stale-bill-runs.ts.\n\n@Entity({ tableName: 'billing_runs' })\n@Index({\n name: 'billing_runs_tenant_status_idx',\n properties: ['tenantId', 'status', 'startedAt'],\n})\n@Index({\n name: 'billing_runs_parent_idx',\n properties: ['parentRunId'],\n})\nexport class BillRun {\n [OptionalProps]?:\n | 'parentRunId'\n | 'dryRun'\n | 'testMode'\n | 'catchUp'\n | 'scopedAccountIds'\n | 'startedAt'\n | 'finishedAt'\n | 'summary'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // 'schedule' | 'manual'.\n @Property({ name: 'triggered_by', type: 'text' })\n triggeredBy!: string\n\n // Set when this run is a \"retry failed\" of a previous run.\n @Property({ name: 'parent_run_id', type: 'uuid', nullable: true })\n parentRunId?: string | null\n\n // True \u2192 compute everything but persist nothing (preview).\n @Property({ name: 'dry_run', type: 'boolean', default: false })\n dryRun: boolean = false\n\n // True \u2192 persist drafts flagged as test, but do not advance state.\n @Property({ name: 'test_mode', type: 'boolean', default: false })\n testMode: boolean = false\n\n // True \u2192 loop missed cycles per account in one run (manual only).\n @Property({ name: 'catch_up', type: 'boolean', default: false })\n catchUp: boolean = false\n\n // Optional \u2014 run processes only these accounts when set. JSONB\n // (Postgres arrays would work too, but jsonb keeps tooling uniform\n // across this package).\n @Property({ name: 'scoped_account_ids', type: 'jsonb', nullable: true })\n scopedAccountIds?: string[] | null\n\n // The \"today\" the run uses to evaluate `next_bill_date <= as_of_date`.\n @Property({ name: 'as_of_date', type: 'date', columnType: 'date' })\n asOfDate!: Date\n\n @Property({ name: 'started_at', type: Date, nullable: true })\n startedAt?: Date | null\n\n @Property({ name: 'finished_at', type: Date, nullable: true })\n finishedAt?: Date | null\n\n // 'running' | 'completed' | 'partial_failure' | 'failed'.\n @Property({ type: 'text' })\n status!: string\n\n // { accounts_processed, drafts_created, drafts_skipped_existing,\n // accounts_failed, accounts_with_warnings, usage_records_rated }\n @Property({ type: 'jsonb', nullable: true })\n summary?: Record<string, unknown> | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillRunOutcome \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Per-account outcome of a Bill Run. Stored in its own table (not as a\n// JSONB array on BillRun.summary) so operators can query failures across\n// runs without jsonb_array_elements gymnastics. See spec rationale.\n\n@Entity({ tableName: 'billing_run_outcomes' })\n@Index({\n name: 'billing_run_outcomes_run_status_idx',\n properties: ['billRunId', 'status'],\n})\n@Index({\n name: 'billing_run_outcomes_account_history_idx',\n properties: ['organizationId', 'tenantId', 'billAccountId', 'createdAt'],\n})\nexport class BillRunOutcome {\n [OptionalProps]?:\n | 'errorMessage'\n | 'warnings'\n | 'draftInvoiceId'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_run_id', type: 'uuid' })\n billRunId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // 'success' | 'success_with_warnings' | 'skipped_existing_draft' | 'failed'.\n @Property({ type: 'text' })\n status!: string\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n // E.g. `{ unmatched_usage_uoms: [\"api_request\"] }`.\n @Property({ type: 'jsonb', nullable: true })\n warnings?: Record<string, unknown> | null\n\n // FK string to the core/sales invoice (drafted by the run). Null when\n // the run skipped (status='skipped_existing_draft' or 'failed').\n @Property({ name: 'draft_invoice_id', type: 'uuid', nullable: true })\n draftInvoiceId?: string | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 DraftInvoiceEdit (audit) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Append-only audit of every operator edit on a draft invoice line.\n// Pattern mirrors `cpq_subscription_change_logs` \u2014 minimal columns\n// (no updated_at / is_active), append-only, soft-delete reserved for\n// compliance erasure only.\n\n@Entity({ tableName: 'billing_draft_invoice_edits' })\n@Index({\n name: 'billing_draft_invoice_edits_invoice_idx',\n properties: ['organizationId', 'tenantId', 'invoiceId', 'createdAt'],\n})\n@Index({\n name: 'billing_draft_invoice_edits_user_idx',\n properties: ['organizationId', 'tenantId', 'userId', 'createdAt'],\n})\nexport class DraftInvoiceEdit {\n [OptionalProps]?: 'invoiceLineId' | 'beforeJson' | 'afterJson' | 'createdAt' | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // FK string to the core/sales invoice (no ORM relation across packages).\n @Property({ name: 'invoice_id', type: 'uuid' })\n invoiceId!: string\n\n // Null for `line_added` / `line_removed` actions whose target line does\n // not yet (or no longer) exist on the invoice.\n @Property({ name: 'invoice_line_id', type: 'uuid', nullable: true })\n invoiceLineId?: string | null\n\n @Property({ name: 'user_id', type: 'uuid' })\n userId!: string\n\n // 'line_added' | 'line_removed' | 'line_edited'.\n @Property({ type: 'text' })\n action!: string\n\n // Snapshot before the edit. Null for `line_added` (no prior state).\n @Property({ name: 'before_json', type: 'jsonb', nullable: true })\n beforeJson?: Record<string, unknown> | null\n\n // Snapshot after the edit. Null for `line_removed` (no resulting state).\n @Property({ name: 'after_json', type: 'jsonb', nullable: true })\n afterJson?: Record<string, unknown> | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n // Reserved for compliance erasure only; runtime never deletes audit rows\n // through normal flows.\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n"],
5
- "mappings": ";;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AA8BzD;AADI,IAAM,iBAAN,MAAqB;AAAA,EAArB;AAmEL,oBAAoB;AAGpB,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AAnEE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ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MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GANxC,iBAOX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GATlC,iBAUX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,OAAO,CAAC;AAAA,GAbnC,iBAcX;AAKA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAlBxD,iBAmBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,WAAW,MAAM,OAAO,CAAC;AAAA,GArBhC,iBAsBX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAzBf,iBA0BX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,eAAe,MAAM,SAAS,UAAU,KAAK,CAAC;AAAA,GA7BrD,iBA8BX;AAIA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,SAAS,UAAU,KAAK,CAAC;AAAA,GAjCpD,iBAkCX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GApC7D,iBAqCX;AAKA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,KAAK,CAAC;AAAA,GAzCjD,iBA0CX;AA1CW,mBAAN;AAAA,EATN,OAAO,EAAE,WAAW,8BAA8B,CAAC;AAAA,EACnD,MAAM;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,kBAAkB,YAAY,aAAa,WAAW;AAAA,EACrE,CAAC;AAAA,EACA,MAAM;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,kBAAkB,YAAY,UAAU,WAAW;AAAA,EAClE,CAAC;AAAA,GACY;",
4
+ "sourcesContent": ["import { OptionalProps } from '@mikro-orm/core'\nimport { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n// \u2500\u2500\u2500 BillingAccount \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A container per customer (typically one customer = one account, but the\n// engine does not enforce uniqueness \u2014 multi-account-per-customer is a\n// legitimate model for B2B with separate budgets / currencies / branches).\n//\n// The `(organization_id, tenant_id, next_bill_date)` partial index is the\n// Bill Run hot path \u2014 every nightly run filters by tenant + org and orders\n// by next_bill_date. Multi-org tenants share `tenant_id` across orgs, so a\n// `(tenant_id, next_bill_date)`-only index would scan every other org's\n// rows for each tenant \u2014 fine at 1 org / tenant, painful at 50.\n\n@Entity({ tableName: 'billing_accounts' })\n@Index({\n name: 'billing_accounts_next_bill_date_idx',\n properties: ['organizationId', 'tenantId', 'nextBillDate'],\n expression:\n 'CREATE INDEX \"billing_accounts_next_bill_date_idx\" ON \"billing_accounts\" (\"organization_id\", \"tenant_id\", \"next_bill_date\") WHERE \"deleted_at\" IS NULL',\n})\n@Index({\n name: 'billing_accounts_customer_idx',\n properties: ['organizationId', 'tenantId', 'customerId'],\n})\n@Index({\n name: 'billing_accounts_sort_idx',\n properties: ['organizationId', 'tenantId', 'deletedAt', 'createdAt'],\n})\nexport class BillingAccount {\n [OptionalProps]?:\n | 'taxId'\n | 'lastBillDate'\n | 'billingMode'\n | 'creditLimit'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // String FK to customers.person.id (or any external customer system).\n // Kept as text so the package stays installable without the customers\n // module \u2014 see SPEC-001 cross-package data rule.\n @Property({ name: 'customer_id', type: 'text' })\n customerId!: string\n\n @Property({ type: 'text' })\n name!: string\n\n // ISO 4217 currency code. An account is single-currency by design \u2014\n // multi-currency = multiple accounts.\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n // 'monthly' | 'quarterly' | 'annually' | 'weekly'. Validated at API ingress.\n @Property({ name: 'bill_cycle', type: 'text' })\n billCycle!: string\n\n // Day-of-month for monthly/quarterly/annually (1\u201328), or weekday code\n // ('mon'\u2026'sun') for weekly. Text so both shapes coexist.\n @Property({ name: 'bill_cycle_anchor', type: 'text' })\n billCycleAnchor!: string\n\n @Property({ name: 'invoice_email', type: 'text' })\n invoiceEmail!: string\n\n // ISO 639-1 (`en`, `pl`, \u2026). Used by mailer / template renderer.\n @Property({ name: 'invoice_language', type: 'text' })\n invoiceLanguage!: string\n\n // NIP / VATIN / TaxID. Nullable for individuals without a registered tax ID.\n @Property({ name: 'tax_id', type: 'text', nullable: true })\n taxId?: string | null\n\n // { line1, line2?, city, postal_code, country } \u2014 JSONB because address\n // shape differs across countries and we never query by address fields.\n @Property({ name: 'invoice_address', type: 'jsonb' })\n invoiceAddress!: Record<string, unknown>\n\n // Anchor of the NEXT bill period to be processed (advanced by Bill Run\n // on success). Date-only \u2014 calendar-aware cycle arithmetic.\n @Property({ name: 'next_bill_date', type: 'date', columnType: 'date' })\n nextBillDate!: Date\n\n // Anchor of the most recently billed period; null for fresh accounts.\n @Property({ name: 'last_bill_date', type: 'date', columnType: 'date', nullable: true })\n lastBillDate?: Date | null\n\n // Billing mode \u2014 'postpaid' (default; the shipped Bill Run \u2192 draft \u2192\n // post flow) or 'prepaid' (top up a balance, draw it down in real time;\n // SPEC-002). Immutable after create (like currency_code); validated at\n // API ingress. Existing rows default to postpaid \u2014 zero behavior change.\n @Property({ name: 'billing_mode', type: 'text', default: 'postpaid' })\n billingMode: string = 'postpaid'\n\n // Credit line extended to this customer (both modes). Prepaid: permitted\n // overdraft below zero. Postpaid: max outstanding AR exposure. `0` = no\n // credit. Reported, never enforced by billing (SPEC-002 assumption #11).\n @Property({ name: 'credit_limit', type: 'numeric', columnType: 'numeric(18, 4)', default: '0' })\n creditLimit: string = '0'\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingItem \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A single line that will appear on an invoice. Three flavours:\n// `one_time` / `recurring` / `usage` \u2014 see rate_json shape per type in\n// data/validators.ts.\n//\n// `(tenant_id, bill_account_id, source_ref)` is unique for idempotency.\n// Postgres treats NULLs as distinct, so items without a source_ref do not\n// conflict \u2014 that is intentional (CSV imports / manual entries).\n\n@Entity({ tableName: 'billing_items' })\n@Unique({\n name: 'billing_items_source_ref_unique',\n properties: ['tenantId', 'billAccountId', 'sourceRef'],\n})\n@Index({\n name: 'billing_items_account_type_idx',\n properties: ['billAccountId', 'type'],\n})\n@Index({\n name: 'billing_items_account_active_idx',\n properties: ['billAccountId', 'type', 'isActive'],\n expression:\n 'CREATE INDEX \"billing_items_account_active_idx\" ON \"billing_items\" (\"bill_account_id\", \"type\", \"is_active\") WHERE \"deleted_at\" IS NULL',\n})\n@Index({\n name: 'billing_items_subscription_idx',\n properties: ['organizationId', 'tenantId', 'subscriptionId'],\n})\nexport class BillingItem {\n [OptionalProps]?:\n | 'billEndDate'\n | 'uomCode'\n | 'subscriptionId'\n | 'subscriptionItemId'\n | 'sourceRef'\n | 'currencyMismatch'\n | 'billedToDate'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // FK string to BillingAccount.id (intra-module; no ORM relation kept to\n // avoid coupling \u2014 we resolve at runtime).\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // 'one_time' | 'recurring' | 'usage'.\n @Property({ type: 'text' })\n type!: string\n\n @Property({ name: 'bill_start_date', type: 'date', columnType: 'date' })\n billStartDate!: Date\n\n // Null = open-ended (typical for ongoing recurring items).\n @Property({ name: 'bill_end_date', type: 'date', columnType: 'date', nullable: true })\n billEndDate?: Date | null\n\n @Property({ type: 'text' })\n description!: string\n\n // Pricing definition. Shape validated by Zod per `type`; see\n // data/validators.ts.\n @Property({ name: 'rate_json', type: 'jsonb' })\n rateJson!: Record<string, unknown>\n\n // Required for type='usage' (must match a Usage record's uom_code\n // exactly \u2014 no conversion). Ignored for other types.\n @Property({ name: 'uom_code', type: 'text', nullable: true })\n uomCode?: string | null\n\n // String FK to upstream subscription (e.g. CPQ's\n // cpq_inventory_subscriptions.id). Null for CSV / manual / non-subscription\n // contexts.\n @Property({ name: 'subscription_id', type: 'text', nullable: true })\n subscriptionId?: string | null\n\n @Property({ name: 'subscription_item_id', type: 'text', nullable: true })\n subscriptionItemId?: string | null\n\n // Idempotency key \u2014 duplicate POST returns the existing row.\n @Property({ name: 'source_ref', type: 'text', nullable: true })\n sourceRef?: string | null\n\n // Set when the integrator POSTed a value in a different currency than the\n // account's currency_code. Operator sees a warning on the draft.\n @Property({ name: 'currency_mismatch', type: 'boolean', default: false })\n currencyMismatch: boolean = false\n\n // Anti-double-bill guard at the item level \u2014 see spec\n // \"Why two anti-duplicate guards\".\n @Property({ name: 'billed_to_date', type: 'date', columnType: 'date', nullable: true })\n billedToDate?: Date | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingAccountUsage \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Bucket for pre-aggregated usage uploaded by external systems. The\n// selection index `(bill_account_id, uom_code, rated_in_bill_run_id,\n// period_end)` matches the Bill Run \"find unrated records\" predicate\n// exactly \u2014 keep it in sync if that predicate changes.\n\n@Entity({ tableName: 'billing_account_usage' })\n@Unique({\n name: 'billing_account_usage_source_ref_unique',\n properties: ['tenantId', 'billAccountId', 'sourceRef'],\n})\n@Index({\n name: 'billing_account_usage_rating_idx',\n properties: ['billAccountId', 'uomCode', 'ratedInBillRunId', 'periodEnd'],\n})\nexport class BillingAccountUsage {\n [OptionalProps]?:\n | 'lineDescription'\n | 'sourceRef'\n | 'ratedInBillRunId'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // Must match the `uom_code` on a corresponding `type='usage'` Billing Item.\n @Property({ name: 'uom_code', type: 'text' })\n uomCode!: string\n\n // numeric(18,4) \u2192 string in app code (standard MikroORM numeric handling).\n @Property({ type: 'numeric', columnType: 'numeric(18, 4)' })\n quantity!: string\n\n @Property({ name: 'period_start', type: Date })\n periodStart!: Date\n\n @Property({ name: 'period_end', type: Date })\n periodEnd!: Date\n\n // Optional per-record description. When set, Bill Run emits one invoice\n // line per Usage record with this description. When null, the run\n // aggregates all matching Usage records into a single line using the\n // Billing Item's `description`.\n @Property({ name: 'line_description', type: 'text', nullable: true })\n lineDescription?: string | null\n\n @Property({ name: 'source_ref', type: 'text', nullable: true })\n sourceRef?: string | null\n\n // Set when consumed; prevents double-rating on retry.\n @Property({ name: 'rated_in_bill_run_id', type: 'uuid', nullable: true })\n ratedInBillRunId?: string | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillRun \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A single execution of the engine \u2014 one row per trigger (schedule or\n// manual). The concurrency lock is a Postgres transaction-scoped advisory\n// lock keyed by hash(tenant_id || 'billing-run'); it is NOT stored on this\n// row. Crash recovery for zombie `status='running'` rows is handled by\n// workers/reap-stale-bill-runs.ts.\n\n@Entity({ tableName: 'billing_runs' })\n@Index({\n name: 'billing_runs_tenant_status_idx',\n properties: ['tenantId', 'status', 'startedAt'],\n})\n@Index({\n name: 'billing_runs_parent_idx',\n properties: ['parentRunId'],\n})\nexport class BillRun {\n [OptionalProps]?:\n | 'parentRunId'\n | 'dryRun'\n | 'testMode'\n | 'catchUp'\n | 'scopedAccountIds'\n | 'startedAt'\n | 'finishedAt'\n | 'summary'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // 'schedule' | 'manual'.\n @Property({ name: 'triggered_by', type: 'text' })\n triggeredBy!: string\n\n // Set when this run is a \"retry failed\" of a previous run.\n @Property({ name: 'parent_run_id', type: 'uuid', nullable: true })\n parentRunId?: string | null\n\n // True \u2192 compute everything but persist nothing (preview).\n @Property({ name: 'dry_run', type: 'boolean', default: false })\n dryRun: boolean = false\n\n // True \u2192 persist drafts flagged as test, but do not advance state.\n @Property({ name: 'test_mode', type: 'boolean', default: false })\n testMode: boolean = false\n\n // True \u2192 loop missed cycles per account in one run (manual only).\n @Property({ name: 'catch_up', type: 'boolean', default: false })\n catchUp: boolean = false\n\n // Optional \u2014 run processes only these accounts when set. JSONB\n // (Postgres arrays would work too, but jsonb keeps tooling uniform\n // across this package).\n @Property({ name: 'scoped_account_ids', type: 'jsonb', nullable: true })\n scopedAccountIds?: string[] | null\n\n // The \"today\" the run uses to evaluate `next_bill_date <= as_of_date`.\n @Property({ name: 'as_of_date', type: 'date', columnType: 'date' })\n asOfDate!: Date\n\n @Property({ name: 'started_at', type: Date, nullable: true })\n startedAt?: Date | null\n\n @Property({ name: 'finished_at', type: Date, nullable: true })\n finishedAt?: Date | null\n\n // 'running' | 'completed' | 'partial_failure' | 'failed'.\n @Property({ type: 'text' })\n status!: string\n\n // { accounts_processed, drafts_created, drafts_skipped_existing,\n // accounts_failed, accounts_with_warnings, usage_records_rated }\n @Property({ type: 'jsonb', nullable: true })\n summary?: Record<string, unknown> | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillRunOutcome \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Per-account outcome of a Bill Run. Stored in its own table (not as a\n// JSONB array on BillRun.summary) so operators can query failures across\n// runs without jsonb_array_elements gymnastics. See spec rationale.\n\n@Entity({ tableName: 'billing_run_outcomes' })\n@Index({\n name: 'billing_run_outcomes_run_status_idx',\n properties: ['billRunId', 'status'],\n})\n@Index({\n name: 'billing_run_outcomes_account_history_idx',\n properties: ['organizationId', 'tenantId', 'billAccountId', 'createdAt'],\n})\nexport class BillRunOutcome {\n [OptionalProps]?:\n | 'errorMessage'\n | 'warnings'\n | 'draftInvoiceId'\n | 'statementId'\n | 'isActive'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_run_id', type: 'uuid' })\n billRunId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // 'success' | 'success_with_warnings' | 'skipped_existing_draft' | 'failed'.\n @Property({ type: 'text' })\n status!: string\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n // E.g. `{ unmatched_usage_uoms: [\"api_request\"] }`.\n @Property({ type: 'jsonb', nullable: true })\n warnings?: Record<string, unknown> | null\n\n // FK string to the core/sales invoice (drafted by the run). Null when\n // the run skipped (status='skipped_existing_draft' or 'failed').\n @Property({ name: 'draft_invoice_id', type: 'uuid', nullable: true })\n draftInvoiceId?: string | null\n\n // FK (string) to the BillingStatement produced for a PREPAID account\n // (SPEC-002). Prepaid accounts get a statement instead of a draft invoice\n // at period close, so this is the prepaid analogue of `draft_invoice_id`.\n @Property({ name: 'statement_id', type: 'uuid', nullable: true })\n statementId?: string | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 DraftInvoiceEdit (audit) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Append-only audit of every operator edit on a draft invoice line.\n// Pattern mirrors `cpq_subscription_change_logs` \u2014 minimal columns\n// (no updated_at / is_active), append-only, soft-delete reserved for\n// compliance erasure only.\n\n@Entity({ tableName: 'billing_draft_invoice_edits' })\n@Index({\n name: 'billing_draft_invoice_edits_invoice_idx',\n properties: ['organizationId', 'tenantId', 'invoiceId', 'createdAt'],\n})\n@Index({\n name: 'billing_draft_invoice_edits_user_idx',\n properties: ['organizationId', 'tenantId', 'userId', 'createdAt'],\n})\nexport class DraftInvoiceEdit {\n [OptionalProps]?: 'invoiceLineId' | 'beforeJson' | 'afterJson' | 'createdAt' | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // FK string to the core/sales invoice (no ORM relation across packages).\n @Property({ name: 'invoice_id', type: 'uuid' })\n invoiceId!: string\n\n // Null for `line_added` / `line_removed` actions whose target line does\n // not yet (or no longer) exist on the invoice.\n @Property({ name: 'invoice_line_id', type: 'uuid', nullable: true })\n invoiceLineId?: string | null\n\n @Property({ name: 'user_id', type: 'uuid' })\n userId!: string\n\n // 'line_added' | 'line_removed' | 'line_edited'.\n @Property({ type: 'text' })\n action!: string\n\n // Snapshot before the edit. Null for `line_added` (no prior state).\n @Property({ name: 'before_json', type: 'jsonb', nullable: true })\n beforeJson?: Record<string, unknown> | null\n\n // Snapshot after the edit. Null for `line_removed` (no resulting state).\n @Property({ name: 'after_json', type: 'jsonb', nullable: true })\n afterJson?: Record<string, unknown> | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n // Reserved for compliance erasure only; runtime never deletes audit rows\n // through normal flows.\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingAccountBalance (SPEC-002) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// The denormalized running balance for a prepaid account \u2014 exactly one\n// row per prepaid account. It is the O(1) read AND the row the atomic\n// `UPDATE \u2026 RETURNING` debit/credit locks, which is why the balance is\n// NOT a column on `billing_accounts`: the high-write balance update never\n// touches the account row that the Bill Run hot-path index sits on.\n//\n// `balance` is the cache; the source of truth is\n// `SUM(billing_account_transactions.amount)`. The reconciliation invariant\n// `balance == SUM(amount) == latest.balance_after` is unit-tested.\n\n@Entity({ tableName: 'billing_account_balances' })\n@Unique({\n name: 'billing_account_balances_account_unique',\n properties: ['tenantId', 'billAccountId'],\n})\n@Index({\n name: 'billing_account_balances_balance_idx',\n properties: ['organizationId', 'tenantId', 'balance'],\n})\nexport class BillingAccountBalance {\n [OptionalProps]?:\n | 'lowBalanceThreshold'\n | 'lastMovementAt'\n | 'createdAt'\n | 'updatedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n // Unique FK (string) to BillingAccount.id \u2014 one balance per account.\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // Denormalized from the account so the balance row is self-contained.\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n // Running balance. May be NEGATIVE (usage is never rejected). Maintained\n // exclusively by the atomic `UPDATE \u2026 RETURNING` in lib/balanceLedger.ts.\n @Property({ name: 'balance', type: 'numeric', columnType: 'numeric(18, 4)', default: '0' })\n balance: string = '0'\n\n // When `balance <= threshold` \u2192 status `low` + `billing.balance.low`.\n // Null = use the tenant config default\n // (`billing.prepaid.low_balance_threshold_default`).\n @Property({\n name: 'low_balance_threshold',\n type: 'numeric',\n columnType: 'numeric(18, 4)',\n nullable: true,\n })\n lowBalanceThreshold?: string | null\n\n // Timestamp of the most recent transaction \u2014 a cheap \"is this account\n // active?\" signal.\n @Property({ name: 'last_movement_at', type: Date, nullable: true })\n lastMovementAt?: Date | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n// \u2500\u2500\u2500 BillingAccountTransaction (SPEC-002, append-only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// The source of truth for every balance movement. Append-only \u2014 pattern\n// mirrors DraftInvoiceEdit (no `updated_at` / `is_active`; `deleted_at`\n// reserved for compliance erasure only). `balance = SUM(amount)`.\n//\n// The unique `(tenant_id, bill_account_id, source_ref)` is the idempotency\n// gate: a deduplicated usage upload or a retried recurring charge can never\n// double-debit (Postgres treats NULL source_ref as distinct \u2014 manual\n// adjustments without a key always insert).\n\n@Entity({ tableName: 'billing_account_transactions' })\n@Unique({\n name: 'billing_account_transactions_source_ref_unique',\n properties: ['tenantId', 'billAccountId', 'sourceRef'],\n})\n@Index({\n name: 'billing_account_transactions_history_idx',\n properties: ['organizationId', 'tenantId', 'billAccountId', 'createdAt'],\n})\n@Index({\n name: 'billing_account_transactions_account_type_idx',\n properties: ['billAccountId', 'type', 'createdAt'],\n})\nexport class BillingAccountTransaction {\n [OptionalProps]?:\n | 'usageId'\n | 'billingItemId'\n | 'topupId'\n | 'statementId'\n | 'sourceRef'\n | 'metadata'\n | 'userId'\n | 'createdAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // 'topup' | 'usage' | 'recurring' | 'one_time' | 'adjustment' | 'reversal'.\n @Property({ type: 'text' })\n type!: string\n\n // SIGNED: `> 0` credit, `< 0` debit. Balance = SUM(amount).\n @Property({ type: 'numeric', columnType: 'numeric(18, 4)' })\n amount!: string\n\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n // Running balance AFTER this transaction \u2014 snapshotted from the atomic\n // `UPDATE \u2026 RETURNING`. Enables audit + fast statement math without\n // re-summing the whole ledger.\n @Property({ name: 'balance_after', type: 'numeric', columnType: 'numeric(18, 4)' })\n balanceAfter!: string\n\n // FK (string) to BillingAccountUsage for type='usage'.\n @Property({ name: 'usage_id', type: 'uuid', nullable: true })\n usageId?: string | null\n\n // FK (string) to the Billing Item that priced this debit.\n @Property({ name: 'billing_item_id', type: 'uuid', nullable: true })\n billingItemId?: string | null\n\n // FK (string) to BillingTopup for type='topup'.\n @Property({ name: 'topup_id', type: 'uuid', nullable: true })\n topupId?: string | null\n\n // FK (string) to the BillingStatement a period-close charge was rolled into.\n @Property({ name: 'statement_id', type: 'uuid', nullable: true })\n statementId?: string | null\n\n @Property({ type: 'text' })\n description!: string\n\n // Idempotency key, unique per (tenant_id, bill_account_id, source_ref).\n // usage debits = the usage record's source_ref; recurring =\n // `recurring-{itemId}-{periodEndISO}`; topup = `topup-{paymentId}`.\n @Property({ name: 'source_ref', type: 'text', nullable: true })\n sourceRef?: string | null\n\n // e.g. usage_tier_breakdown, uom_code, bill_period_start/end, gateway ids.\n @Property({ type: 'jsonb', nullable: true })\n metadata?: Record<string, unknown> | null\n\n // Operator for manual `adjustment` / `reversal`.\n @Property({ name: 'user_id', type: 'uuid', nullable: true })\n userId?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n // Compliance erasure only.\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingTopup (SPEC-002 \u2014 the \"registered top-up\") \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// One row per top-up attempt with a lifecycle (pending \u2192 captured | failed\n// | expired | cancelled), linked to its GatewayTransaction, its balance\n// credit transaction, and its VAT receipt invoice. \"The balance went up\"\n// is always explainable.\n\n@Entity({ tableName: 'billing_topups' })\n@Unique({\n name: 'billing_topups_payment_id_unique',\n properties: ['tenantId', 'paymentId'],\n})\n@Index({\n name: 'billing_topups_account_history_idx',\n properties: ['organizationId', 'tenantId', 'billAccountId', 'createdAt'],\n})\n@Index({\n name: 'billing_topups_status_idx',\n properties: ['tenantId', 'status'],\n})\nexport class BillingTopup {\n [OptionalProps]?:\n | 'gatewayTransactionId'\n | 'transactionId'\n | 'receiptInvoiceId'\n | 'sourceRef'\n | 'metadata'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // 'pending' | 'captured' | 'failed' | 'expired' | 'cancelled'.\n @Property({ type: 'text' })\n status!: string\n\n @Property({ type: 'numeric', columnType: 'numeric(18, 4)' })\n amount!: string\n\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n @Property({ name: 'provider_key', type: 'text' })\n providerKey!: string\n\n // The UUID we pass to createPaymentSession and match the captured event\n // on. Unique per tenant.\n @Property({ name: 'payment_id', type: 'uuid' })\n paymentId!: string\n\n // FK (string) to payment_gateways.GatewayTransaction once the session is\n // created.\n @Property({ name: 'gateway_transaction_id', type: 'uuid', nullable: true })\n gatewayTransactionId?: string | null\n\n // FK (string) to the credit BillingAccountTransaction written on capture.\n @Property({ name: 'transaction_id', type: 'uuid', nullable: true })\n transactionId?: string | null\n\n // FK (string) to the core/sales VAT receipt invoice.\n @Property({ name: 'receipt_invoice_id', type: 'uuid', nullable: true })\n receiptInvoiceId?: string | null\n\n // Optional idempotency for the initiating request.\n @Property({ name: 'source_ref', type: 'text', nullable: true })\n sourceRef?: string | null\n\n // success_url / cancel_url, provider payload echoes.\n @Property({ type: 'jsonb', nullable: true })\n metadata?: Record<string, unknown> | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n// \u2500\u2500\u2500 BillingStatement (SPEC-002 \u2014 period close) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// A non-fiscal consumption summary for a prepaid account's bill period.\n// Chains cleanly: each statement's `opening_balance` equals the prior\n// statement's `closing_balance`. Anti-duplicate via the unique\n// (tenant_id, bill_account_id, period_start, period_end).\n\n@Entity({ tableName: 'billing_statements' })\n@Unique({\n name: 'billing_statements_period_unique',\n properties: ['tenantId', 'billAccountId', 'periodStart', 'periodEnd'],\n})\n@Index({\n name: 'billing_statements_account_period_idx',\n properties: ['organizationId', 'tenantId', 'billAccountId', 'periodEnd'],\n})\nexport class BillingStatement {\n [OptionalProps]?:\n | 'billRunId'\n | 'totalAdjustments'\n | 'createdAt'\n | 'updatedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'bill_account_id', type: 'uuid' })\n billAccountId!: string\n\n // FK (string) to the BillRun that generated it (period close reuses the\n // run engine). Null for a manually-generated statement.\n @Property({ name: 'bill_run_id', type: 'uuid', nullable: true })\n billRunId?: string | null\n\n @Property({ name: 'period_start', type: 'date', columnType: 'date' })\n periodStart!: Date\n\n @Property({ name: 'period_end', type: 'date', columnType: 'date' })\n periodEnd!: Date\n\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n // Balance at period_start (= the prior statement's closing_balance).\n @Property({ name: 'opening_balance', type: 'numeric', columnType: 'numeric(18, 4)' })\n openingBalance!: string\n\n // Sum of credits in window.\n @Property({ name: 'total_topups', type: 'numeric', columnType: 'numeric(18, 4)' })\n totalTopups!: string\n\n // Sum of metered (real-time) usage debits in window (absolute).\n @Property({ name: 'total_usage', type: 'numeric', columnType: 'numeric(18, 4)' })\n totalUsage!: string\n\n // Sum of recurring + one_time charges debited at this close (absolute).\n @Property({ name: 'total_recurring', type: 'numeric', columnType: 'numeric(18, 4)' })\n totalRecurring!: string\n\n // Signed sum of manual adjustment + reversal movements in the window. Kept as\n // its own term so the statement stays self-consistent (closing reproduces\n // from the shown components) and the opening\u2192closing chain never drifts.\n @Property({ name: 'total_adjustments', type: 'numeric', columnType: 'numeric(18, 4)', default: '0' })\n totalAdjustments: string = '0'\n\n // opening + topups + adjustments \u2212 usage \u2212 recurring (= the period's net).\n @Property({ name: 'closing_balance', type: 'numeric', columnType: 'numeric(18, 4)' })\n closingBalance!: string\n\n // Per billing_item_id: { billing_type, uom_code?, quantity, amount }.\n @Property({ name: 'debit_breakdown', type: 'jsonb' })\n debitBreakdown!: Record<string, unknown>\n\n // 'generated' | 'sent'.\n @Property({ type: 'text' })\n status!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n"],
5
+ "mappings": ";;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AA8BzD;AADI,IAAM,iBAAN,MAAqB;AAAA,EAArB;AAyEL,uBAAsB;AAMtB,uBAAsB;AAGtB,oBAAoB;AAGpB,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AAhFE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GAXlD,eAYX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAdxC,eAeX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GAjBlC,eAkBX;AAMA;AAAA,EADC,SAAS,EAAE,MAAM,eAAe,MAAM,OAAO,CAAC;AAAA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;",
6
6
  "names": []
7
7
  }
@@ -4,7 +4,12 @@ const billingEntityIds = {
4
4
  usage: "billing:billing_account_usage",
5
5
  run: "billing:billing_run",
6
6
  runOutcome: "billing:billing_run_outcome",
7
- draftInvoiceEdit: "billing:billing_draft_invoice_edit"
7
+ draftInvoiceEdit: "billing:billing_draft_invoice_edit",
8
+ // SPEC-002 (prepaid balance billing)
9
+ balance: "billing:billing_account_balance",
10
+ transaction: "billing:billing_account_transaction",
11
+ topup: "billing:billing_topup",
12
+ statement: "billing:billing_statement"
8
13
  };
9
14
  export {
10
15
  billingEntityIds
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/billing/data/entityIds.ts"],
4
- "sourcesContent": ["/**\n * Canonical entity IDs for the billing module.\n *\n * Mirrors what `E.billing.<entity>` would be in\n * `.mercato/generated/entities.ids.generated.ts` if the standalone-app\n * CLI properly discovered `@dainamite/*` workspace entities (see the\n * Phase 0 deviation note in `xd-249-billing-spec.md`). Until the CLI\n * gap is closed upstream, this is the single source of truth \u2014 every\n * place that previously would have referenced `E.billing.*` (CRUD\n * factory `entityId`, indexer `entityType`, response enricher\n * `targetEntity`, etc.) imports from here instead.\n *\n * When the CLI is fixed, this file can be replaced by `import { E }\n * from '#generated/entities.ids.generated'` in one PR.\n */\nexport const billingEntityIds = {\n account: 'billing:billing_account',\n item: 'billing:billing_item',\n usage: 'billing:billing_account_usage',\n run: 'billing:billing_run',\n runOutcome: 'billing:billing_run_outcome',\n draftInvoiceEdit: 'billing:billing_draft_invoice_edit',\n} as const\n\nexport type BillingEntityId = (typeof billingEntityIds)[keyof typeof billingEntityIds]\n"],
5
- "mappings": "AAeO,MAAM,mBAAmB;AAAA,EAC9B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,kBAAkB;AACpB;",
4
+ "sourcesContent": ["/**\n * Canonical entity IDs for the billing module.\n *\n * Mirrors what `E.billing.<entity>` would be in\n * `.mercato/generated/entities.ids.generated.ts` if the standalone-app\n * CLI properly discovered `@dainamite/*` workspace entities (see the\n * Phase 0 deviation note in `xd-249-billing-spec.md`). Until the CLI\n * gap is closed upstream, this is the single source of truth \u2014 every\n * place that previously would have referenced `E.billing.*` (CRUD\n * factory `entityId`, indexer `entityType`, response enricher\n * `targetEntity`, etc.) imports from here instead.\n *\n * When the CLI is fixed, this file can be replaced by `import { E }\n * from '#generated/entities.ids.generated'` in one PR.\n */\nexport const billingEntityIds = {\n account: 'billing:billing_account',\n item: 'billing:billing_item',\n usage: 'billing:billing_account_usage',\n run: 'billing:billing_run',\n runOutcome: 'billing:billing_run_outcome',\n draftInvoiceEdit: 'billing:billing_draft_invoice_edit',\n // SPEC-002 (prepaid balance billing)\n balance: 'billing:billing_account_balance',\n transaction: 'billing:billing_account_transaction',\n topup: 'billing:billing_topup',\n statement: 'billing:billing_statement',\n} as const\n\nexport type BillingEntityId = (typeof billingEntityIds)[keyof typeof billingEntityIds]\n"],
5
+ "mappings": "AAeO,MAAM,mBAAmB;AAAA,EAC9B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,kBAAkB;AAAA;AAAA,EAElB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,OAAO;AAAA,EACP,WAAW;AACb;",
6
6
  "names": []
7
7
  }