/** * Sweetlink WebSocket Server * * Main server module that handles WebSocket connections and message routing. */ import { type Server as HttpServer } from 'http'; import type { Server as HttpsServer } from 'https'; import { WebSocketServer } from 'ws'; import type { ConsoleLog, HmrScreenshotData, RecordStartCommand, SweetlinkCommand, SweetlinkResponse } from '../types.js'; export type { ConsoleLog, HmrScreenshotData, SweetlinkCommand, SweetlinkResponse }; /** * Get the project root directory (where the server was started) * This is captured at server initialization time for consistency */ export declare function getProjectRoot(): string; export interface InitSweetlinkOptions { port: number; /** Number of alternative ports to try if the primary port is in use (default: 10) */ maxPortRetries?: number; /** Called when server starts successfully with the actual port */ onReady?: (port: number) => void; /** The port of the associated dev server (e.g., Next.js port). Used to validate browser connections. */ appPort?: number; /** Override the app name (default: auto-detected from package.json) */ appName?: string; /** Existing app server to expose a same-origin WebSocket endpoint on. */ appServer?: HttpServer | HttpsServer; /** Path for the same-origin WebSocket endpoint. Default: /__sweetlink */ wsPath?: string; /** * Public (proxied) URL the app is served on, e.g. a Portless HTTPS front * like https://places.localhost. Browser clients from this origin are * accepted. Defaults to SWEETLINK_APP_URL / PORTLESS_URL when set. */ publicUrl?: string; } /** * Whether a browser client's Origin is one this server legitimately serves: * the same host the WS upgrade arrived on (same-origin /__sweetlink * endpoint), a declared public/proxy origin, or a local origin resolving to * the associated app port. With no associated app port there is nothing to * pin to, so any local origin is accepted (CLI-only environments). * * This is the isolation gate for multi-project setups: without it, a * neighboring project's devbar port-scans onto this server and CLI commands * silently execute against the wrong app's page. */ export declare function isOriginServedByApp(origin: string, opts: { appPort: number | null; publicOrigins: readonly string[]; requestHost?: string | null; }): boolean; /** * Initialize Sweetlink WebSocket server * Automatically tries alternative ports if the specified port is in use */ export declare function initSweetlink(options: InitSweetlinkOptions): Promise; /** Get the port the server is running on */ export declare function getSweetlinkPort(): number | null; /** Get the associated app port */ export declare function getAssociatedAppPort(): number | null; /** Get the detected git branch */ export declare function getGitBranch(): string | undefined; /** Get the app name */ export declare function getAppName(): string | undefined; /** * Allow-list the record-start params that may cross the browser→daemon WS * boundary. The daemon HTTP API also honors `storageState` (a daemon-side * auth-replay file path) and `trace`, but those must stay CLI/HTTP-only and * never be reachable from a browser origin — so only `label`/`viewport` are * forwarded, even if a caller sends more. Returns `undefined` when there's * nothing forwardable (so the daemon sees an empty params object). */ export declare function pickForwardableRecordParams(command: RecordStartCommand): Record | undefined; export declare function closeSweetlink(): Promise; //# sourceMappingURL=index.d.ts.map