// Typed wrappers around the mapdash HTTP API. All network access for the app // goes through here, so response shapes stay in one typed place. import type { Meta, Board, Booking, Filters } from './types'; function buildQuery(f: Filters): string { const params = new URLSearchParams({ city: f.cities.join(','), dimension: f.dimensions.join(','), search: f.search, }); return params.toString(); } async function getJson(url: string): Promise { const res = await fetch(url); if (!res.ok) { throw new Error(`Request failed: ${url} -> HTTP ${res.status}`); } return (await res.json()) as T; } export const api = { meta: (): Promise => getJson('/api/meta'), boards: (f: Filters): Promise => getJson('/api/boards?' + buildQuery(f)), bookings: (f: Filters): Promise => getJson('/api/bookings?' + buildQuery(f)), };