Adds audit logging and sync management infrastructure

Introduces comprehensive audit trail system with:
- AuditService to track entity changes
- SyncManager for background sync of audit entries
- New CoreEvents for entity and audit tracking
- Simplified sync architecture with event-driven approach

Prepares system for enhanced compliance and change tracking
This commit is contained in:
Janus C. H. Knudsen 2025-11-21 23:23:04 +01:00
parent dcd76836bd
commit 9ea98e3a04
18 changed files with 469 additions and 414 deletions

View file

@ -0,0 +1,47 @@
import { IApiRepository } from './IApiRepository';
import { IAuditEntry } from '../types/AuditTypes';
import { EntityType } from '../types/CalendarTypes';
/**
* MockAuditRepository - Mock API repository for audit entries
*
* In production, this would send audit entries to the backend.
* For development/testing, it just logs the operations.
*/
export class MockAuditRepository implements IApiRepository<IAuditEntry> {
readonly entityType: EntityType = 'Audit';
async sendCreate(entity: IAuditEntry): Promise<void> {
// Simulate API call delay
await new Promise(resolve => setTimeout(resolve, 100));
console.log('MockAuditRepository: Audit entry synced to backend:', {
id: entity.id,
entityType: entity.entityType,
entityId: entity.entityId,
operation: entity.operation,
timestamp: new Date(entity.timestamp).toISOString()
});
}
async sendUpdate(_id: string, _entity: IAuditEntry): Promise<void> {
// Audit entries are immutable - updates should not happen
throw new Error('Audit entries cannot be updated');
}
async sendDelete(_id: string): Promise<void> {
// Audit entries should never be deleted
throw new Error('Audit entries cannot be deleted');
}
async fetchAll(): Promise<IAuditEntry[]> {
// For now, return empty array - audit entries are local-first
// In production, this could fetch audit history from backend
return [];
}
async fetchById(_id: string): Promise<IAuditEntry | null> {
// For now, return null - audit entries are local-first
return null;
}
}