import type { DenyReason, IGrants, IQueryInfo, IResolveOptions, UnknownObject } from '../types/index.js'; /** * Represents the resolved `Permission` for a query — the granted (or denied) * access for the target role(s) and resource. Obtain one in two ways: * * 1. The chainable form via `AccessControl#can()`, which returns a `Permission` * once an action method such as `.createAny()` is called: * ```js * const permission = ac.can('user').createAny('video'); * console.log(permission.granted); // boolean * ``` * 2. The one-shot form via `AccessControl#check()`, passing a fulfilled * `IQueryInfo` object: * ```js * const permission = ac.check({ * role: 'user', * resource: 'video', * action: 'create:any' * }); * console.log(permission.granted); // boolean * ``` * */ export declare class Permission { /** * @private */ private _; /** Denial reason for the resolved attributes; set on resolution. */ private _reason?; /** Retained for the async resolution path. */ private readonly _grants; private readonly _query; private readonly _options?; /** * Initializes a new `Permission` instance. * @private * * @param grants - The underlying grants model. * @param query - An `IQueryInfo` arbitrary object. * @param [options] - `pathPrefix`, the merged check `context`, ownership, * strict, vocabulary, require() gates and condition registry. */ constructor(grants: IGrants, query: IQueryInfo, options?: IResolveOptions); /** * Specifies the roles for which the permission is queried for. * Even if the permission is queried for a single role, this will still * return an array. * * If the returned array has multiple roles, this does not necessarily mean * that the queried permission is granted or denied for each and all roles. * Note that when a permission is queried for multiple roles, attributes * are unioned (merged) for all given roles. This means "at least one of * these roles" have the permission for this action and resource attribute. */ get roles(): string[]; /** * Specifies the target resource for which the permission is queried for. */ get resource(): string; /** * The action the permission was checked for — the bare verb, with any * `:possession` suffix stripped (e.g. `read` for `read:any`, `publish` for a * custom `publish:own`). */ get action(): string; /** * The possession that **effectively** granted access — `'own'` or `'any'`. * Because `any` ⊇ `own`, a query for `own` that matched via an `any` grant * resolves to `'any'`. On denial, the requested possession is echoed back. * * @throws {AccessControlError} - If an applicable rule/gate has a custom/async * `{ fn }` condition; use {@link Permission#grantedAsync} first. */ get possession(): 'own' | 'any'; /** * Gets an array of allowed attributes which are defined via * Glob notation. If access is not granted, this will be an empty array. * * Note that when a permission is queried for multiple roles, attributes * are unioned (merged) for all given roles. This means "at least one of * these roles" have the permission for this action and resource attribute. */ get attributes(): string[]; /** * Specifies whether the permission is granted. If `true`, this means at * least one attribute of the target resource is allowed. * * @throws {AccessControlError} - If an applicable rule/gate has a custom/async * `{ fn }` condition; use {@link Permission#grantedAsync} instead. */ get granted(): boolean; /** * Why the permission was denied — `undefined` when granted. Also carried on * the `access` event for audit logs. * * `'out_of_schedule'` is worth distinguishing in UIs: the check failed *only* * because of a `during` schedule, so the same request would be granted at a * covered instant ("granted, but not now" — e.g. show *"outside access * hours"* instead of a generic denial). Any other reason means the grant * itself doesn't apply. * * @throws {AccessControlError} - If an applicable rule/gate has a custom/async * `{ fn }` condition; resolve {@link Permission#grantedAsync} first. * * @example * const permission = ac.can('editor', ctx).updateAny('post'); * if (!permission.granted) { * msg = permission.reason === 'out_of_schedule' * ? 'You are outside your access hours.' * : 'You do not have permission to do that.'; * } */ get reason(): DenyReason | undefined; /** * Async counterpart of {@link Permission#granted}. Resolves custom/async * `{ fn }` conditions (and works for fully-declarative checks too). After it * resolves, the sync `attributes`/`granted`/`filter` accessors are usable. * * @example * if (await ac.can('user', ctx).readAny('post').grantedAsync) { … } */ get grantedAsync(): Promise; /** * Filters the given data object (or array of objects) by the permission * attributes and returns this data with allowed attributes. * @param data - Data object to be filtered. Either a single object or array * of objects. * @returns - The filtered data object. */ filter(data: UnknownObject | UnknownObject[]): UnknownObject | UnknownObject[]; /** Whether an attribute set grants access (≥1 non-negated attribute). */ private static _hasGrant; /** * Returns the synchronously-resolved attributes; throws `asyncRequired` if a * `{ fn }` condition deferred resolution and it hasn't been awaited yet. * @private */ private _resolvedSync; /** * Resolves attributes via the async path (awaiting `{ fn }` conditions) and * memoizes them so subsequent sync accessors work. * @private */ private _resolveAsync; /** Emits the `access` audit event (once per resolution), if a listener exists. */ private _emitAccess; /** Emits the `error` event when a check throws. */ private _emitError; } //# sourceMappingURL=Permission.d.ts.map