UNPKG

tfl-ts

Version:

🚇 Fully-typed TypeScript client for Transport for London (TfL) API • Zero dependencies • Auto-generated types • Real-time arrivals • Journey planning • Universal compatibility

128 lines (127 loc) 5.09 kB
import { Line } from './line'; import { AccidentStats } from './accidentStats'; import { AirQuality } from './airQuality'; import { BikePoint } from './bikePoint'; import { Cabwise } from './cabwise'; import { Journey } from './journey'; import { StopPoint } from './stopPoint'; import { Mode } from './mode'; import { Road } from './road'; import { Modes, ServiceTypes, DisruptionCategories } from './generated/meta/Meta'; import { Lines } from './generated/meta/Line'; import { TflError, TflHttpError, TflNetworkError, TflValidationError, TflTimeoutError, TflConfigError, TflErrorHandler } from './errors'; type ModeName = typeof Modes[number]['modeName']; type ServiceType = typeof ServiceTypes[number]; type DisruptionCategory = typeof DisruptionCategories[number]; type LineId = typeof Lines[number]['id']; declare const LINE_IDS: Record<string, Record<string, string>>; declare const MODES: Record<string, any>; declare const SERVICE_TYPES: { readonly REGULAR: ServiceType; readonly NIGHT: ServiceType; }; declare const DIRECTIONS: { readonly INBOUND: "inbound"; readonly OUTBOUND: "outbound"; readonly ALL: "all"; }; declare const severityByMode: Record<string, { level: number; description: string; }[]>; declare const severityDescriptions: readonly string[]; export type TflLineId = LineId; export type TflMode = keyof typeof MODES; export type TflServiceType = typeof SERVICE_TYPES[keyof typeof SERVICE_TYPES]; export type TflDirection = typeof DIRECTIONS[keyof typeof DIRECTIONS]; interface TflClientConfig { appId?: string; appKey?: string; /** Timeout for API requests in milliseconds (default: 30000) */ timeout?: number; /** Maximum number of retries for failed requests (default: 3) */ maxRetries?: number; /** Retry delay in milliseconds (default: 1000) */ retryDelay?: number; } declare class TflClient { private api; private config; /** * Access all London Underground, Elizabeth line, DLR, Overground, Tram, and other Tfl line data. */ line: Line; /** * Access all Tfl stop points (stations, bus stops, piers, etc). */ stopPoint: StopPoint; /** * Plan journeys across all supported Tfl modes (tube, bus, rail, etc). */ journey: Journey; /** * Access all available transport modes and their metadata. */ mode: Mode; /** * Access all London road corridors and road status/disruption info. */ road: Road; /** * Access all London bike point locations and real-time availability. */ bikePoint: BikePoint; /** * ⚠️ **DEPRECATED API - NOT RECOMMENDED FOR USE** * * Access accident statistics for London roads. * * This API appears to be poorly maintained on TfL's side and may not return * current or reliable data. Recent testing shows that most years return * "Invalid year parameter" errors, suggesting the API is no longer actively * supported. * * **RECOMMENDED ALTERNATIVES:** * - London Datastore: https://data.london.gov.uk/dataset/?tags=GIS&tag=accidents * - TfL Road Safety Data: https://tfl.gov.uk/corporate/publications-and-reports/road-safety */ accidentStats: AccidentStats; /** * ⚠️ **DEPRECATED API - NOT RECOMMENDED FOR USE** * * Access real-time air quality data for London. * * This API appears to be poorly maintained on TfL's side and may not return * current or reliable data. Recent testing shows 500 Internal Server Error * responses, suggesting the API is no longer actively supported. * * **RECOMMENDED ALTERNATIVES:** * - London Air API: https://londonair.org.uk/Londonair/API/ * - London Datastore Air Quality: https://data.london.gov.uk/air-quality/ */ airQuality: AirQuality; /** * Access taxi and minicab contact information through TfL Cabwise service. */ cabwise: Cabwise; constructor(config?: TflClientConfig); /** * Execute an API call with error handling and retry logic */ executeWithRetry<T>(apiCall: () => Promise<T>, _context?: string): Promise<T>; /** * Generate a unique request ID for tracking */ private generateRequestId; /** * Get client configuration */ getConfig(): Readonly<TflClientConfig>; } export default TflClient; export { LINE_IDS, MODES, SERVICE_TYPES, DIRECTIONS, severityByMode, severityDescriptions }; export type { ModeName, ServiceType, DisruptionCategory }; export { TflError, TflHttpError, TflNetworkError, TflValidationError, TflTimeoutError, TflConfigError, TflErrorHandler }; export * from './utils/ui'; export { getLineColor, getLineCssProps, getSeverityCategory, getSeverityClasses, getAccessibleSeverityLabel, sortLinesBySeverityAndOrder, getLineStatusSummary, isNormalService, hasNightService, getLineAriaLabel, getLineDisplayName, LINE_COLORS, SEVERITY_MAPPING, LINE_ORDER } from './utils/ui'; export { getPropertyValue, findElectricBikes, sortByDistance, findClosestWithBikes } from './utils/bikePoint';