bun-ws-router
Version:
Lightweight client/server WebSocket router for Bun with type-safe Zod/Valibot validation.
30 lines • 1.3 kB
TypeScript
/**
* Authentication token attachment for WebSocket connections.
* See @specs/client.md#protocol-merging for protocol handling.
*/
export interface AuthConfig {
getToken?: () => string | null | undefined | Promise<string | null | undefined>;
attach?: "query" | "protocol";
queryParam?: string;
protocolPrefix?: string;
protocolPosition?: "append" | "prepend";
}
/**
* Validates protocolPrefix doesn't contain spaces or commas (RFC 6455).
* Throws TypeError if invalid.
*/
export declare function validateProtocolPrefix(prefix: string): void;
/**
* Attaches auth token to URL as query parameter.
*/
export declare function attachTokenToUrl(url: string | URL, token: string, queryParam: string): URL;
/**
* Merges user protocols with auth token protocol.
* Returns combined protocols array with deduplication.
*/
export declare function mergeProtocols(userProtocols: string | string[] | undefined, token: string | null | undefined, protocolPrefix: string, protocolPosition: "append" | "prepend"): string[] | undefined;
/**
* Retrieves auth token (handles sync/async getToken).
*/
export declare function getAuthToken(getToken?: () => string | null | undefined | Promise<string | null | undefined>): Promise<string | null | undefined>;
//# sourceMappingURL=auth.d.ts.map