Initial LinkedSign platform

This commit is contained in:
2026-04-06 20:33:59 -05:00
commit 1074c7c9d2
159 changed files with 19072 additions and 0 deletions
@@ -0,0 +1,44 @@
const db = require('../../config/db');
const fs = require('fs/promises');
const path = require('path');
const saveEvent = async (event) => {
try {
await db.execute(
'INSERT INTO audit_logs (type, user_id, email, ip, user_agent, metadata) VALUES (?, ?, ?, ?, ?, ?)',
[
event.type,
event.userId || null,
event.email || null,
event.ip || null,
event.userAgent || null,
event.metadata ? JSON.stringify(event.metadata) : null,
]
);
} catch (err) {
// Fallback to file log if DB fails
try {
const logsDir = path.resolve(process.cwd(), 'logs');
await fs.mkdir(logsDir, { recursive: true });
await fs.appendFile(
path.resolve(logsDir, 'audit.log'),
`${JSON.stringify({ ...event, _fallback: true })}\n`
);
} catch {
// Silent
}
}
};
const getEvents = async ({ type, userId, limit = 100, offset = 0 } = {}) => {
let sql = 'SELECT * FROM audit_logs WHERE 1=1';
const params = [];
if (type) { sql += ' AND type = ?'; params.push(type); }
if (userId) { sql += ' AND user_id = ?'; params.push(userId); }
sql += ' ORDER BY created_at DESC LIMIT ? OFFSET ?';
params.push(limit, offset);
const [rows] = await db.execute(sql, params);
return rows;
};
module.exports = { saveEvent, getEvents };