mts-booking-library 2.2.0 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +2 -2
- package/lib/booking/booking.js +5 -11
- package/lib/booking/journeyBooking.js +29 -43
- package/lib/booking/serviceBooking.js +26 -35
- package/lib/booking/subscriptionBooking.js +25 -32
- package/lib/booking/tplBooking.js +27 -37
- 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();
|
@@ -132,27 +132,31 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
132
132
|
};
|
133
133
|
JourneyBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
|
134
134
|
return __awaiter(this, void 0, void 0, function () {
|
135
|
-
var
|
135
|
+
var cart, cartDueDate;
|
136
136
|
return __generator(this, function (_a) {
|
137
|
-
|
137
|
+
switch (_a.label) {
|
138
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
|
139
|
+
case 1:
|
140
|
+
cart = _a.sent();
|
138
141
|
if (cart) {
|
139
|
-
|
142
|
+
cartDueDate = new Date();
|
140
143
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
141
144
|
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
this.cart = cart;
|
146
|
+
this.cartGuid = cart.guid;
|
147
|
+
this.bookingDueDate = cartDueDate; // See Booking class
|
145
148
|
// Update the sellerId. This is particularly important in Linkavel
|
146
|
-
|
149
|
+
this.updateSellerId(cart.sellerId);
|
147
150
|
// Fill the booking process status
|
148
|
-
|
151
|
+
this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
|
149
152
|
}
|
150
153
|
else {
|
151
154
|
// This should never happen, but just in case
|
152
|
-
|
155
|
+
this.resetBooking();
|
153
156
|
}
|
154
157
|
}
|
155
|
-
|
158
|
+
return [2 /*return*/];
|
159
|
+
}
|
156
160
|
});
|
157
161
|
});
|
158
162
|
};
|
@@ -194,7 +198,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
194
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
195
199
|
// Clear all data
|
196
200
|
_this.resetBooking();
|
197
|
-
return
|
201
|
+
return response;
|
198
202
|
})];
|
199
203
|
});
|
200
204
|
});
|
@@ -209,9 +213,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
209
213
|
return __generator(this, function (_a) {
|
210
214
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?");
|
211
215
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
212
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
213
|
-
? response
|
214
|
-
: response.stops;
|
216
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
|
215
217
|
})];
|
216
218
|
});
|
217
219
|
});
|
@@ -228,9 +230,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
228
230
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
229
231
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
|
230
232
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
231
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
232
|
-
? response
|
233
|
-
: response.stops;
|
233
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
|
234
234
|
})];
|
235
235
|
});
|
236
236
|
});
|
@@ -301,7 +301,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
301
301
|
throw new Error("Could not fetch cart");
|
302
302
|
}
|
303
303
|
// Update storage
|
304
|
-
this.getStorage().getState().updateCartGuid(response.
|
304
|
+
this.getStorage().getState().updateCartGuid(response.cartGuid);
|
305
305
|
return [2 /*return*/, this.cart];
|
306
306
|
}
|
307
307
|
});
|
@@ -330,9 +330,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
330
330
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
331
331
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
332
332
|
// Check for errors
|
333
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
333
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
334
334
|
return response;
|
335
|
-
}
|
336
335
|
// For each passenger, parse the outbound and return tariffs
|
337
336
|
var passengers = response.passengers;
|
338
337
|
passengers.map(function (passenger) {
|
@@ -392,9 +391,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
392
391
|
});
|
393
392
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
394
393
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
395
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
394
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
396
395
|
return response;
|
397
|
-
}
|
398
396
|
// Update the booking process status
|
399
397
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
400
398
|
return true;
|
@@ -429,9 +427,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
429
427
|
});
|
430
428
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/seats?").concat(searchParams);
|
431
429
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
432
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
433
|
-
? response
|
434
|
-
: response.busMatrix;
|
430
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.busMatrix;
|
435
431
|
})];
|
436
432
|
});
|
437
433
|
});
|
@@ -459,9 +455,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
459
455
|
});
|
460
456
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats?").concat(searchParams);
|
461
457
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
462
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
463
|
-
? response
|
464
|
-
: response.assignedSeats;
|
458
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
|
465
459
|
})];
|
466
460
|
});
|
467
461
|
});
|
@@ -491,9 +485,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
491
485
|
newSeatsIds: newSeatsIds,
|
492
486
|
cartGuid: this.cart.guid
|
493
487
|
}, options).then(function (response) {
|
494
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
488
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
495
489
|
return response;
|
496
|
-
}
|
497
490
|
// Update the booking process status
|
498
491
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
499
492
|
return true;
|
@@ -519,9 +512,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
519
512
|
searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
|
520
513
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction/trips?").concat(searchParams);
|
521
514
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
522
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
523
|
-
? response
|
524
|
-
: response.trips;
|
515
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
|
525
516
|
})];
|
526
517
|
});
|
527
518
|
});
|
@@ -571,9 +562,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
571
562
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
572
563
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
573
564
|
var _a, _b;
|
574
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
565
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
575
566
|
return response;
|
576
|
-
}
|
577
567
|
var reductionResponse = response;
|
578
568
|
// Update the booking process status
|
579
569
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -611,9 +601,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
611
601
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
612
602
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
613
603
|
var _a, _b, _c;
|
614
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
604
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
615
605
|
return response;
|
616
|
-
}
|
617
606
|
var reductionResponse = response;
|
618
607
|
// Update the booking process status
|
619
608
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -678,9 +667,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
678
667
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
679
668
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
680
669
|
var _a, _b;
|
681
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
670
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
682
671
|
return response;
|
683
|
-
}
|
684
672
|
var reductionResponse = response;
|
685
673
|
// Update the booking process status
|
686
674
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -710,9 +698,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
710
698
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
711
699
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
712
700
|
var _a, _b, _c;
|
713
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
701
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
714
702
|
return response;
|
715
|
-
}
|
716
703
|
var reductionResponse = response;
|
717
704
|
// Update the booking process status
|
718
705
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -770,9 +757,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
770
757
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
771
758
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
772
759
|
var _a, _b;
|
773
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
760
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
774
761
|
return response;
|
775
|
-
}
|
776
762
|
var reductionResponse = response;
|
777
763
|
// Update the booking process status
|
778
764
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -132,27 +132,31 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
132
132
|
};
|
133
133
|
ServiceBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
|
134
134
|
return __awaiter(this, void 0, void 0, function () {
|
135
|
-
var
|
135
|
+
var cart, cartDueDate;
|
136
136
|
return __generator(this, function (_a) {
|
137
|
-
|
137
|
+
switch (_a.label) {
|
138
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
|
139
|
+
case 1:
|
140
|
+
cart = _a.sent();
|
138
141
|
if (cart) {
|
139
|
-
|
142
|
+
cartDueDate = new Date();
|
140
143
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
141
144
|
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
this.cart = cart;
|
146
|
+
this.cartGuid = cart.guid;
|
147
|
+
this.bookingDueDate = cartDueDate; // See Booking class
|
145
148
|
// Update the sellerId. This is particularly important in Linkavel
|
146
|
-
|
149
|
+
this.updateSellerId(cart.sellerId);
|
147
150
|
// Fill the booking process status
|
148
|
-
|
151
|
+
this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
|
149
152
|
}
|
150
153
|
else {
|
151
154
|
// This should never happen, but just in case
|
152
|
-
|
155
|
+
this.resetBooking();
|
153
156
|
}
|
154
157
|
}
|
155
|
-
|
158
|
+
return [2 /*return*/];
|
159
|
+
}
|
156
160
|
});
|
157
161
|
});
|
158
162
|
};
|
@@ -194,7 +198,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
194
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
195
199
|
// Clear all data
|
196
200
|
_this.resetBooking();
|
197
|
-
return
|
201
|
+
return response;
|
198
202
|
})];
|
199
203
|
});
|
200
204
|
});
|
@@ -210,9 +214,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
210
214
|
return __generator(this, function (_a) {
|
211
215
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cities?");
|
212
216
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
213
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
214
|
-
? response
|
215
|
-
: response.cities;
|
217
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
|
216
218
|
})];
|
217
219
|
});
|
218
220
|
});
|
@@ -231,9 +233,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
231
233
|
searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
|
232
234
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services?").concat(searchParams);
|
233
235
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
234
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
235
|
-
? response
|
236
|
-
: response.services;
|
236
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.services;
|
237
237
|
})];
|
238
238
|
});
|
239
239
|
});
|
@@ -253,9 +253,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
253
253
|
searchParams = new URLSearchParams({ serviceId: serviceId.toString(), date: date });
|
254
254
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/trips?").concat(searchParams);
|
255
255
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
256
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
257
|
-
? response
|
258
|
-
: response;
|
256
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
259
257
|
})];
|
260
258
|
});
|
261
259
|
});
|
@@ -302,7 +300,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
302
300
|
throw new Error("Could not fetch cart");
|
303
301
|
}
|
304
302
|
// Update storage
|
305
|
-
this.getStorage().getState().updateCartGuid(response.
|
303
|
+
this.getStorage().getState().updateCartGuid(response.cartGuid);
|
306
304
|
return [2 /*return*/, this.cart];
|
307
305
|
}
|
308
306
|
});
|
@@ -332,9 +330,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
332
330
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
333
331
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
334
332
|
// Check for errors
|
335
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
333
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
336
334
|
return response;
|
337
|
-
}
|
338
335
|
return {
|
339
336
|
buyerDataStatus: response.buyerDataStatus,
|
340
337
|
buyer: response.buyer,
|
@@ -370,9 +367,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
370
367
|
};
|
371
368
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
372
369
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
373
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
370
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
374
371
|
return response;
|
375
|
-
}
|
376
372
|
// Update the booking process status
|
377
373
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
378
374
|
return true;
|
@@ -427,9 +423,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
427
423
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
428
424
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
429
425
|
var _a, _b;
|
430
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
426
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
431
427
|
return response;
|
432
|
-
}
|
433
428
|
var reductionResponse = response;
|
434
429
|
// Update the booking process status
|
435
430
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -467,9 +462,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
467
462
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
468
463
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
469
464
|
var _a, _b, _c;
|
470
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
465
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
471
466
|
return response;
|
472
|
-
}
|
473
467
|
var reductionResponse = response;
|
474
468
|
// Update the booking process status
|
475
469
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -534,9 +528,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
534
528
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
535
529
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
536
530
|
var _a, _b;
|
537
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
531
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
538
532
|
return response;
|
539
|
-
}
|
540
533
|
var reductionResponse = response;
|
541
534
|
// Update the booking process status
|
542
535
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -568,9 +561,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
568
561
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
569
562
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
570
563
|
var _a, _b, _c;
|
571
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
564
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
572
565
|
return response;
|
573
|
-
}
|
574
566
|
var reductionResponse = response;
|
575
567
|
// Update the booking process status
|
576
568
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -628,9 +620,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
628
620
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
629
621
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
630
622
|
var _a, _b;
|
631
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
623
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
632
624
|
return response;
|
633
|
-
}
|
634
625
|
var reductionResponse = response;
|
635
626
|
// Update the booking process status
|
636
627
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -132,27 +132,31 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
132
132
|
};
|
133
133
|
SubscriptionBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
|
134
134
|
return __awaiter(this, void 0, void 0, function () {
|
135
|
-
var
|
135
|
+
var cart, cartDueDate;
|
136
136
|
return __generator(this, function (_a) {
|
137
|
-
|
137
|
+
switch (_a.label) {
|
138
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
|
139
|
+
case 1:
|
140
|
+
cart = _a.sent();
|
138
141
|
if (cart) {
|
139
|
-
|
142
|
+
cartDueDate = new Date();
|
140
143
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
141
144
|
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
this.cart = cart;
|
146
|
+
this.cartGuid = cart.guid;
|
147
|
+
this.bookingDueDate = cartDueDate; // See Booking class
|
145
148
|
// Update the sellerId. This is particularly important in Linkavel
|
146
|
-
|
149
|
+
this.updateSellerId(cart.sellerId);
|
147
150
|
// Fill the booking process status
|
148
|
-
|
151
|
+
this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
|
149
152
|
}
|
150
153
|
else {
|
151
154
|
// This should never happen, but just in case
|
152
|
-
|
155
|
+
this.resetBooking();
|
153
156
|
}
|
154
157
|
}
|
155
|
-
|
158
|
+
return [2 /*return*/];
|
159
|
+
}
|
156
160
|
});
|
157
161
|
});
|
158
162
|
};
|
@@ -193,7 +197,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
193
197
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
|
194
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
195
199
|
_this.resetBooking();
|
196
|
-
return
|
200
|
+
return response;
|
197
201
|
})];
|
198
202
|
});
|
199
203
|
});
|
@@ -208,9 +212,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
208
212
|
return __generator(this, function (_a) {
|
209
213
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/departures?");
|
210
214
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
211
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
212
|
-
? response
|
213
|
-
: response.departures;
|
215
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.departures;
|
214
216
|
})];
|
215
217
|
});
|
216
218
|
});
|
@@ -227,9 +229,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
227
229
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
228
230
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/destinations?").concat(searchParams);
|
229
231
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
230
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
231
|
-
? response
|
232
|
-
: response.destinations;
|
232
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.destinations;
|
233
233
|
})];
|
234
234
|
});
|
235
235
|
});
|
@@ -360,7 +360,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
360
360
|
throw new Error("Could not fetch cart");
|
361
361
|
}
|
362
362
|
// Update storage
|
363
|
-
this.getStorage().getState().updateCartGuid(response.
|
363
|
+
this.getStorage().getState().updateCartGuid(response.cartGuid);
|
364
364
|
return [2 /*return*/, this.cart];
|
365
365
|
}
|
366
366
|
});
|
@@ -389,9 +389,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
389
389
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
390
390
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
391
391
|
// Check for errors
|
392
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
392
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
393
393
|
return response;
|
394
|
-
}
|
395
394
|
// For each passenger, parse the outbound and return tariffs
|
396
395
|
var passengers = response.passengers;
|
397
396
|
passengers.map(function (passenger) {
|
@@ -451,9 +450,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
451
450
|
});
|
452
451
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
453
452
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
454
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
453
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
455
454
|
return response;
|
456
|
-
}
|
457
455
|
// Update the booking process status
|
458
456
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
459
457
|
return true;
|
@@ -507,9 +505,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
507
505
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
508
506
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
509
507
|
var _a, _b;
|
510
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
508
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
511
509
|
return response;
|
512
|
-
}
|
513
510
|
var reductionResponse = response;
|
514
511
|
// Update the booking process status
|
515
512
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -547,9 +544,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
547
544
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
548
545
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
549
546
|
var _a, _b, _c;
|
550
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
547
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
551
548
|
return response;
|
552
|
-
}
|
553
549
|
var reductionResponse = response;
|
554
550
|
// Update the booking process status
|
555
551
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -614,9 +610,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
614
610
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
615
611
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
616
612
|
var _a, _b;
|
617
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
613
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
618
614
|
return response;
|
619
|
-
}
|
620
615
|
var reductionResponse = response;
|
621
616
|
// Update the booking process status
|
622
617
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -648,9 +643,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
648
643
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
649
644
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
650
645
|
var _a, _b, _c;
|
651
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
646
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
652
647
|
return response;
|
653
|
-
}
|
654
648
|
var reductionResponse = response;
|
655
649
|
// Update the booking process status
|
656
650
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -708,9 +702,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
708
702
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
709
703
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
710
704
|
var _a, _b;
|
711
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
705
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
712
706
|
return response;
|
713
|
-
}
|
714
707
|
var reductionResponse = response;
|
715
708
|
// Update the booking process status
|
716
709
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -132,27 +132,31 @@ var TplBooking = /** @class */ (function (_super) {
|
|
132
132
|
};
|
133
133
|
TplBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
|
134
134
|
return __awaiter(this, void 0, void 0, function () {
|
135
|
-
var
|
135
|
+
var cart, cartDueDate;
|
136
136
|
return __generator(this, function (_a) {
|
137
|
-
|
137
|
+
switch (_a.label) {
|
138
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
|
139
|
+
case 1:
|
140
|
+
cart = _a.sent();
|
138
141
|
if (cart) {
|
139
|
-
|
142
|
+
cartDueDate = new Date();
|
140
143
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
141
144
|
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
this.cart = cart;
|
146
|
+
this.cartGuid = cart.guid;
|
147
|
+
this.bookingDueDate = cartDueDate; // See Booking class
|
145
148
|
// Update the sellerId. This is particularly important in Linkavel
|
146
|
-
|
149
|
+
this.updateSellerId(cart.sellerId);
|
147
150
|
// Fill the booking process status
|
148
|
-
|
151
|
+
this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
|
149
152
|
}
|
150
153
|
else {
|
151
154
|
// This should never happen, but just in case
|
152
|
-
|
155
|
+
this.resetBooking();
|
153
156
|
}
|
154
157
|
}
|
155
|
-
|
158
|
+
return [2 /*return*/];
|
159
|
+
}
|
156
160
|
});
|
157
161
|
});
|
158
162
|
};
|
@@ -194,7 +198,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
194
198
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
195
199
|
// Clear all data
|
196
200
|
_this.resetBooking();
|
197
|
-
return
|
201
|
+
return response;
|
198
202
|
})];
|
199
203
|
});
|
200
204
|
});
|
@@ -210,9 +214,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
210
214
|
return __generator(this, function (_a) {
|
211
215
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
|
212
216
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
213
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
214
|
-
? response
|
215
|
-
: response.cities;
|
217
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
|
216
218
|
})];
|
217
219
|
});
|
218
220
|
});
|
@@ -229,9 +231,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
229
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() })));
|
230
232
|
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
|
231
233
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
232
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
233
|
-
? response
|
234
|
-
: response.superAreas;
|
234
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.superAreas;
|
235
235
|
})];
|
236
236
|
});
|
237
237
|
});
|
@@ -263,9 +263,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
263
263
|
searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
|
264
264
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffTypesBySuperArea?").concat(searchParams);
|
265
265
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
266
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
267
|
-
? response
|
268
|
-
: response.tariffTypes;
|
266
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.tariffTypes;
|
269
267
|
})];
|
270
268
|
});
|
271
269
|
});
|
@@ -288,9 +286,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
288
286
|
// Call the API
|
289
287
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
290
288
|
// Check for error
|
291
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
289
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
292
290
|
return response;
|
293
|
-
}
|
294
291
|
// Convert the dictionary in the response and return the the correct object
|
295
292
|
var tariffPlanToTariffs = new Map(Object.entries(response.tariffPlanToTariffs).map(function (_a) {
|
296
293
|
var tariffPlanId = _a[0], tariffs = _a[1];
|
@@ -359,7 +356,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
359
356
|
throw new Error("Could not fetch cart");
|
360
357
|
}
|
361
358
|
// Update storage
|
362
|
-
this.getStorage().getState().updateCartGuid(response.
|
359
|
+
this.getStorage().getState().updateCartGuid(response.cartGuid);
|
363
360
|
return [2 /*return*/, this.cart];
|
364
361
|
}
|
365
362
|
});
|
@@ -389,9 +386,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
389
386
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
390
387
|
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
391
388
|
// Check for errors
|
392
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
389
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
393
390
|
return response;
|
394
|
-
}
|
395
391
|
return {
|
396
392
|
buyerDataStatus: response.buyerDataStatus,
|
397
393
|
buyer: response.buyer,
|
@@ -439,9 +435,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
439
435
|
};
|
440
436
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
441
437
|
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
442
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
438
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
443
439
|
return response;
|
444
|
-
}
|
445
440
|
// Update the booking process status
|
446
441
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
447
442
|
return true;
|
@@ -496,9 +491,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
496
491
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
497
492
|
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
498
493
|
var _a, _b;
|
499
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
494
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
500
495
|
return response;
|
501
|
-
}
|
502
496
|
var reductionResponse = response;
|
503
497
|
// Update the booking process status
|
504
498
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -536,9 +530,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
536
530
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
537
531
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
538
532
|
var _a, _b, _c;
|
539
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
533
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
540
534
|
return response;
|
541
|
-
}
|
542
535
|
var reductionResponse = response;
|
543
536
|
// Update the booking process status
|
544
537
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -603,9 +596,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
603
596
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
604
597
|
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
605
598
|
var _a, _b;
|
606
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
599
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
607
600
|
return response;
|
608
|
-
}
|
609
601
|
var reductionResponse = response;
|
610
602
|
// Update the booking process status
|
611
603
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -637,9 +629,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
637
629
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
638
630
|
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
639
631
|
var _a, _b, _c;
|
640
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
632
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
641
633
|
return response;
|
642
|
-
}
|
643
634
|
var reductionResponse = response;
|
644
635
|
// Update the booking process status
|
645
636
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
@@ -697,9 +688,8 @@ var TplBooking = /** @class */ (function (_super) {
|
|
697
688
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
698
689
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
699
690
|
var _a, _b;
|
700
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
691
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
701
692
|
return response;
|
702
|
-
}
|
703
693
|
var reductionResponse = response;
|
704
694
|
// Update the booking process status
|
705
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;
|