import type { Campaign, CampaignSummary, DecisionRecord, GatedResult, PolicySection, Stats, } from "./types"; async function j(r: Response): Promise { if (!r.ok) { const body = await r.json().catch(() => ({ detail: r.statusText })); throw new Error(typeof body.detail === "string" ? body.detail : `HTTP ${r.status}`); } return r.json() as Promise; } const post = (url: string, payload: unknown) => fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); export const getStats = () => fetch("/api/stats").then((r) => j(r)); export const getCampaigns = () => fetch("/api/campaigns").then((r) => j(r)); export const getCampaign = (id: string) => fetch(`/api/campaigns/${id}`).then((r) => j(r)); export const getDecisions = () => fetch("/api/decisions").then((r) => j(r)); export const getPolicy = () => fetch("/api/policy").then((r) => j(r)); export const runTriage = (campaign_id: string, provider: string, force = false) => post("/api/triage", { campaign_id, provider, force }).then((r) => j(r)); export const postDecision = ( campaign_id: string, human_decision: string, moderator: string, reason: string, ) => post("/api/decisions", { campaign_id, human_decision, moderator, reason }).then((r) => j(r), );