@classytic/ledger 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +82 -20
  2. package/dist/constants/index.d.mts +2 -2
  3. package/dist/constants/index.mjs +3 -3
  4. package/dist/{date-lock.plugin-eYAJ9h_u.mjs → date-lock.plugin-DL6pe24p.mjs} +2 -2
  5. package/dist/{engine-Cn-9yerQ.d.mts → engine-scgOvxHJ.d.mts} +30 -2
  6. package/dist/exports/index.d.mts +1 -1
  7. package/dist/exports/index.mjs +1 -1
  8. package/dist/{exports-I5Xkq-9_.mjs → exports-DoGQQtMQ.mjs} +96 -75
  9. package/dist/{fiscal-close-B6LhQ10f.mjs → fiscal-close-B2_7WMTe.mjs} +748 -751
  10. package/dist/{index-BPukb3L8.d.mts → index-J-XIbXH-.d.mts} +7 -7
  11. package/dist/index.d.mts +239 -87
  12. package/dist/index.mjs +149 -12
  13. package/dist/{fiscal-period.schema-BMnlI9H5.d.mts → journal-entry.schema-JqrfbvB4.d.mts} +12 -12
  14. package/dist/{journals-oH-FK3g8.mjs → journals-BfwnCFam.mjs} +27 -4
  15. package/dist/{currencies-4WAbFRlw.d.mts → journals-DTipb_rz.d.mts} +16 -7
  16. package/dist/money.mjs +2 -2
  17. package/dist/plugins/index.d.mts +1 -1
  18. package/dist/plugins/index.mjs +1 -1
  19. package/dist/{reconciliation.repository-CW4-8q90.d.mts → reconciliation.repository-D-D_ITL-.d.mts} +14 -14
  20. package/dist/{account.repository-BpkSd6q3.mjs → reconciliation.repository-fPwFKvrk.mjs} +255 -255
  21. package/dist/{reconciliation.schema-BuetvZTd.mjs → reconciliation.schema-BA1lPv4t.mjs} +174 -173
  22. package/dist/reports/index.d.mts +1 -1
  23. package/dist/reports/index.mjs +1 -1
  24. package/dist/repositories/index.d.mts +1 -1
  25. package/dist/repositories/index.mjs +1 -1
  26. package/dist/schemas/index.d.mts +6 -6
  27. package/dist/schemas/index.mjs +1 -1
  28. package/dist/{tenant-guard-Fm6AID_6.mjs → tenant-guard-r17Se3Bb.mjs} +1 -1
  29. package/dist/{revaluation-D9x0NE8w.d.mts → trial-balance-DcQ0xj_4.d.mts} +124 -124
  30. package/docs/schemas.md +2 -2
  31. package/package.json +14 -6
  32. /package/dist/{categories-CclX7Q94.mjs → categories-DWogBUgQ.mjs} +0 -0
  33. /package/dist/{errors-B7yC-Jfw.mjs → errors-B_dyYZc_.mjs} +0 -0
  34. /package/dist/{idempotency.plugin-B_CNsInz.d.mts → idempotency.plugin-zU-GKJ0-.d.mts} +0 -0
  35. /package/dist/{logger-CbHWZl7v.d.mts → logger-UbTdBb1x.d.mts} +0 -0
@@ -121,16 +121,16 @@ declare function extractAllRows<TRow>(fieldMap: ExportFieldMap<TRow>, rows: read
121
121
  /** One-shot: map + serialize to CSV string. */
122
122
  declare function exportToCsv<TRow>(fieldMap: ExportFieldMap<TRow>, rows: readonly TRow[], options?: CsvOptions): string;
123
123
  //#endregion
124
- //#region src/exports/flatten-journal.d.ts
125
- /** Flatten a single journal entry into one FlatJournalRow per journal item. */
126
- declare function flattenJournalEntry(entry: PopulatedJournalEntry): FlatJournalRow[];
127
- /** Flatten multiple journal entries into a single flat row array. */
128
- declare function flattenJournalEntries(entries: readonly PopulatedJournalEntry[]): FlatJournalRow[];
129
- //#endregion
130
124
  //#region src/exports/field-maps/quickbooks.d.ts
131
125
  declare const quickbooksFieldMap: ExportFieldMap<FlatJournalRow>;
132
126
  //#endregion
133
127
  //#region src/exports/field-maps/universal.d.ts
134
128
  declare const universalFieldMap: ExportFieldMap<FlatJournalRow>;
135
129
  //#endregion
136
- export { PopulatedJournalEntry as _, exportToCsv as a, getHeaders as c, serializeCsv as d, CsvOptions as f, PopulatedAccount as g, FlatJournalRow as h, flattenJournalEntry as i, buildCsv as l, ExportFieldMap as m, quickbooksFieldMap as n, extractAllRows as o, ExportField as p, flattenJournalEntries as r, extractRow as s, universalFieldMap as t, escapeCell as u, PopulatedJournalItem as v };
130
+ //#region src/exports/flatten-journal.d.ts
131
+ /** Flatten a single journal entry into one FlatJournalRow per journal item. */
132
+ declare function flattenJournalEntry(entry: PopulatedJournalEntry): FlatJournalRow[];
133
+ /** Flatten multiple journal entries into a single flat row array. */
134
+ declare function flattenJournalEntries(entries: readonly PopulatedJournalEntry[]): FlatJournalRow[];
135
+ //#endregion
136
+ export { PopulatedJournalEntry as _, exportToCsv as a, getHeaders as c, serializeCsv as d, CsvOptions as f, PopulatedAccount as g, FlatJournalRow as h, quickbooksFieldMap as i, buildCsv as l, ExportFieldMap as m, flattenJournalEntry as n, extractAllRows as o, ExportField as p, universalFieldMap as r, extractRow as s, flattenJournalEntries as t, escapeCell as u, PopulatedJournalItem as v };
package/dist/index.d.mts CHANGED
@@ -1,18 +1,69 @@
1
1
  import { _ as TaxMetadata, a as Cents, c as DateRange, d as JournalType, f as MainType, g as TaxDetail, h as StatementType, i as CategoryKey, l as EntryState, m as ObjectId, n as CashFlowCategory, o as Currency, p as NormalBalance, s as DateOption, t as AccountType, u as JournalItem, v as TotalAccountOp } from "./core-8Xfnpn6g.mjs";
2
- import { _ as getNormalBalance, a as JOURNAL_CODES, b as isValidCategory, c as getJournalTypeCodes, d as CATEGORY_KEYS, i as isValidCurrency, l as isValidJournalType, n as getCurrency, o as JOURNAL_TYPES, r as getMinorUnit, t as CURRENCIES, u as CATEGORIES, v as isBalanceSheet, y as isIncomeStatement } from "./currencies-4WAbFRlw.mjs";
2
+ import { S as isValidCategory, a as getJournalTypeCodes, b as isBalanceSheet, c as CURRENCIES, d as isValidCurrency, f as CATEGORIES, i as getJournalType, l as getCurrency, n as JOURNAL_TYPES, o as isValidJournalType, p as CATEGORY_KEYS, r as getCustomJournalTypes, s as registerJournalType, t as JOURNAL_CODES, u as getMinorUnit, x as isIncomeStatement, y as getNormalBalance } from "./journals-DTipb_rz.mjs";
3
3
  import { a as TaxReportLine, i as TaxCodesByRegion, n as CountryPackInput, o as TaxReportTemplate, r as TaxCode, s as defineCountryPack, t as CountryPack } from "./index-CxZqRaOU.mjs";
4
- import { _ as PopulatedJournalEntry, a as exportToCsv, h as FlatJournalRow, m as ExportFieldMap, n as quickbooksFieldMap, p as ExportField, r as flattenJournalEntries, t as universalFieldMap } from "./index-BPukb3L8.mjs";
4
+ import { _ as PopulatedJournalEntry, a as exportToCsv, h as FlatJournalRow, i as quickbooksFieldMap, m as ExportFieldMap, p as ExportField, r as universalFieldMap, t as flattenJournalEntries } from "./index-J-XIbXH-.mjs";
5
5
  import { Money, abs, add, allocate, equals, format, formatPlain, fromDecimal, isNegative, isPositive, isValid, isZero, max, min, multiply, negate, parseCents, percentage, round, splitTaxExclusive, splitTaxInclusive, subtract, toDecimal } from "./money.mjs";
6
- import { $ as BudgetVsActualReport, A as generateGeneralLedger, B as GeneralLedgerAccount, E as reopenFiscalPeriod, G as ReportCategory, H as IncomeStatementReport, I as generateTrialBalance, J as TaxReturnSummary, K as ReportGroup, L as BalanceSheetReport, M as generateIncomeStatement, O as generateCashFlow, P as generateBalanceSheet, R as CashFlowReport, T as closeFiscalPeriod, U as LedgerEntry, V as GeneralLedgerReport, W as ReportAccount, X as TrialBalanceRow, Y as TrialBalanceReport, _ as DimensionBreakdownOptions, a as AccountForeignBalance, b as DimensionBreakdownRow, c as buildRevaluationEntry, d as AgedBalanceParams, f as AgedBalanceReport, g as generateAgedBalance, h as DEFAULT_BUCKETS, i as generateRevaluation, l as computeRevaluation, m as AgedBucketConfig, n as RevaluationParams, o as RevaluationRate, p as AgedBalanceRow, q as TaxReport, r as RevaluationReport, s as RevaluationResult, t as RevaluationOptions, u as AgedBalanceOptions, v as DimensionBreakdownParams, x as generateDimensionBreakdown, y as DimensionBreakdownReport, z as CashFlowSection } from "./revaluation-D9x0NE8w.mjs";
7
- import { n as defaultLogger, t as Logger } from "./logger-CbHWZl7v.mjs";
8
- import { a as MultiTenantConfig, i as MultiCurrencyConfig, n as AuditConfig, o as SchemaOptions, r as JournalSchemaOptions, s as StrictnessConfig, t as AccountingEngineConfig } from "./engine-Cn-9yerQ.mjs";
9
- import { a as BulkCreateInput, c as PostOptions, d as ReverseOptions, f as ReverseResult, i as AccountRepository, l as ReconcileParams, m as SeedResult, n as wireAccountMethods, o as BulkCreateResult, p as SeedOptions, r as wireJournalEntryMethods, s as JournalEntryRepository, t as wireReconciliationMethods, u as ReconciliationRepository } from "./reconciliation.repository-CW4-8q90.mjs";
10
- import { n as createJournalEntrySchema, r as createAccountSchema, t as createFiscalPeriodSchema } from "./fiscal-period.schema-BMnlI9H5.mjs";
11
- import { c as dateLockPlugin, i as fiscalLockPlugin, n as idempotencyPlugin, o as doubleEntryPlugin } from "./idempotency.plugin-B_CNsInz.mjs";
6
+ import { n as defaultLogger, t as Logger } from "./logger-UbTdBb1x.mjs";
7
+ import { a as MultiCurrencyConfig, c as StrictnessConfig, i as ModelNames, n as AuditConfig, o as MultiTenantConfig, r as JournalSchemaOptions, s as SchemaOptions, t as AccountingEngineConfig } from "./engine-scgOvxHJ.mjs";
8
+ import { a as BulkCreateInput, c as PostOptions, d as ReverseOptions, f as ReverseResult, i as AccountRepository, l as ReconcileParams, m as SeedResult, n as wireJournalEntryMethods, o as BulkCreateResult, p as SeedOptions, r as wireAccountMethods, s as JournalEntryRepository, t as wireReconciliationMethods, u as ReconciliationRepository } from "./reconciliation.repository-D-D_ITL-.mjs";
9
+ import { n as createFiscalPeriodSchema, r as createAccountSchema, t as createJournalEntrySchema } from "./journal-entry.schema-JqrfbvB4.mjs";
10
+ import { c as dateLockPlugin, i as fiscalLockPlugin, n as idempotencyPlugin, o as doubleEntryPlugin } from "./idempotency.plugin-zU-GKJ0-.mjs";
11
+ import { $ as AgedBucketConfig, A as BudgetVsActualReport, B as IncomeStatementReport, C as DimensionBreakdownReport, D as generateCashFlow, F as BalanceSheetReport, G as TaxReport, H as ReportAccount, I as CashFlowReport, J as TrialBalanceRow, K as TaxReturnSummary, L as CashFlowSection, M as generateBudgetVsActual, O as BudgetVsActualOptions, P as generateBalanceSheet, Q as AgedBalanceRow, R as GeneralLedgerAccount, S as DimensionBreakdownParams, T as generateDimensionBreakdown, U as ReportCategory, V as LedgerEntry, W as ReportGroup, X as AgedBalanceParams, Y as AgedBalanceOptions, Z as AgedBalanceReport, a as RevaluationReport, b as reopenFiscalPeriod, c as RevaluationRate, d as computeRevaluation, et as DEFAULT_BUCKETS, h as generateGeneralLedger, i as RevaluationParams, j as BudgetVsActualRow, k as BudgetVsActualParams, l as RevaluationResult, n as generateTrialBalance, o as generateRevaluation, p as generateIncomeStatement, q as TrialBalanceReport, r as RevaluationOptions, s as AccountForeignBalance, tt as generateAgedBalance, u as buildRevaluationEntry, w as DimensionBreakdownRow, x as DimensionBreakdownOptions, y as closeFiscalPeriod, z as GeneralLedgerReport } from "./trial-balance-DcQ0xj_4.mjs";
12
12
  import * as mongoose$1 from "mongoose";
13
13
  import { ClientSession, Connection, Model } from "mongoose";
14
14
  import { PluginType, Repository } from "@classytic/mongokit";
15
15
 
16
+ //#region src/models/factory.d.ts
17
+ interface LedgerModels {
18
+ Account: Model<unknown>;
19
+ JournalEntry: Model<unknown>;
20
+ FiscalPeriod: Model<unknown>;
21
+ Budget: Model<unknown>;
22
+ Reconciliation: Model<unknown>;
23
+ }
24
+ interface ResolvedModelNames {
25
+ account: string;
26
+ journalEntry: string;
27
+ fiscalPeriod: string;
28
+ budget: string;
29
+ reconciliation: string;
30
+ }
31
+ declare function resolveModelNames(overrides?: ModelNames): ResolvedModelNames;
32
+ /**
33
+ * Create (or reuse) all ledger models on the given connection.
34
+ *
35
+ * If a model with the same name is already registered on the connection,
36
+ * the existing model is reused — this allows multiple engine instances
37
+ * to share models and prevents "OverwriteModelError".
38
+ */
39
+ declare function createModels(connection: Connection, config: AccountingEngineConfig): LedgerModels;
40
+ //#endregion
41
+ //#region src/repositories/factory.d.ts
42
+ interface LedgerRepositoryPlugins {
43
+ account?: PluginType[];
44
+ journalEntry?: PluginType[];
45
+ fiscalPeriod?: PluginType[];
46
+ budget?: PluginType[];
47
+ reconciliation?: PluginType[];
48
+ }
49
+ interface LedgerRepositories {
50
+ accounts: AccountRepository<unknown>;
51
+ journalEntries: JournalEntryRepository<unknown>;
52
+ fiscalPeriods: Repository<unknown>;
53
+ budgets: Repository<unknown>;
54
+ reconciliations: ReconciliationRepository<unknown>;
55
+ }
56
+ /**
57
+ * Build all ledger repositories with plugins + domain methods pre-wired.
58
+ *
59
+ * - `accounts` — has seedAccounts(), bulkCreate()
60
+ * - `journalEntries` — has post(), unpost(), reverse(), duplicate() + double-entry + fiscal-lock (+ idempotency if enabled)
61
+ * - `fiscalPeriods` — plain CRUD
62
+ * - `budgets` — plain CRUD
63
+ * - `reconciliations` — has reconcile(), unreconcile(), getUnreconciled()
64
+ */
65
+ declare function createRepositories(models: LedgerModels, config: AccountingEngineConfig, plugins?: LedgerRepositoryPlugins): LedgerRepositories;
66
+ //#endregion
16
67
  //#region src/engine.d.ts
17
68
  declare class AccountingEngine {
18
69
  readonly config: AccountingEngineConfig;
@@ -42,7 +93,102 @@ declare class AccountingEngine {
42
93
  readonly isValid: typeof isValid;
43
94
  readonly parseCents: typeof parseCents;
44
95
  };
45
- constructor(config: AccountingEngineConfig);
96
+ private _models?;
97
+ private _repositories?;
98
+ private _reports?;
99
+ constructor(config: AccountingEngineConfig, plugins?: LedgerRepositoryPlugins);
100
+ /**
101
+ * Auto-created Mongoose models. Requires `mongoose` in config.
102
+ *
103
+ * @throws if `mongoose` was not provided in config
104
+ */
105
+ get models(): LedgerModels;
106
+ /**
107
+ * Auto-wired repositories with plugins + domain methods (post, reverse, etc.).
108
+ * Requires `mongoose` in config.
109
+ *
110
+ * @throws if `mongoose` was not provided in config
111
+ */
112
+ get repositories(): LedgerRepositories;
113
+ /**
114
+ * Pre-built reports bound to auto-created models. Requires `mongoose` in config.
115
+ * For custom models, use `engine.createReports({ Account, JournalEntry, Budget })`.
116
+ */
117
+ get reports(): {
118
+ trialBalance: (params: {
119
+ organizationId?: unknown;
120
+ dateOption: "month" | "quarter" | "year" | "custom";
121
+ dateValue: unknown;
122
+ accountId?: string;
123
+ filters?: Record<string, unknown>;
124
+ }) => Promise<TrialBalanceReport>;
125
+ balanceSheet: (params: {
126
+ organizationId?: unknown;
127
+ dateOption: "month" | "quarter" | "year" | "custom";
128
+ dateValue: unknown;
129
+ businessName?: string;
130
+ filters?: Record<string, unknown>;
131
+ }) => Promise<BalanceSheetReport>;
132
+ incomeStatement: (params: {
133
+ organizationId?: unknown;
134
+ dateOption: "month" | "quarter" | "year" | "custom";
135
+ dateValue: unknown;
136
+ businessName?: string;
137
+ filters?: Record<string, unknown>;
138
+ }) => Promise<IncomeStatementReport>;
139
+ generalLedger: (params: {
140
+ organizationId?: unknown;
141
+ dateOption: "month" | "quarter" | "year" | "custom";
142
+ dateValue: unknown;
143
+ accountId?: string;
144
+ filters?: Record<string, unknown>;
145
+ }) => Promise<GeneralLedgerReport>;
146
+ cashFlow: (params: {
147
+ organizationId?: unknown;
148
+ dateOption: "month" | "quarter" | "year" | "custom";
149
+ dateValue: unknown;
150
+ businessName?: string;
151
+ filters?: Record<string, unknown>;
152
+ }) => Promise<CashFlowReport>;
153
+ agedBalance: (params: {
154
+ organizationId?: unknown;
155
+ asOfDate?: Date;
156
+ type: "receivable" | "payable";
157
+ accountIds?: unknown[];
158
+ dueDateField?: string;
159
+ contactField?: string;
160
+ buckets?: {
161
+ label: string;
162
+ minDays: number;
163
+ maxDays: number;
164
+ }[] | undefined;
165
+ }) => Promise<AgedBalanceReport>;
166
+ dimensionBreakdown: (params: {
167
+ organizationId?: unknown;
168
+ dateOption: "month" | "quarter" | "year" | "custom";
169
+ dateValue: unknown;
170
+ dimension: string;
171
+ accountCategory?: string;
172
+ filters?: Record<string, unknown>;
173
+ }) => Promise<DimensionBreakdownReport>;
174
+ budgetVsActual: (params: {
175
+ organizationId?: unknown;
176
+ dateOption: "month" | "quarter" | "year" | "custom";
177
+ dateValue: unknown;
178
+ accountIds?: unknown[];
179
+ filters?: Record<string, unknown>;
180
+ }) => Promise<BudgetVsActualReport>;
181
+ revaluation: (params: {
182
+ organizationId?: unknown;
183
+ asOfDate: Date;
184
+ rates: {
185
+ currency: string;
186
+ rate: number;
187
+ }[];
188
+ unrealizedGainLossAccountId: unknown;
189
+ generateEntry?: boolean;
190
+ }) => Promise<RevaluationReport>;
191
+ };
46
192
  createAccountSchema(options?: SchemaOptions): mongoose$1.Schema<any, Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
47
193
  timestamps: true;
48
194
  }, {
@@ -53,9 +199,9 @@ declare class AccountingEngine {
53
199
  [x: string]: any;
54
200
  } & mongoose$1.DefaultTimestampProps, {
55
201
  id: string;
56
- }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
202
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
57
203
  timestamps: true;
58
- }>> & Omit<{
204
+ }> & Omit<{
59
205
  [x: number]: any;
60
206
  [x: string]: any;
61
207
  } & mongoose$1.DefaultTimestampProps & {
@@ -84,9 +230,9 @@ declare class AccountingEngine {
84
230
  [x: string]: any;
85
231
  } & mongoose$1.DefaultTimestampProps, {
86
232
  id: string;
87
- }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
233
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
88
234
  timestamps: true;
89
- }>> & Omit<{
235
+ }> & Omit<{
90
236
  [x: number]: any;
91
237
  [x: string]: any;
92
238
  } & mongoose$1.DefaultTimestampProps & {
@@ -115,9 +261,9 @@ declare class AccountingEngine {
115
261
  [x: string]: any;
116
262
  } & mongoose$1.DefaultTimestampProps, {
117
263
  id: string;
118
- }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
264
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
119
265
  timestamps: true;
120
- }>> & Omit<{
266
+ }> & Omit<{
121
267
  [x: number]: any;
122
268
  [x: string]: any;
123
269
  } & mongoose$1.DefaultTimestampProps & {
@@ -146,9 +292,9 @@ declare class AccountingEngine {
146
292
  [x: string]: any;
147
293
  } & mongoose$1.DefaultTimestampProps, {
148
294
  id: string;
149
- }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
295
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
150
296
  timestamps: true;
151
- }>> & Omit<{
297
+ }> & Omit<{
152
298
  [x: number]: any;
153
299
  [x: string]: any;
154
300
  } & mongoose$1.DefaultTimestampProps & {
@@ -177,9 +323,9 @@ declare class AccountingEngine {
177
323
  [x: string]: any;
178
324
  } & mongoose$1.DefaultTimestampProps, {
179
325
  id: string;
180
- }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
326
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
181
327
  timestamps: true;
182
- }>> & Omit<{
328
+ }> & Omit<{
183
329
  [x: number]: any;
184
330
  [x: string]: any;
185
331
  } & mongoose$1.DefaultTimestampProps & {
@@ -198,6 +344,11 @@ declare class AccountingEngine {
198
344
  } & {
199
345
  __v: number;
200
346
  }>;
347
+ /**
348
+ * Build a reports object bound to the given models. Use this when you
349
+ * need custom/external models. Prefer `engine.reports` when the engine
350
+ * owns the models (via `mongoose` in config).
351
+ */
201
352
  createReports(models: {
202
353
  Account: Model<unknown>;
203
354
  JournalEntry: Model<unknown>;
@@ -277,6 +428,7 @@ declare class AccountingEngine {
277
428
  generateEntry?: boolean;
278
429
  }) => Promise<RevaluationReport>;
279
430
  };
431
+ private _buildReports;
280
432
  /** Get all posting account types (accounts you can post transactions to) */
281
433
  getPostingAccountTypes(): readonly AccountType[];
282
434
  /** Validate an account type code */
@@ -335,23 +487,7 @@ declare class AccountingEngine {
335
487
  */
336
488
  wireReconciliationRepository<TDoc = unknown>(repository: Repository<TDoc>, ReconciliationModel: Model<unknown>, JournalEntryModel: Model<unknown>): ReconciliationRepository<TDoc>;
337
489
  }
338
- declare function createAccountingEngine(config: AccountingEngineConfig): AccountingEngine;
339
- //#endregion
340
- //#region src/utils/date-range.d.ts
341
- /**
342
- * Compute start/end dates from a date option + value.
343
- *
344
- * @throws {Error} If value is null/undefined/invalid for the given option
345
- *
346
- * Examples:
347
- * getDateRange('month', '2025-03') → Mar 1 – Mar 31
348
- * getDateRange('quarter', { quarter: 2, year: 2025 }) → Apr 1 – Jun 30
349
- * getDateRange('year', 2025) → Jan 1 – Dec 31
350
- * getDateRange('custom', { startDate, endDate })
351
- */
352
- declare function getDateRange(option: DateOption, value: unknown): DateRange;
353
- /** Get fiscal year start date for a given date and fiscal start month */
354
- declare function getFiscalYearStart(date: Date, fiscalStartMonth?: number): Date;
490
+ declare function createAccountingEngine(config: AccountingEngineConfig, plugins?: LedgerRepositoryPlugins): AccountingEngine;
355
491
  //#endregion
356
492
  //#region src/utils/account-helpers.d.ts
357
493
  /**
@@ -379,60 +515,21 @@ declare function computeEndingBalance(category: CategoryKey, totalDebit: number,
379
515
  */
380
516
  declare function buildAccountTypeMap(accountTypes: readonly AccountType[]): Map<string, AccountType>;
381
517
  //#endregion
382
- //#region src/utils/errors.d.ts
383
- /**
384
- * Typed error for the accounting package.
385
- * Carries HTTP status + machine-readable code.
386
- * Replaces all ad-hoc `(error as ...).status = N` patterns.
387
- */
388
- declare class AccountingError extends Error {
389
- readonly status: number;
390
- readonly code: string;
391
- constructor(message: string, status?: number, code?: string);
392
- }
393
- /** Convenience factory functions */
394
- declare const Errors: {
395
- readonly validation: (msg: string) => AccountingError;
396
- readonly notFound: (msg: string) => AccountingError;
397
- readonly conflict: (msg: string) => AccountingError;
398
- readonly immutable: (msg: string) => AccountingError;
399
- readonly fiscal: (msg: string) => AccountingError;
400
- };
401
- //#endregion
402
- //#region src/utils/session.d.ts
403
- interface SessionResult {
404
- session: ClientSession | null;
405
- ownSession: boolean;
406
- }
407
- /**
408
- * Acquire a session: uses external if provided, otherwise creates an internal one.
409
- * Returns { session, ownSession } so callers can commit/abort/end appropriately.
410
- *
411
- * When transactions are unavailable (no replica set / standalone), returns
412
- * session=null and the function runs without transactional safety.
413
- */
414
- declare function acquireSession(db: Connection, externalSession: ClientSession | undefined | null, logger?: Logger): Promise<SessionResult>;
415
- /**
416
- * Finalize an owned session: commit or abort, then always end.
417
- */
418
- declare function finalizeSession(session: ClientSession | null, ownSession: boolean, success: boolean): Promise<void>;
419
- //#endregion
420
- //#region src/utils/filter-builder.d.ts
518
+ //#region src/utils/date-range.d.ts
421
519
  /**
422
- * Filter Builder Sanitizes user-supplied dimension filters for aggregation pipelines.
520
+ * Compute start/end dates from a date option + value.
423
521
  *
424
- * Prevents injection of dangerous MongoDB operators while allowing
425
- * standard equality and comparison filters on custom dimension fields.
426
- */
427
- /**
428
- * Build a sanitized filter object from user-supplied dimension filters.
429
- * Blocks dangerous operators ($where, $expr, $function, etc.).
522
+ * @throws {Error} If value is null/undefined/invalid for the given option
430
523
  *
431
- * @param filters - Key-value filters (e.g. { 'journalItems.departmentId': 'dept-1' })
432
- * @returns Sanitized filter object safe for $match stages
433
- * @throws Error if a blocked operator is used
524
+ * Examples:
525
+ * getDateRange('month', '2025-03') → Mar 1 Mar 31
526
+ * getDateRange('quarter', { quarter: 2, year: 2025 }) Apr 1 – Jun 30
527
+ * getDateRange('year', 2025) → Jan 1 – Dec 31
528
+ * getDateRange('custom', { startDate, endDate })
434
529
  */
435
- declare function buildItemFilters(filters?: Record<string, unknown>): Record<string, unknown>;
530
+ declare function getDateRange(option: DateOption, value: unknown): DateRange;
531
+ /** Get fiscal year start date for a given date and fiscal start month */
532
+ declare function getFiscalYearStart(date: Date, fiscalStartMonth?: number): Date;
436
533
  //#endregion
437
534
  //#region src/utils/dimensions.d.ts
438
535
  /**
@@ -483,6 +580,61 @@ declare function buildDimensionIndexes(dimensions: DimensionDefinition[], orgFie
483
580
  options?: Record<string, unknown>;
484
581
  }>;
485
582
  //#endregion
583
+ //#region src/utils/errors.d.ts
584
+ /**
585
+ * Typed error for the accounting package.
586
+ * Carries HTTP status + machine-readable code.
587
+ * Replaces all ad-hoc `(error as ...).status = N` patterns.
588
+ */
589
+ declare class AccountingError extends Error {
590
+ readonly status: number;
591
+ readonly code: string;
592
+ constructor(message: string, status?: number, code?: string);
593
+ }
594
+ /** Convenience factory functions */
595
+ declare const Errors: {
596
+ readonly validation: (msg: string) => AccountingError;
597
+ readonly notFound: (msg: string) => AccountingError;
598
+ readonly conflict: (msg: string) => AccountingError;
599
+ readonly immutable: (msg: string) => AccountingError;
600
+ readonly fiscal: (msg: string) => AccountingError;
601
+ };
602
+ //#endregion
603
+ //#region src/utils/filter-builder.d.ts
604
+ /**
605
+ * Filter Builder — Sanitizes user-supplied dimension filters for aggregation pipelines.
606
+ *
607
+ * Prevents injection of dangerous MongoDB operators while allowing
608
+ * standard equality and comparison filters on custom dimension fields.
609
+ */
610
+ /**
611
+ * Build a sanitized filter object from user-supplied dimension filters.
612
+ * Blocks dangerous operators ($where, $expr, $function, etc.).
613
+ *
614
+ * @param filters - Key-value filters (e.g. { 'journalItems.departmentId': 'dept-1' })
615
+ * @returns Sanitized filter object safe for $match stages
616
+ * @throws Error if a blocked operator is used
617
+ */
618
+ declare function buildItemFilters(filters?: Record<string, unknown>): Record<string, unknown>;
619
+ //#endregion
620
+ //#region src/utils/session.d.ts
621
+ interface SessionResult {
622
+ session: ClientSession | null;
623
+ ownSession: boolean;
624
+ }
625
+ /**
626
+ * Acquire a session: uses external if provided, otherwise creates an internal one.
627
+ * Returns { session, ownSession } so callers can commit/abort/end appropriately.
628
+ *
629
+ * When transactions are unavailable (no replica set / standalone), returns
630
+ * session=null and the function runs without transactional safety.
631
+ */
632
+ declare function acquireSession(db: Connection, externalSession: ClientSession | undefined | null, logger?: Logger): Promise<SessionResult>;
633
+ /**
634
+ * Finalize an owned session: commit or abort, then always end.
635
+ */
636
+ declare function finalizeSession(session: ClientSession | null, ownSession: boolean, success: boolean): Promise<void>;
637
+ //#endregion
486
638
  //#region src/types/contracts.d.ts
487
639
  /** A single line produced by a subledger for posting */
488
640
  interface SubledgerJournalItem {
@@ -527,4 +679,4 @@ interface PostingResult {
527
679
  idempotencyKeys?: string[];
528
680
  }
529
681
  //#endregion
530
- export { type AccountForeignBalance, type AccountRepository, type AccountType, AccountingEngine, type AccountingEngineConfig, AccountingError, type AgedBalanceOptions, type AgedBalanceParams, type AgedBalanceReport, type AgedBalanceRow, type AgedBucketConfig, type AuditConfig, type BalanceSheetReport, type BulkCreateInput, type BulkCreateResult, CATEGORIES, CATEGORY_KEYS, CURRENCIES, type CashFlowCategory, type CashFlowReport, type CashFlowSection, type CategoryKey, type Cents, type CountryPack, type CountryPackInput, type Currency, DEFAULT_BUCKETS, type DateOption, type DateRange, type DimensionBreakdownOptions, type DimensionBreakdownParams, type DimensionBreakdownReport, type DimensionBreakdownRow, type DimensionDefinition, type EntryState, Errors, type ExportField, type ExportFieldMap, type FlatJournalRow, type GeneralLedgerAccount, type GeneralLedgerReport, type IncomeStatementReport, JOURNAL_CODES, JOURNAL_TYPES, type JournalEntryRepository, type JournalItem, type JournalSchemaOptions, type JournalType, type LedgerEntry, type Logger, type MainType, Money, type MultiCurrencyConfig, type MultiTenantConfig, type NormalBalance, type PopulatedJournalEntry, type PostOptions, type PostingContract, type PostingResult, type ReconcileParams, type ReconciliationRepository, type ReportAccount, type ReportCategory, type ReportGroup, type RevaluationOptions, type RevaluationParams, type RevaluationRate, type RevaluationReport, type RevaluationResult, type ReverseOptions, type ReverseResult, type SchemaOptions, type SeedOptions, type SeedResult, type SessionResult, type StatementType, type StrictnessConfig, type SubledgerJournalItem, type SubledgerPostingInput, type TaxCode, type TaxCodesByRegion, type TaxDetail, type TaxMetadata, type TaxReport, type TaxReportLine, type TaxReportTemplate, type TaxReturnSummary, type TotalAccountOp, type TrialBalanceReport, type TrialBalanceRow, acquireSession, add, allocate, buildAccountTypeMap, buildDimensionFields, buildDimensionIndexes, buildItemFilters, buildRevaluationEntry, calculateTotal, closeFiscalPeriod, computeEndingBalance, computeRevaluation, createAccountSchema, createAccountingEngine, createFiscalPeriodSchema, createJournalEntrySchema, dateLockPlugin, defaultLogger, defineCountryPack, doubleEntryPlugin, exportToCsv, finalizeSession, fiscalLockPlugin, flattenJournalEntries, format, formatPlain, fromDecimal, generateAgedBalance, generateBalanceSheet, generateCashFlow, generateDimensionBreakdown, generateGeneralLedger, generateIncomeStatement, generateRevaluation, generateTrialBalance, getCurrency, getDateRange, getFiscalYearStart, getJournalTypeCodes, getMinorUnit, getNormalBalance, idempotencyPlugin, isBalanceSheet, isIncomeStatement, isValidCategory, isValidCurrency, isValidJournalType, isVirtualTaxAccount, multiply, parseCents, percentage, quickbooksFieldMap, reopenFiscalPeriod, splitTaxExclusive, splitTaxInclusive, subtract, toDecimal, universalFieldMap, wireAccountMethods, wireJournalEntryMethods, wireReconciliationMethods };
682
+ export { type AccountForeignBalance, type AccountRepository, type AccountType, AccountingEngine, type AccountingEngineConfig, AccountingError, type AgedBalanceOptions, type AgedBalanceParams, type AgedBalanceReport, type AgedBalanceRow, type AgedBucketConfig, type AuditConfig, type BalanceSheetReport, type BudgetVsActualOptions, type BudgetVsActualParams, type BudgetVsActualReport, type BudgetVsActualRow, type BulkCreateInput, type BulkCreateResult, CATEGORIES, CATEGORY_KEYS, CURRENCIES, type CashFlowCategory, type CashFlowReport, type CashFlowSection, type CategoryKey, type Cents, type CountryPack, type CountryPackInput, type Currency, DEFAULT_BUCKETS, type DateOption, type DateRange, type DimensionBreakdownOptions, type DimensionBreakdownParams, type DimensionBreakdownReport, type DimensionBreakdownRow, type DimensionDefinition, type EntryState, Errors, type ExportField, type ExportFieldMap, type FlatJournalRow, type GeneralLedgerAccount, type GeneralLedgerReport, type IncomeStatementReport, JOURNAL_CODES, JOURNAL_TYPES, type JournalEntryRepository, type JournalItem, type JournalSchemaOptions, type JournalType, type LedgerEntry, type LedgerModels, type LedgerRepositories, type LedgerRepositoryPlugins, type Logger, type MainType, type ModelNames, Money, type MultiCurrencyConfig, type MultiTenantConfig, type NormalBalance, type PopulatedJournalEntry, type PostOptions, type PostingContract, type PostingResult, type ReconcileParams, type ReconciliationRepository, type ReportAccount, type ReportCategory, type ReportGroup, type ResolvedModelNames, type RevaluationOptions, type RevaluationParams, type RevaluationRate, type RevaluationReport, type RevaluationResult, type ReverseOptions, type ReverseResult, type SchemaOptions, type SeedOptions, type SeedResult, type SessionResult, type StatementType, type StrictnessConfig, type SubledgerJournalItem, type SubledgerPostingInput, type TaxCode, type TaxCodesByRegion, type TaxDetail, type TaxMetadata, type TaxReport, type TaxReportLine, type TaxReportTemplate, type TaxReturnSummary, type TotalAccountOp, type TrialBalanceReport, type TrialBalanceRow, acquireSession, add, allocate, buildAccountTypeMap, buildDimensionFields, buildDimensionIndexes, buildItemFilters, buildRevaluationEntry, calculateTotal, closeFiscalPeriod, computeEndingBalance, computeRevaluation, createAccountSchema, createAccountingEngine, createFiscalPeriodSchema, createJournalEntrySchema, createModels, createRepositories, dateLockPlugin, defaultLogger, defineCountryPack, doubleEntryPlugin, exportToCsv, finalizeSession, fiscalLockPlugin, flattenJournalEntries, format, formatPlain, fromDecimal, generateAgedBalance, generateBalanceSheet, generateBudgetVsActual, generateCashFlow, generateDimensionBreakdown, generateGeneralLedger, generateIncomeStatement, generateRevaluation, generateTrialBalance, getCurrency, getCustomJournalTypes, getDateRange, getFiscalYearStart, getJournalType, getJournalTypeCodes, getMinorUnit, getNormalBalance, idempotencyPlugin, isBalanceSheet, isIncomeStatement, isValidCategory, isValidCurrency, isValidJournalType, isVirtualTaxAccount, multiply, parseCents, percentage, quickbooksFieldMap, registerJournalType, reopenFiscalPeriod, resolveModelNames, splitTaxExclusive, splitTaxInclusive, subtract, toDecimal, universalFieldMap, wireAccountMethods, wireJournalEntryMethods, wireReconciliationMethods };