@classytic/ledger 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +161 -64
  2. package/dist/{categories-CclX7Q94.mjs → categories-FJlrvzcl.mjs} +0 -2
  3. package/dist/constants/index.d.mts +2 -2
  4. package/dist/constants/index.mjs +3 -3
  5. package/dist/core-8Xfnpn6g.d.mts +1 -2
  6. package/dist/country/index.d.mts +1 -1
  7. package/dist/country/index.mjs +0 -2
  8. package/dist/currencies-W8kQAkm0.mjs +0 -2
  9. package/dist/{idempotency.plugin-v9NQ_ta-.mjs → date-lock.plugin-C8kqPBjh.mjs} +51 -11
  10. package/dist/{engine-BzBMpWuy.d.mts → engine-DF-MtsEr.d.mts} +10 -6
  11. package/dist/{errors-B7yC-Jfw.mjs → errors-BoGUSUYL.mjs} +0 -2
  12. package/dist/exports/index.d.mts +1 -1
  13. package/dist/exports/index.mjs +1 -1
  14. package/dist/{exports-I5Xkq-9_.mjs → exports-DoGQQtMQ.mjs} +96 -77
  15. package/dist/{fiscal-close-L631E3De.mjs → fiscal-close-DmPV82e4.mjs} +1000 -286
  16. package/dist/{idempotency.plugin-CPxPt4vX.d.mts → idempotency.plugin-zU-GKJ0-.d.mts} +19 -17
  17. package/dist/{index-ZnSiqHYV.d.mts → index-CxZqRaOU.d.mts} +20 -6
  18. package/dist/{index-BPukb3L8.d.mts → index-J-XIbXH-.d.mts} +7 -8
  19. package/dist/index.d.mts +280 -58
  20. package/dist/index.mjs +123 -25
  21. package/dist/journal-entry.schema-B1CzLwC3.d.mts +103 -0
  22. package/dist/{journals-oH-FK3g8.mjs → journals-BcMn71Cq.mjs} +27 -6
  23. package/dist/{currencies-4WAbFRlw.d.mts → journals-DTipb_rz.d.mts} +16 -8
  24. package/dist/logger-UbTdBb1x.d.mts +1 -2
  25. package/dist/money.d.mts +1 -2
  26. package/dist/money.mjs +5 -5
  27. package/dist/plugins/index.d.mts +38 -2
  28. package/dist/plugins/index.mjs +57 -2
  29. package/dist/reconciliation.repository-DEybU_Ok.d.mts +135 -0
  30. package/dist/{account.repository-kDKwDt0I.mjs → reconciliation.repository-DgJEDVS-.mjs} +361 -210
  31. package/dist/{fiscal-period.schema-BQ5wsAq3.mjs → reconciliation.schema-KScbsXbY.mjs} +235 -90
  32. package/dist/reports/index.d.mts +2 -2
  33. package/dist/reports/index.mjs +2 -2
  34. package/dist/repositories/index.d.mts +2 -2
  35. package/dist/repositories/index.mjs +2 -2
  36. package/dist/schemas/index.d.mts +71 -2
  37. package/dist/schemas/index.mjs +2 -2
  38. package/dist/tenant-guard-CAxXoWuS.mjs +13 -0
  39. package/dist/trial-balance-DcQ0xj_4.d.mts +530 -0
  40. package/docs/reports.md +1 -1
  41. package/package.json +14 -6
  42. package/dist/account.repository-C7gwFLfM.d.mts +0 -29
  43. package/dist/account.repository-C7gwFLfM.d.mts.map +0 -1
  44. package/dist/account.repository-kDKwDt0I.mjs.map +0 -1
  45. package/dist/categories-CclX7Q94.mjs.map +0 -1
  46. package/dist/core-8Xfnpn6g.d.mts.map +0 -1
  47. package/dist/country/index.mjs.map +0 -1
  48. package/dist/currencies-4WAbFRlw.d.mts.map +0 -1
  49. package/dist/currencies-W8kQAkm0.mjs.map +0 -1
  50. package/dist/engine-BzBMpWuy.d.mts.map +0 -1
  51. package/dist/errors-B7yC-Jfw.mjs.map +0 -1
  52. package/dist/exports-I5Xkq-9_.mjs.map +0 -1
  53. package/dist/fiscal-close-L631E3De.mjs.map +0 -1
  54. package/dist/fiscal-close-dNlzB37y.d.mts +0 -270
  55. package/dist/fiscal-close-dNlzB37y.d.mts.map +0 -1
  56. package/dist/fiscal-period.schema-BQ5wsAq3.mjs.map +0 -1
  57. package/dist/fiscal-period.schema-BRdKAjrr.d.mts +0 -38
  58. package/dist/fiscal-period.schema-BRdKAjrr.d.mts.map +0 -1
  59. package/dist/idempotency.plugin-CPxPt4vX.d.mts.map +0 -1
  60. package/dist/idempotency.plugin-v9NQ_ta-.mjs.map +0 -1
  61. package/dist/index-BPukb3L8.d.mts.map +0 -1
  62. package/dist/index-ZnSiqHYV.d.mts.map +0 -1
  63. package/dist/index.d.mts.map +0 -1
  64. package/dist/index.mjs.map +0 -1
  65. package/dist/journals-oH-FK3g8.mjs.map +0 -1
  66. package/dist/logger-UbTdBb1x.d.mts.map +0 -1
  67. package/dist/money.d.mts.map +0 -1
  68. package/dist/money.mjs.map +0 -1
  69. package/dist/session-Ba8E3Ufa.mjs +0 -84
  70. package/dist/session-Ba8E3Ufa.mjs.map +0 -1
@@ -3,7 +3,7 @@ import { Money } from "./money.mjs";
3
3
  const NEEDS_QUOTING = /[",\r\n]/;
4
4
  /** Escape a single CSV cell value per RFC 4180. */
5
5
  function escapeCell(value) {
6
- if (NEEDS_QUOTING.test(value)) return "\"" + value.replace(/"/g, "\"\"") + "\"";
6
+ if (NEEDS_QUOTING.test(value)) return `"${value.replace(/"/g, "\"\"")}"`;
7
7
  return value;
8
8
  }
9
9
  /** Serialize a 2D array of strings into a CSV string. */
@@ -18,6 +18,11 @@ function buildCsv(headers, dataRows, options = {}) {
18
18
  }
19
19
  //#endregion
20
20
  //#region src/exports/field-map.ts
21
+ /**
22
+ * Field Map Application — Applies an ExportFieldMap to data rows.
23
+ *
24
+ * @module @classytic/ledger/exports
25
+ */
21
26
  /** Extract headers from a field map. */
22
27
  function getHeaders(fieldMap) {
23
28
  return fieldMap.fields.map((f) => f.header);
@@ -35,80 +40,15 @@ function exportToCsv(fieldMap, rows, options) {
35
40
  return buildCsv(getHeaders(fieldMap), extractAllRows(fieldMap, rows), options);
36
41
  }
37
42
  //#endregion
38
- //#region src/exports/flatten-journal.ts
39
- function toDate(value) {
40
- if (!value) return /* @__PURE__ */ new Date(0);
41
- if (value instanceof Date) return value;
42
- return new Date(value);
43
- }
44
- function resolveAccount(account) {
45
- if (!account) return {
46
- id: "",
47
- name: "",
48
- typeCode: ""
49
- };
50
- if (typeof account === "string") return {
51
- id: account,
52
- name: "",
53
- typeCode: ""
54
- };
55
- return {
56
- id: String(account._id ?? ""),
57
- name: account.name ?? "",
58
- typeCode: account.accountTypeCode ?? ""
59
- };
60
- }
61
- /** Flatten a single journal entry into one FlatJournalRow per journal item. */
62
- function flattenJournalEntry(entry) {
63
- const entryDate = toDate(entry.date);
64
- const items = entry.journalItems ?? [];
65
- const itemCount = items.length;
66
- const KNOWN_ITEM_KEYS = new Set([
67
- "account",
68
- "label",
69
- "date",
70
- "debit",
71
- "credit",
72
- "taxDetails"
73
- ]);
74
- return items.map((item, index) => {
75
- const acct = resolveAccount(item.account);
76
- const firstTax = item.taxDetails?.[0];
77
- const extraItemFields = {};
78
- for (const key of Object.keys(item)) if (!KNOWN_ITEM_KEYS.has(key)) extraItemFields[key] = item[key];
79
- return {
80
- entryId: String(entry._id ?? ""),
81
- journalType: entry.journalType ?? "",
82
- referenceNumber: entry.referenceNumber ?? "",
83
- entryLabel: entry.label ?? "",
84
- entryDate,
85
- state: entry.state,
86
- reversed: entry.reversed ?? false,
87
- totalDebit: entry.totalDebit ?? 0,
88
- totalCredit: entry.totalCredit ?? 0,
89
- accountId: acct.id,
90
- accountName: acct.name,
91
- accountTypeCode: acct.typeCode,
92
- itemLabel: item.label ?? "",
93
- itemDate: item.date ? toDate(item.date) : entryDate,
94
- debit: item.debit ?? 0,
95
- credit: item.credit ?? 0,
96
- taxCode: firstTax?.taxCode ?? "",
97
- taxName: firstTax?.taxName ?? "",
98
- itemIndex: index,
99
- itemCount,
100
- ...extraItemFields
101
- };
102
- });
103
- }
104
- /** Flatten multiple journal entries into a single flat row array. */
105
- function flattenJournalEntries(entries) {
106
- const rows = [];
107
- for (const entry of entries) rows.push(...flattenJournalEntry(entry));
108
- return rows;
109
- }
110
- //#endregion
111
43
  //#region src/exports/field-maps/quickbooks.ts
44
+ /**
45
+ * QuickBooks General Journal Import Field Map
46
+ *
47
+ * Produces CSV compatible with QuickBooks Desktop and Online
48
+ * "Import General Journal Entries" feature.
49
+ *
50
+ * @module @classytic/ledger/exports
51
+ */
112
52
  function formatQbDate(date) {
113
53
  return `${String(date.getMonth() + 1).padStart(2, "0")}/${String(date.getDate()).padStart(2, "0")}/${date.getFullYear()}`;
114
54
  }
@@ -161,6 +101,14 @@ const quickbooksFieldMap = {
161
101
  };
162
102
  //#endregion
163
103
  //#region src/exports/field-maps/universal.ts
104
+ /**
105
+ * Universal Export Field Map
106
+ *
107
+ * Comprehensive CSV export with all available fields.
108
+ * Useful for data portability, auditing, or spreadsheet import.
109
+ *
110
+ * @module @classytic/ledger/exports
111
+ */
164
112
  function formatIsoDate(date) {
165
113
  return date.toISOString().split("T")[0];
166
114
  }
@@ -247,6 +195,77 @@ const universalFieldMap = {
247
195
  ]
248
196
  };
249
197
  //#endregion
250
- export { exportToCsv as a, getHeaders as c, serializeCsv as d, flattenJournalEntry as i, buildCsv as l, quickbooksFieldMap as n, extractAllRows as o, flattenJournalEntries as r, extractRow as s, universalFieldMap as t, escapeCell as u };
251
-
252
- //# sourceMappingURL=exports-I5Xkq-9_.mjs.map
198
+ //#region src/exports/flatten-journal.ts
199
+ function toDate(value) {
200
+ if (!value) return /* @__PURE__ */ new Date(0);
201
+ if (value instanceof Date) return value;
202
+ return new Date(value);
203
+ }
204
+ function resolveAccount(account) {
205
+ if (!account) return {
206
+ id: "",
207
+ name: "",
208
+ typeCode: ""
209
+ };
210
+ if (typeof account === "string") return {
211
+ id: account,
212
+ name: "",
213
+ typeCode: ""
214
+ };
215
+ return {
216
+ id: String(account._id ?? ""),
217
+ name: account.name ?? "",
218
+ typeCode: account.accountTypeCode ?? ""
219
+ };
220
+ }
221
+ /** Flatten a single journal entry into one FlatJournalRow per journal item. */
222
+ function flattenJournalEntry(entry) {
223
+ const entryDate = toDate(entry.date);
224
+ const items = entry.journalItems ?? [];
225
+ const itemCount = items.length;
226
+ const KNOWN_ITEM_KEYS = new Set([
227
+ "account",
228
+ "label",
229
+ "date",
230
+ "debit",
231
+ "credit",
232
+ "taxDetails"
233
+ ]);
234
+ return items.map((item, index) => {
235
+ const acct = resolveAccount(item.account);
236
+ const firstTax = item.taxDetails?.[0];
237
+ const extraItemFields = {};
238
+ for (const key of Object.keys(item)) if (!KNOWN_ITEM_KEYS.has(key)) extraItemFields[key] = item[key];
239
+ return {
240
+ entryId: String(entry._id ?? ""),
241
+ journalType: entry.journalType ?? "",
242
+ referenceNumber: entry.referenceNumber ?? "",
243
+ entryLabel: entry.label ?? "",
244
+ entryDate,
245
+ state: entry.state,
246
+ reversed: entry.reversed ?? false,
247
+ totalDebit: entry.totalDebit ?? 0,
248
+ totalCredit: entry.totalCredit ?? 0,
249
+ accountId: acct.id,
250
+ accountName: acct.name,
251
+ accountTypeCode: acct.typeCode,
252
+ itemLabel: item.label ?? "",
253
+ itemDate: item.date ? toDate(item.date) : entryDate,
254
+ debit: item.debit ?? 0,
255
+ credit: item.credit ?? 0,
256
+ taxCode: firstTax?.taxCode ?? "",
257
+ taxName: firstTax?.taxName ?? "",
258
+ itemIndex: index,
259
+ itemCount,
260
+ ...extraItemFields
261
+ };
262
+ });
263
+ }
264
+ /** Flatten multiple journal entries into a single flat row array. */
265
+ function flattenJournalEntries(entries) {
266
+ const rows = [];
267
+ for (const entry of entries) rows.push(...flattenJournalEntry(entry));
268
+ return rows;
269
+ }
270
+ //#endregion
271
+ export { exportToCsv as a, getHeaders as c, serializeCsv as d, quickbooksFieldMap as i, buildCsv as l, flattenJournalEntry as n, extractAllRows as o, universalFieldMap as r, extractRow as s, flattenJournalEntries as t, escapeCell as u };