Attaches hooks to all collections and writes an immutable entry to a generated audit-logs collection for each create, update, delete and file event. Native login, logout and lockout events are recorded, and external auth can emit events through a helper. It is added through the plugins array and targets Payload 3.
Payload CMS plugin for automatic, compliance-ready audit logging across all collections
Installation
npm i @trieb.work/payload-audit5
Stars
0
Forks
1
Open Issues
2 months ago
Last Updated
237
Weekly Downloads
v1.3.0
npm Version
227.3 KB
Unpacked Size
0
Dependencies
5+2 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 5 |
| Dec 5, 2026 | 5 |
| Dec 4, 2026 | 5 |
| Dec 3, 2026 | 5 |
| Dec 2, 2026 | 5 |
| Dec 1, 2026 | 5 |
| Nov 30, 2026 | 5 |
| Nov 29, 2026 | 5 |
| Nov 28, 2026 | 5 |
| Nov 27, 2026 | 5 |
| Nov 26, 2026 | 5 |
| Nov 25, 2026 | 5 |
| Nov 24, 2026 | 5 |
| Nov 23, 2026 | 5 |
| Nov 22, 2026 | 5 |
| Nov 21, 2026 | 5 |
| Nov 20, 2026 | 5 |
| Nov 19, 2026 | 4 |
| Nov 18, 2026 | 4 |
| Nov 17, 2026 | 4 |
| Nov 16, 2026 | 4 |
| Nov 15, 2026 | 4 |
| Nov 14, 2026 | 4 |
| Nov 13, 2026 | 4 |
| Nov 12, 2026 | 4 |
| Nov 11, 2026 | 4 |
| Nov 10, 2026 | 4 |
| Nov 9, 2026 | 4 |
| Nov 8, 2026 | 4 |
| Nov 7, 2026 | 4 |
| Nov 6, 2026 | 4 |
| Nov 5, 2026 | 4 |
| Nov 4, 2026 | 4 |
| Nov 3, 2026 | 4 |
| Nov 2, 2026 | 4 |
| Nov 1, 2026 | 4 |
| Oct 31, 2026 | 4 |
| Oct 30, 2026 | 4 |
| Oct 29, 2026 | 4 |
| Oct 28, 2026 | 4 |
| Oct 27, 2026 | 4 |
| Oct 26, 2026 | 4 |
| Oct 25, 2026 | 4 |
| Oct 24, 2026 | 4 |
| Oct 23, 2026 | 4 |
| Oct 22, 2026 | 4 |
| Oct 21, 2026 | 4 |
| Oct 20, 2026 | 4 |
| Oct 19, 2026 | 4 |
| Oct 18, 2026 | 4 |
| Oct 17, 2026 | 4 |
| Oct 16, 2026 | 4 |
| Oct 15, 2026 | 4 |
| Oct 14, 2026 | 4 |
| Oct 13, 2026 | 4 |
| Oct 12, 2026 | 4 |
| Oct 11, 2026 | 4 |
| Oct 10, 2026 | 4 |
| Oct 9, 2026 | 4 |
| Oct 8, 2026 | 4 |
| Oct 7, 2026 | 4 |
| Oct 6, 2026 | 4 |
| Oct 5, 2026 | 4 |
| Oct 4, 2026 | 4 |
| Oct 3, 2026 | 4 |
| Oct 2, 2026 | 4 |
| Oct 1, 2026 | 4 |
| Sep 30, 2026 | 4 |
| Sep 29, 2026 | 4 |
| Sep 28, 2026 | 4 |
| Sep 27, 2026 | 4 |
| Sep 26, 2026 | 4 |
| Sep 25, 2026 | 4 |
| Sep 24, 2026 | 4 |
| Sep 23, 2026 | 4 |
| Sep 22, 2026 | 4 |
| Sep 21, 2026 | 4 |
| Sep 20, 2026 | 4 |
| Sep 19, 2026 | 4 |
| Sep 18, 2026 | 4 |
| Sep 17, 2026 | 4 |
| Sep 16, 2026 | 4 |
| Sep 15, 2026 | 4 |
| Sep 14, 2026 | 3 |
| Sep 13, 2026 | 3 |
| Sep 12, 2026 | 3 |
| Sep 11, 2026 | 3 |
| Sep 10, 2026 | 3 |
| Sep 9, 2026 | 3 |
| Sep 8, 2026 | 3 |
| Sep 7, 2026 | 3 |
184+143 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 184 |
| Dec 5, 2026 | 171 |
| Dec 4, 2026 | 156 |
| Dec 3, 2026 | 134 |
| Dec 2, 2026 | 111 |
| Dec 1, 2026 | 112 |
| Nov 30, 2026 | 114 |
| Nov 29, 2026 | 129 |
| Nov 28, 2026 | 128 |
| Nov 27, 2026 | 128 |
| Nov 26, 2026 | 137 |
| Nov 25, 2026 | 220 |
| Nov 24, 2026 | 225 |
| Nov 23, 2026 | 223 |
| Nov 22, 2026 | 212 |
| Nov 21, 2026 | 234 |
| Nov 20, 2026 | 236 |
| Nov 19, 2026 | 248 |
| Nov 18, 2026 | 178 |
| Nov 17, 2026 | 183 |
| Nov 16, 2026 | 185 |
| Nov 15, 2026 | 206 |
| Nov 14, 2026 | 184 |
| Nov 13, 2026 | 227 |
| Nov 12, 2026 | 271 |
| Nov 11, 2026 | 271 |
| Nov 10, 2026 | 276 |
| Nov 9, 2026 | 300 |
| Nov 8, 2026 | 320 |
| Nov 7, 2026 | 370 |
| Nov 6, 2026 | 354 |
| Nov 5, 2026 | 322 |
| Nov 4, 2026 | 402 |
| Nov 3, 2026 | 421 |
| Nov 2, 2026 | 420 |
| Nov 1, 2026 | 417 |
| Oct 31, 2026 | 426 |
| Oct 30, 2026 | 479 |
| Oct 29, 2026 | 426 |
| Oct 28, 2026 | 311 |
| Oct 27, 2026 | 384 |
| Oct 26, 2026 | 508 |
| Oct 25, 2026 | 752 |
| Oct 24, 2026 | 897 |
| Oct 23, 2026 | 790 |
| Oct 22, 2026 | 882 |
| Oct 21, 2026 | 1,030 |
| Oct 20, 2026 | 995 |
| Oct 19, 2026 | 882 |
| Oct 18, 2026 | 650 |
| Oct 17, 2026 | 484 |
| Oct 16, 2026 | 502 |
| Oct 15, 2026 | 430 |
| Oct 14, 2026 | 297 |
| Oct 13, 2026 | 215 |
| Oct 12, 2026 | 180 |
| Oct 11, 2026 | 141 |
| Oct 10, 2026 | 102 |
| Oct 9, 2026 | 112 |
| Oct 8, 2026 | 129 |
| Oct 7, 2026 | 187 |
| Oct 6, 2026 | 216 |
| Oct 5, 2026 | 217 |
| Oct 4, 2026 | 246 |
| Oct 3, 2026 | 260 |
| Oct 2, 2026 | 280 |
| Oct 1, 2026 | 272 |
| Sep 30, 2026 | 202 |
| Sep 29, 2026 | 180 |
| Sep 28, 2026 | 186 |
| Sep 27, 2026 | 148 |
| Sep 26, 2026 | 142 |
| Sep 25, 2026 | 103 |
| Sep 24, 2026 | 109 |
| Sep 23, 2026 | 138 |
| Sep 22, 2026 | 148 |
| Sep 21, 2026 | 166 |
| Sep 20, 2026 | 176 |
| Sep 19, 2026 | 179 |
| Sep 18, 2026 | 321 |
| Sep 17, 2026 | 292 |
| Sep 16, 2026 | 270 |
| Sep 15, 2026 | 258 |
| Sep 14, 2026 | 228 |
| Sep 13, 2026 | 210 |
| Sep 12, 2026 | 184 |
| Sep 11, 2026 | 38 |
| Sep 10, 2026 | 36 |
| Sep 9, 2026 | 42 |
| Sep 8, 2026 | 40 |
| Sep 7, 2026 | 41 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1253340893-root)<a href="https://payloaddirectory.dev/plugins/1253340893-root"><img src="https://payloaddirectory.dev/badge/1253340893-root.svg" alt="Payload Directory"></a>README
Automatic, compliance-ready audit logging and audit trail plugin for Payload CMS. Zero-config change tracking with delegation, forensics, retention, and multi-tenancy built in.
Manually wiring up audit logs for every collection is tedious and easy to get wrong — one forgotten hook and your audit trail has a gap. payload-audit attaches itself to every collection in your Payload config automatically and writes an immutable log entry for every create, update, and delete, so you get a complete, tamper-proof activity trail with a single line of configuration.
It's built to help satisfy the logging and accountability requirements of NIS-2, CRA, GDPR, SEC Cyber Disclosure Rules, HIPAA, PCI-DSS 4.0, ISO/IEC 27001, and SOC 2 — but it's just as useful as a general-purpose "who changed what, when" activity log for any Payload project.
disabledCollections). No per-collection setup.emitAuthEvent call.audit-logs collection denies
create/update/delete through the API; entries can only be written internally
by the plugin, so the log can't be altered or deleted by users.file_upload /
file_delete actions.act semantics) — records who
performed an action on behalf of whom, including nested delegation chains
(User → Agent → Service), via onBehalfOf and delegationChain.sha256) to correlate every action performed with a stolen credential,
without ever storing the raw token.extraActions), e.g. impersonation.started, for manually emitted entries.maxAge), by count
(maxEntries), or both, via a scheduled Payload job (custom cron/queue
supported, or trigger manually).tenant relationship on every entry, with
auto-detection and out-of-the-box interop with
@payloadcms/plugin-multi-tenant.access.read function.writeAuditLog, resolveDelegation, extractTenant,
resolveDocTitle, and pruneAuditLogs are all exported for custom hooks and
scripts. A skipAuditLog request-context flag lets you suppress logging for a
single operation when you emit a more specific entry yourself.pnpm add @trieb.work/payload-audit
// payload.config.ts
import { auditLogPlugin } from '@trieb.work/payload-audit'
export default buildConfig({
// ...
plugins: [
auditLogPlugin({
disabledCollections: ['sessions'],
retention: { maxAge: 365 }, // keep one year of history
}),
],
})
That's it — every collection now writes to an audit-logs collection
automatically. Open the admin UI to see the trail.
All options are optional; sensible, safe defaults are used when omitted.
auditLogPlugin({
// Master switch. `false` turns the plugin into a no-op.
enabled: true,
// Slug of the generated audit collection. Default: 'audit-logs'.
collectionSlug: 'audit-logs',
// Collections that should never be audited (in addition to the audit
// collection itself and Payload's internal collections).
disabledCollections: ['sessions'],
// Read access for the audit trail. Default: any authenticated user.
access: { read: ({ req }) => req.user?.role === 'admin' },
// Prune old entries by age and/or count via a scheduled job.
retention: { maxAge: 365, maxEntries: 100_000, cron: '0 0 * * *' },
// Scope entries per tenant. Interoperates with @payloadcms/plugin-multi-tenant.
multiTenant: { enabled: true, autoDetect: true },
// Opt-in forensic metadata for breach investigation.
forensics: {
authStrategy: true,
requestMethod: true,
tokenFingerprint: true,
},
// RFC 8693 delegation/impersonation-aware logging. Enabled by default.
delegation: { enabled: true, maxChainDepth: 10 },
// Custom action types beyond create/update/delete/file_upload/file_delete.
extraActions: [
{ value: 'impersonation.started', label: 'Impersonation started' },
],
})
Native Payload auth (email/password, API keys, anything that goes through
payload.login() / logout() / refresh()) is recorded automatically:
auth.login.success / auth.login.failureauth.logoutauth.account.locked (when maxLoginAttempts is enabled)auth.token.refresh and auth.password.forgot are off by default (noisy
/ PII). Enable them via authEvents.events.auditLogPlugin({
authEvents: {
events: { refresh: true },
captureIdentifier: 'known-user', // default: store email only if the account exists
},
})
Internal user-document writes during login (sessions, loginAttempts) are not
logged as update.
Failed login and lockout are recorded via Payload's afterError hook, which
runs for REST and GraphQL. Local API payload.login() rethrows without that
hook, so those paths are covered by HTTP-level tests.
emitAuthEvent)Plugins that replace Payload's login (passwordless, Better Auth, custom
endpoints) never fire afterLogin. Call emitAuthEvent at the login / logout /
failure site — the plugin already stored its options on payload.config.custom,
so the call is one argument besides req:
import { emitAuthEvent } from '@trieb.work/payload-audit'
await emitAuthEvent({ req, event: 'login.success', user })
await emitAuthEvent({ req, event: 'login.failure', identifier: email })
await emitAuthEvent({ req, event: 'logout', user })
Register the auth plugin first, then auditLogPlugin, then attach hooks to
collections the auth plugin created (e.g. sessions):
import type { Plugin } from 'payload'
import { emitAuthEvent } from '@trieb.work/payload-audit'
plugins: [authPlugin(), auditLogPlugin(), attachSessionAuthAudit('sessions')]
function attachSessionAuthAudit(slug: string): Plugin {
return (config) => {
const collection = config.collections?.find((c) => c.slug === slug)
if (!collection) return config
collection.hooks ??= {}
collection.hooks.afterChange = [
...(collection.hooks.afterChange ?? []),
async ({ doc, operation, req }) => {
if (operation === 'create') {
const user =
typeof doc.user === 'object' ? doc.user : { id: doc.user }
await emitAuthEvent({ req, event: 'login.success', user })
}
return doc
},
]
collection.hooks.afterDelete = [
...(collection.hooks.afterDelete ?? []),
async ({ doc, req }) => {
const user =
typeof doc?.user === 'object' ? doc.user : { id: doc?.user }
await emitAuthEvent({ req, event: 'logout', user })
return doc
},
]
return config
}
}
The same snippet works for Better Auth (payload-auth): use the session
collection slug that plugin registers (sessions by default).
See the exported TypeScript types (AuditLogPluginConfig and friends) for the
full reference and inline documentation.
| Requirement | Covered by |
|---|---|
| Who changed what, when (GDPR Art. 30, SOC 2 CC7) | Automatic actor/action/timestamp capture on every collection |
| Tamper-proof records (ISO 27001 A.8.15, PCI-DSS 4.0 10.3) | Immutable collection, API writes always denied |
| Incident detection & forensics (NIS-2, SEC Cyber Disclosure) | Forensics metadata, token fingerprinting, delegation chains |
| Data retention limits (GDPR storage limitation) | Configurable retention (age/count) with scheduled pruning |
| Access accountability across tenants (HIPAA, SOC 2) | Multi-tenant scoping of the audit trail |
This is a starting point, not legal advice — always validate against your own compliance obligations.
pnpm install
pnpm dev # start the dev Payload app (zero-config, in-memory Mongo)
pnpm build # build the publishable plugin
The test suite is split into three layers:
Unit tests (pnpm test:int) — Fast, isolated tests for helpers
(extractRequestMeta, resolveDocTitle, extractTenant) and plugin config
wiring. Uses Vitest with vite-tsconfig-paths.
Integration tests (pnpm test:int) — Same Vitest run, but tests live
against a real Payload instance (via getPayload with the dev config and
mongodb-memory-server). Covers create/update/delete logging, upload
tracking, multi-tenant scoping, retention pruning, immutability, native login
events, and emitAuthEvent against real @trieb.work/payload-auth-pwless and
payload-auth (Better Auth).
E2E tests (pnpm test:e2e) — Playwright tests against the running admin
UI. Requires a built dev app first:
pnpm build:dev # or start the dev server manually
pnpm test:e2e
Run everything:
pnpm test # test:int + test:e2e
Issues and pull requests are welcome — see the GitHub repository.
MIT © trieb.work
Topics
payload auditor
Hook-based audit logging for Payload collections and globals with buffered writes and automatic log cleanup
811.4k/wk82v3
payload hooks
Identifier-only audit logging hooks for Payload collections, plus a helper to run callbacks after transaction commit
77225/wk3v3
payload plugin audit log
Append-only audit log of document, global and auth changes with CSV and NDJSON export
72394/wk37v3
payload plugin audit
Audit trail for Payload collections that records who created or updated documents and stores update deltas
6134/wk1v3
sentry
Integrate Sentry error tracking with your Payload application
10034.8k/wk46.1kv3 v4
activity log
Record create, update and delete activity on selected collections and globals in a dedicated log collection
87639/wk115v4