feat(validation): add validators
This commit is contained in:
@ -31,3 +31,60 @@ export interface IInvoiceItem {
|
||||
UnitPrice: number;
|
||||
TotalPrice: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported electronic invoice formats
|
||||
*/
|
||||
export enum InvoiceFormat {
|
||||
UNKNOWN = 'unknown',
|
||||
UBL = 'ubl', // Universal Business Language
|
||||
CII = 'cii', // Cross-Industry Invoice
|
||||
ZUGFERD = 'zugferd', // ZUGFeRD (German e-invoice format)
|
||||
FACTURX = 'facturx', // Factur-X (French e-invoice format)
|
||||
XRECHNUNG = 'xrechnung', // XRechnung (German e-invoice implementation of EN16931)
|
||||
FATTURAPA = 'fatturapa' // FatturaPA (Italian e-invoice format)
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a validation level for invoice validation
|
||||
*/
|
||||
export enum ValidationLevel {
|
||||
SYNTAX = 'syntax', // Schema validation only
|
||||
SEMANTIC = 'semantic', // Semantic validation (field types, required fields, etc.)
|
||||
BUSINESS = 'business' // Business rule validation
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a validation error
|
||||
*/
|
||||
export interface ValidationError {
|
||||
code: string; // Error code (e.g. "BR-16")
|
||||
message: string; // Error message
|
||||
location?: string; // XPath or location in the document
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of a validation operation
|
||||
*/
|
||||
export interface ValidationResult {
|
||||
valid: boolean; // Overall validation result
|
||||
errors: ValidationError[]; // List of validation errors
|
||||
level: ValidationLevel; // The level that was validated
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for the XInvoice class
|
||||
*/
|
||||
export interface XInvoiceOptions {
|
||||
validateOnLoad?: boolean; // Whether to validate when loading an invoice
|
||||
validationLevel?: ValidationLevel; // Level of validation to perform
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for validator implementations
|
||||
*/
|
||||
export interface IValidator {
|
||||
validate(level?: ValidationLevel): ValidationResult;
|
||||
isValid(): boolean;
|
||||
getValidationErrors(): ValidationError[];
|
||||
}
|
||||
|
Reference in New Issue
Block a user