@happyvertical/smrt-ledgers 0.57.1 → 0.57.3

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 (38) hide show
  1. package/AGENTS.md +9 -0
  2. package/README.md +73 -0
  3. package/dist/chunks/{Account-b0RgfbjM.js → Account-IFuMKhPt.js} +42 -8
  4. package/dist/chunks/Account-IFuMKhPt.js.map +1 -0
  5. package/dist/chunks/Ledger-DwxK6NRF.js +68 -0
  6. package/dist/chunks/Ledger-DwxK6NRF.js.map +1 -0
  7. package/dist/collections/JournalEntries.d.ts +26 -0
  8. package/dist/collections/JournalEntries.d.ts.map +1 -1
  9. package/dist/collections/Journals.d.ts.map +1 -1
  10. package/dist/collections/Ledgers.d.ts +6 -0
  11. package/dist/collections/Ledgers.d.ts.map +1 -0
  12. package/dist/collections/index.d.ts +1 -0
  13. package/dist/collections/index.d.ts.map +1 -1
  14. package/dist/index.d.ts +5 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +380 -17
  17. package/dist/index.js.map +1 -1
  18. package/dist/manifest.json +639 -13
  19. package/dist/models/Account.d.ts +4 -0
  20. package/dist/models/Account.d.ts.map +1 -1
  21. package/dist/models/Journal.d.ts +9 -0
  22. package/dist/models/Journal.d.ts.map +1 -1
  23. package/dist/models/JournalEntry.d.ts +10 -0
  24. package/dist/models/JournalEntry.d.ts.map +1 -1
  25. package/dist/models/Ledger.d.ts +18 -0
  26. package/dist/models/Ledger.d.ts.map +1 -0
  27. package/dist/models/index.d.ts +1 -0
  28. package/dist/models/index.d.ts.map +1 -1
  29. package/dist/postings.d.ts +33 -0
  30. package/dist/postings.d.ts.map +1 -0
  31. package/dist/recipes.d.ts +9 -0
  32. package/dist/recipes.d.ts.map +1 -1
  33. package/dist/smrt-knowledge.json +475 -9
  34. package/dist/types.d.ts +23 -0
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/types.js.map +1 -1
  37. package/package.json +5 -5
  38. package/dist/chunks/Account-b0RgfbjM.js.map +0 -1
@@ -3,13 +3,13 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-ledgers",
6
- "packageVersion": "0.57.1",
6
+ "packageVersion": "0.57.3",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "a53c901842be696daf66607dcd30aa3b05ad591dccb95697fc8b4844d478d011",
11
- "packageJson": "45e64e181feb9199c9c5fb35a11ae9a42700b4937e717a80a8b1db9059f2ce2a",
12
- "agents": "a1bece3d7fcf3112b2b5193fdc51cf4438ba8446af146d1c8ac1c95c8ed2f0c8"
10
+ "manifest": "57d87e11095c7b1fd6375eb2732225e7c376b4cf3c22b855f9f9ca9c0e44b062",
11
+ "packageJson": "dd2f5d9d1e5011ceff990ca1c5dcba0a60cced637aa8b0d3ffe7dfb4bbbb594f",
12
+ "agents": "d6890f0ff56feedb3cb850c32492d202b151e612e87873347fc99f0535ca1d44"
13
13
  },
14
14
  "exports": [
15
15
  ".",
@@ -338,6 +338,8 @@
338
338
  "findWithGlobals",
339
339
  "getAccountBalance",
340
340
  "getAccountLedger",
341
+ "getCounterpartyAging",
342
+ "getCounterpartyBalances",
341
343
  "getTotalsForDateRange",
342
344
  "getTrialBalance",
343
345
  "listPostedMovements"
@@ -405,6 +407,23 @@
405
407
  ],
406
408
  "returns": "Promise<Array<object>>"
407
409
  },
410
+ {
411
+ "name": "getCounterpartyAging",
412
+ "async": true,
413
+ "params": [
414
+ "options: PostedJournalMovementOptions",
415
+ "asOf: Date"
416
+ ],
417
+ "returns": "Promise<CounterpartyAgingRow[]>"
418
+ },
419
+ {
420
+ "name": "getCounterpartyBalances",
421
+ "async": true,
422
+ "params": [
423
+ "options: PostedJournalMovementOptions"
424
+ ],
425
+ "returns": "Promise<CounterpartyBalance[]>"
426
+ },
408
427
  {
409
428
  "name": "getTotalsForDateRange",
410
429
  "async": true,
@@ -444,6 +463,18 @@
444
463
  "operation": "findByAccount",
445
464
  "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
446
465
  },
466
+ {
467
+ "kind": "cli",
468
+ "name": "journalentrycollection_getCounterpartyBalances",
469
+ "operation": "getCounterpartyBalances",
470
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
471
+ },
472
+ {
473
+ "kind": "cli",
474
+ "name": "journalentrycollection_getCounterpartyAging",
475
+ "operation": "getCounterpartyAging",
476
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
477
+ },
447
478
  {
448
479
  "kind": "cli",
449
480
  "name": "journalentrycollection_getAccountBalance",
@@ -556,6 +587,20 @@
556
587
  "reason": "not listed in api.include",
557
588
  "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
558
589
  },
590
+ {
591
+ "kind": "api",
592
+ "operation": "getCounterpartyAging",
593
+ "code": "not-included",
594
+ "reason": "not listed in api.include",
595
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
596
+ },
597
+ {
598
+ "kind": "api",
599
+ "operation": "getCounterpartyBalances",
600
+ "code": "not-included",
601
+ "reason": "not listed in api.include",
602
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
603
+ },
559
604
  {
560
605
  "kind": "api",
561
606
  "operation": "getTotalsForDateRange",
@@ -909,6 +954,23 @@
909
954
  "tags": [],
910
955
  "risks": []
911
956
  },
957
+ {
958
+ "name": "LedgerCollection",
959
+ "qualifiedName": "@happyvertical/smrt-ledgers:LedgerCollection",
960
+ "collection": "ledgers",
961
+ "tableName": "ledgers",
962
+ "packageName": "@happyvertical/smrt-ledgers",
963
+ "extends": "SmrtCollection",
964
+ "fields": [],
965
+ "relationships": [],
966
+ "methods": [],
967
+ "surfaces": [],
968
+ "relationshipFeatures": [
969
+ "uuidColumns"
970
+ ],
971
+ "tags": [],
972
+ "risks": []
973
+ },
912
974
  {
913
975
  "name": "Account",
914
976
  "qualifiedName": "@happyvertical/smrt-ledgers:Account",
@@ -963,6 +1025,14 @@
963
1025
  "default": "asset",
964
1026
  "description": "asset, liability, equity, revenue or expense."
965
1027
  },
1028
+ {
1029
+ "name": "ledgerId",
1030
+ "type": "foreignKey",
1031
+ "required": false,
1032
+ "related": "Ledger",
1033
+ "columnType": "UUID",
1034
+ "description": "The ledger policy this account belongs to."
1035
+ },
966
1036
  {
967
1037
  "name": "active",
968
1038
  "type": "boolean",
@@ -986,10 +1056,18 @@
986
1056
  "required": false,
987
1057
  "related": "Account",
988
1058
  "columnType": "UUID"
1059
+ },
1060
+ {
1061
+ "name": "ledgerId",
1062
+ "type": "foreignKey",
1063
+ "required": false,
1064
+ "related": "Ledger",
1065
+ "columnType": "UUID"
989
1066
  }
990
1067
  ],
991
1068
  "methods": [
992
1069
  "createChild",
1070
+ "delete",
993
1071
  "getAncestors",
994
1072
  "getBalance",
995
1073
  "getChildren",
@@ -1012,6 +1090,14 @@
1012
1090
  ],
1013
1091
  "returns": "Promise<Account>"
1014
1092
  },
1093
+ {
1094
+ "name": "delete",
1095
+ "async": true,
1096
+ "params": [
1097
+ "options?: any"
1098
+ ],
1099
+ "returns": "Promise<void>"
1100
+ },
1015
1101
  {
1016
1102
  "name": "getAncestors",
1017
1103
  "async": true,
@@ -1405,6 +1491,26 @@
1405
1491
  "required": false,
1406
1492
  "columnType": "TEXT"
1407
1493
  },
1494
+ {
1495
+ "name": "ledgerId",
1496
+ "type": "foreignKey",
1497
+ "required": false,
1498
+ "related": "Ledger",
1499
+ "columnType": "UUID",
1500
+ "description": "The ledger policy that governs this journal."
1501
+ },
1502
+ {
1503
+ "name": "idempotencyKey",
1504
+ "type": "text",
1505
+ "required": false,
1506
+ "columnType": "TEXT"
1507
+ },
1508
+ {
1509
+ "name": "requestDigest",
1510
+ "type": "text",
1511
+ "required": false,
1512
+ "columnType": "TEXT"
1513
+ },
1408
1514
  {
1409
1515
  "name": "status",
1410
1516
  "type": "text",
@@ -1440,10 +1546,20 @@
1440
1546
  "default": {}
1441
1547
  }
1442
1548
  ],
1443
- "relationships": [],
1549
+ "relationships": [
1550
+ {
1551
+ "name": "ledgerId",
1552
+ "type": "foreignKey",
1553
+ "required": false,
1554
+ "related": "Ledger",
1555
+ "columnType": "UUID"
1556
+ }
1557
+ ],
1444
1558
  "methods": [
1445
1559
  "addEntry",
1560
+ "delete",
1446
1561
  "getEntries",
1562
+ "getLedger",
1447
1563
  "getTotalCredits",
1448
1564
  "getTotalDebits",
1449
1565
  "isBalanced",
@@ -1452,6 +1568,7 @@
1452
1568
  "isPosted",
1453
1569
  "isVoided",
1454
1570
  "post",
1571
+ "save",
1455
1572
  "summarize",
1456
1573
  "void"
1457
1574
  ],
@@ -1464,11 +1581,24 @@
1464
1581
  ],
1465
1582
  "returns": "Promise<void>"
1466
1583
  },
1584
+ {
1585
+ "name": "delete",
1586
+ "async": true,
1587
+ "params": [
1588
+ "options?: any"
1589
+ ],
1590
+ "returns": "Promise<void>"
1591
+ },
1467
1592
  {
1468
1593
  "name": "getEntries",
1469
1594
  "async": true,
1470
1595
  "returns": "any"
1471
1596
  },
1597
+ {
1598
+ "name": "getLedger",
1599
+ "async": true,
1600
+ "returns": "any"
1601
+ },
1472
1602
  {
1473
1603
  "name": "getTotalCredits",
1474
1604
  "async": true,
@@ -1505,6 +1635,14 @@
1505
1635
  "async": true,
1506
1636
  "returns": "Promise<void>"
1507
1637
  },
1638
+ {
1639
+ "name": "save",
1640
+ "async": true,
1641
+ "params": [
1642
+ "options?: any"
1643
+ ],
1644
+ "returns": "Promise<this>"
1645
+ },
1508
1646
  {
1509
1647
  "name": "summarize",
1510
1648
  "async": true,
@@ -1632,6 +1770,12 @@
1632
1770
  "operation": "isBalanced",
1633
1771
  "objectName": "@happyvertical/smrt-ledgers:Journal"
1634
1772
  },
1773
+ {
1774
+ "kind": "cli",
1775
+ "name": "journal_getLedger",
1776
+ "operation": "getLedger",
1777
+ "objectName": "@happyvertical/smrt-ledgers:Journal"
1778
+ },
1635
1779
  {
1636
1780
  "kind": "cli",
1637
1781
  "name": "journal_addEntry",
@@ -1690,6 +1834,13 @@
1690
1834
  "reason": "not listed in api.include",
1691
1835
  "objectName": "@happyvertical/smrt-ledgers:Journal"
1692
1836
  },
1837
+ {
1838
+ "kind": "api",
1839
+ "operation": "getLedger",
1840
+ "code": "not-included",
1841
+ "reason": "not listed in api.include",
1842
+ "objectName": "@happyvertical/smrt-ledgers:Journal"
1843
+ },
1693
1844
  {
1694
1845
  "kind": "api",
1695
1846
  "operation": "getTotalCredits",
@@ -1746,6 +1897,13 @@
1746
1897
  "reason": "not listed in api.include",
1747
1898
  "objectName": "@happyvertical/smrt-ledgers:Journal"
1748
1899
  },
1900
+ {
1901
+ "kind": "api",
1902
+ "operation": "save",
1903
+ "code": "lifecycle-method",
1904
+ "reason": "`save` is a framework lifecycle method, not a distinct operation",
1905
+ "objectName": "@happyvertical/smrt-ledgers:Journal"
1906
+ },
1749
1907
  {
1750
1908
  "kind": "api",
1751
1909
  "operation": "summarize",
@@ -1762,6 +1920,7 @@
1762
1920
  }
1763
1921
  ],
1764
1922
  "relationshipFeatures": [
1923
+ "foreignKey",
1765
1924
  "uuidColumns"
1766
1925
  ],
1767
1926
  "tags": [],
@@ -1797,6 +1956,33 @@
1797
1956
  "columnType": "UUID",
1798
1957
  "description": "The account this entry changes."
1799
1958
  },
1959
+ {
1960
+ "name": "counterpartyKind",
1961
+ "type": "text",
1962
+ "required": false,
1963
+ "columnType": "TEXT",
1964
+ "description": "Generic counterparty type."
1965
+ },
1966
+ {
1967
+ "name": "counterpartyId",
1968
+ "type": "text",
1969
+ "required": false,
1970
+ "columnType": "TEXT",
1971
+ "description": "Generic counterparty identifier."
1972
+ },
1973
+ {
1974
+ "name": "dueDate",
1975
+ "type": "datetime",
1976
+ "required": false,
1977
+ "columnType": "TIMESTAMP",
1978
+ "description": "When this open receivable or payable is due."
1979
+ },
1980
+ {
1981
+ "name": "settlesSourceRef",
1982
+ "type": "text",
1983
+ "required": false,
1984
+ "columnType": "TEXT"
1985
+ },
1800
1986
  {
1801
1987
  "name": "debit",
1802
1988
  "type": "decimal",
@@ -1861,15 +2047,25 @@
1861
2047
  }
1862
2048
  ],
1863
2049
  "methods": [
2050
+ "delete",
1864
2051
  "getAccount",
1865
2052
  "getAmount",
1866
2053
  "getBaseAmount",
1867
2054
  "getDescription",
1868
2055
  "getJournal",
1869
2056
  "isCredit",
1870
- "isDebit"
2057
+ "isDebit",
2058
+ "save"
1871
2059
  ],
1872
2060
  "methodSignatures": [
2061
+ {
2062
+ "name": "delete",
2063
+ "async": true,
2064
+ "params": [
2065
+ "options?: any"
2066
+ ],
2067
+ "returns": "Promise<void>"
2068
+ },
1873
2069
  {
1874
2070
  "name": "getAccount",
1875
2071
  "async": true,
@@ -1900,6 +2096,14 @@
1900
2096
  {
1901
2097
  "name": "isDebit",
1902
2098
  "returns": "boolean"
2099
+ },
2100
+ {
2101
+ "name": "save",
2102
+ "async": true,
2103
+ "params": [
2104
+ "options?: any"
2105
+ ],
2106
+ "returns": "Promise<this>"
1903
2107
  }
1904
2108
  ],
1905
2109
  "tenant": {
@@ -2063,6 +2267,13 @@
2063
2267
  "code": "not-included",
2064
2268
  "reason": "not listed in api.include",
2065
2269
  "objectName": "@happyvertical/smrt-ledgers:JournalEntry"
2270
+ },
2271
+ {
2272
+ "kind": "api",
2273
+ "operation": "save",
2274
+ "code": "lifecycle-method",
2275
+ "reason": "`save` is a framework lifecycle method, not a distinct operation",
2276
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntry"
2066
2277
  }
2067
2278
  ],
2068
2279
  "relationshipFeatures": [
@@ -2071,6 +2282,154 @@
2071
2282
  ],
2072
2283
  "tags": [],
2073
2284
  "risks": []
2285
+ },
2286
+ {
2287
+ "name": "Ledger",
2288
+ "qualifiedName": "@happyvertical/smrt-ledgers:Ledger",
2289
+ "displayLabelField": "name",
2290
+ "collection": "ledgers",
2291
+ "description": "A named accounting scope. Exact ledgers store one currency's minor units and reject fractional entries; legacy journals without a ledger retain the tolerant balance rule for backwards compatibility.",
2292
+ "tableName": "ledgers",
2293
+ "packageName": "@happyvertical/smrt-ledgers",
2294
+ "extends": "SmrtObject",
2295
+ "fields": [
2296
+ {
2297
+ "name": "tenantId",
2298
+ "type": "text",
2299
+ "required": false,
2300
+ "columnType": "UUID"
2301
+ },
2302
+ {
2303
+ "name": "name",
2304
+ "type": "text",
2305
+ "required": false,
2306
+ "columnType": "TEXT",
2307
+ "description": "The accounting scope name."
2308
+ },
2309
+ {
2310
+ "name": "currency",
2311
+ "type": "text",
2312
+ "required": false,
2313
+ "columnType": "TEXT",
2314
+ "description": "ISO 4217 currency used by this ledger."
2315
+ },
2316
+ {
2317
+ "name": "balanceMode",
2318
+ "type": "text",
2319
+ "required": false,
2320
+ "columnType": "TEXT",
2321
+ "default": "tolerant",
2322
+ "description": "tolerant accepts decimal units; exact requires integer minor units."
2323
+ }
2324
+ ],
2325
+ "relationships": [],
2326
+ "methods": [
2327
+ "delete"
2328
+ ],
2329
+ "methodSignatures": [
2330
+ {
2331
+ "name": "delete",
2332
+ "async": true,
2333
+ "returns": "Promise<void>"
2334
+ }
2335
+ ],
2336
+ "tenant": {
2337
+ "scoped": true,
2338
+ "mode": "optional",
2339
+ "field": "tenantId"
2340
+ },
2341
+ "conflictColumns": [
2342
+ "tenant_id",
2343
+ "slug",
2344
+ "context"
2345
+ ],
2346
+ "surfaces": [
2347
+ {
2348
+ "kind": "api",
2349
+ "name": "ledgers.list",
2350
+ "operation": "list",
2351
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
2352
+ "path": "/ledgers",
2353
+ "method": "GET"
2354
+ },
2355
+ {
2356
+ "kind": "api",
2357
+ "name": "ledgers.get",
2358
+ "operation": "get",
2359
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
2360
+ "path": "/ledgers/[id]",
2361
+ "method": "GET"
2362
+ },
2363
+ {
2364
+ "kind": "api",
2365
+ "name": "ledgers.create",
2366
+ "operation": "create",
2367
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
2368
+ "path": "/ledgers",
2369
+ "method": "POST"
2370
+ },
2371
+ {
2372
+ "kind": "api",
2373
+ "name": "ledgers.update",
2374
+ "operation": "update",
2375
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
2376
+ "path": "/ledgers/[id]",
2377
+ "method": "PATCH"
2378
+ },
2379
+ {
2380
+ "kind": "cli",
2381
+ "name": "ledger_list",
2382
+ "operation": "list",
2383
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2384
+ },
2385
+ {
2386
+ "kind": "cli",
2387
+ "name": "ledger_get",
2388
+ "operation": "get",
2389
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2390
+ },
2391
+ {
2392
+ "kind": "cli",
2393
+ "name": "ledger_create",
2394
+ "operation": "create",
2395
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2396
+ },
2397
+ {
2398
+ "kind": "cli",
2399
+ "name": "ledger_update",
2400
+ "operation": "update",
2401
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2402
+ },
2403
+ {
2404
+ "kind": "cli",
2405
+ "name": "ledger_delete",
2406
+ "operation": "delete",
2407
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2408
+ },
2409
+ {
2410
+ "kind": "mcp",
2411
+ "name": "ledger_list",
2412
+ "operation": "list",
2413
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2414
+ },
2415
+ {
2416
+ "kind": "mcp",
2417
+ "name": "ledger_get",
2418
+ "operation": "get",
2419
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2420
+ },
2421
+ {
2422
+ "kind": "mcp",
2423
+ "name": "ledger_create",
2424
+ "operation": "create",
2425
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2426
+ }
2427
+ ],
2428
+ "relationshipFeatures": [
2429
+ "uuidColumns"
2430
+ ],
2431
+ "tags": [],
2432
+ "risks": []
2074
2433
  }
2075
2434
  ],
2076
2435
  "surfaces": [
@@ -2158,6 +2517,18 @@
2158
2517
  "operation": "findByAccount",
2159
2518
  "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
2160
2519
  },
2520
+ {
2521
+ "kind": "cli",
2522
+ "name": "journalentrycollection_getCounterpartyBalances",
2523
+ "operation": "getCounterpartyBalances",
2524
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
2525
+ },
2526
+ {
2527
+ "kind": "cli",
2528
+ "name": "journalentrycollection_getCounterpartyAging",
2529
+ "operation": "getCounterpartyAging",
2530
+ "objectName": "@happyvertical/smrt-ledgers:JournalEntryCollection"
2531
+ },
2161
2532
  {
2162
2533
  "kind": "cli",
2163
2534
  "name": "journalentrycollection_getAccountBalance",
@@ -2564,6 +2935,12 @@
2564
2935
  "operation": "isBalanced",
2565
2936
  "objectName": "@happyvertical/smrt-ledgers:Journal"
2566
2937
  },
2938
+ {
2939
+ "kind": "cli",
2940
+ "name": "journal_getLedger",
2941
+ "operation": "getLedger",
2942
+ "objectName": "@happyvertical/smrt-ledgers:Journal"
2943
+ },
2567
2944
  {
2568
2945
  "kind": "cli",
2569
2946
  "name": "journal_addEntry",
@@ -2705,6 +3082,86 @@
2705
3082
  "name": "journalentry_get",
2706
3083
  "operation": "get",
2707
3084
  "objectName": "@happyvertical/smrt-ledgers:JournalEntry"
3085
+ },
3086
+ {
3087
+ "kind": "api",
3088
+ "name": "ledgers.list",
3089
+ "operation": "list",
3090
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
3091
+ "path": "/ledgers",
3092
+ "method": "GET"
3093
+ },
3094
+ {
3095
+ "kind": "api",
3096
+ "name": "ledgers.get",
3097
+ "operation": "get",
3098
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
3099
+ "path": "/ledgers/[id]",
3100
+ "method": "GET"
3101
+ },
3102
+ {
3103
+ "kind": "api",
3104
+ "name": "ledgers.create",
3105
+ "operation": "create",
3106
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
3107
+ "path": "/ledgers",
3108
+ "method": "POST"
3109
+ },
3110
+ {
3111
+ "kind": "api",
3112
+ "name": "ledgers.update",
3113
+ "operation": "update",
3114
+ "objectName": "@happyvertical/smrt-ledgers:Ledger",
3115
+ "path": "/ledgers/[id]",
3116
+ "method": "PATCH"
3117
+ },
3118
+ {
3119
+ "kind": "cli",
3120
+ "name": "ledger_list",
3121
+ "operation": "list",
3122
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3123
+ },
3124
+ {
3125
+ "kind": "cli",
3126
+ "name": "ledger_get",
3127
+ "operation": "get",
3128
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3129
+ },
3130
+ {
3131
+ "kind": "cli",
3132
+ "name": "ledger_create",
3133
+ "operation": "create",
3134
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3135
+ },
3136
+ {
3137
+ "kind": "cli",
3138
+ "name": "ledger_update",
3139
+ "operation": "update",
3140
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3141
+ },
3142
+ {
3143
+ "kind": "cli",
3144
+ "name": "ledger_delete",
3145
+ "operation": "delete",
3146
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3147
+ },
3148
+ {
3149
+ "kind": "mcp",
3150
+ "name": "ledger_list",
3151
+ "operation": "list",
3152
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3153
+ },
3154
+ {
3155
+ "kind": "mcp",
3156
+ "name": "ledger_get",
3157
+ "operation": "get",
3158
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
3159
+ },
3160
+ {
3161
+ "kind": "mcp",
3162
+ "name": "ledger_create",
3163
+ "operation": "create",
3164
+ "objectName": "@happyvertical/smrt-ledgers:Ledger"
2708
3165
  }
2709
3166
  ],
2710
3167
  "prompts": [
@@ -2713,14 +3170,14 @@
2713
3170
  }
2714
3171
  ],
2715
3172
  "relationshipsV2": {
2716
- "foreignKeyFields": 3,
3173
+ "foreignKeyFields": 5,
2717
3174
  "crossPackageRefFields": 0,
2718
3175
  "junctionCollections": 0,
2719
3176
  "hierarchicalObjects": 1,
2720
3177
  "polymorphicAssociations": 0,
2721
- "uuidColumns": 18
3178
+ "uuidColumns": 26
2722
3179
  },
2723
- "agentDoc": "# @happyvertical/smrt-ledgers\n\nDouble-entry accounting with chart of accounts, journal lifecycle, and balance enforcement.\n\n## Models\n\n- **Account**: 5 types (asset/liability/equity/revenue/expense). Hierarchical via `parentId`. Debit-normal (asset, expense) vs credit-normal (liability, equity, revenue). Methods: `getAncestors()`, `getFullPath()`, `toTreeNode()`, `getBalance(asOfDate?)`. Stored in `ledger_accounts` (explicit `tableName`), never the derived `accounts`: smrt-messages declares an unrelated `Account` on that table (#3098). `src/migrations/ledger-accounts-table.ts` (`smrt db:migrate-ledger-accounts`) moves pre-#3098 rows; the README has the operator sequence.\n- **Journal**: lifecycle `draft → posted → voided`. **Immutable after posting** (can only void, not edit). `sourceModule`/`sourceRef` for cross-package attribution. Auto-numbered (e.g., \"JNL-0001\"). `summarize()` is AI-powered via the smrt-prompts registry (see Prompt Registry below).\n- **JournalEntry**: debit XOR credit (not both, validated on save). Multi-currency via `exchangeRate`. Non-negative amounts required.\n\n## Key Methods\n\n- **`Journal.summarize()`**: Generates a natural-language summary via the registered `smrtLedgers.journal.summarize` prompt, resolved through `@happyvertical/smrt-prompts`. Tenants can override the template, model, temperature, or other params via `_smrt_prompt_overrides` without code changes. Only non-PII fields (number, date, description, status, aggregate total, entry count, balanced flag) reach the AI provider.\n\n## Prompt Registry\n\nRegistered at module-load time via `definePrompt()` in `src/prompts.ts`. Side-effect imported from `src/index.ts` so consumers automatically see the prompts after importing any export from this package.\n\n| Key | Method | Variables |\n|-----|--------|-----------|\n| `smrtLedgers.journal.summarize` | `Journal.summarize()` | `journalNumber`, `journalDate`, `journalDescription`, `journalStatus`, `journalTotal`, `entryCount`, `journalBalanced` |\n\nPII-conscious variable selection: `tenantId`, `sourceRef` (may reference customer/vendor identifiers), per-entry `accountId`/`id`, and the extensible `metadata` blob are intentionally NOT exposed as prompt variables. Tenants who need richer context should override the template via `PromptOverride` and supply their own variables through a custom call site.\n\n## Balance Enforcement\n\n`journal.post()` validates `Math.abs(totalDebits - totalCredits) < BALANCE_EPSILON` where `BALANCE_EPSILON = 0.01` (float rounding tolerance). Unbalanced journals cannot be posted.\n\n**This package is unit-agnostic** — `debit` / `credit` are plain DECIMAL numbers and the balance check only compares the two sides, so it holds for whatever unit the posting module uses. As of #2401, journals posted from `@happyvertical/smrt-commerce` (`Payment.recordPayment()`, `Invoice.recognizeRevenue()`) carry **integer minor units**, which balance exactly rather than merely within the epsilon. A consumer mixing modules that post in different units will get arithmetically balanced but semantically meaningless journals; pick one unit per ledger.\n\n`JournalEntryCollection.listPostedMovements({ tenantId, accountIds, from, to,\ncurrency })` is the bounded reporting input. It joins only rows whose entry and\njournal share the requested tenant, includes every posted source (including\nmanual journals), and excludes drafts and voids. Its debit, credit, and\n`creditMinusDebit` values are raw ledger units; commerce must verify its\nminor-unit convention before using them in an exact tax report. Each returned\nmovement retains the requested `tenantId` so consumers can reject a fact that\ncrosses the reporting boundary.\n\n## Gotchas\n\n- **Float tolerance**: 0.01 epsilon for balance check — not exact equality\n- **Entry requires journalId**: save Journal first, then add entries\n- **Posted journals cannot be modified**: only voided (`voidReason`, `voidedAt`)\n- **Account types inherited by children**: child cannot differ from parent type\n- **getBalance() is async**: requires JournalEntryCollection query (not stored on Account)\n- **Optional tenancy** on all models\n- **Same-named `Account`**: reference the ledger model by constructor (`@foreignKey(Account)`) or qualified name (`@happyvertical/smrt-ledgers:Account`), never the bare string. The PostgreSQL lanes are `pnpm test:postgres` here (ledgers alone) and in smrt-messages (both packages loaded)\n",
3180
+ "agentDoc": "# @happyvertical/smrt-ledgers\n\nDouble-entry accounting with chart of accounts, journal lifecycle, and balance enforcement.\n\n## Models\n\n- **Account**: 5 types (asset/liability/equity/revenue/expense). Hierarchical via `parentId`. Debit-normal (asset, expense) vs credit-normal (liability, equity, revenue). Methods: `getAncestors()`, `getFullPath()`, `toTreeNode()`, `getBalance(asOfDate?)`. Stored in `ledger_accounts` (explicit `tableName`), never the derived `accounts`: smrt-messages declares an unrelated `Account` on that table (#3098). `src/migrations/ledger-accounts-table.ts` (`smrt db:migrate-ledger-accounts`) moves pre-#3098 rows; the README has the operator sequence.\n- **Journal**: lifecycle `draft → posted → voided`. **Immutable after posting** (can only void, not edit). `sourceModule`/`sourceRef` for cross-package attribution. Auto-numbered (e.g., \"JNL-0001\"). `summarize()` is AI-powered via the smrt-prompts registry (see Prompt Registry below).\n- **JournalEntry**: debit XOR credit (not both, validated on save). Multi-currency via `exchangeRate`. Non-negative amounts required.\n\n## Key Methods\n\n- **`Journal.summarize()`**: Generates a natural-language summary via the registered `smrtLedgers.journal.summarize` prompt, resolved through `@happyvertical/smrt-prompts`. Tenants can override the template, model, temperature, or other params via `_smrt_prompt_overrides` without code changes. Only non-PII fields (number, date, description, status, aggregate total, entry count, balanced flag) reach the AI provider.\n\n## Prompt Registry\n\nRegistered at module-load time via `definePrompt()` in `src/prompts.ts`. Side-effect imported from `src/index.ts` so consumers automatically see the prompts after importing any export from this package.\n\n| Key | Method | Variables |\n|-----|--------|-----------|\n| `smrtLedgers.journal.summarize` | `Journal.summarize()` | `journalNumber`, `journalDate`, `journalDescription`, `journalStatus`, `journalTotal`, `entryCount`, `journalBalanced` |\n\nPII-conscious variable selection: `tenantId`, `sourceRef` (may reference customer/vendor identifiers), per-entry `accountId`/`id`, and the extensible `metadata` blob are intentionally NOT exposed as prompt variables. Tenants who need richer context should override the template via `PromptOverride` and supply their own variables through a custom call site.\n\n## Balance Enforcement\n\nNamed `Ledger` scopes freeze owner, currency and balance mode at creation.\n`exact-integer` mode requires safe integer minor units and exact equality; assigned\naccounts freeze scope/owner/type and cannot be deleted. Posted scoped journals and\nlines are immutable, including void/delete; use compensating postings.\n`postReceivable`/`postPayable`/`postSettlement` require exact ledgers and use one\ntransactional claim per tenant/ledger/key with payload-digest replay validation.\nSee README for ownership, reversal, aging and dialect contracts.\n\n\n`journal.post()` validates `Math.abs(totalDebits - totalCredits) < BALANCE_EPSILON` where `BALANCE_EPSILON = 0.01` (float rounding tolerance). Unbalanced journals cannot be posted.\n\n**This package is unit-agnostic** — `debit` / `credit` are plain DECIMAL numbers and the balance check only compares the two sides, so it holds for whatever unit the posting module uses. As of #2401, journals posted from `@happyvertical/smrt-commerce` (`Payment.recordPayment()`, `Invoice.recognizeRevenue()`) carry **integer minor units**, which balance exactly rather than merely within the epsilon. A consumer mixing modules that post in different units will get arithmetically balanced but semantically meaningless journals; pick one unit per ledger.\n\n`JournalEntryCollection.listPostedMovements({ tenantId, accountIds, from, to,\ncurrency })` is the bounded reporting input. It joins only rows whose entry and\njournal share the requested tenant, includes every posted source (including\nmanual journals), and excludes drafts and voids. Its debit, credit, and\n`creditMinusDebit` values are raw ledger units; commerce must verify its\nminor-unit convention before using them in an exact tax report. Each returned\nmovement retains the requested `tenantId` so consumers can reject a fact that\ncrosses the reporting boundary.\n\n## Gotchas\n\n- **Float tolerance**: 0.01 epsilon for balance check — not exact equality\n- **Entry requires journalId**: save Journal first, then add entries\n- **Posted journals cannot be modified**: only voided (`voidReason`, `voidedAt`)\n- **Account types inherited by children**: child cannot differ from parent type\n- **getBalance() is async**: requires JournalEntryCollection query (not stored on Account)\n- **Optional tenancy** on all models\n- **Same-named `Account`**: reference the ledger model by constructor (`@foreignKey(Account)`) or qualified name (`@happyvertical/smrt-ledgers:Account`), never the bare string. The PostgreSQL lanes are `pnpm test:postgres` here (ledgers alone) and in smrt-messages (both packages loaded)\n",
2724
3181
  "recipes": [
2725
3182
  {
2726
3183
  "id": "ledgers.bookkeeping",
@@ -2779,6 +3236,12 @@
2779
3236
  "sourceRef": {
2780
3237
  "visibility": "hidden"
2781
3238
  },
3239
+ "idempotencyKey": {
3240
+ "visibility": "hidden"
3241
+ },
3242
+ "requestDigest": {
3243
+ "visibility": "hidden"
3244
+ },
2782
3245
  "voidedAt": {
2783
3246
  "visibility": "hidden"
2784
3247
  },
@@ -2795,6 +3258,9 @@
2795
3258
  "exchangeRate": {
2796
3259
  "visibility": "hidden"
2797
3260
  },
3261
+ "settlesSourceRef": {
3262
+ "visibility": "hidden"
3263
+ },
2798
3264
  "metadata": {
2799
3265
  "visibility": "hidden"
2800
3266
  }