import { Subject } from './Subject'; import { Node, PermOpts } from './Node'; import { Document, Permission, Hash } from '../interfaces'; export declare type AccessResult = { type: string; access: boolean; reason: string; }; export declare type PermissionsHierarchy = { node: string; nodeId: string; permissions: Permission[]; parents?: PermissionsHierarchy[]; }; /** * Resource class, permissions are stored on these Nodes, and Subject nodes check for access to these nodes. */ export declare class Resource extends Node { /** * Create new permissions property on document if not existing. */ constructor(doc: Document); /** * Sort the permissions on this document by subjectId to allow for fast searching. */ sortPermissions(): this; setDoc(doc: Document): this; /** * Retrieve a permission for a given subject via binary search. Returns an empty permission object if none is found. */ getPermission(subject: Subject): Promise; getPermissionList(): Promise; /** * Determine access to a given permission, provide a reason for access result. Steps for checking access for a given permission: 1. If an assertion function is provided, make sure it returns true - return false if not 2. Check if there is a permission on this resource specifically referencing the given subject - return true || false if the permission is not undefined 3. Recurse up resource hierarchy, checking if parent resource has access to this resource. - if a parent subject specifically has true / false access -- return that boolean 4. Recurse up subject hierarchy */ determineAccess(subject: Subject, permissionType: string | string[], options?: PermOpts): Promise>; /** * Check if a subject has access to this resource. */ isAllowed(subject: Subject, permissionType: string, options?: PermOpts): Promise; /** * Get a string explaining why a subject has a permission set to a particular value for a given resource. */ explainPermission(subject: Subject, permissionType: string, options?: PermOpts): Promise; /** * Modify a permission on this Resource for a given Subject, using `action` to modify the permissions object. If no permission exists, a new permission is created. */ updatePermission(subject: Subject, action: (p: Permission) => Permission): Promise; /** * Set access for a particular permission type to true or false for a given Subject. */ setPermissionAccess(subject: Subject, permissionType: string, access: boolean): Promise; /** * Set access for a particular permission type to true for a given Subject. */ allow(subject: Subject, permissionType: string): Promise; /** * Set access for a particular permission type to false for a given Subject. */ deny(subject: Subject, permissionType: string): Promise; /** * Retrieve permissions hierarchy for this node. */ getPermissionsHierarchy(): Promise; }