@groundbrick/audit-service 1.2.2 → 1.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 +3 -3
- package/dist/AuditService.d.ts +1 -1
- package/dist/AuditService.d.ts.map +1 -1
- package/dist/AuditService.js +7 -3
- package/dist/providers/DatabaseAuditProvider.js +3 -3
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +18 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @groundbrick/audit-service
|
|
2
2
|
|
|
3
|
-
Pluggable audit service for asynchronously recording audit events
|
|
3
|
+
Pluggable audit service for asynchronously recording audit events, each associated with an actor and a tenant.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -59,7 +59,7 @@ Singleton service that delegates event persistence to a provider.
|
|
|
59
59
|
|
|
60
60
|
| Method | Description |
|
|
61
61
|
|---|---|
|
|
62
|
-
| `AuditService.getInstance(provider)` | Returns the singleton instance, initializing it with the given provider on first call. |
|
|
62
|
+
| `AuditService.getInstance(provider)` | Returns the singleton instance, initializing it with the given provider on first call. The provider passed in later calls is ignored. |
|
|
63
63
|
| `auditService.log(event)` | Logs an audit event asynchronously (fire-and-forget). Errors are caught and logged to `console.error`. |
|
|
64
64
|
|
|
65
65
|
### `AuditEvent`
|
|
@@ -96,7 +96,7 @@ interface IAuditProvider {
|
|
|
96
96
|
|
|
97
97
|
### `DatabaseAuditProvider`
|
|
98
98
|
|
|
99
|
-
Built-in provider that persists events to a SQL database via a query executor function.
|
|
99
|
+
Built-in provider that persists events to a SQL database via a query executor function. The query uses `$1`..`$9` placeholders (PostgreSQL). `oldValue`, `newValue` and `metadata` are passed as JSON strings, or `null` when absent; `timestamp` defaults to the current date.
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
102
|
const provider = new DatabaseAuditProvider(
|
package/dist/AuditService.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class AuditService {
|
|
|
6
6
|
private constructor();
|
|
7
7
|
static getInstance(provider: IAuditProvider): AuditService;
|
|
8
8
|
/**
|
|
9
|
-
* Registra um evento de auditoria de forma assíncrona (fire-and-forget).
|
|
9
|
+
* Registra um evento de auditoria de forma assíncrona (fire-and-forget). Falhas do provider vão para console.error.
|
|
10
10
|
* @param event O evento de auditoria a ser registrado.
|
|
11
11
|
*/
|
|
12
12
|
log(event: AuditEvent): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuditService.d.ts","sourceRoot":"","sources":["../src/AuditService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAiB;IAEjC,OAAO;WAIO,WAAW,CAAC,QAAQ,EAAE,cAAc,GAAG,YAAY;IAOjE;;;OAGG;IACI,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"AuditService.d.ts","sourceRoot":"","sources":["../src/AuditService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAiB;IAEjC,OAAO;WAIO,WAAW,CAAC,QAAQ,EAAE,cAAc,GAAG,YAAY;IAOjE;;;OAGG;IACI,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CAOpC"}
|
package/dist/AuditService.js
CHANGED
|
@@ -11,11 +11,15 @@ export class AuditService {
|
|
|
11
11
|
return AuditService.instance;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Registra um evento de auditoria de forma assíncrona (fire-and-forget).
|
|
14
|
+
* Registra um evento de auditoria de forma assíncrona (fire-and-forget). Falhas do provider vão para console.error.
|
|
15
15
|
* @param event O evento de auditoria a ser registrado.
|
|
16
16
|
*/
|
|
17
17
|
log(event) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
try {
|
|
19
|
+
this.provider.save(event).catch(console.error);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -15,9 +15,9 @@ export class DatabaseAuditProvider {
|
|
|
15
15
|
action,
|
|
16
16
|
entity,
|
|
17
17
|
entityId,
|
|
18
|
-
oldValue ? JSON.stringify(oldValue) : null,
|
|
19
|
-
newValue ? JSON.stringify(newValue) : null,
|
|
20
|
-
metadata ? JSON.stringify(metadata) : null,
|
|
18
|
+
oldValue != null ? JSON.stringify(oldValue) : null,
|
|
19
|
+
newValue != null ? JSON.stringify(newValue) : null,
|
|
20
|
+
metadata != null ? JSON.stringify(metadata) : null,
|
|
21
21
|
event.timestamp || new Date(),
|
|
22
22
|
];
|
|
23
23
|
await this.executeQuery(query, params);
|
package/dist/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface AuditEvent {
|
|
|
6
6
|
tenantId: string;
|
|
7
7
|
/** A ação que foi realizada. */
|
|
8
8
|
action: AuditAction;
|
|
9
|
-
/** A entidade que foi afetada. Ex: '
|
|
9
|
+
/** A entidade que foi afetada. Ex: 'ORDER', 'CUSTOMER', 'USER'. */
|
|
10
10
|
entity: string;
|
|
11
11
|
/** O ID da entidade que foi afetada. */
|
|
12
12
|
entityId: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9E,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9E,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACtB,wEAAwE;IACxE,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@groundbrick/audit-service",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Serviço de auditoria plugável para registrar eventos de log de forma assíncrona.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
"types": "./dist/index.d.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc -p tsconfig.build.json",
|
|
21
|
-
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
22
|
-
"clean": "rm -rf dist",
|
|
23
|
-
"prepublishOnly": "npm run clean && npm run build",
|
|
24
|
-
"lint": "eslint src --ext .ts",
|
|
25
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
26
|
-
"prepare": "npm run build"
|
|
27
|
-
},
|
|
28
19
|
"keywords": [
|
|
29
20
|
"audit",
|
|
30
21
|
"log",
|
|
@@ -42,9 +33,24 @@
|
|
|
42
33
|
"@typescript-eslint/parser": "^6.19.1",
|
|
43
34
|
"eslint": "^8.56.0",
|
|
44
35
|
"prettier": "^3.2.4",
|
|
45
|
-
"typescript": "^5.3.3"
|
|
36
|
+
"typescript": "^5.3.3",
|
|
37
|
+
"vitest": "^2.1.9"
|
|
46
38
|
},
|
|
47
39
|
"engines": {
|
|
48
40
|
"node": ">=16.0.0"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/200Systems/groundbrick.git",
|
|
45
|
+
"directory": "packages/audit-service"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.build.json",
|
|
49
|
+
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
50
|
+
"clean": "rm -rf dist",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"lint": "eslint src --ext .ts",
|
|
54
|
+
"format": "prettier --write \"src/**/*.ts\""
|
|
49
55
|
}
|
|
50
|
-
}
|
|
56
|
+
}
|