mts-booking-library 1.2.19 → 1.2.21

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
  })];
@@ -341,11 +341,8 @@ var JourneyBooking = /** @class */ (function (_super) {
341
341
  if (!linkavelCardNumber && !linkavelCardPhoneNumber) {
342
342
  throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
343
343
  }
344
- searchParams = new URLSearchParams({
345
- linkavelCardNumber: linkavelCardNumber !== null && linkavelCardNumber !== void 0 ? linkavelCardNumber : "",
346
- linkavelCardPhoneNumber: linkavelCardPhoneNumber !== null && linkavelCardPhoneNumber !== void 0 ? linkavelCardPhoneNumber : "",
347
- });
348
- url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams, "}");
344
+ searchParams = new URLSearchParams(__assign(__assign({}, (linkavelCardNumber && { linkavelCardNumber: linkavelCardNumber })), (linkavelCardPhoneNumber && { linkavelCardPhoneNumber: linkavelCardPhoneNumber })));
345
+ url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams);
349
346
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
350
347
  // Check for errors
351
348
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -779,18 +776,27 @@ exports.JourneyBooking = JourneyBooking;
779
776
  return __generator(this, function (_a) {
780
777
  switch (_a.label) {
781
778
  case 0:
782
- _a.trys.push([0, 3, , 4]);
783
779
  booking = new JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
784
- if (!booking.cartId) return [3 /*break*/, 2];
785
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
780
+ _a.label = 1;
786
781
  case 1:
782
+ _a.trys.push([1, 4, , 5]);
783
+ if (!booking.cartId) return [3 /*break*/, 3];
784
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
785
+ case 2:
787
786
  _a.sent();
788
- _a.label = 2;
789
- case 2: return [2 /*return*/, booking];
790
- case 3:
787
+ _a.label = 3;
788
+ case 3: return [2 /*return*/, booking];
789
+ case 4:
791
790
  error_1 = _a.sent();
791
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
792
+ // This error can occur when the user refreshes the page and the cart has expired
793
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
794
+ localStorage.removeItem("cartId");
795
+ booking.cartId = undefined;
796
+ return [2 /*return*/, booking];
797
+ }
792
798
  throw new Error("Could not instantiate JourneyBooking");
793
- case 4: return [2 /*return*/];
799
+ case 5: return [2 /*return*/];
794
800
  }
795
801
  });
796
802
  }); };
@@ -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
  })];
@@ -322,11 +322,8 @@ var ServiceBooking = /** @class */ (function (_super) {
322
322
  if (!linkavelCardNumber && !linkavelCardPhoneNumber) {
323
323
  throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
324
324
  }
325
- searchParams = new URLSearchParams({
326
- linkavelCardNumber: linkavelCardNumber !== null && linkavelCardNumber !== void 0 ? linkavelCardNumber : "",
327
- linkavelCardPhoneNumber: linkavelCardPhoneNumber !== null && linkavelCardPhoneNumber !== void 0 ? linkavelCardPhoneNumber : "",
328
- });
329
- url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams, "}");
325
+ searchParams = new URLSearchParams(__assign(__assign({}, (linkavelCardNumber && { linkavelCardNumber: linkavelCardNumber })), (linkavelCardPhoneNumber && { linkavelCardPhoneNumber: linkavelCardPhoneNumber })));
326
+ url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams);
330
327
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
331
328
  // Check for errors
332
329
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -649,18 +646,27 @@ exports.ServiceBooking = ServiceBooking;
649
646
  return __generator(this, function (_a) {
650
647
  switch (_a.label) {
651
648
  case 0:
652
- _a.trys.push([0, 3, , 4]);
653
649
  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)];
650
+ _a.label = 1;
656
651
  case 1:
652
+ _a.trys.push([1, 4, , 5]);
653
+ if (!booking.cartId) return [3 /*break*/, 3];
654
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
655
+ case 2:
657
656
  _a.sent();
658
- _a.label = 2;
659
- case 2: return [2 /*return*/, booking];
660
- case 3:
657
+ _a.label = 3;
658
+ case 3: return [2 /*return*/, booking];
659
+ case 4:
661
660
  error_1 = _a.sent();
662
- throw new Error("Could not instantiate ServiceBooking");
663
- case 4: return [2 /*return*/];
661
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
662
+ // This error can occur when the user refreshes the page and the cart has expired
663
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
664
+ localStorage.removeItem("cartId");
665
+ booking.cartId = undefined;
666
+ return [2 /*return*/, booking];
667
+ }
668
+ throw new Error("Could not instantiate JourneyBooking");
669
+ case 5: return [2 /*return*/];
664
670
  }
665
671
  });
666
672
  }); };
@@ -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
  })];
@@ -403,11 +403,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
403
403
  if (!linkavelCardNumber && !linkavelCardPhoneNumber) {
404
404
  throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
405
405
  }
406
- searchParams = new URLSearchParams({
407
- linkavelCardNumber: linkavelCardNumber !== null && linkavelCardNumber !== void 0 ? linkavelCardNumber : "",
408
- linkavelCardPhoneNumber: linkavelCardPhoneNumber !== null && linkavelCardPhoneNumber !== void 0 ? linkavelCardPhoneNumber : "",
409
- });
410
- url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams, "}");
406
+ searchParams = new URLSearchParams(__assign(__assign({}, (linkavelCardNumber && { linkavelCardNumber: linkavelCardNumber })), (linkavelCardPhoneNumber && { linkavelCardPhoneNumber: linkavelCardPhoneNumber })));
407
+ url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams);
411
408
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
412
409
  // Check for errors
413
410
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -733,18 +730,27 @@ exports.SubscriptionBooking = SubscriptionBooking;
733
730
  return __generator(this, function (_a) {
734
731
  switch (_a.label) {
735
732
  case 0:
736
- _a.trys.push([0, 3, , 4]);
737
733
  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)];
734
+ _a.label = 1;
740
735
  case 1:
736
+ _a.trys.push([1, 4, , 5]);
737
+ if (!booking.cartId) return [3 /*break*/, 3];
738
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
739
+ case 2:
741
740
  _a.sent();
742
- _a.label = 2;
743
- case 2: return [2 /*return*/, booking];
744
- case 3:
741
+ _a.label = 3;
742
+ case 3: return [2 /*return*/, booking];
743
+ case 4:
745
744
  error_1 = _a.sent();
746
- throw new Error("Could not instantiate SubscriptionBooking");
747
- case 4: return [2 /*return*/];
745
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
746
+ // This error can occur when the user refreshes the page and the cart has expired
747
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
748
+ localStorage.removeItem("cartId");
749
+ booking.cartId = undefined;
750
+ return [2 /*return*/, booking];
751
+ }
752
+ throw new Error("Could not instantiate JourneyBooking");
753
+ case 5: return [2 /*return*/];
748
754
  }
749
755
  });
750
756
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.19",
3
+ "version": "1.2.21",
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
  },