@contractspec/module.audit-trail 0.0.0-canary-20260113162409

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 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,7 @@
1
+ import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
2
+
3
+ //#region src/audit-trail.capability.d.ts
4
+ declare const AuditTrailCapability: _contractspec_lib_contracts0.CapabilitySpec;
5
+ //#endregion
6
+ export { AuditTrailCapability };
7
+ //# sourceMappingURL=audit-trail.capability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-trail.capability.d.ts","names":[],"sources":["../src/audit-trail.capability.ts"],"sourcesContent":[],"mappings":";;;cAEa,sBAUX,4BAAA,CAV+B"}
@@ -0,0 +1,20 @@
1
+ import { StabilityEnum, defineCapability } from "@contractspec/lib.contracts";
2
+
3
+ //#region src/audit-trail.capability.ts
4
+ const AuditTrailCapability = defineCapability({ meta: {
5
+ key: "audit-trail",
6
+ version: "1.0.0",
7
+ kind: "data",
8
+ stability: StabilityEnum.Experimental,
9
+ description: "Audit logging and compliance tracking",
10
+ owners: ["@platform.core"],
11
+ tags: [
12
+ "audit",
13
+ "logging",
14
+ "compliance"
15
+ ]
16
+ } });
17
+
18
+ //#endregion
19
+ export { AuditTrailCapability };
20
+ //# sourceMappingURL=audit-trail.capability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-trail.capability.js","names":[],"sources":["../src/audit-trail.capability.ts"],"sourcesContent":["import { defineCapability, StabilityEnum } from '@contractspec/lib.contracts';\n\nexport const AuditTrailCapability = defineCapability({\n meta: {\n key: 'audit-trail',\n version: '1.0.0',\n kind: 'data',\n stability: StabilityEnum.Experimental,\n description: 'Audit logging and compliance tracking',\n owners: ['@platform.core'],\n tags: ['audit', 'logging', 'compliance'],\n },\n});\n"],"mappings":";;;AAEA,MAAa,uBAAuB,iBAAiB,EACnD,MAAM;CACJ,KAAK;CACL,SAAS;CACT,MAAM;CACN,WAAW,cAAc;CACzB,aAAa;CACb,QAAQ,CAAC,iBAAiB;CAC1B,MAAM;EAAC;EAAS;EAAW;EAAa;CACzC,EACF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import * as _contractspec_lib_contracts0 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: _contractspec_lib_contracts0.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":";;;;;;;AAWA;cAAa,mBAkCX,4BAAA,CAlC4B"}
@@ -0,0 +1,66 @@
1
+ import { defineFeature } from "@contractspec/lib.contracts";
2
+
3
+ //#region src/audit-trail.feature.ts
4
+ /**
5
+ * Audit Trail Feature Module Specification
6
+ *
7
+ * Defines the feature module for audit logging and compliance.
8
+ */
9
+ /**
10
+ * Audit Trail feature module that bundles audit log querying,
11
+ * export, and statistics capabilities.
12
+ */
13
+ const AuditTrailFeature = defineFeature({
14
+ meta: {
15
+ key: "audit-trail",
16
+ title: "Audit Trail",
17
+ description: "Audit logging, querying, export, and compliance reporting",
18
+ domain: "platform",
19
+ version: "1.0.0",
20
+ owners: ["@platform.audit-trail"],
21
+ tags: [
22
+ "audit",
23
+ "compliance",
24
+ "logging",
25
+ "security"
26
+ ],
27
+ stability: "stable"
28
+ },
29
+ operations: [
30
+ {
31
+ key: "audit.logs.export",
32
+ version: "1.0.0"
33
+ },
34
+ {
35
+ key: "audit.logs.query",
36
+ version: "1.0.0"
37
+ },
38
+ {
39
+ key: "audit.logs.get",
40
+ version: "1.0.0"
41
+ },
42
+ {
43
+ key: "audit.trace.get",
44
+ version: "1.0.0"
45
+ },
46
+ {
47
+ key: "audit.stats",
48
+ version: "1.0.0"
49
+ }
50
+ ],
51
+ events: [],
52
+ presentations: [],
53
+ opToPresentation: [],
54
+ presentationsTargets: [],
55
+ capabilities: {
56
+ provides: [{
57
+ key: "audit-trail",
58
+ version: "1.0.0"
59
+ }],
60
+ requires: []
61
+ }
62
+ });
63
+
64
+ //#endregion
65
+ export { AuditTrailFeature };
66
+ //# sourceMappingURL=audit-trail.feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-trail.feature.js","names":[],"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 { defineFeature } 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 = defineFeature({\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.0.0',\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.0.0' },\n { key: 'audit.logs.query', version: '1.0.0' },\n { key: 'audit.logs.get', version: '1.0.0' },\n { key: 'audit.trace.get', version: '1.0.0' },\n { key: 'audit.stats', version: '1.0.0' },\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.0.0' }],\n requires: [],\n },\n});\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,oBAAoB,cAAc;CAC7C,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;GAAS;EAC9C;GAAE,KAAK;GAAoB,SAAS;GAAS;EAC7C;GAAE,KAAK;GAAkB,SAAS;GAAS;EAC3C;GAAE,KAAK;GAAmB,SAAS;GAAS;EAC5C;GAAE,KAAK;GAAe,SAAS;GAAS;EACzC;CAGD,QAAQ,EAAE;CAGV,eAAe,EAAE;CACjB,kBAAkB,EAAE;CACpB,sBAAsB,EAAE;CAGxB,cAAc;EACZ,UAAU,CAAC;GAAE,KAAK;GAAe,SAAS;GAAS,CAAC;EACpD,UAAU,EAAE;EACb;CACF,CAAC"}