@moatless/bookkeeping-types 0.2.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.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Error information from a failed deletion attempt
3
+ */
4
+ export interface DeletionError {
5
+ /** When the deletion was attempted */
6
+ attemptedAt: string;
7
+ /** HTTP status code from the API */
8
+ statusCode?: number;
9
+ /** Error code from the integration (e.g., Fortnox error code) */
10
+ errorCode?: number | string;
11
+ /** Human-readable error message */
12
+ message: string;
13
+ }
14
+ /**
15
+ * Represents a discarded inbox item that should be removed from the source integration.
16
+ * Stored in inbox/discarded.json in the organization's storage.
17
+ */
18
+ export interface DiscardedItem {
19
+ /** Directory name in the inbox folder */
20
+ dir: string;
21
+ /** ID of the item in the source integration (e.g., Fortnox file ID) */
22
+ sourceId: string;
23
+ /** Which integration the item came from */
24
+ sourceIntegration: "fortnox" | "bokio" | "ledgit";
25
+ /** Error from the last failed deletion attempt (if any) */
26
+ lastDeletionError?: DeletionError;
27
+ /** Number of failed deletion attempts */
28
+ deletionAttempts?: number;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Exported document format - optimized for Git-based workflow
3
+ * Using camelCase for TypeScript compatibility
4
+ *
5
+ * This format is designed for human-readable YAML exports stored in Git repositories.
6
+ * It removes database-specific metadata (UUIDs, timestamps, sync data) and focuses
7
+ * on the document content and parsed data. Git provides version history and timestamps.
8
+ */
9
+ /**
10
+ * Monetary amount with currency
11
+ * Amount is stored as a string to preserve precision
12
+ */
13
+ export interface DocumentMoneyAmount {
14
+ amount: string;
15
+ currency: string;
16
+ }
17
+ /**
18
+ * Tax detail line item
19
+ */
20
+ export interface TaxDetail {
21
+ rate: number;
22
+ amount: string;
23
+ description?: string;
24
+ }
25
+ /**
26
+ * Document kind/type
27
+ */
28
+ export type DocumentKind = "RECEIPT" | "SUPPLIER_INVOICE" | "CUSTOMER_INVOICE" | "TRAKTAMENTE" | "EMAIL" | "OTHER";
29
+ /**
30
+ * Document status in workflow
31
+ */
32
+ export type DocumentStatus = "DRAFT" | "REVIEWED" | "READY_TO_EXPORT" | "EXPORTED" | "ERROR" | "DISCARDED" | "POSTED";
33
+ /**
34
+ * Complete exported document with parsed data
35
+ *
36
+ * Git-based workflow assumptions:
37
+ * - Creation/update timestamps: Use git log
38
+ * - Author information: Use git commit author
39
+ * - File location: Same directory as YAML file
40
+ * - Organization context: Repository structure
41
+ */
42
+ export interface Document {
43
+ kind: DocumentKind;
44
+ status: DocumentStatus;
45
+ fileName: string;
46
+ mimeType: string;
47
+ documentDate?: string;
48
+ documentNumber?: string;
49
+ description?: string;
50
+ counterparty?: string;
51
+ totalAmount?: DocumentMoneyAmount;
52
+ totalTaxAmount?: DocumentMoneyAmount;
53
+ subTotal?: DocumentMoneyAmount;
54
+ taxDetails?: TaxDetail[];
55
+ dueDate?: string;
56
+ currencyRate?: number;
57
+ vendorTaxId?: string;
58
+ interpretationError?: string;
59
+ sourceIntegration?: "fortnox" | "bokio" | "ledgit";
60
+ sourceId?: string;
61
+ uploadedAt?: string;
62
+ interpretedAt?: string;
63
+ senderEmail?: string;
64
+ senderName?: string;
65
+ emailSubject?: string;
66
+ }
67
+ /**
68
+ * Type alias for backward compatibility
69
+ */
70
+ export type InboxDocument = Document;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Exported document format - optimized for Git-based workflow
3
+ * Using camelCase for TypeScript compatibility
4
+ *
5
+ * This format is designed for human-readable YAML exports stored in Git repositories.
6
+ * It removes database-specific metadata (UUIDs, timestamps, sync data) and focuses
7
+ * on the document content and parsed data. Git provides version history and timestamps.
8
+ */
9
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Exported fiscal year structure for Git storage (YAML format)
3
+ */
4
+ export interface FiscalYear {
5
+ name: string;
6
+ startDate: string;
7
+ endDate: string;
8
+ status: "OPEN" | "CLOSED";
9
+ externalId?: string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from "./journal-entry";
2
+ export * from "./document";
3
+ export * from "./fiscal-year";
4
+ export * from "./ledger-account";
5
+ export * from "./discarded-item";
6
+ export * from "./sync";
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // Journal entry types (used across Git YAML, API, and client)
2
+ export * from "./journal-entry";
3
+ // Document types
4
+ export * from "./document";
5
+ // Fiscal year
6
+ export * from "./fiscal-year";
7
+ // Ledger account
8
+ export * from "./ledger-account";
9
+ // Discarded items
10
+ export * from "./discarded-item";
11
+ // Sync types
12
+ export * from "./sync";
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Unified Journal Entry types
3
+ *
4
+ * These types are used throughout the stack:
5
+ * - Git YAML storage (entry.yaml files)
6
+ * - Server API responses
7
+ * - Client state
8
+ *
9
+ * All monetary amounts use NUMBER type (not strings).
10
+ * All field names use camelCase.
11
+ */
12
+ /**
13
+ * Monetary amount with currency
14
+ */
15
+ export interface MoneyAmount {
16
+ amount: number;
17
+ currency: string;
18
+ originalAmount?: number;
19
+ originalCurrency?: string;
20
+ }
21
+ /**
22
+ * Single line in a journal entry
23
+ */
24
+ export interface JournalLine {
25
+ lineNumber: number;
26
+ account: string;
27
+ debit: MoneyAmount;
28
+ credit: MoneyAmount;
29
+ memo?: string;
30
+ taxCode?: string;
31
+ costCenter?: string;
32
+ /** Populated by API when account details are available */
33
+ ledgerAccountName?: string;
34
+ }
35
+ /**
36
+ * Journal entry series
37
+ * Different series are used for different transaction types:
38
+ * - A: General/miscellaneous transactions
39
+ * - B: Customer invoices (sales)
40
+ * - C: Customer payments (collections)
41
+ * - D: Supplier invoices (purchases)
42
+ * - E: Supplier payments (disbursements)
43
+ * - I: Period-end accruals and adjustments
44
+ * - M: Monthly/quarterly tax reporting
45
+ */
46
+ export type JournalEntrySeries = "A" | "B" | "C" | "D" | "E" | "I" | "M";
47
+ /**
48
+ * Journal entry status
49
+ */
50
+ export type JournalEntryStatus = "DRAFT" | "POSTED";
51
+ /**
52
+ * Complete journal entry
53
+ */
54
+ export interface JournalEntry {
55
+ /** Populated by API (derived from directory name), not stored in YAML */
56
+ id?: string;
57
+ series?: JournalEntrySeries;
58
+ entryNumber: number;
59
+ entryDate: string;
60
+ description: string;
61
+ status: JournalEntryStatus;
62
+ currency: string;
63
+ externalId?: string;
64
+ totalDebit: MoneyAmount;
65
+ totalCredit: MoneyAmount;
66
+ lines: JournalLine[];
67
+ postedAt?: string;
68
+ errorMessage?: string;
69
+ postingCheckpoint?: string;
70
+ voucherNumber?: number;
71
+ voucherSeriesCode?: string;
72
+ fortnoxFileId?: string;
73
+ sourceIntegration?: "fortnox" | "bokio" | "ledgit";
74
+ sourceSyncedAt?: string;
75
+ /** If this entry is a reversal, the external ID of the entry it reverses */
76
+ reversingEntryExternalId?: string;
77
+ /** If this entry was reversed/cancelled, the external ID of the reversing entry */
78
+ reversedByEntryExternalId?: string;
79
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Unified Journal Entry types
3
+ *
4
+ * These types are used throughout the stack:
5
+ * - Git YAML storage (entry.yaml files)
6
+ * - Server API responses
7
+ * - Client state
8
+ *
9
+ * All monetary amounts use NUMBER type (not strings).
10
+ * All field names use camelCase.
11
+ */
12
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Ledger account (chart of accounts entry)
3
+ */
4
+ export interface LedgerAccount {
5
+ code: string;
6
+ name: string;
7
+ description?: string;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/sync.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Result stats for sync operations
3
+ */
4
+ export interface SyncStats {
5
+ fetched: number;
6
+ written: number;
7
+ skipped: number;
8
+ errors: number;
9
+ }
10
+ /**
11
+ * Stats per fiscal year (more detailed)
12
+ */
13
+ export interface FiscalYearStats {
14
+ year: number;
15
+ fetched: number;
16
+ created: number;
17
+ updated: number;
18
+ unchanged: number;
19
+ failed: number;
20
+ }
21
+ /**
22
+ * Error entry for tracking issues
23
+ */
24
+ export interface SyncError {
25
+ year: number;
26
+ externalId: string;
27
+ message: string;
28
+ }
29
+ /**
30
+ * Complete sync result
31
+ */
32
+ export interface SyncJournalResult {
33
+ success: boolean;
34
+ fiscalYears: FiscalYearStats[];
35
+ totals: {
36
+ fetched: number;
37
+ created: number;
38
+ updated: number;
39
+ unchanged: number;
40
+ failed: number;
41
+ };
42
+ errors: SyncError[];
43
+ durationMs: number;
44
+ }
45
+ /**
46
+ * Fiscal year info for sync operations
47
+ */
48
+ export interface FiscalYearInfo {
49
+ /** External ID from provider (used for API calls) */
50
+ externalId: number;
51
+ /** Calendar year (used for file paths) */
52
+ year: number;
53
+ }
54
+ /**
55
+ * Fiscal year with dates (from database)
56
+ */
57
+ export interface FiscalYearWithDates {
58
+ name: string | null;
59
+ start_date: string;
60
+ end_date: string;
61
+ }
62
+ /**
63
+ * Progress update during sync operations
64
+ */
65
+ export interface SyncProgress {
66
+ current: number;
67
+ total: number;
68
+ message?: string;
69
+ phase?: "discovering" | "fetching";
70
+ }
71
+ /**
72
+ * Summary info for a fiscal year (used in sync selection)
73
+ */
74
+ export interface FiscalYearSummary {
75
+ id: number;
76
+ year: number;
77
+ fromDate: string;
78
+ toDate: string;
79
+ entryCount: number;
80
+ }
package/dist/sync.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@moatless/bookkeeping-types",
3
+ "version": "0.2.0",
4
+ "description": "Type definitions for Swedish bookkeeping domain models",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "dev": "tsc --watch",
14
+ "type-check": "tsc --noEmit"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^5.8.3"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ }
22
+ }