HTTP SDK

createHttpSdkFactory returns a factory that creates typed SDK clients bound to a base URL. Like the local SDK, the factory is parameterized with your Router type for compile-time checks on workflowId and params.

Setup

import { createHttpSdkFactory } from "yieldstar";
import type { Router } from "./shared";

const createSdk = createHttpSdkFactory<Router>();
const sdk = createSdk({ url: "http://localhost:8080" });

The factory accepts fetchOptions to pass custom headers or other RequestInit properties to every request:

const sdk = createSdk({
  url: "http://localhost:8080",
  fetchOptions: {
    headers: { Authorization: "Bearer token" },
  },
});

sdk.trigger

Sends a POST to /trigger. Returns an object with executionId, ack(), and waitForResult().

const exec = await sdk.trigger({
  workflowId: "process-order",
  params: { orderId: "abc123" },
});

exec.ack()

Reads the trigger response body. Returns { executionId }.

const { executionId } = await exec.ack();

exec.waitForResult()

Sends a POST to /events with the executionId and blocks until the workflow completes. Returns the result.

const result = await exec.waitForResult();

If the workflow threw an error, waitForResult deserializes and re-throws it with the original stack trace.

Trigger event shape

FieldTypeRequiredDescription
workflowIdstringYesID matching a key in the router
paramsRecord<string, any>Depends on workflow typeInput data accessible via event.params inside the workflow
executionIdstringNoCustom execution ID. Auto-generated via nanoid if omitted
contextRecord<string, any>NoAdditional context passed through middleware