mts-booking-library 1.3.13 → 1.3.15
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.
- package/lib/booking/booking.d.ts +30 -10
- package/lib/booking/booking.js +25 -25
- package/lib/booking/journeyBooking.d.ts +4 -13
- package/lib/booking/journeyBooking.js +36 -23
- package/lib/booking/serviceBooking.d.ts +3 -12
- package/lib/booking/serviceBooking.js +36 -23
- package/lib/booking/subscriptionBooking.d.ts +4 -13
- package/lib/booking/subscriptionBooking.js +36 -23
- package/lib/booking/tplBooking.d.ts +10 -17
- package/lib/booking/tplBooking.js +43 -28
- package/lib/config.d.ts +3 -1
- package/lib/config.js +9 -5
- package/lib/types/common/Person.d.ts +7 -8
- package/lib/types/common/Person.js +3 -0
- package/lib/types/common/Tariffs.d.ts +62 -20
- package/lib/utils/apiCall.js +3 -3
- package/package.json +3 -3
package/lib/booking/booking.d.ts
CHANGED
@@ -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
|
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
|
}
|
package/lib/booking/booking.js
CHANGED
@@ -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(
|
69
|
-
|
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)(
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
14
|
-
|
15
|
-
|
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
|
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
|
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(
|
95
|
-
|
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,
|
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 (
|
797
|
+
JourneyBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
797
798
|
var booking, error_1;
|
798
|
-
|
799
|
-
|
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(
|
802
|
-
|
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
|
-
|
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
|
-
|
809
|
-
|
821
|
+
_c.sent();
|
822
|
+
_c.label = 3;
|
810
823
|
case 3: return [2 /*return*/, booking];
|
811
824
|
case 4:
|
812
|
-
error_1 =
|
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
|
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
|
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(
|
95
|
-
|
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,
|
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 (
|
661
|
+
ServiceBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
661
662
|
var booking, error_1;
|
662
|
-
|
663
|
-
|
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(
|
666
|
-
|
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
|
-
|
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
|
-
|
673
|
-
|
685
|
+
_c.sent();
|
686
|
+
_c.label = 3;
|
674
687
|
case 3: return [2 /*return*/, booking];
|
675
688
|
case 4:
|
676
|
-
error_1 =
|
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
|
-
|
14
|
-
|
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
|
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(
|
95
|
-
|
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,
|
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 (
|
742
|
+
SubscriptionBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
742
743
|
var booking, error_1;
|
743
|
-
|
744
|
-
|
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(
|
747
|
-
|
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
|
-
|
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
|
-
|
754
|
-
|
766
|
+
_c.sent();
|
767
|
+
_c.label = 3;
|
755
768
|
case 3: return [2 /*return*/, booking];
|
756
769
|
case 4:
|
757
|
-
error_1 =
|
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
|
-
|
16
|
-
|
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
|
} & {
|
@@ -112,11 +103,13 @@ export declare class TplBooking extends Booking {
|
|
112
103
|
getTariffs(superAreaId: number, termsTypeId: number | null, onlyTickets: boolean, onlySubscriptions: boolean): Promise<ErrorResponse | GetTariffsResponse>;
|
113
104
|
/**
|
114
105
|
* This method allows to create a TPL cart.
|
115
|
-
* @param
|
116
|
-
* @param
|
117
|
-
* @param
|
106
|
+
* @param tariffIdToQuantity A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff.
|
107
|
+
* @param currency The currency in which the ticket is priced.
|
108
|
+
* @param startDate The start date of the ticket. This is optional and should be used only for subscriptions.
|
109
|
+
* @param isCurrentPeriod Whether the subscription is for the current period. This is optional and should be used only for subscriptions.
|
110
|
+
* @param renewSubscriptionTicketPNR The PNR of the subscription ticket to renew. This is optional and should be used only for subscriptions.
|
118
111
|
*/
|
119
|
-
createTplCart(tariffIdToQuantity: Map<number, number>, currency: Booking.Currencies, startDate?: string): Promise<ErrorResponse | TplCart>;
|
112
|
+
createTplCart(tariffIdToQuantity: Map<number, number>, currency: Booking.Currencies, startDate?: string, isCurrentPeriod?: boolean, renewSubscriptionTicketPNR?: string): Promise<ErrorResponse | TplCart>;
|
120
113
|
/**
|
121
114
|
* @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
|
122
115
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
@@ -175,5 +168,5 @@ export declare class TplBooking extends Booking {
|
|
175
168
|
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
176
169
|
}
|
177
170
|
export declare namespace TplBooking {
|
178
|
-
const createBooking: (env
|
171
|
+
const createBooking: ({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">) => Promise<TplBooking>;
|
179
172
|
}
|
@@ -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(
|
95
|
-
|
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,
|
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) {
|
@@ -312,11 +313,13 @@ var TplBooking = /** @class */ (function (_super) {
|
|
312
313
|
};
|
313
314
|
/**
|
314
315
|
* This method allows to create a TPL cart.
|
315
|
-
* @param
|
316
|
-
* @param
|
317
|
-
* @param
|
316
|
+
* @param tariffIdToQuantity A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff.
|
317
|
+
* @param currency The currency in which the ticket is priced.
|
318
|
+
* @param startDate The start date of the ticket. This is optional and should be used only for subscriptions.
|
319
|
+
* @param isCurrentPeriod Whether the subscription is for the current period. This is optional and should be used only for subscriptions.
|
320
|
+
* @param renewSubscriptionTicketPNR The PNR of the subscription ticket to renew. This is optional and should be used only for subscriptions.
|
318
321
|
*/
|
319
|
-
TplBooking.prototype.createTplCart = function (tariffIdToQuantity, currency, startDate) {
|
322
|
+
TplBooking.prototype.createTplCart = function (tariffIdToQuantity, currency, startDate, isCurrentPeriod, renewSubscriptionTicketPNR) {
|
320
323
|
return __awaiter(this, void 0, void 0, function () {
|
321
324
|
var url, processedTariffIdToQuantity, request;
|
322
325
|
var _this = this;
|
@@ -326,7 +329,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
326
329
|
tariffIdToQuantity.forEach(function (value, key) {
|
327
330
|
processedTariffIdToQuantity[key] = value;
|
328
331
|
});
|
329
|
-
request = __assign({ tariffIdToQuantity: processedTariffIdToQuantity, currency: currency }, (startDate && { startDate: startDate }));
|
332
|
+
request = __assign(__assign(__assign({ tariffIdToQuantity: processedTariffIdToQuantity, currency: currency }, (startDate !== undefined && { startDate: startDate })), (isCurrentPeriod !== undefined && { isCurrentPeriod: isCurrentPeriod })), (renewSubscriptionTicketPNR !== undefined && { renewSubscriptionTicketPNR: renewSubscriptionTicketPNR }));
|
330
333
|
// Call the API
|
331
334
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
332
335
|
// Check for errors
|
@@ -715,23 +718,35 @@ var TplBooking = /** @class */ (function (_super) {
|
|
715
718
|
exports.TplBooking = TplBooking;
|
716
719
|
(function (TplBooking) {
|
717
720
|
var _this = this;
|
718
|
-
TplBooking.createBooking = function (
|
721
|
+
TplBooking.createBooking = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
719
722
|
var booking, error_1;
|
720
|
-
|
721
|
-
|
723
|
+
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;
|
724
|
+
return __generator(this, function (_c) {
|
725
|
+
switch (_c.label) {
|
722
726
|
case 0:
|
723
|
-
booking = new TplBooking(
|
724
|
-
|
727
|
+
booking = new TplBooking({
|
728
|
+
env: env,
|
729
|
+
subKey: subKey,
|
730
|
+
debug: debug,
|
731
|
+
language: language,
|
732
|
+
accessToken: accessToken,
|
733
|
+
restoreState: restoreState,
|
734
|
+
sessionId: sessionId,
|
735
|
+
sellerId: sellerId,
|
736
|
+
resellerId: resellerId,
|
737
|
+
dbType: dbType
|
738
|
+
});
|
739
|
+
_c.label = 1;
|
725
740
|
case 1:
|
726
|
-
|
741
|
+
_c.trys.push([1, 4, , 5]);
|
727
742
|
if (!booking.cartId) return [3 /*break*/, 3];
|
728
743
|
return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
|
729
744
|
case 2:
|
730
|
-
|
731
|
-
|
745
|
+
_c.sent();
|
746
|
+
_c.label = 3;
|
732
747
|
case 3: return [2 /*return*/, booking];
|
733
748
|
case 4:
|
734
|
-
error_1 =
|
749
|
+
error_1 = _c.sent();
|
735
750
|
// Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
|
736
751
|
// This error can occur when the user refreshes the page and the cart has expired
|
737
752
|
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: (
|
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 (
|
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 =
|
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 =
|
37
|
-
config.ACCESS_TOKEN =
|
39
|
+
config.OCP_SUBSCRIPTION_KEY = OCP_SUBSCRIPTION_KEY;
|
40
|
+
config.ACCESS_TOKEN = ACCESS_TOKEN;
|
38
41
|
// Set debug
|
39
|
-
config.DEBUG =
|
42
|
+
config.DEBUG = DEBUG;
|
43
|
+
config.SESSION_ID = SESSION_ID;
|
40
44
|
return config;
|
41
45
|
};
|
42
46
|
exports.setConfig = setConfig;
|
@@ -37,23 +37,22 @@ export type GetPassenger = Person & {
|
|
37
37
|
returnTariffs: Map<number, PassengerTariff[]> | null;
|
38
38
|
};
|
39
39
|
export declare enum BuyerDataStatus {
|
40
|
+
/** The buyer data are optional. Buyer form shall be displayed, but the user can skip it. */
|
40
41
|
OPTIONAL = 0,
|
42
|
+
/** The buyer data are required. Buyer form shall be displayed and the user cannot skip it. */
|
41
43
|
REQUIRED = 1,
|
44
|
+
/** The buyer data cannot be specified. Buyer form shall not be displayed. */
|
42
45
|
CANNOT_BE_SPECIFIED = 2
|
43
46
|
}
|
44
47
|
/**
|
45
|
-
*
|
46
|
-
*
|
47
|
-
* @property {BuyerDataStatus} buyerDataStatus - Whether the for for the buyer data are required, optional or cannot be specified.
|
48
|
-
* - `OPTIONAL`: The buyer data are optional. Buyer form shall be displayed, but the user can skip it.
|
49
|
-
* - `REQUIRED`: The buyer data are required. Buyer form shall be displayed and the user cannot skip it.
|
50
|
-
* - `CANNOT_BE_SPECIFIED`: The buyer data cannot be specified. Buyer form shall not be displayed.
|
51
|
-
* @property {Person} buyer - The {@link Person} object representing the buyer.
|
52
|
-
* @property {GetPassenger[]} passengers - An array of {@link GetPassenger} objects representing the passengers.
|
48
|
+
* Represents the response of the {@link getBuyerPassengersDetails} method.
|
53
49
|
*/
|
54
50
|
export type GetBuyerPassengersDetailsResponse = {
|
51
|
+
/** Whether the form for the buyer data is required, optional or cannot be specified. */
|
55
52
|
buyerDataStatus: BuyerDataStatus;
|
53
|
+
/** The {@link Person} object representing the buyer. */
|
56
54
|
buyer: Person;
|
55
|
+
/** An array of {@link GetPassenger} objects representing the passengers. */
|
57
56
|
passengers: GetPassenger[];
|
58
57
|
};
|
59
58
|
/**
|
@@ -18,7 +18,10 @@ var initializePerson = function (person) {
|
|
18
18
|
exports.initializePerson = initializePerson;
|
19
19
|
var BuyerDataStatus;
|
20
20
|
(function (BuyerDataStatus) {
|
21
|
+
/** The buyer data are optional. Buyer form shall be displayed, but the user can skip it. */
|
21
22
|
BuyerDataStatus[BuyerDataStatus["OPTIONAL"] = 0] = "OPTIONAL";
|
23
|
+
/** The buyer data are required. Buyer form shall be displayed and the user cannot skip it. */
|
22
24
|
BuyerDataStatus[BuyerDataStatus["REQUIRED"] = 1] = "REQUIRED";
|
25
|
+
/** The buyer data cannot be specified. Buyer form shall not be displayed. */
|
23
26
|
BuyerDataStatus[BuyerDataStatus["CANNOT_BE_SPECIFIED"] = 2] = "CANNOT_BE_SPECIFIED";
|
24
27
|
})(BuyerDataStatus || (exports.BuyerDataStatus = BuyerDataStatus = {}));
|
@@ -1,17 +1,43 @@
|
|
1
1
|
/**
|
2
2
|
* This represents a tariff, which defined the price to pay for a certain ticket.
|
3
|
-
* @param {number} id - The id of the tariff.
|
4
|
-
* @param {number} tariffTypeId - The id of the tariff type.
|
5
|
-
* @param {number} termsTypeId - The id of the terms type.
|
6
|
-
* @param {number} value - The value of the tariff (in the currency specified in the {@link Booking} object).
|
7
|
-
* @param {number} quantity - The number of passengers to which this tariff applies.
|
8
3
|
*/
|
9
4
|
export type Tariff = {
|
5
|
+
/** The id of the tariff */
|
10
6
|
id: number;
|
7
|
+
/** The id of the tariff type */
|
11
8
|
tariffTypeId: number;
|
9
|
+
/** The id of the terms type */
|
12
10
|
termsTypeId: number;
|
11
|
+
/** The id of the tariff plan */
|
12
|
+
tariffPlanId: number;
|
13
|
+
/** The id of the seller */
|
14
|
+
sellerId: number;
|
15
|
+
/** The id of the associated segment, if any */
|
16
|
+
segmentId: number | null;
|
17
|
+
/** The id of the associated super area, if any */
|
18
|
+
superAreaId: number | null;
|
19
|
+
/** The id of the associated extra, if any */
|
20
|
+
extraId: number | null;
|
21
|
+
/** The value of the tariff (in the currency specified in the {@link Booking} object) */
|
13
22
|
value: number;
|
23
|
+
/** @deprecated Use {@link Tariff.valueCurrencies} instead */
|
24
|
+
currency: null;
|
25
|
+
/** The value of the tariff in the different currencies */
|
26
|
+
valueCurrencies: {
|
27
|
+
percentage: number | null;
|
28
|
+
eur: number | null;
|
29
|
+
usd: number | null;
|
30
|
+
chf: number | null;
|
31
|
+
id: number;
|
32
|
+
};
|
33
|
+
/** The number of passengers to which this tariff applies */
|
14
34
|
quantity: number;
|
35
|
+
/** The custom code for one-way tickets */
|
36
|
+
oneWayCode: string | null;
|
37
|
+
/** The custom code for round trip tickets */
|
38
|
+
roundTripCode: string | null;
|
39
|
+
/** Whether the tariff is active */
|
40
|
+
isActive: boolean;
|
15
41
|
};
|
16
42
|
/**
|
17
43
|
* This represents a tariff matrix, returned when searching Journeys or Services.
|
@@ -22,41 +48,57 @@ export type Tariff = {
|
|
22
48
|
export type TariffsMatrix = (Tariff | undefined)[][];
|
23
49
|
/**
|
24
50
|
* This represents a tariff type (e.g. "Adult", "Child", "Over65", ...).
|
25
|
-
* @param {number} id - The id of the tariff type in the db.
|
26
|
-
* @param {string} name - The name of the tariff type.
|
27
|
-
* @param {string} description - The description of the tariff type.
|
28
|
-
* @param {boolean} requiredPassengersName - Whether the passengers' names are required for this tariff type.
|
29
|
-
* @param {number} numberOfOccupiedSeats - The number of seats occupied by this tariff type.
|
30
|
-
* @param {string} bookingProcessDescription - A message to be shown to the user during the booking process that describes the tariff type,
|
31
|
-
* including info on the rules that apply to it.
|
32
51
|
*/
|
33
52
|
export type TariffType = {
|
53
|
+
/** The id of the tariff type in the db */
|
34
54
|
id: number;
|
55
|
+
/** The name of the tariff type */
|
35
56
|
name: string;
|
57
|
+
/** The description of the tariff type */
|
36
58
|
description: string;
|
59
|
+
/** Whether the passengers' names are required for this tariff type */
|
37
60
|
requiredPassengersName: boolean;
|
61
|
+
/** The number of seats occupied by this tariff type */
|
38
62
|
numberOfOccupiedSeats: number;
|
63
|
+
/**
|
64
|
+
* A message to be shown to the user during the booking process that describes the tariff type,
|
65
|
+
* including info on the rules that apply to it
|
66
|
+
*/
|
39
67
|
bookingProcessDescription: string;
|
40
68
|
};
|
41
69
|
/**
|
42
70
|
* This represents a terms type (e.g. "Standard", "Business", ...).
|
43
|
-
* @param {number} id - The id of the terms type in the db.
|
44
|
-
* @param {string} name - The name of the terms type.
|
45
|
-
* @param {string} description - The description of the terms type.
|
46
|
-
* @param {boolean} isRefundAllowed - Whether tickets refunds are allowed for this terms type.
|
47
|
-
* @param {boolean} isChangeAllowed - Whether changing the ticket is allowed for this terms type.
|
48
|
-
* @param {string} validationRulesString - A string containing the validation rules that apply to this terms type.
|
49
|
-
* @param {string} bookingProcessDescription - A message to be shown to the user during the booking process that describes the terms type,
|
50
|
-
* including info on the rules that apply to it.
|
51
71
|
*/
|
52
72
|
export type TermsType = {
|
73
|
+
/** The id of the terms type in the db */
|
53
74
|
id: number;
|
75
|
+
/** The name of the terms type */
|
54
76
|
name: string;
|
77
|
+
/** The description of the terms type */
|
55
78
|
description: string;
|
79
|
+
/** Whether tickets refunds are allowed for this terms type */
|
56
80
|
isRefundAllowed: boolean;
|
81
|
+
/** Whether changing the ticket is allowed for this terms type */
|
57
82
|
isChangeAllowed: boolean;
|
83
|
+
/** A string containing the validation rules that apply to this terms type */
|
58
84
|
validationRulesString: string;
|
85
|
+
/**
|
86
|
+
* A message to be shown to the user during the booking process that describes the terms type,
|
87
|
+
* including info on the rules that apply to it
|
88
|
+
*/
|
59
89
|
bookingProcessDescription: string;
|
90
|
+
/** Whether these terms are the default ones */
|
91
|
+
isDefault: boolean;
|
92
|
+
/** Whether the terms are for a subscription */
|
93
|
+
isSubscription: boolean;
|
94
|
+
/** Whether a start date can be selected for this ticket */
|
95
|
+
canSelectStartDate: boolean;
|
96
|
+
/** Whether a start date is mandatory for this ticket */
|
97
|
+
isStartDateMandatory: boolean;
|
98
|
+
/** The validation rule for these terms */
|
99
|
+
validationRule: any | null;
|
100
|
+
/** The rules associated with these terms */
|
101
|
+
rules: any | null;
|
60
102
|
};
|
61
103
|
export type TariffSummary = {
|
62
104
|
quantity: number;
|
package/lib/utils/apiCall.js
CHANGED
@@ -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.
|
3
|
+
"version": "1.3.15",
|
4
4
|
"description": "Library for using MyTicketSolution Booking API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -19,8 +19,8 @@
|
|
19
19
|
"@types/jest": "^29.5.12",
|
20
20
|
"jest": "^29.7.0",
|
21
21
|
"prettier": "^3.3.3",
|
22
|
-
"ts-jest": "^29.2.
|
23
|
-
"typescript": "^5.5.
|
22
|
+
"ts-jest": "^29.2.3",
|
23
|
+
"typescript": "^5.5.4"
|
24
24
|
},
|
25
25
|
"files": [
|
26
26
|
"lib/**/*"
|