mts-booking-library 2.4.14 → 3.0.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.
Files changed (35) hide show
  1. package/lib/booking/booking.d.ts +2 -1
  2. package/lib/booking/journeyBooking.d.ts +46 -6
  3. package/lib/booking/journeyBooking.js +31 -75
  4. package/lib/booking/serviceBooking.d.ts +48 -8
  5. package/lib/booking/serviceBooking.js +33 -74
  6. package/lib/booking/subscriptionBooking.d.ts +45 -3
  7. package/lib/booking/subscriptionBooking.js +31 -38
  8. package/lib/booking/tplBooking.d.ts +46 -6
  9. package/lib/booking/tplBooking.js +27 -78
  10. package/lib/index.d.ts +6 -5
  11. package/lib/index.js +6 -5
  12. package/lib/mtsStorage.d.ts +10 -6
  13. package/lib/types/common/Cart.d.ts +64 -62
  14. package/lib/types/common/Person.d.ts +0 -11
  15. package/lib/types/common/Person.js +1 -11
  16. package/lib/types/common/Reduction.d.ts +14 -21
  17. package/lib/types/common/Tariffs.d.ts +0 -2
  18. package/lib/types/common/dates.d.ts +8 -0
  19. package/lib/types/common/dates.js +320 -0
  20. package/lib/types/journeys/JourneyCart.d.ts +0 -18
  21. package/lib/types/journeys/JourneyCart.js +0 -8
  22. package/lib/types/journeys/JourneyInfo.d.ts +7 -8
  23. package/lib/types/journeys/JourneySearch.d.ts +5 -4
  24. package/lib/types/journeys/JourneySearch.js +10 -5
  25. package/lib/types/journeys/Stop.d.ts +8 -12
  26. package/lib/types/journeys/Trip.d.ts +70 -6
  27. package/lib/types/services/Service.d.ts +13 -4
  28. package/lib/types/services/ServiceCart.d.ts +4 -31
  29. package/lib/types/subscriptions/SubscriptionAvailabilities.d.ts +20 -22
  30. package/lib/types/subscriptions/SubscriptionCart.d.ts +3 -4
  31. package/lib/types/subscriptions/Subscriptions.d.ts +10 -11
  32. package/lib/types/tpl/TplCart.d.ts +2 -21
  33. package/lib/utils/utils.d.ts +0 -8
  34. package/lib/utils/utils.js +1 -17
  35. package/package.json +16 -16
@@ -1,12 +1,76 @@
1
+ import { DateWithTimeZone } from "../common/dates";
1
2
  import { TariffsMatrix, TariffType, TermsType } from "../common/Tariffs";
2
3
  export type Trip = {
4
+ /** The unique identifier for the trip */
3
5
  id: number;
4
- date: Date;
5
- departureStopName: string;
6
- destinationStopName: string;
7
- tariffsMatrix: TariffsMatrix;
8
- tariffTypes: TariffType[];
9
- termsTypes: TermsType[];
6
+ /** The name of the trip */
7
+ name?: string;
8
+ /** Extension of the trip name */
9
+ nameExtension?: string;
10
+ /** LinkAvel Bus name */
11
+ linkAvelBusName?: string;
12
+ /** Extended name of the trip */
13
+ extendedName?: string;
14
+ /** Whether the trip is tentative */
15
+ tentative?: boolean;
16
+ /** Whether the trip is canceled */
17
+ canceled?: boolean;
18
+ /** Bus ID */
19
+ busId?: number;
20
+ /** Seller ID */
21
+ sellerId?: number;
22
+ /** Route ID */
23
+ routeId?: number;
24
+ /** Route name */
25
+ routeName?: string;
26
+ /** Line ID */
27
+ lineId?: number;
28
+ /** Line name */
29
+ lineName?: string;
30
+ /** Whether it's a service */
31
+ isService?: boolean;
32
+ /** Line type */
33
+ lineType?: string;
34
+ /** Date of the trip */
35
+ date?: string;
36
+ /** Date as string */
37
+ dateString?: string;
38
+ /** Whether the trip is sellable */
39
+ isSellable?: boolean;
40
+ /** Apex related trip ID */
41
+ apexRelatedTripId?: number;
42
+ /** Related trips IDs */
43
+ relatedTripsIds?: number[];
44
+ /** Departure time */
45
+ departureTime?: string;
46
+ /** Destination time */
47
+ destinationTime?: string;
48
+ /** Departure time as ISO string */
49
+ departureDateTime?: DateWithTimeZone;
50
+ /** Destination time as ISO string */
51
+ destinationDateTime?: DateWithTimeZone;
52
+ /** All bus tickets IDs */
53
+ allBusTicketsIds?: number[];
54
+ /** Ongoing route stop ID to bus tickets IDs mapping */
55
+ ongoingRouteStopIdToBusTicketsIds?: Record<string, number[]>;
56
+ /** Destination route stop ID to bus tickets IDs mapping */
57
+ destinationRouteStopIdToBusTicketsIds?: Record<string, number[]>;
58
+ /** Departure route stop ID to bus tickets IDs mapping */
59
+ departureRouteStopIdToBusTicketsIds?: Record<string, number[]>;
60
+ /** The name of the departure stop */
61
+ departureStopName?: string;
62
+ /** Departure physical agency stop ID */
63
+ departurePhysicalAgencyStopId?: number;
64
+ /** The name of the destination stop */
65
+ destinationStopName?: string;
66
+ /** Destination physical agency stop ID */
67
+ destinationPhysicalAgencyStopId?: number;
68
+ /** List of the tariffTypes to be found in the tariffsMatrix */
69
+ tariffTypes?: TariffType[];
70
+ /** List of the termsTypes to be found in the tariffsMatrix */
71
+ termsTypes?: TermsType[];
72
+ /** Tariff matrix for this trip */
73
+ tariffsMatrix?: TariffsMatrix;
10
74
  };
11
75
  /**
12
76
  * This type is used to represent a trip for the reduction page. This only makes sense for a JourneyBooking,
@@ -26,18 +26,27 @@ export type Service = {
26
26
  isDateRequired: boolean;
27
27
  isTripMandatory: boolean;
28
28
  };
29
+ export type TripIdAndHour = {
30
+ /** The id of the trip. */
31
+ tripId: number;
32
+ /** The hour of the trip. */
33
+ hour: string;
34
+ };
29
35
  export type ServiceTrip = {
30
- tripId?: number;
31
- date: Date;
36
+ /** The name of the service */
32
37
  name: string;
38
+ /** The date and time of the service in ISO string format, if set. */
39
+ serviceDate?: string;
40
+ /** The id of the trip, if set. */
41
+ tripId?: number;
33
42
  };
34
43
  /**
35
44
  * @description Represents a response from the service trips endpoint
36
45
  * @param {boolean} areThereTrips - Indicates whether there are trips available for the service.
37
- * @param {ServiceTrip[]} trips - An array of {@link ServiceTrip} objects representing the available trips. This can be empty
46
+ * @param {TripIdAndHour[]} trips - An array of {@link TripIdAndHour} objects representing the available trips. This can be empty
38
47
  * even if `areThereTrips` is true, as the user might be not allowed to select a specific trip.
39
48
  */
40
49
  export type ServiceTripsResponse = {
41
50
  areThereTrips: boolean;
42
- trips: ServiceTrip[];
51
+ trips: TripIdAndHour[];
43
52
  };
@@ -2,49 +2,22 @@ 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
31
- *
32
- * @property {ServiceBooking[]} bookings - An array of {@link ServiceBookingType} objects representing the bookings associated
33
- * with this journey cart.
34
8
  */
35
9
  export type ServiceCart = Cart & {
10
+ /** An array of {@link ServiceBookingType} objects representing the bookings associated with this journey cart. */
36
11
  bookings: ServiceBookingType[];
37
12
  };
38
13
  /**
39
14
  * @description Represents a `ServiceBooking`, which contains information about a service booking.
40
- *
41
- * @property {Booking.BookingTypes} type - The type of booking. For services, this is always `Booking.BookingTypes.SERVICE`.
42
- * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
43
- * associated with this journey booking.
44
- * @property {ServiceTrip} info - An array of {@link ServiceTrip} objects representing the stops associated with this journey booking.
45
15
  */
46
16
  export type ServiceBookingType = {
17
+ /** The type of booking. For services, this is always `Booking.BookingTypes.SERVICE`. */
47
18
  type: Booking.BookingTypes;
19
+ /** An array of {@link TariffSummary} objects representing the tariff summary associated with this journey booking. */
48
20
  summary: TariffSummary[];
21
+ /** Information about the service. */
49
22
  info: ServiceTrip;
50
23
  };
@@ -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 hh:mm format */
40
+ outboundDepartureTimeString: string;
41
+ /** The destination time of the outbound trip in hh:mm format */
42
+ outboundDestinationTimeString: string;
43
+ /** The departure time of the return trip in hh:mm format */
44
+ returnDepartureTimeString: string | null;
45
+ /** The destination time of the return trip in hh:mm format */
46
+ returnDestinationTimeString: string | null;
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 ISO string format */
58
+ dateFrom: string;
59
+ /** The end date of the period in ISO string format */
60
+ dateTo: string;
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,13 +31,12 @@ 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 = {
37
+ /** The start date of the period in ISO string format as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities} */
40
38
  dateFrom: string;
39
+ /** The end date of the period in ISO string format as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities} */
41
40
  dateTo: string;
42
41
  };
43
42
  /**
@@ -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,3 @@
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;
9
1
  /**
10
2
  * This method check where a variable is null or undefined
11
3
  * @param value The value to check
@@ -1,22 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNullOrWhiteSpace = exports.isNullOrUndefined = 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;
3
+ exports.isNullOrWhiteSpace = exports.isNullOrUndefined = void 0;
20
4
  /**
21
5
  * This method check where a variable is null or undefined
22
6
  * @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.14",
3
+ "version": "3.0.1",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "build": "tsc",
9
9
  "pretest": "tsc --noEmit",
10
10
  "test": "jest --config jestconfig.json",
11
- "prepare": "npm run build",
11
+ "prepare": "npm audit --audit-level=moderate && npm run build",
12
12
  "prepublishOnly": "npm run test --runInBand",
13
13
  "version": "git add -A src",
14
14
  "postversion": "git push && git push --tags",
@@ -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.13.0",
47
+ "zustand": "~5.0.8"
48
48
  }
49
49
  }