mts-booking-library 1.1.8 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,6 +58,11 @@ export declare class SubscriptionBooking extends Booking {
58
58
  * @returns {GetSubscriptionAvailabilityResponse} The availability of the subscription for the given parameters
59
59
  */
60
60
  getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest): Promise<GetSubscriptionAvailabilityResponse>;
61
+ /**
62
+ * This method creates a subscription cart for the given parameters.
63
+ * @param {CreateSubscriptionCartRequest} request the request object containing the parameters for the availability check
64
+ * @returns
65
+ */
61
66
  createSubscriptionCart(request: CreateSubscriptionCartRequest): Promise<SubscriptionCart>;
62
67
  }
63
68
  export declare namespace SubscriptionBooking {
@@ -219,6 +219,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
219
219
  });
220
220
  });
221
221
  };
222
+ /**
223
+ * This method creates a subscription cart for the given parameters.
224
+ * @param {CreateSubscriptionCartRequest} request the request object containing the parameters for the availability check
225
+ * @returns
226
+ */
222
227
  SubscriptionBooking.prototype.createSubscriptionCart = function (request) {
223
228
  return __awaiter(this, void 0, void 0, function () {
224
229
  var url;
package/lib/index.d.ts CHANGED
@@ -3,7 +3,8 @@ export { JourneyBooking } from "./booking/journeyBooking";
3
3
  export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
5
  export { Person, PassengersDetails, DEFAULT_PERSON } from "./types/common/Person";
6
- export { TariffMatrix, TariffSummary, TariffType, TermsType } from "./types/common/Tariffs";
6
+ export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType } from "./types/common/Tariffs";
7
+ export { ErrorResponse } from "./types/ErrorResponse";
7
8
  export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
8
9
  export { JourneyInfo } from "./types/journeys/JourneyInfo";
9
10
  export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * @description Error response type as returned by the BackEnd
3
3
  *
4
- * @property {number} statusCode - The status code of the error (e.g. 400)
4
+ * @property {number} httpStatus - The http status code of the error (e.g. 400)
5
+ * @property {number} mtsCode - The error code returned by the MTS Backend (e.g. 4001)
5
6
  * @property {string} message - The message of the error (e.g. "Invalid parameters")
6
7
  */
7
8
  export type ErrorResponse = {
8
- statusCode: number;
9
+ httpStatus: number;
10
+ mtsCode: number;
9
11
  message: string;
10
12
  };
@@ -1,9 +1,30 @@
1
- export type TariffMatrix = {
1
+ /**
2
+ * This represents a tariff, a part of a {@link TariffsMatrix} (returned when searching Journeys or Services).
3
+ * @param {number} tariffTypeId - The id of the tariff type.
4
+ * @param {number} termsTypeId - The id of the terms type.
5
+ * @param {number} value - The value of the tariff (in the currency specified in the {@link Booking} object).
6
+ * @param {number} quantity - The number of passengers to which this tariff applies.
7
+ */
8
+ export type Tariff = {
2
9
  tariffTypeId: number;
3
10
  termsTypeId: number;
4
11
  value: number;
5
12
  quantity: number;
6
- }[][];
13
+ };
14
+ /**
15
+ * This represents a tariff matrix, returned when searching Journeys or Services.
16
+ * It is a 2D array of {@link Tariff} objects. On the rows, there are the terms types, while on the columns there are the tariff types.
17
+ */
18
+ export type TariffsMatrix = Tariff[][];
19
+ /**
20
+ * This represents a tariff type, returned when searching Journeys or Services. This shall be used the build the header of the tariff matrix.
21
+ * @param {string} name - The name of the tariff type.
22
+ * @param {string} description - The description of the tariff type.
23
+ * @param {boolean} requiredPassengersName - Whether the passengers' names are required for this tariff type.
24
+ * @param {number} numberOfOccupiedSeats - The number of seats occupied by this tariff type.
25
+ * @param {string} bookingProcessDescription - A message to be shown to the user during the booking process that describes the tariff type,
26
+ * including info on the rules that apply to it.
27
+ */
7
28
  export type TariffType = {
8
29
  name: string;
9
30
  description: string;
@@ -11,6 +32,16 @@ export type TariffType = {
11
32
  numberOfOccupiedSeats: number;
12
33
  bookingProcessDescription: string;
13
34
  };
35
+ /**
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.
37
+ * @param {string} name - The name of the terms type.
38
+ * @param {string} description - The description of the terms type.
39
+ * @param {boolean} isRefundAllowed - Whether tickets refunds are allowed for this terms type.
40
+ * @param {boolean} isChangeAllowed - Whether changing the ticket is allowed for this terms type.
41
+ * @param {string} validationRulesString - A string containing the validation rules that apply to this terms type.
42
+ * @param {string} bookingProcessDescription - A message to be shown to the user during the booking process that describes the terms type,
43
+ * including info on the rules that apply to it.
44
+ */
14
45
  export type TermsType = {
15
46
  name: string;
16
47
  description: string;
@@ -1,6 +1,6 @@
1
1
  import { Booking } from "../../booking/booking";
2
2
  import { Cart } from "../common/Cart";
3
- import { TariffMatrix, TariffSummary } from "../common/Tariffs";
3
+ import { TariffsMatrix, TariffSummary } from "../common/Tariffs";
4
4
  import { Stop } from "./Stop";
5
5
  /**
6
6
  * @description Object containing information about a trip of a selected journey. This object is part of the {@link CreateJourneyCartRequest} object
@@ -9,13 +9,13 @@ import { Stop } from "./Stop";
9
9
  * @property {number} tripId - The unique identifier for the trip.
10
10
  * @property {number} departureStopId - The unique identifier for the departure stop.
11
11
  * @property {number} destinationStopId - The unique identifier for the destination stop.
12
- * @property {TariffMatrix} tariffsMatrix - The tariff matrix for pricing the outbound journey.
12
+ * @property {TariffsMatrix} tariffsMatrix - The tariff matrix for pricing the outbound journey.
13
13
  */
14
14
  export type TripBookingInfo = {
15
15
  tripId: number;
16
16
  departureStopId: number;
17
17
  destinationStopId: number;
18
- tariffsMatrix: TariffMatrix;
18
+ tariffsMatrix: TariffsMatrix;
19
19
  };
20
20
  /**
21
21
  * @description This is the object to be passed to `JourneyBooking.createJourneyCart`, containing information about the selected service.
@@ -1,10 +1,10 @@
1
- import { TariffMatrix, TariffType, TermsType } from "../common/Tariffs";
1
+ import { TariffsMatrix, TariffType, TermsType } from "../common/Tariffs";
2
2
  export type Trip = {
3
3
  id: number;
4
4
  date: Date;
5
5
  departureStopName: string;
6
6
  destinationStopName: string;
7
- tariffsMatrix: TariffMatrix;
7
+ tariffsMatrix: TariffsMatrix;
8
8
  tariffTypes: TariffType[];
9
9
  termsTypes: TermsType[];
10
10
  };
@@ -1,4 +1,4 @@
1
- import { TariffMatrix, TariffType, TermsType } from "../common/Tariffs";
1
+ import { TariffsMatrix, TariffType, TermsType } from "../common/Tariffs";
2
2
  import { Line } from "./Line";
3
3
  import { ServiceInfo } from "./ServiceInfo";
4
4
  /**
@@ -8,7 +8,7 @@ import { ServiceInfo } from "./ServiceInfo";
8
8
  * @property {number} id - The unique identifier for the service.
9
9
  * @property {Line} line - Information about the line or route associated with the service.
10
10
  * @property {ServiceInfo} info - Information about the service itself.
11
- * @property {TariffMatrix} tariffsMatrix - The tariff matrix for pricing.
11
+ * @property {TariffsMatrix} tariffsMatrix - The tariff matrix for pricing.
12
12
  * @property {TariffType[]} tariffTypes - An array of tariff types available for the service.
13
13
  * @property {TermsType[]} termsTypes - An array of terms types related to the service.
14
14
  * @property {boolean} isDateOptional - Indicates whether a date can be optionally specified for this service.
@@ -19,7 +19,7 @@ export type Service = {
19
19
  id: number;
20
20
  line: Line;
21
21
  info: ServiceInfo;
22
- tariffsMatrix: TariffMatrix;
22
+ tariffsMatrix: TariffsMatrix;
23
23
  tariffTypes: TariffType[];
24
24
  termsTypes: TermsType[];
25
25
  isDateOptional: boolean;
@@ -1,6 +1,6 @@
1
1
  import { Booking } from "../../booking/booking";
2
2
  import { Cart } from "../common/Cart";
3
- import { TariffMatrix, TariffSummary } from "../common/Tariffs";
3
+ import { TariffsMatrix, TariffSummary } from "../common/Tariffs";
4
4
  import { ServiceTrip } from "./Service";
5
5
  /**
6
6
  * @description This is the object to be passed to `ServiceBooking.createServiceCart`, containing information about the selected service.
@@ -8,7 +8,7 @@ import { ServiceTrip } from "./Service";
8
8
  * @property {Booking.Currencies} currency - The currency in which the service is priced.
9
9
  * @property {Object} service - Information about the selected service.
10
10
  * @property {number} service.serviceId - The unique identifier for the service.
11
- * @property {TariffMatrix} service.tariffsMatrix - The tariff matrix for pricing the service.
11
+ * @property {TariffsMatrix} service.tariffsMatrix - The tariff matrix for pricing the service.
12
12
  * @property {Date|undefined} [service.date] - The date for the service (optional).
13
13
  * @property {number|undefined} [service.tripId] - The unique identifier for the trip (optional).
14
14
  */
@@ -16,7 +16,7 @@ export type CreateServiceCartRequest = {
16
16
  currency: Booking.Currencies;
17
17
  service: {
18
18
  serviceId: number;
19
- tariffsMatrix: TariffMatrix;
19
+ tariffsMatrix: TariffsMatrix;
20
20
  date?: Date;
21
21
  tripId?: number;
22
22
  };
@@ -28,7 +28,7 @@ export type CreateSubscriptionCartRequest = {
28
28
  outboundRouteId: number;
29
29
  returnRouteId: number;
30
30
  numberOfPassengers: number;
31
- period: SubscriptionPeriod[];
31
+ periods: SubscriptionPeriod[];
32
32
  };
33
33
  /**
34
34
  * @description This is the object that describes which perios should be booked.
@@ -59,27 +59,38 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
59
59
  }
60
60
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
61
61
  var response, error_1, resError;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
62
+ var _a, _b, _c;
63
+ return __generator(this, function (_d) {
64
+ switch (_d.label) {
64
65
  case 0:
65
- _a.trys.push([0, 2, , 3]);
66
+ _d.trys.push([0, 2, , 3]);
66
67
  return [4 /*yield*/, axios_1.default.get(url, {
67
68
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
68
69
  })];
69
70
  case 1:
70
- response = _a.sent();
71
+ response = _d.sent();
71
72
  if (debug) {
72
73
  console.log("GetResponseData", url, response.data);
73
74
  }
74
75
  resolve(response.data);
75
76
  return [3 /*break*/, 3];
76
77
  case 2:
77
- error_1 = _a.sent();
78
- resError = error_1.response.data;
79
- if (debug) {
80
- console.log("GetResponseError", url, resError);
78
+ error_1 = _d.sent();
79
+ if (axios_1.default.isAxiosError(error_1)) {
80
+ resError = {
81
+ httpStatus: ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
82
+ mtsCode: ((_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 500,
83
+ message: ((_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
84
+ };
85
+ if (debug) {
86
+ console.log("GetResponseError", url, resError);
87
+ }
88
+ reject(resError);
89
+ }
90
+ else {
91
+ // Not a axios error, return the error as is
92
+ reject(error_1);
81
93
  }
82
- reject(resError);
83
94
  return [3 /*break*/, 3];
84
95
  case 3: return [2 /*return*/];
85
96
  }
@@ -97,27 +108,38 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
97
108
  }
98
109
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
99
110
  var response, error_2, resError;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
111
+ var _a, _b, _c;
112
+ return __generator(this, function (_d) {
113
+ switch (_d.label) {
102
114
  case 0:
103
- _a.trys.push([0, 2, , 3]);
115
+ _d.trys.push([0, 2, , 3]);
104
116
  return [4 /*yield*/, axios_1.default.post(url, data, {
105
117
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
106
118
  })];
107
119
  case 1:
108
- response = _a.sent();
120
+ response = _d.sent();
109
121
  if (debug) {
110
122
  console.log("PostResponseData", url, response.data);
111
123
  }
112
124
  resolve(response.data);
113
125
  return [3 /*break*/, 3];
114
126
  case 2:
115
- error_2 = _a.sent();
116
- resError = error_2.response.data;
117
- if (debug) {
118
- console.log("PostResponseError", url, resError);
127
+ error_2 = _d.sent();
128
+ if (axios_1.default.isAxiosError(error_2)) {
129
+ resError = {
130
+ httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
131
+ mtsCode: ((_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 500,
132
+ message: ((_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
133
+ };
134
+ if (debug) {
135
+ console.log("GetResponseError", url, resError);
136
+ }
137
+ reject(resError);
138
+ }
139
+ else {
140
+ // Not a axios error, return the error as is
141
+ reject(error_2);
119
142
  }
120
- reject(resError);
121
143
  return [3 /*break*/, 3];
122
144
  case 3: return [2 /*return*/];
123
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",