/** * Nexus Request Context — passed to every page, layout and server action. * Inspired by SvelteKit's RequestEvent and Next.js's Request/Response pattern. */ import type { HeadMeta } from '@nexus_js/head'; export interface NexusLocals { tenantId?: string; tenant?: unknown; [key: string]: unknown; } export interface NexusContext { request: Request; params: Record; url: URL; headers: Headers; locals: NexusLocals; /** * Vault-lite: merged `process.env` at boot plus hot patches (Studio / dev endpoint). * Use `ctx.secrets.get('STRIPE_KEY')` instead of `process.env` when you need live rotation. */ secrets: ReadonlyMap; /** * Merged result of the route's `load(ctx)` (or explicit `nxPretext`) from each layout (outer→inner) * and the page, run in parallel before render. Later segments override keys on collision. * Serialized into the document for `$pretext()` on the client. */ pretext?: Record; /** * Internal: per-request head-metadata stack for SSR auto-injection. * Populated by `defineHead()` when a `ctx` is passed, flushed by the renderer. */ __nexusHeadStack?: HeadMeta[]; /** * Per-request Content-Security-Policy nonce. * When `security.hardened` is enabled, every HTML response gets a fresh random nonce. * Add `nonce="{ctx.cspNonce}"` to any custom inline ` * ``` * * Empty string when `security.hardened` is disabled. */ cspNonce: string; /** Set a response header */ setHeader: (key: string, value: string) => void; /** Set a cookie */ setCookie: (name: string, value: string, opts?: CookieOptions) => void; /** Get a cookie value */ getCookie: (name: string) => string | undefined; /** Redirect — throws, so use `return redirect(...)` pattern */ redirect: (location: string, status?: 301 | 302 | 303 | 307 | 308) => never; /** Return a not-found response */ notFound: () => never; } export interface CookieOptions { path?: string; domain?: string; maxAge?: number; expires?: Date; httpOnly?: boolean; secure?: boolean; sameSite?: 'Strict' | 'Lax' | 'None'; } /** Internal redirect signal — carries response headers (e.g. Set-Cookie on logout). */ export declare class RedirectSignal { readonly location: string; readonly status: number; readonly responseHeaders: Headers; constructor(location: string, status: number, responseHeaders: Headers); } /** Internal not-found signal */ export declare class NotFoundSignal { } export declare function createContext(request: Request, params?: Record, cspNonce?: string): NexusContext & { _responseHeaders: Headers; }; //# sourceMappingURL=context.d.ts.map