feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -27,11 +27,11 @@ export class EN16931Validator {
|
||||
];
|
||||
|
||||
/**
|
||||
* Validates that an invoice object contains all mandatory EN16931 fields
|
||||
* Collects mandatory EN16931 field errors without throwing.
|
||||
* @param invoice The invoice object to validate
|
||||
* @throws Error if mandatory fields are missing
|
||||
* @returns List of validation error messages
|
||||
*/
|
||||
public static validateMandatoryFields(invoice: any): void {
|
||||
public static collectMandatoryFieldErrors(invoice: any): string[] {
|
||||
const errors: string[] = [];
|
||||
|
||||
// BR-01: Invoice number is mandatory
|
||||
@@ -49,7 +49,7 @@ export class EN16931Validator {
|
||||
errors.push('BR-06: Seller name is mandatory');
|
||||
}
|
||||
|
||||
// BR-07: Buyer name is mandatory
|
||||
// BR-07: Buyer name is mandatory
|
||||
if (!invoice.to?.name) {
|
||||
errors.push('BR-07: Buyer name is mandatory');
|
||||
}
|
||||
@@ -67,11 +67,10 @@ export class EN16931Validator {
|
||||
// BR-05: Invoice currency code is mandatory
|
||||
if (!invoice.currency) {
|
||||
errors.push('BR-05: Invoice currency code is mandatory');
|
||||
} else {
|
||||
// Validate currency format
|
||||
if (!this.VALID_CURRENCIES.includes(invoice.currency.toUpperCase())) {
|
||||
errors.push(`Invalid currency code: ${invoice.currency}. Must be a valid ISO 4217 currency code`);
|
||||
}
|
||||
} else if (!this.VALID_CURRENCIES.includes(invoice.currency.toUpperCase())) {
|
||||
errors.push(
|
||||
`BR-05: Invalid currency code: ${invoice.currency}. Must be a valid ISO 4217 currency code`
|
||||
);
|
||||
}
|
||||
|
||||
// BR-08: Seller postal address is mandatory
|
||||
@@ -84,6 +83,17 @@ export class EN16931Validator {
|
||||
errors.push('BR-10: Buyer postal address (city, postal code, country) is mandatory');
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that an invoice object contains all mandatory EN16931 fields
|
||||
* @param invoice The invoice object to validate
|
||||
* @throws Error if mandatory fields are missing
|
||||
*/
|
||||
public static validateMandatoryFields(invoice: any): void {
|
||||
const errors = this.collectMandatoryFieldErrors(invoice);
|
||||
|
||||
if (errors.length > 0) {
|
||||
throw new Error(`EN16931 validation failed:\n${errors.join('\n')}`);
|
||||
}
|
||||
@@ -132,4 +142,4 @@ export class EN16931Validator {
|
||||
throw new Error(`EN16931 XML validation failed:\n${errors.join('\n')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user