@frontegg/entitlements-javascript-commons 1.1.1 → 1.1.2

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.
@@ -19,7 +19,10 @@ function createConditionEvaluator(payload) {
19
19
  return (attributes) => {
20
20
  const attributeKey = payload.condition.attribute;
21
21
  const value = attributes[attributeKey];
22
- const { isValid: result } = value !== undefined && operation ? operation(value) : { isValid: false };
22
+ if (value === undefined || !operation) {
23
+ return false;
24
+ }
25
+ const { isValid: result } = operation(value);
23
26
  return payload.condition.negate ? !result : result;
24
27
  };
25
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"condition.evaluator.js","sourceRoot":"","sources":["../../src/conditions/condition.evaluator.ts"],"names":[],"mappings":";;;AACA,oFAA2E;AAC3E,sFAA4E;AAQ5E,SAAS,yBAAyB;IAChC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,SAAgB,wBAAwB,CAAC,OAAwC;IAC/E,MAAM,SAAS,GAAG,IAAA,kCAAY,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACrD,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,yBAAyB,EAAE,CAAC;KACpC;IAED,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC3E,IAAI,CAAC,WAAW,IAAI,cAAc,KAAK,SAAS,EAAE;QAChD,OAAO,yBAAyB,EAAE,CAAC;KACpC;IAED,MAAM,SAAS,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;IAErE,OAAO,CAAC,UAAmC,EAAE,EAAE;QAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;QACjD,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;QACvC,MAAM,EAAE,OA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EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAE7C,OAAO,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AAzBD,4DAyBC"}
package/docs/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.1.2](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.1.1...v-1.1.2) (2024-01-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **condition:** remove negate when value undefined ([f9d09e0](https://github.com/frontegg/entitlements-javascript-commons/commit/f9d09e00fb3816052ecf07cd800d57ccd9d1d5ce))
7
+
8
+ ## [1.1.2-alpha.1](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.1.1...v-1.1.2-alpha.1) (2024-01-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **condition:** remove negate when value undefined ([f9d09e0](https://github.com/frontegg/entitlements-javascript-commons/commit/f9d09e00fb3816052ecf07cd800d57ccd9d1d5ce))
14
+
1
15
  ## [1.1.1](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.1.0...v-1.1.1) (2024-01-15)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/entitlements-javascript-commons",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,12 @@ export function createConditionEvaluator(payload: CreateConditionEvaluatorPayloa
28
28
  return (attributes: Record<string, unknown>) => {
29
29
  const attributeKey = payload.condition.attribute;
30
30
  const value = attributes[attributeKey];
31
- const { isValid: result } = value !== undefined && operation ? operation(value) : { isValid: false };
31
+
32
+ if (value === undefined || !operation) {
33
+ return false;
34
+ }
35
+
36
+ const { isValid: result } = operation(value);
32
37
 
33
38
  return payload.condition.negate ? !result : result;
34
39
  };
@@ -20,6 +20,16 @@ describe('ConditionEvaluator', () => {
20
20
  expect(conditionEvaluator(attributes)).toEqual(false);
21
21
  });
22
22
 
23
+ it('should return false when attribute value is undefined and negate is true', () => {
24
+ const attributeKey = 'vendorId';
25
+ const attributes = { [attributeKey]: undefined };
26
+ const conditionEvaluator = createConditionEvaluator({
27
+ condition: { op: OperationEnum.Contains, value: { list: ['test'] }, negate: true, attribute: attributeKey },
28
+ });
29
+
30
+ expect(conditionEvaluator(attributes)).toEqual(false);
31
+ });
32
+
23
33
  it('should return false when attribute fails operation validation', () => {
24
34
  const attributeKey = 'vendorId';
25
35
  const attributes = { [attributeKey]: 'Vendor' };