@hacimertgokhan/next-audit 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +58 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @hacimertgokhan/next-audit
2
+
3
+ A lightweight TypeScript library for Next.js to audit backend requests automatically using decorators.
4
+
5
+ ## Features
6
+ - **Easy Integration**: Simply add the `@Audit()` decorator to your controller methods.
7
+ - **Automated Logging**: Captures method, URL, status code, execution duration, and IP.
8
+ - **Data Tracking**: Automatically records `old_value` (for DELETE) and `new_value` (for POST/PUT/PATCH).
9
+ - **MySQL Support**: Built-in adapter for MySQL storage.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @hacimertgokhan/next-audit mysql2 reflect-metadata
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ Create a `audit.conf.ts` file in your project root:
20
+
21
+ ```typescript
22
+ export default {
23
+ database: {
24
+ url: process.env.DATABASE_URL, // e.g., mysql://user:pass@localhost:3306/db
25
+ },
26
+ // Optional: defaults to 'audit_logs'
27
+ tableName: 'audit_logs',
28
+ debug: false
29
+ };
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Use the decorator in your Next.js API route class methods:
35
+
36
+ ```typescript
37
+ import { Audit } from '@hacimertgokhan/next-audit';
38
+ import { NextRequest, NextResponse } from 'next/server';
39
+
40
+ class UserController {
41
+
42
+ @Audit()
43
+ async createUser(req: NextRequest) {
44
+ const data = await req.json();
45
+ // Logic...
46
+ return NextResponse.json({ id: 1, ...data });
47
+ }
48
+
49
+ @Audit()
50
+ async deleteUser(req: NextRequest) {
51
+ // Logic...
52
+ return NextResponse.json({ success: true });
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## License
58
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hacimertgokhan/next-audit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Next.js backend audit system with @Audit decorator",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,4 +28,4 @@
28
28
  "next": "^16.1.3",
29
29
  "typescript": "^5.5.0"
30
30
  }
31
- }
31
+ }