import type { CommonLogger } from '@goatlab/js-utils'; import type * as trpcExpress from '@trpc/server/adapters/express'; import type { AuthConfig, ValidatedAuthUser } from '../bootstraps/ExpressTrpcAppConfig'; import { requestContext } from './request.context'; declare global { namespace Express { interface Request { context: ReturnType; /** Pre-validated Better Auth user (set by middleware) */ betterAuthUser?: ValidatedAuthUser; } } } /** * Options for creating the context factory */ export interface ContextFactoryOptions { /** Token validation callback from auth config */ validateToken?: AuthConfig['validateToken']; /** Logger instance */ logger?: CommonLogger; } /** * Create a context factory with the given auth configuration. * This allows injecting the auth validation logic at app startup. * * @param options - Configuration options including auth validator * @returns A createContext function for tRPC/Express */ export declare function createContextFactory(options?: ContextFactoryOptions): ({ req, info, }: trpcExpress.CreateExpressContextOptions & { info?: { connectionParams?: Record | null; }; }) => Promise>; /** * Default context creator (no auth validation) * Use createContextFactory for production with auth */ export declare const createContext: ({ req, info, }: trpcExpress.CreateExpressContextOptions & { info?: { connectionParams?: Record | null; }; }) => Promise>; export type TrpcContext = Awaited>;