import { Server, ServerOptions } from 'node:https' import { RequestListener } from 'node:http' import { EventEmitter } from 'node:events' export interface KeyMaterial { cert: string key: string certificateAuthority: CertificateAuthority } export interface CertificateAuthority { certificateFilePath: string certificatePem: string privateKeyPem: string initialise(): string } export interface AutoEncryptLocalhostEvents extends EventEmitter { INFORMATION: 'information' WARNINGS: 'warnings' ERRORS: 'errors' information: { RENEWING: symbol HTTP_SERVER_NOTHING_TO_DESTROY: symbol HTTP_SERVER_DESTROYING_SERVER: symbol HTTP_SERVER_DESTROYED: symbol HTTP_SERVER_LISTENING: symbol HTTP_SERVER_SERVING_CA_CERTIFICATE: symbol HTTP_SERVER_REDIRECTING_TO_HTTPS: symbol } warnings: { UNSUPPORTED_LINUX_SYSTEM_STORE: symbol FIREFOX_POLICY_FILE_ALREADY_EXISTS: symbol FIREFOX_NOT_FOUND_IN_DEFAULT_LOCATION: symbol HTTP_SERVER_PORT_80_BUSY: symbol } errors: { CREATING_FIREFOX_POLICY_FILE: symbol HTTP_SERVER_HTTPS_REDIRECT_FAILED: symbol } onAll(eventType: 'information' | 'warnings' | 'errors', eventHandler: (message: string) => void): void } /** Monkeypatched server with asynchronous listen() and close() methods. */ export interface AutoEncryptedLocalhostServer extends Server { close(): Promise listen(...args:any[]): Promise __autoEncryptLocalhost__self: AutoEncryptLocalhost __autoEncryptLocalhost__originalClose: Server['close'] } declare class AutoEncryptLocalhost { /** By aliasing the https property to the AutoEncryptLocalhost static class itself, we enable people to add AutoEncryptLocalhost to their existing apps by importing the module and prefixing their https.createServer(…) line with await AutoEncryptLocalhost. */ static get https(): typeof AutoEncryptLocalhost static events: AutoEncryptLocalhostEvents static getKeyMaterial(settingsPath?: string): KeyMaterial static settingsPathWithDefaultFallback(settingsPath?: string): string /** Automatically provisions trusted development-time (localhost) certificates in Node.js. */ static async createServer(options?: ServerOptions & { settingsPath?: string }, listener?: RequestListener): Promise static async createServer(listener?: RequestListener): Promise } export default AutoEncryptLocalhost