"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.listAlerts = listAlerts; exports.resolveAlert = resolveAlert; exports.getSecuritySettings = getSecuritySettings; exports.updateSecuritySettings = updateSecuritySettings; exports.runIntegrityCheck = runIntegrityCheck; exports.listDbTamperEvents = listDbTamperEvents; exports.processDbTamperCheck = processDbTamperCheck; exports.exportDbTamperEventsCsv = exportDbTamperEventsCsv; exports.dismissSpuriousTamperAlerts = dismissSpuriousTamperAlerts; exports.updateUserSecurity = updateUserSecurity; const securityService = __importStar(require("../services/securityService")); async function listAlerts(req, res) { try { const status = req.query.status; const userId = req.query.userId || undefined; const limit = parseInt(req.query.limit || '50', 10); const offset = parseInt(req.query.offset || '0', 10); const result = await securityService.listSecurityAlerts({ status, userId, limit, offset }); res.json(result); } catch (e) { const msg = e instanceof Error ? e.message : 'Failed to list security alerts'; res.status(500).json({ error: msg }); } } async function resolveAlert(req, res) { try { const alertId = req.params.alertId; const { status, resolutionNote, reactivateWithdrawals } = req.body; if (!status) { res.status(400).json({ error: 'status is required' }); return; } const alert = await securityService.resolveAlert(alertId, req.user.userId, status, resolutionNote, reactivateWithdrawals); if (!alert) { res.status(404).json({ error: 'Alert not found' }); return; } res.json({ message: 'Updated', alertId }); } catch (e) { const msg = e instanceof Error ? e.message : 'Failed to resolve alert'; res.status(400).json({ error: msg }); } } async function getSecuritySettings(_req, res) { try { const settings = await securityService.getSecuritySettings(); res.json(settings); } catch (e) { const msg = e instanceof Error ? e.message : 'Failed to load security settings'; res.status(500).json({ error: msg }); } } async function updateSecuritySettings(req, res) { try { const { alertEmails } = req.body; if (!Array.isArray(alertEmails)) { res.status(400).json({ error: 'alertEmails array is required' }); return; } const settings = await securityService.updateSecuritySettings(alertEmails); res.json(settings); } catch (e) { const msg = e instanceof Error ? e.message : 'Failed to update security settings'; res.status(400).json({ error: msg }); } } async function runIntegrityCheck(_req, res) { try { const issues = await securityService.runLedgerIntegrityCheck(); res.json({ issuesFound: issues.length, issues }); } catch (e) { const msg = e instanceof Error ? e.message : 'Integrity check failed'; res.status(500).json({ error: msg }); } } async function listDbTamperEvents(req, res) { try { const { listDbTamperEvents: listEvents } = await Promise.resolve().then(() => __importStar(require('../services/dbTamperService'))); const limit = parseInt(req.query.limit || '50', 10); const offset = parseInt(req.query.offset || '0', 10); const tableName = req.query.tableName || undefined; const result = await listEvents({ limit, offset, tableName }); res.json(result); } catch (e) { const msg = e instanceof Error ? e.message : 'Failed to list DB tamper events'; res.status(500).json({ error: msg }); } } async function processDbTamperCheck(_req, res) { try { const { processDbTamperEvents } = await Promise.resolve().then(() => __importStar(require('../services/dbTamperService'))); const processed = await processDbTamperEvents(); res.json({ processed }); } catch (e) { const msg = e instanceof Error ? e.message : 'DB tamper check failed'; res.status(500).json({ error: msg }); } } async function exportDbTamperEventsCsv(req, res) { try { const { buildDbTamperEventsCsv } = await Promise.resolve().then(() => __importStar(require('../services/dbTamperService'))); const tableName = req.query.tableName || undefined; const fromRaw = req.query.from ? String(req.query.from) : undefined; const toRaw = req.query.to ? String(req.query.to) : undefined; const from = fromRaw ? new Date(fromRaw) : undefined; const to = toRaw ? new Date(toRaw) : undefined; if (from && Number.isNaN(from.getTime())) { res.status(400).json({ error: 'Invalid from date (use ISO 8601)' }); return; } if (to && Number.isNaN(to.getTime())) { res.status(400).json({ error: 'Invalid to date (use ISO 8601)' }); return; } const csv = await buildDbTamperEventsCsv({ tableName, from, to }); const filename = `db-tamper-audit-${new Date().toISOString().slice(0, 10)}.csv`; res.setHeader('Content-Type', 'text/csv; charset=utf-8'); res.setHeader('Content-Disposition', `attachment; filename="${filename}"`); res.send(csv); } catch (e) { const msg = e instanceof Error ? e.message : 'Export failed'; res.status(500).json({ error: msg }); } } async function dismissSpuriousTamperAlerts(req, res) { try { const count = await securityService.dismissSpuriousTamperAlerts(req.user.userId); res.json({ dismissed: count, message: `${count} fausse(s) alerte(s) classée(s) comme rejetée(s).` }); } catch (e) { const msg = e instanceof Error ? e.message : 'Cleanup failed'; res.status(500).json({ error: msg }); } } async function updateUserSecurity(req, res) { try { const userId = req.params.userId; const { withdrawalsSuspended, underSurveillance, reactivateWithdrawals, reason } = req.body; const { updateSecurityFlags } = await Promise.resolve().then(() => __importStar(require('../repositories/userRepository'))); if (reactivateWithdrawals) { await updateSecurityFlags(userId, { withdrawals_suspended: false, under_surveillance: false, clear_security_reason: true, }); res.json({ message: 'Withdrawals reactivated' }); return; } const flags = {}; if (typeof withdrawalsSuspended === 'boolean') flags.withdrawals_suspended = withdrawalsSuspended; if (typeof underSurveillance === 'boolean') flags.under_surveillance = underSurveillance; if (reason) flags.security_reason_encrypted = reason; if (withdrawalsSuspended || underSurveillance) flags.set_suspended_at = true; if (Object.keys(flags).length === 0) { res.status(400).json({ error: 'No security flags provided' }); return; } await updateSecurityFlags(userId, flags); res.json({ message: 'Security flags updated' }); } catch (e) { const msg = e instanceof Error ? e.message : 'Update failed'; res.status(400).json({ error: msg }); } } //# sourceMappingURL=securityController.js.map