mts-booking-library 1.1.4 → 1.1.5

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.
@@ -1,6 +1,7 @@
1
1
  import { MTSConfig, MTSEnvs } from "../config";
2
2
  export declare abstract class Booking {
3
3
  readonly sellerId?: number | undefined;
4
+ readonly bookingType: Booking.BookingTypes;
4
5
  readonly config: MTSConfig;
5
6
  cartStatus: Booking.CartStatus;
6
7
  bookingDueDate: Date | undefined;
@@ -10,10 +11,11 @@ export declare abstract class Booking {
10
11
  * @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
11
12
  * @param {string} sub_key The subscription key for using the APIs
12
13
  * @param {() => void} onCartExpiration A callback function that will be called when the cart expires
14
+ * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
13
15
  * @param {string} [access_token=undefined] The access token for calling MTS APIs
14
16
  * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
15
17
  */
16
- constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, access_token?: string, sellerId?: number);
18
+ constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, bookingType: Booking.BookingTypes, debug?: boolean, access_token?: string, sellerId?: number);
17
19
  /**
18
20
  * This method allows to renew the access token for calling MTS APIs
19
21
  * @param {string} access_token The new access token
@@ -39,6 +41,6 @@ export declare namespace Booking {
39
41
  enum BookingTypes {
40
42
  MLP = "MLP",
41
43
  SERVICE = "SERVICE",
42
- MLP_SUBSCRIPTIONS = "MLP_SUBSCRIPTIONS"
44
+ MLP_SUBSCRIPTION = "MLP_SUBSCRIPTION"
43
45
  }
44
46
  }
@@ -44,14 +44,16 @@ var Booking = /** @class */ (function () {
44
44
  * @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
45
45
  * @param {string} sub_key The subscription key for using the APIs
46
46
  * @param {() => void} onCartExpiration A callback function that will be called when the cart expires
47
+ * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
47
48
  * @param {string} [access_token=undefined] The access token for calling MTS APIs
48
49
  * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
49
50
  */
50
- function Booking(env, sub_key, onCartExpiration, debug, access_token, sellerId) {
51
+ function Booking(env, sub_key, onCartExpiration, bookingType, debug, access_token, sellerId) {
51
52
  if (debug === void 0) { debug = false; }
52
53
  this.cartStatus = Booking.CartStatus.EMPTY;
53
54
  this.sellerId = sellerId || undefined;
54
55
  this.config = (0, config_1.setConfig)(env, sub_key, debug, access_token);
56
+ this.bookingType = bookingType;
55
57
  this.onCartExpiration = onCartExpiration;
56
58
  }
57
59
  /**
@@ -100,6 +102,6 @@ exports.Booking = Booking;
100
102
  (function (BookingTypes) {
101
103
  BookingTypes["MLP"] = "MLP";
102
104
  BookingTypes["SERVICE"] = "SERVICE";
103
- BookingTypes["MLP_SUBSCRIPTIONS"] = "MLP_SUBSCRIPTIONS";
105
+ BookingTypes["MLP_SUBSCRIPTION"] = "MLP_SUBSCRIPTION";
104
106
  })(BookingTypes = Booking.BookingTypes || (Booking.BookingTypes = {}));
105
107
  })(Booking || (exports.Booking = Booking = {}));
@@ -71,7 +71,7 @@ var JourneyBooking = /** @class */ (function (_super) {
71
71
  if (debug === void 0) { debug = false; }
72
72
  var _this =
73
73
  // Call Booking constructor
74
- _super.call(this, env, sub_key, onCartExpiration, debug, access_token, sellerId) || this;
74
+ _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, access_token, sellerId) || this;
75
75
  var cartId = localStorage.getItem("cartId");
76
76
  if (cartId) {
77
77
  _this.fetchAndSetCart(parseInt(cartId));
@@ -178,6 +178,7 @@ var JourneyBooking = /** @class */ (function (_super) {
178
178
  return [2 /*return*/, (0, apiCall_1.makePost)(url, tripCart).then(function (cart) {
179
179
  _this.cart = cart.cart;
180
180
  _this.cartStatus = cart.cart.status;
181
+ _this.bookingDueDate = new Date(cart.cart.bookingDueDate);
181
182
  _this.createCartTimer(new Date(cart.cart.bookingDueDate));
182
183
  return cart.cart;
183
184
  })];
@@ -71,7 +71,7 @@ var ServiceBooking = /** @class */ (function (_super) {
71
71
  if (debug === void 0) { debug = false; }
72
72
  var _this =
73
73
  // Call Booking constructor
74
- _super.call(this, env, sub_key, onCartExpiration, debug, access_token, sellerId) || this;
74
+ _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, access_token, sellerId) || this;
75
75
  var cartId = localStorage.getItem("cartId");
76
76
  if (cartId) {
77
77
  _this.fetchAndSetCart(parseInt(cartId));
@@ -179,6 +179,7 @@ var ServiceBooking = /** @class */ (function (_super) {
179
179
  return [2 /*return*/, (0, apiCall_1.makePost)(url, serviceCart).then(function (cart) {
180
180
  _this.cart = cart.cart;
181
181
  _this.cartStatus = cart.cart.status;
182
+ _this.bookingDueDate = new Date(cart.cart.bookingDueDate);
182
183
  _this.createCartTimer(new Date(cart.cart.bookingDueDate));
183
184
  return cart.cart;
184
185
  })];
@@ -1,7 +1,7 @@
1
1
  import { MTSEnvs } from "../config";
2
2
  import { Cart } from "../types/common/Cart";
3
3
  import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
4
- import { CreateSubscriptionCartRequest } from "../types/subscriptions/SubscriptionCart";
4
+ import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
5
5
  import { Subscription } from "../types/subscriptions/Subscriptions";
6
6
  import { Booking } from "./booking";
7
7
  export declare class SubscriptionBooking extends Booking {
@@ -21,7 +21,7 @@ export declare class SubscriptionBooking extends Booking {
21
21
  * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
22
22
  * @returns {string[]} The list of possible destinations
23
23
  */
24
- getSubscirptionsDestinations(departureStopName: string): Promise<string[]>;
24
+ getSubscriptionsDestinations(departureStopName: string): Promise<string[]>;
25
25
  /**
26
26
  * This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
27
27
  * The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
@@ -47,7 +47,7 @@ export declare class SubscriptionBooking extends Booking {
47
47
  * @returns {GetSubscriptionAvailabilityResponse} The availability of the subscription for the given parameters
48
48
  */
49
49
  getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest): Promise<GetSubscriptionAvailabilityResponse>;
50
- createSubscriptionCart(request: CreateSubscriptionCartRequest): Promise<any>;
50
+ createSubscriptionCart(request: CreateSubscriptionCartRequest): Promise<SubscriptionCart>;
51
51
  }
52
52
  export declare namespace SubscriptionBooking {
53
53
  enum ValidityTypes {
@@ -71,7 +71,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
71
71
  if (debug === void 0) { debug = false; }
72
72
  var _this =
73
73
  // Call Booking constructor
74
- _super.call(this, env, sub_key, onCartExpiration, debug, access_token, sellerId) || this;
74
+ _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, access_token, sellerId) || this;
75
75
  var cartId = localStorage.getItem("cartId");
76
76
  if (cartId) {
77
77
  _this.fetchAndSetCart(parseInt(cartId));
@@ -141,7 +141,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
141
141
  * @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
142
142
  * @returns {string[]} The list of possible destinations
143
143
  */
144
- SubscriptionBooking.prototype.getSubscirptionsDestinations = function (departureStopName) {
144
+ SubscriptionBooking.prototype.getSubscriptionsDestinations = function (departureStopName) {
145
145
  return __awaiter(this, void 0, void 0, function () {
146
146
  var url;
147
147
  return __generator(this, function (_a) {
@@ -202,9 +202,16 @@ var SubscriptionBooking = /** @class */ (function (_super) {
202
202
  SubscriptionBooking.prototype.createSubscriptionCart = function (request) {
203
203
  return __awaiter(this, void 0, void 0, function () {
204
204
  var url;
205
+ var _this = this;
205
206
  return __generator(this, function (_a) {
206
207
  url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions");
207
- return [2 /*return*/, (0, apiCall_1.makePost)(url, request)];
208
+ return [2 /*return*/, (0, apiCall_1.makePost)(url, request).then(function (cart) {
209
+ _this.cart = cart.cart;
210
+ _this.cartStatus = cart.cart.status;
211
+ _this.bookingDueDate = new Date(cart.cart.bookingDueDate);
212
+ _this.createCartTimer(new Date(cart.cart.bookingDueDate));
213
+ return cart.cart;
214
+ })];
208
215
  });
209
216
  });
210
217
  };
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @description Error response type as returned by the BackEnd
3
+ *
4
+ * @property {number} statusCode - The status code of the error (e.g. 400)
5
+ * @property {string} message - The message of the error (e.g. "Invalid parameters")
6
+ */
1
7
  export type ErrorResponse = {
2
8
  statusCode: number;
3
9
  message: string;
@@ -1,5 +1,4 @@
1
1
  import { Booking } from "../../booking/booking";
2
- import { Person } from "./Person";
3
2
  /**
4
3
  * @description Cart is the object returned by the API when a cart is created.
5
4
  * Note that depending on the type of booking, this type will be extended with different fields:
@@ -11,6 +10,8 @@ import { Person } from "./Person";
11
10
  * @property {Booking.CartStatus} status The status of the cart. See {@link Booking.CartStatus}
12
11
  * @property {Booking.CartStatus} nextStatus The next status of the cart. See {@link Booking.CartStatus}
13
12
  * @property {Booking.Currencies} currency The currency of the cart. See {@link Booking.Currencies}
13
+ * @property {string} bookingDueDate The date and time when the cart expires
14
+ * @property {number} buyerId The id of the buyer
14
15
  */
15
16
  export type Cart = {
16
17
  id: number;
@@ -19,7 +20,7 @@ export type Cart = {
19
20
  nextStatus: Booking.CartStatus;
20
21
  currency: Booking.Currencies;
21
22
  bookingDueDate: string;
22
- buyer: Person;
23
+ buyerId: number;
23
24
  reductions: {
24
25
  tripId: number;
25
26
  tripName: string;
@@ -43,7 +43,7 @@ export type JourneyCart = Cart & {
43
43
  /**
44
44
  * @description Represents a `JourneyBooking`, which contains information about a journey booking.
45
45
  *
46
- * @property {Booking.BookingTypes} type - The type of booking.
46
+ * @property {Booking.BookingTypes} type - The type of booking. For journeys, this is always `Booking.BookingTypes.MLP`.
47
47
  * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
48
48
  * associated with this journey booking.
49
49
  * @property {Stop[]} info - An array of {@link Stop} objects representing the stops associated with this journey booking.
@@ -32,9 +32,9 @@ export type ServiceCart = Cart & {
32
32
  bookings: ServiceBookingType[];
33
33
  };
34
34
  /**
35
- * @description Represents a `JourneyBooking`, which contains information about a journey booking.
35
+ * @description Represents a `ServiceBooking`, which contains information about a service booking.
36
36
  *
37
- * @property {Booking.BookingTypes} type - The type of booking.
37
+ * @property {Booking.BookingTypes} type - The type of booking. For services, this is always `Booking.BookingTypes.SERVICE`.
38
38
  * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
39
39
  * associated with this journey booking.
40
40
  * @property {ServiceTrip} info - An array of {@link ServiceTrip} objects representing the stops associated with this journey booking.
@@ -1,3 +1,6 @@
1
+ import { Booking } from "../../booking/booking";
2
+ import { Cart } from "../common/Cart";
3
+ import { SubscriptionInfo } from "./SubscriptionInfo";
1
4
  /**
2
5
  * @description This is the object to be passed to `SubscriptionBooking.createSubscriptionCart`,
3
6
  * containing information about the selected subscription.
@@ -37,3 +40,23 @@ export type SubscriptionPeriod = {
37
40
  dateFrom: string;
38
41
  dateTo: string;
39
42
  };
43
+ /**
44
+ * @description Represents a `SubscriptionCart`, which extends the {@link Cart} type by including additional information about the bookings.
45
+ *
46
+ * @property {SubscriptionBookingType[]} bookings - An array of {@link SubscriptionBookingType} objects representing the created subscriptions.
47
+ */
48
+ export type SubscriptionCart = Cart & {
49
+ bookings: SubscriptionBookingType[];
50
+ };
51
+ /**
52
+ * @description Represents a `SubscriptionBooking`, which contains information about a subscription booking.
53
+ *
54
+ * @property {Booking.BookingTypes} type - The type of booking. For subscriptions, this is always `Booking.BookingTypes.SUBSCRIPTION`.
55
+ * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
56
+ * associated with this journey booking.
57
+ * @property {ServiceTrip} info - An array of {@link ServiceTrip} objects representing the stops associated with this journey booking.
58
+ */
59
+ export type SubscriptionBookingType = {
60
+ type: Booking.BookingTypes;
61
+ info: SubscriptionInfo;
62
+ };
@@ -0,0 +1,39 @@
1
+ import { SubscriptionBooking } from "../../booking/subscriptionBooking";
2
+ /**
3
+ * @description This object contains information about the created subscription.
4
+ *
5
+ * @property {string} periodsNames - The names of the periods for which the subscription was booked (e.g. "July 2023")
6
+ * @property {boolean} isRoundTrip - Whether the subscription is for a round trip or not.
7
+ * @property {SubscriptionBooking.ValidityTypes} validity - The validity of the subscription.
8
+ * @property {number} totalPrice - The total price of the subscription.
9
+ * @property {string} outboundLineName - The name of the line for the outbound trip.
10
+ * @property {string} outboundRouteName - The name of the route for the outbound trip.
11
+ * @property {string} outboundDepartureStopName - The name of the departure stop for the outbound trip.
12
+ * @property {string} outboundDestinationStopName - The name of the destination stop for the outbound trip.
13
+ * @property {string} outboundDepartureStopTime - The departure time (only time, not date) for the outbound trip.
14
+ * @property {string} outboundDestinationStopTime - The destination time (only time, not date) for the outbound trip.
15
+ * @property {string} returnLineName - The name of the line for the return trip.
16
+ * @property {string} returnRouteName - The name of the route for the return trip.
17
+ * @property {string} returnDepartureStopName - The name of the departure stop for the return trip.
18
+ * @property {string} returnDestinationStopName - The name of the destination stop for the return trip.
19
+ * @property {string} returnDepartureStopTime - The departure time (only time, not date) for the return trip.
20
+ * @property {string} returnDestinationStopTime - The destination time (only time, not date) for the return trip.
21
+ */
22
+ export type SubscriptionInfo = {
23
+ periodsNames: string;
24
+ isRoundTrip: boolean;
25
+ validity: SubscriptionBooking.ValidityTypes;
26
+ totalPrice: number;
27
+ outboundLineName: string;
28
+ outboundRouteName: string;
29
+ outboundDepartureStopName: string;
30
+ outboundDestinationStopName: string;
31
+ outboundDepartureStopTime: string;
32
+ outboundDestinationStopTime: string;
33
+ returnLineName: string;
34
+ returnRouteName: string;
35
+ returnDepartureStopName: string;
36
+ returnDestinationStopName: string;
37
+ returnDepartureStopTime: string;
38
+ returnDestinationStopTime: string;
39
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",