mts-booking-library 3.5.0 → 3.7.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.
@@ -12,6 +12,17 @@ type JourneyLineRouteFilters = {
12
12
  lineId?: number | null;
13
13
  routeId?: number | null;
14
14
  };
15
+ /**
16
+ * A stop with optional metadata. `region` and `hint` may be null when the
17
+ * backend has no Province / City data for the underlying physical stop.
18
+ * Returned by {@link JourneyBooking.getJourneysDeparturesEnriched} and
19
+ * {@link JourneyBooking.getJourneysDestinationsEnriched}.
20
+ */
21
+ export type EnrichedStop = {
22
+ name: string;
23
+ region?: string | null;
24
+ hint?: string | null;
25
+ };
15
26
  export declare class JourneyBooking extends Booking {
16
27
  private cart?;
17
28
  /**
@@ -121,12 +132,25 @@ export declare class JourneyBooking extends Booking {
121
132
  * @returns The list of possible departures
122
133
  */
123
134
  getJourneysDepartures(filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
135
+ /**
136
+ * Like {@link getJourneysDepartures}, but returns the enriched representation
137
+ * (name + optional region + optional hint) when the backend exposes it.
138
+ * Falls back to a flat {name}-only list when the backend response only
139
+ * carries the legacy `stops` field. Separate from the original method to
140
+ * avoid breaking the existing `string[]` contract used by other clients.
141
+ */
142
+ getJourneysDeparturesEnriched(filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | EnrichedStop[]>;
124
143
  /**
125
144
  * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
126
145
  * @param departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
127
146
  * @returns The list of possible destinations
128
147
  */
129
148
  getJourneysDestinations(departureStopName: string, filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | string[]>;
149
+ /**
150
+ * Like {@link getJourneysDestinations}, but returns the enriched
151
+ * representation (see {@link getJourneysDeparturesEnriched}).
152
+ */
153
+ getJourneysDestinationsEnriched(departureStopName: string, filtersOrOptions?: JourneyLineRouteFilters | ApiCallOptions, options?: ApiCallOptions): Promise<ErrorResponse | EnrichedStop[]>;
130
154
  /**
131
155
  * This method returns the journeys that match the given parameters.
132
156
  * Note that it will always return the journeys for the one-way trip.
@@ -81,6 +81,24 @@ var utils_1 = require("../utils/utils");
81
81
  var booking_1 = require("./booking");
82
82
  var isJourneyLineRouteFilters = function (value) { return !!value && ("lineId" in value || "routeId" in value); };
83
83
  var getJourneyLineRouteParams = function (filters) { return (__assign(__assign({}, ((filters === null || filters === void 0 ? void 0 : filters.lineId) && { lineId: filters.lineId.toString() })), ((filters === null || filters === void 0 ? void 0 : filters.routeId) && { routeId: filters.routeId.toString() }))); };
84
+ var isEnrichedStop = function (x) {
85
+ return typeof x === "object" && x !== null && typeof x.name === "string";
86
+ };
87
+ /**
88
+ * Parses the booking-API stop response into the enriched shape. When the
89
+ * backend doesn't populate `stopsEnriched` (older deployment), reconstructs
90
+ * a minimal `{name}` list from the flat `stops` array so callers always
91
+ * receive the same shape.
92
+ */
93
+ var enrichedStopsFromResponse = function (response) {
94
+ var _a;
95
+ var enriched = Array.isArray(response.stopsEnriched)
96
+ ? response.stopsEnriched.filter(isEnrichedStop)
97
+ : [];
98
+ if (enriched.length > 0)
99
+ return enriched;
100
+ return ((_a = response.stops) !== null && _a !== void 0 ? _a : []).map(function (name) { return ({ name: name }); });
101
+ };
84
102
  var JourneyBooking = /** @class */ (function (_super) {
85
103
  __extends(JourneyBooking, _super);
86
104
  /**
@@ -235,6 +253,29 @@ var JourneyBooking = /** @class */ (function (_super) {
235
253
  });
236
254
  });
237
255
  };
256
+ /**
257
+ * Like {@link getJourneysDepartures}, but returns the enriched representation
258
+ * (name + optional region + optional hint) when the backend exposes it.
259
+ * Falls back to a flat {name}-only list when the backend response only
260
+ * carries the legacy `stops` field. Separate from the original method to
261
+ * avoid breaking the existing `string[]` contract used by other clients.
262
+ */
263
+ JourneyBooking.prototype.getJourneysDeparturesEnriched = function (filtersOrOptions, options) {
264
+ return __awaiter(this, void 0, void 0, function () {
265
+ var filters, requestOptions, searchParams, url;
266
+ return __generator(this, function (_a) {
267
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
268
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
269
+ searchParams = new URLSearchParams(getJourneyLineRouteParams(filters));
270
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?").concat(searchParams);
271
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
272
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
273
+ return response;
274
+ return enrichedStopsFromResponse(response);
275
+ })];
276
+ });
277
+ });
278
+ };
238
279
  /**
239
280
  * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
240
281
  * @param departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
@@ -254,6 +295,26 @@ var JourneyBooking = /** @class */ (function (_super) {
254
295
  });
255
296
  });
256
297
  };
298
+ /**
299
+ * Like {@link getJourneysDestinations}, but returns the enriched
300
+ * representation (see {@link getJourneysDeparturesEnriched}).
301
+ */
302
+ JourneyBooking.prototype.getJourneysDestinationsEnriched = function (departureStopName, filtersOrOptions, options) {
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var filters, requestOptions, searchParams, url;
305
+ return __generator(this, function (_a) {
306
+ filters = isJourneyLineRouteFilters(filtersOrOptions) ? filtersOrOptions : undefined;
307
+ requestOptions = isJourneyLineRouteFilters(filtersOrOptions) ? options : filtersOrOptions;
308
+ searchParams = new URLSearchParams(__assign({ departureStopName: departureStopName }, getJourneyLineRouteParams(filters)));
309
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
310
+ return [2 /*return*/, this.callGetApi(url, requestOptions).then(function (response) {
311
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
312
+ return response;
313
+ return enrichedStopsFromResponse(response);
314
+ })];
315
+ });
316
+ });
317
+ };
257
318
  /**
258
319
  * This method returns the journeys that match the given parameters.
259
320
  * Note that it will always return the journeys for the one-way trip.
@@ -253,7 +253,7 @@ var TplBooking = /** @class */ (function (_super) {
253
253
  return __awaiter(this, void 0, void 0, function () {
254
254
  var searchParams, url;
255
255
  return __generator(this, function (_a) {
256
- searchParams = new URLSearchParams(__assign(__assign(__assign({ includeBasicInfo: "true", includeImage: "true", includeAreaIds: "false", includeTariffIds: "false", includeRouteIds: "false", includeMultilingualDescriptions: "false" }, (request.cityId && { cityId: request.cityId.toString() })), (request.tripId && { tripId: request.tripId.toString() })), (request.type && { type: request.type })));
256
+ searchParams = new URLSearchParams(__assign(__assign(__assign({ includeBasicInfo: "true", includeImage: "true", includeAreaIds: "false", includeTariffIds: "false", includeRouteIds: "false", includeMultilingualDescriptions: request.includeMultilingualDescriptions ? "true" : "false" }, (request.cityId && { cityId: request.cityId.toString() })), (request.tripId && { tripId: request.tripId.toString() })), (request.type && { type: request.type })));
257
257
  url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
258
258
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
259
259
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.superAreas;
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Booking } from "./booking/booking";
2
- export { JourneyBooking } from "./booking/journeyBooking";
2
+ export { JourneyBooking, EnrichedStop } from "./booking/journeyBooking";
3
3
  export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
5
  export { TplBooking } from "./booking/tplBooking";
@@ -27,7 +27,7 @@ export { Service, ServiceTrip } from "./types/services/Service";
27
27
  export { ServiceCart, ServiceBookingType } from "./types/services/ServiceCart";
28
28
  export { ServiceInfo } from "./types/services/ServiceInfo";
29
29
  export { GetTariffsResponse } from "./types/tpl/GetTariffsResponse";
30
- export { SuperArea, GetSuperAreasRequest, GetCitiesRequest, SuperAreasTypeFilter } from "./types/tpl/SuperArea";
30
+ export { SuperArea, MTSStringDTO, GetSuperAreasRequest, GetCitiesRequest, SuperAreasTypeFilter } from "./types/tpl/SuperArea";
31
31
  export { TplCart, TplBookingType, TplBookingInfo } from "./types/tpl/TplCart";
32
32
  export { Subscription } from "./types/subscriptions/Subscriptions";
33
33
  export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Multilingual string returned by the backend. Each key holds the
3
+ * translation for that language; consumers should fall back to `it`
4
+ * when the active language is missing, matching the backend's
5
+ * `MTSStringDTO.GetValue` resolution rules.
6
+ */
7
+ export type MTSStringDTO = {
8
+ en: string | null;
9
+ it: string | null;
10
+ fr: string | null;
11
+ de: string | null;
12
+ es: string | null;
13
+ };
1
14
  /** This type represents a super area. It is the return object of the {@link TplBooking.getSuperAreas} method. */
2
15
  export type SuperArea = {
3
16
  /** The id of the super area in the database */
@@ -12,6 +25,11 @@ export type SuperArea = {
12
25
  bookingProcessDescription: string;
13
26
  /** The url of the image of the super area */
14
27
  imageUrl: string;
28
+ /**
29
+ * LinkAvel-specific multilingual description. Only present when the
30
+ * request is made with `includeMultilingualDescriptions: true`.
31
+ */
32
+ linkAvelDescription?: MTSStringDTO;
15
33
  };
16
34
  export declare enum SuperAreasTypeFilter {
17
35
  /** No filter applied (default). */
@@ -33,6 +51,12 @@ export type GetSuperAreasRequest = {
33
51
  * A super area cannot simultaneously be a tour and a regular super area.
34
52
  */
35
53
  type?: SuperAreasTypeFilter;
54
+ /**
55
+ * When true, the response includes the multilingual `linkAvelDescription`
56
+ * field on each super area. Defaults to false to keep payloads minimal
57
+ * for callers that only need basic info.
58
+ */
59
+ includeMultilingualDescriptions?: boolean;
36
60
  };
37
61
  /** Request options for {@link TplBooking.getCities}. */
38
62
  export type GetCitiesRequest = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "3.5.0",
3
+ "version": "3.7.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",