import type { VextRequest } from "./request.js"; export type VextAuthErrorCode = "AUTH_REQUIRED" | "AUTH_INVALID" | "AUTH_FORBIDDEN" | "AUTH_CONFIG_ERROR" | "AUTH_PROVIDER_ERROR"; export type VextAuthSource = "bearer" | "apiKey" | "session" | "custom"; export type VextAuthCan = (action: string, resource?: string, context?: Record) => boolean | Promise; export type VextAuthAssert = (action: string, resource?: string, context?: Record) => void | Promise; export type VextPermissionRequirement = string | { action: string; resource?: string | ((req: VextRequest) => string | undefined); context?: Record | ((req: VextRequest) => Record | undefined); }; export interface VextAuthResult { subject?: string; userId?: string; roles?: string[]; scopes?: string[]; claims?: Record; scheme?: VextAuthSource; provider?: string; can?: VextAuthCan; assert?: VextAuthAssert; } export interface VextAuthContext extends VextAuthResult { isAuthenticated: boolean; roles: string[]; scopes: string[]; claims: Record; error?: VextAuthErrorCode; } export interface VextAuthContextSnapshot { isAuthenticated: boolean; subject?: string; userId?: string; roles: string[]; scopes: string[]; scheme?: VextAuthSource; provider?: string; } export interface VextAuthMiddlewareOptions { source?: VextAuthSource; provider?: string; header?: string; cookie?: string; sessionKey?: string; optional?: boolean; verify(credential: string | undefined, req: VextRequest): VextAuthResult | null | false | Promise; } export interface VextAuthRequirement { /** * Defaults to true. `false` keeps the route public/optional unless roles, * scopes, permissions or check are present. */ required?: boolean; roles?: string[]; scopes?: string[]; permissions?: VextPermissionRequirement[]; mode?: "any" | "all"; security?: string | string[] | Array>; check?: (req: VextRequest, auth: VextAuthContext) => boolean | Promise; }