Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@frontegg/entitlements-javascript-commons

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frontegg/entitlements-javascript-commons - npm Package Compare versions

Comparing version 1.0.0-alpha.8 to 1.0.0-alpha.9

2

dist/index.d.ts

@@ -5,2 +5,2 @@ export { FeatureFlagEvaluationResult, FeatureFlag, evaluateFeatureFlag } from './feature-flags';

export { OperationEnum, ConditionValue } from './operations/types';
export { evaluateIsEntitledToFeature, evaluateIsEntitledToPermissions, CustomAttributes, NotEntitledJustification, UserEntitlementsContext, EntitlementResult, } from './user-entitlements';
export { evaluateIsEntitledToFeature, evaluateIsEntitledToPermissions, CustomAttributes, FronteggAttributes, NotEntitledJustification, UserEntitlementsContext, EntitlementResult, } from './user-entitlements';

@@ -1,3 +0,11 @@

import { CustomAttributes, EntitlementResult, UserEntitlementsContext } from './types';
export declare function evaluateIsEntitledToFeature(featureKey: string, userEntitlementsContext: UserEntitlementsContext, attributes?: CustomAttributes): EntitlementResult;
export declare function evaluateIsEntitledToPermissions(permissionKey: string, userEntitlementsContext: UserEntitlementsContext, attributes?: CustomAttributes): EntitlementResult;
import { EntitlementResult, UserEntitlementsContext, Attributes } from './types';
export declare function evaluateIsEntitledToFeature(featureKey: string, userEntitlementsContext: UserEntitlementsContext, attributes?: Attributes): EntitlementResult;
export declare function evaluateIsEntitledToPermissions(permissionKey: string, userEntitlementsContext: UserEntitlementsContext, attributes?: Attributes): EntitlementResult;
/**
* Merges the `custom` and `frontegg` Records into a single Record,
* Alters the `frontegg` Record keys with a prefix
* Example:
* Input: { 'custom': { 'customAttribute': 'someValue' }, 'frontegg': { 'email': 'user@email.com' } }
* Output: { 'customAttribute': 'someValue', 'imported.email': 'user@email.com' }
*/
export declare function prepareAttributes(attributes?: Attributes): Record<string, unknown>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluateIsEntitledToPermissions = exports.evaluateIsEntitledToFeature = void 0;
exports.prepareAttributes = exports.evaluateIsEntitledToPermissions = exports.evaluateIsEntitledToFeature = void 0;
const types_1 = require("./types");
const feature_flags_1 = require("../feature-flags");
const rules_1 = require("../rules");
function evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes = {}) {
function evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes) {
const feature = userEntitlementsContext.features[featureKey];

@@ -17,3 +17,3 @@ let hasExpired = false;

if (feature && feature.featureFlag) {
const { treatment } = (0, feature_flags_1.evaluateFeatureFlag)(feature.featureFlag, attributes);
const { treatment } = (0, feature_flags_1.evaluateFeatureFlag)(feature.featureFlag, prepareAttributes(attributes));
if (treatment === rules_1.TreatmentEnum.True) {

@@ -23,6 +23,9 @@ return { isEntitled: true };

}
return { isEntitled: false, justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE };
return {
isEntitled: false,
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
};
}
exports.evaluateIsEntitledToFeature = evaluateIsEntitledToFeature;
function evaluateIsEntitledToPermissions(permissionKey, userEntitlementsContext, attributes = {}) {
function evaluateIsEntitledToPermissions(permissionKey, userEntitlementsContext, attributes) {
const permission = userEntitlementsContext.permissions[permissionKey];

@@ -55,2 +58,21 @@ if (!permission) {

}
/**
* Merges the `custom` and `frontegg` Records into a single Record,
* Alters the `frontegg` Record keys with a prefix
* Example:
* Input: { 'custom': { 'customAttribute': 'someValue' }, 'frontegg': { 'email': 'user@email.com' } }
* Output: { 'customAttribute': 'someValue', 'imported.email': 'user@email.com' }
*/
function prepareAttributes(attributes = {}) {
const { custom = {}, frontegg = {} } = attributes;
const importedAttributesPrefix = 'imported.'; // Not Final
return {
...custom,
...Object.keys(frontegg).reduce((modifiedImportedAttributes, key) => {
modifiedImportedAttributes[`${importedAttributesPrefix}${key}`] = frontegg[key];
return modifiedImportedAttributes;
}, {}),
};
}
exports.prepareAttributes = prepareAttributes;
//# sourceMappingURL=is-entitled.evaluator.js.map

@@ -20,2 +20,13 @@ import { FeatureFlag } from '../feature-flags/types';

export type CustomAttributes = Record<string, string | number | boolean | Date>;
export type FronteggAttributes = {
tenantId?: string;
userId?: string;
email?: string;
email_verified?: boolean;
[unmappedAttribute: string]: unknown;
};
export type Attributes = {
custom?: CustomAttributes;
frontegg?: FronteggAttributes;
};
export declare const NO_EXPIRATION_TIME = -1;

@@ -0,1 +1,9 @@

# [1.0.0-alpha.9](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.8...v-1.0.0-alpha.9) (2023-10-12)
### Features
* **user-entitlements:** add frontegg attributes ([878f4aa](https://github.com/frontegg/entitlements-javascript-commons/commit/878f4aa5f284fc2dd27ffae63ed9c0c74b2c8adb))
* **user-entitlements:** add frontegg attributes ([b1c3e30](https://github.com/frontegg/entitlements-javascript-commons/commit/b1c3e30e420e8972167087c5745ef49ac0c6b859))
# [1.0.0-alpha.8](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.7...v-1.0.0-alpha.8) (2023-10-11)

@@ -2,0 +10,0 @@

{
"name": "@frontegg/entitlements-javascript-commons",
"version": "1.0.0-alpha.8",
"version": "1.0.0-alpha.9",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -9,2 +9,3 @@ export { FeatureFlagEvaluationResult, FeatureFlag, evaluateFeatureFlag } from './feature-flags';

CustomAttributes,
FronteggAttributes,
NotEntitledJustification,

@@ -11,0 +12,0 @@ UserEntitlementsContext,

@@ -1,2 +0,8 @@

import { CustomAttributes, EntitlementResult, NotEntitledJustification, NO_EXPIRATION_TIME, UserEntitlementsContext } from './types';
import {
EntitlementResult,
NotEntitledJustification,
NO_EXPIRATION_TIME,
UserEntitlementsContext,
Attributes,
} from './types';
import { evaluateFeatureFlag } from '../feature-flags';

@@ -7,6 +13,5 @@ import { TreatmentEnum } from '../rules';

userEntitlementsContext: UserEntitlementsContext,
attributes: CustomAttributes = {},
attributes?: Attributes,
): EntitlementResult {
const feature = userEntitlementsContext.features[featureKey];
let hasExpired = false;

@@ -22,3 +27,3 @@ if (feature && feature.expireTime !== null) {

if (feature && feature.featureFlag) {
const { treatment } = evaluateFeatureFlag(feature.featureFlag, attributes);
const { treatment } = evaluateFeatureFlag(feature.featureFlag, prepareAttributes(attributes));
if (treatment === TreatmentEnum.True) {

@@ -29,3 +34,6 @@ return { isEntitled: true };

return { isEntitled: false, justification: hasExpired ? NotEntitledJustification.BUNDLE_EXPIRED : NotEntitledJustification.MISSING_FEATURE };
return {
isEntitled: false,
justification: hasExpired ? NotEntitledJustification.BUNDLE_EXPIRED : NotEntitledJustification.MISSING_FEATURE,
};
}

@@ -36,3 +44,3 @@

userEntitlementsContext: UserEntitlementsContext,
attributes: CustomAttributes = {},
attributes?: Attributes,
): EntitlementResult {

@@ -76,1 +84,21 @@ const permission = userEntitlementsContext.permissions[permissionKey];

}
/**
* Merges the `custom` and `frontegg` Records into a single Record,
* Alters the `frontegg` Record keys with a prefix
* Example:
* Input: { 'custom': { 'customAttribute': 'someValue' }, 'frontegg': { 'email': 'user@email.com' } }
* Output: { 'customAttribute': 'someValue', 'imported.email': 'user@email.com' }
*/
export function prepareAttributes(attributes: Attributes = {}): Record<string, unknown> {
const { custom = {}, frontegg = {} } = attributes;
const importedAttributesPrefix = 'imported.'; // Not Final
return {
...custom,
...Object.keys(frontegg).reduce((modifiedImportedAttributes, key) => {
modifiedImportedAttributes[`${importedAttributesPrefix}${key}`] = frontegg[key];
return modifiedImportedAttributes;
}, {}),
};
}
import * as FeatureFlags from '../../feature-flags/feature-flag.evaluator';
import * as IsEntitledEvaluators from '../is-entitled.evaluator';
import { TreatmentEnum } from '../../rules';
import { EntitlementResult, NotEntitledJustification, NO_EXPIRATION_TIME, UserEntitlementsContext } from '../types';
import {
EntitlementResult,
NotEntitledJustification,
NO_EXPIRATION_TIME,
UserEntitlementsContext,
Attributes,
} from '../types';
import { FeatureFlag } from '../../feature-flags/types';

@@ -292,1 +298,19 @@ const mockFeatureFlag: FeatureFlag = {

});
describe('prepareAttributes', () => {
test('given custom & frontegg attributes, expected is merged Record, frontegg attributes altered with prefix', async () => {
const attributes: Attributes = {
custom: { testAttribute: 'testValue' },
frontegg: { email: 'test@email.com', unknownFronteggAttribute: 'unknownFronteggAttribute' },
};
const expectedPreparedAttributes: Record<string, unknown> = {
testAttribute: 'testValue',
'imported.email': 'test@email.com',
'imported.unknownFronteggAttribute': 'unknownFronteggAttribute',
};
const preparedAttributes = IsEntitledEvaluators.prepareAttributes(attributes);
expect(preparedAttributes).toEqual(expectedPreparedAttributes);
});
});

@@ -27,2 +27,12 @@ import { FeatureFlag } from '../feature-flags/types';

export type FronteggAttributes = {
tenantId?: string;
userId?: string;
email?: string;
email_verified?: boolean;
[unmappedAttribute: string]: unknown;
};
export type Attributes = { custom?: CustomAttributes; frontegg?: FronteggAttributes };
export const NO_EXPIRATION_TIME = -1;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc