onroute-policy-engine 1.6.3 → 1.6.5
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.
|
@@ -9,4 +9,5 @@ var ValidationResultCode;
|
|
|
9
9
|
ValidationResultCode["GeneralResult"] = "general-result";
|
|
10
10
|
ValidationResultCode["CostValue"] = "cost-value";
|
|
11
11
|
ValidationResultCode["IsLcvCarrier"] = "lcv-carrier";
|
|
12
|
+
ValidationResultCode["NoFeeClient"] = "no-fee-client";
|
|
12
13
|
})(ValidationResultCode || (exports.ValidationResultCode = ValidationResultCode = {}));
|
|
@@ -44,15 +44,15 @@ function addRuntimeFacts(engine, policy) {
|
|
|
44
44
|
* commodity. Will return true or false.
|
|
45
45
|
*/
|
|
46
46
|
engine.addFact(enum_1.PolicyFacts.ConfigurationIsValid.toString(), async function (params, almanac) {
|
|
47
|
-
const powerUnit = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PowerUnitType);
|
|
48
|
-
const trailerList = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TrailerList);
|
|
49
|
-
let fullVehicleConfiguration = [];
|
|
50
|
-
fullVehicleConfiguration.push(powerUnit);
|
|
51
|
-
fullVehicleConfiguration = fullVehicleConfiguration.concat(trailerList.map((t) => t.vehicleSubType));
|
|
52
|
-
const permitType = await almanac.factValue(enum_1.PermitAppInfo.PermitType);
|
|
53
|
-
const commodity = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.Commodity);
|
|
54
47
|
let isValid;
|
|
55
48
|
try {
|
|
49
|
+
const powerUnit = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PowerUnitType);
|
|
50
|
+
const trailerList = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TrailerList);
|
|
51
|
+
let fullVehicleConfiguration = [];
|
|
52
|
+
fullVehicleConfiguration.push(powerUnit);
|
|
53
|
+
fullVehicleConfiguration = fullVehicleConfiguration.concat(trailerList.map((t) => t.vehicleSubType));
|
|
54
|
+
const permitType = await almanac.factValue(enum_1.PermitAppInfo.PermitType);
|
|
55
|
+
const commodity = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.Commodity);
|
|
56
56
|
isValid = policy.isConfigurationValid(permitType, commodity, fullVehicleConfiguration);
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
package/dist/policy-engine.js
CHANGED
|
@@ -55,7 +55,7 @@ class Policy {
|
|
|
55
55
|
* @returns Results of the validation of the permit application
|
|
56
56
|
*/
|
|
57
57
|
async validate(permit) {
|
|
58
|
-
var _a;
|
|
58
|
+
var _a, _b;
|
|
59
59
|
const engine = this.rulesEngines.get(permit.permitType);
|
|
60
60
|
if (!engine) {
|
|
61
61
|
// If the permit type being validated has no configuration in the
|
|
@@ -75,7 +75,19 @@ class Policy {
|
|
|
75
75
|
const validationResults = new validation_results_1.ValidationResults(engineResult);
|
|
76
76
|
// Include an informational message if the client is an LCV carrier
|
|
77
77
|
if ((_a = this.specialAuthorizations) === null || _a === void 0 ? void 0 : _a.isLcvAllowed) {
|
|
78
|
-
validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.IsLcvCarrier, `Policy validation allowing long combination
|
|
78
|
+
validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.IsLcvCarrier, `Policy validation allowing long combination vehicle permitting for client '${this.specialAuthorizations.companyId}'`));
|
|
79
|
+
}
|
|
80
|
+
// Include an informational message and adjust the cost if the client
|
|
81
|
+
// has a no fee flag set.
|
|
82
|
+
if ((_b = this.specialAuthorizations) === null || _b === void 0 ? void 0 : _b.noFeeType) {
|
|
83
|
+
const originalPermitCost = validationResults === null || validationResults === void 0 ? void 0 : validationResults.cost.reduce((accumulator, { cost }) => accumulator + (cost !== null && cost !== void 0 ? cost : 0), 0);
|
|
84
|
+
// Clear the cost array and replace with zero cost
|
|
85
|
+
validationResults.cost.length = 0;
|
|
86
|
+
const newPermitCostResult = new validation_result_1.ValidationResult(enum_1.ValidationResultType.Cost, enum_1.ValidationResultCode.CostValue, 'Calculated permit cost');
|
|
87
|
+
newPermitCostResult.cost = 0;
|
|
88
|
+
validationResults.cost.push(newPermitCostResult);
|
|
89
|
+
// Add an informational message to the results
|
|
90
|
+
validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.NoFeeClient, `Client '${this.specialAuthorizations.companyId}' has no fee flag, original permit cost would otherwise be '${originalPermitCost}'`));
|
|
79
91
|
}
|
|
80
92
|
return validationResults;
|
|
81
93
|
}
|
|
@@ -322,7 +334,17 @@ class Policy {
|
|
|
322
334
|
}
|
|
323
335
|
else {
|
|
324
336
|
const powerUnit = (_d = (_c = commodity.size) === null || _c === void 0 ? void 0 : _c.powerUnits) === null || _d === void 0 ? void 0 : _d.find((p) => p.type == currentConfiguration[0]);
|
|
325
|
-
|
|
337
|
+
let validTrailers;
|
|
338
|
+
// ORV2-3953
|
|
339
|
+
// If a jeep has been added, only add trailers that
|
|
340
|
+
// permit jeeps from the trailer list
|
|
341
|
+
if (currentConfiguration.includes(enum_1.AccessoryVehicleType.Jeep)) {
|
|
342
|
+
validTrailers = powerUnit === null || powerUnit === void 0 ? void 0 : powerUnit.trailers.filter((t) => t.jeep);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
validTrailers = powerUnit === null || powerUnit === void 0 ? void 0 : powerUnit.trailers;
|
|
346
|
+
}
|
|
347
|
+
const trailerIds = validTrailers === null || validTrailers === void 0 ? void 0 : validTrailers.map((t) => t.type);
|
|
326
348
|
if (currentConfiguration.length == 1) {
|
|
327
349
|
// Just a power unit, return the list of trailerIds for the
|
|
328
350
|
// power unit, plus jeep if any of the trailer Ids allow
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "v1.6.
|
|
1
|
+
export declare const version = "v1.6.5";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED