mts-booking-library 1.0.0 → 1.0.2

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.
package/lib/config.d.ts CHANGED
@@ -1,4 +1,13 @@
1
- export declare const getConfig: () => {
1
+ export declare enum MTSEnvs {
2
+ DEV = "DEV",
3
+ STAGING = "STAGING",
4
+ PROD = "PROD"
5
+ }
6
+ export type MTSConfig = {
7
+ ENV: MTSEnvs;
2
8
  API_ENDPOINT: string;
3
9
  OCP_SUBSCRIPTION_KEY: string;
10
+ ACCESS_TOKEN: string | undefined;
4
11
  };
12
+ export declare const setConfig: (env: MTSEnvs, sub_key: string, access_token?: string) => MTSConfig;
13
+ export declare const getConfig: () => MTSConfig;
package/lib/config.js CHANGED
@@ -1,17 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = void 0;
4
- var MODE = "test";
3
+ exports.getConfig = exports.setConfig = exports.MTSEnvs = void 0;
4
+ var MTSEnvs;
5
+ (function (MTSEnvs) {
6
+ MTSEnvs["DEV"] = "DEV";
7
+ MTSEnvs["STAGING"] = "STAGING";
8
+ MTSEnvs["PROD"] = "PROD";
9
+ })(MTSEnvs || (exports.MTSEnvs = MTSEnvs = {}));
5
10
  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"
11
+ ENV: MTSEnvs.PROD,
12
+ API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api",
13
+ OCP_SUBSCRIPTION_KEY: "",
14
+ ACCESS_TOKEN: undefined
15
+ };
16
+ var setConfig = function (env, sub_key, access_token) {
17
+ // First, set the environment
18
+ config.ENV = env;
19
+ switch (config.ENV) {
20
+ case MTSEnvs.DEV:
21
+ config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/dev";
22
+ break;
23
+ case MTSEnvs.STAGING:
24
+ config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/stag";
25
+ break;
26
+ case MTSEnvs.PROD:
27
+ config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api";
28
+ break;
29
+ default:
30
+ throw new Error("Invalid environment");
12
31
  }
32
+ // Set OCT and access token
33
+ config.OCP_SUBSCRIPTION_KEY = sub_key;
34
+ config.ACCESS_TOKEN = access_token;
35
+ return config;
13
36
  };
37
+ exports.setConfig = setConfig;
14
38
  var getConfig = function () {
15
- return config[MODE];
39
+ return config;
16
40
  };
17
41
  exports.getConfig = getConfig;
package/lib/index.d.ts CHANGED
@@ -1,37 +1,81 @@
1
- import { Cart, TourCart, TripCart } from "./types/Cart";
1
+ import { MTSEnvs } from "./config";
2
+ import { Cart, TourCart, JourneyCart } from "./types/Cart";
2
3
  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[];
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";
11
9
  export declare class Booking {
12
10
  readonly sellerId?: number | undefined;
13
11
  private readonly config;
14
12
  private cart?;
15
13
  private cartStatus;
16
14
  private onCartExpiration;
17
- constructor(params: BookingParams);
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;
18
29
  getCartStatus(): Booking.CartStatus;
19
30
  getCart(): Cart | undefined;
20
31
  private fetchAndSetCart;
21
32
  private createCartTimer;
22
33
  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>;
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[]>;
29
57
  createTourCart(tourCart: TourCart): Promise<Cart>;
30
58
  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>;
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>;
35
79
  getBusMatrix(params: {
36
80
  tripId: number;
37
81
  departureStopId: number;
@@ -42,10 +86,40 @@ export declare class Booking {
42
86
  departureStopId: number;
43
87
  destinationStopId: number;
44
88
  }): Promise<any>;
45
- updateSeatsStatus(params: {
89
+ movePassengers(params: {
46
90
  tripId: number;
47
91
  seatsIds: number[];
48
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[]>;
49
123
  getPassengersDetails(): Promise<any>;
50
124
  updatePassengersDetails(passengersDetails: Details): Promise<any>;
51
125
  }
@@ -58,10 +132,9 @@ export declare namespace Booking {
58
132
  enum CartStatus {
59
133
  EMPTY = "EMPTY",
60
134
  CREATION = "CREATION",
61
- SEAT = "SEATS",
62
- EXTRAS = "EXTRAS",
63
135
  PASSENGERS = "PASSENGERS",
136
+ SEATS = "SEATS",
137
+ EXTRAS = "EXTRAS",
64
138
  PAYMENT = "PAYMENT"
65
139
  }
66
140
  }
67
- export {};
package/lib/index.js CHANGED
@@ -55,16 +55,31 @@ if (typeof localStorage === "undefined" || localStorage === null) {
55
55
  global.localStorage = new LocalStorage("./scratch");
56
56
  }
57
57
  var Booking = /** @class */ (function () {
58
- function Booking(params) {
58
+ /**
59
+ * This is the constructor of the Booking class.
60
+ * @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
61
+ * @param {string} sub_key The subscription key for using the APIs
62
+ * @param {() => void} onCartExpiration A callback function that will be called when the cart expires
63
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
64
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
65
+ */
66
+ function Booking(env, sub_key, onCartExpiration, access_token, sellerId) {
59
67
  this.cartStatus = Booking.CartStatus.EMPTY;
60
- this.sellerId = params.sellerId || undefined;
61
- this.config = (0, config_1.getConfig)();
62
- this.onCartExpiration = params.onCartExpiration;
68
+ this.sellerId = sellerId || undefined;
69
+ this.config = (0, config_1.setConfig)(env, sub_key, access_token);
70
+ this.onCartExpiration = onCartExpiration;
63
71
  var cartId = localStorage.getItem("cartId");
64
72
  if (cartId) {
65
73
  this.fetchAndSetCart(parseInt(cartId));
66
74
  }
67
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
+ };
68
83
  Booking.prototype.getCartStatus = function () {
69
84
  return this.cartStatus;
70
85
  };
@@ -115,7 +130,12 @@ var Booking = /** @class */ (function () {
115
130
  });
116
131
  });
117
132
  };
118
- // Tours config
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
+ */
119
139
  Booking.prototype.getTourCities = function () {
120
140
  return __awaiter(this, void 0, void 0, function () {
121
141
  var url;
@@ -125,15 +145,30 @@ var Booking = /** @class */ (function () {
125
145
  });
126
146
  });
127
147
  };
128
- Booking.prototype.getTours = function (params) {
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) {
129
156
  return __awaiter(this, void 0, void 0, function () {
130
157
  var url;
131
158
  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 })));
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 })));
133
160
  return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
134
161
  });
135
162
  });
136
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
+ */
137
172
  Booking.prototype.getToursTrips = function (tourId, date) {
138
173
  return __awaiter(this, void 0, void 0, function () {
139
174
  var url;
@@ -158,6 +193,7 @@ var Booking = /** @class */ (function () {
158
193
  });
159
194
  });
160
195
  };
196
+ //#endregion
161
197
  Booking.prototype.fetchCart = function (cartId) {
162
198
  return __awaiter(this, void 0, void 0, function () {
163
199
  var url;
@@ -167,8 +203,12 @@ var Booking = /** @class */ (function () {
167
203
  });
168
204
  });
169
205
  };
170
- // Trips config
171
- Booking.prototype.getTripsDepartures = function () {
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 () {
172
212
  return __awaiter(this, void 0, void 0, function () {
173
213
  var url;
174
214
  return __generator(this, function (_a) {
@@ -177,7 +217,12 @@ var Booking = /** @class */ (function () {
177
217
  });
178
218
  });
179
219
  };
180
- Booking.prototype.getTripsDestinations = function (departureStopName) {
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) {
181
226
  return __awaiter(this, void 0, void 0, function () {
182
227
  var url;
183
228
  return __generator(this, function (_a) {
@@ -186,16 +231,26 @@ var Booking = /** @class */ (function () {
186
231
  });
187
232
  });
188
233
  };
189
- Booking.prototype.getTrips = function (params) {
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) {
190
242
  return __awaiter(this, void 0, void 0, function () {
191
243
  var url;
192
244
  return __generator(this, function (_a) {
245
+ if (params.departureStopName === undefined || params.destinationStopName === undefined) {
246
+ throw Error("Fields departureStopName and destinationStopName are required");
247
+ }
193
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(), currency: params.currency, isRoundtrip: params.isRoundtrip.toString() })));
194
249
  return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
195
250
  });
196
251
  });
197
252
  };
198
- Booking.prototype.createTripCart = function (tripCart) {
253
+ Booking.prototype.createJourneyCart = function (tripCart) {
199
254
  return __awaiter(this, void 0, void 0, function () {
200
255
  var url;
201
256
  var _this = this;
@@ -231,7 +286,7 @@ var Booking = /** @class */ (function () {
231
286
  });
232
287
  });
233
288
  };
234
- Booking.prototype.updateSeatsStatus = function (params) {
289
+ Booking.prototype.movePassengers = function (params) {
235
290
  return __awaiter(this, void 0, void 0, function () {
236
291
  var url;
237
292
  return __generator(this, function (_a) {
@@ -243,6 +298,79 @@ var Booking = /** @class */ (function () {
243
298
  });
244
299
  });
245
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
246
374
  Booking.prototype.getPassengersDetails = function () {
247
375
  return __awaiter(this, void 0, void 0, function () {
248
376
  var url;
@@ -281,10 +409,9 @@ exports.Booking = Booking;
281
409
  (function (CartStatus) {
282
410
  CartStatus["EMPTY"] = "EMPTY";
283
411
  CartStatus["CREATION"] = "CREATION";
284
- CartStatus["SEAT"] = "SEATS";
285
- CartStatus["EXTRAS"] = "EXTRAS";
286
412
  CartStatus["PASSENGERS"] = "PASSENGERS";
413
+ CartStatus["SEATS"] = "SEATS";
414
+ CartStatus["EXTRAS"] = "EXTRAS";
287
415
  CartStatus["PAYMENT"] = "PAYMENT";
288
416
  })(CartStatus = Booking.CartStatus || (Booking.CartStatus = {}));
289
- })(Booking = exports.Booking || (exports.Booking = {}));
290
- exports.Booking = Booking;
417
+ })(Booking || (exports.Booking = Booking = {}));
@@ -61,7 +61,7 @@ export type TourCart = {
61
61
  tariffsMatrix: TariffMatrix;
62
62
  };
63
63
  };
64
- export type TripCart = {
64
+ export type JourneyCart = {
65
65
  cartId?: number;
66
66
  currency: Booking.Currencies;
67
67
  outboundJourney: {
@@ -0,0 +1,8 @@
1
+ import { Info } from "./Info";
2
+ import { Stop } from "./Stop";
3
+ import { Trip } from "./Trip";
4
+ export type Journey = {
5
+ stops: Stop[];
6
+ info: Info;
7
+ trips: Trip[];
8
+ };
@@ -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 JourneySearch = {
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 });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,8 @@
1
+ import { Stop } from "./Stop";
2
+ import { Info } from "../Info";
3
+ import { Trip } from "./Trip";
4
+ export type Journey = {
5
+ stops: Stop[];
6
+ info: Info;
7
+ trips: Trip[];
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { Booking } from "../..";
2
+ export type JourneySearch = {
3
+ departureStopName: string | undefined;
4
+ destinationStopName: string | undefined;
5
+ passengersNumber: number;
6
+ date: Date;
7
+ currency: Booking.Currencies;
8
+ isRoundtrip: boolean;
9
+ };
10
+ export declare const DefaultJourneySearch: JourneySearch;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultJourneySearch = void 0;
4
+ var __1 = require("../..");
5
+ exports.DefaultJourneySearch = {
6
+ departureStopName: "",
7
+ destinationStopName: "",
8
+ passengersNumber: 1,
9
+ date: new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 1)),
10
+ currency: __1.Booking.Currencies.EUR,
11
+ isRoundtrip: false,
12
+ };
@@ -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,9 @@
1
+ import { TariffMatrix, TariffType, TermsType } from "../TermsAndTariffs";
2
+ export type Trip = {
3
+ id: number;
4
+ departureStopName: string;
5
+ destinationStopName: string;
6
+ tariffsMatrix: TariffMatrix;
7
+ tariffTypes: TariffType[];
8
+ termsTypes: TermsType[];
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ export type Subscription = {
2
+ departurePhysicalAgencyStopId: number;
3
+ departureStopName: string;
4
+ destinationPhysicalAgencyStopId: number;
5
+ destinationStopName: string;
6
+ departureTime: string;
7
+ destinationTime: string;
8
+ lineName: string;
9
+ routeId: number;
10
+ routeName: string;
11
+ sellerId: number;
12
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare enum ValidityTypes {
2
+ WORKING_WEEK = "WORKING_WEEK",
3
+ WEEKLY = "WEEKLY",
4
+ MONTHLY = "MONTHLY",
5
+ YEARLY = "YEARLY"
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidityTypes = void 0;
4
+ var ValidityTypes;
5
+ (function (ValidityTypes) {
6
+ ValidityTypes["WORKING_WEEK"] = "WORKING_WEEK";
7
+ ValidityTypes["WEEKLY"] = "WEEKLY";
8
+ ValidityTypes["MONTHLY"] = "MONTHLY";
9
+ ValidityTypes["YEARLY"] = "YEARLY";
10
+ })(ValidityTypes || (exports.ValidityTypes = ValidityTypes = {}));
@@ -10,6 +10,7 @@ export type Tour = {
10
10
  termsTypes: TermsType[];
11
11
  isDateOptional: boolean;
12
12
  isDateRequired: boolean;
13
+ isTripMandatory: boolean;
13
14
  };
14
15
  export type TourTrip = {
15
16
  tripId: number;
@@ -0,0 +1,18 @@
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
+ isTripMandatory: boolean;
14
+ };
15
+ export type TourTrip = {
16
+ tripId: number;
17
+ hour: Date;
18
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,9 @@
1
- import { Info } from "./Info";
2
- import { Stop } from "./Stop";
3
1
  import { TariffMatrix, TariffType, TermsType } from "./TermsAndTariffs";
4
2
  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
- }[];
3
+ id: number;
4
+ departureStopName: string;
5
+ destinationStopName: string;
6
+ tariffsMatrix: TariffMatrix;
7
+ tariffTypes: TariffType[];
8
+ termsTypes: TermsType[];
15
9
  };
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -49,10 +60,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
49
60
  case 0:
50
61
  _a.trys.push([0, 2, , 3]);
51
62
  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
- },
63
+ headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
56
64
  })];
57
65
  case 1:
58
66
  response = _a.sent();
@@ -80,10 +88,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
80
88
  case 0:
81
89
  _a.trys.push([0, 2, , 3]);
82
90
  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
- },
91
+ headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
87
92
  })];
88
93
  case 1:
89
94
  response = _a.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,10 +14,10 @@
14
14
  },
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
- "@types/jest": "^29.5.1",
18
- "jest": "^29.5.0",
19
- "ts-jest": "^29.1.0",
20
- "typescript": "^5.0.4"
17
+ "@types/jest": "^29.5.4",
18
+ "jest": "^29.7.0",
19
+ "ts-jest": "^29.1.1",
20
+ "typescript": "^5.2.2"
21
21
  },
22
22
  "files": [
23
23
  "lib/**/*"
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "author": "M",
30
30
  "dependencies": {
31
- "axios": "^1.4.0",
32
- "node-localstorage": "^2.2.1"
31
+ "axios": "^1.5.0",
32
+ "node-localstorage": "^3.0.5"
33
33
  }
34
34
  }