mts-booking-library 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.js +105 -0
- package/lib/booking/journeyBooking.js +246 -0
- package/lib/booking/serviceBooking.js +190 -0
- package/lib/booking/subscriptionBooking.js +201 -0
- package/lib/config.js +5 -2
- package/lib/index.js +16 -415
- package/lib/types/Journeys/JourneyCart.js +2 -0
- package/lib/types/Journeys/JourneyInfo.js +2 -0
- package/lib/types/Journeys/JourneySearch.js +7 -5
- package/lib/types/Journeys/Trip.d.ts +1 -0
- package/lib/types/common/Cart.js +2 -0
- package/lib/types/common/Person.js +11 -0
- package/lib/types/common/Tariffs.js +2 -0
- package/lib/types/services/Line.js +2 -0
- package/lib/types/services/Service.js +2 -0
- package/lib/types/services/ServiceCart.js +2 -0
- package/lib/types/services/ServiceInfo.js +2 -0
- package/lib/utils/apiCall.js +22 -2
- package/package.json +3 -3
@@ -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.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.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.
|
51
|
-
|
52
|
-
var
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|