import { RoleDefinition, RoleHierarchy, Permission } from './types'; /** * Role Hierarchy Manager for managing role inheritance. * * Provides utilities for building and querying hierarchical role structures * where roles can inherit permissions from parent roles. * * @example * ```typescript * const hierarchy = new RoleHierarchyManager(); * * // Define roles * hierarchy.addRole({ id: 'admin', name: 'Admin', permissions: ['*'], priority: 100 }); * hierarchy.addRole({ * id: 'manager', * name: 'Manager', * permissions: ['reports:*', 'team:*'], * inherits: ['user'], * priority: 50, * }); * hierarchy.addRole({ * id: 'user', * name: 'User', * permissions: ['profile:*', 'documents:read'], * priority: 10, * }); * * // Get all permissions for a role (including inherited) * const managerPerms = hierarchy.getEffectivePermissions('manager'); * // ['reports:*', 'team:*', 'profile:*', 'documents:read'] * * // Check if role inherits from another * hierarchy.inheritsFrom('manager', 'user'); // true * ``` */ export declare class RoleHierarchyManager { private roles; private hierarchyMap; private permissionCache; private ancestorCache; constructor(); /** * Add a role to the hierarchy. * * @param role - Role definition to add */ addRole(role: RoleDefinition): void; /** * Add multiple roles at once. * * @param roles - Role definitions to add */ addRoles(roles: RoleDefinition[]): void; /** * Remove a role from the hierarchy. * * @param roleId - Role ID to remove */ removeRole(roleId: string): void; /** * Update a role definition. * * @param roleId - Role ID to update * @param updates - Partial updates to apply */ updateRole(roleId: string, updates: Partial): void; /** * Get a role definition by ID. * * @param roleId - Role ID * @returns Role definition or undefined */ getRole(roleId: string): RoleDefinition | undefined; /** * Get all role definitions. * * @returns Array of all role definitions */ getAllRoles(): RoleDefinition[]; /** * Check if a role exists. * * @param roleId - Role ID to check * @returns Whether role exists */ hasRole(roleId: string): boolean; /** * Get hierarchy information for a role. * * @param roleId - Role ID * @returns Role hierarchy or undefined */ getHierarchy(roleId: string): RoleHierarchy | undefined; /** * Check if a role inherits from another role. * * @param roleId - Role to check * @param ancestorId - Potential ancestor role * @returns Whether roleId inherits from ancestorId */ inheritsFrom(roleId: string, ancestorId: string): boolean; /** * Get all ancestor roles (direct and indirect parents). * * @param roleId - Role ID * @returns Set of ancestor role IDs */ getAncestors(roleId: string): Set; /** * Get direct parent roles. * * @param roleId - Role ID * @returns Array of parent role IDs */ getParents(roleId: string): string[]; /** * Get direct child roles. * * @param roleId - Role ID * @returns Array of child role IDs */ getChildren(roleId: string): string[]; /** * Get all descendant roles (direct and indirect children). * * @param roleId - Role ID * @returns Set of descendant role IDs */ getDescendants(roleId: string): Set; /** * Get the hierarchy level of a role (0 = root). * * @param roleId - Role ID * @returns Hierarchy level */ getLevel(roleId: string): number; /** * Get root roles (roles with no parents). * * @returns Array of root role IDs */ getRootRoles(): string[]; /** * Get leaf roles (roles with no children). * * @returns Array of leaf role IDs */ getLeafRoles(): string[]; /** * Get effective permissions for a role including inherited permissions. * * @param roleId - Role ID * @returns Set of all effective permissions */ getEffectivePermissions(roleId: string): Set; /** * Get effective permissions for multiple roles. * * @param roleIds - Array of role IDs * @returns Combined set of permissions */ getEffectivePermissionsForRoles(roleIds: string[]): Set; /** * Check if a role (including inherited) has a permission. * * @param roleId - Role ID * @param permission - Permission to check * @returns Whether role has the permission */ hasPermission(roleId: string, permission: Permission): boolean; /** * Compare two roles by priority. * * @param roleA - First role ID * @param roleB - Second role ID * @returns Positive if A > B, negative if A < B, 0 if equal */ compareRoles(roleA: string, roleB: string): number; /** * Get the highest priority role from a list. * * @param roleIds - Array of role IDs * @returns Highest priority role ID or undefined */ getHighestPriorityRole(roleIds: string[]): string | undefined; /** * Sort roles by priority (highest first). * * @param roleIds - Array of role IDs * @returns Sorted array of role IDs */ sortByPriority(roleIds: string[]): string[]; /** * Check for circular inheritance. * * @returns Array of cycle descriptions if found */ detectCycles(): string[]; /** * Validate the role hierarchy. * * @returns Validation errors if any */ validate(): string[]; /** * Rebuild the hierarchy map from role definitions. */ private rebuildHierarchy; /** * Calculate hierarchy levels for all roles. */ private calculateLevels; /** * Recursively collect ancestor roles. */ private collectAncestors; /** * Recursively collect descendant roles. */ private collectDescendants; /** * Recursively collect permissions including inherited. */ private collectPermissions; /** * Check for circular inheritance. */ private hasCycle; /** * Clear all caches. */ private clearCaches; } /** * Create a new role hierarchy manager. * * @param roles - Initial role definitions * @returns Configured RoleHierarchyManager */ export declare function createRoleHierarchy(roles?: RoleDefinition[]): RoleHierarchyManager; /** * Standard 4-tier role hierarchy. */ export declare const STANDARD_ROLE_HIERARCHY: RoleDefinition[]; /** * Healthcare-specific role hierarchy. */ export declare const HEALTHCARE_ROLE_HIERARCHY: RoleDefinition[];