mts-booking-library 1.3.10 → 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 = {}));
@@ -2,14 +2,14 @@
2
2
  * @description Represents information about a service.
3
3
  *
4
4
  * @property {string} sellerName - The name of the seller offering the service.
5
- * @property {string} sellerId - The id of the seller offering the service.
5
+ * @property {number} sellerId - The id of the seller offering the service.
6
6
  * @property {string} minimumTotalPrice - The minimum total price for booking the service, meaning the price if all passenger choose the cheapest tariff.
7
7
  * @property {string} bookingProcessMessage - Optional message to be displayed to the user when booking this service.
8
8
  * @property {boolean} isBookable - Indicates whether the service is bookable (true) or not (false).
9
9
  */
10
10
  export type ServiceInfo = {
11
11
  sellerName: string;
12
- sellerId: string;
12
+ sellerId: number;
13
13
  minimumTotalPrice: string;
14
14
  bookingProcessMessage: string;
15
15
  isBookable: boolean;
@@ -57,6 +57,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
57
57
  exports.makeDelete = exports.makePost = exports.makeGet = void 0;
58
58
  var axios_1 = require("axios");
59
59
  var config_1 = require("../config");
60
+ var utils_1 = require("./utils");
60
61
  var removeNullError = function (resData) {
61
62
  var filteredResponse = {};
62
63
  Object.keys(resData)
@@ -68,12 +69,17 @@ var removeNullError = function (resData) {
68
69
  return filteredResponse;
69
70
  };
70
71
  var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
71
- var debug;
72
+ var debug, subKey, errorReport;
72
73
  return __generator(this, function (_a) {
73
74
  debug = (0, config_1.getConfig)().DEBUG;
74
75
  if (debug) {
75
76
  console.log("GET_RequestData", url);
76
77
  }
78
+ subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
79
+ if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
80
+ errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
81
+ throw new Error("MTS Library Error! makeGet: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
82
+ }
77
83
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
78
84
  var response, filteredResponse, error_1, resError, resError;
79
85
  var _a, _b, _c, _d, _e, _f, _g;
@@ -82,7 +88,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
82
88
  case 0:
83
89
  _h.trys.push([0, 2, , 3]);
84
90
  return [4 /*yield*/, axios_1.default.get(url, {
85
- 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) }))
91
+ headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
86
92
  })];
87
93
  case 1:
88
94
  response = _h.sent();
@@ -118,12 +124,17 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
118
124
  }); };
119
125
  exports.makeGet = makeGet;
120
126
  var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
121
- var debug;
127
+ var debug, subKey, errorReport;
122
128
  return __generator(this, function (_a) {
123
129
  debug = (0, config_1.getConfig)().DEBUG;
124
130
  if (debug) {
125
131
  console.log("POST_RequestData", url, data);
126
132
  }
133
+ subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
134
+ if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
135
+ errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
136
+ throw new Error("MTS Library Error! makePost: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
137
+ }
127
138
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
128
139
  var response, filteredResponse, error_2, resError;
129
140
  var _a, _b, _c, _d, _e, _f, _g;
@@ -132,7 +143,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
132
143
  case 0:
133
144
  _h.trys.push([0, 2, , 3]);
134
145
  return [4 /*yield*/, axios_1.default.post(url, data, {
135
- 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) }))
146
+ headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
136
147
  })];
137
148
  case 1:
138
149
  response = _h.sent();
@@ -168,12 +179,17 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
168
179
  }); };
169
180
  exports.makePost = makePost;
170
181
  var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, function () {
171
- var debug;
182
+ var debug, subKey, errorReport;
172
183
  return __generator(this, function (_a) {
173
184
  debug = (0, config_1.getConfig)().DEBUG;
174
185
  if (debug) {
175
186
  console.log("DELETE_RequestData", url);
176
187
  }
188
+ subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
189
+ if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
190
+ errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
191
+ throw new Error("MTS Library Error! makeDelete: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
192
+ }
177
193
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
178
194
  var response, filteredResponse, error_3, resError;
179
195
  var _a, _b, _c, _d, _e, _f, _g;
@@ -182,7 +198,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
182
198
  case 0:
183
199
  _h.trys.push([0, 2, , 3]);
184
200
  return [4 /*yield*/, axios_1.default.delete(url, {
185
- 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) }))
201
+ headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) }))
186
202
  })];
187
203
  case 1:
188
204
  response = _h.sent();
@@ -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");
@@ -12,3 +12,10 @@ export declare const getISOStringWithoutGMT: (date: Date | string | null | undef
12
12
  * @returns True if the value is null or undefined, false otherwise
13
13
  */
14
14
  export declare const isNullOrUndefined: (value: any) => boolean;
15
+ /**
16
+ * This method check whether the input string is null, undefined, or made only by white spaces.
17
+ * It is the equivalent of C# method string.IsNullOrWhiteSpace used in the backend.
18
+ * @param {string | null | undefined} input the string to be tested
19
+ * @returns {boolean} true if the string is null, undefined, or made only by white spaces, false otherwise
20
+ */
21
+ export declare const isNullOrWhiteSpace: (input: string | null | undefined) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNullOrUndefined = exports.getISOStringWithoutGMT = void 0;
3
+ exports.isNullOrWhiteSpace = exports.isNullOrUndefined = exports.getISOStringWithoutGMT = void 0;
4
4
  /**
5
5
  * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
6
6
  * @param {Date | string} date the date to convert
@@ -24,3 +24,13 @@ exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
24
24
  */
25
25
  var isNullOrUndefined = function (value) { return value === null || value === undefined; };
26
26
  exports.isNullOrUndefined = isNullOrUndefined;
27
+ /**
28
+ * This method check whether the input string is null, undefined, or made only by white spaces.
29
+ * It is the equivalent of C# method string.IsNullOrWhiteSpace used in the backend.
30
+ * @param {string | null | undefined} input the string to be tested
31
+ * @returns {boolean} true if the string is null, undefined, or made only by white spaces, false otherwise
32
+ */
33
+ var isNullOrWhiteSpace = function (input) {
34
+ return input === null || input === undefined || input.trim() === "";
35
+ };
36
+ exports.isNullOrWhiteSpace = isNullOrWhiteSpace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.3.10",
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.2.5",
22
- "ts-jest": "^29.1.2",
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/**/*"
@@ -32,7 +32,7 @@
32
32
  "author": "Infoservice s.r.l.",
33
33
  "dependencies": {
34
34
  "@react-native-async-storage/async-storage": "^1.23.1",
35
- "axios": "^1.6.8",
35
+ "axios": "^1.7.2",
36
36
  "dotenv": "^16.4.5",
37
37
  "node-localstorage": "^3.0.5",
38
38
  "zustand": "^4.5.2"