mts-booking-library 1.3.6 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +10 -10
- package/lib/booking/booking.js +30 -16
- package/lib/booking/journeyBooking.d.ts +22 -22
- package/lib/booking/journeyBooking.js +61 -41
- package/lib/booking/serviceBooking.d.ts +30 -30
- package/lib/booking/serviceBooking.js +52 -40
- package/lib/booking/subscriptionBooking.d.ts +34 -34
- package/lib/booking/subscriptionBooking.js +70 -52
- package/lib/booking/tplBooking.d.ts +9 -9
- package/lib/booking/tplBooking.js +35 -20
- package/lib/mtsStorage.js +2 -2
- package/lib/types/ErrorResponse.d.ts +1 -1
- package/lib/types/ErrorResponse.js +1 -1
- package/lib/types/common/Payment.d.ts +4 -2
- package/lib/types/common/Person.d.ts +1 -1
- package/lib/types/common/Person.js +4 -4
- package/lib/types/journeys/JourneyCart.js +1 -1
- package/lib/types/journeys/JourneySearch.js +1 -1
- package/lib/utils/apiCall.js +9 -8
- package/package.json +5 -2
@@ -81,15 +81,15 @@ var booking_1 = require("./booking");
|
|
81
81
|
var TplBooking = /** @class */ (function (_super) {
|
82
82
|
__extends(TplBooking, _super);
|
83
83
|
/**
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
* This is the constructor of the TplBooking class.
|
85
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
86
|
+
* @param {string} sub_key The subscription key for using the APIs
|
87
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
88
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
89
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
90
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
91
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
92
|
+
*/
|
93
93
|
function TplBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
|
94
94
|
if (debug === void 0) { debug = false; }
|
95
95
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
@@ -166,7 +166,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
166
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
167
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
168
168
|
_this.resetBooking();
|
169
|
-
throw new Error(response);
|
169
|
+
throw new Error(JSON.stringify(response, null, 2));
|
170
170
|
}
|
171
171
|
// Check that the cart doe not have issued tickets
|
172
172
|
if (response.cart.hasIssuedTickets) {
|
@@ -211,7 +211,9 @@ var TplBooking = /** @class */ (function (_super) {
|
|
211
211
|
return __generator(this, function (_a) {
|
212
212
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
|
213
213
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
214
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
214
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
215
|
+
? response
|
216
|
+
: response.cities;
|
215
217
|
})];
|
216
218
|
});
|
217
219
|
});
|
@@ -228,7 +230,9 @@ var TplBooking = /** @class */ (function (_super) {
|
|
228
230
|
searchParams = new URLSearchParams({ cityId: cityId.toString() });
|
229
231
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/superAreasByCity?").concat(searchParams);
|
230
232
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
231
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
233
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
234
|
+
? response
|
235
|
+
: response.superAreas;
|
232
236
|
})];
|
233
237
|
});
|
234
238
|
});
|
@@ -244,7 +248,9 @@ var TplBooking = /** @class */ (function (_super) {
|
|
244
248
|
searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
|
245
249
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/termsTypesBySuperArea?").concat(searchParams);
|
246
250
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
247
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
251
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
252
|
+
? response
|
253
|
+
: response.termsTypes;
|
248
254
|
})];
|
249
255
|
});
|
250
256
|
});
|
@@ -278,7 +284,10 @@ var TplBooking = /** @class */ (function (_super) {
|
|
278
284
|
tariffs
|
279
285
|
];
|
280
286
|
}));
|
281
|
-
return {
|
287
|
+
return {
|
288
|
+
tariffs: response.tariffs,
|
289
|
+
tariffPlanToTariffs: tariffPlanToTariffs
|
290
|
+
};
|
282
291
|
})];
|
283
292
|
});
|
284
293
|
});
|
@@ -351,7 +360,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
351
360
|
return {
|
352
361
|
buyerDataStatus: response.buyerDataStatus,
|
353
362
|
buyer: response.buyer,
|
354
|
-
passengers: []
|
363
|
+
passengers: []
|
355
364
|
};
|
356
365
|
})];
|
357
366
|
});
|
@@ -413,7 +422,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
413
422
|
}
|
414
423
|
request = {
|
415
424
|
buyer: buyerDetails,
|
416
|
-
passengers: []
|
425
|
+
passengers: []
|
417
426
|
};
|
418
427
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
419
428
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
@@ -518,9 +527,11 @@ var TplBooking = /** @class */ (function (_super) {
|
|
518
527
|
// Update the booking process status
|
519
528
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
520
529
|
// Update the cart
|
521
|
-
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
|
522
|
-
reduction.type === Reduction_1.ReductionType.
|
523
|
-
|
530
|
+
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
|
531
|
+
return reduction.type === Reduction_1.ReductionType.WALLET ||
|
532
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
533
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
|
534
|
+
})) !== null && _c !== void 0 ? _c : [] });
|
524
535
|
return true;
|
525
536
|
})];
|
526
537
|
});
|
@@ -548,7 +559,11 @@ var TplBooking = /** @class */ (function (_super) {
|
|
548
559
|
if (!issueStep)
|
549
560
|
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
550
561
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
551
|
-
_i = 0, _a = [
|
562
|
+
_i = 0, _a = [
|
563
|
+
booking_1.Booking.BookingSteps.SEATS_SELECTION,
|
564
|
+
booking_1.Booking.BookingSteps.EXTRAS,
|
565
|
+
booking_1.Booking.BookingSteps.DISCOUNTS
|
566
|
+
];
|
552
567
|
_c.label = 1;
|
553
568
|
case 1:
|
554
569
|
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
package/lib/mtsStorage.js
CHANGED
@@ -16,7 +16,7 @@ var async_storage_1 = require("@react-native-async-storage/async-storage");
|
|
16
16
|
var zustand_1 = require("zustand");
|
17
17
|
var middleware_1 = require("zustand/middleware");
|
18
18
|
var INITIAL_STATE = {
|
19
|
-
cartId: 0
|
19
|
+
cartId: 0
|
20
20
|
};
|
21
21
|
var useMtsBookingAsyncState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId) { return set(function () { return ({ cartId: cartId }); }); }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
|
22
22
|
name: "mts-booking-storage",
|
@@ -30,7 +30,7 @@ exports.useMtsBookingLocalState = (0, zustand_1.create)((0, middleware_1.persist
|
|
30
30
|
* This hook will return the correct Zustand state based on the application which runs the library
|
31
31
|
*/
|
32
32
|
var useMtsBookingState = function () {
|
33
|
-
if (typeof document !==
|
33
|
+
if (typeof document !== "undefined") {
|
34
34
|
// Web application
|
35
35
|
return exports.useMtsBookingLocalState;
|
36
36
|
}
|
@@ -2,6 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.objectIsMTSErrorResponse = void 0;
|
4
4
|
var objectIsMTSErrorResponse = function (error) {
|
5
|
-
return "mtsCode" in error && "httpStatus" in error && "message" in error;
|
5
|
+
return (typeof error === "object" && "mtsCode" in error && "httpStatus" in error && "message" in error);
|
6
6
|
};
|
7
7
|
exports.objectIsMTSErrorResponse = objectIsMTSErrorResponse;
|
@@ -27,20 +27,22 @@ export type GetSellerGatewaysResponse = {
|
|
27
27
|
* @param {string | null} axervE_BANCASELLA_PaymentToken The payment token of the Axerve Bancasella gateway
|
28
28
|
* @param {string | null} axervE_BANCASELLA_ShopLogin The shop login of the Axerve Bancasella gateway
|
29
29
|
* @param {string | null} axeptA_BNL_PaymentId The payment id of the Axepta BNL gateway
|
30
|
-
* @param {string | null}
|
30
|
+
* @param {string | null} axeptA_BNL_EasyCheckoutLicenseKey The easy checkout license key of the Axepta BNL gateway
|
31
31
|
* @param {string | null} paypaL_ClientId The client id of the PayPal gateway
|
32
32
|
* @param {string | null} paypaL_OrderId The order id of the PayPal gateway
|
33
33
|
* @param {string | null} paypaL_Link The link of the PayPal gateway
|
34
|
+
* @param {string | null} worldlinE_REDIRECT_URL The redirect URL of the Worldline gateway
|
34
35
|
*/
|
35
36
|
export type GetPaymentInformationFromGatewayResponse = {
|
36
37
|
axervE_BANCASELLA_PaymentId: string | null;
|
37
38
|
axervE_BANCASELLA_PaymentToken: string | null;
|
38
39
|
axervE_BANCASELLA_ShopLogin: string | null;
|
39
40
|
axeptA_BNL_PaymentId: string | null;
|
40
|
-
|
41
|
+
axeptA_BNL_EasyCheckoutLicenseKey: string | null;
|
41
42
|
paypaL_ClientId: string | null;
|
42
43
|
paypaL_OrderId: string | null;
|
43
44
|
paypaL_Link: string | null;
|
45
|
+
worldlinE_REDIRECT_URL: string | null;
|
44
46
|
};
|
45
47
|
/**
|
46
48
|
* @description This enum contains the possible values for the `type` field of the {@link Gateway} type
|
@@ -29,7 +29,7 @@ export declare const initializePerson: (person?: Person | undefined | null) => P
|
|
29
29
|
* the tariff for the passenger.
|
30
30
|
* @property {string} returnNotes - The notes for the return trip.
|
31
31
|
* @property { Map<number, PassengerTariff>} returnTariffs - Same of `outboundTariffs`, but for the return trip.
|
32
|
-
*/
|
32
|
+
*/
|
33
33
|
export type GetPassenger = Person & {
|
34
34
|
outboundNotes: string | null;
|
35
35
|
outboundTariffs: Map<number, PassengerTariff[]>;
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = void 0;
|
5
5
|
exports.DEFAULT_PERSON = {
|
6
6
|
id: 0,
|
7
|
-
name:
|
8
|
-
lastName:
|
9
|
-
email:
|
10
|
-
phoneNumber:
|
7
|
+
name: "",
|
8
|
+
lastName: "",
|
9
|
+
email: "",
|
10
|
+
phoneNumber: ""
|
11
11
|
};
|
12
12
|
var initializePerson = function (person) {
|
13
13
|
if (!person) {
|
package/lib/utils/apiCall.js
CHANGED
@@ -59,10 +59,11 @@ var axios_1 = require("axios");
|
|
59
59
|
var config_1 = require("../config");
|
60
60
|
var removeNullError = function (resData) {
|
61
61
|
var filteredResponse = {};
|
62
|
-
Object.keys(resData)
|
62
|
+
Object.keys(resData)
|
63
|
+
.filter(function (key) { return key !== "error"; })
|
63
64
|
.map(function (key) {
|
64
65
|
var _a;
|
65
|
-
return filteredResponse = __assign(__assign({}, filteredResponse), (_a = {}, _a[key] = resData[key], _a));
|
66
|
+
return (filteredResponse = __assign(__assign({}, filteredResponse), (_a = {}, _a[key] = resData[key], _a)));
|
66
67
|
});
|
67
68
|
return filteredResponse;
|
68
69
|
};
|
@@ -81,7 +82,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
81
82
|
case 0:
|
82
83
|
_h.trys.push([0, 2, , 3]);
|
83
84
|
return [4 /*yield*/, axios_1.default.get(url, {
|
84
|
-
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && {
|
85
|
+
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
|
85
86
|
})];
|
86
87
|
case 1:
|
87
88
|
response = _h.sent();
|
@@ -97,7 +98,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
97
98
|
resError = {
|
98
99
|
httpStatus: ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
|
99
100
|
mtsCode: ((_d = (_c = (_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
|
100
|
-
message: ((_g = (_f = (_e = error_1.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
|
101
|
+
message: ((_g = (_f = (_e = error_1.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
|
101
102
|
};
|
102
103
|
if (debug) {
|
103
104
|
console.log("GET_ResponseError", url, resError);
|
@@ -131,7 +132,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
131
132
|
case 0:
|
132
133
|
_h.trys.push([0, 2, , 3]);
|
133
134
|
return [4 /*yield*/, axios_1.default.post(url, data, {
|
134
|
-
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && {
|
135
|
+
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
|
135
136
|
})];
|
136
137
|
case 1:
|
137
138
|
response = _h.sent();
|
@@ -147,7 +148,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
147
148
|
resError = {
|
148
149
|
httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
|
149
150
|
mtsCode: ((_d = (_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
|
150
|
-
message: ((_g = (_f = (_e = error_2.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
|
151
|
+
message: ((_g = (_f = (_e = error_2.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
|
151
152
|
};
|
152
153
|
if (debug) {
|
153
154
|
console.log("POST_ResponseError", url, resError);
|
@@ -181,7 +182,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
|
|
181
182
|
case 0:
|
182
183
|
_h.trys.push([0, 2, , 3]);
|
183
184
|
return [4 /*yield*/, axios_1.default.delete(url, {
|
184
|
-
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && {
|
185
|
+
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
|
185
186
|
})];
|
186
187
|
case 1:
|
187
188
|
response = _h.sent();
|
@@ -197,7 +198,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
|
|
197
198
|
resError = {
|
198
199
|
httpStatus: ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
|
199
200
|
mtsCode: ((_d = (_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
|
200
|
-
message: ((_g = (_f = (_e = error_3.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
|
201
|
+
message: ((_g = (_f = (_e = error_3.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
|
201
202
|
};
|
202
203
|
if (debug) {
|
203
204
|
console.log("DELETE_ResponseError", url, resError);
|
package/package.json
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
{
|
2
2
|
"name": "mts-booking-library",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.7",
|
4
4
|
"description": "Library for using MyTicketSolution Booking API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
7
7
|
"scripts": {
|
8
8
|
"build": "tsc",
|
9
|
+
"pretest": "tsc --noEmit",
|
9
10
|
"test": "jest --config jestconfig.json",
|
10
11
|
"prepare": "npm run build",
|
11
12
|
"prepublishOnly": "npm run test --runInBand",
|
12
13
|
"version": "git add -A src",
|
13
|
-
"postversion": "git push && git push --tags"
|
14
|
+
"postversion": "git push && git push --tags",
|
15
|
+
"format": "prettier --write src/**"
|
14
16
|
},
|
15
17
|
"license": "ISC",
|
16
18
|
"devDependencies": {
|
17
19
|
"@types/jest": "^29.5.12",
|
18
20
|
"jest": "^29.7.0",
|
21
|
+
"prettier": "^3.2.5",
|
19
22
|
"ts-jest": "^29.1.2",
|
20
23
|
"typescript": "^5.4.5"
|
21
24
|
},
|