Adds an audit-log collection that records create and update operations on selected collections through afterChange hooks. Each log stores the acting user and a jsondiffpatch delta, and read-only virtual fields show the creator and update history in the admin panel. Requires listing audited collections and auth-enabled user collections. Deletes are not recorded, and the plugin is described as early development.
Audit trail plugin for Payload CMS: records who created or updated documents, stores update deltas, and shows them in the admin panel.
Installation
npm i payload-plugin-audit1
Stars
0
Forks
2
Open Issues
1 weeks ago
Last Updated
34
Weekly Downloads
v0.4.0
npm Version
155.7 KB
Unpacked Size
2
Dependencies
1+1 since Nov 8
| Date | Stars |
|---|---|
| Dec 6, 2026 | 1 |
| Dec 5, 2026 | 1 |
| Dec 4, 2026 | 1 |
| Dec 3, 2026 | 1 |
| Dec 2, 2026 | 1 |
| Dec 1, 2026 | 1 |
| Nov 30, 2026 | 1 |
| Nov 29, 2026 | 1 |
| Nov 28, 2026 | 1 |
| Nov 27, 2026 | 1 |
| Nov 26, 2026 | 1 |
| Nov 25, 2026 | 1 |
| Nov 24, 2026 | 1 |
| Nov 23, 2026 | 1 |
| Nov 22, 2026 | 1 |
| Nov 21, 2026 | 1 |
| Nov 20, 2026 | 1 |
| Nov 19, 2026 | 1 |
| Nov 18, 2026 | 1 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
40+40 since Nov 16
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 40 |
| Dec 5, 2026 | 35 |
| Dec 4, 2026 | 37 |
| Dec 3, 2026 | 48 |
| Dec 2, 2026 | 59 |
| Dec 1, 2026 | 73 |
| Nov 30, 2026 | 238 |
| Nov 29, 2026 | 239 |
| Nov 28, 2026 | 263 |
| Nov 27, 2026 | 431 |
| Nov 26, 2026 | 439 |
| Nov 25, 2026 | 612 |
| Nov 24, 2026 | 862 |
| Nov 23, 2026 | 688 |
| Nov 22, 2026 | 675 |
| Nov 21, 2026 | 650 |
| Nov 20, 2026 | 478 |
| Nov 19, 2026 | 458 |
| Nov 18, 2026 | 270 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
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/1454329568-root)<a href="https://payloaddirectory.dev/plugins/1454329568-root"><img src="https://payloaddirectory.dev/badge/1454329568-root.svg" alt="Payload Directory"></a>README
payload-plugin-audit adds an audit trail to Payload CMS collections. It records who created or updated a document, stores update deltas, and exposes the audit information in the Payload admin panel through read-only virtual fields.
Note: This plugin is in early development and may not be suitable for production use yet. Please report any issues you encounter. Until version 1.x.x, the plugin is not considered stable and may have breaking changes in minor releases. Please pin to a specific version if you want to avoid unexpected changes and manually upgrade after reviewing the release notes and changelog.
create and update operations in a dedicated audit-log collection.jsondiffpatch.created by relationship field to audited collections.DeltaViewer component.update logs on a configurable schedule while preserving create logs.Install the plugin in your Payload application:
npm install payload-plugin-audit
# or
pnpm add payload-plugin-audit
# or
yarn add payload-plugin-audit
Add the plugin to the plugins array in payload.config.ts:
import { auditPluginPayload } from "payload-plugin-audit";
import { buildConfig } from "payload";
export default buildConfig({
collections: [Posts, Users],
plugins: [
auditPluginPayload({
collections: ["posts"],
userCollections: ["users"],
}),
],
});
collections contains the slugs to audit. userCollections contains every auth-enabled collection whose users may create or update an audited document. Both arrays are required and cannot be empty.
After adding or changing the plugin configuration, regenerate Payload types and apply the database schema changes using your normal Payload workflow.
The plugin creates an audit-plugin-logs collection by default. Each log contains:
operation: create or update.entity: a polymorphic relationship to the audited document.user: a polymorphic relationship to the user who performed the operation.delta: the jsondiffpatch result for updates.createdAt and updatedAt timestamps.For every audited collection, the plugin also adds these virtual fields:
auditPluginCreatedBy: resolves to the user who created the document.auditPluginUpdateLogs: resolves to the document's update history, including the user, date, and delta for each update.The generated fields are virtual and read-only.
afterChange hooks, so deletes are not currently recorded.join fields are not tracked on collections. If you need to track changes to join fields, consider tracking the collection with the relationship field that the join field points to instead.Use state to control the plugin lifecycle:
state: 'enabled' // default: hooks, logs, and virtual fields are active
enabled: records audit logs and adds the virtual fields.inactive: keeps the audit-log collection and virtual fields but stops creating new logs (disables the afterChange hooks).disabled: leaves the Payload configuration unchanged and disables the plugin entirely.The defaults can be overridden when a migration or an existing naming convention requires it:
db: {
collections: {
logs: {
slug: 'my-custom-collection-slug',
hidden: true,
},
},
fields: {
createdBy: { name: 'myCustomCreatedBy' },
updateLogs: { name: 'myCustomUpdateLogs' },
},
},
Changing collection slug or field names changes the database schema and generated Payload types, so keep it in mind and perform database migrations as needed.
access.read controls who can read audit logs and the generated virtual fields.
access.delete controls manual delete access on the audit-log collection.
Keep access.delete restrictive as users with it can remove parts of the audit trail.
Old update logs can be removed by a scheduled Payload job. create logs are never removed by this job.
Cleanup is disabled by default and should be enabled manually with
cleanup.enabled: truewhen a jobs runner is set up to handle it.
cleanup: {
enabled: false,
olderThanDays: 90,
schedule: '0 0 * * *',
queue: 'payload-plugin-audit',
silent: false,
},
| Option | Default | Description |
|---|---|---|
enabled | false | Registers the cleanup task and its schedule. |
olderThanDays | 90 | update logs older than this many days are deleted. |
schedule | '0 0 * * *' (midnight) | Cron expression, five or six fields (six adds seconds precision). |
queue | 'payload-plugin-audit' | Queue the job is added to. |
silent | false | Suppresses cleanup logging. |
The plugin only queues the cleanup job. Something has to run the queue, otherwise the job just sits there. Pick one that fits your deployment, and use the same queue name as cleanup.queue:
Dedicated server, autoRun (handles both scheduling and running):
import { AUDIT_PLUGIN_QUEUE } from 'payload-plugin-audit'
jobs: {
autoRun: [{ cron: '* * * * *', queue: AUDIT_PLUGIN_QUEUE }], // Or your own queue name provided in cleanup.queue
}
Dedicated server, bin script:
# For --queue use the same queue name as cleanup.queue. If not provided, the default queue name is `payload-plugin-audit` as provided via `AUDIT_PLUGIN_QUEUE`.
pnpm payload jobs:run --cron "* * * * *" --queue payload-plugin-audit --handle-schedules
Serverless (e.g. Vercel): use an external cron to call both endpoints:
For ?queue use the same queue name as cleanup.queue. If not provided, the default queue name is payload-plugin-audit as provided via AUDIT_PLUGIN_QUEUE.
GET /api/payload-jobs/handle-schedules?queue=payload-plugin-audit
GET /api/payload-jobs/run?queue=payload-plugin-audit
Don't combine autoRun with the handle-schedules bin script for the same queue, or jobs will be queued twice. Never use autoRun on serverless platforms.
If you'd rather not use the built-in schedule, set cleanup.enabled: false and call the cleanup function from your own endpoint, script or task:
import { cleanupAuditLogs } from 'payload-plugin-audit'
await cleanupAuditLogs({
collectionSlug: 'audit-logs', // your logs collection slug
olderThanDays: 30,
payload,
})
If cleanup.enabled is true, you can also trigger the registered task on demand:
import { AUDIT_CLEANUP_TASK_SLUG } from 'payload-plugin-audit'
await payload.jobs.queue({ task: AUDIT_CLEANUP_TASK_SLUG })
The cleanup bypasses collection access control, so it works even though access.delete blocks all manual deletes.
Labels and date formatting can be customized through the ui option.
The client components are also available from the payload-plugin-audit/client export, however, they are primarily intended for Payload admin component configuration and are already wired into the generated fields and audit-log collection.
pnpm install # install dependencies
pnpm docker:reload # start the database
pnpm dev # start the development server
Useful commands:
pnpm test # run tests
pnpm lint # run linter
pnpm build # build the plugin
This project is licensed under the Mozilla Public License 2.0. See the LICENSE file for details.
audit fields
Adds createdBy and lastModifiedBy fields to Payload collections and globals
922.3k/wk115v4
activity log
Record create, update and delete activity on selected collections and globals in a dedicated log collection
87639/wk115v4
activity log
Chronological activity feed of document changes and user logins with links to affected documents and versions
62185/wk16v3
audit fields
Track who created and last modified each document, with a Modified By column in the versions view
62176/wk16v3
authors info
Automatically record who created, edited and published documents across collections and globals
59277/wk183v3
payload plugin author fields
Adds createdBy and updatedBy fields to all collections and globals in a Payload app
3676/wk43v1 v2