@hacimertgokhan/next-audit
v1.0.5
Published
Next.js backend audit system with @Audit decorator
Maintainers
Readme
@hacimertgokhan/next-audit
A lightweight TypeScript library for Next.js to audit backend requests automatically using decorators.
Features
- Easy Integration: Simply add the
@Audit()decorator to your controller methods. - Automated Logging: Captures method, URL, status code, execution duration, and IP.
- Data Tracking: Automatically records
old_value(for DELETE) andnew_value(for POST/PUT/PATCH). - MySQL Support: Built-in adapter for MySQL storage.
Installation
npm install @hacimertgokhan/next-audit mysql2 reflect-metadataConfiguration
Create a audit.conf.ts file in your project root:
export default {
database: {
url: process.env.DATABASE_URL,
},
tableName: 'audit_logs',
debug: false
};Usage
Use the decorator in your Next.js API route class methods:
import { Audit } from '@hacimertgokhan/next-audit';
import { NextRequest, NextResponse } from 'next/server';
class UserController {
@Audit()
async createUser(req: NextRequest) {
const data = await req.json();
return NextResponse.json({ id: 1, ...data });
}
@Audit()
async deleteUser(req: NextRequest) {
return NextResponse.json({ success: true });
}
}License
ISC
