mts-booking-library 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +13 -12
- package/lib/booking/booking.js +24 -24
- package/lib/booking/journeyBooking.d.ts +32 -31
- package/lib/booking/journeyBooking.js +49 -49
- package/lib/booking/serviceBooking.d.ts +22 -21
- package/lib/booking/serviceBooking.js +34 -34
- package/lib/booking/subscriptionBooking.d.ts +34 -33
- package/lib/booking/subscriptionBooking.js +49 -49
- package/lib/booking/tplBooking.d.ts +23 -22
- package/lib/booking/tplBooking.js +38 -38
- package/lib/utils/apiCall.d.ts +9 -4
- package/lib/utils/apiCall.js +12 -8
- package/package.json +1 -1
- package/lib/SubscriptionBooking.d.ts +0 -0
- package/lib/SubscriptionBooking.js +0 -148
- package/lib/utils/testUtils.d.ts +0 -8
- package/lib/utils/testUtils.js +0 -19
@@ -130,12 +130,12 @@ var TplBooking = /** @class */ (function (_super) {
|
|
130
130
|
console.log(e);
|
131
131
|
}
|
132
132
|
};
|
133
|
-
TplBooking.prototype.fetchAndSetCart = function (cartGuid) {
|
133
|
+
TplBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
|
134
134
|
return __awaiter(this, void 0, void 0, function () {
|
135
135
|
var _this = this;
|
136
136
|
return __generator(this, function (_a) {
|
137
137
|
switch (_a.label) {
|
138
|
-
case 0: return [4 /*yield*/, this.fetchCart(cartGuid).then(function (cart) {
|
138
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options).then(function (cart) {
|
139
139
|
if (cart) {
|
140
140
|
var cartDueDate = new Date();
|
141
141
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
@@ -161,13 +161,13 @@ var TplBooking = /** @class */ (function (_super) {
|
|
161
161
|
});
|
162
162
|
});
|
163
163
|
};
|
164
|
-
TplBooking.prototype.fetchCart = function (cartGuid) {
|
164
|
+
TplBooking.prototype.fetchCart = function (cartGuid, options) {
|
165
165
|
return __awaiter(this, void 0, void 0, function () {
|
166
166
|
var url;
|
167
167
|
var _this = this;
|
168
168
|
return __generator(this, function (_a) {
|
169
169
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: cartGuid }));
|
170
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
170
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
171
171
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
172
172
|
_this.resetBooking();
|
173
173
|
throw new Error(JSON.stringify(response, null, 2));
|
@@ -186,7 +186,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
186
186
|
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
187
187
|
* data will be deleted.
|
188
188
|
*/
|
189
|
-
TplBooking.prototype.deleteCart = function () {
|
189
|
+
TplBooking.prototype.deleteCart = function (options) {
|
190
190
|
return __awaiter(this, void 0, void 0, function () {
|
191
191
|
var url;
|
192
192
|
var _this = this;
|
@@ -196,7 +196,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
196
196
|
throw Error("Cart is not initialized yet");
|
197
197
|
}
|
198
198
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
|
199
|
-
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
199
|
+
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
200
200
|
// Clear all data
|
201
201
|
_this.resetBooking();
|
202
202
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
@@ -209,12 +209,12 @@ var TplBooking = /** @class */ (function (_super) {
|
|
209
209
|
* @returns An array of {@link City} objects representing the cities where it is possible to book a TPL service
|
210
210
|
* if the call is successful, an {@link ErrorResponse} object otherwise.
|
211
211
|
*/
|
212
|
-
TplBooking.prototype.getCities = function () {
|
212
|
+
TplBooking.prototype.getCities = function (options) {
|
213
213
|
return __awaiter(this, void 0, void 0, function () {
|
214
214
|
var url;
|
215
215
|
return __generator(this, function (_a) {
|
216
216
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
|
217
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
217
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
218
218
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
219
219
|
? response
|
220
220
|
: response.cities;
|
@@ -227,13 +227,13 @@ var TplBooking = /** @class */ (function (_super) {
|
|
227
227
|
* the TPL service is available at a certain price.
|
228
228
|
* @returns An array of {@link SuperArea} objects representing the SuperAreas if the call is successful, an {@link ErrorResponse} object otherwise.
|
229
229
|
*/
|
230
|
-
TplBooking.prototype.getSuperAreas = function (request) {
|
230
|
+
TplBooking.prototype.getSuperAreas = function (request, options) {
|
231
231
|
return __awaiter(this, void 0, void 0, function () {
|
232
232
|
var searchParams, url;
|
233
233
|
return __generator(this, function (_a) {
|
234
234
|
searchParams = new URLSearchParams(__assign(__assign({ includeBasicInfo: "true", includeAreaIds: "false", includeTariffIds: "false", includeRouteIds: "false" }, (request.cityId && { cityId: request.cityId.toString() })), (request.tripId && { tripId: request.tripId.toString() })));
|
235
235
|
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
|
236
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
236
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
237
237
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
238
238
|
? response
|
239
239
|
: response.superAreas;
|
@@ -245,13 +245,13 @@ var TplBooking = /** @class */ (function (_super) {
|
|
245
245
|
* This method fetches the list of terms types in a given super area.
|
246
246
|
* @returns An array of {@link TermsType} objects representing the available terms types if the call is successful, an {@link ErrorResponse} object otherwise.
|
247
247
|
*/
|
248
|
-
TplBooking.prototype.getTermsTypes = function (superAreaId) {
|
248
|
+
TplBooking.prototype.getTermsTypes = function (superAreaId, options) {
|
249
249
|
return __awaiter(this, void 0, void 0, function () {
|
250
250
|
var searchParams, url;
|
251
251
|
return __generator(this, function (_a) {
|
252
252
|
searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
|
253
253
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/termsTypesBySuperArea?").concat(searchParams);
|
254
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
254
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
255
255
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.termsTypes;
|
256
256
|
})];
|
257
257
|
});
|
@@ -261,13 +261,13 @@ var TplBooking = /** @class */ (function (_super) {
|
|
261
261
|
* This method fetches the list of tariff types in a given super area.
|
262
262
|
* @returns An array of {@link TariffType} objects representing the available tariff types if the call is successful, an {@link ErrorResponse} object otherwise.
|
263
263
|
*/
|
264
|
-
TplBooking.prototype.getTariffTypes = function (superAreaId) {
|
264
|
+
TplBooking.prototype.getTariffTypes = function (superAreaId, options) {
|
265
265
|
return __awaiter(this, void 0, void 0, function () {
|
266
266
|
var searchParams, url;
|
267
267
|
return __generator(this, function (_a) {
|
268
268
|
searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
|
269
269
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffTypesBySuperArea?").concat(searchParams);
|
270
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
270
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
271
271
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
272
272
|
? response
|
273
273
|
: response.tariffTypes;
|
@@ -277,21 +277,21 @@ var TplBooking = /** @class */ (function (_super) {
|
|
277
277
|
};
|
278
278
|
/**
|
279
279
|
* This method fetches the list of available tariffs for the selected terms type in a given super area.
|
280
|
-
* @param
|
281
|
-
* @param
|
280
|
+
* @param superAreaId The id of the super area (as returned by the {@link getSuperAreas} method).
|
281
|
+
* @param termsTypeId The id of the terms type (as returned by the {@link getTermsTypes} method).
|
282
282
|
* If null, tariffs from all terms types will be considered.
|
283
|
-
* @param
|
284
|
-
* @param
|
283
|
+
* @param onlyTickets If true, only only return the tariffs that are for single tickets.
|
284
|
+
* @param onlySubscriptions If true, only return the tariffs that are for subscriptions.
|
285
285
|
* @returns A {@link GetTariffsResponse} if the call is successful, an {@link ErrorResponse} object otherwise.
|
286
286
|
*/
|
287
|
-
TplBooking.prototype.getTariffs = function (superAreaId, termsTypeId, onlyTickets, onlySubscriptions) {
|
287
|
+
TplBooking.prototype.getTariffs = function (superAreaId, termsTypeId, onlyTickets, onlySubscriptions, options) {
|
288
288
|
return __awaiter(this, void 0, void 0, function () {
|
289
289
|
var searchParams, url;
|
290
290
|
return __generator(this, function (_a) {
|
291
291
|
searchParams = new URLSearchParams(__assign(__assign({ superAreaId: superAreaId.toString() }, (termsTypeId && { termsTypeId: termsTypeId.toString() })), { onlyTickets: onlyTickets.toString(), onlySubscriptions: onlySubscriptions.toString() }));
|
292
292
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/tariffs?").concat(searchParams);
|
293
293
|
// Call the API
|
294
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
294
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
295
295
|
// Check for error
|
296
296
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
297
297
|
return response;
|
@@ -315,7 +315,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
315
315
|
/**
|
316
316
|
* This method allows to create a TPL cart.
|
317
317
|
*/
|
318
|
-
TplBooking.prototype.createTplCart = function (tplCart) {
|
318
|
+
TplBooking.prototype.createTplCart = function (tplCart, options) {
|
319
319
|
return __awaiter(this, void 0, void 0, function () {
|
320
320
|
var url, processedTariffIdToQuantity, request;
|
321
321
|
var _this = this;
|
@@ -329,7 +329,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
329
329
|
renewSubscriptionTicketPNR: tplCart.renewSubscriptionTicketPNR
|
330
330
|
})), (tplCart.otaResellerId !== undefined && { otaResellerId: tplCart.otaResellerId })), (tplCart.otaTicketPicture !== undefined && { otaTicketPicture: tplCart.otaTicketPicture }));
|
331
331
|
// Call the API
|
332
|
-
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
332
|
+
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
333
333
|
// Check for errors
|
334
334
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
335
335
|
// If there was an error, reset cartGuid and remove it from the mts-storage
|
@@ -358,7 +358,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
358
358
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
359
359
|
* as well as a list of the available tariffs for each trip.
|
360
360
|
*/
|
361
|
-
TplBooking.prototype.getBuyerPassengersDetails = function () {
|
361
|
+
TplBooking.prototype.getBuyerPassengersDetails = function (options) {
|
362
362
|
return __awaiter(this, void 0, void 0, function () {
|
363
363
|
var buyerPassengersDetails, searchParams, url;
|
364
364
|
return __generator(this, function (_a) {
|
@@ -372,7 +372,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
372
372
|
}
|
373
373
|
searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
|
374
374
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
|
375
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
375
|
+
return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
|
376
376
|
// Check for errors
|
377
377
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
378
378
|
return response;
|
@@ -394,7 +394,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
394
394
|
* with the subscription. This parameter is required if the cart contains a subscription.
|
395
395
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
396
396
|
*/
|
397
|
-
TplBooking.prototype.updateBuyerPassengersDetails = function (buyerDetails, subscriptionPersonCode) {
|
397
|
+
TplBooking.prototype.updateBuyerPassengersDetails = function (buyerDetails, subscriptionPersonCode, options) {
|
398
398
|
return __awaiter(this, void 0, void 0, function () {
|
399
399
|
var buyerPassengersDetails, request, url;
|
400
400
|
var _this = this;
|
@@ -423,7 +423,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
423
423
|
: []
|
424
424
|
};
|
425
425
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
|
426
|
-
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
426
|
+
return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
|
427
427
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
428
428
|
return response;
|
429
429
|
}
|
@@ -438,10 +438,10 @@ var TplBooking = /** @class */ (function (_super) {
|
|
438
438
|
//#region Reductions APIs
|
439
439
|
/**
|
440
440
|
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
441
|
-
* @param
|
441
|
+
* @param request The information about the reduction to add
|
442
442
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
443
443
|
*/
|
444
|
-
TplBooking.prototype.addReduction = function (request) {
|
444
|
+
TplBooking.prototype.addReduction = function (request, options) {
|
445
445
|
return __awaiter(this, void 0, void 0, function () {
|
446
446
|
var discountsStep, _i, _a, step, url;
|
447
447
|
var _this = this;
|
@@ -479,7 +479,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
479
479
|
_c.label = 5;
|
480
480
|
case 5:
|
481
481
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
482
|
-
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
|
482
|
+
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
|
483
483
|
var _a, _b;
|
484
484
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
485
485
|
return response;
|
@@ -501,7 +501,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
501
501
|
* will be removed from the whole cart.
|
502
502
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
503
503
|
*/
|
504
|
-
TplBooking.prototype.removeReduction = function (tripId) {
|
504
|
+
TplBooking.prototype.removeReduction = function (tripId, options) {
|
505
505
|
return __awaiter(this, void 0, void 0, function () {
|
506
506
|
var discountsStep, queryParams, url;
|
507
507
|
var _this = this;
|
@@ -519,7 +519,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
519
519
|
cartGuid: this.cartGuid
|
520
520
|
});
|
521
521
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
522
|
-
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
522
|
+
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
523
523
|
var _a, _b, _c;
|
524
524
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
525
525
|
return response;
|
@@ -544,7 +544,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
544
544
|
* remaining amount with another payment method.
|
545
545
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
546
546
|
*/
|
547
|
-
TplBooking.prototype.useWallet = function () {
|
547
|
+
TplBooking.prototype.useWallet = function (options) {
|
548
548
|
return __awaiter(this, void 0, void 0, function () {
|
549
549
|
var issueStep, _i, _a, step, url;
|
550
550
|
var _this = this;
|
@@ -586,7 +586,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
586
586
|
_c.label = 5;
|
587
587
|
case 5:
|
588
588
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
589
|
-
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
|
589
|
+
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
|
590
590
|
var _a, _b;
|
591
591
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
592
592
|
return response;
|
@@ -607,7 +607,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
607
607
|
*
|
608
608
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
609
609
|
*/
|
610
|
-
TplBooking.prototype.removeWalletReduction = function () {
|
610
|
+
TplBooking.prototype.removeWalletReduction = function (options) {
|
611
611
|
return __awaiter(this, void 0, void 0, function () {
|
612
612
|
var queryParams, url;
|
613
613
|
var _this = this;
|
@@ -620,7 +620,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
620
620
|
cartGuid: this.cartGuid
|
621
621
|
});
|
622
622
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
623
|
-
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
623
|
+
return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
|
624
624
|
var _a, _b, _c;
|
625
625
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
626
626
|
return response;
|
@@ -639,10 +639,10 @@ var TplBooking = /** @class */ (function (_super) {
|
|
639
639
|
* @description This method allows the user to use a voucher to pay the cart.
|
640
640
|
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
641
641
|
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
642
|
-
* @param
|
642
|
+
* @param voucherCode The code of the voucher to use
|
643
643
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
644
644
|
*/
|
645
|
-
TplBooking.prototype.useVoucher = function (voucherCode) {
|
645
|
+
TplBooking.prototype.useVoucher = function (voucherCode, options) {
|
646
646
|
return __awaiter(this, void 0, void 0, function () {
|
647
647
|
var discountsStep, _i, _a, step, url;
|
648
648
|
var _this = this;
|
@@ -680,7 +680,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
680
680
|
_c.label = 5;
|
681
681
|
case 5:
|
682
682
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
|
683
|
-
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }).then(function (response) {
|
683
|
+
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
|
684
684
|
var _a, _b;
|
685
685
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
686
686
|
return response;
|
package/lib/utils/apiCall.d.ts
CHANGED
@@ -5,8 +5,13 @@
|
|
5
5
|
* @method makePost - Makes a POST request to the MTS API
|
6
6
|
* @method makeDelete - Makes a DELETE request to the MTS API
|
7
7
|
*/
|
8
|
+
import { GenericAbortSignal } from "axios";
|
8
9
|
import { ErrorResponse } from "../types/ErrorResponse";
|
9
|
-
export
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
export interface ApiCallOptions {
|
11
|
+
/** An abort signal to be passed to Axios, in case you want to cancel the request */
|
12
|
+
signal?: GenericAbortSignal;
|
13
|
+
}
|
14
|
+
export declare const makeGet: (url: string, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
|
15
|
+
export declare const makePost: (url: string, data: any, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
|
16
|
+
export declare const makePut: (url: string, data: any, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
|
17
|
+
export declare const makeDelete: (url: string, options?: ApiCallOptions) => Promise<ErrorResponse | any>;
|
package/lib/utils/apiCall.js
CHANGED
@@ -68,7 +68,7 @@ var removeNullError = function (resData) {
|
|
68
68
|
});
|
69
69
|
return filteredResponse;
|
70
70
|
};
|
71
|
-
var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
71
|
+
var makeGet = function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
|
72
72
|
var debug, subKey, errorReport;
|
73
73
|
return __generator(this, function (_a) {
|
74
74
|
debug = (0, config_1.getConfig)().DEBUG;
|
@@ -88,7 +88,8 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
88
88
|
case 0:
|
89
89
|
_h.trys.push([0, 2, , 3]);
|
90
90
|
return [4 /*yield*/, axios_1.default.get(url, {
|
91
|
-
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
|
91
|
+
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
92
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
92
93
|
})];
|
93
94
|
case 1:
|
94
95
|
response = _h.sent();
|
@@ -129,7 +130,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
129
130
|
});
|
130
131
|
}); };
|
131
132
|
exports.makeGet = makeGet;
|
132
|
-
var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
|
133
|
+
var makePost = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
|
133
134
|
var debug, subKey, errorReport;
|
134
135
|
return __generator(this, function (_a) {
|
135
136
|
debug = (0, config_1.getConfig)().DEBUG;
|
@@ -149,7 +150,8 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
149
150
|
case 0:
|
150
151
|
_h.trys.push([0, 2, , 3]);
|
151
152
|
return [4 /*yield*/, axios_1.default.post(url, data, {
|
152
|
-
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
|
153
|
+
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
154
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
153
155
|
})];
|
154
156
|
case 1:
|
155
157
|
response = _h.sent();
|
@@ -190,7 +192,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
190
192
|
});
|
191
193
|
}); };
|
192
194
|
exports.makePost = makePost;
|
193
|
-
var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
|
195
|
+
var makePut = function (url, data, options) { return __awaiter(void 0, void 0, void 0, function () {
|
194
196
|
var debug, subKey, errorReport;
|
195
197
|
return __generator(this, function (_a) {
|
196
198
|
debug = (0, config_1.getConfig)().DEBUG;
|
@@ -210,7 +212,8 @@ var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, fu
|
|
210
212
|
case 0:
|
211
213
|
_h.trys.push([0, 2, , 3]);
|
212
214
|
return [4 /*yield*/, axios_1.default.put(url, data, {
|
213
|
-
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
|
215
|
+
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
216
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
214
217
|
})];
|
215
218
|
case 1:
|
216
219
|
response = _h.sent();
|
@@ -251,7 +254,7 @@ var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, fu
|
|
251
254
|
});
|
252
255
|
}); };
|
253
256
|
exports.makePut = makePut;
|
254
|
-
var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
257
|
+
var makeDelete = function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
|
255
258
|
var debug, subKey, errorReport;
|
256
259
|
return __generator(this, function (_a) {
|
257
260
|
debug = (0, config_1.getConfig)().DEBUG;
|
@@ -271,7 +274,8 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
|
|
271
274
|
case 0:
|
272
275
|
_h.trys.push([0, 2, , 3]);
|
273
276
|
return [4 /*yield*/, axios_1.default.delete(url, {
|
274
|
-
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
|
277
|
+
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
278
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
275
279
|
})];
|
276
280
|
case 1:
|
277
281
|
response = _h.sent();
|
package/package.json
CHANGED
File without changes
|
@@ -1,148 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// import { MTSEnvs } from "../config";
|
3
|
-
// import { ServiceBooking } from "../booking/serviceBooking";
|
4
|
-
// import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
5
|
-
// import { Service, ServiceTripsResponse } from "../types/services/Service";
|
6
|
-
// import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
7
|
-
// import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
|
8
|
-
// import { useTestState } from "../mtsStorage";
|
9
|
-
// import { SubscriptionBooking } from "../booking/subscriptionBooking";
|
10
|
-
// // Load .env file
|
11
|
-
// require('dotenv').config();
|
12
|
-
// // How to run the test: npm run test -- SubscriptionBooking.test.ts
|
13
|
-
// describe("SubscriptionBooking", () => {
|
14
|
-
// const timeOut = 120000;
|
15
|
-
// const sub_key = process.env.OCP_SUB_KEY_MTS;
|
16
|
-
// const access_token = process.env.ACCESS_TOKEN;
|
17
|
-
// const sellerId = 8; // ATV
|
18
|
-
// // Define localStorage for local testing
|
19
|
-
// if (typeof localStorage === "undefined" || localStorage === null) {
|
20
|
-
// var LocalStorage = require("node-localstorage").LocalStorage;
|
21
|
-
// global.localStorage = new LocalStorage("./scratch");
|
22
|
-
// }
|
23
|
-
// test("search_tpl", async () => {
|
24
|
-
// const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
|
25
|
-
// // First, get the departures and destinations
|
26
|
-
// const departures = await booking.getSubscriptionsDepartures() as string[];
|
27
|
-
// expect(departures.length).toBeGreaterThan(0);
|
28
|
-
// expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
|
29
|
-
// const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
|
30
|
-
// const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
|
31
|
-
// expect(destinations.length).toBeGreaterThan(0);
|
32
|
-
// expect(destinations).toContain("GARDA AUTOSTAZIONE");
|
33
|
-
// const selectedDestination = "GARDA AUTOSTAZIONE";
|
34
|
-
// // Then get the validity types
|
35
|
-
// const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
|
36
|
-
// expect(validityTypes.length).toBeGreaterThan(0);
|
37
|
-
// for (const validityType of validityTypes) {
|
38
|
-
// // Check that all returned validity types are valid
|
39
|
-
// expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
|
40
|
-
// }
|
41
|
-
// }, timeOut);
|
42
|
-
// const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
|
43
|
-
// const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
|
44
|
-
// const services = servicesResponse as Service[];
|
45
|
-
// // Build create cart request
|
46
|
-
// let tariffsMatrix = services[0].tariffsMatrix;
|
47
|
-
// tariffsMatrix[0][0].quantity = 1;
|
48
|
-
// const createServiceCartRequest: CreateServiceCartRequest = {
|
49
|
-
// currency: ServiceBooking.Currencies.EUR,
|
50
|
-
// service: {
|
51
|
-
// serviceId: services[0].id,
|
52
|
-
// tariffsMatrix: tariffsMatrix
|
53
|
-
// }
|
54
|
-
// };
|
55
|
-
// // Create cart
|
56
|
-
// const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
|
57
|
-
// return cart;
|
58
|
-
// }
|
59
|
-
// test("create_service_cart", async () => {
|
60
|
-
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
61
|
-
// const cart = await createCart(booking);
|
62
|
-
// // Check that the cartId was saved to the local storage
|
63
|
-
// expect(useTestState().getState().cartId).toBe(cart.id);
|
64
|
-
// expect(booking.cartId).toBe(cart.id);
|
65
|
-
// // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
|
66
|
-
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
|
67
|
-
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
|
68
|
-
// // Test booking due date
|
69
|
-
// expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
|
70
|
-
// // Test expired tickets
|
71
|
-
// expect(cart.hasIssuedTickets).toBe(false);
|
72
|
-
// // Test seller data
|
73
|
-
// expect(booking.getSellerId()).toBe(cart.sellerId);
|
74
|
-
// expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
|
75
|
-
// expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
|
76
|
-
// // Now try to get the cart
|
77
|
-
// const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
78
|
-
// expect(newBooking.cartId).toBe(cart.id);
|
79
|
-
// expect(newBooking.getCart()?.id).toBe(cart.id)
|
80
|
-
// expect(newBooking.getSellerId()).toBe(cart.sellerId);
|
81
|
-
// // Finally try to delete the cart
|
82
|
-
// await booking.deleteCart();
|
83
|
-
// expect(booking.getCart()).toBe(undefined);
|
84
|
-
// expect(useTestState().getState().cartId).toBe(undefined);
|
85
|
-
// }, timeOut);
|
86
|
-
// test("get_edit_buyer_data", async () => {
|
87
|
-
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
88
|
-
// const cart = await createCart(booking);
|
89
|
-
// // First, try to get the buyer data
|
90
|
-
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
91
|
-
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
92
|
-
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
93
|
-
// expect(buyer).toBe(null);
|
94
|
-
// // Now try to edit the buyer data
|
95
|
-
// buyer = {
|
96
|
-
// id: 0,
|
97
|
-
// name: "TestName",
|
98
|
-
// lastName: "TestSurname",
|
99
|
-
// email: "testBookingLib@infos.it",
|
100
|
-
// phoneNumber: "+391234567890"
|
101
|
-
// }
|
102
|
-
// await booking.updateBuyerPassengersDetails(buyer);
|
103
|
-
// // Finally, get the buyer data again and check that the data was updated
|
104
|
-
// buyerDataResponse = await booking.getBuyerPassengersDetails();
|
105
|
-
// const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
106
|
-
// expect(updatedBuyer.id).toBeGreaterThan(0);
|
107
|
-
// expect(updatedBuyer.name).toBe(buyer.name);
|
108
|
-
// expect(updatedBuyer.lastName).toBe(buyer.lastName);
|
109
|
-
// expect(updatedBuyer.email).toBe(buyer.email);
|
110
|
-
// expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
|
111
|
-
// // Finally try to delete the cart
|
112
|
-
// await booking.deleteCart();
|
113
|
-
// expect(booking.getCart()).toBe(undefined);
|
114
|
-
// expect(useTestState().getState().cartId).toBe(undefined);
|
115
|
-
// }, timeOut);
|
116
|
-
// test("get_gateway_info", async () => {
|
117
|
-
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
118
|
-
// const cart = await createCart(booking);
|
119
|
-
// booking.updateSellerId(cart.sellerId);
|
120
|
-
// // First, try to get the buyer data
|
121
|
-
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
122
|
-
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
123
|
-
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
124
|
-
// expect(buyer).toBe(null);
|
125
|
-
// // Now try to edit the buyer data
|
126
|
-
// buyer = {
|
127
|
-
// id: 0,
|
128
|
-
// name: "TestName",
|
129
|
-
// lastName: "TestSurname",
|
130
|
-
// email: "testBookingLib@infos.it",
|
131
|
-
// phoneNumber: "+391234567890"
|
132
|
-
// }
|
133
|
-
// await booking.updateBuyerPassengersDetails(buyer);
|
134
|
-
// // Try to get the gateways
|
135
|
-
// const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
|
136
|
-
// if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
|
137
|
-
// throw new Error("No gateways found");
|
138
|
-
// }
|
139
|
-
// const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
|
140
|
-
// expect(gateway?.id).toBeGreaterThan(0);
|
141
|
-
// // Now try to get the info
|
142
|
-
// const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
|
143
|
-
// // Finally try to delete the cart
|
144
|
-
// await booking.deleteCart();
|
145
|
-
// expect(booking.getCart()).toBe(undefined);
|
146
|
-
// expect(useTestState().getState().cartId).toBe(undefined);
|
147
|
-
// }, timeOut);
|
148
|
-
// });
|
package/lib/utils/testUtils.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
|
3
|
-
* @param {Date | string} date the date to convert
|
4
|
-
* @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
|
5
|
-
* that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
|
6
|
-
* @returns {string} the ISO string
|
7
|
-
*/
|
8
|
-
export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
|
package/lib/utils/testUtils.js
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getISOStringWithoutGMT = void 0;
|
4
|
-
/**
|
5
|
-
* This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
|
6
|
-
* @param {Date | string} date the date to convert
|
7
|
-
* @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
|
8
|
-
* that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
|
9
|
-
* @returns {string} the ISO string
|
10
|
-
*/
|
11
|
-
var getISOStringWithoutGMT = function (date, removeTimezone) {
|
12
|
-
if (removeTimezone === void 0) { removeTimezone = true; }
|
13
|
-
if (!date)
|
14
|
-
return null;
|
15
|
-
var newDate = new Date(date);
|
16
|
-
var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
|
17
|
-
return removeTimezone ? isoString.slice(0, -1) : isoString;
|
18
|
-
};
|
19
|
-
exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
|