mts-booking-library 1.0.5 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/lib/booking/booking.d.ts +44 -0
  2. package/lib/booking/booking.js +105 -0
  3. package/lib/booking/journeyBooking.d.ts +49 -0
  4. package/lib/booking/journeyBooking.js +246 -0
  5. package/lib/booking/serviceBooking.d.ts +36 -0
  6. package/lib/booking/serviceBooking.js +190 -0
  7. package/lib/booking/subscriptionBooking.d.ts +50 -0
  8. package/lib/booking/subscriptionBooking.js +201 -0
  9. package/lib/config.d.ts +2 -1
  10. package/lib/config.js +5 -2
  11. package/lib/index.d.ts +15 -140
  12. package/lib/index.js +16 -415
  13. package/lib/types/common/Cart.d.ts +47 -0
  14. package/lib/types/common/Person.d.ts +31 -0
  15. package/lib/types/common/Person.js +11 -0
  16. package/lib/types/{TermsAndTariffs.d.ts → common/Tariffs.d.ts} +5 -0
  17. package/lib/types/journeys/JourneyCart.d.ts +55 -0
  18. package/lib/types/journeys/JourneyInfo.d.ts +18 -0
  19. package/lib/types/journeys/JourneySearch.d.ts +19 -0
  20. package/lib/types/{Journeys → journeys}/JourneySearch.js +7 -5
  21. package/lib/types/journeys/Stop.d.ts +16 -0
  22. package/lib/types/{Journeys → journeys}/Trip.d.ts +1 -1
  23. package/lib/types/services/Line.d.ts +14 -0
  24. package/lib/types/services/Service.d.ts +33 -0
  25. package/lib/types/services/ServiceCart.d.ts +46 -0
  26. package/lib/types/services/ServiceInfo.d.ts +14 -0
  27. package/lib/utils/apiCall.js +22 -2
  28. package/package.json +3 -3
  29. package/lib/types/Booking.d.ts +0 -0
  30. package/lib/types/Booking.js +0 -1
  31. package/lib/types/Cart.d.ts +0 -79
  32. package/lib/types/Details.d.ts +0 -9
  33. package/lib/types/Info.d.ts +0 -8
  34. package/lib/types/Journey.d.ts +0 -8
  35. package/lib/types/JourneySearch.d.ts +0 -9
  36. package/lib/types/Journeys/BusMatrix.d.ts +0 -0
  37. package/lib/types/Journeys/BusMatrix.js +0 -1
  38. package/lib/types/Journeys/Journey.d.ts +0 -8
  39. package/lib/types/Journeys/JourneySearch.d.ts +0 -11
  40. package/lib/types/Journeys/Stop.d.ts +0 -7
  41. package/lib/types/Line.d.ts +0 -6
  42. package/lib/types/Person.d.ts +0 -7
  43. package/lib/types/Stop.d.ts +0 -7
  44. package/lib/types/Stop.js +0 -2
  45. package/lib/types/Subscriptions/ValidityTypes.d.ts +0 -6
  46. package/lib/types/Subscriptions/ValidityTypes.js +0 -10
  47. package/lib/types/TermsAndTariffs.js +0 -2
  48. package/lib/types/Tour.d.ts +0 -18
  49. package/lib/types/Tour.js +0 -2
  50. package/lib/types/Tours/Tour.d.ts +0 -18
  51. package/lib/types/Tours/Tour.js +0 -2
  52. package/lib/types/Tours.d.ts +0 -0
  53. package/lib/types/Tours.js +0 -1
  54. package/lib/types/Trip.d.ts +0 -9
  55. package/lib/types/Trip.js +0 -2
  56. package/lib/types/TripSearch.d.ts +0 -9
  57. package/lib/types/TripSearch.js +0 -2
  58. /package/lib/types/{Cart.js → common/Cart.js} +0 -0
  59. /package/lib/types/{Details.js → common/Tariffs.js} +0 -0
  60. /package/lib/types/{BusMatrix.d.ts → journeys/BusMatrix.d.ts} +0 -0
  61. /package/lib/types/{BusMatrix.js → journeys/BusMatrix.js} +0 -0
  62. /package/lib/types/{Info.js → journeys/JourneyCart.js} +0 -0
  63. /package/lib/types/{Journey.js → journeys/JourneyInfo.js} +0 -0
  64. /package/lib/types/{Journeys → journeys}/Stop.js +0 -0
  65. /package/lib/types/{Journeys → journeys}/Trip.js +0 -0
  66. /package/lib/types/{Line.js → services/Line.js} +0 -0
  67. /package/lib/types/{JourneySearch.js → services/Service.js} +0 -0
  68. /package/lib/types/{Journeys/Journey.js → services/ServiceCart.js} +0 -0
  69. /package/lib/types/{Person.js → services/ServiceInfo.js} +0 -0
  70. /package/lib/types/{Subscriptions → subscriptions}/Subscrptions.d.ts +0 -0
  71. /package/lib/types/{Subscriptions → subscriptions}/Subscrptions.js +0 -0
@@ -0,0 +1,16 @@
1
+ /**
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
+ */
10
+ export type Stop = {
11
+ id: number;
12
+ departureTime: Date;
13
+ destinationTime: Date;
14
+ name: string;
15
+ address: string;
16
+ };
@@ -1,4 +1,4 @@
1
- import { TariffMatrix, TariffType, TermsType } from "../TermsAndTariffs";
1
+ import { TariffMatrix, TariffType, TermsType } from "../common/Tariffs";
2
2
  export type Trip = {
3
3
  id: number;
4
4
  date: Date;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @description Represents a line on which the service is sold.
3
+ *
4
+ * @property {number} id - The unique identifier for the line.
5
+ * @property {string} name - The name of the line.
6
+ * @property {string} linkavelDescription - A description of the line, to be used in {@link https://linkavel.com/} or in other ecommerses.
7
+ * @property {string} backofficeNotes - Additional notes or information about the line for internal use.
8
+ */
9
+ export type Line = {
10
+ id: number;
11
+ name: string;
12
+ linkavelDescription: string;
13
+ backofficeNotes: string;
14
+ };
@@ -0,0 +1,33 @@
1
+ import { TariffMatrix, TariffType, TermsType } from "../common/Tariffs";
2
+ import { Line } from "./Line";
3
+ import { ServiceInfo } from "./ServiceInfo";
4
+ /**
5
+ * @description Represents a service offering, including information about the service, tariffs,
6
+ * terms, and other details.
7
+ *
8
+ * @property {number} id - The unique identifier for the service.
9
+ * @property {Line} line - Information about the line or route associated with the service.
10
+ * @property {ServiceInfo} info - Information about the service itself.
11
+ * @property {TariffMatrix} tariffsMatrix - The tariff matrix for pricing.
12
+ * @property {TariffType[]} tariffTypes - An array of tariff types available for the service.
13
+ * @property {TermsType[]} termsTypes - An array of terms types related to the service.
14
+ * @property {boolean} isDateOptional - Indicates whether a date can be optionally specified for this service.
15
+ * @property {boolean} isDateRequired - Indicates whether specifying a date is required for booking.
16
+ * @property {boolean} isTripMandatory - Indicates whether the selection of the trip in the selected date is mandatory.
17
+ */
18
+ export type Service = {
19
+ id: number;
20
+ line: Line;
21
+ info: ServiceInfo;
22
+ tariffsMatrix: TariffMatrix;
23
+ tariffTypes: TariffType[];
24
+ termsTypes: TermsType[];
25
+ isDateOptional: boolean;
26
+ isDateRequired: boolean;
27
+ isTripMandatory: boolean;
28
+ };
29
+ export type ServiceTrip = {
30
+ tripId?: number;
31
+ date: Date;
32
+ name: string;
33
+ };
@@ -0,0 +1,46 @@
1
+ import { Booking } from "../../booking/booking";
2
+ import { Cart } from "../common/Cart";
3
+ import { TariffMatrix, TariffSummary } from "../common/Tariffs";
4
+ import { ServiceTrip } from "./Service";
5
+ /**
6
+ * @description This is the object to be passed to `ServiceBooking.createServiceCart`, containing information about the selected service.
7
+ *
8
+ * @property {Booking.Currencies} currency - The currency in which the service is priced.
9
+ * @property {Object} service - Information about the selected service.
10
+ * @property {number} service.serviceId - The unique identifier for the service.
11
+ * @property {TariffMatrix} service.tariffsMatrix - The tariff matrix for pricing the service.
12
+ * @property {Date|undefined} [service.date] - The date for the service (optional).
13
+ * @property {number|undefined} [service.tripId] - The unique identifier for the trip (optional).
14
+ */
15
+ export type CreateServiceCartRequest = {
16
+ currency: Booking.Currencies;
17
+ service: {
18
+ serviceId: number;
19
+ tariffsMatrix: TariffMatrix;
20
+ date?: Date;
21
+ tripId?: number;
22
+ };
23
+ };
24
+ /**
25
+ * @description Represents a `JourneyCart`, which extends the {@link Cart} type by including additional
26
+ * information about the bookings
27
+ *
28
+ * @property {ServiceBooking[]} bookings - An array of {@link ServiceBookingType} objects representing the bookings associated
29
+ * with this journey cart.
30
+ */
31
+ export type ServiceCart = Cart & {
32
+ bookings: ServiceBookingType[];
33
+ };
34
+ /**
35
+ * @description Represents a `JourneyBooking`, which contains information about a journey booking.
36
+ *
37
+ * @property {Booking.BookingTypes} type - The type of booking.
38
+ * @property {TariffSummary[]} summary - An array of {@link TariffSummary} objects representing the tariff summary
39
+ * associated with this journey booking.
40
+ * @property {ServiceTrip} info - An array of {@link ServiceTrip} objects representing the stops associated with this journey booking.
41
+ */
42
+ export type ServiceBookingType = {
43
+ type: Booking.BookingTypes;
44
+ summary: TariffSummary[];
45
+ info: ServiceTrip;
46
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @description Represents information about a service.
3
+ *
4
+ * @property {string} sellerName - The name of the seller offering the service.
5
+ * @property {string} minimumTotalPrice - The minimum total price for booking the service, meaning the price if all passenger choose the cheapest tariff.
6
+ * @property {string} bookingProcessMessage - Optional message to be displayed to the user when booking this service.
7
+ * @property {boolean} isBookable - Indicates whether the service is bookable (true) or not (false).
8
+ */
9
+ export type ServiceInfo = {
10
+ sellerName: string;
11
+ minimumTotalPrice: string;
12
+ bookingProcessMessage: string;
13
+ isBookable: boolean;
14
+ };
@@ -51,8 +51,12 @@ exports.makePost = exports.makeGet = void 0;
51
51
  var axios_1 = require("axios");
52
52
  var config_1 = require("../config");
53
53
  var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
54
+ var debug;
54
55
  return __generator(this, function (_a) {
55
- console.log("GET ".concat(url));
56
+ debug = (0, config_1.getConfig)().DEBUG;
57
+ if (debug) {
58
+ console.log("GetRequestData", url);
59
+ }
56
60
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
57
61
  var response, error_1, resError;
58
62
  return __generator(this, function (_a) {
@@ -64,11 +68,17 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
64
68
  })];
65
69
  case 1:
66
70
  response = _a.sent();
71
+ if (debug) {
72
+ console.log("GetResponseData", url, response.data);
73
+ }
67
74
  resolve(response.data);
68
75
  return [3 /*break*/, 3];
69
76
  case 2:
70
77
  error_1 = _a.sent();
71
78
  resError = error_1.response.data;
79
+ if (debug) {
80
+ console.log("GetResponseError", url, resError);
81
+ }
72
82
  reject(resError);
73
83
  return [3 /*break*/, 3];
74
84
  case 3: return [2 /*return*/];
@@ -79,8 +89,12 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
79
89
  }); };
80
90
  exports.makeGet = makeGet;
81
91
  var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
92
+ var debug;
82
93
  return __generator(this, function (_a) {
83
- console.log("POST ".concat(url));
94
+ debug = (0, config_1.getConfig)().DEBUG;
95
+ if (debug) {
96
+ console.log("PostRequestData", url, data);
97
+ }
84
98
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
85
99
  var response, error_2, resError;
86
100
  return __generator(this, function (_a) {
@@ -92,11 +106,17 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
92
106
  })];
93
107
  case 1:
94
108
  response = _a.sent();
109
+ if (debug) {
110
+ console.log("PostResponseData", url, response.data);
111
+ }
95
112
  resolve(response.data);
96
113
  return [3 /*break*/, 3];
97
114
  case 2:
98
115
  error_2 = _a.sent();
99
116
  resError = error_2.response.data;
117
+ if (debug) {
118
+ console.log("PostResponseError", url, resError);
119
+ }
100
120
  reject(resError);
101
121
  return [3 /*break*/, 3];
102
122
  case 3: return [2 /*return*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
- "@types/jest": "^29.5.4",
17
+ "@types/jest": "^29.5.5",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.1",
20
20
  "typescript": "^5.2.2"
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "author": "M",
30
30
  "dependencies": {
31
- "axios": "^1.5.0",
31
+ "axios": "^1.5.1",
32
32
  "node-localstorage": "^3.0.5"
33
33
  }
34
34
  }
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,79 +0,0 @@
1
- import { Booking } from "..";
2
- import { Person } from "./Person";
3
- import { TariffMatrix } from "./TermsAndTariffs";
4
- export type Cart = {
5
- id: number;
6
- cartCode: string;
7
- status: Booking.CartStatus;
8
- nextStatus: Booking.CartStatus;
9
- currency: string;
10
- bookingDueDate: string;
11
- bookings: {
12
- type: string;
13
- summary: {
14
- quantity: number;
15
- label: string;
16
- value: number;
17
- }[];
18
- }[];
19
- info: {
20
- stops: {
21
- id: number;
22
- departureTime: Date;
23
- destinationTime: Date;
24
- name: string;
25
- address: string;
26
- }[];
27
- };
28
- buyer: Person;
29
- reductions: {
30
- tripId: number;
31
- tripName: string;
32
- value: number;
33
- isPercentage: boolean;
34
- voucherCode?: string;
35
- }[];
36
- isSeatsSelectionAllowed: boolean;
37
- sellingMethod: string;
38
- totalValue: number;
39
- totalResellerFee?: number;
40
- totalCreditFromChange: number;
41
- totalAmountToPay: number;
42
- extas: {
43
- id: number;
44
- resourceId: number;
45
- name: string;
46
- description: string;
47
- notes: string;
48
- tariff: {
49
- tariffId: number;
50
- tariffName: string;
51
- };
52
- }[];
53
- };
54
- export type TourCart = {
55
- cartId?: number;
56
- currency: Booking.Currencies;
57
- tour: {
58
- tourId: number;
59
- date?: Date;
60
- tripId?: number;
61
- tariffsMatrix: TariffMatrix;
62
- };
63
- };
64
- export type JourneyCart = {
65
- cartId?: number;
66
- currency: Booking.Currencies;
67
- outboundJourney: {
68
- departureStopId: number;
69
- destinationStopId: number;
70
- tripId: number;
71
- tariffsMatrix: TariffMatrix;
72
- }[];
73
- returnJourney: {
74
- tripId: number;
75
- departureStopId: number;
76
- destinationStopId: number;
77
- tariffsMatrix: TariffMatrix;
78
- }[] | null;
79
- };
@@ -1,9 +0,0 @@
1
- import { Person } from "./Person";
2
- export type Details = {
3
- passengers: Person[] & {
4
- tripsToTariffs: {
5
- [tripId: number]: number;
6
- };
7
- };
8
- buyer: Person;
9
- };
@@ -1,8 +0,0 @@
1
- export type Info = {
2
- sellerName: string;
3
- minimumTotalPrice: string;
4
- remainingSeats?: number;
5
- totalNumberOfSeats?: number;
6
- bookingProcessMessage: string;
7
- isBookable: boolean;
8
- };
@@ -1,8 +0,0 @@
1
- import { Info } from "./Info";
2
- import { Stop } from "./Stop";
3
- import { Trip } from "./Trip";
4
- export type Journey = {
5
- stops: Stop[];
6
- info: Info;
7
- trips: Trip[];
8
- };
@@ -1,9 +0,0 @@
1
- import { Booking } from "..";
2
- export type JourneySearch = {
3
- departureStopName: string;
4
- destinationStopName: string;
5
- passengersNumber: number;
6
- date: Date;
7
- currency: Booking.Currencies;
8
- isRoundtrip: boolean;
9
- };
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,8 +0,0 @@
1
- import { Stop } from "./Stop";
2
- import { Info } from "../Info";
3
- import { Trip } from "./Trip";
4
- export type Journey = {
5
- stops: Stop[];
6
- info: Info;
7
- trips: Trip[];
8
- };
@@ -1,11 +0,0 @@
1
- import { Booking } from "../..";
2
- export type JourneySearch = {
3
- departureStopName: string | undefined;
4
- destinationStopName: string | undefined;
5
- passengersNumber: number;
6
- date: Date;
7
- roundTripDate: Date | null;
8
- currency: Booking.Currencies;
9
- isRoundtrip: boolean;
10
- };
11
- export declare const DefaultJourneySearch: JourneySearch;
@@ -1,7 +0,0 @@
1
- export type Stop = {
2
- id: number;
3
- departureTime: Date;
4
- destinationTime: Date;
5
- name: string;
6
- address: string;
7
- };
@@ -1,6 +0,0 @@
1
- export type Line = {
2
- id: number;
3
- name: string;
4
- linkavelDescription: string;
5
- backofficeNotes: string;
6
- };
@@ -1,7 +0,0 @@
1
- export type Person = {
2
- id: number;
3
- name: string;
4
- lastName: string;
5
- email: string;
6
- phoneNumber: string;
7
- };
@@ -1,7 +0,0 @@
1
- export type Stop = {
2
- id: number;
3
- departureTime: Date;
4
- destinationTime: Date;
5
- name: string;
6
- address: string;
7
- };
package/lib/types/Stop.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- export declare enum ValidityTypes {
2
- WORKING_WEEK = "WORKING_WEEK",
3
- WEEKLY = "WEEKLY",
4
- MONTHLY = "MONTHLY",
5
- YEARLY = "YEARLY"
6
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidityTypes = void 0;
4
- var ValidityTypes;
5
- (function (ValidityTypes) {
6
- ValidityTypes["WORKING_WEEK"] = "WORKING_WEEK";
7
- ValidityTypes["WEEKLY"] = "WEEKLY";
8
- ValidityTypes["MONTHLY"] = "MONTHLY";
9
- ValidityTypes["YEARLY"] = "YEARLY";
10
- })(ValidityTypes || (exports.ValidityTypes = ValidityTypes = {}));
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,18 +0,0 @@
1
- import { Info } from "./Info";
2
- import { Line } from "./Line";
3
- import { TariffMatrix, TariffType, TermsType } from "./TermsAndTariffs";
4
- export type Tour = {
5
- id: number;
6
- line: Line;
7
- info: Info;
8
- tariffsMatrix: TariffMatrix;
9
- tariffTypes: TariffType[];
10
- termsTypes: TermsType[];
11
- isDateOptional: boolean;
12
- isDateRequired: boolean;
13
- isTripMandatory: boolean;
14
- };
15
- export type TourTrip = {
16
- tripId: number;
17
- hour: Date;
18
- };
package/lib/types/Tour.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,18 +0,0 @@
1
- import { Info } from "../Info";
2
- import { Line } from "../Line";
3
- import { TariffMatrix, TariffType, TermsType } from "../TermsAndTariffs";
4
- export type Tour = {
5
- id: number;
6
- line: Line;
7
- info: Info;
8
- tariffsMatrix: TariffMatrix;
9
- tariffTypes: TariffType[];
10
- termsTypes: TermsType[];
11
- isDateOptional: boolean;
12
- isDateRequired: boolean;
13
- isTripMandatory: boolean;
14
- };
15
- export type TourTrip = {
16
- tripId: number;
17
- hour: Date;
18
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,9 +0,0 @@
1
- import { TariffMatrix, TariffType, TermsType } from "./TermsAndTariffs";
2
- export type Trip = {
3
- id: number;
4
- departureStopName: string;
5
- destinationStopName: string;
6
- tariffsMatrix: TariffMatrix;
7
- tariffTypes: TariffType[];
8
- termsTypes: TermsType[];
9
- };
package/lib/types/Trip.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { Booking } from "..";
2
- export type TripSearch = {
3
- departureStopName: string;
4
- destinationStopName: string;
5
- passengersNumber: number;
6
- date: Date;
7
- currency: Booking.Currencies;
8
- isRoundtrip: boolean;
9
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes