Skip to content

Documentation / @facturometro/einvoice / 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:264

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), 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: 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, or an override that sets test, when or context on a structural rule only the parser checks.

Example ​

ts
import { dkRuleset, en16931Ruleset, peppolRuleset, validate } from '@facturometro/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:275

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:286

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 artefacts belong to OpenPEPPOL, CEN and OASIS.