mts-booking-library 2.1.3 → 2.2.2

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.
@@ -132,30 +132,29 @@ var JourneyBooking = /** @class */ (function (_super) {
132
132
  };
133
133
  JourneyBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
- var _this = this;
135
+ var cart, cartDueDate;
136
136
  return __generator(this, function (_a) {
137
137
  switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options).then(function (cart) {
139
- if (cart) {
140
- var cartDueDate = new Date();
141
- cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
142
- if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
143
- _this.cart = cart;
144
- _this.cartGuid = cart.guid;
145
- _this.bookingDueDate = cartDueDate; // See Booking class
146
- // Update the sellerId. This is particularly important in Linkavel
147
- _this.updateSellerId(cart.sellerId);
148
- // Fill the booking process status
149
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
150
- }
151
- else {
152
- // This should never happen, but just in case
153
- _this.resetBooking();
154
- }
155
- }
156
- })];
138
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
157
139
  case 1:
158
- _a.sent();
140
+ cart = _a.sent();
141
+ if (cart) {
142
+ cartDueDate = new Date();
143
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
144
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
145
+ this.cart = cart;
146
+ this.cartGuid = cart.guid;
147
+ this.bookingDueDate = cartDueDate; // See Booking class
148
+ // Update the sellerId. This is particularly important in Linkavel
149
+ this.updateSellerId(cart.sellerId);
150
+ // Fill the booking process status
151
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
152
+ }
153
+ else {
154
+ // This should never happen, but just in case
155
+ this.resetBooking();
156
+ }
157
+ }
159
158
  return [2 /*return*/];
160
159
  }
161
160
  });
@@ -271,26 +270,46 @@ var JourneyBooking = /** @class */ (function (_super) {
271
270
  return __generator(this, function (_a) {
272
271
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/carts");
273
272
  request = __assign(__assign({}, journeyCart), (this.cartGuid && { cartGuid: this.cartGuid }));
274
- return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
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 response;
280
- }
281
- _this.cart = response.cart;
282
- _this.cartGuid = response.cart.guid;
283
- // Save the cartGuid in the storage
284
- _this.getStorage().getState().updateCartGuid(response.cart.guid);
285
- // Fill the booking process status
286
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
287
- var cartDueDate = new Date();
288
- cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
289
- _this.bookingDueDate = cartDueDate;
290
- // Update the sellerId. This is particularly important in Linkavel
291
- _this.updateSellerId(response.cart.sellerId);
292
- return response.cart;
293
- })];
273
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
274
+ var cartDueDate;
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0:
278
+ // Check for errors
279
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
280
+ // If there was an error, reset cartGuid and remove it from the mts-storage
281
+ this.resetBooking();
282
+ return [2 /*return*/, response];
283
+ }
284
+ if (!response.cart) return [3 /*break*/, 1];
285
+ this.cart = response.cart;
286
+ this.cartGuid = response.cart.guid;
287
+ // Save the cartGuid in the storage
288
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
289
+ // Fill the booking process status
290
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
291
+ cartDueDate = new Date();
292
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
293
+ this.bookingDueDate = cartDueDate;
294
+ // Update the sellerId. This is particularly important in Linkavel
295
+ this.updateSellerId(response.cart.sellerId);
296
+ return [2 /*return*/, response.cart];
297
+ case 1:
298
+ // Fetch & update local properties
299
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
300
+ case 2:
301
+ // Fetch & update local properties
302
+ _a.sent();
303
+ if (!this.cart) {
304
+ // Should already be handled, but just in case
305
+ throw new Error("Could not fetch cart");
306
+ }
307
+ // Update storage
308
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
309
+ return [2 /*return*/, this.cart];
310
+ }
311
+ });
312
+ }); })];
294
313
  });
295
314
  });
296
315
  };
@@ -132,30 +132,29 @@ var ServiceBooking = /** @class */ (function (_super) {
132
132
  };
133
133
  ServiceBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
- var _this = this;
135
+ var cart, cartDueDate;
136
136
  return __generator(this, function (_a) {
137
137
  switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options).then(function (cart) {
139
- if (cart) {
140
- var cartDueDate = new Date();
141
- cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
142
- if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
143
- _this.cart = cart;
144
- _this.cartGuid = cart.guid;
145
- _this.bookingDueDate = cartDueDate; // See Booking class
146
- // Update the sellerId. This is particularly important in Linkavel
147
- _this.updateSellerId(cart.sellerId);
148
- // Fill the booking process status
149
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
150
- }
151
- else {
152
- // This should never happen, but just in case
153
- _this.resetBooking();
154
- }
155
- }
156
- })];
138
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
157
139
  case 1:
158
- _a.sent();
140
+ cart = _a.sent();
141
+ if (cart) {
142
+ cartDueDate = new Date();
143
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
144
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
145
+ this.cart = cart;
146
+ this.cartGuid = cart.guid;
147
+ this.bookingDueDate = cartDueDate; // See Booking class
148
+ // Update the sellerId. This is particularly important in Linkavel
149
+ this.updateSellerId(cart.sellerId);
150
+ // Fill the booking process status
151
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
152
+ }
153
+ else {
154
+ // This should never happen, but just in case
155
+ this.resetBooking();
156
+ }
157
+ }
159
158
  return [2 /*return*/];
160
159
  }
161
160
  });
@@ -271,27 +270,47 @@ var ServiceBooking = /** @class */ (function (_super) {
271
270
  var _this = this;
272
271
  return __generator(this, function (_a) {
273
272
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/carts");
274
- return [2 /*return*/, this.callPostApi(url, serviceCart, options).then(function (response) {
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 response;
280
- }
281
- // Save the local data
282
- _this.cart = response.cart;
283
- _this.cartGuid = response.cart.guid;
284
- // Save the cartGuid in the mts-storage
285
- _this.getStorage().getState().updateCartGuid(response.cart.guid);
286
- // Fill the booking process status
287
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
288
- var cartDueDate = new Date();
289
- cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
290
- _this.bookingDueDate = cartDueDate;
291
- // Update the sellerId. This is particularly important in Linkavel
292
- _this.updateSellerId(response.cart.sellerId);
293
- return response.cart;
294
- })];
273
+ return [2 /*return*/, this.callPostApi(url, serviceCart, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
274
+ var cartDueDate;
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0:
278
+ // Check for errors
279
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
280
+ // If there was an error, reset cartGuid and remove it from the mts-storage
281
+ this.resetBooking();
282
+ return [2 /*return*/, response];
283
+ }
284
+ if (!response.cart) return [3 /*break*/, 1];
285
+ // Save the local data
286
+ this.cart = response.cart;
287
+ this.cartGuid = response.cart.guid;
288
+ // Save the cartGuid in the mts-storage
289
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
290
+ // Fill the booking process status
291
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
292
+ cartDueDate = new Date();
293
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
294
+ this.bookingDueDate = cartDueDate;
295
+ // Update the sellerId. This is particularly important in Linkavel
296
+ this.updateSellerId(response.cart.sellerId);
297
+ return [2 /*return*/, response.cart];
298
+ case 1:
299
+ // Fetch & update local properties
300
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
301
+ case 2:
302
+ // Fetch & update local properties
303
+ _a.sent();
304
+ if (!this.cart) {
305
+ // Should already be handled, but just in case
306
+ throw new Error("Could not fetch cart");
307
+ }
308
+ // Update storage
309
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
310
+ return [2 /*return*/, this.cart];
311
+ }
312
+ });
313
+ }); })];
295
314
  });
296
315
  });
297
316
  };
@@ -132,30 +132,29 @@ var SubscriptionBooking = /** @class */ (function (_super) {
132
132
  };
133
133
  SubscriptionBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
- var _this = this;
135
+ var cart, cartDueDate;
136
136
  return __generator(this, function (_a) {
137
137
  switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options).then(function (cart) {
139
- if (cart) {
140
- var cartDueDate = new Date();
141
- cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
142
- if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
143
- _this.cart = cart;
144
- _this.cartGuid = cart.guid;
145
- _this.bookingDueDate = cartDueDate; // See Booking class
146
- // Update the sellerId. This is particularly important in Linkavel
147
- _this.updateSellerId(cart.sellerId);
148
- // Fill the booking process status
149
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
150
- }
151
- else {
152
- // This should never happen, but just in case
153
- _this.resetBooking();
154
- }
155
- }
156
- })];
138
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
157
139
  case 1:
158
- _a.sent();
140
+ cart = _a.sent();
141
+ if (cart) {
142
+ cartDueDate = new Date();
143
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
144
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
145
+ this.cart = cart;
146
+ this.cartGuid = cart.guid;
147
+ this.bookingDueDate = cartDueDate; // See Booking class
148
+ // Update the sellerId. This is particularly important in Linkavel
149
+ this.updateSellerId(cart.sellerId);
150
+ // Fill the booking process status
151
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
152
+ }
153
+ else {
154
+ // This should never happen, but just in case
155
+ this.resetBooking();
156
+ }
157
+ }
159
158
  return [2 /*return*/];
160
159
  }
161
160
  });
@@ -330,26 +329,46 @@ var SubscriptionBooking = /** @class */ (function (_super) {
330
329
  var _this = this;
331
330
  return __generator(this, function (_a) {
332
331
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/carts");
333
- return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
334
- // Check for errors
335
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
336
- // If there was an error, reset cartGuid and remove it from the mts-storage
337
- _this.resetBooking();
338
- return response;
339
- }
340
- _this.cart = response.cart;
341
- _this.cartGuid = response.cart.guid;
342
- // Save the cartGuid in the mts-storage
343
- _this.getStorage().getState().updateCartGuid(response.cart.guid);
344
- // Fill the booking process status
345
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
346
- var cartDueDate = new Date();
347
- cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
348
- _this.bookingDueDate = cartDueDate;
349
- // Update the sellerId. This is particularly important in Linkavel
350
- _this.updateSellerId(response.cart.sellerId);
351
- return response.cart;
352
- })];
332
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
333
+ var cartDueDate;
334
+ return __generator(this, function (_a) {
335
+ switch (_a.label) {
336
+ case 0:
337
+ // Check for errors
338
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
339
+ // If there was an error, reset cartGuid and remove it from the mts-storage
340
+ this.resetBooking();
341
+ return [2 /*return*/, response];
342
+ }
343
+ if (!response.cart) return [3 /*break*/, 1];
344
+ this.cart = response.cart;
345
+ this.cartGuid = response.cart.guid;
346
+ // Save the cartGuid in the mts-storage
347
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
348
+ // Fill the booking process status
349
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
350
+ cartDueDate = new Date();
351
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
352
+ this.bookingDueDate = cartDueDate;
353
+ // Update the sellerId. This is particularly important in Linkavel
354
+ this.updateSellerId(response.cart.sellerId);
355
+ return [2 /*return*/, response.cart];
356
+ case 1:
357
+ // Fetch & update local properties
358
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
359
+ case 2:
360
+ // Fetch & update local properties
361
+ _a.sent();
362
+ if (!this.cart) {
363
+ // Should already be handled, but just in case
364
+ throw new Error("Could not fetch cart");
365
+ }
366
+ // Update storage
367
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
368
+ return [2 /*return*/, this.cart];
369
+ }
370
+ });
371
+ }); })];
353
372
  });
354
373
  });
355
374
  };
@@ -132,30 +132,29 @@ var TplBooking = /** @class */ (function (_super) {
132
132
  };
133
133
  TplBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
- var _this = this;
135
+ var cart, cartDueDate;
136
136
  return __generator(this, function (_a) {
137
137
  switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options).then(function (cart) {
139
- if (cart) {
140
- var cartDueDate = new Date();
141
- cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
142
- if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
143
- _this.cart = cart;
144
- _this.cartGuid = cart.guid;
145
- _this.bookingDueDate = cartDueDate; // See Booking class
146
- // Update the sellerId. This is particularly important in Linkavel
147
- _this.updateSellerId(cart.sellerId);
148
- // Fill the booking process status
149
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
150
- }
151
- else {
152
- // This should never happen, but just in case
153
- _this.resetBooking();
154
- }
155
- }
156
- })];
138
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
157
139
  case 1:
158
- _a.sent();
140
+ cart = _a.sent();
141
+ if (cart) {
142
+ cartDueDate = new Date();
143
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
144
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
145
+ this.cart = cart;
146
+ this.cartGuid = cart.guid;
147
+ this.bookingDueDate = cartDueDate; // See Booking class
148
+ // Update the sellerId. This is particularly important in Linkavel
149
+ this.updateSellerId(cart.sellerId);
150
+ // Fill the booking process status
151
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
152
+ }
153
+ else {
154
+ // This should never happen, but just in case
155
+ this.resetBooking();
156
+ }
157
+ }
159
158
  return [2 /*return*/];
160
159
  }
161
160
  });
@@ -329,26 +328,46 @@ var TplBooking = /** @class */ (function (_super) {
329
328
  renewSubscriptionTicketPNR: tplCart.renewSubscriptionTicketPNR
330
329
  })), (tplCart.otaResellerId !== undefined && { otaResellerId: tplCart.otaResellerId })), (tplCart.otaTicketPicture !== undefined && { otaTicketPicture: tplCart.otaTicketPicture }));
331
330
  // Call the API
332
- return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
333
- // Check for errors
334
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
335
- // If there was an error, reset cartGuid and remove it from the mts-storage
336
- _this.resetBooking();
337
- return response;
338
- }
339
- _this.cart = response.cart;
340
- _this.cartGuid = response.cart.guid;
341
- // Save the cartGuid in the mts-storage
342
- _this.getStorage().getState().updateCartGuid(response.cart.guid);
343
- // Fill the booking process status
344
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
345
- var cartDueDate = new Date();
346
- cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
347
- _this.bookingDueDate = cartDueDate;
348
- // Update the sellerId. This is particularly important in Linkavel
349
- _this.updateSellerId(response.cart.sellerId);
350
- return response.cart;
351
- })];
331
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
332
+ var cartDueDate;
333
+ return __generator(this, function (_a) {
334
+ switch (_a.label) {
335
+ case 0:
336
+ // Check for errors
337
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
338
+ // If there was an error, reset cartGuid and remove it from the mts-storage
339
+ this.resetBooking();
340
+ return [2 /*return*/, response];
341
+ }
342
+ if (!response.cart) return [3 /*break*/, 1];
343
+ this.cart = response.cart;
344
+ this.cartGuid = response.cart.guid;
345
+ // Save the cartGuid in the mts-storage
346
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
347
+ // Fill the booking process status
348
+ this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
349
+ cartDueDate = new Date();
350
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + response.cart.bookingDueDateRemainingSeconds);
351
+ this.bookingDueDate = cartDueDate;
352
+ // Update the sellerId. This is particularly important in Linkavel
353
+ this.updateSellerId(response.cart.sellerId);
354
+ return [2 /*return*/, response.cart];
355
+ case 1:
356
+ // Fetch & update local properties
357
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
358
+ case 2:
359
+ // Fetch & update local properties
360
+ _a.sent();
361
+ if (!this.cart) {
362
+ // Should already be handled, but just in case
363
+ throw new Error("Could not fetch cart");
364
+ }
365
+ // Update storage
366
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
367
+ return [2 /*return*/, this.cart];
368
+ }
369
+ });
370
+ }); })];
352
371
  });
353
372
  });
354
373
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "2.1.3",
3
+ "version": "2.2.2",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",