audit-log.mjs
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
1 day ago
| 1 | /** |
| 2 | * Hub audit log. Appends events to data_dir/hub_audit.log. |
| 3 | */ |
| 4 | |
| 5 | import fs from 'fs'; |
| 6 | import path from 'path'; |
| 7 | |
| 8 | /** |
| 9 | * Append an audit entry. Creates data_dir if needed. |
| 10 | * @param {string} dataDir - Path to data directory |
| 11 | * @param {{ |
| 12 | * userId: string, |
| 13 | * action: string, |
| 14 | * proposalId: string, |
| 15 | * detail?: Record<string, unknown>, |
| 16 | * }} entry |
| 17 | */ |
| 18 | export function appendAudit(dataDir, entry) { |
| 19 | const logPath = path.join(dataDir, 'hub_audit.log'); |
| 20 | const dir = path.dirname(logPath); |
| 21 | if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); |
| 22 | const line = |
| 23 | JSON.stringify({ |
| 24 | ts: new Date().toISOString(), |
| 25 | user_id: entry.userId, |
| 26 | action: entry.action, |
| 27 | proposal_id: entry.proposalId, |
| 28 | ...(entry.detail && typeof entry.detail === 'object' ? { detail: entry.detail } : {}), |
| 29 | }) + '\n'; |
| 30 | fs.appendFileSync(logPath, line, 'utf8'); |
| 31 | } |
File History
1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
1 day ago