JavaScript SDK API reference
CURRENT · 0.2.2
The OpenCloud browser SDK is the self-hosted ESM package @opencloud/js. Create one client per application origin:
js
const runtime = await fetch("/_opencloud/config").then((response) =>
response.json(),
);
const { createOpenCloudClient } = await import(
runtime.javascriptSdk.module
);
const opencloud = createOpenCloudClient();Client API
| API | Returns | Details |
|---|---|---|
createOpenCloudClient(options?) | OpenCloudClient | Client creation |
opencloud.config() | Promise<OpenCloudRuntimeConfig> | Runtime configuration |
opencloud.session(options?) | Promise<OpenCloudSession | null> | Safe session |
opencloud.rest.request(path, init?) | Promise<Response> | REST requests |
opencloud.storage.request(path, init?) | Promise<Response> | Storage requests |
opencloud.functions.invoke(name, init?) | Promise<Response> | Authenticated Functions |
opencloud.functions.invokePublic(name, init?) | Promise<Response> | Public Functions |
opencloud.realtime.channel(name, options?) | RealtimeChannel | Private Realtime |
opencloud.telemetry.summary() | Promise<OpenCloudTelemetrySummary> | Telemetry summary |
opencloud.telemetry.increment(name, value?, options?) | Promise<OpenCloudMetricWriteResult> | Custom counters |
opencloud.telemetry.gauge(name, value, options?) | Promise<OpenCloudMetricWriteResult> | Custom gauges |
opencloud.dispose() | void | Release client state |
Realtime channel API
| API | Returns |
|---|---|
channel.onStateChange(handler) | Unsubscribe function |
channel.onBroadcast(handler) | Unsubscribe function |
channel.connect() | Promise<void> |
channel.broadcast(event, payload) | Promise<void> |
channel.close() | void |
Types and errors
The exact declarations for the current release are available from the versioned index.d.ts. See Errors for OpenCloudError and OpenCloudAuthError, and Versioning before pinning an SDK URL.
The SDK keeps access and refresh tokens private. Application code receives only the safe session shape documented above.