mts-booking-library 1.1.10 → 1.2.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/lib/booking/booking.d.ts +61 -10
- package/lib/booking/booking.js +174 -12
- package/lib/booking/journeyBooking.d.ts +42 -18
- package/lib/booking/journeyBooking.js +164 -50
- package/lib/booking/serviceBooking.d.ts +5 -4
- package/lib/booking/serviceBooking.js +45 -12
- package/lib/booking/subscriptionBooking.d.ts +21 -7
- package/lib/booking/subscriptionBooking.js +116 -15
- package/lib/index.d.ts +5 -2
- package/lib/index.js +7 -2
- package/lib/types/ErrorResponse.d.ts +1 -0
- package/lib/types/ErrorResponse.js +5 -0
- package/lib/types/common/Cart.d.ts +14 -26
- package/lib/types/common/Extra.d.ts +20 -0
- package/lib/types/common/Extra.js +2 -0
- package/lib/types/common/Payment.d.ts +63 -0
- package/lib/types/common/Payment.js +24 -0
- package/lib/types/common/Person.d.ts +18 -1
- package/lib/types/common/Reduction.d.ts +31 -0
- package/lib/types/common/Reduction.js +2 -0
- package/lib/types/common/Tariffs.d.ts +21 -0
- package/lib/types/journeys/BusMatrix.d.ts +34 -0
- package/lib/types/journeys/BusMatrix.js +20 -0
- package/lib/types/services/ServiceCart.d.ts +1 -1
- package/lib/utils/apiCall.js +14 -8
- package/package.json +3 -3
| @@ -52,6 +52,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { | |
| 52 52 | 
             
            };
         | 
| 53 53 | 
             
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 54 54 | 
             
            exports.JourneyBooking = void 0;
         | 
| 55 | 
            +
            var ErrorResponse_1 = require("../types/ErrorResponse");
         | 
| 55 56 | 
             
            var booking_1 = require("./booking");
         | 
| 56 57 | 
             
            var JourneyBooking = /** @class */ (function (_super) {
         | 
| 57 58 | 
             
                __extends(JourneyBooking, _super);
         | 
| @@ -90,7 +91,14 @@ var JourneyBooking = /** @class */ (function (_super) { | |
| 90 91 | 
             
                                if (cartDate > new Date()) {
         | 
| 91 92 | 
             
                                    _this.cart = cart;
         | 
| 92 93 | 
             
                                    _this.bookingDueDate = cartDate; // See Booking class
         | 
| 93 | 
            -
                                     | 
| 94 | 
            +
                                    // Fill the booking process status
         | 
| 95 | 
            +
                                    _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
         | 
| 96 | 
            +
                                        var bookingStep = _a[0], values = _a[1];
         | 
| 97 | 
            +
                                        return [
         | 
| 98 | 
            +
                                            bookingStep,
         | 
| 99 | 
            +
                                            values
         | 
| 100 | 
            +
                                        ];
         | 
| 101 | 
            +
                                    }));
         | 
| 94 102 | 
             
                                    _this.createCartTimer(cartDate);
         | 
| 95 103 | 
             
                                }
         | 
| 96 104 | 
             
                            });
         | 
| @@ -105,7 +113,7 @@ var JourneyBooking = /** @class */ (function (_super) { | |
| 105 113 | 
             
                            setTimeout(function () {
         | 
| 106 114 | 
             
                                localStorage.removeItem("cartId");
         | 
| 107 115 | 
             
                                // Put actions that have to be done when timer expires here
         | 
| 108 | 
            -
                                _this. | 
| 116 | 
            +
                                _this.bookingStepsToStatus = new Map();
         | 
| 109 117 | 
             
                                _this.cart = undefined;
         | 
| 110 118 | 
             
                                _this.bookingDueDate = undefined; // See Booking class
         | 
| 111 119 | 
             
                                _this.onCartExpiration();
         | 
| @@ -119,7 +127,13 @@ var JourneyBooking = /** @class */ (function (_super) { | |
| 119 127 | 
             
                        var url;
         | 
| 120 128 | 
             
                        return __generator(this, function (_a) {
         | 
| 121 129 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
         | 
| 122 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 130 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 131 | 
            +
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         | 
| 132 | 
            +
                                        localStorage.removeItem("cartId");
         | 
| 133 | 
            +
                                        throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
         | 
| 134 | 
            +
                                    }
         | 
| 135 | 
            +
                                    return response.cart;
         | 
| 136 | 
            +
                                })];
         | 
| 123 137 | 
             
                        });
         | 
| 124 138 | 
             
                    });
         | 
| 125 139 | 
             
                };
         | 
| @@ -132,7 +146,9 @@ var JourneyBooking = /** @class */ (function (_super) { | |
| 132 146 | 
             
                        var url;
         | 
| 133 147 | 
             
                        return __generator(this, function (_a) {
         | 
| 134 148 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/departures?");
         | 
| 135 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 149 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 150 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
         | 
| 151 | 
            +
                                })];
         | 
| 136 152 | 
             
                        });
         | 
| 137 153 | 
             
                    });
         | 
| 138 154 | 
             
                };
         | 
| @@ -147,7 +163,9 @@ var JourneyBooking = /** @class */ (function (_super) { | |
| 147 163 | 
             
                        return __generator(this, function (_a) {
         | 
| 148 164 | 
             
                            searchParams = new URLSearchParams({ departureStopName: departureStopName });
         | 
| 149 165 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/destinations?").concat(searchParams);
         | 
| 150 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 166 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 167 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
         | 
| 168 | 
            +
                                })];
         | 
| 151 169 | 
             
                        });
         | 
| 152 170 | 
             
                    });
         | 
| 153 171 | 
             
                };
         | 
| @@ -155,107 +173,203 @@ var JourneyBooking = /** @class */ (function (_super) { | |
| 155 173 | 
             
                * This method returns the journeys that match the given parameters.
         | 
| 156 174 | 
             
                * Note that it will always return the journeys for the one-way trip.
         | 
| 157 175 | 
             
                * If you want to get the journeys for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
         | 
| 158 | 
            -
                * @param {JourneySearch}  | 
| 176 | 
            +
                * @param {JourneySearch} request an object of type {@link JourneySearch} containing the parameters of the search
         | 
| 159 177 | 
             
                * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
         | 
| 160 178 | 
             
                */
         | 
| 161 | 
            -
                JourneyBooking.prototype.getJourneys = function ( | 
| 179 | 
            +
                JourneyBooking.prototype.getJourneys = function (request) {
         | 
| 162 180 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 163 181 | 
             
                        var searchParams, url;
         | 
| 164 182 | 
             
                        return __generator(this, function (_a) {
         | 
| 165 | 
            -
                            if ( | 
| 183 | 
            +
                            if (request.departureStopName === undefined || request.destinationStopName === undefined) {
         | 
| 166 184 | 
             
                                throw Error("Fields departureStopName and destinationStopName are required");
         | 
| 167 185 | 
             
                            }
         | 
| 168 186 | 
             
                            searchParams = new URLSearchParams({
         | 
| 169 | 
            -
                                departureStopName:  | 
| 170 | 
            -
                                destinationStopName:  | 
| 171 | 
            -
                                passengersNumber:  | 
| 172 | 
            -
                                date:  | 
| 173 | 
            -
                                roundTripDate:  | 
| 174 | 
            -
                                currency:  | 
| 175 | 
            -
                                isRoundtrip:  | 
| 187 | 
            +
                                departureStopName: request.departureStopName,
         | 
| 188 | 
            +
                                destinationStopName: request.destinationStopName,
         | 
| 189 | 
            +
                                passengersNumber: request.passengersNumber.toString(),
         | 
| 190 | 
            +
                                date: request.date,
         | 
| 191 | 
            +
                                roundTripDate: request.roundTripDate ? request.roundTripDate : "null",
         | 
| 192 | 
            +
                                currency: request.currency,
         | 
| 193 | 
            +
                                isRoundtrip: request.isRoundtrip.toString()
         | 
| 176 194 | 
             
                            });
         | 
| 177 195 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/journeys?").concat(searchParams);
         | 
| 178 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 196 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 197 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.journeys;
         | 
| 198 | 
            +
                                })];
         | 
| 179 199 | 
             
                        });
         | 
| 180 200 | 
             
                    });
         | 
| 181 201 | 
             
                };
         | 
| 182 | 
            -
                JourneyBooking.prototype.createJourneyCart = function ( | 
| 202 | 
            +
                JourneyBooking.prototype.createJourneyCart = function (journeyCart) {
         | 
| 183 203 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 184 204 | 
             
                        var url;
         | 
| 185 205 | 
             
                        var _this = this;
         | 
| 186 206 | 
             
                        return __generator(this, function (_a) {
         | 
| 187 207 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/cart");
         | 
| 188 | 
            -
                            return [2 /*return*/, this.callPostApi(url,  | 
| 189 | 
            -
                                     | 
| 190 | 
            -
                                     | 
| 191 | 
            -
             | 
| 192 | 
            -
                                     | 
| 193 | 
            -
                                     | 
| 208 | 
            +
                            return [2 /*return*/, this.callPostApi(url, journeyCart).then(function (response) {
         | 
| 209 | 
            +
                                    // Check for errors
         | 
| 210 | 
            +
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         | 
| 211 | 
            +
                                        return response;
         | 
| 212 | 
            +
                                    }
         | 
| 213 | 
            +
                                    _this.cart = response.cart;
         | 
| 214 | 
            +
                                    // Save the cartId in the localStorage
         | 
| 215 | 
            +
                                    localStorage.setItem("cartId", response.cart.id.toString());
         | 
| 216 | 
            +
                                    // Fill the booking process status
         | 
| 217 | 
            +
                                    _this.bookingStepsToStatus = new Map(Object.entries(response.cart.stepsToStatus).map(function (_a) {
         | 
| 218 | 
            +
                                        var bookingStep = _a[0], values = _a[1];
         | 
| 219 | 
            +
                                        return [
         | 
| 220 | 
            +
                                            bookingStep,
         | 
| 221 | 
            +
                                            values
         | 
| 222 | 
            +
                                        ];
         | 
| 223 | 
            +
                                    }));
         | 
| 224 | 
            +
                                    _this.bookingDueDate = new Date(response.cart.bookingDueDate);
         | 
| 225 | 
            +
                                    _this.createCartTimer(new Date(response.cart.bookingDueDate));
         | 
| 226 | 
            +
                                    return response.cart;
         | 
| 194 227 | 
             
                                })];
         | 
| 195 228 | 
             
                        });
         | 
| 196 229 | 
             
                    });
         | 
| 197 230 | 
             
                };
         | 
| 198 | 
            -
                 | 
| 231 | 
            +
                /**
         | 
| 232 | 
            +
                 * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
         | 
| 233 | 
            +
                 * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
         | 
| 234 | 
            +
                 * as well as a list of the available tariffs for each trip.
         | 
| 235 | 
            +
                 */
         | 
| 236 | 
            +
                JourneyBooking.prototype.getBuyerPassengersDetails = function () {
         | 
| 199 237 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 200 | 
            -
                        var  | 
| 238 | 
            +
                        var buyerPassengersDetails, url;
         | 
| 201 239 | 
             
                        return __generator(this, function (_a) {
         | 
| 202 | 
            -
                             | 
| 203 | 
            -
             | 
| 204 | 
            -
                                 | 
| 205 | 
            -
                            } | 
| 206 | 
            -
                             | 
| 207 | 
            -
                             | 
| 240 | 
            +
                            // First check that it is possible to call this API
         | 
| 241 | 
            +
                            if (!this.cart) {
         | 
| 242 | 
            +
                                throw Error("Cart is not initialized yet");
         | 
| 243 | 
            +
                            }
         | 
| 244 | 
            +
                            buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
         | 
| 245 | 
            +
                            if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
         | 
| 246 | 
            +
                                throw Error("The status of the cart does not allow to call this API");
         | 
| 247 | 
            +
                            }
         | 
| 248 | 
            +
                            url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?");
         | 
| 249 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 250 | 
            +
                                    // Check for errors
         | 
| 251 | 
            +
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         | 
| 252 | 
            +
                                        return response;
         | 
| 253 | 
            +
                                    }
         | 
| 254 | 
            +
                                    // Parse the map for the tariffs
         | 
| 255 | 
            +
                                    var tripsToTariffs = new Map(Object.entries(response.tariffs).map(function (_a) {
         | 
| 256 | 
            +
                                        var tripId = _a[0], tariff = _a[1];
         | 
| 257 | 
            +
                                        return [
         | 
| 258 | 
            +
                                            +tripId,
         | 
| 259 | 
            +
                                            tariff
         | 
| 260 | 
            +
                                        ];
         | 
| 261 | 
            +
                                    }));
         | 
| 262 | 
            +
                                    return {
         | 
| 263 | 
            +
                                        buyer: response.buyer,
         | 
| 264 | 
            +
                                        passengers: response.passengers,
         | 
| 265 | 
            +
                                        tariffs: tripsToTariffs
         | 
| 266 | 
            +
                                    };
         | 
| 267 | 
            +
                                })];
         | 
| 208 268 | 
             
                        });
         | 
| 209 269 | 
             
                    });
         | 
| 210 270 | 
             
                };
         | 
| 211 | 
            -
                 | 
| 212 | 
            -
             | 
| 271 | 
            +
                /**
         | 
| 272 | 
            +
                 * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
         | 
| 273 | 
            +
                 * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
         | 
| 274 | 
            +
                 * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
         | 
| 275 | 
            +
                 */
         | 
| 276 | 
            +
                JourneyBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
         | 
| 213 277 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 214 | 
            -
                        var  | 
| 278 | 
            +
                        var buyerPassengersDetails, url;
         | 
| 215 279 | 
             
                        return __generator(this, function (_a) {
         | 
| 280 | 
            +
                            // First check that it is possible to call this API
         | 
| 216 281 | 
             
                            if (!this.cart) {
         | 
| 217 282 | 
             
                                throw Error("Cart is not initialized yet");
         | 
| 218 283 | 
             
                            }
         | 
| 219 | 
            -
                             | 
| 220 | 
            -
                             | 
| 221 | 
            -
             | 
| 284 | 
            +
                            buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
         | 
| 285 | 
            +
                            if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
         | 
| 286 | 
            +
                                throw Error("The status of the cart does not allow to call this API");
         | 
| 287 | 
            +
                            }
         | 
| 288 | 
            +
                            url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
         | 
| 289 | 
            +
                            return [2 /*return*/, this.callPostApi(url, passengersDetails).then(function (response) {
         | 
| 290 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
         | 
| 291 | 
            +
                                })];
         | 
| 222 292 | 
             
                        });
         | 
| 223 293 | 
             
                    });
         | 
| 224 294 | 
             
                };
         | 
| 225 | 
            -
                 | 
| 226 | 
            -
             | 
| 295 | 
            +
                /**
         | 
| 296 | 
            +
                 * @description This method shall be used when the user wants to retrieve the bus matrix for a trip. The bus matrix shows
         | 
| 297 | 
            +
                 * the seats that are available and the ones that are already taken, as well as how the bus is made.
         | 
| 298 | 
            +
                 * @param {number} tripId The id of the trip for which the bus matrix should be retrieved
         | 
| 299 | 
            +
                 * @param {number} departureStopId The id of the departure stop
         | 
| 300 | 
            +
                 * @param {number} destinationStopId The id of the destination stop
         | 
| 301 | 
            +
                 * @returns An {@link ErrorResponse} object in case of error, a {@link BusMatrix} otherwise.
         | 
| 302 | 
            +
                 */
         | 
| 303 | 
            +
                JourneyBooking.prototype.getBusMatrix = function (tripId, departureStopId, destinationStopId) {
         | 
| 227 304 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 228 | 
            -
                        var url;
         | 
| 305 | 
            +
                        var seatSelectionStatus, searchParams, url;
         | 
| 229 306 | 
             
                        return __generator(this, function (_a) {
         | 
| 307 | 
            +
                            // First check that it is possible to call this API
         | 
| 230 308 | 
             
                            if (!this.cart) {
         | 
| 231 309 | 
             
                                throw Error("Cart is not initialized yet");
         | 
| 232 310 | 
             
                            }
         | 
| 233 | 
            -
                             | 
| 234 | 
            -
                             | 
| 311 | 
            +
                            seatSelectionStatus = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.SEATS_SELECTION);
         | 
| 312 | 
            +
                            if (!seatSelectionStatus || !seatSelectionStatus[0]) {
         | 
| 313 | 
            +
                                throw Error("The status of the cart does not allow to call this API");
         | 
| 314 | 
            +
                            }
         | 
| 315 | 
            +
                            searchParams = new URLSearchParams({
         | 
| 316 | 
            +
                                departureStopId: departureStopId.toString(),
         | 
| 317 | 
            +
                                destinationStopId: destinationStopId.toString()
         | 
| 318 | 
            +
                            });
         | 
| 319 | 
            +
                            url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/trips/").concat(tripId, "/seats?").concat(searchParams);
         | 
| 320 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 321 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.busMatrix;
         | 
| 322 | 
            +
                                })];
         | 
| 235 323 | 
             
                        });
         | 
| 236 324 | 
             
                    });
         | 
| 237 325 | 
             
                };
         | 
| 238 | 
            -
                 | 
| 326 | 
            +
                /**
         | 
| 327 | 
            +
                 * @description This method shall be called when the user wants to retrieve which seats were assigned for this booking.
         | 
| 328 | 
            +
                 * @param {number} tripId The id of the trip for which the seats should be retrieved.
         | 
| 329 | 
            +
                 * @returns An {@link ErrorResponse} object in case of error, a list of {@link BusLayoutCell} ids otherwise, representing the assigned seats.
         | 
| 330 | 
            +
                 */
         | 
| 331 | 
            +
                JourneyBooking.prototype.getAssignedSeats = function (tripId) {
         | 
| 239 332 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 240 | 
            -
                        var url;
         | 
| 333 | 
            +
                        var seatSelectionStatus, searchParams, url;
         | 
| 241 334 | 
             
                        return __generator(this, function (_a) {
         | 
| 335 | 
            +
                            // First check that it is possible to call this API
         | 
| 242 336 | 
             
                            if (!this.cart) {
         | 
| 243 337 | 
             
                                throw Error("Cart is not initialized yet");
         | 
| 244 338 | 
             
                            }
         | 
| 245 | 
            -
                             | 
| 246 | 
            -
                             | 
| 339 | 
            +
                            seatSelectionStatus = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.SEATS_SELECTION);
         | 
| 340 | 
            +
                            if (!seatSelectionStatus || !seatSelectionStatus[0]) {
         | 
| 341 | 
            +
                                throw Error("The status of the cart does not allow to call this API");
         | 
| 342 | 
            +
                            }
         | 
| 343 | 
            +
                            searchParams = new URLSearchParams({ tripId: tripId.toString() });
         | 
| 344 | 
            +
                            url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats?").concat(searchParams);
         | 
| 345 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 346 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
         | 
| 347 | 
            +
                                })];
         | 
| 247 348 | 
             
                        });
         | 
| 248 349 | 
             
                    });
         | 
| 249 350 | 
             
                };
         | 
| 250 | 
            -
                 | 
| 351 | 
            +
                /**
         | 
| 352 | 
            +
                 * @description This method shall be called when the user wants to change the assigned seats of a trip.
         | 
| 353 | 
            +
                 * @param {number} tripId The id of the trip for which the seats should be changed
         | 
| 354 | 
            +
                 * @param {number[]} newSeatsIds The ids of the new seats, as found the {@link BusMatrix}
         | 
| 355 | 
            +
                 * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
         | 
| 356 | 
            +
                 */
         | 
| 357 | 
            +
                JourneyBooking.prototype.changeSeatsOfTrip = function (tripId, newSeatsIds) {
         | 
| 251 358 | 
             
                    return __awaiter(this, void 0, void 0, function () {
         | 
| 252 | 
            -
                        var url;
         | 
| 359 | 
            +
                        var seatSelectionStatus, url;
         | 
| 253 360 | 
             
                        return __generator(this, function (_a) {
         | 
| 361 | 
            +
                            // First check that it is possible to call this API
         | 
| 254 362 | 
             
                            if (!this.cart) {
         | 
| 255 363 | 
             
                                throw Error("Cart is not initialized yet");
         | 
| 256 364 | 
             
                            }
         | 
| 257 | 
            -
                             | 
| 258 | 
            -
                             | 
| 365 | 
            +
                            seatSelectionStatus = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.SEATS_SELECTION);
         | 
| 366 | 
            +
                            if (!seatSelectionStatus || !seatSelectionStatus[0]) {
         | 
| 367 | 
            +
                                throw Error("The status of the cart does not allow to call this API");
         | 
| 368 | 
            +
                            }
         | 
| 369 | 
            +
                            url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats");
         | 
| 370 | 
            +
                            return [2 /*return*/, this.callPostApi(url, { tripId: tripId, seatsIds: newSeatsIds }).then(function (response) {
         | 
| 371 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
         | 
| 372 | 
            +
                                })];
         | 
| 259 373 | 
             
                        });
         | 
| 260 374 | 
             
                    });
         | 
| 261 375 | 
             
                };
         | 
| @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            import { MTSEnvs } from "../config";
         | 
| 2 | 
            +
            import { ErrorResponse } from "../types/ErrorResponse";
         | 
| 2 3 | 
             
            import { Service, ServiceTrip } from "../types/services/Service";
         | 
| 3 4 | 
             
            import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
         | 
| 4 5 | 
             
            import { Booking } from "./booking";
         | 
| @@ -25,7 +26,7 @@ export declare class ServiceBooking extends Booking { | |
| 25 26 | 
             
                * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
         | 
| 26 27 | 
             
                * @returns {string[]} The list of possible cities
         | 
| 27 28 | 
             
                */
         | 
| 28 | 
            -
                getServiceCities(): Promise<string[]>;
         | 
| 29 | 
            +
                getServiceCities(): Promise<ErrorResponse | string[]>;
         | 
| 29 30 | 
             
                /**
         | 
| 30 31 | 
             
                * This method returns the tours sold by this seller in the given city.
         | 
| 31 32 | 
             
                * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
         | 
| @@ -33,7 +34,7 @@ export declare class ServiceBooking extends Booking { | |
| 33 34 | 
             
                * @param {Booking.Currencies} currency The currency in which the prices should be returned
         | 
| 34 35 | 
             
                * @returns {Tour[]} The returned tours
         | 
| 35 36 | 
             
                */
         | 
| 36 | 
            -
                getServices(currency: Booking.Currencies, cityName?: string): Promise<Service[]>;
         | 
| 37 | 
            +
                getServices(currency: Booking.Currencies, cityName?: string): Promise<ErrorResponse | Service[]>;
         | 
| 37 38 | 
             
                /**
         | 
| 38 39 | 
             
                * This method returns the tours available for the given date. This method can be used if the seller wants the user to book a specific date
         | 
| 39 40 | 
             
                * and/or a specific hour for the tour.
         | 
| @@ -42,6 +43,6 @@ export declare class ServiceBooking extends Booking { | |
| 42 43 | 
             
                * @param {Date} date The date on which to get the tours
         | 
| 43 44 | 
             
                * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
         | 
| 44 45 | 
             
                */
         | 
| 45 | 
            -
                getServiceTrips(serviceId: number, date: Date): Promise<ServiceTrip[]>;
         | 
| 46 | 
            -
                createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ServiceCart>;
         | 
| 46 | 
            +
                getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
         | 
| 47 | 
            +
                createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
         | 
| 47 48 | 
             
            }
         | 
| @@ -63,6 +63,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { | |
| 63 63 | 
             
            };
         | 
| 64 64 | 
             
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 65 65 | 
             
            exports.ServiceBooking = void 0;
         | 
| 66 | 
            +
            var ErrorResponse_1 = require("../types/ErrorResponse");
         | 
| 66 67 | 
             
            var booking_1 = require("./booking");
         | 
| 67 68 | 
             
            var ServiceBooking = /** @class */ (function (_super) {
         | 
| 68 69 | 
             
                __extends(ServiceBooking, _super);
         | 
| @@ -101,7 +102,14 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 101 102 | 
             
                                if (cartDate > new Date()) {
         | 
| 102 103 | 
             
                                    _this.cart = cart;
         | 
| 103 104 | 
             
                                    _this.bookingDueDate = cartDate; // See Booking class
         | 
| 104 | 
            -
                                     | 
| 105 | 
            +
                                    // Fill the booking process status
         | 
| 106 | 
            +
                                    _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
         | 
| 107 | 
            +
                                        var bookingStep = _a[0], values = _a[1];
         | 
| 108 | 
            +
                                        return [
         | 
| 109 | 
            +
                                            bookingStep,
         | 
| 110 | 
            +
                                            values
         | 
| 111 | 
            +
                                        ];
         | 
| 112 | 
            +
                                    }));
         | 
| 105 113 | 
             
                                    _this.createCartTimer(cartDate);
         | 
| 106 114 | 
             
                                }
         | 
| 107 115 | 
             
                            });
         | 
| @@ -116,7 +124,6 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 116 124 | 
             
                            setTimeout(function () {
         | 
| 117 125 | 
             
                                localStorage.removeItem("cartId");
         | 
| 118 126 | 
             
                                // Put actions that have to be done when timer expires here
         | 
| 119 | 
            -
                                _this.cartStatus = booking_1.Booking.CartStatus.EMPTY;
         | 
| 120 127 | 
             
                                _this.cart = undefined;
         | 
| 121 128 | 
             
                                _this.bookingDueDate = undefined; // See Booking class
         | 
| 122 129 | 
             
                                _this.onCartExpiration();
         | 
| @@ -130,7 +137,13 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 130 137 | 
             
                        var url;
         | 
| 131 138 | 
             
                        return __generator(this, function (_a) {
         | 
| 132 139 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
         | 
| 133 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 140 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 141 | 
            +
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         | 
| 142 | 
            +
                                        localStorage.removeItem("cartId");
         | 
| 143 | 
            +
                                        throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
         | 
| 144 | 
            +
                                    }
         | 
| 145 | 
            +
                                    return response.cart;
         | 
| 146 | 
            +
                                })];
         | 
| 134 147 | 
             
                        });
         | 
| 135 148 | 
             
                    });
         | 
| 136 149 | 
             
                };
         | 
| @@ -144,7 +157,9 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 144 157 | 
             
                        var url;
         | 
| 145 158 | 
             
                        return __generator(this, function (_a) {
         | 
| 146 159 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/services/cities?");
         | 
| 147 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 160 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 161 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
         | 
| 162 | 
            +
                                })];
         | 
| 148 163 | 
             
                        });
         | 
| 149 164 | 
             
                    });
         | 
| 150 165 | 
             
                };
         | 
| @@ -161,7 +176,9 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 161 176 | 
             
                        return __generator(this, function (_a) {
         | 
| 162 177 | 
             
                            searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
         | 
| 163 178 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/services?").concat(searchParams);
         | 
| 164 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 179 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 180 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.services;
         | 
| 181 | 
            +
                                })];
         | 
| 165 182 | 
             
                        });
         | 
| 166 183 | 
             
                    });
         | 
| 167 184 | 
             
                };
         | 
| @@ -179,7 +196,9 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 179 196 | 
             
                        return __generator(this, function (_a) {
         | 
| 180 197 | 
             
                            searchParams = new URLSearchParams({ date: date.toDateString() });
         | 
| 181 198 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/services/").concat(serviceId, "/trips?").concat(searchParams);
         | 
| 182 | 
            -
                            return [2 /*return*/, this.callGetApi(url) | 
| 199 | 
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         | 
| 200 | 
            +
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
         | 
| 201 | 
            +
                                })];
         | 
| 183 202 | 
             
                        });
         | 
| 184 203 | 
             
                    });
         | 
| 185 204 | 
             
                };
         | 
| @@ -189,12 +208,26 @@ var ServiceBooking = /** @class */ (function (_super) { | |
| 189 208 | 
             
                        var _this = this;
         | 
| 190 209 | 
             
                        return __generator(this, function (_a) {
         | 
| 191 210 | 
             
                            url = "".concat(this.config.API_ENDPOINT, "/booking/services/cart");
         | 
| 192 | 
            -
                            return [2 /*return*/, this.callPostApi(url, serviceCart).then(function ( | 
| 193 | 
            -
                                     | 
| 194 | 
            -
                                     | 
| 195 | 
            -
             | 
| 196 | 
            -
                                     | 
| 197 | 
            -
                                     | 
| 211 | 
            +
                            return [2 /*return*/, this.callPostApi(url, serviceCart).then(function (response) {
         | 
| 212 | 
            +
                                    // Check for errors
         | 
| 213 | 
            +
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         | 
| 214 | 
            +
                                        return response;
         | 
| 215 | 
            +
                                    }
         | 
| 216 | 
            +
                                    // Save the local data
         | 
| 217 | 
            +
                                    _this.cart = response.cart;
         | 
| 218 | 
            +
                                    // Save the cartId in the localStorage
         | 
| 219 | 
            +
                                    localStorage.setItem("cartId", response.cart.id.toString());
         | 
| 220 | 
            +
                                    // Fill the booking process status
         | 
| 221 | 
            +
                                    _this.bookingStepsToStatus = new Map(Object.entries(response.cart.stepsToStatus).map(function (_a) {
         | 
| 222 | 
            +
                                        var bookingStep = _a[0], values = _a[1];
         | 
| 223 | 
            +
                                        return [
         | 
| 224 | 
            +
                                            bookingStep,
         | 
| 225 | 
            +
                                            values
         | 
| 226 | 
            +
                                        ];
         | 
| 227 | 
            +
                                    }));
         | 
| 228 | 
            +
                                    _this.bookingDueDate = new Date(response.cart.bookingDueDate);
         | 
| 229 | 
            +
                                    _this.createCartTimer(new Date(response.cart.bookingDueDate));
         | 
| 230 | 
            +
                                    return response.cart;
         | 
| 198 231 | 
             
                                })];
         | 
| 199 232 | 
             
                        });
         | 
| 200 233 | 
             
                    });
         | 
| @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            import { MTSEnvs } from "../config";
         | 
| 2 | 
            +
            import { ErrorResponse } from "../types/ErrorResponse";
         | 
| 2 3 | 
             
            import { Cart } from "../types/common/Cart";
         | 
| 4 | 
            +
            import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
         | 
| 3 5 | 
             
            import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
         | 
| 4 6 | 
             
            import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
         | 
| 5 7 | 
             
            import { Subscription } from "../types/subscriptions/Subscriptions";
         | 
| @@ -26,13 +28,13 @@ export declare class SubscriptionBooking extends Booking { | |
| 26 28 | 
             
                * This method returns the possible departures for all subscriptions sold by this seller.
         | 
| 27 29 | 
             
                * @returns {string[]} The list of possible departures
         | 
| 28 30 | 
             
                */
         | 
| 29 | 
            -
                getSubscriptionsDepartures(): Promise<string[]>;
         | 
| 31 | 
            +
                getSubscriptionsDepartures(): Promise<ErrorResponse | string[]>;
         | 
| 30 32 | 
             
                /**
         | 
| 31 33 | 
             
                * This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
         | 
| 32 34 | 
             
                * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
         | 
| 33 35 | 
             
                * @returns {string[]} The list of possible destinations
         | 
| 34 36 | 
             
                */
         | 
| 35 | 
            -
                getSubscriptionsDestinations(departureStopName: string): Promise<string[]>;
         | 
| 37 | 
            +
                getSubscriptionsDestinations(departureStopName: string): Promise<ErrorResponse | string[]>;
         | 
| 36 38 | 
             
                /**
         | 
| 37 39 | 
             
                * This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
         | 
| 38 40 | 
             
                * The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
         | 
| @@ -40,7 +42,7 @@ export declare class SubscriptionBooking extends Booking { | |
| 40 42 | 
             
                * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
         | 
| 41 43 | 
             
                * @returns {ValidityTypes[]} The list of possible validity types
         | 
| 42 44 | 
             
                */
         | 
| 43 | 
            -
                getSubscriptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<SubscriptionBooking.ValidityTypes[]>;
         | 
| 45 | 
            +
                getSubscriptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<ErrorResponse | SubscriptionBooking.ValidityTypes[]>;
         | 
| 44 46 | 
             
                /**
         | 
| 45 47 | 
             
                * This method returns the subscriptions that match the given parameters.
         | 
| 46 48 | 
             
                * Note that it will always return the subscription for the one-way trip.
         | 
| @@ -50,20 +52,32 @@ export declare class SubscriptionBooking extends Booking { | |
| 50 52 | 
             
                * @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
         | 
| 51 53 | 
             
                * @returns {Array<Subscription>} The subscriptions that match the given parameters
         | 
| 52 54 | 
             
                */
         | 
| 53 | 
            -
                getSubscriptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<Subscription[]>;
         | 
| 55 | 
            +
                getSubscriptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<ErrorResponse | Subscription[]>;
         | 
| 54 56 | 
             
                /**
         | 
| 55 57 | 
             
                 * This method returns the availability of the subscription for the given parameters.
         | 
| 56 58 | 
             
                 * Note that, contrary for the previous method, you should make one single request for both the outbound and return trip.
         | 
| 57 59 | 
             
                 * @param {GetSubscriptionAvailabilityRequest} request the request object containing the parameters for the availability check
         | 
| 58 60 | 
             
                 * @returns {GetSubscriptionAvailabilityResponse} The availability of the subscription for the given parameters
         | 
| 59 61 | 
             
                 */
         | 
| 60 | 
            -
                getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest): Promise<GetSubscriptionAvailabilityResponse>;
         | 
| 62 | 
            +
                getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest): Promise<ErrorResponse | GetSubscriptionAvailabilityResponse>;
         | 
| 61 63 | 
             
                /**
         | 
| 62 64 | 
             
                 * This method creates a subscription cart for the given parameters.
         | 
| 63 65 | 
             
                 * @param {CreateSubscriptionCartRequest} request the request object containing the parameters for the availability check
         | 
| 64 | 
            -
                 * @returns
         | 
| 66 | 
            +
                 * @returns {SubscriptionCart} The created cart
         | 
| 65 67 | 
             
                 */
         | 
| 66 | 
            -
                createSubscriptionCart(request: CreateSubscriptionCartRequest): Promise<SubscriptionCart>;
         | 
| 68 | 
            +
                createSubscriptionCart(request: CreateSubscriptionCartRequest): Promise<ErrorResponse | SubscriptionCart>;
         | 
| 69 | 
            +
                /**
         | 
| 70 | 
            +
                 * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
         | 
| 71 | 
            +
                 * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
         | 
| 72 | 
            +
                 * as well as a list of the available tariffs for each trip.
         | 
| 73 | 
            +
                 */
         | 
| 74 | 
            +
                getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
         | 
| 75 | 
            +
                /**
         | 
| 76 | 
            +
                 * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
         | 
| 77 | 
            +
                 * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
         | 
| 78 | 
            +
                 * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
         | 
| 79 | 
            +
                 */
         | 
| 80 | 
            +
                updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | any>;
         | 
| 67 81 | 
             
            }
         | 
| 68 82 | 
             
            export declare namespace SubscriptionBooking {
         | 
| 69 83 | 
             
                enum ValidityTypes {
         |