/** * OpenCloud's same-origin browser runtime client. * * Access tokens are deliberately kept inside this module. The public session * shape contains identity and expiry metadata only; token refresh is brokered * through the HttpOnly OpenCloud session cookie. */ /** Exact version of the self-hosted OpenCloud JavaScript SDK. */ export declare const OPEN_CLOUD_JS_VERSION = "0.2.2"; /** @deprecated Use {@link OPEN_CLOUD_JS_VERSION}. */ export declare const BROWSER_CLIENT_VERSION = "0.2.2"; export interface OpenCloudJavaScriptSdkConfig { package: "@opencloud/js"; version: string; module: string; types: string; docs: string; } export interface OpenCloudRuntimeConfig { appId: string; deploymentVersion: string | null; visibility: "public" | "private"; supabaseUrl: string; supabaseAnonKey: string; storageBucket: string; functionsBasePath: string; javascriptSdk: OpenCloudJavaScriptSdkConfig; /** Exact module URL; retained as a compatibility alias. */ browserClient: string; environment: string; } export interface OpenCloudSessionProfile { email: string | null; displayName: string | null; avatarUrl: string | null; } export interface OpenCloudSession { appId: string; userId: string; profile: OpenCloudSessionProfile; accessTokenExpiresAt: string; refreshAfter: string; sessionExpiresAt: string; } interface WireSession extends OpenCloudSession { accessToken: string; } export type OpenCloudAuthMode = "authenticated" | "anonymous" | "optional"; export interface OpenCloudRequestInit extends RequestInit { auth?: OpenCloudAuthMode; } export interface OpenCloudClientOptions { /** Defaults to window.location.origin. Must be an origin, not a path. */ baseUrl?: string; /** Primarily useful to deterministic browser tests. */ fetch?: typeof fetch; /** Primarily useful to deterministic browser tests. */ WebSocket?: typeof WebSocket; /** Disable only in deterministic tests; production defaults to true. */ automaticSessionRefresh?: boolean; /** Primarily useful to deterministic browser tests. */ now?: () => number; } export type RealtimeState = "idle" | "connecting" | "joined" | "reconnecting" | "closed"; export interface RealtimeChannelOptions { broadcast?: { ack?: boolean; self?: boolean; }; reconnect?: { initialDelayMs?: number; maxDelayMs?: number; }; } export interface RealtimeBroadcast { event: string; payload: unknown; } export type OpenCloudTelemetrySurface = "page" | "rest" | "storage" | "realtime" | "function" | "cron"; export interface OpenCloudTelemetrySurfaceActivity { lastActivityAt: string | null; requests24h: number; errors24h: number; lastStatus: number | null; } export interface OpenCloudTelemetryRollup { windowStart: string; windowEnd: string; calculationVersion: string; completeness: "complete" | "partial" | "corrected"; metrics: Record; createdAt: string; } export interface OpenCloudTelemetryActivity { window: { from: string; to: string; seconds: number; }; telemetry: { status: "available" | "unavailable"; latestIngestedAt: string | null; ingestionLagSeconds: number | null; sampledEntries: number; truncated: boolean; }; surfaces: Record; } /** Safe, host-bound 24-hour aggregate. It never contains raw logs or paths. */ export interface OpenCloudTelemetrySummary { appId: string; asOf: string; usage: OpenCloudTelemetryRollup | null; activity: OpenCloudTelemetryActivity; } export type OpenCloudMetricDimensions = Record; export interface OpenCloudMetricWriteOptions { dimensions?: OpenCloudMetricDimensions; /** Stable key used to make a retried measurement idempotent. */ idempotencyKey?: string; } export interface OpenCloudMetricWriteResult { accepted: number; duplicates: number; recordedAt: string; } export declare class OpenCloudError extends Error { } export declare class OpenCloudAuthError extends OpenCloudError { } declare class RuntimeResourceClient { private readonly client; private readonly basePath; private readonly defaultAuth; constructor(client: OpenCloudBrowserClient, basePath: "/rest/v1" | "/storage/v1", defaultAuth: OpenCloudAuthMode); /** * Send a path relative to this resource namespace. * * Authentication defaults to the current user. Pass `auth: "anonymous"` * only for a deliberately public REST or Storage operation. */ request(path: string, init?: OpenCloudRequestInit): Promise; } export declare class OpenCloudFunctionsClient { private readonly client; constructor(client: OpenCloudBrowserClient); /** Invoke a verifyJwt:true function with the current user's bearer token. */ invoke(name: string, init?: Omit): Promise; /** * Invoke a verifyJwt:false function. * * OpenCloud still supplies the anonymous project identity required by the * gateway, even when a signed-in user has an active brokered session. */ invokePublic(name: string, init?: Omit): Promise; } export declare class OpenCloudTelemetryClient { private readonly request; constructor(request: (path: string, init?: RequestInit) => Promise); /** * Read the exact, safe 24-hour activity and latest usage-rollup shape. * * Missing activity is quiet or unknown, never proof of health. Check * `activity.telemetry.status`, `latestIngestedAt`, and `truncated`. */ summary(): Promise; /** Add a non-negative delta to a deployment-declared counter. */ increment(name: string, value?: number, options?: OpenCloudMetricWriteOptions): Promise; /** Record the current value of a deployment-declared gauge. */ gauge(name: string, value: number, options?: OpenCloudMetricWriteOptions): Promise; private write; } interface ChannelDependencies { config: () => Promise; session: (forceRefresh: boolean) => Promise; WebSocket: typeof WebSocket; setTimer: (handler: () => void, timeoutMilliseconds: number) => ReturnType; clearTimer: (timer: ReturnType) => void; } export declare class OpenCloudPrivateRealtimeChannel { private readonly channelName; private readonly dependencies; private readonly options; private stateValue; private socket; private joinReference; private reference; private reconnectAttempt; private reconnectTimer; private heartbeatTimer; private connectPromise; private resolveConnect; private rejectConnect; private deliberatelyClosed; private readonly broadcastHandlers; private readonly stateHandlers; private readonly initialReconnectDelay; private readonly maxReconnectDelay; constructor(channelName: string, dependencies: ChannelDependencies, options?: RealtimeChannelOptions); /** Current connection lifecycle state. */ get state(): RealtimeState; /** Register a broadcast handler and return its unsubscribe function. */ onBroadcast(handler: (message: RealtimeBroadcast) => void): () => void; /** Register a state handler and return its unsubscribe function. */ onStateChange(handler: (state: RealtimeState) => void): () => void; /** Connect or resolve immediately when already joined. */ connect(): Promise; /** Ensure the channel is joined and send a private broadcast. */ broadcast(event: string, payload: unknown): Promise; /** Permanently stop reconnect/heartbeat behavior and close the socket. */ close(): void; private open; private join; private handleMessage; private topic; private scheduleReconnect; private startHeartbeat; private stopHeartbeat; private clearTimers; private rejectPending; private clearPending; private setState; private nextReference; } export declare class OpenCloudRealtimeClient { private readonly client; constructor(client: OpenCloudBrowserClient); /** Create a private app-scoped logical channel. */ channel(name: string, options?: RealtimeChannelOptions): OpenCloudPrivateRealtimeChannel; } export declare class OpenCloudBrowserClient { readonly rest: RuntimeResourceClient; readonly storage: RuntimeResourceClient; readonly functions: OpenCloudFunctionsClient; readonly realtime: OpenCloudRealtimeClient; readonly telemetry: OpenCloudTelemetryClient; private readonly baseUrl; private readonly fetcher; private readonly WebSocketImplementation; private readonly automaticSessionRefresh; private readonly now; private configValue; private configPromise; private wireSession; private sessionPromise; private refreshTimer; /** Create a same-origin client. Prefer {@link createOpenCloudClient}. */ constructor(options?: OpenCloudClientOptions); /** Read and cache host-bound runtime configuration. */ config(): Promise; /** * Return the safe current-user profile and exact expiry metadata. * Access and refresh tokens are never returned by this public API. */ session(options?: { refresh?: boolean; }): Promise; /** @internal Used by resource namespaces to preserve SDK auth behavior. */ runtimeRequest(path: string, init: OpenCloudRequestInit, auth: OpenCloudAuthMode): Promise; /** Stop automatic session refresh and clear cached session state. */ dispose(): void; /** @internal Used by the first-party Realtime namespace. */ realtimeDependencies(): ChannelDependencies; private loadSession; private scheduleRefresh; private cancelRefresh; } /** Create one same-origin OpenCloud client for the current app. */ export declare function createOpenCloudClient(options?: OpenCloudClientOptions): OpenCloudBrowserClient; export {}; //# sourceMappingURL=index.d.ts.map