import { API_BASE } from "@/lib/config" import type { Account, CreateAccountInput, Template, CreateTemplateInput, Domain, CreateDomainInput, ChangesetResponse, ApplyRequest, } from "./types" async function req(path: string, init?: RequestInit): Promise { const res = await fetch(`${API_BASE}${path}`, { headers: { "Content-Type": "application/json" }, method: "GET", ...init, }) if (!res.ok) { let msg = `HTTP ${res.status}` try { const b = await res.json(); if (b?.error) msg = String(b.error) } catch { /* ignore */ } throw new Error(msg) } if (res.status === 204) return undefined as T return (await res.json()) as T } export const api = { listAccounts: () => req("/accounts"), createAccount: (input: CreateAccountInput) => req("/accounts", { method: "POST", body: JSON.stringify(input) }), deleteAccount: (id: string) => req(`/accounts/${id}`, { method: "DELETE" }), listTemplates: () => req("/templates"), createTemplate: (input: CreateTemplateInput) => req