Files
events-hub/backend/src/utils/audit.js
T
joshuaandClaude Opus 5.5 e72330893a Hub v1: install API, licences, health dashboard, alerts
- Protocol 1 (docs/hub-protocol.md): public key, register, signed heartbeats
- Ed25519 licence tokens (30-day validity, status, expiry, grace, limits)
- Dashboard: installs, install detail, customers and licences, alerts,
  settings and audit log; two-factor login required
- Alert checks every 5 minutes, emailed once; heartbeat roll-up after 30 days
- Unit tests for encryption, tokens, signatures, TOTP and alert rules

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
2026-10-26 12:12:51 +02:00

17 lines
551 B
JavaScript

const prisma = require('../config/db');
function clientIp(req) {
return req?.ip || req?.socket?.remoteAddress || null;
}
/** Record an admin action. Never throws — logging must not break the action itself. */
async function audit(req, action, target = null, metadata = null) {
try {
await prisma.auditLog.create({ data: { actorId: req?.admin?.id || null, action, target, metadata: metadata || undefined, ip: clientIp(req) } });
} catch (e) {
console.error('[audit] failed:', e?.message);
}
}
module.exports = { audit, clientIp };