← All @molecule/* packages · App templates
@molecule/api-audit-databaseProvider bond · audit · API (Node) · v1.0.1 · Apache-2.0
Database-backed audit trail provider for molecule.dev
npm install @molecule/api-audit-databasenpm · Source on GitHub · Implements @molecule/api-audit
@molecule/api-audit-database 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-database'
setProvider(provider)Works with: @molecule/api-audit, @molecule/api-database
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.
Database-backed audit provider for molecule.dev.
Persists audit trail entries using the abstract DataStore from
@molecule/api-database. Supports filtering, pagination, and export
to CSV or JSON.
import { setProvider } from '@molecule/api-audit'
import { provider } from '@molecule/api-audit-database'
setProvider(provider)
provider
npm install @molecule/api-audit-database @molecule/api-audit @molecule/api-database
DatabaseAuditConfigConfiguration options for the database-backed audit provider.
interface DatabaseAuditConfig {
/** Name of the database table used to store audit records. Defaults to `'audit_log'`. */
tableName?: string
}
createProvider(config)Creates a database-backed audit provider.
function createProvider(config?: DatabaseAuditConfig): AuditProvider
config — Optional provider configuration.Returns: An AuditProvider backed by the bonded DataStore.
providerDefault database 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-database'
export function setupAuditDatabase(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/api-audit ^1.0.1@molecule/api-database ^1.0.1@molecule/api-audit
@molecule/api-database
Wire the database bond first — every method uses the abstract DataStore
(create/findMany/count from @molecule/api-database), which throws if no
database provider is bonded when the first audit call runs.
The audit table is NOT auto-created. Ship a migration for audit_log (or your
config.tableName) with columns: id TEXT PRIMARY KEY, actor TEXT NOT NULL,
action TEXT NOT NULL, resource TEXT NOT NULL, resource_id TEXT NULL,
details TEXT NULL (a JSON string — stringified on write, parsed on read),
ip TEXT NULL, user_agent TEXT NULL, timestamp TIMESTAMPTZ/TEXT NOT NULL
(ISO-8601; range-filtered and sorted descending).
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.