@explita/prisma-audit-log 0.2.1 → 0.2.3
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.
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ const prisma = new PrismaClient().$extends(
|
|
|
102
102
|
},
|
|
103
103
|
|
|
104
104
|
// Timestamp-only updates are skipped automatically, so no extra config needed
|
|
105
|
-
})
|
|
105
|
+
}),
|
|
106
106
|
);
|
|
107
107
|
```
|
|
108
108
|
|
|
@@ -164,10 +164,11 @@ route.put("/test/:id", async (request, reply) => {
|
|
|
164
164
|
| `maskValue` | `any` | Value to use for masked fields (default: `[REDACTED]`) |
|
|
165
165
|
| `maxStringLength` | `number` | Truncate long strings |
|
|
166
166
|
| `maxArrayLength` | `number` | Truncate large arrays |
|
|
167
|
+
| `enabled` | `boolean` | Enable or disable audit logging (defaults to `true`) |
|
|
167
168
|
| `maxPayloadBytes` | `number` | Maximum JSON payload size (before truncation) |
|
|
168
169
|
| `fieldFilters` | `{ [model: string]: { include?: string[]; exclude?: string[] } }` | Configure field inclusion/exclusion per model. Use `include` to whitelist fields or `exclude` to blacklist them. |
|
|
169
170
|
| `skip` | `(params: { model: string; operation: string; args: any }) => boolean \| Promise<boolean>` | Skip logging for specific operations |
|
|
170
|
-
| `logger` | `(log: AuditLog
|
|
171
|
+
| `logger` | `(log: AuditLog[]) => void \| Promise<void>` | Custom logger function for audit logs |
|
|
171
172
|
|
|
172
173
|
## License
|
|
173
174
|
|
|
@@ -2,4 +2,4 @@ import type { AuditLogOptions } from "../types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates a Prisma extension that adds audit logging
|
|
4
4
|
*/
|
|
5
|
-
export declare function auditLogExtension(
|
|
5
|
+
export declare function auditLogExtension(opts?: AuditLogOptions): (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client").InternalArgs<{}, {}, {}, {}> & import("@prisma/client/runtime/client").DefaultArgs>;
|
|
@@ -13,7 +13,8 @@ const upsert_js_1 = require("../core/upsert.js");
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a Prisma extension that adds audit logging
|
|
15
15
|
*/
|
|
16
|
-
function auditLogExtension(
|
|
16
|
+
function auditLogExtension(opts = {}) {
|
|
17
|
+
const options = { enabled: true, ...opts };
|
|
17
18
|
return extension_1.Prisma.defineExtension((prisma) => {
|
|
18
19
|
return prisma.$extends({
|
|
19
20
|
name: "auditLogExtension",
|
|
@@ -25,8 +26,8 @@ function auditLogExtension(options = {}) {
|
|
|
25
26
|
if (["auditLog", "AuditLog"].includes(modelName !== null && modelName !== void 0 ? modelName : "")) {
|
|
26
27
|
return query(args);
|
|
27
28
|
}
|
|
28
|
-
// Skip if model is excluded or not included
|
|
29
|
-
if ((0, utils_js_1.shouldSkipModel)(modelName, options)) {
|
|
29
|
+
// Skip if model is excluded or not included or disabled
|
|
30
|
+
if (!options.enabled || (0, utils_js_1.shouldSkipModel)(modelName, options)) {
|
|
30
31
|
return query(args);
|
|
31
32
|
}
|
|
32
33
|
// Check if the operation should be skipped via the skip callback
|
|
@@ -39,6 +39,9 @@ function maskAndTruncate(value, opts, keyPath = []) {
|
|
|
39
39
|
const limited = maxArrayLength ? value.slice(0, maxArrayLength) : value;
|
|
40
40
|
return limited.map((v, i) => maskAndTruncate(v, opts, [...keyPath, String(i)]));
|
|
41
41
|
}
|
|
42
|
+
if (typeof value === "bigint") {
|
|
43
|
+
return value.toString();
|
|
44
|
+
}
|
|
42
45
|
// Handle Decimal type from Prisma
|
|
43
46
|
if (value &&
|
|
44
47
|
typeof value === "object" &&
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { JsArgs } from "@prisma/client/runtime/client";
|
|
2
2
|
export interface AuditLogOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Enable or disable audit logging
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
enabled?: boolean;
|
|
3
8
|
/**
|
|
4
9
|
* Function to determine if audit logging should be skipped for the current operation
|
|
5
10
|
* @returns true to skip logging, false or undefined to continue with logging
|
|
@@ -37,7 +42,7 @@ export interface AuditLogOptions {
|
|
|
37
42
|
* Custom logger function
|
|
38
43
|
* If not provided, logs will be written to console
|
|
39
44
|
*/
|
|
40
|
-
logger?: (log: AuditLog
|
|
45
|
+
logger?: (log: AuditLog[]) => void | Promise<void>;
|
|
41
46
|
/**
|
|
42
47
|
* Keys to mask in oldData/newData/metadata. Exact match on property name.
|
|
43
48
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@explita/prisma-audit-log",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A Prisma extension for automatic audit logging",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,11 +12,20 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "Explita",
|
|
15
|
+
"sideEffects": false,
|
|
15
16
|
"scripts": {
|
|
16
17
|
"clean": "rimraf dist",
|
|
17
18
|
"build": "npm run clean && tsc",
|
|
18
19
|
"prepublishOnly": "npm run build"
|
|
19
20
|
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/explita/prisma-audit-log.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/explita/prisma-audit-log/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/explita/prisma-audit-log#readme",
|
|
20
29
|
"peerDependencies": {
|
|
21
30
|
"@prisma/client": "^7"
|
|
22
31
|
},
|