Skip to content
← All SDKs
TS

TypeScript / Node.js SDK

npm install @orch8.io/sdk

Features

  • Single package: @orch8.io/sdk (client, builder, and polling worker)
  • 80+ methods covering all engine domains — sequences, instances, pools, credentials, circuit breakers, approvals, SSE streaming, and more
  • Fluent WorkflowBuilder with .step(), .parallel(), .race(), .loop(), .forEach(), .router(), .tryCatch(), .subSequence(), .abSplit(), .cancellationScope(), .delay(), .raw()
  • Polling worker with circuit breaker awareness — skips handlers with open breakers
  • Exponential backoff on poll failures (doubles up to 30s, resets on success)
  • onTaskComplete / onTaskFail observability callbacks
  • SSE streaming via async generator for real-time instance progress
  • Full TypeScript types with Zod schema validation on build()

Client methods (80)

Full management surface covering all engine API domains.

  • listSequences / createSequence / getSequence / getSequenceByName / deleteSequence / deprecateSequence / listSequenceVersions / migrateInstance
  • createInstance / batchCreateInstances / getInstance / listInstances / updateInstanceState / updateInstanceContext / sendSignal / retryInstance / injectBlocks / streamInstance
  • getOutputs / getExecutionTree / listAuditLog
  • listCheckpoints / saveCheckpoint / getLatestCheckpoint / pruneCheckpoints
  • bulkUpdateState / bulkReschedule / listDLQ
  • listApprovals
  • listWorkerTasks / getWorkerTaskStats / pollTasks / pollTasksFromQueue / completeTask / failTask / heartbeatTask
  • createCron / listCron / getCron / updateCron / deleteCron
  • createTrigger / listTriggers / getTrigger / deleteTrigger / fireTrigger
  • createPlugin / listPlugins / getPlugin / updatePlugin / deletePlugin
  • createSession / getSession / getSessionByKey / updateSessionData / updateSessionState / listSessionInstances
  • listPools / createPool / getPool / deletePool / listPoolResources / createPoolResource / updatePoolResource / deletePoolResource
  • listCredentials / createCredential / getCredential / deleteCredential / updateCredential
  • listCircuitBreakers / getCircuitBreaker / resetCircuitBreaker / listTenantCircuitBreakers / getTenantCircuitBreaker / resetTenantCircuitBreaker
  • listClusterNodes / drainNode / health

API coverage

The engine exposes 122+ REST endpoints across 20 domains. = full, ~ = partial, W = via worker SDK, = use REST API directly.

DomainEndpointsThis SDK
Sequences7
Instances13
Checkpoints4
Audit log1
Bulk operations2
Dead letter queue1
Worker tasks7
Cron schedules5
Triggers5
Plugins5
Sessions6
Credentials5
Resource pools8
Approvals1
Circuit breakers6incl. per-tenant
Cluster2
Health2~ready only
SSE streaming1
Instance migration1
Block injection1

Management Client

Full API surface — sequences, instances, pools, credentials, cron, triggers, sessions, DLQ, circuit breakers, and more.

import { Orch8Client } from "@orch8.io/sdk";

const client = new Orch8Client({
  baseUrl: "http://localhost:8080",
  tenantId: "my-tenant",
  apiKey: "optional-bearer-token",
});

// Create a sequence definition
const seq = await client.createSequence({
  tenant_id: "my-tenant",
  namespace: "default",
  name: "onboarding-drip",
  version: 1,
  blocks: [
    { type: "Step", handler: "send_welcome_email" },
    { type: "Step", handler: "wait_48h", delay: "48h" },
    { type: "Router", handler: "check_engagement", routes: {
      engaged: "send_tips",
      inactive: "send_reminder",
    }},
  ],
});

// Schedule an instance
const instance = await client.createInstance({
  sequence_id: seq.id,
  tenant_id: "my-tenant",
  context: { data: { userId: "usr_123", email: "user@example.com" } },
});

// Send a signal
await client.sendSignal(instance.id, "update_context", {
  preferences: "weekly",
});

Workflow Builder

Fluent API for defining sequences in code. Chain blocks, add delays, nest parallel and try-catch — then call .build() to validate with Zod and get the JSON definition.

import { workflow, Orch8Client } from "@orch8.io/sdk";

const onboarding = workflow("onboarding-drip")
  .step("send_welcome", "send_welcome_email")
  .delay("2d")
  .step("check_activation", "http_request", {
    method: "GET",
    url: "https://api.yourapp.com/users/{{context.user_id}}/activation",
  })
  .router("engagement_branch", [
    { condition: "{{steps.check_activation.output.active}}", blocks: [
      { type: "Step", id: "send_tips", handler: "send_tips_email" },
    ]},
  ], { type: "Step", id: "send_reminder", handler: "send_reminder_email" })
  .tryCatch("safe_crm_update",
    (b) => b.step("crm_update", "update_hubspot"),
    (b) => b.step("log_error", "log", { level: "error" }),
  )
  .build(); // Validates with Zod, returns sequence JSON

// Deploy
const client = new Orch8Client({
  baseUrl: "http://localhost:8080",
  tenantId: "my-tenant",
});
await client.createSequence(onboarding);

Polling Worker

Register handler functions and let the worker poll, execute, heartbeat, and report results automatically.

import { Orch8Worker } from "@orch8.io/sdk";

const worker = new Orch8Worker({
  engineUrl: "http://localhost:8080",
  workerId: "worker-1",
  pollIntervalMs: 1000,       // poll every 1s per handler
  heartbeatIntervalMs: 15000,  // heartbeat every 15s
  maxConcurrent: 10,           // across all handlers
  handlers: {
    send_welcome_email: async (task) => {
      const { email } = task.context.data;
      await sendEmail(email, "Welcome!");
      return { sent: true };
    },
    check_engagement: async (task) => {
      const score = await getEngagementScore(task.context.data.userId);
      return { route: score > 50 ? "engaged" : "inactive" };
    },
  },
});

await worker.start();
// worker.stop() for graceful shutdown (30s drain)

Full API reference

All SDKs cover the complete engine API. For the raw REST documentation including request/response schemas and authentication details, see the API reference.

View full API reference (122+ endpoints) →