mts-booking-library 1.0.5 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,190 @@
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.ServiceBooking = void 0;
66
+ var apiCall_1 = require("../utils/apiCall");
67
+ var booking_1 = require("./booking");
68
+ var ServiceBooking = /** @class */ (function (_super) {
69
+ __extends(ServiceBooking, _super);
70
+ function ServiceBooking(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
+ ServiceBooking.prototype.getCart = function () {
82
+ return this.cart;
83
+ };
84
+ ServiceBooking.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
+ ServiceBooking.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
+ ServiceBooking.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 list of cities in which the seller offers tours.
128
+ * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
129
+ * @returns {string[]} The list of possible cities
130
+ */
131
+ ServiceBooking.prototype.getServiceCities = function () {
132
+ return __awaiter(this, void 0, void 0, function () {
133
+ var url;
134
+ return __generator(this, function (_a) {
135
+ url = "".concat(this.config.API_ENDPOINT, "/booking/services/cities?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
136
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
137
+ });
138
+ });
139
+ };
140
+ /**
141
+ * This method returns the tours sold by this seller in the given city.
142
+ * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
143
+ * @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
144
+ * @param {Booking.Currencies} currency The currency in which the prices should be returned
145
+ * @returns {Tour[]} The returned tours
146
+ */
147
+ ServiceBooking.prototype.getServices = function (currency, cityName) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var url;
150
+ return __generator(this, function (_a) {
151
+ 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 })));
152
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
153
+ });
154
+ });
155
+ };
156
+ /**
157
+ * 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
158
+ * and/or a specific hour for the tour.
159
+ * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
160
+ * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
161
+ * @param {Date} date The date on which to get the tours
162
+ * @returns {ServiceTrip[]} The returned information about the tour (tripId and hour)
163
+ */
164
+ ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ var url;
167
+ return __generator(this, function (_a) {
168
+ url = "".concat(this.config.API_ENDPOINT, "/booking/services/").concat(serviceId, "/trips?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { date: date.toDateString() })));
169
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
170
+ });
171
+ });
172
+ };
173
+ ServiceBooking.prototype.createServiceCart = function (serviceCart) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var url;
176
+ var _this = this;
177
+ return __generator(this, function (_a) {
178
+ url = "".concat(this.config.API_ENDPOINT, "/booking/services/cart");
179
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, serviceCart).then(function (cart) {
180
+ _this.cart = cart.cart;
181
+ _this.cartStatus = cart.cart.status;
182
+ _this.createCartTimer(new Date(cart.cart.bookingDueDate));
183
+ return cart.cart;
184
+ })];
185
+ });
186
+ });
187
+ };
188
+ return ServiceBooking;
189
+ }(booking_1.Booking));
190
+ exports.ServiceBooking = ServiceBooking;
@@ -0,0 +1,50 @@
1
+ import { MTSEnvs } from "../config";
2
+ import { Cart } from "../types/common/Cart";
3
+ import { Subscription } from "../types/subscriptions/Subscrptions";
4
+ import { Booking } from "./booking";
5
+ export declare class SubscriptionBooking extends Booking {
6
+ private cart?;
7
+ constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, access_token?: string, sellerId?: number);
8
+ getCart(): Cart | undefined;
9
+ private fetchAndSetCart;
10
+ private createCartTimer;
11
+ fetchCart(cartId: number): Promise<Cart>;
12
+ /**
13
+ * This method returns the possible departures for all subscriptions sold by this seller.
14
+ * @returns {string[]} The list of possible departures
15
+ */
16
+ getSubscriptionsDepartures(): Promise<string[]>;
17
+ /**
18
+ * This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
19
+ * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
20
+ * @returns {string[]} The list of possible destinations
21
+ */
22
+ getSubscrptionsDestinations(departureStopName: string): Promise<string[]>;
23
+ /**
24
+ * This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
25
+ * The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
26
+ * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
27
+ * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
28
+ * @returns {ValidityTypes[]} The list of possible validity types
29
+ */
30
+ getSubscrptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<SubscriptionBooking.ValidityTypes[]>;
31
+ /**
32
+ * This method returns the subscriptions that match the given parameters.
33
+ * Note that it will always return the subscription for the one-way trip.
34
+ * 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)
35
+ * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
36
+ * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
37
+ * @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
38
+ * @returns {Array<Subscription>} The subscriptions that match the given parameters
39
+ */
40
+ getSubscrptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<Subscription[]>;
41
+ getSubscrptionAvailabilities(departureStopName: string, destinationStopName: string, validityType: string): Promise<Subscription[]>;
42
+ }
43
+ export declare namespace SubscriptionBooking {
44
+ enum ValidityTypes {
45
+ WORKING_WEEK = "WORKING_WEEK",
46
+ WEEKLY = "WEEKLY",
47
+ MONTHLY = "MONTHLY",
48
+ YEARLY = "YEARLY"
49
+ }
50
+ }
@@ -0,0 +1,201 @@
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.SubscriptionBooking = void 0;
66
+ var apiCall_1 = require("../utils/apiCall");
67
+ var booking_1 = require("./booking");
68
+ var SubscriptionBooking = /** @class */ (function (_super) {
69
+ __extends(SubscriptionBooking, _super);
70
+ function SubscriptionBooking(env, sub_key, onCartExpiration, debug, access_token, sellerId) {
71
+ if (debug === void 0) { debug = false; }
72
+ // Call Booking constructor
73
+ return _super.call(this, env, sub_key, onCartExpiration, debug, access_token, sellerId) || this;
74
+ }
75
+ SubscriptionBooking.prototype.getCart = function () {
76
+ return this.cart;
77
+ };
78
+ SubscriptionBooking.prototype.fetchAndSetCart = function (cartId) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ var _this = this;
81
+ return __generator(this, function (_a) {
82
+ this.fetchCart(cartId).then(function (cart) {
83
+ var cartDate = new Date(cart.bookingDueDate);
84
+ if (cartDate > new Date()) {
85
+ _this.cart = cart;
86
+ _this.bookingDueDate = cartDate; // See Booking class
87
+ _this.cartStatus = cart.status;
88
+ _this.createCartTimer(cartDate);
89
+ }
90
+ });
91
+ return [2 /*return*/];
92
+ });
93
+ });
94
+ };
95
+ SubscriptionBooking.prototype.createCartTimer = function (expiringDate) {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ var _this = this;
98
+ return __generator(this, function (_a) {
99
+ setTimeout(function () {
100
+ localStorage.removeItem("cartId");
101
+ // Put actions that have to be done when timer expires here
102
+ _this.cartStatus = booking_1.Booking.CartStatus.EMPTY;
103
+ _this.cart = undefined;
104
+ _this.bookingDueDate = undefined; // See Booking class
105
+ _this.onCartExpiration();
106
+ }, expiringDate.valueOf() - new Date().valueOf());
107
+ return [2 /*return*/];
108
+ });
109
+ });
110
+ };
111
+ SubscriptionBooking.prototype.fetchCart = function (cartId) {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var url;
114
+ return __generator(this, function (_a) {
115
+ url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cart/").concat(cartId);
116
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
117
+ });
118
+ });
119
+ };
120
+ /**
121
+ * This method returns the possible departures for all subscriptions sold by this seller.
122
+ * @returns {string[]} The list of possible departures
123
+ */
124
+ SubscriptionBooking.prototype.getSubscriptionsDepartures = function () {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var url;
127
+ return __generator(this, function (_a) {
128
+ url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/departures?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
129
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
130
+ });
131
+ });
132
+ };
133
+ /**
134
+ * This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
135
+ * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
136
+ * @returns {string[]} The list of possible destinations
137
+ */
138
+ SubscriptionBooking.prototype.getSubscrptionsDestinations = function (departureStopName) {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var url;
141
+ return __generator(this, function (_a) {
142
+ url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/destinations?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName })));
143
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
144
+ });
145
+ });
146
+ };
147
+ /**
148
+ * This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
149
+ * The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
150
+ * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
151
+ * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
152
+ * @returns {ValidityTypes[]} The list of possible validity types
153
+ */
154
+ SubscriptionBooking.prototype.getSubscrptionsValidityTypes = function (departureStopName, destinationStopName) {
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ var url;
157
+ return __generator(this, function (_a) {
158
+ url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/validityTypes?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName, destinationStopName: destinationStopName })));
159
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
160
+ });
161
+ });
162
+ };
163
+ /**
164
+ * This method returns the subscriptions that match the given parameters.
165
+ * Note that it will always return the subscription for the one-way trip.
166
+ * 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)
167
+ * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
168
+ * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
169
+ * @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
170
+ * @returns {Array<Subscription>} The subscriptions that match the given parameters
171
+ */
172
+ SubscriptionBooking.prototype.getSubscrptions = function (departureStopName, destinationStopName, validityType) {
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/subscriptions/search?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName, destinationStopName: destinationStopName, validityType: validityType })));
177
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
178
+ });
179
+ });
180
+ };
181
+ SubscriptionBooking.prototype.getSubscrptionAvailabilities = function (departureStopName, destinationStopName, validityType) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var url;
184
+ return __generator(this, function (_a) {
185
+ 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 })));
186
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
187
+ });
188
+ });
189
+ };
190
+ return SubscriptionBooking;
191
+ }(booking_1.Booking));
192
+ exports.SubscriptionBooking = SubscriptionBooking;
193
+ (function (SubscriptionBooking) {
194
+ var ValidityTypes;
195
+ (function (ValidityTypes) {
196
+ ValidityTypes["WORKING_WEEK"] = "WORKING_WEEK";
197
+ ValidityTypes["WEEKLY"] = "WEEKLY";
198
+ ValidityTypes["MONTHLY"] = "MONTHLY";
199
+ ValidityTypes["YEARLY"] = "YEARLY";
200
+ })(ValidityTypes = SubscriptionBooking.ValidityTypes || (SubscriptionBooking.ValidityTypes = {}));
201
+ })(SubscriptionBooking || (exports.SubscriptionBooking = SubscriptionBooking = {}));
package/lib/config.d.ts CHANGED
@@ -8,6 +8,7 @@ export type MTSConfig = {
8
8
  API_ENDPOINT: string;
9
9
  OCP_SUBSCRIPTION_KEY: string;
10
10
  ACCESS_TOKEN: string | undefined;
11
+ DEBUG: boolean;
11
12
  };
12
- export declare const setConfig: (env: MTSEnvs, sub_key: string, access_token?: string) => MTSConfig;
13
+ export declare const setConfig: (env: MTSEnvs, sub_key: string, debug: boolean, access_token?: string) => MTSConfig;
13
14
  export declare const getConfig: () => MTSConfig;
package/lib/config.js CHANGED
@@ -11,9 +11,10 @@ var config = {
11
11
  ENV: MTSEnvs.PROD,
12
12
  API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api",
13
13
  OCP_SUBSCRIPTION_KEY: "",
14
- ACCESS_TOKEN: undefined
14
+ ACCESS_TOKEN: undefined,
15
+ DEBUG: false
15
16
  };
16
- var setConfig = function (env, sub_key, access_token) {
17
+ var setConfig = function (env, sub_key, debug, access_token) {
17
18
  // First, set the environment
18
19
  config.ENV = env;
19
20
  switch (config.ENV) {
@@ -32,6 +33,8 @@ var setConfig = function (env, sub_key, access_token) {
32
33
  // Set OCT and access token
33
34
  config.OCP_SUBSCRIPTION_KEY = sub_key;
34
35
  config.ACCESS_TOKEN = access_token;
36
+ // Set debug
37
+ config.DEBUG = debug;
35
38
  return config;
36
39
  };
37
40
  exports.setConfig = setConfig;
package/lib/index.d.ts CHANGED
@@ -1,140 +1,15 @@
1
- import { MTSEnvs } from "./config";
2
- import { Cart, TourCart, JourneyCart } from "./types/Cart";
3
- import { Details } from "./types/Details";
4
- import { Tour, TourTrip } from "./types/Tours/Tour";
5
- import { JourneySearch } from "./types/Journeys/JourneySearch";
6
- import { Subscription } from "./types/Subscriptions/Subscrptions";
7
- import { ValidityTypes } from "./types/Subscriptions/ValidityTypes";
8
- import { Journey } from "./types/Journeys/Journey";
9
- export declare class Booking {
10
- readonly sellerId?: number | undefined;
11
- private readonly config;
12
- private cart?;
13
- private cartStatus;
14
- private onCartExpiration;
15
- /**
16
- * This is the constructor of the Booking class.
17
- * @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
18
- * @param {string} sub_key The subscription key for using the APIs
19
- * @param {() => void} onCartExpiration A callback function that will be called when the cart expires
20
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
21
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
22
- */
23
- constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, access_token?: string, sellerId?: number);
24
- /**
25
- * This method allows to renew the access token for calling MTS APIs
26
- * @param {string} access_token The new access token
27
- */
28
- renewAccessToken(access_token: string): void;
29
- getCartStatus(): Booking.CartStatus;
30
- getCart(): Cart | undefined;
31
- private fetchAndSetCart;
32
- private createCartTimer;
33
- getCartExpirationTimeInMs(): Promise<number>;
34
- /**
35
- * This method returns the list of cities in which the seller offers tours.
36
- * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
37
- * @returns {string[]} The list of possible cities
38
- */
39
- getTourCities(): Promise<string[]>;
40
- /**
41
- * This method returns the tours sold by this seller in the given city.
42
- * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
43
- * @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
44
- * @param {Booking.Currencies} currency The currency in which the prices should be returned
45
- * @returns {Tour[]} The returned tours
46
- */
47
- getTours(currency: Booking.Currencies, cityName?: string): Promise<Tour[]>;
48
- /**
49
- * 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
50
- * and/or a specific hour for the tour.
51
- * You should call this method only if {@link Tour.isDateOptional} or {@link Tour.isDateRequired} is true for the selected tour.
52
- * @param {number} tourId The id of the selected tour (can be retrieved in the object {@link Tour} returned by {@link getTours})
53
- * @param {Date} date The date on which to get the tours
54
- * @returns {TourTrip[]} The returned information about the tour (tripId and hour)
55
- */
56
- getToursTrips(tourId: number, date: Date): Promise<TourTrip[]>;
57
- createTourCart(tourCart: TourCart): Promise<Cart>;
58
- fetchCart(cartId: number): Promise<Cart>;
59
- /**
60
- * This method returns the possible departures for all journeys (MLP) sold by this seller.
61
- * @returns {string[]} The list of possible departures
62
- */
63
- getJourneysDepartures(): Promise<string[]>;
64
- /**
65
- * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
66
- * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
67
- * @returns {string[]} The list of possible destinations
68
- */
69
- getJourneysDestinations(departureStopName: string): Promise<string[]>;
70
- /**
71
- * This method returns the journeys that match the given parameters.
72
- * Note that it will always return the journeys for the one-way trip.
73
- * 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)
74
- * @param {JourneySearch} params an object of type {@link JourneySearch} containing the parameters of the search
75
- * @returns {Journey[]} The returned journeys that match the given parameters
76
- */
77
- getJourneys(params: JourneySearch): Promise<Journey[]>;
78
- createJourneyCart(tripCart: JourneyCart): Promise<Cart>;
79
- getBusMatrix(params: {
80
- tripId: number;
81
- departureStopId: number;
82
- destinationStopId: number;
83
- }): Promise<any>;
84
- getSeatsStatus(params: {
85
- tripId: number;
86
- departureStopId: number;
87
- destinationStopId: number;
88
- }): Promise<any>;
89
- movePassengers(params: {
90
- tripId: number;
91
- seatsIds: number[];
92
- }): Promise<any>;
93
- /**
94
- * This method returns the possible departures for all subscriptions sold by this seller.
95
- * @returns {string[]} The list of possible departures
96
- */
97
- getSubscriptionsDepartures(): Promise<string[]>;
98
- /**
99
- * This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
100
- * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
101
- * @returns {string[]} The list of possible destinations
102
- */
103
- getSubscrptionsDestinations(departureStopName: string): Promise<string[]>;
104
- /**
105
- * This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
106
- * The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
107
- * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
108
- * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
109
- * @returns {ValidityTypes[]} The list of possible validity types
110
- */
111
- getSubscrptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<ValidityTypes[]>;
112
- /**
113
- * This method returns the subscriptions that match the given parameters.
114
- * Note that it will always return the subscription for the one-way trip.
115
- * 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)
116
- * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
117
- * @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
118
- * @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
119
- * @returns {Array<Subscription>} The subscriptions that match the given parameters
120
- */
121
- getSubscrptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<Subscription[]>;
122
- getSubscrptionAvailabilities(departureStopName: string, destinationStopName: string, validityType: string): Promise<Subscription[]>;
123
- getPassengersDetails(): Promise<any>;
124
- updatePassengersDetails(passengersDetails: Details): Promise<any>;
125
- }
126
- export declare namespace Booking {
127
- enum Currencies {
128
- EUR = "EUR",
129
- USD = "USD",
130
- CHF = "CHF"
131
- }
132
- enum CartStatus {
133
- EMPTY = "EMPTY",
134
- CREATION = "CREATION",
135
- PASSENGERS = "PASSENGERS",
136
- SEATS = "SEATS",
137
- EXTRAS = "EXTRAS",
138
- PAYMENT = "PAYMENT"
139
- }
140
- }
1
+ export { JourneyBooking } from "./booking/journeyBooking";
2
+ export { ServiceBooking } from "./booking/serviceBooking";
3
+ export { SubscriptionBooking } from "./booking/subscriptionBooking";
4
+ export { Person, PassengersDetails, DEFAULT_PERSON } from "./types/common/Person";
5
+ export { TariffMatrix, TariffSummary, TariffType, TermsType } from "./types/common/Tariffs";
6
+ export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, JourneyBookingInfo } from "./types/journeys/JourneyCart";
7
+ export { JourneyInfo } from "./types/journeys/JourneyInfo";
8
+ export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
9
+ export { Stop } from "./types/journeys/Stop";
10
+ export { Trip } from "./types/journeys/Trip";
11
+ export { Line } from "./types/services/Line";
12
+ export { Service, ServiceTrip } from "./types/services/Service";
13
+ export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
14
+ export { ServiceInfo } from "./types/services/ServiceInfo";
15
+ export { Subscription } from "./types/subscriptions/Subscrptions";