mts-booking-library 2.2.2 → 2.3.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.
@@ -198,7 +198,7 @@ var ServiceBooking = /** @class */ (function (_super) {
198
198
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
199
199
  // Clear all data
200
200
  _this.resetBooking();
201
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
201
+ return response;
202
202
  })];
203
203
  });
204
204
  });
@@ -214,9 +214,7 @@ var ServiceBooking = /** @class */ (function (_super) {
214
214
  return __generator(this, function (_a) {
215
215
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cities?");
216
216
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
217
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
218
- ? response
219
- : response.cities;
217
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
220
218
  })];
221
219
  });
222
220
  });
@@ -235,9 +233,7 @@ var ServiceBooking = /** @class */ (function (_super) {
235
233
  searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
236
234
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services?").concat(searchParams);
237
235
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
238
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
239
- ? response
240
- : response.services;
236
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.services;
241
237
  })];
242
238
  });
243
239
  });
@@ -257,13 +253,50 @@ var ServiceBooking = /** @class */ (function (_super) {
257
253
  searchParams = new URLSearchParams({ serviceId: serviceId.toString(), date: date });
258
254
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/trips?").concat(searchParams);
259
255
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
260
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
261
- ? response
262
- : response;
256
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
263
257
  })];
264
258
  });
265
259
  });
266
260
  };
261
+ /**
262
+ * This method creates a service cart for the given parameters.
263
+ * @returns The created cart
264
+ */
265
+ ServiceBooking.prototype.createCart = function (request, options) {
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ var url;
268
+ var _this = this;
269
+ return __generator(this, function (_a) {
270
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts");
271
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
272
+ return __generator(this, function (_a) {
273
+ switch (_a.label) {
274
+ case 0:
275
+ // Check for errors
276
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
277
+ // If there was an error, reset cartGuid and remove it from the mts-storage
278
+ this.resetBooking();
279
+ return [2 /*return*/, response];
280
+ }
281
+ // Fetch the newly created cart & update local properties
282
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
283
+ case 1:
284
+ // Fetch the newly created cart & update local properties
285
+ _a.sent();
286
+ if (!this.cart) {
287
+ // Should already be handled, but just in case
288
+ throw new Error("Could not fetch cart");
289
+ }
290
+ // Update storage
291
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
292
+ return [2 /*return*/, this.cart];
293
+ }
294
+ });
295
+ }); })];
296
+ });
297
+ });
298
+ };
299
+ /** @deprecated Use {@link createCart} instead. */
267
300
  ServiceBooking.prototype.createServiceCart = function (serviceCart, options) {
268
301
  return __awaiter(this, void 0, void 0, function () {
269
302
  var url;
@@ -336,9 +369,8 @@ var ServiceBooking = /** @class */ (function (_super) {
336
369
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
337
370
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
338
371
  // Check for errors
339
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
372
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
340
373
  return response;
341
- }
342
374
  return {
343
375
  buyerDataStatus: response.buyerDataStatus,
344
376
  buyer: response.buyer,
@@ -374,9 +406,8 @@ var ServiceBooking = /** @class */ (function (_super) {
374
406
  };
375
407
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
376
408
  return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
377
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
409
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
378
410
  return response;
379
- }
380
411
  // Update the booking process status
381
412
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
382
413
  return true;
@@ -431,9 +462,8 @@ var ServiceBooking = /** @class */ (function (_super) {
431
462
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
432
463
  return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
433
464
  var _a, _b;
434
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
465
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
435
466
  return response;
436
- }
437
467
  var reductionResponse = response;
438
468
  // Update the booking process status
439
469
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -471,9 +501,8 @@ var ServiceBooking = /** @class */ (function (_super) {
471
501
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
472
502
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
473
503
  var _a, _b, _c;
474
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
504
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
475
505
  return response;
476
- }
477
506
  var reductionResponse = response;
478
507
  // Update the booking process status
479
508
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -538,9 +567,8 @@ var ServiceBooking = /** @class */ (function (_super) {
538
567
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
539
568
  return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
540
569
  var _a, _b;
541
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
570
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
542
571
  return response;
543
- }
544
572
  var reductionResponse = response;
545
573
  // Update the booking process status
546
574
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -572,9 +600,8 @@ var ServiceBooking = /** @class */ (function (_super) {
572
600
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
573
601
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
574
602
  var _a, _b, _c;
575
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
603
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
576
604
  return response;
577
- }
578
605
  var reductionResponse = response;
579
606
  // Update the booking process status
580
607
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -632,9 +659,8 @@ var ServiceBooking = /** @class */ (function (_super) {
632
659
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
633
660
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
634
661
  var _a, _b;
635
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
662
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
636
663
  return response;
637
- }
638
664
  var reductionResponse = response;
639
665
  // Update the booking process status
640
666
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
4
  import { AddReductionRequest } from "../types/common/Reduction";
4
5
  import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
@@ -104,9 +105,9 @@ export declare class SubscriptionBooking extends Booking {
104
105
  * @returns The availability of the subscription for the given parameters
105
106
  */
106
107
  getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest, options?: ApiCallOptions): Promise<ErrorResponse | GetSubscriptionAvailabilityResponse>;
108
+ createCart(request: CreateUpdateCartRequest): Promise<never>;
107
109
  /**
108
110
  * This method creates a subscription cart for the given parameters.
109
- * @param request the request object containing the parameters for the availability check
110
111
  * @returns The created cart
111
112
  */
112
113
  createSubscriptionCart(request: CreateSubscriptionCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | SubscriptionCart>;
@@ -197,7 +197,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
197
197
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
198
198
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
199
199
  _this.resetBooking();
200
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
200
+ return response;
201
201
  })];
202
202
  });
203
203
  });
@@ -212,9 +212,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
212
212
  return __generator(this, function (_a) {
213
213
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/departures?");
214
214
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
215
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
216
- ? response
217
- : response.departures;
215
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.departures;
218
216
  })];
219
217
  });
220
218
  });
@@ -231,9 +229,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
231
229
  searchParams = new URLSearchParams({ departureStopName: departureStopName });
232
230
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/destinations?").concat(searchParams);
233
231
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
234
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
235
- ? response
236
- : response.destinations;
232
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.destinations;
237
233
  })];
238
234
  });
239
235
  });
@@ -318,9 +314,15 @@ var SubscriptionBooking = /** @class */ (function (_super) {
318
314
  });
319
315
  });
320
316
  };
317
+ SubscriptionBooking.prototype.createCart = function (request) {
318
+ return __awaiter(this, void 0, void 0, function () {
319
+ return __generator(this, function (_a) {
320
+ throw new Error("Method not available for this booking type. Use createSubscriptionCart instead.");
321
+ });
322
+ });
323
+ };
321
324
  /**
322
325
  * This method creates a subscription cart for the given parameters.
323
- * @param request the request object containing the parameters for the availability check
324
326
  * @returns The created cart
325
327
  */
326
328
  SubscriptionBooking.prototype.createSubscriptionCart = function (request, options) {
@@ -393,9 +395,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
393
395
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
394
396
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
395
397
  // Check for errors
396
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
398
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
397
399
  return response;
398
- }
399
400
  // For each passenger, parse the outbound and return tariffs
400
401
  var passengers = response.passengers;
401
402
  passengers.map(function (passenger) {
@@ -455,9 +456,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
455
456
  });
456
457
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
457
458
  return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
458
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
459
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
459
460
  return response;
460
- }
461
461
  // Update the booking process status
462
462
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
463
463
  return true;
@@ -511,9 +511,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
511
511
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
512
512
  return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
513
513
  var _a, _b;
514
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
514
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
515
515
  return response;
516
- }
517
516
  var reductionResponse = response;
518
517
  // Update the booking process status
519
518
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -551,9 +550,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
551
550
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
552
551
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
553
552
  var _a, _b, _c;
554
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
553
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
555
554
  return response;
556
- }
557
555
  var reductionResponse = response;
558
556
  // Update the booking process status
559
557
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -618,9 +616,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
618
616
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
619
617
  return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
620
618
  var _a, _b;
621
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
619
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
622
620
  return response;
623
- }
624
621
  var reductionResponse = response;
625
622
  // Update the booking process status
626
623
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -652,9 +649,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
652
649
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
653
650
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
654
651
  var _a, _b, _c;
655
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
652
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
656
653
  return response;
657
- }
658
654
  var reductionResponse = response;
659
655
  // Update the booking process status
660
656
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -712,9 +708,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
712
708
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
713
709
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
714
710
  var _a, _b;
715
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
711
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
716
712
  return response;
717
- }
718
713
  var reductionResponse = response;
719
714
  // Update the booking process status
720
715
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { City } from "../types/common/City";
3
4
  import { PersonDetails, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
4
5
  import { AddReductionRequest } from "../types/common/Reduction";
@@ -103,8 +104,11 @@ export declare class TplBooking extends Booking {
103
104
  */
104
105
  getTariffs(superAreaId: number, termsTypeId: number | null, onlyTickets: boolean, onlySubscriptions: boolean, options?: ApiCallOptions): Promise<ErrorResponse | GetTariffsResponse>;
105
106
  /**
106
- * This method allows to create a TPL cart.
107
+ * This method creates a tpl cart for the given parameters.
108
+ * @returns The created cart
107
109
  */
110
+ createCart(request: CreateUpdateCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | TplCart>;
111
+ /** @deprecated Use {@link createCart} instead. */
108
112
  createTplCart(tplCart: CreateTplCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | TplCart>;
109
113
  /**
110
114
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -198,7 +198,7 @@ var TplBooking = /** @class */ (function (_super) {
198
198
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
199
199
  // Clear all data
200
200
  _this.resetBooking();
201
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
201
+ return response;
202
202
  })];
203
203
  });
204
204
  });
@@ -214,9 +214,7 @@ var TplBooking = /** @class */ (function (_super) {
214
214
  return __generator(this, function (_a) {
215
215
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
216
216
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
217
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
218
- ? response
219
- : response.cities;
217
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
220
218
  })];
221
219
  });
222
220
  });
@@ -233,9 +231,7 @@ var TplBooking = /** @class */ (function (_super) {
233
231
  searchParams = new URLSearchParams(__assign(__assign({ includeBasicInfo: "true", includeAreaIds: "false", includeTariffIds: "false", includeRouteIds: "false" }, (request.cityId && { cityId: request.cityId.toString() })), (request.tripId && { tripId: request.tripId.toString() })));
234
232
  url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
235
233
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
236
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
237
- ? response
238
- : response.superAreas;
234
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.superAreas;
239
235
  })];
240
236
  });
241
237
  });
@@ -267,9 +263,7 @@ var TplBooking = /** @class */ (function (_super) {
267
263
  searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
268
264
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffTypesBySuperArea?").concat(searchParams);
269
265
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
270
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
271
- ? response
272
- : response.tariffTypes;
266
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.tariffTypes;
273
267
  })];
274
268
  });
275
269
  });
@@ -292,9 +286,8 @@ var TplBooking = /** @class */ (function (_super) {
292
286
  // Call the API
293
287
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
294
288
  // Check for error
295
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
289
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
296
290
  return response;
297
- }
298
291
  // Convert the dictionary in the response and return the the correct object
299
292
  var tariffPlanToTariffs = new Map(Object.entries(response.tariffPlanToTariffs).map(function (_a) {
300
293
  var tariffPlanId = _a[0], tariffs = _a[1];
@@ -312,8 +305,44 @@ var TplBooking = /** @class */ (function (_super) {
312
305
  });
313
306
  };
314
307
  /**
315
- * This method allows to create a TPL cart.
308
+ * This method creates a tpl cart for the given parameters.
309
+ * @returns The created cart
316
310
  */
311
+ TplBooking.prototype.createCart = function (request, options) {
312
+ return __awaiter(this, void 0, void 0, function () {
313
+ var url;
314
+ var _this = this;
315
+ return __generator(this, function (_a) {
316
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts");
317
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
318
+ return __generator(this, function (_a) {
319
+ switch (_a.label) {
320
+ case 0:
321
+ // Check for errors
322
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
323
+ // If there was an error, reset cartGuid and remove it from the mts-storage
324
+ this.resetBooking();
325
+ return [2 /*return*/, response];
326
+ }
327
+ // Fetch the newly created cart & update local properties
328
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
329
+ case 1:
330
+ // Fetch the newly created cart & update local properties
331
+ _a.sent();
332
+ if (!this.cart) {
333
+ // Should already be handled, but just in case
334
+ throw new Error("Could not fetch cart");
335
+ }
336
+ // Update storage
337
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
338
+ return [2 /*return*/, this.cart];
339
+ }
340
+ });
341
+ }); })];
342
+ });
343
+ });
344
+ };
345
+ /** @deprecated Use {@link createCart} instead. */
317
346
  TplBooking.prototype.createTplCart = function (tplCart, options) {
318
347
  return __awaiter(this, void 0, void 0, function () {
319
348
  var url, processedTariffIdToQuantity, request;
@@ -393,9 +422,8 @@ var TplBooking = /** @class */ (function (_super) {
393
422
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
394
423
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
395
424
  // Check for errors
396
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
425
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
397
426
  return response;
398
- }
399
427
  return {
400
428
  buyerDataStatus: response.buyerDataStatus,
401
429
  buyer: response.buyer,
@@ -443,9 +471,8 @@ var TplBooking = /** @class */ (function (_super) {
443
471
  };
444
472
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
445
473
  return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
446
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
474
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
447
475
  return response;
448
- }
449
476
  // Update the booking process status
450
477
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
451
478
  return true;
@@ -500,9 +527,8 @@ var TplBooking = /** @class */ (function (_super) {
500
527
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
501
528
  return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
502
529
  var _a, _b;
503
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
530
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
504
531
  return response;
505
- }
506
532
  var reductionResponse = response;
507
533
  // Update the booking process status
508
534
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -540,9 +566,8 @@ var TplBooking = /** @class */ (function (_super) {
540
566
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
541
567
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
542
568
  var _a, _b, _c;
543
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
569
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
544
570
  return response;
545
- }
546
571
  var reductionResponse = response;
547
572
  // Update the booking process status
548
573
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -607,9 +632,8 @@ var TplBooking = /** @class */ (function (_super) {
607
632
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
608
633
  return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
609
634
  var _a, _b;
610
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
635
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
611
636
  return response;
612
- }
613
637
  var reductionResponse = response;
614
638
  // Update the booking process status
615
639
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -641,9 +665,8 @@ var TplBooking = /** @class */ (function (_super) {
641
665
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
642
666
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
643
667
  var _a, _b, _c;
644
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
668
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
645
669
  return response;
646
- }
647
670
  var reductionResponse = response;
648
671
  // Update the booking process status
649
672
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -701,9 +724,8 @@ var TplBooking = /** @class */ (function (_super) {
701
724
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
702
725
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
703
726
  var _a, _b;
704
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
727
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
705
728
  return response;
706
- }
707
729
  var reductionResponse = response;
708
730
  // Update the booking process status
709
731
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
package/lib/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
5
  export { TplBooking } from "./booking/tplBooking";
6
6
  export { useMtsBookingState } from "./mtsStorage";
7
+ export { CreateUpdateCartRequest, CartBooking } from "./types/common/Cart";
7
8
  export { Person, PersonDetails, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
8
9
  export { GetBuyerPassengersDetailsResponse, GetPersonRequest, GetPassenger, BuyerDataStatus, EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
9
10
  export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType, PassengerTariff, ExtraTariff } from "./types/common/Tariffs";
package/lib/index.js CHANGED
@@ -16,9 +16,6 @@ Object.defineProperty(exports, "TplBooking", { enumerable: true, get: function (
16
16
  //#region Export Zustand states
17
17
  var mtsStorage_1 = require("./mtsStorage");
18
18
  Object.defineProperty(exports, "useMtsBookingState", { enumerable: true, get: function () { return mtsStorage_1.useMtsBookingState; } });
19
- //#endregion
20
- //#region Export common types
21
- // @note: Cart is not exported because it is extended by other types
22
19
  var Person_1 = require("./types/common/Person");
23
20
  Object.defineProperty(exports, "DEFAULT_PERSON", { enumerable: true, get: function () { return Person_1.DEFAULT_PERSON; } });
24
21
  Object.defineProperty(exports, "initializePerson", { enumerable: true, get: function () { return Person_1.initializePerson; } });
@@ -1,13 +1,14 @@
1
1
  /**
2
- * @description Error response type as returned by the BackEnd
3
- *
4
- * @property {number} httpStatus - The http status code of the error (e.g. 400)
5
- * @property {number} mtsCode - The error code returned by the MTS Backend (e.g. 4001)
6
- * @property {string} message - The message of the error (e.g. "Invalid parameters")
2
+ * Error response type as returned by the BackEnd
7
3
  */
8
4
  export type ErrorResponse = {
5
+ /** The http status code of the error (e.g. 400) */
9
6
  httpStatus: number;
7
+ /** The error code returned by the MTS Backend (e.g. 4001) */
10
8
  mtsCode: number;
9
+ /** The message of the error (e.g. "Invalid parameters") */
11
10
  message: string;
11
+ /** Whether this is a 403 error generate by Azure, and should be treated like a maintenance error (so, like a 503) */
12
+ isAzureMaintenance?: boolean;
12
13
  };
13
14
  export declare const objectIsMTSErrorResponse: (error: any) => error is ErrorResponse;
@@ -7,6 +7,37 @@ export declare enum SellingMethod {
7
7
  RESELLER = "RESELLER",
8
8
  MTSAPP = "MTSAPP"
9
9
  }
10
+ export type CreateUpdateCartRequest = {
11
+ /** The unique identifier for the cart.
12
+ * This should be passed during the change process to link the new ticket to the already existing change cart */
13
+ cartGuid?: string;
14
+ /** The currency of the cart. See {@link Booking.Currencies} */
15
+ currency: Booking.Currencies;
16
+ /** The booking to be added to the cart. */
17
+ cartBooking: CartBooking;
18
+ /** The return booking to be added to the cart (e.g. for MLP). */
19
+ returnCartBooking?: CartBooking;
20
+ };
21
+ export type CartBooking = {
22
+ /** A record containing tariff ids as keys and their respective quantities as values. */
23
+ tariffIdToQuantity?: Record<number, number>;
24
+ /** The date of the booking in ISO string format (optional). */
25
+ date?: string;
26
+ /** The id of the trip, if necessary. For example, this is used by services that require a specific trip to be selected, or by MLP booking */
27
+ tripId?: number;
28
+ /** The id of the line, if necessary. For example, this is used by Services */
29
+ lineId?: number;
30
+ /** The start date of the booking, if necessary. For example, this is used by TPL subscriptions. */
31
+ startDate?: string;
32
+ /** If true, then the booking will be the current period (e.g. this month or this year), otherwise it will be the next period. */
33
+ isCurrentPeriod?: boolean;
34
+ /** The PNR of the ticket of reference, if necessary. For example, this is used in TPL when renewing a subscription. */
35
+ pnr?: string;
36
+ /** The id of the OTA Reseller that sold the ticket */
37
+ otaResellerId?: number;
38
+ /** A string in base64 representing the picture of the ticket that was sold */
39
+ otaTicketPicture?: string;
40
+ };
10
41
  /**
11
42
  * @description Cart is the object returned by the API when a cart is created.
12
43
  * Note that depending on the type of booking, this type will be extended with different fields:
@@ -1,6 +1,6 @@
1
1
  import { Tariff } from "../common/Tariffs";
2
2
  /**
3
- * This represents the response of the API {@link TplBooking.getTariffs}.
3
+ * This represents the response of the API {@link TplBooking.getTariffs()}.
4
4
  * @param {Tariff[]} tariffs - The list of available tariffs. This is meant to be a fast access for displaying the data.
5
5
  * In particular, this array is equivalent to `tariffPlanToTariffs[0]`
6
6
  * @param {Map<number, Tariff[]>} tariffPlanToTariffs - A map that associates a tariff plan to the list of tariffs available for that tariff plan.
@@ -6,12 +6,11 @@
6
6
  * @method makeDelete - Makes a DELETE request to the MTS API
7
7
  */
8
8
  import { GenericAbortSignal } from "axios";
9
- import { ErrorResponse } from "../types/ErrorResponse";
10
9
  export interface ApiCallOptions {
11
10
  /** An abort signal to be passed to Axios, in case you want to cancel the request */
12
11
  signal?: GenericAbortSignal;
13
12
  }
14
- export declare const makeGet: (url: string, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
15
- export declare const makePost: (url: string, data: any, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
16
- export declare const makePut: (url: string, data: any, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
17
- export declare const makeDelete: (url: string, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
13
+ export declare const makeGet: (url: string, options?: ApiCallOptions) => Promise<any>;
14
+ export declare const makePost: (url: string, data: any, options?: ApiCallOptions) => Promise<any>;
15
+ export declare const makePut: (url: string, data: any, options?: ApiCallOptions) => Promise<any>;
16
+ export declare const makeDelete: (url: string, options?: ApiCallOptions) => Promise<any>;