feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -3,6 +3,14 @@ import type { TInvoice, TCreditNote, TDebitNote } from '../../interfaces/common.
|
||||
import { CII_NAMESPACES, CIIProfile } from './cii.types.js';
|
||||
import { DOMParser, xpath } from '../../plugins.js';
|
||||
|
||||
const ciiParser = new DOMParser();
|
||||
const ciiNamespaces = {
|
||||
rsm: CII_NAMESPACES.RSM,
|
||||
ram: CII_NAMESPACES.RAM,
|
||||
udt: CII_NAMESPACES.UDT,
|
||||
};
|
||||
const ciiSelect = xpath.useNamespaces(ciiNamespaces);
|
||||
|
||||
/**
|
||||
* Base decoder for CII-based invoice formats
|
||||
*/
|
||||
@@ -16,22 +24,22 @@ export abstract class CIIBaseDecoder extends BaseDecoder {
|
||||
super(xml, skipValidation);
|
||||
|
||||
// Parse XML document
|
||||
this.doc = new DOMParser().parseFromString(xml, 'application/xml');
|
||||
this.doc = ciiParser.parseFromString(xml, 'application/xml');
|
||||
|
||||
// Set up namespaces for XPath queries
|
||||
this.namespaces = {
|
||||
rsm: CII_NAMESPACES.RSM,
|
||||
ram: CII_NAMESPACES.RAM,
|
||||
udt: CII_NAMESPACES.UDT
|
||||
};
|
||||
this.namespaces = ciiNamespaces;
|
||||
|
||||
// Create XPath selector with namespaces
|
||||
this.select = xpath.useNamespaces(this.namespaces);
|
||||
this.select = ciiSelect;
|
||||
|
||||
// Detect profile
|
||||
this.detectProfile();
|
||||
}
|
||||
|
||||
public override getParsedDocument(): Document {
|
||||
return this.doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes CII XML into a TInvoice object
|
||||
* @returns Promise resolving to a TInvoice object
|
||||
@@ -93,7 +101,8 @@ export abstract class CIIBaseDecoder extends BaseDecoder {
|
||||
* @returns Text value or empty string if not found
|
||||
*/
|
||||
protected getText(xpathExpr: string, context?: Node): string {
|
||||
const node = this.select(xpathExpr, context || this.doc)[0];
|
||||
const result = this.select(xpathExpr, context || this.doc);
|
||||
const node = Array.isArray(result) ? result[0] : null;
|
||||
return node ? (node.textContent || '') : '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user