import type { DeclarativeFlow, DeployResult, Job, JsonObject, StartResult, Workflow } from "./types.js"; /** Render a workflow (either surface) to its executable BPMN model. */ export declare function toBpmn(wf: Workflow): string; /** * Render a workflow to *deployable* BPMN — the executable model plus diagram * interchange (DI), auto-generated with `bpmn-auto-layout` — so the deployed * process opens rendered and inspectable in a modeller/Operate rather than as a * blank canvas. The semantic model stays authoritative; DI is derived. * * DI generation needs the optional peer dependency `bpmn-auto-layout`. When it is * absent, this degrades gracefully: it warns once and returns the DI-less model * so `deploy` still works everywhere. Pass `{ layout: false }` to skip layout * deliberately. A genuine layout failure (the dep is installed but errors) is * surfaced, not swallowed. */ export declare function toDeployableBpmn(wf: Workflow, opts?: { layout?: boolean; }): Promise; /** * The subset of the `@nanobpm/nano-sdk` (Camunda orchestration-cluster) client * that the workflow surface uses. `createCamundaClient` returns a superset of * this, so a test — or an author bringing their own transport (e.g. the embedded * engine) — can inject any object satisfying it. */ export interface NanoSdkClient { createDeployment(input: { resources: File[]; [k: string]: unknown; }, options?: unknown): Promise; createProcessInstance(input: { processDefinitionId: string; variables?: JsonObject; }, options?: unknown): Promise; correlateMessage(input: { name: string; correlationKey: string; variables?: JsonObject; }, options?: unknown): Promise; getProcessInstance(input: { processInstanceKey: string; }, consistency: { consistency: { waitUpToMs: number; }; }, options?: unknown): Promise; createJobWorker(cfg: JobWorkerConfig): NanoJobWorker; } /** Config for a nano-sdk job worker (the subset the Worker runtime sets). */ export interface JobWorkerConfig { jobType: string; jobHandler: (job: ActivatedJob) => Promise | unknown; workerName?: string; maxParallelJobs?: number; /** Job lock timeout in ms. */ jobTimeoutMs?: number; /** Long-poll timeout in ms. */ pollTimeoutMs?: number; /** Start polling immediately. The Worker runtime sets this false and starts explicitly. */ autoStart?: boolean; } /** The handle returned by `createJobWorker`. */ export interface NanoJobWorker { start(): void; stop(): void | Promise; stopGracefully?(opts?: { waitUpToMs?: number; }): Promise; } /** The subset of a raw `@nanobpm/nano-sdk` job worker the adapter drives. Its * `start()` may be synchronous or async: on nano-sdk >=1.2.5's Falcon/auto path * it is async and the SDK self-starts the worker after an asynchronous transport * bind (see {@link adaptJobWorker}). */ export interface RawNanoJobWorker { start(): void | Promise; stop(): void | Promise; stopGracefully(opts?: { waitUpToMs?: number; }): Promise; } /** Adapt a raw `@nanobpm/nano-sdk` job worker to the {@link NanoJobWorker} handle * the Worker runtime drives, making the eager `start()` NULL-SAFE. * * nano-sdk >=1.2.5's Falcon/auto worker SELF-STARTS after an ASYNCHRONOUS * transport bind: `createJobWorker` hands back a worker whose transport is null * until Nano is detected, at which point the SDK `bindTransport(t)`s it and * `start()`s the worker ITSELF. Calling `start()` before that bind dereferences * the null transport and — because `start()` is async — surfaces as an UNHANDLED * REJECTION that crashes the process * (`TypeError: Cannot read properties of null (reading 'subscribe')`, #415). The * REST/manual worker, by contrast, never self-starts, so `start()` must still be * called here. We resolve the version-skew by starting eagerly but NULL-SAFELY: * swallow ONLY the pre-bind race (the SDK self-starts once the transport binds) * and SURFACE any other start failure via `console.warn` rather than masking it. * The SDK owns the start lifecycle end to end (it logs and falls back to REST on * its own subscribe failure), so discarding the resolved result — as the previous * `void worker.start()` already did — is safe. Pairs with the library-side * null-safe, idempotent start (jwulf/nano-sdk-js#12) so neither an eager nor a * duplicate start can crash. */ export declare function adaptJobWorker(worker: RawNanoJobWorker): NanoJobWorker; /** An activated job as delivered to a nano-sdk job handler: the workflow `Job` * fields plus the acknowledgement actions. */ export type ActivatedJob = Job & { complete(variables?: JsonObject): Promise; fail(body: { errorMessage: string; retries?: number; }): Promise; }; /** Options common to both ways of building a `WorkflowClient`. */ interface WorkflowClientCommon { /** Auth token for the gateway (CAMUNDA_TOKEN). */ token?: string; /** Transport mode passed to `createCamundaClient`: "auto" | "falcon" | "rest". * Default "auto" (Falcon on a Nano server, REST elsewhere). */ transport?: "auto" | "falcon" | "rest"; } /** Construct a `WorkflowClient` from **either** a `baseUrl` (a nano-sdk client is * built for you) **or** a pre-built `client`. The union makes TypeScript enforce * that exactly one is supplied, matching the constructor's runtime requirement. */ export type WorkflowClientOptions = (WorkflowClientCommon & { /** Base URL of the nanobpmn gateway, e.g. `http://localhost:8080`. The * nano-sdk client normalises this to the `/v2` REST address. */ baseUrl: string; client?: never; }) | (WorkflowClientCommon & { /** Inject a pre-built nano-sdk client (or a compatible fake) instead of * constructing one from `baseUrl`. Useful for tests, the embedded * transport, and advanced authors who build the client themselves. */ client: NanoSdkClient; baseUrl?: never; }); export declare class WorkflowError extends Error { readonly status?: number | undefined; readonly body?: string | undefined; constructor(message: string, status?: number | undefined, body?: string | undefined); } export declare class WorkflowClient { /** The underlying nano-sdk client, exposed so the Worker runtime and app * authors can reach the engine through the same transport (ADR 0055). The * exported `NanoSdkClient` type intentionally models only the subset of * methods this package uses (deploy, create, correlate, get, job workers); * the runtime value is the full nano-sdk client. */ readonly sdk: NanoSdkClient; constructor(opts: WorkflowClientOptions); /** * Deploy a workflow's derived BPMN model. The deployed model includes * auto-generated diagram interchange (DI) so it is inspectable in a * modeller/Operate; pass `{ layout: false }` to deploy the DI-less semantic * model. DI needs the optional `bpmn-auto-layout` dependency — see * `toDeployableBpmn` for the graceful-degradation behaviour when it is absent. */ deploy(wf: Workflow, opts?: { layout?: boolean; }): Promise; /** * Start a workflow instance. For imperative workflows the engine variables are * seeded with `{ input, journal: {}, wfDone: false }` (the replay state); for * declarative flows `input` becomes the instance variables directly. */ start(wf: Workflow, input?: JsonObject): Promise; /** Correlate a signal to a parked declarative `signal` step. Fails fast on an * unknown signal name (a typo would otherwise send an uncorrelatable message * that the gateway silently drops). */ signal(flow: DeclarativeFlow, signalName: string, correlationKey: string, variables?: JsonObject): Promise; /** Fetch an instance (used by demos/tests to observe completion). Reads with * zero-wait consistency; returns null when the instance is not (yet) visible. */ getInstance(processInstanceKey: string): Promise; } export {};