import { Equatable, Serializable } from "./../utilities"; import { Resource } from "../resource"; import { GrantSet } from "./grant-set"; import { WhenFn } from "../common"; /** * Permission * * A single Permission. */ export declare class Permission implements Equatable, Serializable { readonly name: string; readonly grants: GrantSet; constructor(name: string, grants: GrantSet); /** * All() * * Creates a Permission instance that grants access to all actions for the named resource. * @param resource The resource the permission applies to. * @returns the created permission. */ static All(resource: Resource): Permission; /** * None() * * Creates a Permission instance that grants no actions to the named resource. * @param resource the resource the permission applies. * @returns the created permission */ static None(resource: Resource): Permission; /** * Private() * * creates a Permission instance that only allows the resource owner to access or modify the resource. * @param resource the resource the permission applies to. * @returns the created resource. */ static Private(resource: Resource): Permission; /** * Protected() * * Creates a Permission instance where anyone can create and view. However, only the owner of the resource can update and delete. * @param resource the resource the permission applies to. * @returns The created instance. */ static Protected(resource: Resource): Permission; /** * Public() * * Creates a Permission where everything is permitted except destruction. * @param resource The resource the permission applies to. * @returns The created instance. */ static Public(resource: Resource): Permission; /** * ReadOnly() * * Creates a Permission where the read action is the only allowed action. * @param resource the resource the permission applies to. * @returns the created instance. */ static ReadOnly(resource: Resource): Permission; equals(suspect: any): boolean; serialize(): string; toString(): string; toPermissionsList(): string[]; } /** * PermissionsList * * A permissions list. */ export declare abstract class PermissionsList { readonly subject: string; protected readonly permissions: Map; readonly scope: string; readonly identifier: string; constructor(subject: string, permissions: Map, scope: string, identifier: string); /** * create() * * determines if the create action can be peformed on a resource. * @param resource The resource in which the action will be performed on. * @param when An optional function to customize the behavior. the when function returns true if additional * requirements to grant permissions is met. * @returns TRUE if the entity can perform the action on the resource. FALSE otherwise. */ abstract create(resource: Resource, when?: WhenFn): boolean; /** * read() * * determines if the read action can be perormed on a resource. * @param resource The resource in which the action will be performed on. * @param when An optional function to customize the behavior. the when function returns true if additional * requirements to grant permissions is met. * @returns TRUE if the entity can perform the action on the resource. FALSE otherwise. */ abstract read(resource: Resource, when?: WhenFn): boolean; /** * update() * * determines if the update action can be performed on a resource. * @param resource The resource in which the action will be performed on. * @param when An optional function to customize the behavior. the when function returns true if additional * requirements to grant permissions is met. * @returns TRUE if the entity can perform the action on the resource. FALSE otherwise. */ abstract update(resource: Resource, when?: WhenFn): boolean; /** * delete() * * determines if the delete action can be performed on a resource. * @param resource The resource in which the action will be performed on. * @param when An optional function to customize the behavior. the when function returns true if additional * requirements to grant permissions is met. * @returns TRUE if the entity can perform the action on the resource. FALSE otherwise. */ abstract delete(resource: Resource, when?: WhenFn): boolean; } /** * PermissionsWhiteList * * A permissions list that defines situations when actions are permissible. */ export declare class PermissionsWhitelist extends PermissionsList { constructor(subject: string, permissioins: Map, identifier?: string, scope?: string); private isPermissible; private hasMatchingResourceScope; create(resource: Resource, when?: WhenFn): boolean; read(resource: Resource, when?: WhenFn): boolean; update(resource: Resource, when?: WhenFn): boolean; delete(resource: Resource, when?: WhenFn): boolean; } /** * PermissionsBlackList * * A permissions list that defines situations when actions are not permissible. */ export declare class PermissionsBlacklist extends PermissionsList { constructor(subject: string, permissioins: Map, identifier?: string, scope?: string); private isProhibited; private hasProhibitedScope; create(resource: Resource, when?: WhenFn): boolean; read(resource: Resource, when?: WhenFn): boolean; update(resource: Resource, when?: WhenFn): boolean; delete(resource: Resource, when?: WhenFn): boolean; }