mts-booking-library 3.5.0 → 3.6.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.
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",