Comparing version 4.2.5 to 4.2.6
@@ -76,2 +76,23 @@ "use strict"; | ||
} | ||
function hasPermissions(participants, securityLevel, ...validModules) { | ||
let state = false; | ||
const scopes = []; | ||
const validModuleIds = validModules.map((m) => m.module_id); | ||
for (const participant of participants) { | ||
if (validModuleIds.includes(participant.module_id)) { | ||
scopes.push(...participant.scopes); | ||
} | ||
} | ||
for (const scope of scopes) { | ||
// if disallows, return immediately | ||
if (bf_types_1.ScopeDefinition[scope].disallows.indexOf(securityLevel) !== -1) { | ||
return false; | ||
} | ||
// if allowed set state to true, but continue looking, in case a scope disallows it, Disallows trumps allows | ||
if (bf_types_1.ScopeDefinition[scope].allows.indexOf(securityLevel) !== -1) { | ||
state = true; | ||
} | ||
} | ||
return state; | ||
} | ||
function logOut() { | ||
@@ -86,4 +107,5 @@ system_1.default.nexus.disconnect(); | ||
getOrganization, | ||
hasPermissions, | ||
logOut, | ||
}; | ||
exports.default = system_1.default.sealModule(Object.freeze(auth)); |
@@ -1,2 +0,2 @@ | ||
import { IModuleLink, IOrganization, IUser, IUserEntity } from 'bf-types'; | ||
import { IModuleLink, IOrganization, IParticipant, IUser, IUserEntity, TSecurityTypes } from 'bf-types'; | ||
export interface Auth { | ||
@@ -8,3 +8,4 @@ getUser(): Promise<IUserEntity>; | ||
getOrganizationDoc(): Promise<IOrganization>; | ||
hasPermissions(participants: IParticipant[], securityLevel: TSecurityTypes, ...validModules: IModuleLink[]): boolean; | ||
logOut(): void; | ||
} |
{ | ||
"name": "bf-lib", | ||
"version": "4.2.5", | ||
"version": "4.2.6", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "the standard client library for block-5 software", |
137159
3204