import type { api } from '@replit/protocol'; import type { Channel } from './channel'; import CrosisError from './util/CrosisError'; export declare enum ConnectionState { CONNECTING = 0, CONNECTED = 1, DISCONNECTED = 2 } export declare enum FetchConnectionMetadataError { Aborted = "Aborted", Retriable = "Retriable" } export interface GovalMetadata { token: string; gurl: string; conmanURL: string; wsURL: string; dotdevHostname: string; } export type Result = (Res & { error: null; }) | { error: Err; }; export type FetchConnectionMetadataResult = Result; export interface ConnectOptions { fetchConnectionMetadata: (abortSignal: AbortSignal) => Promise; timeout: number | null; WebSocketClass?: typeof WebSocket; context: Ctx; reuseConnectionMetadata: boolean; pollingHost?: string; getNextRetryDelayMs: (tryCount: number) => number; } export interface UrlOptions { secure: boolean; host: string; port: string; } export interface OpenOptions extends Partial> { fetchConnectionMetadata: (abortSignal: AbortSignal) => Promise; urlOptions?: UrlOptions; context: Ctx; } export declare enum ClientCloseReason { Intentional = "Intentional", Temporary = "Temporary", Disconnected = "Disconnected", ErrorOrDestroy = "ErrorOrDestroy" } export type DebugLogBreadcrumb = { type: 'breadcrumb'; message: 'constructor' | 'status:open' | 'status:connected' | 'status:closed' | 'status:reconnecting' | 'status:destroy' | 'close:intentional' | 'close:temporary' | 'timeout:cancel' | 'timeout:reset' | 'timeout:hit' | 'websocket:polling fallback'; } | { type: 'breadcrumb'; message: 'status:connecting'; data: { connectionState: ConnectionState; connectTries: number; websocketFailureCount: number; readyState: WebSocket['readyState'] | undefined; chan0CbExists: boolean; }; } | { type: 'breadcrumb'; message: 'status:retrying'; data: { connectionState: ConnectionState; connectTries: number; websocketFailureCount: number; error: CrosisError; wsReadyState?: WebSocket['readyState']; }; } | { type: 'breadcrumb'; message: 'container:state'; data: api.ContainerState.State; } | { type: 'breadcrumb'; message: 'websocket:close'; data?: { event: CloseEvent | Event; }; } | { type: 'breadcrumb'; message: 'websocket:cleanup'; data: { hasWs: boolean; readyState: WebSocket['readyState'] | null; connectionState: ConnectionState; }; } | { type: 'breadcrumb'; message: 'requestOpenChannel'; data?: { name: ChannelOptions['name']; service: ChannelOptions['service']; action: ChannelOptions['action']; ref: string; }; } | { type: 'breadcrumb'; message: 'requestOpenChannel:openChanRes'; data: { id: number; state: api.OpenChannelRes['state']; error: string; ref: string; }; } | { type: 'breadcrumb'; message: 'requestOpenChannel:explicit skip'; data: { service: ChannelOptions['service']; name: ChannelOptions['name']; }; } | { type: 'breadcrumb'; message: 'requestCloseChannel'; data: { id: number; name: ChannelOptions['name']; service: ChannelOptions['service']; }; } | { type: 'breadcrumb'; message: 'requestCloseChannel:chan0Closed'; data: { id: number; name: ChannelOptions['name']; service: ChannelOptions['service']; }; } | { type: 'breadcrumb'; message: 'requestCloseChannel:closeChanRes'; data: { id: number; name: ChannelOptions['name']; service: ChannelOptions['service']; closeStatus: api.CloseChannelRes.Status; }; } | { type: 'breadcrumb'; message: 'client:redirectInitiatorFallback'; data: { connectionState: ConnectionState; connectTries: number; websocketFailureCount: number; error: CrosisError; wsReadyState?: WebSocket['readyState']; }; } | { type: 'breadcrumb'; message: 'client:handleRedirect'; data: { connectionMetadata: GovalMetadata | null; }; } | { type: 'breadcrumb'; message: 'client:handleClose'; data: { closeReason: ClientCloseReason; connectionState: ConnectionState; }; } | { type: 'breadcrumb'; message: 'client:handleClose:closing channel'; data: { channelId: number | null; service: ChannelOptions['service']; name: ChannelOptions['name']; closeRequested: boolean; channelRequestIsOpen: boolean; willChannelReconnect: boolean; hasWs: boolean; }; } | { type: 'breadcrumb'; message: 'client:handleClose:out of sync'; data: { channelId: number | null; status: string; service: string | undefined; name: ChannelOptions['name']; }; } | { type: 'breadcrumb'; message: 'client:openChannel:delayed'; data: { service: ChannelOptions['service']; name: ChannelOptions['name']; connectionState: ConnectionState; }; } | { type: 'breadcrumb'; message: 'client:closeChannel:channel not open'; data: { channelId: number | null; service: ChannelOptions['service']; name: ChannelOptions['name']; connectionState: ConnectionState; }; } | { type: 'breadcrumb'; message: 'client:closeChannel:already requested'; data: { channelId: number | null; service: ChannelOptions['service']; name: ChannelOptions['name']; }; } | { type: 'breadcrumb'; message: 'onUnrecoverableError'; data: { message: string; }; }; export type DebugLog = DebugLogBreadcrumb | { type: 'log'; log: { direction: 'in' | 'out'; channel: { id: number; name?: ChannelOptions['name']; service?: ChannelOptions['service']; }; cmd: api.Command; }; }; export type ChannelCloseReason = { initiator: 'client'; willReconnect: boolean; } | { initiator: 'channel'; willReconnect: false; }; interface ServiceThunk { (context: Ctx): string; } export declare enum ChannelRequestPriority { High = 0, Medium = 1, Low = 2 } export interface ChannelOptions { name?: string; service: string | ServiceThunk; action?: api.OpenChannel.Action; skip?: (context: Ctx) => boolean; priority?: ChannelRequestPriority; } export type OpenChannelCb = (res: { channel: Channel; context: Ctx; }) => void | ((reason: ChannelCloseReason) => void); export interface RequestResult extends api.Command { channelClosed?: ChannelCloseReason; } export declare const CloseCode: { INVALID_UPSTREAM_RESPONSE: number; POLICY_VIOLATION: number; FIREWALL_DENIED: number; TRY_ANOTHER_MACHINE: number; USER_ERROR: number; CONCURRENT_REPL_LIMIT: number; }; export {};