onroute-policy-engine 0.5.0 → 0.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.
@@ -1,11 +1,14 @@
1
1
  export declare enum PolicyFacts {
2
2
  AllowedVehicles = "allowedVehicles",
3
- ConditionalFixedCost = "conditionalFixedCost",
4
3
  DaysInPermitYear = "daysInPermitYear",
5
4
  EndOfPermitQuarter = "endOfPermitQuarter",
6
5
  ValidationDate = "validationDate",
6
+ ConfigurationIsValid = "configurationIsValid"
7
+ }
8
+ export declare enum CostFacts {
9
+ ConditionalFixedCost = "conditionalFixedCost",
7
10
  FixedCost = "fixedCost",
8
11
  CostPerMonth = "costPerMonth",
9
- RangeMatrixCostLookup = "rangeMatrixCostLookup",
10
- ConfigurationIsValid = "configurationIsValid"
12
+ CostPerKilometre = "costPerKilometre",
13
+ RangeMatrixCostLookup = "rangeMatrixCostLookup"
11
14
  }
@@ -1,15 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PolicyFacts = void 0;
3
+ exports.CostFacts = exports.PolicyFacts = void 0;
4
4
  var PolicyFacts;
5
5
  (function (PolicyFacts) {
6
6
  PolicyFacts["AllowedVehicles"] = "allowedVehicles";
7
- PolicyFacts["ConditionalFixedCost"] = "conditionalFixedCost";
8
7
  PolicyFacts["DaysInPermitYear"] = "daysInPermitYear";
9
8
  PolicyFacts["EndOfPermitQuarter"] = "endOfPermitQuarter";
10
9
  PolicyFacts["ValidationDate"] = "validationDate";
11
- PolicyFacts["FixedCost"] = "fixedCost";
12
- PolicyFacts["CostPerMonth"] = "costPerMonth";
13
- PolicyFacts["RangeMatrixCostLookup"] = "rangeMatrixCostLookup";
14
10
  PolicyFacts["ConfigurationIsValid"] = "configurationIsValid";
15
11
  })(PolicyFacts || (exports.PolicyFacts = PolicyFacts = {}));
12
+ var CostFacts;
13
+ (function (CostFacts) {
14
+ CostFacts["ConditionalFixedCost"] = "conditionalFixedCost";
15
+ CostFacts["FixedCost"] = "fixedCost";
16
+ CostFacts["CostPerMonth"] = "costPerMonth";
17
+ CostFacts["CostPerKilometre"] = "costPerKilometre";
18
+ CostFacts["RangeMatrixCostLookup"] = "rangeMatrixCostLookup";
19
+ })(CostFacts || (exports.CostFacts = CostFacts = {}));
@@ -1,5 +1,5 @@
1
1
  export { AccessoryVehicleType } from './accessory-vehicle-type';
2
- export { PolicyFacts } from './facts';
2
+ export { PolicyFacts, CostFacts } from './facts';
3
3
  export { PermitAppInfo } from './permit-app-info';
4
4
  export { RelativePosition } from './relative-position';
5
5
  export { ValidationResultCode } from './validation-result-code';
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VehicleTypes = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
3
+ exports.VehicleTypes = 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");
7
7
  Object.defineProperty(exports, "PolicyFacts", { enumerable: true, get: function () { return facts_1.PolicyFacts; } });
8
+ Object.defineProperty(exports, "CostFacts", { enumerable: true, get: function () { return facts_1.CostFacts; } });
8
9
  var permit_app_info_1 = require("./permit-app-info");
9
10
  Object.defineProperty(exports, "PermitAppInfo", { enumerable: true, get: function () { return permit_app_info_1.PermitAppInfo; } });
10
11
  var relative_position_1 = require("./relative-position");
@@ -12,5 +12,6 @@ export declare enum PermitAppInfo {
12
12
  PermitDuration = "$.permitDuration",
13
13
  PowerUnitType = "$.vehicleDetails.vehicleSubType",
14
14
  TrailerList = "$.vehicleConfiguration.trailers",
15
- Commodity = "$.permittedCommodity.commodityType"
15
+ Commodity = "$.permittedCommodity.commodityType",
16
+ TotalDistance = "$.permittedRoute.manualRoute.totalDistance"
16
17
  }
@@ -17,4 +17,5 @@ var PermitAppInfo;
17
17
  PermitAppInfo["PowerUnitType"] = "$.vehicleDetails.vehicleSubType";
18
18
  PermitAppInfo["TrailerList"] = "$.vehicleConfiguration.trailers";
19
19
  PermitAppInfo["Commodity"] = "$.permittedCommodity.commodityType";
20
+ PermitAppInfo["TotalDistance"] = "$.permittedRoute.manualRoute.totalDistance";
20
21
  })(PermitAppInfo || (exports.PermitAppInfo = PermitAppInfo = {}));
@@ -65,7 +65,7 @@ function addRuntimeFacts(engine, policy) {
65
65
  * Add runtime fact for a fixed permit cost, the cost supplied
66
66
  * as a parameter.
67
67
  */
68
- engine.addFact(enum_1.PolicyFacts.FixedCost.toString(), async function (params) {
68
+ engine.addFact(enum_1.CostFacts.FixedCost.toString(), async function (params) {
69
69
  return params.cost;
70
70
  });
71
71
  /**
@@ -73,7 +73,7 @@ function addRuntimeFacts(engine, policy) {
73
73
  * cost rule applied only when the fact and value supplied as parameters
74
74
  * match.
75
75
  */
76
- engine.addFact(enum_1.PolicyFacts.ConditionalFixedCost.toString(), async function (params, almanac) {
76
+ engine.addFact(enum_1.CostFacts.ConditionalFixedCost.toString(), async function (params, almanac) {
77
77
  const conditionValue = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.fact);
78
78
  if (conditionValue && conditionValue === params.value) {
79
79
  return params.cost;
@@ -87,7 +87,7 @@ function addRuntimeFacts(engine, policy) {
87
87
  * policy as a 30 day period or portion thereof, except in the
88
88
  * case of a full year in which case it is 12 months.
89
89
  */
90
- engine.addFact(enum_1.PolicyFacts.CostPerMonth.toString(), async function (params, almanac) {
90
+ engine.addFact(enum_1.CostFacts.CostPerMonth.toString(), async function (params, almanac) {
91
91
  const duration = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PermitDuration);
92
92
  const daysInPermitYear = await almanac.factValue(enum_1.PolicyFacts.DaysInPermitYear.toString());
93
93
  let months = Math.floor(duration / 30);
@@ -101,4 +101,18 @@ function addRuntimeFacts(engine, policy) {
101
101
  }
102
102
  return months * params.cost;
103
103
  });
104
+ /**
105
+ * Add runtime fact for cost per kilometre driven in the applicant's
106
+ * permitted route. Accepts an optional parameter minValue which
107
+ * specifies the minimum value for the permit if the kilometre cost
108
+ * is less than that value.
109
+ */
110
+ engine.addFact(enum_1.CostFacts.CostPerKilometre.toString(), async function (params, almanac) {
111
+ const distance = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TotalDistance);
112
+ let cost = distance * params.cost;
113
+ if (typeof params.minValue === 'number') {
114
+ cost = Math.max(cost, params.minValue);
115
+ }
116
+ return cost;
117
+ });
104
118
  }
package/package.json CHANGED
@@ -86,5 +86,5 @@
86
86
  ],
87
87
  "testEnvironment": "node"
88
88
  },
89
- "version": "v0.5.0"
89
+ "version": "v0.6.0"
90
90
  }