Files
aris/packages/aris-data-source-tfl/scripts/fetch-fixtures.ts
kenneth 8ec8b9a13e Add @aris/data-source-tfl package
TfL data source for tube, overground, and Elizabeth line alerts.

- Fetches line statuses and filters to minor/major delays and closures
- Sorts alerts by severity, then by proximity to user location
- Caches station data after first fetch
- Uses arktype for API response validation
- Supports API injection for testing

Co-authored-by: Ona <no-reply@ona.com>
2026-01-16 23:57:29 +00:00

36 lines
1.2 KiB
TypeScript

// Fetches real TfL API responses and saves them as test fixtures
const TEST_LINES = ["northern", "central", "elizabeth"]
const BASE_URL = "https://api.tfl.gov.uk"
async function fetchFixtures() {
console.log("Fetching line statuses...")
const statusRes = await fetch(`${BASE_URL}/Line/${TEST_LINES.join(",")}/Status`)
const lineStatuses = await statusRes.json()
console.log("Fetching stop points...")
const stopPoints: Record<string, unknown> = {}
for (const lineId of TEST_LINES) {
console.log(` Fetching ${lineId}...`)
const res = await fetch(`${BASE_URL}/Line/${lineId}/StopPoints`)
stopPoints[lineId] = await res.json()
}
const fixtures = {
fetchedAt: new Date().toISOString(),
lineStatuses,
stopPoints,
}
const path = new URL("../fixtures/tfl-responses.json", import.meta.url)
await Bun.write(path, JSON.stringify(fixtures, null, "\t"))
console.log(`\nFixtures saved to fixtures/tfl-responses.json`)
console.log(` Line statuses: ${(lineStatuses as unknown[]).length} lines`)
for (const [lineId, stops] of Object.entries(stopPoints)) {
console.log(` ${lineId} stops: ${(stops as unknown[]).length}`)
}
}
fetchFixtures().catch(console.error)