import { ActionError } from "@/lib/system/actions"; // The system actions' answers: JSON, never cached; an error in words with its // status, and the plan when the confirm was refused by it. export const ok = (v: unknown) => Response.json(v, { headers: { "cache-control": "no-store" } }); export function fail(e: unknown) { const status = e instanceof ActionError ? e.status : 500; const plan = e instanceof ActionError ? e.plan : null; return Response.json({ error: e instanceof Error ? e.message : String(e), ...(plan ? { plan } : {}) }, { status, headers: { "cache-control": "no-store" } }); } export async function bodyOf(request: Request): Promise> { const b = (await request.json().catch(() => null)) as Record | null; if (!b || typeof b !== "object" || Array.isArray(b)) throw new ActionError("expected a JSON object"); return b; }