SDKsTypeScript / JavaScript

TypeScript / JavaScript SDK

Three packages share one implementation (@causet/sdk-core). Source: causet-sdks (MIT license).

PackageUse for
@causet/sdkBrowser / bundler apps (Vite, Webpack) — re-exports sdk-core
@causet/sdk-nodeNode.js 18+ backends — createCausetClient() factory
@causet/sdk-coreDirect dependency for custom framework integrations
@causet/sdk-nextNext.js App Router — React hooks + server helpers

The JavaScript / TypeScript SDK is Supported preview with Supported for pilots production use. Verified npm version: 0.2.0. See What runs today? and Support policy.

Mental model: Applications submit intents. Causet emits committed business events. Use client.submitIntent() (or language equivalents) to submit intents from your application.

Package status

FieldValue
AvailabilityAvailable now
MaturitySupported preview
Production useSupported for pilots
Registrynpm — @causet/sdk, @causet/sdk-core, @causet/sdk-node, @causet/sdk-next at 0.2.0
LicenseMIT (causet-sdks)
Runtime compatibilityNode.js 18+ (ESM); browsers with native fetch; TypeScript 5+ declarations

Installation

npm install @causet/sdk-node   # Node.js backends (recommended for retrofit)
# or
npm install @causet/sdk        # browser / Vite / React (non-Next)

Only install packages that resolve on npm. Do not reference unpublished registry coordinates in copy-paste examples.


Requirements

  • Node.js 18+ with native fetch (for @causet/sdk-node)
  • ES2022+ browser with fetch (for @causet/sdk)
  • TypeScript 5+ if you consume .d.ts declarations
  • WebSocket support for default realtime transport (or use SSE mode)

Client setup

import { CausetClient } from '@causet/sdk'; // or '@causet/sdk-node'
 
const client = new CausetClient({
  apiUrl: 'https://api.causet.cloud',   // local dev: http://localhost:8085
  platformSlug: 'my-platform',
  appSlug: 'my-app',
  forkId: 'sandbox',
  apiKey: 'ck_live_xxx.secret',          // server-side only
});
 
await client.init();

@causet/sdk-node factory:

import { createCausetClient } from '@causet/sdk-node';
 
const client = createCausetClient({
  apiUrl: process.env.CAUSET_API_URL ?? 'http://localhost:8085',
  platformSlug: process.env.CAUSET_PLATFORM,
  appSlug: process.env.CAUSET_APPLICATION,
  forkId: process.env.CAUSET_FORK ?? 'sandbox',
  apiKey: process.env.CAUSET_API_KEY,
});
await client.init();

Authentication

Provide either apiKey or bearerToken:

MethodUse when
apiKeyServer-side integrations — exchanged for a short-lived JWT via POST /v1/token
bearerTokenBrowser apps — pass a session JWT from your auth layer (Clerk, Auth0, etc.)

Never embed API keys in browser bundles. Proxy through your backend or use bearer tokens.


Submit intents

Primary API:

const result = await client.submitIntent(
  'ticket_stream',
  'tkt_1',
  'CREATE_TICKET',
  { customer_id: 'cust_1', subject: 'Help', body: 'Need assistance' },
  'optional-idempotency-key',
);
// { accepted, executionId?, error?, statePatch? }

Stream intent progress (SSE — long-running server contexts only):

await client.submitIntentStream(
  'ticket_stream', 'tkt_1', 'CREATE_TICKET', payload,
  (ev) => console.log(ev.event, ev.data),
  'optional-idempotency-key',
  abortSignal,
);

Reading state

await client.subscribe('stream_id', 'entity_id');
const state = client.getState('stream_id', 'entity_id');
await client.fetchState('stream_id', 'entity_id'); // one-shot, no cache
await client.listEntities({ streamName: 'orders', limit: 50 });

After a successful intent, the client applies statePatch from the response or refetches entity state.


Querying projections

const { items, next_cursor } = await client.runQuery(
  'urgent_tickets',
  { status: 'open' },
  { limit: 20, cursor: 'abc', includeTotal: true },
);
 
await client.listQueries();
await client.getQueryDefinition('urgent_tickets');
await client.listProjections();

Errors

import { CausetApiError, CausetAuthError, CausetError } from '@causet/sdk-core';
 
try {
  await client.submitIntent('ticket_stream', 'tkt_1', 'CREATE_TICKET', {});
} catch (e) {
  if (e instanceof CausetApiError) {
    console.error(e.statusCode, e.body);
  } else if (e instanceof CausetAuthError) {
    console.error('Auth failed:', e.message);
  }
}
ErrorTypical cause
CausetAuthErrorMissing/expired token, invalid API key
CausetApiError4xx/5xx from management or runtime API
Rejection in resultPreflight/rule rejection — check result.error / rejection message

Timeouts and retries

  • Configure fetchImpl to wrap fetch with your timeout/retry policy for HTTP calls.
  • Idempotency keys are the primary retry mechanism for intent submission — reuse the same key on safe retries.
  • Do not blindly retry non-idempotent intents without a stable idempotency key.

Idempotency

Pass a stable key as the fifth argument to submitIntent():

await client.submitIntent(
  'refund_stream', refundId, 'REFUND_REQUESTED', payload, refundId,
);

See Idempotency.


Streaming (realtime)

Live committed events come from the Realtime service — not the management API host. SDKs derive URLs from apiUrl:

const connId = await client.connectStream('ticket_stream', {
  fromCursor: 0,
  channels: [{ channel: 'ledger' }, { channel: 'state' }],
});
 
client.on('stream_event', (ev) => console.log(ev));
client.disconnectStream();

Local defaults: HTTP http://localhost:8081, WebSocket ws://localhost:8081/ws. See SSE / WebSocket.


Runtime compatibility

EnvironmentapiUrlNotes
Local Dockerhttp://localhost:8085Causet management API — after causet local up
Managed Cloudhttps://api.causet.cloud (or sandbox URL)Requires login / API key

Direct runtime API (http://localhost:8080) is for advanced local debugging only — prefer the management API for SDK integrations.

SDK 0.2.x targets the intent submission paths documented below. Sync versions via sdk-status.json.


HTTP endpoints used

OperationMethodPath
Token exchangePOST/v1/token
Submit intentPOST/v1/runtime/platforms/{p}/applications/{a}/intents/submit
Intent SSEPOST/v1/runtime/stream/platforms/{p}/applications/{a}/intents/submit
Entity stateGET/v1/platforms/{p}/applications/{a}/entities/{stream}/{id}/state
Run queryPOST/v1/platforms/{p}/applications/{a}/forks/{fork}/queries/{slug}/run
WebSocketWS{wsUrl} (derived from realtime host)
Stream SSEGET{realtimeUrl}/v1/platforms/{p}/applications/{a}/streams/{streamId}/events

Next steps