export interface ChokepointRow {
id: string;
name: string;
status: 'green' | 'yellow' | 'red';
disruption_score: number;
war_risk_tier: string;
congestion_level: string | null;
active_warnings: number;
ais_disruptions: number;
transit_today_total: number | null;
flow_ratio: number | null;
flow_disrupted: boolean | null;
}
export async function getChokepointStatusOpenData(chokepointId?: string) {
const res = await fetch('https://www.worldmonitor.app/data/v1/chokepoints/latest.json', {
headers: { 'User-Agent': 'chokepoint-agent-tool/1.0 (+https://example.com)' },
signal: AbortSignal.timeout(10_000),
});
if (!res.ok) throw new Error(`Chokepoint dataset HTTP ${res.status}`);
const data = (await res.json()) as {
snapshot_date: string;
source_fetched_at: string;
chokepoints: ChokepointRow[];
};
const rows = chokepointId
? data.chokepoints.filter((row) => row.id === chokepointId)
: data.chokepoints;
return {
snapshotDate: data.snapshot_date,
sourceFetchedAt: data.source_fetched_at,
chokepoints: rows,
};
}