@orch8.io/sdk
v0.1.0
Published
Node.js SDK for Orch8 workflow engine
Maintainers
Readme
@orch8/sdk
Node.js SDK for the Orch8 workflow engine.
Installation
npm install @orch8/sdkRequires Node.js 18+.
Quick Start
import { Orch8Client } from "@orch8/sdk";
const client = new Orch8Client({
baseUrl: "https://api.orch8.io",
tenantId: "my-tenant",
});
const seq = await client.createSequence({
name: "my-sequence",
namespace: "default",
blocks: [],
});
const inst = await client.createInstance({
sequence_id: seq.id,
context: { user_id: "123" },
});Worker
Run a polling worker that claims and executes tasks:
import { Orch8Client, Orch8Worker } from "@orch8/sdk";
const client = new Orch8Client({ baseUrl: "https://api.orch8.io", tenantId: "my-tenant" });
const worker = new Orch8Worker({
client,
workerId: "worker-1",
handlers: {
"send-email": async (task) => {
console.log(`Sending email to ${task.params.to}`);
return { sent: true };
},
},
maxConcurrent: 10,
});
await worker.start(); // blocks until worker.stop() is calledError Handling
import { Orch8Error } from "@orch8/sdk";
try {
await client.getInstance("non-existent");
} catch (err) {
if (err instanceof Orch8Error) {
console.error(`API error ${err.status} on ${err.path}`);
}
}Development
npm install
npm run build
npm test