Move resolvePath and exec out of index.mjs into server/helpers.mjs so actions can import them directly rather than receiving them as arguments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
986 B
JavaScript
42 lines
986 B
JavaScript
// Pending queue — holds actions awaiting user approval.
|
|
|
|
import { randomUUID } from "crypto";
|
|
|
|
const pending = new Map();
|
|
|
|
export function enqueue(action, params) {
|
|
const id = randomUUID();
|
|
const entry = {
|
|
id,
|
|
action,
|
|
params,
|
|
status: "pending",
|
|
createdAt: new Date().toISOString(),
|
|
};
|
|
pending.set(id, entry);
|
|
console.log(`\n[QUEUE] New request #${id.slice(0, 8)}`);
|
|
console.log(` Action: ${action}`);
|
|
console.log(` Params: ${JSON.stringify(params)}`);
|
|
console.log(` Approve: POST /queue/${id}/approve`);
|
|
console.log(` Deny: POST /queue/${id}/deny\n`);
|
|
return id;
|
|
}
|
|
|
|
export function getEntry(id) {
|
|
return pending.get(id) ?? null;
|
|
}
|
|
|
|
export function listPending() {
|
|
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.resolvedAt = new Date().toISOString();
|
|
return entry;
|
|
}
|