BREAKING CHANGE(XInvoice): Refactor XInvoice API for XML handling and PDF export by replacing deprecated methods (addXmlString and getParsedXmlData) with fromXml and loadXml, and by introducing a new ExportFormat type for type-safe export. Update tests accordingly.

This commit is contained in:
2025-03-20 14:39:32 +00:00
parent d954fb4768
commit 9510d851af
10 changed files with 174 additions and 72 deletions

View File

@ -400,8 +400,8 @@ export class XInvoice implements plugins.tsclass.business.ILetter {
* @param format Target format (e.g., 'facturx', 'xrechnung')
* @returns XML string in the specified format
*/
public async exportXml(format: string = 'facturx'): Promise<string> {
format = format.toLowerCase();
public async exportXml(format: interfaces.ExportFormat = 'facturx'): Promise<string> {
format = format.toLowerCase() as interfaces.ExportFormat;
// Generate XML based on format
switch (format) {
@ -421,11 +421,11 @@ export class XInvoice implements plugins.tsclass.business.ILetter {
/**
* Exports the invoice to PDF format with embedded XML
* @param format Target format (e.g., 'facturx', 'zugferd')
* @returns PDF buffer with embedded XML
* @param format Target format (e.g., 'facturx', 'zugferd', 'xrechnung', 'ubl')
* @returns PDF object with embedded XML
*/
public async exportPdf(format: string = 'facturx'): Promise<Uint8Array> {
format = format.toLowerCase();
public async exportPdf(format: interfaces.ExportFormat = 'facturx'): Promise<plugins.tsclass.business.IPdf> {
format = format.toLowerCase() as interfaces.ExportFormat;
if (!this.pdf) {
throw new Error('No PDF data available. Use loadPdf() first or set the pdf property.');
@ -484,7 +484,7 @@ export class XInvoice implements plugins.tsclass.business.ILetter {
buffer: modifiedPdfBytes
};
return modifiedPdfBytes;
return this.pdf;
} catch (error) {
console.error('Error embedding XML into PDF:', error);
throw error;