mts-booking-library 2.4.12 → 3.0.0

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.
Files changed (36) hide show
  1. package/lib/booking/booking.d.ts +1 -1
  2. package/lib/booking/journeyBooking.d.ts +46 -6
  3. package/lib/booking/journeyBooking.js +33 -75
  4. package/lib/booking/serviceBooking.d.ts +47 -7
  5. package/lib/booking/serviceBooking.js +33 -73
  6. package/lib/booking/subscriptionBooking.d.ts +45 -3
  7. package/lib/booking/subscriptionBooking.js +30 -38
  8. package/lib/booking/tplBooking.d.ts +46 -6
  9. package/lib/booking/tplBooking.js +27 -78
  10. package/lib/index.d.ts +5 -4
  11. package/lib/index.js +8 -5
  12. package/lib/mtsStorage.d.ts +10 -6
  13. package/lib/types/common/Cart.d.ts +14 -14
  14. package/lib/types/common/Person.d.ts +0 -11
  15. package/lib/types/common/Person.js +1 -11
  16. package/lib/types/common/Tariffs.d.ts +0 -2
  17. package/lib/types/journeys/JourneyCart.d.ts +0 -18
  18. package/lib/types/journeys/JourneyCart.js +0 -8
  19. package/lib/types/journeys/JourneyInfo.d.ts +7 -8
  20. package/lib/types/journeys/JourneySearch.d.ts +3 -3
  21. package/lib/types/journeys/JourneySearch.js +4 -5
  22. package/lib/types/journeys/Stop.d.ts +7 -8
  23. package/lib/types/journeys/Trip.d.ts +8 -1
  24. package/lib/types/services/Service.d.ts +5 -2
  25. package/lib/types/services/ServiceCart.d.ts +0 -23
  26. package/lib/types/subscriptions/SubscriptionAvailabilities.d.ts +20 -22
  27. package/lib/types/subscriptions/SubscriptionCart.d.ts +5 -6
  28. package/lib/types/subscriptions/Subscriptions.d.ts +10 -11
  29. package/lib/types/tpl/TplCart.d.ts +2 -21
  30. package/lib/utils/utils.d.ts +9 -6
  31. package/lib/utils/utils.js +46 -14
  32. package/package.json +15 -15
  33. package/lib/SubscriptionBooking.d.ts +0 -0
  34. package/lib/SubscriptionBooking.js +0 -148
  35. package/lib/utils/testUtils.d.ts +0 -8
  36. package/lib/utils/testUtils.js +0 -19
@@ -1,20 +1,19 @@
1
1
  /**
2
2
  * @description Represents information about a journey.
3
- *
4
- * @property {string} sellerName - The name of the seller operating the journey.
5
- * @property {string} sellerId - The id of the seller operating the journey.
6
- * @property {string} minimumTotalPrice - The minimum total price for booking the journey, meaning the price if all passenger choose the cheapest tariff.
7
- * @property {number} remainingSeats - The number of remaining seats for the journey.
8
- * @property {number} totalNumberOfSeats - The total number of seats for the journey (including booked seats).
9
- * @property {string} bookingProcessMessage - Optional message to be displayed to the user when booking this journey.
10
- * @property {boolean} isBookable - Indicates whether the journey is bookable (true) or not (false).
11
3
  */
12
4
  export type JourneyInfo = {
5
+ /** The name of the seller operating the journey. */
13
6
  sellerName: string;
7
+ /** The id of the seller operating the journey. */
14
8
  sellerId: string;
9
+ /** The minimum total price for booking the journey, meaning the price if all passengers choose the cheapest tariff. */
15
10
  minimumTotalPrice: string;
11
+ /** The number of remaining seats for the journey. */
16
12
  remainingSeats: number;
13
+ /** The total number of seats for the journey (including booked seats). */
17
14
  totalNumberOfSeats: number;
15
+ /** Optional message to be displayed to the user when booking this journey. */
18
16
  bookingProcessMessage: string;
17
+ /** Indicates whether the journey is bookable (true) or not (false). */
19
18
  isBookable: boolean;
20
19
  };
@@ -6,10 +6,10 @@ export type JourneySearchRequest = {
6
6
  departureStopName: string | undefined;
7
7
  destinationStopName: string | undefined;
8
8
  passengersNumber: number;
9
- date: string;
10
- roundTripDate?: string | null;
9
+ dateTimeLocalLong: number;
10
+ roundTripDateTimeLocalLong?: number | null;
11
11
  currency: Booking.Currencies;
12
- isRoundtrip: boolean;
12
+ isRoundTrip: boolean;
13
13
  outboundTripId?: number | null;
14
14
  };
15
15
  export declare const DEFAULT_JOURNEY_SEARCH: JourneySearchRequest;
@@ -2,13 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_JOURNEY_SEARCH = void 0;
4
4
  var booking_1 = require("../../booking/booking");
5
+ var utils_1 = require("../../utils/utils");
5
6
  exports.DEFAULT_JOURNEY_SEARCH = {
6
7
  departureStopName: "",
7
8
  destinationStopName: "",
8
9
  passengersNumber: 1,
9
- date: new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 1))
10
- .toISOString()
11
- .slice(0, -1),
12
- currency: booking_1.Booking.Currencies.EUR,
13
- isRoundtrip: false
10
+ dateTimeLocalLong: (0, utils_1.getLongFromDate)(new Date()),
11
+ isRoundTrip: false,
12
+ currency: booking_1.Booking.Currencies.EUR
14
13
  };
@@ -1,16 +1,15 @@
1
1
  /**
2
2
  * @description Represents a stop in a journey.
3
- *
4
- * @property {number} id - The unique identifier for the stop.
5
- * @property {Date} departureTime - The time when the journey departs from this stop.
6
- * @property {Date} destinationTime - The time when the journey arrives at this stop.
7
- * @property {string} name - The name of the stop.
8
- * @property {string} address - The address of the stop.
9
3
  */
10
4
  export type Stop = {
5
+ /** The unique identifier for the stop */
11
6
  id: number;
12
- departureTime: Date;
13
- destinationTime: Date;
7
+ /** The time when the journey departs from this stop in YYYYMMDDHHMMSSMMM format */
8
+ departureTimeLong: number;
9
+ /** The time when the journey arrives at this stop in YYYYMMDDHHMMSSMMM format */
10
+ destinationTimeLong: number;
11
+ /** The name of the stop */
14
12
  name: string;
13
+ /** The address of the stop */
15
14
  address: string;
16
15
  };
@@ -1,11 +1,18 @@
1
1
  import { TariffsMatrix, TariffType, TermsType } from "../common/Tariffs";
2
2
  export type Trip = {
3
+ /** The unique identifier for the trip */
3
4
  id: number;
4
- date: Date;
5
+ /** The date and departure time for the trip in YYYYMMDDHHMMSSMMM format. The time refers to the local time zone of the seller. */
6
+ departureTimeLocalLong: number;
7
+ /** The name of the departure stop */
5
8
  departureStopName: string;
9
+ /** The name of the destination stop */
6
10
  destinationStopName: string;
11
+ /** Tariff matrix for this trip */
7
12
  tariffsMatrix: TariffsMatrix;
13
+ /** List of the tariffTypes to be found in the tariffsMatrix */
8
14
  tariffTypes: TariffType[];
15
+ /** List of the termsTypes to be found in the tariffsMatrix */
9
16
  termsTypes: TermsType[];
10
17
  };
11
18
  /**
@@ -27,9 +27,12 @@ export type Service = {
27
27
  isTripMandatory: boolean;
28
28
  };
29
29
  export type ServiceTrip = {
30
- tripId?: number;
31
- date: Date;
30
+ /** The name of the service */
32
31
  name: string;
32
+ /** The date and time of the service, if set. */
33
+ dateTimeLong?: number;
34
+ /** The id of the trip, if set. */
35
+ tripId?: number;
33
36
  };
34
37
  /**
35
38
  * @description Represents a response from the service trips endpoint
@@ -2,29 +2,6 @@ import { Booking } from "../../booking/booking";
2
2
  import { Cart } from "../common/Cart";
3
3
  import { TariffSummary } from "../common/Tariffs";
4
4
  import { ServiceTrip } from "./Service";
5
- /**
6
- * This is the object to be passed to `ServiceBooking.createServiceCart`, containing
7
- * information about the selected service.
8
- */
9
- export type CreateServiceCartRequest = {
10
- /** The currency in which the service is priced. */
11
- currency: Booking.Currencies;
12
- /** Information about the selected service. */
13
- service: {
14
- /** The unique identifier for the service. */
15
- serviceId: number;
16
- /** A record containing tariff ids as keys and their respective quantities as values. */
17
- tariffIdToQuantity: Record<number, number>;
18
- /** The date for the service in ISO string format (optional). */
19
- date?: string;
20
- /** The unique identifier for the trip (optional). */
21
- tripId?: number;
22
- /** The id of the OTA Reseller that sold the ticket */
23
- otaResellerId?: number;
24
- /** A string in base64 representing the picture of the ticket that was sold */
25
- otaTicketPicture?: string;
26
- };
27
- };
28
5
  /**
29
6
  * @description Represents a `ServiceCart`, which extends the {@link Cart} type by including additional
30
7
  * information about the bookings
@@ -30,40 +30,38 @@ export type GetSubscriptionAvailabilityRequest = {
30
30
  * @description This is the object to be returned by to `SubscriptionBooking.getSubscrptionAvailabilities`,
31
31
  * containing general information about the selected subscription as well as the list of periods in which it is possible to
32
32
  * book the subscription.
33
- *
34
- * @property {string} departureStopName - The name of the departure stop.
35
- * @property {string} destinationStopName - The name of the destination stop.
36
- * @property {Date} outboundDepartureTime - The departure time of the outbound trip.
37
- * @property {Date} outboundDestinationTime - The destination time of the outbound trip.
38
- * @property {Date} returnDepartureTime - The departure time of the return trip.
39
- * @property {Date} returnDestinationTime - The destination time of the return trip.
40
- * @property {SubscriptionCalendarDayPeriodInfo[]} periods - The list of periods for which the availability of the subscription was checked.
41
33
  */
42
34
  export type GetSubscriptionAvailabilityResponse = {
35
+ /** The name of the departure stop. */
43
36
  departureStopName: string;
37
+ /** The name of the destination stop. */
44
38
  destinationStopName: string;
45
- outboundDepartureTime: Date;
46
- outboundDestinationTime: Date;
47
- returnDepartureTime: Date;
48
- returnDestinationTime: Date;
39
+ /** The departure time of the outbound trip in YYYYMMDDHHMMSSMMM format */
40
+ outboundDepartureTimeLong: number;
41
+ /** The destination time of the outbound trip in YYYYMMDDHHMMSSMMM format */
42
+ outboundDestinationTimeLong: number;
43
+ /** The departure time of the return trip in YYYYMMDDHHMMSSMMM format */
44
+ returnDepartureTimeLong: number;
45
+ /** The destination time of the return trip in YYYYMMDDHHMMSSMMM format */
46
+ returnDestinationTimeLong: number;
47
+ /** The list of periods for which the availability of the subscription was checked. */
49
48
  periods: SubscriptionCalendarDayPeriodInfo[];
50
49
  };
51
50
  /**
52
51
  * @description This is the object descibing the availability of a subscription for a given period.
53
- * Note that it is possible to book a subscription only is both {@link journeyAvailable} and {@link isAvailable} are true.
54
- *
55
- * @property {string} periodName - The name of the period (e.g. "July 2023")
56
- * @property {Date} dateFrom - The start date of the period.
57
- * @property {Date} dateTo - The end date of the period.
58
- * @property {number} price - The price of the subscription for the given period.
59
- * @property {boolean} journeyAvailable - Whether this subscription is available in this period.
60
- * @property {boolean} isAvailable - If this subscription is available (i.e. if {@link journeyAvailable} is true), this tells whether it can be booked
52
+ * Note that it is possible to book a subscription only is both journeyAvailable and isAvailable are true.
61
53
  */
62
54
  export type SubscriptionCalendarDayPeriodInfo = {
55
+ /** The name of the period (e.g. "July 2023") */
63
56
  periodName: string;
64
- dateFrom: Date;
65
- dateTo: Date;
57
+ /** The start date of the period in YYYYMMDDHHMMSSMMM format */
58
+ dateFromLong: number;
59
+ /** The end date of the period in YYYYMMDDHHMMSSMMM format */
60
+ dateToLong: number;
61
+ /** The price of the subscription for the given period */
66
62
  price: number;
63
+ /** Whether this subscription is available in this period */
67
64
  journeyAvailable: boolean;
65
+ /** If this subscription is available (i.e. if journeyAvailable is true), this tells whether it can be booked */
68
66
  isAvailable: boolean;
69
67
  };
@@ -31,14 +31,13 @@ export type CreateSubscriptionCartRequest = {
31
31
  periods: SubscriptionPeriod[];
32
32
  };
33
33
  /**
34
- * @description This is the object that describes which perios should be booked.
35
- *
36
- * @property {string} dateFrom - The start date of the period as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities}.
37
- * @property {string} dateTo - The end date of the period as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities}.
34
+ * @description This is the object that describes which periods should be booked.
38
35
  */
39
36
  export type SubscriptionPeriod = {
40
- dateFrom: string;
41
- dateTo: string;
37
+ /** The start date of the period in YYYYMMDDHHMMSSMMM format as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities} */
38
+ dateFromLong: number;
39
+ /** The end date of the period in YYYYMMDDHHMMSSMMM format as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities} */
40
+ dateToLong: number;
42
41
  };
43
42
  /**
44
43
  * @description Represents a `SubscriptionCart`, which extends the {@link Cart} type by including additional information about the bookings.
@@ -1,26 +1,25 @@
1
1
  /**
2
2
  * @description This is the object to be returned by to `SubscriptionBooking.getSubscrptions`, containing information about the selected subscription.
3
- *
4
- * @property {number} departurePhysicalAgencyStopId - The id of the departure stop.
5
- * @property {string} departureStopName - The name of the departure stop.
6
- * @property {number} destinationPhysicalAgencyStopId - The id of the destination stop.
7
- * @property {string} destinationStopName - The name of the destination stop.
8
- * @property {string} departureTime - The time of departure from the departureStop.
9
- * @property {string} destinationTime - The time of arrival to the destinationStop.
10
- * @property {string} lineName - The name of the line on which the subscription is sold.
11
- * @property {number} routeId - The id of the route on which the subscription is sold.
12
- * @property {string} routeName - The name of the route on which the subscription is sold.
13
- * @property {number} sellerId - The id of the seller selling the subscription.
14
3
  */
15
4
  export type Subscription = {
5
+ /** The id of the departure stop. */
16
6
  departurePhysicalAgencyStopId: number;
7
+ /** The name of the departure stop. */
17
8
  departureStopName: string;
9
+ /** The id of the destination stop. */
18
10
  destinationPhysicalAgencyStopId: number;
11
+ /** The name of the destination stop. */
19
12
  destinationStopName: string;
13
+ /** The time of departure from the departureStop in MM/DD/YYYY HH:MM:SS format. */
20
14
  departureTime: string;
15
+ /** The time of arrival to the destinationStop in MM/DD/YYYY HH:MM:SS format. */
21
16
  destinationTime: string;
17
+ /** The name of the line on which the subscription is sold. */
22
18
  lineName: string;
19
+ /** The id of the route on which the subscription is sold. */
23
20
  routeId: number;
21
+ /** The name of the route on which the subscription is sold. */
24
22
  routeName: string;
23
+ /** The id of the seller selling the subscription. */
25
24
  sellerId: number;
26
25
  };
@@ -1,25 +1,6 @@
1
1
  import { Booking } from "../../booking/booking";
2
2
  import { Cart } from "../common/Cart";
3
3
  import { TariffSummary } from "../common/Tariffs";
4
- /**
5
- * @description This is the object to be passed to {@link TplBooking.createTplCart}, containing information about the selected tpl service.
6
- */
7
- export type CreateTplCartRequest = {
8
- /** The currency in which the ticket is priced. */
9
- currency: Booking.Currencies;
10
- /** A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff. */
11
- tariffIdToQuantity: Map<number, number>;
12
- /** The start date of the ticket. This is optional and should be used only for subscriptions */
13
- startDate?: string;
14
- /** Whether the subscription is for the current period. This is optional and should be used only for subscriptions. */
15
- isCurrentPeriod?: boolean;
16
- /** The PNR of the subscription ticket to renew. This is optional and should be used only for subscriptions. */
17
- renewSubscriptionTicketPNR?: string;
18
- /** The id of the OTA Reseller that sold the ticket */
19
- otaResellerId?: number;
20
- /** A string in base64 representing the picture of the ticket that was sold */
21
- otaTicketPicture?: string;
22
- };
23
4
  /**
24
5
  * @description Represents a `TplCart`, which extends the {@link Cart} type by including additional
25
6
  * information about the bookings
@@ -55,8 +36,8 @@ export type TplBookingInfo = {
55
36
  superAreaId: number;
56
37
  /** The validity of the ticket (or of the subscription). */
57
38
  validity: string;
58
- /** The start date of the ticket (or of the subscription). */
39
+ /** The start date of the ticket (or of the subscription). Format: "DD/MM/YYYY HH:MM" */
59
40
  startDate: string;
60
- /** The end date of the ticket (or of the subscription). */
41
+ /** The end date of the ticket (or of the subscription). Format: "DD/MM/YYYY HH:MM" */
61
42
  endDate: string;
62
43
  };
@@ -1,11 +1,14 @@
1
1
  /**
2
- * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
3
- * @param {Date | string} date the date to convert
4
- * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
5
- * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
6
- * @returns {string} the ISO string
2
+ * @param date The date to convert
3
+ * @param onlyDate If true, the function will return a number in the format YYYYMMDD000000000 (all 0 for HH, MM, SS, and MMM).
4
+ * @returns A number in the format YYYYMMDDHHMMSSMMM
7
5
  */
8
- export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
6
+ export declare const getLongFromDate: (date: Date, onlyDate?: boolean) => number;
7
+ /**
8
+ * @param long A number in the format YYYYMMDDHHMMSSMMM (which represents a date)
9
+ * @returns The corresponding Date object
10
+ */
11
+ export declare const getDateFromLong: (long: number) => Date | null;
9
12
  /**
10
13
  * This method check where a variable is null or undefined
11
14
  * @param value The value to check
@@ -1,22 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNullOrWhiteSpace = exports.isNullOrUndefined = exports.getISOStringWithoutGMT = void 0;
3
+ exports.isNullOrWhiteSpace = exports.isNullOrUndefined = exports.getDateFromLong = exports.getLongFromDate = void 0;
4
4
  /**
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
- * @param {Date | string} date the date to convert
7
- * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
8
- * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
9
- * @returns {string} the ISO string
5
+ * @param date The date to convert
6
+ * @param onlyDate If true, the function will return a number in the format YYYYMMDD000000000 (all 0 for HH, MM, SS, and MMM).
7
+ * @returns A number in the format YYYYMMDDHHMMSSMMM
10
8
  */
11
- var getISOStringWithoutGMT = function (date, removeTimezone) {
12
- if (removeTimezone === void 0) { removeTimezone = true; }
13
- if (!date)
14
- return null;
15
- var newDate = new Date(date);
16
- var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
17
- return removeTimezone ? isoString.slice(0, -1) : isoString;
9
+ var getLongFromDate = function (date, onlyDate) {
10
+ if (onlyDate === void 0) { onlyDate = false; }
11
+ try {
12
+ if (onlyDate) {
13
+ return (date.getFullYear() * 10000000000000 +
14
+ (date.getMonth() + 1) * 100000000000 +
15
+ date.getDate() * 1000000000);
16
+ }
17
+ return (date.getFullYear() * 10000000000000 +
18
+ (date.getMonth() + 1) * 100000000000 +
19
+ date.getDate() * 1000000000 +
20
+ date.getHours() * 10000000 +
21
+ date.getMinutes() * 100000 +
22
+ date.getSeconds() * 1000 +
23
+ date.getMilliseconds());
24
+ }
25
+ catch (error) {
26
+ throw new Error("Error in MTSBookingLib. Function getLongFromDate. Date: ".concat(date, ". onlyDate: ").concat(onlyDate, ". Error: ").concat(error));
27
+ }
18
28
  };
19
- exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
29
+ exports.getLongFromDate = getLongFromDate;
30
+ /**
31
+ * @param long A number in the format YYYYMMDDHHMMSSMMM (which represents a date)
32
+ * @returns The corresponding Date object
33
+ */
34
+ var getDateFromLong = function (long) {
35
+ try {
36
+ if (long === 0)
37
+ return null;
38
+ var year = Math.floor(long / 10000000000000);
39
+ var month = Math.floor((long % 10000000000000) / 100000000000);
40
+ var day = Math.floor((long % 100000000000) / 1000000000);
41
+ var hour = Math.floor((long % 1000000000) / 10000000);
42
+ var minute = Math.floor((long % 10000000) / 100000);
43
+ var second = Math.floor((long % 100000) / 1000);
44
+ var millisecond = long % 1000;
45
+ return new Date(Date.UTC(year, month - 1, day, hour, minute, second, millisecond));
46
+ }
47
+ catch (error) {
48
+ throw new Error("Error in MTSBookingLib. Function getDateFromLong. DateLong: ".concat(long, ". Error: ").concat(error));
49
+ }
50
+ };
51
+ exports.getDateFromLong = getDateFromLong;
20
52
  /**
21
53
  * This method check where a variable is null or undefined
22
54
  * @param value The value to check
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "2.4.12",
3
+ "version": "3.0.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,19 +19,19 @@
19
19
  },
20
20
  "license": "ISC",
21
21
  "devDependencies": {
22
- "@eslint/js": "^9.27.0",
23
- "@types/jest": "^29.5.14",
22
+ "@eslint/js": "^9.33.0",
23
+ "@types/jest": "^30.0.0",
24
24
  "@types/node-localstorage": "^1.3.3",
25
- "dotenv": "^16.5.0",
26
- "eslint": "^9.27.0",
27
- "eslint-config-prettier": "^10.1.5",
28
- "globals": "^16.2.0",
29
- "jest": "^29.7.0",
25
+ "dotenv": "^17.2.1",
26
+ "eslint": "^9.33.0",
27
+ "eslint-config-prettier": "^10.1.8",
28
+ "globals": "^16.3.0",
29
+ "jest": "^30.0.5",
30
30
  "node-localstorage": "^3.0.5",
31
- "prettier": "^3.5.3",
32
- "ts-jest": "^29.3.4",
33
- "typescript": "^5.8.3",
34
- "typescript-eslint": "^8.32.1"
31
+ "prettier": "^3.6.2",
32
+ "ts-jest": "^29.4.1",
33
+ "typescript": "^5.9.2",
34
+ "typescript-eslint": "^8.40.0"
35
35
  },
36
36
  "files": [
37
37
  "lib/**/*"
@@ -42,8 +42,8 @@
42
42
  ],
43
43
  "author": "Infoservice s.r.l.",
44
44
  "dependencies": {
45
- "@react-native-async-storage/async-storage": "^2.2.0",
46
- "axios": "^1.11.0",
47
- "zustand": "^5.0.6"
45
+ "@react-native-async-storage/async-storage": "~2.2.0",
46
+ "axios": "~1.11.0",
47
+ "zustand": "~5.0.8"
48
48
  }
49
49
  }
File without changes
@@ -1,148 +0,0 @@
1
- "use strict";
2
- // import { MTSEnvs } from "../config";
3
- // import { ServiceBooking } from "../booking/serviceBooking";
4
- // import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
5
- // import { Service, ServiceTripsResponse } from "../types/services/Service";
6
- // import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
7
- // import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
8
- // import { useTestState } from "../mtsStorage";
9
- // import { SubscriptionBooking } from "../booking/subscriptionBooking";
10
- // // Load .env file
11
- // require('dotenv').config();
12
- // // How to run the test: npm run test -- SubscriptionBooking.test.ts
13
- // describe("SubscriptionBooking", () => {
14
- // const timeOut = 120000;
15
- // const sub_key = process.env.OCP_SUB_KEY_MTS;
16
- // const access_token = process.env.ACCESS_TOKEN;
17
- // const sellerId = 8; // ATV
18
- // // Define localStorage for local testing
19
- // if (typeof localStorage === "undefined" || localStorage === null) {
20
- // var LocalStorage = require("node-localstorage").LocalStorage;
21
- // global.localStorage = new LocalStorage("./scratch");
22
- // }
23
- // test("search_tpl", async () => {
24
- // const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
25
- // // First, get the departures and destinations
26
- // const departures = await booking.getSubscriptionsDepartures() as string[];
27
- // expect(departures.length).toBeGreaterThan(0);
28
- // expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
29
- // const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
30
- // const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
31
- // expect(destinations.length).toBeGreaterThan(0);
32
- // expect(destinations).toContain("GARDA AUTOSTAZIONE");
33
- // const selectedDestination = "GARDA AUTOSTAZIONE";
34
- // // Then get the validity types
35
- // const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
36
- // expect(validityTypes.length).toBeGreaterThan(0);
37
- // for (const validityType of validityTypes) {
38
- // // Check that all returned validity types are valid
39
- // expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
40
- // }
41
- // }, timeOut);
42
- // const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
43
- // const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
44
- // const services = servicesResponse as Service[];
45
- // // Build create cart request
46
- // let tariffsMatrix = services[0].tariffsMatrix;
47
- // tariffsMatrix[0][0].quantity = 1;
48
- // const createServiceCartRequest: CreateServiceCartRequest = {
49
- // currency: ServiceBooking.Currencies.EUR,
50
- // service: {
51
- // serviceId: services[0].id,
52
- // tariffsMatrix: tariffsMatrix
53
- // }
54
- // };
55
- // // Create cart
56
- // const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
57
- // return cart;
58
- // }
59
- // test("create_service_cart", async () => {
60
- // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
61
- // const cart = await createCart(booking);
62
- // // Check that the cartId was saved to the local storage
63
- // expect(useTestState().getState().cartId).toBe(cart.id);
64
- // expect(booking.cartId).toBe(cart.id);
65
- // // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
66
- // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
67
- // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
68
- // // Test booking due date
69
- // expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
70
- // // Test expired tickets
71
- // expect(cart.hasIssuedTickets).toBe(false);
72
- // // Test seller data
73
- // expect(booking.getSellerId()).toBe(cart.sellerId);
74
- // expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
75
- // expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
76
- // // Now try to get the cart
77
- // const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
78
- // expect(newBooking.cartId).toBe(cart.id);
79
- // expect(newBooking.getCart()?.id).toBe(cart.id)
80
- // expect(newBooking.getSellerId()).toBe(cart.sellerId);
81
- // // Finally try to delete the cart
82
- // await booking.deleteCart();
83
- // expect(booking.getCart()).toBe(undefined);
84
- // expect(useTestState().getState().cartId).toBe(undefined);
85
- // }, timeOut);
86
- // test("get_edit_buyer_data", async () => {
87
- // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
88
- // const cart = await createCart(booking);
89
- // // First, try to get the buyer data
90
- // let buyerDataResponse = await booking.getBuyerPassengersDetails();
91
- // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
92
- // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
93
- // expect(buyer).toBe(null);
94
- // // Now try to edit the buyer data
95
- // buyer = {
96
- // id: 0,
97
- // name: "TestName",
98
- // lastName: "TestSurname",
99
- // email: "testBookingLib@infos.it",
100
- // phoneNumber: "+391234567890"
101
- // }
102
- // await booking.updateBuyerPassengersDetails(buyer);
103
- // // Finally, get the buyer data again and check that the data was updated
104
- // buyerDataResponse = await booking.getBuyerPassengersDetails();
105
- // const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
106
- // expect(updatedBuyer.id).toBeGreaterThan(0);
107
- // expect(updatedBuyer.name).toBe(buyer.name);
108
- // expect(updatedBuyer.lastName).toBe(buyer.lastName);
109
- // expect(updatedBuyer.email).toBe(buyer.email);
110
- // expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
111
- // // Finally try to delete the cart
112
- // await booking.deleteCart();
113
- // expect(booking.getCart()).toBe(undefined);
114
- // expect(useTestState().getState().cartId).toBe(undefined);
115
- // }, timeOut);
116
- // test("get_gateway_info", async () => {
117
- // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
118
- // const cart = await createCart(booking);
119
- // booking.updateSellerId(cart.sellerId);
120
- // // First, try to get the buyer data
121
- // let buyerDataResponse = await booking.getBuyerPassengersDetails();
122
- // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
123
- // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
124
- // expect(buyer).toBe(null);
125
- // // Now try to edit the buyer data
126
- // buyer = {
127
- // id: 0,
128
- // name: "TestName",
129
- // lastName: "TestSurname",
130
- // email: "testBookingLib@infos.it",
131
- // phoneNumber: "+391234567890"
132
- // }
133
- // await booking.updateBuyerPassengersDetails(buyer);
134
- // // Try to get the gateways
135
- // const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
136
- // if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
137
- // throw new Error("No gateways found");
138
- // }
139
- // const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
140
- // expect(gateway?.id).toBeGreaterThan(0);
141
- // // Now try to get the info
142
- // const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
143
- // // Finally try to delete the cart
144
- // await booking.deleteCart();
145
- // expect(booking.getCart()).toBe(undefined);
146
- // expect(useTestState().getState().cartId).toBe(undefined);
147
- // }, timeOut);
148
- // });
@@ -1,8 +0,0 @@
1
- /**
2
- * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
3
- * @param {Date | string} date the date to convert
4
- * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
5
- * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
6
- * @returns {string} the ISO string
7
- */
8
- export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getISOStringWithoutGMT = void 0;
4
- /**
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
- * @param {Date | string} date the date to convert
7
- * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
8
- * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
9
- * @returns {string} the ISO string
10
- */
11
- var getISOStringWithoutGMT = function (date, removeTimezone) {
12
- if (removeTimezone === void 0) { removeTimezone = true; }
13
- if (!date)
14
- return null;
15
- var newDate = new Date(date);
16
- var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
17
- return removeTimezone ? isoString.slice(0, -1) : isoString;
18
- };
19
- exports.getISOStringWithoutGMT = getISOStringWithoutGMT;