@happyvertical/smrt-commerce 0.56.0 → 0.56.1

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 (211) hide show
  1. package/AGENTS.md +9 -8
  2. package/README.md +76 -0
  3. package/agents/accounting-snapshot-mapper.md +111 -0
  4. package/agents/contract-money.md +18 -0
  5. package/agents/cost-billing.md +7 -2
  6. package/agents/document-money.md +126 -0
  7. package/agents/invoice-calculations.md +14 -2
  8. package/agents/line-amount-migration.md +50 -0
  9. package/agents/minor-unit-migration.md +20 -0
  10. package/agents/money-calculator.md +45 -0
  11. package/agents/money-model.md +113 -0
  12. package/agents/revenue-journal.md +23 -0
  13. package/agents/tax-codes.md +48 -0
  14. package/agents/tax-summary.md +126 -0
  15. package/dist/accounting-snapshot.d.ts +79 -0
  16. package/dist/accounting-snapshot.d.ts.map +1 -0
  17. package/dist/billing/runtime.d.ts +2 -0
  18. package/dist/billing/runtime.d.ts.map +1 -1
  19. package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js +265 -0
  20. package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js.map +1 -0
  21. package/dist/chunks/CustomerCollection-DQIujn4f.js +99 -0
  22. package/dist/chunks/CustomerCollection-DQIujn4f.js.map +1 -0
  23. package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js +1639 -0
  24. package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js.map +1 -0
  25. package/dist/chunks/InvoiceCollection-CKQflFjc.js +1047 -0
  26. package/dist/chunks/InvoiceCollection-CKQflFjc.js.map +1 -0
  27. package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js +467 -0
  28. package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js.map +1 -0
  29. package/dist/chunks/TaxCodeCollection-DOpzW4y8.js +149 -0
  30. package/dist/chunks/TaxCodeCollection-DOpzW4y8.js.map +1 -0
  31. package/dist/chunks/TaxComponentCollection-Cs2uXwEl.js +129 -0
  32. package/dist/chunks/TaxComponentCollection-Cs2uXwEl.js.map +1 -0
  33. package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js +319 -0
  34. package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js.map +1 -0
  35. package/dist/chunks/{money-DfrRxrel.js → allocation-integrity-DI3G16BN.js} +7 -12
  36. package/dist/chunks/allocation-integrity-DI3G16BN.js.map +1 -0
  37. package/dist/chunks/{calculations-Bz7RB3qK.js → calculations-DaHR17il.js} +134 -54
  38. package/dist/chunks/calculations-DaHR17il.js.map +1 -0
  39. package/dist/chunks/credit-allocation-yspz0Lab.js +121 -0
  40. package/dist/chunks/credit-allocation-yspz0Lab.js.map +1 -0
  41. package/dist/chunks/document-money-DNVhDJyC.js +860 -0
  42. package/dist/chunks/document-money-DNVhDJyC.js.map +1 -0
  43. package/dist/chunks/invoice-posting-BwV8g7z0.js +229 -0
  44. package/dist/chunks/invoice-posting-BwV8g7z0.js.map +1 -0
  45. package/dist/chunks/money-rational-CcW7gzG5.js +64 -0
  46. package/dist/chunks/money-rational-CcW7gzG5.js.map +1 -0
  47. package/dist/chunks/revenue-journal-DY9fro8E.js +140 -0
  48. package/dist/chunks/revenue-journal-DY9fro8E.js.map +1 -0
  49. package/dist/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
  50. package/dist/chunks/tenant-money-barrier-DjRXgMnX.js +135 -0
  51. package/dist/chunks/tenant-money-barrier-DjRXgMnX.js.map +1 -0
  52. package/dist/chunks/{types-zVnIjSOk.js → types-LDETvQ1C.js} +3 -14
  53. package/dist/chunks/types-LDETvQ1C.js.map +1 -0
  54. package/dist/chunks/{units-BpZ0_Dpk.js → units-CNcjH_eE.js} +2 -2
  55. package/dist/chunks/{units-BpZ0_Dpk.js.map → units-CNcjH_eE.js.map} +1 -1
  56. package/dist/collections/ContractCollection.d.ts +35 -1
  57. package/dist/collections/ContractCollection.d.ts.map +1 -1
  58. package/dist/collections/ContractLineItemCollection.d.ts +26 -1
  59. package/dist/collections/ContractLineItemCollection.d.ts.map +1 -1
  60. package/dist/collections/DocumentTaxCollection.d.ts +75 -0
  61. package/dist/collections/DocumentTaxCollection.d.ts.map +1 -0
  62. package/dist/collections/InvoiceCollection.d.ts +26 -1
  63. package/dist/collections/InvoiceCollection.d.ts.map +1 -1
  64. package/dist/collections/InvoiceLineItemCollection.d.ts +26 -1
  65. package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -1
  66. package/dist/collections/MoneyMigrationDocumentCollection.d.ts +12 -0
  67. package/dist/collections/MoneyMigrationDocumentCollection.d.ts.map +1 -0
  68. package/dist/collections/PaymentAllocationCollection.d.ts +2 -0
  69. package/dist/collections/PaymentAllocationCollection.d.ts.map +1 -1
  70. package/dist/collections/TaxCodeCollection.d.ts +7 -0
  71. package/dist/collections/TaxCodeCollection.d.ts.map +1 -0
  72. package/dist/collections/TaxComponentCollection.d.ts +6 -0
  73. package/dist/collections/TaxComponentCollection.d.ts.map +1 -0
  74. package/dist/collections/TaxSettingsCollection.d.ts +16 -0
  75. package/dist/collections/TaxSettingsCollection.d.ts.map +1 -0
  76. package/dist/collections/TaxSummaryReportCollection.d.ts +151 -0
  77. package/dist/collections/TaxSummaryReportCollection.d.ts.map +1 -0
  78. package/dist/collections/index.d.ts +6 -0
  79. package/dist/collections/index.d.ts.map +1 -1
  80. package/dist/commerce-money-tools.d.ts +9 -0
  81. package/dist/commerce-money-tools.d.ts.map +1 -0
  82. package/dist/contract-money.d.ts +27 -0
  83. package/dist/contract-money.d.ts.map +1 -0
  84. package/dist/cost-billing.d.ts +0 -1
  85. package/dist/cost-billing.d.ts.map +1 -1
  86. package/dist/cost-billing.js +10 -15
  87. package/dist/cost-billing.js.map +1 -1
  88. package/dist/credit-allocation.d.ts +48 -0
  89. package/dist/credit-allocation.d.ts.map +1 -0
  90. package/dist/document-money-internal.d.ts +44 -0
  91. package/dist/document-money-internal.d.ts.map +1 -0
  92. package/dist/document-money.d.ts +85 -0
  93. package/dist/document-money.d.ts.map +1 -0
  94. package/dist/index.d.ts +15 -4
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +5395 -4246
  97. package/dist/index.js.map +1 -1
  98. package/dist/invoice-accounting-sync.d.ts +96 -0
  99. package/dist/invoice-accounting-sync.d.ts.map +1 -0
  100. package/dist/invoice-mcp.d.ts +16 -0
  101. package/dist/invoice-mcp.d.ts.map +1 -0
  102. package/dist/invoice-posting.d.ts +9 -0
  103. package/dist/invoice-posting.d.ts.map +1 -0
  104. package/dist/invoice-record-screen.d.ts +60 -0
  105. package/dist/invoice-record-screen.d.ts.map +1 -0
  106. package/dist/invoices.d.ts +2 -0
  107. package/dist/invoices.d.ts.map +1 -1
  108. package/dist/invoices.js +3 -2
  109. package/dist/manifest.json +10365 -4562
  110. package/dist/migrations/commerceLineAmounts.d.ts +84 -0
  111. package/dist/migrations/commerceLineAmounts.d.ts.map +1 -0
  112. package/dist/models/Contract.d.ts +25 -1
  113. package/dist/models/Contract.d.ts.map +1 -1
  114. package/dist/models/ContractLineItem.d.ts +30 -1
  115. package/dist/models/ContractLineItem.d.ts.map +1 -1
  116. package/dist/models/Customer.d.ts +7 -0
  117. package/dist/models/Customer.d.ts.map +1 -1
  118. package/dist/models/DocumentTax.d.ts +50 -0
  119. package/dist/models/DocumentTax.d.ts.map +1 -0
  120. package/dist/models/Invoice.d.ts +46 -2
  121. package/dist/models/Invoice.d.ts.map +1 -1
  122. package/dist/models/InvoiceLineItem.d.ts +33 -2
  123. package/dist/models/InvoiceLineItem.d.ts.map +1 -1
  124. package/dist/models/MoneyMigrationDocument.d.ts +28 -0
  125. package/dist/models/MoneyMigrationDocument.d.ts.map +1 -0
  126. package/dist/models/Payment.d.ts +5 -1
  127. package/dist/models/Payment.d.ts.map +1 -1
  128. package/dist/models/PaymentAllocation.d.ts.map +1 -1
  129. package/dist/models/TaxCode.d.ts +22 -0
  130. package/dist/models/TaxCode.d.ts.map +1 -0
  131. package/dist/models/TaxComponent.d.ts +21 -0
  132. package/dist/models/TaxComponent.d.ts.map +1 -0
  133. package/dist/models/TaxSettings.d.ts +33 -0
  134. package/dist/models/TaxSettings.d.ts.map +1 -0
  135. package/dist/models/TaxSummaryReport.d.ts +35 -0
  136. package/dist/models/TaxSummaryReport.d.ts.map +1 -0
  137. package/dist/models/Vendor.d.ts +9 -0
  138. package/dist/models/Vendor.d.ts.map +1 -1
  139. package/dist/models/index.d.ts +6 -0
  140. package/dist/models/index.d.ts.map +1 -1
  141. package/dist/money-rational.d.ts +15 -0
  142. package/dist/money-rational.d.ts.map +1 -0
  143. package/dist/money.d.ts +106 -25
  144. package/dist/money.d.ts.map +1 -1
  145. package/dist/money.js +274 -0
  146. package/dist/money.js.map +1 -0
  147. package/dist/recipes.d.ts +15 -15
  148. package/dist/revenue-journal.d.ts +61 -0
  149. package/dist/revenue-journal.d.ts.map +1 -0
  150. package/dist/smrt-knowledge.json +5711 -1029
  151. package/dist/svelte/components/InvoiceActions.svelte +12 -0
  152. package/dist/svelte/components/InvoiceActions.svelte.d.ts +5 -0
  153. package/dist/svelte/components/InvoiceActions.svelte.d.ts.map +1 -1
  154. package/dist/svelte/components/InvoiceEditor.svelte +15 -1
  155. package/dist/svelte/components/InvoiceEditor.svelte.d.ts.map +1 -1
  156. package/dist/svelte/components/InvoiceLineItems.svelte +3 -3
  157. package/dist/svelte/components/InvoiceRecordScreen.svelte +94 -0
  158. package/dist/svelte/components/InvoiceRecordScreen.svelte.d.ts +21 -0
  159. package/dist/svelte/components/InvoiceRecordScreen.svelte.d.ts.map +1 -0
  160. package/dist/svelte/components/InvoiceTotals.svelte +2 -2
  161. package/dist/svelte/components/MoneyInvoiceEditor.svelte +282 -0
  162. package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts +31 -0
  163. package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts.map +1 -0
  164. package/dist/svelte/components/PurchaseOrderEditor.svelte +53 -1
  165. package/dist/svelte/components/PurchaseOrderEditor.svelte.d.ts +5 -0
  166. package/dist/svelte/components/PurchaseOrderEditor.svelte.d.ts.map +1 -1
  167. package/dist/svelte/components/QuoteEditor.svelte +54 -1
  168. package/dist/svelte/components/QuoteEditor.svelte.d.ts +5 -0
  169. package/dist/svelte/components/QuoteEditor.svelte.d.ts.map +1 -1
  170. package/dist/svelte/i18n.d.ts +16 -0
  171. package/dist/svelte/i18n.d.ts.map +1 -1
  172. package/dist/svelte/i18n.js +16 -0
  173. package/dist/svelte/index.d.ts +7 -2
  174. package/dist/svelte/index.d.ts.map +1 -1
  175. package/dist/svelte/index.js +4 -1
  176. package/dist/svelte/invoices/calculations.d.ts +7 -2
  177. package/dist/svelte/invoices/calculations.d.ts.map +1 -1
  178. package/dist/svelte/invoices/calculations.js +141 -47
  179. package/dist/svelte/invoices/money-editor.d.ts +123 -0
  180. package/dist/svelte/invoices/money-editor.d.ts.map +1 -0
  181. package/dist/svelte/invoices/money-editor.js +101 -0
  182. package/dist/svelte/invoices/types.d.ts +5 -1
  183. package/dist/svelte/invoices/types.d.ts.map +1 -1
  184. package/dist/svelte/purchasing-i18n.d.ts +5 -0
  185. package/dist/svelte/purchasing-i18n.d.ts.map +1 -1
  186. package/dist/svelte/purchasing-i18n.js +5 -0
  187. package/dist/svelte/quote-i18n.d.ts +5 -0
  188. package/dist/svelte/quote-i18n.d.ts.map +1 -1
  189. package/dist/svelte/quote-i18n.js +5 -0
  190. package/dist/tax/cookbook.d.ts +22 -0
  191. package/dist/tax/cookbook.d.ts.map +1 -0
  192. package/dist/tax/example-pack.d.ts +25 -0
  193. package/dist/tax/example-pack.d.ts.map +1 -0
  194. package/dist/tax/identity.d.ts +5 -0
  195. package/dist/tax/identity.d.ts.map +1 -0
  196. package/dist/tax/index.d.ts +4 -0
  197. package/dist/tax/index.d.ts.map +1 -0
  198. package/dist/tax/legacy.d.ts +48 -0
  199. package/dist/tax/legacy.d.ts.map +1 -0
  200. package/dist/tax-summary-report-adapter.d.ts +37 -0
  201. package/dist/tax-summary-report-adapter.d.ts.map +1 -0
  202. package/dist/tax-summary.d.ts +129 -0
  203. package/dist/tax-summary.d.ts.map +1 -0
  204. package/dist/tenant-money-barrier.d.ts +66 -0
  205. package/dist/tenant-money-barrier.d.ts.map +1 -0
  206. package/dist/types/index.d.ts +137 -1
  207. package/dist/types/index.d.ts.map +1 -1
  208. package/package.json +19 -11
  209. package/dist/chunks/calculations-Bz7RB3qK.js.map +0 -1
  210. package/dist/chunks/money-DfrRxrel.js.map +0 -1
  211. package/dist/chunks/types-zVnIjSOk.js.map +0 -1
@@ -0,0 +1,96 @@
1
+ /** Frozen Invoice projection and guarded accounting-provider synchronization. */
2
+ import type { AccountingProvider, QuickBooksCreditMemoRequest, QuickBooksInvoiceRequest } from '@happyvertical/accounting';
3
+ import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
4
+ import { type FrozenAccountingDocumentSnapshot, type FrozenQuickBooksTaxMapping } from './accounting-snapshot.js';
5
+ import type { Invoice } from './models/Invoice.js';
6
+ import { type AccountingInvoiceInput } from './types/index.js';
7
+ export interface QuickBooksFrozenInvoiceMapping extends FrozenQuickBooksTaxMapping {
8
+ readonly realmId: string;
9
+ readonly environment: 'sandbox' | 'production';
10
+ }
11
+ export interface FrozenInvoiceAccountingOptions {
12
+ readonly mapping: QuickBooksFrozenInvoiceMapping;
13
+ }
14
+ export interface FrozenInvoiceAccountingInput extends FrozenInvoiceAccountingOptions {
15
+ readonly db: DatabaseInterface;
16
+ readonly tenantId: string;
17
+ readonly invoiceId: string;
18
+ }
19
+ export interface FrozenInvoiceAccountingSnapshot {
20
+ readonly document: FrozenAccountingDocumentSnapshot;
21
+ readonly moneySnapshotId: string;
22
+ readonly creditedInvoiceScope?: Readonly<{
23
+ provider: 'quickbooks';
24
+ realmId: string;
25
+ environment: 'sandbox' | 'production';
26
+ }>;
27
+ }
28
+ type FrozenSyncStatus = 'in_flight' | 'unknown' | 'rejected' | 'synced';
29
+ export interface FrozenAccountingSyncResult {
30
+ readonly status: 'synced' | 'unchanged';
31
+ readonly externalId: string;
32
+ readonly syncedAt: Date;
33
+ readonly moneySnapshotId: string;
34
+ }
35
+ export interface SyncFrozenInvoiceToAccountingInput extends FrozenInvoiceAccountingInput {
36
+ readonly provider: Pick<AccountingProvider, 'type' | 'invoices' | 'creditMemos'>;
37
+ }
38
+ export interface ReconcileFrozenInvoiceAccountingInput extends FrozenInvoiceAccountingInput {
39
+ /** The request descriptor observed before checking QuickBooks. */
40
+ readonly requestId: string;
41
+ /** The unresolved local owner observed with that request descriptor. */
42
+ readonly attemptId: string;
43
+ /**
44
+ * Required only for an interrupted `in_flight` record. The trusted server
45
+ * caller must first establish that the original process/request owner can no
46
+ * longer complete. A provider lookup reporting absence is not sufficient.
47
+ */
48
+ readonly confirmInterruptedOwnerStopped?: true;
49
+ /**
50
+ * The authoritative result of looking up that request in QuickBooks.
51
+ * `absent` means QuickBooks confirmed that no document was created.
52
+ */
53
+ readonly outcome: {
54
+ readonly status: 'found';
55
+ readonly externalId: string;
56
+ readonly syncedAt: Date;
57
+ } | {
58
+ readonly status: 'absent';
59
+ };
60
+ }
61
+ export interface FrozenAccountingReconciliationReady {
62
+ readonly status: 'ready';
63
+ readonly moneySnapshotId: string;
64
+ readonly requestId: string;
65
+ }
66
+ /** Load and validate one authoritative issued snapshot without provider I/O. */
67
+ export declare function loadFrozenInvoiceAccountingSnapshot(input: Omit<FrozenInvoiceAccountingInput, 'mapping'>): Promise<FrozenInvoiceAccountingSnapshot>;
68
+ /** Convert authoritative persisted facts into the released SDK invoice shape. */
69
+ export declare function toFrozenInvoiceAccountingInput(input: FrozenInvoiceAccountingInput): Promise<AccountingInvoiceInput>;
70
+ /**
71
+ * Push one frozen invoice exactly once per provider/realm/environment/snapshot.
72
+ * Local and remote writes are intentionally separate phases. An unknown remote
73
+ * outcome is persisted and requires reconciliation instead of a blind replay.
74
+ */
75
+ export declare function syncFrozenInvoiceToAccounting(input: SyncFrozenInvoiceToAccountingInput): Promise<FrozenAccountingSyncResult>;
76
+ /**
77
+ * Record an authoritative QuickBooks lookup after an unknown/interrupted push.
78
+ * The caller must first query the exact persisted request descriptor and must
79
+ * only report `absent` when the provider confirms that no document exists.
80
+ */
81
+ export declare function reconcileFrozenInvoiceAccountingSync(input: ReconcileFrozenInvoiceAccountingInput): Promise<FrozenAccountingSyncResult | FrozenAccountingReconciliationReady>;
82
+ /** Read the persisted coordination state for diagnostics/reconciliation. */
83
+ export declare function readFrozenAccountingSyncState(invoice: Invoice): Readonly<{
84
+ status: FrozenSyncStatus;
85
+ provider: string;
86
+ realmId: string;
87
+ environment: string;
88
+ moneySnapshotId: string;
89
+ requestId: string;
90
+ attemptId: string;
91
+ startedAt: string;
92
+ documentKind: 'invoice' | 'creditMemo';
93
+ request: QuickBooksInvoiceRequest | QuickBooksCreditMemoRequest;
94
+ }> | null;
95
+ export {};
96
+ //# sourceMappingURL=invoice-accounting-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-accounting-sync.d.ts","sourceRoot":"","sources":["../src/invoice-accounting-sync.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAGjF,OAAO,KAAK,EACV,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,EAEzB,MAAM,2BAA2B,CAAC;AAMnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,OAAO,EAEL,KAAK,gCAAgC,EACrC,KAAK,0BAA0B,EAEhC,MAAM,0BAA0B,CAAC;AASlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAAE,KAAK,sBAAsB,EAAiB,MAAM,kBAAkB,CAAC;AAE9E,MAAM,WAAW,8BACf,SAAQ,0BAA0B;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,SAAS,GAAG,YAAY,CAAC;CAChD;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,OAAO,EAAE,8BAA8B,CAAC;CAClD;AAED,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@ -0,0 +1,16 @@
1
+ /** Stored-money projection for the generated Invoice MCP get tool. */
2
+ import type { PublicJsonOptions } from '@happyvertical/smrt-core';
3
+ import { getInvoiceMoneyFacts } from './document-money.js';
4
+ import type { Invoice } from './models/Invoice.js';
5
+ export type InvoiceMcpGetResult = Record<string, unknown> & {
6
+ money?: Awaited<ReturnType<typeof getInvoiceMoneyFacts>>;
7
+ };
8
+ /**
9
+ * Serialize one already-authorized Invoice get response.
10
+ *
11
+ * Legacy tenants keep the ordinary public Invoice shape. Money-v2 tenants get
12
+ * the authoritative stored snapshot and DocumentTax rows under `money`; this
13
+ * function never resolves current tax codes or recalculates totals.
14
+ */
15
+ export declare function serializeInvoiceMcpGet(invoice: Invoice, options?: PublicJsonOptions): Promise<InvoiceMcpGetResult>;
16
+ //# sourceMappingURL=invoice-mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-mcp.d.ts","sourceRoot":"","sources":["../src/invoice-mcp.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAInD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC1D,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC;CAC1D,CAAC;AAsFF;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAuC9B"}
@@ -0,0 +1,9 @@
1
+ /** Atomic money-v2 revenue posting and cancellation reversal. */
2
+ import type { Journal } from '@happyvertical/smrt-ledgers';
3
+ import type { Invoice } from './models/Invoice.js';
4
+ import { type CancelRevenueOptions, type RecognizeRevenueOptions } from './types/index.js';
5
+ /** Return null for legacy tenants so Invoice can preserve its old path. */
6
+ export declare function recognizeInvoiceRevenueV2(input: Invoice, options: RecognizeRevenueOptions): Promise<Journal | null>;
7
+ /** Atomically reverse a posted v2 invoice and move it to CANCELLED. */
8
+ export declare function cancelInvoiceWithRevenueReversal(input: Invoice, options: CancelRevenueOptions): Promise<Journal | null>;
9
+ //# sourceMappingURL=invoice-posting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-posting.d.ts","sourceRoot":"","sources":["../src/invoice-posting.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAGjE,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,6BAA6B,CAAC;AAW7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAgK1B,2EAA2E;AAC3E,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CA0GzB;AA6BD,uEAAuE;AACvE,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAsHzB"}
@@ -0,0 +1,60 @@
1
+ /** Commerce composition data for the generic record screen. */
2
+ import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
3
+ import { type InvoiceMoneyFacts } from './document-money.js';
4
+ /** A frozen component row shaped for `RecordScreen.lineItemStoredTotals`. */
5
+ export interface InvoiceRecordTaxComponent {
6
+ taxComponentId: string;
7
+ name: string;
8
+ percent: string;
9
+ taxable: number;
10
+ tax: number;
11
+ }
12
+ /** The immutable totals projection that the generic record widget displays. */
13
+ export interface InvoiceRecordStoredTotals {
14
+ subtotal: number;
15
+ discount: number;
16
+ tax: number;
17
+ total: number;
18
+ lineAmountType: 'exclusive' | 'inclusive' | 'none';
19
+ roundingScope: 'line' | 'document';
20
+ showNetSubtotal: boolean;
21
+ taxes: readonly InvoiceRecordTaxComponent[];
22
+ }
23
+ /** A credit-note summary safe to show beside its source invoice. */
24
+ export interface InvoiceRecordCreditNote {
25
+ id: string;
26
+ invoiceNumber: string;
27
+ status: string;
28
+ issueDate: string;
29
+ totalMinor: number;
30
+ }
31
+ /** Tenant-scoped, stored-only data for an invoice record screen. */
32
+ export interface InvoiceRecordScreenData {
33
+ invoiceId: string;
34
+ kind: InvoiceMoneyFacts['kind'];
35
+ status: InvoiceMoneyFacts['status'];
36
+ currency: string;
37
+ storedTotals: InvoiceRecordStoredTotals;
38
+ creditNotes: readonly InvoiceRecordCreditNote[];
39
+ }
40
+ export interface LoadInvoiceRecordScreenDataInput {
41
+ db: DatabaseInterface;
42
+ tenantId: string;
43
+ invoiceId: string;
44
+ /** Hosts choose whether inclusive taxed records disclose their net subtotal. */
45
+ showNetSubtotal?: boolean;
46
+ }
47
+ /**
48
+ * Maps only persisted invoice and `DocumentTax` fields to the generic widget
49
+ * contract. No tax, discount, or total is calculated here.
50
+ */
51
+ export declare function invoiceRecordStoredTotals(facts: InvoiceMoneyFacts, options?: {
52
+ showNetSubtotal?: boolean;
53
+ }): InvoiceRecordStoredTotals;
54
+ /**
55
+ * Loads a v2 invoice's frozen record-screen data in one tenant money read
56
+ * scope. Callers must already be executing for the same tenant; this helper
57
+ * never switches a principal from its supplied id.
58
+ */
59
+ export declare function loadInvoiceRecordScreenData(input: LoadInvoiceRecordScreenDataInput): Promise<InvoiceRecordScreenData>;
60
+ //# sourceMappingURL=invoice-record-screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-record-screen.d.ts","sourceRoot":"","sources":["../src/invoice-record-screen.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAE/D,OAAO,KAAK,EAAE,i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IAClB,gFAAgF;IAChF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA8BD;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,iBAAiB,EACxB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,yBAAyB,CAuB3B;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,gCAAgC,GACtC,OAAO,CAAC,uBAAuB,CAAC,CA2ClC"}
@@ -1,3 +1,5 @@
1
1
  /** Svelte-free invoice draft calculation and validation for server handlers. */
2
+ export type { MoneyValidationCode } from './money.js';
3
+ export { MoneyValidationError } from './money.js';
2
4
  export * from './svelte/invoices/calculations.js';
3
5
  //# sourceMappingURL=invoices.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoices.d.ts","sourceRoot":"","sources":["../src/invoices.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,cAAc,mCAAmC,CAAC"}
1
+ {"version":3,"file":"invoices.d.ts","sourceRoot":"","sources":["../src/invoices.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,cAAc,mCAAmC,CAAC"}
package/dist/invoices.js CHANGED
@@ -1,2 +1,3 @@
1
- import { i as resolveInvoiceLineDraft, n as calculateInvoiceLine, r as calculateInvoiceMinorLine, t as calculateInvoiceDraft } from "./chunks/calculations-Bz7RB3qK.js";
2
- export { calculateInvoiceDraft, calculateInvoiceLine, calculateInvoiceMinorLine, resolveInvoiceLineDraft };
1
+ import { i as resolveInvoiceLineDraft, n as calculateInvoiceLine, r as calculateInvoiceMinorLine, t as calculateInvoiceDraft } from "./chunks/calculations-DaHR17il.js";
2
+ import { MoneyValidationError } from "./money.js";
3
+ export { MoneyValidationError, calculateInvoiceDraft, calculateInvoiceLine, calculateInvoiceMinorLine, resolveInvoiceLineDraft };