@contractspec/module.audit-trail 3.7.17 → 3.7.19

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.
@@ -1,102 +1,2 @@
1
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
- }
70
- }
71
-
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
- };
2
+ class F{records=[];async store(h){this.records.push(h)}async query(h){let j=[...this.records];if(h.eventKey){let k=h.eventKey.replace(/\*/g,".*"),q=new RegExp(`^${k}$`);j=j.filter((w)=>q.test(w.eventKey))}if(h.actorId)j=j.filter((k)=>k.metadata?.actorId===h.actorId);if(h.targetId)j=j.filter((k)=>k.metadata?.targetId===h.targetId);if(h.targetType)j=j.filter((k)=>k.metadata?.targetType===h.targetType);if(h.orgId)j=j.filter((k)=>k.metadata?.orgId===h.orgId);if(h.traceId)j=j.filter((k)=>k.traceId===h.traceId);if(h.from){let k=h.from;j=j.filter((q)=>new Date(q.occurredAt)>=k)}if(h.to){let k=h.to;j=j.filter((q)=>new Date(q.occurredAt)<=k)}let v=h.orderBy??"occurredAt",G=h.orderDir??"desc";j.sort((k,q)=>{let w=v==="occurredAt"?new Date(k.occurredAt).getTime():k.recordedAt.getTime(),E=v==="occurredAt"?new Date(q.occurredAt).getTime():q.recordedAt.getTime();return G==="desc"?E-w:w-E});let z=h.offset??0,H=h.limit??100;return j.slice(z,z+H)}async count(h){return(await this.query({...h,limit:1/0})).length}async getById(h){return this.records.find((j)=>j.id===h)??null}async getByTraceId(h){return this.query({traceId:h})}async deleteOlderThan(h){let j=this.records.length;return this.records=this.records.filter((v)=>new Date(v.occurredAt)>=h),j-this.records.length}getAll(){return[...this.records]}clear(){this.records=[]}}class J{config;constructor(h){this.config=h}getHotCutoff(){let h=new Date;return h.setDate(h.getDate()-this.config.hotRetentionDays),h}getArchiveCutoff(){if(!this.config.archiveRetentionDays)return null;let h=new Date;return h.setDate(h.getDate()-this.config.archiveRetentionDays),h}async apply(h){let j=this.getHotCutoff();return{deletedCount:await h.deleteOlderThan(j)}}}function K(){return new F}export{K as createInMemoryAuditStorage,J as RetentionPolicy,F as InMemoryAuditStorage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/module.audit-trail",
3
- "version": "3.7.17",
3
+ "version": "3.7.19",
4
4
  "description": "Audit trail module for tracking and querying system events",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -21,21 +21,21 @@
21
21
  "dev": "contractspec-bun-build dev",
22
22
  "clean": "rimraf dist .turbo",
23
23
  "lint": "bun lint:fix",
24
- "lint:fix": "biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .",
25
- "lint:check": "biome check .",
24
+ "lint:fix": "node ../../../scripts/biome.cjs check --write --unsafe --only=nursery/useSortedClasses . && node ../../../scripts/biome.cjs check --write .",
25
+ "lint:check": "node ../../../scripts/biome.cjs check .",
26
26
  "prebuild": "contractspec-bun-build prebuild",
27
27
  "typecheck": "tsc --noEmit"
28
28
  },
29
29
  "dependencies": {
30
30
  "@contractspec/lib.schema": "3.7.14",
31
- "@contractspec/lib.contracts-spec": "5.1.0",
32
- "@contractspec/lib.bus": "3.7.17",
31
+ "@contractspec/lib.contracts-spec": "5.3.0",
32
+ "@contractspec/lib.bus": "3.7.19",
33
33
  "zod": "^4.3.5"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@contractspec/tool.typescript": "3.7.13",
37
37
  "typescript": "^5.9.3",
38
- "@contractspec/tool.bun": "3.7.13"
38
+ "@contractspec/tool.bun": "3.7.14"
39
39
  },
40
40
  "exports": {
41
41
  ".": {