SDK TypeScript e linha de comandos
Um cliente tipado sem dependências (Node 18+, Deno, Bun) e a ferramenta de linha de comandos einv. Instale-os a partir do npm: npm install @einvoiceengine/sdk (licença MIT); a CLI fica então disponível como npx einv.
Cliente
import { EInvoicing, EInvoicingError } from "@einvoiceengine/sdk";
const einv = new EInvoicing({ apiKey: process.env.EINV_KEY!, lang: "de" });
const r = await einv.validate(xml); // string, Uint8Array or ArrayBuffer; PDFs are detected
if (!r.valid) for (const f of r.findings) console.log(f.ruleId, f.explanation, f.suggestion);
const cii = await einv.convert(xml, "cii");
const diff = await einv.compare(xml, cii.document); // business-level, not billed
const proposals = await einv.analyze(rejected, "Abgelehnt: BR-DE-15");
const set = await einv.testdata("xrechnung-ubl"); // synthetic test invoices
const run = await einv.testSets.run(setId); // stored test set: expectations + diff to the previous run
const session = await einv.widgetSession({ origin: "https://app.example.com" });
Cada método corresponde a um endpoint da API. Os erros são lançados como EInvoicingError com status, code, message, details e requestId. As respostas com 429 ou 5xx são repetidas com backoff (respeitando Retry-After, 3 repetições por predefinição); as chamadas que criam algo levam uma Idempotency-Key, pelo que uma repetição nunca é faturada duas vezes. lang define o idioma das explicações e sugestões.
Linha de comandos
export EINV_KEY=einv_test_…
einv validate invoice.xml other.pdf --lang de
einv convert invoice.xml --to zugferd-facturx --out invoice.pdf
einv compare erp-export.xml received.xml
einv explain BR-CO-16
einv testdata --target xrechnung-cii --out fixtures # synthetic invoices + expected.json
einv ci out/invoices --rules 2026-11 --baseline einv-baseline.json
einv ci --test-set <id> --rules 2026-11 # run a test set stored in your account
einv formats
Códigos de saída: 0 tudo passou, 1 uma fatura falhou ou duas faturas diferem, 2 erro de utilização ou da API. einv ci funciona como einv-ci.mjs: com --update-baseline regista os resultados atuais; a partir daí, apenas as novas falhas fazem falhar o build.
E-Invoicing API