/** * Shared utility functions for @oxpulse/chat-sdk. * * Mirror: web/src/lib/api/sdkChat.ts contains equivalent implementations. * Keep in sync when modifying either file. */ import type { SDKChatErrorCode, TypingEvent, PresenceEvent, ReadReceiptEvent } from './types.js'; /** Callbacks accepted by dispatchTransient — subset of SubscribeArgs / SubscribeOpts. */ export interface TransientCallbacks { onTyping?: (event: TypingEvent) => void; onPresence?: (event: PresenceEvent) => void; onReadReceipt?: (event: ReadReceiptEvent) => void; } /** * Route a transient SSE event (typing / presence / read_receipt) to the * appropriate callback. * * Single source of truth — imported by both packages/chat-sdk/src/client.ts * and web/src/lib/api/sdkChat.ts. Keep in sync with the event shapes emitted * by sdk_presence.rs. */ export declare function dispatchTransient(evType: string, data: Record, callbacks: TransientCallbacks): void; /** * ArrayBuffer → standard base64 string (with `+`/`/`, with padding). * * B2 fix: server uses `base64::engine::general_purpose::STANDARD` which rejects * URL-safe characters (`-`, `_`). All sealed payload round-trips MUST use this * function so client-produced base64 survives server decode. * * @deprecated `arrayBufferToBase64url` (URL-safe, no padding) is kept for * backward-compat with any existing callers outside this package; new code * MUST use `arrayBufferToBase64`. */ export declare function arrayBufferToBase64(buf: ArrayBuffer): string; /** base64 (standard or url-safe, with or without padding) → ArrayBuffer. */ export declare function base64ToArrayBuffer(b64: string): ArrayBuffer; /** Map an HTTP status code to an SDKChatErrorCode. */ export declare function httpStatusToCode(status: number): SDKChatErrorCode; /** * Reconnect backoff with ±20% jitter and a configurable schedule. * * `base = schedule[attempt] ?? fallback`, then `Math.round(base * (0.8 + * Math.random() * 0.4))` spreads concurrent client retries across a window so * a server restart with N peers doesn't trigger N synchronised retry waves at * T+1s, T+2s… * * Same shape as `web/src/lib/reconnect-backoff.ts` — mirrored here as the * canonical SDK implementation. `backoffMs` is a thin opt-out wrapper over * this function using the default exponential schedule + 30 s fallback. * * @param attempt 0-based reconnect attempt index. * @param schedule readonly base delays indexed by attempt; defaults to the * exponential `[1000, 2000, 4000, 8000, 16000, 30000]`. * @param fallback base delay used once `attempt` exceeds `schedule.length`; * defaults to `30000`. * @returns jittered delay in ms (±20% of the base). */ export declare function backoffWithJitter(attempt: number, schedule?: readonly number[], fallback?: number): number; /** * Returns jittered backoff in ms. Caps at 30 s. * * Thin wrapper over `backoffWithJitter` using the default exponential schedule * + 30 s fallback. Signature unchanged (backward compatible) — existing * callers (`client.ts`) are unaffected. */ export declare function backoffMs(attempt: number): number; /** * Generate a UUID v4 using a cryptographically-secure RNG. * * F13 (fail-closed CSPRNG): `crypto.randomUUID` is preferred; otherwise the 16 random bytes * come from `crypto.getRandomValues`. When NEITHER is available we THROW rather than fall back * to `Math.random()` — a non-CSPRNG would be a SILENT security downgrade for any caller that * treats the id as unpredictable, and this is a public export (index.ts) usable for nonces / * session ids, not only message ids. On every supported runtime — a browser secure origin, or * Node >= 18 with WebCrypto (`globalThis.crypto`) — `getRandomValues` is present, so the throw * is unreachable in practice; it converts an unsupported/insecure runtime into a loud error * instead of weak randomness. */ export declare function generateUUID(): string; //# sourceMappingURL=utils.d.ts.map