mts-booking-library 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,7 +51,6 @@ export declare abstract class Booking {
51
51
  getBookingStepsToStatus(): Map<string, boolean[]>;
52
52
  changeCurrency(currency: Booking.Currencies): void;
53
53
  changeLanguage(language: string): void;
54
- getCartExpirationTimeInMs(): Promise<number>;
55
54
  /**
56
55
  * This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
57
56
  * @param bookingStep The booking step to mark as completed
@@ -104,22 +104,33 @@ var Booking = /** @class */ (function () {
104
104
  (0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, this.config.DEBUG, access_token);
105
105
  };
106
106
  Booking.prototype.callGetApi = function (url) {
107
+ var _a, _b, _c, _d;
107
108
  // Add sellerId, resellerId and language to the query string.
108
109
  // If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
109
110
  // Otherwise, add it (as we are adding some parameters to the query string)
110
- var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(__assign(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language })));
111
+ var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams({
112
+ sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0",
113
+ resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0",
114
+ language: this.language
115
+ }));
111
116
  return (0, apiCall_1.makeGet)(completeUrl);
112
117
  };
113
118
  Booking.prototype.callPostApi = function (url, body) {
119
+ var _a, _b, _c, _d;
114
120
  // Add sellerId, resellerId and language to the query string
115
- var completeBody = __assign(__assign(__assign(__assign({}, body), (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language });
121
+ var completeBody = __assign(__assign({}, body), { sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 0, resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : 0, language: this.language });
116
122
  return (0, apiCall_1.makePost)(url, completeBody);
117
123
  };
118
124
  Booking.prototype.callDeleteApi = function (url) {
125
+ var _a, _b, _c, _d;
119
126
  // Add sellerId, resellerId and language to the query string.
120
127
  // If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
121
128
  // Otherwise, add it (as we are adding some parameters to the query string)
122
- var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(__assign(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language })));
129
+ var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams({
130
+ sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0",
131
+ resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0",
132
+ language: this.language
133
+ }));
123
134
  return (0, apiCall_1.makeDelete)(completeUrl);
124
135
  };
125
136
  Booking.prototype.getBookingStepsToStatus = function () {
@@ -138,19 +149,6 @@ var Booking = /** @class */ (function () {
138
149
  this.language = Booking.Languages.EN;
139
150
  }
140
151
  };
141
- Booking.prototype.getCartExpirationTimeInMs = function () {
142
- return __awaiter(this, void 0, void 0, function () {
143
- return __generator(this, function (_a) {
144
- // If cart is initialized, return the time in ms until the cart expires.
145
- // Note that bookingDueDate is initialized only when the cart is created.
146
- if (this.bookingDueDate) {
147
- return [2 /*return*/, (new Date(this.bookingDueDate).valueOf() - new Date().valueOf())];
148
- }
149
- // Cart is not initialized
150
- throw Error("Cart is not initialized yet");
151
- });
152
- });
153
- };
154
152
  /**
155
153
  * This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
156
154
  * @param bookingStep The booking step to mark as completed
@@ -176,7 +174,7 @@ var Booking = /** @class */ (function () {
176
174
  // Booking step is already completed, no need to call the API
177
175
  if (currentStepStatus[0])
178
176
  return [2 /*return*/, true];
179
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/bookingSteps");
177
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/bookingSteps");
180
178
  return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
181
179
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
182
180
  return response;
@@ -259,7 +257,7 @@ var Booking = /** @class */ (function () {
259
257
  throw Error("The status of the cart does not allow to call this API");
260
258
  }
261
259
  searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString() }, (returnUrl && { returnUrl: returnUrl })));
262
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment?").concat(searchParams);
260
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment?").concat(searchParams);
263
261
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
264
262
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
265
263
  })];
@@ -324,7 +322,7 @@ var Booking = /** @class */ (function () {
324
322
  }
325
323
  _c.label = 7;
326
324
  case 7:
327
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/issue");
325
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/issue");
328
326
  body = {
329
327
  cartId: this.cartId,
330
328
  paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
@@ -161,7 +161,7 @@ var JourneyBooking = /** @class */ (function (_super) {
161
161
  var url;
162
162
  var _this = this;
163
163
  return __generator(this, function (_a) {
164
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
164
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
165
165
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
166
166
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
167
167
  _this.resetBooking();
@@ -258,7 +258,7 @@ var JourneyBooking = /** @class */ (function (_super) {
258
258
  var url, request;
259
259
  var _this = this;
260
260
  return __generator(this, function (_a) {
261
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/cart");
261
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/carts");
262
262
  request = __assign(__assign({}, journeyCart), (this.cartId && { cartId: this.cartId.toString() }));
263
263
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
264
264
  // Check for errors
@@ -298,7 +298,7 @@ var JourneyBooking = /** @class */ (function (_super) {
298
298
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
299
299
  throw Error("The status of the cart does not allow to call this API");
300
300
  }
301
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
301
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
302
302
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
303
303
  // Check for errors
304
304
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -394,7 +394,7 @@ var JourneyBooking = /** @class */ (function (_super) {
394
394
  });
395
395
  request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
396
396
  });
397
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
397
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
398
398
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
399
399
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
400
400
  return response;
@@ -455,7 +455,7 @@ var JourneyBooking = /** @class */ (function (_super) {
455
455
  throw Error("The status of the cart does not allow to call this API");
456
456
  }
457
457
  searchParams = new URLSearchParams({ tripId: tripId.toString() });
458
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/seats?").concat(searchParams);
458
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats?").concat(searchParams);
459
459
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
460
460
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
461
461
  })];
@@ -481,7 +481,7 @@ var JourneyBooking = /** @class */ (function (_super) {
481
481
  if (!seatSelectionStatus || !seatSelectionStatus[0]) {
482
482
  throw Error("The status of the cart does not allow to call this API");
483
483
  }
484
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/seats");
484
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats");
485
485
  return [2 /*return*/, this.callPostApi(url, { tripId: tripId, newSeatsIds: newSeatsIds }).then(function (response) {
486
486
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
487
487
  return response;
@@ -508,7 +508,7 @@ var JourneyBooking = /** @class */ (function (_super) {
508
508
  if (!this.cart) {
509
509
  throw Error("Cart is not initialized yet");
510
510
  }
511
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/payment/reduction/trips?");
511
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/payment/reduction/trips?");
512
512
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
513
513
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
514
514
  })];
@@ -557,7 +557,7 @@ var JourneyBooking = /** @class */ (function (_super) {
557
557
  }
558
558
  _c.label = 5;
559
559
  case 5:
560
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
560
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
561
561
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
562
562
  var _a, _b;
563
563
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -594,7 +594,7 @@ var JourneyBooking = /** @class */ (function (_super) {
594
594
  throw Error("The status of the cart does not allow to call this API");
595
595
  }
596
596
  queryParams = new URLSearchParams({ tripId: tripId.toString() });
597
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
597
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
598
598
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
599
599
  var _a, _b, _c;
600
600
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -651,11 +651,11 @@ var JourneyBooking = /** @class */ (function (_super) {
651
651
  // Check again if the discounts step is accessible
652
652
  issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
653
653
  if (!issueStep || !issueStep[0]) {
654
- throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
654
+ throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
655
655
  }
656
656
  _c.label = 5;
657
657
  case 5:
658
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
658
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
659
659
  return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
660
660
  var _a, _b;
661
661
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -686,7 +686,7 @@ var JourneyBooking = /** @class */ (function (_super) {
686
686
  if (!this.cartId || this.cartId === 0) {
687
687
  throw Error("Cart is not initialized yet");
688
688
  }
689
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
689
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
690
690
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
691
691
  var _a, _b, _c;
692
692
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -746,7 +746,7 @@ var JourneyBooking = /** @class */ (function (_super) {
746
746
  }
747
747
  _c.label = 5;
748
748
  case 5:
749
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
749
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
750
750
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
751
751
  var _a, _b;
752
752
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -2,7 +2,7 @@ import { MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
3
  import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
4
  import { AddReductionRequest } from "../types/common/Reduction";
5
- import { Service, ServiceTrip } from "../types/services/Service";
5
+ import { Service, ServiceTripsResponse } from "../types/services/Service";
6
6
  import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
7
7
  import { Booking } from "./booking";
8
8
  export declare class ServiceBooking extends Booking {
@@ -93,10 +93,10 @@ export declare class ServiceBooking extends Booking {
93
93
  * and/or a specific hour for the tour.
94
94
  * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
95
95
  * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
96
- * @param {Date} date The date on which to get the tours
97
- * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
96
+ * @param {string} date The date on which to get the tours, in ISO string format
97
+ * @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
98
98
  */
99
- getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
99
+ getServiceTrips(serviceId: number, date: string): Promise<ErrorResponse | ServiceTripsResponse>;
100
100
  createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
101
101
  /**
102
102
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -161,7 +161,7 @@ var ServiceBooking = /** @class */ (function (_super) {
161
161
  var url;
162
162
  var _this = this;
163
163
  return __generator(this, function (_a) {
164
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
164
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
165
165
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
166
166
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
167
167
  _this.resetBooking();
@@ -239,17 +239,17 @@ var ServiceBooking = /** @class */ (function (_super) {
239
239
  * and/or a specific hour for the tour.
240
240
  * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
241
241
  * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
242
- * @param {Date} date The date on which to get the tours
243
- * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
242
+ * @param {string} date The date on which to get the tours, in ISO string format
243
+ * @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
244
244
  */
245
245
  ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
246
246
  return __awaiter(this, void 0, void 0, function () {
247
247
  var searchParams, url;
248
248
  return __generator(this, function (_a) {
249
- searchParams = new URLSearchParams({ date: date.toDateString() });
249
+ searchParams = new URLSearchParams({ date: date });
250
250
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/").concat(serviceId, "/trips?").concat(searchParams);
251
251
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
252
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
252
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
253
253
  })];
254
254
  });
255
255
  });
@@ -259,7 +259,7 @@ var ServiceBooking = /** @class */ (function (_super) {
259
259
  var url;
260
260
  var _this = this;
261
261
  return __generator(this, function (_a) {
262
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cart");
262
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/carts");
263
263
  return [2 /*return*/, this.callPostApi(url, serviceCart).then(function (response) {
264
264
  // Check for errors
265
265
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -300,7 +300,7 @@ var ServiceBooking = /** @class */ (function (_super) {
300
300
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
301
301
  throw Error("The status of the cart does not allow to call this API");
302
302
  }
303
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
303
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
304
304
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
305
305
  // Check for errors
306
306
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -373,7 +373,7 @@ var ServiceBooking = /** @class */ (function (_super) {
373
373
  buyer: buyerDetails,
374
374
  passengers: [],
375
375
  };
376
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
376
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
377
377
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
378
378
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
379
379
  return response;
@@ -429,7 +429,7 @@ var ServiceBooking = /** @class */ (function (_super) {
429
429
  }
430
430
  _c.label = 5;
431
431
  case 5:
432
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
432
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
433
433
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
434
434
  var _a, _b;
435
435
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -466,7 +466,7 @@ var ServiceBooking = /** @class */ (function (_super) {
466
466
  throw Error("The status of the cart does not allow to call this API");
467
467
  }
468
468
  queryParams = new URLSearchParams({ tripId: tripId.toString() });
469
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
469
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
470
470
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
471
471
  var _a, _b, _c;
472
472
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -523,11 +523,11 @@ var ServiceBooking = /** @class */ (function (_super) {
523
523
  // Check again if the discounts step is accessible
524
524
  issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
525
525
  if (!issueStep || !issueStep[0]) {
526
- throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
526
+ throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
527
527
  }
528
528
  _c.label = 5;
529
529
  case 5:
530
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
530
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
531
531
  return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
532
532
  var _a, _b;
533
533
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -558,7 +558,7 @@ var ServiceBooking = /** @class */ (function (_super) {
558
558
  if (!this.cartId || this.cartId === 0) {
559
559
  throw Error("Cart is not initialized yet");
560
560
  }
561
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
561
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
562
562
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
563
563
  var _a, _b, _c;
564
564
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -618,7 +618,7 @@ var ServiceBooking = /** @class */ (function (_super) {
618
618
  }
619
619
  _c.label = 5;
620
620
  case 5:
621
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
621
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
622
622
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
623
623
  var _a, _b;
624
624
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -161,7 +161,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
161
161
  var url;
162
162
  var _this = this;
163
163
  return __generator(this, function (_a) {
164
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
164
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
165
165
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
166
166
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
167
167
  _this.resetBooking();
@@ -314,7 +314,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
314
314
  var url;
315
315
  var _this = this;
316
316
  return __generator(this, function (_a) {
317
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/cart");
317
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/carts");
318
318
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
319
319
  // Check for errors
320
320
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -353,7 +353,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
353
353
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
354
354
  throw Error("The status of the cart does not allow to call this API");
355
355
  }
356
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
356
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
357
357
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
358
358
  // Check for errors
359
359
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -449,7 +449,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
449
449
  });
450
450
  request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
451
451
  });
452
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
452
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
453
453
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
454
454
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
455
455
  return response;
@@ -504,7 +504,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
504
504
  }
505
505
  _c.label = 5;
506
506
  case 5:
507
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
507
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
508
508
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
509
509
  var _a, _b;
510
510
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -541,7 +541,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
541
541
  throw Error("The status of the cart does not allow to call this API");
542
542
  }
543
543
  queryParams = new URLSearchParams({ tripId: tripId.toString() });
544
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
544
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
545
545
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
546
546
  var _a, _b, _c;
547
547
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -598,11 +598,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
598
598
  // Check again if the discounts step is accessible
599
599
  issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
600
600
  if (!issueStep || !issueStep[0]) {
601
- throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
601
+ throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
602
602
  }
603
603
  _c.label = 5;
604
604
  case 5:
605
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
605
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
606
606
  return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
607
607
  var _a, _b;
608
608
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -633,7 +633,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
633
633
  if (!this.cartId || this.cartId === 0) {
634
634
  throw Error("Cart is not initialized yet");
635
635
  }
636
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
636
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
637
637
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
638
638
  var _a, _b, _c;
639
639
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -693,7 +693,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
693
693
  }
694
694
  _c.label = 5;
695
695
  case 5:
696
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
696
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
697
697
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
698
698
  var _a, _b;
699
699
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -161,7 +161,7 @@ var TplBooking = /** @class */ (function (_super) {
161
161
  var url;
162
162
  var _this = this;
163
163
  return __generator(this, function (_a) {
164
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
164
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
165
165
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
166
166
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
167
167
  _this.resetBooking();
@@ -287,7 +287,7 @@ var TplBooking = /** @class */ (function (_super) {
287
287
  var url, processedTariffIdToQuantity, request;
288
288
  var _this = this;
289
289
  return __generator(this, function (_a) {
290
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cart");
290
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/carts");
291
291
  processedTariffIdToQuantity = {};
292
292
  tariffIdToQuantity.forEach(function (value, key) {
293
293
  processedTariffIdToQuantity[key] = value;
@@ -333,7 +333,7 @@ var TplBooking = /** @class */ (function (_super) {
333
333
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
334
334
  throw Error("The status of the cart does not allow to call this API");
335
335
  }
336
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
336
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
337
337
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
338
338
  // Check for errors
339
339
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -406,7 +406,7 @@ var TplBooking = /** @class */ (function (_super) {
406
406
  buyer: buyerDetails,
407
407
  passengers: [],
408
408
  };
409
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
409
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
410
410
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
411
411
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
412
412
  return response;
@@ -462,7 +462,7 @@ var TplBooking = /** @class */ (function (_super) {
462
462
  }
463
463
  _c.label = 5;
464
464
  case 5:
465
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
465
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
466
466
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
467
467
  var _a, _b;
468
468
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -499,7 +499,7 @@ var TplBooking = /** @class */ (function (_super) {
499
499
  throw Error("The status of the cart does not allow to call this API");
500
500
  }
501
501
  queryParams = new URLSearchParams({ tripId: tripId.toString() });
502
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
502
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
503
503
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
504
504
  var _a, _b, _c;
505
505
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -556,11 +556,11 @@ var TplBooking = /** @class */ (function (_super) {
556
556
  // Check again if the discounts step is accessible
557
557
  issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
558
558
  if (!issueStep || !issueStep[0]) {
559
- throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
559
+ throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
560
560
  }
561
561
  _c.label = 5;
562
562
  case 5:
563
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
563
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
564
564
  return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
565
565
  var _a, _b;
566
566
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -591,7 +591,7 @@ var TplBooking = /** @class */ (function (_super) {
591
591
  if (!this.cartId || this.cartId === 0) {
592
592
  throw Error("Cart is not initialized yet");
593
593
  }
594
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
594
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
595
595
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
596
596
  var _a, _b, _c;
597
597
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -651,7 +651,7 @@ var TplBooking = /** @class */ (function (_super) {
651
651
  }
652
652
  _c.label = 5;
653
653
  case 5:
654
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
654
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
655
655
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
656
656
  var _a, _b;
657
657
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -31,3 +31,13 @@ export type ServiceTrip = {
31
31
  date: Date;
32
32
  name: string;
33
33
  };
34
+ /**
35
+ * @description Represents a response from the service trips endpoint
36
+ * @param {boolean} areThereTrips - Indicates whether there are trips available for the service.
37
+ * @param {ServiceTrip[]} trips - An array of {@link ServiceTrip} objects representing the available trips. This can be empty
38
+ * even if `areThereTrips` is true, as the user might be not allowed to select a specific trip.
39
+ */
40
+ export type ServiceTripsResponse = {
41
+ areThereTrips: boolean;
42
+ trips: ServiceTrip[];
43
+ };
@@ -9,7 +9,7 @@ import { ServiceTrip } from "./Service";
9
9
  * @property {Object} service - Information about the selected service.
10
10
  * @property {number} service.serviceId - The unique identifier for the service.
11
11
  * @property {TariffsMatrix} service.tariffsMatrix - The tariff matrix for pricing the service.
12
- * @property {Date|undefined} [service.date] - The date for the service (optional).
12
+ * @property {string|undefined} [service.date] - The date for the service in ISO string format (optional).
13
13
  * @property {number|undefined} [service.tripId] - The unique identifier for the trip (optional).
14
14
  */
15
15
  export type CreateServiceCartRequest = {
@@ -17,7 +17,7 @@ export type CreateServiceCartRequest = {
17
17
  service: {
18
18
  serviceId: number;
19
19
  tariffsMatrix: TariffsMatrix;
20
- date?: Date;
20
+ date?: string;
21
21
  tripId?: number;
22
22
  };
23
23
  };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
3
+ * @param {Date | string} date the date to convert
4
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
5
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
6
+ * @returns {string} the ISO string
7
+ */
8
+ export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
9
+ /**
10
+ * This method check where a variable is null or undefined
11
+ * @param value The value to check
12
+ * @returns True if the value is null or undefined, false otherwise
13
+ */
14
+ export declare const isNullOrUndefined: (value: any) => boolean;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNullOrUndefined = exports.getISOStringWithoutGMT = void 0;
4
+ /**
5
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
6
+ * @param {Date | string} date the date to convert
7
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
8
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
9
+ * @returns {string} the ISO string
10
+ */
11
+ var getISOStringWithoutGMT = function (date, removeTimezone) {
12
+ if (removeTimezone === void 0) { removeTimezone = true; }
13
+ if (!date)
14
+ return null;
15
+ var newDate = new Date(date);
16
+ var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
17
+ return removeTimezone ? isoString.slice(0, -1) : isoString;
18
+ };
19
+ exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
20
+ /**
21
+ * This method check where a variable is null or undefined
22
+ * @param value The value to check
23
+ * @returns True if the value is null or undefined, false otherwise
24
+ */
25
+ var isNullOrUndefined = function (value) { return value === null || value === undefined; };
26
+ exports.isNullOrUndefined = isNullOrUndefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "@types/jest": "^29.5.12",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.2",
20
- "typescript": "^5.4.2"
20
+ "typescript": "^5.4.3"
21
21
  },
22
22
  "files": [
23
23
  "lib/**/*"
@@ -30,6 +30,7 @@
30
30
  "dependencies": {
31
31
  "@react-native-async-storage/async-storage": "^1.23.1",
32
32
  "axios": "^1.6.8",
33
+ "dotenv": "^16.4.5",
33
34
  "node-localstorage": "^3.0.5",
34
35
  "zustand": "^4.5.2"
35
36
  }