gngz

audit logs

by gngz
payload-kit
Logging & monitoring
v3
^3.0.0
^3.0.0 · prerelease
MIT

Overview

Summary generated from the README

Adds a read-only audit-logs collection that records create, update, delete, login and logout events across monitored collections and globals. It stores field-level diffs, optional snapshots, actor details and client IP and user agent, while stripping sensitive fields such as passwords and tokens. Registered through the plugin array in the Payload config, it works with Payload 3 and supports retention-based pruning via the Jobs Queue.

Features

  • Records create, update, delete, login and logout events for chosen collections and globals
  • Field-level diffs and optional document snapshots per collection
  • Redacts passwords, hashes, salts, reset tokens and TOTP secrets before storage
  • Configurable client IP resolution with presets for Cloudflare, Vercel and trusted proxy hops
  • Retention by age or record count with optional Jobs Queue task and prune endpoint
  • Custom access overrides and a context flag to skip auditing on internal calls

Use cases

  • Track who changed orders or inventory and what values changed for compliance review
  • Monitor admin sign-ins and sign-outs with IP and user agent metadata
  • Keep audit log storage bounded by pruning old entries on a schedule

From the author

Audit trail and activity logging plugin for Payload CMS

Installation

npm i @payload-kit/audit-logs

0

Stars

0

Forks

3

Open Issues

Yesterday

Last Updated

517

Weekly Downloads

v0.1.0-alpha.1

npm Version

105.4 KB

Unpacked Size

1

Dependencies

Repository stars

00 since Nov 22

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260

Shared by 5 plugins in gngz/payload-kit.

npm weekly downloads

Trends appear after 7 days of data. Collecting since Dec 2 — 4 daily snapshots so far.

Each point is npm's rolling 7-day download count.

Health Score

67/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1474969753-audit-logs.svg)](https://payloaddirectory.dev/plugins/1474969753-audit-logs)
HTML
<a href="https://payloaddirectory.dev/plugins/1474969753-audit-logs"><img src="https://payloaddirectory.dev/badge/1474969753-audit-logs.svg" alt="Payload Directory"></a>
Updated Dec 4, 2026Created Nov 27, 2026Published Nov 29, 2026

README

@payload-kit/audit-logs

Audit trail plugin for Payload CMS. Adds a read-only audit-logs collection that records create, update, delete, login, and logout events across monitored collections and globals, with field-level diffs, actor metadata, and redaction of sensitive fields.

Installation

pnpm add @payload-kit/audit-logs

Peer dependency: payload (^3.0.0).

Usage

Register auditPlugin in payload.config.ts:

import { buildConfig } from "payload";
import { auditPlugin } from "@payload-kit/audit-logs";

export default buildConfig({
  plugins: [
    auditPlugin({
      collections: {
        orders: { trackDiff: true, trackSnapshot: true },
        inventory: { trackDiff: true },
        media: { trackDiff: false },
        users: {
          trackDiff: true,
          excludeFields: ["password", "totpSecret"],
        },
      },
      trackAuth: true,
      captureMetadata: true,
    }),
  ],
});

Configuration options

OptionTypeDefaultDescription
enabledbooleantrueEnables or disables the plugin. When false, returns the config unchanged.
collectionSlugstring"audit-logs"Slug for the generated audit collection.
adminGroupfalse | string | Record<string, string>undefinedSidebar group in the Payload Admin panel.
usersCollectionSlugstring"users"Slug of the auth collection used for actor relations and auth hooks.
collectionsstring[] | Record<string, AuditCollectionOptions | boolean>all collectionsCollections to monitor. Per-collection options support trackDiff, trackSnapshot, excludeFields, and includeFields.
globalsstring[] | Record<string, AuditCollectionOptions | boolean>all globalsGlobals to monitor.
trackAuthbooleantrueRecords login and logout events on usersCollectionSlug.
captureMetadatabooleantrueCaptures client IP and User-Agent headers from the request.
resolveClientIp(req: PayloadRequest) => string | null | undefinedx-forwarded-for / x-real-ipCustom client IP resolver (e.g. Cloudflare cf-connecting-ip or right-most trusted proxy hop). Output is validated as IP.
globalExcludeFieldsstring[]built-in sensitive listAdditional field names redacted across all monitored collections and globals.
access{ read?, delete?, prune? }admin-only read, immutable writesOverrides access control for reading logs, deleting logs, and calling /prune.
retentionAuditRetentionOptionsundefinedLog retention limits and optional Payload Jobs Queue task.

Reverse proxies and client IP resolution

By default, @payload-kit/audit-logs resolves client IPs from x-forwarded-for (first entry) and falls back to x-real-ip. Provider-specific headers such as cf-connecting-ip are not read by default to avoid header spoofing outside that provider.

Use clientIpResolvers presets or pass a custom resolveClientIp(req) callback:

import { auditPlugin, clientIpResolvers } from "@payload-kit/audit-logs";

// Behind Cloudflare (`cf-connecting-ip`)
auditPlugin({ resolveClientIp: clientIpResolvers.cloudflare });

// Behind AWS ALB / Nginx / Caddy (1 trusted proxy appending to `x-forwarded-for`)
auditPlugin({ resolveClientIp: clientIpResolvers.forwardedFor({ trustedHops: 1 }) });

// Behind Vercel (`x-vercel-forwarded-for`), Fly.io (`fly-client-ip`), Fastly (`fastly-client-ip`), or a custom header
auditPlugin({ resolveClientIp: clientIpResolvers.vercel });
auditPlugin({ resolveClientIp: clientIpResolvers.header("true-client-ip") });

Retention and pruning

Configure retention to prune older entries by age (days), total count (maxRecords), or both. Setting job.enabled: true registers a Payload Jobs Queue task and exposes POST /api/<collectionSlug>/prune for manual or webhook runs.

auditPlugin({
  retention: {
    days: 60,
    maxRecords: 10000,
    job: {
      enabled: true,
      taskSlug: "pruneAuditLogs",
      cron: "0 3 * * *",
    },
  },
});

Behavior and gotchas

  • Default access rules block API writes on the audit collection (create, update, and delete return false).
  • Sensitive fields (passwords, hashes, salts, reset tokens, and TOTP secrets) are stripped from diffs and snapshots before storage.
  • Hooks pass req through so audit writes share the active database transaction.
  • Set req.context.skipAudit = true on internal Local API calls when you want to bypass audit logging or avoid recursive hooks.
  • Admin UI labels ship in English (en) and European Portuguese (pt).

License

MIT

Similar plugins