mts-booking-library 1.2.2 → 1.2.4

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.
@@ -21,7 +21,7 @@ export declare class JourneyBooking extends Booking {
21
21
  */
22
22
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
23
23
  getCart(): JourneyCart | undefined;
24
- private fetchAndSetCart;
24
+ fetchAndSetCart(cartId: number): Promise<void>;
25
25
  private createCartTimer;
26
26
  fetchCart(cartId: number): Promise<JourneyCart>;
27
27
  /**
@@ -88,3 +88,6 @@ export declare class JourneyBooking extends Booking {
88
88
  */
89
89
  changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse | any>;
90
90
  }
91
+ export declare namespace JourneyBooking {
92
+ const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
93
+ }
@@ -74,9 +74,10 @@ var JourneyBooking = /** @class */ (function (_super) {
74
74
  var _this =
75
75
  // Call Booking constructor
76
76
  _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
77
+ // Set cartId
77
78
  var cartId = localStorage.getItem("cartId");
78
79
  if (cartId) {
79
- _this.fetchAndSetCart(parseInt(cartId));
80
+ _this.cartId = parseInt(cartId);
80
81
  }
81
82
  return _this;
82
83
  }
@@ -87,23 +88,28 @@ var JourneyBooking = /** @class */ (function (_super) {
87
88
  return __awaiter(this, void 0, void 0, function () {
88
89
  var _this = this;
89
90
  return __generator(this, function (_a) {
90
- this.fetchCart(cartId).then(function (cart) {
91
- var cartDate = new Date(cart.bookingDueDate);
92
- if (cartDate > new Date()) {
93
- _this.cart = cart;
94
- _this.bookingDueDate = cartDate; // See Booking class
95
- // Fill the booking process status
96
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
97
- var bookingStep = _a[0], values = _a[1];
98
- return [
99
- bookingStep,
100
- values
101
- ];
102
- }));
103
- _this.createCartTimer(cartDate);
104
- }
105
- });
106
- return [2 /*return*/];
91
+ switch (_a.label) {
92
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
93
+ var cartDate = new Date(cart.bookingDueDate);
94
+ if (cartDate > new Date()) {
95
+ _this.cart = cart;
96
+ _this.cartId = cart.id;
97
+ _this.bookingDueDate = cartDate; // See Booking class
98
+ // Fill the booking process status
99
+ _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
100
+ var bookingStep = _a[0], values = _a[1];
101
+ return [
102
+ bookingStep,
103
+ values
104
+ ];
105
+ }));
106
+ _this.createCartTimer(cartDate);
107
+ }
108
+ })];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/];
112
+ }
107
113
  });
108
114
  });
109
115
  };
@@ -116,6 +122,7 @@ var JourneyBooking = /** @class */ (function (_super) {
116
122
  // Put actions that have to be done when timer expires here
117
123
  _this.bookingStepsToStatus = new Map();
118
124
  _this.cart = undefined;
125
+ _this.cartId = undefined;
119
126
  _this.bookingDueDate = undefined; // See Booking class
120
127
  _this.onCartExpiration();
121
128
  }, expiringDate.valueOf() - new Date().valueOf());
@@ -416,3 +423,26 @@ var JourneyBooking = /** @class */ (function (_super) {
416
423
  return JourneyBooking;
417
424
  }(booking_1.Booking));
418
425
  exports.JourneyBooking = JourneyBooking;
426
+ (function (JourneyBooking) {
427
+ var _this = this;
428
+ JourneyBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
429
+ var booking, error_1;
430
+ return __generator(this, function (_a) {
431
+ switch (_a.label) {
432
+ case 0:
433
+ _a.trys.push([0, 3, , 4]);
434
+ booking = new JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
435
+ if (!booking.cartId) return [3 /*break*/, 2];
436
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
437
+ case 1:
438
+ _a.sent();
439
+ _a.label = 2;
440
+ case 2: return [2 /*return*/, booking];
441
+ case 3:
442
+ error_1 = _a.sent();
443
+ throw new Error("Could not instantiate JourneyBooking");
444
+ case 4: return [2 /*return*/];
445
+ }
446
+ });
447
+ }); };
448
+ })(JourneyBooking || (exports.JourneyBooking = JourneyBooking = {}));
@@ -19,7 +19,7 @@ export declare class ServiceBooking extends Booking {
19
19
  */
20
20
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
21
21
  getCart(): ServiceCart | undefined;
22
- private fetchAndSetCart;
22
+ fetchAndSetCart(cartId: number): Promise<void>;
23
23
  private createCartTimer;
24
24
  fetchCart(cartId: number): Promise<ServiceCart>;
25
25
  /**
@@ -47,3 +47,6 @@ export declare class ServiceBooking extends Booking {
47
47
  getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
48
48
  createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
49
49
  }
50
+ export declare namespace ServiceBooking {
51
+ const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
52
+ }
@@ -85,9 +85,10 @@ var ServiceBooking = /** @class */ (function (_super) {
85
85
  var _this =
86
86
  // Call Booking constructor
87
87
  _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
88
+ // Set cartId
88
89
  var cartId = localStorage.getItem("cartId");
89
90
  if (cartId) {
90
- _this.fetchAndSetCart(parseInt(cartId));
91
+ _this.cartId = parseInt(cartId);
91
92
  }
92
93
  return _this;
93
94
  }
@@ -98,23 +99,28 @@ var ServiceBooking = /** @class */ (function (_super) {
98
99
  return __awaiter(this, void 0, void 0, function () {
99
100
  var _this = this;
100
101
  return __generator(this, function (_a) {
101
- this.fetchCart(cartId).then(function (cart) {
102
- var cartDate = new Date(cart.bookingDueDate);
103
- if (cartDate > new Date()) {
104
- _this.cart = cart;
105
- _this.bookingDueDate = cartDate; // See Booking class
106
- // Fill the booking process status
107
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
108
- var bookingStep = _a[0], values = _a[1];
109
- return [
110
- bookingStep,
111
- values
112
- ];
113
- }));
114
- _this.createCartTimer(cartDate);
115
- }
116
- });
117
- return [2 /*return*/];
102
+ switch (_a.label) {
103
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
104
+ var cartDate = new Date(cart.bookingDueDate);
105
+ if (cartDate > new Date()) {
106
+ _this.cart = cart;
107
+ _this.cartId = cart.id;
108
+ _this.bookingDueDate = cartDate; // See Booking class
109
+ // Fill the booking process status
110
+ _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
111
+ var bookingStep = _a[0], values = _a[1];
112
+ return [
113
+ bookingStep,
114
+ values
115
+ ];
116
+ }));
117
+ _this.createCartTimer(cartDate);
118
+ }
119
+ })];
120
+ case 1:
121
+ _a.sent();
122
+ return [2 /*return*/];
123
+ }
118
124
  });
119
125
  });
120
126
  };
@@ -126,6 +132,7 @@ var ServiceBooking = /** @class */ (function (_super) {
126
132
  localStorage.removeItem("cartId");
127
133
  // Put actions that have to be done when timer expires here
128
134
  _this.cart = undefined;
135
+ _this.cartId = undefined;
129
136
  _this.bookingDueDate = undefined; // See Booking class
130
137
  _this.onCartExpiration();
131
138
  }, expiringDate.valueOf() - new Date().valueOf());
@@ -237,3 +244,26 @@ var ServiceBooking = /** @class */ (function (_super) {
237
244
  return ServiceBooking;
238
245
  }(booking_1.Booking));
239
246
  exports.ServiceBooking = ServiceBooking;
247
+ (function (ServiceBooking) {
248
+ var _this = this;
249
+ ServiceBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
250
+ var booking, error_1;
251
+ return __generator(this, function (_a) {
252
+ switch (_a.label) {
253
+ case 0:
254
+ _a.trys.push([0, 3, , 4]);
255
+ booking = new ServiceBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
256
+ if (!booking.cartId) return [3 /*break*/, 2];
257
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
258
+ case 1:
259
+ _a.sent();
260
+ _a.label = 2;
261
+ case 2: return [2 /*return*/, booking];
262
+ case 3:
263
+ error_1 = _a.sent();
264
+ throw new Error("Could not instantiate ServiceBooking");
265
+ case 4: return [2 /*return*/];
266
+ }
267
+ });
268
+ }); };
269
+ })(ServiceBooking || (exports.ServiceBooking = ServiceBooking = {}));
@@ -22,7 +22,7 @@ export declare class SubscriptionBooking extends Booking {
22
22
  */
23
23
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
24
24
  getCart(): Cart | undefined;
25
- private fetchAndSetCart;
25
+ fetchAndSetCart(cartId: number): Promise<void>;
26
26
  private createCartTimer;
27
27
  fetchCart(cartId: number): Promise<Cart>;
28
28
  /**
@@ -90,6 +90,7 @@ export declare class SubscriptionBooking extends Booking {
90
90
  updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | any>;
91
91
  }
92
92
  export declare namespace SubscriptionBooking {
93
+ const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
93
94
  enum ValidityTypes {
94
95
  WORKING_WEEK = "WORKING_WEEK",
95
96
  WEEKLY = "WEEKLY",
@@ -74,9 +74,10 @@ var SubscriptionBooking = /** @class */ (function (_super) {
74
74
  var _this =
75
75
  // Call Booking constructor
76
76
  _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
77
+ // Set cartId
77
78
  var cartId = localStorage.getItem("cartId");
78
79
  if (cartId) {
79
- _this.fetchAndSetCart(parseInt(cartId));
80
+ _this.cartId = parseInt(cartId);
80
81
  }
81
82
  return _this;
82
83
  }
@@ -87,23 +88,28 @@ var SubscriptionBooking = /** @class */ (function (_super) {
87
88
  return __awaiter(this, void 0, void 0, function () {
88
89
  var _this = this;
89
90
  return __generator(this, function (_a) {
90
- this.fetchCart(cartId).then(function (cart) {
91
- var cartDate = new Date(cart.bookingDueDate);
92
- if (cartDate > new Date()) {
93
- _this.cart = cart;
94
- _this.bookingDueDate = cartDate; // See Booking class
95
- // Fill the booking process status
96
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
97
- var bookingStep = _a[0], values = _a[1];
98
- return [
99
- bookingStep,
100
- values
101
- ];
102
- }));
103
- _this.createCartTimer(cartDate);
104
- }
105
- });
106
- return [2 /*return*/];
91
+ switch (_a.label) {
92
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
93
+ var cartDate = new Date(cart.bookingDueDate);
94
+ if (cartDate > new Date()) {
95
+ _this.cart = cart;
96
+ _this.cartId = cart.id;
97
+ _this.bookingDueDate = cartDate; // See Booking class
98
+ // Fill the booking process status
99
+ _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
100
+ var bookingStep = _a[0], values = _a[1];
101
+ return [
102
+ bookingStep,
103
+ values
104
+ ];
105
+ }));
106
+ _this.createCartTimer(cartDate);
107
+ }
108
+ })];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/];
112
+ }
107
113
  });
108
114
  });
109
115
  };
@@ -116,6 +122,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
116
122
  // Put actions that have to be done when timer expires here
117
123
  _this.bookingStepsToStatus = new Map();
118
124
  _this.cart = undefined;
125
+ _this.cartId = undefined;
119
126
  _this.bookingDueDate = undefined; // See Booking class
120
127
  _this.onCartExpiration();
121
128
  }, expiringDate.valueOf() - new Date().valueOf());
@@ -385,6 +392,27 @@ var SubscriptionBooking = /** @class */ (function (_super) {
385
392
  }(booking_1.Booking));
386
393
  exports.SubscriptionBooking = SubscriptionBooking;
387
394
  (function (SubscriptionBooking) {
395
+ var _this = this;
396
+ SubscriptionBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
397
+ var booking, error_1;
398
+ return __generator(this, function (_a) {
399
+ switch (_a.label) {
400
+ case 0:
401
+ _a.trys.push([0, 3, , 4]);
402
+ booking = new SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
403
+ if (!booking.cartId) return [3 /*break*/, 2];
404
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
405
+ case 1:
406
+ _a.sent();
407
+ _a.label = 2;
408
+ case 2: return [2 /*return*/, booking];
409
+ case 3:
410
+ error_1 = _a.sent();
411
+ throw new Error("Could not instantiate SubscriptionBooking");
412
+ case 4: return [2 /*return*/];
413
+ }
414
+ });
415
+ }); };
388
416
  var ValidityTypes;
389
417
  (function (ValidityTypes) {
390
418
  ValidityTypes["WORKING_WEEK"] = "WORKING_WEEK";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",