@contractspec/module.audit-trail 1.44.0
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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/audit-trail.feature.d.ts +12 -0
- package/dist/audit-trail.feature.d.ts.map +1 -0
- package/dist/audit-trail.feature.js +59 -0
- package/dist/audit-trail.feature.js.map +1 -0
- package/dist/contracts/index.d.ts +583 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +370 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/entities/index.d.ts +91 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +126 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/storage/index.d.ts +88 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +112 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @contractspec/module.audit-trail
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Audit trail module for tracking and querying system events in ContractSpec applications.
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides a complete audit logging solution that captures, stores, and queries audit events. Integrates with the event bus to automatically capture domain events and exposes a query API for compliance and debugging.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Event Capture**: Automatic capture of events from the event bus
|
|
15
|
+
- **Persistent Storage**: Multiple storage adapters (Prisma, append-only log)
|
|
16
|
+
- **Rich Querying**: Filter by actor, target, organization, time range
|
|
17
|
+
- **Retention Policies**: Configurable retention and archival
|
|
18
|
+
- **Export**: Export audit logs for compliance reporting
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bun add @contractspec/module.audit-trail
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Entity Specs (for schema generation)
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { auditTrailSchemaContribution } from '@contractspec/module.audit-trail/entities';
|
|
32
|
+
|
|
33
|
+
// Use in schema composition
|
|
34
|
+
const config = {
|
|
35
|
+
modules: [auditTrailSchemaContribution],
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Set Up Audit Capture
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { createAuditCapture, PrismaAuditStorage } from '@contractspec/module.audit-trail';
|
|
43
|
+
import { prisma } from './db';
|
|
44
|
+
|
|
45
|
+
// Create storage adapter
|
|
46
|
+
const storage = new PrismaAuditStorage(prisma);
|
|
47
|
+
|
|
48
|
+
// Create audit capture (connects to event bus)
|
|
49
|
+
const auditCapture = createAuditCapture({
|
|
50
|
+
bus: eventBus,
|
|
51
|
+
storage,
|
|
52
|
+
filters: {
|
|
53
|
+
// Only audit events with audit:true tag or from specific domains
|
|
54
|
+
domains: ['identity', 'billing', 'security'],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Start capturing
|
|
59
|
+
auditCapture.start();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Query Audit Logs
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { AuditLogService } from '@contractspec/module.audit-trail';
|
|
66
|
+
|
|
67
|
+
const service = new AuditLogService(storage);
|
|
68
|
+
|
|
69
|
+
// Query by actor
|
|
70
|
+
const userActions = await service.query({
|
|
71
|
+
actorId: 'user-123',
|
|
72
|
+
from: new Date('2024-01-01'),
|
|
73
|
+
to: new Date(),
|
|
74
|
+
limit: 100,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Query by target
|
|
78
|
+
const resourceChanges = await service.query({
|
|
79
|
+
targetId: 'project-456',
|
|
80
|
+
eventName: 'project.*',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Export for compliance
|
|
84
|
+
const report = await service.export({
|
|
85
|
+
orgId: 'org-789',
|
|
86
|
+
from: new Date('2024-01-01'),
|
|
87
|
+
to: new Date('2024-12-31'),
|
|
88
|
+
format: 'csv',
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Entity Overview
|
|
93
|
+
|
|
94
|
+
| Entity | Description |
|
|
95
|
+
|--------|-------------|
|
|
96
|
+
| AuditLog | Main audit log entry |
|
|
97
|
+
| AuditLogArchive | Archived logs for retention |
|
|
98
|
+
|
|
99
|
+
## Retention
|
|
100
|
+
|
|
101
|
+
Configure retention policies:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const retention = new RetentionPolicy({
|
|
105
|
+
// Keep detailed logs for 90 days
|
|
106
|
+
hotRetentionDays: 90,
|
|
107
|
+
// Archive for 7 years (compliance)
|
|
108
|
+
archiveRetentionDays: 2555,
|
|
109
|
+
// Run cleanup daily at 3 AM
|
|
110
|
+
cleanupSchedule: '0 3 * * *',
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FeatureModuleSpec } from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/audit-trail.feature.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Audit Trail feature module that bundles audit log querying,
|
|
7
|
+
* export, and statistics capabilities.
|
|
8
|
+
*/
|
|
9
|
+
declare const AuditTrailFeature: FeatureModuleSpec;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { AuditTrailFeature };
|
|
12
|
+
//# sourceMappingURL=audit-trail.feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-trail.feature.d.ts","names":[],"sources":["../src/audit-trail.feature.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAWa,mBAAmB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/audit-trail.feature.ts
|
|
2
|
+
/**
|
|
3
|
+
* Audit Trail feature module that bundles audit log querying,
|
|
4
|
+
* export, and statistics capabilities.
|
|
5
|
+
*/
|
|
6
|
+
const AuditTrailFeature = {
|
|
7
|
+
meta: {
|
|
8
|
+
key: "audit-trail",
|
|
9
|
+
title: "Audit Trail",
|
|
10
|
+
description: "Audit logging, querying, export, and compliance reporting",
|
|
11
|
+
domain: "platform",
|
|
12
|
+
version: 1,
|
|
13
|
+
owners: ["@platform.audit-trail"],
|
|
14
|
+
tags: [
|
|
15
|
+
"audit",
|
|
16
|
+
"compliance",
|
|
17
|
+
"logging",
|
|
18
|
+
"security"
|
|
19
|
+
],
|
|
20
|
+
stability: "stable"
|
|
21
|
+
},
|
|
22
|
+
operations: [
|
|
23
|
+
{
|
|
24
|
+
key: "audit.logs.export",
|
|
25
|
+
version: 1
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "audit.logs.query",
|
|
29
|
+
version: 1
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "audit.logs.get",
|
|
33
|
+
version: 1
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "audit.trace.get",
|
|
37
|
+
version: 1
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "audit.stats",
|
|
41
|
+
version: 1
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
events: [],
|
|
45
|
+
presentations: [],
|
|
46
|
+
opToPresentation: [],
|
|
47
|
+
presentationsTargets: [],
|
|
48
|
+
capabilities: {
|
|
49
|
+
provides: [{
|
|
50
|
+
key: "audit-trail",
|
|
51
|
+
version: 1
|
|
52
|
+
}],
|
|
53
|
+
requires: []
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { AuditTrailFeature };
|
|
59
|
+
//# sourceMappingURL=audit-trail.feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-trail.feature.js","names":["AuditTrailFeature: FeatureModuleSpec"],"sources":["../src/audit-trail.feature.ts"],"sourcesContent":["/**\n * Audit Trail Feature Module Specification\n *\n * Defines the feature module for audit logging and compliance.\n */\nimport type { FeatureModuleSpec } from '@contractspec/lib.contracts';\n\n/**\n * Audit Trail feature module that bundles audit log querying,\n * export, and statistics capabilities.\n */\nexport const AuditTrailFeature: FeatureModuleSpec = {\n meta: {\n key: 'audit-trail',\n title: 'Audit Trail',\n description: 'Audit logging, querying, export, and compliance reporting',\n domain: 'platform',\n version: 1,\n owners: ['@platform.audit-trail'],\n tags: ['audit', 'compliance', 'logging', 'security'],\n stability: 'stable',\n },\n\n // All contract operations included in this feature\n operations: [\n { key: 'audit.logs.export', version: 1 },\n { key: 'audit.logs.query', version: 1 },\n { key: 'audit.logs.get', version: 1 },\n { key: 'audit.trace.get', version: 1 },\n { key: 'audit.stats', version: 1 },\n ],\n\n // No events for this feature - it consumes events, doesn't emit them\n events: [],\n\n // No presentations for this module feature\n presentations: [],\n opToPresentation: [],\n presentationsTargets: [],\n\n // Capability definitions\n capabilities: {\n provides: [{ key: 'audit-trail', version: 1 }],\n requires: [],\n },\n};\n"],"mappings":";;;;;AAWA,MAAaA,oBAAuC;CAClD,MAAM;EACJ,KAAK;EACL,OAAO;EACP,aAAa;EACb,QAAQ;EACR,SAAS;EACT,QAAQ,CAAC,wBAAwB;EACjC,MAAM;GAAC;GAAS;GAAc;GAAW;GAAW;EACpD,WAAW;EACZ;CAGD,YAAY;EACV;GAAE,KAAK;GAAqB,SAAS;GAAG;EACxC;GAAE,KAAK;GAAoB,SAAS;GAAG;EACvC;GAAE,KAAK;GAAkB,SAAS;GAAG;EACrC;GAAE,KAAK;GAAmB,SAAS;GAAG;EACtC;GAAE,KAAK;GAAe,SAAS;GAAG;EACnC;CAGD,QAAQ,EAAE;CAGV,eAAe,EAAE;CACjB,kBAAkB,EAAE;CACpB,sBAAsB,EAAE;CAGxB,cAAc;EACZ,UAAU,CAAC;GAAE,KAAK;GAAe,SAAS;GAAG,CAAC;EAC9C,UAAU,EAAE;EACb;CACF"}
|