UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

32 lines 1.4 kB
import type { AuditLogPort } from "../ports/index.js"; /** * Wrap an audit log port so missing `actor`, `tenant`, `requestId`, and * `traceId` fields are filled from the ambient request context at record time. * * The server keeps the ambient context current for requests (including * identity elevated by hooks) and for service contexts created for jobs, * listeners, schedules, and tasks. Because enrichment happens when * `record(...)` runs, the wrapper also works for ports rebuilt per * transaction inside a unit of work — wrap both the top-level audit port and * the per-transaction rebuild. * * Fields provided on the entry always win; only missing fields are filled. * When no ambient context is active (for example on runtimes without * `AsyncLocalStorage` propagation), entries pass through unchanged. * * @example * ```ts * const audit = createAmbientAuditLog( * createInstrumentedAuditLog({ * audit: createDrizzleSqliteAuditLogPort(db), * instrumentation: ports, * }), * ); * await audit.record({ action: "posts.publish", resource: { type: "post", id } }); * ``` * * @param audit - Underlying audit log port to write enriched entries to. * @returns An audit log port that fills missing context fields before writing. */ export declare function createAmbientAuditLog(audit: AuditLogPort): AuditLogPort; //# sourceMappingURL=audit-context.d.ts.map