@fin.cx/einvoice
Version:
A TypeScript module for creating, manipulating, and embedding XML data within PDF files specifically tailored for electronic invoice (einvoice) packages.
137 lines (136 loc) • 4.55 kB
TypeScript
import { business, finance } from './plugins.js';
import { InvoiceFormat, ValidationLevel } from './interfaces/common.js';
import type { ValidationResult, ValidationError, XInvoiceOptions, IPdf, ExportFormat } from './interfaces/common.js';
/**
* Main class for working with electronic invoices.
* Supports various invoice formats including Factur-X, ZUGFeRD, UBL, and XRechnung
* Implements TInvoice interface for seamless integration with existing systems
*/
export declare class XInvoice {
id: string;
invoiceId: string;
invoiceType: 'creditnote' | 'debitnote';
versionInfo: business.TDocumentEnvelope<string, any>['versionInfo'];
type: 'invoice';
date: number;
status: 'draft' | 'invoice' | 'paid' | 'refunded';
subject: string;
from: business.TContact;
to: business.TContact;
incidenceId: string;
language: string;
legalContact?: business.TContact;
objectActions: any[];
pdf: IPdf | null;
pdfAttachments: IPdf[] | null;
accentColor: string | null;
logoUrl: string | null;
items: finance.TInvoiceItem[];
dueInDays: number;
reverseCharge: boolean;
currency: finance.TCurrency;
notes: string[];
periodOfPerformance?: {
from: number;
to: number;
};
deliveryDate?: number;
buyerReference?: string;
electronicAddress?: {
scheme: string;
value: string;
};
paymentOptions?: finance.IPaymentOptionInfo;
private xmlString;
private detectedFormat;
private validationErrors;
private options;
private pdfEmbedder;
private pdfExtractor;
/**
* Creates a new XInvoice instance
* @param options Configuration options
*/
constructor(options?: XInvoiceOptions);
/**
* Creates an empty TContact object
*/
private createEmptyContact;
/**
* Creates a new XInvoice instance from XML
* @param xmlString XML content
* @param options Configuration options
* @returns XInvoice instance
*/
static fromXml(xmlString: string, options?: XInvoiceOptions): Promise<XInvoice>;
/**
* Creates a new XInvoice instance from PDF
* @param pdfBuffer PDF buffer
* @param options Configuration options
* @returns XInvoice instance
*/
static fromPdf(pdfBuffer: Uint8Array | Buffer, options?: XInvoiceOptions): Promise<XInvoice>;
/**
* Loads XML data into the XInvoice instance
* @param xmlString XML content
* @param validate Whether to validate the XML
* @returns This instance for chaining
*/
loadXml(xmlString: string, validate?: boolean): Promise<XInvoice>;
/**
* Loads PDF data into the XInvoice instance
* @param pdfBuffer PDF buffer
* @param validate Whether to validate the extracted XML
* @returns This instance for chaining
*/
loadPdf(pdfBuffer: Uint8Array | Buffer, validate?: boolean): Promise<XInvoice>;
/**
* Copies data from a TInvoice object
* @param invoice Source invoice data
*/
private copyInvoiceData;
/**
* Validates the XML against the appropriate format rules
* @param level Validation level (syntax, semantic, business)
* @returns Validation result
*/
validate(level?: ValidationLevel): Promise<ValidationResult>;
/**
* Checks if the invoice is valid
* @returns True if no validation errors were found
*/
isValid(): boolean;
/**
* Gets validation errors from the last validation
* @returns Array of validation errors
*/
getValidationErrors(): ValidationError[];
/**
* Exports the invoice as XML in the specified format
* @param format Target format (e.g., 'facturx', 'xrechnung')
* @returns XML string in the specified format
*/
exportXml(format?: ExportFormat): Promise<string>;
/**
* Exports the invoice as a PDF with embedded XML
* @param format Target format (e.g., 'facturx', 'zugferd', 'xrechnung', 'ubl')
* @returns PDF object with embedded XML
*/
exportPdf(format?: ExportFormat): Promise<IPdf>;
/**
* Gets the raw XML content
* @returns XML string
*/
getXml(): string;
/**
* Gets the invoice format as an enum value
* @returns InvoiceFormat enum value
*/
getFormat(): InvoiceFormat;
/**
* Checks if the invoice is in the specified format
* @param format Format to check
* @returns True if the invoice is in the specified format
*/
isFormat(format: InvoiceFormat): boolean;
}