Skip to content

Documentation / @einvoice-ts/validator / validate

Function: validate() ​

The implementation behind the overloads.

Param ​

document

A parsed or built document.

Param ​

options

Which ruleset to run.

Call Signature ​

validate(document, options?): ValidationResult<Invoice>

Defined in: packages/validator/src/engine/validate.ts:268

Runs a composition of rulesets over a document and reports every issue it finds.

Never throws for a document problem: a document missing its cbc:CustomizationID still gets its BR-01 and is validated against [en16931Ruleset]. The ruleset option lists the constants explicitly; otherwise the registry resolves a composition from the customization id: Peppol rules run only for a document that declares the Peppol BIS Billing 3.0 id (or an id starting with it), CIUS-ES-FACE rules only for one that declares the CIUS-ES-FACE 1.0.0 id, and every other document gets EN 16931 alone. Defaults carry no national rules, so without dkRuleset a Danish invoice the official Peppol validator rejects can pass here.

Parameters ​

document ​

Invoice | UncheckedInvoice

A parsed (Unchecked*) or built document.

options? ​

ValidateOptions

Which rulesets to run.

Returns ​

ValidationResult<Invoice>

The outcome; ok when no fatal issue was found.

Throws ​

When document.kind is neither Invoice nor CreditNote.

Throws ​

When the ruleset composition does not compile: a ruleset that is not a list of ruleset constants, an empty list, a constant listed twice, a required constant missing or listed later, a duplicate rule id, a rule id defined again after an earlier constant disabled it, a disable or override that names nothing earlier in the list (a rule, or a structural id of the base layer) or can match one of the library's own EINV- ids, a disable entry that starts with * or matches a rule its own constant defines or replaces, or an override that sets test, when or context on a structural id that is not a rule defined earlier.

Example ​

ts
import { dkRuleset, en16931Ruleset, peppolRuleset, validate } from '@einvoice-ts/validator';

const result = validate({ kind: 'Invoice' }); // no customization id: EN 16931 alone
result.ok; // false
result.fatal.map((issue) => issue.id); // ['BR-01', 'BR-02', ...]
result.ruleset.ids; // ['en16931']

validate(peppolInvoice).ruleset.ids; // ['en16931', 'peppol'], from its cbc:CustomizationID
validate(invoice, { ruleset: [en16931Ruleset, peppolRuleset, dkRuleset] }); // with the Danish rules

Call Signature ​

validate(document, options?): ValidationResult<CreditNote>

Defined in: packages/validator/src/engine/validate.ts:279

Runs a ruleset over a credit note; see the invoice overload.

Parameters ​

document ​

CreditNote | UncheckedCreditNote

A parsed or built credit note.

options? ​

ValidateOptions

Which ruleset to run.

Returns ​

ValidationResult<CreditNote>

The outcome, with the document narrowed to CreditNote when ok.

Call Signature ​

validate(document, options?): ValidationResult

Defined in: packages/validator/src/engine/validate.ts:290

Runs a ruleset over a document of either kind; see the invoice overload.

Parameters ​

document ​

Document | UncheckedDocument

A parsed or built document.

options? ​

ValidateOptions

Which ruleset to run.

Returns ​

ValidationResult

The outcome, with the document narrowed to Document when ok.

MIT licensed. Specification material belongs to OpenPeppol, CEN and OASIS (see NOTICE). Peppol is a trademark of OpenPeppol AISBL; this project is not affiliated with it.