diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..2804bce --- /dev/null +++ b/index.d.ts @@ -0,0 +1,73 @@ +import { Server as HttpServer } from 'http'; +import { Server as HttpsServer, ServerOptions as NodeHttpsServerOptions } from 'https'; +import { Http2SecureServer, SecureServerOptions as NodeHttp2ServerOptions } from 'http2'; + +type IPAddress = string; +type FilePath = string; + +type PEMPath = string; +type PEMData = string | Buffer; +type PEM = PEMPath | PEMData; +type PEMChain = PEM[]; +type PEMs = PEM | PEMChain; +type CertificatePEMs = PEMs | PEMs[]; + +type CommonOptions = { + timeout?: number, + handler?: Function, +} + +type ServerOptions = CommonOptions & { + port?: number, + host: IPAddress, +} + +type HttpOptions = ServerOptions; + +type TLSOptions = { + ciphers?: string, + honorCipherOrder?: boolean, + /** + * Required if ca, cert or key are FilePath + */ + root?: FilePath, + key?: PEM, + cert?: CertificatePEMs, + ca?: PEMs, +} + +type SNIOptions = { + sni?: { + [hostname: string]: TLSOptions + } +} + +type HttpsOptions = ServerOptions & TLSOptions & SNIOptions & NodeHttpsServerOptions; + +type Http2Options = HttpsOptions & NodeHttp2ServerOptions; + +type Options = { + http?: HttpOptions | Array, + https?: HttpsOptions | Array, + http2?: Http2Options | Array, + handler?: Function, +} + +type Errors = { + message: string, + http?: Error | Error[], + https?: Error | Error[], + http2?: Error | Error[], +} + +type Servers = { + http?: HttpServer | HttpServer[], + https?: HttpsServer | HttpsServer[], + http2?: Http2SecureServer | Http2SecureServer[], +} + +type Callback = (error?: Errors, servers?: Servers) => void; + +declare function createServers(options: Options, callback: Callback): void; + +export = createServers; diff --git a/package-lock.json b/package-lock.json index 30331e2..4b39703 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "create-servers", - "version": "3.2.0", + "version": "3.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -39,6 +39,12 @@ "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", "dev": true }, + "@types/node": { + "version": "16.3.3", + "resolved": "https://artifactory.secureserver.net/artifactory/api/npm/node-virt/@types/node/-/node-16.3.3.tgz", + "integrity": "sha1-DDCt/ze7vHpQ65tY+uKlBNDYgDg=", + "dev": true + }, "array-from": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", diff --git a/package.json b/package.json index 3c1cb8b..add4f24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-servers", - "version": "3.2.0", + "version": "3.2.1", "description": "Create an http AND/OR an https server and call the same request handler.", "main": "index.js", "scripts": { @@ -27,6 +27,7 @@ "object-assign": "^4.1.0" }, "devDependencies": { + "@types/node": "^16.3.3", "evil-dns": "^0.2.0", "sinon": "^5.0.7", "tape": "~4.9.0"