mts-booking-library 3.3.0 → 3.5.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.
@@ -2,12 +2,16 @@ import { ErrorResponse } from "../types/ErrorResponse";
2
2
  import { CreateUpdateCartRequest } from "../types/common/Cart";
3
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
4
4
  import { AddReductionRequest } from "../types/common/Reduction";
5
- import { BusMatrix } from "../types/journeys/BusMatrix";
5
+ import { BusMatrix, SeatChange } from "../types/journeys/BusMatrix";
6
6
  import { JourneyCart } from "../types/journeys/JourneyCart";
7
7
  import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
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
+ };
11
15
  export declare class JourneyBooking extends Booking {
12
16
  private cart?;
13
17
  /**
@@ -116,13 +120,13 @@ export declare class JourneyBooking extends Booking {
116
120
  * This method returns the possible departures for all journeys (MLP) sold by this seller.
117
121
  * @returns The list of possible departures
118
122
  */
119
- getJourneysDepartures(options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
123
+ getJourneysDepartures(filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
120
124
  /**
121
125
  * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
122
126
  * @param departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
123
127
  * @returns The list of possible destinations
124
128
  */
125
- getJourneysDestinations(departureStopName: string, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
129
+ getJourneysDestinations(departureStopName: string, filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
126
130
  /**
127
131
  * This method returns the journeys that match the given parameters.
128
132
  * Note that it will always return the journeys for the one-way trip.
@@ -165,11 +169,24 @@ export declare class JourneyBooking extends Booking {
165
169
  getAssignedSeats(tripId: number, options?: ApiCallOptions): Promise<ErrorResponse | number[]>;
166
170
  /**
167
171
  * @description This method shall be called when the user wants to change the assigned seats of a trip.
172
+ *
173
+ * Two shapes are supported. Callers should prefer `seatChanges` when
174
+ * the cart has more than one passenger on the trip — the BE pairs by
175
+ * {@link SeatChange.oldSeatId}, which uniquely identifies the cart's
176
+ * underlying TripBusLayoutCell. The legacy `newSeatsIds` form is a
177
+ * full positional snapshot of every passenger's new seat; the BE
178
+ * zips it against EF-ordered TripBusLayoutCells, which can reassign
179
+ * the wrong passenger when the two orderings disagree.
180
+ *
181
+ * Send only one of the two arguments per call. If both are present
182
+ * the BE prefers `seatChanges`.
168
183
  * @param tripId The id of the trip for which the seats should be changed
169
- * @param newSeatsIds The ids of the new seats, as found the {@link BusMatrix}
184
+ * @param seatsOrChanges Either the legacy `newSeatsIds` array (every
185
+ * passenger's new seat, in order) or an explicit list of
186
+ * {@link SeatChange} pairs (only the seats that change).
170
187
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
171
188
  */
172
- changeSeatsOfTrip(tripId: number, newSeatsIds: number[], options?: ApiCallOptions): Promise<ErrorResponse | boolean>;
189
+ changeSeatsOfTrip(tripId: number, seatsOrChanges: number[] | SeatChange[], options?: ApiCallOptions): Promise<ErrorResponse | boolean>;
173
190
  /**
174
191
  * @description This method shall be called when the user wants to retrieve the trips in the cart, for adding a available reduction
175
192
  * to a specific trip (rather than to the whole cart).
@@ -215,3 +232,4 @@ export declare class JourneyBooking extends Booking {
215
232
  export declare namespace JourneyBooking {
216
233
  const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, appVersion, os, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<JourneyBooking>;
217
234
  }
235
+ export {};
@@ -79,6 +79,8 @@ 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() }))); };
82
84
  var JourneyBooking = /** @class */ (function (_super) {
83
85
  __extends(JourneyBooking, _super);
84
86
  /**
@@ -219,12 +221,15 @@ var JourneyBooking = /** @class */ (function (_super) {
219
221
  * This method returns the possible departures for all journeys (MLP) sold by this seller.
220
222
  * @returns The list of possible departures
221
223
  */
222
- JourneyBooking.prototype.getJourneysDepartures = function (options) {
224
+ JourneyBooking.prototype.getJourneysDepartures = function (filtersOrOptions, options) {
223
225
  return __awaiter(this, void 0, void 0, function () {
224
- var url;
226
+ var filters, requestOptions, searchParams, url;
225
227
  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) {
228
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
229
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
230
+ searchParams = new URLSearchParams(getJourneyLineRouteParams(filters));
231
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?").concat(searchParams);
232
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
228
233
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
229
234
  })];
230
235
  });
@@ -235,13 +240,15 @@ var JourneyBooking = /** @class */ (function (_super) {
235
240
  * @param departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
236
241
  * @returns The list of possible destinations
237
242
  */
238
- JourneyBooking.prototype.getJourneysDestinations = function (departureStopName, options) {
243
+ JourneyBooking.prototype.getJourneysDestinations = function (departureStopName, filtersOrOptions, options) {
239
244
  return __awaiter(this, void 0, void 0, function () {
240
- var searchParams, url;
245
+ var filters, requestOptions, searchParams, url;
241
246
  return __generator(this, function (_a) {
242
- searchParams = new URLSearchParams({ departureStopName: departureStopName });
247
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
248
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
249
+ searchParams = new URLSearchParams(__assign({ departureStopName: departureStopName }, getJourneyLineRouteParams(filters)));
243
250
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
244
- return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
251
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
245
252
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
246
253
  })];
247
254
  });
@@ -262,7 +269,7 @@ var JourneyBooking = /** @class */ (function (_super) {
262
269
  if (request.departureStopName === undefined || request.destinationStopName === undefined) {
263
270
  throw Error("Fields departureStopName and destinationStopName are required");
264
271
  }
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 })));
272
+ 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
273
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys_v4?").concat(searchParams);
267
274
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
268
275
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
@@ -462,13 +469,26 @@ var JourneyBooking = /** @class */ (function (_super) {
462
469
  };
463
470
  /**
464
471
  * @description This method shall be called when the user wants to change the assigned seats of a trip.
472
+ *
473
+ * Two shapes are supported. Callers should prefer `seatChanges` when
474
+ * the cart has more than one passenger on the trip — the BE pairs by
475
+ * {@link SeatChange.oldSeatId}, which uniquely identifies the cart's
476
+ * underlying TripBusLayoutCell. The legacy `newSeatsIds` form is a
477
+ * full positional snapshot of every passenger's new seat; the BE
478
+ * zips it against EF-ordered TripBusLayoutCells, which can reassign
479
+ * the wrong passenger when the two orderings disagree.
480
+ *
481
+ * Send only one of the two arguments per call. If both are present
482
+ * the BE prefers `seatChanges`.
465
483
  * @param tripId The id of the trip for which the seats should be changed
466
- * @param newSeatsIds The ids of the new seats, as found the {@link BusMatrix}
484
+ * @param seatsOrChanges Either the legacy `newSeatsIds` array (every
485
+ * passenger's new seat, in order) or an explicit list of
486
+ * {@link SeatChange} pairs (only the seats that change).
467
487
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
468
488
  */
469
- JourneyBooking.prototype.changeSeatsOfTrip = function (tripId, newSeatsIds, options) {
489
+ JourneyBooking.prototype.changeSeatsOfTrip = function (tripId, seatsOrChanges, options) {
470
490
  return __awaiter(this, void 0, void 0, function () {
471
- var seatSelectionStatus, url;
491
+ var seatSelectionStatus, usesExplicitShape, body, url;
472
492
  var _this = this;
473
493
  return __generator(this, function (_a) {
474
494
  // First check that it is possible to call this API
@@ -479,12 +499,19 @@ var JourneyBooking = /** @class */ (function (_super) {
479
499
  if (!seatSelectionStatus || !seatSelectionStatus[0]) {
480
500
  throw Error("The status of the cart does not allow to call this API");
481
501
  }
502
+ usesExplicitShape = seatsOrChanges.length > 0 && typeof seatsOrChanges[0] === "object";
503
+ body = {
504
+ tripId: tripId,
505
+ cartGuid: this.cart.guid
506
+ };
507
+ if (usesExplicitShape) {
508
+ body.seatChanges = seatsOrChanges;
509
+ }
510
+ else {
511
+ body.newSeatsIds = seatsOrChanges;
512
+ }
482
513
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats");
483
- return [2 /*return*/, this.callPostApi(url, {
484
- tripId: tripId,
485
- newSeatsIds: newSeatsIds,
486
- cartGuid: this.cart.guid
487
- }, options).then(function (response) {
514
+ return [2 /*return*/, this.callPostApi(url, body, options).then(function (response) {
488
515
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
489
516
  return response;
490
517
  // Update the booking process status
package/lib/index.d.ts CHANGED
@@ -16,7 +16,7 @@ export { ErrorResponse, objectIsMTSErrorResponse } from "./types/ErrorResponse";
16
16
  export { City } from "./types/common/City";
17
17
  export { Extra, GetExtrasResponse, GetExtrasForBookingResponse } from "./types/common/Extra";
18
18
  export * from "./types/common/dates";
19
- export { BusLayoutCell, BusMatrix, BusCellTypes, SeatStatus } from "./types/journeys/BusMatrix";
19
+ export { BusLayoutCell, BusMatrix, BusCellTypes, SeatChange, SeatStatus } from "./types/journeys/BusMatrix";
20
20
  export { JourneyCart, JourneyBookingType, TripBookingInfo } from "./types/journeys/JourneyCart";
21
21
  export { JourneyInfo } from "./types/journeys/JourneyInfo";
22
22
  export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
@@ -18,6 +18,17 @@ export type BusLayoutCell = {
18
18
  * - On the third dimension, the are the columns.
19
19
  */
20
20
  export type BusMatrix = BusLayoutCell[][][];
21
+ /**
22
+ * Explicit (oldSeatId, newSeatId) pair for a single seat change in a
23
+ * cart. Used by `JourneyBooking.changeSeatsOfTrip` instead of the
24
+ * legacy positional `newSeatsIds` snapshot — the BE pairs by
25
+ * `oldSeatId`, so multi-passenger swaps no longer depend on array
26
+ * order and can never reassign the wrong passenger.
27
+ */
28
+ export type SeatChange = {
29
+ oldSeatId: number;
30
+ newSeatId: number;
31
+ };
21
32
  export declare enum BusCellTypes {
22
33
  SEAT = "SEAT",
23
34
  SELECTED_SEAT = "SELECTED_SEAT",
@@ -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.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",