//#region src/service.d.ts /** * The service configuration. */ interface Service { /** * The host of the service. */ readonly host: string; /** * The port of the service. */ readonly port: number; /** * The login name for the service, if any. */ readonly user?: string; /** * The URL pattern of the service, if any. */ readonly urlPattern: RegExp; /** * Extra options for the `ssh` command, if any. * @since 0.3.0 */ readonly extraOptions?: readonly string[]; /** * Extra arguments for the `ssh` command, if any. * @since 0.3.0 */ readonly extraArgs?: readonly string[]; /** * Trusted SSH host public keys, grouped by OpenSSH `known_hosts` host * pattern. Use `[hostname]:port` for a service on a nonstandard SSH port. * Multiple keys can be supplied for staged key rotation or different host * key algorithms. * @since 0.5.0 */ readonly knownHosts?: Readonly>; } /** * Available services. */ type BuiltInServiceName = "serveo.net" | "pinggy.io"; declare const SERVICES: Readonly>; //#endregion //#region src/index.d.ts type ServiceRegistryShape = { readonly [TName in keyof TServices]-?: Service }; type ServiceName = Extract; interface BaseTunnelOptions> { /** * The local port to expose. */ readonly port: number; /** * The name of the service to use. If not provided, a random service will be * chosen. If provided, the `exclude` option is ignored. */ readonly service?: ServiceName; /** * The service names to exclude from the random selection. If the `service` * option is provided, this option is ignored. */ readonly exclude?: readonly ServiceName[]; /** * The maximum number of milliseconds to wait for a service to provide a * tunnel URL. It must be between 0 and 2,147,483,647 milliseconds. If * omitted, the default is 10 seconds. */ readonly startupTimeout?: number; } interface DefaultServicesOption { /** * The services to use. If not provided, {@link SERVICES} will be used. */ readonly services?: typeof SERVICES; } interface CustomServicesOption> { /** * The services to use instead of {@link SERVICES}. */ readonly services: TServices; } /** * Checks if `ssh` is installed on the system. * @returns `true` if `ssh` is installed, `false` otherwise. */ declare function isSshInstalled(): Promise; /** * The tunnel options using the default {@link SERVICES} registry. */ type TunnelOptions = BaseTunnelOptions & DefaultServicesOption; /** * The tunnel options using a custom service registry. */ type CustomTunnelOptions> = BaseTunnelOptions & CustomServicesOption; /** * The opened tunnel. */ interface Tunnel { /** * The public URL of the tunnel. */ readonly url: URL; /** * The local port being exposed. */ readonly localPort: number; /** * The process ID of the `ssh` process. */ readonly pid: number | undefined; /** * Closes the tunnel and resolves after the SSH process and its temporary * resources have been cleaned up. */ close(): Promise; } /** * Opens a tunnel to the specified port. * * @example * ```typescript * const tunnel = await openTunnel({ port: 8000 }); * console.log(tunnel.url.href); * alert("Press Enter to close the tunnel."); * await tunnel.close(); * ``` * * @param options The tunnel options. * @returns The public URL of the tunnel. * @throws {Error} If the `ssh` is not installed on the system. */ declare function openTunnel(options: TunnelOptions): Promise; declare function openTunnel>(options: CustomTunnelOptions): Promise; //#endregion export { CustomTunnelOptions, SERVICES, type Service, Tunnel, TunnelOptions, isSshInstalled, openTunnel };