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
@@ -0,0 +1,44 @@
1
+ import { MTSConfig, MTSEnvs } from "../config";
2
+ export declare abstract class Booking {
3
+ readonly sellerId?: number | undefined;
4
+ readonly config: MTSConfig;
5
+ cartStatus: Booking.CartStatus;
6
+ bookingDueDate: Date | undefined;
7
+ onCartExpiration: () => void;
8
+ /**
9
+ * This is the constructor of the Booking class.
10
+ * @param {string} env The environment in which the app is running. Can be "dev", "stag" 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 {string} [access_token=undefined] The access token for calling MTS APIs
14
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
15
+ */
16
+ constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, access_token?: string, sellerId?: number);
17
+ /**
18
+ * This method allows to renew the access token for calling MTS APIs
19
+ * @param {string} access_token The new access token
20
+ */
21
+ renewAccessToken(access_token: string): void;
22
+ getCartStatus(): Booking.CartStatus;
23
+ getCartExpirationTimeInMs(): Promise<number>;
24
+ }
25
+ export declare namespace Booking {
26
+ enum Currencies {
27
+ EUR = "EUR",
28
+ USD = "USD",
29
+ CHF = "CHF"
30
+ }
31
+ enum CartStatus {
32
+ EMPTY = "EMPTY",
33
+ CREATION = "CREATION",
34
+ PASSENGERS = "PASSENGERS",
35
+ SEATS = "SEATS",
36
+ EXTRAS = "EXTRAS",
37
+ PAYMENT = "PAYMENT"
38
+ }
39
+ enum BookingTypes {
40
+ MLP = "MLP",
41
+ SERVICE = "SERVICE",
42
+ MLP_SUBSCRIPTIONS = "MLP_SUBSCRIPTIONS"
43
+ }
44
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Booking = void 0;
40
+ var config_1 = require("../config");
41
+ var Booking = /** @class */ (function () {
42
+ /**
43
+ * This is the constructor of the Booking class.
44
+ * @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
45
+ * @param {string} sub_key The subscription key for using the APIs
46
+ * @param {() => void} onCartExpiration A callback function that will be called when the cart expires
47
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
48
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
49
+ */
50
+ function Booking(env, sub_key, onCartExpiration, debug, access_token, sellerId) {
51
+ if (debug === void 0) { debug = false; }
52
+ this.cartStatus = Booking.CartStatus.EMPTY;
53
+ this.sellerId = sellerId || undefined;
54
+ this.config = (0, config_1.setConfig)(env, sub_key, debug, access_token);
55
+ this.onCartExpiration = onCartExpiration;
56
+ }
57
+ /**
58
+ * This method allows to renew the access token for calling MTS APIs
59
+ * @param {string} access_token The new access token
60
+ */
61
+ Booking.prototype.renewAccessToken = function (access_token) {
62
+ (0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, this.config.DEBUG, access_token);
63
+ };
64
+ Booking.prototype.getCartStatus = function () {
65
+ return this.cartStatus;
66
+ };
67
+ Booking.prototype.getCartExpirationTimeInMs = function () {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ return __generator(this, function (_a) {
70
+ // If cart is initialized, return the time in ms until the cart expires.
71
+ // Note that bookingDueDate is initialized only when the cart is created.
72
+ if (this.bookingDueDate) {
73
+ return [2 /*return*/, (new Date(this.bookingDueDate).valueOf() - new Date().valueOf())];
74
+ }
75
+ // Cart is not initialized
76
+ throw Error("Cart is not initialized yet");
77
+ });
78
+ });
79
+ };
80
+ return Booking;
81
+ }());
82
+ exports.Booking = Booking;
83
+ (function (Booking) {
84
+ var Currencies;
85
+ (function (Currencies) {
86
+ Currencies["EUR"] = "EUR";
87
+ Currencies["USD"] = "USD";
88
+ Currencies["CHF"] = "CHF";
89
+ })(Currencies = Booking.Currencies || (Booking.Currencies = {}));
90
+ var CartStatus;
91
+ (function (CartStatus) {
92
+ CartStatus["EMPTY"] = "EMPTY";
93
+ CartStatus["CREATION"] = "CREATION";
94
+ CartStatus["PASSENGERS"] = "PASSENGERS";
95
+ CartStatus["SEATS"] = "SEATS";
96
+ CartStatus["EXTRAS"] = "EXTRAS";
97
+ CartStatus["PAYMENT"] = "PAYMENT";
98
+ })(CartStatus = Booking.CartStatus || (Booking.CartStatus = {}));
99
+ var BookingTypes;
100
+ (function (BookingTypes) {
101
+ BookingTypes["MLP"] = "MLP";
102
+ BookingTypes["SERVICE"] = "SERVICE";
103
+ BookingTypes["MLP_SUBSCRIPTIONS"] = "MLP_SUBSCRIPTIONS";
104
+ })(BookingTypes = Booking.BookingTypes || (Booking.BookingTypes = {}));
105
+ })(Booking || (exports.Booking = Booking = {}));
@@ -0,0 +1,49 @@
1
+ import { MTSEnvs } from "../config";
2
+ import { PassengersDetails } from "../types/common/Person";
3
+ import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
4
+ import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
5
+ import { Booking } from "./booking";
6
+ export declare class JourneyBooking extends Booking {
7
+ private cart?;
8
+ constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, access_token?: string, sellerId?: number);
9
+ getCart(): JourneyCart | undefined;
10
+ private fetchAndSetCart;
11
+ private createCartTimer;
12
+ fetchCart(cartId: number): Promise<JourneyCart>;
13
+ /**
14
+ * This method returns the possible departures for all journeys (MLP) sold by this seller.
15
+ * @returns {string[]} The list of possible departures
16
+ */
17
+ getJourneysDepartures(): Promise<string[]>;
18
+ /**
19
+ * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
20
+ * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
21
+ * @returns {string[]} The list of possible destinations
22
+ */
23
+ getJourneysDestinations(departureStopName: string): Promise<string[]>;
24
+ /**
25
+ * This method returns the journeys that match the given parameters.
26
+ * Note that it will always return the journeys for the one-way trip.
27
+ * 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)
28
+ * @param {JourneySearch} params an object of type {@link JourneySearch} containing the parameters of the search
29
+ * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
30
+ */
31
+ getJourneys(params: JourneySearchRequest): Promise<JourneySearchResult[]>;
32
+ createJourneyCart(tripCart: CreateJourneyCartRequest): Promise<JourneyCart>;
33
+ getBusMatrix(params: {
34
+ tripId: number;
35
+ departureStopId: number;
36
+ destinationStopId: number;
37
+ }): Promise<any>;
38
+ getSeatsStatus(params: {
39
+ tripId: number;
40
+ departureStopId: number;
41
+ destinationStopId: number;
42
+ }): Promise<any>;
43
+ movePassengers(params: {
44
+ tripId: number;
45
+ seatsIds: number[];
46
+ }): Promise<any>;
47
+ getPassengersDetails(): Promise<any>;
48
+ updatePassengersDetails(passengersDetails: PassengersDetails): Promise<any>;
49
+ }
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ 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;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.JourneyBooking = void 0;
66
+ var apiCall_1 = require("../utils/apiCall");
67
+ var booking_1 = require("./booking");
68
+ var JourneyBooking = /** @class */ (function (_super) {
69
+ __extends(JourneyBooking, _super);
70
+ function JourneyBooking(env, sub_key, onCartExpiration, debug, access_token, sellerId) {
71
+ if (debug === void 0) { debug = false; }
72
+ var _this =
73
+ // Call Booking constructor
74
+ _super.call(this, env, sub_key, onCartExpiration, debug, access_token, sellerId) || this;
75
+ var cartId = localStorage.getItem("cartId");
76
+ if (cartId) {
77
+ _this.fetchAndSetCart(parseInt(cartId));
78
+ }
79
+ return _this;
80
+ }
81
+ JourneyBooking.prototype.getCart = function () {
82
+ return this.cart;
83
+ };
84
+ JourneyBooking.prototype.fetchAndSetCart = function (cartId) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var _this = this;
87
+ return __generator(this, function (_a) {
88
+ this.fetchCart(cartId).then(function (cart) {
89
+ var cartDate = new Date(cart.bookingDueDate);
90
+ if (cartDate > new Date()) {
91
+ _this.cart = cart;
92
+ _this.bookingDueDate = cartDate; // See Booking class
93
+ _this.cartStatus = cart.status;
94
+ _this.createCartTimer(cartDate);
95
+ }
96
+ });
97
+ return [2 /*return*/];
98
+ });
99
+ });
100
+ };
101
+ JourneyBooking.prototype.createCartTimer = function (expiringDate) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var _this = this;
104
+ return __generator(this, function (_a) {
105
+ setTimeout(function () {
106
+ localStorage.removeItem("cartId");
107
+ // Put actions that have to be done when timer expires here
108
+ _this.cartStatus = booking_1.Booking.CartStatus.EMPTY;
109
+ _this.cart = undefined;
110
+ _this.bookingDueDate = undefined; // See Booking class
111
+ _this.onCartExpiration();
112
+ }, expiringDate.valueOf() - new Date().valueOf());
113
+ return [2 /*return*/];
114
+ });
115
+ });
116
+ };
117
+ JourneyBooking.prototype.fetchCart = function (cartId) {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var url;
120
+ return __generator(this, function (_a) {
121
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/\n ").concat(new URLSearchParams({ cartId: cartId.toString() }));
122
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
123
+ });
124
+ });
125
+ };
126
+ /**
127
+ * This method returns the possible departures for all journeys (MLP) sold by this seller.
128
+ * @returns {string[]} The list of possible departures
129
+ */
130
+ JourneyBooking.prototype.getJourneysDepartures = function () {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var url;
133
+ return __generator(this, function (_a) {
134
+ url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/departures?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
135
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
136
+ });
137
+ });
138
+ };
139
+ /**
140
+ * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
141
+ * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
142
+ * @returns {string[]} The list of possible destinations
143
+ */
144
+ JourneyBooking.prototype.getJourneysDestinations = function (departureStopName) {
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var url;
147
+ return __generator(this, function (_a) {
148
+ url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/destinations?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName })));
149
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
150
+ });
151
+ });
152
+ };
153
+ /**
154
+ * This method returns the journeys that match the given parameters.
155
+ * Note that it will always return the journeys for the one-way trip.
156
+ * 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)
157
+ * @param {JourneySearch} params an object of type {@link JourneySearch} containing the parameters of the search
158
+ * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
159
+ */
160
+ JourneyBooking.prototype.getJourneys = function (params) {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ var url;
163
+ return __generator(this, function (_a) {
164
+ if (params.departureStopName === undefined || params.destinationStopName === undefined) {
165
+ throw Error("Fields departureStopName and destinationStopName are required");
166
+ }
167
+ 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, roundTripDate: params.roundTripDate ? params.roundTripDate : "null", currency: params.currency, isRoundtrip: params.isRoundtrip.toString() })));
168
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
169
+ });
170
+ });
171
+ };
172
+ JourneyBooking.prototype.createJourneyCart = function (tripCart) {
173
+ return __awaiter(this, void 0, void 0, function () {
174
+ var url;
175
+ var _this = this;
176
+ return __generator(this, function (_a) {
177
+ url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/cart");
178
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, tripCart).then(function (cart) {
179
+ _this.cart = cart.cart;
180
+ _this.cartStatus = cart.cart.status;
181
+ _this.createCartTimer(new Date(cart.cart.bookingDueDate));
182
+ return cart.cart;
183
+ })];
184
+ });
185
+ });
186
+ };
187
+ JourneyBooking.prototype.getBusMatrix = function (params) {
188
+ return __awaiter(this, void 0, void 0, function () {
189
+ var url;
190
+ return __generator(this, function (_a) {
191
+ 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() })));
192
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
193
+ });
194
+ });
195
+ };
196
+ JourneyBooking.prototype.getSeatsStatus = function (params) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var url;
199
+ return __generator(this, function (_a) {
200
+ if (!this.cart) {
201
+ throw Error("Cart is not initialized yet");
202
+ }
203
+ 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() })));
204
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
205
+ });
206
+ });
207
+ };
208
+ JourneyBooking.prototype.movePassengers = function (params) {
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ var url;
211
+ return __generator(this, function (_a) {
212
+ if (!this.cart) {
213
+ throw Error("Cart is not initialized yet");
214
+ }
215
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats");
216
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, params)];
217
+ });
218
+ });
219
+ };
220
+ JourneyBooking.prototype.getPassengersDetails = function () {
221
+ return __awaiter(this, void 0, void 0, function () {
222
+ var url;
223
+ return __generator(this, function (_a) {
224
+ if (!this.cart) {
225
+ throw Error("Cart is not initialized yet");
226
+ }
227
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
228
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
229
+ });
230
+ });
231
+ };
232
+ JourneyBooking.prototype.updatePassengersDetails = function (passengersDetails) {
233
+ return __awaiter(this, void 0, void 0, function () {
234
+ var url;
235
+ return __generator(this, function (_a) {
236
+ if (!this.cart) {
237
+ throw Error("Cart is not initialized yet");
238
+ }
239
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
240
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, passengersDetails)];
241
+ });
242
+ });
243
+ };
244
+ return JourneyBooking;
245
+ }(booking_1.Booking));
246
+ exports.JourneyBooking = JourneyBooking;
@@ -0,0 +1,36 @@
1
+ import { MTSEnvs } from "../config";
2
+ import { Service, ServiceTrip } from "../types/services/Service";
3
+ import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
4
+ import { Booking } from "./booking";
5
+ export declare class ServiceBooking extends Booking {
6
+ private cart?;
7
+ constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, access_token?: string, sellerId?: number);
8
+ getCart(): ServiceCart | undefined;
9
+ private fetchAndSetCart;
10
+ private createCartTimer;
11
+ fetchCart(cartId: number): Promise<ServiceCart>;
12
+ /**
13
+ * This method returns the list of cities in which the seller offers tours.
14
+ * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
15
+ * @returns {string[]} The list of possible cities
16
+ */
17
+ getServiceCities(): Promise<string[]>;
18
+ /**
19
+ * This method returns the tours sold by this seller in the given city.
20
+ * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
21
+ * @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
22
+ * @param {Booking.Currencies} currency The currency in which the prices should be returned
23
+ * @returns {Tour[]} The returned tours
24
+ */
25
+ getServices(currency: Booking.Currencies, cityName?: string): Promise<Service[]>;
26
+ /**
27
+ * 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
28
+ * and/or a specific hour for the tour.
29
+ * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
30
+ * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
31
+ * @param {Date} date The date on which to get the tours
32
+ * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
33
+ */
34
+ getServiceTrips(serviceId: number, date: Date): Promise<ServiceTrip[]>;
35
+ createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ServiceCart>;
36
+ }