onroute-policy-engine 1.1.0 → 1.3.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.
@@ -4,4 +4,5 @@ export { PermitAppInfo } from './permit-app-info';
4
4
  export { RelativePosition } from './relative-position';
5
5
  export { ValidationResultCode } from './validation-result-code';
6
6
  export { ValidationResultType } from './validation-result-type';
7
+ export { VehicleCategory } from './vehicle-category';
7
8
  export { VehicleTypes } from './vehicle-types';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VehicleTypes = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
3
+ exports.VehicleTypes = exports.VehicleCategory = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
4
4
  var accessory_vehicle_type_1 = require("./accessory-vehicle-type");
5
5
  Object.defineProperty(exports, "AccessoryVehicleType", { enumerable: true, get: function () { return accessory_vehicle_type_1.AccessoryVehicleType; } });
6
6
  var facts_1 = require("./facts");
@@ -14,5 +14,7 @@ var validation_result_code_1 = require("./validation-result-code");
14
14
  Object.defineProperty(exports, "ValidationResultCode", { enumerable: true, get: function () { return validation_result_code_1.ValidationResultCode; } });
15
15
  var validation_result_type_1 = require("./validation-result-type");
16
16
  Object.defineProperty(exports, "ValidationResultType", { enumerable: true, get: function () { return validation_result_type_1.ValidationResultType; } });
17
+ var vehicle_category_1 = require("./vehicle-category");
18
+ Object.defineProperty(exports, "VehicleCategory", { enumerable: true, get: function () { return vehicle_category_1.VehicleCategory; } });
17
19
  var vehicle_types_1 = require("./vehicle-types");
18
20
  Object.defineProperty(exports, "VehicleTypes", { enumerable: true, get: function () { return vehicle_types_1.VehicleTypes; } });
@@ -0,0 +1,4 @@
1
+ export declare enum VehicleCategory {
2
+ PowerUnit = "powerUnit",
3
+ Trailer = "trailer"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VehicleCategory = void 0;
4
+ var VehicleCategory;
5
+ (function (VehicleCategory) {
6
+ VehicleCategory["PowerUnit"] = "powerUnit";
7
+ VehicleCategory["Trailer"] = "trailer";
8
+ })(VehicleCategory || (exports.VehicleCategory = VehicleCategory = {}));
@@ -75,7 +75,7 @@ function addRuntimeFacts(engine, policy) {
75
75
  allowedVehicles = permitType.allowedVehicles;
76
76
  // Filter out long combination vehcles if necessary
77
77
  if (!policy.specialAuthorizations ||
78
- !policy.specialAuthorizations.lcv) {
78
+ !policy.specialAuthorizations.isLcvAllowed) {
79
79
  allowedVehicles =
80
80
  policy.filterOutLongCombinationVehicles(allowedVehicles);
81
81
  }
@@ -6,3 +6,11 @@ import { VehicleTypes } from '../types';
6
6
  * @returns
7
7
  */
8
8
  export declare function filterOutLcv(vehicleList: Array<string>, vehicleTypes: VehicleTypes): Array<string>;
9
+ /**
10
+ * Filters a list of vehicles to include only those matching the supplied
11
+ * vehicle type - either powerUnit or trailer.
12
+ * @param vehicleList List of vehicle IDs to filter
13
+ * @param vehicleTypes Configured vehicle types from policy configuration
14
+ * @param type Type of vehicle to filter, either powerUnit or trailer
15
+ */
16
+ export declare function filterVehiclesByType(vehicleList: Array<string>, vehicleTypes: VehicleTypes, type: string): Array<string>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterOutLcv = filterOutLcv;
4
+ exports.filterVehiclesByType = filterVehiclesByType;
5
+ const enum_1 = require("../enum");
4
6
  /**
5
7
  * Filters out all LCV vehicles from a supplied list of vehicle IDs.
6
8
  * @param vehicleList List of vehicle IDs to filter
@@ -26,3 +28,31 @@ function filterOutLcv(vehicleList, vehicleTypes) {
26
28
  });
27
29
  return filteredList;
28
30
  }
31
+ /**
32
+ * Filters a list of vehicles to include only those matching the supplied
33
+ * vehicle type - either powerUnit or trailer.
34
+ * @param vehicleList List of vehicle IDs to filter
35
+ * @param vehicleTypes Configured vehicle types from policy configuration
36
+ * @param type Type of vehicle to filter, either powerUnit or trailer
37
+ */
38
+ function filterVehiclesByType(vehicleList, vehicleTypes, type) {
39
+ if (type !== enum_1.VehicleCategory.PowerUnit.toString() &&
40
+ type !== enum_1.VehicleCategory.Trailer.toString()) {
41
+ throw new Error(`Cannot filter based on invalid type '${type}'`);
42
+ }
43
+ let targetVehicleTypes;
44
+ if (type === enum_1.VehicleCategory.PowerUnit) {
45
+ targetVehicleTypes = vehicleTypes.powerUnitTypes;
46
+ }
47
+ else {
48
+ targetVehicleTypes = vehicleTypes.trailerTypes;
49
+ }
50
+ if (!targetVehicleTypes) {
51
+ return new Array();
52
+ }
53
+ const filteredVehicles = vehicleList.filter((vid) => {
54
+ const vehicleDef = targetVehicleTypes.find((vt) => vt.id === vid);
55
+ return vehicleDef;
56
+ });
57
+ return filteredVehicles;
58
+ }
@@ -68,7 +68,7 @@ export declare class Policy {
68
68
  * other keyed on 'trailers'. Each map consists of a string id for the
69
69
  * vehicle, and a string common name for the vehicle.
70
70
  */
71
- getPermittableVehicleTypes(permitTypeId: string, commodityId: string): Map<string, Map<string, string>>;
71
+ getPermittableVehicleTypes(permitTypeId: string, commodityId?: string): Map<string, Map<string, string>>;
72
72
  /**
73
73
  * Gets a list of all allowable power unit types for the given permit type
74
74
  * and commodity.
@@ -163,4 +163,11 @@ export declare class Policy {
163
163
  * axle group in the vehicle configuration
164
164
  */
165
165
  calculateBridge(axleConfig: Array<AxleConfiguration>): Array<BridgeCalculationResult>;
166
+ /**
167
+ * Gets the list of allowed vehicles separated into two maps, one
168
+ * for trailers and one for power units. This will filter out LCV
169
+ * vehicles unless authorized in special authorizations.
170
+ * @param permitType Permit type definition
171
+ */
172
+ getAllowedVehicles(permitType: PermitType): Map<string, Map<string, string>>;
166
173
  }
@@ -73,8 +73,8 @@ class Policy {
73
73
  // Wrap the json-rules-engine result in a ValidationResult object
74
74
  const validationResults = new validation_results_1.ValidationResults(engineResult);
75
75
  // Include an informational message if the client is an LCV carrier
76
- if ((_a = this.specialAuthorizations) === null || _a === void 0 ? void 0 : _a.lcv) {
77
- validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.IsLcvCarrier, `Policy validation allowing long combination vahicle permitting for client '${this.specialAuthorizations.clientNumber}'`));
76
+ if ((_a = this.specialAuthorizations) === null || _a === void 0 ? void 0 : _a.isLcvAllowed) {
77
+ validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.IsLcvCarrier, `Policy validation allowing long combination vahicle permitting for client '${this.specialAuthorizations.companyId}'`));
78
78
  }
79
79
  return validationResults;
80
80
  }
@@ -169,21 +169,24 @@ class Policy {
169
169
  */
170
170
  getPermittableVehicleTypes(permitTypeId, commodityId) {
171
171
  var _a, _b, _c, _d, _e;
172
- if (!permitTypeId || !commodityId) {
173
- throw new Error('Missing permitTypeId and/or commodityId');
172
+ if (!permitTypeId) {
173
+ throw new Error('Missing permitTypeId');
174
174
  }
175
175
  const permitType = this.getPermitTypeDefinition(permitTypeId);
176
176
  if (!permitType) {
177
177
  throw new Error(`Invalid permit type: '${permitTypeId}'`);
178
178
  }
179
179
  if (!permitType.commodityRequired) {
180
- // If commodity is not required, this method cannot calculate the
181
- // permittable vehicle types since they will not be configured.
182
- throw new Error(`Permit type '${permitTypeId}' does not require a commodity`);
180
+ // If commodity is not required, get the permittable vehicle types
181
+ // from the permit allowedVehicles list.
182
+ return this.getAllowedVehicles(permitType);
183
183
  }
184
184
  let puTypes;
185
185
  let trTypes;
186
186
  const allowableCommodities = this.getCommodities(permitTypeId);
187
+ if (!commodityId) {
188
+ throw new Error('Missing commodityId, permit type requires it');
189
+ }
187
190
  if (!allowableCommodities.has(commodityId)) {
188
191
  // If the commodity is not allowed for the permit type, no power
189
192
  // units or trailers are allowed.
@@ -206,7 +209,7 @@ class Policy {
206
209
  let puTypeIdsOW = [];
207
210
  let trTypeIdsOW = [];
208
211
  // Remove long combination vehicles if needed
209
- if (!((_e = this.specialAuthorizations) === null || _e === void 0 ? void 0 : _e.lcv)) {
212
+ if (!((_e = this.specialAuthorizations) === null || _e === void 0 ? void 0 : _e.isLcvAllowed)) {
210
213
  if (puTypeIdsOS) {
211
214
  puTypeIdsOS = this.filterOutLongCombinationVehicles(puTypeIdsOS);
212
215
  }
@@ -346,7 +349,7 @@ class Policy {
346
349
  }
347
350
  }
348
351
  // Remove long combination vehicles if required
349
- if (!((_e = this.specialAuthorizations) === null || _e === void 0 ? void 0 : _e.lcv)) {
352
+ if (!((_e = this.specialAuthorizations) === null || _e === void 0 ? void 0 : _e.isLcvAllowed)) {
350
353
  if (vehicleTypeIds) {
351
354
  vehicleTypeIds = this.filterOutLongCombinationVehicles(vehicleTypeIds);
352
355
  }
@@ -393,7 +396,8 @@ class Policy {
393
396
  // invalid as a complete configuration.
394
397
  return validatePartial;
395
398
  }
396
- if (!this.specialAuthorizations || !this.specialAuthorizations.lcv) {
399
+ if (!this.specialAuthorizations ||
400
+ !this.specialAuthorizations.isLcvAllowed) {
397
401
  // No provision for allowing long combination vehicles
398
402
  const filteredConfiguration = this.filterOutLongCombinationVehicles(currentConfiguration);
399
403
  if (filteredConfiguration.length !== currentConfiguration.length) {
@@ -708,5 +712,32 @@ class Policy {
708
712
  }
709
713
  return bridgeResults;
710
714
  }
715
+ /**
716
+ * Gets the list of allowed vehicles separated into two maps, one
717
+ * for trailers and one for power units. This will filter out LCV
718
+ * vehicles unless authorized in special authorizations.
719
+ * @param permitType Permit type definition
720
+ */
721
+ getAllowedVehicles(permitType) {
722
+ if (permitType.commodityRequired) {
723
+ // If commodity is required, this method cannot be used since it
724
+ // requires a fixed set of allowed vehicle types, not commodity-based
725
+ throw new Error(`Allowed vehicles not configured for permit type requiring commodity: '${permitType.id}'`);
726
+ }
727
+ let allowedVehicles = permitType.allowedVehicles;
728
+ if (!allowedVehicles) {
729
+ return new Map();
730
+ }
731
+ if (!this.specialAuthorizations ||
732
+ !this.specialAuthorizations.isLcvAllowed) {
733
+ allowedVehicles = this.filterOutLongCombinationVehicles(allowedVehicles);
734
+ }
735
+ const allowedVehicleMap = new Map();
736
+ const powerUnitIds = (0, vehicles_helper_1.filterVehiclesByType)(allowedVehicles, this.policyDefinition.vehicleTypes, enum_1.VehicleCategory.PowerUnit);
737
+ const trailerIds = (0, vehicles_helper_1.filterVehiclesByType)(allowedVehicles, this.policyDefinition.vehicleTypes, enum_1.VehicleCategory.Trailer);
738
+ allowedVehicleMap.set(enum_1.VehicleTypes.PowerUnits, (0, lists_helper_1.extractIdentifiedObjects)(this.policyDefinition.vehicleTypes.powerUnitTypes, powerUnitIds));
739
+ allowedVehicleMap.set(enum_1.VehicleTypes.Trailers, (0, lists_helper_1.extractIdentifiedObjects)(this.policyDefinition.vehicleTypes.trailerTypes, trailerIds));
740
+ return allowedVehicleMap;
741
+ }
711
742
  }
712
743
  exports.Policy = Policy;
@@ -1,5 +1,5 @@
1
1
  export type SpecialAuthorizations = {
2
- clientNumber: string;
3
- lcv?: boolean;
4
- noFee?: boolean;
2
+ companyId: number;
3
+ isLcvAllowed?: boolean;
4
+ noFeeType?: string;
5
5
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v1.1.0";
1
+ export declare const version = "v1.3.0";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = 'v1.1.0';
5
+ exports.version = 'v1.3.0';
package/package.json CHANGED
@@ -89,5 +89,5 @@
89
89
  ],
90
90
  "testEnvironment": "node"
91
91
  },
92
- "version": "v1.1.0"
92
+ "version": "v1.3.0"
93
93
  }