// The audit-logger's entrypoint. The per-node module runtime imports this once the broker is // bound; the on("#") subscription is the whole handshake — it consumes every event on the mesh // (module.*, mesh.*, node.*) and writes each to the trail. // // **No event is lost** (novox/hq issue 276). A line that cannot be written is thrown, so the bus offers // the event again; the first failure spools it on disk, its last delivery is taken from the spool, and // the spool is replayed into the trail once writing works again (spool.ts). The trail skips an event id // it already holds, so a redelivery or a replay never writes it twice (audit.ts). import { on } from "@novox/mesh-sdk/events"; import { auditLogPath, auditSpoolPath, Trail } from "./audit.js"; import { replayEvery, Spool, takeOrSpool } from "./spool.js"; const say = (line: string) => console.error(`[audit-logger] ${line}`); const trail = await Trail.open(auditLogPath()); const spool = await Spool.open(auditSpoolPath()); const write = (event: Parameters[0]) => trail.record(event); replayEvery(spool, write, 30_000, say); await on("#", (event) => takeOrSpool(event, write, spool, say)); console.log( `[audit-logger] recording all mesh events to ${trail.path}` + (spool.size > 0 ? `; ${spool.size} spooled event(s) wait in ${spool.dir}` : ""), );