In Node.js, generate PINT AE documents with a namespace-aware XML builder, validate schema with libxmljs or an external service, run the PINT AE schematron through an XSLT processor or a validation microservice, queue submissions with BullMQ on Redis, isolate each Accredited Service Provider behind an adapter, and record acknowledgements per document. For multi-tenant platforms, each tenant is a distinct seller with its own TIN, provider appointment and credentials.
Key facts at a glance
- Generation: xmlbuilder2 with explicit namespaces and element order.
- Schema: libxmljs2 or a validation service; schematron via XSLT (Saxon-JS) or service.
- Queue: BullMQ with exponential back-off and dead-letter handling.
- Adapters: one module per ASP implementing
submit()andstatus(). - Multi-tenant: per-tenant TIN, provider and credentials; shared validation.
Building the XML
import { create } from 'xmlbuilder2';
const doc = create({ version: '1.0', encoding: 'UTF-8' })
.ele('Invoice', { xmlns: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',
'xmlns:cac': CAC, 'xmlns:cbc': CBC })
.ele('cbc:CustomizationID').txt(PINT_AE_ID).up()
.ele('cbc:ID').txt(inv.number).up()
.ele('cbc:IssueDate').txt(inv.issuedOn).up()
.ele('cbc:InvoiceTypeCode').txt('380').up()
.ele('cbc:DocumentCurrencyCode').txt(inv.currency).up();
appendParty(doc, 'cac:AccountingSupplierParty', seller); // EndpointID schemeID="0235"
appendParty(doc, 'cac:AccountingCustomerParty', buyer);
// payment means, allowances, tax total, monetary total, lines (in schema order)
const xml = doc.end({ prettyPrint: false });
Validation strategy
Schematron execution in pure JavaScript is possible with Saxon-JS after compiling the PINT AE rules to SEF, but many teams find it simpler to run a small validation microservice (any language with mature schematron support) and call it over HTTP. Either way, validate locally before enqueueing, and keep a corpus of scenario documents under test.
Queue and adapter
const queue = new Queue('einvoice', { connection });
await queue.add('submit', { invoiceId }, { jobId: invoice.number,
attempts: 10, backoff: { type: 'exponential', delay: 60_000 } });
new Worker('einvoice', async job => {
const inv = await loadInvoice(job.data.invoiceId);
const asp = adapterFor(inv.tenant); // per-tenant provider
const res = await asp.submit(inv.xml, { idempotencyKey: inv.number });
await recordAck(inv.id, 'provider_accepted', res);
}, { connection });Using the document number as jobId makes duplicate enqueues no-ops, which pairs with the provider-side idempotency key.
Multi-tenant SaaS specifics
| Topic | Practice |
|---|---|
| Who is the seller? | Always the tenant business, identified by its own TIN; the platform is its software |
| Provider appointment | Each tenant appoints an ASP in EmaraTax; the platform stores the tenant's provider credentials or uses a reseller arrangement |
| Isolation | Per-tenant queues or job prefixes; per-tenant archives; row-level security |
| Onboarding | Collect TIN/TRN, structured address and provider details before enabling e-invoicing for a tenant |
| Reporting | Per-tenant reconciliation exports for their VAT returns |
Where Zaini Developers fits in
We have designed exactly this for platforms that bill on behalf of many UAE businesses. If you run a Node.js SaaS, we can deliver the compliance module and the tenant onboarding flow as a package.
Book a free consultation →Frequently asked questions
Can a SaaS platform be the ASP for its tenants?
Only if it is accredited by the MoF. Otherwise it connects tenants to accredited providers, directly or through a reseller arrangement.
Is TypeScript recommended?
Strongly. Typed document models catch ordering and cardinality mistakes before runtime.
How do I render a PDF from the XML in Node?
Apply an XSLT stylesheet or render from the same JSON model with a headless browser; generate from the finished data, never separately.
How do I test provider adapters?
Record sandbox interactions and replay them in tests; keep a live sandbox smoke test in CI on a schedule.
