mts-booking-library 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Introduction
2
+ TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
3
+
4
+ # Getting Started
5
+ TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
6
+ 1. Installation process
7
+ 2. Software dependencies
8
+ 3. Latest releases
9
+ 4. API references
10
+
11
+ # Build and Test
12
+ TODO: Describe and show how to build your code and run the tests.
13
+
14
+ # Contribute
15
+ TODO: Explain how other users and developers can contribute to make your code better.
16
+
17
+ If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
18
+ - [ASP.NET Core](https://github.com/aspnet/Home)
19
+ - [Visual Studio Code](https://github.com/Microsoft/vscode)
20
+ - [Chakra Core](https://github.com/Microsoft/ChakraCore)
@@ -0,0 +1,4 @@
1
+ export declare const getConfig: () => {
2
+ API_ENDPOINT: string;
3
+ OCP_SUBSCRIPTION_KEY: string;
4
+ };
package/lib/config.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfig = void 0;
4
+ var MODE = "test";
5
+ var config = {
6
+ prod: {
7
+ API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api/",
8
+ },
9
+ test: {
10
+ API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api/dev",
11
+ OCP_SUBSCRIPTION_KEY: "6bfc2f70b9d643a1892ffd930a32ae3b"
12
+ }
13
+ };
14
+ var getConfig = function () {
15
+ return config[MODE];
16
+ };
17
+ exports.getConfig = getConfig;
package/lib/index.d.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { Cart, TourCart, TripCart } from "./types/Cart";
2
+ import { Details } from "./types/Details";
3
+ import { Tour } from "./types/Tour";
4
+ import { Trip } from "./types/Trip";
5
+ import { TripSearch } from "./types/TripSearch";
6
+ type BookingParams = {
7
+ sellerId?: number;
8
+ onCartExpiration: () => void;
9
+ };
10
+ type StopNames = string[];
11
+ export declare class Booking {
12
+ readonly sellerId?: number | undefined;
13
+ private readonly config;
14
+ private cart?;
15
+ private cartStatus;
16
+ private onCartExpiration;
17
+ constructor(params: BookingParams);
18
+ getCartStatus(): Booking.CartStatus;
19
+ getCart(): Cart | undefined;
20
+ private fetchAndSetCart;
21
+ private createCartTimer;
22
+ getCartExpirationTimeInMs(): Promise<number>;
23
+ getTourCities(): Promise<StopNames>;
24
+ getTours(params: {
25
+ cityName?: string;
26
+ currency: Booking.Currencies;
27
+ }): Promise<Tour[]>;
28
+ getToursTrips(tourId: number, date: Date): Promise<any>;
29
+ createTourCart(tourCart: TourCart): Promise<Cart>;
30
+ fetchCart(cartId: number): Promise<Cart>;
31
+ getTripsDepartures(): Promise<StopNames>;
32
+ getTripsDestinations(departureStopName: string): Promise<StopNames>;
33
+ getTrips(params: TripSearch): Promise<Trip[]>;
34
+ createTripCart(tripCart: TripCart): Promise<Cart>;
35
+ getBusMatrix(params: {
36
+ tripId: number;
37
+ departureStopId: number;
38
+ destinationStopId: number;
39
+ }): Promise<any>;
40
+ getSeatsStatus(params: {
41
+ tripId: number;
42
+ departureStopId: number;
43
+ destinationStopId: number;
44
+ }): Promise<any>;
45
+ updateSeatsStatus(params: {
46
+ tripId: number;
47
+ seatsIds: number[];
48
+ }): Promise<any>;
49
+ getPassengersDetails(): Promise<any>;
50
+ updatePassengersDetails(passengersDetails: Details): Promise<any>;
51
+ }
52
+ export declare namespace Booking {
53
+ enum Currencies {
54
+ EUR = "EUR",
55
+ USD = "USD",
56
+ CHF = "CHF"
57
+ }
58
+ enum CartStatus {
59
+ EMPTY = "EMPTY",
60
+ CREATION = "CREATION",
61
+ SEAT = "SEATS",
62
+ EXTRAS = "EXTRAS",
63
+ PASSENGERS = "PASSENGERS",
64
+ PAYMENT = "PAYMENT"
65
+ }
66
+ }
67
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,290 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Booking = void 0;
51
+ var config_1 = require("./config");
52
+ var apiCall_1 = require("./utils/apiCall");
53
+ if (typeof localStorage === "undefined" || localStorage === null) {
54
+ var LocalStorage = require("node-localstorage").LocalStorage;
55
+ global.localStorage = new LocalStorage("./scratch");
56
+ }
57
+ var Booking = /** @class */ (function () {
58
+ function Booking(params) {
59
+ this.cartStatus = Booking.CartStatus.EMPTY;
60
+ this.sellerId = params.sellerId || undefined;
61
+ this.config = (0, config_1.getConfig)();
62
+ this.onCartExpiration = params.onCartExpiration;
63
+ var cartId = localStorage.getItem("cartId");
64
+ if (cartId) {
65
+ this.fetchAndSetCart(parseInt(cartId));
66
+ }
67
+ }
68
+ Booking.prototype.getCartStatus = function () {
69
+ return this.cartStatus;
70
+ };
71
+ Booking.prototype.getCart = function () {
72
+ return this.cart;
73
+ };
74
+ Booking.prototype.fetchAndSetCart = function (cartId) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var _this = this;
77
+ return __generator(this, function (_a) {
78
+ this.fetchCart(cartId).then(function (cart) {
79
+ var cartDate = new Date(cart.bookingDueDate);
80
+ if (cartDate > new Date()) {
81
+ _this.cart = cart;
82
+ _this.cartStatus = cart.status;
83
+ _this.createCartTimer(cartDate);
84
+ }
85
+ });
86
+ return [2 /*return*/];
87
+ });
88
+ });
89
+ };
90
+ Booking.prototype.createCartTimer = function (expiringDate) {
91
+ return __awaiter(this, void 0, void 0, function () {
92
+ var _this = this;
93
+ return __generator(this, function (_a) {
94
+ setTimeout(function () {
95
+ localStorage.removeItem("cartId");
96
+ // Put actions that have to be done when timer expires here
97
+ _this.cartStatus = Booking.CartStatus.EMPTY;
98
+ _this.cart = undefined;
99
+ _this.onCartExpiration();
100
+ }, expiringDate.valueOf() - new Date().valueOf());
101
+ return [2 /*return*/];
102
+ });
103
+ });
104
+ };
105
+ Booking.prototype.getCartExpirationTimeInMs = function () {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ return __generator(this, function (_a) {
108
+ if (this.cart) {
109
+ return [2 /*return*/, (new Date(this.cart.bookingDueDate).valueOf() - new Date().valueOf())];
110
+ }
111
+ else {
112
+ throw Error("Cart is not initialized yet");
113
+ }
114
+ return [2 /*return*/];
115
+ });
116
+ });
117
+ };
118
+ // Tours config
119
+ Booking.prototype.getTourCities = function () {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var url;
122
+ return __generator(this, function (_a) {
123
+ url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cities?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
124
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
125
+ });
126
+ });
127
+ };
128
+ Booking.prototype.getTours = function (params) {
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var url;
131
+ return __generator(this, function (_a) {
132
+ url = "".concat(this.config.API_ENDPOINT, "/booking/tours?").concat(new URLSearchParams(__assign(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), (params.cityName && { cityName: params.cityName })), { currency: params.currency })));
133
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
134
+ });
135
+ });
136
+ };
137
+ Booking.prototype.getToursTrips = function (tourId, date) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var url;
140
+ return __generator(this, function (_a) {
141
+ 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() })));
142
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
143
+ });
144
+ });
145
+ };
146
+ Booking.prototype.createTourCart = function (tourCart) {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var url;
149
+ var _this = this;
150
+ return __generator(this, function (_a) {
151
+ url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cart");
152
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, tourCart).then(function (cart) {
153
+ _this.cart = cart.cart;
154
+ _this.cartStatus = cart.cart.status;
155
+ _this.createCartTimer(new Date(cart.cart.bookingDueDate));
156
+ return cart.cart;
157
+ })];
158
+ });
159
+ });
160
+ };
161
+ Booking.prototype.fetchCart = function (cartId) {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var url;
164
+ return __generator(this, function (_a) {
165
+ url = "".concat(this.config.API_ENDPOINT, "/booking/tours/cart/").concat(cartId);
166
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
167
+ });
168
+ });
169
+ };
170
+ // Trips config
171
+ Booking.prototype.getTripsDepartures = function () {
172
+ return __awaiter(this, void 0, void 0, function () {
173
+ var url;
174
+ return __generator(this, function (_a) {
175
+ url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/departures?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
176
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
177
+ });
178
+ });
179
+ };
180
+ Booking.prototype.getTripsDestinations = function (departureStopName) {
181
+ return __awaiter(this, void 0, void 0, function () {
182
+ var url;
183
+ return __generator(this, function (_a) {
184
+ url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/destinations?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: departureStopName })));
185
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
186
+ });
187
+ });
188
+ };
189
+ Booking.prototype.getTrips = function (params) {
190
+ return __awaiter(this, void 0, void 0, function () {
191
+ var url;
192
+ return __generator(this, function (_a) {
193
+ 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(), currency: params.currency, isRoundtrip: params.isRoundtrip.toString() })));
194
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
195
+ });
196
+ });
197
+ };
198
+ Booking.prototype.createTripCart = function (tripCart) {
199
+ return __awaiter(this, void 0, void 0, function () {
200
+ var url;
201
+ var _this = this;
202
+ return __generator(this, function (_a) {
203
+ url = "".concat(this.config.API_ENDPOINT, "/booking/journeys/cart");
204
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, tripCart).then(function (cart) {
205
+ _this.cart = cart.cart;
206
+ _this.cartStatus = cart.cart.status;
207
+ _this.createCartTimer(new Date(cart.cart.bookingDueDate));
208
+ return cart.cart;
209
+ })];
210
+ });
211
+ });
212
+ };
213
+ Booking.prototype.getBusMatrix = function (params) {
214
+ return __awaiter(this, void 0, void 0, function () {
215
+ var url;
216
+ return __generator(this, function (_a) {
217
+ 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() })));
218
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
219
+ });
220
+ });
221
+ };
222
+ Booking.prototype.getSeatsStatus = function (params) {
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ var url;
225
+ return __generator(this, function (_a) {
226
+ if (!this.cart) {
227
+ throw Error("Cart is not initialized yet");
228
+ }
229
+ 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() })));
230
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
231
+ });
232
+ });
233
+ };
234
+ Booking.prototype.updateSeatsStatus = function (params) {
235
+ return __awaiter(this, void 0, void 0, function () {
236
+ var url;
237
+ return __generator(this, function (_a) {
238
+ if (!this.cart) {
239
+ throw Error("Cart is not initialized yet");
240
+ }
241
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats");
242
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, params)];
243
+ });
244
+ });
245
+ };
246
+ Booking.prototype.getPassengersDetails = function () {
247
+ return __awaiter(this, void 0, void 0, function () {
248
+ var url;
249
+ return __generator(this, function (_a) {
250
+ if (!this.cart) {
251
+ throw Error("Cart is not initialized yet");
252
+ }
253
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?").concat(new URLSearchParams(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() }))));
254
+ return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
255
+ });
256
+ });
257
+ };
258
+ Booking.prototype.updatePassengersDetails = function (passengersDetails) {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var url;
261
+ return __generator(this, function (_a) {
262
+ if (!this.cart) {
263
+ throw Error("Cart is not initialized yet");
264
+ }
265
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
266
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, passengersDetails)];
267
+ });
268
+ });
269
+ };
270
+ return Booking;
271
+ }());
272
+ exports.Booking = Booking;
273
+ (function (Booking) {
274
+ var Currencies;
275
+ (function (Currencies) {
276
+ Currencies["EUR"] = "EUR";
277
+ Currencies["USD"] = "USD";
278
+ Currencies["CHF"] = "CHF";
279
+ })(Currencies = Booking.Currencies || (Booking.Currencies = {}));
280
+ var CartStatus;
281
+ (function (CartStatus) {
282
+ CartStatus["EMPTY"] = "EMPTY";
283
+ CartStatus["CREATION"] = "CREATION";
284
+ CartStatus["SEAT"] = "SEATS";
285
+ CartStatus["EXTRAS"] = "EXTRAS";
286
+ CartStatus["PASSENGERS"] = "PASSENGERS";
287
+ CartStatus["PAYMENT"] = "PAYMENT";
288
+ })(CartStatus = Booking.CartStatus || (Booking.CartStatus = {}));
289
+ })(Booking = exports.Booking || (exports.Booking = {}));
290
+ exports.Booking = Booking;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,79 @@
1
+ import { Booking } from "..";
2
+ import { Person } from "./Person";
3
+ import { TariffMatrix } from "./TermsAndTariffs";
4
+ export type Cart = {
5
+ id: number;
6
+ cartCode: string;
7
+ status: Booking.CartStatus;
8
+ nextStatus: Booking.CartStatus;
9
+ currency: string;
10
+ bookingDueDate: string;
11
+ bookings: {
12
+ type: string;
13
+ summary: {
14
+ quantity: number;
15
+ label: string;
16
+ value: number;
17
+ }[];
18
+ }[];
19
+ info: {
20
+ stops: {
21
+ id: number;
22
+ departureTime: Date;
23
+ destinationTime: Date;
24
+ name: string;
25
+ address: string;
26
+ }[];
27
+ };
28
+ buyer: Person;
29
+ reductions: {
30
+ tripId: number;
31
+ tripName: string;
32
+ value: number;
33
+ isPercentage: boolean;
34
+ voucherCode?: string;
35
+ }[];
36
+ isSeatsSelectionAllowed: boolean;
37
+ sellingMethod: string;
38
+ totalValue: number;
39
+ totalResellerFee?: number;
40
+ totalCreditFromChange: number;
41
+ totalAmountToPay: number;
42
+ extas: {
43
+ id: number;
44
+ resourceId: number;
45
+ name: string;
46
+ description: string;
47
+ notes: string;
48
+ tariff: {
49
+ tariffId: number;
50
+ tariffName: string;
51
+ };
52
+ }[];
53
+ };
54
+ export type TourCart = {
55
+ cartId?: number;
56
+ currency: Booking.Currencies;
57
+ tour: {
58
+ tourId: number;
59
+ date?: Date;
60
+ tripId?: number;
61
+ tariffsMatrix: TariffMatrix;
62
+ };
63
+ };
64
+ export type TripCart = {
65
+ cartId?: number;
66
+ currency: Booking.Currencies;
67
+ outboundJourney: {
68
+ departureStopId: number;
69
+ destinationStopId: number;
70
+ tripId: number;
71
+ tariffsMatrix: TariffMatrix;
72
+ }[];
73
+ returnJourney: {
74
+ tripId: number;
75
+ departureStopId: number;
76
+ destinationStopId: number;
77
+ tariffsMatrix: TariffMatrix;
78
+ }[] | null;
79
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Person } from "./Person";
2
+ export type Details = {
3
+ passengers: Person[] & {
4
+ tripsToTariffs: {
5
+ [tripId: number]: number;
6
+ };
7
+ };
8
+ buyer: Person;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type ErrorResponse = {
2
+ statusCode: number;
3
+ message: string;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export type Info = {
2
+ sellerName: string;
3
+ minimumTotalPrice: string;
4
+ remainingSeats?: number;
5
+ bookingProcessMessage: string;
6
+ isBookable: boolean;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export type Line = {
2
+ id: number;
3
+ name: string;
4
+ linkavelDescription: string;
5
+ backofficeNotes: string;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export type Person = {
2
+ id: number;
3
+ name: string;
4
+ lastName: string;
5
+ email: string;
6
+ phoneNumber: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export type Stop = {
2
+ id: number;
3
+ departureTime: Date;
4
+ destinationTime: Date;
5
+ name: string;
6
+ address: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ export type TariffMatrix = {
2
+ tariffTypeId: number;
3
+ termsTypeId: number;
4
+ value: number;
5
+ quantity: number;
6
+ }[][];
7
+ export type TariffType = {
8
+ name: string;
9
+ description: string;
10
+ requiredPassengersName: boolean;
11
+ numberOfOccupiedSeats: number;
12
+ bookingProcessDescription: string;
13
+ };
14
+ export type TermsType = {
15
+ name: string;
16
+ description: string;
17
+ isRefundAllowed: boolean;
18
+ isChangeAllowed: boolean;
19
+ validationRulesString: string;
20
+ bookingProcessDescription: string;
21
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import { Info } from "./Info";
2
+ import { Line } from "./Line";
3
+ import { TariffMatrix, TariffType, TermsType } from "./TermsAndTariffs";
4
+ export type Tour = {
5
+ id: number;
6
+ line: Line;
7
+ info: Info;
8
+ tariffsMatrix: TariffMatrix;
9
+ tariffTypes: TariffType[];
10
+ termsTypes: TermsType[];
11
+ isDateOptional: boolean;
12
+ isDateRequired: boolean;
13
+ };
14
+ export type TourTrip = {
15
+ tripId: number;
16
+ hour: Date;
17
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,15 @@
1
+ import { Info } from "./Info";
2
+ import { Stop } from "./Stop";
3
+ import { TariffMatrix, TariffType, TermsType } from "./TermsAndTariffs";
4
+ export type Trip = {
5
+ stops: Stop[];
6
+ info: Info;
7
+ trips: {
8
+ id: number;
9
+ departureStopName: string;
10
+ destinationStopName: string;
11
+ tariffsMatrix: TariffMatrix;
12
+ tariffTypes: TariffType[];
13
+ termsTypes: TermsType[];
14
+ }[];
15
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Booking } from "..";
2
+ export type TripSearch = {
3
+ departureStopName: string;
4
+ destinationStopName: string;
5
+ passengersNumber: number;
6
+ date: Date;
7
+ currency: Booking.Currencies;
8
+ isRoundtrip: boolean;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { ErrorResponse } from "../types/ErrorResponse";
2
+ export declare const makeGet: (url: string) => Promise<ErrorResponse | any>;
3
+ export declare const makePost: (url: string, data: any) => Promise<ErrorResponse | any>;
@@ -0,0 +1,103 @@
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.makePost = exports.makeGet = void 0;
40
+ var axios_1 = require("axios");
41
+ var config_1 = require("../config");
42
+ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ console.log("GET ".concat(url));
45
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
46
+ var response, error_1, resError;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ _a.trys.push([0, 2, , 3]);
51
+ return [4 /*yield*/, axios_1.default.get(url, {
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY,
55
+ },
56
+ })];
57
+ case 1:
58
+ response = _a.sent();
59
+ resolve(response.data);
60
+ return [3 /*break*/, 3];
61
+ case 2:
62
+ error_1 = _a.sent();
63
+ resError = error_1.response.data;
64
+ reject(resError);
65
+ return [3 /*break*/, 3];
66
+ case 3: return [2 /*return*/];
67
+ }
68
+ });
69
+ }); })];
70
+ });
71
+ }); };
72
+ exports.makeGet = makeGet;
73
+ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
74
+ return __generator(this, function (_a) {
75
+ console.log("POST ".concat(url));
76
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
77
+ var response, error_2, resError;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ _a.trys.push([0, 2, , 3]);
82
+ return [4 /*yield*/, axios_1.default.post(url, data, {
83
+ headers: {
84
+ "Content-Type": "application/json",
85
+ "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY,
86
+ },
87
+ })];
88
+ case 1:
89
+ response = _a.sent();
90
+ resolve(response.data);
91
+ return [3 /*break*/, 3];
92
+ case 2:
93
+ error_2 = _a.sent();
94
+ resError = error_2.response.data;
95
+ reject(resError);
96
+ return [3 /*break*/, 3];
97
+ case 3: return [2 /*return*/];
98
+ }
99
+ });
100
+ }); })];
101
+ });
102
+ }); };
103
+ exports.makePost = makePost;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => boolean;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var _this = this;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = (function () {
5
+ try {
6
+ return _this === window;
7
+ }
8
+ catch (e) {
9
+ return false;
10
+ }
11
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "mts-booking-library",
3
+ "version": "1.0.0",
4
+ "description": "Library for use MyTicketSolution Booking API",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "jest --config jestconfig.json",
10
+ "prepare": "npm run build",
11
+ "prepublishOnly": "npm run test",
12
+ "version": "git add -A src",
13
+ "postversion": "git push && git push --tags"
14
+ },
15
+ "license": "ISC",
16
+ "devDependencies": {
17
+ "@types/jest": "^29.5.1",
18
+ "jest": "^29.5.0",
19
+ "ts-jest": "^29.1.0",
20
+ "typescript": "^5.0.4"
21
+ },
22
+ "files": [
23
+ "lib/**/*"
24
+ ],
25
+ "keywords": [
26
+ "myticketsolution",
27
+ "booking"
28
+ ],
29
+ "author": "M",
30
+ "dependencies": {
31
+ "axios": "^1.4.0",
32
+ "node-localstorage": "^2.2.1"
33
+ }
34
+ }