mts-booking-library 1.2.35 → 1.3.1

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.js CHANGED
@@ -10,7 +10,7 @@ var MTSEnvs;
10
10
  })(MTSEnvs || (exports.MTSEnvs = MTSEnvs = {}));
11
11
  var config = {
12
12
  ENV: MTSEnvs.PROD,
13
- API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api",
13
+ API_ENDPOINT: "https://prod-myticketsolutionapim.azure-api.net/api",
14
14
  OCP_SUBSCRIPTION_KEY: "",
15
15
  ACCESS_TOKEN: undefined,
16
16
  DEBUG: false
@@ -21,13 +21,13 @@ var setConfig = function (env, sub_key, debug, access_token) {
21
21
  switch (config.ENV) {
22
22
  case MTSEnvs.TEST:
23
23
  case MTSEnvs.DEV:
24
- config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/dev";
24
+ config.API_ENDPOINT = "https://dev-myticketsolutionapim.azure-api.net/api";
25
25
  break;
26
26
  case MTSEnvs.STAGING:
27
- config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/stag";
27
+ config.API_ENDPOINT = "https://stag-myticketsolutionapim.azure-api.net/api";
28
28
  break;
29
29
  case MTSEnvs.PROD:
30
- config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api";
30
+ config.API_ENDPOINT = "https://prod-myticketsolutionapim.azure-api.net/api";
31
31
  break;
32
32
  default:
33
33
  throw new Error("Invalid environment");
package/lib/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { Booking } from "./booking/booking";
2
2
  export { JourneyBooking } from "./booking/journeyBooking";
3
3
  export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
+ export { TplBooking } from "./booking/tplBooking";
5
6
  export { Person, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
6
7
  export { GetBuyerPassengersDetailsResponse, GetPassenger, BuyerDataStatus } from "./types/common/Person";
7
8
  export { EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
@@ -19,6 +20,9 @@ export { Line } from "./types/services/Line";
19
20
  export { Service, ServiceTrip } from "./types/services/Service";
20
21
  export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
21
22
  export { ServiceInfo } from "./types/services/ServiceInfo";
23
+ export { GetTariffsResponse } from "./types/tpl/GetTariffsResponse";
24
+ export { SuperArea } from "./types/tpl/SuperArea";
25
+ export { TplCart, TplBookingType, TplBookingInfo } from "./types/tpl/TplCart";
22
26
  export { Subscription } from "./types/subscriptions/Subscriptions";
23
27
  export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
24
28
  export { SubscriptionCart, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
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.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.PaymentMethods = exports.GatewayTypes = exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = 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; } });
@@ -10,6 +10,8 @@ var serviceBooking_1 = require("./booking/serviceBooking");
10
10
  Object.defineProperty(exports, "ServiceBooking", { enumerable: true, get: function () { return serviceBooking_1.ServiceBooking; } });
11
11
  var subscriptionBooking_1 = require("./booking/subscriptionBooking");
12
12
  Object.defineProperty(exports, "SubscriptionBooking", { enumerable: true, get: function () { return subscriptionBooking_1.SubscriptionBooking; } });
13
+ var tplBooking_1 = require("./booking/tplBooking");
14
+ Object.defineProperty(exports, "TplBooking", { enumerable: true, get: function () { return tplBooking_1.TplBooking; } });
13
15
  //#endregion
14
16
  //#region Export common types
15
17
  // @note: Cart is not exported because it is extended by other types
@@ -0,0 +1,44 @@
1
+ type MtsBookingState = {
2
+ cartId: number | undefined;
3
+ };
4
+ type MtsBookingAction = {
5
+ updateCartId: (cartId: MtsBookingState["cartId"]) => void;
6
+ resetState: () => void;
7
+ };
8
+ export declare const useMtsBookingLocalState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<MtsBookingState & MtsBookingAction>, "persist"> & {
9
+ persist: {
10
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>) => void;
11
+ clearStorage: () => void;
12
+ rehydrate: () => void | Promise<void>;
13
+ hasHydrated: () => boolean;
14
+ onHydrate: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
15
+ onFinishHydration: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
16
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>;
17
+ };
18
+ }>;
19
+ /**
20
+ * This hook will return the correct Zustand state based on the application which runs the library
21
+ */
22
+ export declare const useMtsBookingState: () => import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<MtsBookingState & MtsBookingAction>, "persist"> & {
23
+ persist: {
24
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>) => void;
25
+ clearStorage: () => void;
26
+ rehydrate: () => void | Promise<void>;
27
+ hasHydrated: () => boolean;
28
+ onHydrate: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
29
+ onFinishHydration: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
30
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>;
31
+ };
32
+ }>;
33
+ export declare const useTestState: () => import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<MtsBookingState & MtsBookingAction>, "persist"> & {
34
+ persist: {
35
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>) => void;
36
+ clearStorage: () => void;
37
+ rehydrate: () => void | Promise<void>;
38
+ hasHydrated: () => boolean;
39
+ onHydrate: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
40
+ onFinishHydration: (fn: (state: MtsBookingState & MtsBookingAction) => void) => () => void;
41
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<MtsBookingState & MtsBookingAction, MtsBookingState & MtsBookingAction>>;
42
+ };
43
+ }>;
44
+ export {};
@@ -0,0 +1,48 @@
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
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.useTestState = exports.useMtsBookingState = exports.useMtsBookingLocalState = void 0;
15
+ var async_storage_1 = require("@react-native-async-storage/async-storage");
16
+ var zustand_1 = require("zustand");
17
+ var middleware_1 = require("zustand/middleware");
18
+ var INITIAL_STATE = {
19
+ cartId: 0,
20
+ };
21
+ var useMtsBookingAsyncState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId) { return set(function () { return ({ cartId: cartId }); }); }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
22
+ name: "mts-booking-storage",
23
+ storage: (0, middleware_1.createJSONStorage)(function () { return async_storage_1.default; })
24
+ }));
25
+ exports.useMtsBookingLocalState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId) { return set(function () { return ({ cartId: cartId }); }); }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
26
+ name: "mts-booking-storage",
27
+ storage: (0, middleware_1.createJSONStorage)(function () { return localStorage; })
28
+ }));
29
+ /**
30
+ * This hook will return the correct Zustand state based on the application which runs the library
31
+ */
32
+ var useMtsBookingState = function () {
33
+ if (typeof document !== 'undefined') {
34
+ // Web application
35
+ return exports.useMtsBookingLocalState;
36
+ }
37
+ // react-native application
38
+ return useMtsBookingAsyncState;
39
+ };
40
+ exports.useMtsBookingState = useMtsBookingState;
41
+ var useTestState = function () {
42
+ if (typeof localStorage === "undefined" || localStorage === null) {
43
+ var LocalStorage = require("node-localstorage").LocalStorage;
44
+ global.localStorage = new LocalStorage("./scratch");
45
+ }
46
+ return exports.useMtsBookingLocalState;
47
+ };
48
+ exports.useTestState = useTestState;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * This type represents a city
3
+ * @param {number} id The id of the city in the database
4
+ * @param {string} name The name of the city
5
+ * @param {string} stateName The name of the state where the city is located (e.g. "Italy")
6
+ * @param {string} regionName The name of the region where the city is located (e.g. "Lombardia")
7
+ * @param {string} provinceName The name of the province where the city is located (e.g. "Milano")
8
+ * @param {string} shortProvinceName The short name of the province where the city is located (e.g. "MI")
9
+ */
10
+ export type City = {
11
+ id: number;
12
+ name: string;
13
+ stateName: string;
14
+ regionName: string;
15
+ provinceName: string;
16
+ shortProvinceName: string;
17
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,13 @@
1
1
  /**
2
- * This represents a tariff, a part of a {@link TariffsMatrix} (returned when searching Journeys or Services).
2
+ * This represents a tariff, which defined the price to pay for a certain ticket.
3
+ * @param {number} id - The id of the tariff.
3
4
  * @param {number} tariffTypeId - The id of the tariff type.
4
5
  * @param {number} termsTypeId - The id of the terms type.
5
6
  * @param {number} value - The value of the tariff (in the currency specified in the {@link Booking} object).
6
7
  * @param {number} quantity - The number of passengers to which this tariff applies.
7
8
  */
8
9
  export type Tariff = {
10
+ id: number;
9
11
  tariffTypeId: number;
10
12
  termsTypeId: number;
11
13
  value: number;
@@ -17,7 +19,8 @@ export type Tariff = {
17
19
  */
18
20
  export type TariffsMatrix = Tariff[][];
19
21
  /**
20
- * This represents a tariff type, returned when searching Journeys or Services. This shall be used the build the header of the tariff matrix.
22
+ * This represents a tariff type (e.g. "Adult", "Child", "Over65", ...).
23
+ * @param {number} id - The id of the tariff type in the db.
21
24
  * @param {string} name - The name of the tariff type.
22
25
  * @param {string} description - The description of the tariff type.
23
26
  * @param {boolean} requiredPassengersName - Whether the passengers' names are required for this tariff type.
@@ -26,6 +29,7 @@ export type TariffsMatrix = Tariff[][];
26
29
  * including info on the rules that apply to it.
27
30
  */
28
31
  export type TariffType = {
32
+ id: number;
29
33
  name: string;
30
34
  description: string;
31
35
  requiredPassengersName: boolean;
@@ -33,7 +37,8 @@ export type TariffType = {
33
37
  bookingProcessDescription: string;
34
38
  };
35
39
  /**
36
- * This represents a terms type, returned when searching Journeys or Services. This shall be used the build the header of the rows of the tariff matrix.
40
+ * This represents a terms type (e.g. "Standard", "Business", ...).
41
+ * @param {number} id - The id of the terms type in the db.
37
42
  * @param {string} name - The name of the terms type.
38
43
  * @param {string} description - The description of the terms type.
39
44
  * @param {boolean} isRefundAllowed - Whether tickets refunds are allowed for this terms type.
@@ -43,6 +48,7 @@ export type TariffType = {
43
48
  * including info on the rules that apply to it.
44
49
  */
45
50
  export type TermsType = {
51
+ id: number;
46
52
  name: string;
47
53
  description: string;
48
54
  isRefundAllowed: boolean;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @description Represents information about a journey.
3
3
  *
4
- * @property {string} sellerName - The name of the seller offering the journey.
4
+ * @property {string} sellerName - The name of the seller operating the journey.
5
+ * @property {string} sellerId - The id of the seller operating the journey.
5
6
  * @property {string} minimumTotalPrice - The minimum total price for booking the journey, meaning the price if all passenger choose the cheapest tariff.
6
7
  * @property {number} remainingSeats - The number of remaining seats for the journey.
7
8
  * @property {number} totalNumberOfSeats - The total number of seats for the journey (including booked seats).
@@ -10,6 +11,7 @@
10
11
  */
11
12
  export type JourneyInfo = {
12
13
  sellerName: string;
14
+ sellerId: string;
13
15
  minimumTotalPrice: string;
14
16
  remainingSeats: number;
15
17
  totalNumberOfSeats: number;
@@ -0,0 +1,12 @@
1
+ import { Tariff } from "../common/Tariffs";
2
+ /**
3
+ * This represents the response of the API {@link TplBooking.getTariffs}.
4
+ * @param {Tariff[]} tariffs - The list of available tariffs. This is meant to be a fast access for displaying the data.
5
+ * In particular, this array is equivalent to `tariffPlanToTariffs[0]`
6
+ * @param {Map<number, Tariff[]>} tariffPlanToTariffs - A map that associates a tariff plan to the list of tariffs available for that tariff plan.
7
+ * The key is the tariff plan id, while the value is the list of available tariffs.
8
+ */
9
+ export type GetTariffsResponse = {
10
+ tariffs: Tariff[];
11
+ tariffPlanToTariffs: Map<number, Tariff[]>;
12
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This type represents a super area. It is the return object of the {@link TplBooking.getSuperAreas} method.
3
+ * @param {number} id The id of the super area in the database
4
+ * @param {string} name The name of the super area
5
+ * @param {string} shortName The short name of the super area
6
+ * @param {string} description The description of the super area
7
+ */
8
+ export type SuperArea = {
9
+ id: number;
10
+ name: string;
11
+ shortName: string;
12
+ description: string;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,41 @@
1
+ import { Booking } from "../../booking/booking";
2
+ import { Cart } from "../common/Cart";
3
+ import { TariffSummary } from "../common/Tariffs";
4
+ /**
5
+ * @description Represents a `TplCart`, which extends the {@link Cart} type by including additional
6
+ * information about the bookings
7
+ *
8
+ * @property {JourneyBookingType[]} bookings - An array of {@link TplBookingType} objects representing the bookings associated
9
+ * with this tpl cart.
10
+ */
11
+ export type TplCart = Cart & {
12
+ bookings: TplBookingType[];
13
+ };
14
+ /**
15
+ * @description Represents a `Tpl`, which contains information about a tpl booking.
16
+ *
17
+ * @property {Booking.BookingTypes} type - The type of booking. For journeys, this is always `Booking.BookingTypes.TPL`.
18
+ * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
19
+ * associated with this tpl booking.
20
+ * @property {TplBookingInfo} info - An {@link TplBookingInfo} object containing general information about the booking.
21
+ */
22
+ export type TplBookingType = {
23
+ type: Booking.BookingTypes;
24
+ info: TplBookingInfo;
25
+ summary: TariffSummary[];
26
+ };
27
+ /**
28
+ * @description Represents a `TplBookingInfo`, which contains general information about a tpl booking.
29
+ * @property {boolean} isSubscription - Whether the booking is a subscription or a single ticket.
30
+ * @property {number} superAreaId - The id of the super area.
31
+ * @property {number} validity - The validity of the ticket (or of the subscription).
32
+ * @property {string} startDate - The start date of the ticket (or of the subscription).
33
+ * @property {string} endDate - The end date of the ticket (or of the subscription).
34
+ */
35
+ export type TplBookingInfo = {
36
+ isSubscription: boolean;
37
+ superAreaId: number;
38
+ validity: number;
39
+ startDate: string;
40
+ endDate: string;
41
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -145,8 +145,8 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
145
145
  error_2 = _h.sent();
146
146
  if (axios_1.default.isAxiosError(error_2)) {
147
147
  resError = {
148
- httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
149
- mtsCode: ((_d = (_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 500,
148
+ httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
149
+ mtsCode: ((_d = (_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
150
150
  message: ((_g = (_f = (_e = error_2.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error",
151
151
  };
152
152
  if (debug) {
@@ -195,8 +195,8 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
195
195
  error_3 = _h.sent();
196
196
  if (axios_1.default.isAxiosError(error_3)) {
197
197
  resError = {
198
- httpStatus: ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
199
- mtsCode: ((_d = (_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 500,
198
+ httpStatus: ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
199
+ mtsCode: ((_d = (_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
200
200
  message: ((_g = (_f = (_e = error_3.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error",
201
201
  };
202
202
  if (debug) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.35",
4
- "description": "Library for use MyTicketSolution Booking API",
3
+ "version": "1.3.1",
4
+ "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "@types/jest": "^29.5.12",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.2",
20
- "typescript": "^5.3.3"
20
+ "typescript": "^5.4.2"
21
21
  },
22
22
  "files": [
23
23
  "lib/**/*"
@@ -26,9 +26,11 @@
26
26
  "myticketsolution",
27
27
  "booking"
28
28
  ],
29
- "author": "M",
29
+ "author": "Infoservice s.r.l.",
30
30
  "dependencies": {
31
- "axios": "^1.6.7",
32
- "node-localstorage": "^3.0.5"
31
+ "@react-native-async-storage/async-storage": "^1.23.1",
32
+ "axios": "^1.6.8",
33
+ "node-localstorage": "^3.0.5",
34
+ "zustand": "^4.5.2"
33
35
  }
34
36
  }