import { type RequestIdentity } from '@pipeline-builder/api-core'; import type { Request } from 'express'; import { SSEManager, type SSEEventType } from '../http/sse-connection-manager.js'; declare global { namespace Express { interface Request { /** Unique request ID (set by app-factory middleware) */ requestId?: string; /** Request context with identity, logging, and SSE */ context?: RequestContext; } } } /** * Request logger function type */ export type RequestLogger = (type: SSEEventType, message: string, data?: unknown) => void; /** * Request context with identity and logging */ export interface RequestContext { /** Unique request ID */ requestId: string; /** Identity from headers */ identity: RequestIdentity; /** Logging function: logger always, plus the SSE log stream when the service enables it */ log: RequestLogger; } /** * Create a request context with identity and logging * * Creates a logger that outputs to both console and SSE. * * @param req - Express request * @param sseManager - SSE manager for real-time logs * @returns Request context with identity and logger * * @example * ```typescript * app.post('/api/resource', requireAuth, async (req, res) => { * const ctx = createRequestContext(req, sseManager); * * ctx.log('INFO', 'Processing request', { data: req.body }); * * if (!ctx.identity.orgId) { * ctx.log('ERROR', 'Missing organization ID'); * return sendBadRequest(res, 'x-org-id header required'); * } * * // Process request... * ctx.log('COMPLETED', 'Request processed successfully'); * }); * ``` */ export declare function createRequestContext(req: Request, sseManager: SSEManager): RequestContext;