mts-booking-library 1.0.5 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/lib/booking/booking.d.ts +44 -0
  2. package/lib/booking/booking.js +105 -0
  3. package/lib/booking/journeyBooking.d.ts +49 -0
  4. package/lib/booking/journeyBooking.js +246 -0
  5. package/lib/booking/serviceBooking.d.ts +36 -0
  6. package/lib/booking/serviceBooking.js +190 -0
  7. package/lib/booking/subscriptionBooking.d.ts +50 -0
  8. package/lib/booking/subscriptionBooking.js +201 -0
  9. package/lib/config.d.ts +2 -1
  10. package/lib/config.js +5 -2
  11. package/lib/index.d.ts +15 -140
  12. package/lib/index.js +16 -415
  13. package/lib/types/common/Cart.d.ts +47 -0
  14. package/lib/types/common/Person.d.ts +31 -0
  15. package/lib/types/common/Person.js +11 -0
  16. package/lib/types/{TermsAndTariffs.d.ts → common/Tariffs.d.ts} +5 -0
  17. package/lib/types/journeys/JourneyCart.d.ts +55 -0
  18. package/lib/types/journeys/JourneyInfo.d.ts +18 -0
  19. package/lib/types/journeys/JourneySearch.d.ts +19 -0
  20. package/lib/types/{Journeys → journeys}/JourneySearch.js +7 -5
  21. package/lib/types/journeys/Stop.d.ts +16 -0
  22. package/lib/types/{Journeys → journeys}/Trip.d.ts +1 -1
  23. package/lib/types/services/Line.d.ts +14 -0
  24. package/lib/types/services/Service.d.ts +33 -0
  25. package/lib/types/services/ServiceCart.d.ts +46 -0
  26. package/lib/types/services/ServiceInfo.d.ts +14 -0
  27. package/lib/utils/apiCall.js +22 -2
  28. package/package.json +3 -3
  29. package/lib/types/Booking.d.ts +0 -0
  30. package/lib/types/Booking.js +0 -1
  31. package/lib/types/Cart.d.ts +0 -79
  32. package/lib/types/Details.d.ts +0 -9
  33. package/lib/types/Info.d.ts +0 -8
  34. package/lib/types/Journey.d.ts +0 -8
  35. package/lib/types/JourneySearch.d.ts +0 -9
  36. package/lib/types/Journeys/BusMatrix.d.ts +0 -0
  37. package/lib/types/Journeys/BusMatrix.js +0 -1
  38. package/lib/types/Journeys/Journey.d.ts +0 -8
  39. package/lib/types/Journeys/JourneySearch.d.ts +0 -11
  40. package/lib/types/Journeys/Stop.d.ts +0 -7
  41. package/lib/types/Line.d.ts +0 -6
  42. package/lib/types/Person.d.ts +0 -7
  43. package/lib/types/Stop.d.ts +0 -7
  44. package/lib/types/Stop.js +0 -2
  45. package/lib/types/Subscriptions/ValidityTypes.d.ts +0 -6
  46. package/lib/types/Subscriptions/ValidityTypes.js +0 -10
  47. package/lib/types/TermsAndTariffs.js +0 -2
  48. package/lib/types/Tour.d.ts +0 -18
  49. package/lib/types/Tour.js +0 -2
  50. package/lib/types/Tours/Tour.d.ts +0 -18
  51. package/lib/types/Tours/Tour.js +0 -2
  52. package/lib/types/Tours.d.ts +0 -0
  53. package/lib/types/Tours.js +0 -1
  54. package/lib/types/Trip.d.ts +0 -9
  55. package/lib/types/Trip.js +0 -2
  56. package/lib/types/TripSearch.d.ts +0 -9
  57. package/lib/types/TripSearch.js +0 -2
  58. /package/lib/types/{Cart.js → common/Cart.js} +0 -0
  59. /package/lib/types/{Details.js → common/Tariffs.js} +0 -0
  60. /package/lib/types/{BusMatrix.d.ts → journeys/BusMatrix.d.ts} +0 -0
  61. /package/lib/types/{BusMatrix.js → journeys/BusMatrix.js} +0 -0
  62. /package/lib/types/{Info.js → journeys/JourneyCart.js} +0 -0
  63. /package/lib/types/{Journey.js → journeys/JourneyInfo.js} +0 -0
  64. /package/lib/types/{Journeys → journeys}/Stop.js +0 -0
  65. /package/lib/types/{Journeys → journeys}/Trip.js +0 -0
  66. /package/lib/types/{Line.js → services/Line.js} +0 -0
  67. /package/lib/types/{JourneySearch.js → services/Service.js} +0 -0
  68. /package/lib/types/{Journeys/Journey.js → services/ServiceCart.js} +0 -0
  69. /package/lib/types/{Person.js → services/ServiceInfo.js} +0 -0
  70. /package/lib/types/{Subscriptions → subscriptions}/Subscrptions.d.ts +0 -0
  71. /package/lib/types/{Subscriptions → subscriptions}/Subscrptions.js +0 -0
package/lib/index.js CHANGED
@@ -1,417 +1,18 @@
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
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
2
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Booking = void 0;
51
- var config_1 = require("./config");
52
- var apiCall_1 = require("./utils/apiCall");
53
- if (typeof localStorage === "undefined" || localStorage === null) {
54
- var LocalStorage = require("node-localstorage").LocalStorage;
55
- global.localStorage = new LocalStorage("./scratch");
56
- }
57
- var Booking = /** @class */ (function () {
58
- /**
59
- * This is the constructor of the Booking class.
60
- * @param {string} env The environment in which the app is running. Can be "dev", "stag" 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 {string} [access_token=undefined] The access token for calling MTS APIs
64
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
65
- */
66
- function Booking(env, sub_key, onCartExpiration, access_token, sellerId) {
67
- this.cartStatus = Booking.CartStatus.EMPTY;
68
- this.sellerId = sellerId || undefined;
69
- this.config = (0, config_1.setConfig)(env, sub_key, access_token);
70
- this.onCartExpiration = onCartExpiration;
71
- var cartId = localStorage.getItem("cartId");
72
- if (cartId) {
73
- this.fetchAndSetCart(parseInt(cartId));
74
- }
75
- }
76
- /**
77
- * This method allows to renew the access token for calling MTS APIs
78
- * @param {string} access_token The new access token
79
- */
80
- Booking.prototype.renewAccessToken = function (access_token) {
81
- (0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, access_token);
82
- };
83
- Booking.prototype.getCartStatus = function () {
84
- return this.cartStatus;
85
- };
86
- Booking.prototype.getCart = function () {
87
- return this.cart;
88
- };
89
- Booking.prototype.fetchAndSetCart = function (cartId) {
90
- return __awaiter(this, void 0, void 0, function () {
91
- var _this = this;
92
- return __generator(this, function (_a) {
93
- this.fetchCart(cartId).then(function (cart) {
94
- var cartDate = new Date(cart.bookingDueDate);
95
- if (cartDate > new Date()) {
96
- _this.cart = cart;
97
- _this.cartStatus = cart.status;
98
- _this.createCartTimer(cartDate);
99
- }
100
- });
101
- return [2 /*return*/];
102
- });
103
- });
104
- };
105
- Booking.prototype.createCartTimer = function (expiringDate) {
106
- return __awaiter(this, void 0, void 0, function () {
107
- var _this = this;
108
- return __generator(this, function (_a) {
109
- setTimeout(function () {
110
- localStorage.removeItem("cartId");
111
- // Put actions that have to be done when timer expires here
112
- _this.cartStatus = Booking.CartStatus.EMPTY;
113
- _this.cart = undefined;
114
- _this.onCartExpiration();
115
- }, expiringDate.valueOf() - new Date().valueOf());
116
- return [2 /*return*/];
117
- });
118
- });
119
- };
120
- Booking.prototype.getCartExpirationTimeInMs = function () {
121
- return __awaiter(this, void 0, void 0, function () {
122
- return __generator(this, function (_a) {
123
- if (this.cart) {
124
- return [2 /*return*/, (new Date(this.cart.bookingDueDate).valueOf() - new Date().valueOf())];
125
- }
126
- else {
127
- throw Error("Cart is not initialized yet");
128
- }
129
- return [2 /*return*/];
130
- });
131
- });
132
- };
133
- // #region Tours config
134
- /**
135
- * This method returns the list of cities in which the seller offers tours.
136
- * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
137
- * @returns {string[]} The list of possible cities
138
- */
139
- Booking.prototype.getTourCities = function () {
140
- return __awaiter(this, void 0, void 0, function () {
141
- var url;
142
- return __generator(this, function (_a) {
143
- url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cities?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
144
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
145
- });
146
- });
147
- };
148
- /**
149
- * This method returns the tours sold by this seller in the given city.
150
- * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
151
- * @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
152
- * @param {Booking.Currencies} currency The currency in which the prices should be returned
153
- * @returns {Tour[]} The returned tours
154
- */
155
- Booking.prototype.getTours = function (currency, cityName) {
156
- return __awaiter(this, void 0, void 0, function () {
157
- var url;
158
- return __generator(this, function (_a) {
159
- url = "".concat(this.config.API_ENDPOINT, "/booking/tours?").concat(new URLSearchParams(__assign(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), (cityName && { cityName: cityName })), { currency: currency })));
160
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
161
- });
162
- });
163
- };
164
- /**
165
- * This method returns the tours available for the given date. This method can be used if the seller wants the user to book a specific date
166
- * and/or a specific hour for the tour.
167
- * You should call this method only if {@link Tour.isDateOptional} or {@link Tour.isDateRequired} is true for the selected tour.
168
- * @param {number} tourId The id of the selected tour (can be retrieved in the object {@link Tour} returned by {@link getTours})
169
- * @param {Date} date The date on which to get the tours
170
- * @returns {TourTrip[]} The returned information about the tour (tripId and hour)
171
- */
172
- Booking.prototype.getToursTrips = function (tourId, date) {
173
- return __awaiter(this, void 0, void 0, function () {
174
- var url;
175
- return __generator(this, function (_a) {
176
- url = "".concat(this.config.API_ENDPOINT, "/booking/tours/").concat(tourId, "/trips?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { date: date.toDateString() })));
177
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
178
- });
179
- });
180
- };
181
- Booking.prototype.createTourCart = function (tourCart) {
182
- return __awaiter(this, void 0, void 0, function () {
183
- var url;
184
- var _this = this;
185
- return __generator(this, function (_a) {
186
- url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cart");
187
- return [2 /*return*/, (0, apiCall_1.makePost)(url, tourCart).then(function (cart) {
188
- _this.cart = cart.cart;
189
- _this.cartStatus = cart.cart.status;
190
- _this.createCartTimer(new Date(cart.cart.bookingDueDate));
191
- return cart.cart;
192
- })];
193
- });
194
- });
195
- };
196
- //#endregion
197
- Booking.prototype.fetchCart = function (cartId) {
198
- return __awaiter(this, void 0, void 0, function () {
199
- var url;
200
- return __generator(this, function (_a) {
201
- url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cart/").concat(cartId);
202
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
203
- });
204
- });
205
- };
206
- //#region Journeys config
207
- /**
208
- * This method returns the possible departures for all journeys (MLP) sold by this seller.
209
- * @returns {string[]} The list of possible departures
210
- */
211
- Booking.prototype.getJourneysDepartures = function () {
212
- return __awaiter(this, void 0, void 0, function () {
213
- var url;
214
- return __generator(this, function (_a) {
215
- url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/departures?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
216
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
217
- });
218
- });
219
- };
220
- /**
221
- * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
222
- * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
223
- * @returns {string[]} The list of possible destinations
224
- */
225
- Booking.prototype.getJourneysDestinations = function (departureStopName) {
226
- return __awaiter(this, void 0, void 0, function () {
227
- var url;
228
- return __generator(this, function (_a) {
229
- url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/destinations?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName })));
230
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
231
- });
232
- });
233
- };
234
- /**
235
- * This method returns the journeys that match the given parameters.
236
- * Note that it will always return the journeys for the one-way trip.
237
- * If you want to get the journeys for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
238
- * @param {JourneySearch} params an object of type {@link JourneySearch} containing the parameters of the search
239
- * @returns {Journey[]} The returned journeys that match the given parameters
240
- */
241
- Booking.prototype.getJourneys = function (params) {
242
- return __awaiter(this, void 0, void 0, function () {
243
- var url;
244
- return __generator(this, function (_a) {
245
- if (params.departureStopName === undefined || params.destinationStopName === undefined) {
246
- throw Error("Fields departureStopName and destinationStopName are required");
247
- }
248
- url = "".concat(this.config.API_ENDPOINT, "/booking/journeys?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: params.departureStopName, destinationStopName: params.destinationStopName, passengersNumber: params.passengersNumber.toString(), date: params.date.toDateString(), roundTripDate: params.roundTripDate ? params.roundTripDate.toDateString() : "null", currency: params.currency, isRoundtrip: params.isRoundtrip.toString() })));
249
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
250
- });
251
- });
252
- };
253
- Booking.prototype.createJourneyCart = function (tripCart) {
254
- return __awaiter(this, void 0, void 0, function () {
255
- var url;
256
- var _this = this;
257
- return __generator(this, function (_a) {
258
- url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/cart");
259
- return [2 /*return*/, (0, apiCall_1.makePost)(url, tripCart).then(function (cart) {
260
- _this.cart = cart.cart;
261
- _this.cartStatus = cart.cart.status;
262
- _this.createCartTimer(new Date(cart.cart.bookingDueDate));
263
- return cart.cart;
264
- })];
265
- });
266
- });
267
- };
268
- Booking.prototype.getBusMatrix = function (params) {
269
- return __awaiter(this, void 0, void 0, function () {
270
- var url;
271
- return __generator(this, function (_a) {
272
- url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/trips/").concat(params.tripId, "/seats?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopId: params.departureStopId.toString(), destinationStopId: params.destinationStopId.toString() })));
273
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
274
- });
275
- });
276
- };
277
- Booking.prototype.getSeatsStatus = function (params) {
278
- return __awaiter(this, void 0, void 0, function () {
279
- var url;
280
- return __generator(this, function (_a) {
281
- if (!this.cart) {
282
- throw Error("Cart is not initialized yet");
283
- }
284
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { tripId: params.tripId.toString() })));
285
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
286
- });
287
- });
288
- };
289
- Booking.prototype.movePassengers = function (params) {
290
- return __awaiter(this, void 0, void 0, function () {
291
- var url;
292
- return __generator(this, function (_a) {
293
- if (!this.cart) {
294
- throw Error("Cart is not initialized yet");
295
- }
296
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats");
297
- return [2 /*return*/, (0, apiCall_1.makePost)(url, params)];
298
- });
299
- });
300
- };
301
- //#endregion
302
- //#region Subscriptions config
303
- /**
304
- * This method returns the possible departures for all subscriptions sold by this seller.
305
- * @returns {string[]} The list of possible departures
306
- */
307
- Booking.prototype.getSubscriptionsDepartures = function () {
308
- return __awaiter(this, void 0, void 0, function () {
309
- var url;
310
- return __generator(this, function (_a) {
311
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/departures?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
312
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
313
- });
314
- });
315
- };
316
- /**
317
- * This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
318
- * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
319
- * @returns {string[]} The list of possible destinations
320
- */
321
- Booking.prototype.getSubscrptionsDestinations = function (departureStopName) {
322
- return __awaiter(this, void 0, void 0, function () {
323
- var url;
324
- return __generator(this, function (_a) {
325
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/destinations?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName })));
326
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
327
- });
328
- });
329
- };
330
- /**
331
- * This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
332
- * The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
333
- * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
334
- * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
335
- * @returns {ValidityTypes[]} The list of possible validity types
336
- */
337
- Booking.prototype.getSubscrptionsValidityTypes = function (departureStopName, destinationStopName) {
338
- return __awaiter(this, void 0, void 0, function () {
339
- var url;
340
- return __generator(this, function (_a) {
341
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/validityTypes?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName, destinationStopName: destinationStopName })));
342
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
343
- });
344
- });
345
- };
346
- /**
347
- * This method returns the subscriptions that match the given parameters.
348
- * Note that it will always return the subscription for the one-way trip.
349
- * If you want to get the subscription for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
350
- * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
351
- * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
352
- * @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
353
- * @returns {Array<Subscription>} The subscriptions that match the given parameters
354
- */
355
- Booking.prototype.getSubscrptions = function (departureStopName, destinationStopName, validityType) {
356
- return __awaiter(this, void 0, void 0, function () {
357
- var url;
358
- return __generator(this, function (_a) {
359
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/search?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName, destinationStopName: destinationStopName, validityType: validityType })));
360
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
361
- });
362
- });
363
- };
364
- Booking.prototype.getSubscrptionAvailabilities = function (departureStopName, destinationStopName, validityType) {
365
- return __awaiter(this, void 0, void 0, function () {
366
- var url;
367
- return __generator(this, function (_a) {
368
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/search?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName, destinationStopName: destinationStopName, validityType: validityType })));
369
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
370
- });
371
- });
372
- };
373
- //#endregion
374
- Booking.prototype.getPassengersDetails = function () {
375
- return __awaiter(this, void 0, void 0, function () {
376
- var url;
377
- return __generator(this, function (_a) {
378
- if (!this.cart) {
379
- throw Error("Cart is not initialized yet");
380
- }
381
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
382
- return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
383
- });
384
- });
385
- };
386
- Booking.prototype.updatePassengersDetails = function (passengersDetails) {
387
- return __awaiter(this, void 0, void 0, function () {
388
- var url;
389
- return __generator(this, function (_a) {
390
- if (!this.cart) {
391
- throw Error("Cart is not initialized yet");
392
- }
393
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
394
- return [2 /*return*/, (0, apiCall_1.makePost)(url, passengersDetails)];
395
- });
396
- });
397
- };
398
- return Booking;
399
- }());
400
- exports.Booking = Booking;
401
- (function (Booking) {
402
- var Currencies;
403
- (function (Currencies) {
404
- Currencies["EUR"] = "EUR";
405
- Currencies["USD"] = "USD";
406
- Currencies["CHF"] = "CHF";
407
- })(Currencies = Booking.Currencies || (Booking.Currencies = {}));
408
- var CartStatus;
409
- (function (CartStatus) {
410
- CartStatus["EMPTY"] = "EMPTY";
411
- CartStatus["CREATION"] = "CREATION";
412
- CartStatus["PASSENGERS"] = "PASSENGERS";
413
- CartStatus["SEATS"] = "SEATS";
414
- CartStatus["EXTRAS"] = "EXTRAS";
415
- CartStatus["PAYMENT"] = "PAYMENT";
416
- })(CartStatus = Booking.CartStatus || (Booking.CartStatus = {}));
417
- })(Booking || (exports.Booking = Booking = {}));
3
+ exports.DEFAULT_JOURNEY_SEARCH = exports.DEFAULT_PERSON = exports.SubscriptionBooking = exports.ServiceBooking = exports.JourneyBooking = void 0;
4
+ //#region Export Booking classes
5
+ var journeyBooking_1 = require("./booking/journeyBooking");
6
+ Object.defineProperty(exports, "JourneyBooking", { enumerable: true, get: function () { return journeyBooking_1.JourneyBooking; } });
7
+ var serviceBooking_1 = require("./booking/serviceBooking");
8
+ Object.defineProperty(exports, "ServiceBooking", { enumerable: true, get: function () { return serviceBooking_1.ServiceBooking; } });
9
+ var subscriptionBooking_1 = require("./booking/subscriptionBooking");
10
+ Object.defineProperty(exports, "SubscriptionBooking", { enumerable: true, get: function () { return subscriptionBooking_1.SubscriptionBooking; } });
11
+ //#endregion
12
+ //#region Export common types
13
+ // @note: Cart is not exported because it is extended by other types
14
+ var Person_1 = require("./types/common/Person");
15
+ Object.defineProperty(exports, "DEFAULT_PERSON", { enumerable: true, get: function () { return Person_1.DEFAULT_PERSON; } });
16
+ var JourneySearch_1 = require("./types/journeys/JourneySearch");
17
+ Object.defineProperty(exports, "DEFAULT_JOURNEY_SEARCH", { enumerable: true, get: function () { return JourneySearch_1.DEFAULT_JOURNEY_SEARCH; } });
18
+ //#endregion
@@ -0,0 +1,47 @@
1
+ import { Booking } from "../../booking/booking";
2
+ import { Person } from "./Person";
3
+ /**
4
+ * @description Cart is the object returned by the API when a cart is created.
5
+ * Note that depending on the type of booking, this type will be extended with different fields:
6
+ * - TourCart: {@link TourCart.ts}
7
+ * - JourneyCart: {@link JourneyCart.ts}
8
+ * - SubscriptionCart: {@link SubscriptionCart.ts}
9
+ * @property {number} id The id of the cart
10
+ * @property {string} cartCode The code of the cart
11
+ * @property {Booking.CartStatus} status The status of the cart. See {@link Booking.CartStatus}
12
+ * @property {Booking.CartStatus} nextStatus The next status of the cart. See {@link Booking.CartStatus}
13
+ * @property {Booking.Currencies} currency The currency of the cart. See {@link Booking.Currencies}
14
+ */
15
+ export type Cart = {
16
+ id: number;
17
+ cartCode: string;
18
+ status: Booking.CartStatus;
19
+ nextStatus: Booking.CartStatus;
20
+ currency: Booking.Currencies;
21
+ bookingDueDate: string;
22
+ buyer: Person;
23
+ reductions: {
24
+ tripId: number;
25
+ tripName: string;
26
+ value: number;
27
+ isPercentage: boolean;
28
+ voucherCode?: string;
29
+ }[];
30
+ isSeatsSelectionAllowed: boolean;
31
+ sellingMethod: string;
32
+ totalValue: number;
33
+ totalResellerFee?: number;
34
+ totalCreditFromChange: number;
35
+ totalAmountToPay: number;
36
+ extas: {
37
+ id: number;
38
+ resourceId: number;
39
+ name: string;
40
+ description: string;
41
+ notes: string;
42
+ tariff: {
43
+ tariffId: number;
44
+ tariffName: string;
45
+ };
46
+ }[];
47
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @description Represents a person, that can be a passenger or the buyer.
3
+ *
4
+ * @property {number} id - The unique identifier for the person.
5
+ * @property {string} name - The name of the person.
6
+ * @property {string} lastName - The last name of the person.
7
+ * @property {string} email - The email of the person.
8
+ * @property {string} phoneNumber - The phone number of the person.
9
+ */
10
+ export type Person = {
11
+ id: number;
12
+ name: string;
13
+ lastName: string;
14
+ email: string;
15
+ phoneNumber: string;
16
+ };
17
+ export declare const DEFAULT_PERSON: Person;
18
+ /**
19
+ * @description Represents the passengers details.
20
+ *
21
+ * @property {Person[]} passengers - An array of {@link Person} extended by the map `tripsToTariffs` objects representing the passengers.
22
+ * @property {Person} buyer - The {@link Person} object representing the buyer.
23
+ */
24
+ export type PassengersDetails = {
25
+ passengers: Person[] & {
26
+ tripsToTariffs: {
27
+ [tripId: number]: number;
28
+ };
29
+ };
30
+ buyer: Person;
31
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // This module contains the types to manage the passengers information
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DEFAULT_PERSON = void 0;
5
+ exports.DEFAULT_PERSON = {
6
+ id: 0,
7
+ name: '',
8
+ lastName: '',
9
+ email: '',
10
+ phoneNumber: ''
11
+ };
@@ -19,3 +19,8 @@ export type TermsType = {
19
19
  validationRulesString: string;
20
20
  bookingProcessDescription: string;
21
21
  };
22
+ export type TariffSummary = {
23
+ quantity: number;
24
+ label: string;
25
+ value: number;
26
+ };
@@ -0,0 +1,55 @@
1
+ import { Booking } from "../../booking/booking";
2
+ import { Cart } from "../common/Cart";
3
+ import { TariffMatrix, TariffSummary } from "../common/Tariffs";
4
+ import { Stop } from "./Stop";
5
+ /**
6
+ * @description Object containing information about the selected journey, to be used when booking the journey.
7
+ *
8
+ * @property {number} tripId - The unique identifier for the trip.
9
+ * @property {number} departureStopId - The unique identifier for the departure stop.
10
+ * @property {number} destinationStopId - The unique identifier for the destination stop.
11
+ * @property {TariffMatrix} tariffsMatrix - The tariff matrix for pricing the outbound journey.
12
+ */
13
+ export type JourneyBookingInfo = {
14
+ tripId: number;
15
+ departureStopId: number;
16
+ destinationStopId: number;
17
+ tariffsMatrix: TariffMatrix;
18
+ };
19
+ /**
20
+ * @description This is the object to be passed to `JourneyBooking.createJourneyCart`, containing information about the selected service.
21
+ *
22
+ * @property {number|undefined} [cartId=0] - The unique identifier for the cart (optional).
23
+ * @property {Booking.Currencies} currency - The currency in which the journey is priced.
24
+ * @property {JourneyBookingInfo[]} outboundJourney - Information about outbound journeys.
25
+ * @property {JourneyBookingInfo[]|null} returnJourney - Information about return journeys (optional, can be null).
26
+ */
27
+ export type CreateJourneyCartRequest = {
28
+ cartId?: number;
29
+ currency: Booking.Currencies;
30
+ outboundJourney: JourneyBookingInfo[];
31
+ returnJourney: JourneyBookingInfo[] | null;
32
+ };
33
+ /**
34
+ * @description Represents a `JourneyCart`, which extends the {@link Cart} type by including additional
35
+ * information about the bookings
36
+ *
37
+ * @property {JourneyBookingType[]} bookings - An array of {@link JourneyBookingType} objects representing the bookings associated
38
+ * with this journey cart.
39
+ */
40
+ export type JourneyCart = Cart & {
41
+ bookings: JourneyBookingType[];
42
+ };
43
+ /**
44
+ * @description Represents a `JourneyBooking`, which contains information about a journey booking.
45
+ *
46
+ * @property {Booking.BookingTypes} type - The type of booking.
47
+ * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
48
+ * associated with this journey booking.
49
+ * @property {Stop[]} info - An array of {@link Stop} objects representing the stops associated with this journey booking.
50
+ */
51
+ export type JourneyBookingType = {
52
+ type: Booking.BookingTypes;
53
+ summary: TariffSummary[];
54
+ info: Stop[];
55
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description Represents information about a journey.
3
+ *
4
+ * @property {string} sellerName - The name of the seller offering the journey.
5
+ * @property {string} minimumTotalPrice - The minimum total price for booking the journey, meaning the price if all passenger choose the cheapest tariff.
6
+ * @property {number} remainingSeats - The number of remaining seats for the journey.
7
+ * @property {number} totalNumberOfSeats - The total number of seats for the journey (including booked seats).
8
+ * @property {string} bookingProcessMessage - Optional message to be displayed to the user when booking this journey.
9
+ * @property {boolean} isBookable - Indicates whether the journey is bookable (true) or not (false).
10
+ */
11
+ export type JourneyInfo = {
12
+ sellerName: string;
13
+ minimumTotalPrice: string;
14
+ remainingSeats: number;
15
+ totalNumberOfSeats: number;
16
+ bookingProcessMessage: string;
17
+ isBookable: boolean;
18
+ };
@@ -0,0 +1,19 @@
1
+ import { Booking } from "../../booking/booking";
2
+ import { JourneyInfo } from "./JourneyInfo";
3
+ import { Stop } from "./Stop";
4
+ import { Trip } from "./Trip";
5
+ export type JourneySearchRequest = {
6
+ departureStopName: string | undefined;
7
+ destinationStopName: string | undefined;
8
+ passengersNumber: number;
9
+ date: string;
10
+ roundTripDate: string | null;
11
+ currency: Booking.Currencies;
12
+ isRoundtrip: boolean;
13
+ };
14
+ export declare const DEFAULT_JOURNEY_SEARCH: JourneySearchRequest;
15
+ export type JourneySearchResult = {
16
+ stops: Stop[];
17
+ info: JourneyInfo;
18
+ trips: Trip[];
19
+ };
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultJourneySearch = void 0;
4
- var __1 = require("../..");
5
- exports.DefaultJourneySearch = {
3
+ exports.DEFAULT_JOURNEY_SEARCH = void 0;
4
+ var booking_1 = require("../../booking/booking");
5
+ exports.DEFAULT_JOURNEY_SEARCH = {
6
6
  departureStopName: "",
7
7
  destinationStopName: "",
8
8
  passengersNumber: 1,
9
- date: new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 1)),
9
+ date: new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 1))
10
+ .toISOString()
11
+ .slice(0, -1),
10
12
  roundTripDate: null,
11
- currency: __1.Booking.Currencies.EUR,
13
+ currency: booking_1.Booking.Currencies.EUR,
12
14
  isRoundtrip: false,
13
15
  };