import { type Socket } from 'socket.io-client'; import type { InboxPushName, InboxPushes, InboxRequestName, InboxRequests } from './events'; import type { MediaUploader } from '../types/inbox'; export interface InboxClientOptions { /** * Where the inbox socket listens. Its own origin, not the REST gateway's: the * gateway proxies HTTP only and forwards no upgrade. */ url: string; /** * Ecosystem bearer token, or a function returning one. A function is called on * every connect, so a reconnect after an expiry picks up a fresh token instead * of retrying with the one that just failed. */ token: string | (() => string | Promise); /** Your ecosystem client id. Sent on the handshake, as on every REST call. */ clientId: string; /** Socket.IO path, if the deployment moved it. */ path?: string; /** How long a request waits for its acknowledgement. Default 20s. */ timeout?: number; /** Connect on construction. Default `true`. */ autoConnect?: boolean; /** Extra socket.io options, merged last. */ socketOptions?: Record; /** * How to upload a file, for `messages.sendMedia({ file })`. * * A socket cannot presign -- the ticket comes from the REST API -- so this is * the seam between the two. Satisfied by * `crm.inboxMedia.upload.bind(crm.inboxMedia)`. * * Optional, and a function rather than a client, so an app that only ever sends * an already-uploaded `link` pulls in none of the REST surface. */ uploadMedia?: MediaUploader; } /** * The live-chat inbox over a socket. * * Requests are promises: each emit carries an acknowledgement callback, so two * concurrent reads of different threads cannot be confused for one another. The * server also emits replies under the request's own event name for older clients * -- {@link InboxClient.on} sees those too, which is why a handler for * `chat.action` receives both your own actions and other agents'. * * Credentials travel in `auth`, not in a header: a browser cannot set headers on * a WebSocket upgrade, so a header-based handshake only works for as long as the * connection stays on long-polling. */ export declare class InboxClient { private readonly options; private readonly socket; private readonly timeout; /** * The uploader this client was built with, if any. * * Read by `messages.sendMedia` when it is handed a file rather than a link. */ get uploadMedia(): MediaUploader | undefined; constructor(options: InboxClientOptions); /** Resolved per connect, so a reconnect never reuses an expired token. */ private credentials; /** The underlying socket, for lifecycle events and anything not wrapped here. */ get raw(): Socket; get connected(): boolean; connect(): this; disconnect(): this; /** Resolves once connected, or rejects with the handshake's reason. */ ready(): Promise; /** * Sends one request and waits for its answer. * * A refusal rejects with a {@link CrmApiError} carrying the same code and status * the REST API would have returned, so one error path covers both transports. */ request(event: E, payload: InboxRequests[E]['payload']): Promise; /** * Listens for a pushed event. Returns the unsubscribe function, so a component * can tear its own listener down without knowing what else is attached. */ on(event: E, handler: (payload: InboxPushes[E]) => void): () => void; /** Fires once, then unsubscribes. */ once(event: E, handler: (payload: InboxPushes[E]) => void): void; }