|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * [BSD-3-Clause](https://github.com/perki/backloop.dev/blob/main/LICENSE) |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * HTTPS options for use with Node.js https.createServer() |
| 8 | + */ |
| 9 | +export interface HttpsOptions { |
| 10 | + /** Private key in PEM format */ |
| 11 | + key: string; |
| 12 | + /** Certificate in PEM format */ |
| 13 | + cert: string; |
| 14 | + /** Certificate Authority chain in PEM format */ |
| 15 | + ca: string; |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Callback for httpsOptionsAsync |
| 20 | + */ |
| 21 | +export type HttpsOptionsCallback = (error: Error | null, options?: HttpsOptions) => void; |
| 22 | + |
| 23 | +/** |
| 24 | + * Synchronously returns HTTPS options for backloop.dev certificates. |
| 25 | + * If certificates are missing or expired, attempts an automatic update |
| 26 | + * and exits the process. |
| 27 | + * |
| 28 | + * @returns HTTPS options object with key, cert, and ca properties |
| 29 | + * |
| 30 | + * @example |
| 31 | + * ```js |
| 32 | + * const https = require('https'); |
| 33 | + * const { httpsOptions } = require('backloop.dev'); |
| 34 | + * |
| 35 | + * https.createServer(httpsOptions(), app).listen(443); |
| 36 | + * ``` |
| 37 | + */ |
| 38 | +export function httpsOptions(): HttpsOptions; |
| 39 | + |
| 40 | +/** |
| 41 | + * Asynchronously retrieves HTTPS options using a callback. |
| 42 | + * Updates certificates if needed before returning. |
| 43 | + * |
| 44 | + * @param done - Callback called with (error, options) |
| 45 | + * |
| 46 | + * @example |
| 47 | + * ```js |
| 48 | + * const { httpsOptionsAsync } = require('backloop.dev'); |
| 49 | + * |
| 50 | + * httpsOptionsAsync((err, options) => { |
| 51 | + * if (err) throw err; |
| 52 | + * https.createServer(options, app).listen(443); |
| 53 | + * }); |
| 54 | + * ``` |
| 55 | + */ |
| 56 | +export function httpsOptionsAsync(done: HttpsOptionsCallback): void; |
| 57 | + |
| 58 | +/** |
| 59 | + * Asynchronously retrieves HTTPS options using a Promise. |
| 60 | + * Updates certificates if needed before returning. |
| 61 | + * |
| 62 | + * @returns Promise resolving to HTTPS options |
| 63 | + * |
| 64 | + * @example |
| 65 | + * ```js |
| 66 | + * const { httpsOptionsPromise } = require('backloop.dev'); |
| 67 | + * |
| 68 | + * const options = await httpsOptionsPromise(); |
| 69 | + * https.createServer(options, app).listen(443); |
| 70 | + * ``` |
| 71 | + */ |
| 72 | +export function httpsOptionsPromise(): Promise<HttpsOptions>; |
0 commit comments