mts-booking-library 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -134,30 +134,25 @@ var JourneyBooking = /** @class */ (function (_super) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
135
  var _this = this;
136
136
  return __generator(this, function (_a) {
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
- }
137
+ return [2 /*return*/, this.fetchCart(cartGuid, options).then(function (cart) {
138
+ if (cart) {
139
+ var cartDueDate = new Date();
140
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
141
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
142
+ _this.cart = cart;
143
+ _this.cartGuid = cart.guid;
144
+ _this.bookingDueDate = cartDueDate; // See Booking class
145
+ // Update the sellerId. This is particularly important in Linkavel
146
+ _this.updateSellerId(cart.sellerId);
147
+ // Fill the booking process status
148
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
155
149
  }
156
- })];
157
- case 1:
158
- _a.sent();
159
- return [2 /*return*/];
160
- }
150
+ else {
151
+ // This should never happen, but just in case
152
+ _this.resetBooking();
153
+ }
154
+ }
155
+ })];
161
156
  });
162
157
  });
163
158
  };
@@ -271,26 +266,46 @@ var JourneyBooking = /** @class */ (function (_super) {
271
266
  return __generator(this, function (_a) {
272
267
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/carts");
273
268
  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
- })];
269
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
270
+ var cartDueDate;
271
+ return __generator(this, function (_a) {
272
+ switch (_a.label) {
273
+ case 0:
274
+ // Check for errors
275
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
276
+ // If there was an error, reset cartGuid and remove it from the mts-storage
277
+ this.resetBooking();
278
+ return [2 /*return*/, response];
279
+ }
280
+ if (!response.cart) return [3 /*break*/, 1];
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
+ 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 [2 /*return*/, response.cart];
293
+ case 1:
294
+ // Fetch & update local properties
295
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
296
+ case 2:
297
+ // Fetch & update local properties
298
+ _a.sent();
299
+ if (!this.cart) {
300
+ // Should already be handled, but just in case
301
+ throw new Error("Could not fetch cart");
302
+ }
303
+ // Update storage
304
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
305
+ return [2 /*return*/, this.cart];
306
+ }
307
+ });
308
+ }); })];
294
309
  });
295
310
  });
296
311
  };
@@ -134,30 +134,25 @@ var ServiceBooking = /** @class */ (function (_super) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
135
  var _this = this;
136
136
  return __generator(this, function (_a) {
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
- }
137
+ return [2 /*return*/, this.fetchCart(cartGuid, options).then(function (cart) {
138
+ if (cart) {
139
+ var cartDueDate = new Date();
140
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
141
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
142
+ _this.cart = cart;
143
+ _this.cartGuid = cart.guid;
144
+ _this.bookingDueDate = cartDueDate; // See Booking class
145
+ // Update the sellerId. This is particularly important in Linkavel
146
+ _this.updateSellerId(cart.sellerId);
147
+ // Fill the booking process status
148
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
155
149
  }
156
- })];
157
- case 1:
158
- _a.sent();
159
- return [2 /*return*/];
160
- }
150
+ else {
151
+ // This should never happen, but just in case
152
+ _this.resetBooking();
153
+ }
154
+ }
155
+ })];
161
156
  });
162
157
  });
163
158
  };
@@ -271,27 +266,47 @@ var ServiceBooking = /** @class */ (function (_super) {
271
266
  var _this = this;
272
267
  return __generator(this, function (_a) {
273
268
  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
- })];
269
+ return [2 /*return*/, this.callPostApi(url, serviceCart, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
270
+ var cartDueDate;
271
+ return __generator(this, function (_a) {
272
+ switch (_a.label) {
273
+ case 0:
274
+ // Check for errors
275
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
276
+ // If there was an error, reset cartGuid and remove it from the mts-storage
277
+ this.resetBooking();
278
+ return [2 /*return*/, response];
279
+ }
280
+ if (!response.cart) return [3 /*break*/, 1];
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
+ 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 [2 /*return*/, response.cart];
294
+ case 1:
295
+ // Fetch & update local properties
296
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
297
+ case 2:
298
+ // Fetch & update local properties
299
+ _a.sent();
300
+ if (!this.cart) {
301
+ // Should already be handled, but just in case
302
+ throw new Error("Could not fetch cart");
303
+ }
304
+ // Update storage
305
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
306
+ return [2 /*return*/, this.cart];
307
+ }
308
+ });
309
+ }); })];
295
310
  });
296
311
  });
297
312
  };
@@ -134,30 +134,25 @@ var SubscriptionBooking = /** @class */ (function (_super) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
135
  var _this = this;
136
136
  return __generator(this, function (_a) {
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
- }
137
+ return [2 /*return*/, this.fetchCart(cartGuid, options).then(function (cart) {
138
+ if (cart) {
139
+ var cartDueDate = new Date();
140
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
141
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
142
+ _this.cart = cart;
143
+ _this.cartGuid = cart.guid;
144
+ _this.bookingDueDate = cartDueDate; // See Booking class
145
+ // Update the sellerId. This is particularly important in Linkavel
146
+ _this.updateSellerId(cart.sellerId);
147
+ // Fill the booking process status
148
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
155
149
  }
156
- })];
157
- case 1:
158
- _a.sent();
159
- return [2 /*return*/];
160
- }
150
+ else {
151
+ // This should never happen, but just in case
152
+ _this.resetBooking();
153
+ }
154
+ }
155
+ })];
161
156
  });
162
157
  });
163
158
  };
@@ -330,26 +325,46 @@ var SubscriptionBooking = /** @class */ (function (_super) {
330
325
  var _this = this;
331
326
  return __generator(this, function (_a) {
332
327
  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
- })];
328
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
329
+ var cartDueDate;
330
+ return __generator(this, function (_a) {
331
+ switch (_a.label) {
332
+ case 0:
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 [2 /*return*/, response];
338
+ }
339
+ if (!response.cart) return [3 /*break*/, 1];
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
+ 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 [2 /*return*/, response.cart];
352
+ case 1:
353
+ // Fetch & update local properties
354
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
355
+ case 2:
356
+ // Fetch & update local properties
357
+ _a.sent();
358
+ if (!this.cart) {
359
+ // Should already be handled, but just in case
360
+ throw new Error("Could not fetch cart");
361
+ }
362
+ // Update storage
363
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
364
+ return [2 /*return*/, this.cart];
365
+ }
366
+ });
367
+ }); })];
353
368
  });
354
369
  });
355
370
  };
@@ -134,30 +134,25 @@ var TplBooking = /** @class */ (function (_super) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
135
  var _this = this;
136
136
  return __generator(this, function (_a) {
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
- }
137
+ return [2 /*return*/, this.fetchCart(cartGuid, options).then(function (cart) {
138
+ if (cart) {
139
+ var cartDueDate = new Date();
140
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
141
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
142
+ _this.cart = cart;
143
+ _this.cartGuid = cart.guid;
144
+ _this.bookingDueDate = cartDueDate; // See Booking class
145
+ // Update the sellerId. This is particularly important in Linkavel
146
+ _this.updateSellerId(cart.sellerId);
147
+ // Fill the booking process status
148
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
155
149
  }
156
- })];
157
- case 1:
158
- _a.sent();
159
- return [2 /*return*/];
160
- }
150
+ else {
151
+ // This should never happen, but just in case
152
+ _this.resetBooking();
153
+ }
154
+ }
155
+ })];
161
156
  });
162
157
  });
163
158
  };
@@ -329,26 +324,46 @@ var TplBooking = /** @class */ (function (_super) {
329
324
  renewSubscriptionTicketPNR: tplCart.renewSubscriptionTicketPNR
330
325
  })), (tplCart.otaResellerId !== undefined && { otaResellerId: tplCart.otaResellerId })), (tplCart.otaTicketPicture !== undefined && { otaTicketPicture: tplCart.otaTicketPicture }));
331
326
  // 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
- })];
327
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
328
+ var cartDueDate;
329
+ return __generator(this, function (_a) {
330
+ switch (_a.label) {
331
+ case 0:
332
+ // Check for errors
333
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
334
+ // If there was an error, reset cartGuid and remove it from the mts-storage
335
+ this.resetBooking();
336
+ return [2 /*return*/, response];
337
+ }
338
+ if (!response.cart) return [3 /*break*/, 1];
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
+ 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 [2 /*return*/, response.cart];
351
+ case 1:
352
+ // Fetch & update local properties
353
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
354
+ case 2:
355
+ // Fetch & update local properties
356
+ _a.sent();
357
+ if (!this.cart) {
358
+ // Should already be handled, but just in case
359
+ throw new Error("Could not fetch cart");
360
+ }
361
+ // Update storage
362
+ this.getStorage().getState().updateCartGuid(response.cart.guid);
363
+ return [2 /*return*/, this.cart];
364
+ }
365
+ });
366
+ }); })];
352
367
  });
353
368
  });
354
369
  };
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.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",