Call the ledger over its internal endpoint

Node · Node · intermediate · modification

Moves the billing worker's ledger calls from the public endpoint to the internal one. A new `src/ledger/tls.ts` builds a dedicated `https.Agent` for the ledger: keep-alive with up to 10 sockets, our internal CA as the only trusted root (loaded from `LEDGER_CA_FILE`, which `src/config.ts` now requires), and an identity check for the certificates our internal CA issues. `postJournalEntry` in `src/ledger/client.ts` now sends its requests through that agent; the request, the response handling and the errors are unchanged.

Node 22 LTS, TypeScript 5 (strict), CommonJS; a background billing worker, no HTTP server of its own. `postJournalEntry` is called only by the invoice-finalisation job (unchanged), which marks the invoice as posted with the returned `entryId` when the call resolves, and on `LedgerError` retries the invoice later with the same `invoiceId` (the ledger dedupes on it). Infra sets `LEDGER_URL=https://ledger.billing.internal` in every environment (deploy config, outside this repo). `LEDGER_CA_FILE` points to the company's internal root CA in PEM, mounted read-only by the platform; a missing or unreadable file fails the worker at startup, which is intended, as for a missing variable. Internal DNS: `*.internal` names resolve inside the company network. The internal CA is the platform's self-service issuer: every internal service (the wiki, CI runners, team sandboxes) gets a certificate from it for its own `*.internal` hostname, and the ledger's certificate names `ledger.billing.internal` as a DNS SAN. The ledger answers with small JSON bodies (under 1 KB). `src/logger.ts` is unchanged and writes one JSON line per call.

Requirements

Files touched

Review this PR

Node practice