express-companion
Version:
Companion server for Express
1 lines • 6.48 kB
Source Map (JSON)
{"version":3,"sources":["../../src/types/index.d.ts"],"names":["index_d_module"],"mappings":"AAgBAA,EAAA,QAAS","sourcesContent":["import { EventEmitter } from \"node:events\";\n\nimport {\n type BodyParser,\n type OptionsJson,\n type OptionsText,\n type OptionsUrlencoded,\n} from \"body-parser\";\nimport { type CompressionOptions } from \"compression\";\nimport { type CookieParseOptions } from \"cookie-parser\";\nimport { type CorsOptions } from \"cors\";\nimport { DotenvConfigOptions } from \"dotenv\";\nimport { Application, Express } from \"express\";\nimport { type Options as RateLimitOptions } from \"express-rate-limit\";\nimport { type SessionOptions } from \"express-session\";\n\nexport = companion;\n\ndeclare function companion(\n options: companion.CompanionOptions\n): companion.CompanionReturn;\n\n/**\n * Configuration interface for the Companion plugin.\n */\nexport interface CompanionOptions {\n /**\n * Name of the application.\n */\n name: string;\n\n /**\n * Hostname or IP address to listen on (defaults to 'localhost').\n */\n host?: string;\n\n /**\n * Port number to listen on (defaults to 3000).\n */\n port?: number;\n\n /**\n * Secret key used for session management and other security features.\n * Required if using session middleware.\n */\n secretKey?: string;\n\n /**\n * Directory for serving static files (defaults to 'public').\n */\n publicDir?: string;\n\n /**\n * Directory for storing view templates (defaults to 'views').\n */\n viewsDir?: string;\n\n /**\n * View engine to use (defaults to 'ejs'). Can be disabled (false) or any supported engine.\n */\n viewEngine?: false | string;\n\n /**\n * Allowed HTTP methods for the application (defaults to ['GET', 'POST', 'PUT', 'DELETE']).\n */\n allowedMethods?: Array<\"GET\" | \"POST\" | \"PUT\" | \"DELETE\">;\n\n /**\n * Flag to enable/distable automatic express server creation (defaults to true).\n * Can be disabled (false) if you want to use your own express server.\n */\n express?: true | Express;\n\n /**\n * Configuration options for custom request/response headers.\n */\n headers?: OptionsHeaders;\n\n /**\n * Configuration options for various middleware functionalities.\n */\n middlewares?: OptionsMiddlewares;\n}\n\n/**\n * Interface for custom request/response header configuration.\n */\nexport interface OptionsHeaders {\n /**\n * Value for the X-Powered-By header. Can be disabled (false) or a custom string.\n */\n xPoweredBy?: boolean | string;\n\n /**\n * Function to generate a unique request ID or a boolean (true/false) to enable/distable.\n */\n xRequestId?: boolean | (() => string);\n\n /**\n * Flag to enable/distable including the user-agent header (defaults to true).\n */\n xUserAgent?: boolean;\n\n /**\n * Flag to enable/distable including the real IP address (defaults to true).\n */\n xRealIp?: boolean;\n\n /**\n * Flag to enable/distable including the X-Forwarded-For header (defaults to true).\n */\n xForwardedFor?: boolean;\n}\n\n/**\n * Interface for configuration options of various middleware functionalities.\n */\nexport interface OptionsMiddlewares {\n /**\n * Options for loading environment variables via the `dotenv` library.\n */\n env?: DotenvConfigOptions;\n\n /**\n * Configuration for rate limiting requests using the `express-rate-limit` library.\n */\n rateLimit?: RateLimitOptions;\n\n /**\n * Options for enabling CORS (Cross-Origin Resource Sharing) using the `cors` library.\n */\n cors: CorsOptions;\n\n /**\n * Configuration for compressing responses using the `compression` library.\n */\n compression?: CompressionOptions;\n\n /**\n * Options for CSRF (Cross-Site Request Forgery) protection.\n * Specific types depend on the chosen library.\n */\n csrf?: unknown;\n\n /**\n * Configuration for session management using the `express-session` library.\n */\n session?: boolean | SessionOptions;\n\n /**\n * Configuration for parsing cookies using the `cookie-parser` library.\n */\n cookieParser?: boolean | CookieParseOptions;\n\n /**\n * Configuration for parsing request bodies using the `body-parser` library.\n */\n bodyParser?: boolean | BodyParser;\n\n /**\n * Options for parsing JSON request bodies.\n */\n jsonParser?: boolean | OptionsJson;\n\n /**\n * Options for parsing text request bodies.\n */\n textParser?: boolean | OptionsText;\n\n /**\n * Options for parsing urlencoded request bodies.\n */\n urlencodedParser?: boolean | OptionsUrlencoded;\n\n /**\n * Configuration for custom middleware functions.\n */\n custom?: OptionsCustomMiddleware[];\n}\n\n/**\n * Interface for defining custom middleware functionalities.\n */\nexport interface OptionsCustomMiddleware {\n /**\n * Name for the custom middleware.\n */\n name: string;\n\n /**\n * Placement of the middleware in the request processing pipeline.\n * Can be \"pre-middleware\" or \"post-middleware\".\n */\n place: \"pre-middleware\" | \"post-middleware\";\n\n /**\n * Options object or function that defines the custom middleware behavior.\n * The type of options can vary depending on the specific middleware implementation.\n */\n options:\n | unknown\n | ((\n req: import(\"express\").Request,\n res: import(\"express\").Response,\n next: import(\"express\").NextFunction\n ) => void);\n}\n\n/**\n * Return type for the companion plugin function.\n */\nexport interface CompanionReturn {\n /**\n * The configured Express application instance.\n */\n server: Application;\n\n /**\n * Accessor for environment variables (if `env` middleware is used).\n */\n readonly env: unknown; // Separate interface for environment variables\n\n /**\n * The loaded configuration object.\n */\n readonly config: CompanionOptions;\n\n /**\n * Error object encountered during plugin setup (optional).\n */\n error?: Error;\n\n /**\n * Function for logging messages (optional).\n */\n logger?: (message: string) => void;\n\n /**\n * Function for channel-specific debugging messages (optional).\n */\n debug?: (channel: string, message: string) => void;\n\n /**\n * Event emitter for plugin events (optional).\n */\n events?: EventEmitter; // Utilize the EventEmitter library\n}\n\n/**\n * Companion plugin configuration options.\n */\n// declare namespace companion {\n\n// }\n"]}