Files
2026-04-05 00:43:23 +05:30

20 lines
739 B
TypeScript

// Thin API client for the negoT8 FastAPI backend
import type { Negotiation, Stats } from "./types";
const BASE = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
async function get<T>(path: string): Promise<T> {
const res = await fetch(`${BASE}${path}`, { cache: "no-store" });
if (!res.ok) throw new Error(`GET ${path}${res.status}`);
return res.json() as Promise<T>;
}
export const api = {
stats: () => get<Stats>("/api/stats"),
negotiations: () =>
get<{ negotiations: Negotiation[]; total: number }>("/api/negotiations"),
negotiation: (id: string) => get<Negotiation>(`/api/negotiations/${id}`),
analytics: (id: string) =>
get<Negotiation["analytics"]>(`/api/negotiations/${id}/analytics`),
};