@contractspec/module.audit-trail 1.57.0 → 1.58.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.
Files changed (36) hide show
  1. package/dist/audit-trail.capability.d.ts +1 -6
  2. package/dist/audit-trail.capability.d.ts.map +1 -1
  3. package/dist/audit-trail.capability.js +17 -20
  4. package/dist/audit-trail.feature.d.ts +1 -6
  5. package/dist/audit-trail.feature.d.ts.map +1 -1
  6. package/dist/audit-trail.feature.js +31 -64
  7. package/dist/browser/audit-trail.capability.js +16 -0
  8. package/dist/browser/audit-trail.feature.js +32 -0
  9. package/dist/browser/contracts/index.js +241 -0
  10. package/dist/browser/entities/index.js +103 -0
  11. package/dist/browser/index.js +474 -0
  12. package/dist/browser/storage/index.js +101 -0
  13. package/dist/contracts/index.d.ts +549 -555
  14. package/dist/contracts/index.d.ts.map +1 -1
  15. package/dist/contracts/index.js +227 -355
  16. package/dist/entities/index.d.ts +70 -75
  17. package/dist/entities/index.d.ts.map +1 -1
  18. package/dist/entities/index.js +100 -122
  19. package/dist/index.d.ts +6 -6
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +474 -5
  22. package/dist/node/audit-trail.capability.js +16 -0
  23. package/dist/node/audit-trail.feature.js +32 -0
  24. package/dist/node/contracts/index.js +241 -0
  25. package/dist/node/entities/index.js +103 -0
  26. package/dist/node/index.js +474 -0
  27. package/dist/node/storage/index.js +101 -0
  28. package/dist/storage/index.d.ts +59 -63
  29. package/dist/storage/index.d.ts.map +1 -1
  30. package/dist/storage/index.js +100 -110
  31. package/package.json +86 -25
  32. package/dist/audit-trail.capability.js.map +0 -1
  33. package/dist/audit-trail.feature.js.map +0 -1
  34. package/dist/contracts/index.js.map +0 -1
  35. package/dist/entities/index.js.map +0 -1
  36. package/dist/storage/index.js.map +0 -1
@@ -1,87 +1,83 @@
1
- import { AuditQueryOptions, AuditRecord, AuditStorage } from "@contractspec/lib.bus";
2
-
3
- //#region src/storage/index.d.ts
1
+ import type { AuditRecord, AuditQueryOptions, AuditStorage } from '@contractspec/lib.bus';
4
2
  /**
5
3
  * Extended query options for audit storage.
6
4
  */
7
- interface ExtendedAuditQueryOptions extends AuditQueryOptions {
8
- targetType?: string;
9
- clientIp?: string;
10
- sessionId?: string;
11
- orderBy?: 'occurredAt' | 'recordedAt';
12
- orderDir?: 'asc' | 'desc';
5
+ export interface ExtendedAuditQueryOptions extends AuditQueryOptions {
6
+ targetType?: string;
7
+ clientIp?: string;
8
+ sessionId?: string;
9
+ orderBy?: 'occurredAt' | 'recordedAt';
10
+ orderDir?: 'asc' | 'desc';
13
11
  }
14
12
  /**
15
13
  * Audit storage adapter interface with extended capabilities.
16
14
  */
17
- interface AuditStorageAdapter extends AuditStorage {
18
- /** Query audit records with extended options */
19
- query(options: ExtendedAuditQueryOptions): Promise<AuditRecord[]>;
20
- /** Count matching records */
21
- count(options: Omit<ExtendedAuditQueryOptions, 'limit' | 'offset'>): Promise<number>;
22
- /** Get a single record by ID */
23
- getById(id: string): Promise<AuditRecord | null>;
24
- /** Get all records for a trace */
25
- getByTraceId(traceId: string): Promise<AuditRecord[]>;
26
- /** Delete old records (for retention) */
27
- deleteOlderThan(date: Date): Promise<number>;
15
+ export interface AuditStorageAdapter extends AuditStorage {
16
+ /** Query audit records with extended options */
17
+ query(options: ExtendedAuditQueryOptions): Promise<AuditRecord[]>;
18
+ /** Count matching records */
19
+ count(options: Omit<ExtendedAuditQueryOptions, 'limit' | 'offset'>): Promise<number>;
20
+ /** Get a single record by ID */
21
+ getById(id: string): Promise<AuditRecord | null>;
22
+ /** Get all records for a trace */
23
+ getByTraceId(traceId: string): Promise<AuditRecord[]>;
24
+ /** Delete old records (for retention) */
25
+ deleteOlderThan(date: Date): Promise<number>;
28
26
  }
29
27
  /**
30
28
  * In-memory audit storage for development/testing.
31
29
  */
32
- declare class InMemoryAuditStorage implements AuditStorageAdapter {
33
- private records;
34
- store(record: AuditRecord): Promise<void>;
35
- query(options: ExtendedAuditQueryOptions): Promise<AuditRecord[]>;
36
- count(options: Omit<ExtendedAuditQueryOptions, 'limit' | 'offset'>): Promise<number>;
37
- getById(id: string): Promise<AuditRecord | null>;
38
- getByTraceId(traceId: string): Promise<AuditRecord[]>;
39
- deleteOlderThan(date: Date): Promise<number>;
40
- /**
41
- * Get all records (for testing).
42
- */
43
- getAll(): AuditRecord[];
44
- /**
45
- * Clear all records (for testing).
46
- */
47
- clear(): void;
30
+ export declare class InMemoryAuditStorage implements AuditStorageAdapter {
31
+ private records;
32
+ store(record: AuditRecord): Promise<void>;
33
+ query(options: ExtendedAuditQueryOptions): Promise<AuditRecord[]>;
34
+ count(options: Omit<ExtendedAuditQueryOptions, 'limit' | 'offset'>): Promise<number>;
35
+ getById(id: string): Promise<AuditRecord | null>;
36
+ getByTraceId(traceId: string): Promise<AuditRecord[]>;
37
+ deleteOlderThan(date: Date): Promise<number>;
38
+ /**
39
+ * Get all records (for testing).
40
+ */
41
+ getAll(): AuditRecord[];
42
+ /**
43
+ * Clear all records (for testing).
44
+ */
45
+ clear(): void;
48
46
  }
49
47
  /**
50
48
  * Retention policy configuration.
51
49
  */
52
- interface RetentionPolicyConfig {
53
- /** Days to keep detailed logs */
54
- hotRetentionDays: number;
55
- /** Days to keep archived logs (for compliance) */
56
- archiveRetentionDays?: number;
57
- /** Cron expression for cleanup schedule */
58
- cleanupSchedule?: string;
50
+ export interface RetentionPolicyConfig {
51
+ /** Days to keep detailed logs */
52
+ hotRetentionDays: number;
53
+ /** Days to keep archived logs (for compliance) */
54
+ archiveRetentionDays?: number;
55
+ /** Cron expression for cleanup schedule */
56
+ cleanupSchedule?: string;
59
57
  }
60
58
  /**
61
59
  * Retention policy manager.
62
60
  */
63
- declare class RetentionPolicy {
64
- private readonly config;
65
- constructor(config: RetentionPolicyConfig);
66
- /**
67
- * Get the cutoff date for hot storage.
68
- */
69
- getHotCutoff(): Date;
70
- /**
71
- * Get the cutoff date for archive storage.
72
- */
73
- getArchiveCutoff(): Date | null;
74
- /**
75
- * Apply retention policy to storage.
76
- */
77
- apply(storage: AuditStorageAdapter): Promise<{
78
- deletedCount: number;
79
- }>;
61
+ export declare class RetentionPolicy {
62
+ private readonly config;
63
+ constructor(config: RetentionPolicyConfig);
64
+ /**
65
+ * Get the cutoff date for hot storage.
66
+ */
67
+ getHotCutoff(): Date;
68
+ /**
69
+ * Get the cutoff date for archive storage.
70
+ */
71
+ getArchiveCutoff(): Date | null;
72
+ /**
73
+ * Apply retention policy to storage.
74
+ */
75
+ apply(storage: AuditStorageAdapter): Promise<{
76
+ deletedCount: number;
77
+ }>;
80
78
  }
81
79
  /**
82
80
  * Create an in-memory audit storage.
83
81
  */
84
- declare function createInMemoryAuditStorage(): InMemoryAuditStorage;
85
- //#endregion
86
- export { AuditStorageAdapter, ExtendedAuditQueryOptions, InMemoryAuditStorage, RetentionPolicy, RetentionPolicyConfig, createInMemoryAuditStorage };
82
+ export declare function createInMemoryAuditStorage(): InMemoryAuditStorage;
87
83
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/storage/index.ts"],"mappings":";;;;;AASA;UAAiB,yBAAA,SAAkC,iBAAA;EACjD,UAAA;EACA,QAAA;EACA,SAAA;EACA,OAAA;EACA,QAAA;AAAA;;;;UAMe,mBAAA,SAA4B,YAAA;EAA5B;EAEf,KAAA,CAAM,OAAA,EAAS,yBAAA,GAA4B,OAAA,CAAQ,WAAA;;EAEnD,KAAA,CACE,OAAA,EAAS,IAAA,CAAK,yBAAA,wBACb,OAAA;EAJgD;EAMnD,OAAA,CAAQ,EAAA,WAAa,OAAA,CAAQ,WAAA;EAHb;EAKhB,YAAA,CAAa,OAAA,WAAkB,OAAA,CAAQ,WAAA;EAJpC;EAMH,eAAA,CAAgB,IAAA,EAAM,IAAA,GAAO,OAAA;AAAA;;;;cAMlB,oBAAA,YAAgC,mBAAA;EAAA,QACnC,OAAA;EAEF,KAAA,CAAM,MAAA,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M,CAAC;IACzB,kDAAkD;IAClD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,2CAA2C;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,qBAAqB;IAE1D;;OAEG;IACH,YAAY,IAAI,IAAI;IAMpB;;OAEG;IACH,gBAAgB,IAAI,IAAI,GAAG,IAAI;IAO/B;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC;QACjD,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CAKH;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,oBAAoB,CAEjE"}
@@ -1,112 +1,102 @@
1
- //#region src/storage/index.ts
2
- /**
3
- * In-memory audit storage for development/testing.
4
- */
5
- var InMemoryAuditStorage = class {
6
- records = [];
7
- async store(record) {
8
- this.records.push(record);
9
- }
10
- async query(options) {
11
- let results = [...this.records];
12
- if (options.eventKey) {
13
- const pattern = options.eventKey.replace(/\*/g, ".*");
14
- const regex = new RegExp(`^${pattern}$`);
15
- results = results.filter((r) => regex.test(r.eventKey));
16
- }
17
- if (options.actorId) results = results.filter((r) => r.metadata?.actorId === options.actorId);
18
- if (options.targetId) results = results.filter((r) => r.metadata?.targetId === options.targetId);
19
- if (options.targetType) results = results.filter((r) => r.metadata?.targetType === options.targetType);
20
- if (options.orgId) results = results.filter((r) => r.metadata?.orgId === options.orgId);
21
- if (options.traceId) results = results.filter((r) => r.traceId === options.traceId);
22
- if (options.from) {
23
- const fromDate = options.from;
24
- results = results.filter((r) => new Date(r.occurredAt) >= fromDate);
25
- }
26
- if (options.to) {
27
- const toDate = options.to;
28
- results = results.filter((r) => new Date(r.occurredAt) <= toDate);
29
- }
30
- const orderBy = options.orderBy ?? "occurredAt";
31
- const orderDir = options.orderDir ?? "desc";
32
- results.sort((a, b) => {
33
- const aTime = orderBy === "occurredAt" ? new Date(a.occurredAt).getTime() : a.recordedAt.getTime();
34
- const bTime = orderBy === "occurredAt" ? new Date(b.occurredAt).getTime() : b.recordedAt.getTime();
35
- return orderDir === "desc" ? bTime - aTime : aTime - bTime;
36
- });
37
- const offset = options.offset ?? 0;
38
- const limit = options.limit ?? 100;
39
- return results.slice(offset, offset + limit);
40
- }
41
- async count(options) {
42
- return (await this.query({
43
- ...options,
44
- limit: Infinity
45
- })).length;
46
- }
47
- async getById(id) {
48
- return this.records.find((r) => r.id === id) ?? null;
49
- }
50
- async getByTraceId(traceId) {
51
- return this.query({ traceId });
52
- }
53
- async deleteOlderThan(date) {
54
- const before = this.records.length;
55
- this.records = this.records.filter((r) => new Date(r.occurredAt) >= date);
56
- return before - this.records.length;
57
- }
58
- /**
59
- * Get all records (for testing).
60
- */
61
- getAll() {
62
- return [...this.records];
63
- }
64
- /**
65
- * Clear all records (for testing).
66
- */
67
- clear() {
68
- this.records = [];
69
- }
70
- };
71
- /**
72
- * Retention policy manager.
73
- */
74
- var RetentionPolicy = class {
75
- constructor(config) {
76
- this.config = config;
77
- }
78
- /**
79
- * Get the cutoff date for hot storage.
80
- */
81
- getHotCutoff() {
82
- const cutoff = /* @__PURE__ */ new Date();
83
- cutoff.setDate(cutoff.getDate() - this.config.hotRetentionDays);
84
- return cutoff;
85
- }
86
- /**
87
- * Get the cutoff date for archive storage.
88
- */
89
- getArchiveCutoff() {
90
- if (!this.config.archiveRetentionDays) return null;
91
- const cutoff = /* @__PURE__ */ new Date();
92
- cutoff.setDate(cutoff.getDate() - this.config.archiveRetentionDays);
93
- return cutoff;
94
- }
95
- /**
96
- * Apply retention policy to storage.
97
- */
98
- async apply(storage) {
99
- const cutoff = this.getHotCutoff();
100
- return { deletedCount: await storage.deleteOlderThan(cutoff) };
101
- }
102
- };
103
- /**
104
- * Create an in-memory audit storage.
105
- */
106
- function createInMemoryAuditStorage() {
107
- return new InMemoryAuditStorage();
1
+ // @bun
2
+ // src/storage/index.ts
3
+ class InMemoryAuditStorage {
4
+ records = [];
5
+ async store(record) {
6
+ this.records.push(record);
7
+ }
8
+ async query(options) {
9
+ let results = [...this.records];
10
+ if (options.eventKey) {
11
+ const pattern = options.eventKey.replace(/\*/g, ".*");
12
+ const regex = new RegExp(`^${pattern}$`);
13
+ results = results.filter((r) => regex.test(r.eventKey));
14
+ }
15
+ if (options.actorId) {
16
+ results = results.filter((r) => r.metadata?.actorId === options.actorId);
17
+ }
18
+ if (options.targetId) {
19
+ results = results.filter((r) => r.metadata?.targetId === options.targetId);
20
+ }
21
+ if (options.targetType) {
22
+ results = results.filter((r) => r.metadata?.targetType === options.targetType);
23
+ }
24
+ if (options.orgId) {
25
+ results = results.filter((r) => r.metadata?.orgId === options.orgId);
26
+ }
27
+ if (options.traceId) {
28
+ results = results.filter((r) => r.traceId === options.traceId);
29
+ }
30
+ if (options.from) {
31
+ const fromDate = options.from;
32
+ results = results.filter((r) => new Date(r.occurredAt) >= fromDate);
33
+ }
34
+ if (options.to) {
35
+ const toDate = options.to;
36
+ results = results.filter((r) => new Date(r.occurredAt) <= toDate);
37
+ }
38
+ const orderBy = options.orderBy ?? "occurredAt";
39
+ const orderDir = options.orderDir ?? "desc";
40
+ results.sort((a, b) => {
41
+ const aTime = orderBy === "occurredAt" ? new Date(a.occurredAt).getTime() : a.recordedAt.getTime();
42
+ const bTime = orderBy === "occurredAt" ? new Date(b.occurredAt).getTime() : b.recordedAt.getTime();
43
+ return orderDir === "desc" ? bTime - aTime : aTime - bTime;
44
+ });
45
+ const offset = options.offset ?? 0;
46
+ const limit = options.limit ?? 100;
47
+ return results.slice(offset, offset + limit);
48
+ }
49
+ async count(options) {
50
+ const results = await this.query({ ...options, limit: Infinity });
51
+ return results.length;
52
+ }
53
+ async getById(id) {
54
+ return this.records.find((r) => r.id === id) ?? null;
55
+ }
56
+ async getByTraceId(traceId) {
57
+ return this.query({ traceId });
58
+ }
59
+ async deleteOlderThan(date) {
60
+ const before = this.records.length;
61
+ this.records = this.records.filter((r) => new Date(r.occurredAt) >= date);
62
+ return before - this.records.length;
63
+ }
64
+ getAll() {
65
+ return [...this.records];
66
+ }
67
+ clear() {
68
+ this.records = [];
69
+ }
108
70
  }
109
71
 
110
- //#endregion
111
- export { InMemoryAuditStorage, RetentionPolicy, createInMemoryAuditStorage };
112
- //# sourceMappingURL=index.js.map
72
+ class RetentionPolicy {
73
+ config;
74
+ constructor(config) {
75
+ this.config = config;
76
+ }
77
+ getHotCutoff() {
78
+ const cutoff = new Date;
79
+ cutoff.setDate(cutoff.getDate() - this.config.hotRetentionDays);
80
+ return cutoff;
81
+ }
82
+ getArchiveCutoff() {
83
+ if (!this.config.archiveRetentionDays)
84
+ return null;
85
+ const cutoff = new Date;
86
+ cutoff.setDate(cutoff.getDate() - this.config.archiveRetentionDays);
87
+ return cutoff;
88
+ }
89
+ async apply(storage) {
90
+ const cutoff = this.getHotCutoff();
91
+ const deletedCount = await storage.deleteOlderThan(cutoff);
92
+ return { deletedCount };
93
+ }
94
+ }
95
+ function createInMemoryAuditStorage() {
96
+ return new InMemoryAuditStorage;
97
+ }
98
+ export {
99
+ createInMemoryAuditStorage,
100
+ RetentionPolicy,
101
+ InMemoryAuditStorage
102
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/module.audit-trail",
3
- "version": "1.57.0",
3
+ "version": "1.58.0",
4
4
  "description": "Audit trail module for tracking and querying system events",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -15,34 +15,38 @@
15
15
  "scripts": {
16
16
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
17
17
  "publish:pkg:canary": "bun publish:pkg --tag canary",
18
- "build": "bun build:types && bun build:bundle",
19
- "build:bundle": "tsdown",
20
- "build:types": "tsc --noEmit",
21
- "dev": "bun build:bundle --watch",
18
+ "build": "bun run prebuild && bun run build:bundle && bun run build:types",
19
+ "build:bundle": "contractspec-bun-build transpile",
20
+ "build:types": "contractspec-bun-build types",
21
+ "dev": "contractspec-bun-build dev",
22
22
  "clean": "rimraf dist .turbo",
23
23
  "lint": "bun lint:fix",
24
24
  "lint:fix": "eslint src --fix",
25
- "lint:check": "eslint src"
25
+ "lint:check": "eslint src",
26
+ "prebuild": "contractspec-bun-build prebuild",
27
+ "typecheck": "tsc --noEmit"
26
28
  },
27
29
  "dependencies": {
28
- "@contractspec/lib.schema": "1.57.0",
29
- "@contractspec/lib.contracts": "1.57.0",
30
- "@contractspec/lib.bus": "1.57.0",
30
+ "@contractspec/lib.schema": "1.58.0",
31
+ "@contractspec/lib.contracts": "1.58.0",
32
+ "@contractspec/lib.bus": "1.58.0",
31
33
  "zod": "^4.3.5"
32
34
  },
33
35
  "devDependencies": {
34
- "@contractspec/tool.typescript": "1.57.0",
35
- "@contractspec/tool.tsdown": "1.57.0",
36
- "typescript": "^5.9.3"
36
+ "@contractspec/tool.typescript": "1.58.0",
37
+ "typescript": "^5.9.3",
38
+ "@contractspec/tool.bun": "1.57.0"
37
39
  },
38
40
  "exports": {
39
- ".": "./dist/index.js",
40
- "./audit-trail.capability": "./dist/audit-trail.capability.js",
41
- "./audit-trail.feature": "./dist/audit-trail.feature.js",
42
- "./contracts": "./dist/contracts/index.js",
43
- "./entities": "./dist/entities/index.js",
44
- "./storage": "./dist/storage/index.js",
45
- "./*": "./*"
41
+ ".": "./src/index.ts",
42
+ "./audit-trail.capability": "./src/audit-trail.capability.ts",
43
+ "./audit-trail.feature": "./src/audit-trail.feature.ts",
44
+ "./contracts": "./src/contracts/index.ts",
45
+ "./contracts/index": "./src/contracts/index.ts",
46
+ "./entities": "./src/entities/index.ts",
47
+ "./entities/index": "./src/entities/index.ts",
48
+ "./storage": "./src/storage/index.ts",
49
+ "./storage/index": "./src/storage/index.ts"
46
50
  },
47
51
  "files": [
48
52
  "dist",
@@ -51,12 +55,69 @@
51
55
  "publishConfig": {
52
56
  "access": "public",
53
57
  "exports": {
54
- ".": "./dist/index.js",
55
- "./audit-trail.feature": "./dist/audit-trail.feature.js",
56
- "./contracts": "./dist/contracts/index.js",
57
- "./entities": "./dist/entities/index.js",
58
- "./storage": "./dist/storage/index.js",
59
- "./*": "./*"
58
+ ".": {
59
+ "types": "./dist/index.d.ts",
60
+ "bun": "./dist/index.js",
61
+ "node": "./dist/node/index.mjs",
62
+ "browser": "./dist/browser/index.js",
63
+ "default": "./dist/index.js"
64
+ },
65
+ "./audit-trail.capability": {
66
+ "types": "./dist/audit-trail.capability.d.ts",
67
+ "bun": "./dist/audit-trail.capability.js",
68
+ "node": "./dist/node/audit-trail.capability.mjs",
69
+ "browser": "./dist/browser/audit-trail.capability.js",
70
+ "default": "./dist/audit-trail.capability.js"
71
+ },
72
+ "./audit-trail.feature": {
73
+ "types": "./dist/audit-trail.feature.d.ts",
74
+ "bun": "./dist/audit-trail.feature.js",
75
+ "node": "./dist/node/audit-trail.feature.mjs",
76
+ "browser": "./dist/browser/audit-trail.feature.js",
77
+ "default": "./dist/audit-trail.feature.js"
78
+ },
79
+ "./contracts": {
80
+ "types": "./dist/contracts/index.d.ts",
81
+ "bun": "./dist/contracts/index.js",
82
+ "node": "./dist/node/contracts/index.mjs",
83
+ "browser": "./dist/browser/contracts/index.js",
84
+ "default": "./dist/contracts/index.js"
85
+ },
86
+ "./contracts/index": {
87
+ "types": "./dist/contracts/index.d.ts",
88
+ "bun": "./dist/contracts/index.js",
89
+ "node": "./dist/node/contracts/index.mjs",
90
+ "browser": "./dist/browser/contracts/index.js",
91
+ "default": "./dist/contracts/index.js"
92
+ },
93
+ "./entities": {
94
+ "types": "./dist/entities/index.d.ts",
95
+ "bun": "./dist/entities/index.js",
96
+ "node": "./dist/node/entities/index.mjs",
97
+ "browser": "./dist/browser/entities/index.js",
98
+ "default": "./dist/entities/index.js"
99
+ },
100
+ "./entities/index": {
101
+ "types": "./dist/entities/index.d.ts",
102
+ "bun": "./dist/entities/index.js",
103
+ "node": "./dist/node/entities/index.mjs",
104
+ "browser": "./dist/browser/entities/index.js",
105
+ "default": "./dist/entities/index.js"
106
+ },
107
+ "./storage": {
108
+ "types": "./dist/storage/index.d.ts",
109
+ "bun": "./dist/storage/index.js",
110
+ "node": "./dist/node/storage/index.mjs",
111
+ "browser": "./dist/browser/storage/index.js",
112
+ "default": "./dist/storage/index.js"
113
+ },
114
+ "./storage/index": {
115
+ "types": "./dist/storage/index.d.ts",
116
+ "bun": "./dist/storage/index.js",
117
+ "node": "./dist/node/storage/index.mjs",
118
+ "browser": "./dist/browser/storage/index.js",
119
+ "default": "./dist/storage/index.js"
120
+ }
60
121
  },
61
122
  "registry": "https://registry.npmjs.org/"
62
123
  },
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/contracts/index.ts"],"sourcesContent":["import {\n defineCommand,\n defineQuery,\n defineSchemaModel,\n} from '@contractspec/lib.contracts';\nimport { ScalarTypeEnum, defineEnum } from '@contractspec/lib.schema';\n\nconst OWNERS = ['platform.audit-trail'] as const;\n\n// ============ Schemas ============\n\nexport const AuditLogModel = defineSchemaModel({\n name: 'AuditLog',\n description: 'Detailed audit log entry',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n eventName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n eventVersion: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n payload: { type: ScalarTypeEnum.JSONObject(), isOptional: false },\n actorId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n actorType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n actorEmail: { type: ScalarTypeEnum.EmailAddress(), isOptional: true },\n targetId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n targetType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n clientIp: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n occurredAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n recordedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\nexport const AuditQueryInputModel = defineSchemaModel({\n name: 'AuditQueryInput',\n description: 'Input for querying audit logs',\n fields: {\n eventName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n actorId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n targetId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n targetType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n from: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n to: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n limit: {\n type: ScalarTypeEnum.Int_unsecure(),\n isOptional: true,\n defaultValue: 100,\n },\n offset: {\n type: ScalarTypeEnum.Int_unsecure(),\n isOptional: true,\n defaultValue: 0,\n },\n },\n});\n\nexport const AuditQueryOutputModel = defineSchemaModel({\n name: 'AuditQueryOutput',\n description: 'Output from querying audit logs',\n fields: {\n logs: { type: AuditLogModel, isArray: true, isOptional: false },\n total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n hasMore: { type: ScalarTypeEnum.Boolean(), isOptional: false },\n },\n});\n\nexport const ExportFormatEnum = defineEnum('ExportFormat', [\n 'json',\n 'csv',\n 'parquet',\n]);\n\nexport const AuditExportInputModel = defineSchemaModel({\n name: 'AuditExportInput',\n description: 'Input for exporting audit logs',\n fields: {\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n from: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n to: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n format: { type: ExportFormatEnum, isOptional: true, defaultValue: 'json' },\n eventNames: {\n type: ScalarTypeEnum.String_unsecure(),\n isArray: true,\n isOptional: true,\n },\n },\n});\n\nexport const ExportStatusEnum = defineEnum('ExportStatus', [\n 'pending',\n 'processing',\n 'completed',\n 'failed',\n]);\n\nexport const AuditExportOutputModel = defineSchemaModel({\n name: 'AuditExportOutput',\n description: 'Output from initiating an audit export',\n fields: {\n exportId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n status: { type: ExportStatusEnum, isOptional: false },\n downloadUrl: { type: ScalarTypeEnum.URL(), isOptional: true },\n },\n});\n\nexport const AuditStatsInputModel = defineSchemaModel({\n name: 'AuditStatsInput',\n description: 'Input for getting audit statistics',\n fields: {\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n from: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n to: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n },\n});\n\nexport const AuditStatsOutputModel = defineSchemaModel({\n name: 'AuditStatsOutput',\n description: 'Audit log statistics',\n fields: {\n totalLogs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n uniqueActors: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n uniqueTargets: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n eventCounts: { type: ScalarTypeEnum.JSONObject(), isOptional: false },\n },\n});\n\n// ============ Contracts ============\n\n/**\n * Query audit logs.\n */\nexport const QueryAuditLogsContract = defineQuery({\n meta: {\n key: 'audit.logs.query',\n version: '1.0.0',\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['audit', 'logs', 'query'],\n description: 'Query audit logs with filters.',\n goal: 'Enable searching and filtering of audit history.',\n context: 'Admin dashboard, compliance reporting, debugging.',\n },\n io: {\n input: AuditQueryInputModel,\n output: AuditQueryOutputModel,\n },\n policy: {\n auth: 'admin',\n },\n});\n\n/**\n * Get audit log by ID.\n */\nexport const GetAuditLogContract = defineQuery({\n meta: {\n key: 'audit.logs.get',\n version: '1.0.0',\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['audit', 'logs', 'get'],\n description: 'Get a specific audit log by ID.',\n goal: 'View detailed audit log entry.',\n context: 'Log detail view.',\n },\n io: {\n input: defineSchemaModel({\n name: 'GetAuditLogInput',\n fields: {\n logId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n }),\n output: AuditLogModel,\n },\n policy: {\n auth: 'admin',\n },\n});\n\n/**\n * Get audit logs by trace ID.\n */\nexport const GetAuditTraceContract = defineQuery({\n meta: {\n key: 'audit.trace.get',\n version: '1.0.0',\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['audit', 'trace', 'get'],\n description: 'Get all audit logs for a trace.',\n goal: 'View complete request trace for debugging.',\n context: 'Request tracing, debugging.',\n },\n io: {\n input: defineSchemaModel({\n name: 'GetAuditTraceInput',\n fields: {\n traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n }),\n output: defineSchemaModel({\n name: 'GetAuditTraceOutput',\n fields: {\n logs: { type: AuditLogModel, isArray: true, isOptional: false },\n },\n }),\n },\n policy: {\n auth: 'admin',\n },\n});\n\n/**\n * Export audit logs.\n */\nexport const ExportAuditLogsContract = defineCommand({\n meta: {\n key: 'audit.logs.export',\n version: '1.0.0',\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['audit', 'logs', 'export'],\n description: 'Export audit logs for compliance reporting.',\n goal: 'Generate audit reports for compliance.',\n context: 'Compliance reporting, external audits.',\n },\n io: {\n input: AuditExportInputModel,\n output: AuditExportOutputModel,\n },\n policy: {\n auth: 'admin',\n },\n});\n\n/**\n * Get audit statistics.\n */\nexport const GetAuditStatsContract = defineQuery({\n meta: {\n key: 'audit.stats',\n version: '1.0.0',\n stability: 'stable',\n owners: [...OWNERS],\n tags: ['audit', 'stats'],\n description: 'Get audit log statistics.',\n goal: 'Monitor audit activity levels.',\n context: 'Admin dashboard, monitoring.',\n },\n io: {\n input: AuditStatsInputModel,\n output: AuditStatsOutputModel,\n },\n policy: {\n auth: 'admin',\n },\n});\n"],"mappings":";;;;AAOA,MAAM,SAAS,CAAC,uBAAuB;AAIvC,MAAa,gBAAgB,kBAAkB;CAC7C,MAAM;CACN,aAAa;CACb,QAAQ;EACN,IAAI;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACjE,WAAW;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACxE,cAAc;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EAC3E,SAAS;GAAE,MAAM,eAAe,YAAY;GAAE,YAAY;GAAO;EACjE,SAAS;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACrE,WAAW;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACvE,YAAY;GAAE,MAAM,eAAe,cAAc;GAAE,YAAY;GAAM;EACrE,UAAU;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACtE,YAAY;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACxE,OAAO;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACnE,SAAS;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACrE,UAAU;GAAE,MAAM,eAAe,iBA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,YAAY;CAC/C,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,GAAG,OAAO;EACnB,MAAM,CAAC,SAAS,QAAQ;EACxB,aAAa;EACb,MAAM;EACN,SAAS;EACV;CACD,IAAI;EACF,OAAO;EACP,QAAQ;EACT;CACD,QAAQ,EACN,MAAM,SACP;CACF,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/entities/index.ts"],"sourcesContent":["import { defineEntity, field, index } from '@contractspec/lib.schema';\nimport type { ModuleSchemaContribution } from '@contractspec/lib.schema';\n\n/**\n * AuditLog entity - main audit log entry.\n */\nexport const AuditLogEntity = defineEntity({\n name: 'AuditLog',\n description: 'Audit log entry for tracking system events.',\n schema: 'lssm_audit',\n map: 'audit_log',\n fields: {\n id: field.id({ description: 'Unique audit log ID' }),\n\n // Event info\n eventName: field.string({ description: 'Event name/type' }),\n eventVersion: field.int({ description: 'Event version' }),\n payload: field.json({ description: 'Event payload (may be redacted)' }),\n\n // Actor info\n actorId: field.string({\n isOptional: true,\n description: 'User/service that triggered the event',\n }),\n actorType: field.string({\n isOptional: true,\n description: 'Actor type (user, system, service)',\n }),\n actorEmail: field.string({\n isOptional: true,\n description: 'Actor email (for searchability)',\n }),\n\n // Target info\n targetId: field.string({\n isOptional: true,\n description: 'Resource affected by the event',\n }),\n targetType: field.string({\n isOptional: true,\n description: 'Resource type',\n }),\n\n // Context\n orgId: field.string({\n isOptional: true,\n description: 'Organization context',\n }),\n tenantId: field.string({ isOptional: true, description: 'Tenant context' }),\n\n // Tracing\n traceId: field.string({\n isOptional: true,\n description: 'Distributed trace ID',\n }),\n spanId: field.string({ isOptional: true, description: 'Span ID' }),\n requestId: field.string({ isOptional: true, description: 'Request ID' }),\n sessionId: field.string({ isOptional: true, description: 'Session ID' }),\n\n // Client info\n clientIp: field.string({\n isOptional: true,\n description: 'Client IP address',\n }),\n userAgent: field.string({\n isOptional: true,\n description: 'User agent string',\n }),\n\n // Metadata\n tags: field.json({\n isOptional: true,\n description: 'Custom tags for filtering',\n }),\n metadata: field.json({\n isOptional: true,\n description: 'Additional metadata',\n }),\n\n // Timestamps\n occurredAt: field.dateTime({ description: 'When the event occurred' }),\n recordedAt: field.createdAt({ description: 'When the log was recorded' }),\n },\n indexes: [\n index.on(['actorId', 'occurredAt']),\n index.on(['targetId', 'occurredAt']),\n index.on(['orgId', 'occurredAt']),\n index.on(['eventName', 'occurredAt']),\n index.on(['traceId']),\n index.on(['occurredAt']),\n ],\n});\n\n/**\n * AuditLogArchive entity - archived logs for long-term retention.\n */\nexport const AuditLogArchiveEntity = defineEntity({\n name: 'AuditLogArchive',\n description: 'Archived audit logs for long-term retention.',\n schema: 'lssm_audit',\n map: 'audit_log_archive',\n fields: {\n id: field.id(),\n\n // Batch info\n batchId: field.string({ description: 'Archive batch ID' }),\n logCount: field.int({ description: 'Number of logs in batch' }),\n\n // Time range\n fromDate: field.dateTime({ description: 'Earliest log in batch' }),\n toDate: field.dateTime({ description: 'Latest log in batch' }),\n\n // Storage\n storagePath: field.string({ description: 'Path to archived data' }),\n storageType: field.string({ description: 'Storage type (s3, gcs, file)' }),\n compressedSize: field.int({ description: 'Compressed size in bytes' }),\n\n // Integrity\n checksum: field.string({ description: 'SHA-256 checksum' }),\n\n // Retention\n retainUntil: field.dateTime({ description: 'When archive can be deleted' }),\n\n // Timestamps\n createdAt: field.createdAt(),\n },\n indexes: [index.on(['fromDate', 'toDate']), index.on(['retainUntil'])],\n});\n\n/**\n * All audit trail entities for schema composition.\n */\nexport const auditTrailEntities = [AuditLogEntity, AuditLogArchiveEntity];\n\n/**\n * Module schema contribution for audit trail.\n */\nexport const auditTrailSchemaContribution: ModuleSchemaContribution = {\n moduleId: '@contractspec/module.audit-trail',\n entities: auditTrailEntities,\n};\n"],"mappings":";;;;;;AAMA,MAAa,iBAAiB,aAAa;CACzC,MAAM;CACN,aAAa;CACb,QAAQ;CACR,KAAK;CACL,QAAQ;EACN,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aAAa,CAAC;EACnC,MAAM,GAAG,CAAC,YAAY,aAAa,CAAC;EACpC,MAAM,GAAG,CAAC,SAAS,aAAa,CAAC;EACjC,MAAM,GAAG,CAAC,aAAa,aAAa,CAAC;EACrC,MAAM,GAAG,CAAC,UAAU,CAAC;EACrB,MAAM,GAAG,CAAC,aAAa,CAAC;EACzB;CACF,CAAC;;;;AAKF,MAAa,wBAAwB,aAAa;CAChD,MAAM;CACN,aAAa;CACb,QAAQ;CACR,KAAK;CACL,QAAQ;EACN,IAAI,MAAM,IAAI;EAGd,SAAS,MAAM,OAAO,EAAE,aAAa,oBAAoB,CAAC;EAC1D,UAAU,MAAM,IAAI,EAAE,aAAa,2BAA2B,CAAC;EAG/D,UAAU,MAAM,SAAS,EAAE,aAAa,yBAAyB,CAAC;EAClE,QAAQ,MAAM,SAAS,EAAE,aAAa,uBAAuB,CAAC;EAG9D,aAAa,MAAM,OAAO,EAAE,aAAa,yBAAyB,CAAC;EACnE,aAAa,MAAM,OAAO,EAAE,aAAa,gCAAgC,CAAC;EAC1E,gBAAgB,MAAM,IAAI,EAAE,aAAa,4BAA4B,CAAC;EAGtE,UAAU,MAAM,OAAO,EAAE,aAAa,oBAAoB,CAAC;EAG3D,aAAa,MAAM,SAAS,EAAE,aAAa,+BAA+B,CAAC;EAG3E,WAAW,MAAM,WAAW;EAC7B;CACD,SAAS,CAAC,MAAM,GAAG,CAAC,YAAY,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,cAAc,CAAC,CAAC;CACvE,CAAC;;;;AAKF,MAAa,qBAAqB,CAAC,gBAAgB,sBAAsB;;;;AAKzE,MAAa,+BAAyD;CACpE,UAAU;CACV,UAAU;CACX"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/storage/index.ts"],"sourcesContent":["import type {\n AuditRecord,\n AuditQueryOptions,\n AuditStorage,\n} from '@contractspec/lib.bus';\n\n/**\n * Extended query options for audit storage.\n */\nexport interface ExtendedAuditQueryOptions extends AuditQueryOptions {\n targetType?: string;\n clientIp?: string;\n sessionId?: string;\n orderBy?: 'occurredAt' | 'recordedAt';\n orderDir?: 'asc' | 'desc';\n}\n\n/**\n * Audit storage adapter interface with extended capabilities.\n */\nexport interface AuditStorageAdapter extends AuditStorage {\n /** Query audit records with extended options */\n query(options: ExtendedAuditQueryOptions): Promise<AuditRecord[]>;\n /** Count matching records */\n count(\n options: Omit<ExtendedAuditQueryOptions, 'limit' | 'offset'>\n ): Promise<number>;\n /** Get a single record by ID */\n getById(id: string): Promise<AuditRecord | null>;\n /** Get all records for a trace */\n getByTraceId(traceId: string): Promise<AuditRecord[]>;\n /** Delete old records (for retention) */\n deleteOlderThan(date: Date): Promise<number>;\n}\n\n/**\n * In-memory audit storage for development/testing.\n */\nexport class InMemoryAuditStorage implements AuditStorageAdapter {\n private records: AuditRecord[] = [];\n\n async store(record: AuditRecord): Promise<void> {\n this.records.push(record);\n }\n\n async query(options: ExtendedAuditQueryOptions): Promise<AuditRecord[]> {\n let results = [...this.records];\n\n // Apply filters\n if (options.eventKey) {\n const pattern = options.eventKey.replace(/\\*/g, '.*');\n const regex = new RegExp(`^${pattern}$`);\n results = results.filter((r) => regex.test(r.eventKey));\n }\n\n if (options.actorId) {\n results = results.filter((r) => r.metadata?.actorId === options.actorId);\n }\n\n if (options.targetId) {\n results = results.filter(\n (r) => r.metadata?.targetId === options.targetId\n );\n }\n\n if (options.targetType) {\n results = results.filter(\n (r) => r.metadata?.targetType === options.targetType\n );\n }\n\n if (options.orgId) {\n results = results.filter((r) => r.metadata?.orgId === options.orgId);\n }\n\n if (options.traceId) {\n results = results.filter((r) => r.traceId === options.traceId);\n }\n\n if (options.from) {\n const fromDate = options.from;\n results = results.filter((r) => new Date(r.occurredAt) >= fromDate);\n }\n\n if (options.to) {\n const toDate = options.to;\n results = results.filter((r) => new Date(r.occurredAt) <= toDate);\n }\n\n // Sort\n const orderBy = options.orderBy ?? 'occurredAt';\n const orderDir = options.orderDir ?? 'desc';\n results.sort((a, b) => {\n const aTime =\n orderBy === 'occurredAt'\n ? new Date(a.occurredAt).getTime()\n : a.recordedAt.getTime();\n const bTime =\n orderBy === 'occurredAt'\n ? new Date(b.occurredAt).getTime()\n : b.recordedAt.getTime();\n return orderDir === 'desc' ? bTime - aTime : aTime - bTime;\n });\n\n // Paginate\n const offset = options.offset ?? 0;\n const limit = options.limit ?? 100;\n return results.slice(offset, offset + limit);\n }\n\n async count(\n options: Omit<ExtendedAuditQueryOptions, 'limit' | 'offset'>\n ): Promise<number> {\n const results = await this.query({ ...options, limit: Infinity });\n return results.length;\n }\n\n async getById(id: string): Promise<AuditRecord | null> {\n return this.records.find((r) => r.id === id) ?? null;\n }\n\n async getByTraceId(traceId: string): Promise<AuditRecord[]> {\n return this.query({ traceId });\n }\n\n async deleteOlderThan(date: Date): Promise<number> {\n const before = this.records.length;\n this.records = this.records.filter((r) => new Date(r.occurredAt) >= date);\n return before - this.records.length;\n }\n\n /**\n * Get all records (for testing).\n */\n getAll(): AuditRecord[] {\n return [...this.records];\n }\n\n /**\n * Clear all records (for testing).\n */\n clear(): void {\n this.records = [];\n }\n}\n\n/**\n * Retention policy configuration.\n */\nexport interface RetentionPolicyConfig {\n /** Days to keep detailed logs */\n hotRetentionDays: number;\n /** Days to keep archived logs (for compliance) */\n archiveRetentionDays?: number;\n /** Cron expression for cleanup schedule */\n cleanupSchedule?: string;\n}\n\n/**\n * Retention policy manager.\n */\nexport class RetentionPolicy {\n constructor(private readonly config: RetentionPolicyConfig) {}\n\n /**\n * Get the cutoff date for hot storage.\n */\n getHotCutoff(): Date {\n const cutoff = new Date();\n cutoff.setDate(cutoff.getDate() - this.config.hotRetentionDays);\n return cutoff;\n }\n\n /**\n * Get the cutoff date for archive storage.\n */\n getArchiveCutoff(): Date | null {\n if (!this.config.archiveRetentionDays) return null;\n const cutoff = new Date();\n cutoff.setDate(cutoff.getDate() - this.config.archiveRetentionDays);\n return cutoff;\n }\n\n /**\n * Apply retention policy to storage.\n */\n async apply(storage: AuditStorageAdapter): Promise<{\n deletedCount: number;\n }> {\n const cutoff = this.getHotCutoff();\n const deletedCount = await storage.deleteOlderThan(cutoff);\n return { deletedCount };\n }\n}\n\n/**\n * Create an in-memory audit storage.\n */\nexport function createInMemoryAuditStorage(): InMemoryAuditStorage {\n return new InMemoryAuditStorage();\n}\n"],"mappings":";;;;AAsCA,IAAa,uBAAb,MAAiE;CAC/D,AAAQ,UAAyB,EAAE;CAEnC,MAAM,MAAM,QAAoC;AAC9C,OAAK,QAAQ,KAAK,OAAO;;CAG3B,MAAM,MAAM,SAA4D;EACtE,IAAI,UAAU,CAAC,GAAG,KAAK,QAAQ;AAG/B,MAAI,QAAQ,UAAU;GACpB,MAAM,UAAU,QAAQ,SAAS,QAAQ,OAAO,KAAK;GACrD,MAAM,QAAQ,IAAI,OAAO,IAAI,QAAQ,GAAG;AACxC,aAAU,QAAQ,QAAQ,MAAM,MAAM,KAAK,EAAE,SAAS,CAAC;;AAGzD,MAAI,QAAQ,QACV,WAAU,QAAQ,QAAQ,MAAM,EAAE,UAAU,YAAY,QAAQ,QAAQ;AAG1E,MAAI,QAAQ,SACV,WAAU,QAAQ,QACf,MAAM,EAAE,UAAU,aAAa,QAAQ,SACzC;AAGH,MAAI,QAAQ,WACV,WAAU,QAAQ,QACf,MAAM,EAAE,UAAU,eAAe,QAAQ,WAC3C;AAGH,MAAI,QAAQ,MACV,WAAU,QAAQ,QAAQ,MAAM,EAAE,UAAU,UAAU,QAAQ,MAAM;AAGtE,MAAI,QAAQ,QACV,WAAU,QAAQ,QAAQ,MAAM,EAAE,YAAY,QAAQ,QAAQ;AAGhE,MAAI,QAAQ,MAAM;GAChB,MAAM,WAAW,QAAQ;AACzB,aAAU,QAAQ,QAAQ,MAAM,IAAI,KAAK,EAAE,WAAW,IAAI,SAAS;;AAGrE,MAAI,QAAQ,IAAI;GACd,MAAM,SAAS,QAAQ;AACvB,aAAU,QAAQ,QAAQ,MAAM,IAAI,KAAK,EAAE,WA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