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
package/dist/api/info.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { validate, stringifyId } from "../utils/validation";
|
|
2
|
+
import { rawHelplineResponseSchema, rawServiceTypesResponseSchema, rawAboutDataResponseSchema, rawEmergencyMessagesResponseSchema, rawFareScrollMessagesResponseSchema, } from "../schemas/info";
|
|
3
|
+
/**
|
|
4
|
+
* Transform raw transit API response to clean, normalized format
|
|
5
|
+
*/
|
|
6
|
+
function transformHelplineResponse(raw) {
|
|
7
|
+
return {
|
|
8
|
+
items: raw.data.map((item) => ({
|
|
9
|
+
labelName: item.labelname,
|
|
10
|
+
busStopName: item.busstopname,
|
|
11
|
+
helplineNumber: item.helplinenumber,
|
|
12
|
+
})),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Transform raw service types API response to clean, normalized format
|
|
17
|
+
*/
|
|
18
|
+
function transformServiceTypesResponse(raw) {
|
|
19
|
+
return {
|
|
20
|
+
items: raw.data.map((item) => ({
|
|
21
|
+
serviceType: item.servicetype,
|
|
22
|
+
serviceTypeId: stringifyId(item.servicetypeid),
|
|
23
|
+
})),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Transform raw about data API response to clean, normalized format
|
|
28
|
+
*/
|
|
29
|
+
function transformAboutDataResponse(raw) {
|
|
30
|
+
// About data typically has only one item
|
|
31
|
+
const item = raw.data[0];
|
|
32
|
+
return {
|
|
33
|
+
item: {
|
|
34
|
+
termsAndConditionsUrl: item.termsandconditionsurl,
|
|
35
|
+
aboutBmtcUrl: item.aboutbmtcurl,
|
|
36
|
+
aboutDeveloperUrl: item.aboutdeveloperurl,
|
|
37
|
+
airportLatitude: item.airportlattitude,
|
|
38
|
+
airportLongitude: item.airportlongitude,
|
|
39
|
+
airportStationId: stringifyId(item.airportstationid),
|
|
40
|
+
airportStationName: item.airportstationname,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Transform raw emergency messages API response to clean, normalized format
|
|
46
|
+
*/
|
|
47
|
+
function transformEmergencyMessagesResponse(raw) {
|
|
48
|
+
return {
|
|
49
|
+
items: raw.data.map((item) => ({
|
|
50
|
+
id: stringifyId(item.id),
|
|
51
|
+
messageEnglish: item.message_english,
|
|
52
|
+
messageKannada: item.message_kannada,
|
|
53
|
+
isDisplay: item.isdisplay === 1,
|
|
54
|
+
displayKey: item.display_key,
|
|
55
|
+
})),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Transform raw fare scroll messages API response to clean, normalized format
|
|
60
|
+
*/
|
|
61
|
+
function transformFareScrollMessagesResponse(raw) {
|
|
62
|
+
return {
|
|
63
|
+
items: raw.data.map((item) => ({
|
|
64
|
+
id: stringifyId(item.id),
|
|
65
|
+
messageEnglish: item.message_english,
|
|
66
|
+
messageKannada: item.message_kannada,
|
|
67
|
+
isDisplay: item.isdisplay === 1,
|
|
68
|
+
displayKey: item.display_key,
|
|
69
|
+
})),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Info/General API methods
|
|
74
|
+
*/
|
|
75
|
+
export class InfoAPI {
|
|
76
|
+
client;
|
|
77
|
+
constructor(client) {
|
|
78
|
+
this.client = client;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get transit helpline information
|
|
82
|
+
* @returns Helpline information including contact numbers in normalized format
|
|
83
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const helpline = await client.info.getHelpline();
|
|
87
|
+
* helpline.items.forEach(item => {
|
|
88
|
+
* console.log(`${item.title}: ${item.contactNumber}`);
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
async getHelpline() {
|
|
93
|
+
const response = await this.client.getClient().post("GetHelplineData", {
|
|
94
|
+
json: {},
|
|
95
|
+
});
|
|
96
|
+
const data = await response.json();
|
|
97
|
+
// Validate raw response with Zod schema
|
|
98
|
+
const rawResponse = validate(rawHelplineResponseSchema, data, "Invalid helpline response");
|
|
99
|
+
// Transform to clean, normalized format
|
|
100
|
+
return transformHelplineResponse(rawResponse);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get service types (e.g., AC, Non AC/Ordinary)
|
|
104
|
+
* @returns List of available service types in normalized format
|
|
105
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const serviceTypes = await client.info.getServiceTypes();
|
|
109
|
+
* const acService = serviceTypes.items.find(s => s.serviceTypeName.includes("AC"));
|
|
110
|
+
* // Use acService.serviceTypeId in planTrip({ serviceTypeId })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
async getServiceTypes() {
|
|
114
|
+
const response = await this.client.getClient().post("GetAllServiceTypes", {
|
|
115
|
+
json: {},
|
|
116
|
+
});
|
|
117
|
+
const data = await response.json();
|
|
118
|
+
// Validate raw response with Zod schema
|
|
119
|
+
const rawResponse = validate(rawServiceTypesResponseSchema, data, "Invalid service types response");
|
|
120
|
+
// Transform to clean, normalized format
|
|
121
|
+
return transformServiceTypesResponse(rawResponse);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get about information including URLs and airport information
|
|
125
|
+
* @returns About data with terms, URLs, and airport coordinates in normalized format
|
|
126
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const about = await client.info.getAbout();
|
|
130
|
+
* console.log(`Airport coordinates: [${about.airportLatitude}, ${about.airportLongitude}]`);
|
|
131
|
+
* console.log(`Terms URL: ${about.termsUrl}`);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
async getAbout() {
|
|
135
|
+
const response = await this.client.getClient().post("GetAboutData", {
|
|
136
|
+
json: {},
|
|
137
|
+
});
|
|
138
|
+
const data = await response.json();
|
|
139
|
+
// Validate raw response with Zod schema
|
|
140
|
+
const rawResponse = validate(rawAboutDataResponseSchema, data, "Invalid about data response");
|
|
141
|
+
// Transform to clean, normalized format
|
|
142
|
+
return transformAboutDataResponse(rawResponse);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get emergency messages (English and Kannada)
|
|
146
|
+
* @returns List of emergency messages with display settings in normalized format
|
|
147
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const messages = await client.info.getEmergencyMessages();
|
|
151
|
+
* const activeMessages = messages.items.filter(m => m.isDisplay);
|
|
152
|
+
*
|
|
153
|
+
* activeMessages.forEach(msg => {
|
|
154
|
+
* console.log(`${msg.displayKey}: ${msg.messageEn}`);
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
async getEmergencyMessages() {
|
|
159
|
+
const response = await this.client
|
|
160
|
+
.getClient()
|
|
161
|
+
.post("GetEmergencyMessage_v1", {
|
|
162
|
+
json: {},
|
|
163
|
+
});
|
|
164
|
+
const data = await response.json();
|
|
165
|
+
// Validate raw response with Zod schema
|
|
166
|
+
const rawResponse = validate(rawEmergencyMessagesResponseSchema, data, "Invalid emergency messages response");
|
|
167
|
+
// Transform to clean, normalized format
|
|
168
|
+
return transformEmergencyMessagesResponse(rawResponse);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get fare scroll messages (English and Kannada)
|
|
172
|
+
* @returns List of fare scroll messages with display settings in normalized format
|
|
173
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const messages = await client.info.getFareScrollMessages();
|
|
177
|
+
* messages.items.forEach(msg => {
|
|
178
|
+
* if (msg.isDisplay) {
|
|
179
|
+
* console.log(`Fare update: ${msg.messageEn}`);
|
|
180
|
+
* }
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
async getFareScrollMessages() {
|
|
185
|
+
const response = await this.client
|
|
186
|
+
.getClient()
|
|
187
|
+
.post("GetFareScrollMessage", {
|
|
188
|
+
json: {},
|
|
189
|
+
});
|
|
190
|
+
const data = await response.json();
|
|
191
|
+
// Validate raw response with Zod schema
|
|
192
|
+
const rawResponse = validate(rawFareScrollMessagesResponseSchema, data, "Invalid fare scroll messages response");
|
|
193
|
+
// Transform to clean, normalized format
|
|
194
|
+
return transformFareScrollMessagesResponse(rawResponse);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=info.js.map
|
|
@@ -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IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAW,CAAC;QAE5C,wCAAwC;QACxC,MAAM,WAAW,GAAG,QAAQ,CAC3B,kCAAkC,EAClC,IAAI,EACJ,qCAAqC,CACrC,CAAC;QAEF,wCAAwC;QACxC,OAAO,kCAAkC,CAAC,WAAW,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,qBAAqB;QAC1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM;aAChC,SAAS,EAAE;aACX,IAAI,CAAC,sBAAsB,EAAE;YAC7B,IAAI,EAAE,EAAE;SACR,CAAC,CAAC;QAEJ,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAW,CAAC;QAE5C,wCAAwC;QACxC,MAAM,WAAW,GAAG,QAAQ,CAC3B,mCAAmC,EACnC,IAAI,EACJ,uCAAuC,CACvC,CAAC;QAEF,wCAAwC;QACxC,OAAO,mCAAmC,CAAC,WAAW,CAAC,CAAC;IACzD,CAAC;CACD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BaseClient } from "../client/base-client";
|
|
2
|
+
import type { SearchPlacesResponse, SearchPlacesParams } from "../types/locations";
|
|
3
|
+
/**
|
|
4
|
+
* Locations API methods
|
|
5
|
+
*/
|
|
6
|
+
export declare class LocationsAPI {
|
|
7
|
+
private client;
|
|
8
|
+
constructor(client: BaseClient);
|
|
9
|
+
/**
|
|
10
|
+
* Search for places by name
|
|
11
|
+
* @param params - Parameters including search query
|
|
12
|
+
* @param params.query - Place name to search for
|
|
13
|
+
* @returns List of matching places in normalized format
|
|
14
|
+
* @throws {TransitValidationError} If query is invalid or validation fails
|
|
15
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const places = await client.locations.searchPlaces({ query: "Kempegowda Bus Station" });
|
|
19
|
+
* places.items.forEach(place => {
|
|
20
|
+
* console.log(`${place.title} - [${place.latitude}, ${place.longitude}]`);
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
searchPlaces(params: SearchPlacesParams): Promise<SearchPlacesResponse>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=locations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locations.d.ts","sourceRoot":"","sources":["../../src/api/locations.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACX,oBAAoB,EAEpB,kBAAkB,EAElB,MAAM,oBAAoB,CAAC;AAoB5B;;GAEG;AACH,qBAAa,YAAY;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;;;;;;;;;;;;OAcG;IACG,YAAY,CACjB,MAAM,EAAE,kBAAkB,GACxB,OAAO,CAAC,oBAAoB,CAAC;CA4BhC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { validate } from "../utils/validation";
|
|
2
|
+
import { rawSearchPlacesResponseSchema, searchPlacesParamsSchema, } from "../schemas/locations";
|
|
3
|
+
/**
|
|
4
|
+
* Transform raw search places API response to clean, normalized format
|
|
5
|
+
*/
|
|
6
|
+
function transformSearchPlacesResponse(raw) {
|
|
7
|
+
const items = raw.data.map((item) => ({
|
|
8
|
+
title: item.title,
|
|
9
|
+
address: item.placename,
|
|
10
|
+
latitude: item.lat,
|
|
11
|
+
longitude: item.lng,
|
|
12
|
+
}));
|
|
13
|
+
return {
|
|
14
|
+
items,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Locations API methods
|
|
19
|
+
*/
|
|
20
|
+
export class LocationsAPI {
|
|
21
|
+
client;
|
|
22
|
+
constructor(client) {
|
|
23
|
+
this.client = client;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Search for places by name
|
|
27
|
+
* @param params - Parameters including search query
|
|
28
|
+
* @param params.query - Place name to search for
|
|
29
|
+
* @returns List of matching places in normalized format
|
|
30
|
+
* @throws {TransitValidationError} If query is invalid or validation fails
|
|
31
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const places = await client.locations.searchPlaces({ query: "Kempegowda Bus Station" });
|
|
35
|
+
* places.items.forEach(place => {
|
|
36
|
+
* console.log(`${place.title} - [${place.latitude}, ${place.longitude}]`);
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
async searchPlaces(params) {
|
|
41
|
+
// Validate input parameters - API expects "placename", map from "query"
|
|
42
|
+
const validatedParams = validate(searchPlacesParamsSchema, {
|
|
43
|
+
placename: params.query,
|
|
44
|
+
}, "Invalid search places parameters");
|
|
45
|
+
const response = await this.client
|
|
46
|
+
.getClient()
|
|
47
|
+
.post("GetSearchPlaceData", {
|
|
48
|
+
json: validatedParams,
|
|
49
|
+
});
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
// Validate raw response with Zod schema
|
|
52
|
+
const rawResponse = validate(rawSearchPlacesResponseSchema, data, "Invalid search places response");
|
|
53
|
+
// Transform to clean, normalized format
|
|
54
|
+
return transformSearchPlacesResponse(rawResponse);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=locations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locations.js","sourceRoot":"","sources":["../../src/api/locations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EACN,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,sBAAsB,CAAC;AAS9B;;GAEG;AACH,SAAS,6BAA6B,CACrC,GAA4B;IAE5B,MAAM,KAAK,GAAgB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAClD,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,SAAS;QACvB,QAAQ,EAAE,IAAI,CAAC,GAAG;QAClB,SAAS,EAAE,IAAI,CAAC,GAAG;KACnB,CAAC,CAAC,CAAC;IAEJ,OAAO;QACN,KAAK;KACL,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;IACJ;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,YAAY,CACjB,MAA0B;QAE1B,wEAAwE;QACxE,MAAM,eAAe,GAAG,QAAQ,CAC/B,wBAAwB,EACxB;YACC,SAAS,EAAE,MAAM,CAAC,KAAK;SACvB,EACD,kCAAkC,CAClC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM;aAChC,SAAS,EAAE;aACX,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,EAAE,eAAe;SACrB,CAAC,CAAC;QAEJ,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAW,CAAC;QAE5C,wCAAwC;QACxC,MAAM,WAAW,GAAG,QAAQ,CAC3B,6BAA6B,EAC7B,IAAI,EACJ,gCAAgC,CAChC,CAAC;QAEF,wCAAwC;QACxC,OAAO,6BAA6B,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;CACD"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import type { BaseClient } from "../client/base-client";
|
|
2
|
+
import type { RoutePointsResponse, RoutePointsParams, RouteSearchResponse, RouteSearchParams, AllRoutesResponse, TimetableResponse, TimetableByRouteParams, RouteDetailsResponse, RouteDetailsParams, RoutesBetweenStopsResponse, RoutesBetweenStopsParams, FareDataResponse, FareDataParams, TripPlannerResponse, TripPlannerParams, PathDetailsParams, PathDetailsResponse, WaypointsParams, TripPathResponse, TimetableByStationParams, TimetableByStationResponse } from "../types/routes";
|
|
3
|
+
/**
|
|
4
|
+
* Routes API methods
|
|
5
|
+
*/
|
|
6
|
+
export declare class RoutesAPI {
|
|
7
|
+
private client;
|
|
8
|
+
constructor(client: BaseClient);
|
|
9
|
+
/**
|
|
10
|
+
* Get route points (path) for a given route ID
|
|
11
|
+
* @param params - Parameters including route ID
|
|
12
|
+
* @param params.routeId - Route ID (always string for consistency)
|
|
13
|
+
* @returns Route path as GeoJSON LineString FeatureCollection
|
|
14
|
+
* @throws {TransitValidationError} If routeId is invalid or validation fails
|
|
15
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const routePath = await client.routes.getRoutePoints({
|
|
19
|
+
* routeId: "11797"
|
|
20
|
+
* });
|
|
21
|
+
* // Use routePath.routePath.features[0].geometry.coordinates to draw on map
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
getRoutePoints(params: RoutePointsParams): Promise<RoutePointsResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Search for routes by query text (partial match)
|
|
27
|
+
* @param params - Parameters including search query
|
|
28
|
+
* @param params.query - Search query for routes (partial match supported)
|
|
29
|
+
* @returns List of matching routes in normalized format
|
|
30
|
+
* @throws {TransitValidationError} If query is invalid or validation fails
|
|
31
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const routes = await client.routes.searchRoutes({ query: "285-M" });
|
|
35
|
+
* routes.items.forEach(route => {
|
|
36
|
+
* console.log(`${route.routeNo} - ${route.parentRouteId}`);
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
searchRoutes(params: RouteSearchParams): Promise<RouteSearchResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Get all routes list
|
|
43
|
+
* @returns List of all routes in normalized format
|
|
44
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const allRoutes = await client.routes.getAllRoutes();
|
|
48
|
+
* console.log(`Total routes: ${allRoutes.items.length}`);
|
|
49
|
+
*
|
|
50
|
+
* // Find routes by name
|
|
51
|
+
* const matchingRoutes = allRoutes.items.filter(r =>
|
|
52
|
+
* r.routeName.includes("KBS")
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
getAllRoutes(): Promise<AllRoutesResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Get timetable by route ID
|
|
59
|
+
* @param params - Parameters including route ID and optional filters
|
|
60
|
+
* @param params.routeId - Route ID (always string for consistency)
|
|
61
|
+
* @param params.startTime - Optional: Start time for timetable (Date object, defaults to current time)
|
|
62
|
+
* @param params.endTime - Optional: End time for timetable (Date object, defaults to 23:59 of startTime date)
|
|
63
|
+
* @param params.fromStopId - Optional: Filter by from stop ID (requires toStopId)
|
|
64
|
+
* @param params.toStopId - Optional: Filter by to stop ID (requires fromStopId)
|
|
65
|
+
* @returns Timetable data in normalized format
|
|
66
|
+
* @throws {TransitValidationError} If routeId is invalid, validation fails, or stop IDs are provided incorrectly
|
|
67
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Get timetable for entire route
|
|
71
|
+
* const timetable = await client.routes.getTimetableByRoute({
|
|
72
|
+
* routeId: "11797"
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Get timetable between specific stops
|
|
76
|
+
* const timetable = await client.routes.getTimetableByRoute({
|
|
77
|
+
* routeId: "11797",
|
|
78
|
+
* fromStopId: "22357",
|
|
79
|
+
* toStopId: "21447",
|
|
80
|
+
* startTime: new Date("2026-01-20T09:00:00")
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
getTimetableByRoute(params: TimetableByRouteParams): Promise<TimetableResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Search route details by parent route ID
|
|
87
|
+
* @param params - Parameters including parent route ID and optional service type ID
|
|
88
|
+
* @param params.parentRouteId - Parent route ID (always string for consistency, obtained from searchRoutes)
|
|
89
|
+
* @param params.serviceTypeId - Optional: Filter by service type ID
|
|
90
|
+
* @returns Route details with live vehicle information for both directions (up and down)
|
|
91
|
+
* @throws {Error} If parentRouteId is invalid or validation fails
|
|
92
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
93
|
+
* @remarks
|
|
94
|
+
* The parentRouteId should be obtained from searchRoutes().parentRouteId.
|
|
95
|
+
* The response contains subroute IDs in up.stops and down.stops (subrouteId property).
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // First search for route
|
|
99
|
+
* const routes = await client.routes.searchRoutes({ query: "500-CA" });
|
|
100
|
+
* const parentRouteId = routes.items[0].parentRouteId;
|
|
101
|
+
*
|
|
102
|
+
* // Get route details with live vehicles
|
|
103
|
+
* const details = await client.routes.searchByRouteDetails({ parentRouteId });
|
|
104
|
+
*
|
|
105
|
+
* // Access live vehicles for up direction
|
|
106
|
+
* details.up.vehicles.features.forEach(vehicle => {
|
|
107
|
+
* console.log(`Vehicle ${vehicle.properties.vehicleRegNo} at ${vehicle.geometry.coordinates}`);
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
searchByRouteDetails(params: RouteDetailsParams): Promise<RouteDetailsResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Get routes between two stops
|
|
114
|
+
* @param params - Parameters including from and to stop IDs
|
|
115
|
+
* @param params.fromStopId - From stop ID (always string for consistency)
|
|
116
|
+
* @param params.toStopId - To stop ID (always string for consistency)
|
|
117
|
+
* @returns List of routes connecting the two stops in normalized format
|
|
118
|
+
* @throws {TransitValidationError} If stop IDs are invalid or validation fails
|
|
119
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
120
|
+
* @remarks
|
|
121
|
+
* The routeId in the response is likely a subroute ID (specific to direction/variant).
|
|
122
|
+
* It can be used with searchByRouteDetails() endpoint.
|
|
123
|
+
* Note: This differs from parentRouteId returned by searchRoutes().
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const routes = await client.routes.getRoutesBetweenStops({
|
|
127
|
+
* fromStopId: "22357",
|
|
128
|
+
* toStopId: "21447"
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* routes.items.forEach(route => {
|
|
132
|
+
* console.log(`Route ${route.routeNo}: ${route.fromStop} → ${route.toStop}`);
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
getRoutesBetweenStops(params: RoutesBetweenStopsParams): Promise<RoutesBetweenStopsResponse>;
|
|
137
|
+
/**
|
|
138
|
+
* Get fares for a route between stops
|
|
139
|
+
* @param params - Parameters from getRoutesBetweenStops() response
|
|
140
|
+
* @param params.routeId - Subroute ID (always string for consistency, from RouteBetweenStopsItem)
|
|
141
|
+
* @param params.routeDirection - Route direction: "up" or "down"
|
|
142
|
+
* @param params.sourceCode - Source code (from RouteBetweenStopsItem)
|
|
143
|
+
* @param params.destinationCode - Destination code (from RouteBetweenStopsItem)
|
|
144
|
+
* @returns Fares with service types and their fare amounts
|
|
145
|
+
* @throws {Error} If parameters are invalid or validation fails
|
|
146
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
147
|
+
* @remarks
|
|
148
|
+
* The parameters should come from a RouteBetweenStopsItem returned by getRoutesBetweenStops().
|
|
149
|
+
* This endpoint requires the subroute ID (not parent route ID) along with route direction,
|
|
150
|
+
* source and destination codes to determine the exact fare for that route variant.
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // First get routes between stops
|
|
154
|
+
* const routes = await client.routes.getRoutesBetweenStops({
|
|
155
|
+
* fromStopId: "22357",
|
|
156
|
+
* toStopId: "21447"
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* // Get fare for first route
|
|
160
|
+
* const route = routes.items[0];
|
|
161
|
+
* const fare = await client.routes.getFares({
|
|
162
|
+
* routeId: route.subrouteId,
|
|
163
|
+
* routeDirection: route.routeDirection,
|
|
164
|
+
* sourceCode: route.sourceCode,
|
|
165
|
+
* destinationCode: route.destinationCode
|
|
166
|
+
* });
|
|
167
|
+
*
|
|
168
|
+
* fare.items.forEach(item => {
|
|
169
|
+
* console.log(`Service: ${item.serviceType}, Fare: ₹${item.fare}`);
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
getFares(params: FareDataParams): Promise<FareDataResponse>;
|
|
174
|
+
/**
|
|
175
|
+
* Plan a trip with multiple route options
|
|
176
|
+
* @param params - Trip planner parameters with 4 possible combinations:
|
|
177
|
+
* - Stop to Stop: fromStopId, toStopId
|
|
178
|
+
* - Stop to Location: fromStopId, toCoordinates
|
|
179
|
+
* - Location to Stop: fromCoordinates, toStopId
|
|
180
|
+
* - Location to Location: fromCoordinates, toCoordinates
|
|
181
|
+
* @returns Trip plans with all available routes (merged from directRoutes and transferRoutes)
|
|
182
|
+
* @remarks
|
|
183
|
+
* This endpoint supports 4 combinations of origin/destination:
|
|
184
|
+
* - Stop IDs (always string for consistency, will be converted to numbers for API)
|
|
185
|
+
* - Coordinates (latitude/longitude)
|
|
186
|
+
* Optional parameters:
|
|
187
|
+
* - serviceTypeId: Filter by service type (from getAllServiceTypes)
|
|
188
|
+
* - fromDateTime: Future datetime (Date object, converted to "YYYY-MM-DD HH:mm" format)
|
|
189
|
+
* - filterBy: "minimum-transfers" or "shortest-time"
|
|
190
|
+
*
|
|
191
|
+
* All routes are returned in a single `routes` array. Filter by `transferCount === 0` to identify direct routes.
|
|
192
|
+
* @throws {TransitError} If fromDateTime is not in the future
|
|
193
|
+
* @throws {TransitValidationError} If parameters are invalid or validation fails
|
|
194
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // Location to Stop
|
|
198
|
+
* const trip = await client.routes.planTrip({
|
|
199
|
+
* fromCoordinates: [13.09784, 77.59167],
|
|
200
|
+
* toStopId: "20922"
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* // Find fastest direct route
|
|
204
|
+
* const fastest = trip.routes
|
|
205
|
+
* .filter(r => r.transferCount === 0)
|
|
206
|
+
* .sort((a, b) => a.totalDurationSeconds - b.totalDurationSeconds)[0];
|
|
207
|
+
* ```
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // Stop to Stop with filters
|
|
211
|
+
* const trip = await client.routes.planTrip({
|
|
212
|
+
* fromStopId: "22357",
|
|
213
|
+
* toStopId: "21447",
|
|
214
|
+
* filterBy: "shortest-time",
|
|
215
|
+
* fromDateTime: new Date("2026-01-20T09:00:00")
|
|
216
|
+
* });
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
planTrip(params: TripPlannerParams): Promise<TripPlannerResponse>;
|
|
220
|
+
/**
|
|
221
|
+
* Get all stops/stations along trip legs
|
|
222
|
+
* @param params - Path details parameters with array of trip leg segments
|
|
223
|
+
* @param params.trips - Array of trip leg segments, each with tripId, fromStopId, and toStopId
|
|
224
|
+
* @returns All stops along the trip legs with station details, scheduled times, and coordinates as GeoJSON FeatureCollection
|
|
225
|
+
* @remarks
|
|
226
|
+
* This endpoint is typically used after planning a trip to get detailed
|
|
227
|
+
* station-by-station information for each leg of the journey.
|
|
228
|
+
* Each item in the request should have tripId, fromStopId, and toStopId
|
|
229
|
+
* (typically from TripPlannerPathLeg).
|
|
230
|
+
*
|
|
231
|
+
* Note: This returns stops/stations, not a geographic path (for route paths, use getTripPath).
|
|
232
|
+
* @throws {TransitValidationError} If trip parameters are invalid or validation fails
|
|
233
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // After planning a trip, get all stops along the route
|
|
237
|
+
* const trip = await client.routes.planTrip({
|
|
238
|
+
* fromStopId: "22357",
|
|
239
|
+
* toStopId: "21447"
|
|
240
|
+
* });
|
|
241
|
+
*
|
|
242
|
+
* // Extract trip legs (excluding walking segments)
|
|
243
|
+
* const tripLegs = trip.routes[0].legs
|
|
244
|
+
* .filter(leg => !leg.routeNo.startsWith('walk'))
|
|
245
|
+
* .map(leg => ({
|
|
246
|
+
* tripId: leg.tripId,
|
|
247
|
+
* fromStopId: leg.fromStopId,
|
|
248
|
+
* toStopId: leg.toStopId
|
|
249
|
+
* }));
|
|
250
|
+
*
|
|
251
|
+
* // Get all stops as GeoJSON
|
|
252
|
+
* const stops = await client.routes.getTripStops({ trips: tripLegs });
|
|
253
|
+
* // Use stops.features to display on map
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
getTripStops(params: PathDetailsParams): Promise<PathDetailsResponse>;
|
|
257
|
+
/**
|
|
258
|
+
* Get trip path as GeoJSON FeatureCollection with LineString features
|
|
259
|
+
* @param params - Trip path parameters with via points (bus stops)
|
|
260
|
+
* @param params.viaPoints - Array of [latitude, longitude] coordinates or GeoJSON FeatureCollection from getTripStops()
|
|
261
|
+
* @returns GeoJSON FeatureCollection with LineString features representing the route path
|
|
262
|
+
* @remarks
|
|
263
|
+
* This endpoint returns encoded polyline strings representing path segments between origin, via points, and destination.
|
|
264
|
+
* The wrapper decodes these using HERE Flexible Polyline format into GeoJSON LineString features.
|
|
265
|
+
* Each segment becomes a LineString feature with [lng, lat] coordinates.
|
|
266
|
+
*
|
|
267
|
+
* The first point in viaPoints is the origin, the last point is the destination.
|
|
268
|
+
* All intermediate points are treated as via points (bus stops along the route).
|
|
269
|
+
*
|
|
270
|
+
* You can pass GeoJSON FeatureCollection from `getTripStops()` - coordinates will be extracted, properties ignored.
|
|
271
|
+
* @throws {TransitValidationError} If viaPoints are invalid or validation fails
|
|
272
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* // Get stops first
|
|
276
|
+
* const stops = await client.routes.getTripStops({ trips: tripLegs });
|
|
277
|
+
*
|
|
278
|
+
* // Get path using stops (coordinates extracted automatically)
|
|
279
|
+
* const path = await client.routes.getTripPath({ viaPoints: stops });
|
|
280
|
+
* // Use path.features to draw route lines on map
|
|
281
|
+
* ```
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* // Or use coordinates directly
|
|
285
|
+
* const path = await client.routes.getTripPath({
|
|
286
|
+
* viaPoints: [
|
|
287
|
+
* [13.09784, 77.59167], // Origin
|
|
288
|
+
* [13.09884, 77.59267], // Via point
|
|
289
|
+
* [13.09984, 77.59367] // Destination
|
|
290
|
+
* ]
|
|
291
|
+
* });
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
getTripPath(params: WaypointsParams): Promise<TripPathResponse>;
|
|
295
|
+
/**
|
|
296
|
+
* Get routes that pass through both stations (in sequence)
|
|
297
|
+
* @param params - Parameters including from station ID, to station ID, and optional filters
|
|
298
|
+
* @param params.fromStopId - From stop ID (always string for consistency)
|
|
299
|
+
* @param params.toStopId - To stop ID (always string for consistency)
|
|
300
|
+
* @param params.routeId - Optional: Filter by specific route ID
|
|
301
|
+
* @param params.date - Optional: Date for timetable (Date object, defaults to current date)
|
|
302
|
+
* @returns Routes that go through both stations with schedule information
|
|
303
|
+
* @remarks
|
|
304
|
+
* This is NOT a full timetable - each route has one startTime, not multiple scheduled trips.
|
|
305
|
+
* Routes may start before fromStop and/or continue after toStop.
|
|
306
|
+
* @throws {TransitValidationError} If stop IDs are invalid or validation fails
|
|
307
|
+
* @throws {HTTPError} If the API request fails (network error, 4xx, 5xx)
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* // Find routes passing through both stops
|
|
311
|
+
* const routes = await client.routes.getRoutesThroughStations({
|
|
312
|
+
* fromStopId: "30475",
|
|
313
|
+
* toStopId: "35376"
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* routes.items.forEach(route => {
|
|
317
|
+
* console.log(`Route ${route.routeNo} starts at ${route.startTime}`);
|
|
318
|
+
* console.log(`Travel time: ${route.travelTime}, Distance: ${route.distance} km`);
|
|
319
|
+
* });
|
|
320
|
+
* ```
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* // Filter by specific route
|
|
324
|
+
* const routes = await client.routes.getRoutesThroughStations({
|
|
325
|
+
* fromStopId: "30475",
|
|
326
|
+
* toStopId: "35376",
|
|
327
|
+
* routeId: "2292",
|
|
328
|
+
* date: new Date("2026-01-20")
|
|
329
|
+
* });
|
|
330
|
+
* ```
|
|
331
|
+
* @remarks
|
|
332
|
+
* This endpoint returns all routes that pass through both the fromStation and toStation in sequence.
|
|
333
|
+
* The routes may start before fromStation and/or continue after toStation - they just need to pass through both.
|
|
334
|
+
* Returns one startTime per route (not a full timetable with multiple trips).
|
|
335
|
+
* For a full timetable with multiple trips, use getTimetableByRoute() instead.
|
|
336
|
+
* The date, start time, and end time parameters are required by the API but don't affect the output.
|
|
337
|
+
* Use routeId to filter results to a specific route.
|
|
338
|
+
*/
|
|
339
|
+
getRoutesThroughStations(params: TimetableByStationParams): Promise<TimetableByStationResponse>;
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/api/routes.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACX,mBAAmB,EAEnB,iBAAiB,EACjB,mBAAmB,EAEnB,iBAAiB,EAEjB,iBAAiB,EAGjB,iBAAiB,EAEjB,sBAAsB,EAEtB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