@opentripplanner/core-utils 15.0.0 → 16.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.
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +104 -78
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +2 -2
- package/esm/map.js.map +1 -1
- package/esm/query-gen.js +9 -5
- package/esm/query-gen.js.map +1 -1
- package/esm/route.js +26 -20
- package/esm/route.js.map +1 -1
- package/esm/storage.js +4 -1
- package/esm/storage.js.map +1 -1
- package/esm/time.js +6 -5
- package/esm/time.js.map +1 -1
- package/esm/ui.js +4 -2
- package/esm/ui.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts +20 -11
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +96 -85
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +2 -2
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +1 -1
- package/lib/map.js.map +1 -1
- package/lib/query-gen.d.ts +1 -19
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +9 -5
- package/lib/query-gen.js.map +1 -1
- package/lib/route.d.ts +10 -8
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +22 -16
- package/lib/route.js.map +1 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.d.ts.map +1 -1
- package/lib/storage.js +4 -1
- package/lib/storage.js.map +1 -1
- package/lib/time.d.ts +3 -1
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +5 -4
- package/lib/time.js.map +1 -1
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +4 -2
- package/lib/ui.js.map +1 -1
- package/package.json +9 -7
- package/src/__tests__/itinerary.ts +64 -6
- package/src/index.ts +3 -0
- package/src/itinerary.ts +145 -97
- package/src/map.ts +5 -3
- package/src/query-gen.ts +15 -9
- package/src/route.ts +65 -38
- package/src/storage.ts +8 -2
- package/src/time.ts +7 -6
- package/src/ui.ts +8 -6
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/esm/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as itinerary from "./itinerary";
|
|
2
2
|
import * as map from "./map";
|
|
3
|
+
// @ts-expect-error not typed
|
|
3
4
|
import * as profile from "./profile";
|
|
5
|
+
// @ts-expect-error not typed
|
|
4
6
|
import * as query from "./query";
|
|
7
|
+
// @ts-expect-error not typed
|
|
5
8
|
import * as queryParams from "./query-params";
|
|
6
9
|
import * as route from "./route";
|
|
7
10
|
import * as storage from "./storage";
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["itinerary","map","profile","query","queryParams","route","storage","time","ui","queryGen","SafeSuspense","core"],"sources":["../src/index.ts"],"sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\nimport * as profile from \"./profile\";\nimport * as query from \"./query\";\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\nimport * as queryGen from \"./query-gen\";\nimport SafeSuspense from \"./suspense\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryGen,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport { SafeSuspense };\nexport default core;\n"],"mappings":"AAAA,OAAO,KAAKA,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,GAAG,MAAM,OAAO;AAC5B,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,KAAK,MAAM,SAAS;AAChC,OAAO,KAAKC,WAAW,MAAM,gBAAgB;AAC7C,OAAO,KAAKC,KAAK,MAAM,SAAS;AAChC,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,IAAI,MAAM,QAAQ;AAC9B,OAAO,KAAKC,EAAE,MAAM,MAAM;AAC1B,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,OAAOC,YAAY,MAAM,YAAY;AAErC,IAAMC,IAAI,GAAG;EACXX,SAAS,EAATA,SAAS;EACTC,GAAG,EAAHA,GAAG;EACHC,OAAO,EAAPA,OAAO;EACPC,KAAK,EAALA,KAAK;EACLM,QAAQ,EAARA,QAAQ;EACRL,WAAW,EAAXA,WAAW;EACXC,KAAK,EAALA,KAAK;EACLC,OAAO,EAAPA,OAAO;EACPC,IAAI,EAAJA,IAAI;EACJC,EAAE,EAAFA;AACF,CAAC;AAED,SAASE,YAAY;AACrB,eAAeC,IAAI","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["itinerary","map","profile","query","queryParams","route","storage","time","ui","queryGen","SafeSuspense","core"],"sources":["../src/index.ts"],"sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\n// @ts-expect-error not typed\nimport * as profile from \"./profile\";\n// @ts-expect-error not typed\nimport * as query from \"./query\";\n// @ts-expect-error not typed\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\nimport * as queryGen from \"./query-gen\";\nimport SafeSuspense from \"./suspense\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryGen,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport { SafeSuspense };\nexport default core;\n"],"mappings":"AAAA,OAAO,KAAKA,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,GAAG,MAAM,OAAO;AAC5B;AACA,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC;AACA,OAAO,KAAKC,KAAK,MAAM,SAAS;AAChC;AACA,OAAO,KAAKC,WAAW,MAAM,gBAAgB;AAC7C,OAAO,KAAKC,KAAK,MAAM,SAAS;AAChC,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,IAAI,MAAM,QAAQ;AAC9B,OAAO,KAAKC,EAAE,MAAM,MAAM;AAC1B,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,OAAOC,YAAY,MAAM,YAAY;AAErC,IAAMC,IAAI,GAAG;EACXX,SAAS,EAATA,SAAS;EACTC,GAAG,EAAHA,GAAG;EACHC,OAAO,EAAPA,OAAO;EACPC,KAAK,EAALA,KAAK;EACLM,QAAQ,EAARA,QAAQ;EACRL,WAAW,EAAXA,WAAW;EACXC,KAAK,EAALA,KAAK;EACLC,OAAO,EAAPA,OAAO;EACPC,IAAI,EAAJA,IAAI;EACJC,EAAE,EAAFA;AACF,CAAC;AAED,SAASE,YAAY;AACrB,eAAeC,IAAI","ignoreList":[]}
|
package/esm/itinerary.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -58,10 +59,11 @@ export function legContainsGeometry(leg) {
|
|
|
58
59
|
}
|
|
59
60
|
export function isAdvanceBookingRequired(info) {
|
|
60
61
|
var _info$latestBookingTi;
|
|
61
|
-
|
|
62
|
+
var daysPrior = info === null || info === void 0 || (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior;
|
|
63
|
+
return typeof daysPrior === "number" && daysPrior > 0;
|
|
62
64
|
}
|
|
63
65
|
export function legDropoffRequiresAdvanceBooking(leg) {
|
|
64
|
-
return isAdvanceBookingRequired(leg
|
|
66
|
+
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -166,6 +168,7 @@ export function hasRental(modesStr) {
|
|
|
166
168
|
});
|
|
167
169
|
}
|
|
168
170
|
export function getMapColor(mode) {
|
|
171
|
+
// @ts-expect-error this is not typed
|
|
169
172
|
mode = mode || this.get("mode");
|
|
170
173
|
if (mode === "WALK") return "#444";
|
|
171
174
|
if (mode === "BICYCLE") return "#0073e5";
|
|
@@ -199,14 +202,15 @@ export function getCompanyFromLeg(leg) {
|
|
|
199
202
|
rentedCar = leg.rentedCar,
|
|
200
203
|
rentedVehicle = leg.rentedVehicle,
|
|
201
204
|
rideHailingEstimate = leg.rideHailingEstimate;
|
|
205
|
+
var firstNetwork = Array.isArray(from.networks) && from.networks.length > 0 ? from.networks[0] : null;
|
|
202
206
|
if (mode === "CAR" && rentedCar) {
|
|
203
|
-
return
|
|
207
|
+
return firstNetwork;
|
|
204
208
|
}
|
|
205
209
|
if (mode === "CAR" && rideHailingEstimate) {
|
|
206
210
|
return rideHailingEstimate.provider.id;
|
|
207
211
|
}
|
|
208
|
-
if (mode === "BICYCLE" && rentedBike
|
|
209
|
-
return
|
|
212
|
+
if (mode === "BICYCLE" && rentedBike) {
|
|
213
|
+
return firstNetwork;
|
|
210
214
|
}
|
|
211
215
|
if (from.rentalVehicle) {
|
|
212
216
|
return from.rentalVehicle.network;
|
|
@@ -214,8 +218,8 @@ export function getCompanyFromLeg(leg) {
|
|
|
214
218
|
if ((_from$vehicleRentalSt = from.vehicleRentalStation) !== null && _from$vehicleRentalSt !== void 0 && _from$vehicleRentalSt.rentalNetwork) {
|
|
215
219
|
return from.vehicleRentalStation.rentalNetwork.networkId;
|
|
216
220
|
}
|
|
217
|
-
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle
|
|
218
|
-
return
|
|
221
|
+
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle) {
|
|
222
|
+
return firstNetwork;
|
|
219
223
|
}
|
|
220
224
|
return null;
|
|
221
225
|
}
|
|
@@ -225,7 +229,7 @@ export function getItineraryBounds(itinerary) {
|
|
|
225
229
|
var legCoords = polyline.toGeoJSON(leg.legGeometry.points).coordinates.map(function (c) {
|
|
226
230
|
return [c[1], c[0]];
|
|
227
231
|
});
|
|
228
|
-
coords
|
|
232
|
+
coords.push.apply(coords, _toConsumableArray(legCoords));
|
|
229
233
|
});
|
|
230
234
|
return coords;
|
|
231
235
|
}
|
|
@@ -248,51 +252,50 @@ export function getLegBounds(leg) {
|
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
251
|
-
|
|
252
255
|
export function legLocationAtDistance(leg, distance) {
|
|
253
|
-
if (!leg.legGeometry) return
|
|
256
|
+
if (!leg.legGeometry) return undefined;
|
|
254
257
|
try {
|
|
258
|
+
var _pt$geometry;
|
|
255
259
|
var line = polyline.toGeoJSON(leg.legGeometry.points);
|
|
256
260
|
var pt = turfAlong(line, distance, {
|
|
257
261
|
units: "meters"
|
|
258
262
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// FIXME handle error!
|
|
263
|
+
var coords = pt === null || pt === void 0 || (_pt$geometry = pt.geometry) === null || _pt$geometry === void 0 ? void 0 : _pt$geometry.coordinates;
|
|
264
|
+
return [coords[1], coords[0]];
|
|
265
|
+
} catch (_unused) {
|
|
266
|
+
// This is designed to catch the toGeoJSON from throwing if the geometry is not in the correct format
|
|
264
267
|
}
|
|
265
268
|
return null;
|
|
266
269
|
}
|
|
267
270
|
|
|
268
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Returns an interpolated elevation at a specified distance along a leg
|
|
273
|
+
* @param points - The points of the elevation profile. Each point is a tuple of [distance, elevation].
|
|
274
|
+
* @param distance - The distance along the leg to interpolate the elevation at
|
|
275
|
+
* @returns The interpolated elevation at the specified distance
|
|
276
|
+
*/
|
|
269
277
|
|
|
270
278
|
export function legElevationAtDistance(points, distance) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (distance >=
|
|
282
|
-
|
|
283
|
-
// compute & return interpolated elevation value
|
|
284
|
-
if (start[1] === null) {
|
|
285
|
-
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
var pct = (distance - traversed) / elevDistanceSpan;
|
|
289
|
-
var elevSpan = points[i][1] - start[1];
|
|
290
|
-
return start[1] + elevSpan * pct;
|
|
279
|
+
var elevation = points.reduce(function (acc, point, index) {
|
|
280
|
+
var prevPoint = points[index - 1];
|
|
281
|
+
// at the first index there is no previous point
|
|
282
|
+
if (!prevPoint) return acc;
|
|
283
|
+
var _point = _slicedToArray(point, 2),
|
|
284
|
+
pointDistance = _point[0],
|
|
285
|
+
pointElevation = _point[1];
|
|
286
|
+
var _prevPoint = _slicedToArray(prevPoint, 2),
|
|
287
|
+
prevPointDistance = _prevPoint[0],
|
|
288
|
+
prevPointElevation = _prevPoint[1];
|
|
289
|
+
if (distance >= prevPointDistance && distance <= pointDistance) {
|
|
290
|
+
return prevPointElevation + (pointElevation - prevPointElevation) * (distance - prevPointDistance) / (pointDistance - prevPointDistance);
|
|
291
291
|
}
|
|
292
|
-
|
|
292
|
+
return acc;
|
|
293
|
+
}, undefined);
|
|
294
|
+
if (elevation === undefined) {
|
|
295
|
+
console.warn("Elevation value does not exist for distance.", distance);
|
|
296
|
+
return undefined;
|
|
293
297
|
}
|
|
294
|
-
|
|
295
|
-
return null;
|
|
298
|
+
return elevation;
|
|
296
299
|
}
|
|
297
300
|
export function mapOldElevationComponentToNew(oldElev) {
|
|
298
301
|
return {
|
|
@@ -365,6 +368,7 @@ export function getTextWidth(text) {
|
|
|
365
368
|
// reuse canvas object for better performance
|
|
366
369
|
var canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
|
367
370
|
var context = canvas.getContext("2d");
|
|
371
|
+
if (!context) return 0;
|
|
368
372
|
context.font = font;
|
|
369
373
|
var metrics = context.measureText(text);
|
|
370
374
|
return metrics.width;
|
|
@@ -430,18 +434,16 @@ export function calculatePhysicalActivity(itinerary) {
|
|
|
430
434
|
*/
|
|
431
435
|
export function calculateTncFares(itinerary) {
|
|
432
436
|
return itinerary.legs.filter(function (leg) {
|
|
433
|
-
return leg.mode === "CAR" && leg.rideHailingEstimate;
|
|
434
|
-
}).reduce(function (
|
|
435
|
-
var
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
var minPrice = rideHailingEstimate.minPrice,
|
|
439
|
-
maxPrice = rideHailingEstimate.maxPrice;
|
|
437
|
+
return leg.mode === "CAR" && leg.rideHailingEstimate !== undefined;
|
|
438
|
+
}).reduce(function (acc, leg) {
|
|
439
|
+
var _leg$rideHailingEstim2 = leg.rideHailingEstimate,
|
|
440
|
+
minPrice = _leg$rideHailingEstim2.minPrice,
|
|
441
|
+
maxPrice = _leg$rideHailingEstim2.maxPrice;
|
|
440
442
|
return {
|
|
441
443
|
// Assumes a single currency for entire itinerary.
|
|
442
444
|
currencyCode: minPrice.currency.code,
|
|
443
|
-
maxTNCFare: maxTNCFare + maxPrice.amount,
|
|
444
|
-
minTNCFare: minTNCFare + minPrice.amount
|
|
445
|
+
maxTNCFare: acc.maxTNCFare + maxPrice.amount,
|
|
446
|
+
minTNCFare: acc.minTNCFare + minPrice.amount
|
|
445
447
|
};
|
|
446
448
|
}, {
|
|
447
449
|
currencyCode: null,
|
|
@@ -539,7 +541,6 @@ export var zeroDollars = function zeroDollars(currency) {
|
|
|
539
541
|
currency: currency
|
|
540
542
|
};
|
|
541
543
|
};
|
|
542
|
-
|
|
543
544
|
/**
|
|
544
545
|
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
545
546
|
* @param leg Leg with Fares v2 information
|
|
@@ -555,9 +556,9 @@ export function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
555
556
|
if (!leg.fareProducts) return {
|
|
556
557
|
price: undefined
|
|
557
558
|
};
|
|
558
|
-
var relevantFareProducts = leg.fareProducts.filter(function (
|
|
559
|
+
var relevantFareProducts = leg.fareProducts.filter(function (_ref) {
|
|
559
560
|
var _product$riderCategor, _product$riderCategor2, _product$medium, _product$medium2;
|
|
560
|
-
var product =
|
|
561
|
+
var product = _ref.product;
|
|
561
562
|
// riderCategory and medium can be specifically defined as null to handle
|
|
562
563
|
// generic GTFS based fares from OTP when there is no fare model
|
|
563
564
|
|
|
@@ -567,13 +568,18 @@ export function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
567
568
|
return productRiderCategoryId === riderCategoryId && productMediaId === mediumId && (// Make sure there's a price
|
|
568
569
|
// Some fare products don't have a price at all.
|
|
569
570
|
product === null || product === void 0 ? void 0 : product.price);
|
|
571
|
+
})
|
|
572
|
+
// Make sure there's a price
|
|
573
|
+
// Some fare products don't have a price at all.
|
|
574
|
+
.filter(function (fare) {
|
|
575
|
+
var _fare$product;
|
|
576
|
+
return ((_fare$product = fare.product) === null || _fare$product === void 0 ? void 0 : _fare$product.price) !== undefined;
|
|
570
577
|
}).map(function (fare) {
|
|
571
|
-
var alreadySeen = (seenFareIds === null || seenFareIds === void 0 ? void 0 : seenFareIds.indexOf(fare.id)) > -1;
|
|
572
|
-
var currency = fare.product.price.currency;
|
|
578
|
+
var alreadySeen = !!seenFareIds && (seenFareIds === null || seenFareIds === void 0 ? void 0 : seenFareIds.indexOf(fare.id)) > -1;
|
|
573
579
|
return {
|
|
574
580
|
id: fare.id,
|
|
575
581
|
product: _objectSpread(_objectSpread({}, fare.product), {}, {
|
|
576
|
-
legPrice: alreadySeen ? zeroDollars(currency) : fare.product.price
|
|
582
|
+
legPrice: alreadySeen && fare.product.price ? zeroDollars(fare.product.price.currency) : fare.product.price
|
|
577
583
|
})
|
|
578
584
|
};
|
|
579
585
|
}).sort(function (a, b) {
|
|
@@ -604,37 +610,47 @@ export function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
604
610
|
* @param category Rider category (youth, regular, senior)
|
|
605
611
|
* @param container Fare container (cash, electronic)
|
|
606
612
|
* @param seenFareIds List of fare product IDs that have already been seen on prev legs.
|
|
613
|
+
* @param nulledTotalFareOnAnyMissingFare If this is set to true, the total fare
|
|
614
|
+
* will be null if *any* fare is missing. If false, the total will be the total
|
|
615
|
+
* fare with the missing fares ignored.
|
|
607
616
|
* @returns Money object for the total itinerary cost.
|
|
608
617
|
*/
|
|
609
618
|
export function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
610
|
-
|
|
619
|
+
var nulledTotalFareOnAnyMissingFare = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
611
620
|
if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
currency: null
|
|
619
|
-
};
|
|
620
|
-
for (var i = 0; i < mediumId.length; i++) {
|
|
621
|
-
var newCost = getItineraryCost(legs, mediumId[i], riderCategoryId[i]);
|
|
622
|
-
if (newCost) {
|
|
623
|
-
var _total, _total$currency;
|
|
624
|
-
total = {
|
|
625
|
-
amount: ((_total = total) === null || _total === void 0 ? void 0 : _total.amount) + ((newCost === null || newCost === void 0 ? void 0 : newCost.amount) || 0),
|
|
626
|
-
currency: (_total$currency = total.currency) !== null && _total$currency !== void 0 ? _total$currency : newCost === null || newCost === void 0 ? void 0 : newCost.currency
|
|
627
|
-
};
|
|
621
|
+
// TODO: Better input type handling
|
|
622
|
+
if (Array.isArray(mediumId) && Array.isArray(riderCategoryId)) {
|
|
623
|
+
var _total$currency;
|
|
624
|
+
if (mediumId.length !== riderCategoryId.length) {
|
|
625
|
+
console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
|
|
626
|
+
return getItineraryCost(legs, mediumId[0], riderCategoryId[0]);
|
|
628
627
|
}
|
|
628
|
+
var total = mediumId.reduce(function (acc, currentMediumId, index) {
|
|
629
|
+
var _newCost$currency;
|
|
630
|
+
var newCost = getItineraryCost(legs, currentMediumId, riderCategoryId[index]);
|
|
631
|
+
if (!newCost) return acc;
|
|
632
|
+
return {
|
|
633
|
+
amount: acc.amount + (newCost.amount || 0),
|
|
634
|
+
currency: acc.currency.code !== "" ? acc.currency : (_newCost$currency = newCost.currency) !== null && _newCost$currency !== void 0 ? _newCost$currency : acc.currency
|
|
635
|
+
};
|
|
636
|
+
}, {
|
|
637
|
+
amount: 0,
|
|
638
|
+
currency: {
|
|
639
|
+
code: "",
|
|
640
|
+
digits: 0
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
if (!((_total$currency = total.currency) !== null && _total$currency !== void 0 && _total$currency.code)) return undefined;
|
|
644
|
+
return total;
|
|
629
645
|
}
|
|
630
|
-
|
|
631
|
-
return
|
|
646
|
+
console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
|
|
647
|
+
return undefined;
|
|
632
648
|
}
|
|
633
649
|
var legCosts = legs
|
|
634
650
|
// Only legs with fares (no walking legs)
|
|
635
651
|
.filter(function (leg) {
|
|
636
652
|
var _leg$fareProducts;
|
|
637
|
-
return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
|
|
653
|
+
return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) && leg.fareProducts.length > 0;
|
|
638
654
|
})
|
|
639
655
|
// Get the leg cost object of each leg
|
|
640
656
|
.reduce(function (acc, leg) {
|
|
@@ -646,6 +662,7 @@ export function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
646
662
|
appliedFareProduct = _getLegCost.appliedFareProduct,
|
|
647
663
|
productUseId = _getLegCost.productUseId;
|
|
648
664
|
if (!appliedFareProduct) return acc;
|
|
665
|
+
if (!productUseId) return acc;
|
|
649
666
|
return {
|
|
650
667
|
legCosts: [].concat(_toConsumableArray(acc.legCosts), [appliedFareProduct]),
|
|
651
668
|
seenIds: [].concat(_toConsumableArray(acc.seenIds), [productUseId])
|
|
@@ -656,17 +673,26 @@ export function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
656
673
|
}).legCosts.map(function (lc) {
|
|
657
674
|
return lc.legPrice;
|
|
658
675
|
});
|
|
676
|
+
if (nulledTotalFareOnAnyMissingFare && legs.filter(function (l) {
|
|
677
|
+
return l.transitLeg;
|
|
678
|
+
}).length !== legCosts.length) {
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
659
681
|
if (legCosts.length === 0) return undefined;
|
|
660
682
|
// Calculate the total
|
|
661
683
|
return legCosts.reduce(function (prev, cur) {
|
|
662
|
-
var _prev$currency;
|
|
663
684
|
return {
|
|
664
685
|
amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
|
|
665
|
-
currency:
|
|
686
|
+
currency: prev.currency.code !== "" ? prev.currency : cur.currency
|
|
666
687
|
};
|
|
667
|
-
},
|
|
688
|
+
},
|
|
689
|
+
// eslint-disable-next-line prettier/prettier -- old eslint doesn't know satisfies
|
|
690
|
+
{
|
|
668
691
|
amount: 0,
|
|
669
|
-
currency:
|
|
692
|
+
currency: {
|
|
693
|
+
code: "",
|
|
694
|
+
digits: 0
|
|
695
|
+
}
|
|
670
696
|
});
|
|
671
697
|
}
|
|
672
698
|
var pickupDropoffTypeToOtp1 = function pickupDropoffTypeToOtp1(otp2Type) {
|