Complete developer reference for @vaakworkflow/sdk and the workflow execution REST API. Build fluent DAG workflows and control distributed execution pools.
Type-safe, fluent workflow construction DSL with automatic Saga compensation and crash-resilient step dispatching.
import { WorkflowEngine, WorkflowBuilder } from '@vaakworkflow/sdk';
// 1. Define a strongly-typed DAG Workflow
const orderWorkflow = new WorkflowBuilder('order-fulfillment-pipeline')
.step('validate-order', async (ctx) => {
const isValid = await verifyStock(ctx.input.orderId);
if (!isValid) throw new Error('Insufficient inventory');
return { validatedAt: new Date().toISOString() };
})
.step('process-payment', async (ctx) => {
const payment = await paymentGateway.charge({
customerId: ctx.input.customerId,
amount: ctx.input.amount
});
return { transactionId: payment.id };
}, { retries: 3, backoff: 'exponential' })
.fork('parallel-fulfillment', [
(branch) => branch.step('reserve-warehouse', async (ctx) => {
return await warehouseService.reserve(ctx.input.orderId);
}),
(branch) => branch.step('generate-tax-invoice', async (ctx) => {
return await taxService.generateInvoice(ctx.input.orderId);
})
], { join: 'wait-all' })
.step('dispatch-notification', async (ctx) => {
await emailService.sendOrderConfirmed(ctx.input.customerId);
})
.onFailure(async (ctx, error) => {
// Automatic Saga compensation
console.error(`Workflow ${ctx.executionId} failed at ${ctx.failedStep}:`, error);
await ctx.compensate();
})
.build();
// 2. Initialize Engine & Execute
const engine = new WorkflowEngine({
databaseUrl: process.env.VAAKWORKFLOW_DB_URL,
concurrency: 50,
workerPool: 'production-orders'
});
const execution = await engine.execute(orderWorkflow, {
orderId: 'ord_98721',
amount: 1499.00,
customerId: 'cust_4482'
});
console.log(`Execution started with ID: ${execution.id}`);
const result = await execution.waitForResult();
console.log('Workflow status:', result.status);
Administrative HTTP endpoints for external orchestrators, CI/CD pipelines, and operations consoles.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/workflows |
List all registered workflow definitions, current revisions, and schema hashes. |
POST |
/api/v1/workflows |
Register or update a declarative JSON DAG workflow blueprint. |
POST |
/api/v1/workflows/:id/execute |
Trigger a new execution run with custom payload and idempotency key. |
GET |
/api/v1/executions/:id |
Retrieve real-time execution status, completed steps, and state machine context. |
POST |
/api/v1/executions/:id/pause |
Pause an active execution safely at the next atomic step boundary. |
POST |
/api/v1/executions/:id/resume |
Resume a paused workflow run from its last durable write-ahead checkpoint. |
POST |
/api/v1/executions/:id/cancel |
Terminate execution immediately and trigger defined Saga rollback handlers. |
GET |
/api/v1/executions/:id/history |
Inspect immutable state machine transition timeline and step logs. |