Skip to Content
TelamonJS

AuditChangesViewer

Renders an audit entry's payload, whether a field diff, before/after snapshots or a plain object, with secrets masked

The "what changed" panel of an audit log detail. Hand it whatever your audit trail stored and it picks the layout. It is pure UI: no fetching. Together with PermissionMatrix it is one of the building blocks of the upcoming admin kit.

'use client'
import { AuditChangesViewer } from '@telamonjs/ui'

export function AuditEntryChanges({ log }: { log: AuditLogRow }) {
  return log.before !== undefined || log.after !== undefined ? (
    <AuditChangesViewer before={log.before} after={log.after} />
  ) : (
    <AuditChangesViewer changes={log.changes} />
  )
}

Payload shapes

PayloadRendered as
changes={{ name: { old: 'Ann', new: 'Anna' } }}: every entry is { old, new }, { from, to }, or { before, after } as logger.audit() writes itField / Before / After table
before={…} after={…}, or changes={{ before, after }}Field / Before / After, computed here: changed fields only, with a "Show all fields" toggle
changes={{ title: 'Hello', tags: ['a'] }}: any other object (a request body, metadata)Field / Value list
an array, a number or free textpretty-printed block
null, undefined, {}localized "No changes recorded."
  • A JSON string (a text column holding JSON) is parsed first, for changes, before and after.
  • Nested values (objects, arrays) are pretty-printed inside a native <details>, collapsed, with the entry count as the summary.
  • before/after: fields are compared deeply (key order does not count). A creation (before={null}) lists every field of after. When nothing differs, the viewer says so and the toggle still shows every field. Unchanged fields render muted.
  • null shows as null and a missing value as —, so "cleared" and "not recorded" stay distinct.

Redaction

Keys containing password, passwd, senha, secret, token, apikey, authorization, cookie or privatekey are masked at any depth, in every shape, before anything reaches the DOM. Matching is case-insensitive and ignores _ and -, so passwordHash, api_token and clientSecret are covered. redactKeys adds keys to that list:

<AuditChangesViewer changes={log.changes} redactKeys={['taxId', 'birthDate']} />

Redaction only hides values on screen. Keep secrets out of the audit trail on the server too.

Props

PropTypeDefault
changesunknown: diff, { before, after }, object, JSON string—
beforeunknown, snapshot before the change (takes precedence over changes)—
afterunknown, snapshot after the change—
redactKeysstring[], added to the built-in list—
classNamestring—

Labels come from the library messages (telamonjs.admin.auditChanges.*).

What stays in your app

The rest of the audit detail: who, when, IP, user agent, action badges and entity names (compose them with DetailCard and Tabs), field display names, and adapting other shapes. A list of changes, for example, becomes a diff in one line: Object.fromEntries(list.map(c => [c.field, { from: c.from, to: c.to }])).

On this page