@contractspec/module.audit-trail 1.46.2 → 1.48.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/dist/audit-trail.capability.d.ts +7 -0
- package/dist/audit-trail.capability.d.ts.map +1 -0
- package/dist/audit-trail.capability.js +20 -0
- package/dist/audit-trail.capability.js.map +1 -0
- package/dist/audit-trail.feature.d.ts +2 -2
- package/dist/audit-trail.feature.d.ts.map +1 -1
- package/dist/audit-trail.feature.js +9 -2
- package/dist/audit-trail.feature.js.map +1 -1
- package/dist/contracts/index.d.ts +6 -6
- package/dist/contracts/index.js +1 -1
- package/dist/entities/index.js.map +1 -1
- package/dist/storage/index.js.map +1 -1
- package/package.json +8 -9
|
@@ -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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
|
|
2
2
|
|
|
3
3
|
//#region src/audit-trail.feature.d.ts
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ import { FeatureModuleSpec } from "@contractspec/lib.contracts";
|
|
|
6
6
|
* Audit Trail feature module that bundles audit log querying,
|
|
7
7
|
* export, and statistics capabilities.
|
|
8
8
|
*/
|
|
9
|
-
declare const AuditTrailFeature: FeatureModuleSpec;
|
|
9
|
+
declare const AuditTrailFeature: _contractspec_lib_contracts0.FeatureModuleSpec;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { AuditTrailFeature };
|
|
12
12
|
//# sourceMappingURL=audit-trail.feature.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-trail.feature.d.ts","names":[],"sources":["../src/audit-trail.feature.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"audit-trail.feature.d.ts","names":[],"sources":["../src/audit-trail.feature.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWA;cAAa,mBAkCX,4BAAA,CAlC4B"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { defineFeature } from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
1
3
|
//#region src/audit-trail.feature.ts
|
|
2
4
|
/**
|
|
5
|
+
* Audit Trail Feature Module Specification
|
|
6
|
+
*
|
|
7
|
+
* Defines the feature module for audit logging and compliance.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
3
10
|
* Audit Trail feature module that bundles audit log querying,
|
|
4
11
|
* export, and statistics capabilities.
|
|
5
12
|
*/
|
|
6
|
-
const AuditTrailFeature = {
|
|
13
|
+
const AuditTrailFeature = defineFeature({
|
|
7
14
|
meta: {
|
|
8
15
|
key: "audit-trail",
|
|
9
16
|
title: "Audit Trail",
|
|
@@ -52,7 +59,7 @@ const AuditTrailFeature = {
|
|
|
52
59
|
}],
|
|
53
60
|
requires: []
|
|
54
61
|
}
|
|
55
|
-
};
|
|
62
|
+
});
|
|
56
63
|
|
|
57
64
|
//#endregion
|
|
58
65
|
export { AuditTrailFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-trail.feature.js","names":[
|
|
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,5 +1,5 @@
|
|
|
1
|
+
import * as _contractspec_lib_contracts1 from "@contractspec/lib.contracts";
|
|
1
2
|
import * as _contractspec_lib_schema0 from "@contractspec/lib.schema";
|
|
2
|
-
import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
|
|
3
3
|
|
|
4
4
|
//#region src/contracts/index.d.ts
|
|
5
5
|
declare const AuditLogModel: _contractspec_lib_schema0.SchemaModel<{
|
|
@@ -251,7 +251,7 @@ declare const AuditStatsOutputModel: _contractspec_lib_schema0.SchemaModel<{
|
|
|
251
251
|
/**
|
|
252
252
|
* Query audit logs.
|
|
253
253
|
*/
|
|
254
|
-
declare const QueryAuditLogsContract:
|
|
254
|
+
declare const QueryAuditLogsContract: _contractspec_lib_contracts1.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
|
|
255
255
|
eventName: {
|
|
256
256
|
type: _contractspec_lib_schema0.FieldType<string, string>;
|
|
257
257
|
isOptional: true;
|
|
@@ -369,7 +369,7 @@ declare const QueryAuditLogsContract: _contractspec_lib_contracts0.OperationSpec
|
|
|
369
369
|
/**
|
|
370
370
|
* Get audit log by ID.
|
|
371
371
|
*/
|
|
372
|
-
declare const GetAuditLogContract:
|
|
372
|
+
declare const GetAuditLogContract: _contractspec_lib_contracts1.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
|
|
373
373
|
logId: {
|
|
374
374
|
type: _contractspec_lib_schema0.FieldType<string, string>;
|
|
375
375
|
isOptional: false;
|
|
@@ -435,7 +435,7 @@ declare const GetAuditLogContract: _contractspec_lib_contracts0.OperationSpec<_c
|
|
|
435
435
|
/**
|
|
436
436
|
* Get audit logs by trace ID.
|
|
437
437
|
*/
|
|
438
|
-
declare const GetAuditTraceContract:
|
|
438
|
+
declare const GetAuditTraceContract: _contractspec_lib_contracts1.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
|
|
439
439
|
traceId: {
|
|
440
440
|
type: _contractspec_lib_schema0.FieldType<string, string>;
|
|
441
441
|
isOptional: false;
|
|
@@ -507,7 +507,7 @@ declare const GetAuditTraceContract: _contractspec_lib_contracts0.OperationSpec<
|
|
|
507
507
|
/**
|
|
508
508
|
* Export audit logs.
|
|
509
509
|
*/
|
|
510
|
-
declare const ExportAuditLogsContract:
|
|
510
|
+
declare const ExportAuditLogsContract: _contractspec_lib_contracts1.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
|
|
511
511
|
orgId: {
|
|
512
512
|
type: _contractspec_lib_schema0.FieldType<string, string>;
|
|
513
513
|
isOptional: false;
|
|
@@ -547,7 +547,7 @@ declare const ExportAuditLogsContract: _contractspec_lib_contracts0.OperationSpe
|
|
|
547
547
|
/**
|
|
548
548
|
* Get audit statistics.
|
|
549
549
|
*/
|
|
550
|
-
declare const GetAuditStatsContract:
|
|
550
|
+
declare const GetAuditStatsContract: _contractspec_lib_contracts1.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
|
|
551
551
|
orgId: {
|
|
552
552
|
type: _contractspec_lib_schema0.FieldType<string, string>;
|
|
553
553
|
isOptional: true;
|
package/dist/contracts/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ScalarTypeEnum, defineEnum } from "@contractspec/lib.schema";
|
|
2
1
|
import { defineCommand, defineQuery, defineSchemaModel } from "@contractspec/lib.contracts";
|
|
2
|
+
import { ScalarTypeEnum, defineEnum } from "@contractspec/lib.schema";
|
|
3
3
|
|
|
4
4
|
//#region src/contracts/index.ts
|
|
5
5
|
const OWNERS = ["platform.audit-trail"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
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,IAAI,MAAM,GAAG,EAAE,aAAa,uBAAuB,CAAC;EAGpD,WAAW,MAAM,OAAO,EAAE,aAAa,mBAAmB,CAAC;EAC3D,cAAc,MAAM,IAAI,EAAE,aAAa,iBAAiB,CAAC;EACzD,SAAS,MAAM,KAAK,EAAE,aAAa,mCAAmC,CAAC;EAGvE,SAAS,MAAM,OAAO;GACpB,YAAY;GACZ,aAAa;GACd,CAAC;EACF,WAAW,MAAM,OAAO;GACtB,YAAY;GACZ,aAAa;GACd,CAAC;EACF,YAAY,MAAM,OAAO;GACvB,YAAY;GACZ,aAAa;GACd,CAAC;EAGF,UAAU,MAAM,OAAO;GACrB,YAAY;GACZ,aAAa;GACd,CAAC;EACF,YAAY,MAAM,OAAO;GACvB,YAAY;GACZ,aAAa;GACd,CAAC;EAGF,OAAO,MAAM,OAAO;GAClB,YAAY;GACZ,aAAa;GACd,CAAC;EACF,UAAU,MAAM,OAAO;GAAE,YAAY;GAAM,aAAa;GAAkB,CAAC;EAG3E,SAAS,MAAM,OAAO;GACpB,YAAY;GACZ,aAAa;GACd,CAAC;EACF,QAAQ,MAAM,OAAO;GAAE,YAAY;GAAM,aAAa;G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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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
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,wBAAQ,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,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AC1D,SAAO,KAAK,MAAM,EAAE,SAAS,CAAC;;CAGhC,MAAM,gBAAgB,MAA6B;EACjD,MAAM,SAAS,KAAK,QAAQ;AAC5B,OAAK,UAAU,KAAK,QAAQ,QAAQ,MAAM,IAAI,KAAK,EAAE,WAAW,IAAI,KAAK;AACzE,SAAO,SAAS,KAAK,QAAQ;;;;;CAM/B,SAAwB;AACtB,SAAO,CAAC,GAAG,KAAK,QAAQ;;;;;CAM1B,QAAc;AACZ,OAAK,UAAU,EAAE;;;;;;AAmBrB,IAAa,kBAAb,MAA6B;CAC3B,YAAY,AAAiB,QAA+B;EAA/B;;;;;CAK7B,eAAqB;EACnB,MAAM,yBAAS,IAAI,MAAM;AACzB,SAAO,QAAQ,OAAO,SAAS,GAAG,KAAK,OAAO,iBAAiB;AAC/D,SAAO;;;;;CAMT,mBAAgC;AAC9B,MAAI,CAAC,KAAK,OAAO,qBAAsB,QAAO;EAC9C,MAAM,yBAAS,IAAI,MAAM;AACzB,SAAO,QAAQ,OAAO,SAAS,GAAG,KAAK,OAAO,qBAAqB;AACnE,SAAO;;;;;CAMT,MAAM,MAAM,SAET;EACD,MAAM,SAAS,KAAK,cAAc;AAElC,SAAO,EAAE,cADY,MAAM,QAAQ,gBAAgB,OAAO,EACnC;;;;;;AAO3B,SAAgB,6BAAmD;AACjE,QAAO,IAAI,sBAAsB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/module.audit-trail",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"description": "Audit trail module for tracking and querying system events",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"events",
|
|
11
11
|
"typescript"
|
|
12
12
|
],
|
|
13
|
-
"main": "./dist/index.js",
|
|
14
13
|
"types": "./dist/index.d.ts",
|
|
15
14
|
"type": "module",
|
|
16
15
|
"scripts": {
|
|
@@ -26,25 +25,25 @@
|
|
|
26
25
|
"lint:check": "eslint src"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"@contractspec/lib.schema": "1.
|
|
30
|
-
"@contractspec/lib.contracts": "1.
|
|
31
|
-
"@contractspec/lib.bus": "1.
|
|
32
|
-
"zod": "^4.
|
|
28
|
+
"@contractspec/lib.schema": "1.48.0",
|
|
29
|
+
"@contractspec/lib.contracts": "1.48.0",
|
|
30
|
+
"@contractspec/lib.bus": "1.48.0",
|
|
31
|
+
"zod": "^4.3.5"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"@contractspec/tool.typescript": "1.
|
|
36
|
-
"@contractspec/tool.tsdown": "1.
|
|
34
|
+
"@contractspec/tool.typescript": "1.48.0",
|
|
35
|
+
"@contractspec/tool.tsdown": "1.48.0",
|
|
37
36
|
"typescript": "^5.9.3"
|
|
38
37
|
},
|
|
39
38
|
"exports": {
|
|
40
39
|
".": "./dist/index.js",
|
|
40
|
+
"./audit-trail.capability": "./dist/audit-trail.capability.js",
|
|
41
41
|
"./audit-trail.feature": "./dist/audit-trail.feature.js",
|
|
42
42
|
"./contracts": "./dist/contracts/index.js",
|
|
43
43
|
"./entities": "./dist/entities/index.js",
|
|
44
44
|
"./storage": "./dist/storage/index.js",
|
|
45
45
|
"./*": "./*"
|
|
46
46
|
},
|
|
47
|
-
"module": "./dist/index.js",
|
|
48
47
|
"files": [
|
|
49
48
|
"dist",
|
|
50
49
|
"README.md"
|