Each request logs timestamp, method, path and user. Queue entries log a single line on enqueue and on resolve. Drop the verbose approve/deny curl instructions from queue output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
998 B
JavaScript
42 lines
998 B
JavaScript
import { randomUUID } from 'crypto';
|
|
|
|
const pending = new Map();
|
|
|
|
function ts() {
|
|
return new Date().toLocaleTimeString();
|
|
}
|
|
|
|
export function enqueue(action, params, submitted_by) {
|
|
const id = randomUUID();
|
|
const entry = {
|
|
id,
|
|
action,
|
|
params,
|
|
submitted_by,
|
|
status: 'pending',
|
|
created_at: new Date().toISOString(),
|
|
};
|
|
pending.set(id, entry);
|
|
console.log(`[${ts()}] [QUEUE] ${submitted_by} requested '${action}' (${id.slice(0, 8)}) — params: ${JSON.stringify(params)}`);
|
|
return id;
|
|
}
|
|
|
|
export function get_entry(id) {
|
|
return pending.get(id) ?? null;
|
|
}
|
|
|
|
export function list_pending() {
|
|
return [...pending.values()].filter((e) => e.status === 'pending');
|
|
}
|
|
|
|
export function resolve(id, decision) {
|
|
const entry = pending.get(id);
|
|
if (!entry) {
|
|
return null;
|
|
}
|
|
entry.status = decision; // 'approved' | 'denied'
|
|
entry.resolved_at = new Date().toISOString();
|
|
console.log(`[${ts()}] [QUEUE] ${id.slice(0, 8)} ${decision} by ${entry.resolved_by ?? 'unknown'}`);
|
|
return entry;
|
|
}
|