UNPKG

dhis2-mcp-server

Version:

A Model Context Protocol server providing 108 tools for DHIS2 development, including code generators, debugging helpers, and documentation access for web and Android app development.

77 lines 2.74 kB
export class AuditLogger { entries = []; maxEntries = 1000; // Keep last 1000 entries in memory log(entry) { const auditEntry = { ...entry, timestamp: new Date().toISOString(), }; // Sanitize sensitive data auditEntry.parameters = this.sanitizeParameters(auditEntry.parameters); this.entries.push(auditEntry); // Maintain max entries limit if (this.entries.length > this.maxEntries) { this.entries = this.entries.slice(-this.maxEntries); } // Log to console for development console.log(`[AUDIT] ${auditEntry.timestamp} - ${auditEntry.toolName}: ${auditEntry.outcome}${auditEntry.error ? ` (${auditEntry.error})` : ''}`); } sanitizeParameters(params) { const sanitized = { ...params }; // Remove sensitive information if (sanitized.password) { sanitized.password = '***REDACTED***'; } if (sanitized.token) { sanitized.token = '***REDACTED***'; } if (sanitized.apiKey) { sanitized.apiKey = '***REDACTED***'; } return sanitized; } getAuditTrail(limit) { const entries = limit ? this.entries.slice(-limit) : this.entries; return [...entries]; // Return copy to prevent mutation } getSuccessCount() { return this.entries.filter(entry => entry.outcome === 'success').length; } getErrorCount() { return this.entries.filter(entry => entry.outcome === 'error').length; } getAuditSummary() { const toolUsage = new Map(); this.entries.forEach(entry => { toolUsage.set(entry.toolName, (toolUsage.get(entry.toolName) || 0) + 1); }); const mostUsedTools = Array.from(toolUsage.entries()) .map(([tool, count]) => ({ tool, count })) .sort((a, b) => b.count - a.count) .slice(0, 10); const recentErrors = this.entries .filter(entry => entry.outcome === 'error') .slice(-5); return { totalOperations: this.entries.length, successCount: this.getSuccessCount(), errorCount: this.getErrorCount(), mostUsedTools, recentErrors }; } exportAuditLog() { return JSON.stringify({ exportTimestamp: new Date().toISOString(), entries: this.entries, summary: this.getAuditSummary() }, null, 2); } clear() { this.entries = []; console.log('[AUDIT] Audit log cleared'); } } // Global audit logger instance export const auditLogger = new AuditLogger(); //# sourceMappingURL=audit-logger.js.map