import { AuthorizationResponse } from './gate'; import type { UserModel as OrmUserModel } from '@stacksjs/orm'; /** For tests, and for a dev server that regenerated the registry. */ export declare function resetPolicyRegistry(): void; /** * Discover and register policies: the explicit mappings in `app/Gates.ts` * first, then anything under `app/Policies/` that follows the `ModelPolicy` * convention. */ export declare function discoverPolicies(): Promise; /** * Register inline gates from Gates.ts */ export declare function registerGates(): Promise; /** * Initialize the authorization system: register the gates and before/after * callbacks from `app/Gates.ts`, then the policies. * * Called from `injectGlobalAutoImports()`, which is the one place every entry * point comes through - HTTP, `buddy seed`, a scheduled job, a console command. * Nothing called it before. It was exported, documented, and dead, so every * gate an application defined was never registered and every `Gate.allows(...)` * fell through to the default deny. That is the failure mode authorization is * least able to report, because a gate that denies everything and a gate that * was never registered are the same answer. * * Never throws: an application that cannot boot over a typo in a gate is worse * than one that logs the typo. A `Gates.ts` that fails to load is reported at * error level, not swallowed at debug. */ export declare function initializeAuthorization(): Promise; // Use the row/instance shape from orm so policies operate on the // authenticated user object, not the User class constructor. declare type UserModel = OrmUserModel; export declare abstract class BasePolicy { before?(user: UserModel | null, ability: string): boolean | null | Promise; viewAny?(user: UserModel | null): boolean | Promise | AuthorizationResponse; view?(user: UserModel | null, model: T): boolean | Promise | AuthorizationResponse; create?(user: UserModel | null): boolean | Promise | AuthorizationResponse; update?(user: UserModel | null, model: T): boolean | Promise | AuthorizationResponse; delete?(user: UserModel | null, model: T): boolean | Promise | AuthorizationResponse; restore?(user: UserModel | null, model: T): boolean | Promise | AuthorizationResponse; forceDelete?(user: UserModel | null, model: T): boolean | Promise | AuthorizationResponse; protected allow(message?: string): AuthorizationResponse; protected deny(message?: string, code?: string): AuthorizationResponse; protected denyIf(condition: boolean, message?: string): AuthorizationResponse | boolean; protected denyUnless(condition: boolean, message?: string): AuthorizationResponse | boolean; protected allowIf(condition: boolean, message?: string): AuthorizationResponse | boolean; } export { AuthorizationResponse };