import { type ExecutionContext } from '@nestjs/common'; import type { Request as ExpressRequest } from 'express'; import type { IKeycloakUser, IKeycloakTokenClaims } from '../keycloak/keycloak.types.js'; /** * Express Request augmented with Keycloak user and token claims. * Used in HTTP and GraphQL contexts where a request object is available. */ type TAuthenticatedRequest = ExpressRequest & { readonly user?: IKeycloakUser; readonly keycloakClaims?: IKeycloakTokenClaims; }; /** * Context Options for Authentication Decorators * * Defines options for context-aware parameter extraction in authentication decorators. * Supports automatic context detection and explicit context type specification. * * @example * ```ts * // Auto-detect context type (HTTP, GraphQL, WebSocket) * @Get('profile') * getProfile(@CurrentUser() user: IKeycloakUser) {} * * // Explicit GraphQL context * @Query(() => IUser) * async getUser(@CurrentUser(undefined, { contextType: 'graphql' }) user: IKeycloakUser) {} * * // Disable auto-detection * @CurrentUser(undefined, { autoDetect: false, contextType: 'http' }) * ``` */ export interface IContextOptions { /** * The execution context type. If not specified, context will be auto-detected. */ contextType?: 'http' | 'graphql' | 'websocket' | undefined; /** * Whether to auto-detect the context type. Defaults to true. * When true, the decorator will automatically determine the context type. * When false, the contextType must be explicitly specified. */ autoDetect?: boolean; } /** * Default context options with auto-detection enabled */ export declare const DEFAULT_CONTEXT_OPTIONS: IContextOptions; /** * Type guard that narrows an unknown value to a plain record. * * Used in place of blind `as Record` casts when extracting nested * properties from dynamically-shaped values (e.g. an authenticated user object) whose * exact shape is not statically known at the call site. * * @param value - The value to check * @returns `true` if `value` is a non-null object (and therefore safe to index), narrowing its type to `Record` * * @example * ```ts * const maybeUser: unknown = getUser(); * if (IsRecord(maybeUser)) { * console.log(maybeUser['id']); * } * ``` */ export declare function IsRecord(value: unknown): value is Record; /** * Detects the execution context type from the current ExecutionContext * * @param ctx - The NestJS execution context * @returns The detected context type ('http', 'graphql', or 'websocket'); defaults to 'http' if undetermined * * @example * ```ts * const contextType = DetectContextType(ctx); * if (contextType === 'graphql') { * // Handle GraphQL context * } * ``` */ export declare function DetectContextType(ctx: ExecutionContext): 'http' | 'graphql' | 'websocket'; /** * Extracts the request object from any supported execution context * * @param ctx - The NestJS execution context * @param options - Context options for extraction behavior * @returns The request object from the appropriate context * @throws {Error} If request cannot be extracted or context type is unsupported * * @example * ```ts * const request = ExtractRequestFromContext(ctx); * const user = request.user; * const token = request.headers.authorization; * ``` */ export declare function ExtractRequestFromContext(ctx: ExecutionContext, options?: IContextOptions): TAuthenticatedRequest; /** * Extracts the authenticated user from any supported execution context * * @param ctx - The NestJS execution context * @param options - Context options for extraction behavior * @returns The authenticated user object or undefined if not found * * @example * ```ts * const user = ExtractUserFromContext(ctx); * if (user) { * console.log('IUser ID:', user.id); * } * ``` * * @example With property path * ```ts * const userId = extractUserFromContext(ctx, { property: 'id' }); * ``` */ export declare function ExtractUserFromContext(ctx: ExecutionContext, options?: IContextOptions & { property?: string; }): unknown; /** * Extracts the authorization token from any supported execution context * * @param ctx - The NestJS execution context * @param options - Context options for extraction behavior * @returns The authorization token string or undefined if not found * * @example * ```ts * const token = ExtractAuthTokenFromContext(ctx); * if (token) { * // Validate token * } * ``` */ export declare function ExtractAuthTokenFromContext(ctx: ExecutionContext, options?: IContextOptions): string | undefined; export {}; //# sourceMappingURL=context-utils.d.ts.map