mts-booking-library 1.3.6 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,23 +81,25 @@ var booking_1 = require("./booking");
81
81
  var TplBooking = /** @class */ (function (_super) {
82
82
  __extends(TplBooking, _super);
83
83
  /**
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
- function TplBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
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 {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
90
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
91
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
92
+ * @param {number} [resellerId=undefined] The id of the reseller.
93
+ */
94
+ function TplBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
94
95
  if (debug === void 0) { debug = false; }
95
96
  if (language === void 0) { language = booking_1.Booking.Languages.EN; }
97
+ if (restoreState === void 0) { restoreState = true; }
96
98
  // Call Booking constructor
97
99
  var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.TPL, debug, language, access_token, sellerId, resellerId) || this;
98
100
  // Set cartId
99
101
  var cartId = _this.getStorage().getState().cartId;
100
- if (cartId) {
102
+ if (cartId && restoreState) {
101
103
  _this.cartId = cartId;
102
104
  }
103
105
  return _this;
@@ -166,7 +168,7 @@ var TplBooking = /** @class */ (function (_super) {
166
168
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
167
169
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
168
170
  _this.resetBooking();
169
- throw new Error(response);
171
+ throw new Error(JSON.stringify(response, null, 2));
170
172
  }
171
173
  // Check that the cart doe not have issued tickets
172
174
  if (response.cart.hasIssuedTickets) {
@@ -211,7 +213,9 @@ var TplBooking = /** @class */ (function (_super) {
211
213
  return __generator(this, function (_a) {
212
214
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/cities?");
213
215
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
214
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
216
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
217
+ ? response
218
+ : response.cities;
215
219
  })];
216
220
  });
217
221
  });
@@ -228,7 +232,9 @@ var TplBooking = /** @class */ (function (_super) {
228
232
  searchParams = new URLSearchParams({ cityId: cityId.toString() });
229
233
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/superAreasByCity?").concat(searchParams);
230
234
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
231
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.superAreas;
235
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
236
+ ? response
237
+ : response.superAreas;
232
238
  })];
233
239
  });
234
240
  });
@@ -244,7 +250,9 @@ var TplBooking = /** @class */ (function (_super) {
244
250
  searchParams = new URLSearchParams({ superAreaId: superAreaId.toString() });
245
251
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/termsTypesBySuperArea?").concat(searchParams);
246
252
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
247
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.termsTypes;
253
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
254
+ ? response
255
+ : response.termsTypes;
248
256
  })];
249
257
  });
250
258
  });
@@ -278,7 +286,10 @@ var TplBooking = /** @class */ (function (_super) {
278
286
  tariffs
279
287
  ];
280
288
  }));
281
- return { tariffs: response.tariffs, tariffPlanToTariffs: tariffPlanToTariffs };
289
+ return {
290
+ tariffs: response.tariffs,
291
+ tariffPlanToTariffs: tariffPlanToTariffs
292
+ };
282
293
  })];
283
294
  });
284
295
  });
@@ -351,7 +362,7 @@ var TplBooking = /** @class */ (function (_super) {
351
362
  return {
352
363
  buyerDataStatus: response.buyerDataStatus,
353
364
  buyer: response.buyer,
354
- passengers: [],
365
+ passengers: []
355
366
  };
356
367
  })];
357
368
  });
@@ -413,7 +424,7 @@ var TplBooking = /** @class */ (function (_super) {
413
424
  }
414
425
  request = {
415
426
  buyer: buyerDetails,
416
- passengers: [],
427
+ passengers: []
417
428
  };
418
429
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
419
430
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
@@ -518,9 +529,11 @@ var TplBooking = /** @class */ (function (_super) {
518
529
  // Update the booking process status
519
530
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
520
531
  // 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) { return reduction.type === Reduction_1.ReductionType.WALLET ||
522
- reduction.type === Reduction_1.ReductionType.VOUCHER ||
523
- (reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId); })) !== null && _c !== void 0 ? _c : [] });
532
+ _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) {
533
+ return reduction.type === Reduction_1.ReductionType.WALLET ||
534
+ reduction.type === Reduction_1.ReductionType.VOUCHER ||
535
+ (reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
536
+ })) !== null && _c !== void 0 ? _c : [] });
524
537
  return true;
525
538
  })];
526
539
  });
@@ -548,7 +561,11 @@ var TplBooking = /** @class */ (function (_super) {
548
561
  if (!issueStep)
549
562
  throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
550
563
  if (!!issueStep[0]) return [3 /*break*/, 5];
551
- _i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
564
+ _i = 0, _a = [
565
+ booking_1.Booking.BookingSteps.SEATS_SELECTION,
566
+ booking_1.Booking.BookingSteps.EXTRAS,
567
+ booking_1.Booking.BookingSteps.DISCOUNTS
568
+ ];
552
569
  _c.label = 1;
553
570
  case 1:
554
571
  if (!(_i < _a.length)) return [3 /*break*/, 4];
@@ -682,12 +699,12 @@ var TplBooking = /** @class */ (function (_super) {
682
699
  exports.TplBooking = TplBooking;
683
700
  (function (TplBooking) {
684
701
  var _this = this;
685
- TplBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
702
+ TplBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
686
703
  var booking, error_1;
687
704
  return __generator(this, function (_a) {
688
705
  switch (_a.label) {
689
706
  case 0:
690
- booking = new TplBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
707
+ booking = new TplBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
691
708
  _a.label = 1;
692
709
  case 1:
693
710
  _a.trys.push([1, 4, , 5]);
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 !== 'undefined') {
33
+ if (typeof document !== "undefined") {
34
34
  // Web application
35
35
  return exports.useMtsBookingLocalState;
36
36
  }
@@ -10,4 +10,4 @@ export type ErrorResponse = {
10
10
  mtsCode: number;
11
11
  message: string;
12
12
  };
13
- export declare const objectIsMTSErrorResponse: (error: any) => boolean;
13
+ export declare const objectIsMTSErrorResponse: (error: any) => error is ErrorResponse;
@@ -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} axeptA_BNL_SmartLicenseKey The smart license key of the Axepta BNL gateway
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
- axeptA_BNL_SmartLicenseKey: string | null;
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) {
@@ -6,5 +6,5 @@ exports.DEFAULT_CREATE_JOURNEY_CART = {
6
6
  cartId: 0,
7
7
  currency: booking_1.Booking.Currencies.EUR,
8
8
  outboundJourney: [],
9
- returnJourney: null,
9
+ returnJourney: null
10
10
  };
@@ -11,5 +11,5 @@ exports.DEFAULT_JOURNEY_SEARCH = {
11
11
  .slice(0, -1),
12
12
  roundTripDate: null,
13
13
  currency: booking_1.Booking.Currencies.EUR,
14
- isRoundtrip: false,
14
+ isRoundtrip: false
15
15
  };
@@ -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).filter(function (key) { return key !== "error"; })
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 && { "Authorization": "Bearer ".concat((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 && { "Authorization": "Bearer ".concat((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 && { "Authorization": "Bearer ".concat((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.6",
3
+ "version": "1.3.8",
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
  },