mts-booking-library 1.2.18 → 1.2.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -153,7 +153,7 @@ var JourneyBooking = /** @class */ (function (_super) {
153
153
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
154
154
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
155
155
  localStorage.removeItem("cartId");
156
- throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
156
+ throw new Error(response);
157
157
  }
158
158
  return response.cart;
159
159
  })];
@@ -233,15 +233,7 @@ var JourneyBooking = /** @class */ (function (_super) {
233
233
  if (request.departureStopName === undefined || request.destinationStopName === undefined) {
234
234
  throw Error("Fields departureStopName and destinationStopName are required");
235
235
  }
236
- searchParams = new URLSearchParams({
237
- departureStopName: request.departureStopName,
238
- destinationStopName: request.destinationStopName,
239
- passengersNumber: request.passengersNumber.toString(),
240
- date: request.date,
241
- roundTripDate: request.roundTripDate ? request.roundTripDate : "null",
242
- currency: request.currency,
243
- isRoundtrip: request.isRoundtrip.toString()
244
- });
236
+ searchParams = new URLSearchParams(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), date: request.date, roundTripDate: request.roundTripDate ? request.roundTripDate : "null", currency: request.currency, isRoundtrip: request.isRoundtrip.toString() }, (this.cartId && { cartId: this.cartId.toString() })));
245
237
  url = "".concat(this.config.API_ENDPOINT, "/booking/journeys?").concat(searchParams);
246
238
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
247
239
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.journeys;
@@ -251,11 +243,12 @@ var JourneyBooking = /** @class */ (function (_super) {
251
243
  };
252
244
  JourneyBooking.prototype.createJourneyCart = function (journeyCart) {
253
245
  return __awaiter(this, void 0, void 0, function () {
254
- var url;
246
+ var url, request;
255
247
  var _this = this;
256
248
  return __generator(this, function (_a) {
257
249
  url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/cart");
258
- return [2 /*return*/, this.callPostApi(url, journeyCart).then(function (response) {
250
+ request = __assign(__assign({}, journeyCart), (this.cartId && { cartId: this.cartId.toString() }));
251
+ return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
259
252
  // Check for errors
260
253
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
261
254
  return response;
@@ -786,18 +779,27 @@ exports.JourneyBooking = JourneyBooking;
786
779
  return __generator(this, function (_a) {
787
780
  switch (_a.label) {
788
781
  case 0:
789
- _a.trys.push([0, 3, , 4]);
790
782
  booking = new JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
791
- if (!booking.cartId) return [3 /*break*/, 2];
792
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
783
+ _a.label = 1;
793
784
  case 1:
785
+ _a.trys.push([1, 4, , 5]);
786
+ if (!booking.cartId) return [3 /*break*/, 3];
787
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
788
+ case 2:
794
789
  _a.sent();
795
- _a.label = 2;
796
- case 2: return [2 /*return*/, booking];
797
- case 3:
790
+ _a.label = 3;
791
+ case 3: return [2 /*return*/, booking];
792
+ case 4:
798
793
  error_1 = _a.sent();
794
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
795
+ // This error can occur when the user refreshes the page and the cart has expired
796
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
797
+ localStorage.removeItem("cartId");
798
+ booking.cartId = undefined;
799
+ return [2 /*return*/, booking];
800
+ }
799
801
  throw new Error("Could not instantiate JourneyBooking");
800
- case 4: return [2 /*return*/];
802
+ case 5: return [2 /*return*/];
801
803
  }
802
804
  });
803
805
  }); };
@@ -152,7 +152,7 @@ var ServiceBooking = /** @class */ (function (_super) {
152
152
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
153
153
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
154
154
  localStorage.removeItem("cartId");
155
- throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
155
+ throw new Error(response);
156
156
  }
157
157
  return response.cart;
158
158
  })];
@@ -649,18 +649,27 @@ exports.ServiceBooking = ServiceBooking;
649
649
  return __generator(this, function (_a) {
650
650
  switch (_a.label) {
651
651
  case 0:
652
- _a.trys.push([0, 3, , 4]);
653
652
  booking = new ServiceBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
654
- if (!booking.cartId) return [3 /*break*/, 2];
655
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
653
+ _a.label = 1;
656
654
  case 1:
655
+ _a.trys.push([1, 4, , 5]);
656
+ if (!booking.cartId) return [3 /*break*/, 3];
657
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
658
+ case 2:
657
659
  _a.sent();
658
- _a.label = 2;
659
- case 2: return [2 /*return*/, booking];
660
- case 3:
660
+ _a.label = 3;
661
+ case 3: return [2 /*return*/, booking];
662
+ case 4:
661
663
  error_1 = _a.sent();
662
- throw new Error("Could not instantiate ServiceBooking");
663
- case 4: return [2 /*return*/];
664
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
665
+ // This error can occur when the user refreshes the page and the cart has expired
666
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
667
+ localStorage.removeItem("cartId");
668
+ booking.cartId = undefined;
669
+ return [2 /*return*/, booking];
670
+ }
671
+ throw new Error("Could not instantiate JourneyBooking");
672
+ case 5: return [2 /*return*/];
664
673
  }
665
674
  });
666
675
  }); };
@@ -159,7 +159,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
159
159
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
160
160
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
161
161
  localStorage.removeItem("cartId");
162
- throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
162
+ throw new Error(response);
163
163
  }
164
164
  return response.cart;
165
165
  })];
@@ -733,18 +733,27 @@ exports.SubscriptionBooking = SubscriptionBooking;
733
733
  return __generator(this, function (_a) {
734
734
  switch (_a.label) {
735
735
  case 0:
736
- _a.trys.push([0, 3, , 4]);
737
736
  booking = new SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
738
- if (!booking.cartId) return [3 /*break*/, 2];
739
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
737
+ _a.label = 1;
740
738
  case 1:
739
+ _a.trys.push([1, 4, , 5]);
740
+ if (!booking.cartId) return [3 /*break*/, 3];
741
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
742
+ case 2:
741
743
  _a.sent();
742
- _a.label = 2;
743
- case 2: return [2 /*return*/, booking];
744
- case 3:
744
+ _a.label = 3;
745
+ case 3: return [2 /*return*/, booking];
746
+ case 4:
745
747
  error_1 = _a.sent();
746
- throw new Error("Could not instantiate SubscriptionBooking");
747
- case 4: return [2 /*return*/];
748
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
749
+ // This error can occur when the user refreshes the page and the cart has expired
750
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
751
+ localStorage.removeItem("cartId");
752
+ booking.cartId = undefined;
753
+ return [2 /*return*/, booking];
754
+ }
755
+ throw new Error("Could not instantiate JourneyBooking");
756
+ case 5: return [2 /*return*/];
748
757
  }
749
758
  });
750
759
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "build": "tsc",
9
9
  "test": "jest --config jestconfig.json",
10
10
  "prepare": "npm run build",
11
- "prepublishOnly": "npm run test",
11
+ "prepublishOnly": "npm run test --runInBand",
12
12
  "version": "git add -A src",
13
13
  "postversion": "git push && git push --tags"
14
14
  },