TypeScript / JavaScript SDK
Three packages share one implementation (@causet/sdk-core). Source: causet-sdks (MIT license).
| Package | Use for |
|---|---|
@causet/sdk | Browser / bundler apps (Vite, Webpack) — re-exports sdk-core |
@causet/sdk-node | Node.js 18+ backends — createCausetClient() factory |
@causet/sdk-core | Direct dependency for custom framework integrations |
@causet/sdk-next | Next.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.
client.submitIntent() (or language equivalents) to submit intents from your application.Package status
| Field | Value |
|---|---|
| Availability | Available now |
| Maturity | Supported preview |
| Production use | Supported for pilots |
| Registry | npm — @causet/sdk, @causet/sdk-core, @causet/sdk-node, @causet/sdk-next at 0.2.0 |
| License | MIT (causet-sdks) |
| Runtime compatibility | Node.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.tsdeclarations - 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:
| Method | Use when |
|---|---|
apiKey | Server-side integrations — exchanged for a short-lived JWT via POST /v1/token |
bearerToken | Browser 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);
}
}| Error | Typical cause |
|---|---|
CausetAuthError | Missing/expired token, invalid API key |
CausetApiError | 4xx/5xx from management or runtime API |
| Rejection in result | Preflight/rule rejection — check result.error / rejection message |
Timeouts and retries
- Configure
fetchImplto wrapfetchwith 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
| Environment | apiUrl | Notes |
|---|---|---|
| Local Docker | http://localhost:8085 | Causet management API — after causet local up |
| Managed Cloud | https://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
| Operation | Method | Path |
|---|---|---|
| Token exchange | POST | /v1/token |
| Submit intent | POST | /v1/runtime/platforms/{p}/applications/{a}/intents/submit |
| Intent SSE | POST | /v1/runtime/stream/platforms/{p}/applications/{a}/intents/submit |
| Entity state | GET | /v1/platforms/{p}/applications/{a}/entities/{stream}/{id}/state |
| Run query | POST | /v1/platforms/{p}/applications/{a}/forks/{fork}/queries/{slug}/run |
| WebSocket | WS | {wsUrl} (derived from realtime host) |
| Stream SSE | GET | {realtimeUrl}/v1/platforms/{p}/applications/{a}/streams/{streamId}/events |