mts-booking-library 1.3.11 → 1.3.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  import { MTSConfig, MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
+ import { processedStepsToStatus } from "../types/common/Cart";
3
4
  import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueTicketsResponse } from "../types/common/Payment";
4
5
  import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
5
6
  import { AddReductionRequest } from "../types/common/Reduction";
@@ -18,7 +19,7 @@ export declare abstract class Booking {
18
19
  * - The second tells whether the section is completed. <br/>
19
20
  * - The third tells whether the section is required. <br/>
20
21
  */
21
- bookingStepsToStatus: Map<string, boolean[]>;
22
+ bookingStepsToStatus: processedStepsToStatus;
22
23
  cartId: number | undefined;
23
24
  bookingDueDate: Date | undefined;
24
25
  /**
@@ -48,7 +49,7 @@ export declare abstract class Booking {
48
49
  callGetApi(url: string): Promise<ErrorResponse | any>;
49
50
  callPostApi(url: string, body: any): Promise<any>;
50
51
  callDeleteApi(url: string): Promise<ErrorResponse | any>;
51
- getBookingStepsToStatus(): Map<string, boolean[]>;
52
+ getBookingStepsToStatus(): processedStepsToStatus;
52
53
  changeCurrency(currency: Booking.Currencies): void;
53
54
  changeLanguage(language: string): void;
54
55
  /**
@@ -41,7 +41,7 @@ export declare class JourneyBooking extends Booking {
41
41
  resetState: () => void;
42
42
  }>>) => void;
43
43
  clearStorage: () => void;
44
- rehydrate: () => void | Promise<void>;
44
+ rehydrate: () => Promise<void> | void;
45
45
  hasHydrated: () => boolean;
46
46
  onHydrate: (fn: (state: {
47
47
  cartId: number | undefined;
@@ -38,7 +38,7 @@ export declare class ServiceBooking extends Booking {
38
38
  resetState: () => void;
39
39
  }>>) => void;
40
40
  clearStorage: () => void;
41
- rehydrate: () => void | Promise<void>;
41
+ rehydrate: () => Promise<void> | void;
42
42
  hasHydrated: () => boolean;
43
43
  onHydrate: (fn: (state: {
44
44
  cartId: number | undefined;
@@ -39,7 +39,7 @@ export declare class SubscriptionBooking extends Booking {
39
39
  resetState: () => void;
40
40
  }>>) => void;
41
41
  clearStorage: () => void;
42
- rehydrate: () => void | Promise<void>;
42
+ rehydrate: () => Promise<void> | void;
43
43
  hasHydrated: () => boolean;
44
44
  onHydrate: (fn: (state: {
45
45
  cartId: number | undefined;
@@ -41,7 +41,7 @@ export declare class TplBooking extends Booking {
41
41
  resetState: () => void;
42
42
  }>>) => void;
43
43
  clearStorage: () => void;
44
- rehydrate: () => void | Promise<void>;
44
+ rehydrate: () => Promise<void> | void;
45
45
  hasHydrated: () => boolean;
46
46
  onHydrate: (fn: (state: {
47
47
  cartId: number | undefined;
package/lib/index.d.ts CHANGED
@@ -3,12 +3,14 @@ export { JourneyBooking } from "./booking/journeyBooking";
3
3
  export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
5
  export { TplBooking } from "./booking/tplBooking";
6
+ export { useMtsBookingState } from "./mtsStorage";
6
7
  export { Person, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
7
8
  export { GetBuyerPassengersDetailsResponse, GetPassenger, BuyerDataStatus } from "./types/common/Person";
8
9
  export { EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
9
10
  export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType, PassengerTariff, ExtraTariff } from "./types/common/Tariffs";
10
11
  export { Reduction, AddReductionRequest } from "./types/common/Reduction";
11
12
  export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, IssueTicketsResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
13
+ export { ReductionType } from "./types/common/Reduction";
12
14
  export { ErrorResponse, objectIsMTSErrorResponse } from "./types/ErrorResponse";
13
15
  export { BusLayoutCell, BusMatrix, BusCellTypes, SeatStatus } from "./types/journeys/BusMatrix";
14
16
  export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_JOURNEY_SEARCH = exports.DEFAULT_CREATE_JOURNEY_CART = exports.SeatStatus = exports.BusCellTypes = exports.objectIsMTSErrorResponse = exports.PaymentMethods = exports.GatewayTypes = exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = exports.TplBooking = exports.SubscriptionBooking = exports.ServiceBooking = exports.JourneyBooking = exports.Booking = void 0;
3
+ exports.DEFAULT_JOURNEY_SEARCH = exports.DEFAULT_CREATE_JOURNEY_CART = exports.SeatStatus = exports.BusCellTypes = exports.objectIsMTSErrorResponse = exports.ReductionType = exports.PaymentMethods = exports.GatewayTypes = exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = exports.useMtsBookingState = exports.TplBooking = exports.SubscriptionBooking = exports.ServiceBooking = exports.JourneyBooking = exports.Booking = void 0;
4
4
  //#region Export Booking classes
5
5
  var booking_1 = require("./booking/booking");
6
6
  Object.defineProperty(exports, "Booking", { enumerable: true, get: function () { return booking_1.Booking; } });
@@ -13,6 +13,10 @@ Object.defineProperty(exports, "SubscriptionBooking", { enumerable: true, get: f
13
13
  var tplBooking_1 = require("./booking/tplBooking");
14
14
  Object.defineProperty(exports, "TplBooking", { enumerable: true, get: function () { return tplBooking_1.TplBooking; } });
15
15
  //#endregion
16
+ //#region Export Zustand states
17
+ var mtsStorage_1 = require("./mtsStorage");
18
+ Object.defineProperty(exports, "useMtsBookingState", { enumerable: true, get: function () { return mtsStorage_1.useMtsBookingState; } });
19
+ //#endregion
16
20
  //#region Export common types
17
21
  // @note: Cart is not exported because it is extended by other types
18
22
  var Person_1 = require("./types/common/Person");
@@ -23,6 +27,8 @@ Object.defineProperty(exports, "BuyerDataStatus", { enumerable: true, get: funct
23
27
  var Payment_1 = require("./types/common/Payment");
24
28
  Object.defineProperty(exports, "GatewayTypes", { enumerable: true, get: function () { return Payment_1.GatewayTypes; } });
25
29
  Object.defineProperty(exports, "PaymentMethods", { enumerable: true, get: function () { return Payment_1.PaymentMethods; } });
30
+ var Reduction_1 = require("./types/common/Reduction");
31
+ Object.defineProperty(exports, "ReductionType", { enumerable: true, get: function () { return Reduction_1.ReductionType; } });
26
32
  var ErrorResponse_1 = require("./types/ErrorResponse");
27
33
  Object.defineProperty(exports, "objectIsMTSErrorResponse", { enumerable: true, get: function () { return ErrorResponse_1.objectIsMTSErrorResponse; } });
28
34
  //#endregion
@@ -9,7 +9,7 @@ export declare const useMtsBookingLocalState: import("zustand").UseBoundStore<Om
9
9
  persist: {
10
10
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>) => void;
11
11
  clearStorage: () => void;
12
- rehydrate: () => void | Promise<void>;
12
+ rehydrate: () => Promise<void> | void;
13
13
  hasHydrated: () => boolean;
14
14
  onHydrate: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
15
15
  onFinishHydration: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
@@ -23,7 +23,7 @@ export declare const useMtsBookingState: () => import("zustand").UseBoundStore<O
23
23
  persist: {
24
24
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>) => void;
25
25
  clearStorage: () => void;
26
- rehydrate: () => void | Promise<void>;
26
+ rehydrate: () => Promise<void> | void;
27
27
  hasHydrated: () => boolean;
28
28
  onHydrate: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
29
29
  onFinishHydration: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
@@ -34,7 +34,7 @@ export declare const useTestState: () => import("zustand").UseBoundStore<Omit<im
34
34
  persist: {
35
35
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>) => void;
36
36
  clearStorage: () => void;
37
- rehydrate: () => void | Promise<void>;
37
+ rehydrate: () => Promise<void> | void;
38
38
  hasHydrated: () => boolean;
39
39
  onHydrate: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
40
40
  onFinishHydration: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
@@ -1,67 +1,102 @@
1
1
  import { Booking } from "../../booking/booking";
2
2
  import { Reduction } from "./Reduction";
3
3
  import { Extra } from "./Extra";
4
+ export declare enum SellingMethod {
5
+ LINKAVEL = "LINKAVEL",
6
+ BACKOFFICE = "BACKOFFICE",
7
+ RESELLER = "RESELLER",
8
+ MTSAPP = "MTSAPP"
9
+ }
4
10
  /**
5
11
  * @description Cart is the object returned by the API when a cart is created.
6
12
  * Note that depending on the type of booking, this type will be extended with different fields:
7
13
  * - TourCart: {@link ServiceCart}
8
14
  * - JourneyCart: {@link JourneyCart}
9
15
  * - SubscriptionCart: {@link SubscriptionCart}
10
- * @property {number} id The id of the cart
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.
14
- * @property {number} sellerId The id of the seller of the tickets in the cart
15
- * @property {string} sellerPrivacyUrl The url redirecting to the privacy policy of the seller
16
- * @property {string} sellerTermsUrl The url redirecting to the terms and conditions of the seller
17
- * @property {Map<string, boolean[]>} stepsToStatus This data structure describes the steps of the booking process.
18
- * The keys of this dictionary represent the booking steps. See ... for the list of possible steps. If the
19
- * key is present, then the booking step shall be displayed. The value is a list of 3 booleans:
20
- * - The first tells whether it is possible to go to that section. If not, other sections must be completed first.
21
- * - The second tells whether the section is completed.
22
- * - The third tells whether the section is required.
23
- * @property {Booking.Currencies} currency The currency of the cart. See {@link Booking.Currencies}
24
- * @property {number} bookingDueDateRemainingSeconds The number of seconds remaining before the cart expires. This should be equivalent `bookingDueDate`
25
- * @property {string} bookingDueDate The date and time when the cart expires
26
- * @property {Reduction[]} reductions The list of reductions applied to the cart
27
- * @property {Extra[]} extras The list of extras services of the cart
28
- * @property {string} sellingMethod The selling method of the cart (LinkAvel, Backoffice)
29
- * @property {number} totalValue The total value of the cart, meaning the sum of the nominal prices of all tickets. It is expressed in the currency of the cart.
30
- * @property {number} totalResellerFee The total reseller fee of the cart, meaning the sum of the reseller fees of all tickets. It is expressed in the currency of the cart.
31
- * @property {number} totalCreditFromChange The total credit from change of the cart. This is non zero only during the change process, and represents
32
- * the credit that the user has from the previous cart. It is expressed in the currency of the cart.
33
- * @property {number} totalAmountToPay The total amount to pay of the cart, meaning the amount that the user has to pay to complete the booking. This is
34
- * what is displayed in the payment page. It is expressed in the currency of the cart.
35
16
  */
36
17
  export type Cart = {
18
+ /** The id of the cart */
37
19
  id: number;
20
+ /** The id of the seller of the tickets in the cart */
38
21
  sellerId: number;
22
+ /** The url redirecting to the privacy policy of the seller */
39
23
  sellerPrivacyUrl: string;
24
+ /** The url redirecting to the terms and conditions of the seller */
40
25
  sellerTermsUrl: string;
26
+ /** The code of the cart */
41
27
  cartCode: string;
28
+ /**
29
+ * A boolean telling whether the cart has issued tickets.
30
+ * Note that if this is the case, the cart will be null because it is not
31
+ * possible to add tickets to an issued cart. Thus, all data should be reset.
32
+ */
42
33
  hasIssuedTickets: boolean;
43
- stepsToStatus: Map<string, boolean[]>;
34
+ /**
35
+ * This data structure describes the steps of the booking process.
36
+ * The keys of this dictionary represent the booking steps. See {@link Booking.BookingSteps}
37
+ * for the list of possible steps.
38
+ * If the key is present, then the booking step shall be displayed. The value
39
+ * is a list of 3 booleans:
40
+ * - The first tells whether it is possible to go to that section. If not, other
41
+ * sections must be completed first.
42
+ * - The second tells whether the section is completed.
43
+ * - The third tells whether the section is required.
44
+ */
45
+ stepsToStatus: Record<Booking.BookingSteps, [boolean, boolean, boolean]>;
46
+ /** The currency of the cart. See {@link Booking.Currencies} */
44
47
  currency: Booking.Currencies;
48
+ /** The date and time when the cart expires */
45
49
  bookingDueDate: string;
50
+ /**
51
+ * The number of seconds remaining before the cart expires. This should be equivalent
52
+ * `bookingDueDate`
53
+ */
46
54
  bookingDueDateRemainingSeconds: number;
55
+ /** The list of reductions applied to the cart */
47
56
  reductions: Reduction[];
57
+ /** The list of extras services of the cart */
48
58
  extras: Extra[];
49
- sellingMethod: string;
59
+ /** The selling method of the cart (LinkAvel, Backoffice) */
60
+ sellingMethod: SellingMethod;
61
+ /**
62
+ * The total value of the cart, meaning the sum of the nominal prices of all tickets.
63
+ * It is expressed in the currency of the cart.
64
+ */
50
65
  totalValue: number;
66
+ /**
67
+ * The total reseller fee of the cart, meaning the sum of the reseller fees of
68
+ * all tickets. It is expressed in the currency of the cart.
69
+ */
51
70
  totalResellerFee?: number;
71
+ /**
72
+ * The total credit from change of the cart. This is non zero only during the
73
+ * change process, and represents the credit that the user has from the previous
74
+ * cart. It is expressed in the currency of the cart.
75
+ */
52
76
  totalCreditFromChange: number;
77
+ /**
78
+ * The total amount to pay of the cart, meaning the amount that the user has to
79
+ * pay to complete the booking. This is what is displayed in the payment page.
80
+ * It is expressed in the currency of the cart.
81
+ */
53
82
  totalAmountToPay: number;
54
83
  };
84
+ /** The type that {@link Cart.stepsToStatus} assumes once parsed to a map */
85
+ export type processedStepsToStatus = Map<Booking.BookingSteps, [boolean, boolean, boolean]>;
55
86
  /**
56
87
  * Base response type for the booking process. All APIs that update the cart, share this.
57
- *
58
- * @property {Map<string, boolean[]>} stepsToStatus This data structure describes the steps of the booking process.
59
- * The keys of this dictionary represent the booking steps. See ... for the list of possible steps. If the
60
- * key is present, then the booking step shall be displayed. The value is a list of 3 booleans:
61
- * - The first tells whether it is possible to go to that section. If not, other sections must be completed first.
62
- * - The second tells whether the section is completed.
63
- * - The third tells whether the section is required.
64
88
  */
65
89
  export type BaseBookingProcessResponse = {
66
- stepsToStatus: Map<string, boolean[]>;
90
+ /**
91
+ * This data structure describes the steps of the booking process.
92
+ * The keys of this dictionary represent the booking steps. See {@link Booking.BookingSteps}
93
+ * for the list of possible steps.
94
+ * If the key is present, then the booking step shall be displayed. The value
95
+ * is a list of 3 booleans:
96
+ * - The first tells whether it is possible to go to that section. If not, other
97
+ * sections must be completed first.
98
+ * - The second tells whether the section is completed.
99
+ * - The third tells whether the section is required.
100
+ */
101
+ stepsToStatus: Record<Booking.BookingSteps, [boolean, boolean, boolean]>;
67
102
  };
@@ -1,2 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SellingMethod = void 0;
4
+ var SellingMethod;
5
+ (function (SellingMethod) {
6
+ SellingMethod["LINKAVEL"] = "LINKAVEL";
7
+ SellingMethod["BACKOFFICE"] = "BACKOFFICE";
8
+ SellingMethod["RESELLER"] = "RESELLER";
9
+ SellingMethod["MTSAPP"] = "MTSAPP";
10
+ })(SellingMethod || (exports.SellingMethod = SellingMethod = {}));
@@ -1,7 +1,8 @@
1
+ import { Cart, processedStepsToStatus } from "../types/common/Cart";
1
2
  /**
2
3
  * This function process the stepsToStatus object returned by the BE in several APIs and returns the processed Map.
3
4
  * This is necessary because Typescript does not treat the jsonized map as an actual Map making it impossible to use.
4
5
  * @param stepsToStatus the stepsToStatus object returned by the BE
5
6
  * @returns The processed Map
6
7
  */
7
- export declare const processBookingSteps: (stepsToStatus: any) => Map<string, boolean[]>;
8
+ export declare const processBookingSteps: (stepsToStatus: Cart["stepsToStatus"]) => processedStepsToStatus;
@@ -9,13 +9,7 @@ exports.processBookingSteps = void 0;
9
9
  */
10
10
  var processBookingSteps = function (stepsToStatus) {
11
11
  try {
12
- return new Map(Object.entries(stepsToStatus).map(function (_a) {
13
- var bookingStep = _a[0], values = _a[1];
14
- return [
15
- bookingStep,
16
- values
17
- ];
18
- }));
12
+ return new Map(Object.entries(stepsToStatus));
19
13
  }
20
14
  catch (error) {
21
15
  throw new Error("Error while processing booking steps");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  "devDependencies": {
19
19
  "@types/jest": "^29.5.12",
20
20
  "jest": "^29.7.0",
21
- "prettier": "^3.3.0",
22
- "ts-jest": "^29.1.4",
23
- "typescript": "^5.4.5"
21
+ "prettier": "^3.3.2",
22
+ "ts-jest": "^29.1.5",
23
+ "typescript": "^5.5.2"
24
24
  },
25
25
  "files": [
26
26
  "lib/**/*"