payload-gatekeeper
Version:
The ultimate access control gatekeeper for Payload CMS v3 - Advanced RBAC with wildcard support, auto role assignment, and flexible configuration
32 lines • 1.38 kB
TypeScript
import type { Payload } from 'payload';
import type { GatekeeperOptions } from '../types';
/**
* Check if user has required permission
* Supports wildcards and pattern matching
* Optimized for performance with early returns
*/
export declare const hasPermission: (userPermissions: string[] | undefined, requiredPermission: string) => boolean;
/**
* Check if a permission is covered by user permissions
* Handles wildcards like 'users.*' covering 'users.read'
* Optimized version using early returns and cached regex
*/
export declare const isPermissionCovered: (permission: string, userPermissions: string[]) => boolean;
/**
* Check if user can assign a specific role
* Based on permission subset check and protected flag
*/
export declare const canAssignRole: (userPermissions: string[], targetRole: {
protected?: boolean;
permissions?: string[];
active?: boolean;
}) => boolean;
/**
* Helper function for access control checks
* Supports string ID, number ID, populated role object, null, and undefined
* Note: With afterRead hook, role should usually be populated already
*/
export declare const checkPermission: (payload: Payload, userRole: string | number | {
[key: string]: any;
} | null | undefined, permission: string, userId?: string | number, options?: GatekeeperOptions) => Promise<boolean>;
//# sourceMappingURL=checkPermission.d.ts.map