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
179 lines (178 loc) • 7.25 kB
JavaScript
"use strict";
/**
* Cabwise API Module
*
* Provides access to taxi and minicab contact information through the TfL Cabwise service.
* This module allows users to search for nearby taxi and minicab services based on location.
*
* **Note**: While this API is functional and returns data, the information provided may have limitations:
* - Some operators may have very few vehicles (e.g., 1-2 vehicles)
* - Addresses are often registration addresses rather than operational addresses
* - For comprehensive local minicab information, consider using the official TfL form:
* https://tfl.gov.uk/forms/12389.aspx
*
* @example
* // Search for nearby taxi services
* const results = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* radius: 5000,
* maxResults: 10
* });
*
* // Search for wheelchair accessible services
* const accessibleResults = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* wc: 'true',
* optype: 'Minicab' // TypeScript provides autocomplete for valid operator types
* });
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cabwise = void 0;
const stripTypes_1 = require("./utils/stripTypes");
// Import raw data from generated meta files
const Meta_1 = require("./generated/meta/Meta");
/**
* Cabwise class for interacting with TfL Cabwise API endpoints
*
* This API provides access to licensed private hire operators in London.
* While functional, users should be aware that some operators may have limited
* vehicle fleets and addresses may be registration rather than operational.
*
* @example
* // Search for nearby taxi services
* const results = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* radius: 5000,
* maxResults: 10
* });
*
* // Search for wheelchair accessible services
* const accessibleResults = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* wc: 'true',
* optype: 'Minicab' // TypeScript provides autocomplete for valid operator types
* });
*/
class Cabwise {
constructor(api) {
this.api = api;
/** Available mode names (static, no HTTP request needed) */
this.MODE_NAMES = Meta_1.Modes.map(m => m.modeName);
/** Available service types (static, no HTTP request needed) */
this.SERVICE_TYPES = Meta_1.ServiceTypes;
/** Available disruption categories (static, no HTTP request needed) */
this.DISRUPTION_CATEGORIES = Meta_1.DisruptionCategories;
/** Available place types (static, no HTTP request needed) */
this.PLACE_TYPES = Meta_1.PlaceTypes;
/** Available search providers (static, no HTTP request needed) */
this.SEARCH_PROVIDERS = Meta_1.SearchProviders;
/** Available sort options (static, no HTTP request needed) */
this.SORT_OPTIONS = Meta_1.Sorts;
/** Available stop types (static, no HTTP request needed) */
this.STOP_TYPES = Meta_1.StopTypes;
/** Available categories with their keys (static, no HTTP request needed) */
this.CATEGORIES = Meta_1.Categories;
/** All severity levels and descriptions (static, no HTTP request needed) */
this.ALL_SEVERITY = Meta_1.Severity;
/** Available operator types for cabwise searches */
this.OPERATOR_TYPES = [
'Chauffeur',
'Contract',
'Driver Guide(Tourist service)',
'Executive',
'Limousine',
'Minicab',
'MPV',
'Other',
'School Runs',
'Unknown'
];
}
/**
* Gets taxis and minicabs contact information
*
* This method searches for taxi and minicab services near a specified location,
* with optional filters for operator type, accessibility, and service availability.
*
* @param params - Search parameters including location and optional filters
* @returns Promise resolving to taxi and minicab contact information
* @example
* // Search for nearby taxi services
* const results = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* radius: 5000,
* maxResults: 10
* });
*
* // Search for wheelchair accessible services
* const accessibleResults = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* wc: 'true',
* optype: 'Minicab' // TypeScript provides autocomplete for valid operator types
* });
*
* // Search for 24/7 services
* const twentyFourSevenResults = await client.cabwise.search({
* lat: 51.514792,
* lon: -0.118509,
* twentyFourSevenOnly: true
* });
*/
async search(params) {
const { keepTflTypes, ...searchParams } = params;
return this.api.cabwise.cabwiseGet(searchParams)
.then(response => (0, stripTypes_1.stripTypeFields)(response.data, keepTflTypes));
}
/**
* Get API endpoint information
*
* This method returns information about the available API endpoints
* for the Cabwise module.
*
* @returns Object containing endpoint information
* @example
* // Get endpoint information
* const endpoints = client.cabwise.getEndpoints();
* console.log('Available endpoints:', Object.keys(endpoints));
*
* // Get specific endpoint details
* const searchEndpoint = endpoints.SEARCH;
* console.log('Search endpoint path:', searchEndpoint.path);
* console.log('Search endpoint method:', searchEndpoint.method);
*/
getEndpoints() {
return Cabwise.ENDPOINTS;
}
}
exports.Cabwise = Cabwise;
/** API name for this module */
Cabwise.API_NAME = 'Cabwise API';
/** Available API endpoints */
Cabwise.ENDPOINTS = {
/** Search for taxi and minicab services */
SEARCH: {
path: '/Cabwise/search',
method: 'GET',
description: 'Gets taxis and minicabs contact information',
parameters: [
{ name: 'lat', type: 'number', required: true, description: 'Latitude' },
{ name: 'lon', type: 'number', required: true, description: 'Longitude' },
{ name: 'optype', type: 'string', required: false, description: 'Operator Type e.g Minicab, Executive, Limousine' },
{ name: 'wc', type: 'string', required: false, description: 'Wheelchair accessible' },
{ name: 'radius', type: 'number', required: false, description: 'The radius of the bounding circle in metres' },
{ name: 'name', type: 'string', required: false, description: 'Trading name of operating company' },
{ name: 'maxResults', type: 'number', required: false, description: 'An optional parameter to limit the number of results return. Default and maximum is 20.' },
{ name: 'legacyFormat', type: 'boolean', required: false, description: 'Legacy Format' },
{ name: 'forceXml', type: 'boolean', required: false, description: 'Force Xml' },
{ name: 'twentyFourSevenOnly', type: 'boolean', required: false, description: 'Twenty Four Seven Only' }
]
}
};
/** Total number of endpoints */
Cabwise.TOTAL_ENDPOINTS = 1;