steam-backlog-enforcer/web/src/api.ts
Krzysztof kuhy Rudnicki fcae46faf1 Show the gaming budget in the web UI
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 07:17:42 +02:00

26 lines
853 B
TypeScript

import type { BudgetSnapshot, WebDataset } from './types'
/** Fetch and decode a JSON document from the Python backend. */
async function getJson<T>(path: string): Promise<T> {
const resp = await fetch(path)
if (!resp.ok) {
throw new Error(`API returned ${resp.status} ${resp.statusText}`)
}
return (await resp.json()) as T
}
/** Fetch the projected dataset from the Python backend. */
export function fetchDataset(): Promise<WebDataset> {
return getJson<WebDataset>('/api/dataset')
}
/**
* Fetch the current gaming-budget snapshot.
*
* `demo` reads the short-budget demo run instead of production, which is how
* the cutoff can be watched in the browser without spending a real day.
*/
export function fetchBudget(demo: boolean): Promise<BudgetSnapshot> {
return getJson<BudgetSnapshot>(`/api/budget${demo ? '?demo=1' : ''}`)
}