mts-booking-library 3.4.0 → 3.6.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.
@@ -8,6 +8,21 @@ import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/Jou
8
8
  import { ReductionTrip } from "../types/journeys/Trip";
9
9
  import { ApiCallOptions } from "../utils/apiCall";
10
10
  import { Booking } from "./booking";
11
+ type JourneyLineRouteFilters = {
12
+ lineId?: number | null;
13
+ routeId?: number | null;
14
+ };
15
+ /**
16
+ * A stop with optional metadata. `region` and `hint` may be null when the
17
+ * backend has no Province / City data for the underlying physical stop.
18
+ * Returned by {@link JourneyBooking.getJourneysDeparturesEnriched} and
19
+ * {@link JourneyBooking.getJourneysDestinationsEnriched}.
20
+ */
21
+ export type EnrichedStop = {
22
+ name: string;
23
+ region?: string | null;
24
+ hint?: string | null;
25
+ };
11
26
  export declare class JourneyBooking extends Booking {
12
27
  private cart?;
13
28
  /**
@@ -116,13 +131,26 @@ export declare class JourneyBooking extends Booking {
116
131
  * This method returns the possible departures for all journeys (MLP) sold by this seller.
117
132
  * @returns The list of possible departures
118
133
  */
119
- getJourneysDepartures(options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
134
+ getJourneysDepartures(filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
135
+ /**
136
+ * Like {@link getJourneysDepartures}, but returns the enriched representation
137
+ * (name + optional region + optional hint) when the backend exposes it.
138
+ * Falls back to a flat {name}-only list when the backend response only
139
+ * carries the legacy `stops` field. Separate from the original method to
140
+ * avoid breaking the existing `string[]` contract used by other clients.
141
+ */
142
+ getJourneysDeparturesEnriched(filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | EnrichedStop[]>;
120
143
  /**
121
144
  * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
122
145
  * @param departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
123
146
  * @returns The list of possible destinations
124
147
  */
125
- getJourneysDestinations(departureStopName: string, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
148
+ getJourneysDestinations(departureStopName: string, filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
149
+ /**
150
+ * Like {@link getJourneysDestinations}, but returns the enriched
151
+ * representation (see {@link getJourneysDeparturesEnriched}).
152
+ */
153
+ getJourneysDestinationsEnriched(departureStopName: string, filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | EnrichedStop[]>;
126
154
  /**
127
155
  * This method returns the journeys that match the given parameters.
128
156
  * Note that it will always return the journeys for the one-way trip.
@@ -228,3 +256,4 @@ export declare class JourneyBooking extends Booking {
228
256
  export declare namespace JourneyBooking {
229
257
  const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, appVersion, os, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<JourneyBooking>;
230
258
  }
259
+ export {};
@@ -79,6 +79,26 @@ var Reduction_1 = require("../types/common/Reduction");
79
79
  var processBookingSteps_1 = require("../utils/processBookingSteps");
80
80
  var utils_1 = require("../utils/utils");
81
81
  var booking_1 = require("./booking");
82
+ var isJourneyLineRouteFilters = function (value) { return !!value && ("lineId" in value || "routeId" in value); };
83
+ var getJourneyLineRouteParams = function (filters) { return (__assign(__assign({}, ((filters === null || filters === void 0 ? void 0 : filters.lineId) && { lineId: filters.lineId.toString() })), ((filters === null || filters === void 0 ? void 0 : filters.routeId) && { routeId: filters.routeId.toString() }))); };
84
+ var isEnrichedStop = function (x) {
85
+ return typeof x === "object" && x !== null && typeof x.name === "string";
86
+ };
87
+ /**
88
+ * Parses the booking-API stop response into the enriched shape. When the
89
+ * backend doesn't populate `stopsEnriched` (older deployment), reconstructs
90
+ * a minimal `{name}` list from the flat `stops` array so callers always
91
+ * receive the same shape.
92
+ */
93
+ var enrichedStopsFromResponse = function (response) {
94
+ var _a;
95
+ var enriched = Array.isArray(response.stopsEnriched)
96
+ ? response.stopsEnriched.filter(isEnrichedStop)
97
+ : [];
98
+ if (enriched.length > 0)
99
+ return enriched;
100
+ return ((_a = response.stops) !== null && _a !== void 0 ? _a : []).map(function (name) { return ({ name: name }); });
101
+ };
82
102
  var JourneyBooking = /** @class */ (function (_super) {
83
103
  __extends(JourneyBooking, _super);
84
104
  /**
@@ -219,34 +239,82 @@ var JourneyBooking = /** @class */ (function (_super) {
219
239
  * This method returns the possible departures for all journeys (MLP) sold by this seller.
220
240
  * @returns The list of possible departures
221
241
  */
222
- JourneyBooking.prototype.getJourneysDepartures = function (options) {
242
+ JourneyBooking.prototype.getJourneysDepartures = function (filtersOrOptions, options) {
223
243
  return __awaiter(this, void 0, void 0, function () {
224
- var url;
244
+ var filters, requestOptions, searchParams, url;
225
245
  return __generator(this, function (_a) {
226
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?");
227
- return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
246
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
247
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
248
+ searchParams = new URLSearchParams(getJourneyLineRouteParams(filters));
249
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?").concat(searchParams);
250
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
228
251
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
229
252
  })];
230
253
  });
231
254
  });
232
255
  };
256
+ /**
257
+ * Like {@link getJourneysDepartures}, but returns the enriched representation
258
+ * (name + optional region + optional hint) when the backend exposes it.
259
+ * Falls back to a flat {name}-only list when the backend response only
260
+ * carries the legacy `stops` field. Separate from the original method to
261
+ * avoid breaking the existing `string[]` contract used by other clients.
262
+ */
263
+ JourneyBooking.prototype.getJourneysDeparturesEnriched = function (filtersOrOptions, options) {
264
+ return __awaiter(this, void 0, void 0, function () {
265
+ var filters, requestOptions, searchParams, url;
266
+ return __generator(this, function (_a) {
267
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
268
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
269
+ searchParams = new URLSearchParams(getJourneyLineRouteParams(filters));
270
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?").concat(searchParams);
271
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
272
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
273
+ return response;
274
+ return enrichedStopsFromResponse(response);
275
+ })];
276
+ });
277
+ });
278
+ };
233
279
  /**
234
280
  * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
235
281
  * @param departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
236
282
  * @returns The list of possible destinations
237
283
  */
238
- JourneyBooking.prototype.getJourneysDestinations = function (departureStopName, options) {
284
+ JourneyBooking.prototype.getJourneysDestinations = function (departureStopName, filtersOrOptions, options) {
239
285
  return __awaiter(this, void 0, void 0, function () {
240
- var searchParams, url;
286
+ var filters, requestOptions, searchParams, url;
241
287
  return __generator(this, function (_a) {
242
- searchParams = new URLSearchParams({ departureStopName: departureStopName });
288
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
289
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
290
+ searchParams = new URLSearchParams(__assign({ departureStopName: departureStopName }, getJourneyLineRouteParams(filters)));
243
291
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
244
- return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
292
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
245
293
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
246
294
  })];
247
295
  });
248
296
  });
249
297
  };
298
+ /**
299
+ * Like {@link getJourneysDestinations}, but returns the enriched
300
+ * representation (see {@link getJourneysDeparturesEnriched}).
301
+ */
302
+ JourneyBooking.prototype.getJourneysDestinationsEnriched = function (departureStopName, filtersOrOptions, options) {
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var filters, requestOptions, searchParams, url;
305
+ return __generator(this, function (_a) {
306
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
307
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
308
+ searchParams = new URLSearchParams(__assign({ departureStopName: departureStopName }, getJourneyLineRouteParams(filters)));
309
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
310
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
311
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
312
+ return response;
313
+ return enrichedStopsFromResponse(response);
314
+ })];
315
+ });
316
+ });
317
+ };
250
318
  /**
251
319
  * This method returns the journeys that match the given parameters.
252
320
  * Note that it will always return the journeys for the one-way trip.
@@ -262,7 +330,7 @@ var JourneyBooking = /** @class */ (function (_super) {
262
330
  if (request.departureStopName === undefined || request.destinationStopName === undefined) {
263
331
  throw Error("Fields departureStopName and destinationStopName are required");
264
332
  }
265
- searchParams = new URLSearchParams(__assign(__assign(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), outboundDate: request.outboundDate.dateTime }, (request.returnDate && { returnDate: request.returnDate.dateTime })), { currency: request.currency, outboundTripId: (_b = (_a = request.outboundTripId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "null" }), (this.cartGuid && { cartGuid: this.cartGuid })));
333
+ searchParams = new URLSearchParams(__assign(__assign(__assign(__assign(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), outboundDate: request.outboundDate.dateTime }, (request.returnDate && { returnDate: request.returnDate.dateTime })), { currency: request.currency, outboundTripId: (_b = (_a = request.outboundTripId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "null" }), (request.lineId && { lineId: request.lineId.toString() })), (request.routeId && { routeId: request.routeId.toString() })), (this.cartGuid && { cartGuid: this.cartGuid })));
266
334
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys_v4?").concat(searchParams);
267
335
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
268
336
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Booking } from "./booking/booking";
2
- export { JourneyBooking } from "./booking/journeyBooking";
2
+ export { JourneyBooking, EnrichedStop } from "./booking/journeyBooking";
3
3
  export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
5
  export { TplBooking } from "./booking/tplBooking";
@@ -12,6 +12,8 @@ export type JourneySearchRequest = {
12
12
  currency: Booking.Currencies;
13
13
  isRoundTrip: boolean;
14
14
  outboundTripId?: number | null;
15
+ lineId?: number | null;
16
+ routeId?: number | null;
15
17
  };
16
18
  export declare const DEFAULT_JOURNEY_SEARCH: JourneySearchRequest;
17
19
  export type JourneySearchResult = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",