onroute-policy-engine 0.4.6 → 0.5.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,6 +1,8 @@
1
1
  export declare enum PolicyFacts {
2
2
  AllowedVehicles = "allowedVehicles",
3
+ ConditionalFixedCost = "conditionalFixedCost",
3
4
  DaysInPermitYear = "daysInPermitYear",
5
+ EndOfPermitQuarter = "endOfPermitQuarter",
4
6
  ValidationDate = "validationDate",
5
7
  FixedCost = "fixedCost",
6
8
  CostPerMonth = "costPerMonth",
@@ -4,7 +4,9 @@ exports.PolicyFacts = void 0;
4
4
  var PolicyFacts;
5
5
  (function (PolicyFacts) {
6
6
  PolicyFacts["AllowedVehicles"] = "allowedVehicles";
7
+ PolicyFacts["ConditionalFixedCost"] = "conditionalFixedCost";
7
8
  PolicyFacts["DaysInPermitYear"] = "daysInPermitYear";
9
+ PolicyFacts["EndOfPermitQuarter"] = "endOfPermitQuarter";
8
10
  PolicyFacts["ValidationDate"] = "validationDate";
9
11
  PolicyFacts["FixedCost"] = "fixedCost";
10
12
  PolicyFacts["CostPerMonth"] = "costPerMonth";
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.addRuntimeFacts = addRuntimeFacts;
7
7
  const dayjs_1 = __importDefault(require("dayjs"));
8
+ const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
8
9
  const enum_1 = require("onroute-policy-engine/enum");
10
+ dayjs_1.default.extend(quarterOfYear_1.default);
9
11
  /**
10
12
  * Adds runtime facts for the validation. For example, adds the
11
13
  * validation date for comparison against startDate of the permit.
@@ -25,6 +27,17 @@ function addRuntimeFacts(engine, policy) {
25
27
  const daysInPermitYear = dateFrom.add(1, 'year').diff(dateFrom, 'day');
26
28
  return daysInPermitYear;
27
29
  });
30
+ /**
31
+ * Add runtime fact to get the last day of the quarter
32
+ * that the permit start date falls in. Returns the date
33
+ * formatted as a string in the standard permit date format.
34
+ */
35
+ engine.addFact(enum_1.PolicyFacts.EndOfPermitQuarter, async function (params, almanac) {
36
+ const startDate = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PermitStartDate);
37
+ const dateFrom = (0, dayjs_1.default)(startDate, enum_1.PermitAppInfo.PermitDateFormat);
38
+ const endOfQuarter = dateFrom.endOf('quarter');
39
+ return endOfQuarter.format(enum_1.PermitAppInfo.PermitDateFormat);
40
+ });
28
41
  /**
29
42
  * Adds a runtime fact specifying whether the vehicle configuration
30
43
  * in the permit application is valid for the permit type and
@@ -55,6 +68,20 @@ function addRuntimeFacts(engine, policy) {
55
68
  engine.addFact(enum_1.PolicyFacts.FixedCost.toString(), async function (params) {
56
69
  return params.cost;
57
70
  });
71
+ /**
72
+ * Add runtime fact for a conditional fixed permit cost, where the
73
+ * cost rule applied only when the fact and value supplied as parameters
74
+ * match.
75
+ */
76
+ engine.addFact(enum_1.PolicyFacts.ConditionalFixedCost.toString(), async function (params, almanac) {
77
+ const conditionValue = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.fact);
78
+ if (conditionValue && conditionValue === params.value) {
79
+ return params.cost;
80
+ }
81
+ else {
82
+ return 0;
83
+ }
84
+ });
58
85
  /**
59
86
  * Add runtime fact for cost per month, where month is defined by
60
87
  * policy as a 30 day period or portion thereof, except in the
package/package.json CHANGED
@@ -86,5 +86,5 @@
86
86
  ],
87
87
  "testEnvironment": "node"
88
88
  },
89
- "version": "v0.4.6"
89
+ "version": "v0.5.0"
90
90
  }