40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
|
|
|
export interface Scenario {
|
|
id: string;
|
|
name: string;
|
|
status: string;
|
|
kpis_json: string | null;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface ProgressEvent {
|
|
stage: string;
|
|
pct: number;
|
|
}
|
|
|
|
export async function createScenario(name: string): Promise<Scenario> {
|
|
const res = await fetch(`${API_BASE}/api/scenarios`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ name }),
|
|
});
|
|
if (!res.ok) throw new Error(`API error ${res.status}`);
|
|
return res.json() as Promise<Scenario>;
|
|
}
|
|
|
|
export async function getScenario(id: string): Promise<Scenario> {
|
|
const res = await fetch(`${API_BASE}/api/scenarios/${id}`);
|
|
if (!res.ok) throw new Error(`API error ${res.status}`);
|
|
return res.json() as Promise<Scenario>;
|
|
}
|
|
|
|
export async function listScenarios(): Promise<Scenario[]> {
|
|
const res = await fetch(`${API_BASE}/api/scenarios`);
|
|
if (!res.ok) throw new Error(`API error ${res.status}`);
|
|
return res.json() as Promise<Scenario[]>;
|
|
}
|
|
|
|
export function scenarioEventsUrl(id: string): string {
|
|
return `${API_BASE}/api/scenarios/${id}/events`;
|
|
}
|