mts-booking-library 2.0.1 → 2.1.1

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.
@@ -130,12 +130,12 @@ var TplBooking = /** @class */ (function (_super) {
130
130
  console.log(e);
131
131
  }
132
132
  };
133
- TplBooking.prototype.fetchAndSetCart = function (cartGuid) {
133
+ TplBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
135
  var _this = this;
136
136
  return __generator(this, function (_a) {
137
137
  switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.fetchCart(cartGuid).then(function (cart) {
138
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options).then(function (cart) {
139
139
  if (cart) {
140
140
  var cartDueDate = new Date();
141
141
  cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
@@ -161,13 +161,13 @@ var TplBooking = /** @class */ (function (_super) {
161
161
  });
162
162
  });
163
163
  };
164
- TplBooking.prototype.fetchCart = function (cartGuid) {
164
+ TplBooking.prototype.fetchCart = function (cartGuid, options) {
165
165
  return __awaiter(this, void 0, void 0, function () {
166
166
  var url;
167
167
  var _this = this;
168
168
  return __generator(this, function (_a) {
169
169
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: cartGuid }));
170
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
170
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
171
171
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
172
172
  _this.resetBooking();
173
173
  throw new Error(JSON.stringify(response, null, 2));
@@ -186,7 +186,7 @@ var TplBooking = /** @class */ (function (_super) {
186
186
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
187
187
  * data will be deleted.
188
188
  */
189
- TplBooking.prototype.deleteCart = function () {
189
+ TplBooking.prototype.deleteCart = function (options) {
190
190
  return __awaiter(this, void 0, void 0, function () {
191
191
  var url;
192
192
  var _this = this;
@@ -196,7 +196,7 @@ var TplBooking = /** @class */ (function (_super) {
196
196
  throw Error("Cart is not initialized yet");
197
197
  }
198
198
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
199
- return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
199
+ return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
200
200
  // Clear all data
201
201
  _this.resetBooking();
202
202
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
@@ -209,12 +209,12 @@ var TplBooking = /** @class */ (function (_super) {
209
209
  * @returns An array of {@link City} objects representing the cities where it is possible to book a TPL service
210
210
  * if the call is successful, an {@link ErrorResponse} object otherwise.
211
211
  */
212
- TplBooking.prototype.getCities = function () {
212
+ TplBooking.prototype.getCities = function (options) {
213
213
  return __awaiter(this, void 0, void 0, function () {
214
214
  var url;
215
215
  return __generator(this, function (_a) {
216
216
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
217
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
217
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
218
218
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
219
219
  ? response
220
220
  : response.cities;
@@ -227,13 +227,13 @@ var TplBooking = /** @class */ (function (_super) {
227
227
  * the TPL service is available at a certain price.
228
228
  * @returns An array of {@link SuperArea} objects representing the SuperAreas if the call is successful, an {@link ErrorResponse} object otherwise.
229
229
  */
230
- TplBooking.prototype.getSuperAreas = function (request) {
230
+ TplBooking.prototype.getSuperAreas = function (request, options) {
231
231
  return __awaiter(this, void 0, void 0, function () {
232
232
  var searchParams, url;
233
233
  return __generator(this, function (_a) {
234
234
  searchParams = new URLSearchParams(__assign(__assign({ includeBasicInfo: "true", includeAreaIds: "false", includeTariffIds: "false", includeRouteIds: "false" }, (request.cityId && { cityId: request.cityId.toString() })), (request.tripId && { tripId: request.tripId.toString() })));
235
235
  url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
236
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
236
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
237
237
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
238
238
  ? response
239
239
  : response.superAreas;
@@ -245,13 +245,13 @@ var TplBooking = /** @class */ (function (_super) {
245
245
  * This method fetches the list of terms types in a given super area.
246
246
  * @returns An array of {@link TermsType} objects representing the available terms types if the call is successful, an {@link ErrorResponse} object otherwise.
247
247
  */
248
- TplBooking.prototype.getTermsTypes = function (superAreaId) {
248
+ TplBooking.prototype.getTermsTypes = function (superAreaId, options) {
249
249
  return __awaiter(this, void 0, void 0, function () {
250
250
  var searchParams, url;
251
251
  return __generator(this, function (_a) {
252
252
  searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
253
253
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/termsTypesBySuperArea?").concat(searchParams);
254
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
254
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
255
255
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.termsTypes;
256
256
  })];
257
257
  });
@@ -261,13 +261,13 @@ var TplBooking = /** @class */ (function (_super) {
261
261
  * This method fetches the list of tariff types in a given super area.
262
262
  * @returns An array of {@link TariffType} objects representing the available tariff types if the call is successful, an {@link ErrorResponse} object otherwise.
263
263
  */
264
- TplBooking.prototype.getTariffTypes = function (superAreaId) {
264
+ TplBooking.prototype.getTariffTypes = function (superAreaId, options) {
265
265
  return __awaiter(this, void 0, void 0, function () {
266
266
  var searchParams, url;
267
267
  return __generator(this, function (_a) {
268
268
  searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
269
269
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffTypesBySuperArea?").concat(searchParams);
270
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
270
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
271
271
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
272
272
  ? response
273
273
  : response.tariffTypes;
@@ -277,21 +277,21 @@ var TplBooking = /** @class */ (function (_super) {
277
277
  };
278
278
  /**
279
279
  * This method fetches the list of available tariffs for the selected terms type in a given super area.
280
- * @param {number} superAreaId The id of the super area (as returned by the {@link getSuperAreas} method).
281
- * @param {number | null} termsTypeId The id of the terms type (as returned by the {@link getTermsTypes} method).
280
+ * @param superAreaId The id of the super area (as returned by the {@link getSuperAreas} method).
281
+ * @param termsTypeId The id of the terms type (as returned by the {@link getTermsTypes} method).
282
282
  * If null, tariffs from all terms types will be considered.
283
- * @param {boolean} onlyTickets If true, only only return the tariffs that are for single tickets.
284
- * @param {boolean} onlySubscriptions If true, only return the tariffs that are for subscriptions.
283
+ * @param onlyTickets If true, only only return the tariffs that are for single tickets.
284
+ * @param onlySubscriptions If true, only return the tariffs that are for subscriptions.
285
285
  * @returns A {@link GetTariffsResponse} if the call is successful, an {@link ErrorResponse} object otherwise.
286
286
  */
287
- TplBooking.prototype.getTariffs = function (superAreaId, termsTypeId, onlyTickets, onlySubscriptions) {
287
+ TplBooking.prototype.getTariffs = function (superAreaId, termsTypeId, onlyTickets, onlySubscriptions, options) {
288
288
  return __awaiter(this, void 0, void 0, function () {
289
289
  var searchParams, url;
290
290
  return __generator(this, function (_a) {
291
291
  searchParams = new URLSearchParams(__assign(__assign({ superAreaId: superAreaId.toString() }, (termsTypeId && { termsTypeId: termsTypeId.toString() })), { onlyTickets: onlyTickets.toString(), onlySubscriptions: onlySubscriptions.toString() }));
292
292
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffs?").concat(searchParams);
293
293
  // Call the API
294
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
294
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
295
295
  // Check for error
296
296
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
297
297
  return response;
@@ -315,7 +315,7 @@ var TplBooking = /** @class */ (function (_super) {
315
315
  /**
316
316
  * This method allows to create a TPL cart.
317
317
  */
318
- TplBooking.prototype.createTplCart = function (tplCart) {
318
+ TplBooking.prototype.createTplCart = function (tplCart, options) {
319
319
  return __awaiter(this, void 0, void 0, function () {
320
320
  var url, processedTariffIdToQuantity, request;
321
321
  var _this = this;
@@ -329,7 +329,7 @@ var TplBooking = /** @class */ (function (_super) {
329
329
  renewSubscriptionTicketPNR: tplCart.renewSubscriptionTicketPNR
330
330
  })), (tplCart.otaResellerId !== undefined && { otaResellerId: tplCart.otaResellerId })), (tplCart.otaTicketPicture !== undefined && { otaTicketPicture: tplCart.otaTicketPicture }));
331
331
  // Call the API
332
- return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
332
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
333
333
  // Check for errors
334
334
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
335
335
  // If there was an error, reset cartGuid and remove it from the mts-storage
@@ -358,7 +358,7 @@ var TplBooking = /** @class */ (function (_super) {
358
358
  * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
359
359
  * as well as a list of the available tariffs for each trip.
360
360
  */
361
- TplBooking.prototype.getBuyerPassengersDetails = function () {
361
+ TplBooking.prototype.getBuyerPassengersDetails = function (options) {
362
362
  return __awaiter(this, void 0, void 0, function () {
363
363
  var buyerPassengersDetails, searchParams, url;
364
364
  return __generator(this, function (_a) {
@@ -372,7 +372,7 @@ var TplBooking = /** @class */ (function (_super) {
372
372
  }
373
373
  searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
374
374
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
375
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
375
+ return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
376
376
  // Check for errors
377
377
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
378
378
  return response;
@@ -394,7 +394,7 @@ var TplBooking = /** @class */ (function (_super) {
394
394
  * with the subscription. This parameter is required if the cart contains a subscription.
395
395
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
396
396
  */
397
- TplBooking.prototype.updateBuyerPassengersDetails = function (buyerDetails, subscriptionPersonCode) {
397
+ TplBooking.prototype.updateBuyerPassengersDetails = function (buyerDetails, subscriptionPersonCode, options) {
398
398
  return __awaiter(this, void 0, void 0, function () {
399
399
  var buyerPassengersDetails, request, url;
400
400
  var _this = this;
@@ -423,7 +423,7 @@ var TplBooking = /** @class */ (function (_super) {
423
423
  : []
424
424
  };
425
425
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
426
- return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
426
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
427
427
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
428
428
  return response;
429
429
  }
@@ -438,10 +438,10 @@ var TplBooking = /** @class */ (function (_super) {
438
438
  //#region Reductions APIs
439
439
  /**
440
440
  * @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
441
- * @param {AddReductionRequest} request The information about the reduction to add
441
+ * @param request The information about the reduction to add
442
442
  * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
443
443
  */
444
- TplBooking.prototype.addReduction = function (request) {
444
+ TplBooking.prototype.addReduction = function (request, options) {
445
445
  return __awaiter(this, void 0, void 0, function () {
446
446
  var discountsStep, _i, _a, step, url;
447
447
  var _this = this;
@@ -479,7 +479,7 @@ var TplBooking = /** @class */ (function (_super) {
479
479
  _c.label = 5;
480
480
  case 5:
481
481
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
482
- return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
482
+ return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
483
483
  var _a, _b;
484
484
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
485
485
  return response;
@@ -501,7 +501,7 @@ var TplBooking = /** @class */ (function (_super) {
501
501
  * will be removed from the whole cart.
502
502
  * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
503
503
  */
504
- TplBooking.prototype.removeReduction = function (tripId) {
504
+ TplBooking.prototype.removeReduction = function (tripId, options) {
505
505
  return __awaiter(this, void 0, void 0, function () {
506
506
  var discountsStep, queryParams, url;
507
507
  var _this = this;
@@ -519,7 +519,7 @@ var TplBooking = /** @class */ (function (_super) {
519
519
  cartGuid: this.cartGuid
520
520
  });
521
521
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
522
- return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
522
+ return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
523
523
  var _a, _b, _c;
524
524
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
525
525
  return response;
@@ -544,7 +544,7 @@ var TplBooking = /** @class */ (function (_super) {
544
544
  * remaining amount with another payment method.
545
545
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
546
546
  */
547
- TplBooking.prototype.useWallet = function () {
547
+ TplBooking.prototype.useWallet = function (options) {
548
548
  return __awaiter(this, void 0, void 0, function () {
549
549
  var issueStep, _i, _a, step, url;
550
550
  var _this = this;
@@ -586,7 +586,7 @@ var TplBooking = /** @class */ (function (_super) {
586
586
  _c.label = 5;
587
587
  case 5:
588
588
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
589
- return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
589
+ return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
590
590
  var _a, _b;
591
591
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
592
592
  return response;
@@ -607,7 +607,7 @@ var TplBooking = /** @class */ (function (_super) {
607
607
  *
608
608
  * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
609
609
  */
610
- TplBooking.prototype.removeWalletReduction = function () {
610
+ TplBooking.prototype.removeWalletReduction = function (options) {
611
611
  return __awaiter(this, void 0, void 0, function () {
612
612
  var queryParams, url;
613
613
  var _this = this;
@@ -620,7 +620,7 @@ var TplBooking = /** @class */ (function (_super) {
620
620
  cartGuid: this.cartGuid
621
621
  });
622
622
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
623
- return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
623
+ return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
624
624
  var _a, _b, _c;
625
625
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
626
626
  return response;
@@ -639,10 +639,10 @@ var TplBooking = /** @class */ (function (_super) {
639
639
  * @description This method allows the user to use a voucher to pay the cart.
640
640
  * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
641
641
  * Otherwise, the user will be asked to pay the remaining amount with another payment method.
642
- * @param {string} voucherCode The code of the voucher to use
642
+ * @param voucherCode The code of the voucher to use
643
643
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
644
644
  */
645
- TplBooking.prototype.useVoucher = function (voucherCode) {
645
+ TplBooking.prototype.useVoucher = function (voucherCode, options) {
646
646
  return __awaiter(this, void 0, void 0, function () {
647
647
  var discountsStep, _i, _a, step, url;
648
648
  var _this = this;
@@ -680,7 +680,7 @@ var TplBooking = /** @class */ (function (_super) {
680
680
  _c.label = 5;
681
681
  case 5:
682
682
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
683
- return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }).then(function (response) {
683
+ return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
684
684
  var _a, _b;
685
685
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
686
686
  return response;
@@ -5,8 +5,13 @@
5
5
  * @method makePost - Makes a POST request to the MTS API
6
6
  * @method makeDelete - Makes a DELETE request to the MTS API
7
7
  */
8
+ import { GenericAbortSignal } from "axios";
8
9
  import { ErrorResponse } from "../types/ErrorResponse";
9
- export declare const makeGet: (url: string) => Promise<ErrorResponse | any>;
10
- export declare const makePost: (url: string, data: any) => Promise<ErrorResponse | any>;
11
- export declare const makePut: (url: string, data: any) => Promise<ErrorResponse | any>;
12
- export declare const makeDelete: (url: string) => Promise<ErrorResponse | any>;
10
+ export interface ApiCallOptions {
11
+ /** An abort signal to be passed to Axios, in case you want to cancel the request */
12
+ signal?: GenericAbortSignal;
13
+ }
14
+ export declare const makeGet: (url: string, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
15
+ export declare const makePost: (url: string, data: any, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
16
+ export declare const makePut: (url: string, data: any, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
17
+ export declare const makeDelete: (url: string, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
@@ -68,7 +68,7 @@ var removeNullError = function (resData) {
68
68
  });
69
69
  return filteredResponse;
70
70
  };
71
- var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
71
+ var makeGet = function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
72
72
  var debug, subKey, errorReport;
73
73
  return __generator(this, function (_a) {
74
74
  debug = (0, config_1.getConfig)().DEBUG;
@@ -82,16 +82,17 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
82
82
  }
83
83
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
84
84
  var response, filteredResponse, error_1, message, resError, resError;
85
- var _a, _b, _c, _d, _e, _f, _g;
86
- return __generator(this, function (_h) {
87
- switch (_h.label) {
85
+ var _a, _b, _c, _d, _e, _f, _g, _h;
86
+ return __generator(this, function (_j) {
87
+ switch (_j.label) {
88
88
  case 0:
89
- _h.trys.push([0, 2, , 3]);
89
+ _j.trys.push([0, 2, , 3]);
90
90
  return [4 /*yield*/, axios_1.default.get(url, {
91
- headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
91
+ headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
92
+ signal: options === null || options === void 0 ? void 0 : options.signal
92
93
  })];
93
94
  case 1:
94
- response = _h.sent();
95
+ response = _j.sent();
95
96
  filteredResponse = removeNullError(response.data);
96
97
  if (debug) {
97
98
  console.log("GET_ResponseData", url, filteredResponse);
@@ -99,14 +100,14 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
99
100
  resolve(filteredResponse);
100
101
  return [3 /*break*/, 3];
101
102
  case 2:
102
- error_1 = _h.sent();
103
+ error_1 = _j.sent();
103
104
  if (axios_1.default.isAxiosError(error_1)) {
104
- message = "error" in ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data)
105
- ? (_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data.error.message
106
- : (_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.message;
105
+ message = ((_b = (_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
106
+ ? error_1.response.data.error.message
107
+ : (_d = (_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
107
108
  resError = {
108
- httpStatus: ((_d = error_1.response) === null || _d === void 0 ? void 0 : _d.status) || 0,
109
- mtsCode: ((_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.code) || 0,
109
+ httpStatus: ((_e = error_1.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
110
+ mtsCode: ((_h = (_g = (_f = error_1.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
110
111
  message: message || "Unknown error"
111
112
  };
112
113
  if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
@@ -129,7 +130,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
129
130
  });
130
131
  }); };
131
132
  exports.makeGet = makeGet;
132
- var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
133
+ var makePost = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
133
134
  var debug, subKey, errorReport;
134
135
  return __generator(this, function (_a) {
135
136
  debug = (0, config_1.getConfig)().DEBUG;
@@ -143,16 +144,17 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
143
144
  }
144
145
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
145
146
  var response, filteredResponse, error_2, message, resError, resError;
146
- var _a, _b, _c, _d, _e, _f, _g;
147
- return __generator(this, function (_h) {
148
- switch (_h.label) {
147
+ var _a, _b, _c, _d, _e, _f, _g, _h;
148
+ return __generator(this, function (_j) {
149
+ switch (_j.label) {
149
150
  case 0:
150
- _h.trys.push([0, 2, , 3]);
151
+ _j.trys.push([0, 2, , 3]);
151
152
  return [4 /*yield*/, axios_1.default.post(url, data, {
152
- headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
153
+ headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
154
+ signal: options === null || options === void 0 ? void 0 : options.signal
153
155
  })];
154
156
  case 1:
155
- response = _h.sent();
157
+ response = _j.sent();
156
158
  filteredResponse = removeNullError(response.data);
157
159
  if (debug) {
158
160
  console.log("POST_ResponseData", url, filteredResponse);
@@ -160,14 +162,14 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
160
162
  resolve(filteredResponse);
161
163
  return [3 /*break*/, 3];
162
164
  case 2:
163
- error_2 = _h.sent();
165
+ error_2 = _j.sent();
164
166
  if (axios_1.default.isAxiosError(error_2)) {
165
- message = "error" in ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.data)
166
- ? (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error.message
167
- : (_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data.message;
167
+ message = ((_b = (_a = error_2.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
168
+ ? error_2.response.data.error.message
169
+ : (_d = (_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
168
170
  resError = {
169
- httpStatus: ((_d = error_2.response) === null || _d === void 0 ? void 0 : _d.status) || 0,
170
- mtsCode: ((_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.code) || 0,
171
+ httpStatus: ((_e = error_2.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
172
+ mtsCode: ((_h = (_g = (_f = error_2.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
171
173
  message: message || "Unknown error"
172
174
  };
173
175
  if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
@@ -190,7 +192,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
190
192
  });
191
193
  }); };
192
194
  exports.makePost = makePost;
193
- var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
195
+ var makePut = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
194
196
  var debug, subKey, errorReport;
195
197
  return __generator(this, function (_a) {
196
198
  debug = (0, config_1.getConfig)().DEBUG;
@@ -204,16 +206,17 @@ var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, fu
204
206
  }
205
207
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
206
208
  var response, filteredResponse, error_3, message, resError, resError;
207
- var _a, _b, _c, _d, _e, _f, _g;
208
- return __generator(this, function (_h) {
209
- switch (_h.label) {
209
+ var _a, _b, _c, _d, _e, _f, _g, _h;
210
+ return __generator(this, function (_j) {
211
+ switch (_j.label) {
210
212
  case 0:
211
- _h.trys.push([0, 2, , 3]);
213
+ _j.trys.push([0, 2, , 3]);
212
214
  return [4 /*yield*/, axios_1.default.put(url, data, {
213
- headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
215
+ headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
216
+ signal: options === null || options === void 0 ? void 0 : options.signal
214
217
  })];
215
218
  case 1:
216
- response = _h.sent();
219
+ response = _j.sent();
217
220
  filteredResponse = removeNullError(response.data);
218
221
  if (debug) {
219
222
  console.log("PUT_ResponseData", url, filteredResponse);
@@ -221,14 +224,14 @@ var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, fu
221
224
  resolve(filteredResponse);
222
225
  return [3 /*break*/, 3];
223
226
  case 2:
224
- error_3 = _h.sent();
227
+ error_3 = _j.sent();
225
228
  if (axios_1.default.isAxiosError(error_3)) {
226
- message = "error" in ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.data)
227
- ? (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data.error.message
228
- : (_c = error_3.response) === null || _c === void 0 ? void 0 : _c.data.message;
229
+ message = ((_b = (_a = error_3.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
230
+ ? error_3.response.data.error.message
231
+ : (_d = (_c = error_3.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
229
232
  resError = {
230
- httpStatus: ((_d = error_3.response) === null || _d === void 0 ? void 0 : _d.status) || 0,
231
- mtsCode: ((_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.code) || 0,
233
+ httpStatus: ((_e = error_3.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
234
+ mtsCode: ((_h = (_g = (_f = error_3.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
232
235
  message: message || "Unknown error"
233
236
  };
234
237
  if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
@@ -251,7 +254,7 @@ var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, fu
251
254
  });
252
255
  }); };
253
256
  exports.makePut = makePut;
254
- var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, function () {
257
+ var makeDelete = function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
255
258
  var debug, subKey, errorReport;
256
259
  return __generator(this, function (_a) {
257
260
  debug = (0, config_1.getConfig)().DEBUG;
@@ -265,16 +268,17 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
265
268
  }
266
269
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
267
270
  var response, filteredResponse, error_4, message, resError, resError;
268
- var _a, _b, _c, _d, _e, _f, _g;
269
- return __generator(this, function (_h) {
270
- switch (_h.label) {
271
+ var _a, _b, _c, _d, _e, _f, _g, _h;
272
+ return __generator(this, function (_j) {
273
+ switch (_j.label) {
271
274
  case 0:
272
- _h.trys.push([0, 2, , 3]);
275
+ _j.trys.push([0, 2, , 3]);
273
276
  return [4 /*yield*/, axios_1.default.delete(url, {
274
- headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
277
+ headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
278
+ signal: options === null || options === void 0 ? void 0 : options.signal
275
279
  })];
276
280
  case 1:
277
- response = _h.sent();
281
+ response = _j.sent();
278
282
  filteredResponse = removeNullError(response.data);
279
283
  if (debug) {
280
284
  console.log("DELETE_ResponseData", url, filteredResponse);
@@ -282,14 +286,14 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
282
286
  resolve(filteredResponse);
283
287
  return [3 /*break*/, 3];
284
288
  case 2:
285
- error_4 = _h.sent();
289
+ error_4 = _j.sent();
286
290
  if (axios_1.default.isAxiosError(error_4)) {
287
- message = "error" in ((_a = error_4.response) === null || _a === void 0 ? void 0 : _a.data)
288
- ? (_b = error_4.response) === null || _b === void 0 ? void 0 : _b.data.error.message
289
- : (_c = error_4.response) === null || _c === void 0 ? void 0 : _c.data.message;
291
+ message = ((_b = (_a = error_4.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
292
+ ? error_4.response.data.error.message
293
+ : (_d = (_c = error_4.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
290
294
  resError = {
291
- httpStatus: ((_d = error_4.response) === null || _d === void 0 ? void 0 : _d.status) || 0,
292
- mtsCode: ((_g = (_f = (_e = error_4.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.code) || 0,
295
+ httpStatus: ((_e = error_4.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
296
+ mtsCode: ((_h = (_g = (_f = error_4.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
293
297
  message: message || "Unknown error"
294
298
  };
295
299
  if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
File without changes