// Validate an invoice with TypeScript (Node 20+, no dependencies). // Run: EINV_BASE=… EINV_KEY=… npx tsx validate.ts invoice.xml import { readFile } from "node:fs/promises"; const base = process.env.EINV_BASE!; const key = process.env.EINV_KEY!; const xml = await readFile(process.argv[2] ?? "invoice.xml"); const res = await fetch(`${base}/v1/invoices/validate`, { method: "POST", headers: { authorization: `Bearer ${key}`, "content-type": "application/xml" }, body: xml, }); if (!res.ok) { const { error } = await res.json(); throw new Error(`${error.code}: ${error.message} (request ${error.requestId})`); } const result = await res.json(); console.log(result.status, `${result.summary.errors} errors`); for (const f of result.findings.filter((f: { severity: string }) => f.severity === "error")) { console.log(`- ${f.ruleId}: ${f.explanation} (line ${f.location?.line ?? "?"})`); }