import type { AccessControl } from '../index.js'; import type { ConditionJSON, IAccessInfo, IGrants } from '../types/index.js'; import { type INameOptions } from '../utils/index.js'; /** * Represents the inner `Access` class that helps build an access information * to be granted or denied; and finally commits it to the underlying grants * model. You can get a first instance of this class by calling * `AccessControl#grant()` or `AccessControl#deny()` methods. */ export declare class Access { /** Inner `IAccessInfo` object. */ protected _: IAccessInfo; /** * Pending `.during()` expressions. Kept separate from `_.condition` and * merged at commit so a later `.where()` (which overwrites the condition by * contract) can never silently drop an attached schedule. */ protected _during: string[]; /** Main grants object. */ protected _ac: AccessControl; /** Main grants object. */ protected _grants: IGrants; /** Notation path sentinel for compiling conditions (from the engine policy). */ protected _pathPrefix: string; /** Charset / safe-errors policy threaded into name validation + messages. */ protected _nameOpts: INameOptions; /** * Initializes a new instance of `Access`. * @private * * @param ac - AccessControl instance. * @param [roleOrInfo] - Either an `IAccessInfo` object, a single or an array * of roles. If an object is passed, possession and attributes properties are * optional. CAUTION: if attributes is omitted, it defaults to `["*"]`: * every attribute, allowed on a grant and denied on a deny. If possession is * omitted, it defaults to `"any"`. * @param denied - Specifies whether this `Access` is denied. */ constructor(ac: AccessControl, roleOrInfo?: string | string[] | IAccessInfo, denied?: boolean); /** * Specifies whether this access is initially denied. */ get denied(): boolean; /** * A chainer method that sets the role(s) for this `Access` instance. * @param value - A single or array of roles. * @returns - Self instance of `Access`. */ role(value: string | string[]): Access; /** * A chainer method that sets the resource for this `Access` instance. * @param value - Target resource for this `Access` instance. * @returns - Self instance of `Access`. */ resource(value: string | string[]): Access; /** * Sets the attributes for the next action committed in this chain: the * allowed ones on a grant, the denied ones on a deny. An attributes * argument passed to the action method itself takes precedence. * @param value - Attributes to be set. * @returns - Self instance of `Access`. */ attributes(value: string | string[]): Access; /** * Attaches a declarative condition to this grant — *whether* the grant * applies at check time. Accepts the string-sugar form * (`'$.order.value > 100000'`) or canonical JSON (`{ and|or|not }` / * `[lhs, op, rhs]`); it is compiled and validated when committed. Pairs with * the attribute list (`['*','!password']`), which decides *what fields* return. * @param condition - The condition (string sugar or canonical JSON). * @returns - Self instance of `Access`. * * @example * ac.grant('manager') * .where('$.order.value > 100000') * .updateAny('order', ['*']); */ where(condition: ConditionJSON): Access; /** * Attaches a temporal schedule to this grant: it applies only while the * check instant — the reserved `$.now` (i.e. `context.now`, defaulting to * the current time) — is covered by the given * {@link https://dtrexp.org | dtrexp} expression. Shorthand for AND-ing * `['$.now', 'during', expression]` into this grant's condition; composes * with `.where()` regardless of call order. The timezone comes from the * reserved `context.tz` (IANA name; defaults to the system zone). The * expression is validated when the chain commits (on the action call): * malformed or never-matching expressions throw. * * Repeated calls AND together (all schedules must cover the instant); to * express alternatives, use a union (`|`) inside a single expression. * @param expression - A dtrexp date-time range / recurrence expression. * @returns - Self instance of `Access`. * * @example * ac.grant('trader') * .where('$.order.value <= 100000') * .during('T0900:1800 E1:5') // Mon–Fri, 09:00–18:00 * .updateAny('order', ['*']); */ during(expression: string): Access; /** * Sets the roles to be extended (inherited) for this `Access` instance. * * @param roles - A single or array of roles. * @returns - Self instance of `Access`. * * @example * ac.grant('user').createAny('video') * .grant('admin').extend('user'); * const permission = ac.can('admin').createAny('video'); * console.log(permission.granted); // true */ extend(roles: string | string[]): Access; /** * Shorthand to switch to a new `Access` instance with a different role * within the method chain. * @param [roleOrInfo] - Either a single or an array of roles or an * @returns - A new `Access` instance. * @example * ac.grant('user').createOwn('video') * .grant('admin').updateAny('video'); */ grant(roleOrInfo?: string | string[] | IAccessInfo): Access; /** * Shorthand to switch to a new `Access` instance with a different * (or same) role within the method chain. * @param [roleOrInfo] - Either a single or an array of roles or an * @returns - A new `Access` instance. * @example * ac.grant('admin').createAny('video') * .deny('user').deleteAny('video'); */ deny(roleOrInfo?: string | string[] | IAccessInfo): Access; /** * Chainable, convenience shortcut for `AccessControl#lock()`. */ lock(): Access; /** * Generic authoring entry for **any** action — CRUD or custom. The CRUD * methods (`createAny`, `updateOwn`, …) are named sugar over this same commit * path. `actionSpec` may carry possession via the `:own`/`:any` convention * (omit ⇒ `any`). * @param actionSpec - Action name, optionally `name:own`/`name:any`. * @param [resource] - Target resource(s). * @param [attributes] - Granted (or denied) attributes; omitted, the list * set with `.attributes()`, else `['*']`. * @returns - Self instance of `Access`. * * @example * ac.grant('editor').action('publish', 'article', ['*']); // publish:any * ac.grant('author').action('publish:own', 'article', ['*']); // ownership-gated */ action(actionSpec: string, resource?: string | string[], attributes?: string | string[]): Access; /** * The single sanctioned alias of {@link Access#action} — the one * intentional exception to the v3 alias purge. Generic: CRUD and custom. * @param actionSpec - Action name, optionally `name:own`/`name:any`. * @param [resource] - Target resource(s). * @param [attributes] - Granted attributes. * @returns - Self instance of `Access`. */ do(actionSpec: string, resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"create"` and possession to `"own"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ createOwn(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"create"` and possession to `"any"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ createAny(resource?: string | string[], attributes?: string | string[]): Access; /** * Alias of `createAny` * @private */ create(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"read"` and possession to `"own"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ readOwn(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"read"` and possession to `"any"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ readAny(resource?: string | string[], attributes?: string | string[]): Access; /** * Alias of `readAny` * @private */ read(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"update"` and possession to `"own"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ updateOwn(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"update"` and possession to `"any"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ updateAny(resource?: string | string[], attributes?: string | string[]): Access; /** * Alias of `updateAny` * @private */ update(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"delete"` and possession to `"own"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ deleteOwn(resource?: string | string[], attributes?: string | string[]): Access; /** * Sets the action to `"delete"` and possession to `"any"` and commits the * current access instance to the underlying grant model. * * @param [resource] - Defines the target resource this access is granted or * denied for. This is only optional if the resource is previously defined. * If not defined and omitted, this will throw. * @param [attributes] - Defines the resource attributes for which the access * is granted or denied. Omitted, it defaults to `["*"]`: every attribute, * granted or denied, unless a list was set with `.attributes()` in the * chain. An explicit `[]` is kept: a grant of no attributes, or a deny of * none. * * @throws {AccessControlError} - If the access instance to be committed has * any invalid data. * * @returns - Self instance of `Access` so that you can chain and define * another access instance to be committed. */ deleteAny(resource?: string | string[], attributes?: string | string[]): Access; /** * Alias of `deleteAny` * @private */ delete(resource?: string | string[], attributes?: string | string[]): Access; /** * @private * @param action * @param possession * @param resource * @param attributes * @returns - Self instance of `Access`. */ private _prepareAndCommit; } //# sourceMappingURL=Access.d.ts.map