mts-booking-library 1.2.32 → 1.2.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -207,7 +207,7 @@ var Booking = /** @class */ (function () {
207
207
  }
208
208
  issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
209
209
  if (!issueStep)
210
- throw Error("Booking step not found!");
210
+ throw Error("Booking step: ".concat(Booking.BookingSteps.ISSUE, " not found!"));
211
211
  if (!!issueStep[0]) return [3 /*break*/, 5];
212
212
  _b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
213
213
  _c = [];
@@ -230,13 +230,13 @@ var Booking = /** @class */ (function () {
230
230
  return [3 /*break*/, 1];
231
231
  case 4:
232
232
  // Check again if the issue step is accessible
233
- issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
233
+ issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
234
234
  if (!issueStep || !issueStep[0]) {
235
235
  throw Error("The status of the cart does not allow to call this API");
236
236
  }
237
237
  _e.label = 5;
238
238
  case 5:
239
- url = "".concat(this.config.API_ENDPOINT, "/booking/sellers/").concat(this.sellerId, "/gateways?language=").concat(this.language);
239
+ url = "".concat(this.config.API_ENDPOINT, "/booking/sellers/").concat(this.sellerId, "/gateways?");
240
240
  // We use directly makeGet because we don't want to add sellerId to the query string (it is already present in the url)
241
241
  return [2 /*return*/, (0, apiCall_1.makeGet)(url).then(function (response) {
242
242
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
@@ -620,7 +620,7 @@ var JourneyBooking = /** @class */ (function (_super) {
620
620
  JourneyBooking.prototype.useWallet = function () {
621
621
  var _a;
622
622
  return __awaiter(this, void 0, void 0, function () {
623
- var discountsStep, _b, _c, _d, _i, step, url;
623
+ var issueStep, _b, _c, _d, _i, step, url;
624
624
  var _this = this;
625
625
  return __generator(this, function (_e) {
626
626
  switch (_e.label) {
@@ -629,11 +629,11 @@ var JourneyBooking = /** @class */ (function (_super) {
629
629
  if (!this.cartId || this.cartId === 0) {
630
630
  throw Error("Cart is not initialized yet");
631
631
  }
632
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
633
- if (!discountsStep)
634
- throw Error("Booking step not found!");
635
- if (!!discountsStep[0]) return [3 /*break*/, 5];
636
- _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
632
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
633
+ if (!issueStep)
634
+ throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
635
+ if (!!issueStep[0]) return [3 /*break*/, 5];
636
+ _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
637
637
  _c = [];
638
638
  for (_d in _b)
639
639
  _c.push(_d);
@@ -654,9 +654,9 @@ var JourneyBooking = /** @class */ (function (_super) {
654
654
  return [3 /*break*/, 1];
655
655
  case 4:
656
656
  // Check again if the discounts step is accessible
657
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
658
- if (!discountsStep || !discountsStep[0]) {
659
- throw Error("The status of the cart does not allow to call this API");
657
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
658
+ if (!issueStep || !issueStep[0]) {
659
+ throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
660
660
  }
661
661
  _e.label = 5;
662
662
  case 5:
@@ -47,10 +47,10 @@ export declare class ServiceBooking extends Booking {
47
47
  * and/or a specific hour for the tour.
48
48
  * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
49
49
  * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
50
- * @param {Date} date The date on which to get the tours
50
+ * @param {string} date The date on which to get the tours, in ISO string format
51
51
  * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
52
52
  */
53
- getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
53
+ getServiceTrips(serviceId: number, date: string): Promise<ErrorResponse | ServiceTrip[]>;
54
54
  createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
55
55
  /**
56
56
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -232,14 +232,14 @@ var ServiceBooking = /** @class */ (function (_super) {
232
232
  * and/or a specific hour for the tour.
233
233
  * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
234
234
  * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
235
- * @param {Date} date The date on which to get the tours
235
+ * @param {string} date The date on which to get the tours, in ISO string format
236
236
  * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
237
237
  */
238
238
  ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
239
239
  return __awaiter(this, void 0, void 0, function () {
240
240
  var searchParams, url;
241
241
  return __generator(this, function (_a) {
242
- searchParams = new URLSearchParams({ date: date.toDateString() });
242
+ searchParams = new URLSearchParams({ date: date });
243
243
  url = "".concat(this.config.API_ENDPOINT, "/booking/services/").concat(serviceId, "/trips?").concat(searchParams);
244
244
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
245
245
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
@@ -492,7 +492,7 @@ var ServiceBooking = /** @class */ (function (_super) {
492
492
  ServiceBooking.prototype.useWallet = function () {
493
493
  var _a;
494
494
  return __awaiter(this, void 0, void 0, function () {
495
- var discountsStep, _b, _c, _d, _i, step, url;
495
+ var issueStep, _b, _c, _d, _i, step, url;
496
496
  var _this = this;
497
497
  return __generator(this, function (_e) {
498
498
  switch (_e.label) {
@@ -501,11 +501,11 @@ var ServiceBooking = /** @class */ (function (_super) {
501
501
  if (!this.cartId || this.cartId === 0) {
502
502
  throw Error("Cart is not initialized yet");
503
503
  }
504
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
505
- if (!discountsStep)
506
- throw Error("Booking step not found!");
507
- if (!!discountsStep[0]) return [3 /*break*/, 5];
508
- _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
504
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
505
+ if (!issueStep)
506
+ throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
507
+ if (!!issueStep[0]) return [3 /*break*/, 5];
508
+ _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
509
509
  _c = [];
510
510
  for (_d in _b)
511
511
  _c.push(_d);
@@ -526,9 +526,9 @@ var ServiceBooking = /** @class */ (function (_super) {
526
526
  return [3 /*break*/, 1];
527
527
  case 4:
528
528
  // Check again if the discounts step is accessible
529
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
530
- if (!discountsStep || !discountsStep[0]) {
531
- throw Error("The status of the cart does not allow to call this API");
529
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
530
+ if (!issueStep || !issueStep[0]) {
531
+ throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
532
532
  }
533
533
  _e.label = 5;
534
534
  case 5:
@@ -567,7 +567,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
567
567
  SubscriptionBooking.prototype.useWallet = function () {
568
568
  var _a;
569
569
  return __awaiter(this, void 0, void 0, function () {
570
- var discountsStep, _b, _c, _d, _i, step, url;
570
+ var issueStep, _b, _c, _d, _i, step, url;
571
571
  var _this = this;
572
572
  return __generator(this, function (_e) {
573
573
  switch (_e.label) {
@@ -576,11 +576,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
576
576
  if (!this.cartId || this.cartId === 0) {
577
577
  throw Error("Cart is not initialized yet");
578
578
  }
579
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
580
- if (!discountsStep)
581
- throw Error("Booking step not found!");
582
- if (!!discountsStep[0]) return [3 /*break*/, 5];
583
- _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
579
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
580
+ if (!issueStep)
581
+ throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
582
+ if (!!issueStep[0]) return [3 /*break*/, 5];
583
+ _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
584
584
  _c = [];
585
585
  for (_d in _b)
586
586
  _c.push(_d);
@@ -601,9 +601,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
601
601
  return [3 /*break*/, 1];
602
602
  case 4:
603
603
  // Check again if the discounts step is accessible
604
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
605
- if (!discountsStep || !discountsStep[0]) {
606
- throw Error("The status of the cart does not allow to call this API");
604
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
605
+ if (!issueStep || !issueStep[0]) {
606
+ throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
607
607
  }
608
608
  _e.label = 5;
609
609
  case 5:
package/lib/config.js CHANGED
@@ -32,7 +32,7 @@ var setConfig = function (env, sub_key, debug, access_token) {
32
32
  default:
33
33
  throw new Error("Invalid environment");
34
34
  }
35
- // Set OCT and access token
35
+ // Set OCP and access token
36
36
  config.OCP_SUBSCRIPTION_KEY = sub_key;
37
37
  config.ACCESS_TOKEN = access_token;
38
38
  // Set debug
@@ -75,16 +75,16 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
75
75
  }
76
76
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
77
77
  var response, filteredResponse, error_1, resError, resError;
78
- var _a, _b, _c;
79
- return __generator(this, function (_d) {
80
- switch (_d.label) {
78
+ var _a, _b, _c, _d, _e, _f, _g;
79
+ return __generator(this, function (_h) {
80
+ switch (_h.label) {
81
81
  case 0:
82
- _d.trys.push([0, 2, , 3]);
82
+ _h.trys.push([0, 2, , 3]);
83
83
  return [4 /*yield*/, axios_1.default.get(url, {
84
84
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
85
85
  })];
86
86
  case 1:
87
- response = _d.sent();
87
+ response = _h.sent();
88
88
  filteredResponse = removeNullError(response.data);
89
89
  if (debug) {
90
90
  console.log("GET_ResponseData", url, filteredResponse);
@@ -92,12 +92,12 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
92
92
  resolve(filteredResponse);
93
93
  return [3 /*break*/, 3];
94
94
  case 2:
95
- error_1 = _d.sent();
95
+ error_1 = _h.sent();
96
96
  if (axios_1.default.isAxiosError(error_1)) {
97
97
  resError = {
98
98
  httpStatus: ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
99
- mtsCode: ((_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 0,
100
- message: ((_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
99
+ mtsCode: ((_d = (_c = (_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
100
+ message: ((_g = (_f = (_e = error_1.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error",
101
101
  };
102
102
  if (debug) {
103
103
  console.log("GET_ResponseError", url, resError);
@@ -125,16 +125,16 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
125
125
  }
126
126
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
127
127
  var response, filteredResponse, error_2, resError;
128
- var _a, _b, _c, _d, _e;
129
- return __generator(this, function (_f) {
130
- switch (_f.label) {
128
+ var _a, _b, _c, _d, _e, _f, _g;
129
+ return __generator(this, function (_h) {
130
+ switch (_h.label) {
131
131
  case 0:
132
- _f.trys.push([0, 2, , 3]);
132
+ _h.trys.push([0, 2, , 3]);
133
133
  return [4 /*yield*/, axios_1.default.post(url, data, {
134
134
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
135
135
  })];
136
136
  case 1:
137
- response = _f.sent();
137
+ response = _h.sent();
138
138
  filteredResponse = removeNullError(response.data);
139
139
  if (debug) {
140
140
  console.log("POST_ResponseData", url, filteredResponse);
@@ -142,12 +142,12 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
142
142
  resolve(filteredResponse);
143
143
  return [3 /*break*/, 3];
144
144
  case 2:
145
- error_2 = _f.sent();
145
+ error_2 = _h.sent();
146
146
  if (axios_1.default.isAxiosError(error_2)) {
147
147
  resError = {
148
148
  httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
149
- mtsCode: ((_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error) === null || _c === void 0 ? void 0 : _c.code) || 500,
150
- message: ((_e = (_d = error_2.response) === null || _d === void 0 ? void 0 : _d.data.error) === null || _e === void 0 ? void 0 : _e.message) || "Unknown error",
149
+ mtsCode: ((_d = (_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 500,
150
+ message: ((_g = (_f = (_e = error_2.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error",
151
151
  };
152
152
  if (debug) {
153
153
  console.log("POST_ResponseError", url, resError);
@@ -175,16 +175,16 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
175
175
  }
176
176
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
177
177
  var response, filteredResponse, error_3, resError;
178
- var _a, _b, _c, _d, _e;
179
- return __generator(this, function (_f) {
180
- switch (_f.label) {
178
+ var _a, _b, _c, _d, _e, _f, _g;
179
+ return __generator(this, function (_h) {
180
+ switch (_h.label) {
181
181
  case 0:
182
- _f.trys.push([0, 2, , 3]);
182
+ _h.trys.push([0, 2, , 3]);
183
183
  return [4 /*yield*/, axios_1.default.delete(url, {
184
184
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
185
185
  })];
186
186
  case 1:
187
- response = _f.sent();
187
+ response = _h.sent();
188
188
  filteredResponse = removeNullError(response.data);
189
189
  if (debug) {
190
190
  console.log("DELETE_ResponseData", url, filteredResponse);
@@ -192,12 +192,12 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
192
192
  resolve(filteredResponse);
193
193
  return [3 /*break*/, 3];
194
194
  case 2:
195
- error_3 = _f.sent();
195
+ error_3 = _h.sent();
196
196
  if (axios_1.default.isAxiosError(error_3)) {
197
197
  resError = {
198
198
  httpStatus: ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
199
- mtsCode: ((_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data.error) === null || _c === void 0 ? void 0 : _c.code) || 500,
200
- message: ((_e = (_d = error_3.response) === null || _d === void 0 ? void 0 : _d.data.error) === null || _e === void 0 ? void 0 : _e.message) || "Unknown error",
199
+ mtsCode: ((_d = (_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 500,
200
+ message: ((_g = (_f = (_e = error_3.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error",
201
201
  };
202
202
  if (debug) {
203
203
  console.log("DELETE_ResponseError", url, resError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.32",
3
+ "version": "1.2.34",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",