X Enterprises
fastify-xauth-better

pruneAuditLogs(options)

Deletes AuthAuditLog records older than a configurable age, with optional dry-run mode.

pruneAuditLogs(options)

Deletes AuthAuditLog rows older than olderThanDays days. Available on fastify.xauthbetter (shared across all instances — operates on the global Prisma client). Supports a dryRun mode that returns a count without deleting anything.

Signature

fastify.xauthbetter.pruneAuditLogs(options?: {
  olderThanDays?: number
  dryRun?: boolean
}): Promise<{ count: number; deleted: boolean }>

Params

NameTypeRequiredDefaultDescription
options.olderThanDaysnumberNo365Delete logs created more than this many days ago. Must be greater than 0.
options.dryRunbooleanNofalseWhen true, returns the count without deleting

Returns

{ count: number; deleted: boolean }
FieldDescription
countNumber of records deleted (or matching, in dry-run mode)
deletedtrue if records were deleted, false in dry-run mode

Throws

  • Error: olderThanDays must be greater than 0 — invalid retention value

Examples

Delete logs older than 90 days

const result = await fastify.xauthbetter.pruneAuditLogs({ olderThanDays: 90 });
fastify.log.info(`Pruned ${result.count} audit log records`);

Dry run — check count before deleting

const { count } = await fastify.xauthbetter.pruneAuditLogs({
  olderThanDays: 365,
  dryRun: true,
});
fastify.log.info(`${count} audit logs would be deleted`);

// Proceed only if reasonable
if (count < 50000) {
  await fastify.xauthbetter.pruneAuditLogs({ olderThanDays: 365 });
}

See also

AI Context

package: "@xenterprises/fastify-xauth-better"
method: fastify.xauthbetter.pruneAuditLogs(options?) | fastify.xauthbetter.get(name).pruneAuditLogs(options?)
use-when: Delete old audit log entries — run periodically to manage table size
params: olderThanDays (default: retention setting), dryRun
returns: { count, deleted }
Copyright © 2026