@frontegg/client
Advanced tools
Comparing version 5.1.0-alpha.1 to 5.1.0-alpha.2
@@ -17,2 +17,3 @@ import { IsEntitledResult } from './types'; | ||
constructor(entity: T, cache: EntitlementsCache); | ||
private findUserId; | ||
isEntitledToFeature(featureKey: string): Promise<IsEntitledResult>; | ||
@@ -19,0 +20,0 @@ isEntitledToPermission(permissionKey: string): Promise<IsEntitledResult>; |
@@ -5,3 +5,4 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
const types_2 = require("./storage/types"); | ||
const types_2 = require("../identity/types"); | ||
const types_3 = require("./storage/types"); | ||
const exp_time_utils_1 = require("./storage/exp-time.utils"); | ||
@@ -14,5 +15,3 @@ class EntitlementsUserScoped { | ||
const entityWithUserId = entity; | ||
if (entityWithUserId.userId) { | ||
this.userId = entityWithUserId.userId; | ||
} | ||
this.userId = this.findUserId(entityWithUserId); | ||
const entityWithPossiblePermissions = entity; | ||
@@ -26,2 +25,11 @@ if (Array.isArray(entityWithPossiblePermissions.permissions)) { | ||
} | ||
findUserId(entity) { | ||
switch (entity.type) { | ||
case types_2.tokenTypes.UserToken: | ||
return entity.sub; | ||
case types_2.tokenTypes.UserApiToken: | ||
case types_2.tokenTypes.UserAccessToken: | ||
return entity.userId; | ||
} | ||
} | ||
async isEntitledToFeature(featureKey) { | ||
@@ -40,3 +48,3 @@ const tenantEntitlementExpTime = await this.cache.getEntitlementExpirationTime(featureKey, this.tenantId); | ||
} | ||
else if (expTime === types_2.NO_EXPIRE || expTime > new Date().getTime()) { | ||
else if (expTime === types_3.NO_EXPIRE || expTime > new Date().getTime()) { | ||
return { | ||
@@ -43,0 +51,0 @@ result: true, |
@@ -35,3 +35,6 @@ "use strict"; | ||
} | ||
return { ...(entityWithRoles || {}), ...entity }; | ||
return { | ||
...(entityWithRoles || ((options === null || options === void 0 ? void 0 : options.withRolesAndPermissions) ? await this.getEntity(entity) : {})), | ||
...entity | ||
}; | ||
} | ||
@@ -38,0 +41,0 @@ async init() { |
@@ -12,2 +12,3 @@ export declare enum AuthHeaderType { | ||
permissions?: string[]; | ||
withRolesAndPermissions?: boolean; | ||
} | ||
@@ -14,0 +15,0 @@ export declare enum tokenTypes { |
@@ -0,1 +1,8 @@ | ||
# [5.1.0-alpha.2](https://github.com/frontegg/nodejs-sdk/compare/5.1.0-alpha.1...5.1.0-alpha.2) (2023-07-21) | ||
### Bug Fixes | ||
* **entitlements:** fixed the way of fetching user ID ([6df03ac](https://github.com/frontegg/nodejs-sdk/commit/6df03ac156434b4eab1e76126a8766f36360fd03)) | ||
# [5.1.0-alpha.1](https://github.com/frontegg/nodejs-sdk/compare/5.0.0...5.1.0-alpha.1) (2023-07-17) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@frontegg/client", | ||
"version": "5.1.0-alpha.1", | ||
"version": "5.1.0-alpha.2", | ||
"description": "Frontegg Javascript Library for backend node servers", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -216,4 +216,7 @@ <br /> | ||
// validate token and decode its properties | ||
const userOrTenantEntity = await identityClient.validateToken(token); | ||
const userOrTenantEntity = await identityClient.validateToken(token, { withRolesAndPermissions: true }); | ||
``` | ||
> Note, that some JWT tokens might not contain permissions stored in their payloads. Permissions are essential for | ||
> entitlement decision-making, so remember to add option flag: `withRolesAndPermissions: true`. | ||
(see <a href="#validating-jwt-manually">Validating JWT manually</a> section for more details). | ||
@@ -220,0 +223,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
189726
2535
319
0