@tokensapi/dsh-finance 0.1.0-beta.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.
@@ -0,0 +1,67 @@
1
+ import { z } from 'zod';
2
+ import { type FinanceState } from './contract.ts';
3
+ export declare const FINANCE_STATE_KEY = "primary";
4
+ export declare const financeDomainSpec: {
5
+ name: string;
6
+ version: number;
7
+ tables: {
8
+ state: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, Readonly<{
9
+ format: "tokens-cowork-finance-state";
10
+ version: 1;
11
+ revision: number;
12
+ companies: Readonly<{
13
+ id: string;
14
+ name: string;
15
+ baseCurrency: string;
16
+ currencyExponent: number;
17
+ openingDate: string;
18
+ openingLocked: boolean;
19
+ retainedEarningsAccountId: string;
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }>[];
23
+ accounts: Readonly<{
24
+ id: string;
25
+ companyId: string;
26
+ code: string;
27
+ name: string;
28
+ category: "asset" | "liability" | "equity" | "income" | "expense";
29
+ reportItem: string;
30
+ openingBalanceMinor: string;
31
+ isContra: boolean;
32
+ isActive: boolean;
33
+ createdAt: string;
34
+ updatedAt: string;
35
+ }>[];
36
+ batches: Readonly<{
37
+ id: string;
38
+ companyId: string;
39
+ fundingAccountId: string;
40
+ sourceType: "csv" | "xlsx" | "paste" | "sample";
41
+ sourceFileName: string | null;
42
+ importedAt: string;
43
+ status: "draft" | "approved";
44
+ approvedAt: string | null;
45
+ createdAt: string;
46
+ updatedAt: string;
47
+ }>[];
48
+ transactions: Readonly<{
49
+ id: string;
50
+ companyId: string;
51
+ batchId: string;
52
+ date: string;
53
+ amountMinor: string;
54
+ businessAccountId: string;
55
+ description: string;
56
+ counterparty: string;
57
+ sourceRowNumber: number | null;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ }>[];
61
+ createdAt: string;
62
+ updatedAt: string;
63
+ }>>;
64
+ };
65
+ };
66
+ export declare function createEmptyFinanceState(now?: string): FinanceState;
67
+ export declare const financeStateKeySchema: z.ZodLiteral<"primary">;
@@ -0,0 +1,10 @@
1
+ import { type BackupEnvelope, type BackupPreview, type FinanceState } from '../contract.ts';
2
+ export declare const MAX_BACKUP_FILE_BYTES: number;
3
+ export declare class BackupValidationError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ export declare function validateBackup(backup: BackupEnvelope): BackupEnvelope;
7
+ export declare function parseBackupContent(content: string): BackupEnvelope;
8
+ export declare function exportBackupData(state: FinanceState, exportedAt?: string): BackupEnvelope;
9
+ export declare function previewBackupData(content: string): BackupPreview;
10
+ export declare function stateFromBackup(current: FinanceState, backup: BackupEnvelope, now: string): FinanceState;
@@ -0,0 +1,2 @@
1
+ export declare function isIsoDate(value: string): boolean;
2
+ export declare function requireIsoDate(value: string): string;
@@ -0,0 +1,18 @@
1
+ import type { AccountCategory } from './types.ts';
2
+ export interface DefaultAccountTemplate {
3
+ code: string;
4
+ name: string;
5
+ category: AccountCategory;
6
+ reportItem: string;
7
+ isContra?: boolean;
8
+ retainedEarnings?: boolean;
9
+ }
10
+ export declare const REPORT_ITEMS_BY_CATEGORY: {
11
+ readonly asset: readonly ["cash", "bank", "accounts_receivable", "inventory", "fixed_assets", "accumulated_depreciation"];
12
+ readonly liability: readonly ["short_term_loans", "accounts_payable", "payroll_payable", "taxes_payable", "other_payables"];
13
+ readonly equity: readonly ["paid_in_capital", "current_year_profit", "retained_earnings"];
14
+ readonly income: readonly ["main_revenue", "other_revenue", "non_operating_income"];
15
+ readonly expense: readonly ["main_cost", "other_cost", "selling_expense", "administrative_expense", "financial_expense", "non_operating_expense", "income_tax_expense"];
16
+ };
17
+ export declare const DEFAULT_ACCOUNTS: readonly DefaultAccountTemplate[];
18
+ export declare function isReportItemCompatible(category: AccountCategory, reportItem: string): boolean;
@@ -0,0 +1,10 @@
1
+ import type { Account, Company, ImportPreview, PreviewImportInput } from '../contract.ts';
2
+ export declare const MAX_IMPORT_FILE_BYTES: number;
3
+ export declare const MAX_IMPORT_ROWS = 20000;
4
+ export declare class ImportParseError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare function parseDelimitedText(source: string): string[][];
8
+ export declare function normalizeImportDate(value: string): string | null;
9
+ export declare function decimalToMinor(value: string, exponent: number): string | null;
10
+ export declare function previewImportData(revision: number, company: Company, accounts: readonly Account[], input: PreviewImportInput): ImportPreview;
@@ -0,0 +1,3 @@
1
+ export declare function parseMinor(value: string): bigint;
2
+ export declare function normalizeMinor(value: string): string;
3
+ export declare function isZeroMinor(value: string): boolean;
@@ -0,0 +1,12 @@
1
+ import type { z } from 'zod';
2
+ import type { accountSchema } from '../contract.ts';
3
+ export interface OpeningSummary {
4
+ assetsMinor: string;
5
+ liabilitiesMinor: string;
6
+ equityMinor: string;
7
+ differenceMinor: string;
8
+ balanced: boolean;
9
+ }
10
+ type Account = z.infer<typeof accountSchema>;
11
+ export declare function calculateOpeningSummary(accounts: readonly Account[]): OpeningSummary;
12
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { FinanceReports, FinanceState, ImportBatch, Transaction } from '../contract.ts';
2
+ export declare class ReportCalculationError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export interface PostingLine {
6
+ accountId: string;
7
+ debitMinor: bigint;
8
+ creditMinor: bigint;
9
+ }
10
+ export declare function createPostingLines(transaction: Transaction, batch: ImportBatch): [PostingLine, PostingLine];
11
+ export declare function calculateFinanceReports(state: FinanceState, companyId: string, startDate: string, endDate: string): FinanceReports;