@nestjs-dash/audit-log 1.0.0 → 1.0.2

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 +60 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @nestjs-dash/audit-log
2
+
3
+ The audit-log plugin for nestjs-dash — persists a resource-mutation audit trail and provides a built-in, read-only **Activity** resource for browsing it.
4
+
5
+ ## Architecture: a core + plugin split
6
+
7
+ Audit logging isn't a `panel.plugins([...])` entry you add — it's split between core and this plugin:
8
+
9
+ - **Core** (`@nestjs-dash/nestjs`) always runs `AdminAuditInterceptor` on every `AdminController` route, regardless of whether this plugin is installed. It decides *what* to audit (every `@AdminAction(...)`-tagged mutating route, skipping `'view'`) and builds the `before`/`after` payload — but does nothing with that payload unless auditing is turned on.
10
+ - **This plugin** supplies the actual persistence (`AuditLogEntity`, a TypeORM table) and the read-only `AdminActivityResource` for browsing it. `AdminModule` dynamically `import()`s this package at bootstrap only when `audit.enabled` is `true` — it's an ordinary `package.json` dependency, but you never import or wire `AdminActivityResource` into `panel.resources` yourself; `AdminModule` registers it for you under the "System" nav group.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pnpm add @nestjs-dash/audit-log
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import { AdminModule } from '@nestjs-dash/nestjs';
22
+
23
+ AdminModule.forRootAsync({
24
+ inject: [DataSource],
25
+ useFactory: (dataSource: DataSource) => ({
26
+ autoBindTypeOrm: true,
27
+ dataSource, // required — audit storage is TypeORM-only, and unlike
28
+ // `autoBindTypeOrm` (which can find a DataSource via Nest DI on its
29
+ // own), audit logging insists on getting one explicitly.
30
+ audit: { enabled: true },
31
+ // ...
32
+ }),
33
+ });
34
+ ```
35
+
36
+ `AuditLogEntity` must be listed in your `TypeOrmModule.forRootAsync`'s `entities: [...]` array explicitly — TypeORM's `DataSource` only knows about entities passed there at connection time; it won't discover `AuditLogEntity` just because this package gets `import()`-ed at Nest bootstrap.
37
+
38
+ ## Querying the audit trail yourself
39
+
40
+ `AuditLogEntity` is a normal TypeORM entity — query it directly (e.g. for dashboard widgets) rather than going through `AdminActivityResource`'s adapter:
41
+
42
+ ```ts
43
+ import { AuditLogEntity } from '@nestjs-dash/audit-log';
44
+
45
+ const eventsToday = await dataSource
46
+ .getRepository(AuditLogEntity)
47
+ .count({ where: { createdAt: MoreThanOrEqual(startOfToday) } });
48
+ ```
49
+
50
+ ## What gets logged
51
+
52
+ Every create/update/delete/bulk-action/relation-manager mutation made through the admin UI or the JSON API, with the actor, the resource/record touched, and the full `before`/`after` snapshot.
53
+
54
+ ## Part of nestjs-dash
55
+
56
+ This package is one piece of [nestjs-dash](https://github.com/nestjs-dash/nestjs-dash), a NestJS-native admin framework. See the `example-audit-log` demo app for a complete walkthrough, including dashboard widgets built on `AuditLogEntity`.
57
+
58
+ ## License
59
+
60
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs-dash/audit-log",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Audit log plugin for NestJS Dash (resource-mutation audit trail + built-in read-only Activity resource)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@nestjs-dash/core": "1.0.0",
21
- "@nestjs-dash/nestjs": "1.0.0"
20
+ "@nestjs-dash/core": "1.1.0",
21
+ "@nestjs-dash/nestjs": "1.1.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@nestjs-dash/typescript-config": "0.1.0",