bengaluru-transit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +507 -0
- package/dist/api/info.d.ts +77 -0
- package/dist/api/info.d.ts.map +1 -0
- package/dist/api/info.js +197 -0
- package/dist/api/info.js.map +1 -0
- package/dist/api/locations.d.ts +26 -0
- package/dist/api/locations.d.ts.map +1 -0
- package/dist/api/locations.js +57 -0
- package/dist/api/locations.js.map +1 -0
- package/dist/api/routes.d.ts +341 -0
- package/dist/api/routes.d.ts.map +1 -0
- package/dist/api/routes.js +1133 -0
- package/dist/api/routes.js.map +1 -0
- package/dist/api/stops.d.ts +92 -0
- package/dist/api/stops.d.ts.map +1 -0
- package/dist/api/stops.js +237 -0
- package/dist/api/stops.js.map +1 -0
- package/dist/api/vehicles.d.ts +49 -0
- package/dist/api/vehicles.d.ts.map +1 -0
- package/dist/api/vehicles.js +154 -0
- package/dist/api/vehicles.js.map +1 -0
- package/dist/client/base-client.d.ts +52 -0
- package/dist/client/base-client.d.ts.map +1 -0
- package/dist/client/base-client.js +76 -0
- package/dist/client/base-client.js.map +1 -0
- package/dist/client/transit-client.d.ts +91 -0
- package/dist/client/transit-client.d.ts.map +1 -0
- package/dist/client/transit-client.js +98 -0
- package/dist/client/transit-client.js.map +1 -0
- package/dist/constants/api.d.ts +16 -0
- package/dist/constants/api.d.ts.map +1 -0
- package/dist/constants/api.js +16 -0
- package/dist/constants/api.js.map +1 -0
- package/dist/constants/routes.d.ts +16 -0
- package/dist/constants/routes.d.ts.map +1 -0
- package/dist/constants/routes.js +16 -0
- package/dist/constants/routes.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/common.d.ts +34 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/common.js +20 -0
- package/dist/schemas/common.js.map +1 -0
- package/dist/schemas/index.d.ts +7 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +7 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/info.d.ts +390 -0
- package/dist/schemas/info.d.ts.map +1 -0
- package/dist/schemas/info.js +110 -0
- package/dist/schemas/info.js.map +1 -0
- package/dist/schemas/locations.d.ts +84 -0
- package/dist/schemas/locations.d.ts.map +1 -0
- package/dist/schemas/locations.js +31 -0
- package/dist/schemas/locations.js.map +1 -0
- package/dist/schemas/routes.d.ts +3967 -0
- package/dist/schemas/routes.d.ts.map +1 -0
- package/dist/schemas/routes.js +532 -0
- package/dist/schemas/routes.js.map +1 -0
- package/dist/schemas/stops.d.ts +543 -0
- package/dist/schemas/stops.d.ts.map +1 -0
- package/dist/schemas/stops.js +129 -0
- package/dist/schemas/stops.js.map +1 -0
- package/dist/schemas/vehicles.d.ts +602 -0
- package/dist/schemas/vehicles.d.ts.map +1 -0
- package/dist/schemas/vehicles.js +116 -0
- package/dist/schemas/vehicles.js.map +1 -0
- package/dist/types/api.d.ts +9 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +5 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/coordinates.d.ts +7 -0
- package/dist/types/coordinates.d.ts.map +1 -0
- package/dist/types/coordinates.js +2 -0
- package/dist/types/coordinates.js.map +1 -0
- package/dist/types/geojson.d.ts +84 -0
- package/dist/types/geojson.d.ts.map +1 -0
- package/dist/types/geojson.js +2 -0
- package/dist/types/geojson.js.map +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/info.d.ts +133 -0
- package/dist/types/info.d.ts.map +1 -0
- package/dist/types/info.js +5 -0
- package/dist/types/info.js.map +1 -0
- package/dist/types/locations.d.ts +59 -0
- package/dist/types/locations.d.ts.map +1 -0
- package/dist/types/locations.js +5 -0
- package/dist/types/locations.js.map +1 -0
- package/dist/types/routes.d.ts +1137 -0
- package/dist/types/routes.d.ts.map +1 -0
- package/dist/types/routes.js +14 -0
- package/dist/types/routes.js.map +1 -0
- package/dist/types/stops.d.ts +286 -0
- package/dist/types/stops.d.ts.map +1 -0
- package/dist/types/stops.js +26 -0
- package/dist/types/stops.js.map +1 -0
- package/dist/types/vehicles.d.ts +138 -0
- package/dist/types/vehicles.d.ts.map +1 -0
- package/dist/types/vehicles.js +5 -0
- package/dist/types/vehicles.js.map +1 -0
- package/dist/utils/date.d.ts +35 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +49 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/errors.d.ts +34 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +41 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/geojson.d.ts +36 -0
- package/dist/utils/geojson.d.ts.map +1 -0
- package/dist/utils/geojson.js +115 -0
- package/dist/utils/geojson.js.map +1 -0
- package/dist/utils/validation.d.ts +40 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +62 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type KyInstance } from "ky";
|
|
2
|
+
/**
|
|
3
|
+
* Base HTTP client configuration for transit API
|
|
4
|
+
*/
|
|
5
|
+
export interface BaseClientConfig {
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
retry?: number;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Language preference: 'en' for English, 'kn' for Kannada
|
|
12
|
+
* @default 'en'
|
|
13
|
+
*/
|
|
14
|
+
language?: "en" | "kn";
|
|
15
|
+
/**
|
|
16
|
+
* Device type identifier
|
|
17
|
+
* @default 'WEB'
|
|
18
|
+
*/
|
|
19
|
+
deviceType?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Authentication token
|
|
22
|
+
* @default 'N/A'
|
|
23
|
+
*/
|
|
24
|
+
authToken?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Device identifier
|
|
27
|
+
* @default ''
|
|
28
|
+
*/
|
|
29
|
+
deviceId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Base HTTP client class using ky
|
|
33
|
+
*/
|
|
34
|
+
export declare class BaseClient {
|
|
35
|
+
protected client: KyInstance;
|
|
36
|
+
protected baseURL: string;
|
|
37
|
+
protected language: "en" | "kn";
|
|
38
|
+
constructor(config?: BaseClientConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Get the underlying ky client instance
|
|
41
|
+
*/
|
|
42
|
+
getClient(): KyInstance;
|
|
43
|
+
/**
|
|
44
|
+
* Get the base URL
|
|
45
|
+
*/
|
|
46
|
+
getBaseURL(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Get the language preference
|
|
49
|
+
*/
|
|
50
|
+
getLanguage(): "en" | "kn";
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=base-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-client.d.ts","sourceRoot":"","sources":["../../src/client/base-client.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAOzC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,UAAU;IACtB,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;IAC7B,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;gBAEpB,MAAM,GAAE,gBAAqB;IAqDzC;;OAEG;IACH,SAAS,IAAI,UAAU;IAIvB;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,WAAW,IAAI,IAAI,GAAG,IAAI;CAG1B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import ky from "ky";
|
|
2
|
+
import { DEFAULT_BASE_URL, DEFAULT_DEVICE_TYPE, DEFAULT_AUTH_TOKEN, } from "../constants/api";
|
|
3
|
+
/**
|
|
4
|
+
* Base HTTP client class using ky
|
|
5
|
+
*/
|
|
6
|
+
export class BaseClient {
|
|
7
|
+
client;
|
|
8
|
+
baseURL;
|
|
9
|
+
language;
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
this.baseURL = config.baseURL || DEFAULT_BASE_URL;
|
|
12
|
+
this.language = config.language || "en";
|
|
13
|
+
// Default transit API headers
|
|
14
|
+
const defaultHeaders = {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
Accept: "application/json, text/plain, */*",
|
|
17
|
+
lan: this.language,
|
|
18
|
+
deviceType: config.deviceType || DEFAULT_DEVICE_TYPE,
|
|
19
|
+
authToken: config.authToken || DEFAULT_AUTH_TOKEN,
|
|
20
|
+
deviceId: config.deviceId || "",
|
|
21
|
+
};
|
|
22
|
+
this.client = ky.create({
|
|
23
|
+
prefixUrl: this.baseURL,
|
|
24
|
+
timeout: config.timeout,
|
|
25
|
+
retry: config.retry || {
|
|
26
|
+
limit: 2,
|
|
27
|
+
methods: ["get"],
|
|
28
|
+
statusCodes: [408, 413, 429, 500, 502, 503, 504],
|
|
29
|
+
},
|
|
30
|
+
headers: {
|
|
31
|
+
...defaultHeaders,
|
|
32
|
+
...config.headers, // Allow overriding any header
|
|
33
|
+
},
|
|
34
|
+
hooks: {
|
|
35
|
+
beforeError: [
|
|
36
|
+
async (error) => {
|
|
37
|
+
// Enhance error message with API-specific details
|
|
38
|
+
let errorMessage = error.message || "Request failed";
|
|
39
|
+
// Try to parse error response body
|
|
40
|
+
try {
|
|
41
|
+
const errorBody = (await error.response?.json());
|
|
42
|
+
if (errorBody?.message) {
|
|
43
|
+
errorMessage = errorBody.message;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Ignore JSON parse errors
|
|
48
|
+
}
|
|
49
|
+
// Update the error message and return the original HTTPError
|
|
50
|
+
error.message = errorMessage;
|
|
51
|
+
return error;
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the underlying ky client instance
|
|
59
|
+
*/
|
|
60
|
+
getClient() {
|
|
61
|
+
return this.client;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the base URL
|
|
65
|
+
*/
|
|
66
|
+
getBaseURL() {
|
|
67
|
+
return this.baseURL;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the language preference
|
|
71
|
+
*/
|
|
72
|
+
getLanguage() {
|
|
73
|
+
return this.language;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=base-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-client.js","sourceRoot":"","sources":["../../src/client/base-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,IAAI,CAAC;AACzC,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAgC1B;;GAEG;AACH,MAAM,OAAO,UAAU;IACZ,MAAM,CAAa;IACnB,OAAO,CAAS;IAChB,QAAQ,CAAc;IAEhC,YAAY,SAA2B,EAAE;QACxC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC;QAExC,8BAA8B;QAC9B,MAAM,cAAc,GAA2B;YAC9C,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,mCAAmC;YAC3C,GAAG,EAAE,IAAI,CAAC,QAAQ;YAClB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,mBAAmB;YACpD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,kBAAkB;YACjD,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE;SAC/B,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;YACvB,SAAS,EAAE,IAAI,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI;gBACtB,KAAK,EAAE,CAAC;gBACR,OAAO,EAAE,CAAC,KAAK,CAAC;gBAChB,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;aAChD;YACD,OAAO,EAAE;gBACR,GAAG,cAAc;gBACjB,GAAG,MAAM,CAAC,OAAO,EAAE,8BAA8B;aACjD;YACD,KAAK,EAAE;gBACN,WAAW,EAAE;oBACZ,KAAK,EAAE,KAAK,EAAE,EAAE;wBACf,kDAAkD;wBAClD,IAAI,YAAY,GAAG,KAAK,CAAC,OAAO,IAAI,gBAAgB,CAAC;wBAErD,mCAAmC;wBACnC,IAAI,CAAC;4BACJ,MAAM,SAAS,GAAG,CAAC,MAAM,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAEnC,CAAC;4BACb,IAAI,SAAS,EAAE,OAAO,EAAE,CAAC;gCACxB,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC;4BAClC,CAAC;wBACF,CAAC;wBAAC,MAAM,CAAC;4BACR,2BAA2B;wBAC5B,CAAC;wBAED,6DAA6D;wBAC7D,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC;wBAC7B,OAAO,KAAK,CAAC;oBACd,CAAC;iBACD;aACD;SACD,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,UAAU;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,WAAW;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;CACD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BaseClient, type BaseClientConfig } from "./base-client";
|
|
2
|
+
import { InfoAPI } from "../api/info";
|
|
3
|
+
import { VehiclesAPI } from "../api/vehicles";
|
|
4
|
+
import { RoutesAPI } from "../api/routes";
|
|
5
|
+
import { StopsAPI } from "../api/stops";
|
|
6
|
+
import { LocationsAPI } from "../api/locations";
|
|
7
|
+
/**
|
|
8
|
+
* Main Bengaluru Transit API client
|
|
9
|
+
*
|
|
10
|
+
* Provides a type-safe, validated interface to Bengaluru public transit APIs.
|
|
11
|
+
* All responses are normalized and validated using Zod schemas.
|
|
12
|
+
*
|
|
13
|
+
* **Note**: This is an unofficial SDK. It is not affiliated with, endorsed by, or connected to any official transit authority.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Basic usage
|
|
18
|
+
* const client = new BengaluruTransitClient({ language: "en" });
|
|
19
|
+
*
|
|
20
|
+
* // Plan a trip
|
|
21
|
+
* const trip = await client.routes.planTrip({
|
|
22
|
+
* fromCoordinates: [13.09784, 77.59167],
|
|
23
|
+
* toStopId: "20922"
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Find nearby stops
|
|
27
|
+
* const stops = await client.stops.findNearbyStops({
|
|
28
|
+
* coordinates: [13.09784, 77.59167],
|
|
29
|
+
* radius: 1
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // With custom configuration
|
|
36
|
+
* const client = new BengaluruTransitClient({
|
|
37
|
+
* language: "kn", // Kannada
|
|
38
|
+
* timeout: 10000, // 10 second timeout
|
|
39
|
+
* baseURL: "https://custom-api.example.com" // Custom base URL
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class BengaluruTransitClient extends BaseClient {
|
|
44
|
+
/**
|
|
45
|
+
* Info API - General transit information, helpline, service types, emergency messages
|
|
46
|
+
*/
|
|
47
|
+
readonly info: InfoAPI;
|
|
48
|
+
/**
|
|
49
|
+
* Vehicles API - Search vehicles and track live bus locations
|
|
50
|
+
*/
|
|
51
|
+
readonly vehicles: VehiclesAPI;
|
|
52
|
+
/**
|
|
53
|
+
* Routes API - Trip planning, route search, timetables, fares, route details
|
|
54
|
+
*/
|
|
55
|
+
readonly routes: RoutesAPI;
|
|
56
|
+
/**
|
|
57
|
+
* Stops API - Find nearby stops/stations, search stops, get facilities
|
|
58
|
+
*/
|
|
59
|
+
readonly stops: StopsAPI;
|
|
60
|
+
/**
|
|
61
|
+
* Locations API - Search for places/locations by name
|
|
62
|
+
*/
|
|
63
|
+
readonly locations: LocationsAPI;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new Bengaluru Transit API client
|
|
66
|
+
*
|
|
67
|
+
* @param config - Client configuration options
|
|
68
|
+
* @param config.language - Language preference: 'en' for English, 'kn' for Kannada (default: 'en')
|
|
69
|
+
* @param config.baseURL - Base URL for transit API (default: official API URL)
|
|
70
|
+
* @param config.timeout - Request timeout in milliseconds
|
|
71
|
+
* @param config.retry - Retry configuration for failed requests
|
|
72
|
+
* @param config.headers - Additional headers to include in requests
|
|
73
|
+
* @param config.deviceType - Device type identifier (default: 'WEB')
|
|
74
|
+
* @param config.authToken - Authentication token (default: 'N/A')
|
|
75
|
+
* @param config.deviceId - Device identifier
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Default configuration
|
|
80
|
+
* const client = new BengaluruTransitClient();
|
|
81
|
+
*
|
|
82
|
+
* // With language preference
|
|
83
|
+
* const client = new BengaluruTransitClient({ language: "kn" });
|
|
84
|
+
*
|
|
85
|
+
* // With custom timeout
|
|
86
|
+
* const client = new BengaluruTransitClient({ timeout: 15000 });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
constructor(config?: BaseClientConfig);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=transit-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transit-client.d.ts","sourceRoot":"","sources":["../../src/client/transit-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IACrD;;OAEG;IACH,SAAgB,IAAI,EAAE,OAAO,CAAC;IAE9B;;OAEG;IACH,SAAgB,QAAQ,EAAE,WAAW,CAAC;IAEtC;;OAEG;IACH,SAAgB,MAAM,EAAE,SAAS,CAAC;IAElC;;OAEG;IACH,SAAgB,KAAK,EAAE,QAAQ,CAAC;IAEhC;;OAEG;IACH,SAAgB,SAAS,EAAE,YAAY,CAAC;IAExC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;gBACS,MAAM,GAAE,gBAAqB;CAQzC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { BaseClient } from "./base-client";
|
|
2
|
+
import { InfoAPI } from "../api/info";
|
|
3
|
+
import { VehiclesAPI } from "../api/vehicles";
|
|
4
|
+
import { RoutesAPI } from "../api/routes";
|
|
5
|
+
import { StopsAPI } from "../api/stops";
|
|
6
|
+
import { LocationsAPI } from "../api/locations";
|
|
7
|
+
/**
|
|
8
|
+
* Main Bengaluru Transit API client
|
|
9
|
+
*
|
|
10
|
+
* Provides a type-safe, validated interface to Bengaluru public transit APIs.
|
|
11
|
+
* All responses are normalized and validated using Zod schemas.
|
|
12
|
+
*
|
|
13
|
+
* **Note**: This is an unofficial SDK. It is not affiliated with, endorsed by, or connected to any official transit authority.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Basic usage
|
|
18
|
+
* const client = new BengaluruTransitClient({ language: "en" });
|
|
19
|
+
*
|
|
20
|
+
* // Plan a trip
|
|
21
|
+
* const trip = await client.routes.planTrip({
|
|
22
|
+
* fromCoordinates: [13.09784, 77.59167],
|
|
23
|
+
* toStopId: "20922"
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Find nearby stops
|
|
27
|
+
* const stops = await client.stops.findNearbyStops({
|
|
28
|
+
* coordinates: [13.09784, 77.59167],
|
|
29
|
+
* radius: 1
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // With custom configuration
|
|
36
|
+
* const client = new BengaluruTransitClient({
|
|
37
|
+
* language: "kn", // Kannada
|
|
38
|
+
* timeout: 10000, // 10 second timeout
|
|
39
|
+
* baseURL: "https://custom-api.example.com" // Custom base URL
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export class BengaluruTransitClient extends BaseClient {
|
|
44
|
+
/**
|
|
45
|
+
* Info API - General transit information, helpline, service types, emergency messages
|
|
46
|
+
*/
|
|
47
|
+
info;
|
|
48
|
+
/**
|
|
49
|
+
* Vehicles API - Search vehicles and track live bus locations
|
|
50
|
+
*/
|
|
51
|
+
vehicles;
|
|
52
|
+
/**
|
|
53
|
+
* Routes API - Trip planning, route search, timetables, fares, route details
|
|
54
|
+
*/
|
|
55
|
+
routes;
|
|
56
|
+
/**
|
|
57
|
+
* Stops API - Find nearby stops/stations, search stops, get facilities
|
|
58
|
+
*/
|
|
59
|
+
stops;
|
|
60
|
+
/**
|
|
61
|
+
* Locations API - Search for places/locations by name
|
|
62
|
+
*/
|
|
63
|
+
locations;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new Bengaluru Transit API client
|
|
66
|
+
*
|
|
67
|
+
* @param config - Client configuration options
|
|
68
|
+
* @param config.language - Language preference: 'en' for English, 'kn' for Kannada (default: 'en')
|
|
69
|
+
* @param config.baseURL - Base URL for transit API (default: official API URL)
|
|
70
|
+
* @param config.timeout - Request timeout in milliseconds
|
|
71
|
+
* @param config.retry - Retry configuration for failed requests
|
|
72
|
+
* @param config.headers - Additional headers to include in requests
|
|
73
|
+
* @param config.deviceType - Device type identifier (default: 'WEB')
|
|
74
|
+
* @param config.authToken - Authentication token (default: 'N/A')
|
|
75
|
+
* @param config.deviceId - Device identifier
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Default configuration
|
|
80
|
+
* const client = new BengaluruTransitClient();
|
|
81
|
+
*
|
|
82
|
+
* // With language preference
|
|
83
|
+
* const client = new BengaluruTransitClient({ language: "kn" });
|
|
84
|
+
*
|
|
85
|
+
* // With custom timeout
|
|
86
|
+
* const client = new BengaluruTransitClient({ timeout: 15000 });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
constructor(config = {}) {
|
|
90
|
+
super(config);
|
|
91
|
+
this.info = new InfoAPI(this);
|
|
92
|
+
this.vehicles = new VehiclesAPI(this);
|
|
93
|
+
this.routes = new RoutesAPI(this);
|
|
94
|
+
this.stops = new StopsAPI(this);
|
|
95
|
+
this.locations = new LocationsAPI(this);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=transit-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transit-client.js","sourceRoot":"","sources":["../../src/client/transit-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyB,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IACrD;;OAEG;IACa,IAAI,CAAU;IAE9B;;OAEG;IACa,QAAQ,CAAc;IAEtC;;OAEG;IACa,MAAM,CAAY;IAElC;;OAEG;IACa,KAAK,CAAW;IAEhC;;OAEG;IACa,SAAS,CAAe;IAExC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,YAAY,SAA2B,EAAE;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for transit API defaults and configuration
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default device type for API requests
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_DEVICE_TYPE = "WEB";
|
|
8
|
+
/**
|
|
9
|
+
* Default authentication token (when not provided)
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_AUTH_TOKEN = "N/A";
|
|
12
|
+
/**
|
|
13
|
+
* Default base URL for transit API
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_BASE_URL = "https://bmtcmobileapi.karnataka.gov.in/WebAPI";
|
|
16
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/constants/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,gBAAgB,kDACmB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for transit API defaults and configuration
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default device type for API requests
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_DEVICE_TYPE = "WEB";
|
|
8
|
+
/**
|
|
9
|
+
* Default authentication token (when not provided)
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_AUTH_TOKEN = "N/A";
|
|
12
|
+
/**
|
|
13
|
+
* Default base URL for transit API
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_BASE_URL = "https://bmtcmobileapi.karnataka.gov.in/WebAPI";
|
|
16
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/constants/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC5B,+CAA+C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for route-related API values
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Route number prefix indicating a walking segment
|
|
6
|
+
*/
|
|
7
|
+
export declare const WALK_ROUTE_PREFIX = "walk_source";
|
|
8
|
+
/**
|
|
9
|
+
* Route number prefix for walking segments (any route starting with "walk")
|
|
10
|
+
*/
|
|
11
|
+
export declare const WALK_PREFIX = "walk";
|
|
12
|
+
/**
|
|
13
|
+
* Invalid/empty subroute ID value from API
|
|
14
|
+
*/
|
|
15
|
+
export declare const EMPTY_SUBROUTE_ID = "0";
|
|
16
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/constants/routes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,WAAW,SAAS,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for route-related API values
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Route number prefix indicating a walking segment
|
|
6
|
+
*/
|
|
7
|
+
export const WALK_ROUTE_PREFIX = "walk_source";
|
|
8
|
+
/**
|
|
9
|
+
* Route number prefix for walking segments (any route starting with "walk")
|
|
10
|
+
*/
|
|
11
|
+
export const WALK_PREFIX = "walk";
|
|
12
|
+
/**
|
|
13
|
+
* Invalid/empty subroute ID value from API
|
|
14
|
+
*/
|
|
15
|
+
export const EMPTY_SUBROUTE_ID = "0";
|
|
16
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/constants/routes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bengaluru Transit TypeScript SDK
|
|
3
|
+
* Main entry point for the package
|
|
4
|
+
*/
|
|
5
|
+
export { BengaluruTransitClient } from './client/transit-client';
|
|
6
|
+
export type { BaseClientConfig } from './client/base-client';
|
|
7
|
+
export type * from './types';
|
|
8
|
+
export { createStopFeature, createRouteFeature, createLocationFeature, createFeatureCollection, validateCoordinates, normalizeCoordinates, } from './utils/geojson';
|
|
9
|
+
export { validate, safeValidate } from './utils/validation';
|
|
10
|
+
export { TransitError, TransitValidationError } from './utils/errors';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,mBAAmB,SAAS,CAAC;AAG7B,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bengaluru Transit TypeScript SDK
|
|
3
|
+
* Main entry point for the package
|
|
4
|
+
*/
|
|
5
|
+
export { BengaluruTransitClient } from './client/transit-client';
|
|
6
|
+
// Export utilities (if needed for advanced usage)
|
|
7
|
+
export { createStopFeature, createRouteFeature, createLocationFeature, createFeatureCollection, validateCoordinates, normalizeCoordinates, } from './utils/geojson';
|
|
8
|
+
export { validate, safeValidate } from './utils/validation';
|
|
9
|
+
export { TransitError, TransitValidationError } from './utils/errors';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAMjE,kDAAkD;AAClD,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Common Zod schemas for validation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Schema for sort parameters
|
|
7
|
+
*/
|
|
8
|
+
export declare const sortSchema: z.ZodObject<{
|
|
9
|
+
sortBy: z.ZodOptional<z.ZodString>;
|
|
10
|
+
sortOrder: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
sortBy?: string | undefined;
|
|
13
|
+
sortOrder?: "asc" | "desc" | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
sortBy?: string | undefined;
|
|
16
|
+
sortOrder?: "asc" | "desc" | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Schema for API error response
|
|
20
|
+
*/
|
|
21
|
+
export declare const apiErrorSchema: z.ZodObject<{
|
|
22
|
+
message: z.ZodString;
|
|
23
|
+
code: z.ZodOptional<z.ZodString>;
|
|
24
|
+
statusCode: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
message: string;
|
|
27
|
+
code?: string | undefined;
|
|
28
|
+
statusCode?: number | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
message: string;
|
|
31
|
+
code?: string | undefined;
|
|
32
|
+
statusCode?: number | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/schemas/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;EAGrB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;EAIzB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Common Zod schemas for validation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Schema for sort parameters
|
|
7
|
+
*/
|
|
8
|
+
export const sortSchema = z.object({
|
|
9
|
+
sortBy: z.string().optional(),
|
|
10
|
+
sortOrder: z.enum(['asc', 'desc']).optional(),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Schema for API error response
|
|
14
|
+
*/
|
|
15
|
+
export const apiErrorSchema = z.object({
|
|
16
|
+
message: z.string(),
|
|
17
|
+
code: z.string().optional(),
|
|
18
|
+
statusCode: z.number().optional(),
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/schemas/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|