// frontend/lib/notify/api.ts — notifyApi (triage/guard/digests/senders + reclassify/undo) import type { Digest, Notification, NotifyBucket, NotifyGuard, SenderRule, Triage, } from "@/lib/types"; const J = { "Content-Type": "application/json" }; async function ok(r: Response): Promise { if (!r.ok) throw new Error(`${r.status} ${r.statusText}`); return r.json() as Promise; } export const notifyApi = { triage: () => fetch("/api/notifications", { cache: "no-store" }).then((r) => ok(r)), guard: () => fetch("/api/notifications/guard", { cache: "no-store" }).then((r) => ok(r)), digests: () => fetch("/api/notifications/digests", { cache: "no-store" }).then((r) => ok(r)), senders: () => fetch("/api/notifications/senders", { cache: "no-store" }).then((r) => ok(r)), reclassify: (id: string, to_bucket: NotifyBucket) => fetch(`/api/notifications/${id}/reclassify`, { method: "POST", headers: J, body: JSON.stringify({ to_bucket }), }).then((r) => ok(r)), undo: (id: string) => fetch(`/api/notifications/${id}/undo`, { method: "POST", headers: J, body: "{}" }).then((r) => ok(r), ), setGuard: (on: boolean) => fetch("/api/notifications/guard", { method: "POST", headers: J, body: JSON.stringify({ on }), }).then((r) => ok(r)), };