@fin.cx/skr
Version:
SKR03 and SKR04 German accounting standards for double-entry bookkeeping
141 lines (140 loc) • 3.46 kB
TypeScript
import type { IInvoice, IInvoiceFilter, IDuplicateCheckResult } from './skr.invoice.entity.js';
/**
* Invoice storage metadata
*/
export interface IInvoiceMetadata {
invoiceId: string;
invoiceNumber: string;
direction: 'inbound' | 'outbound';
issueDate: string;
supplierName: string;
customerName: string;
totalAmount: number;
currency: string;
contentHash: string;
pdfHash?: string;
xmlHash: string;
journalEntryId?: string;
transactionIds?: string[];
validationResult: {
isValid: boolean;
errors: number;
warnings: number;
};
parserVersion: string;
storedAt: string;
storedBy: string;
}
/**
* Invoice registry entry (for NDJSON streaming)
*/
export interface IInvoiceRegistryEntry {
id: string;
hash: string;
metadata: IInvoiceMetadata;
}
/**
* Storage statistics
*/
export interface IStorageStats {
totalInvoices: number;
inboundCount: number;
outboundCount: number;
totalSize: number;
duplicatesDetected: number;
lastUpdate: Date;
}
/**
* Content-addressed storage for invoices
* Integrates with BagIt archive structure for GoBD compliance
*/
export declare class InvoiceStorage {
private exportPath;
private logger;
private registryPath;
private metadataCache;
private readonly MAX_CACHE_SIZE;
private cacheAccessOrder;
constructor(exportPath: string);
/**
* Manage cache size using LRU eviction
*/
private manageCacheSize;
/**
* Update cache access order for LRU
*/
private touchCacheEntry;
/**
* Initialize storage directories
*/
initialize(): Promise<void>;
private readonly MAX_PDF_SIZE;
/**
* Store an invoice with content addressing
*/
storeInvoice(invoice: IInvoice, pdfBuffer?: Buffer): Promise<string>;
/**
* Retrieve an invoice by content hash
*/
retrieveInvoice(contentHash: string): Promise<IInvoice | null>;
/**
* Check for duplicate invoices
*/
checkDuplicate(invoice: IInvoice, contentHash: string): Promise<IDuplicateCheckResult>;
/**
* Search invoices by filter
*/
searchInvoices(filter: IInvoiceFilter): Promise<IInvoiceMetadata[]>;
/**
* Get storage statistics
*/
getStatistics(): Promise<IStorageStats>;
/**
* Create EN16931 compliance report
*/
createComplianceReport(): Promise<void>;
/**
* Load registry from disk
*/
private loadRegistry;
/**
* Update registry with new entry
*/
private updateRegistry;
/**
* Find invoice file by hash and extension
*/
private findInvoiceFile;
/**
* Calculate SHA-256 hash
*/
private calculateHash;
/**
* Check if metadata matches filter
*/
private matchesFilter;
/**
* Count errors in validation result
*/
private countErrors;
/**
* Count warnings in validation result
*/
private countWarnings;
/**
* Clean up old invoices (for testing only)
*/
cleanup(olderThanDays?: number): Promise<number>;
/**
* Set cache entry with LRU eviction
*/
private setCacheEntry;
/**
* Get cache entry and update access order
*/
private getCacheEntry;
/**
* Update metadata in storage and cache
*/
updateMetadata(contentHash: string, updates: Partial<IInvoiceMetadata>): Promise<void>;
}