Skip to main content
Introducing packages.sweber.dev
Documentation menuAPI

API

Functions and types of @sweberdev/logarithm.

createAuditLog(options)

OptionTypeMeaning
storeAuditStoreWhere events are stored
redactstring[]Field names stored as [redacted]. Default DEFAULT_REDACT
ignorestring[]Dot paths left out of computed diffs
defaultsAuditDefaultsTenant, actor, context and metadata for every event
now() => DateClock, for tests

Returns an AuditLog:

MethodReturns
record(input)Promise<AuditEvent>
recordMany(inputs)Promise<AuditEvent[]>, one write
query(query?)Promise<AuditPage>, newest first
get(id)Promise<AuditEvent | null>
with(defaults)A scoped AuditLog

Invalid input throws AuditValidationError; invalid queries throw AuditQueryError.

AuditQuery

FieldMeaning
tenantIdTenant, or null for events without one
actorIdExact actor id
actionExact action or prefix.*; an array means OR
targetId, targetTypeEvent has a target with this id or type
from, toTime range, from inclusive, to exclusive
searchCase-insensitive text in action, actor and targets
limit1 to 500, default 50
cursornextCursor of the previous page

AuditEvent

interface AuditEvent {
  id: string                 // ULID
  occurredAt: string         // ISO 8601, UTC
  tenantId: string | null
  action: string
  actor: { id: string; type?: string; name?: string; email?: string }
  targets: { id: string; type: string; name?: string }[]
  changes: { field: string; before?: unknown; after?: unknown }[]
  context: { ip?: string; userAgent?: string; requestId?: string; location?: string }
  metadata: Record<string, unknown>
}

Helpers

FunctionMeaning
diff(before, after, options?)Field changes with redaction
describeAction(event, { locale, nouns })Short sentence such as updated project "Website"
memoryStore()In-memory store for tests and demos
ulid()Time-sortable id

Subpaths

ImportExports
@sweberdev/logarithm/postgrespostgresStore, migratePostgres, postgresSchema
@sweberdev/logarithm/sqlitesqliteStore, migrateSqlite, sqliteSchema