declare module "utils" { /** * @private */ export function flatten(object: { [key: string]: any; }, separator?: string): { [key: string]: any; }; /** * @private */ export function mergeRoles(dst: { [key: string]: any; }, ...srcs: Array<{ [key: string]: any; }>): { [key: string]: any; }; } declare module "index" { /** * RBAC classref */ export class RBAC { /** * RBAC roles object */ private _rules; private _rulesCompiled; private _refs; private _memoize; private _collectRefs; private _compile; /** * RBAC constructor * @param options RBAC options */ constructor(options?: RBAC.Options); /** * Adds new role to rules. * @public * @version 1.1.X * @param role user role * @param resource resource to access * @param operation allowed operation * @param when function for additional checks */ add(role: string, resource: string, operation: string, when?: RBAC.WhenFn): void; /** * Remove rule(s). * @public * @version 1.1.X * @param role user role * @param resource resource to access * @param operation operation */ remove(role: string, resource?: string, operation?: string): void; /** * Checks if user can perform operation without checking when condition. * @public * @version 1.X.X * @param role user role * @param resource resource to access * @param operation operation on resource * @returns true if role has access to resources */ can(role: string, resource: string, operation?: string): boolean; /** * Checks if user can perform operation with checking when condition if it's provided. * @public * @version 1.X.X * @param role user role * @param resource resource to access * @param operation operation on resource * @param context context passed to when function, set it to null * @returns true if role has access to resources. */ can(role: string, resource: string, operation: string, context: TContext): Promise; } export namespace RBAC { /** * Dynamic condition check function. */ type WhenFn = (context: TContext) => boolean | Promise; /** * Interherence references. * @see {@link RBAC.RoleRules} */ interface Refs { /** * Role rules. * {@link (RBAC:namespace).RoleRules} */ [roleName: string]: RoleRules; } /** * Operation permission list. */ interface OperationRules { /** * Operation permission. * @description `true` if allowed or `function` if need additional dynamic checks * @see {@link RBAC.WhenFn} */ [operationName: string]: boolean | WhenFn; } /** * Resource operations list. * @type Object * @see {@link RBAC.OperationRules} */ interface ResourceRules { /** * Resoure operation. */ [resourceName: string]: OperationRules; } /** * Role's resources list. * @type Object * @see {@link RBAC.ResourceRules} */ interface RoleRules { /** * Resource permissions list. */ [roleName: string]: ResourceRules; } /** * Resoure permission. */ interface ResourcePermission { /** * Resourece name or resource with operation. * @example "foo" * @example "foo:read" */ name: string; /** * Operation name. * @example "read" */ operation?: string; /** * Dynamic condition check function. * @see {@link RBAC.WhenFn} */ when?: WhenFn; } /** * List of RBAC rules and inherited roles. */ interface RulesObject { /** * List of resource and permissions. * @example * can: ["foo:create", "bar:*", "*:read"] * can: ["*"] * can: [{ * name: "baz", * operation: "create", * when: (ctx) => { * return ctx.user.id === ctx.obj.creatorId * } * }] * @see {@link RBAC.ResourcePermission} */ can: Array; /** * Optionally extend permissions from other roles. */ inherits?: Array; } /** * RBAC options. */ interface Options { /** * List of roles and their permissions. * @type Object * @see {@link RBAC.RulesObject} */ roles?: { /** * Role and it's permissions. */ [roleName: string]: RBAC.RulesObject; }; /** * If true makes wildcard matches faster. * @default true */ memoize?: boolean; } } export default RBAC; } //# sourceMappingURL=rbac.bundle.system.d.ts.map