mts-booking-library 1.3.13 → 1.3.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,17 +23,9 @@ export declare abstract class Booking {
23
23
  cartId: number | undefined;
24
24
  bookingDueDate: Date | undefined;
25
25
  /**
26
- * This is the constructor of the Booking class.
27
- * @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
28
- * @param {string} sub_key The subscription key for using the APIs
29
- * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
30
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
31
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
32
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
33
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
34
- * @param {number} [resellerId=undefined] The id of the reseller.
26
+ * This is the constructor of the Booking class. See {@link Booking.BookingConfig} for more information.
35
27
  */
36
- constructor(env: MTSEnvs, sub_key: string, bookingType: Booking.BookingTypes, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
28
+ constructor({ env, subKey, bookingType, debug, language, sessionId, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "restoreState">);
37
29
  /**
38
30
  * This method allows to update the sellerId. It is mostly important for Linkavel, as we start with sellerId = 0
39
31
  * but then it changes to the actual sellerId once the cart is created.
@@ -116,4 +108,32 @@ export declare namespace Booking {
116
108
  MLP_SUBSCRIPTION = "MLP_SUBSCRIPTION",
117
109
  TPL = "TPL"
118
110
  }
111
+ type BookingConfig = {
112
+ /** The environment in which the app is running. Can be "DEV", "STAGING" or "PROD" */
113
+ env: MTSEnvs;
114
+ /** The subscription key for using the APIs. */
115
+ subKey: string;
116
+ /** The type of booking. */
117
+ bookingType: Booking.BookingTypes;
118
+ /** If true, the app will run in debug mode (meaning that will print requests and responses in the console) */
119
+ debug: boolean;
120
+ /** The language in which the app is running. Can be "it", "en", "fr", "de" */
121
+ language: Booking.Languages;
122
+ /**
123
+ * If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage.
124
+ * After reading the cartId, the BE will be called to retrieve the status of the cart.
125
+ * E.g. set this to `true` if you want your booking to be preserved after a page refresh.
126
+ */
127
+ restoreState: boolean;
128
+ /** The id of the session, for logging purposes (optional). */
129
+ sessionId?: number | undefined;
130
+ /** The access token for calling MTS APIs */
131
+ accessToken?: string | undefined;
132
+ /** The id of the seller. If not set, it will return the results for all sellers (e.g. like LinkAvel) */
133
+ sellerId?: number;
134
+ /** The id of the reseller that is using the system. */
135
+ resellerId?: number;
136
+ /** The type of the database, only for DEV environment */
137
+ dbType?: string | undefined;
138
+ };
119
139
  }
@@ -55,19 +55,10 @@ var apiCall_1 = require("../utils/apiCall");
55
55
  var processBookingSteps_1 = require("../utils/processBookingSteps");
56
56
  var Booking = /** @class */ (function () {
57
57
  /**
58
- * This is the constructor of the Booking class.
59
- * @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
60
- * @param {string} sub_key The subscription key for using the APIs
61
- * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
62
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
63
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
64
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
65
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
66
- * @param {number} [resellerId=undefined] The id of the reseller.
58
+ * This is the constructor of the Booking class. See {@link Booking.BookingConfig} for more information.
67
59
  */
68
- function Booking(env, sub_key, bookingType, debug, language, access_token, sellerId, resellerId) {
69
- if (debug === void 0) { debug = false; }
70
- if (language === void 0) { language = Booking.Languages.EN; }
60
+ function Booking(_a) {
61
+ var env = _a.env, subKey = _a.subKey, bookingType = _a.bookingType, debug = _a.debug, language = _a.language, sessionId = _a.sessionId, accessToken = _a.accessToken, sellerId = _a.sellerId, resellerId = _a.resellerId, dbType = _a.dbType;
71
62
  this.language = Booking.Languages.EN;
72
63
  this.selectedCurrency = Booking.Currencies.EUR;
73
64
  /**
@@ -81,7 +72,14 @@ var Booking = /** @class */ (function () {
81
72
  this.bookingStepsToStatus = new Map();
82
73
  this.sellerId = sellerId || undefined;
83
74
  this.resellerId = resellerId || undefined;
84
- this.config = (0, config_1.setConfig)(env, sub_key, debug, access_token);
75
+ this.config = (0, config_1.setConfig)({
76
+ ENV: env,
77
+ OCP_SUBSCRIPTION_KEY: subKey,
78
+ DEBUG: debug,
79
+ ACCESS_TOKEN: accessToken,
80
+ DB_TYPE: dbType,
81
+ SESSION_ID: sessionId
82
+ });
85
83
  this.bookingType = bookingType;
86
84
  this.changeLanguage(language);
87
85
  }
@@ -101,24 +99,29 @@ var Booking = /** @class */ (function () {
101
99
  * @param {string} access_token The new access token
102
100
  */
103
101
  Booking.prototype.renewAccessToken = function (access_token) {
104
- (0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, this.config.DEBUG, access_token);
102
+ var newConfig = {
103
+ ENV: this.config.ENV,
104
+ OCP_SUBSCRIPTION_KEY: this.config.OCP_SUBSCRIPTION_KEY,
105
+ DEBUG: this.config.DEBUG,
106
+ ACCESS_TOKEN: access_token,
107
+ DB_TYPE: this.config.DB_TYPE
108
+ };
109
+ (0, config_1.setConfig)(newConfig);
105
110
  };
106
111
  Booking.prototype.callGetApi = function (url) {
107
112
  var _a, _b, _c, _d;
108
113
  // Add sellerId, resellerId and language to the query string.
109
114
  // If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
110
115
  // Otherwise, add it (as we are adding some parameters to the query string)
111
- var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams({
112
- sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0",
113
- resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0",
114
- language: this.language
115
- }));
116
+ var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(__assign({ sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0", resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0", language: this.language }, ((0, config_1.getConfig)().ENV === config_1.MTSEnvs.DEV &&
117
+ (0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }))));
116
118
  return (0, apiCall_1.makeGet)(completeUrl);
117
119
  };
118
120
  Booking.prototype.callPostApi = function (url, body) {
119
121
  var _a, _b, _c, _d;
120
122
  // Add sellerId, resellerId and language to the query string
121
- var completeBody = __assign(__assign({}, body), { sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 0, resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : 0, language: this.language });
123
+ var completeBody = __assign(__assign(__assign({}, body), { sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 0, resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : 0, language: this.language }), ((0, config_1.getConfig)().ENV === config_1.MTSEnvs.DEV &&
124
+ (0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }));
122
125
  return (0, apiCall_1.makePost)(url, completeBody);
123
126
  };
124
127
  Booking.prototype.callDeleteApi = function (url) {
@@ -126,11 +129,8 @@ var Booking = /** @class */ (function () {
126
129
  // Add sellerId, resellerId and language to the query string.
127
130
  // If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
128
131
  // Otherwise, add it (as we are adding some parameters to the query string)
129
- var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams({
130
- sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0",
131
- resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0",
132
- language: this.language
133
- }));
132
+ var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(__assign({ sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0", resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0", language: this.language }, ((0, config_1.getConfig)().ENV === config_1.MTSEnvs.DEV &&
133
+ (0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }))));
134
134
  return (0, apiCall_1.makeDelete)(completeUrl);
135
135
  };
136
136
  Booking.prototype.getBookingStepsToStatus = function () {
@@ -1,4 +1,3 @@
1
- import { MTSEnvs } from "../config";
2
1
  import { ErrorResponse } from "../types/ErrorResponse";
3
2
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
3
  import { AddReductionRequest } from "../types/common/Reduction";
@@ -10,17 +9,9 @@ import { Booking } from "./booking";
10
9
  export declare class JourneyBooking extends Booking {
11
10
  private cart?;
12
11
  /**
13
- * This is the constructor of the ServiceBooking class.
14
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
15
- * @param {string} sub_key The subscription key for using the APIs
16
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
17
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
18
- * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
19
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
20
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
21
- * @param {number} [resellerId=undefined] The id of the reseller.
22
- */
23
- constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
12
+ * This is the constructor of the JourneyBooking class. See {@link Booking.BookingConfig} for more information.
13
+ */
14
+ constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
24
15
  getCart(): JourneyCart | undefined;
25
16
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
26
17
  cartId: number | undefined;
@@ -183,5 +174,5 @@ export declare class JourneyBooking extends Booking {
183
174
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
184
175
  }
185
176
  export declare namespace JourneyBooking {
186
- const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
177
+ const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<JourneyBooking>;
187
178
  }
@@ -81,22 +81,23 @@ var booking_1 = require("./booking");
81
81
  var JourneyBooking = /** @class */ (function (_super) {
82
82
  __extends(JourneyBooking, _super);
83
83
  /**
84
- * This is the constructor of the ServiceBooking 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.
84
+ * This is the constructor of the JourneyBooking class. See {@link Booking.BookingConfig} for more information.
93
85
  */
94
- function JourneyBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
95
- if (debug === void 0) { debug = false; }
96
- if (language === void 0) { language = booking_1.Booking.Languages.EN; }
97
- if (restoreState === void 0) { restoreState = true; }
86
+ function JourneyBooking(_a) {
87
+ var env = _a.env, subKey = _a.subKey, debug = _a.debug, language = _a.language, sessionId = _a.sessionId, restoreState = _a.restoreState, accessToken = _a.accessToken, sellerId = _a.sellerId, resellerId = _a.resellerId, dbType = _a.dbType;
98
88
  // Call Booking constructor
99
- var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
89
+ var _this = _super.call(this, {
90
+ env: env,
91
+ subKey: subKey,
92
+ bookingType: booking_1.Booking.BookingTypes.MLP,
93
+ debug: debug,
94
+ language: language,
95
+ accessToken: accessToken,
96
+ sessionId: sessionId,
97
+ sellerId: sellerId,
98
+ resellerId: resellerId,
99
+ dbType: dbType
100
+ }) || this;
100
101
  // Set cartId
101
102
  var cartId = _this.getStorage().getState().cartId;
102
103
  if (cartId && restoreState) {
@@ -793,23 +794,35 @@ var JourneyBooking = /** @class */ (function (_super) {
793
794
  exports.JourneyBooking = JourneyBooking;
794
795
  (function (JourneyBooking) {
795
796
  var _this = this;
796
- JourneyBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
797
+ JourneyBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
797
798
  var booking, error_1;
798
- return __generator(this, function (_a) {
799
- switch (_a.label) {
799
+ var env = _b.env, subKey = _b.subKey, debug = _b.debug, language = _b.language, sessionId = _b.sessionId, restoreState = _b.restoreState, accessToken = _b.accessToken, sellerId = _b.sellerId, resellerId = _b.resellerId, dbType = _b.dbType;
800
+ return __generator(this, function (_c) {
801
+ switch (_c.label) {
800
802
  case 0:
801
- booking = new JourneyBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
802
- _a.label = 1;
803
+ booking = new JourneyBooking({
804
+ env: env,
805
+ subKey: subKey,
806
+ debug: debug,
807
+ language: language,
808
+ accessToken: accessToken,
809
+ restoreState: restoreState,
810
+ sessionId: sessionId,
811
+ sellerId: sellerId,
812
+ resellerId: resellerId,
813
+ dbType: dbType
814
+ });
815
+ _c.label = 1;
803
816
  case 1:
804
- _a.trys.push([1, 4, , 5]);
817
+ _c.trys.push([1, 4, , 5]);
805
818
  if (!booking.cartId) return [3 /*break*/, 3];
806
819
  return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
807
820
  case 2:
808
- _a.sent();
809
- _a.label = 3;
821
+ _c.sent();
822
+ _c.label = 3;
810
823
  case 3: return [2 /*return*/, booking];
811
824
  case 4:
812
- error_1 = _a.sent();
825
+ error_1 = _c.sent();
813
826
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
814
827
  // This error can occur when the user refreshes the page and the cart has expired
815
828
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
@@ -1,4 +1,3 @@
1
- import { MTSEnvs } from "../config";
2
1
  import { ErrorResponse } from "../types/ErrorResponse";
3
2
  import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
3
  import { AddReductionRequest } from "../types/common/Reduction";
@@ -8,17 +7,9 @@ import { Booking } from "./booking";
8
7
  export declare class ServiceBooking extends Booking {
9
8
  private cart?;
10
9
  /**
11
- * This is the constructor of the ServiceBooking class.
12
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
13
- * @param {string} sub_key The subscription key for using the APIs
14
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
15
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
16
- * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
17
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
18
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
19
- * @param {number} [resellerId=undefined] The id of the reseller.
10
+ * This is the constructor of the ServiceBooking class. See {@link Booking.BookingConfig} for more information.
20
11
  */
21
- constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
12
+ constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
22
13
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
23
14
  cartId: number | undefined;
24
15
  } & {
@@ -157,5 +148,5 @@ export declare class ServiceBooking extends Booking {
157
148
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
158
149
  }
159
150
  export declare namespace ServiceBooking {
160
- const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
151
+ const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<ServiceBooking>;
161
152
  }
@@ -81,22 +81,23 @@ var booking_1 = require("./booking");
81
81
  var ServiceBooking = /** @class */ (function (_super) {
82
82
  __extends(ServiceBooking, _super);
83
83
  /**
84
- * This is the constructor of the ServiceBooking 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.
84
+ * This is the constructor of the ServiceBooking class. See {@link Booking.BookingConfig} for more information.
93
85
  */
94
- function ServiceBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
95
- if (debug === void 0) { debug = false; }
96
- if (language === void 0) { language = booking_1.Booking.Languages.EN; }
97
- if (restoreState === void 0) { restoreState = true; }
86
+ function ServiceBooking(_a) {
87
+ var env = _a.env, subKey = _a.subKey, debug = _a.debug, language = _a.language, sessionId = _a.sessionId, restoreState = _a.restoreState, accessToken = _a.accessToken, sellerId = _a.sellerId, resellerId = _a.resellerId, dbType = _a.dbType;
98
88
  // Call Booking constructor
99
- var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
89
+ var _this = _super.call(this, {
90
+ env: env,
91
+ subKey: subKey,
92
+ bookingType: booking_1.Booking.BookingTypes.SERVICE,
93
+ debug: debug,
94
+ language: language,
95
+ accessToken: accessToken,
96
+ sessionId: sessionId,
97
+ sellerId: sellerId,
98
+ resellerId: resellerId,
99
+ dbType: dbType
100
+ }) || this;
100
101
  // Set cartId
101
102
  var cartId = _this.getStorage().getState().cartId;
102
103
  if (cartId && restoreState) {
@@ -657,23 +658,35 @@ var ServiceBooking = /** @class */ (function (_super) {
657
658
  exports.ServiceBooking = ServiceBooking;
658
659
  (function (ServiceBooking) {
659
660
  var _this = this;
660
- ServiceBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
661
+ ServiceBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
661
662
  var booking, error_1;
662
- return __generator(this, function (_a) {
663
- switch (_a.label) {
663
+ var env = _b.env, subKey = _b.subKey, debug = _b.debug, language = _b.language, sessionId = _b.sessionId, restoreState = _b.restoreState, accessToken = _b.accessToken, sellerId = _b.sellerId, resellerId = _b.resellerId, dbType = _b.dbType;
664
+ return __generator(this, function (_c) {
665
+ switch (_c.label) {
664
666
  case 0:
665
- booking = new ServiceBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
666
- _a.label = 1;
667
+ booking = new ServiceBooking({
668
+ env: env,
669
+ subKey: subKey,
670
+ debug: debug,
671
+ language: language,
672
+ accessToken: accessToken,
673
+ restoreState: restoreState,
674
+ sessionId: sessionId,
675
+ sellerId: sellerId,
676
+ resellerId: resellerId,
677
+ dbType: dbType
678
+ });
679
+ _c.label = 1;
667
680
  case 1:
668
- _a.trys.push([1, 4, , 5]);
681
+ _c.trys.push([1, 4, , 5]);
669
682
  if (!booking.cartId) return [3 /*break*/, 3];
670
683
  return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
671
684
  case 2:
672
- _a.sent();
673
- _a.label = 3;
685
+ _c.sent();
686
+ _c.label = 3;
674
687
  case 3: return [2 /*return*/, booking];
675
688
  case 4:
676
- error_1 = _a.sent();
689
+ error_1 = _c.sent();
677
690
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
678
691
  // This error can occur when the user refreshes the page and the cart has expired
679
692
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
@@ -1,4 +1,3 @@
1
- import { MTSEnvs } from "../config";
2
1
  import { ErrorResponse } from "../types/ErrorResponse";
3
2
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
3
  import { AddReductionRequest } from "../types/common/Reduction";
@@ -9,17 +8,9 @@ import { Booking } from "./booking";
9
8
  export declare class SubscriptionBooking extends Booking {
10
9
  private cart?;
11
10
  /**
12
- * This is the constructor of the ServiceBooking class.
13
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
14
- * @param {string} sub_key The subscription key for using the APIs
15
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
16
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
17
- * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
18
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
19
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
20
- * @param {number} [resellerId=undefined] The id of the reseller.
21
- */
22
- constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
11
+ * This is the constructor of the ServiceBooking class. See {@link Booking.BookingConfig} for more information.
12
+ */
13
+ constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
23
14
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
24
15
  cartId: number | undefined;
25
16
  } & {
@@ -175,7 +166,7 @@ export declare class SubscriptionBooking extends Booking {
175
166
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
176
167
  }
177
168
  export declare namespace SubscriptionBooking {
178
- const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
169
+ const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<SubscriptionBooking>;
179
170
  enum ValidityTypes {
180
171
  WORKING_WEEK = "WORKING_WEEK",
181
172
  ONE_WEEK = "ONE_WEEK",
@@ -81,22 +81,23 @@ var booking_1 = require("./booking");
81
81
  var SubscriptionBooking = /** @class */ (function (_super) {
82
82
  __extends(SubscriptionBooking, _super);
83
83
  /**
84
- * This is the constructor of the ServiceBooking 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.
84
+ * This is the constructor of the ServiceBooking class. See {@link Booking.BookingConfig} for more information.
93
85
  */
94
- function SubscriptionBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
95
- if (debug === void 0) { debug = false; }
96
- if (language === void 0) { language = booking_1.Booking.Languages.EN; }
97
- if (restoreState === void 0) { restoreState = true; }
86
+ function SubscriptionBooking(_a) {
87
+ var env = _a.env, subKey = _a.subKey, debug = _a.debug, language = _a.language, sessionId = _a.sessionId, restoreState = _a.restoreState, accessToken = _a.accessToken, sellerId = _a.sellerId, resellerId = _a.resellerId, dbType = _a.dbType;
98
88
  // Call Booking constructor
99
- var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
89
+ var _this = _super.call(this, {
90
+ env: env,
91
+ subKey: subKey,
92
+ bookingType: booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION,
93
+ debug: debug,
94
+ language: language,
95
+ accessToken: accessToken,
96
+ sessionId: sessionId,
97
+ sellerId: sellerId,
98
+ resellerId: resellerId,
99
+ dbType: dbType
100
+ }) || this;
100
101
  // Set cartId
101
102
  var cartId = _this.getStorage().getState().cartId;
102
103
  if (cartId && restoreState) {
@@ -738,23 +739,35 @@ var SubscriptionBooking = /** @class */ (function (_super) {
738
739
  exports.SubscriptionBooking = SubscriptionBooking;
739
740
  (function (SubscriptionBooking) {
740
741
  var _this = this;
741
- SubscriptionBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
742
+ SubscriptionBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
742
743
  var booking, error_1;
743
- return __generator(this, function (_a) {
744
- switch (_a.label) {
744
+ var env = _b.env, subKey = _b.subKey, debug = _b.debug, language = _b.language, sessionId = _b.sessionId, restoreState = _b.restoreState, accessToken = _b.accessToken, sellerId = _b.sellerId, resellerId = _b.resellerId, dbType = _b.dbType;
745
+ return __generator(this, function (_c) {
746
+ switch (_c.label) {
745
747
  case 0:
746
- booking = new SubscriptionBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
747
- _a.label = 1;
748
+ booking = new SubscriptionBooking({
749
+ env: env,
750
+ subKey: subKey,
751
+ debug: debug,
752
+ language: language,
753
+ accessToken: accessToken,
754
+ restoreState: restoreState,
755
+ sessionId: sessionId,
756
+ sellerId: sellerId,
757
+ resellerId: resellerId,
758
+ dbType: dbType
759
+ });
760
+ _c.label = 1;
748
761
  case 1:
749
- _a.trys.push([1, 4, , 5]);
762
+ _c.trys.push([1, 4, , 5]);
750
763
  if (!booking.cartId) return [3 /*break*/, 3];
751
764
  return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
752
765
  case 2:
753
- _a.sent();
754
- _a.label = 3;
766
+ _c.sent();
767
+ _c.label = 3;
755
768
  case 3: return [2 /*return*/, booking];
756
769
  case 4:
757
- error_1 = _a.sent();
770
+ error_1 = _c.sent();
758
771
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
759
772
  // This error can occur when the user refreshes the page and the cart has expired
760
773
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
@@ -1,4 +1,3 @@
1
- import { MTSEnvs } from "../config";
2
1
  import { ErrorResponse } from "../types/ErrorResponse";
3
2
  import { City } from "../types/common/City";
4
3
  import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
@@ -11,17 +10,9 @@ import { Booking } from "./booking";
11
10
  export declare class TplBooking extends Booking {
12
11
  private cart?;
13
12
  /**
14
- * This is the constructor of the TplBooking class.
15
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
16
- * @param {string} sub_key The subscription key for using the APIs
17
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
18
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
19
- * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
20
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
21
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
22
- * @param {number} [resellerId=undefined] The id of the reseller.
23
- */
24
- constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
13
+ * This is the constructor of the TplBooking class. See {@link Booking.BookingConfig} for more information.
14
+ */
15
+ constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
25
16
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
26
17
  cartId: number | undefined;
27
18
  } & {
@@ -175,5 +166,5 @@ export declare class TplBooking extends Booking {
175
166
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
176
167
  }
177
168
  export declare namespace TplBooking {
178
- const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<TplBooking>;
169
+ const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<TplBooking>;
179
170
  }
@@ -81,22 +81,23 @@ 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 {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.
84
+ * This is the constructor of the TplBooking class. See {@link Booking.BookingConfig} for more information.
93
85
  */
94
- function TplBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
95
- if (debug === void 0) { debug = false; }
96
- if (language === void 0) { language = booking_1.Booking.Languages.EN; }
97
- if (restoreState === void 0) { restoreState = true; }
86
+ function TplBooking(_a) {
87
+ var env = _a.env, subKey = _a.subKey, debug = _a.debug, language = _a.language, sessionId = _a.sessionId, restoreState = _a.restoreState, accessToken = _a.accessToken, sellerId = _a.sellerId, resellerId = _a.resellerId, dbType = _a.dbType;
98
88
  // Call Booking constructor
99
- var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.TPL, debug, language, access_token, sellerId, resellerId) || this;
89
+ var _this = _super.call(this, {
90
+ env: env,
91
+ subKey: subKey,
92
+ bookingType: booking_1.Booking.BookingTypes.TPL,
93
+ debug: debug,
94
+ language: language,
95
+ accessToken: accessToken,
96
+ sessionId: sessionId,
97
+ sellerId: sellerId,
98
+ resellerId: resellerId,
99
+ dbType: dbType
100
+ }) || this;
100
101
  // Set cartId
101
102
  var cartId = _this.getStorage().getState().cartId;
102
103
  if (cartId && restoreState) {
@@ -715,23 +716,35 @@ var TplBooking = /** @class */ (function (_super) {
715
716
  exports.TplBooking = TplBooking;
716
717
  (function (TplBooking) {
717
718
  var _this = this;
718
- TplBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
719
+ TplBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
719
720
  var booking, error_1;
720
- return __generator(this, function (_a) {
721
- switch (_a.label) {
721
+ var env = _b.env, subKey = _b.subKey, debug = _b.debug, language = _b.language, sessionId = _b.sessionId, restoreState = _b.restoreState, accessToken = _b.accessToken, sellerId = _b.sellerId, resellerId = _b.resellerId, dbType = _b.dbType;
722
+ return __generator(this, function (_c) {
723
+ switch (_c.label) {
722
724
  case 0:
723
- booking = new TplBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
724
- _a.label = 1;
725
+ booking = new TplBooking({
726
+ env: env,
727
+ subKey: subKey,
728
+ debug: debug,
729
+ language: language,
730
+ accessToken: accessToken,
731
+ restoreState: restoreState,
732
+ sessionId: sessionId,
733
+ sellerId: sellerId,
734
+ resellerId: resellerId,
735
+ dbType: dbType
736
+ });
737
+ _c.label = 1;
725
738
  case 1:
726
- _a.trys.push([1, 4, , 5]);
739
+ _c.trys.push([1, 4, , 5]);
727
740
  if (!booking.cartId) return [3 /*break*/, 3];
728
741
  return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
729
742
  case 2:
730
- _a.sent();
731
- _a.label = 3;
743
+ _c.sent();
744
+ _c.label = 3;
732
745
  case 3: return [2 /*return*/, booking];
733
746
  case 4:
734
- error_1 = _a.sent();
747
+ error_1 = _c.sent();
735
748
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
736
749
  // This error can occur when the user refreshes the page and the cart has expired
737
750
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
package/lib/config.d.ts CHANGED
@@ -10,6 +10,8 @@ export type MTSConfig = {
10
10
  OCP_SUBSCRIPTION_KEY: string;
11
11
  ACCESS_TOKEN: string | undefined;
12
12
  DEBUG: boolean;
13
+ DB_TYPE?: string | undefined;
14
+ SESSION_ID?: number | undefined;
13
15
  };
14
- export declare const setConfig: (env: MTSEnvs, sub_key: string, debug: boolean, access_token?: string) => MTSConfig;
16
+ export declare const setConfig: ({ ENV, OCP_SUBSCRIPTION_KEY, DEBUG, ACCESS_TOKEN, DB_TYPE, SESSION_ID }: Omit<MTSConfig, "API_ENDPOINT">) => MTSConfig;
15
17
  export declare const getConfig: () => MTSConfig;
package/lib/config.js CHANGED
@@ -15,13 +15,16 @@ var config = {
15
15
  ACCESS_TOKEN: undefined,
16
16
  DEBUG: false
17
17
  };
18
- var setConfig = function (env, sub_key, debug, access_token) {
18
+ var setConfig = function (_a) {
19
+ var ENV = _a.ENV, OCP_SUBSCRIPTION_KEY = _a.OCP_SUBSCRIPTION_KEY, DEBUG = _a.DEBUG, ACCESS_TOKEN = _a.ACCESS_TOKEN, DB_TYPE = _a.DB_TYPE, SESSION_ID = _a.SESSION_ID;
20
+ config.DB_TYPE = undefined;
19
21
  // First, set the environment
20
- config.ENV = env.toUpperCase();
22
+ config.ENV = ENV.toUpperCase();
21
23
  switch (config.ENV) {
22
24
  case MTSEnvs.TEST:
23
25
  case MTSEnvs.DEV:
24
26
  config.API_ENDPOINT = "https://dev-myticketsolutionapim.azure-api.net/api";
27
+ config.DB_TYPE = DB_TYPE;
25
28
  break;
26
29
  case MTSEnvs.STAGING:
27
30
  config.API_ENDPOINT = "https://stag-myticketsolutionapim.azure-api.net/api";
@@ -33,10 +36,11 @@ var setConfig = function (env, sub_key, debug, access_token) {
33
36
  throw new Error("Invalid environment");
34
37
  }
35
38
  // Set OCP and access token
36
- config.OCP_SUBSCRIPTION_KEY = sub_key;
37
- config.ACCESS_TOKEN = access_token;
39
+ config.OCP_SUBSCRIPTION_KEY = OCP_SUBSCRIPTION_KEY;
40
+ config.ACCESS_TOKEN = ACCESS_TOKEN;
38
41
  // Set debug
39
- config.DEBUG = debug;
42
+ config.DEBUG = DEBUG;
43
+ config.SESSION_ID = SESSION_ID;
40
44
  return config;
41
45
  };
42
46
  exports.setConfig = setConfig;
@@ -88,7 +88,7 @@ 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({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
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
92
  })];
93
93
  case 1:
94
94
  response = _h.sent();
@@ -143,7 +143,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
143
143
  case 0:
144
144
  _h.trys.push([0, 2, , 3]);
145
145
  return [4 /*yield*/, axios_1.default.post(url, data, {
146
- headers: __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) }))
146
+ 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 }))
147
147
  })];
148
148
  case 1:
149
149
  response = _h.sent();
@@ -198,7 +198,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
198
198
  case 0:
199
199
  _h.trys.push([0, 2, , 3]);
200
200
  return [4 /*yield*/, axios_1.default.delete(url, {
201
- headers: __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) }))
201
+ 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 }))
202
202
  })];
203
203
  case 1:
204
204
  response = _h.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "^29.5.12",
20
20
  "jest": "^29.7.0",
21
21
  "prettier": "^3.3.3",
22
- "ts-jest": "^29.2.2",
22
+ "ts-jest": "^29.2.3",
23
23
  "typescript": "^5.5.3"
24
24
  },
25
25
  "files": [