@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.
- package/AGENTS.md +9 -8
- package/README.md +76 -0
- package/agents/accounting-snapshot-mapper.md +111 -0
- package/agents/contract-money.md +18 -0
- package/agents/cost-billing.md +7 -2
- package/agents/document-money.md +126 -0
- package/agents/invoice-calculations.md +14 -2
- package/agents/line-amount-migration.md +50 -0
- package/agents/minor-unit-migration.md +20 -0
- package/agents/money-calculator.md +45 -0
- package/agents/money-model.md +113 -0
- package/agents/revenue-journal.md +23 -0
- package/agents/tax-codes.md +48 -0
- package/agents/tax-summary.md +126 -0
- package/dist/accounting-snapshot.d.ts +79 -0
- package/dist/accounting-snapshot.d.ts.map +1 -0
- package/dist/billing/runtime.d.ts +2 -0
- package/dist/billing/runtime.d.ts.map +1 -1
- package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js +265 -0
- package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js.map +1 -0
- package/dist/chunks/CustomerCollection-DQIujn4f.js +99 -0
- package/dist/chunks/CustomerCollection-DQIujn4f.js.map +1 -0
- package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js +1639 -0
- package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js.map +1 -0
- package/dist/chunks/InvoiceCollection-CKQflFjc.js +1047 -0
- package/dist/chunks/InvoiceCollection-CKQflFjc.js.map +1 -0
- package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js +467 -0
- package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js.map +1 -0
- package/dist/chunks/TaxCodeCollection-DOpzW4y8.js +149 -0
- package/dist/chunks/TaxCodeCollection-DOpzW4y8.js.map +1 -0
- package/dist/chunks/TaxComponentCollection-Cs2uXwEl.js +129 -0
- package/dist/chunks/TaxComponentCollection-Cs2uXwEl.js.map +1 -0
- package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js +319 -0
- package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js.map +1 -0
- package/dist/chunks/{money-DfrRxrel.js → allocation-integrity-DI3G16BN.js} +7 -12
- package/dist/chunks/allocation-integrity-DI3G16BN.js.map +1 -0
- package/dist/chunks/{calculations-Bz7RB3qK.js → calculations-DaHR17il.js} +134 -54
- package/dist/chunks/calculations-DaHR17il.js.map +1 -0
- package/dist/chunks/credit-allocation-yspz0Lab.js +121 -0
- package/dist/chunks/credit-allocation-yspz0Lab.js.map +1 -0
- package/dist/chunks/document-money-DNVhDJyC.js +860 -0
- package/dist/chunks/document-money-DNVhDJyC.js.map +1 -0
- package/dist/chunks/invoice-posting-BwV8g7z0.js +229 -0
- package/dist/chunks/invoice-posting-BwV8g7z0.js.map +1 -0
- package/dist/chunks/money-rational-CcW7gzG5.js +64 -0
- package/dist/chunks/money-rational-CcW7gzG5.js.map +1 -0
- package/dist/chunks/revenue-journal-DY9fro8E.js +140 -0
- package/dist/chunks/revenue-journal-DY9fro8E.js.map +1 -0
- package/dist/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/chunks/tenant-money-barrier-DjRXgMnX.js +135 -0
- package/dist/chunks/tenant-money-barrier-DjRXgMnX.js.map +1 -0
- package/dist/chunks/{types-zVnIjSOk.js → types-LDETvQ1C.js} +3 -14
- package/dist/chunks/types-LDETvQ1C.js.map +1 -0
- package/dist/chunks/{units-BpZ0_Dpk.js → units-CNcjH_eE.js} +2 -2
- package/dist/chunks/{units-BpZ0_Dpk.js.map → units-CNcjH_eE.js.map} +1 -1
- package/dist/collections/ContractCollection.d.ts +35 -1
- package/dist/collections/ContractCollection.d.ts.map +1 -1
- package/dist/collections/ContractLineItemCollection.d.ts +26 -1
- package/dist/collections/ContractLineItemCollection.d.ts.map +1 -1
- package/dist/collections/DocumentTaxCollection.d.ts +75 -0
- package/dist/collections/DocumentTaxCollection.d.ts.map +1 -0
- package/dist/collections/InvoiceCollection.d.ts +26 -1
- package/dist/collections/InvoiceCollection.d.ts.map +1 -1
- package/dist/collections/InvoiceLineItemCollection.d.ts +26 -1
- package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -1
- package/dist/collections/MoneyMigrationDocumentCollection.d.ts +12 -0
- package/dist/collections/MoneyMigrationDocumentCollection.d.ts.map +1 -0
- package/dist/collections/PaymentAllocationCollection.d.ts +2 -0
- package/dist/collections/PaymentAllocationCollection.d.ts.map +1 -1
- package/dist/collections/TaxCodeCollection.d.ts +7 -0
- package/dist/collections/TaxCodeCollection.d.ts.map +1 -0
- package/dist/collections/TaxComponentCollection.d.ts +6 -0
- package/dist/collections/TaxComponentCollection.d.ts.map +1 -0
- package/dist/collections/TaxSettingsCollection.d.ts +16 -0
- package/dist/collections/TaxSettingsCollection.d.ts.map +1 -0
- package/dist/collections/TaxSummaryReportCollection.d.ts +151 -0
- package/dist/collections/TaxSummaryReportCollection.d.ts.map +1 -0
- package/dist/collections/index.d.ts +6 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/commerce-money-tools.d.ts +9 -0
- package/dist/commerce-money-tools.d.ts.map +1 -0
- package/dist/contract-money.d.ts +27 -0
- package/dist/contract-money.d.ts.map +1 -0
- package/dist/cost-billing.d.ts +0 -1
- package/dist/cost-billing.d.ts.map +1 -1
- package/dist/cost-billing.js +10 -15
- package/dist/cost-billing.js.map +1 -1
- package/dist/credit-allocation.d.ts +48 -0
- package/dist/credit-allocation.d.ts.map +1 -0
- package/dist/document-money-internal.d.ts +44 -0
- package/dist/document-money-internal.d.ts.map +1 -0
- package/dist/document-money.d.ts +85 -0
- package/dist/document-money.d.ts.map +1 -0
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5395 -4246
- package/dist/index.js.map +1 -1
- package/dist/invoice-accounting-sync.d.ts +96 -0
- package/dist/invoice-accounting-sync.d.ts.map +1 -0
- package/dist/invoice-mcp.d.ts +16 -0
- package/dist/invoice-mcp.d.ts.map +1 -0
- package/dist/invoice-posting.d.ts +9 -0
- package/dist/invoice-posting.d.ts.map +1 -0
- package/dist/invoice-record-screen.d.ts +60 -0
- package/dist/invoice-record-screen.d.ts.map +1 -0
- package/dist/invoices.d.ts +2 -0
- package/dist/invoices.d.ts.map +1 -1
- package/dist/invoices.js +3 -2
- package/dist/manifest.json +10365 -4562
- package/dist/migrations/commerceLineAmounts.d.ts +84 -0
- package/dist/migrations/commerceLineAmounts.d.ts.map +1 -0
- package/dist/models/Contract.d.ts +25 -1
- package/dist/models/Contract.d.ts.map +1 -1
- package/dist/models/ContractLineItem.d.ts +30 -1
- package/dist/models/ContractLineItem.d.ts.map +1 -1
- package/dist/models/Customer.d.ts +7 -0
- package/dist/models/Customer.d.ts.map +1 -1
- package/dist/models/DocumentTax.d.ts +50 -0
- package/dist/models/DocumentTax.d.ts.map +1 -0
- package/dist/models/Invoice.d.ts +46 -2
- package/dist/models/Invoice.d.ts.map +1 -1
- package/dist/models/InvoiceLineItem.d.ts +33 -2
- package/dist/models/InvoiceLineItem.d.ts.map +1 -1
- package/dist/models/MoneyMigrationDocument.d.ts +28 -0
- package/dist/models/MoneyMigrationDocument.d.ts.map +1 -0
- package/dist/models/Payment.d.ts +5 -1
- package/dist/models/Payment.d.ts.map +1 -1
- package/dist/models/PaymentAllocation.d.ts.map +1 -1
- package/dist/models/TaxCode.d.ts +22 -0
- package/dist/models/TaxCode.d.ts.map +1 -0
- package/dist/models/TaxComponent.d.ts +21 -0
- package/dist/models/TaxComponent.d.ts.map +1 -0
- package/dist/models/TaxSettings.d.ts +33 -0
- package/dist/models/TaxSettings.d.ts.map +1 -0
- package/dist/models/TaxSummaryReport.d.ts +35 -0
- package/dist/models/TaxSummaryReport.d.ts.map +1 -0
- package/dist/models/Vendor.d.ts +9 -0
- package/dist/models/Vendor.d.ts.map +1 -1
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/money-rational.d.ts +15 -0
- package/dist/money-rational.d.ts.map +1 -0
- package/dist/money.d.ts +106 -25
- package/dist/money.d.ts.map +1 -1
- package/dist/money.js +274 -0
- package/dist/money.js.map +1 -0
- package/dist/recipes.d.ts +15 -15
- package/dist/revenue-journal.d.ts +61 -0
- package/dist/revenue-journal.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +5711 -1029
- package/dist/svelte/components/InvoiceActions.svelte +12 -0
- package/dist/svelte/components/InvoiceActions.svelte.d.ts +5 -0
- package/dist/svelte/components/InvoiceActions.svelte.d.ts.map +1 -1
- package/dist/svelte/components/InvoiceEditor.svelte +15 -1
- package/dist/svelte/components/InvoiceEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/components/InvoiceLineItems.svelte +3 -3
- package/dist/svelte/components/InvoiceRecordScreen.svelte +94 -0
- package/dist/svelte/components/InvoiceRecordScreen.svelte.d.ts +21 -0
- package/dist/svelte/components/InvoiceRecordScreen.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InvoiceTotals.svelte +2 -2
- package/dist/svelte/components/MoneyInvoiceEditor.svelte +282 -0
- package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts +31 -0
- package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts.map +1 -0
- package/dist/svelte/components/PurchaseOrderEditor.svelte +53 -1
- package/dist/svelte/components/PurchaseOrderEditor.svelte.d.ts +5 -0
- package/dist/svelte/components/PurchaseOrderEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/components/QuoteEditor.svelte +54 -1
- package/dist/svelte/components/QuoteEditor.svelte.d.ts +5 -0
- package/dist/svelte/components/QuoteEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/i18n.d.ts +16 -0
- package/dist/svelte/i18n.d.ts.map +1 -1
- package/dist/svelte/i18n.js +16 -0
- package/dist/svelte/index.d.ts +7 -2
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +4 -1
- package/dist/svelte/invoices/calculations.d.ts +7 -2
- package/dist/svelte/invoices/calculations.d.ts.map +1 -1
- package/dist/svelte/invoices/calculations.js +141 -47
- package/dist/svelte/invoices/money-editor.d.ts +123 -0
- package/dist/svelte/invoices/money-editor.d.ts.map +1 -0
- package/dist/svelte/invoices/money-editor.js +101 -0
- package/dist/svelte/invoices/types.d.ts +5 -1
- package/dist/svelte/invoices/types.d.ts.map +1 -1
- package/dist/svelte/purchasing-i18n.d.ts +5 -0
- package/dist/svelte/purchasing-i18n.d.ts.map +1 -1
- package/dist/svelte/purchasing-i18n.js +5 -0
- package/dist/svelte/quote-i18n.d.ts +5 -0
- package/dist/svelte/quote-i18n.d.ts.map +1 -1
- package/dist/svelte/quote-i18n.js +5 -0
- package/dist/tax/cookbook.d.ts +22 -0
- package/dist/tax/cookbook.d.ts.map +1 -0
- package/dist/tax/example-pack.d.ts +25 -0
- package/dist/tax/example-pack.d.ts.map +1 -0
- package/dist/tax/identity.d.ts +5 -0
- package/dist/tax/identity.d.ts.map +1 -0
- package/dist/tax/index.d.ts +4 -0
- package/dist/tax/index.d.ts.map +1 -0
- package/dist/tax/legacy.d.ts +48 -0
- package/dist/tax/legacy.d.ts.map +1 -0
- package/dist/tax-summary-report-adapter.d.ts +37 -0
- package/dist/tax-summary-report-adapter.d.ts.map +1 -0
- package/dist/tax-summary.d.ts +129 -0
- package/dist/tax-summary.d.ts.map +1 -0
- package/dist/tenant-money-barrier.d.ts +66 -0
- package/dist/tenant-money-barrier.d.ts.map +1 -0
- package/dist/types/index.d.ts +137 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +19 -11
- package/dist/chunks/calculations-Bz7RB3qK.js.map +0 -1
- package/dist/chunks/money-DfrRxrel.js.map +0 -1
- package/dist/chunks/types-zVnIjSOk.js.map +0 -1
package/dist/cost-billing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-billing.js","names":["components"],"sources":["../src/cost-billing.ts"],"sourcesContent":["/** Exact, transport-neutral cost pricing. All money is signed integer minor units. */\nexport type CostBillingMode =\n | 'reimbursement-plus-fee'\n | 'fee-only'\n | 'nonbillable'\n | 'fixed-contract';\n\n/** Caller-defined precedence, most specific first. No industry hierarchy is assumed. */\nexport interface CostMarkupOverride {\n source: string;\n policy?: string;\n version?: string;\n /** Exact percent in [0, 100000], with at most six decimal places. */\n percent?: string;\n}\n\n/** Detached provenance suitable for the caller's accepted pricing snapshot. */\nexport interface ResolvedCostMarkup {\n percent: string;\n selectedIndex: number;\n overrides: CostMarkupOverride[];\n}\n\nconst SCALE = 1000000n;\nconst DENOMINATOR = 100n * SCALE;\nconst LIMIT = BigInt(Number.MAX_SAFE_INTEGER);\n\nfunction percentUnits(value: string): bigint {\n if (\n typeof value !== 'string' ||\n !/^(0|[1-9]\\d{0,5})(\\.\\d{1,6})?$/.test(value)\n ) {\n throw new TypeError(\n 'Percent must be an exact decimal string with at most six decimal places',\n );\n }\n const [whole, fraction = ''] = value.split('.');\n const units = BigInt(whole) * SCALE + BigInt(fraction.padEnd(6, '0'));\n if (units > 100000n * SCALE) throw new RangeError('Percent exceeds 100000');\n return units;\n}\n\nfunction money(value: number): bigint {\n if (!Number.isSafeInteger(value))\n throw new RangeError('Money must be safe integer minor units');\n return BigInt(value);\n}\n\nfunction safe(value: bigint): number {\n if (value > LIMIT || value < -LIMIT)\n throw new RangeError('Calculated money exceeds safe integer minor units');\n return Number(value);\n}\n\nfunction rounded(numerator: bigint): bigint {\n const magnitude = numerator < 0n ? -numerator : numerator;\n const result = (magnitude + DENOMINATOR / 2n) / DENOMINATOR;\n return numerator < 0n ? -result : result;\n}\n\nfunction identifier(value: string): void {\n if (typeof value !== 'string' || value.trim().length === 0)\n throw new TypeError('Identifiers must be nonempty strings');\n}\n\n/** Select the first supplied percent, validating even shadowed overrides. */\nexport function resolveCostMarkup(\n overrides: readonly CostMarkupOverride[],\n): ResolvedCostMarkup {\n let selectedIndex = -1;\n const copy = overrides.map((override, index) => {\n identifier(override.source);\n if (override.policy !== undefined) identifier(override.policy);\n if (override.version !== undefined) identifier(override.version);\n if (override.percent !== undefined) {\n percentUnits(override.percent);\n if (selectedIndex === -1) selectedIndex = index;\n }\n return { ...override };\n });\n if (selectedIndex === -1)\n throw new TypeError('An explicit markup percent is required');\n return {\n percent: copy[selectedIndex].percent as string,\n selectedIndex,\n overrides: copy,\n };\n}\n\n/** Calculate an explicitly supplied basis; this never reprices persisted snapshots. */\nexport function calculateCostBilling(input: {\n basisMinor: number;\n mode: CostBillingMode;\n markup: ResolvedCostMarkup;\n}): {\n principalMinor: number;\n feeMinor: number;\n totalMinor: number;\n markup: ResolvedCostMarkup;\n} {\n const basis = money(input.basisMinor);\n const markup = resolveCostMarkup(input.markup.overrides);\n if (\n markup.percent !== input.markup.percent ||\n markup.selectedIndex !== input.markup.selectedIndex\n ) {\n throw new TypeError('Resolved markup does not match its provenance');\n }\n let principal = 0n;\n let fee = 0n;\n switch (input.mode) {\n case 'reimbursement-plus-fee':\n principal = basis;\n fee = rounded(basis * percentUnits(markup.percent));\n break;\n case 'fee-only':\n fee = rounded(basis * percentUnits(markup.percent));\n break;\n case 'nonbillable':\n case 'fixed-contract':\n break;\n default:\n throw new TypeError('Unknown cost billing mode');\n }\n return {\n principalMinor: safe(principal),\n feeMinor: safe(fee),\n totalMinor: safe(principal + fee),\n markup,\n };\n}\n\n/** Explicit noncompounding tax components; an empty array means tax exempt. */\nexport interface CostBillingTaxRule {\n category: string;\n components: readonly { id: string; percent: string }[];\n}\n\n/**\n * Tax signed amounts with half-away-from-zero rounding. Invoice scope rounds each\n * component once after aggregation; line scope rounds each line/component pair.\n * A shared component ID must have the same exact rate across categories.\n */\nexport function calculateCostBillingTax(input: {\n lines: readonly { id: string; amountMinor: number; category: string }[];\n rules: readonly CostBillingTaxRule[];\n roundingScope: 'line' | 'invoice';\n}): { taxMinor: number; components: { id: string; taxMinor: number }[] } {\n if (input.roundingScope !== 'line' && input.roundingScope !== 'invoice') {\n throw new TypeError('Unknown tax rounding scope');\n }\n const categories = new Map<string, { id: string; rate: bigint }[]>();\n const rates = new Map<string, bigint>();\n const totals = new Map<string, bigint>();\n for (const rule of input.rules) {\n identifier(rule.category);\n if (categories.has(rule.category))\n throw new TypeError('Duplicate tax category');\n const seen = new Set<string>();\n const components = rule.components.map((component) => {\n identifier(component.id);\n const rate = percentUnits(component.percent);\n if (seen.has(component.id))\n throw new TypeError('Duplicate tax component');\n if (rates.has(component.id) && rates.get(component.id) !== rate)\n throw new TypeError('Conflicting tax component rate');\n seen.add(component.id);\n rates.set(component.id, rate);\n return { id: component.id, rate };\n });\n categories.set(rule.category, components);\n }\n const ids = new Set<string>();\n for (const line of input.lines) {\n identifier(line.id);\n identifier(line.category);\n if (ids.has(line.id)) throw new TypeError('Duplicate tax line');\n ids.add(line.id);\n const amount = money(line.amountMinor);\n const components = categories.get(line.category);\n if (!components)\n throw new TypeError('Missing explicit tax category mapping');\n for (const component of components) {\n const numerator = amount * component.rate;\n const tax =\n input.roundingScope === 'line' ? rounded(numerator) : numerator;\n totals.set(component.id, (totals.get(component.id) ?? 0n) + tax);\n }\n }\n let total = 0n;\n const components = Array.from(totals, ([id, value]) => {\n const tax = input.roundingScope === 'invoice' ? rounded(value) : value;\n total += tax;\n return { id, taxMinor: safe(tax) };\n });\n return { taxMinor: safe(total), components };\n}\n\n/** Caller-ordered component; only explicitly named earlier taxes enter its basis. */\nexport interface OrderedCostBillingTaxComponent {\n id: string;\n percent: string;\n priorComponentIds: readonly string[];\n}\n\n/** Explicit membership; an empty component list declares the category exempt. */\nexport interface OrderedCostBillingTaxCategory {\n category: string;\n componentIds: readonly string[];\n}\n\n/** Invoice allocation is mandatory at invoice scope and forbidden at line scope. */\nexport type OrderedCostBillingTaxInput = {\n lines: readonly { id: string; amountMinor: number; category: string }[];\n categories: readonly OrderedCostBillingTaxCategory[];\n components: readonly OrderedCostBillingTaxComponent[];\n} & (\n | { roundingScope: 'line'; invoiceAllocation?: never }\n | {\n roundingScope: 'invoice';\n invoiceAllocation: 'signed-largest-remainder';\n }\n);\n\n/** Component order follows policy; eligible line details use code-unit ID order. */\nexport interface OrderedCostBillingTaxResult {\n taxMinor: number;\n components: {\n id: string;\n taxMinor: number;\n lines: { id: string; basisMinor: number; taxMinor: number }[];\n }[];\n}\n\nfunction compareTaxLineIds(a: { id: string }, b: { id: string }): number {\n return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n}\n\n/**\n * Calculate explicitly ordered taxes without selecting jurisdiction or persistence\n * policy. Invoice allocation truncates exact line taxes toward zero, then assigns\n * residual minor units by signed remainder, ties by code-unit line ID order.\n * Full signed reversals negate allocations; caller-selected subsets use those\n * allocations, never independently rounded prior taxes. See agents/cost-billing.md.\n */\nexport function calculateOrderedCostBillingTax(\n input: OrderedCostBillingTaxInput,\n): OrderedCostBillingTaxResult {\n if (input.roundingScope === 'invoice') {\n if (input.invoiceAllocation !== 'signed-largest-remainder')\n throw new TypeError('Explicit invoice tax allocation is required');\n } else if (input.roundingScope === 'line') {\n if ('invoiceAllocation' in input)\n throw new TypeError('Invoice allocation is not valid at line scope');\n } else {\n throw new TypeError('Unknown tax rounding scope');\n }\n if (\n !Array.isArray(input.lines) ||\n !Array.isArray(input.categories) ||\n !Array.isArray(input.components)\n )\n throw new TypeError('Tax lines, categories and components must be arrays');\n\n const knownComponents = new Set<string>();\n const definitions = input.components.map((component) => {\n identifier(component.id);\n if (knownComponents.has(component.id))\n throw new TypeError('Duplicate tax component');\n const rate = percentUnits(component.percent);\n if (!Array.isArray(component.priorComponentIds))\n throw new TypeError('Explicit prior tax component IDs are required');\n const priorIds = new Set<string>();\n for (const id of component.priorComponentIds) {\n identifier(id);\n if (!knownComponents.has(id))\n throw new TypeError('Prior tax component must precede this component');\n if (priorIds.has(id))\n throw new TypeError('Duplicate prior tax component');\n priorIds.add(id);\n }\n knownComponents.add(component.id);\n return { id: component.id, rate, priorIds };\n });\n const categories = new Map<string, Set<string>>();\n for (const category of input.categories) {\n identifier(category.category);\n if (categories.has(category.category))\n throw new TypeError('Duplicate tax category');\n if (!Array.isArray(category.componentIds))\n throw new TypeError('Explicit category tax component IDs are required');\n const ids = new Set<string>();\n for (const id of category.componentIds) {\n identifier(id);\n if (!knownComponents.has(id))\n throw new TypeError('Unknown category tax component');\n if (ids.has(id)) throw new TypeError('Duplicate category tax component');\n ids.add(id);\n }\n categories.set(category.category, ids);\n }\n const lineIds = new Set<string>();\n const lines = input.lines\n .map((line) => {\n identifier(line.id);\n identifier(line.category);\n if (lineIds.has(line.id)) throw new TypeError('Duplicate tax line');\n lineIds.add(line.id);\n const eligible = categories.get(line.category);\n if (!eligible)\n throw new TypeError('Missing explicit tax category mapping');\n return {\n id: line.id,\n net: money(line.amountMinor),\n eligible,\n taxes: new Map<string, bigint>(),\n };\n })\n .sort(compareTaxLineIds);\n\n let total = 0n;\n const components = definitions.map((component) => {\n const allocations = lines\n .filter((line) => line.eligible.has(component.id))\n .map((line) => {\n let basis = line.net;\n for (const id of component.priorIds) basis += line.taxes.get(id) ?? 0n;\n const numerator = basis * component.rate;\n return {\n id: line.id,\n line,\n basisMinor: safe(basis),\n numerator,\n remainder: numerator % DENOMINATOR,\n tax:\n input.roundingScope === 'line'\n ? rounded(numerator)\n : numerator / DENOMINATOR,\n };\n });\n let tax = allocations.reduce((sum, allocation) => sum + allocation.tax, 0n);\n if (input.roundingScope === 'invoice') {\n const target = rounded(\n allocations.reduce((sum, a) => sum + a.numerator, 0n),\n );\n const residual = target - tax;\n if (residual !== 0n) {\n const direction = residual > 0n ? 1n : -1n;\n const ranked = [...allocations].sort((a, b) => {\n const difference = (b.remainder - a.remainder) * direction;\n return difference < 0n\n ? -1\n : difference > 0n\n ? 1\n : compareTaxLineIds(a, b);\n });\n const count = residual * direction;\n for (let index = 0; BigInt(index) < count; index++)\n ranked[index].tax += direction;\n }\n tax = target;\n }\n total += tax;\n return {\n id: component.id,\n taxMinor: safe(tax),\n lines: allocations.map((allocation) => {\n allocation.line.taxes.set(component.id, allocation.tax);\n return {\n id: allocation.id,\n basisMinor: allocation.basisMinor,\n taxMinor: safe(allocation.tax),\n };\n }),\n };\n });\n return { ta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,SAAS,IACjB,YAAY;GACpB;EACF,CAAC;EACH,IAAI,MAAM,YAAY,QAAQ,KAAK,eAAe,MAAM,WAAW,KAAK,EAAE;EAC1E,IAAI,MAAM,kBAAkB,WAAW;GACrC,MAAM,SAAS,QACb,YAAY,QAAQ,KAAK,MAAM,MAAM,EAAE,WAAW,EAAE,CACtD;GACA,MAAM,WAAW,SAAS;GAC1B,IAAI,aAAa,IAAI;IACnB,MAAM,YAAY,WAAW,KAAK,KAAK,CAAC;IACxC,MAAM,SAAS,CAAC,GAAG,WAAW,CAAA,CAAE,MAAM,GAAG,MAAM;KAC7C,MAAM,cAAc,EAAE,YAAY,EAAE,aAAa;KACjD,OAAO,aAAa,KAChB,KACA,aAAa,KACX,IACA,kBAAkB,GAAG,CAAC;IAC9B,CAAC;IACD,MAAM,QAAQ,WAAW;IACzB,KAAA,IAAS,QAAQ,GAAG,OAAO,KAAK,IAAI,OAAO,SACzC,OAAO,MAAK,CAAE,OAAO;GACzB;GACA,MAAM;EACR;EACA,SAAS;EACT,OAAO;GACL,IAAI,UAAU;GACd,UAAU,KAAK,GAAG;GAClB,OAAO,YAAY,KAAK,eAAe;IACrC,WAAW,KAAK,MAAM,IAAI,UAAU,IAAI,WAAW,GAAG;IACtD,OAAO;KACL,IAAI,WAAW;KACf,YAAY,WAAW;KACvB,UAAU,KAAK,WAAW,GAAG;IAC/B;GACF,CAAC;EACH;CACF,CAAC;CACD,OAAO;EAAE,UAAU,KAAK,KAAK;EAAG;CAAW;AAC7C"}
|
|
1
|
+
{"version":3,"file":"cost-billing.js","names":["components"],"sources":["../src/cost-billing.ts"],"sourcesContent":["/** Exact, transport-neutral cost pricing. All money is signed integer minor units. */\nimport {\n allocateSignedRationals,\n roundSignedRational,\n} from './money-rational.js';\nexport type CostBillingMode =\n | 'reimbursement-plus-fee'\n | 'fee-only'\n | 'nonbillable'\n | 'fixed-contract';\n\n/** Caller-defined precedence, most specific first. No industry hierarchy is assumed. */\nexport interface CostMarkupOverride {\n source: string;\n policy?: string;\n version?: string;\n /** Exact percent in [0, 100000], with at most six decimal places. */\n percent?: string;\n}\n\n/** Detached provenance suitable for the caller's accepted pricing snapshot. */\nexport interface ResolvedCostMarkup {\n percent: string;\n selectedIndex: number;\n overrides: CostMarkupOverride[];\n}\n\nconst SCALE = 1000000n;\nconst DENOMINATOR = 100n * SCALE;\nconst LIMIT = BigInt(Number.MAX_SAFE_INTEGER);\n\nfunction percentUnits(value: string): bigint {\n if (\n typeof value !== 'string' ||\n !/^(0|[1-9]\\d{0,5})(\\.\\d{1,6})?$/.test(value)\n ) {\n throw new TypeError(\n 'Percent must be an exact decimal string with at most six decimal places',\n );\n }\n const [whole, fraction = ''] = value.split('.');\n const units = BigInt(whole) * SCALE + BigInt(fraction.padEnd(6, '0'));\n if (units > 100000n * SCALE) throw new RangeError('Percent exceeds 100000');\n return units;\n}\n\nfunction money(value: number): bigint {\n if (!Number.isSafeInteger(value))\n throw new RangeError('Money must be safe integer minor units');\n return BigInt(value);\n}\n\nfunction safe(value: bigint): number {\n if (value > LIMIT || value < -LIMIT)\n throw new RangeError('Calculated money exceeds safe integer minor units');\n return Number(value);\n}\n\nfunction rounded(numerator: bigint): bigint {\n return roundSignedRational(numerator, DENOMINATOR);\n}\n\nfunction identifier(value: string): void {\n if (typeof value !== 'string' || value.trim().length === 0)\n throw new TypeError('Identifiers must be nonempty strings');\n}\n\n/** Select the first supplied percent, validating even shadowed overrides. */\nexport function resolveCostMarkup(\n overrides: readonly CostMarkupOverride[],\n): ResolvedCostMarkup {\n let selectedIndex = -1;\n const copy = overrides.map((override, index) => {\n identifier(override.source);\n if (override.policy !== undefined) identifier(override.policy);\n if (override.version !== undefined) identifier(override.version);\n if (override.percent !== undefined) {\n percentUnits(override.percent);\n if (selectedIndex === -1) selectedIndex = index;\n }\n return { ...override };\n });\n if (selectedIndex === -1)\n throw new TypeError('An explicit markup percent is required');\n return {\n percent: copy[selectedIndex].percent as string,\n selectedIndex,\n overrides: copy,\n };\n}\n\n/** Calculate an explicitly supplied basis; this never reprices persisted snapshots. */\nexport function calculateCostBilling(input: {\n basisMinor: number;\n mode: CostBillingMode;\n markup: ResolvedCostMarkup;\n}): {\n principalMinor: number;\n feeMinor: number;\n totalMinor: number;\n markup: ResolvedCostMarkup;\n} {\n const basis = money(input.basisMinor);\n const markup = resolveCostMarkup(input.markup.overrides);\n if (\n markup.percent !== input.markup.percent ||\n markup.selectedIndex !== input.markup.selectedIndex\n ) {\n throw new TypeError('Resolved markup does not match its provenance');\n }\n let principal = 0n;\n let fee = 0n;\n switch (input.mode) {\n case 'reimbursement-plus-fee':\n principal = basis;\n fee = rounded(basis * percentUnits(markup.percent));\n break;\n case 'fee-only':\n fee = rounded(basis * percentUnits(markup.percent));\n break;\n case 'nonbillable':\n case 'fixed-contract':\n break;\n default:\n throw new TypeError('Unknown cost billing mode');\n }\n return {\n principalMinor: safe(principal),\n feeMinor: safe(fee),\n totalMinor: safe(principal + fee),\n markup,\n };\n}\n\n/** Explicit noncompounding tax components; an empty array means tax exempt. */\nexport interface CostBillingTaxRule {\n category: string;\n components: readonly { id: string; percent: string }[];\n}\n\n/**\n * Tax signed amounts with half-away-from-zero rounding. Invoice scope rounds each\n * component once after aggregation; line scope rounds each line/component pair.\n * A shared component ID must have the same exact rate across categories.\n */\nexport function calculateCostBillingTax(input: {\n lines: readonly { id: string; amountMinor: number; category: string }[];\n rules: readonly CostBillingTaxRule[];\n roundingScope: 'line' | 'invoice';\n}): { taxMinor: number; components: { id: string; taxMinor: number }[] } {\n if (input.roundingScope !== 'line' && input.roundingScope !== 'invoice') {\n throw new TypeError('Unknown tax rounding scope');\n }\n const categories = new Map<string, { id: string; rate: bigint }[]>();\n const rates = new Map<string, bigint>();\n const totals = new Map<string, bigint>();\n for (const rule of input.rules) {\n identifier(rule.category);\n if (categories.has(rule.category))\n throw new TypeError('Duplicate tax category');\n const seen = new Set<string>();\n const components = rule.components.map((component) => {\n identifier(component.id);\n const rate = percentUnits(component.percent);\n if (seen.has(component.id))\n throw new TypeError('Duplicate tax component');\n if (rates.has(component.id) && rates.get(component.id) !== rate)\n throw new TypeError('Conflicting tax component rate');\n seen.add(component.id);\n rates.set(component.id, rate);\n return { id: component.id, rate };\n });\n categories.set(rule.category, components);\n }\n const ids = new Set<string>();\n for (const line of input.lines) {\n identifier(line.id);\n identifier(line.category);\n if (ids.has(line.id)) throw new TypeError('Duplicate tax line');\n ids.add(line.id);\n const amount = money(line.amountMinor);\n const components = categories.get(line.category);\n if (!components)\n throw new TypeError('Missing explicit tax category mapping');\n for (const component of components) {\n const numerator = amount * component.rate;\n const tax =\n input.roundingScope === 'line' ? rounded(numerator) : numerator;\n totals.set(component.id, (totals.get(component.id) ?? 0n) + tax);\n }\n }\n let total = 0n;\n const components = Array.from(totals, ([id, value]) => {\n const tax = input.roundingScope === 'invoice' ? rounded(value) : value;\n total += tax;\n return { id, taxMinor: safe(tax) };\n });\n return { taxMinor: safe(total), components };\n}\n\n/** Caller-ordered component; only explicitly named earlier taxes enter its basis. */\nexport interface OrderedCostBillingTaxComponent {\n id: string;\n percent: string;\n priorComponentIds: readonly string[];\n}\n\n/** Explicit membership; an empty component list declares the category exempt. */\nexport interface OrderedCostBillingTaxCategory {\n category: string;\n componentIds: readonly string[];\n}\n\n/** Invoice allocation is mandatory at invoice scope and forbidden at line scope. */\nexport type OrderedCostBillingTaxInput = {\n lines: readonly { id: string; amountMinor: number; category: string }[];\n categories: readonly OrderedCostBillingTaxCategory[];\n components: readonly OrderedCostBillingTaxComponent[];\n} & (\n | { roundingScope: 'line'; invoiceAllocation?: never }\n | {\n roundingScope: 'invoice';\n invoiceAllocation: 'signed-largest-remainder';\n }\n);\n\n/** Component order follows policy; eligible line details use code-unit ID order. */\nexport interface OrderedCostBillingTaxResult {\n taxMinor: number;\n components: {\n id: string;\n taxMinor: number;\n lines: { id: string; basisMinor: number; taxMinor: number }[];\n }[];\n}\n\nfunction compareTaxLineIds(a: { id: string }, b: { id: string }): number {\n return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n}\n\n/**\n * Calculate explicitly ordered taxes without selecting jurisdiction or persistence\n * policy. Invoice allocation truncates exact line taxes toward zero, then assigns\n * residual minor units by signed remainder, ties by code-unit line ID order.\n * Full signed reversals negate allocations; caller-selected subsets use those\n * allocations, never independently rounded prior taxes. See agents/cost-billing.md.\n */\nexport function calculateOrderedCostBillingTax(\n input: OrderedCostBillingTaxInput,\n): OrderedCostBillingTaxResult {\n if (input.roundingScope === 'invoice') {\n if (input.invoiceAllocation !== 'signed-largest-remainder')\n throw new TypeError('Explicit invoice tax allocation is required');\n } else if (input.roundingScope === 'line') {\n if ('invoiceAllocation' in input)\n throw new TypeError('Invoice allocation is not valid at line scope');\n } else {\n throw new TypeError('Unknown tax rounding scope');\n }\n if (\n !Array.isArray(input.lines) ||\n !Array.isArray(input.categories) ||\n !Array.isArray(input.components)\n )\n throw new TypeError('Tax lines, categories and components must be arrays');\n\n const knownComponents = new Set<string>();\n const definitions = input.components.map((component) => {\n identifier(component.id);\n if (knownComponents.has(component.id))\n throw new TypeError('Duplicate tax component');\n const rate = percentUnits(component.percent);\n if (!Array.isArray(component.priorComponentIds))\n throw new TypeError('Explicit prior tax component IDs are required');\n const priorIds = new Set<string>();\n for (const id of component.priorComponentIds) {\n identifier(id);\n if (!knownComponents.has(id))\n throw new TypeError('Prior tax component must precede this component');\n if (priorIds.has(id))\n throw new TypeError('Duplicate prior tax component');\n priorIds.add(id);\n }\n knownComponents.add(component.id);\n return { id: component.id, rate, priorIds };\n });\n const categories = new Map<string, Set<string>>();\n for (const category of input.categories) {\n identifier(category.category);\n if (categories.has(category.category))\n throw new TypeError('Duplicate tax category');\n if (!Array.isArray(category.componentIds))\n throw new TypeError('Explicit category tax component IDs are required');\n const ids = new Set<string>();\n for (const id of category.componentIds) {\n identifier(id);\n if (!knownComponents.has(id))\n throw new TypeError('Unknown category tax component');\n if (ids.has(id)) throw new TypeError('Duplicate category tax component');\n ids.add(id);\n }\n categories.set(category.category, ids);\n }\n const lineIds = new Set<string>();\n const lines = input.lines\n .map((line) => {\n identifier(line.id);\n identifier(line.category);\n if (lineIds.has(line.id)) throw new TypeError('Duplicate tax line');\n lineIds.add(line.id);\n const eligible = categories.get(line.category);\n if (!eligible)\n throw new TypeError('Missing explicit tax category mapping');\n return {\n id: line.id,\n net: money(line.amountMinor),\n eligible,\n taxes: new Map<string, bigint>(),\n };\n })\n .sort(compareTaxLineIds);\n\n let total = 0n;\n const components = definitions.map((component) => {\n const allocations = lines\n .filter((line) => line.eligible.has(component.id))\n .map((line) => {\n let basis = line.net;\n for (const id of component.priorIds) basis += line.taxes.get(id) ?? 0n;\n const numerator = basis * component.rate;\n return {\n id: line.id,\n line,\n basisMinor: safe(basis),\n numerator,\n tax:\n input.roundingScope === 'line'\n ? rounded(numerator)\n : numerator / DENOMINATOR,\n };\n });\n let tax = allocations.reduce((sum, allocation) => sum + allocation.tax, 0n);\n if (input.roundingScope === 'invoice') {\n const distributed = allocateSignedRationals(\n allocations.map((allocation) => ({\n id: allocation.id,\n numerator: allocation.numerator,\n denominator: DENOMINATOR,\n })),\n );\n const byId = new Map(\n distributed.allocations.map((allocation) => [\n allocation.id,\n allocation.value,\n ]),\n );\n for (const allocation of allocations)\n allocation.tax = byId.get(allocation.id) as bigint;\n tax = distributed.target;\n }\n total += tax;\n return {\n id: component.id,\n taxMinor: safe(tax),\n lines: allocations.map((allocation) => {\n allocation.line.taxes.set(component.id, allocation.tax);\n return {\n id: allocation.id,\n basisMinor: allocation.basisMinor,\n taxMinor: safe(allocation.tax),\n };\n }),\n };\n });\n return { taxMinor: safe(total), components };\n}\n"],"mappings":";;AA2BA,IAAM,QAAQ;AACd,IAAM,cAAc,OAAO;AAC3B,IAAM,QAAQ,OAAO,OAAO,gBAAgB;AAE5C,SAAS,aAAa,OAAuB;CAC3C,IACE,OAAO,UAAU,YACjB,CAAC,iCAAiC,KAAK,KAAK,GAE5C,MAAM,IAAI,UACR,yEACF;CAEF,MAAM,CAAC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b,CAAC,CACH;GACA,KAAA,MAAW,cAAc,aACvB,WAAW,MAAM,KAAK,IAAI,WAAW,EAAE;GACzC,MAAM,YAAY;EACpB;EACA,SAAS;EACT,OAAO;GACL,IAAI,UAAU;GACd,UAAU,KAAK,GAAG;GAClB,OAAO,YAAY,KAAK,eAAe;IACrC,WAAW,KAAK,MAAM,IAAI,UAAU,IAAI,WAAW,GAAG;IACtD,OAAO;KACL,IAAI,WAAW;KACf,YAAY,WAAW;KACvB,UAAU,KAAK,WAAW,GAAG;IAC/B;GACF,CAAC;EACH;CACF,CAAC;CACD,OAAO;EAAE,UAAU,KAAK,KAAK;EAAG;CAAW;AAC7C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Pure allocation of positive credit requests against frozen invoice lines. */
|
|
2
|
+
import type { InvoiceCreditCalculationBasis } from './types/index.js';
|
|
3
|
+
export interface FrozenCreditSourceLine {
|
|
4
|
+
id: string;
|
|
5
|
+
quantity: string;
|
|
6
|
+
netMinor: number;
|
|
7
|
+
discountMinor: number;
|
|
8
|
+
unitPrice: number;
|
|
9
|
+
discountType: 'none' | 'percent' | 'amount';
|
|
10
|
+
discountRate: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IssuedCreditConsumption {
|
|
13
|
+
creditedLineId: string;
|
|
14
|
+
quantity: string;
|
|
15
|
+
netMinor: number;
|
|
16
|
+
discountMinor: number;
|
|
17
|
+
}
|
|
18
|
+
export type FrozenCreditRequest = {
|
|
19
|
+
creditedLineId: string;
|
|
20
|
+
quantity: string;
|
|
21
|
+
} | {
|
|
22
|
+
creditedLineId: string;
|
|
23
|
+
netMinor: number;
|
|
24
|
+
};
|
|
25
|
+
export interface FrozenCreditAllocation {
|
|
26
|
+
creditedLineId: string;
|
|
27
|
+
basis: InvoiceCreditCalculationBasis;
|
|
28
|
+
netMinor: number | null;
|
|
29
|
+
discountMinor: number;
|
|
30
|
+
/** Signed tax-exclusive source capacity remaining before this allocation. */
|
|
31
|
+
remainingNetMinor: number;
|
|
32
|
+
exhaustsLine: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface FrozenCreditAllocationResult {
|
|
35
|
+
allocations: FrozenCreditAllocation[];
|
|
36
|
+
exhaustsDocument: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface AvailableRefundInput {
|
|
39
|
+
sourceTotalMinor: number;
|
|
40
|
+
sourcePaidMinor: number;
|
|
41
|
+
issuedCreditMinor: number;
|
|
42
|
+
settledRefundMinor: number;
|
|
43
|
+
}
|
|
44
|
+
/** Exact unapplied credit available to refund across one source invoice. */
|
|
45
|
+
export declare function calculateAvailableRefund(input: AvailableRefundInput): number;
|
|
46
|
+
/** Validate caps and normalize flat-discount/final-residual allocation. */
|
|
47
|
+
export declare function allocateFrozenCredit(sourceLines: readonly FrozenCreditSourceLine[], issued: readonly IssuedCreditConsumption[], requests: readonly FrozenCreditRequest[]): FrozenCreditAllocationResult;
|
|
48
|
+
//# sourceMappingURL=credit-allocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-allocation.d.ts","sourceRoot":"","sources":["../src/credit-allocation.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAIhF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AA2BtE,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC5C,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,6BAA6B,CAAC;IACrC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,4BAA4B;IAC3C,WAAW,EAAE,sBAAsB,EAAE,CAAC;IACtC,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,4EAA4E;AAC5E,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAiB5E;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,SAAS,sBAAsB,EAAE,EAC9C,MAAM,EAAE,SAAS,uBAAuB,EAAE,EAC1C,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GACvC,4BAA4B,CAuM9B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Internal capabilities shared by commerce document-money persistence. */
|
|
2
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
3
|
+
/**
|
|
4
|
+
* Capability required by derived money rows. This module is intentionally not
|
|
5
|
+
* exported from the package root; aggregate persistence owns every mutation.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DOCUMENT_MONEY_WRITE: unique symbol;
|
|
8
|
+
export type DocumentMoneyWriteCapability = typeof DOCUMENT_MONEY_WRITE;
|
|
9
|
+
/** Internal capability for the server-owned tenant money migration marker. */
|
|
10
|
+
export declare const MONEY_MIGRATION_WRITE: unique symbol;
|
|
11
|
+
export type MoneyMigrationWriteCapability = typeof MONEY_MIGRATION_WRITE;
|
|
12
|
+
/** Internal capability for returning a locked snapshot on its root executor. */
|
|
13
|
+
export declare const DOCUMENT_MONEY_READ_REBIND: unique symbol;
|
|
14
|
+
export type DocumentMoneyReadRebindCapability = typeof DOCUMENT_MONEY_READ_REBIND;
|
|
15
|
+
export interface MoneyParentLockCollection {
|
|
16
|
+
readonly tableName: string;
|
|
17
|
+
query(sql: string, params: unknown[], options: {
|
|
18
|
+
allowRawOnTenantScoped: true;
|
|
19
|
+
}): Promise<unknown[]>;
|
|
20
|
+
}
|
|
21
|
+
export interface MoneyParentLockTarget {
|
|
22
|
+
id: string;
|
|
23
|
+
tenantId: string;
|
|
24
|
+
collection: MoneyParentLockCollection;
|
|
25
|
+
}
|
|
26
|
+
/** Run aggregate work on one transaction-bound database executor. */
|
|
27
|
+
export declare function withDocumentMoneyTransaction<T>(db: DatabaseInterface, operation: (tx: DatabaseInterface) => Promise<T>): Promise<T>;
|
|
28
|
+
interface DocumentMoneyTransactionalObject {
|
|
29
|
+
readonly db: DatabaseInterface;
|
|
30
|
+
withTransaction<T>(operation: (bound: this) => Promise<T>): Promise<T>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Run aggregate work through the model's root transaction so rejected writes
|
|
34
|
+
* restore the instance's persistence revision before callers retry it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function withDocumentMoneyObjectTransaction<TObject extends DocumentMoneyTransactionalObject, TResult>(input: TObject, operation: (bound: TObject, tx: DatabaseInterface) => Promise<TResult>): Promise<TResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Serialize aggregate writers by touching each tenant-owned parent first.
|
|
39
|
+
* Parents are locked sequentially in stable code-unit ID order. Callers must
|
|
40
|
+
* re-read authoritative parent and child state on the same executor afterward.
|
|
41
|
+
*/
|
|
42
|
+
export declare function lockDocumentMoneyParents(targets: readonly MoneyParentLockTarget[]): Promise<void>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=document-money-internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-money-internal.d.ts","sourceRoot":"","sources":["../src/document-money-internal.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAK7E;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAAwC,CAAC;AAE1E,MAAM,MAAM,4BAA4B,GAAG,OAAO,oBAAoB,CAAC;AAEvE,8EAA8E;AAC9E,eAAO,MAAM,qBAAqB,eAAyC,CAAC;AAE5E,MAAM,MAAM,6BAA6B,GAAG,OAAO,qBAAqB,CAAC;AAEzE,gFAAgF;AAChF,eAAO,MAAM,0BAA0B,eAEtC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAC3C,OAAO,0BAA0B,CAAC;AAEpC,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,KAAK,CACH,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EAAE,EACjB,OAAO,EAAE;QAAE,sBAAsB,EAAE,IAAI,CAAA;KAAE,GACxC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CACvB;AACD,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,yBAAyB,CAAC;CACvC;AA4BD,qEAAqE;AACrE,wBAAsB,4BAA4B,CAAC,CAAC,EAClD,EAAE,EAAE,iBAAiB,EACrB,SAAS,EAAE,CAAC,EAAE,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/C,OAAO,CAAC,CAAC,CAAC,CAgBZ;AAED,UAAU,gCAAgC;IACxC,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACxE;AAED;;;GAGG;AACH,wBAAsB,kCAAkC,CACtD,OAAO,SAAS,gCAAgC,EAChD,OAAO,EAEP,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,GACrE,OAAO,CAAC,OAAO,CAAC,CAalB;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,SAAS,qBAAqB,EAAE,GACxC,OAAO,CAAC,IAAI,CAAC,CAkCf"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Transactional Invoice money aggregate persistence. */
|
|
2
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
3
|
+
import { type DocumentTaxWriteInput } from './collections/DocumentTaxCollection.js';
|
|
4
|
+
import { InvoiceCollection } from './collections/InvoiceCollection.js';
|
|
5
|
+
import type { Invoice } from './models/Invoice.js';
|
|
6
|
+
import { InvoiceLineItem } from './models/InvoiceLineItem.js';
|
|
7
|
+
type DeleteOptions = {
|
|
8
|
+
expectedUpdatedAt?: Date | string;
|
|
9
|
+
};
|
|
10
|
+
export interface PreviewInvoiceMoneyInput {
|
|
11
|
+
db: DatabaseInterface;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
invoiceId: string;
|
|
14
|
+
draft?: {
|
|
15
|
+
header?: Partial<Pick<Invoice, 'currency' | 'lineAmountType' | 'taxRoundingScope' | 'providerTaxAmount' | 'customerId'>>;
|
|
16
|
+
lines?: Array<Partial<Pick<InvoiceLineItem, 'id' | 'description' | 'productId' | 'quantity' | 'unitPrice' | 'discountType' | 'discountRate' | 'discount' | 'taxMode' | 'taxCodeId'>>>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface PreviewInvoiceMoneyResult {
|
|
20
|
+
source: 'calculated';
|
|
21
|
+
header: {
|
|
22
|
+
currency: string;
|
|
23
|
+
lineAmountType: Invoice['lineAmountType'];
|
|
24
|
+
taxRoundingScope: Invoice['taxRoundingScope'];
|
|
25
|
+
subtotalMinor: number;
|
|
26
|
+
discountTotalMinor: number;
|
|
27
|
+
taxAmountMinor: number;
|
|
28
|
+
providerTaxAmountMinor: number;
|
|
29
|
+
totalAmountMinor: number;
|
|
30
|
+
};
|
|
31
|
+
lines: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
grossMinor: number;
|
|
34
|
+
discountMinor: number;
|
|
35
|
+
amountMinor: number;
|
|
36
|
+
taxMinor: number;
|
|
37
|
+
taxCodeId: string | null;
|
|
38
|
+
taxCodeCode: string | null;
|
|
39
|
+
taxCodeName: string | null;
|
|
40
|
+
taxComponents: InvoiceLineItem['taxComponents'];
|
|
41
|
+
}>;
|
|
42
|
+
taxes: DocumentTaxWriteInput[];
|
|
43
|
+
}
|
|
44
|
+
export interface GetInvoiceMoneyFactsInput {
|
|
45
|
+
db: DatabaseInterface;
|
|
46
|
+
tenantId: string;
|
|
47
|
+
invoiceId: string;
|
|
48
|
+
}
|
|
49
|
+
export interface InvoiceMoneyFacts {
|
|
50
|
+
source: 'stored';
|
|
51
|
+
invoiceId: string;
|
|
52
|
+
moneySnapshotId: string;
|
|
53
|
+
kind: Invoice['kind'];
|
|
54
|
+
status: Invoice['status'];
|
|
55
|
+
header: PreviewInvoiceMoneyResult['header'];
|
|
56
|
+
lines: PreviewInvoiceMoneyResult['lines'];
|
|
57
|
+
taxes: DocumentTaxWriteInput[];
|
|
58
|
+
}
|
|
59
|
+
/** @internal Acquire the invoice money lock and reload persisted authority. */
|
|
60
|
+
export declare function lockAndReloadInvoice(db: DatabaseInterface, invoiceId: string, tenantId: string): Promise<{
|
|
61
|
+
collection: InvoiceCollection;
|
|
62
|
+
invoice: Invoice;
|
|
63
|
+
}>;
|
|
64
|
+
/** Calculate a proposed draft invoice in memory through the owning resolver. */
|
|
65
|
+
export declare function previewInvoiceMoney(input: PreviewInvoiceMoneyInput): Promise<PreviewInvoiceMoneyResult>;
|
|
66
|
+
/** Read authoritative persisted money facts without resolution or recalculation. */
|
|
67
|
+
export declare function getInvoiceMoneyFacts(input: GetInvoiceMoneyFactsInput): Promise<InvoiceMoneyFacts>;
|
|
68
|
+
/** Persist an invoice through either legacy compatibility or the v2 aggregate. */
|
|
69
|
+
export declare function saveInvoice(input: Invoice): Promise<Invoice>;
|
|
70
|
+
/** Migration-only draft materializer; caller already owns the tenant migration transaction. */
|
|
71
|
+
export declare function materializeInvoiceMoneyDraft(input: {
|
|
72
|
+
db: DatabaseInterface;
|
|
73
|
+
invoiceId: string;
|
|
74
|
+
tenantId: string;
|
|
75
|
+
migrationId: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
invoiceId: string;
|
|
78
|
+
taxRows: DocumentTaxWriteInput[];
|
|
79
|
+
}>;
|
|
80
|
+
/** Persist a line and recompute its complete invoice aggregate. */
|
|
81
|
+
export declare function saveInvoiceLineItem(input: InvoiceLineItem): Promise<InvoiceLineItem>;
|
|
82
|
+
export declare function deleteInvoiceLineItem(input: InvoiceLineItem, options: DeleteOptions): Promise<void>;
|
|
83
|
+
export declare function deleteInvoice(input: Invoice, options: DeleteOptions): Promise<void>;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=document-money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-money.d.ts","sourceRoot":"","sources":["../src/document-money.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAG7E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,wCAAwC,CAAC;AAChD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BAAsB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA2NlE;AAED,+FAA+F;AAC/F,wBAAsB,4BAA4B,CAAC,KAAK,EAAE;IACxD,EAAE,EAAE,iBAAiB,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,qBAAqB,EAAE,CAAA;CAAE,CAAC,CAmBnE;AAED,mEAAmE;AACnE,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,eAAe,CAAC,CA0F1B;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CA2Cf;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAgCf"}
|
package/dist/index.d.ts
CHANGED
|
@@ -62,14 +62,25 @@
|
|
|
62
62
|
*/
|
|
63
63
|
import './__smrt-register__.js';
|
|
64
64
|
export * from './billing/index.js';
|
|
65
|
-
export { ContractCollection, ContractLineItemCollection, type CreatePayoutFromPaymentArgs, CustomerCollection, FulfillmentCollection, FulfillmentLineItemCollection, InvoiceCollection, InvoiceLineItemCollection, type InvoiceNumberOptions, PaymentAllocationCollection, PaymentCollection, PaymentInstrumentCollection, PaymentIntentCollection, type PaymentIntentIdempotencyArgs, type PaymentIntentSeed, PayoutCollection, PurchaseContractCollection, SalesContractCollection, UNPAID_STATUSES, VendorCollection, } from './collections/index.js';
|
|
65
|
+
export { ContractCollection, ContractLineItemCollection, type CreatePayoutFromPaymentArgs, CustomerCollection, DocumentTaxCollection, type DocumentTaxReportFact, type DocumentTaxReportFactsOptions, FulfillmentCollection, FulfillmentLineItemCollection, InvoiceCollection, InvoiceLineItemCollection, type InvoiceNumberOptions, type InvoiceTaxReportFact, type InvoiceTaxReportFactsOptions, MoneyMigrationDocumentCollection, PaymentAllocationCollection, PaymentCollection, PaymentInstrumentCollection, PaymentIntentCollection, type PaymentIntentIdempotencyArgs, type PaymentIntentSeed, PayoutCollection, PurchaseContractCollection, type RefreshTaxSummaryReportOptions, SalesContractCollection, TaxCodeCollection, TaxComponentCollection, TaxSettingsCollection, type TaxSummaryContributorDrilldown, type TaxSummaryContributorDrilldownOptions, type TaxSummaryDrilldownContributor, type TaxSummaryDrilldownPending, type TaxSummaryExpenseSource, type TaxSummaryInvoiceDrilldownOptions, type TaxSummaryLedgerDrilldownFact, type TaxSummaryLedgerDrilldownSource, type TaxSummaryLedgerSource, TaxSummaryReportCollection, type TaxSummaryReportMeasure, type TaxSummaryReportRefreshResult, UNPAID_STATUSES, VendorCollection, } from './collections/index.js';
|
|
66
|
+
export { COMMERCE_INVOICE_LINE_ADD_TOOL_SLUG, COMMERCE_INVOICE_LINE_UPDATE_TOOL_SLUG, COMMERCE_INVOICE_PREVIEW_TOOL_SLUG, COMMERCE_TAX_CODES_LIST_TOOL_SLUG, createCommerceMoneyTools, } from './commerce-money-tools.js';
|
|
67
|
+
export { type AvailableRefundInput, allocateFrozenCredit, calculateAvailableRefund, type FrozenCreditAllocation, type FrozenCreditAllocationResult, type FrozenCreditRequest, type FrozenCreditSourceLine, type IssuedCreditConsumption, } from './credit-allocation.js';
|
|
68
|
+
export { type GetInvoiceMoneyFactsInput, getInvoiceMoneyFacts, type InvoiceMoneyFacts, type PreviewInvoiceMoneyInput, type PreviewInvoiceMoneyResult, previewInvoiceMoney, } from './document-money.js';
|
|
69
|
+
export { type FrozenAccountingReconciliationReady, type FrozenAccountingSyncResult, type FrozenInvoiceAccountingInput, type FrozenInvoiceAccountingOptions, type FrozenInvoiceAccountingSnapshot, loadFrozenInvoiceAccountingSnapshot, type QuickBooksFrozenInvoiceMapping, type ReconcileFrozenInvoiceAccountingInput, readFrozenAccountingSyncState, reconcileFrozenInvoiceAccountingSync, type SyncFrozenInvoiceToAccountingInput, syncFrozenInvoiceToAccounting, toFrozenInvoiceAccountingInput, } from './invoice-accounting-sync.js';
|
|
70
|
+
export { type InvoiceMcpGetResult, serializeInvoiceMcpGet, } from './invoice-mcp.js';
|
|
71
|
+
export { type InvoiceRecordCreditNote, type InvoiceRecordScreenData, type InvoiceRecordStoredTotals, type InvoiceRecordTaxComponent, invoiceRecordStoredTotals, type LoadInvoiceRecordScreenDataInput, loadInvoiceRecordScreenData, } from './invoice-record-screen.js';
|
|
72
|
+
export { type CommerceLineAmountDocumentReport, type CommerceLineAmountReasonCode, type CommerceLineAmountsMigrationResult, type CommerceLineAmountsReport, type CommerceLineAmountsReportOutput, type CommerceLineAmountsRollbackResult, type CommerceLineAmountTenantSummary, type CommerceMoneyTotals, type MigrateCommerceLineAmountsOptions, migrateCommerceLineAmounts, type PreflightCommerceLineAmountsOptions, preflightCommerceLineAmounts, type RollbackCommerceLineAmountsOptions, rollbackCommerceLineAmounts, serializeCommerceLineAmountsReportCsv, serializeCommerceLineAmountsReportJson, } from './migrations/commerceLineAmounts.js';
|
|
66
73
|
export { type InvoiceEditorStorageEngine, type InvoiceEditorStorageMigrationResult, type InvoiceEditorStoragePreflight, migrateInvoiceEditorStorage, preflightInvoiceEditorStorage, } from './migrations/invoiceEditorStorage.js';
|
|
67
74
|
export { COMMERCE_MONEY_COLUMNS, COMMERCE_MONEY_MINOR_UNITS_BACKFILL, COMMERCE_NATIVE_UNIT_COLUMNS, migrateCommerceMoneyToMinorUnits, preflightCommerceMoneyMinorUnits, } from './migrations/moneyMinorUnits.js';
|
|
68
75
|
export { type CommerceContractTypeGroup, type CommercePartyLinkRow, type CommercePartyLinksPreflight, preflightCommercePartyLinks, } from './migrations/partyLinks.js';
|
|
69
|
-
export { Agreement, BillingAccount, type BillingCloseKind, BillingLineSource, type BillingLineSourceType, BillingPaymentAttempt, type BillingPaymentAttemptFlag, type BillingPaymentAttemptPurpose, type BillingPaymentAttemptTransition, BillingPeriodClose, type BillingPeriodCloseStatus, type BillingStanding, Cart, Contract, ContractLineItem, Customer, Estimate, Fulfillment, FulfillmentLineItem, Invoice, InvoiceLineItem, Lease, type LicenseRightsSnapshot, LicenseSale, Order, Payment, PaymentAllocation, PaymentInstrument, PaymentIntent, Payout, ProductionOrder, PurchaseContract, PurchaseOrder, SalesContract, Vendor, WholesaleOrder, } from './models/index.js';
|
|
70
|
-
export { assertIntegerMinorUnits } from './money.js';
|
|
76
|
+
export { Agreement, BillingAccount, type BillingCloseKind, BillingLineSource, type BillingLineSourceType, BillingPaymentAttempt, type BillingPaymentAttemptFlag, type BillingPaymentAttemptPurpose, type BillingPaymentAttemptTransition, BillingPeriodClose, type BillingPeriodCloseStatus, type BillingStanding, Cart, type CommerceDocumentType, Contract, ContractLineItem, Customer, DocumentTax, type DocumentTaxOptions, Estimate, Fulfillment, FulfillmentLineItem, Invoice, InvoiceLineItem, Lease, type LicenseRightsSnapshot, LicenseSale, MoneyMigrationDocument, type MoneyMigrationDocumentOptions, type MoneyMigrationDocumentState, type MoneyMigrationDocumentType, Order, Payment, PaymentAllocation, PaymentInstrument, PaymentIntent, Payout, ProductionOrder, PurchaseContract, PurchaseOrder, SalesContract, TaxCode, TaxComponent, TaxSettings, TaxSummaryReport, type TaxSummaryReportRowKind, Vendor, WholesaleOrder, } from './models/index.js';
|
|
77
|
+
export { assertIntegerMinorUnits, calculateMoneyDocument, type LineAmountType, type MoneyDiscountInput, type MoneyDocumentResult, type MoneyDocumentTaxResult, type MoneyLineInput, type MoneyLineResult, type MoneyTaxCodeInput, type MoneyValidationCode, MoneyValidationError, type ResolvableTaxCodeInput, type ResolvedLineTaxCode, type ResolveLineTaxCodeContext, type ResolveLineTaxCodeInput, resolveLineTaxCode, type TaxCodeAppliesTo, type TaxCodeKind, type TaxCodeResolutionSource, type TaxComponentInput, type TaxRoundingScope, } from './money.js';
|
|
71
78
|
export { applyPartyContactIntent, DEFAULT_PARTY_CONTACT_FIELD_NAMES, normalizePartyContacts, PARTY_CONTACT_MAX_LENGTHS, type PartyContactErrorCode, type PartyContactField, type PartyContactFieldNames, type PartyContactFormSource, type PartyContactInput, type PartyContactIntents, PartyContactPartyNotFoundError, PartyContactPayloadError, type PartyContactRowErrors, PartyContactValidationError, readPartyContactRows, type SavePartyContactsOptions, savePartyContacts, validatePartyContactRows, } from './party-contacts.js';
|
|
72
79
|
export { AgreementsRecipe, CustomersRecipe, EstimatesRecipe, FulfillmentRecipe, InvoicingRecipe, LeasesRecipe, LicensesRecipe, PurchasesRecipe, SalesRecipe, VendorsRecipe, WholesaleRecipe, } from './recipes.js';
|
|
73
|
-
export {
|
|
80
|
+
export { buildRevenueJournalEntries, type RevenueJournalDocumentInput, type RevenueJournalEntry, type RevenueJournalLineInput, type RevenueJournalOptions, type RevenueJournalResult, type RevenueJournalTaxInput, type RevenueJournalWarning, } from './revenue-journal.js';
|
|
81
|
+
export { applyCommerceCookbookSettings, applyCookbookTaxSettings, applyTaxCodeExamplePack, COMMON_TAX_CODE_EXAMPLE_PACK, type CookbookTaxSettingsInput, cookbookTaxSettings, ensureTenantTaxCodes, type LegacyTaxMapReport, type LegacyTaxRateRow, type MapLegacyTaxRatesOptions, mapLegacyTaxRates, mapLegacyTaxRatesInTransaction, type TaxCodeExamplePack, } from './tax/index.js';
|
|
82
|
+
export { aggregateTaxSummary, type TaxSummaryComponentMapping, type TaxSummaryComponentRow, type TaxSummaryDirection, type TaxSummaryExpenseFact, type TaxSummaryInput, type TaxSummaryKindRow, type TaxSummaryLedgerMovement, type TaxSummaryReconciliationRow, type TaxSummaryResult, type TaxSummarySourceScope, type TaxSummaryStoredFact, type TaxSummaryWarning, } from './tax-summary.js';
|
|
83
|
+
export { buildTaxSummaryReportAdapterDescriptor, createTaxSummaryMaterializedReportHost, drilldownTaxSummaryContributors, drilldownTaxSummaryInvoiceFacts, TAX_SUMMARY_REPORT_ADAPTER, type TaxSummaryMaterializedReportDrilldownSources, type TaxSummaryMaterializedReportHostOptions, } from './tax-summary-report-adapter.js';
|
|
84
|
+
export { type Address, type CancelRevenueOptions, ContractStatus, ContractType, CustomerStatus, CustomerType, FulfillmentStatus, FulfillmentType, type InvoiceCollectionMethod, type InvoiceCreditCalculationBasis, type InvoiceKind, InvoiceStatus, type PartyContact, PaymentInstrumentStatus, PaymentIntentStatus, type PaymentKind, PaymentMethod, type PaymentOption, PaymentStatus, PayoutStatus, type PurchaseContractOptions, type PurchaseOrderOptions, type RecognizeRevenueOptions, type RecordPaymentOptions, type SalesContractOptions, VendorStatus, } from './types/index.js';
|
|
74
85
|
export { COMMERCE_MODULE_META, COMMERCE_UI_SLOTS } from './ui.js';
|
|
75
86
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAKH,OAAO,wBAAwB,CAAC;AAGhC,cAAc,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAKH,OAAO,wBAAwB,CAAC;AAGhC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,KAAK,2BAA2B,EAChC,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,qBAAqB,EACrB,6BAA6B,EAC7B,iBAAiB,EACjB,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EACjC,gCAAgC,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