fix(exports): stabilize published types and compatibility with updated dependencies

This commit is contained in:
2026-04-16 19:41:55 +00:00
parent cb6b3db15a
commit 40ffc2b355
25 changed files with 4539 additions and 5354 deletions
+31 -11
View File
@@ -18,11 +18,25 @@ import type {
*/
export class InvoiceAdapter {
private logger: plugins.smartlog.ConsoleLog;
private readonly einvoiceModuleName = '@fin.cx/einvoice';
constructor() {
this.logger = new plugins.smartlog.ConsoleLog();
}
private async getEInvoiceClass(): Promise<{
new (): any;
fromXml(xmlString: string): Promise<any>;
}> {
const { EInvoice } = (await import(this.einvoiceModuleName)) as {
EInvoice: {
new (): any;
fromXml(xmlString: string): Promise<any>;
};
};
return EInvoice;
}
private readonly MAX_XML_SIZE = 10 * 1024 * 1024; // 10MB max
private readonly MAX_PDF_SIZE = 50 * 1024 * 1024; // 50MB max
@@ -44,13 +58,14 @@ export class InvoiceAdapter {
}
// Parse the invoice using @fin.cx/einvoice
let einvoice;
const EInvoice = await this.getEInvoiceClass();
let einvoice: any;
if (typeof file === 'string') {
einvoice = await plugins.einvoice.EInvoice.fromXml(file);
einvoice = await EInvoice.fromXml(file);
} else {
// Convert buffer to string first
const xmlString = file.toString('utf-8');
einvoice = await plugins.einvoice.EInvoice.fromXml(xmlString);
einvoice = await EInvoice.fromXml(xmlString);
}
// Get detected format
@@ -74,7 +89,7 @@ export class InvoiceAdapter {
invoice.xmlContent = einvoice.getXml();
// Calculate content hash
invoice.contentHash = await this.calculateContentHash(invoice.xmlContent);
invoice.contentHash = await this.calculateContentHash(invoice.xmlContent!);
// Classify tax scenario
invoice.taxScenario = this.classifyTaxScenario(invoice);
@@ -82,7 +97,8 @@ export class InvoiceAdapter {
return invoice;
} catch (error) {
this.logger.log('error', `Failed to parse invoice: ${error}`);
throw new Error(`Invoice parsing failed: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Invoice parsing failed: ${errorMessage}`);
}
}
@@ -310,7 +326,7 @@ export class InvoiceAdapter {
* Get exemption reason for VAT category
*/
private getExemptionReason(categoryCode: string): string | undefined {
const exemptionReasons: Record<string, string> = {
const exemptionReasons: Record<string, string | undefined> = {
'E': 'Tax exempt',
'Z': 'Zero rated',
'AE': 'Reverse charge (§13b UStG)',
@@ -516,7 +532,8 @@ export class InvoiceAdapter {
): Promise<string> {
try {
// Load from existing XML
const einvoice = await plugins.einvoice.EInvoice.fromXml(invoice.xmlContent!);
const EInvoice = await this.getEInvoiceClass();
const einvoice: any = await EInvoice.fromXml(invoice.xmlContent!);
// Convert to target format (takes ~0.6ms)
const convertedXml = await einvoice.exportXml(targetFormat as any);
@@ -524,7 +541,8 @@ export class InvoiceAdapter {
return convertedXml;
} catch (error) {
this.logger.log('error', `Failed to convert invoice format: ${error}`);
throw new Error(`Format conversion failed: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Format conversion failed: ${errorMessage}`);
}
}
@@ -537,7 +555,8 @@ export class InvoiceAdapter {
): Promise<{ xml: string; pdf?: Buffer }> {
try {
// Create a new invoice instance
const einvoice = new plugins.einvoice.EInvoice();
const EInvoice = await this.getEInvoiceClass();
const einvoice: any = new EInvoice();
// Set invoice data
const businessTerms = this.mapToBusinessTerms(invoiceData);
@@ -558,7 +577,8 @@ export class InvoiceAdapter {
return { xml, pdf };
} catch (error) {
this.logger.log('error', `Failed to generate invoice: ${error}`);
throw new Error(`Invoice generation failed: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Invoice generation failed: ${errorMessage}`);
}
}
@@ -578,4 +598,4 @@ export class InvoiceAdapter {
// This would be a comprehensive mapping in production
};
}
}
}