mts-booking-library 1.1.6 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +17 -3
- package/lib/booking/booking.js +52 -4
- package/lib/booking/journeyBooking.d.ts +13 -6
- package/lib/booking/journeyBooking.js +53 -36
- package/lib/booking/serviceBooking.d.ts +12 -1
- package/lib/booking/serviceBooking.js +27 -14
- package/lib/booking/subscriptionBooking.d.ts +12 -1
- package/lib/booking/subscriptionBooking.js +51 -31
- package/lib/config.js +1 -1
- package/package.json +1 -1
- package/lib/types/subscriptions/Subscrptions.d.ts +0 -12
- package/lib/types/subscriptions/Subscrptions.js +0 -2
package/lib/booking/booking.d.ts
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
import { MTSConfig, MTSEnvs } from "../config";
|
2
2
|
export declare abstract class Booking {
|
3
3
|
readonly sellerId?: number | undefined;
|
4
|
+
readonly resellerId?: number | undefined;
|
4
5
|
readonly bookingType: Booking.BookingTypes;
|
5
6
|
readonly config: MTSConfig;
|
7
|
+
language: string;
|
6
8
|
selectedCurrency: Booking.Currencies;
|
7
9
|
cartStatus: Booking.CartStatus;
|
8
10
|
bookingDueDate: Date | undefined;
|
9
11
|
onCartExpiration: () => void;
|
10
12
|
/**
|
11
13
|
* This is the constructor of the Booking class.
|
12
|
-
* @param {string} env The environment in which the app is running. Can be "
|
14
|
+
* @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
13
15
|
* @param {string} sub_key The subscription key for using the APIs
|
14
16
|
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
15
17
|
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
16
|
-
* @param {
|
18
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
19
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
17
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.
|
18
22
|
*/
|
19
|
-
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, bookingType: Booking.BookingTypes, debug?: boolean,
|
23
|
+
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, bookingType: Booking.BookingTypes, debug?: boolean, language?: string, sellerId?: number, resellerId?: number);
|
20
24
|
/**
|
21
25
|
* This method allows to renew the access token for calling MTS APIs
|
22
26
|
* @param {string} access_token The new access token
|
23
27
|
*/
|
24
28
|
renewAccessToken(access_token: string): void;
|
29
|
+
callGetApi(url: string): Promise<any>;
|
30
|
+
callPostApi(url: string, body: any): Promise<any>;
|
25
31
|
getCartStatus(): Booking.CartStatus;
|
26
32
|
changeCurrency(currency: Booking.Currencies): void;
|
33
|
+
changeLanguage(language: string): void;
|
27
34
|
getCartExpirationTimeInMs(): Promise<number>;
|
28
35
|
}
|
29
36
|
export declare namespace Booking {
|
@@ -32,6 +39,13 @@ export declare namespace Booking {
|
|
32
39
|
USD = "USD",
|
33
40
|
CHF = "CHF"
|
34
41
|
}
|
42
|
+
enum Languages {
|
43
|
+
IT = "it",
|
44
|
+
EN = "en",
|
45
|
+
FR = "fr",
|
46
|
+
DE = "de",
|
47
|
+
ES = "es"
|
48
|
+
}
|
35
49
|
enum CartStatus {
|
36
50
|
EMPTY = "EMPTY",
|
37
51
|
CREATION = "CREATION",
|
package/lib/booking/booking.js
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -38,24 +49,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
50
|
exports.Booking = void 0;
|
40
51
|
var config_1 = require("../config");
|
52
|
+
var apiCall_1 = require("../utils/apiCall");
|
41
53
|
var Booking = /** @class */ (function () {
|
42
54
|
/**
|
43
55
|
* This is the constructor of the Booking class.
|
44
|
-
* @param {string} env The environment in which the app is running. Can be "
|
56
|
+
* @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
45
57
|
* @param {string} sub_key The subscription key for using the APIs
|
46
58
|
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
47
59
|
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
48
|
-
* @param {
|
60
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
61
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
49
62
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
63
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
50
64
|
*/
|
51
|
-
function Booking(env, sub_key, onCartExpiration, bookingType, debug,
|
65
|
+
function Booking(env, sub_key, onCartExpiration, bookingType, debug, language, sellerId, resellerId) {
|
52
66
|
if (debug === void 0) { debug = false; }
|
67
|
+
if (language === void 0) { language = Booking.Languages.EN; }
|
68
|
+
this.language = Booking.Languages.EN;
|
53
69
|
this.selectedCurrency = Booking.Currencies.EUR;
|
54
70
|
this.cartStatus = Booking.CartStatus.EMPTY;
|
55
71
|
this.sellerId = sellerId || undefined;
|
56
|
-
this.
|
72
|
+
this.resellerId = resellerId || undefined;
|
73
|
+
this.config = (0, config_1.setConfig)(env, sub_key, debug);
|
57
74
|
this.bookingType = bookingType;
|
58
75
|
this.onCartExpiration = onCartExpiration;
|
76
|
+
this.changeLanguage(language);
|
59
77
|
}
|
60
78
|
/**
|
61
79
|
* This method allows to renew the access token for calling MTS APIs
|
@@ -64,12 +82,34 @@ var Booking = /** @class */ (function () {
|
|
64
82
|
Booking.prototype.renewAccessToken = function (access_token) {
|
65
83
|
(0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, this.config.DEBUG, access_token);
|
66
84
|
};
|
85
|
+
Booking.prototype.callGetApi = function (url) {
|
86
|
+
// Add sellerId, resellerId and language to the query string.
|
87
|
+
// If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
|
88
|
+
// Otherwise, add it (as we are adding some parameters to the query string)
|
89
|
+
var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(__assign(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language })));
|
90
|
+
return (0, apiCall_1.makeGet)(completeUrl);
|
91
|
+
};
|
92
|
+
Booking.prototype.callPostApi = function (url, body) {
|
93
|
+
// Add sellerId, resellerId and language to the query string
|
94
|
+
var completeBody = __assign(__assign(__assign(__assign({}, body), (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language });
|
95
|
+
return (0, apiCall_1.makePost)(url, completeBody);
|
96
|
+
};
|
67
97
|
Booking.prototype.getCartStatus = function () {
|
68
98
|
return this.cartStatus;
|
69
99
|
};
|
70
100
|
Booking.prototype.changeCurrency = function (currency) {
|
71
101
|
this.selectedCurrency = currency;
|
72
102
|
};
|
103
|
+
Booking.prototype.changeLanguage = function (language) {
|
104
|
+
// If the request language is supported, set it as the new language
|
105
|
+
if (Object.values(Booking.Languages).includes(language.toLowerCase())) {
|
106
|
+
this.language = language.toLowerCase();
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
// Otherwise, set the default language (English)
|
110
|
+
this.language = Booking.Languages.EN;
|
111
|
+
}
|
112
|
+
};
|
73
113
|
Booking.prototype.getCartExpirationTimeInMs = function () {
|
74
114
|
return __awaiter(this, void 0, void 0, function () {
|
75
115
|
return __generator(this, function (_a) {
|
@@ -93,6 +133,14 @@ exports.Booking = Booking;
|
|
93
133
|
Currencies["USD"] = "USD";
|
94
134
|
Currencies["CHF"] = "CHF";
|
95
135
|
})(Currencies = Booking.Currencies || (Booking.Currencies = {}));
|
136
|
+
var Languages;
|
137
|
+
(function (Languages) {
|
138
|
+
Languages["IT"] = "it";
|
139
|
+
Languages["EN"] = "en";
|
140
|
+
Languages["FR"] = "fr";
|
141
|
+
Languages["DE"] = "de";
|
142
|
+
Languages["ES"] = "es";
|
143
|
+
})(Languages = Booking.Languages || (Booking.Languages = {}));
|
96
144
|
var CartStatus;
|
97
145
|
(function (CartStatus) {
|
98
146
|
CartStatus["EMPTY"] = "EMPTY";
|
@@ -5,7 +5,18 @@ import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/Jou
|
|
5
5
|
import { Booking } from "./booking";
|
6
6
|
export declare class JourneyBooking extends Booking {
|
7
7
|
private cart?;
|
8
|
-
|
8
|
+
/**
|
9
|
+
* This is the constructor of the ServiceBooking class.
|
10
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
11
|
+
* @param {string} sub_key The subscription key for using the APIs
|
12
|
+
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
13
|
+
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
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 {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
17
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
18
|
+
*/
|
19
|
+
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, sellerId?: number, resellerId?: number);
|
9
20
|
getCart(): JourneyCart | undefined;
|
10
21
|
private fetchAndSetCart;
|
11
22
|
private createCartTimer;
|
@@ -30,11 +41,7 @@ export declare class JourneyBooking extends Booking {
|
|
30
41
|
*/
|
31
42
|
getJourneys(params: JourneySearchRequest): Promise<JourneySearchResult[]>;
|
32
43
|
createJourneyCart(tripCart: CreateJourneyCartRequest): Promise<JourneyCart>;
|
33
|
-
getBusMatrix(
|
34
|
-
tripId: number;
|
35
|
-
departureStopId: number;
|
36
|
-
destinationStopId: number;
|
37
|
-
}): Promise<any>;
|
44
|
+
getBusMatrix(tripId: number, departureStopId: number, destinationStopId: number): Promise<any>;
|
38
45
|
getSeatsStatus(params: {
|
39
46
|
tripId: number;
|
40
47
|
departureStopId: number;
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
15
|
};
|
16
16
|
})();
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
18
|
-
__assign = Object.assign || function(t) {
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
20
|
-
s = arguments[i];
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
22
|
-
t[p] = s[p];
|
23
|
-
}
|
24
|
-
return t;
|
25
|
-
};
|
26
|
-
return __assign.apply(this, arguments);
|
27
|
-
};
|
28
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
29
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
30
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -63,15 +52,26 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
63
52
|
};
|
64
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
65
54
|
exports.JourneyBooking = void 0;
|
66
|
-
var apiCall_1 = require("../utils/apiCall");
|
67
55
|
var booking_1 = require("./booking");
|
68
56
|
var JourneyBooking = /** @class */ (function (_super) {
|
69
57
|
__extends(JourneyBooking, _super);
|
70
|
-
|
58
|
+
/**
|
59
|
+
* This is the constructor of the ServiceBooking class.
|
60
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
61
|
+
* @param {string} sub_key The subscription key for using the APIs
|
62
|
+
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
63
|
+
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
64
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
65
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
66
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
67
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
68
|
+
*/
|
69
|
+
function JourneyBooking(env, sub_key, onCartExpiration, debug, language, sellerId, resellerId) {
|
71
70
|
if (debug === void 0) { debug = false; }
|
71
|
+
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
72
72
|
var _this =
|
73
73
|
// Call Booking constructor
|
74
|
-
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug,
|
74
|
+
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, language, sellerId, resellerId) || this;
|
75
75
|
var cartId = localStorage.getItem("cartId");
|
76
76
|
if (cartId) {
|
77
77
|
_this.fetchAndSetCart(parseInt(cartId));
|
@@ -118,8 +118,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
118
118
|
return __awaiter(this, void 0, void 0, function () {
|
119
119
|
var url;
|
120
120
|
return __generator(this, function (_a) {
|
121
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart
|
122
|
-
return [2 /*return*/,
|
121
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
122
|
+
return [2 /*return*/, this.callGetApi(url)];
|
123
123
|
});
|
124
124
|
});
|
125
125
|
};
|
@@ -131,8 +131,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
131
131
|
return __awaiter(this, void 0, void 0, function () {
|
132
132
|
var url;
|
133
133
|
return __generator(this, function (_a) {
|
134
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/departures?")
|
135
|
-
return [2 /*return*/,
|
134
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/departures?");
|
135
|
+
return [2 /*return*/, this.callGetApi(url)];
|
136
136
|
});
|
137
137
|
});
|
138
138
|
};
|
@@ -143,10 +143,11 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
143
143
|
*/
|
144
144
|
JourneyBooking.prototype.getJourneysDestinations = function (departureStopName) {
|
145
145
|
return __awaiter(this, void 0, void 0, function () {
|
146
|
-
var url;
|
146
|
+
var searchParams, url;
|
147
147
|
return __generator(this, function (_a) {
|
148
|
-
|
149
|
-
|
148
|
+
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
149
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/destinations?").concat(searchParams);
|
150
|
+
return [2 /*return*/, this.callGetApi(url)];
|
150
151
|
});
|
151
152
|
});
|
152
153
|
};
|
@@ -159,13 +160,22 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
159
160
|
*/
|
160
161
|
JourneyBooking.prototype.getJourneys = function (params) {
|
161
162
|
return __awaiter(this, void 0, void 0, function () {
|
162
|
-
var url;
|
163
|
+
var searchParams, url;
|
163
164
|
return __generator(this, function (_a) {
|
164
165
|
if (params.departureStopName === undefined || params.destinationStopName === undefined) {
|
165
166
|
throw Error("Fields departureStopName and destinationStopName are required");
|
166
167
|
}
|
167
|
-
|
168
|
-
|
168
|
+
searchParams = new URLSearchParams({
|
169
|
+
departureStopName: params.departureStopName,
|
170
|
+
destinationStopName: params.destinationStopName,
|
171
|
+
passengersNumber: params.passengersNumber.toString(),
|
172
|
+
date: params.date,
|
173
|
+
roundTripDate: params.roundTripDate ? params.roundTripDate : "null",
|
174
|
+
currency: params.currency,
|
175
|
+
isRoundtrip: params.isRoundtrip.toString()
|
176
|
+
});
|
177
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys?").concat(searchParams);
|
178
|
+
return [2 /*return*/, this.callGetApi(url)];
|
169
179
|
});
|
170
180
|
});
|
171
181
|
};
|
@@ -175,7 +185,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
175
185
|
var _this = this;
|
176
186
|
return __generator(this, function (_a) {
|
177
187
|
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/cart");
|
178
|
-
return [2 /*return*/,
|
188
|
+
return [2 /*return*/, this.callPostApi(url, tripCart).then(function (cart) {
|
179
189
|
_this.cart = cart.cart;
|
180
190
|
_this.cartStatus = cart.cart.status;
|
181
191
|
_this.bookingDueDate = new Date(cart.cart.bookingDueDate);
|
@@ -185,27 +195,34 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
185
195
|
});
|
186
196
|
});
|
187
197
|
};
|
188
|
-
JourneyBooking.prototype.getBusMatrix = function (
|
198
|
+
JourneyBooking.prototype.getBusMatrix = function (tripId, departureStopId, destinationStopId) {
|
189
199
|
return __awaiter(this, void 0, void 0, function () {
|
190
|
-
var url;
|
200
|
+
var searchParams, url;
|
191
201
|
return __generator(this, function (_a) {
|
192
|
-
|
193
|
-
|
202
|
+
searchParams = new URLSearchParams({
|
203
|
+
departureStopId: departureStopId.toString(),
|
204
|
+
destinationStopId: destinationStopId.toString()
|
205
|
+
});
|
206
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/trips/").concat(tripId, "/seats?").concat(searchParams);
|
207
|
+
return [2 /*return*/, this.callGetApi(url)];
|
194
208
|
});
|
195
209
|
});
|
196
210
|
};
|
211
|
+
// TODO: Fix this
|
197
212
|
JourneyBooking.prototype.getSeatsStatus = function (params) {
|
198
213
|
return __awaiter(this, void 0, void 0, function () {
|
199
|
-
var url;
|
214
|
+
var searchParams, url;
|
200
215
|
return __generator(this, function (_a) {
|
201
216
|
if (!this.cart) {
|
202
217
|
throw Error("Cart is not initialized yet");
|
203
218
|
}
|
204
|
-
|
205
|
-
|
219
|
+
searchParams = new URLSearchParams({ tripId: params.tripId.toString() });
|
220
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats?").concat(searchParams);
|
221
|
+
return [2 /*return*/, this.callGetApi(url)];
|
206
222
|
});
|
207
223
|
});
|
208
224
|
};
|
225
|
+
// TODO: Fix this
|
209
226
|
JourneyBooking.prototype.movePassengers = function (params) {
|
210
227
|
return __awaiter(this, void 0, void 0, function () {
|
211
228
|
var url;
|
@@ -214,7 +231,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
214
231
|
throw Error("Cart is not initialized yet");
|
215
232
|
}
|
216
233
|
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats");
|
217
|
-
return [2 /*return*/,
|
234
|
+
return [2 /*return*/, this.callGetApi(url)];
|
218
235
|
});
|
219
236
|
});
|
220
237
|
};
|
@@ -225,8 +242,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
225
242
|
if (!this.cart) {
|
226
243
|
throw Error("Cart is not initialized yet");
|
227
244
|
}
|
228
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?")
|
229
|
-
return [2 /*return*/,
|
245
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?");
|
246
|
+
return [2 /*return*/, this.callGetApi(url)];
|
230
247
|
});
|
231
248
|
});
|
232
249
|
};
|
@@ -238,7 +255,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
238
255
|
throw Error("Cart is not initialized yet");
|
239
256
|
}
|
240
257
|
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
|
241
|
-
return [2 /*return*/,
|
258
|
+
return [2 /*return*/, this.callPostApi(url, passengersDetails)];
|
242
259
|
});
|
243
260
|
});
|
244
261
|
};
|
@@ -4,7 +4,18 @@ import { CreateServiceCartRequest, ServiceCart } from "../types/services/Service
|
|
4
4
|
import { Booking } from "./booking";
|
5
5
|
export declare class ServiceBooking extends Booking {
|
6
6
|
private cart?;
|
7
|
-
|
7
|
+
/**
|
8
|
+
* This is the constructor of the ServiceBooking class.
|
9
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
10
|
+
* @param {string} sub_key The subscription key for using the APIs
|
11
|
+
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
12
|
+
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
13
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
14
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
15
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
16
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
17
|
+
*/
|
18
|
+
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, sellerId?: number, resellerId?: number);
|
8
19
|
getCart(): ServiceCart | undefined;
|
9
20
|
private fetchAndSetCart;
|
10
21
|
private createCartTimer;
|
@@ -63,15 +63,26 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
63
63
|
};
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
65
65
|
exports.ServiceBooking = void 0;
|
66
|
-
var apiCall_1 = require("../utils/apiCall");
|
67
66
|
var booking_1 = require("./booking");
|
68
67
|
var ServiceBooking = /** @class */ (function (_super) {
|
69
68
|
__extends(ServiceBooking, _super);
|
70
|
-
|
69
|
+
/**
|
70
|
+
* This is the constructor of the ServiceBooking class.
|
71
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
72
|
+
* @param {string} sub_key The subscription key for using the APIs
|
73
|
+
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
74
|
+
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
75
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
76
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
77
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
78
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
79
|
+
*/
|
80
|
+
function ServiceBooking(env, sub_key, onCartExpiration, debug, language, sellerId, resellerId) {
|
71
81
|
if (debug === void 0) { debug = false; }
|
82
|
+
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
72
83
|
var _this =
|
73
84
|
// Call Booking constructor
|
74
|
-
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug,
|
85
|
+
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, language, sellerId, resellerId) || this;
|
75
86
|
var cartId = localStorage.getItem("cartId");
|
76
87
|
if (cartId) {
|
77
88
|
_this.fetchAndSetCart(parseInt(cartId));
|
@@ -118,8 +129,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
118
129
|
return __awaiter(this, void 0, void 0, function () {
|
119
130
|
var url;
|
120
131
|
return __generator(this, function (_a) {
|
121
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart
|
122
|
-
return [2 /*return*/,
|
132
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
133
|
+
return [2 /*return*/, this.callGetApi(url)];
|
123
134
|
});
|
124
135
|
});
|
125
136
|
};
|
@@ -132,8 +143,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
132
143
|
return __awaiter(this, void 0, void 0, function () {
|
133
144
|
var url;
|
134
145
|
return __generator(this, function (_a) {
|
135
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/services/cities?")
|
136
|
-
return [2 /*return*/,
|
146
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/services/cities?");
|
147
|
+
return [2 /*return*/, this.callGetApi(url)];
|
137
148
|
});
|
138
149
|
});
|
139
150
|
};
|
@@ -146,10 +157,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
146
157
|
*/
|
147
158
|
ServiceBooking.prototype.getServices = function (currency, cityName) {
|
148
159
|
return __awaiter(this, void 0, void 0, function () {
|
149
|
-
var url;
|
160
|
+
var searchParams, url;
|
150
161
|
return __generator(this, function (_a) {
|
151
|
-
|
152
|
-
|
162
|
+
searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
|
163
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/services?").concat(searchParams);
|
164
|
+
return [2 /*return*/, this.callGetApi(url)];
|
153
165
|
});
|
154
166
|
});
|
155
167
|
};
|
@@ -163,10 +175,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
163
175
|
*/
|
164
176
|
ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
|
165
177
|
return __awaiter(this, void 0, void 0, function () {
|
166
|
-
var url;
|
178
|
+
var searchParams, url;
|
167
179
|
return __generator(this, function (_a) {
|
168
|
-
|
169
|
-
|
180
|
+
searchParams = new URLSearchParams({ date: date.toDateString() });
|
181
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/services/").concat(serviceId, "/trips?").concat(searchParams);
|
182
|
+
return [2 /*return*/, this.callGetApi(url)];
|
170
183
|
});
|
171
184
|
});
|
172
185
|
};
|
@@ -176,7 +189,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
176
189
|
var _this = this;
|
177
190
|
return __generator(this, function (_a) {
|
178
191
|
url = "".concat(this.config.API_ENDPOINT, "/booking/services/cart");
|
179
|
-
return [2 /*return*/,
|
192
|
+
return [2 /*return*/, this.callPostApi(url, serviceCart).then(function (cart) {
|
180
193
|
_this.cart = cart.cart;
|
181
194
|
_this.cartStatus = cart.cart.status;
|
182
195
|
_this.bookingDueDate = new Date(cart.cart.bookingDueDate);
|
@@ -6,7 +6,18 @@ import { Subscription } from "../types/subscriptions/Subscriptions";
|
|
6
6
|
import { Booking } from "./booking";
|
7
7
|
export declare class SubscriptionBooking extends Booking {
|
8
8
|
private cart?;
|
9
|
-
|
9
|
+
/**
|
10
|
+
* This is the constructor of the ServiceBooking class.
|
11
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
12
|
+
* @param {string} sub_key The subscription key for using the APIs
|
13
|
+
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
14
|
+
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
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 {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
18
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
19
|
+
*/
|
20
|
+
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, sellerId?: number, resellerId?: number);
|
10
21
|
getCart(): Cart | undefined;
|
11
22
|
private fetchAndSetCart;
|
12
23
|
private createCartTimer;
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
15
|
};
|
16
16
|
})();
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
18
|
-
__assign = Object.assign || function(t) {
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
20
|
-
s = arguments[i];
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
22
|
-
t[p] = s[p];
|
23
|
-
}
|
24
|
-
return t;
|
25
|
-
};
|
26
|
-
return __assign.apply(this, arguments);
|
27
|
-
};
|
28
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
29
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
30
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -63,15 +52,26 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
63
52
|
};
|
64
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
65
54
|
exports.SubscriptionBooking = void 0;
|
66
|
-
var apiCall_1 = require("../utils/apiCall");
|
67
55
|
var booking_1 = require("./booking");
|
68
56
|
var SubscriptionBooking = /** @class */ (function (_super) {
|
69
57
|
__extends(SubscriptionBooking, _super);
|
70
|
-
|
58
|
+
/**
|
59
|
+
* This is the constructor of the ServiceBooking class.
|
60
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
61
|
+
* @param {string} sub_key The subscription key for using the APIs
|
62
|
+
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
63
|
+
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
64
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
65
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
66
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
67
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
68
|
+
*/
|
69
|
+
function SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, sellerId, resellerId) {
|
71
70
|
if (debug === void 0) { debug = false; }
|
71
|
+
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
72
72
|
var _this =
|
73
73
|
// Call Booking constructor
|
74
|
-
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug,
|
74
|
+
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, sellerId, resellerId) || this;
|
75
75
|
var cartId = localStorage.getItem("cartId");
|
76
76
|
if (cartId) {
|
77
77
|
_this.fetchAndSetCart(parseInt(cartId));
|
@@ -118,8 +118,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
118
118
|
return __awaiter(this, void 0, void 0, function () {
|
119
119
|
var url;
|
120
120
|
return __generator(this, function (_a) {
|
121
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/
|
122
|
-
return [2 /*return*/,
|
121
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
122
|
+
return [2 /*return*/, this.callGetApi(url)];
|
123
123
|
});
|
124
124
|
});
|
125
125
|
};
|
@@ -131,8 +131,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
131
131
|
return __awaiter(this, void 0, void 0, function () {
|
132
132
|
var url;
|
133
133
|
return __generator(this, function (_a) {
|
134
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/departures?")
|
135
|
-
return [2 /*return*/,
|
134
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/departures?");
|
135
|
+
return [2 /*return*/, this.callGetApi(url)];
|
136
136
|
});
|
137
137
|
});
|
138
138
|
};
|
@@ -143,10 +143,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
143
143
|
*/
|
144
144
|
SubscriptionBooking.prototype.getSubscriptionsDestinations = function (departureStopName) {
|
145
145
|
return __awaiter(this, void 0, void 0, function () {
|
146
|
-
var url;
|
146
|
+
var searchParams, url;
|
147
147
|
return __generator(this, function (_a) {
|
148
|
-
|
149
|
-
|
148
|
+
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
149
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/destinations?").concat(searchParams);
|
150
|
+
return [2 /*return*/, this.callGetApi(url)];
|
150
151
|
});
|
151
152
|
});
|
152
153
|
};
|
@@ -159,10 +160,14 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
159
160
|
*/
|
160
161
|
SubscriptionBooking.prototype.getSubscriptionsValidityTypes = function (departureStopName, destinationStopName) {
|
161
162
|
return __awaiter(this, void 0, void 0, function () {
|
162
|
-
var url;
|
163
|
+
var searchParams, url;
|
163
164
|
return __generator(this, function (_a) {
|
164
|
-
|
165
|
-
|
165
|
+
searchParams = new URLSearchParams({
|
166
|
+
departureStopName: departureStopName,
|
167
|
+
destinationStopName: destinationStopName
|
168
|
+
});
|
169
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/validityTypes?").concat(searchParams);
|
170
|
+
return [2 /*return*/, this.callGetApi(url)];
|
166
171
|
});
|
167
172
|
});
|
168
173
|
};
|
@@ -177,10 +182,15 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
177
182
|
*/
|
178
183
|
SubscriptionBooking.prototype.getSubscriptions = function (departureStopName, destinationStopName, validityType) {
|
179
184
|
return __awaiter(this, void 0, void 0, function () {
|
180
|
-
var url;
|
185
|
+
var searchParams, url;
|
181
186
|
return __generator(this, function (_a) {
|
182
|
-
|
183
|
-
|
187
|
+
searchParams = new URLSearchParams({
|
188
|
+
departureStopName: departureStopName,
|
189
|
+
destinationStopName: destinationStopName,
|
190
|
+
validityType: validityType
|
191
|
+
});
|
192
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/search?").concat(searchParams);
|
193
|
+
return [2 /*return*/, this.callGetApi(url)];
|
184
194
|
});
|
185
195
|
});
|
186
196
|
};
|
@@ -192,10 +202,20 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
192
202
|
*/
|
193
203
|
SubscriptionBooking.prototype.getSubscriptionAvailabilities = function (request) {
|
194
204
|
return __awaiter(this, void 0, void 0, function () {
|
195
|
-
var url;
|
205
|
+
var searchParams, url;
|
196
206
|
return __generator(this, function (_a) {
|
197
|
-
|
198
|
-
|
207
|
+
searchParams = new URLSearchParams({
|
208
|
+
outboundRouteId: request.outboundRouteId.toString(),
|
209
|
+
returnRouteId: request.returnRouteId.toString(),
|
210
|
+
outboundDeparturePhysicalAgencyStopId: request.outboundDeparturePhysicalAgencyStopId.toString(),
|
211
|
+
outboundDestinationPhysicalAgencyStopId: request.outboundDestinationPhysicalAgencyStopId.toString(),
|
212
|
+
returnDeparturePhysicalAgencyStopId: request.returnDeparturePhysicalAgencyStopId.toString(),
|
213
|
+
returnDestinationPhysicalAgencyStopId: request.returnDestinationPhysicalAgencyStopId.toString(),
|
214
|
+
numberOfPassengers: request.numberOfPassengers.toString(),
|
215
|
+
validityType: request.validityType
|
216
|
+
});
|
217
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/availabilities?").concat(searchParams);
|
218
|
+
return [2 /*return*/, this.callGetApi(url)];
|
199
219
|
});
|
200
220
|
});
|
201
221
|
};
|
@@ -205,7 +225,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
205
225
|
var _this = this;
|
206
226
|
return __generator(this, function (_a) {
|
207
227
|
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions");
|
208
|
-
return [2 /*return*/,
|
228
|
+
return [2 /*return*/, this.callPostApi(url, request).then(function (cart) {
|
209
229
|
_this.cart = cart.cart;
|
210
230
|
_this.cartStatus = cart.cart.status;
|
211
231
|
_this.bookingDueDate = new Date(cart.cart.bookingDueDate);
|
package/lib/config.js
CHANGED
@@ -16,7 +16,7 @@ var config = {
|
|
16
16
|
};
|
17
17
|
var setConfig = function (env, sub_key, debug, access_token) {
|
18
18
|
// First, set the environment
|
19
|
-
config.ENV = env;
|
19
|
+
config.ENV = env.toUpperCase();
|
20
20
|
switch (config.ENV) {
|
21
21
|
case MTSEnvs.DEV:
|
22
22
|
config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/dev";
|
package/package.json
CHANGED
@@ -1,12 +0,0 @@
|
|
1
|
-
export type Subscription = {
|
2
|
-
departurePhysicalAgencyStopId: number;
|
3
|
-
departureStopName: string;
|
4
|
-
destinationPhysicalAgencyStopId: number;
|
5
|
-
destinationStopName: string;
|
6
|
-
departureTime: string;
|
7
|
-
destinationTime: string;
|
8
|
-
lineName: string;
|
9
|
-
routeId: number;
|
10
|
-
routeName: string;
|
11
|
-
sellerId: number;
|
12
|
-
};
|