@classytic/ledger 0.1.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.
- package/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/account.repository-1C2sZvB2.d.mts +29 -0
- package/dist/account.repository-1C2sZvB2.d.mts.map +1 -0
- package/dist/account.repository-Crf5DGO4.mjs +393 -0
- package/dist/account.repository-Crf5DGO4.mjs.map +1 -0
- package/dist/categories-BNJBd4ze.mjs +70 -0
- package/dist/categories-BNJBd4ze.mjs.map +1 -0
- package/dist/constants/index.d.mts +2 -0
- package/dist/constants/index.mjs +5 -0
- package/dist/core-Cx0baosR.d.mts +104 -0
- package/dist/core-Cx0baosR.d.mts.map +1 -0
- package/dist/country/index.d.mts +105 -0
- package/dist/country/index.d.mts.map +1 -0
- package/dist/country/index.mjs +27 -0
- package/dist/country/index.mjs.map +1 -0
- package/dist/currencies-BBk3NwXn.mjs +82 -0
- package/dist/currencies-BBk3NwXn.mjs.map +1 -0
- package/dist/currencies-Bkn3FNkC.d.mts +38 -0
- package/dist/currencies-Bkn3FNkC.d.mts.map +1 -0
- package/dist/engine-Cd73EOT6.d.mts +72 -0
- package/dist/engine-Cd73EOT6.d.mts.map +1 -0
- package/dist/errors-CeqRahE-.mjs +28 -0
- package/dist/errors-CeqRahE-.mjs.map +1 -0
- package/dist/exports/index.d.mts +2 -0
- package/dist/exports/index.mjs +3 -0
- package/dist/fiscal-close-CNOwv_ud.mjs +934 -0
- package/dist/fiscal-close-CNOwv_ud.mjs.map +1 -0
- package/dist/fiscal-close-CzUzpnMg.d.mts +270 -0
- package/dist/fiscal-close-CzUzpnMg.d.mts.map +1 -0
- package/dist/fiscal-period.schema-CbALaaKl.mjs +477 -0
- package/dist/fiscal-period.schema-CbALaaKl.mjs.map +1 -0
- package/dist/fiscal-period.schema-DI2scngu.d.mts +38 -0
- package/dist/fiscal-period.schema-DI2scngu.d.mts.map +1 -0
- package/dist/idempotency.plugin-BESs9YPD.d.mts +58 -0
- package/dist/idempotency.plugin-BESs9YPD.d.mts.map +1 -0
- package/dist/idempotency.plugin-C6r8RI8d.mjs +165 -0
- package/dist/idempotency.plugin-C6r8RI8d.mjs.map +1 -0
- package/dist/index.d.mts +308 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +171 -0
- package/dist/index.mjs.map +1 -0
- package/dist/journals-CI3Wb4EF.mjs +92 -0
- package/dist/journals-CI3Wb4EF.mjs.map +1 -0
- package/dist/logger-Cv6VVc4r.d.mts +15 -0
- package/dist/logger-Cv6VVc4r.d.mts.map +1 -0
- package/dist/money.d.mts +129 -0
- package/dist/money.d.mts.map +1 -0
- package/dist/money.mjs +197 -0
- package/dist/money.mjs.map +1 -0
- package/dist/plugins/index.d.mts +2 -0
- package/dist/plugins/index.mjs +3 -0
- package/dist/reports/index.d.mts +2 -0
- package/dist/reports/index.mjs +3 -0
- package/dist/repositories/index.d.mts +2 -0
- package/dist/repositories/index.mjs +3 -0
- package/dist/schemas/index.d.mts +2 -0
- package/dist/schemas/index.mjs +3 -0
- package/dist/session-Dh0s6zG4.mjs +87 -0
- package/dist/session-Dh0s6zG4.mjs.map +1 -0
- package/dist/universal-CMfrZ2hG.mjs +257 -0
- package/dist/universal-CMfrZ2hG.mjs.map +1 -0
- package/dist/universal-x33ZJODp.d.mts +137 -0
- package/dist/universal-x33ZJODp.d.mts.map +1 -0
- package/docs/country-packs.md +117 -0
- package/docs/engine.md +147 -0
- package/docs/exports.md +81 -0
- package/docs/money.md +81 -0
- package/docs/plugins.md +136 -0
- package/docs/reports.md +154 -0
- package/docs/repositories.md +239 -0
- package/docs/schemas.md +146 -0
- package/docs/subledger-integration.md +287 -0
- package/package.json +116 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/constants/categories.ts
|
|
2
|
+
/** All valid categories */
|
|
3
|
+
const CATEGORIES = Object.freeze({
|
|
4
|
+
"Balance Sheet-Asset": {
|
|
5
|
+
name: "Balance Sheet",
|
|
6
|
+
mainType: "Asset",
|
|
7
|
+
statementType: "Balance Sheet"
|
|
8
|
+
},
|
|
9
|
+
"Balance Sheet-Liability": {
|
|
10
|
+
name: "Balance Sheet",
|
|
11
|
+
mainType: "Liability",
|
|
12
|
+
statementType: "Balance Sheet"
|
|
13
|
+
},
|
|
14
|
+
"Balance Sheet-Equity": {
|
|
15
|
+
name: "Balance Sheet",
|
|
16
|
+
mainType: "Equity",
|
|
17
|
+
statementType: "Balance Sheet"
|
|
18
|
+
},
|
|
19
|
+
"Income Statement-Income": {
|
|
20
|
+
name: "Income Statement",
|
|
21
|
+
mainType: "Income",
|
|
22
|
+
statementType: "Income Statement"
|
|
23
|
+
},
|
|
24
|
+
"Income Statement-Expense": {
|
|
25
|
+
name: "Income Statement",
|
|
26
|
+
mainType: "Expense",
|
|
27
|
+
statementType: "Income Statement"
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const CATEGORY_KEYS = Object.keys(CATEGORIES);
|
|
31
|
+
function isValidCategory(key) {
|
|
32
|
+
return key in CATEGORIES;
|
|
33
|
+
}
|
|
34
|
+
function getCategoryMainType(key) {
|
|
35
|
+
return CATEGORIES[key].mainType;
|
|
36
|
+
}
|
|
37
|
+
function getCategoryStatementType(key) {
|
|
38
|
+
return CATEGORIES[key].statementType;
|
|
39
|
+
}
|
|
40
|
+
function isBalanceSheet(key) {
|
|
41
|
+
return CATEGORIES[key].statementType === "Balance Sheet";
|
|
42
|
+
}
|
|
43
|
+
function isIncomeStatement(key) {
|
|
44
|
+
return CATEGORIES[key].statementType === "Income Statement";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the normal balance for a main type.
|
|
48
|
+
* Assets & Expenses → debit. Liabilities, Equity & Income → credit.
|
|
49
|
+
*/
|
|
50
|
+
function getNormalBalance(mainType) {
|
|
51
|
+
return mainType === "Asset" || mainType === "Expense" ? "debit" : "credit";
|
|
52
|
+
}
|
|
53
|
+
/** Build a category key from parts */
|
|
54
|
+
function categoryKey(statement, mainType) {
|
|
55
|
+
return `${statement}-${mainType}`;
|
|
56
|
+
}
|
|
57
|
+
/** Extract main type from a category key string */
|
|
58
|
+
function extractMainType(key) {
|
|
59
|
+
const parts = key.split("-");
|
|
60
|
+
return parts.length === 2 ? parts[1] : null;
|
|
61
|
+
}
|
|
62
|
+
/** Extract statement type from a category key string */
|
|
63
|
+
function extractStatementType(key) {
|
|
64
|
+
const parts = key.split("-");
|
|
65
|
+
return parts.length === 2 ? parts[0] : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { extractStatementType as a, getNormalBalance as c, isValidCategory as d, extractMainType as i, isBalanceSheet as l, CATEGORY_KEYS as n, getCategoryMainType as o, categoryKey as r, getCategoryStatementType as s, CATEGORIES as t, isIncomeStatement as u };
|
|
70
|
+
//# sourceMappingURL=categories-BNJBd4ze.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories-BNJBd4ze.mjs","names":[],"sources":["../src/constants/categories.ts"],"sourcesContent":["/**\r\n * Account Categories — Single source of truth for account classification.\r\n */\r\n\r\nimport type { Category, CategoryKey, MainType, StatementType } from '../types/core.js';\r\n\r\n/** All valid categories */\r\nexport const CATEGORIES: Readonly<Record<CategoryKey, Category>> = Object.freeze({\r\n 'Balance Sheet-Asset': { name: 'Balance Sheet', mainType: 'Asset', statementType: 'Balance Sheet' },\r\n 'Balance Sheet-Liability': { name: 'Balance Sheet', mainType: 'Liability', statementType: 'Balance Sheet' },\r\n 'Balance Sheet-Equity': { name: 'Balance Sheet', mainType: 'Equity', statementType: 'Balance Sheet' },\r\n 'Income Statement-Income': { name: 'Income Statement', mainType: 'Income', statementType: 'Income Statement' },\r\n 'Income Statement-Expense': { name: 'Income Statement', mainType: 'Expense', statementType: 'Income Statement' },\r\n});\r\n\r\nexport const CATEGORY_KEYS = Object.keys(CATEGORIES) as CategoryKey[];\r\n\r\nexport function isValidCategory(key: string): key is CategoryKey {\r\n return key in CATEGORIES;\r\n}\r\n\r\nexport function getCategoryMainType(key: CategoryKey): MainType {\r\n return CATEGORIES[key].mainType;\r\n}\r\n\r\nexport function getCategoryStatementType(key: CategoryKey): StatementType {\r\n return CATEGORIES[key].statementType;\r\n}\r\n\r\nexport function isBalanceSheet(key: CategoryKey): boolean {\r\n return CATEGORIES[key].statementType === 'Balance Sheet';\r\n}\r\n\r\nexport function isIncomeStatement(key: CategoryKey): boolean {\r\n return CATEGORIES[key].statementType === 'Income Statement';\r\n}\r\n\r\n/**\r\n * Get the normal balance for a main type.\r\n * Assets & Expenses → debit. Liabilities, Equity & Income → credit.\r\n */\r\nexport function getNormalBalance(mainType: MainType): 'debit' | 'credit' {\r\n return mainType === 'Asset' || mainType === 'Expense' ? 'debit' : 'credit';\r\n}\r\n\r\n/** Build a category key from parts */\r\nexport function categoryKey(statement: StatementType, mainType: MainType): CategoryKey {\r\n return `${statement}-${mainType}` as CategoryKey;\r\n}\r\n\r\n/** Extract main type from a category key string */\r\nexport function extractMainType(key: string): MainType | null {\r\n const parts = key.split('-');\r\n return (parts.length === 2 ? parts[1] : null) as MainType | null;\r\n}\r\n\r\n/** Extract statement type from a category key string */\r\nexport function extractStatementType(key: string): StatementType | null {\r\n const parts = key.split('-');\r\n return (parts.length === 2 ? parts[0] : null) as StatementType | null;\r\n}\r\n"],"mappings":";;AAOA,MAAa,aAAsD,OAAO,OAAO;CAC/E,uBAAuB;EAAE,MAAM;EAAiB,UAAU;EAAS,eAAe;EAAiB;CACnG,2BAA2B;EAAE,MAAM;EAAiB,UAAU;EAAa,eAAe;EAAiB;CAC3G,wBAAwB;EAAE,MAAM;EAAiB,UAAU;EAAU,eAAe;EAAiB;CACrG,2BAA2B;EAAE,MAAM;EAAoB,UAAU;EAAU,eAAe;EAAoB;CAC9G,4BAA4B;EAAE,MAAM;EAAoB,UAAU;EAAW,eAAe;EAAoB;CACjH,CAAC;AAEF,MAAa,gBAAgB,OAAO,KAAK,WAAW;AAEpD,SAAgB,gBAAgB,KAAiC;AAC/D,QAAO,OAAO;;AAGhB,SAAgB,oBAAoB,KAA4B;AAC9D,QAAO,WAAW,KAAK;;AAGzB,SAAgB,yBAAyB,KAAiC;AACxE,QAAO,WAAW,KAAK;;AAGzB,SAAgB,eAAe,KAA2B;AACxD,QAAO,WAAW,KAAK,kBAAkB;;AAG3C,SAAgB,kBAAkB,KAA2B;AAC3D,QAAO,WAAW,KAAK,kBAAkB;;;;;;AAO3C,SAAgB,iBAAiB,UAAwC;AACvE,QAAO,aAAa,WAAW,aAAa,YAAY,UAAU;;;AAIpE,SAAgB,YAAY,WAA0B,UAAiC;AACrF,QAAO,GAAG,UAAU,GAAG;;;AAIzB,SAAgB,gBAAgB,KAA8B;CAC5D,MAAM,QAAQ,IAAI,MAAM,IAAI;AAC5B,QAAQ,MAAM,WAAW,IAAI,MAAM,KAAK;;;AAI1C,SAAgB,qBAAqB,KAAmC;CACtE,MAAM,QAAQ,IAAI,MAAM,IAAI;AAC5B,QAAQ,MAAM,WAAW,IAAI,MAAM,KAAK"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as getNormalBalance, a as JOURNAL_CODES, b as isValidCategory, c as getJournalTypeCodes, d as CATEGORY_KEYS, f as categoryKey, g as getCategoryStatementType, h as getCategoryMainType, i as isValidCurrency, l as isValidJournalType, m as extractStatementType, n as getCurrency, o as JOURNAL_TYPES, p as extractMainType, r as getMinorUnit, s as getJournalType, t as CURRENCIES, u as CATEGORIES, v as isBalanceSheet, y as isIncomeStatement } from "../currencies-Bkn3FNkC.mjs";
|
|
2
|
+
export { CATEGORIES, CATEGORY_KEYS, CURRENCIES, JOURNAL_CODES, JOURNAL_TYPES, categoryKey, extractMainType, extractStatementType, getCategoryMainType, getCategoryStatementType, getCurrency, getJournalType, getJournalTypeCodes, getMinorUnit, getNormalBalance, isBalanceSheet, isIncomeStatement, isValidCategory, isValidCurrency, isValidJournalType };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { a as isValidJournalType, i as getJournalTypeCodes, n as JOURNAL_TYPES, r as getJournalType, t as JOURNAL_CODES } from "../journals-CI3Wb4EF.mjs";
|
|
2
|
+
import { a as extractStatementType, c as getNormalBalance, d as isValidCategory, i as extractMainType, l as isBalanceSheet, n as CATEGORY_KEYS, o as getCategoryMainType, r as categoryKey, s as getCategoryStatementType, t as CATEGORIES, u as isIncomeStatement } from "../categories-BNJBd4ze.mjs";
|
|
3
|
+
import { i as isValidCurrency, n as getCurrency, r as getMinorUnit, t as CURRENCIES } from "../currencies-BBk3NwXn.mjs";
|
|
4
|
+
|
|
5
|
+
export { CATEGORIES, CATEGORY_KEYS, CURRENCIES, JOURNAL_CODES, JOURNAL_TYPES, categoryKey, extractMainType, extractStatementType, getCategoryMainType, getCategoryStatementType, getCurrency, getJournalType, getJournalTypeCodes, getMinorUnit, getNormalBalance, isBalanceSheet, isIncomeStatement, isValidCategory, isValidCurrency, isValidJournalType };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ClientSession, Types } from "mongoose";
|
|
2
|
+
|
|
3
|
+
//#region src/types/core.d.ts
|
|
4
|
+
/** Integer cents — the canonical monetary type throughout the engine */
|
|
5
|
+
type Cents = number & {
|
|
6
|
+
readonly __brand: 'Cents';
|
|
7
|
+
};
|
|
8
|
+
/** Mongoose ObjectId */
|
|
9
|
+
type ObjectId = Types.ObjectId;
|
|
10
|
+
/** Statement type — which financial statement an account belongs to */
|
|
11
|
+
type StatementType = 'Balance Sheet' | 'Income Statement';
|
|
12
|
+
/** Main account type — the fundamental classification */
|
|
13
|
+
type MainType = 'Asset' | 'Liability' | 'Equity' | 'Income' | 'Expense';
|
|
14
|
+
/**
|
|
15
|
+
* Category key — composite key used throughout the engine.
|
|
16
|
+
* Format: "{StatementType}-{MainType}"
|
|
17
|
+
*/
|
|
18
|
+
type CategoryKey = 'Balance Sheet-Asset' | 'Balance Sheet-Liability' | 'Balance Sheet-Equity' | 'Income Statement-Income' | 'Income Statement-Expense';
|
|
19
|
+
/** Category definition */
|
|
20
|
+
interface Category {
|
|
21
|
+
readonly name: StatementType;
|
|
22
|
+
readonly mainType: MainType;
|
|
23
|
+
readonly statementType: StatementType;
|
|
24
|
+
}
|
|
25
|
+
/** Normal balance — which side increases this account type */
|
|
26
|
+
type NormalBalance = 'debit' | 'credit';
|
|
27
|
+
/** Cash flow classification */
|
|
28
|
+
type CashFlowCategory = 'Operating' | 'Investing' | 'Financing';
|
|
29
|
+
/** Roll-up operation for total accounts */
|
|
30
|
+
interface TotalAccountOp {
|
|
31
|
+
readonly account: string;
|
|
32
|
+
readonly operation: '+' | '-';
|
|
33
|
+
}
|
|
34
|
+
/** Tax metadata embedded in tax account type definitions */
|
|
35
|
+
interface TaxMetadata {
|
|
36
|
+
readonly taxType: string;
|
|
37
|
+
readonly rate?: number;
|
|
38
|
+
readonly direction: 'collected' | 'recoverable' | 'instalment' | 'payable' | 'receivable';
|
|
39
|
+
readonly craLine?: number | null;
|
|
40
|
+
readonly provinces?: readonly string[];
|
|
41
|
+
readonly isContraAccount?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* AccountType — a template/definition for an account (NOT a database row).
|
|
45
|
+
* Provided by country packs.
|
|
46
|
+
*/
|
|
47
|
+
interface AccountType {
|
|
48
|
+
readonly code: string;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly category: CategoryKey;
|
|
51
|
+
readonly description: string;
|
|
52
|
+
readonly parentCode: string | null;
|
|
53
|
+
readonly isTotal?: boolean;
|
|
54
|
+
readonly isVirtualTotal?: boolean;
|
|
55
|
+
readonly isGroup?: boolean;
|
|
56
|
+
readonly totalAccountTypes?: readonly TotalAccountOp[];
|
|
57
|
+
readonly cashFlowCategory?: CashFlowCategory | null;
|
|
58
|
+
readonly taxMetadata?: TaxMetadata;
|
|
59
|
+
readonly deprecated?: boolean;
|
|
60
|
+
readonly replacedBy?: string;
|
|
61
|
+
readonly notes?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Journal type definition */
|
|
64
|
+
interface JournalType {
|
|
65
|
+
readonly code: string;
|
|
66
|
+
readonly name: string;
|
|
67
|
+
readonly description: string;
|
|
68
|
+
}
|
|
69
|
+
/** Entry state machine: draft → posted, draft → archived */
|
|
70
|
+
type EntryState = 'draft' | 'posted' | 'archived';
|
|
71
|
+
/** Tax detail on a journal item (audit reference only) */
|
|
72
|
+
interface TaxDetail {
|
|
73
|
+
taxCode?: string;
|
|
74
|
+
taxName?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A single line in a journal entry.
|
|
78
|
+
* Additional dimension fields can be injected via `extraItemFields` in JournalSchemaOptions.
|
|
79
|
+
*/
|
|
80
|
+
interface JournalItem {
|
|
81
|
+
account: ObjectId | string;
|
|
82
|
+
label?: string;
|
|
83
|
+
date?: Date;
|
|
84
|
+
debit: number;
|
|
85
|
+
credit: number;
|
|
86
|
+
taxDetails?: TaxDetail[];
|
|
87
|
+
/** Extra dimension fields injected via extraItemFields */
|
|
88
|
+
[key: string]: unknown;
|
|
89
|
+
}
|
|
90
|
+
/** ISO 4217 currency definition */
|
|
91
|
+
interface Currency {
|
|
92
|
+
readonly code: string;
|
|
93
|
+
readonly name: string;
|
|
94
|
+
readonly symbol: string;
|
|
95
|
+
readonly minorUnit: number;
|
|
96
|
+
}
|
|
97
|
+
type DateOption = 'month' | 'quarter' | 'year' | 'custom';
|
|
98
|
+
interface DateRange {
|
|
99
|
+
startDate: Date;
|
|
100
|
+
endDate: Date;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { TaxMetadata as _, Cents as a, DateRange as c, JournalType as d, MainType as f, TaxDetail as g, StatementType as h, CategoryKey as i, EntryState as l, ObjectId as m, CashFlowCategory as n, Currency as o, NormalBalance as p, Category as r, DateOption as s, AccountType as t, JournalItem as u, TotalAccountOp as v };
|
|
104
|
+
//# sourceMappingURL=core-Cx0baosR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-Cx0baosR.d.mts","names":[],"sources":["../src/types/core.ts"],"mappings":";;;AAgCA;AAAA,KAdY,KAAA;EAAA,SAA4B,OAAA;AAAA;;KAG5B,QAAA,GAAW,KAAA,CAAM,QAAA;AAoB7B;AAAA,KATY,aAAA;;KAGA,QAAA;;AAcZ;;;KARY,WAAA;;UAQK,QAAA;EAAA,SACN,IAAA,EAAM,aAAA;EAAA,SACN,QAAA,EAAU,QAAA;EAAA,SACV,aAAA,EAAe,aAAA;AAAA;;KAId,aAAA;;KAGA,gBAAA;;UAKK,cAAA;EAAA,SACN,OAAA;EAAA,SACA,SAAA;AAAA;;UAIM,WAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,SAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA;EAAA,SACA,eAAA;AAAA;;;;AANX;UAaiB,WAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,WAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,cAAA;EAAA,SACA,OAAA;EAAA,SACA,iBAAA,YAA6B,cAAA;EAAA,SAC7B,gBAAA,GAAmB,gBAAA;EAAA,SACnB,WAAA,GAAc,WAAA;EAAA,SACd,UAAA;EAAA,SACA,UAAA;EAAA,SACA,KAAA;AAAA;;UAMM,WAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA;AAAA;;KAIC,UAAA;;UAGK,SAAA;EACf,OAAA;EACA,OAAA;AAAA;;;;;UAOe,WAAA;EACf,OAAA,EAAS,QAAA;EACT,KAAA;EACA,IAAA,GAAO,IAAA;EACP,KAAA;EACA,MAAA;EACA,UAAA,GAAa,SAAA;EAzBE;EAAA,CA2Bd,GAAA;AAAA;;UAMc,QAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;EAAA,SACA,SAAA;AAAA;AAAA,KAKC,UAAA;AAAA,UAcK,SAAA;EACf,SAAA,EAAW,IAAA;EACX,OAAA,EAAS,IAAA;AAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { t as AccountType } from "../core-Cx0baosR.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/country/index.d.ts
|
|
4
|
+
interface TaxCode {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly taxType: string;
|
|
8
|
+
readonly rate: number;
|
|
9
|
+
readonly direction: 'collected' | 'recoverable' | 'paid';
|
|
10
|
+
readonly province?: string;
|
|
11
|
+
readonly reportLines?: readonly number[];
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly active: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface TaxCodesByRegion {
|
|
16
|
+
readonly [region: string]: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
interface TaxReportLine {
|
|
19
|
+
readonly line: number | string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly type: 'input' | 'calculated' | 'manual';
|
|
23
|
+
readonly calculate?: (data: Record<string | number, number>) => number;
|
|
24
|
+
readonly section: string;
|
|
25
|
+
}
|
|
26
|
+
interface TaxReportTemplate {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly lines: Readonly<Record<string | number, TaxReportLine>>;
|
|
29
|
+
calculate(inputData: Record<string | number, number>, manualData?: Record<string | number, number>): Record<string | number, number>;
|
|
30
|
+
summarize(calculated: Record<string | number, number>): Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
interface CountryPack {
|
|
33
|
+
/** ISO 3166-1 alpha-2 code (e.g., 'CA', 'US', 'GB') */
|
|
34
|
+
readonly code: string;
|
|
35
|
+
/** Country name */
|
|
36
|
+
readonly name: string;
|
|
37
|
+
/** Default currency code */
|
|
38
|
+
readonly defaultCurrency: string;
|
|
39
|
+
/**
|
|
40
|
+
* Full chart of accounts template — flat array of account type definitions.
|
|
41
|
+
* Includes both regular accounts and virtual tax sub-accounts.
|
|
42
|
+
*/
|
|
43
|
+
readonly accountTypes: readonly AccountType[];
|
|
44
|
+
/** Tax codes indexed by code string */
|
|
45
|
+
readonly taxCodes: Readonly<Record<string, TaxCode>>;
|
|
46
|
+
/** Tax codes grouped by region/province/state */
|
|
47
|
+
readonly taxCodesByRegion: TaxCodesByRegion;
|
|
48
|
+
/** Available regions (provinces/states) */
|
|
49
|
+
readonly regions: readonly string[];
|
|
50
|
+
/** Tax report template (e.g., CRA GST/HST return) */
|
|
51
|
+
readonly taxReport?: TaxReportTemplate;
|
|
52
|
+
/** Account code for prior retained earnings (e.g. '3660' CA, '3200' US) */
|
|
53
|
+
readonly retainedEarningsCode?: string;
|
|
54
|
+
/** Account code for current year net income (e.g. '3680' CA, '3210' US) */
|
|
55
|
+
readonly currentYearEarningsCode?: string;
|
|
56
|
+
/** Group label code used to identify Cost of Sales in the income statement */
|
|
57
|
+
readonly cogsGroupCode?: string;
|
|
58
|
+
/** Override default English report section names */
|
|
59
|
+
readonly reportLabels?: {
|
|
60
|
+
readonly assets?: string;
|
|
61
|
+
readonly liabilities?: string;
|
|
62
|
+
readonly equity?: string;
|
|
63
|
+
readonly revenue?: string;
|
|
64
|
+
readonly expenses?: string;
|
|
65
|
+
};
|
|
66
|
+
/** Get all account types that can be posted to (not groups, not totals) */
|
|
67
|
+
getPostingAccountTypes(): readonly AccountType[];
|
|
68
|
+
/** Get account type by code */
|
|
69
|
+
getAccountType(code: string): AccountType | undefined;
|
|
70
|
+
/** Validate an account type code exists */
|
|
71
|
+
isValidAccountType(code: string): boolean;
|
|
72
|
+
/** Check if an account type can receive postings */
|
|
73
|
+
isPostingAccount(code: string): boolean;
|
|
74
|
+
/** Get tax codes for a specific region */
|
|
75
|
+
getTaxCodesForRegion(region: string): TaxCode[];
|
|
76
|
+
/** Flatten hierarchical accounts (if needed) */
|
|
77
|
+
flattenAccountTypes(): readonly AccountType[];
|
|
78
|
+
}
|
|
79
|
+
interface CountryPackInput {
|
|
80
|
+
code: string;
|
|
81
|
+
name: string;
|
|
82
|
+
defaultCurrency: string;
|
|
83
|
+
accountTypes: readonly AccountType[];
|
|
84
|
+
taxCodes: Readonly<Record<string, TaxCode>>;
|
|
85
|
+
taxCodesByRegion: TaxCodesByRegion;
|
|
86
|
+
regions: readonly string[];
|
|
87
|
+
taxReport?: TaxReportTemplate;
|
|
88
|
+
retainedEarningsCode?: string;
|
|
89
|
+
currentYearEarningsCode?: string;
|
|
90
|
+
cogsGroupCode?: string;
|
|
91
|
+
reportLabels?: {
|
|
92
|
+
readonly assets?: string;
|
|
93
|
+
readonly liabilities?: string;
|
|
94
|
+
readonly equity?: string;
|
|
95
|
+
readonly revenue?: string;
|
|
96
|
+
readonly expenses?: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Factory to create a CountryPack with auto-generated helper methods.
|
|
101
|
+
*/
|
|
102
|
+
declare function defineCountryPack(input: CountryPackInput): CountryPack;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { CountryPack, CountryPackInput, TaxCode, TaxCodesByRegion, TaxReportLine, TaxReportTemplate, defineCountryPack };
|
|
105
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/country/index.ts"],"mappings":";;;UAgBiB,OAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,SAAA;EAAA,SACA,QAAA;EAAA,SACA,WAAA;EAAA,SACA,WAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,gBAAA;EAAA,UACL,MAAA;AAAA;AAAA,UAKK,aAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA;EAAA,SACA,IAAA;EAAA,SACA,SAAA,IAAa,IAAA,EAAM,MAAA;EAAA,SACnB,OAAA;AAAA;AAAA,UAGM,iBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA,EAAO,QAAA,CAAS,MAAA,kBAAwB,aAAA;EACjD,SAAA,CAAU,SAAA,EAAW,MAAA,2BAAiC,UAAA,GAAa,MAAA,4BAAkC,MAAA;EACrG,SAAA,CAAU,UAAA,EAAY,MAAA,4BAAkC,MAAA;AAAA;AAAA,UAKzC,WAAA;EAPU;EAAA,SAShB,IAAA;EARY;EAAA,SAUZ,IAAA;EAV4F;EAAA,SAY5F,eAAA;EAX+C;;;;EAAA,SAiB/C,YAAA,WAAuB,WAAA;EAnBhB;EAAA,SAsBP,QAAA,EAAU,QAAA,CAAS,MAAA,SAAe,OAAA;EAtBM;EAAA,SAyBxC,gBAAA,EAAkB,gBAAA;EAxBN;EAAA,SA2BZ,OAAA;EA3B0D;EAAA,SA8B1D,SAAA,GAAY,iBAAA;EA9BgF;EAAA,SAmC5F,oBAAA;EAlCa;EAAA,SAoCb,uBAAA;EApC+C;EAAA,SAsC/C,aAAA;EAtCqD;EAAA,SAwCrD,YAAA;IAAA,SACE,MAAA;IAAA,SACA,WAAA;IAAA,SACA,MAAA;IAAA,SACA,OAAA;IAAA,SACA,QAAA;EAAA;EAtBgB;EA4B3B,sBAAA,aAAmC,WAAA;EAAA;EAGnC,cAAA,CAAe,IAAA,WAAe,WAAA;EASQ;EANtC,kBAAA,CAAmB,IAAA;EASwB;EAN3C,gBAAA,CAAiB,IAAA;EArDR;EAwDT,oBAAA,CAAqB,MAAA,WAAiB,OAAA;EApD7B;EAuDT,mBAAA,aAAgC,WAAA;AAAA;AAAA,UAKjB,gBAAA;EACf,IAAA;EACA,IAAA;EACA,eAAA;EACA,YAAA,WAAuB,WAAA;EACvB,QAAA,EAAU,QAAA,CAAS,MAAA,SAAe,OAAA;EAClC,gBAAA,EAAkB,gBAAA;EAClB,OAAA;EACA,SAAA,GAAY,iBAAA;EACZ,oBAAA;EACA,uBAAA;EACA,aAAA;EACA,YAAA;IAAA,SACW,MAAA;IAAA,SACA,WAAA;IAAA,SACA,MAAA;IAAA,SACA,OAAA;IAAA,SACA,QAAA;EAAA;AAAA;;;;iBAOG,iBAAA,CAAkB,KAAA,EAAO,gBAAA,GAAmB,WAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/country/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Factory to create a CountryPack with auto-generated helper methods.
|
|
4
|
+
*/
|
|
5
|
+
function defineCountryPack(input) {
|
|
6
|
+
const accountMap = /* @__PURE__ */ new Map();
|
|
7
|
+
for (const at of input.accountTypes) accountMap.set(at.code, at);
|
|
8
|
+
const postingTypes = input.accountTypes.filter((at) => !at.isTotal && !at.isGroup);
|
|
9
|
+
return {
|
|
10
|
+
...input,
|
|
11
|
+
getPostingAccountTypes: () => postingTypes,
|
|
12
|
+
getAccountType: (code) => accountMap.get(code),
|
|
13
|
+
isValidAccountType: (code) => accountMap.has(code),
|
|
14
|
+
isPostingAccount: (code) => {
|
|
15
|
+
const at = accountMap.get(code);
|
|
16
|
+
return at !== void 0 && !at.isTotal && !at.isGroup;
|
|
17
|
+
},
|
|
18
|
+
getTaxCodesForRegion: (region) => {
|
|
19
|
+
return (input.taxCodesByRegion[region] ?? []).map((c) => input.taxCodes[c]).filter(Boolean);
|
|
20
|
+
},
|
|
21
|
+
flattenAccountTypes: () => input.accountTypes
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { defineCountryPack };
|
|
27
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/country/index.ts"],"sourcesContent":["/**\n * Country Pack Interface\n *\n * A country pack provides everything country-specific:\n * account types (chart of accounts template), tax codes,\n * and optionally a tax report generator.\n *\n * Example:\n * import { canadaPack } from '@classytic/ledger-ca';\n * const engine = createAccountingEngine({ country: canadaPack, currency: 'CAD' });\n */\n\nimport type { AccountType, CategoryKey } from '../types/core.js';\n\n// ─── Tax Code ────────────────────────────────────────────────────────────────\n\nexport interface TaxCode {\n readonly code: string;\n readonly name: string;\n readonly taxType: string;\n readonly rate: number;\n readonly direction: 'collected' | 'recoverable' | 'paid';\n readonly province?: string;\n readonly reportLines?: readonly number[];\n readonly description: string;\n readonly active: boolean;\n}\n\nexport interface TaxCodesByRegion {\n readonly [region: string]: readonly string[];\n}\n\n// ─── Tax Report Generator ────────────────────────────────────────────────────\n\nexport interface TaxReportLine {\n readonly line: number | string;\n readonly name: string;\n readonly description: string;\n readonly type: 'input' | 'calculated' | 'manual';\n readonly calculate?: (data: Record<string | number, number>) => number;\n readonly section: string;\n}\n\nexport interface TaxReportTemplate {\n readonly name: string;\n readonly lines: Readonly<Record<string | number, TaxReportLine>>;\n calculate(inputData: Record<string | number, number>, manualData?: Record<string | number, number>): Record<string | number, number>;\n summarize(calculated: Record<string | number, number>): Record<string, unknown>;\n}\n\n// ─── Country Pack ────────────────────────────────────────────────────────────\n\nexport interface CountryPack {\n /** ISO 3166-1 alpha-2 code (e.g., 'CA', 'US', 'GB') */\n readonly code: string;\n /** Country name */\n readonly name: string;\n /** Default currency code */\n readonly defaultCurrency: string;\n\n /**\n * Full chart of accounts template — flat array of account type definitions.\n * Includes both regular accounts and virtual tax sub-accounts.\n */\n readonly accountTypes: readonly AccountType[];\n\n /** Tax codes indexed by code string */\n readonly taxCodes: Readonly<Record<string, TaxCode>>;\n\n /** Tax codes grouped by region/province/state */\n readonly taxCodesByRegion: TaxCodesByRegion;\n\n /** Available regions (provinces/states) */\n readonly regions: readonly string[];\n\n /** Tax report template (e.g., CRA GST/HST return) */\n readonly taxReport?: TaxReportTemplate;\n\n // ── Country-specific report defaults ──\n\n /** Account code for prior retained earnings (e.g. '3660' CA, '3200' US) */\n readonly retainedEarningsCode?: string;\n /** Account code for current year net income (e.g. '3680' CA, '3210' US) */\n readonly currentYearEarningsCode?: string;\n /** Group label code used to identify Cost of Sales in the income statement */\n readonly cogsGroupCode?: string;\n /** Override default English report section names */\n readonly reportLabels?: {\n readonly assets?: string;\n readonly liabilities?: string;\n readonly equity?: string;\n readonly revenue?: string;\n readonly expenses?: string;\n };\n\n // ── Helpers ──\n\n /** Get all account types that can be posted to (not groups, not totals) */\n getPostingAccountTypes(): readonly AccountType[];\n\n /** Get account type by code */\n getAccountType(code: string): AccountType | undefined;\n\n /** Validate an account type code exists */\n isValidAccountType(code: string): boolean;\n\n /** Check if an account type can receive postings */\n isPostingAccount(code: string): boolean;\n\n /** Get tax codes for a specific region */\n getTaxCodesForRegion(region: string): TaxCode[];\n\n /** Flatten hierarchical accounts (if needed) */\n flattenAccountTypes(): readonly AccountType[];\n}\n\n// ─── Helper: Build a country pack from raw data ──────────────────────────────\n\nexport interface CountryPackInput {\n code: string;\n name: string;\n defaultCurrency: string;\n accountTypes: readonly AccountType[];\n taxCodes: Readonly<Record<string, TaxCode>>;\n taxCodesByRegion: TaxCodesByRegion;\n regions: readonly string[];\n taxReport?: TaxReportTemplate;\n retainedEarningsCode?: string;\n currentYearEarningsCode?: string;\n cogsGroupCode?: string;\n reportLabels?: {\n readonly assets?: string;\n readonly liabilities?: string;\n readonly equity?: string;\n readonly revenue?: string;\n readonly expenses?: string;\n };\n}\n\n/**\n * Factory to create a CountryPack with auto-generated helper methods.\n */\nexport function defineCountryPack(input: CountryPackInput): CountryPack {\n // Build lookup map once\n const accountMap = new Map<string, AccountType>();\n for (const at of input.accountTypes) {\n accountMap.set(at.code, at);\n }\n\n const postingTypes = input.accountTypes.filter(at => !at.isTotal && !at.isGroup);\n\n return {\n ...input,\n\n getPostingAccountTypes: () => postingTypes,\n\n getAccountType: (code: string) => accountMap.get(code),\n\n isValidAccountType: (code: string) => accountMap.has(code),\n\n isPostingAccount: (code: string) => {\n const at = accountMap.get(code);\n return at !== undefined && !at.isTotal && !at.isGroup;\n },\n\n getTaxCodesForRegion: (region: string) => {\n const codes = input.taxCodesByRegion[region] ?? [];\n return codes.map(c => input.taxCodes[c]).filter(Boolean) as TaxCode[];\n },\n\n flattenAccountTypes: () => input.accountTypes,\n };\n}\n"],"mappings":";;;;AA8IA,SAAgB,kBAAkB,OAAsC;CAEtE,MAAM,6BAAa,IAAI,KAA0B;AACjD,MAAK,MAAM,MAAM,MAAM,aACrB,YAAW,IAAI,GAAG,MAAM,GAAG;CAG7B,MAAM,eAAe,MAAM,aAAa,QAAO,OAAM,CAAC,GAAG,WAAW,CAAC,GAAG,QAAQ;AAEhF,QAAO;EACL,GAAG;EAEH,8BAA8B;EAE9B,iBAAiB,SAAiB,WAAW,IAAI,KAAK;EAEtD,qBAAqB,SAAiB,WAAW,IAAI,KAAK;EAE1D,mBAAmB,SAAiB;GAClC,MAAM,KAAK,WAAW,IAAI,KAAK;AAC/B,UAAO,OAAO,UAAa,CAAC,GAAG,WAAW,CAAC,GAAG;;EAGhD,uBAAuB,WAAmB;AAExC,WADc,MAAM,iBAAiB,WAAW,EAAE,EACrC,KAAI,MAAK,MAAM,SAAS,GAAG,CAAC,OAAO,QAAQ;;EAG1D,2BAA2B,MAAM;EAClC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/constants/currencies.ts
|
|
2
|
+
const CURRENCIES = Object.freeze({
|
|
3
|
+
CAD: {
|
|
4
|
+
code: "CAD",
|
|
5
|
+
name: "Canadian Dollar",
|
|
6
|
+
symbol: "$",
|
|
7
|
+
minorUnit: 2
|
|
8
|
+
},
|
|
9
|
+
USD: {
|
|
10
|
+
code: "USD",
|
|
11
|
+
name: "US Dollar",
|
|
12
|
+
symbol: "$",
|
|
13
|
+
minorUnit: 2
|
|
14
|
+
},
|
|
15
|
+
GBP: {
|
|
16
|
+
code: "GBP",
|
|
17
|
+
name: "British Pound",
|
|
18
|
+
symbol: "£",
|
|
19
|
+
minorUnit: 2
|
|
20
|
+
},
|
|
21
|
+
EUR: {
|
|
22
|
+
code: "EUR",
|
|
23
|
+
name: "Euro",
|
|
24
|
+
symbol: "€",
|
|
25
|
+
minorUnit: 2
|
|
26
|
+
},
|
|
27
|
+
JPY: {
|
|
28
|
+
code: "JPY",
|
|
29
|
+
name: "Japanese Yen",
|
|
30
|
+
symbol: "¥",
|
|
31
|
+
minorUnit: 0
|
|
32
|
+
},
|
|
33
|
+
AUD: {
|
|
34
|
+
code: "AUD",
|
|
35
|
+
name: "Australian Dollar",
|
|
36
|
+
symbol: "$",
|
|
37
|
+
minorUnit: 2
|
|
38
|
+
},
|
|
39
|
+
CHF: {
|
|
40
|
+
code: "CHF",
|
|
41
|
+
name: "Swiss Franc",
|
|
42
|
+
symbol: "CHF",
|
|
43
|
+
minorUnit: 2
|
|
44
|
+
},
|
|
45
|
+
INR: {
|
|
46
|
+
code: "INR",
|
|
47
|
+
name: "Indian Rupee",
|
|
48
|
+
symbol: "₹",
|
|
49
|
+
minorUnit: 2
|
|
50
|
+
},
|
|
51
|
+
BDT: {
|
|
52
|
+
code: "BDT",
|
|
53
|
+
name: "Bangladeshi Taka",
|
|
54
|
+
symbol: "৳",
|
|
55
|
+
minorUnit: 2
|
|
56
|
+
},
|
|
57
|
+
AED: {
|
|
58
|
+
code: "AED",
|
|
59
|
+
name: "UAE Dirham",
|
|
60
|
+
symbol: "د.إ",
|
|
61
|
+
minorUnit: 2
|
|
62
|
+
},
|
|
63
|
+
SAR: {
|
|
64
|
+
code: "SAR",
|
|
65
|
+
name: "Saudi Riyal",
|
|
66
|
+
symbol: "﷼",
|
|
67
|
+
minorUnit: 2
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
function getCurrency(code) {
|
|
71
|
+
return CURRENCIES[code] ?? null;
|
|
72
|
+
}
|
|
73
|
+
function isValidCurrency(code) {
|
|
74
|
+
return code in CURRENCIES;
|
|
75
|
+
}
|
|
76
|
+
function getMinorUnit(code) {
|
|
77
|
+
return CURRENCIES[code]?.minorUnit ?? 2;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { isValidCurrency as i, getCurrency as n, getMinorUnit as r, CURRENCIES as t };
|
|
82
|
+
//# sourceMappingURL=currencies-BBk3NwXn.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currencies-BBk3NwXn.mjs","names":[],"sources":["../src/constants/currencies.ts"],"sourcesContent":["/**\r\n * ISO 4217 Currency Definitions\r\n */\r\n\r\nimport type { Currency } from '../types/core.js';\r\n\r\nexport const CURRENCIES: Readonly<Record<string, Currency>> = Object.freeze({\r\n CAD: { code: 'CAD', name: 'Canadian Dollar', symbol: '$', minorUnit: 2 },\r\n USD: { code: 'USD', name: 'US Dollar', symbol: '$', minorUnit: 2 },\r\n GBP: { code: 'GBP', name: 'British Pound', symbol: '£', minorUnit: 2 },\r\n EUR: { code: 'EUR', name: 'Euro', symbol: '€', minorUnit: 2 },\r\n JPY: { code: 'JPY', name: 'Japanese Yen', symbol: '¥', minorUnit: 0 },\r\n AUD: { code: 'AUD', name: 'Australian Dollar', symbol: '$', minorUnit: 2 },\r\n CHF: { code: 'CHF', name: 'Swiss Franc', symbol: 'CHF', minorUnit: 2 },\r\n INR: { code: 'INR', name: 'Indian Rupee', symbol: '₹', minorUnit: 2 },\r\n BDT: { code: 'BDT', name: 'Bangladeshi Taka', symbol: '৳', minorUnit: 2 },\r\n AED: { code: 'AED', name: 'UAE Dirham', symbol: 'د.إ', minorUnit: 2 },\r\n SAR: { code: 'SAR', name: 'Saudi Riyal', symbol: '﷼', minorUnit: 2 },\r\n});\r\n\r\nexport function getCurrency(code: string): Currency | null {\r\n return CURRENCIES[code] ?? null;\r\n}\r\n\r\nexport function isValidCurrency(code: string): boolean {\r\n return code in CURRENCIES;\r\n}\r\n\r\nexport function getMinorUnit(code: string): number {\r\n return CURRENCIES[code]?.minorUnit ?? 2;\r\n}\r\n"],"mappings":";AAMA,MAAa,aAAiD,OAAO,OAAO;CAC1E,KAAK;EAAE,MAAM;EAAO,MAAM;EAAmB,QAAQ;EAAK,WAAW;EAAG;CACxE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAa,QAAQ;EAAK,WAAW;EAAG;CAClE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAiB,QAAQ;EAAK,WAAW;EAAG;CACtE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAQ,QAAQ;EAAK,WAAW;EAAG;CAC7D,KAAK;EAAE,MAAM;EAAO,MAAM;EAAgB,QAAQ;EAAK,WAAW;EAAG;CACrE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAqB,QAAQ;EAAK,WAAW;EAAG;CAC1E,KAAK;EAAE,MAAM;EAAO,MAAM;EAAe,QAAQ;EAAO,WAAW;EAAG;CACtE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAgB,QAAQ;EAAK,WAAW;EAAG;CACrE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAoB,QAAQ;EAAK,WAAW;EAAG;CACzE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAc,QAAQ;EAAO,WAAW;EAAG;CACrE,KAAK;EAAE,MAAM;EAAO,MAAM;EAAe,QAAQ;EAAK,WAAW;EAAG;CACrE,CAAC;AAEF,SAAgB,YAAY,MAA+B;AACzD,QAAO,WAAW,SAAS;;AAG7B,SAAgB,gBAAgB,MAAuB;AACrD,QAAO,QAAQ;;AAGjB,SAAgB,aAAa,MAAsB;AACjD,QAAO,WAAW,OAAO,aAAa"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { d as JournalType, f as MainType, h as StatementType, i as CategoryKey, o as Currency, r as Category } from "./core-Cx0baosR.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/constants/categories.d.ts
|
|
4
|
+
/** All valid categories */
|
|
5
|
+
declare const CATEGORIES: Readonly<Record<CategoryKey, Category>>;
|
|
6
|
+
declare const CATEGORY_KEYS: CategoryKey[];
|
|
7
|
+
declare function isValidCategory(key: string): key is CategoryKey;
|
|
8
|
+
declare function getCategoryMainType(key: CategoryKey): MainType;
|
|
9
|
+
declare function getCategoryStatementType(key: CategoryKey): StatementType;
|
|
10
|
+
declare function isBalanceSheet(key: CategoryKey): boolean;
|
|
11
|
+
declare function isIncomeStatement(key: CategoryKey): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get the normal balance for a main type.
|
|
14
|
+
* Assets & Expenses → debit. Liabilities, Equity & Income → credit.
|
|
15
|
+
*/
|
|
16
|
+
declare function getNormalBalance(mainType: MainType): 'debit' | 'credit';
|
|
17
|
+
/** Build a category key from parts */
|
|
18
|
+
declare function categoryKey(statement: StatementType, mainType: MainType): CategoryKey;
|
|
19
|
+
/** Extract main type from a category key string */
|
|
20
|
+
declare function extractMainType(key: string): MainType | null;
|
|
21
|
+
/** Extract statement type from a category key string */
|
|
22
|
+
declare function extractStatementType(key: string): StatementType | null;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/constants/journals.d.ts
|
|
25
|
+
declare const JOURNAL_TYPES: Readonly<Record<string, JournalType>>;
|
|
26
|
+
declare const JOURNAL_CODES: Readonly<Record<string, string>>;
|
|
27
|
+
declare function getJournalTypeCodes(): string[];
|
|
28
|
+
declare function isValidJournalType(code: string): boolean;
|
|
29
|
+
declare function getJournalType(code: string): JournalType | null;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/constants/currencies.d.ts
|
|
32
|
+
declare const CURRENCIES: Readonly<Record<string, Currency>>;
|
|
33
|
+
declare function getCurrency(code: string): Currency | null;
|
|
34
|
+
declare function isValidCurrency(code: string): boolean;
|
|
35
|
+
declare function getMinorUnit(code: string): number;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { getNormalBalance as _, JOURNAL_CODES as a, isValidCategory as b, getJournalTypeCodes as c, CATEGORY_KEYS as d, categoryKey as f, getCategoryStatementType as g, getCategoryMainType as h, isValidCurrency as i, isValidJournalType as l, extractStatementType as m, getCurrency as n, JOURNAL_TYPES as o, extractMainType as p, getMinorUnit as r, getJournalType as s, CURRENCIES as t, CATEGORIES as u, isBalanceSheet as v, isIncomeStatement as y };
|
|
38
|
+
//# sourceMappingURL=currencies-Bkn3FNkC.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currencies-Bkn3FNkC.d.mts","names":[],"sources":["../src/constants/categories.ts","../src/constants/journals.ts","../src/constants/currencies.ts"],"mappings":";;;;cAOa,UAAA,EAAY,QAAA,CAAS,MAAA,CAAO,WAAA,EAAa,QAAA;AAAA,cAQzC,aAAA,EAA2C,WAAA;AAAA,iBAExC,eAAA,CAAgB,GAAA,WAAc,GAAA,IAAO,WAAA;AAAA,iBAIrC,mBAAA,CAAoB,GAAA,EAAK,WAAA,GAAc,QAAA;AAAA,iBAIvC,wBAAA,CAAyB,GAAA,EAAK,WAAA,GAAc,aAAA;AAAA,iBAI5C,cAAA,CAAe,GAAA,EAAK,WAAA;AAAA,iBAIpB,iBAAA,CAAkB,GAAA,EAAK,WAAA;;;;;iBAQvB,gBAAA,CAAiB,QAAA,EAAU,QAAA;;iBAK3B,WAAA,CAAY,SAAA,EAAW,aAAA,EAAe,QAAA,EAAU,QAAA,GAAW,WAAA;;iBAK3D,eAAA,CAAgB,GAAA,WAAc,QAAA;;iBAM9B,oBAAA,CAAqB,GAAA,WAAc,aAAA;;;cClDtC,aAAA,EAAe,QAAA,CAAS,MAAA,SAAe,WAAA;AAAA,cAkBvC,aAAA,EAAa,QAAA,CAAA,MAAA;AAAA,iBAIV,mBAAA,CAAA;AAAA,iBAIA,kBAAA,CAAmB,IAAA;AAAA,iBAInB,cAAA,CAAe,IAAA,WAAe,WAAA;;;cC/BjC,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,QAAA;AAAA,iBAcjC,WAAA,CAAY,IAAA,WAAe,QAAA;AAAA,iBAI3B,eAAA,CAAgB,IAAA;AAAA,iBAIhB,YAAA,CAAa,IAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CountryPack } from "./country/index.mjs";
|
|
2
|
+
import { t as Logger } from "./logger-Cv6VVc4r.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/types/engine.d.ts
|
|
5
|
+
/** Multi-tenant configuration */
|
|
6
|
+
interface MultiTenantConfig {
|
|
7
|
+
/** Field name for the organization reference (e.g., 'business', 'organization', 'company') */
|
|
8
|
+
orgField: string;
|
|
9
|
+
/** Mongoose model name the org field references (e.g., 'Business', 'Organization') */
|
|
10
|
+
orgRef: string;
|
|
11
|
+
}
|
|
12
|
+
/** Options passed to schema factory functions */
|
|
13
|
+
interface SchemaOptions {
|
|
14
|
+
/** Add recommended indexes (default: true) */
|
|
15
|
+
indexes?: boolean;
|
|
16
|
+
/** Extra Mongoose schema fields to merge in */
|
|
17
|
+
extraFields?: Record<string, unknown>;
|
|
18
|
+
/** Extra indexes to add */
|
|
19
|
+
extraIndexes?: Array<{
|
|
20
|
+
fields: Record<string, 1 | -1>;
|
|
21
|
+
options?: Record<string, unknown>;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** Journal entry schema-specific options */
|
|
25
|
+
interface JournalSchemaOptions extends SchemaOptions {
|
|
26
|
+
/** Auto-generate reference numbers (default: true) */
|
|
27
|
+
autoReference?: boolean;
|
|
28
|
+
/** Enable text search index on reference + label (default: true) */
|
|
29
|
+
textSearch?: boolean;
|
|
30
|
+
/** Extra Mongoose schema fields to merge into the JournalItem subdocument */
|
|
31
|
+
extraItemFields?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** Audit trail configuration */
|
|
34
|
+
interface AuditConfig {
|
|
35
|
+
/** Track actor (user) who performs each operation (post, reverse, approve) */
|
|
36
|
+
trackActor?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Strictness rules for the ledger */
|
|
39
|
+
interface StrictnessConfig {
|
|
40
|
+
/** If true, unpost() is disabled — correction only via reverse() (immutable ledger) */
|
|
41
|
+
immutable?: boolean;
|
|
42
|
+
/** If true, actorId is required on post/reverse/unpost operations */
|
|
43
|
+
requireActor?: boolean;
|
|
44
|
+
/** If true, entries must have approvedBy/approvedAt set before posting */
|
|
45
|
+
requireApproval?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Main engine configuration */
|
|
48
|
+
interface AccountingEngineConfig {
|
|
49
|
+
/** Country pack providing account types, tax codes, and templates */
|
|
50
|
+
country: CountryPack;
|
|
51
|
+
/** Default ISO 4217 currency code (e.g., 'CAD', 'USD') */
|
|
52
|
+
currency: string;
|
|
53
|
+
/** Multi-tenant configuration. Omit for single-tenant apps. */
|
|
54
|
+
multiTenant?: MultiTenantConfig;
|
|
55
|
+
/** Fiscal year start month (1-12, default: 1 = January) */
|
|
56
|
+
fiscalYearStartMonth?: number;
|
|
57
|
+
/** Display code for prior retained earnings on balance sheet (default: '3660') */
|
|
58
|
+
retainedEarningsCode?: string;
|
|
59
|
+
/** Display code for current year net income on balance sheet (default: '3680') */
|
|
60
|
+
currentYearEarningsCode?: string;
|
|
61
|
+
/** Logger instance. Defaults to console-based logger. */
|
|
62
|
+
logger?: Logger;
|
|
63
|
+
/** Audit trail configuration */
|
|
64
|
+
audit?: AuditConfig;
|
|
65
|
+
/** Enable built-in idempotency key field on journal entries */
|
|
66
|
+
idempotency?: boolean;
|
|
67
|
+
/** Strictness rules for the ledger */
|
|
68
|
+
strictness?: StrictnessConfig;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { SchemaOptions as a, MultiTenantConfig as i, AuditConfig as n, StrictnessConfig as o, JournalSchemaOptions as r, AccountingEngineConfig as t };
|
|
72
|
+
//# sourceMappingURL=engine-Cd73EOT6.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-Cd73EOT6.d.mts","names":[],"sources":["../src/types/engine.ts"],"mappings":";;;;;UAaiB,iBAAA;EAUa;EAR5B,QAAA;EAYc;EAVd,MAAA;AAAA;;UAMe,aAAA;EAMK;EAJpB,OAAA;EAEA;EAAA,WAAA,GAAc,MAAA;EAEd;EAAA,YAAA,GAAe,KAAA;IAAQ,MAAA,EAAQ,MAAA;IAAwB,OAAA,GAAU,MAAA;EAAA;AAAA;;UAIlD,oBAAA,SAA6B,aAAA;EAA7B;EAEf,aAAA;;EAEA,UAAA;EAJ4C;EAM5C,eAAA,GAAkB,MAAA;AAAA;;UAMH,WAAA;EANS;EAQxB,UAAA;AAAA;;UAMe,gBAAA;EANf;EAQA,SAAA;EAFe;EAIf,YAAA;;EAEA,eAAA;AAAA;;UAMe,sBAAA;EANA;EAQf,OAAA,EAAS,WAAA;EAFM;EAIf,QAAA;;EAEA,WAAA,GAAc,iBAAA;EAAA;EAEd,oBAAA;EAQQ;EANR,oBAAA;EAU6B;EAR7B,uBAAA;EAVA;EAYA,MAAA,GAAS,MAAA;EAVT;EAYA,KAAA,GAAQ,WAAA;EAVM;EAYd,WAAA;EARA;EAUA,UAAA,GAAa,gBAAA;AAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/utils/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Typed error for the accounting package.
|
|
4
|
+
* Carries HTTP status + machine-readable code.
|
|
5
|
+
* Replaces all ad-hoc `(error as ...).status = N` patterns.
|
|
6
|
+
*/
|
|
7
|
+
var AccountingError = class extends Error {
|
|
8
|
+
status;
|
|
9
|
+
code;
|
|
10
|
+
constructor(message, status = 400, code = "ACCOUNTING_ERROR") {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "AccountingError";
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** Convenience factory functions */
|
|
18
|
+
const Errors = {
|
|
19
|
+
validation: (msg) => new AccountingError(msg, 400, "VALIDATION_ERROR"),
|
|
20
|
+
notFound: (msg) => new AccountingError(msg, 404, "NOT_FOUND"),
|
|
21
|
+
conflict: (msg) => new AccountingError(msg, 409, "CONFLICT"),
|
|
22
|
+
immutable: (msg) => new AccountingError(msg, 403, "IMMUTABLE_ENTRY"),
|
|
23
|
+
fiscal: (msg) => new AccountingError(msg, 400, "FISCAL_ERROR")
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Errors as n, AccountingError as t };
|
|
28
|
+
//# sourceMappingURL=errors-CeqRahE-.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CeqRahE-.mjs","names":[],"sources":["../src/utils/errors.ts"],"sourcesContent":["/**\r\n * Typed error for the accounting package.\r\n * Carries HTTP status + machine-readable code.\r\n * Replaces all ad-hoc `(error as ...).status = N` patterns.\r\n */\r\nexport class AccountingError extends Error {\r\n readonly status: number;\r\n readonly code: string;\r\n\r\n constructor(message: string, status = 400, code = 'ACCOUNTING_ERROR') {\r\n super(message);\r\n this.name = 'AccountingError';\r\n this.status = status;\r\n this.code = code;\r\n }\r\n}\r\n\r\n/** Convenience factory functions */\r\nexport const Errors = {\r\n validation: (msg: string) => new AccountingError(msg, 400, 'VALIDATION_ERROR'),\r\n notFound: (msg: string) => new AccountingError(msg, 404, 'NOT_FOUND'),\r\n conflict: (msg: string) => new AccountingError(msg, 409, 'CONFLICT'),\r\n immutable: (msg: string) => new AccountingError(msg, 403, 'IMMUTABLE_ENTRY'),\r\n fiscal: (msg: string) => new AccountingError(msg, 400, 'FISCAL_ERROR'),\r\n} as const;\r\n"],"mappings":";;;;;;AAKA,IAAa,kBAAb,cAAqC,MAAM;CACzC,AAAS;CACT,AAAS;CAET,YAAY,SAAiB,SAAS,KAAK,OAAO,oBAAoB;AACpE,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,SAAS;AACd,OAAK,OAAO;;;;AAKhB,MAAa,SAAS;CACpB,aAAa,QAAgB,IAAI,gBAAgB,KAAK,KAAK,mBAAmB;CAC9E,WAAW,QAAgB,IAAI,gBAAgB,KAAK,KAAK,YAAY;CACrE,WAAW,QAAgB,IAAI,gBAAgB,KAAK,KAAK,WAAW;CACpE,YAAY,QAAgB,IAAI,gBAAgB,KAAK,KAAK,kBAAkB;CAC5E,SAAS,QAAgB,IAAI,gBAAgB,KAAK,KAAK,eAAe;CACvE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as PopulatedJournalEntry, a as exportToCsv, c as getHeaders, d as serializeCsv, f as CsvOptions, g as PopulatedAccount, h as FlatJournalRow, i as flattenJournalEntry, l as buildCsv, m as ExportFieldMap, n as quickbooksFieldMap, o as extractAllRows, p as ExportField, r as flattenJournalEntries, s as extractRow, t as universalFieldMap, u as escapeCell, v as PopulatedJournalItem } from "../universal-x33ZJODp.mjs";
|
|
2
|
+
export { type CsvOptions, type ExportField, type ExportFieldMap, type FlatJournalRow, type PopulatedAccount, type PopulatedJournalEntry, type PopulatedJournalItem, buildCsv, escapeCell, exportToCsv, extractAllRows, extractRow, flattenJournalEntries, flattenJournalEntry, getHeaders, quickbooksFieldMap, serializeCsv, universalFieldMap };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as exportToCsv, c as getHeaders, d as serializeCsv, i as flattenJournalEntry, l as buildCsv, n as quickbooksFieldMap, o as extractAllRows, r as flattenJournalEntries, s as extractRow, t as universalFieldMap, u as escapeCell } from "../universal-CMfrZ2hG.mjs";
|
|
2
|
+
|
|
3
|
+
export { buildCsv, escapeCell, exportToCsv, extractAllRows, extractRow, flattenJournalEntries, flattenJournalEntry, getHeaders, quickbooksFieldMap, serializeCsv, universalFieldMap };
|