mts-booking-library 1.2.11 → 1.2.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -61,9 +61,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
61
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
62
  }
63
63
  };
64
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
+ if (ar || !(i in from)) {
67
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
+ ar[i] = from[i];
69
+ }
70
+ }
71
+ return to.concat(ar || Array.prototype.slice.call(from));
72
+ };
64
73
  Object.defineProperty(exports, "__esModule", { value: true });
65
74
  exports.SubscriptionBooking = void 0;
66
75
  var ErrorResponse_1 = require("../types/ErrorResponse");
76
+ var Reduction_1 = require("../types/common/Reduction");
67
77
  var processBookingSteps_1 = require("../utils/processBookingSteps");
68
78
  var booking_1 = require("./booking");
69
79
  var SubscriptionBooking = /** @class */ (function (_super) {
@@ -446,6 +456,273 @@ var SubscriptionBooking = /** @class */ (function (_super) {
446
456
  });
447
457
  });
448
458
  };
459
+ //#region Reductions APIs
460
+ /**
461
+ * @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
462
+ * @param {AddReductionRequest} request The information about the reduction to add
463
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
464
+ */
465
+ SubscriptionBooking.prototype.addReduction = function (request) {
466
+ var _a;
467
+ return __awaiter(this, void 0, void 0, function () {
468
+ var discountsStep, _b, _c, _d, _i, step, url;
469
+ var _this = this;
470
+ return __generator(this, function (_e) {
471
+ switch (_e.label) {
472
+ case 0:
473
+ // First check that it is possible to call this API
474
+ if (!this.cartId || this.cartId === 0) {
475
+ throw Error("Cart is not initialized yet");
476
+ }
477
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
478
+ if (!discountsStep)
479
+ throw Error("Booking step not found!");
480
+ if (!!discountsStep[0]) return [3 /*break*/, 5];
481
+ _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
482
+ _c = [];
483
+ for (_d in _b)
484
+ _c.push(_d);
485
+ _i = 0;
486
+ _e.label = 1;
487
+ case 1:
488
+ if (!(_i < _c.length)) return [3 /*break*/, 4];
489
+ _d = _c[_i];
490
+ if (!(_d in _b)) return [3 /*break*/, 3];
491
+ step = _d;
492
+ if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
493
+ return [4 /*yield*/, this.markBookingStepCompleted(step)];
494
+ case 2:
495
+ _e.sent();
496
+ _e.label = 3;
497
+ case 3:
498
+ _i++;
499
+ return [3 /*break*/, 1];
500
+ case 4:
501
+ // Check again if the discounts step is accessible
502
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
503
+ if (!discountsStep || !discountsStep[0]) {
504
+ throw Error("The status of the cart does not allow to call this API");
505
+ }
506
+ _e.label = 5;
507
+ case 5:
508
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction");
509
+ return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
510
+ var _a, _b;
511
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
512
+ return response;
513
+ }
514
+ var reductionResponse = response;
515
+ // Update the booking process status
516
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
517
+ // Update the cart
518
+ _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: __spreadArray(__spreadArray([], ((_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) !== null && _b !== void 0 ? _b : []), true), [reductionResponse.reduction], false) });
519
+ return true;
520
+ })];
521
+ }
522
+ });
523
+ });
524
+ };
525
+ /**
526
+ * @description This method allows to remove a reduction from the whole cart or from a single trip in the cart.
527
+ * @param tripId The id of the trip from which the reduction should be removed. If the tripId is 0, then the reduction
528
+ * will be removed from the whole cart.
529
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
530
+ */
531
+ SubscriptionBooking.prototype.removeReduction = function (tripId) {
532
+ return __awaiter(this, void 0, void 0, function () {
533
+ var discountsStep, queryParams, url;
534
+ var _this = this;
535
+ return __generator(this, function (_a) {
536
+ // First check that it is possible to call this API
537
+ if (!this.cartId || this.cartId === 0) {
538
+ throw Error("Cart is not initialized yet");
539
+ }
540
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
541
+ if (!discountsStep || !discountsStep[0]) {
542
+ throw Error("The status of the cart does not allow to call this API");
543
+ }
544
+ queryParams = new URLSearchParams({ tripId: tripId.toString() });
545
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
546
+ return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
547
+ var _a, _b, _c;
548
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
549
+ return response;
550
+ }
551
+ var reductionResponse = response;
552
+ // Update the booking process status
553
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
554
+ // Update the cart
555
+ _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) { return reduction.type === Reduction_1.ReductionType.WALLET ||
556
+ reduction.type === Reduction_1.ReductionType.VOUCHER ||
557
+ (reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId); })) !== null && _c !== void 0 ? _c : [] });
558
+ return true;
559
+ })];
560
+ });
561
+ });
562
+ };
563
+ /**
564
+ * @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
565
+ * the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
566
+ * remaining amount with another payment method.
567
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
568
+ */
569
+ SubscriptionBooking.prototype.useWallet = function () {
570
+ var _a;
571
+ return __awaiter(this, void 0, void 0, function () {
572
+ var discountsStep, _b, _c, _d, _i, step, url;
573
+ var _this = this;
574
+ return __generator(this, function (_e) {
575
+ switch (_e.label) {
576
+ case 0:
577
+ // First check that it is possible to call this API
578
+ if (!this.cartId || this.cartId === 0) {
579
+ throw Error("Cart is not initialized yet");
580
+ }
581
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
582
+ if (!discountsStep)
583
+ throw Error("Booking step not found!");
584
+ if (!!discountsStep[0]) return [3 /*break*/, 5];
585
+ _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
586
+ _c = [];
587
+ for (_d in _b)
588
+ _c.push(_d);
589
+ _i = 0;
590
+ _e.label = 1;
591
+ case 1:
592
+ if (!(_i < _c.length)) return [3 /*break*/, 4];
593
+ _d = _c[_i];
594
+ if (!(_d in _b)) return [3 /*break*/, 3];
595
+ step = _d;
596
+ if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
597
+ return [4 /*yield*/, this.markBookingStepCompleted(step)];
598
+ case 2:
599
+ _e.sent();
600
+ _e.label = 3;
601
+ case 3:
602
+ _i++;
603
+ return [3 /*break*/, 1];
604
+ case 4:
605
+ // Check again if the discounts step is accessible
606
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
607
+ if (!discountsStep || !discountsStep[0]) {
608
+ throw Error("The status of the cart does not allow to call this API");
609
+ }
610
+ _e.label = 5;
611
+ case 5:
612
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
613
+ return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
614
+ var _a, _b;
615
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
616
+ return response;
617
+ }
618
+ var reductionResponse = response;
619
+ // Update the booking process status
620
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
621
+ // Update the cart
622
+ _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: __spreadArray(__spreadArray([], ((_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) !== null && _b !== void 0 ? _b : []), true), [reductionResponse.reduction], false) });
623
+ return true;
624
+ })];
625
+ }
626
+ });
627
+ });
628
+ };
629
+ /**
630
+ * @description This method allows to remove a waller reduction from the cart.
631
+ *
632
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
633
+ */
634
+ SubscriptionBooking.prototype.removeWalletReduction = function () {
635
+ return __awaiter(this, void 0, void 0, function () {
636
+ var url;
637
+ var _this = this;
638
+ return __generator(this, function (_a) {
639
+ // First check that it is possible to call this API
640
+ if (!this.cartId || this.cartId === 0) {
641
+ throw Error("Cart is not initialized yet");
642
+ }
643
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
644
+ return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
645
+ var _a, _b, _c;
646
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
647
+ return response;
648
+ }
649
+ var reductionResponse = response;
650
+ // Update the booking process status
651
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
652
+ // Update the cart
653
+ _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) { return reduction.type !== Reduction_1.ReductionType.WALLET; })) !== null && _c !== void 0 ? _c : [] });
654
+ return true;
655
+ })];
656
+ });
657
+ });
658
+ };
659
+ /**
660
+ * @description This method allows the user to use a voucher to pay the cart.
661
+ * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
662
+ * Otherwise, the user will be asked to pay the remaining amount with another payment method.
663
+ * @param {string} voucherCode The code of the voucher to use
664
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
665
+ */
666
+ SubscriptionBooking.prototype.useVoucher = function (voucherCode) {
667
+ var _a;
668
+ return __awaiter(this, void 0, void 0, function () {
669
+ var discountsStep, _b, _c, _d, _i, step, url;
670
+ var _this = this;
671
+ return __generator(this, function (_e) {
672
+ switch (_e.label) {
673
+ case 0:
674
+ // First check that it is possible to call this API
675
+ if (!this.cartId || this.cartId === 0) {
676
+ throw Error("Cart is not initialized yet");
677
+ }
678
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
679
+ if (!discountsStep)
680
+ throw Error("Booking step not found!");
681
+ if (!!discountsStep[0]) return [3 /*break*/, 5];
682
+ _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
683
+ _c = [];
684
+ for (_d in _b)
685
+ _c.push(_d);
686
+ _i = 0;
687
+ _e.label = 1;
688
+ case 1:
689
+ if (!(_i < _c.length)) return [3 /*break*/, 4];
690
+ _d = _c[_i];
691
+ if (!(_d in _b)) return [3 /*break*/, 3];
692
+ step = _d;
693
+ if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
694
+ return [4 /*yield*/, this.markBookingStepCompleted(step)];
695
+ case 2:
696
+ _e.sent();
697
+ _e.label = 3;
698
+ case 3:
699
+ _i++;
700
+ return [3 /*break*/, 1];
701
+ case 4:
702
+ // Check again if the discounts step is accessible
703
+ discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
704
+ if (!discountsStep || !discountsStep[0]) {
705
+ throw Error("The status of the cart does not allow to call this API");
706
+ }
707
+ _e.label = 5;
708
+ case 5:
709
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/voucher");
710
+ return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
711
+ var _a, _b;
712
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
713
+ return response;
714
+ }
715
+ var reductionResponse = response;
716
+ // Update the booking process status
717
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
718
+ // Update the cart
719
+ _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: __spreadArray(__spreadArray([], ((_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) !== null && _b !== void 0 ? _b : []), true), [reductionResponse.reduction], false) });
720
+ return true;
721
+ })];
722
+ }
723
+ });
724
+ });
725
+ };
449
726
  return SubscriptionBooking;
450
727
  }(booking_1.Booking));
451
728
  exports.SubscriptionBooking = SubscriptionBooking;
@@ -34,3 +34,16 @@ export type Cart = {
34
34
  totalAmountToPay: number;
35
35
  extras: Extra[];
36
36
  };
37
+ /**
38
+ * Base response type for the booking process. All APIs that update the cart, share this.
39
+ *
40
+ * @property {Map<string, boolean[]>} stepsToStatus This data structure describes the steps of the booking process.
41
+ * The keys of this dictionary represent the booking steps. See ... for the list of possible steps. If the
42
+ * key is present, then the booking step shall be displayed. The value is a list of 3 booleans:
43
+ * - The first tells whether it is possible to go to that section. If not, other sections must be completed first.
44
+ * - The second tells whether the section is completed.
45
+ * - The third tells whether the section is required.
46
+ */
47
+ export type BaseBookingProcessResponse = {
48
+ stepsToStatus: Map<string, boolean[]>;
49
+ };
@@ -1,6 +1,13 @@
1
+ import { BaseBookingProcessResponse } from "./Cart";
2
+ export declare enum ReductionType {
3
+ VOUCHER = "VOUCHER",
4
+ WALLET = "WALLET",
5
+ CASH = "CASH"
6
+ }
1
7
  /**
2
8
  * @description This type represents a reduction applied to the cart. Reductions are applied in the booking step `DISCOUNTS`.
3
9
  *
10
+ * @property {ReductionType} type The type of the reduction
4
11
  * @property {number} tripId The id of the trip to which the reduction is applied
5
12
  * @property {string} tripName The name of the trip to which the reduction is applied
6
13
  * @property {number} value The value of the reduction
@@ -9,6 +16,7 @@
9
16
  * @property {string} [voucherCode=undefined] The voucher code used to apply the reduction
10
17
  */
11
18
  export type Reduction = {
19
+ type: ReductionType;
12
20
  tripId: number;
13
21
  tripName: string;
14
22
  value: number;
@@ -29,3 +37,22 @@ export type AddReductionRequest = {
29
37
  reduction: number;
30
38
  isPercentage: boolean;
31
39
  };
40
+ /**
41
+ * @description This type represents a response to add a reduction to the cart. It is used in the APIs
42
+ * {@link Booking.addReduction}, {@link Booking.useVoucher} and {@link Booking.useWallet}
43
+ *
44
+ * @property {Reduction} reduction Information about the reduction applied
45
+ */
46
+ export type ReductionResponse = BaseReductionResponse & {
47
+ reduction: Reduction;
48
+ };
49
+ /**
50
+ * @description This type represents a base response to handle reduction in the cart. It is used in the APIs
51
+ * {@link Booking.addReduction}, {@link Booking.removeReduction} {@link Booking.useVoucher}, {@link Booking.useWallet}
52
+ * and {@link Booking.removeWalletReduction}
53
+ *
54
+ * @property {number} totalAmountToPay The total amount to pay after the reduction was applied
55
+ */
56
+ export type BaseReductionResponse = BaseBookingProcessResponse & {
57
+ totalAmountToPay: number;
58
+ };
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReductionType = void 0;
4
+ var ReductionType;
5
+ (function (ReductionType) {
6
+ ReductionType["VOUCHER"] = "VOUCHER";
7
+ ReductionType["WALLET"] = "WALLET";
8
+ ReductionType["CASH"] = "CASH";
9
+ })(ReductionType || (exports.ReductionType = ReductionType = {}));
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @module apiCall - This module contains the functions to make the API calls to the MTS API
3
+ * It contains the following functions:
4
+ * @method makeGet - Makes a GET request to the MTS API
5
+ * @method makePost - Makes a POST request to the MTS API
6
+ * @method makeDelete - Makes a DELETE request to the MTS API
7
+ */
1
8
  import { ErrorResponse } from "../types/ErrorResponse";
2
9
  export declare const makeGet: (url: string) => Promise<ErrorResponse | any>;
3
10
  export declare const makePost: (url: string, data: any) => Promise<ErrorResponse | any>;
11
+ export declare const makeDelete: (url: string) => Promise<ErrorResponse | any>;
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * @module apiCall - This module contains the functions to make the API calls to the MTS API
4
+ * It contains the following functions:
5
+ * @method makeGet - Makes a GET request to the MTS API
6
+ * @method makePost - Makes a POST request to the MTS API
7
+ * @method makeDelete - Makes a DELETE request to the MTS API
8
+ */
2
9
  var __assign = (this && this.__assign) || function () {
3
10
  __assign = Object.assign || function(t) {
4
11
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -47,7 +54,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
54
  }
48
55
  };
49
56
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.makePost = exports.makeGet = void 0;
57
+ exports.makeDelete = exports.makePost = exports.makeGet = void 0;
51
58
  var axios_1 = require("axios");
52
59
  var config_1 = require("../config");
53
60
  var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
@@ -55,7 +62,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
55
62
  return __generator(this, function (_a) {
56
63
  debug = (0, config_1.getConfig)().DEBUG;
57
64
  if (debug) {
58
- console.log("GetRequestData", url);
65
+ console.log("GET_RequestData", url);
59
66
  }
60
67
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
61
68
  var response_1, filteredResponse_1, error_1, resError, resError;
@@ -76,7 +83,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
76
83
  return filteredResponse_1 = __assign(__assign({}, filteredResponse_1), (_a = {}, _a[key] = response_1.data[key], _a));
77
84
  });
78
85
  if (debug) {
79
- console.log("GetResponseData", url, filteredResponse_1);
86
+ console.log("GET_ResponseData", url, filteredResponse_1);
80
87
  }
81
88
  resolve(filteredResponse_1);
82
89
  return [3 /*break*/, 3];
@@ -89,7 +96,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
89
96
  message: ((_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
90
97
  };
91
98
  if (debug) {
92
- console.log("GetResponseError", url, resError);
99
+ console.log("GET_ResponseError", url, resError);
93
100
  }
94
101
  reject(resError);
95
102
  }
@@ -110,7 +117,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
110
117
  return __generator(this, function (_a) {
111
118
  debug = (0, config_1.getConfig)().DEBUG;
112
119
  if (debug) {
113
- console.log("PostRequestData", url, data);
120
+ console.log("POST_RequestData", url, data);
114
121
  }
115
122
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
116
123
  var response, error_2, resError;
@@ -125,7 +132,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
125
132
  case 1:
126
133
  response = _f.sent();
127
134
  if (debug) {
128
- console.log("PostResponseData", url, response.data);
135
+ console.log("POST_ResponseData", url, response.data);
129
136
  }
130
137
  resolve(response.data);
131
138
  return [3 /*break*/, 3];
@@ -138,7 +145,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
138
145
  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",
139
146
  };
140
147
  if (debug) {
141
- console.log("GetResponseError", url, resError);
148
+ console.log("POST_ResponseError", url, resError);
142
149
  }
143
150
  reject(resError);
144
151
  }
@@ -154,3 +161,52 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
154
161
  });
155
162
  }); };
156
163
  exports.makePost = makePost;
164
+ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, function () {
165
+ var debug;
166
+ return __generator(this, function (_a) {
167
+ debug = (0, config_1.getConfig)().DEBUG;
168
+ if (debug) {
169
+ console.log("DELETE_RequestData", url);
170
+ }
171
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
172
+ var response, error_3, resError;
173
+ var _a, _b, _c, _d, _e;
174
+ return __generator(this, function (_f) {
175
+ switch (_f.label) {
176
+ case 0:
177
+ _f.trys.push([0, 2, , 3]);
178
+ return [4 /*yield*/, axios_1.default.delete(url, {
179
+ 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) })),
180
+ })];
181
+ case 1:
182
+ response = _f.sent();
183
+ if (debug) {
184
+ console.log("DELETE_ResponseData", url, response.data);
185
+ }
186
+ resolve(response.data);
187
+ return [3 /*break*/, 3];
188
+ case 2:
189
+ error_3 = _f.sent();
190
+ if (axios_1.default.isAxiosError(error_3)) {
191
+ resError = {
192
+ httpStatus: ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
193
+ mtsCode: ((_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data.error) === null || _c === void 0 ? void 0 : _c.code) || 500,
194
+ 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",
195
+ };
196
+ if (debug) {
197
+ console.log("DELETE_ResponseError", url, resError);
198
+ }
199
+ reject(resError);
200
+ }
201
+ else {
202
+ // Not a axios error, return the error as is
203
+ reject(error_3);
204
+ }
205
+ return [3 /*break*/, 3];
206
+ case 3: return [2 /*return*/];
207
+ }
208
+ });
209
+ }); })];
210
+ });
211
+ }); };
212
+ exports.makeDelete = makeDelete;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",