import type { EmitterLike } from '@adonisjs/core/types/events'; import type { ContainerResolver } from '@adonisjs/core/container'; import { type Constructor, type LazyImport } from '@adonisjs/core/types/common'; import { AuthorizationResponse } from './response.ts'; import type { BouncerEvents, ResponseBuilder, GetPolicyMethods, AuthorizerResponse } from './types.ts'; /** * Exposes the API to authorize a user using a pre-defined policy. * PolicyAuthorizer handles the execution of policy methods and manages * policy lifecycle including before/after hooks. * * @example * ```js * const authorizer = new PolicyAuthorizer(user, PostPolicy, responseBuilder) * const canEdit = await authorizer.allows('edit', post) * await authorizer.authorize('delete', post) * ``` */ export declare class PolicyAuthorizer, Policy extends Constructor> { #private; /** * Create a new PolicyAuthorizer instance * * @param user User object or null for guest * @param policy Policy class or lazy import function * @param responseBuilder Function to normalize authorization responses */ constructor(user: User | null, policy: LazyImport | Policy, responseBuilder: ResponseBuilder); /** * Set a container resolver to use for resolving policies * * @param containerResolver IoC container resolver for constructing policy instances */ setContainerResolver(containerResolver?: ContainerResolver): this; /** * Define the event emitter instance to use for emitting * authorization events * * @param emitter Event emitter instance */ setEmitter(emitter?: EmitterLike): this; /** * Execute an action from the list of pre-defined actions * * @param action Policy method name to execute * @param args Arguments to pass to the policy method * * @example * ```js * const result = await authorizer.execute('edit', post) * ``` */ execute>>(action: Method, ...args: InstanceType[Method] extends (user: User, ...args: infer Args) => AuthorizerResponse | Promise ? Args : never): Promise; /** * Check if a user is allowed to perform an action using * one of the known policy methods * * @param action Policy method name to check * @param args Arguments to pass to the policy method * * @example * ```js * const canEdit = await authorizer.allows('edit', post) * ``` */ allows>>(action: Method, ...args: InstanceType[Method] extends (user: User, ...args: infer Args) => AuthorizerResponse | Promise ? Args : never): Promise; /** * Check if a user is denied from performing an action using * one of the known policy methods * * @param action Policy method name to check * @param args Arguments to pass to the policy method * * @example * ```js * const cannotEdit = await authorizer.denies('edit', post) * ``` */ denies>>(action: Method, ...args: InstanceType[Method] extends (user: User, ...args: infer Args) => AuthorizerResponse | Promise ? Args : never): Promise; /** * Authorize a user against a given policy action * * @param action Policy method name to authorize * @param args Arguments to pass to the policy method * @throws E_AUTHORIZATION_FAILURE * * @example * ```js * await authorizer.authorize('edit', post) * ``` */ authorize>>(action: Method, ...args: InstanceType[Method] extends (user: User, ...args: infer Args) => AuthorizerResponse | Promise ? Args : never): Promise; }