import { type Application, type Request } from "express"; /** * ExpressService - Singleton para el servidor Express. * * Aplica el patrón Singleton: una única instancia centraliza la creación, * configuración de middlewares, rutas, manejo de errores y ciclo de vida del * servidor HTTP (start/stop). Idempotente: crear, finalizar y arrancar son * operaciones seguras de repetir. * * @example * ```ts * const app = ExpressService.getInstance().useCreate(); * app.use("/assistant", useCreateAssistantRouter()); * ExpressService.getInstance().useStart(3000, "localhost"); * ``` */ export declare class ExpressService { private static instance; /** Express application instance. */ private app; /** Whether the HTTP server has been started. */ private started; /** Whether the error handler / 404 catch-all has been registered. */ private finalized; /** * Constructor privado - enforce singleton. */ private constructor(); /** * Obtiene la instancia única del ExpressService (Singleton). * * @returns La instancia única de {@link ExpressService}. */ static getInstance(): ExpressService; /** * Returns the raw request body buffer captured by the JSON parser, if any. * Needed to verify webhook signatures (e.g. `X-Hub-Signature-256`). * * @param request - The Express request. * @returns The raw body buffer, or `undefined` when not available. */ useGetRawBody(request: Request): Buffer | undefined; /** * Set up CORS, JSON body parser and URL-encoded middleware. * The JSON parser also captures the raw body for signature verification. * * @param expressApp - Express application instance * * @example * ```ts * const expressApp = express(); * useExpressSetupMiddlewares(expressApp); * ``` */ private useSetupMiddlewares; /** * Set up health check and application routes. * * @param expressApp - Express application instance * * @example * ```ts * useExpressSetupRoutes(expressApp); * // GET /health returns { status: "ok", timestamp: "..." } * ``` */ private useSetupRoutes; /** * Set up global error handling and 404 fallback. Register this AFTER all * channel routers are mounted so it does not shadow them. * * @param expressApp - Express application instance * * @example * ```ts * useExpressSetupErrorHandling(expressApp); * // Unhandled errors return 500, unknown routes return 404 * ``` */ private useSetupErrorHandling; /** * Create and configure the Express application. Mount channel routers on the * returned app BEFORE calling {@link useFinalize} / {@link useStart}, * otherwise the 404 catch-all will shadow them. * * @returns Configured Express Application instance * * @example * ```ts * const expressApp = ExpressService.getInstance().useCreate(); * expressApp.use("/assistant", useCreateAssistantRouter()); * ``` */ useCreate(): Application; /** * Registers the error handler and 404 catch-all. Idempotent. Call this after * mounting every channel router so it runs last. {@link useStart} * invokes it automatically. * * @example * ```ts * ExpressService.getInstance().useGetApp().use("/assistant", useCreateAssistantRouter()); * ExpressService.getInstance().useFinalize(); * ``` */ useFinalize(): void; /** * Start the Express HTTP server. Idempotent - subsequent calls are no-ops. * Finalizes error handling before listening. * * @param port - Port to listen on (default: 3000) * @param host - Host to bind to (default: "localhost") * * @example * ```ts * ExpressService.getInstance().useStart(3000, "localhost"); * // Server running on http://localhost:3000 * ``` */ useStart(port?: number, host?: string): void; /** * Get the Express application instance. Creates it if it doesn't exist. * * @returns Express Application instance * * @example * ```ts * const expressApp = ExpressService.getInstance().useGetApp(); * expressApp.get("/custom", (req, res) => res.json({ ok: true })); * ``` */ useGetApp(): Application; } /** * Returns the raw request body buffer captured by the JSON parser, if any. * Needed to verify webhook signatures (e.g. `X-Hub-Signature-256`). * * @param request - The Express request. * @returns The raw body buffer, or `undefined` when not available. */ export declare function useGetRawBody(request: Request): Buffer | undefined; /** * Create and configure the Express application. Mount channel routers on the * returned app BEFORE calling {@link useExpressFinalize} / {@link useExpressStart}, * otherwise the 404 catch-all will shadow them. * * @returns Configured Express Application instance * * @example * ```ts * const expressApp = useExpressCreate(); * expressApp.use("/assistant", useCreateAssistantRouter()); * useExpressStart(); * ``` */ export declare const useExpressCreate: () => Application; /** * Registers the error handler and 404 catch-all. Idempotent. Call this after * mounting every channel router so it runs last. {@link useExpressStart} * invokes it automatically. * * @example * ```ts * useExpressGetApp().use("/assistant", useCreateAssistantRouter()); * useExpressFinalize(); * ``` */ export declare const useExpressFinalize: () => void; /** * Start the Express HTTP server. Idempotent - subsequent calls are no-ops. * Finalizes error handling before listening. * * @param port - Port to listen on (default: 3000) * @param host - Host to bind to (default: "localhost") * * @example * ```ts * useExpressStart(3000, "localhost"); * // Server running on http://localhost:3000 * ``` */ export declare const useExpressStart: (port?: number, host?: string) => void; /** * Get the Express application instance. Creates it if it doesn't exist. * * @returns Express Application instance * * @example * ```ts * const expressApp = useExpressGetApp(); * expressApp.get("/custom", (req, res) => res.json({ ok: true })); * ``` */ export declare const useExpressGetApp: () => Application; //# sourceMappingURL=server.d.ts.map