@geekmidas/audit 2.1.0 → 2.2.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.
- package/CHANGELOG.md +30 -0
- package/README.md +74 -2
- package/dist/{Auditor-_Dn2dp8d.d.mts → Auditor-CW2NrfHS.d.mts} +30 -2
- package/dist/Auditor-CW2NrfHS.d.mts.map +1 -0
- package/dist/{Auditor-sW7YAJIA.d.cts → Auditor-DpBHXIJM.d.cts} +30 -2
- package/dist/Auditor-DpBHXIJM.d.cts.map +1 -0
- package/dist/Auditor.d.cts +1 -1
- package/dist/Auditor.d.mts +1 -1
- package/dist/{DefaultAuditor-BSYMwojG.d.cts → DefaultAuditor-DlJ1ENfx.d.mts} +2 -2
- package/dist/{DefaultAuditor-BSYMwojG.d.cts.map → DefaultAuditor-DlJ1ENfx.d.mts.map} +1 -1
- package/dist/{DefaultAuditor-CYE-uAry.d.mts → DefaultAuditor-GRFI86N_.d.cts} +2 -2
- package/dist/{DefaultAuditor-CYE-uAry.d.mts.map → DefaultAuditor-GRFI86N_.d.cts.map} +1 -1
- package/dist/DefaultAuditor.d.cts +2 -2
- package/dist/DefaultAuditor.d.mts +2 -2
- package/dist/{cache-2VI80Vao.d.mts → cache-Bih6HxY6.d.cts} +2 -2
- package/dist/{cache-2VI80Vao.d.mts.map → cache-Bih6HxY6.d.cts.map} +1 -1
- package/dist/{cache-CDHqXqcl.d.cts → cache-wET57t6d.d.mts} +2 -2
- package/dist/{cache-CDHqXqcl.d.cts.map → cache-wET57t6d.d.mts.map} +1 -1
- package/dist/cache.d.cts +2 -2
- package/dist/cache.d.mts +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/knex.cjs +233 -0
- package/dist/knex.cjs.map +1 -0
- package/dist/knex.d.cts +178 -0
- package/dist/knex.d.cts.map +1 -0
- package/dist/knex.d.mts +178 -0
- package/dist/knex.d.mts.map +1 -0
- package/dist/knex.mjs +231 -0
- package/dist/knex.mjs.map +1 -0
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +1 -29
- package/dist/kysely.d.cts.map +1 -1
- package/dist/kysely.d.mts +1 -29
- package/dist/kysely.d.mts.map +1 -1
- package/dist/kysely.mjs.map +1 -1
- package/dist/memory.d.cts +2 -2
- package/dist/memory.d.mts +2 -2
- package/dist/storage.d.cts +2 -2
- package/dist/storage.d.mts +2 -2
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +20 -5
- package/src/__tests__/KnexAuditStorage.integration.spec.ts +739 -0
- package/src/knex.ts +430 -0
- package/src/kysely.ts +6 -28
- package/src/storage.ts +28 -0
- package/dist/Auditor-_Dn2dp8d.d.mts.map +0 -1
- package/dist/Auditor-sW7YAJIA.d.cts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @geekmidas/audit
|
|
2
2
|
|
|
3
|
+
## 2.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
8
|
+
registry. The previous release only published the four packages that had
|
|
9
|
+
version bumps; the remaining packages failed with "cannot publish over the
|
|
10
|
+
previously published versions" because their versions were unchanged.
|
|
11
|
+
- Updated dependencies [[`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309)]:
|
|
12
|
+
- @geekmidas/cache@1.1.2
|
|
13
|
+
- @geekmidas/schema@1.0.4
|
|
14
|
+
|
|
15
|
+
## 2.2.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- ✨ [#10](https://github.com/geekmidas/toolbox/pull/10) [`ae678fe`](https://github.com/geekmidas/toolbox/commit/ae678fe6fbc89307d052335468f1b955b306a604) Thanks [@geekmidas](https://github.com/geekmidas)! - Add Knex audit storage via a new `@geekmidas/audit/knex` entry point.
|
|
20
|
+
|
|
21
|
+
`KnexAuditStorage` mirrors `KyselyAuditStorage` — same config (`db`,
|
|
22
|
+
`tableName`, `databaseServiceName`, `autoId`), same `query()`/`count()`
|
|
23
|
+
filters, and the same transaction semantics. A `withAuditableTransaction`
|
|
24
|
+
helper is included; passing an existing transaction reuses it instead of
|
|
25
|
+
opening a savepoint, so audits roll back with the outer transaction.
|
|
26
|
+
|
|
27
|
+
Because it implements `withTransaction()`, `getDatabase()` and
|
|
28
|
+
`databaseServiceName`, endpoints wrap handlers and audit flushes in a single
|
|
29
|
+
transaction with Knex just as they do with Kysely.
|
|
30
|
+
|
|
31
|
+
`knex` is an optional peer dependency, so Kysely-only users are unaffected.
|
|
32
|
+
|
|
3
33
|
## 2.1.0
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
- **Type-safe Audit Actions**: Define audit types with TypeScript for compile-time safety
|
|
12
12
|
- **Transactional Support**: Flush audits atomically within database transactions
|
|
13
|
-
- **Flexible Storage**: Pluggable storage interface (Kysely, in-memory, cache)
|
|
13
|
+
- **Flexible Storage**: Pluggable storage interface (Kysely, Knex, in-memory, cache)
|
|
14
14
|
- **Actor Tracking**: Record who performed each action (users, services, systems)
|
|
15
15
|
- **Rich Metadata**: Attach request context, entity references, and custom data
|
|
16
16
|
- **Query Support**: Query audit logs with filters, pagination, and sorting
|
|
@@ -70,6 +70,17 @@ const storage = new KyselyAuditStorage<Database>({
|
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
**For Production (KnexAuditStorage):**
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { KnexAuditStorage } from '@geekmidas/audit/knex';
|
|
77
|
+
|
|
78
|
+
const storage = new KnexAuditStorage({
|
|
79
|
+
db: knexDb,
|
|
80
|
+
tableName: 'audit_logs',
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
73
84
|
### 3. Create an Auditor
|
|
74
85
|
|
|
75
86
|
```typescript
|
|
@@ -275,6 +286,67 @@ const count = await storage.count({
|
|
|
275
286
|
});
|
|
276
287
|
```
|
|
277
288
|
|
|
289
|
+
### `KnexAuditStorage`
|
|
290
|
+
|
|
291
|
+
Built-in Knex storage implementation. It mirrors `KyselyAuditStorage` — same
|
|
292
|
+
config, same `query()`/`count()` filters, same transaction semantics:
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { KnexAuditStorage } from '@geekmidas/audit/knex';
|
|
296
|
+
|
|
297
|
+
const storage = new KnexAuditStorage({
|
|
298
|
+
db: knexDb,
|
|
299
|
+
tableName: 'audit_logs',
|
|
300
|
+
databaseServiceName: 'database', // Optional: for automatic transaction injection
|
|
301
|
+
autoId: false, // Optional: let database generate IDs
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const audits = await storage.query({
|
|
305
|
+
type: 'user.created',
|
|
306
|
+
actorId: 'user-123',
|
|
307
|
+
from: new Date('2024-01-01'),
|
|
308
|
+
limit: 100,
|
|
309
|
+
orderBy: 'timestamp',
|
|
310
|
+
orderDirection: 'desc',
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const count = await storage.count({
|
|
314
|
+
type: ['user.created', 'user.updated'],
|
|
315
|
+
actorId: 'user-123',
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Column names are camelCase, matching the Kysely storage. If your database uses
|
|
320
|
+
snake_case columns, configure Knex with a case mapper:
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { knexSnakeCaseMappers } from 'objection';
|
|
324
|
+
|
|
325
|
+
const knexDb = knex({
|
|
326
|
+
client: 'pg',
|
|
327
|
+
connection: process.env.DATABASE_URL,
|
|
328
|
+
...knexSnakeCaseMappers(),
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Transactions work the same way as the Kysely storage:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import { withAuditableTransaction } from '@geekmidas/audit/knex';
|
|
336
|
+
|
|
337
|
+
const user = await withAuditableTransaction(knexDb, auditor, async (trx) => {
|
|
338
|
+
const [user] = await trx('users').insert(data).returning('*');
|
|
339
|
+
|
|
340
|
+
auditor.audit('user.created', { userId: user.id, email: user.email });
|
|
341
|
+
|
|
342
|
+
return user;
|
|
343
|
+
});
|
|
344
|
+
// Audits are flushed inside the transaction, before it commits
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Passing a transaction as the first argument reuses it instead of opening a
|
|
348
|
+
savepoint, so audits roll back with the outer transaction.
|
|
349
|
+
|
|
278
350
|
### `InMemoryAuditStorage`
|
|
279
351
|
|
|
280
352
|
Convenience wrapper around `CacheAuditStorage` with `InMemoryCache`. Useful for testing and development:
|
|
@@ -332,7 +404,7 @@ await storage.clear();
|
|
|
332
404
|
|
|
333
405
|
## Database Schema
|
|
334
406
|
|
|
335
|
-
Create an `audit_logs` table for `KyselyAuditStorage`:
|
|
407
|
+
Create an `audit_logs` table for `KyselyAuditStorage` or `KnexAuditStorage`:
|
|
336
408
|
|
|
337
409
|
```sql
|
|
338
410
|
CREATE TABLE audit_logs (
|
|
@@ -2,6 +2,34 @@ import { InferStandardSchema } from "@geekmidas/schema";
|
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/storage.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal interface for transaction-aware audit flushing.
|
|
8
|
+
* Use this when you need to flush audits within a database transaction.
|
|
9
|
+
*
|
|
10
|
+
* @template TTransaction - Transaction type (e.g., Kysely `Transaction`, Knex `Transaction`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { withAuditableTransaction } from '@geekmidas/audit/kysely';
|
|
15
|
+
* import type { TransactionAwareAuditor } from '@geekmidas/audit/kysely';
|
|
16
|
+
*
|
|
17
|
+
* const result = await withAuditableTransaction(
|
|
18
|
+
* db,
|
|
19
|
+
* auditor as TransactionAwareAuditor<Transaction<DB>>,
|
|
20
|
+
* async (trx) => {
|
|
21
|
+
* // Your transactional operations
|
|
22
|
+
* return result;
|
|
23
|
+
* },
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface TransactionAwareAuditor<TTransaction = unknown> {
|
|
28
|
+
/** Register the transaction with the auditor for use during flush */
|
|
29
|
+
setTransaction(trx: TTransaction): void;
|
|
30
|
+
/** Flush all pending audits, optionally within a transaction */
|
|
31
|
+
flush(trx?: TTransaction): Promise<void>;
|
|
32
|
+
}
|
|
5
33
|
/**
|
|
6
34
|
* Options for querying audit records.
|
|
7
35
|
*/
|
|
@@ -422,5 +450,5 @@ interface Auditor<TAuditAction extends AuditableAction<string, unknown> = Audita
|
|
|
422
450
|
//# sourceMappingURL=Auditor.d.ts.map
|
|
423
451
|
|
|
424
452
|
//#endregion
|
|
425
|
-
export { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit };
|
|
426
|
-
//# sourceMappingURL=Auditor-
|
|
453
|
+
export { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit, TransactionAwareAuditor };
|
|
454
|
+
//# sourceMappingURL=Auditor-CW2NrfHS.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Auditor-CW2NrfHS.d.mts","names":[],"sources":["../src/storage.ts","../src/types.ts","../src/Audit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;;;;;AAC8B;AAK/D;EAKiB,MAAA,CAAA,MAAU,ECqCX,IDrCW,CCqCN,WDrCM,EAAA,IAAA,GAAA,WAAA,GAAA,OAAA,CAAA,CAAA,EAAA,IAAA;EAYV;AAkBjB;;;EAM0B,UAIL,EAAA,ECGN,WDHM,EAAA;EAAM;;;;;;EAYF,KAAA,CAAA,GAAA,CAAA,ECDZ,YDCY,CAAA,ECDG,ODCH,CAAA,IAAA,CAAA;EAMR;;;;EAMU,KAEd,EAAA,EAAA,IAAA;EAAM;AAEA;AAOnB;;;;;;;;;;;;;;;;EAc+B,WAChB,CAAA,QAAA,ECbQ,aDaR,CAAA,EAAA,IAAA;EAAM;AAQrB;;;;;AAAoE;AAKpE;;;;;;AACsD;;;;ACrHtD;;;;;;;;EAsCa,cACkB,CAAA,GAAA,EA8EV,YA9EU,CAAA,EAAA,IAAA;EAAY;;;;EAWX,cAAhB,EAAA,EAyEG,YAzEH,GAAA,SAAA"}
|
|
@@ -2,6 +2,34 @@ import { InferStandardSchema } from "@geekmidas/schema";
|
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/storage.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal interface for transaction-aware audit flushing.
|
|
8
|
+
* Use this when you need to flush audits within a database transaction.
|
|
9
|
+
*
|
|
10
|
+
* @template TTransaction - Transaction type (e.g., Kysely `Transaction`, Knex `Transaction`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { withAuditableTransaction } from '@geekmidas/audit/kysely';
|
|
15
|
+
* import type { TransactionAwareAuditor } from '@geekmidas/audit/kysely';
|
|
16
|
+
*
|
|
17
|
+
* const result = await withAuditableTransaction(
|
|
18
|
+
* db,
|
|
19
|
+
* auditor as TransactionAwareAuditor<Transaction<DB>>,
|
|
20
|
+
* async (trx) => {
|
|
21
|
+
* // Your transactional operations
|
|
22
|
+
* return result;
|
|
23
|
+
* },
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface TransactionAwareAuditor<TTransaction = unknown> {
|
|
28
|
+
/** Register the transaction with the auditor for use during flush */
|
|
29
|
+
setTransaction(trx: TTransaction): void;
|
|
30
|
+
/** Flush all pending audits, optionally within a transaction */
|
|
31
|
+
flush(trx?: TTransaction): Promise<void>;
|
|
32
|
+
}
|
|
5
33
|
/**
|
|
6
34
|
* Options for querying audit records.
|
|
7
35
|
*/
|
|
@@ -422,5 +450,5 @@ interface Auditor<TAuditAction extends AuditableAction<string, unknown> = Audita
|
|
|
422
450
|
//# sourceMappingURL=Auditor.d.ts.map
|
|
423
451
|
|
|
424
452
|
//#endregion
|
|
425
|
-
export { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit };
|
|
426
|
-
//# sourceMappingURL=Auditor-
|
|
453
|
+
export { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit, TransactionAwareAuditor };
|
|
454
|
+
//# sourceMappingURL=Auditor-DpBHXIJM.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Auditor-DpBHXIJM.d.cts","names":[],"sources":["../src/storage.ts","../src/types.ts","../src/Auditor.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAuBA;;;;;AAImC;AAMnC;;;;;AAYU;AAwCV;;;;;;AAe+C,UA7E9B,uBA6E8B,CAAA,eAAA,OAAA,CAAA,CAAA;EAAO;EASpB,cAAW,CAAA,GAAA,EApFxB,YAoFwB,CAAA,EAAA,IAAA;EAAW;EAAZ,KAStB,CAAA,GAAA,CAAA,EA3FT,YA2FS,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,ODCH,CAAA,IAAA,CAAA;EAMR;;;;EAMU,KAEd,EAAA,EAAA,IAAA;EAAM;AAEA;AAOnB;;;;;;;;;;;;;;;;EAc+B,WAChB,CAAA,QAAA,ECbQ,aDaR,CAAA,EAAA,IAAA;EAAM;AAQrB;;;;;AAAoE;AAKpE;;;;;;AACsD;;;;ACrHtD;;;;;;;;EAsCa,cACkB,CAAA,GAAA,EA8EV,YA9EU,CAAA,EAAA,IAAA;EAAY;;;;EAWX,cAAhB,EAAA,EAyEG,YAzEH,GAAA,SAAA"}
|
package/dist/Auditor.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Auditor } from "./Auditor-
|
|
1
|
+
import { Auditor } from "./Auditor-DpBHXIJM.cjs";
|
|
2
2
|
export { Auditor };
|
package/dist/Auditor.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Auditor } from "./Auditor-
|
|
1
|
+
import { Auditor } from "./Auditor-CW2NrfHS.mjs";
|
|
2
2
|
export { Auditor };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuditActor, AuditMetadata, AuditOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType } from "./Auditor-
|
|
1
|
+
import { AuditActor, AuditMetadata, AuditOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType } from "./Auditor-CW2NrfHS.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/DefaultAuditor.d.ts
|
|
4
4
|
|
|
@@ -56,4 +56,4 @@ declare class DefaultAuditor<TAuditAction extends AuditableAction<string, unknow
|
|
|
56
56
|
//# sourceMappingURL=DefaultAuditor.d.ts.map
|
|
57
57
|
//#endregion
|
|
58
58
|
export { DefaultAuditor, DefaultAuditorConfig };
|
|
59
|
-
//# sourceMappingURL=DefaultAuditor-
|
|
59
|
+
//# sourceMappingURL=DefaultAuditor-DlJ1ENfx.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultAuditor-
|
|
1
|
+
{"version":3,"file":"DefaultAuditor-DlJ1ENfx.d.mts","names":[],"sources":["../src/DefaultAuditor.ts"],"sourcesContent":[],"mappings":";;;;AAgBA;;;AAIU,UAJO,oBAAA,CAIP;EAAY;EAEG,KAAA,EAJjB,UAIiB;EA0BZ;EAAc,OAAA,EA5BjB,YA4BiB;EAAA;EACU,QAAoB,CAAA,EA3B7C,aA2B6C;EAAe;EAKvC,UAAE,CAAA,EAAA,GAAA,GAAA,MAAA;;;;;;;;;;;;;;;;;;;AAAf;;;;cANP,oCACS,mCAAmC,qEAK5C,QAAQ,cAAc;kBAElB;;;;;;sBAOI;sBAOA,iBAAiB,qBAC9B,gBACG,oBAAoB,cAAc,kBACjC;iBAmBI,KAAK;gBAcN;cAII,eAAe;sBAab;oBAIF;;wBAQI"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuditActor, AuditMetadata, AuditOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType } from "./Auditor-
|
|
1
|
+
import { AuditActor, AuditMetadata, AuditOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType } from "./Auditor-DpBHXIJM.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/DefaultAuditor.d.ts
|
|
4
4
|
|
|
@@ -56,4 +56,4 @@ declare class DefaultAuditor<TAuditAction extends AuditableAction<string, unknow
|
|
|
56
56
|
//# sourceMappingURL=DefaultAuditor.d.ts.map
|
|
57
57
|
//#endregion
|
|
58
58
|
export { DefaultAuditor, DefaultAuditorConfig };
|
|
59
|
-
//# sourceMappingURL=DefaultAuditor-
|
|
59
|
+
//# sourceMappingURL=DefaultAuditor-GRFI86N_.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultAuditor-
|
|
1
|
+
{"version":3,"file":"DefaultAuditor-GRFI86N_.d.cts","names":[],"sources":["../src/DefaultAuditor.ts"],"sourcesContent":[],"mappings":";;;;AAgBA;;;AAIU,UAJO,oBAAA,CAIP;EAAY;EAEG,KAAA,EAJjB,UAIiB;EA0BZ;EAAc,OAAA,EA5BjB,YA4BiB;EAAA;EACU,QAAoB,CAAA,EA3B7C,aA2B6C;EAAe;EAKvC,UAAE,CAAA,EAAA,GAAA,GAAA,MAAA;;;;;;;;;;;;;;;;;;;AAAf;;;;cANP,oCACS,mCAAmC,qEAK5C,QAAQ,cAAc;kBAElB;;;;;;sBAOI;sBAOA,iBAAiB,qBAC9B,gBACG,oBAAoB,cAAc,kBACjC;iBAmBI,KAAK;gBAcN;cAII,eAAe;sBAab;oBAIF;;wBAQI"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./Auditor-
|
|
2
|
-
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-
|
|
1
|
+
import "./Auditor-DpBHXIJM.cjs";
|
|
2
|
+
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-GRFI86N_.cjs";
|
|
3
3
|
export { DefaultAuditor, DefaultAuditorConfig };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./Auditor-
|
|
2
|
-
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-
|
|
1
|
+
import "./Auditor-CW2NrfHS.mjs";
|
|
2
|
+
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-DlJ1ENfx.mjs";
|
|
3
3
|
export { DefaultAuditor, DefaultAuditorConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction } from "./Auditor-
|
|
1
|
+
import { AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction } from "./Auditor-DpBHXIJM.cjs";
|
|
2
2
|
import { Cache } from "@geekmidas/cache";
|
|
3
3
|
|
|
4
4
|
//#region src/cache.d.ts
|
|
@@ -93,4 +93,4 @@ declare class CacheAuditStorage<TAuditAction extends AuditableAction<string, unk
|
|
|
93
93
|
//# sourceMappingURL=cache.d.ts.map
|
|
94
94
|
//#endregion
|
|
95
95
|
export { CacheAuditStorage, CacheAuditStorageConfig };
|
|
96
|
-
//# sourceMappingURL=cache-
|
|
96
|
+
//# sourceMappingURL=cache-Bih6HxY6.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-
|
|
1
|
+
{"version":3,"file":"cache-Bih6HxY6.d.cts","names":[],"sources":["../src/cache.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAqDA;AAA8B,UArDb,uBAAA,CAqDa;EAAA;EACO,KAAoB,EApDjD,KAoDiD;EAAe;;;;;EA+CjC,MAAW,CAAA,EAAA,MAAA;EAAW;;;;EA+BlD,GAQkB,CAAA,EAAA,MAAA;;;;AAlFJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cALZ,uCACS,mCAAmC,6CAI5C,aAAa;;;;;sBAOL;;;;iBAUC,gBAAgB;;;;iBA0BhB,oBAAoB,QAAQ;;;;iBA8BvC,KAAK,yCACZ;;;;gBAQiB,QAAQ;;;;WAOb"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction } from "./Auditor-
|
|
1
|
+
import { AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction } from "./Auditor-CW2NrfHS.mjs";
|
|
2
2
|
import { Cache } from "@geekmidas/cache";
|
|
3
3
|
|
|
4
4
|
//#region src/cache.d.ts
|
|
@@ -93,4 +93,4 @@ declare class CacheAuditStorage<TAuditAction extends AuditableAction<string, unk
|
|
|
93
93
|
//# sourceMappingURL=cache.d.ts.map
|
|
94
94
|
//#endregion
|
|
95
95
|
export { CacheAuditStorage, CacheAuditStorageConfig };
|
|
96
|
-
//# sourceMappingURL=cache-
|
|
96
|
+
//# sourceMappingURL=cache-wET57t6d.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-
|
|
1
|
+
{"version":3,"file":"cache-wET57t6d.d.mts","names":[],"sources":["../src/cache.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAqDA;AAA8B,UArDb,uBAAA,CAqDa;EAAA;EACO,KAAoB,EApDjD,KAoDiD;EAAe;;;;;EA+CjC,MAAW,CAAA,EAAA,MAAA;EAAW;;;;EA+BlD,GAQkB,CAAA,EAAA,MAAA;;;;AAlFJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cALZ,uCACS,mCAAmC,6CAI5C,aAAa;;;;;sBAOL;;;;iBAUC,gBAAgB;;;;iBA0BhB,oBAAoB,QAAQ;;;;iBA8BvC,KAAK,yCACZ;;;;gBAQiB,QAAQ;;;;WAOb"}
|
package/dist/cache.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./Auditor-
|
|
2
|
-
import { CacheAuditStorage, CacheAuditStorageConfig } from "./cache-
|
|
1
|
+
import "./Auditor-DpBHXIJM.cjs";
|
|
2
|
+
import { CacheAuditStorage, CacheAuditStorageConfig } from "./cache-Bih6HxY6.cjs";
|
|
3
3
|
export { CacheAuditStorage, CacheAuditStorageConfig };
|
package/dist/cache.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./Auditor-
|
|
2
|
-
import { CacheAuditStorage, CacheAuditStorageConfig } from "./cache-
|
|
1
|
+
import "./Auditor-CW2NrfHS.mjs";
|
|
2
|
+
import { CacheAuditStorage, CacheAuditStorageConfig } from "./cache-wET57t6d.mjs";
|
|
3
3
|
export { CacheAuditStorage, CacheAuditStorageConfig };
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit } from "./Auditor-
|
|
2
|
-
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-
|
|
1
|
+
import { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit } from "./Auditor-DpBHXIJM.cjs";
|
|
2
|
+
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-GRFI86N_.cjs";
|
|
3
3
|
export { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, DefaultAuditor, DefaultAuditorConfig, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit } from "./Auditor-
|
|
2
|
-
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-
|
|
1
|
+
import { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit } from "./Auditor-CW2NrfHS.mjs";
|
|
2
|
+
import { DefaultAuditor, DefaultAuditorConfig } from "./DefaultAuditor-DlJ1ENfx.mjs";
|
|
3
3
|
export { AuditActor, AuditMetadata, AuditOperation, AuditOptions, AuditQueryOptions, AuditRecord, AuditStorage, AuditableAction, Auditor, DefaultAuditor, DefaultAuditorConfig, ExtractAuditPayload, ExtractAuditType, ExtractAuditorAction, ExtractStorageAuditAction, MappedAudit };
|
package/dist/knex.cjs
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const nanoid = require_chunk.__toESM(require("nanoid"));
|
|
3
|
+
|
|
4
|
+
//#region src/knex.ts
|
|
5
|
+
/**
|
|
6
|
+
* Type guard for an active Knex transaction.
|
|
7
|
+
*
|
|
8
|
+
* Knex marks transaction instances with `isTransaction`, and a completed
|
|
9
|
+
* transaction can no longer be used, so a settled transaction is treated as a
|
|
10
|
+
* plain connection.
|
|
11
|
+
*/
|
|
12
|
+
function isActiveTransaction(connection) {
|
|
13
|
+
return connection.isTransaction === true && !connection.isCompleted();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute a callback within a database transaction with automatic audit handling.
|
|
17
|
+
*
|
|
18
|
+
* This wrapper ensures that:
|
|
19
|
+
* 1. The transaction is automatically registered with the auditor
|
|
20
|
+
* 2. Manual audits (via `auditor.audit()`) are flushed BEFORE the transaction commits
|
|
21
|
+
* 3. If audit flush fails, the entire transaction rolls back
|
|
22
|
+
* 4. If the callback fails, audits are NOT written (atomic consistency)
|
|
23
|
+
*
|
|
24
|
+
* **Note:** Declarative audits (defined via `.audit([...])` on the endpoint builder)
|
|
25
|
+
* are processed AFTER the handler returns, so they run outside this transaction.
|
|
26
|
+
* If you need all audits to be atomic with your database operations, use manual
|
|
27
|
+
* audits via `auditor.audit()` inside this wrapper.
|
|
28
|
+
*
|
|
29
|
+
* @param db - Database connection (Knex instance or Transaction)
|
|
30
|
+
* @param auditor - Auditor instance that will receive the transaction
|
|
31
|
+
* @param cb - Callback to execute within the transaction
|
|
32
|
+
* @param settings - Optional transaction settings (isolation level)
|
|
33
|
+
* @returns The result of the callback
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { withAuditableTransaction } from '@geekmidas/audit/knex';
|
|
38
|
+
*
|
|
39
|
+
* const result = await withAuditableTransaction(
|
|
40
|
+
* services.database,
|
|
41
|
+
* auditor,
|
|
42
|
+
* async (trx) => {
|
|
43
|
+
* const [user] = await trx('users').insert(data).returning('*');
|
|
44
|
+
*
|
|
45
|
+
* // Manual audits are atomic with the transaction
|
|
46
|
+
* auditor.audit('user.created', { userId: user.id, email: user.email });
|
|
47
|
+
*
|
|
48
|
+
* return user;
|
|
49
|
+
* },
|
|
50
|
+
* );
|
|
51
|
+
* // Audits are automatically flushed inside the transaction before commit
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
async function withAuditableTransaction(db, auditor, cb, settings) {
|
|
55
|
+
const execute = async (trx) => {
|
|
56
|
+
auditor.setTransaction(trx);
|
|
57
|
+
const result = await cb(trx);
|
|
58
|
+
await auditor.flush(trx);
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
if (isActiveTransaction(db)) return execute(db);
|
|
62
|
+
return db.transaction(execute, settings);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Knex-based audit storage implementation.
|
|
66
|
+
* Stores audit records in a database table using Knex.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const storage = new KnexAuditStorage({
|
|
71
|
+
* db: knexDb,
|
|
72
|
+
* tableName: 'audit_logs',
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* const auditor = new DefaultAuditor({
|
|
76
|
+
* actor: { id: 'user-123', type: 'user' },
|
|
77
|
+
* storage,
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
var KnexAuditStorage = class {
|
|
82
|
+
db;
|
|
83
|
+
tableName;
|
|
84
|
+
autoId;
|
|
85
|
+
databaseServiceName;
|
|
86
|
+
constructor(config) {
|
|
87
|
+
this.db = config.db;
|
|
88
|
+
this.tableName = config.tableName;
|
|
89
|
+
this.databaseServiceName = config.databaseServiceName;
|
|
90
|
+
this.autoId = config.autoId ?? false;
|
|
91
|
+
}
|
|
92
|
+
async write(records, trx) {
|
|
93
|
+
if (records.length === 0) return;
|
|
94
|
+
const db = trx ?? this.db;
|
|
95
|
+
const rows = records.map((record) => this.toRow(record));
|
|
96
|
+
await db(this.tableName).insert(rows);
|
|
97
|
+
}
|
|
98
|
+
async query(options) {
|
|
99
|
+
let query = this.db(this.tableName).select("*");
|
|
100
|
+
query = this.applyFilters(query, options);
|
|
101
|
+
const orderBy = options.orderBy ?? "timestamp";
|
|
102
|
+
const orderDirection = options.orderDirection ?? "desc";
|
|
103
|
+
query = query.orderBy(orderBy === "timestamp" ? "timestamp" : "type", orderDirection);
|
|
104
|
+
if (options.limit !== void 0) query = query.limit(options.limit);
|
|
105
|
+
if (options.offset !== void 0) query = query.offset(options.offset);
|
|
106
|
+
const rows = await query;
|
|
107
|
+
return rows.map((row) => this.fromRow(row));
|
|
108
|
+
}
|
|
109
|
+
async count(options) {
|
|
110
|
+
let query = this.db(this.tableName).count({ count: "id" });
|
|
111
|
+
query = this.applyFilters(query, options);
|
|
112
|
+
const result = await query.first();
|
|
113
|
+
return Number(result?.count ?? 0);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the Knex database instance for transactional operations.
|
|
117
|
+
* Used by endpoint adaptors to automatically wrap handlers in transactions.
|
|
118
|
+
*/
|
|
119
|
+
getDatabase() {
|
|
120
|
+
return this.db;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Execute a callback within a Knex transaction with automatic audit handling.
|
|
124
|
+
* The auditor is registered with the transaction and audits are flushed
|
|
125
|
+
* before the transaction commits.
|
|
126
|
+
*
|
|
127
|
+
* If the provided db connection is already a transaction, it will be reused
|
|
128
|
+
* instead of opening a savepoint.
|
|
129
|
+
*/
|
|
130
|
+
async withTransaction(auditor, callback, db) {
|
|
131
|
+
const connection = db ?? this.db;
|
|
132
|
+
if (isActiveTransaction(connection)) {
|
|
133
|
+
auditor.setTransaction(connection);
|
|
134
|
+
const result = await callback();
|
|
135
|
+
await auditor.flush(connection);
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
return connection.transaction(async (trx) => {
|
|
139
|
+
auditor.setTransaction(trx);
|
|
140
|
+
const result = await callback();
|
|
141
|
+
await auditor.flush(trx);
|
|
142
|
+
return result;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
applyFilters(query, options) {
|
|
146
|
+
if (options.type !== void 0) if (Array.isArray(options.type)) query = query.whereIn("type", options.type);
|
|
147
|
+
else query = query.where("type", options.type);
|
|
148
|
+
if (options.entityId !== void 0) {
|
|
149
|
+
const entityId = typeof options.entityId === "string" ? options.entityId : JSON.stringify(options.entityId);
|
|
150
|
+
query = query.where("entityId", entityId);
|
|
151
|
+
}
|
|
152
|
+
if (options.table !== void 0) query = query.where("table", options.table);
|
|
153
|
+
if (options.actorId !== void 0) query = query.where("actorId", options.actorId);
|
|
154
|
+
if (options.from !== void 0) query = query.where("timestamp", ">=", options.from);
|
|
155
|
+
if (options.to !== void 0) query = query.where("timestamp", "<=", options.to);
|
|
156
|
+
return query;
|
|
157
|
+
}
|
|
158
|
+
toRow(record) {
|
|
159
|
+
const id = this.autoId ? void 0 : record.id || (0, nanoid.nanoid)();
|
|
160
|
+
return {
|
|
161
|
+
...id && { id },
|
|
162
|
+
type: record.type,
|
|
163
|
+
operation: record.operation,
|
|
164
|
+
table: record.table ?? null,
|
|
165
|
+
entityId: record.entityId === void 0 ? null : typeof record.entityId === "string" ? record.entityId : JSON.stringify(record.entityId),
|
|
166
|
+
oldValues: this.toJsonColumn(record.oldValues),
|
|
167
|
+
newValues: this.toJsonColumn(record.newValues),
|
|
168
|
+
payload: this.toJsonColumn(record.payload),
|
|
169
|
+
timestamp: record.timestamp,
|
|
170
|
+
actorId: record.actor?.id ?? null,
|
|
171
|
+
actorType: record.actor?.type ?? null,
|
|
172
|
+
actorData: record.actor !== void 0 ? this.toJsonColumn(this.getActorData(record.actor)) : null,
|
|
173
|
+
metadata: this.toJsonColumn(record.metadata)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
fromRow(row) {
|
|
177
|
+
const actor = row.actorId !== null || row.actorType !== null ? {
|
|
178
|
+
id: row.actorId ?? void 0,
|
|
179
|
+
type: row.actorType ?? void 0,
|
|
180
|
+
...row.actorData ? this.parseJson(row.actorData) : {}
|
|
181
|
+
} : void 0;
|
|
182
|
+
return {
|
|
183
|
+
id: row.id,
|
|
184
|
+
type: row.type,
|
|
185
|
+
operation: row.operation,
|
|
186
|
+
table: row.table ?? void 0,
|
|
187
|
+
entityId: row.entityId ? this.parseEntityId(row.entityId) : void 0,
|
|
188
|
+
oldValues: row.oldValues ? this.parseJson(row.oldValues) : void 0,
|
|
189
|
+
newValues: row.newValues ? this.parseJson(row.newValues) : void 0,
|
|
190
|
+
payload: row.payload ? this.parseJson(row.payload) : void 0,
|
|
191
|
+
timestamp: row.timestamp,
|
|
192
|
+
actor,
|
|
193
|
+
metadata: row.metadata ? this.parseJson(row.metadata) : void 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Serialize a JSON value for insertion.
|
|
198
|
+
*
|
|
199
|
+
* Unlike Kysely, Knex has no per-column type information to tell a json/jsonb
|
|
200
|
+
* column from an object it should bind as a composite value, so plain objects
|
|
201
|
+
* are stringified before they reach the driver.
|
|
202
|
+
*/
|
|
203
|
+
toJsonColumn(value) {
|
|
204
|
+
if (value === void 0 || value === null) return null;
|
|
205
|
+
return JSON.stringify(value);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Parse a JSON value that may already be parsed (e.g., from jsonb columns).
|
|
209
|
+
*/
|
|
210
|
+
parseJson(value) {
|
|
211
|
+
if (typeof value === "object" && value !== null) return value;
|
|
212
|
+
if (typeof value === "string") return JSON.parse(value);
|
|
213
|
+
return {};
|
|
214
|
+
}
|
|
215
|
+
getActorData(actor) {
|
|
216
|
+
const { id, type,...rest } = actor;
|
|
217
|
+
return rest;
|
|
218
|
+
}
|
|
219
|
+
parseEntityId(entityId) {
|
|
220
|
+
try {
|
|
221
|
+
const parsed = JSON.parse(entityId);
|
|
222
|
+
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
223
|
+
return entityId;
|
|
224
|
+
} catch {
|
|
225
|
+
return entityId;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
//#endregion
|
|
231
|
+
exports.KnexAuditStorage = KnexAuditStorage;
|
|
232
|
+
exports.withAuditableTransaction = withAuditableTransaction;
|
|
233
|
+
//# sourceMappingURL=knex.cjs.map
|