mts-booking-library 2.2.2 → 2.2.3
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.
- package/lib/booking/booking.d.ts +2 -2
- package/lib/booking/booking.js +5 -11
- package/lib/booking/journeyBooking.js +14 -32
- package/lib/booking/serviceBooking.js +11 -24
- package/lib/booking/subscriptionBooking.js +10 -21
- package/lib/booking/tplBooking.js +12 -26
- package/lib/types/ErrorResponse.d.ts +6 -5
- package/lib/utils/apiCall.d.ts +4 -5
- package/lib/utils/apiCall.js +50 -228
- package/package.json +1 -1
package/lib/booking/booking.d.ts
CHANGED
@@ -40,10 +40,10 @@ export declare abstract class Booking {
|
|
40
40
|
* @param {string} access_token The new access token
|
41
41
|
*/
|
42
42
|
renewAccessToken(access_token: string): void;
|
43
|
-
callGetApi(url: string, options?: ApiCallOptions): Promise<
|
43
|
+
callGetApi(url: string, options?: ApiCallOptions): Promise<any>;
|
44
44
|
callPostApi(url: string, body: any, options?: ApiCallOptions): Promise<any>;
|
45
45
|
callPutApi(url: string, body: any, options?: ApiCallOptions): Promise<any>;
|
46
|
-
callDeleteApi(url: string, options?: ApiCallOptions): Promise<
|
46
|
+
callDeleteApi(url: string, options?: ApiCallOptions): Promise<any>;
|
47
47
|
getBookingStepsToStatus(): processedStepsToStatus;
|
48
48
|
changeCurrency(currency: Booking.Currencies): void;
|
49
49
|
changeLanguage(language: string): void;
|
package/lib/booking/booking.js
CHANGED
@@ -185,9 +185,8 @@ var Booking = /** @class */ (function () {
|
|
185
185
|
return [2 /*return*/, true];
|
186
186
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/bookingSteps");
|
187
187
|
return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep, cartGuid: this.cartGuid }, options).then(function (response) {
|
188
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
188
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
189
189
|
return response;
|
190
|
-
}
|
191
190
|
// Update the booking process status
|
192
191
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
193
192
|
return true;
|
@@ -220,9 +219,8 @@ var Booking = /** @class */ (function () {
|
|
220
219
|
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
221
220
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
222
221
|
// Check for errors
|
223
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
222
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
224
223
|
return response;
|
225
|
-
}
|
226
224
|
// Return the person details
|
227
225
|
var person = __assign(__assign({}, response.persons[0]), { socialSecurityNumber: response.persons[0].personDetails.socialSecurityNumber });
|
228
226
|
return person;
|
@@ -341,9 +339,8 @@ var Booking = /** @class */ (function () {
|
|
341
339
|
paymentMethodToSet = Payment_1.PaymentMethods.CASH;
|
342
340
|
return true;
|
343
341
|
}
|
344
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
342
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
345
343
|
return response;
|
346
|
-
}
|
347
344
|
})];
|
348
345
|
case 1:
|
349
346
|
_c.sent();
|
@@ -384,9 +381,7 @@ var Booking = /** @class */ (function () {
|
|
384
381
|
paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet
|
385
382
|
};
|
386
383
|
return [2 /*return*/, this.callPostApi(url, body, options).then(function (response) {
|
387
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
388
|
-
? response
|
389
|
-
: response;
|
384
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
390
385
|
})];
|
391
386
|
}
|
392
387
|
});
|
@@ -440,9 +435,8 @@ var Booking = /** @class */ (function () {
|
|
440
435
|
return [4 /*yield*/, this.callPutApi(url, body, options)];
|
441
436
|
case 1:
|
442
437
|
res = _a.sent();
|
443
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(res))
|
438
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(res))
|
444
439
|
return [2 /*return*/, res];
|
445
|
-
}
|
446
440
|
return [4 /*yield*/, this.fetchAndSetCart(cartGuid)];
|
447
441
|
case 2:
|
448
442
|
_a.sent();
|
@@ -198,7 +198,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
198
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
199
199
|
// Clear all data
|
200
200
|
_this.resetBooking();
|
201
|
-
return
|
201
|
+
return response;
|
202
202
|
})];
|
203
203
|
});
|
204
204
|
});
|
@@ -213,9 +213,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
213
213
|
return __generator(this, function (_a) {
|
214
214
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?");
|
215
215
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
216
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
217
|
-
? response
|
218
|
-
: response.stops;
|
216
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
|
219
217
|
})];
|
220
218
|
});
|
221
219
|
});
|
@@ -232,9 +230,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
232
230
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
233
231
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
|
234
232
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
235
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
236
|
-
? response
|
237
|
-
: response.stops;
|
233
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
|
238
234
|
})];
|
239
235
|
});
|
240
236
|
});
|
@@ -334,9 +330,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
334
330
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
335
331
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
336
332
|
// Check for errors
|
337
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
333
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
338
334
|
return response;
|
339
|
-
}
|
340
335
|
// For each passenger, parse the outbound and return tariffs
|
341
336
|
var passengers = response.passengers;
|
342
337
|
passengers.map(function (passenger) {
|
@@ -396,9 +391,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
396
391
|
});
|
397
392
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
398
393
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
399
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
394
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
400
395
|
return response;
|
401
|
-
}
|
402
396
|
// Update the booking process status
|
403
397
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
404
398
|
return true;
|
@@ -433,9 +427,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
433
427
|
});
|
434
428
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/seats?").concat(searchParams);
|
435
429
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
436
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
437
|
-
? response
|
438
|
-
: response.busMatrix;
|
430
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.busMatrix;
|
439
431
|
})];
|
440
432
|
});
|
441
433
|
});
|
@@ -463,9 +455,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
463
455
|
});
|
464
456
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats?").concat(searchParams);
|
465
457
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
466
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
467
|
-
? response
|
468
|
-
: response.assignedSeats;
|
458
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
|
469
459
|
})];
|
470
460
|
});
|
471
461
|
});
|
@@ -495,9 +485,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
495
485
|
newSeatsIds: newSeatsIds,
|
496
486
|
cartGuid: this.cart.guid
|
497
487
|
}, options).then(function (response) {
|
498
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
488
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
499
489
|
return response;
|
500
|
-
}
|
501
490
|
// Update the booking process status
|
502
491
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
503
492
|
return true;
|
@@ -523,9 +512,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
523
512
|
searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
|
524
513
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction/trips?").concat(searchParams);
|
525
514
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
526
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
527
|
-
? response
|
528
|
-
: response.trips;
|
515
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
|
529
516
|
})];
|
530
517
|
});
|
531
518
|
});
|
@@ -575,9 +562,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
575
562
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
576
563
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
577
564
|
var _a, _b;
|
578
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
565
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
579
566
|
return response;
|
580
|
-
}
|
581
567
|
var reductionResponse = response;
|
582
568
|
// Update the booking process status
|
583
569
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -615,9 +601,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
615
601
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
616
602
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
617
603
|
var _a, _b, _c;
|
618
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
604
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
619
605
|
return response;
|
620
|
-
}
|
621
606
|
var reductionResponse = response;
|
622
607
|
// Update the booking process status
|
623
608
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -682,9 +667,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
682
667
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
683
668
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
684
669
|
var _a, _b;
|
685
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
670
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
686
671
|
return response;
|
687
|
-
}
|
688
672
|
var reductionResponse = response;
|
689
673
|
// Update the booking process status
|
690
674
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -714,9 +698,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
714
698
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
715
699
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
716
700
|
var _a, _b, _c;
|
717
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
701
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
718
702
|
return response;
|
719
|
-
}
|
720
703
|
var reductionResponse = response;
|
721
704
|
// Update the booking process status
|
722
705
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -774,9 +757,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
774
757
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
775
758
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
776
759
|
var _a, _b;
|
777
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
760
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
778
761
|
return response;
|
779
|
-
}
|
780
762
|
var reductionResponse = response;
|
781
763
|
// Update the booking process status
|
782
764
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -198,7 +198,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
198
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
199
199
|
// Clear all data
|
200
200
|
_this.resetBooking();
|
201
|
-
return
|
201
|
+
return response;
|
202
202
|
})];
|
203
203
|
});
|
204
204
|
});
|
@@ -214,9 +214,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
214
214
|
return __generator(this, function (_a) {
|
215
215
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cities?");
|
216
216
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
217
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
218
|
-
? response
|
219
|
-
: response.cities;
|
217
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
|
220
218
|
})];
|
221
219
|
});
|
222
220
|
});
|
@@ -235,9 +233,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
235
233
|
searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
|
236
234
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services?").concat(searchParams);
|
237
235
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
238
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
239
|
-
? response
|
240
|
-
: response.services;
|
236
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.services;
|
241
237
|
})];
|
242
238
|
});
|
243
239
|
});
|
@@ -257,9 +253,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
257
253
|
searchParams = new URLSearchParams({ serviceId: serviceId.toString(), date: date });
|
258
254
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/trips?").concat(searchParams);
|
259
255
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
260
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
261
|
-
? response
|
262
|
-
: response;
|
256
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
263
257
|
})];
|
264
258
|
});
|
265
259
|
});
|
@@ -336,9 +330,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
336
330
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
337
331
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
338
332
|
// Check for errors
|
339
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
333
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
340
334
|
return response;
|
341
|
-
}
|
342
335
|
return {
|
343
336
|
buyerDataStatus: response.buyerDataStatus,
|
344
337
|
buyer: response.buyer,
|
@@ -374,9 +367,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
374
367
|
};
|
375
368
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
376
369
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
377
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
370
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
378
371
|
return response;
|
379
|
-
}
|
380
372
|
// Update the booking process status
|
381
373
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
382
374
|
return true;
|
@@ -431,9 +423,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
431
423
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
432
424
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
433
425
|
var _a, _b;
|
434
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
426
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
435
427
|
return response;
|
436
|
-
}
|
437
428
|
var reductionResponse = response;
|
438
429
|
// Update the booking process status
|
439
430
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -471,9 +462,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
471
462
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
472
463
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
473
464
|
var _a, _b, _c;
|
474
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
465
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
475
466
|
return response;
|
476
|
-
}
|
477
467
|
var reductionResponse = response;
|
478
468
|
// Update the booking process status
|
479
469
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -538,9 +528,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
538
528
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
539
529
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
540
530
|
var _a, _b;
|
541
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
531
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
542
532
|
return response;
|
543
|
-
}
|
544
533
|
var reductionResponse = response;
|
545
534
|
// Update the booking process status
|
546
535
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -572,9 +561,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
572
561
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
573
562
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
574
563
|
var _a, _b, _c;
|
575
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
564
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
576
565
|
return response;
|
577
|
-
}
|
578
566
|
var reductionResponse = response;
|
579
567
|
// Update the booking process status
|
580
568
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -632,9 +620,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
632
620
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
633
621
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
634
622
|
var _a, _b;
|
635
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
623
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
636
624
|
return response;
|
637
|
-
}
|
638
625
|
var reductionResponse = response;
|
639
626
|
// Update the booking process status
|
640
627
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -197,7 +197,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
197
197
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
|
198
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
199
199
|
_this.resetBooking();
|
200
|
-
return
|
200
|
+
return response;
|
201
201
|
})];
|
202
202
|
});
|
203
203
|
});
|
@@ -212,9 +212,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
212
212
|
return __generator(this, function (_a) {
|
213
213
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/departures?");
|
214
214
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
215
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
216
|
-
? response
|
217
|
-
: response.departures;
|
215
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.departures;
|
218
216
|
})];
|
219
217
|
});
|
220
218
|
});
|
@@ -231,9 +229,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
231
229
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
232
230
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/destinations?").concat(searchParams);
|
233
231
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
234
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
235
|
-
? response
|
236
|
-
: response.destinations;
|
232
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.destinations;
|
237
233
|
})];
|
238
234
|
});
|
239
235
|
});
|
@@ -393,9 +389,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
393
389
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
394
390
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
395
391
|
// Check for errors
|
396
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
392
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
397
393
|
return response;
|
398
|
-
}
|
399
394
|
// For each passenger, parse the outbound and return tariffs
|
400
395
|
var passengers = response.passengers;
|
401
396
|
passengers.map(function (passenger) {
|
@@ -455,9 +450,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
455
450
|
});
|
456
451
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
457
452
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
458
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
453
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
459
454
|
return response;
|
460
|
-
}
|
461
455
|
// Update the booking process status
|
462
456
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
463
457
|
return true;
|
@@ -511,9 +505,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
511
505
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
512
506
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
513
507
|
var _a, _b;
|
514
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
508
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
515
509
|
return response;
|
516
|
-
}
|
517
510
|
var reductionResponse = response;
|
518
511
|
// Update the booking process status
|
519
512
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -551,9 +544,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
551
544
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
552
545
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
553
546
|
var _a, _b, _c;
|
554
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
547
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
555
548
|
return response;
|
556
|
-
}
|
557
549
|
var reductionResponse = response;
|
558
550
|
// Update the booking process status
|
559
551
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -618,9 +610,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
618
610
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
619
611
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
620
612
|
var _a, _b;
|
621
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
613
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
622
614
|
return response;
|
623
|
-
}
|
624
615
|
var reductionResponse = response;
|
625
616
|
// Update the booking process status
|
626
617
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -652,9 +643,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
652
643
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
653
644
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
654
645
|
var _a, _b, _c;
|
655
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
646
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
656
647
|
return response;
|
657
|
-
}
|
658
648
|
var reductionResponse = response;
|
659
649
|
// Update the booking process status
|
660
650
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -712,9 +702,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
712
702
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
713
703
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
714
704
|
var _a, _b;
|
715
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
705
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
716
706
|
return response;
|
717
|
-
}
|
718
707
|
var reductionResponse = response;
|
719
708
|
// Update the booking process status
|
720
709
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -198,7 +198,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
198
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
199
199
|
// Clear all data
|
200
200
|
_this.resetBooking();
|
201
|
-
return
|
201
|
+
return response;
|
202
202
|
})];
|
203
203
|
});
|
204
204
|
});
|
@@ -214,9 +214,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
214
214
|
return __generator(this, function (_a) {
|
215
215
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
|
216
216
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
217
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
218
|
-
? response
|
219
|
-
: response.cities;
|
217
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
|
220
218
|
})];
|
221
219
|
});
|
222
220
|
});
|
@@ -233,9 +231,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
233
231
|
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() })));
|
234
232
|
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
|
235
233
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
236
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
237
|
-
? response
|
238
|
-
: response.superAreas;
|
234
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.superAreas;
|
239
235
|
})];
|
240
236
|
});
|
241
237
|
});
|
@@ -267,9 +263,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
267
263
|
searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
|
268
264
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffTypesBySuperArea?").concat(searchParams);
|
269
265
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
270
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
271
|
-
? response
|
272
|
-
: response.tariffTypes;
|
266
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.tariffTypes;
|
273
267
|
})];
|
274
268
|
});
|
275
269
|
});
|
@@ -292,9 +286,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
292
286
|
// Call the API
|
293
287
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
294
288
|
// Check for error
|
295
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
289
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
296
290
|
return response;
|
297
|
-
}
|
298
291
|
// Convert the dictionary in the response and return the the correct object
|
299
292
|
var tariffPlanToTariffs = new Map(Object.entries(response.tariffPlanToTariffs).map(function (_a) {
|
300
293
|
var tariffPlanId = _a[0], tariffs = _a[1];
|
@@ -393,9 +386,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
393
386
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
394
387
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
395
388
|
// Check for errors
|
396
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
389
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
397
390
|
return response;
|
398
|
-
}
|
399
391
|
return {
|
400
392
|
buyerDataStatus: response.buyerDataStatus,
|
401
393
|
buyer: response.buyer,
|
@@ -443,9 +435,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
443
435
|
};
|
444
436
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
445
437
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
446
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
438
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
447
439
|
return response;
|
448
|
-
}
|
449
440
|
// Update the booking process status
|
450
441
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
451
442
|
return true;
|
@@ -500,9 +491,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
500
491
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
501
492
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
502
493
|
var _a, _b;
|
503
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
494
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
504
495
|
return response;
|
505
|
-
}
|
506
496
|
var reductionResponse = response;
|
507
497
|
// Update the booking process status
|
508
498
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -540,9 +530,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
540
530
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
541
531
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
542
532
|
var _a, _b, _c;
|
543
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
533
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
544
534
|
return response;
|
545
|
-
}
|
546
535
|
var reductionResponse = response;
|
547
536
|
// Update the booking process status
|
548
537
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -607,9 +596,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
607
596
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
608
597
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
609
598
|
var _a, _b;
|
610
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
599
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
611
600
|
return response;
|
612
|
-
}
|
613
601
|
var reductionResponse = response;
|
614
602
|
// Update the booking process status
|
615
603
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -641,9 +629,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
641
629
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
642
630
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
643
631
|
var _a, _b, _c;
|
644
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
632
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
645
633
|
return response;
|
646
|
-
}
|
647
634
|
var reductionResponse = response;
|
648
635
|
// Update the booking process status
|
649
636
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -701,9 +688,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
701
688
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
702
689
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
703
690
|
var _a, _b;
|
704
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
691
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
705
692
|
return response;
|
706
|
-
}
|
707
693
|
var reductionResponse = response;
|
708
694
|
// Update the booking process status
|
709
695
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -1,13 +1,14 @@
|
|
1
1
|
/**
|
2
|
-
*
|
3
|
-
*
|
4
|
-
* @property {number} httpStatus - The http status code of the error (e.g. 400)
|
5
|
-
* @property {number} mtsCode - The error code returned by the MTS Backend (e.g. 4001)
|
6
|
-
* @property {string} message - The message of the error (e.g. "Invalid parameters")
|
2
|
+
* Error response type as returned by the BackEnd
|
7
3
|
*/
|
8
4
|
export type ErrorResponse = {
|
5
|
+
/** The http status code of the error (e.g. 400) */
|
9
6
|
httpStatus: number;
|
7
|
+
/** The error code returned by the MTS Backend (e.g. 4001) */
|
10
8
|
mtsCode: number;
|
9
|
+
/** The message of the error (e.g. "Invalid parameters") */
|
11
10
|
message: string;
|
11
|
+
/** Whether this is a 403 error generate by Azure, and should be treated like a maintenance error (so, like a 503) */
|
12
|
+
isAzureMaintenance?: boolean;
|
12
13
|
};
|
13
14
|
export declare const objectIsMTSErrorResponse: (error: any) => error is ErrorResponse;
|
package/lib/utils/apiCall.d.ts
CHANGED
@@ -6,12 +6,11 @@
|
|
6
6
|
* @method makeDelete - Makes a DELETE request to the MTS API
|
7
7
|
*/
|
8
8
|
import { GenericAbortSignal } from "axios";
|
9
|
-
import { ErrorResponse } from "../types/ErrorResponse";
|
10
9
|
export interface ApiCallOptions {
|
11
10
|
/** An abort signal to be passed to Axios, in case you want to cancel the request */
|
12
11
|
signal?: GenericAbortSignal;
|
13
12
|
}
|
14
|
-
export declare const makeGet: (url: string, options?: ApiCallOptions) => Promise<
|
15
|
-
export declare const makePost: (url: string, data: any, options?: ApiCallOptions) => Promise<
|
16
|
-
export declare const makePut: (url: string, data: any, options?: ApiCallOptions) => Promise<
|
17
|
-
export declare const makeDelete: (url: string, options?: ApiCallOptions) => Promise<
|
13
|
+
export declare const makeGet: (url: string, options?: ApiCallOptions) => Promise<any>;
|
14
|
+
export declare const makePost: (url: string, data: any, options?: ApiCallOptions) => Promise<any>;
|
15
|
+
export declare const makePut: (url: string, data: any, options?: ApiCallOptions) => Promise<any>;
|
16
|
+
export declare const makeDelete: (url: string, options?: ApiCallOptions) => Promise<any>;
|
package/lib/utils/apiCall.js
CHANGED
@@ -68,43 +68,55 @@ var removeNullError = function (resData) {
|
|
68
68
|
});
|
69
69
|
return filteredResponse;
|
70
70
|
};
|
71
|
-
var
|
72
|
-
var debug, subKey, errorReport;
|
71
|
+
var makeRequest = function (method, url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
|
72
|
+
var debug, subKey, errorReport, axiosConfig, requestFunctions;
|
73
73
|
return __generator(this, function (_a) {
|
74
|
+
if (data && method !== "POST" && method !== "PUT")
|
75
|
+
throw new Error("MTS Library Error! makeRequest: data is not supported for ".concat(method, " calls. url: ").concat(url));
|
74
76
|
debug = (0, config_1.getConfig)().DEBUG;
|
75
77
|
if (debug) {
|
76
|
-
console.log("
|
78
|
+
console.log("".concat(method, "_RequestData"), url);
|
77
79
|
}
|
78
80
|
subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
|
79
81
|
if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
|
80
82
|
errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
|
81
|
-
throw new Error("MTS Library Error!
|
83
|
+
throw new Error("MTS Library Error! makeRequest: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
|
84
|
+
}
|
85
|
+
axiosConfig = {
|
86
|
+
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 })),
|
87
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
88
|
+
};
|
89
|
+
requestFunctions = {
|
90
|
+
GET: function () { return axios_1.default.get(url, axiosConfig); },
|
91
|
+
DELETE: function () { return axios_1.default.delete(url, axiosConfig); },
|
92
|
+
POST: function () { return axios_1.default.post(url, data, axiosConfig); },
|
93
|
+
PUT: function () { return axios_1.default.put(url, data, axiosConfig); }
|
94
|
+
};
|
95
|
+
if (!requestFunctions[method]) {
|
96
|
+
throw new Error("MTS Library Error! makeRequest: unsupported method ".concat(method));
|
82
97
|
}
|
83
98
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
84
|
-
var response, filteredResponse, error_1, message, resError, resError;
|
85
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
86
|
-
return __generator(this, function (
|
87
|
-
switch (
|
99
|
+
var response, filteredResponse, error_1, message, status_1, isAzureMaintenance, resError, resError;
|
100
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
101
|
+
return __generator(this, function (_m) {
|
102
|
+
switch (_m.label) {
|
88
103
|
case 0:
|
89
|
-
|
90
|
-
return [4 /*yield*/,
|
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
|
93
|
-
})];
|
104
|
+
_m.trys.push([0, 2, , 3]);
|
105
|
+
return [4 /*yield*/, requestFunctions[method]()];
|
94
106
|
case 1:
|
95
|
-
response =
|
107
|
+
response = _m.sent();
|
96
108
|
filteredResponse = removeNullError(response.data);
|
97
109
|
if (debug) {
|
98
|
-
console.log("
|
110
|
+
console.log("".concat(method, "_ResponseData"), url, filteredResponse);
|
99
111
|
}
|
100
112
|
resolve(filteredResponse);
|
101
113
|
return [3 /*break*/, 3];
|
102
114
|
case 2:
|
103
|
-
error_1 =
|
115
|
+
error_1 = _m.sent();
|
104
116
|
if (axios_1.default.isCancel(error_1)) {
|
105
117
|
// Log cancellation
|
106
118
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
107
|
-
console.log("
|
119
|
+
console.log("".concat(method, "_RequestCanceled"), url);
|
108
120
|
// Resolve with empty object
|
109
121
|
resolve({});
|
110
122
|
}
|
@@ -112,20 +124,22 @@ var makeGet = function (url, options) { return __awaiter(void 0, void 0, void 0,
|
|
112
124
|
message = ((_b = (_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
113
125
|
? error_1.response.data.error.message
|
114
126
|
: (_d = (_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
127
|
+
status_1 = ((_e = error_1.response) === null || _e === void 0 ? void 0 : _e.status) || 0;
|
128
|
+
isAzureMaintenance = status_1 === 403
|
129
|
+
? !((_f = error_1.response) === null || _f === void 0 ? void 0 : _f.data.error) &&
|
130
|
+
!!(((_g = error_1.response) === null || _g === void 0 ? void 0 : _g.data.includes("Web App - Unavailable")) ||
|
131
|
+
((_h = error_1.response) === null || _h === void 0 ? void 0 : _h.data.includes("Site Disabled")))
|
132
|
+
: undefined;
|
133
|
+
resError = __assign({ httpStatus: status_1, mtsCode: ((_l = (_k = (_j = error_1.response) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.error) === null || _l === void 0 ? void 0 : _l.code) || 0, message: message || "Unknown error" }, (isAzureMaintenance !== undefined && { isAzureMaintenance: isAzureMaintenance }));
|
120
134
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
121
|
-
console.log("
|
135
|
+
console.log("".concat(method, "_ResponseAxiosError"), url, resError);
|
122
136
|
}
|
123
137
|
reject(resError);
|
124
138
|
}
|
125
139
|
else {
|
126
140
|
resError = __assign(__assign({}, error_1), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
|
127
141
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
128
|
-
console.log("
|
142
|
+
console.log("".concat(method, "_ResponseError"), url, resError);
|
129
143
|
}
|
130
144
|
reject(resError);
|
131
145
|
}
|
@@ -136,211 +150,19 @@ var makeGet = function (url, options) { return __awaiter(void 0, void 0, void 0,
|
|
136
150
|
}); })];
|
137
151
|
});
|
138
152
|
}); };
|
153
|
+
var makeGet = function (url, options) {
|
154
|
+
return makeRequest("GET", url, undefined, options);
|
155
|
+
};
|
139
156
|
exports.makeGet = makeGet;
|
140
|
-
var makePost = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
|
141
|
-
|
142
|
-
|
143
|
-
debug = (0, config_1.getConfig)().DEBUG;
|
144
|
-
if (debug) {
|
145
|
-
console.log("POST_RequestData", url, data);
|
146
|
-
}
|
147
|
-
subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
|
148
|
-
if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
|
149
|
-
errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
|
150
|
-
throw new Error("MTS Library Error! makePost: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
|
151
|
-
}
|
152
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
153
|
-
var response, filteredResponse, error_2, message, resError, resError;
|
154
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
155
|
-
return __generator(this, function (_j) {
|
156
|
-
switch (_j.label) {
|
157
|
-
case 0:
|
158
|
-
_j.trys.push([0, 2, , 3]);
|
159
|
-
return [4 /*yield*/, axios_1.default.post(url, data, {
|
160
|
-
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 })),
|
161
|
-
signal: options === null || options === void 0 ? void 0 : options.signal
|
162
|
-
})];
|
163
|
-
case 1:
|
164
|
-
response = _j.sent();
|
165
|
-
filteredResponse = removeNullError(response.data);
|
166
|
-
if (debug) {
|
167
|
-
console.log("POST_ResponseData", url, filteredResponse);
|
168
|
-
}
|
169
|
-
resolve(filteredResponse);
|
170
|
-
return [3 /*break*/, 3];
|
171
|
-
case 2:
|
172
|
-
error_2 = _j.sent();
|
173
|
-
if (axios_1.default.isCancel(error_2)) {
|
174
|
-
// Log cancellation
|
175
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
176
|
-
console.log("POST_RequestCanceled", url);
|
177
|
-
// Resolve with empty object
|
178
|
-
resolve({});
|
179
|
-
}
|
180
|
-
else if (axios_1.default.isAxiosError(error_2)) {
|
181
|
-
message = ((_b = (_a = error_2.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
182
|
-
? error_2.response.data.error.message
|
183
|
-
: (_d = (_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
184
|
-
resError = {
|
185
|
-
httpStatus: ((_e = error_2.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
186
|
-
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,
|
187
|
-
message: message || "Unknown error"
|
188
|
-
};
|
189
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
190
|
-
console.log("POST_ResponseAxiosError", url, resError);
|
191
|
-
}
|
192
|
-
reject(resError);
|
193
|
-
}
|
194
|
-
else {
|
195
|
-
resError = __assign(__assign({}, error_2), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
|
196
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
197
|
-
console.log("POST_ResponseError", url, resError);
|
198
|
-
}
|
199
|
-
reject(resError);
|
200
|
-
}
|
201
|
-
return [3 /*break*/, 3];
|
202
|
-
case 3: return [2 /*return*/];
|
203
|
-
}
|
204
|
-
});
|
205
|
-
}); })];
|
206
|
-
});
|
207
|
-
}); };
|
157
|
+
var makePost = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
158
|
+
return [2 /*return*/, makeRequest("POST", url, data, options)];
|
159
|
+
}); }); };
|
208
160
|
exports.makePost = makePost;
|
209
|
-
var makePut = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
|
210
|
-
|
211
|
-
|
212
|
-
debug = (0, config_1.getConfig)().DEBUG;
|
213
|
-
if (debug) {
|
214
|
-
console.log("PUT_RequestData", url, data);
|
215
|
-
}
|
216
|
-
subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
|
217
|
-
if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
|
218
|
-
errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
|
219
|
-
throw new Error("MTS Library Error! makePut: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
|
220
|
-
}
|
221
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
222
|
-
var response, filteredResponse, error_3, message, resError, resError;
|
223
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
224
|
-
return __generator(this, function (_j) {
|
225
|
-
switch (_j.label) {
|
226
|
-
case 0:
|
227
|
-
_j.trys.push([0, 2, , 3]);
|
228
|
-
return [4 /*yield*/, axios_1.default.put(url, data, {
|
229
|
-
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 })),
|
230
|
-
signal: options === null || options === void 0 ? void 0 : options.signal
|
231
|
-
})];
|
232
|
-
case 1:
|
233
|
-
response = _j.sent();
|
234
|
-
filteredResponse = removeNullError(response.data);
|
235
|
-
if (debug) {
|
236
|
-
console.log("PUT_ResponseData", url, filteredResponse);
|
237
|
-
}
|
238
|
-
resolve(filteredResponse);
|
239
|
-
return [3 /*break*/, 3];
|
240
|
-
case 2:
|
241
|
-
error_3 = _j.sent();
|
242
|
-
if (axios_1.default.isCancel(error_3)) {
|
243
|
-
// Log cancellation
|
244
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
245
|
-
console.log("PUT_RequestCanceled", url);
|
246
|
-
// Resolve with empty object
|
247
|
-
resolve({});
|
248
|
-
}
|
249
|
-
else if (axios_1.default.isAxiosError(error_3)) {
|
250
|
-
message = ((_b = (_a = error_3.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
251
|
-
? error_3.response.data.error.message
|
252
|
-
: (_d = (_c = error_3.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
253
|
-
resError = {
|
254
|
-
httpStatus: ((_e = error_3.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
255
|
-
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,
|
256
|
-
message: message || "Unknown error"
|
257
|
-
};
|
258
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
259
|
-
console.log("PUT_ResponseAxiosError", url, resError);
|
260
|
-
}
|
261
|
-
reject(resError);
|
262
|
-
}
|
263
|
-
else {
|
264
|
-
resError = __assign(__assign({}, error_3), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
|
265
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
266
|
-
console.log("PUT_ResponseError", url, resError);
|
267
|
-
}
|
268
|
-
reject(resError);
|
269
|
-
}
|
270
|
-
return [3 /*break*/, 3];
|
271
|
-
case 3: return [2 /*return*/];
|
272
|
-
}
|
273
|
-
});
|
274
|
-
}); })];
|
275
|
-
});
|
276
|
-
}); };
|
161
|
+
var makePut = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
162
|
+
return [2 /*return*/, makeRequest("PUT", url, data, options)];
|
163
|
+
}); }); };
|
277
164
|
exports.makePut = makePut;
|
278
|
-
var makeDelete = function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
|
279
|
-
|
280
|
-
|
281
|
-
debug = (0, config_1.getConfig)().DEBUG;
|
282
|
-
if (debug) {
|
283
|
-
console.log("DELETE_RequestData", url);
|
284
|
-
}
|
285
|
-
subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
|
286
|
-
if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
|
287
|
-
errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
|
288
|
-
throw new Error("MTS Library Error! makeDelete: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
|
289
|
-
}
|
290
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
291
|
-
var response, filteredResponse, error_4, message, resError, resError;
|
292
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
293
|
-
return __generator(this, function (_j) {
|
294
|
-
switch (_j.label) {
|
295
|
-
case 0:
|
296
|
-
_j.trys.push([0, 2, , 3]);
|
297
|
-
return [4 /*yield*/, axios_1.default.delete(url, {
|
298
|
-
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 })),
|
299
|
-
signal: options === null || options === void 0 ? void 0 : options.signal
|
300
|
-
})];
|
301
|
-
case 1:
|
302
|
-
response = _j.sent();
|
303
|
-
filteredResponse = removeNullError(response.data);
|
304
|
-
if (debug) {
|
305
|
-
console.log("DELETE_ResponseData", url, filteredResponse);
|
306
|
-
}
|
307
|
-
resolve(filteredResponse);
|
308
|
-
return [3 /*break*/, 3];
|
309
|
-
case 2:
|
310
|
-
error_4 = _j.sent();
|
311
|
-
if (axios_1.default.isCancel(error_4)) {
|
312
|
-
// Log cancellation
|
313
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
314
|
-
console.log("DELETE_RequestCanceled", url);
|
315
|
-
// Resolve with empty object
|
316
|
-
resolve({});
|
317
|
-
}
|
318
|
-
else if (axios_1.default.isAxiosError(error_4)) {
|
319
|
-
message = ((_b = (_a = error_4.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
320
|
-
? error_4.response.data.error.message
|
321
|
-
: (_d = (_c = error_4.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
322
|
-
resError = {
|
323
|
-
httpStatus: ((_e = error_4.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
324
|
-
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,
|
325
|
-
message: message || "Unknown error"
|
326
|
-
};
|
327
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
328
|
-
console.log("DELETE_ResponseAxiosError", url, resError);
|
329
|
-
}
|
330
|
-
reject(resError);
|
331
|
-
}
|
332
|
-
else {
|
333
|
-
resError = __assign(__assign({}, error_4), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
|
334
|
-
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
335
|
-
console.log("DELETE_ResponseError", url, resError);
|
336
|
-
}
|
337
|
-
reject(resError);
|
338
|
-
}
|
339
|
-
return [3 /*break*/, 3];
|
340
|
-
case 3: return [2 /*return*/];
|
341
|
-
}
|
342
|
-
});
|
343
|
-
}); })];
|
344
|
-
});
|
345
|
-
}); };
|
165
|
+
var makeDelete = function (url, options) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
166
|
+
return [2 /*return*/, makeRequest("DELETE", url, undefined, options)];
|
167
|
+
}); }); };
|
346
168
|
exports.makeDelete = makeDelete;
|