← All @molecule/* packages · App templates
@molecule/api-audit-fileProvider bond · audit · API (Node) · v1.0.1 · Apache-2.0
File-based audit trail provider for molecule.dev — NDJSON storage with rotation
npm install @molecule/api-audit-filenpm · Source on GitHub · Implements @molecule/api-audit
@molecule/api-audit-file is a provider bond on the API (Node) side: it implements the audit core interface (@molecule/api-audit) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { setProvider } from '@molecule/api-audit'
import { provider } from '@molecule/api-audit-file'
setProvider(provider)Works with: @molecule/api-audit
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
File-based audit provider for molecule.dev.
Stores audit trail entries as newline-delimited JSON (NDJSON) files. Supports log rotation, querying, and export to CSV or JSON. Ideal for development, testing, or single-instance deployments.
import { setProvider } from '@molecule/api-audit'
import { provider } from '@molecule/api-audit-file'
setProvider(provider)
provider
npm install @molecule/api-audit-file @molecule/api-audit
FileAuditConfigConfiguration options for the file-based audit provider.
interface FileAuditConfig {
/** Directory path where audit log files are written. Must already exist — the provider does not create it. Defaults to `'./audit-logs'`. */
directory?: string
/** Maximum size (in bytes) of a single log file before rotation. Defaults to `10_485_760` (10 MB). */
maxFileSize?: number
/** Prefix for log file names. Defaults to `'audit'`. */
filePrefix?: string
}
createProvider(config)Creates a file-based audit provider.
function createProvider(config?: FileAuditConfig): AuditProvider
config — Optional provider configuration.Returns: An AuditProvider backed by NDJSON files on disk.
providerDefault file audit provider instance. Lazily initializes on first property access with default options.
const provider: AuditProvider
Implements @molecule/api-audit interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/api-audit'
import { provider } from '@molecule/api-audit-file'
export function setupAuditFile(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/api-audit ^1.0.1@molecule/api-audit
Create the log directory before the first log() call. The provider
does NOT create it: log() throws ENOENT if directory (default
'./audit-logs') doesn't exist. await mkdir('./audit-logs', { recursive: true })
at startup (or point createProvider({ directory }) at an existing path).
Appends rewrite the whole current log file and query()/export() load
every matching record into memory — fine for dev/single-instance volumes;
use @molecule/api-audit-database for sustained production write rates.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
log() is called from the handler that does the work, not merely
defined. Confirm the entry exists via the audit view or a query().actor is the authenticated user from the server session:
two different signed-in users produce two different actors, never a
hardcoded/anonymous/client-supplied id.query)
narrows the results as expected.query/auditExport) is admin-only — a
normal user gets 403 / no UI and cannot read everyone else's activity.