import { cents, computeTotals, percent, quantity, unitPrice, assertValidInvoice } from 'facturx-sdk';
const draft = {
id: 'F-2026-0001', issueDate: '2026-09-11', typeCode: '380', currency: 'EUR',
operationCategory: 'services', // goods / services / mixed (French reform)
seller: { name: 'Atelier Exemple SAS', siren: '443061841', vatId: 'FR64443061841',
address: { postCode: '75011', city: 'Paris', countryCode: 'FR' } },
buyer: { name: 'Client Démo SARL', siren: '732829320',
electronicAddress: { value: '732829320', scheme: '0225' }, // platform routing
address: { postCode: '69002', city: 'Lyon', countryCode: 'FR' } },
delivery: { date: '2026-09-10' },
lines: [{ id: '1', name: 'Consulting', quantity: quantity(20000), unitCode: 'DAY',
unitPrice: unitPrice(8000000), netAmount: cents(160000),
tax: { category: 'S', rate: percent('20') } }],
paymentTerms: { dueDate: '2026-10-11', latePenaltyRate: percent('10'),
recoveryIndemnity: cents(4000), earlyPaymentDiscount: 'none' },
};
const invoice = assertValidInvoice({ ...draft, ...computeTotals(draft) });
// otherwise: FacturXValidationError { issues: [{ code: 'BR-CO-15', path: 'totals.taxInclusiveAmount', … }] }
import { renderInvoicePdf, embedFacturX } from 'facturx-sdk/pdf';
// The human-readable page, drawn from the model — no need to bring your own PDF
const page = await renderInvoicePdf(invoice, {
fonts: { regular: ttf, bold: ttfBold }, // a static font, embedded
labels: 'en',
});
// The page + the XML → PDF/A-3 Factur-X, checked by veraPDF on every commit
const pdfA3 = await embedFacturX(page, { invoice }, {
outputIntent: { iccProfile: srgb },
});
import { fromCiiXml, fromUblXml } from 'facturx-sdk';
import { extractInvoice } from 'facturx-sdk/pdf';
// Received PDF → typed, validated invoice (or undefined if it carries no Factur-X)
const received = await extractInvoice(pdfBytes);
// The three syntaxes of the French socle, one model
const fromCii = fromCiiXml(xmlString);
const fromUbl = fromUblXml(xmlString); // same invoice ⇒ same object
// FacturXParseError { code, path } when a document cannot be read