@happyvertical/smrt-commerce 0.62.5 → 0.62.7

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 (76) hide show
  1. package/AGENTS.md +1 -0
  2. package/agents/accounting-connection.md +76 -0
  3. package/agents/accounting-live-gate.md +40 -0
  4. package/agents/accounting-mapping.md +60 -0
  5. package/agents/accounting-payment-sync.md +88 -0
  6. package/agents/ordinary-accounting.md +3 -0
  7. package/dist/accounting-connection.d.ts +179 -0
  8. package/dist/accounting-connection.d.ts.map +1 -0
  9. package/dist/accounting-live-gate.d.ts +50 -0
  10. package/dist/accounting-live-gate.d.ts.map +1 -0
  11. package/dist/accounting-mapping.d.ts +189 -0
  12. package/dist/accounting-mapping.d.ts.map +1 -0
  13. package/dist/accounting-payment-sync.d.ts +233 -0
  14. package/dist/accounting-payment-sync.d.ts.map +1 -0
  15. package/dist/accounting-provider-adapters.d.ts +97 -0
  16. package/dist/accounting-provider-adapters.d.ts.map +1 -0
  17. package/dist/chunks/{InvoiceCollection-Cc-fJrHy.js → InvoiceCollection-xooQnUwq.js} +10 -10
  18. package/dist/chunks/{InvoiceCollection-Cc-fJrHy.js.map → InvoiceCollection-xooQnUwq.js.map} +1 -1
  19. package/dist/chunks/{allocation-integrity-CvXQm3wK.js → allocation-integrity-C4SZJcao.js} +6 -6
  20. package/dist/chunks/{allocation-integrity-CvXQm3wK.js.map → allocation-integrity-C4SZJcao.js.map} +1 -1
  21. package/dist/chunks/{contract-money-BoKHNfV6.js → contract-money-ATacxU6t.js} +4 -7
  22. package/dist/chunks/{contract-money-BoKHNfV6.js.map → contract-money-ATacxU6t.js.map} +1 -1
  23. package/dist/chunks/{invoice-posting-DlR_-TG1.js → invoice-posting-CDfxug3Q.js} +4 -5
  24. package/dist/chunks/{invoice-posting-DlR_-TG1.js.map → invoice-posting-CDfxug3Q.js.map} +1 -1
  25. package/dist/chunks/retention-accounting-BA4wXUQc.js +8710 -0
  26. package/dist/chunks/retention-accounting-BA4wXUQc.js.map +1 -0
  27. package/dist/chunks/{tenant-money-barrier-Bmu4YiID.js → tenant-money-barrier-BdyXIVT5.js} +3 -3
  28. package/dist/chunks/{tenant-money-barrier-Bmu4YiID.js.map → tenant-money-barrier-BdyXIVT5.js.map} +1 -1
  29. package/dist/collections/AccountingConnectionCollection.d.ts +27 -0
  30. package/dist/collections/AccountingConnectionCollection.d.ts.map +1 -0
  31. package/dist/collections/AccountingMappingCollection.d.ts +24 -0
  32. package/dist/collections/AccountingMappingCollection.d.ts.map +1 -0
  33. package/dist/collections/AccountingSyncRecordCollections.d.ts +27 -0
  34. package/dist/collections/AccountingSyncRecordCollections.d.ts.map +1 -0
  35. package/dist/collections/index.d.ts +3 -0
  36. package/dist/collections/index.d.ts.map +1 -1
  37. package/dist/index.d.ts +11 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1601 -21
  40. package/dist/index.js.map +1 -1
  41. package/dist/invoice-accounting-sync.d.ts +6 -0
  42. package/dist/invoice-accounting-sync.d.ts.map +1 -1
  43. package/dist/invoices.js +1 -1
  44. package/dist/manifest.json +6303 -3740
  45. package/dist/models/AccountingConnection.d.ts +101 -0
  46. package/dist/models/AccountingConnection.d.ts.map +1 -0
  47. package/dist/models/AccountingMapping.d.ts +85 -0
  48. package/dist/models/AccountingMapping.d.ts.map +1 -0
  49. package/dist/models/AccountingSyncRecords.d.ts +95 -0
  50. package/dist/models/AccountingSyncRecords.d.ts.map +1 -0
  51. package/dist/models/index.d.ts +3 -0
  52. package/dist/models/index.d.ts.map +1 -1
  53. package/dist/ordinary-accounting.d.ts +1 -0
  54. package/dist/ordinary-accounting.d.ts.map +1 -1
  55. package/dist/recipes.d.ts +1 -1
  56. package/dist/retention-accounting.d.ts +1 -0
  57. package/dist/retention-accounting.d.ts.map +1 -1
  58. package/dist/smrt-knowledge.json +1327 -99
  59. package/dist/smrt-knowledge.okf.md +55 -23
  60. package/package.json +18 -18
  61. package/dist/chunks/ContractLineItemCollection-BKHy-nR8.js +0 -260
  62. package/dist/chunks/ContractLineItemCollection-BKHy-nR8.js.map +0 -1
  63. package/dist/chunks/DocumentTaxCollection-BRebznXF.js +0 -4649
  64. package/dist/chunks/DocumentTaxCollection-BRebznXF.js.map +0 -1
  65. package/dist/chunks/TaxCodeCollection-BBqCugs5.js +0 -155
  66. package/dist/chunks/TaxCodeCollection-BBqCugs5.js.map +0 -1
  67. package/dist/chunks/TaxComponentCollection-BHJjbQxq.js +0 -134
  68. package/dist/chunks/TaxComponentCollection-BHJjbQxq.js.map +0 -1
  69. package/dist/chunks/credit-allocation-yspz0Lab.js +0 -121
  70. package/dist/chunks/credit-allocation-yspz0Lab.js.map +0 -1
  71. package/dist/chunks/retention-accounting-D0KzSw3f.js +0 -3069
  72. package/dist/chunks/retention-accounting-D0KzSw3f.js.map +0 -1
  73. package/dist/chunks/retention-accounting-internal-DNxLLVvK.js +0 -30
  74. package/dist/chunks/retention-accounting-internal-DNxLLVvK.js.map +0 -1
  75. package/dist/chunks/units-8ElbjVZK.js +0 -60
  76. package/dist/chunks/units-8ElbjVZK.js.map +0 -1
@@ -1,30 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- //#region src/ordinary-accounting-internal.ts
3
- var authority$1 = new AsyncLocalStorage();
4
- function withOrdinaryAccountingAuthority(tenantId, invoiceId, operation) {
5
- return authority$1.run({
6
- tenantId,
7
- invoiceId
8
- }, operation);
9
- }
10
- function hasOrdinaryAccountingAuthority(tenantId, invoiceId) {
11
- const current = authority$1.getStore();
12
- return !!current && current.tenantId === tenantId && current.invoiceId === invoiceId;
13
- }
14
- //#endregion
15
- //#region src/retention-accounting-internal.ts
16
- var authority = new AsyncLocalStorage();
17
- function withRetentionAccountingAuthority(tenantId, invoiceId, operation) {
18
- return authority.run({
19
- tenantId,
20
- invoiceId
21
- }, operation);
22
- }
23
- function hasRetentionAccountingAuthority(tenantId, invoiceId) {
24
- const current = authority.getStore();
25
- return !!current && current.tenantId === tenantId && current.invoiceId === invoiceId;
26
- }
27
- //#endregion
28
- export { withOrdinaryAccountingAuthority as i, withRetentionAccountingAuthority as n, hasOrdinaryAccountingAuthority as r, hasRetentionAccountingAuthority as t };
29
-
30
- //# sourceMappingURL=retention-accounting-internal-DNxLLVvK.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retention-accounting-internal-DNxLLVvK.js","names":[],"sources":["../../src/ordinary-accounting-internal.ts","../../src/retention-accounting-internal.ts"],"sourcesContent":["/** Internal authority for the ordinary-invoice coordinator; not a public bypass. */\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nconst authority = new AsyncLocalStorage<{\n tenantId: string;\n invoiceId: string;\n}>();\nexport function withOrdinaryAccountingAuthority<T>(\n tenantId: string,\n invoiceId: string,\n operation: () => Promise<T>,\n): Promise<T> {\n return authority.run({ tenantId, invoiceId }, operation);\n}\nexport function hasOrdinaryAccountingAuthority(\n tenantId: string | null | undefined,\n invoiceId: string | null | undefined,\n): boolean {\n const current = authority.getStore();\n return (\n !!current &&\n current.tenantId === tenantId &&\n current.invoiceId === invoiceId\n );\n}\n","/** Internal authority for the retained-invoice coordinator; not a public bypass. */\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nconst authority = new AsyncLocalStorage<{\n tenantId: string;\n invoiceId: string;\n}>();\nexport function withRetentionAccountingAuthority<T>(\n tenantId: string,\n invoiceId: string,\n operation: () => Promise<T>,\n): Promise<T> {\n return authority.run({ tenantId, invoiceId }, operation);\n}\nexport function hasRetentionAccountingAuthority(\n tenantId: string | null | undefined,\n invoiceId: string | null | undefined,\n): boolean {\n const current = authority.getStore();\n return (\n !!current &&\n current.tenantId === tenantId &&\n current.invoiceId === invoiceId\n );\n}\n"],"mappings":";;AAGA,IAAM,cAAY,IAAI,kBAGnB;AACI,SAAS,gCACd,UACA,WACA,WACY;CACZ,OAAO,YAAU,IAAI;EAAE;EAAU;CAAU,GAAG,SAAS;AACzD;AACO,SAAS,+BACd,UACA,WACS;CACT,MAAM,UAAU,YAAU,SAAS;CACnC,OACE,CAAC,CAAC,WACF,QAAQ,aAAa,YACrB,QAAQ,cAAc;AAE1B;;;ACrBA,IAAM,YAAY,IAAI,kBAGnB;AACI,SAAS,iCACd,UACA,WACA,WACY;CACZ,OAAO,UAAU,IAAI;EAAE;EAAU;CAAU,GAAG,SAAS;AACzD;AACO,SAAS,gCACd,UACA,WACS;CACT,MAAM,UAAU,UAAU,SAAS;CACnC,OACE,CAAC,CAAC,WACF,QAAQ,aAAa,YACrB,QAAQ,cAAc;AAE1B"}
@@ -1,60 +0,0 @@
1
- import { ISO_4217_MINOR_UNITS } from "@happyvertical/smrt-ui/currency";
2
- //#region src/svelte/invoices/currency.ts
3
- var CURRENCY_PATTERN = /^[A-Z]{3}$/;
4
- function normalizeCurrency(currency) {
5
- const code = String(currency ?? "").trim().toUpperCase();
6
- if (!CURRENCY_PATTERN.test(code)) throw new Error(`Currency '${currency}' must be a three-letter code.`);
7
- return code;
8
- }
9
- function currencyMinorUnitExponent(currency) {
10
- const code = normalizeCurrency(currency);
11
- const exponent = ISO_4217_MINOR_UNITS.get(code);
12
- if (exponent === void 0) throw new Error(`Unsupported currency '${code}'.`);
13
- if (exponent === null) throw new Error(`Currency '${code}' does not define a minor unit.`);
14
- return exponent;
15
- }
16
- //#endregion
17
- //#region src/billing/units.ts
18
- function minorToMajorUnits(amount, currency) {
19
- if (!Number.isSafeInteger(amount)) throw new Error(`Amount ${amount} must be a safe integer number of minor units.`);
20
- return amount / 10 ** currencyMinorUnitExponent(currency);
21
- }
22
- function majorToMinorUnits(amount, currency) {
23
- if (!Number.isFinite(amount)) throw new Error(`Provider amount ${amount} is not a finite number.`);
24
- const scaled = amount * 10 ** currencyMinorUnitExponent(currency);
25
- const minor = Math.round(scaled);
26
- if (Math.abs(scaled - minor) > 1e-6 || !Number.isSafeInteger(minor)) throw new Error(`Provider amount ${amount} ${normalizeCurrency(currency)} is not a whole number of minor units.`);
27
- return minor;
28
- }
29
- async function deterministicId(parts) {
30
- const bytes = new TextEncoder().encode(JSON.stringify(parts));
31
- const uuid = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)).slice(0, 16);
32
- uuid[6] = uuid[6] & 15 | 80;
33
- uuid[8] = uuid[8] & 63 | 128;
34
- const joined = Array.from(uuid, (byte) => byte.toString(16).padStart(2, "0")).join("");
35
- return [
36
- joined.slice(0, 8),
37
- joined.slice(8, 12),
38
- joined.slice(12, 16),
39
- joined.slice(16, 20),
40
- joined.slice(20)
41
- ].join("-");
42
- }
43
- var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
44
- function canonicalTenantId(id, label = "Tenant ID") {
45
- if (typeof id !== "string" || !UUID_PATTERN.test(id)) throw new Error(`${label} must be a UUID.`);
46
- return id.toLowerCase();
47
- }
48
- function isUuid(id) {
49
- return typeof id === "string" && UUID_PATTERN.test(id);
50
- }
51
- function isTenantId(id) {
52
- return typeof id === "string" && UUID_PATTERN.test(id);
53
- }
54
- function tenantKey(id) {
55
- return id ? String(id).toLowerCase() : "";
56
- }
57
- //#endregion
58
- export { majorToMinorUnits as a, currencyMinorUnitExponent as c, isUuid as i, normalizeCurrency as l, deterministicId as n, minorToMajorUnits as o, isTenantId as r, tenantKey as s, canonicalTenantId as t };
59
-
60
- //# sourceMappingURL=units-8ElbjVZK.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"units-8ElbjVZK.js","names":[],"sources":["../../src/svelte/invoices/currency.ts","../../src/billing/units.ts"],"sourcesContent":["/** Svelte-free currency precision shared by invoice previews and billing. */\n\nimport { ISO_4217_MINOR_UNITS } from '@happyvertical/smrt-ui/currency';\n\nconst CURRENCY_PATTERN = /^[A-Z]{3}$/;\n\n/** Upper-case, validate, and return an ISO 4217-shaped currency code. */\nexport function normalizeCurrency(currency: string): string {\n const code = String(currency ?? '')\n .trim()\n .toUpperCase();\n if (!CURRENCY_PATTERN.test(code)) {\n throw new Error(`Currency '${currency}' must be a three-letter code.`);\n }\n return code;\n}\n\n/**\n * The ISO 4217 minor-unit exponent of a currency (2 for USD and RSD, 0 for\n * JPY, 3 for IQD). Unknown codes and currencies without a minor unit fail\n * closed because assigning either an inferred or invented exponent changes\n * the represented amount.\n */\nexport function currencyMinorUnitExponent(currency: string): number {\n const code = normalizeCurrency(currency);\n const exponent = ISO_4217_MINOR_UNITS.get(code);\n if (exponent === undefined)\n throw new Error(`Unsupported currency '${code}'.`);\n if (exponent === null)\n throw new Error(`Currency '${code}' does not define a minor unit.`);\n return exponent;\n}\n","/**\n * Money-unit and identity helpers for billing-period close (#3060).\n *\n * Commerce stores money as integer minor units. `@happyvertical/accounting`\n * takes and returns currency *major* units and converts to the provider's own\n * representation itself, so the only conversion this package performs is the\n * ISO 4217 one: minor units ÷ 10^exponent.\n */\n\nimport {\n currencyMinorUnitExponent,\n normalizeCurrency,\n} from '../svelte/invoices/currency.js';\n\nexport {\n currencyMinorUnitExponent,\n normalizeCurrency,\n} from '../svelte/invoices/currency.js';\n\n/** Integer minor units → major units (`1999` USD → `19.99`). */\nexport function minorToMajorUnits(amount: number, currency: string): number {\n if (!Number.isSafeInteger(amount)) {\n throw new Error(\n `Amount ${amount} must be a safe integer number of minor units.`,\n );\n }\n return amount / 10 ** currencyMinorUnitExponent(currency);\n}\n\n/**\n * Major units → integer minor units. Rejects a value that is not a whole\n * number of minor units instead of rounding it: a provider amount that does\n * not round-trip exactly means the two sides disagree about the currency.\n */\nexport function majorToMinorUnits(amount: number, currency: string): number {\n if (!Number.isFinite(amount)) {\n throw new Error(`Provider amount ${amount} is not a finite number.`);\n }\n const scaled = amount * 10 ** currencyMinorUnitExponent(currency);\n const minor = Math.round(scaled);\n if (Math.abs(scaled - minor) > 1e-6 || !Number.isSafeInteger(minor)) {\n throw new Error(\n `Provider amount ${amount} ${normalizeCurrency(currency)} is not a whole number of minor units.`,\n );\n }\n return minor;\n}\n\n/**\n * A stable UUID derived from its parts (SHA-256, version/variant bits set).\n * Deterministic ids are what make every period-close write replay-safe: a\n * retry recomputes the same identity instead of creating a second row.\n */\nexport async function deterministicId(parts: string[]): Promise<string> {\n const bytes = new TextEncoder().encode(JSON.stringify(parts));\n const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', bytes));\n const uuid = digest.slice(0, 16);\n uuid[6] = (uuid[6] & 0x0f) | 0x50;\n uuid[8] = (uuid[8] & 0x3f) | 0x80;\n const hex = Array.from(uuid, (byte) => byte.toString(16).padStart(2, '0'));\n const joined = hex.join('');\n return [\n joined.slice(0, 8),\n joined.slice(8, 12),\n joined.slice(12, 16),\n joined.slice(16, 20),\n joined.slice(20),\n ].join('-');\n}\n\nconst UUID_PATTERN =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/** Validate and lower-case a tenant UUID. */\nexport function canonicalTenantId(id: string, label = 'Tenant ID'): string {\n if (typeof id !== 'string' || !UUID_PATTERN.test(id)) {\n throw new Error(`${label} must be a UUID.`);\n }\n return id.toLowerCase();\n}\n\n/** Whether `id` is a UUID (any case), such as a billing record id. */\nexport function isUuid(id: string): boolean {\n return typeof id === 'string' && UUID_PATTERN.test(id);\n}\n\n/** Whether `id` is a tenant UUID (any case). */\nexport function isTenantId(id: string): boolean {\n return typeof id === 'string' && UUID_PATTERN.test(id);\n}\n\n/** Lower-case a possibly-empty tenant id for comparison. */\nexport function tenantKey(id: string | null | undefined): string {\n return id ? String(id).toLowerCase() : '';\n}\n"],"mappings":";;AAIA,IAAM,mBAAmB;AAGlB,SAAS,kBAAkB,UAA0B;CAC1D,MAAM,OAAO,OAAO,YAAY,EAAE,CAAA,CAC/B,KAAK,CAAA,CACL,YAAY;CACf,IAAI,CAAC,iBAAiB,KAAK,IAAI,GAC7B,MAAM,IAAI,MAAM,aAAa,SAAQ,+BAAgC;CAEvE,OAAO;AACT;AAQO,SAAS,0BAA0B,UAA0B;CAClE,MAAM,OA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