mts-booking-library 1.2.27 → 1.2.29

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.
@@ -39,6 +39,7 @@ export declare abstract class Booking {
39
39
  * @param sellerId The id of the seller.
40
40
  */
41
41
  updateSellerId(sellerId: number): void;
42
+ getSellerId(): number | undefined;
42
43
  /**
43
44
  * This method allows to renew the access token for calling MTS APIs
44
45
  * @param {string} access_token The new access token
@@ -93,6 +93,9 @@ var Booking = /** @class */ (function () {
93
93
  Booking.prototype.updateSellerId = function (sellerId) {
94
94
  this.sellerId = sellerId;
95
95
  };
96
+ Booking.prototype.getSellerId = function () {
97
+ return this.sellerId;
98
+ };
96
99
  /**
97
100
  * This method allows to renew the access token for calling MTS APIs
98
101
  * @param {string} access_token The new access token
@@ -233,7 +236,7 @@ var Booking = /** @class */ (function () {
233
236
  }
234
237
  _e.label = 5;
235
238
  case 5:
236
- url = "".concat(this.config.API_ENDPOINT, "/sellers/").concat(this.sellerId, "/gateways?language=").concat(this.language);
239
+ url = "".concat(this.config.API_ENDPOINT, "/booking/sellers/").concat(this.sellerId, "/gateways?language=").concat(this.language);
237
240
  // We use directly makeGet because we don't want to add sellerId to the query string (it is already present in the url)
238
241
  return [2 /*return*/, (0, apiCall_1.makeGet)(url).then(function (response) {
239
242
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
@@ -3,7 +3,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
3
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
4
  import { AddReductionRequest } from "../types/common/Reduction";
5
5
  import { BusMatrix } from "../types/journeys/BusMatrix";
6
- import { CreateJourneyCartRequest, GetJourneyCartResponse, JourneyCart } from "../types/journeys/JourneyCart";
6
+ import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
7
7
  import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
8
8
  import { ReductionTrip } from "../types/journeys/Trip";
9
9
  import { Booking } from "./booking";
@@ -23,7 +23,7 @@ export declare class JourneyBooking extends Booking {
23
23
  getCart(): JourneyCart | undefined;
24
24
  resetBooking(): void;
25
25
  fetchAndSetCart(cartId: number): Promise<void>;
26
- fetchCart(cartId: number): Promise<GetJourneyCartResponse>;
26
+ fetchCart(cartId: number): Promise<JourneyCart>;
27
27
  /**
28
28
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
29
29
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -72,6 +72,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
72
  };
73
73
  Object.defineProperty(exports, "__esModule", { value: true });
74
74
  exports.JourneyBooking = void 0;
75
+ var config_1 = require("../config");
75
76
  var ErrorResponse_1 = require("../types/ErrorResponse");
76
77
  var Reduction_1 = require("../types/common/Reduction");
77
78
  var processBookingSteps_1 = require("../utils/processBookingSteps");
@@ -108,22 +109,32 @@ var JourneyBooking = /** @class */ (function (_super) {
108
109
  this.cartId = undefined;
109
110
  this.bookingStepsToStatus = new Map();
110
111
  this.bookingDueDate = undefined;
111
- localStorage.removeItem("cartId");
112
+ try {
113
+ localStorage.removeItem("cartId");
114
+ }
115
+ catch (e) {
116
+ if (this.config.ENV !== config_1.MTSEnvs.TEST) {
117
+ throw new Error("Error while deleting cartId from localStorage");
118
+ }
119
+ console.log(e);
120
+ }
112
121
  };
113
122
  JourneyBooking.prototype.fetchAndSetCart = function (cartId) {
114
123
  return __awaiter(this, void 0, void 0, function () {
115
124
  var _this = this;
116
125
  return __generator(this, function (_a) {
117
126
  switch (_a.label) {
118
- case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (response) {
119
- if (response.cart) {
120
- var cartDate = new Date(response.cart.bookingDueDate);
121
- if (cartDate > new Date()) {
122
- _this.cart = response.cart;
123
- _this.cartId = response.cart.id;
127
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
128
+ if (cart) {
129
+ var cartDate = new Date(cart.bookingDueDate);
130
+ if (cartDate > new Date() && !cart.hasIssuedTickets) {
131
+ _this.cart = cart;
132
+ _this.cartId = cart.id;
124
133
  _this.bookingDueDate = cartDate; // See Booking class
134
+ // Update the sellerId. This is particularly important in Linkavel
135
+ _this.updateSellerId(cart.sellerId);
125
136
  // Fill the booking process status
126
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
137
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
127
138
  }
128
139
  else {
129
140
  // This should never happen, but just in case
@@ -149,11 +160,11 @@ var JourneyBooking = /** @class */ (function (_super) {
149
160
  _this.resetBooking();
150
161
  throw new Error(response);
151
162
  }
152
- // Check that the cart doe not have issued tickets
153
- if (response.hasIssuedTickets) {
163
+ // Check that the cart does not have issued tickets
164
+ if (response.cart.hasIssuedTickets) {
154
165
  _this.resetBooking();
155
166
  }
156
- return response;
167
+ return response.cart;
157
168
  })];
158
169
  });
159
170
  });
@@ -256,6 +267,8 @@ var JourneyBooking = /** @class */ (function (_super) {
256
267
  // Fill the booking process status
257
268
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
258
269
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
270
+ // Update the sellerId. This is particularly important in Linkavel
271
+ _this.updateSellerId(response.cart.sellerId);
259
272
  return response.cart;
260
273
  })];
261
274
  });
@@ -3,7 +3,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
3
3
  import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
4
  import { AddReductionRequest } from "../types/common/Reduction";
5
5
  import { Service, ServiceTrip } from "../types/services/Service";
6
- import { CreateServiceCartRequest, GetServiceCartResponse, ServiceCart } from "../types/services/ServiceCart";
6
+ import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
7
7
  import { Booking } from "./booking";
8
8
  export declare class ServiceBooking extends Booking {
9
9
  private cart?;
@@ -21,7 +21,7 @@ export declare class ServiceBooking extends Booking {
21
21
  getCart(): ServiceCart | undefined;
22
22
  resetBooking(): void;
23
23
  fetchAndSetCart(cartId: number): Promise<void>;
24
- fetchCart(cartId: number): Promise<GetServiceCartResponse>;
24
+ fetchCart(cartId: number): Promise<ServiceCart>;
25
25
  /**
26
26
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
27
27
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -72,6 +72,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
72
  };
73
73
  Object.defineProperty(exports, "__esModule", { value: true });
74
74
  exports.ServiceBooking = void 0;
75
+ var config_1 = require("../config");
75
76
  var ErrorResponse_1 = require("../types/ErrorResponse");
76
77
  var Reduction_1 = require("../types/common/Reduction");
77
78
  var processBookingSteps_1 = require("../utils/processBookingSteps");
@@ -108,23 +109,32 @@ var ServiceBooking = /** @class */ (function (_super) {
108
109
  this.cartId = undefined;
109
110
  this.bookingStepsToStatus = new Map();
110
111
  this.bookingDueDate = undefined;
111
- localStorage.removeItem("cartId");
112
+ try {
113
+ localStorage.removeItem("cartId");
114
+ }
115
+ catch (e) {
116
+ if (this.config.ENV !== config_1.MTSEnvs.TEST) {
117
+ throw new Error("Error while deleting cartId from localStorage");
118
+ }
119
+ console.log(e);
120
+ }
112
121
  };
113
122
  ServiceBooking.prototype.fetchAndSetCart = function (cartId) {
114
123
  return __awaiter(this, void 0, void 0, function () {
115
124
  var _this = this;
116
125
  return __generator(this, function (_a) {
117
126
  switch (_a.label) {
118
- case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (response) {
119
- console.log(response);
120
- if (response.cart) {
121
- var cartDate = new Date(response.cart.bookingDueDate);
122
- if (cartDate > new Date()) {
123
- _this.cart = response.cart;
124
- _this.cartId = response.cart.id;
127
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
128
+ if (cart) {
129
+ var cartDate = new Date(cart.bookingDueDate);
130
+ if (cartDate > new Date() && !cart.hasIssuedTickets) {
131
+ _this.cart = cart;
132
+ _this.cartId = cart.id;
125
133
  _this.bookingDueDate = cartDate; // See Booking class
134
+ // Update the sellerId. This is particularly important in Linkavel
135
+ _this.updateSellerId(cart.sellerId);
126
136
  // Fill the booking process status
127
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
137
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
128
138
  }
129
139
  else {
130
140
  // This should never happen, but just in case
@@ -151,10 +161,10 @@ var ServiceBooking = /** @class */ (function (_super) {
151
161
  throw new Error(response);
152
162
  }
153
163
  // Check that the cart doe not have issued tickets
154
- if (response.hasIssuedTickets) {
164
+ if (response.cart.hasIssuedTickets) {
155
165
  _this.resetBooking();
156
166
  }
157
- return response;
167
+ return response.cart;
158
168
  })];
159
169
  });
160
170
  });
@@ -258,6 +268,8 @@ var ServiceBooking = /** @class */ (function (_super) {
258
268
  // Fill the booking process status
259
269
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
260
270
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
271
+ // Update the sellerId. This is particularly important in Linkavel
272
+ _this.updateSellerId(response.cart.sellerId);
261
273
  return response.cart;
262
274
  })];
263
275
  });
@@ -3,7 +3,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
3
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
4
  import { AddReductionRequest } from "../types/common/Reduction";
5
5
  import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
6
- import { CreateSubscriptionCartRequest, GetSubscriptionCartResponse, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
6
+ import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
7
7
  import { Subscription } from "../types/subscriptions/Subscriptions";
8
8
  import { Booking } from "./booking";
9
9
  export declare class SubscriptionBooking extends Booking {
@@ -22,7 +22,7 @@ export declare class SubscriptionBooking extends Booking {
22
22
  getCart(): SubscriptionCart | undefined;
23
23
  resetBooking(): void;
24
24
  fetchAndSetCart(cartId: number): Promise<void>;
25
- fetchCart(cartId: number): Promise<GetSubscriptionCartResponse>;
25
+ fetchCart(cartId: number): Promise<SubscriptionCart>;
26
26
  /**
27
27
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
28
28
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -72,6 +72,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
72
  };
73
73
  Object.defineProperty(exports, "__esModule", { value: true });
74
74
  exports.SubscriptionBooking = void 0;
75
+ var config_1 = require("../config");
75
76
  var ErrorResponse_1 = require("../types/ErrorResponse");
76
77
  var Reduction_1 = require("../types/common/Reduction");
77
78
  var processBookingSteps_1 = require("../utils/processBookingSteps");
@@ -108,22 +109,32 @@ var SubscriptionBooking = /** @class */ (function (_super) {
108
109
  this.cartId = undefined;
109
110
  this.bookingStepsToStatus = new Map();
110
111
  this.bookingDueDate = undefined;
111
- localStorage.removeItem("cartId");
112
+ try {
113
+ localStorage.removeItem("cartId");
114
+ }
115
+ catch (e) {
116
+ if (this.config.ENV !== config_1.MTSEnvs.TEST) {
117
+ throw new Error("Error while deleting cartId from localStorage");
118
+ }
119
+ console.log(e);
120
+ }
112
121
  };
113
122
  SubscriptionBooking.prototype.fetchAndSetCart = function (cartId) {
114
123
  return __awaiter(this, void 0, void 0, function () {
115
124
  var _this = this;
116
125
  return __generator(this, function (_a) {
117
126
  switch (_a.label) {
118
- case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (response) {
119
- if (response.cart) {
120
- var cartDate = new Date(response.cart.bookingDueDate);
121
- if (cartDate > new Date()) {
122
- _this.cart = response.cart;
123
- _this.cartId = response.cart.id;
127
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
128
+ if (cart) {
129
+ var cartDate = new Date(cart.bookingDueDate);
130
+ if (cartDate > new Date() && !cart.hasIssuedTickets) {
131
+ _this.cart = cart;
132
+ _this.cartId = cart.id;
124
133
  _this.bookingDueDate = cartDate; // See Booking class
134
+ // Update the sellerId. This is particularly important in Linkavel
135
+ _this.updateSellerId(cart.sellerId);
125
136
  // Fill the booking process status
126
- _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
137
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
127
138
  }
128
139
  else {
129
140
  // This should never happen, but just in case
@@ -150,7 +161,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
150
161
  throw new Error(response);
151
162
  }
152
163
  // Check that the cart doe not have issued tickets
153
- if (response.hasIssuedTickets) {
164
+ if (response.cart.hasIssuedTickets) {
154
165
  _this.resetBooking();
155
166
  }
156
167
  return response;
@@ -311,6 +322,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
311
322
  // Fill the booking process status
312
323
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
313
324
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
325
+ // Update the sellerId. This is particularly important in Linkavel
326
+ _this.updateSellerId(response.cart.sellerId);
314
327
  return response.cart;
315
328
  })];
316
329
  });
package/lib/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare enum MTSEnvs {
2
+ TEST = "TEST",
2
3
  DEV = "DEV",
3
4
  STAGING = "STAGING",
4
5
  PROD = "PROD"
package/lib/config.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getConfig = exports.setConfig = exports.MTSEnvs = void 0;
4
4
  var MTSEnvs;
5
5
  (function (MTSEnvs) {
6
+ MTSEnvs["TEST"] = "TEST";
6
7
  MTSEnvs["DEV"] = "DEV";
7
8
  MTSEnvs["STAGING"] = "STAGING";
8
9
  MTSEnvs["PROD"] = "PROD";
@@ -18,6 +19,7 @@ var setConfig = function (env, sub_key, debug, access_token) {
18
19
  // First, set the environment
19
20
  config.ENV = env.toUpperCase();
20
21
  switch (config.ENV) {
22
+ case MTSEnvs.TEST:
21
23
  case MTSEnvs.DEV:
22
24
  config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/dev";
23
25
  break;
package/lib/index.d.ts CHANGED
@@ -10,15 +10,15 @@ export { Reduction, AddReductionRequest } from "./types/common/Reduction";
10
10
  export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, IssueTicketsResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
11
11
  export { ErrorResponse, objectIsMTSErrorResponse } from "./types/ErrorResponse";
12
12
  export { BusLayoutCell, BusMatrix, BusCellTypes, SeatStatus } from "./types/journeys/BusMatrix";
13
- export { JourneyCart, GetJourneyCartResponse, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
13
+ export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
14
14
  export { JourneyInfo } from "./types/journeys/JourneyInfo";
15
15
  export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
16
16
  export { Stop } from "./types/journeys/Stop";
17
17
  export { Trip, CartTrip, ReductionTrip } from "./types/journeys/Trip";
18
18
  export { Line } from "./types/services/Line";
19
19
  export { Service, ServiceTrip } from "./types/services/Service";
20
- export { ServiceCart, GetServiceCartResponse, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
20
+ export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
21
21
  export { ServiceInfo } from "./types/services/ServiceInfo";
22
22
  export { Subscription } from "./types/subscriptions/Subscriptions";
23
23
  export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
24
- export { SubscriptionCart, GetSubscriptionCartResponse, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
24
+ export { SubscriptionCart, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
@@ -9,6 +9,8 @@ import { Extra } from "./Extra";
9
9
  * - SubscriptionCart: {@link SubscriptionCart}
10
10
  * @property {number} id The id of the cart
11
11
  * @property {string} cartCode The code of the cart
12
+ * @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
13
+ * the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
12
14
  * @property {number} sellerId The id of the seller of the tickets in the cart
13
15
  * @property {Map<string, boolean[]>} stepsToStatus This data structure describes the steps of the booking process.
14
16
  * The keys of this dictionary represent the booking steps. See ... for the list of possible steps. If the
@@ -23,6 +25,7 @@ export type Cart = {
23
25
  id: number;
24
26
  sellerId: number;
25
27
  cartCode: string;
28
+ hasIssuedTickets: boolean;
26
29
  stepsToStatus: Map<string, boolean[]>;
27
30
  currency: Booking.Currencies;
28
31
  bookingDueDate: string;
@@ -35,16 +35,6 @@ export type CreateJourneyCartRequest = {
35
35
  returnJourney: TripBookingInfo[] | null;
36
36
  };
37
37
  export declare const DEFAULT_CREATE_JOURNEY_CART: CreateJourneyCartRequest;
38
- /**
39
- * This type represents the response of the {@link JourneyBooking.fetchCart} API.
40
- * @property {JourneyCart} cart - The {@link JourneyCart} object representing the cart.
41
- * @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
42
- * the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
43
- */
44
- export type GetJourneyCartResponse = {
45
- cart: JourneyCart | null;
46
- hasIssuedTickets: boolean;
47
- };
48
38
  /**
49
39
  * @description Represents a `JourneyCart`, which extends the {@link Cart} type by including additional
50
40
  * information about the bookings
@@ -31,16 +31,6 @@ export type CreateServiceCartRequest = {
31
31
  export type ServiceCart = Cart & {
32
32
  bookings: ServiceBookingType[];
33
33
  };
34
- /**
35
- * This type represents the response of the {@link ServiceBooking.fetchCart} API.
36
- * @property {JourneyCart} cart - The {@link ServiceCart} object representing the cart.
37
- * @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
38
- * the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
39
- */
40
- export type GetServiceCartResponse = {
41
- cart: ServiceCart | null;
42
- hasIssuedTickets: boolean;
43
- };
44
34
  /**
45
35
  * @description Represents a `ServiceBooking`, which contains information about a service booking.
46
36
  *
@@ -48,16 +48,6 @@ export type SubscriptionPeriod = {
48
48
  export type SubscriptionCart = Cart & {
49
49
  bookings: SubscriptionBookingType[];
50
50
  };
51
- /**
52
- * This type represents the response of the {@link SubscriptionBooking.fetchCart} API.
53
- * @property {JourneyCart} cart - The {@link SubscriptionCart} object representing the cart.
54
- * @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
55
- * the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
56
- */
57
- export type GetSubscriptionCartResponse = {
58
- cart: SubscriptionCart | null;
59
- hasIssuedTickets: boolean;
60
- };
61
51
  /**
62
52
  * @description Represents a `SubscriptionBooking`, which contains information about a subscription booking.
63
53
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.27",
3
+ "version": "1.2.29",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",