@camunda8/orchestration-cluster-api 8.9.0-alpha.9 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +270 -3
- package/README.md +534 -56
- package/dist/{chunk-Z4VZYLZG.js → chunk-43TOWWPR.js} +2216 -8891
- package/dist/chunk-43TOWWPR.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/{chunk-W6JB7JZH.js → chunk-KQ4UL2WX.js} +3 -17
- package/dist/chunk-KQ4UL2WX.js.map +1 -0
- package/dist/fp/index.cjs +13181 -11574
- package/dist/fp/index.cjs.map +1 -1
- package/dist/fp/index.d.cts +2 -1
- package/dist/fp/index.d.ts +2 -1
- package/dist/fp/index.js +3 -2
- package/dist/{index-DxghwSgN.d.ts → index-B7HfPv-I.d.ts} +4153 -613
- package/dist/{index-Da0Q45ah.d.cts → index-C0kkfkPq.d.cts} +4153 -613
- package/dist/index.cjs +14133 -12223
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +336 -59
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +2 -2
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.js +2 -1
- package/dist/threadWorkerEntry.cjs +146 -0
- package/dist/threadWorkerEntry.cjs.map +1 -0
- package/dist/threadWorkerEntry.js +144 -0
- package/dist/threadWorkerEntry.js.map +1 -0
- package/dist/zod.gen-J3DNBFMQ.js +8277 -0
- package/dist/zod.gen-J3DNBFMQ.js.map +1 -0
- package/package.json +38 -38
- package/dist/chunk-W6JB7JZH.js.map +0 -1
- package/dist/chunk-Z4VZYLZG.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Camunda 8 Orchestration Cluster TypeScript SDK
|
|
2
2
|
|
|
3
|
+
<!-- WARNING: The content and specific structure of this file drives Docusaurus generation in camunda-docs. Also, code examples are injected during build. Please refer to MAINTAINER.md before editing. -->
|
|
4
|
+
|
|
3
5
|
Type‑safe, promise‑based client for the Camunda 8 Orchestration Cluster REST API.
|
|
4
6
|
|
|
5
7
|
## Highlights
|
|
@@ -13,7 +15,8 @@ Type‑safe, promise‑based client for the Camunda 8 Orchestration Cluster REST
|
|
|
13
15
|
- Eventual consistency helper for polling endpoints
|
|
14
16
|
- Immutable, deep‑frozen configuration accessible through a factory‑created client instance
|
|
15
17
|
- Automatic body-level tenantId defaulting: if a request body supports an optional tenantId and you omit it, the SDK fills it from CAMUNDA_DEFAULT_TENANT_ID (path params are never auto-filled)
|
|
16
|
-
- Automatic transient HTTP retry (429, 503, network) with exponential backoff + full jitter (configurable via CAMUNDA_SDK_HTTP_RETRY\*). Non-retryable 500s fail fast.
|
|
18
|
+
- Automatic transient HTTP retry (429, 503, network) with exponential backoff + full jitter (configurable via CAMUNDA_SDK_HTTP_RETRY\*). Non-retryable 500s fail fast.
|
|
19
|
+
- Per-method retry override: disable or customize retry policy on any individual API call without changing global settings
|
|
17
20
|
|
|
18
21
|
## Install
|
|
19
22
|
|
|
@@ -28,27 +31,129 @@ Runtime support:
|
|
|
28
31
|
|
|
29
32
|
For older Node versions supply a fetch ponyfill AND a `File` shim (or upgrade). For legacy browsers, add a fetch polyfill (e.g. `whatwg-fetch`).
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
### Versioning
|
|
35
|
+
|
|
36
|
+
This SDK has a different release cadence from the Camunda server. Features and fixes land in the SDK during a server release.
|
|
37
|
+
|
|
38
|
+
The major version of the SDK signals a 1:1 type coherence with the server API for a Camunda minor release.
|
|
39
|
+
|
|
40
|
+
SDK version `n.y.z` -> server version `8.n`, so the type surface of SDK version 9.y.z matches the API surface of Camunda 8.9.
|
|
41
|
+
|
|
42
|
+
Using a later SDK version, for example: SDK version 10.y.z with Camunda 8.9, means that the SDK contains additive surfaces that are not guaranteed at runtime, and the compiler cannot warn of unsupported operations.
|
|
43
|
+
|
|
44
|
+
Using an earlier SDK version, for example: SDK version 9.y.z with Camunda 8.10, results in slightly degraded compiler reasoning: exhaustiveness checks cannot be guaranteed by the compiler for any extended surfaces (principally, enums with added members).
|
|
45
|
+
|
|
46
|
+
In the vast majority of use-cases, this will not be an issue; but you should be aware that using the matching SDK major version for the server minor version provides the strongest compiler guarantees about runtime reliability.
|
|
47
|
+
|
|
48
|
+
**Recommended approach**:
|
|
49
|
+
|
|
50
|
+
- Check the [CHANGELOG](https://github.com/camunda/orchestration-cluster-api-js/releases).
|
|
51
|
+
- As a sanity check during server version upgrade, rebuild applications with the matching SDK major version to identify any affected runtime surfaces.
|
|
52
|
+
|
|
53
|
+
## Migrating from 8.8
|
|
54
|
+
|
|
55
|
+
SDK 9.x (for Camunda 8.9) introduces two categories of breaking type changes relative to SDK 8.x (for Camunda 8.8). Neither change affects runtime behavior — existing code that compiled against 8.x will run identically — but the compiler will flag type mismatches until you update.
|
|
56
|
+
|
|
57
|
+
### Search results: optional → required fields
|
|
58
|
+
|
|
59
|
+
The search result types changed several fields from **optional** to **required**:
|
|
60
|
+
|
|
61
|
+
**`SearchQueryPageResponse` (page metadata)**
|
|
62
|
+
|
|
63
|
+
| Field | SDK 8.x (Camunda 8.8) | SDK 9.x (Camunda 8.9) |
|
|
64
|
+
|-------|----------------------|----------------------|
|
|
65
|
+
| `totalItems` | `totalItems?: number` | `totalItems: number` |
|
|
66
|
+
| `hasMoreTotalItems` | `hasMoreTotalItems?: boolean` | `hasMoreTotalItems: boolean` |
|
|
67
|
+
| `endCursor` | `endCursor?: EndCursor` | `endCursor: EndCursor \| null` |
|
|
68
|
+
| `startCursor` | `startCursor?: StartCursor` | `startCursor: StartCursor \| null` |
|
|
69
|
+
|
|
70
|
+
**`*SearchQueryResult` types (result containers)**
|
|
71
|
+
|
|
72
|
+
| Field | SDK 8.x (Camunda 8.8) | SDK 9.x (Camunda 8.9) |
|
|
73
|
+
|-------|----------------------|----------------------|
|
|
74
|
+
| `items` | `items?: T[]` | `items: T[]` |
|
|
75
|
+
| `page` | `page?: SearchQueryPageResponse` | `page: SearchQueryPageResponse` |
|
|
76
|
+
|
|
77
|
+
This reflects upstream OpenAPI spec changes where these fields are now always present in the response, with `null` indicating "no value" for cursors rather than being absent.
|
|
78
|
+
|
|
79
|
+
**What to change**: Update code that checks for these fields using optional chaining or `undefined` comparisons. The `items` array and `page` object are now always present, so optional chaining on them is unnecessary:
|
|
80
|
+
|
|
81
|
+
<!-- snippet-exempt: migration example showing before/after patterns -->
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// Before (8.x) — checking for undefined
|
|
85
|
+
if (result.page?.endCursor !== undefined) {
|
|
86
|
+
nextPage(result.page.endCursor);
|
|
87
|
+
}
|
|
88
|
+
const count = result.items?.length ?? 0;
|
|
89
|
+
|
|
90
|
+
// After (9.x) — page and items are always present; check cursors for null
|
|
91
|
+
if (result.page.endCursor !== null) {
|
|
92
|
+
nextPage(result.page.endCursor);
|
|
93
|
+
}
|
|
94
|
+
const count = result.items.length;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
If you have a custom `PagedResponse` type, update its `page` shape to match:
|
|
32
98
|
|
|
33
|
-
|
|
99
|
+
<!-- snippet-exempt: migration example showing type definition update -->
|
|
34
100
|
|
|
35
|
-
|
|
101
|
+
```ts
|
|
102
|
+
// Before (8.x)
|
|
103
|
+
type PagedResponse<T> = {
|
|
104
|
+
items?: T[];
|
|
105
|
+
page?: {
|
|
106
|
+
totalItems?: number;
|
|
107
|
+
endCursor?: string;
|
|
108
|
+
startCursor?: string;
|
|
109
|
+
hasMoreTotalItems?: boolean;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// After (9.x)
|
|
114
|
+
type PagedResponse<T> = {
|
|
115
|
+
items: T[];
|
|
116
|
+
page: {
|
|
117
|
+
totalItems: number;
|
|
118
|
+
endCursor: EndCursor | null;
|
|
119
|
+
startCursor: StartCursor | null;
|
|
120
|
+
hasMoreTotalItems: boolean;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
```
|
|
36
124
|
|
|
37
|
-
|
|
125
|
+
### Branded key types for `tenantId`
|
|
38
126
|
|
|
39
|
-
|
|
127
|
+
The `tenantId` field on request types (e.g. `CreateDeploymentData`) changed from `string` to the branded `TenantId` type. A plain `string` is no longer assignable:
|
|
40
128
|
|
|
41
|
-
-
|
|
42
|
-
- **Pin and review** — pin to a specific patch version in `package.json` and review the [CHANGELOG](https://github.com/camunda/orchestration-cluster-api-js/releases) before upgrading:
|
|
129
|
+
<!-- snippet-exempt: migration example showing branded type usage -->
|
|
43
130
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
131
|
+
```ts
|
|
132
|
+
import { TenantId } from '@camunda8/orchestration-cluster-api';
|
|
133
|
+
|
|
134
|
+
// Before (8.x) — plain string worked
|
|
135
|
+
await camunda.createDeployment({
|
|
136
|
+
tenantId: 'my-tenant',
|
|
137
|
+
resources: [file],
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// After (9.x) — use the branded type helper
|
|
141
|
+
await camunda.createDeployment({
|
|
142
|
+
tenantId: TenantId.assumeExists('my-tenant'),
|
|
143
|
+
resources: [file],
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`TenantId.assumeExists()` validates the string against the tenant ID pattern and brands it at zero runtime cost. See [Branded Keys](#branded-keys) for more on this pattern.
|
|
148
|
+
|
|
149
|
+
> **Tip**: If your tenant ID comes from a validated source (environment variable, config file), call `TenantId.assumeExists()` once at startup and pass the branded value throughout your application.
|
|
47
150
|
|
|
48
151
|
## Quick Start (Zero‑Config – Recommended)
|
|
49
152
|
|
|
50
153
|
Keep configuration out of application code. Let the factory read `CAMUNDA_*` variables from the environment (12‑factor style). This makes rotation, secret management, and environment promotion safer & simpler.
|
|
51
154
|
|
|
155
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeDefaultImport+ReadmeQuickStart -->
|
|
156
|
+
|
|
52
157
|
```ts
|
|
53
158
|
import createCamundaClient from '@camunda8/orchestration-cluster-api';
|
|
54
159
|
|
|
@@ -89,6 +194,8 @@ CAMUNDA_SDK_HTTP_RETRY_MAX_DELAY_MS=2000 # optional: cap (ms)
|
|
|
89
194
|
|
|
90
195
|
Use only when you must supply or mutate configuration dynamically (e.g. multi‑tenant routing, tests, ephemeral preview environments) or in the browser. Keys mirror their `CAMUNDA_*` env names.
|
|
91
196
|
|
|
197
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeOverrides -->
|
|
198
|
+
|
|
92
199
|
```ts
|
|
93
200
|
const camunda = createCamundaClient({
|
|
94
201
|
config: {
|
|
@@ -104,6 +211,8 @@ const camunda = createCamundaClient({
|
|
|
104
211
|
|
|
105
212
|
Inject a custom `fetch` to add tracing, mock responses, instrumentation, circuit breakers, etc.
|
|
106
213
|
|
|
214
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeCustomFetch -->
|
|
215
|
+
|
|
107
216
|
```ts
|
|
108
217
|
const camunda = createCamundaClient({
|
|
109
218
|
fetch: (input, init) => {
|
|
@@ -149,15 +258,65 @@ Behavior:
|
|
|
149
258
|
- `strict` - fail on type mismatch or missing required fields
|
|
150
259
|
- `fanatical` - fail on type mismatch, missing required fields, or unknown additional fields
|
|
151
260
|
|
|
261
|
+
> **Note on `int64` fields**: The upstream OpenAPI spec declares some fields (e.g. `totalItems`, `timeout`, `timestamp`) as `integer` with `format: int64`. The TypeScript types map these to `number`. JSON responses also deserialize as `number` (with precision loss beyond `Number.MAX_SAFE_INTEGER`). The Zod schemas use `z.coerce.number().int()` for these fields, preserving the integer constraint while keeping the runtime type aligned with TypeScript. All validation modes (`none`, `warn`, `strict`, `fanatical`) return `number`.
|
|
262
|
+
|
|
263
|
+
## Per-Method Retry Override
|
|
264
|
+
|
|
265
|
+
Every API method accepts an optional trailing `options` parameter that lets you override or disable the global retry policy for that single call.
|
|
266
|
+
|
|
267
|
+
### Disable Retry for a Single Call
|
|
268
|
+
|
|
269
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeDisableRetry -->
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
// This call will not retry on transient errors
|
|
273
|
+
await camunda.completeJob({ jobKey }, { retry: false });
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Override Specific Retry Settings
|
|
277
|
+
|
|
278
|
+
Pass a partial `HttpRetryPolicy` to override individual fields. Unspecified fields inherit from the global configuration.
|
|
279
|
+
|
|
280
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeRetryOverride -->
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
// More aggressive retry for this operation only
|
|
284
|
+
await camunda.createProcessInstance(
|
|
285
|
+
{ processDefinitionId },
|
|
286
|
+
{ retry: { maxAttempts: 8, maxDelayMs: 5000 } }
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
// Minimal retry: single retry with short backoff
|
|
290
|
+
await camunda.getTopology({ retry: { maxAttempts: 2, baseDelayMs: 50 } });
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### How It Works
|
|
294
|
+
|
|
295
|
+
| `options.retry` value | Behavior |
|
|
296
|
+
| --------------------- | -------------------------------------------------------------------- |
|
|
297
|
+
| omitted / `undefined` | Uses global policy (`CAMUNDA_SDK_HTTP_RETRY_*` env vars) |
|
|
298
|
+
| `false` | Disables retry entirely (single attempt, no backoff) |
|
|
299
|
+
| `{ maxAttempts: 5 }` | Merges with global policy — only the specified fields are overridden |
|
|
300
|
+
|
|
301
|
+
The `HttpRetryPolicy` fields available for override:
|
|
302
|
+
|
|
303
|
+
| Field | Type | Description |
|
|
304
|
+
| ------------- | -------- | --------------------------------------- |
|
|
305
|
+
| `maxAttempts` | `number` | Total attempts (initial + retries) |
|
|
306
|
+
| `baseDelayMs` | `number` | Base delay for exponential backoff (ms) |
|
|
307
|
+
| `maxDelayMs` | `number` | Maximum delay cap (ms) |
|
|
308
|
+
|
|
152
309
|
## Advanced HTTP Retry: Cockatiel Adapter (Optional)
|
|
153
310
|
|
|
154
|
-
|
|
311
|
+
For advanced resilience patterns beyond per-method overrides — circuit breakers, timeouts, custom classification, combining policies — you can integrate [cockatiel](https://github.com/connor4312/cockatiel).
|
|
312
|
+
|
|
313
|
+
> **Tip:** For most use cases, per-method retry override (above) is sufficient. Reach for Cockatiel when you need circuit breaking, hedging, or bulkhead controls.
|
|
155
314
|
|
|
156
315
|
### When To Use Cockatiel
|
|
157
316
|
|
|
158
|
-
- You need different retry policies per operation (e.g. idempotent GET vs mutating POST)
|
|
159
317
|
- You want circuit breaking, hedging, timeout, or bulkhead controls
|
|
160
318
|
- You want to add custom classification (e.g. retry certain 5xx only on safe verbs)
|
|
319
|
+
- You need to compose multiple resilience policies together
|
|
161
320
|
|
|
162
321
|
### Disable Built‑In HTTP Retries
|
|
163
322
|
|
|
@@ -165,6 +324,7 @@ Set `CAMUNDA_SDK_HTTP_RETRY_MAX_ATTEMPTS=1` so the SDK does only the initial att
|
|
|
165
324
|
|
|
166
325
|
### Minimal Example (Single Operation)
|
|
167
326
|
|
|
327
|
+
<!-- snippet-exempt: uses external cockatiel library -->
|
|
168
328
|
```ts
|
|
169
329
|
import { createCamundaClient } from '@camunda8/orchestration-cluster-api';
|
|
170
330
|
import { retry, ExponentialBackoff, handleAll } from 'cockatiel';
|
|
@@ -193,6 +353,7 @@ console.log(topo.brokers?.length);
|
|
|
193
353
|
|
|
194
354
|
### Bulk Wrapping All Operations
|
|
195
355
|
|
|
356
|
+
<!-- snippet-exempt: uses external cockatiel library -->
|
|
196
357
|
```ts
|
|
197
358
|
import { createCamundaClient } from '@camunda8/orchestration-cluster-api';
|
|
198
359
|
import { retry, ExponentialBackoff, handleAll } from 'cockatiel';
|
|
@@ -271,6 +432,7 @@ Refer to `./docs/CONFIG_REFERENCE.md` for the full list of related environment v
|
|
|
271
432
|
|
|
272
433
|
Retry only network errors + 429/503, plus optionally 500 on safe GET endpoints you mark:
|
|
273
434
|
|
|
435
|
+
<!-- snippet-exempt: uses external cockatiel library -->
|
|
274
436
|
```ts
|
|
275
437
|
import { retry, ExponentialBackoff, handleWhen } from 'cockatiel';
|
|
276
438
|
|
|
@@ -292,7 +454,7 @@ const policy = retry(classify, {
|
|
|
292
454
|
- Keep SDK retries disabled to prevent duplicate layers.
|
|
293
455
|
- SDK synthesizes `Error` objects with a `status` for retry-significant HTTP responses (429, 503, 500), enabling classification.
|
|
294
456
|
- You can tag errors (e.g. assign `err.__opVerb`) in a wrapper if verb-level logic is needed.
|
|
295
|
-
-
|
|
457
|
+
- For per-operation retry customization without external dependencies, use the built-in [per-method retry override](#per-method-retry-override) instead.
|
|
296
458
|
|
|
297
459
|
> Combine cockatiel retry with a circuit breaker, timeout, or bulkhead policy for more robust behavior in partial outages.
|
|
298
460
|
|
|
@@ -394,12 +556,29 @@ Factors use integer percentages to avoid floating point drift in env parsing; th
|
|
|
394
556
|
|
|
395
557
|
If you have concrete tuning needs, open an issue describing workload patterns (operation mix, baseline concurrency, observed broker limits) to help prioritize which knobs to surface.
|
|
396
558
|
|
|
559
|
+
### What Should I Set?
|
|
560
|
+
|
|
561
|
+
If you're unsure about your workload shape, **don't set anything**. The default BALANCED profile activates automatically and outperforms no-gating (LEGACY) in most scenarios — on raw throughput alone, not just error reduction.
|
|
562
|
+
|
|
563
|
+
Benchmark results against a single-node local cluster with multiple independent clients (no shared state between them):
|
|
564
|
+
|
|
565
|
+
| Scenario | BALANCED | LEGACY (no gating) |
|
|
566
|
+
| ----------------------------- | --------------- | ------------------ |
|
|
567
|
+
| Single-client (1K processes) | **80.1 ops/s** | 67.8 ops/s |
|
|
568
|
+
| Single-client sustained (10K) | **119.6 ops/s** | 87.8 ops/s |
|
|
569
|
+
| Multi-client 3+2 spike | **86.3 ops/s** | 48.0 ops/s |
|
|
570
|
+
| Stress 8 clients ×1000 | 76.3 ops/s | **106.4 ops/s** |
|
|
571
|
+
|
|
572
|
+
BALANCED wins 3 of 4 on pure throughput. The only scenario where LEGACY is faster is extreme overload (800 concurrent requests against a single broker) — and in that case LEGACY accumulates 44,505 errors vs BALANCED's 15,527. The default just works.
|
|
573
|
+
|
|
397
574
|
## Job Workers (Polling API)
|
|
398
575
|
|
|
399
576
|
The SDK provides a lightweight polling job worker for service task job types using `createJobWorker`. It activates jobs in batches (respecting a concurrency limit), validates variables (optional), and offers action helpers on each job.
|
|
400
577
|
|
|
401
578
|
### Minimal Example
|
|
402
579
|
|
|
580
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeJobWorkerImport+ReadmeJobWorkerMinimal -->
|
|
581
|
+
|
|
403
582
|
```ts
|
|
404
583
|
import createCamundaClient from '@camunda8/orchestration-cluster-api';
|
|
405
584
|
import { z } from 'zod';
|
|
@@ -413,7 +592,7 @@ const Output = z.object({ processed: z.boolean() });
|
|
|
413
592
|
const worker = client.createJobWorker({
|
|
414
593
|
jobType: 'process-order',
|
|
415
594
|
maxParallelJobs: 10,
|
|
416
|
-
|
|
595
|
+
jobTimeoutMs: 15_000, // long‑poll timeout (server side requestTimeout)
|
|
417
596
|
pollIntervalMs: 100, // delay between polls when no jobs / at capacity
|
|
418
597
|
// Optional: only fetch specific variables during activation
|
|
419
598
|
fetchVariables: ['orderId'],
|
|
@@ -425,8 +604,9 @@ const worker = client.createJobWorker({
|
|
|
425
604
|
jobHandler: (job) => {
|
|
426
605
|
// Access typed variables
|
|
427
606
|
const vars = job.variables; // inferred from Input schema
|
|
607
|
+
console.log(`Processing order: ${vars.orderId}`);
|
|
428
608
|
// Do work...
|
|
429
|
-
return job.complete({
|
|
609
|
+
return job.complete({ processed: true });
|
|
430
610
|
},
|
|
431
611
|
});
|
|
432
612
|
|
|
@@ -444,6 +624,8 @@ TypeScript inference:
|
|
|
444
624
|
|
|
445
625
|
- When you provide `inputSchema`, the type of `fetchVariables` is constrained to the keys of the inferred `variables` type from that schema. Example:
|
|
446
626
|
|
|
627
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeJobWorkerInference -->
|
|
628
|
+
|
|
447
629
|
```ts
|
|
448
630
|
const Input = z.object({ orderId: z.string(), amount: z.number() });
|
|
449
631
|
client.createJobWorker({
|
|
@@ -463,7 +645,7 @@ client.createJobWorker({
|
|
|
463
645
|
|
|
464
646
|
Your `jobHandler` must ultimately invoke exactly one of:
|
|
465
647
|
|
|
466
|
-
- `job.complete(
|
|
648
|
+
- `job.complete(variables?, result?)` OR `job.complete()`
|
|
467
649
|
- `job.fail({ errorMessage, retries?, retryBackoff? })`
|
|
468
650
|
- `job.cancelWorkflow({})` (cancels the process instance)
|
|
469
651
|
- `job.error({ errorCode, errorMessage? })` (throws a business error)
|
|
@@ -488,6 +670,7 @@ Recommended usage:
|
|
|
488
670
|
|
|
489
671
|
Example patterns:
|
|
490
672
|
|
|
673
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeJobCompletionPatterns -->
|
|
491
674
|
```ts
|
|
492
675
|
// GOOD: explicit completion
|
|
493
676
|
return job.complete({ variables: { processed: true } });
|
|
@@ -498,13 +681,61 @@ const ack = await job.complete();
|
|
|
498
681
|
return ack;
|
|
499
682
|
|
|
500
683
|
// GOOD: explicit ignore
|
|
501
|
-
const
|
|
684
|
+
const ack2 = await job.ignore();
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
### Job Corrections (User Task Listeners)
|
|
688
|
+
|
|
689
|
+
When a job worker handles a [user task listener](https://docs.camunda.io/docs/components/concepts/user-task-listeners/), it can correct task properties (assignee, due date, candidate groups, etc.) by passing a `result` to `job.complete()`:
|
|
690
|
+
|
|
691
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeJobCorrectionsImport+ReadmeJobCorrections -->
|
|
692
|
+
|
|
693
|
+
```ts
|
|
694
|
+
import type { JobResult } from '@camunda8/orchestration-cluster-api';
|
|
695
|
+
|
|
696
|
+
const worker = client.createJobWorker({
|
|
697
|
+
jobType: 'io.camunda:userTaskListener',
|
|
698
|
+
jobTimeoutMs: 30_000,
|
|
699
|
+
maxParallelJobs: 5,
|
|
700
|
+
jobHandler: async (job) => {
|
|
701
|
+
const result: JobResult = {
|
|
702
|
+
type: 'userTask',
|
|
703
|
+
corrections: {
|
|
704
|
+
assignee: 'corrected-user',
|
|
705
|
+
priority: 80,
|
|
706
|
+
},
|
|
707
|
+
};
|
|
708
|
+
return job.complete({}, result);
|
|
709
|
+
},
|
|
710
|
+
});
|
|
502
711
|
```
|
|
503
712
|
|
|
713
|
+
To deny a task completion (reject the work):
|
|
714
|
+
|
|
715
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeJobCorrectionsDenial -->
|
|
716
|
+
|
|
504
717
|
```ts
|
|
505
|
-
|
|
718
|
+
return job.complete(
|
|
719
|
+
{},
|
|
720
|
+
{
|
|
721
|
+
type: 'userTask',
|
|
722
|
+
denied: true,
|
|
723
|
+
deniedReason: 'Insufficient documentation',
|
|
724
|
+
}
|
|
725
|
+
);
|
|
506
726
|
```
|
|
507
727
|
|
|
728
|
+
| Correctable attribute | Type | Clear value |
|
|
729
|
+
|---|---|---|
|
|
730
|
+
| `assignee` | `string` | Empty string `""` |
|
|
731
|
+
| `dueDate` | `string` (ISO 8601) | Empty string `""` |
|
|
732
|
+
| `followUpDate` | `string` (ISO 8601) | Empty string `""` |
|
|
733
|
+
| `candidateUsers` | `string[]` | Empty array `[]` |
|
|
734
|
+
| `candidateGroups` | `string[]` | Empty array `[]` |
|
|
735
|
+
| `priority` | `number` (0–100) | — |
|
|
736
|
+
|
|
737
|
+
Omitting an attribute or passing `null` preserves the persisted value.
|
|
738
|
+
|
|
508
739
|
### Concurrency & Backpressure
|
|
509
740
|
|
|
510
741
|
Set `maxParallelJobs` to the maximum number of jobs you want actively processing concurrently. The worker will long‑poll for up to the remaining capacity each cycle. Global backpressure (adaptive concurrency) still applies to the underlying REST calls; activation itself is a normal operation.
|
|
@@ -521,6 +752,8 @@ If `validateSchemas` is true:
|
|
|
521
752
|
|
|
522
753
|
Use `await worker.stopGracefully({ waitUpToMs?, checkIntervalMs? })` to drain without force‑cancelling the current activation request.
|
|
523
754
|
|
|
755
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeJobWorkerGraceful -->
|
|
756
|
+
|
|
524
757
|
```ts
|
|
525
758
|
// Attempt graceful drain for up to 8 seconds
|
|
526
759
|
const { remainingJobs, timedOut } = await worker.stopGracefully({ waitUpToMs: 8000 });
|
|
@@ -548,6 +781,8 @@ You can register multiple workers on a single client instance—one per job type
|
|
|
548
781
|
|
|
549
782
|
When deploying multiple application instances simultaneously (e.g. a rolling restart or scale-up), all workers start polling at the same time and can saturate the server with activation requests. Set `startupJitterMaxSeconds` to spread out the initial poll across a random window:
|
|
550
783
|
|
|
784
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeJobWorkerJitter -->
|
|
785
|
+
|
|
551
786
|
```ts
|
|
552
787
|
client.createJobWorker({
|
|
553
788
|
jobType: 'process-order',
|
|
@@ -560,13 +795,71 @@ client.createJobWorker({
|
|
|
560
795
|
|
|
561
796
|
A value of `0` (the default) means no delay.
|
|
562
797
|
|
|
798
|
+
### Heritable Worker Defaults
|
|
799
|
+
|
|
800
|
+
When running many workers with the same base configuration, you can set global defaults via environment variables (or equivalent keys in `CamundaOptions.config`). These apply to every worker created by the client (both `createJobWorker` and `createThreadedJobWorker`) unless the individual worker config explicitly overrides them.
|
|
801
|
+
|
|
802
|
+
| Environment Variable | Worker Config Field | Type |
|
|
803
|
+
| ------------------------------------------ | -------------------------- | ------ |
|
|
804
|
+
| `CAMUNDA_WORKER_TIMEOUT` | `jobTimeoutMs` | number |
|
|
805
|
+
| `CAMUNDA_WORKER_MAX_CONCURRENT_JOBS` | `maxParallelJobs` | number |
|
|
806
|
+
| `CAMUNDA_WORKER_REQUEST_TIMEOUT` | `pollTimeoutMs` | number |
|
|
807
|
+
| `CAMUNDA_WORKER_NAME` | `workerName` | string |
|
|
808
|
+
| `CAMUNDA_WORKER_STARTUP_JITTER_MAX_SECONDS`| `startupJitterMaxSeconds` | number |
|
|
809
|
+
|
|
810
|
+
**Precedence:** explicit worker config value > `CAMUNDA_WORKER_*` (from environment variables or `CamundaOptions.config` overrides) > hardcoded default (where applicable).
|
|
811
|
+
|
|
812
|
+
Example — set defaults via environment:
|
|
813
|
+
|
|
814
|
+
```bash
|
|
815
|
+
export CAMUNDA_WORKER_TIMEOUT=30000
|
|
816
|
+
export CAMUNDA_WORKER_MAX_CONCURRENT_JOBS=8
|
|
817
|
+
export CAMUNDA_WORKER_NAME=order-service
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeWorkerDefaultsEnv -->
|
|
821
|
+
```ts
|
|
822
|
+
// Workers inherit timeout, concurrency, and name from environment
|
|
823
|
+
const w1 = client.createJobWorker({
|
|
824
|
+
jobType: 'validate-order',
|
|
825
|
+
jobHandler: async (job) => job.complete(),
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
const w2 = client.createJobWorker({
|
|
829
|
+
jobType: 'ship-order',
|
|
830
|
+
jobHandler: async (job) => job.complete(),
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// Per-worker override: this worker uses 32 concurrent jobs instead of the global 8
|
|
834
|
+
const w3 = client.createJobWorker({
|
|
835
|
+
jobType: 'bulk-import',
|
|
836
|
+
maxParallelJobs: 32,
|
|
837
|
+
jobHandler: async (job) => job.complete(),
|
|
838
|
+
});
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
You can also pass defaults programmatically via the client constructor:
|
|
842
|
+
|
|
843
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeWorkerDefaultsClient -->
|
|
844
|
+
```ts
|
|
845
|
+
const client = createCamundaClient({
|
|
846
|
+
config: {
|
|
847
|
+
CAMUNDA_WORKER_TIMEOUT: 30000,
|
|
848
|
+
CAMUNDA_WORKER_MAX_CONCURRENT_JOBS: 8,
|
|
849
|
+
},
|
|
850
|
+
});
|
|
851
|
+
```
|
|
852
|
+
|
|
563
853
|
### Receipt Type (Unique Symbol)
|
|
564
854
|
|
|
565
855
|
Action methods return a unique symbol (not a string) to avoid accidental misuse and allow internal metrics. If you store the receipt, annotate its type as `JobActionReceipt` to preserve uniqueness:
|
|
566
856
|
|
|
857
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeReceiptImport+ReadmeReceipt -->
|
|
858
|
+
|
|
567
859
|
```ts
|
|
568
|
-
import { JobActionReceipt } from '@camunda8/orchestration-cluster-api';
|
|
569
|
-
|
|
860
|
+
import type { JobActionReceipt } from '@camunda8/orchestration-cluster-api';
|
|
861
|
+
|
|
862
|
+
const receipt: JobActionReceipt = await job.complete({ processed: true });
|
|
570
863
|
```
|
|
571
864
|
|
|
572
865
|
If you ignore the return value you don’t need to import the symbol.
|
|
@@ -599,16 +892,126 @@ This reverts to only per‑request retry for transient errors (no global gating)
|
|
|
599
892
|
|
|
600
893
|
Call `client.getBackpressureState()` to obtain:
|
|
601
894
|
|
|
895
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeBackpressureState -->
|
|
602
896
|
```ts
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
897
|
+
const state = client.getBackpressureState();
|
|
898
|
+
// state.severity: 'healthy' | 'soft' | 'severe'
|
|
899
|
+
// state.consecutive: number — consecutive backpressure signals observed
|
|
900
|
+
// state.permitsMax: number | null — current concurrency cap (null => unlimited/not engaged)
|
|
901
|
+
// state.permitsCurrent: number — currently acquired permits
|
|
902
|
+
// state.waiters: number — queued operations waiting for a permit
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
### Threaded Job Workers (Node.js Only)
|
|
906
|
+
|
|
907
|
+
For CPU-intensive job handlers, `createThreadedJobWorker` offloads handler execution to a pool of Node.js `worker_threads`. Polling and I/O remain on the main event loop, while handler logic runs in parallel threads — dramatically improving throughput when the handler does CPU-bound work (JSON processing, validation, transformation, cryptography).
|
|
908
|
+
|
|
909
|
+
#### When to use
|
|
910
|
+
|
|
911
|
+
- Your handler spends significant time on CPU work (not just waiting for HTTP responses)
|
|
912
|
+
- You observe that a single-threaded worker saturates one CPU core while throughput plateaus
|
|
913
|
+
- You need to process more jobs per second without deploying additional instances
|
|
914
|
+
|
|
915
|
+
If your handler is mostly I/O-bound (HTTP calls, database queries), the standard `createJobWorker` is sufficient.
|
|
916
|
+
|
|
917
|
+
#### Handler module
|
|
918
|
+
|
|
919
|
+
The handler must be a **separate file** (not an inline function) that exports a default async function:
|
|
920
|
+
|
|
921
|
+
<!-- snippet-exempt: pseudo-code referencing heavyComputation which cannot be type-checked -->
|
|
922
|
+
```ts
|
|
923
|
+
// my-handler.ts (or my-handler.js)
|
|
924
|
+
import type { ThreadedJobHandler } from '@camunda8/orchestration-cluster-api';
|
|
925
|
+
|
|
926
|
+
const handler: ThreadedJobHandler = async (job, client) => {
|
|
927
|
+
const { orderId } = job.variables;
|
|
928
|
+
// CPU-intensive work here...
|
|
929
|
+
const result = heavyComputation(orderId);
|
|
930
|
+
return job.complete({ result });
|
|
931
|
+
};
|
|
932
|
+
export default handler;
|
|
610
933
|
```
|
|
611
934
|
|
|
935
|
+
Typing your handler as `ThreadedJobHandler` gives full intellisense for `job` (variables, action methods like `complete()`, `fail()`, `error()`) and `client` (every `CamundaClient` API method).
|
|
936
|
+
|
|
937
|
+
The handler receives two arguments:
|
|
938
|
+
|
|
939
|
+
1. **`job`** — a proxy with the same shape as a regular job worker job (`variables`, `customHeaders`, `jobKey`, plus action methods: `complete()`, `fail()`, `error()`, `cancelWorkflow()`, `ignore()`)
|
|
940
|
+
2. **`client`** — a proxy to the `CamundaClient` on the main thread. You can call any SDK method (e.g. `client.publishMessage(...)`, `client.createProcessInstance(...)`) and it will be forwarded to the main thread and executed there.
|
|
941
|
+
|
|
942
|
+
#### Minimal example
|
|
943
|
+
|
|
944
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeThreadedWorkerImport+ReadmeThreadedWorker -->
|
|
945
|
+
|
|
946
|
+
```ts
|
|
947
|
+
import createCamundaClient from '@camunda8/orchestration-cluster-api';
|
|
948
|
+
import path from 'node:path';
|
|
949
|
+
import { fileURLToPath } from 'node:url';
|
|
950
|
+
|
|
951
|
+
const client = createCamundaClient();
|
|
952
|
+
|
|
953
|
+
const worker = client.createThreadedJobWorker({
|
|
954
|
+
jobType: 'cpu-heavy-task',
|
|
955
|
+
handlerModule: path.join(path.dirname(fileURLToPath(import.meta.url)), 'my-handler.js'),
|
|
956
|
+
maxParallelJobs: 32,
|
|
957
|
+
jobTimeoutMs: 30_000,
|
|
958
|
+
});
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
#### Configuration
|
|
962
|
+
|
|
963
|
+
`createThreadedJobWorker` accepts all the same options as `createJobWorker` (except `jobHandler`), plus:
|
|
964
|
+
|
|
965
|
+
| Option | Type | Default | Description |
|
|
966
|
+
| ---------------- | -------- | --------------------------- | ---------------------------------------------------------------- |
|
|
967
|
+
| `handlerModule` | `string` | (required) | Path to handler module (absolute or relative to `process.cwd()`) |
|
|
968
|
+
| `threadPoolSize` | `number` | `os.availableParallelism()` | Number of worker threads in the pool |
|
|
969
|
+
|
|
970
|
+
Other familiar options: `jobType`, `maxParallelJobs`, `jobTimeoutMs`, `pollIntervalMs`, `pollTimeoutMs`, `fetchVariables`, `inputSchema`, `outputSchema`, `customHeadersSchema`, `validateSchemas`, `autoStart`, `startupJitterMaxSeconds`, `workerName`.
|
|
971
|
+
|
|
972
|
+
#### Lifecycle
|
|
973
|
+
|
|
974
|
+
Threaded workers integrate with the same lifecycle as regular workers:
|
|
975
|
+
|
|
976
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeThreadedLifecycle -->
|
|
977
|
+
```ts
|
|
978
|
+
// Returned by getWorkers()
|
|
979
|
+
const allWorkers = client.getWorkers();
|
|
980
|
+
|
|
981
|
+
// Stopped by stopAllWorkers()
|
|
982
|
+
client.stopAllWorkers();
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeThreadedGraceful -->
|
|
986
|
+
```ts
|
|
987
|
+
// Graceful shutdown (waits for in-flight jobs to finish)
|
|
988
|
+
const { timedOut, remainingJobs } = await worker.stopGracefully({ waitUpToMs: 10_000 });
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
#### Pool stats
|
|
992
|
+
|
|
993
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmePoolStats -->
|
|
994
|
+
```ts
|
|
995
|
+
worker.poolSize; // number of threads
|
|
996
|
+
worker.busyThreads; // threads currently processing a job
|
|
997
|
+
worker.activeJobs; // total jobs dispatched but not yet completed
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
#### How it works
|
|
1001
|
+
|
|
1002
|
+
1. The main thread polls `activateJobs` using the same mechanism as `createJobWorker`
|
|
1003
|
+
2. Activated jobs are serialized and dispatched to an idle thread via `MessageChannel`
|
|
1004
|
+
3. The thread loads the handler module (lazy, on first job), creates a proxy for `job` action methods and `client` API calls
|
|
1005
|
+
4. Action methods (`job.complete()`, `job.fail()`, etc.) and client calls are forwarded back to the main thread over the `MessagePort` and executed there
|
|
1006
|
+
5. The result is relayed back, and the thread is marked idle for the next job
|
|
1007
|
+
|
|
1008
|
+
#### Constraints
|
|
1009
|
+
|
|
1010
|
+
- **Node.js only**: `worker_threads` is not available in browsers or Deno
|
|
1011
|
+
- **Handler must be a file module**: Inline functions cannot be transferred to threads
|
|
1012
|
+
- **Job variables must be JSON-serializable**: Functions and class instances on the job are stripped during transfer
|
|
1013
|
+
- **Client calls are async round-trips**: Each `client.xyz()` call crosses a thread boundary, adding a small amount of latency per call
|
|
1014
|
+
|
|
612
1015
|
---
|
|
613
1016
|
|
|
614
1017
|
## Authentication
|
|
@@ -678,25 +1081,58 @@ Browser usage: There is no disk concept—if executed in a browser the SDK (when
|
|
|
678
1081
|
|
|
679
1082
|
If you need a custom persistence strategy (e.g. Redis / encrypted keychain), wrap the client and periodically call `client.forceAuthRefresh()` while storing and re‑injecting the token via a headers hook; first measure whether the built‑in disk cache already meets your needs.
|
|
680
1083
|
|
|
681
|
-
## mTLS (Node only)
|
|
1084
|
+
## Self-signed TLS / mTLS (Node only)
|
|
1085
|
+
|
|
1086
|
+
The SDK supports custom TLS certificates via environment variables. This is useful for:
|
|
1087
|
+
|
|
1088
|
+
- **Self-signed server certificates** — trust a CA that signed your server's certificate, without presenting a client identity.
|
|
1089
|
+
- **Mutual TLS (mTLS)** — present a client certificate and key to prove the client's identity.
|
|
1090
|
+
- **Both** — trust a custom CA _and_ present client credentials.
|
|
682
1091
|
|
|
683
|
-
|
|
1092
|
+
### Trusting a self-signed server certificate
|
|
1093
|
+
|
|
1094
|
+
Set only the CA certificate to trust the server's self-signed certificate:
|
|
1095
|
+
|
|
1096
|
+
```bash
|
|
1097
|
+
# Path to PEM file:
|
|
1098
|
+
CAMUNDA_MTLS_CA_PATH=/path/to/ca.pem
|
|
684
1099
|
|
|
1100
|
+
# Or inline PEM (must contain real newlines, not literal '\n'):
|
|
1101
|
+
CAMUNDA_MTLS_CA="$(cat /path/to/ca.pem)"
|
|
685
1102
|
```
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
1103
|
+
|
|
1104
|
+
### Mutual TLS (client certificate)
|
|
1105
|
+
|
|
1106
|
+
To present a client certificate for mutual TLS, provide both the certificate and private key:
|
|
1107
|
+
|
|
1108
|
+
```bash
|
|
1109
|
+
CAMUNDA_MTLS_CERT_PATH=/path/to/client.crt
|
|
1110
|
+
CAMUNDA_MTLS_KEY_PATH=/path/to/client.key
|
|
1111
|
+
|
|
1112
|
+
# Optional — passphrase if the key is encrypted:
|
|
1113
|
+
# CAMUNDA_MTLS_KEY_PASSPHRASE=secret
|
|
690
1114
|
```
|
|
691
1115
|
|
|
692
|
-
|
|
1116
|
+
### Full mTLS with custom CA
|
|
1117
|
+
|
|
1118
|
+
Combine a custom CA with client credentials:
|
|
1119
|
+
|
|
1120
|
+
```bash
|
|
1121
|
+
CAMUNDA_MTLS_CA_PATH=/path/to/ca.pem
|
|
1122
|
+
CAMUNDA_MTLS_CERT_PATH=/path/to/client.crt
|
|
1123
|
+
CAMUNDA_MTLS_KEY_PATH=/path/to/client.key
|
|
1124
|
+
```
|
|
1125
|
+
|
|
1126
|
+
Inline PEM values (`CAMUNDA_MTLS_CERT`, `CAMUNDA_MTLS_KEY`, `CAMUNDA_MTLS_CA`) take precedence over their `_PATH` counterparts. An `https.Agent` is attached to all outbound calls (including token fetches).
|
|
693
1127
|
|
|
694
1128
|
## Branded Keys
|
|
695
1129
|
|
|
696
1130
|
Import branded key helpers directly:
|
|
697
1131
|
|
|
1132
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeBrandedKeysImport+ReadmeBrandedKeys -->
|
|
1133
|
+
|
|
698
1134
|
```ts
|
|
699
|
-
import { ProcessDefinitionKey, ProcessInstanceKey } from '@camunda8/orchestration-cluster';
|
|
1135
|
+
import { ProcessDefinitionKey, ProcessInstanceKey } from '@camunda8/orchestration-cluster-api';
|
|
700
1136
|
|
|
701
1137
|
const defKey = ProcessDefinitionKey.assumeExists('2251799813686749');
|
|
702
1138
|
// @ts-expect-error – cannot assign def key to instance key
|
|
@@ -709,8 +1145,13 @@ They are zero‑cost runtime strings with compile‑time separation.
|
|
|
709
1145
|
|
|
710
1146
|
All methods return a `CancelablePromise<T>`:
|
|
711
1147
|
|
|
1148
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeCancelable -->
|
|
1149
|
+
|
|
712
1150
|
```ts
|
|
713
|
-
const p = camunda.searchProcessInstances(
|
|
1151
|
+
const p = camunda.searchProcessInstances(
|
|
1152
|
+
{ filter: { processDefinitionKey: defKey } },
|
|
1153
|
+
{ consistency: { waitUpToMs: 0 } }
|
|
1154
|
+
);
|
|
714
1155
|
setTimeout(() => p.cancel(), 100); // best‑effort cancel
|
|
715
1156
|
try {
|
|
716
1157
|
await p; // resolves if not cancelled
|
|
@@ -731,8 +1172,17 @@ Notes:
|
|
|
731
1172
|
|
|
732
1173
|
@experimental - this feature is not guaranteed to be tested or stable.
|
|
733
1174
|
|
|
1175
|
+
> **Peer dependency:** `fp-ts` is an optional peer dependency. If you use real `fp-ts` functions
|
|
1176
|
+
> (e.g. `pipe`, `TE.match`) alongside this subpath, install it separately:
|
|
1177
|
+
> ```sh
|
|
1178
|
+
> npm install fp-ts
|
|
1179
|
+
> ```
|
|
1180
|
+
> The `/fp` subpath works without `fp-ts` installed — it exposes structurally-compatible
|
|
1181
|
+
> `Either`/`TaskEither` shapes that interoperate with `fp-ts` but do not require it at runtime.
|
|
1182
|
+
|
|
734
1183
|
The main entry stays minimal. To opt in to a TaskEither-style facade & helper combinators import from the dedicated subpath:
|
|
735
1184
|
|
|
1185
|
+
<!-- snippet-exempt: uses SDK /fp subpath not available in examples project -->
|
|
736
1186
|
```ts
|
|
737
1187
|
import {
|
|
738
1188
|
createCamundaFpClient,
|
|
@@ -740,7 +1190,7 @@ import {
|
|
|
740
1190
|
withTimeoutTE,
|
|
741
1191
|
eventuallyTE,
|
|
742
1192
|
isLeft,
|
|
743
|
-
} from '@camunda8/orchestration-cluster/fp';
|
|
1193
|
+
} from '@camunda8/orchestration-cluster-api/fp';
|
|
744
1194
|
|
|
745
1195
|
const fp = createCamundaFpClient();
|
|
746
1196
|
const deployTE = fp.deployResourcesFromFiles(['./bpmn/process.bpmn']);
|
|
@@ -808,16 +1258,22 @@ Use this to understand convergence speed and data shape evolution during tests o
|
|
|
808
1258
|
|
|
809
1259
|
### Example
|
|
810
1260
|
|
|
1261
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeEventualConsistency -->
|
|
1262
|
+
|
|
811
1263
|
```ts
|
|
812
|
-
const jobs = await camunda.searchJobs(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
waitUpToMs: 5000,
|
|
816
|
-
pollIntervalMs: 200,
|
|
817
|
-
trace: true,
|
|
818
|
-
predicate: (r) => Array.isArray(r.items) && r.items.some((j) => j.state === 'CREATED'),
|
|
1264
|
+
const jobs = await camunda.searchJobs(
|
|
1265
|
+
{
|
|
1266
|
+
filter: { type: 'payment' },
|
|
819
1267
|
},
|
|
820
|
-
|
|
1268
|
+
{
|
|
1269
|
+
consistency: {
|
|
1270
|
+
waitUpToMs: 5000,
|
|
1271
|
+
pollIntervalMs: 200,
|
|
1272
|
+
trace: true,
|
|
1273
|
+
predicate: (r) => Array.isArray(r.items) && r.items.some((j) => j.state === 'CREATED'),
|
|
1274
|
+
},
|
|
1275
|
+
}
|
|
1276
|
+
);
|
|
821
1277
|
```
|
|
822
1278
|
|
|
823
1279
|
On timeout an `EventualConsistencyTimeoutError` includes diagnostic fields: `{ attempts, elapsedMs, lastStatus, lastResponse, operationId }`.
|
|
@@ -826,6 +1282,8 @@ On timeout an `EventualConsistencyTimeoutError` includes diagnostic fields: `{ a
|
|
|
826
1282
|
|
|
827
1283
|
Per‑client logger; no global singleton. The level defaults from `CAMUNDA_SDK_LOG_LEVEL` (default `error`).
|
|
828
1284
|
|
|
1285
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeLogging -->
|
|
1286
|
+
|
|
829
1287
|
```ts
|
|
830
1288
|
const client = createCamundaClient({
|
|
831
1289
|
log: {
|
|
@@ -877,9 +1335,10 @@ Provide a `transport` function to forward structured `LogEvent` objects into any
|
|
|
877
1335
|
|
|
878
1336
|
#### Pino
|
|
879
1337
|
|
|
1338
|
+
<!-- snippet-exempt: uses external pino dependency -->
|
|
880
1339
|
```ts
|
|
881
1340
|
import pino from 'pino';
|
|
882
|
-
import createCamundaClient from '@camunda8/orchestration-cluster';
|
|
1341
|
+
import createCamundaClient from '@camunda8/orchestration-cluster-api';
|
|
883
1342
|
|
|
884
1343
|
const p = pino();
|
|
885
1344
|
const client = createCamundaClient({
|
|
@@ -895,9 +1354,10 @@ const client = createCamundaClient({
|
|
|
895
1354
|
|
|
896
1355
|
#### Winston
|
|
897
1356
|
|
|
1357
|
+
<!-- snippet-exempt: uses external winston dependency -->
|
|
898
1358
|
```ts
|
|
899
1359
|
import winston from 'winston';
|
|
900
|
-
import createCamundaClient from '@camunda8/orchestration-cluster';
|
|
1360
|
+
import createCamundaClient from '@camunda8/orchestration-cluster-api';
|
|
901
1361
|
|
|
902
1362
|
const w = winston.createLogger({ transports: [new winston.transports.Console()] });
|
|
903
1363
|
const client = createCamundaClient({
|
|
@@ -920,9 +1380,10 @@ const client = createCamundaClient({
|
|
|
920
1380
|
|
|
921
1381
|
#### loglevel
|
|
922
1382
|
|
|
1383
|
+
<!-- snippet-exempt: uses external loglevel dependency -->
|
|
923
1384
|
```ts
|
|
924
1385
|
import log from 'loglevel';
|
|
925
|
-
import createCamundaClient from '@camunda8/orchestration-cluster';
|
|
1386
|
+
import createCamundaClient from '@camunda8/orchestration-cluster-api';
|
|
926
1387
|
|
|
927
1388
|
log.setLevel('info'); // host app level
|
|
928
1389
|
const client = createCamundaClient({
|
|
@@ -963,9 +1424,10 @@ May throw:
|
|
|
963
1424
|
|
|
964
1425
|
All SDK-thrown operational errors normalize to a discriminated union (`SdkError`) when they originate from HTTP, network, auth, or validation layers. Use the guard `isSdkError` to narrow inside a catch:
|
|
965
1426
|
|
|
1427
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeErrorHandlingImport+ReadmeErrorHandling -->
|
|
1428
|
+
|
|
966
1429
|
```ts
|
|
967
|
-
import { createCamundaClient } from '@camunda8/orchestration-cluster-api';
|
|
968
|
-
import { isSdkError } from '@camunda8/orchestration-cluster-api/dist/runtime/errors';
|
|
1430
|
+
import { createCamundaClient, isSdkError } from '@camunda8/orchestration-cluster-api';
|
|
969
1431
|
|
|
970
1432
|
const client = createCamundaClient();
|
|
971
1433
|
|
|
@@ -1012,13 +1474,15 @@ _Note that this feature is experimental and subject to change._
|
|
|
1012
1474
|
|
|
1013
1475
|
If you prefer FP‑style explicit error handling instead of exceptions, use the result client wrapper:
|
|
1014
1476
|
|
|
1477
|
+
<!-- snippet-source: examples/readme-imports.txt,examples/readme.ts | regions: ReadmeResultClientImport+ReadmeResultClient -->
|
|
1478
|
+
|
|
1015
1479
|
```ts
|
|
1016
|
-
import { createCamundaResultClient, isOk } from '@camunda8/orchestration-cluster';
|
|
1480
|
+
import { createCamundaResultClient, isOk } from '@camunda8/orchestration-cluster-api';
|
|
1017
1481
|
|
|
1018
1482
|
const camundaR = createCamundaResultClient();
|
|
1019
1483
|
const res = await camundaR.createDeployment({ resources: [file] });
|
|
1020
1484
|
if (isOk(res)) {
|
|
1021
|
-
console.log('Deployment key', res.value.
|
|
1485
|
+
console.log('Deployment key', res.value.deploymentKey);
|
|
1022
1486
|
} else {
|
|
1023
1487
|
console.error('Deployment failed', res.error);
|
|
1024
1488
|
}
|
|
@@ -1032,8 +1496,9 @@ API surface differences:
|
|
|
1032
1496
|
|
|
1033
1497
|
Helpers:
|
|
1034
1498
|
|
|
1499
|
+
<!-- snippet-exempt: one-liner import example -->
|
|
1035
1500
|
```ts
|
|
1036
|
-
import { isOk, isErr } from '@camunda8/orchestration-cluster';
|
|
1501
|
+
import { isOk, isErr } from '@camunda8/orchestration-cluster-api';
|
|
1037
1502
|
```
|
|
1038
1503
|
|
|
1039
1504
|
When to use:
|
|
@@ -1048,8 +1513,9 @@ _Note that this feature is experimental and subject to change._
|
|
|
1048
1513
|
|
|
1049
1514
|
For projects using `fp-ts`, wrap the throwing client in a lazy `TaskEither` facade:
|
|
1050
1515
|
|
|
1516
|
+
<!-- snippet-exempt: requires external fp-ts dependency -->
|
|
1051
1517
|
```ts
|
|
1052
|
-
import { createCamundaFpClient } from '@camunda8/orchestration-cluster';
|
|
1518
|
+
import { createCamundaFpClient } from '@camunda8/orchestration-cluster-api/fp';
|
|
1053
1519
|
import { pipe } from 'fp-ts/function';
|
|
1054
1520
|
import * as TE from 'fp-ts/TaskEither';
|
|
1055
1521
|
|
|
@@ -1097,6 +1563,8 @@ The deployment endpoint requires each resource to have a filename (extension use
|
|
|
1097
1563
|
|
|
1098
1564
|
### Browser
|
|
1099
1565
|
|
|
1566
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeDeployBrowser -->
|
|
1567
|
+
|
|
1100
1568
|
```ts
|
|
1101
1569
|
const bpmnXml = `<definitions id="process" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">...</definitions>`;
|
|
1102
1570
|
const file = new File([bpmnXml], 'order-process.bpmn', { type: 'application/xml' });
|
|
@@ -1106,6 +1574,7 @@ console.log(result.deployments.length);
|
|
|
1106
1574
|
|
|
1107
1575
|
From an existing Blob:
|
|
1108
1576
|
|
|
1577
|
+
<!-- snippet-exempt: uses hypothetical getBlob() function -->
|
|
1109
1578
|
```ts
|
|
1110
1579
|
const blob: Blob = getBlob();
|
|
1111
1580
|
const file = new File([blob], 'model.bpmn');
|
|
@@ -1116,6 +1585,8 @@ await camunda.createDeployment({ resources: [file] });
|
|
|
1116
1585
|
|
|
1117
1586
|
Use the built-in helper `deployResourcesFromFiles(...)` to read local files and create `File` objects automatically. It returns the enriched `ExtendedDeploymentResult` (adds typed arrays: `processes`, `decisions`, `decisionRequirements`, `forms`, `resources`).
|
|
1118
1587
|
|
|
1588
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeDeployNode -->
|
|
1589
|
+
|
|
1119
1590
|
```ts
|
|
1120
1591
|
const result = await camunda.deployResourcesFromFiles([
|
|
1121
1592
|
'./bpmn/order-process.bpmn',
|
|
@@ -1129,12 +1600,14 @@ console.log(result.decisions.length);
|
|
|
1129
1600
|
|
|
1130
1601
|
With explicit tenant (overriding tenant from configuration):
|
|
1131
1602
|
|
|
1603
|
+
<!-- snippet-exempt: small variant of injected deploy example above -->
|
|
1132
1604
|
```ts
|
|
1133
1605
|
await camunda.deployResourcesFromFiles(['./bpmn/order-process.bpmn'], { tenantId: 'tenant-a' });
|
|
1134
1606
|
```
|
|
1135
1607
|
|
|
1136
1608
|
Error handling:
|
|
1137
1609
|
|
|
1610
|
+
<!-- snippet-exempt: small variant of injected deploy example above -->
|
|
1138
1611
|
```ts
|
|
1139
1612
|
try {
|
|
1140
1613
|
await camunda.deployResourcesFromFiles([]); // throws (empty array)
|
|
@@ -1145,6 +1618,7 @@ try {
|
|
|
1145
1618
|
|
|
1146
1619
|
Manual construction alternative (if you need custom logic):
|
|
1147
1620
|
|
|
1621
|
+
<!-- snippet-exempt: alternative construction pattern using node:buffer -->
|
|
1148
1622
|
```ts
|
|
1149
1623
|
import { File } from 'node:buffer';
|
|
1150
1624
|
const bpmnXml =
|
|
@@ -1166,6 +1640,8 @@ Empty arrays are rejected. Always use correct extensions so the server can class
|
|
|
1166
1640
|
|
|
1167
1641
|
Create isolated clients per test file:
|
|
1168
1642
|
|
|
1643
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeTestingClient -->
|
|
1644
|
+
|
|
1169
1645
|
```ts
|
|
1170
1646
|
const client = createCamundaClient({
|
|
1171
1647
|
config: { CAMUNDA_REST_ADDRESS: 'http://localhost:8080', CAMUNDA_AUTH_STRATEGY: 'NONE' },
|
|
@@ -1174,9 +1650,11 @@ const client = createCamundaClient({
|
|
|
1174
1650
|
|
|
1175
1651
|
Inject a mock fetch:
|
|
1176
1652
|
|
|
1653
|
+
<!-- snippet-source: examples/readme.ts | regions: ReadmeTestingMock -->
|
|
1654
|
+
|
|
1177
1655
|
```ts
|
|
1178
1656
|
const client = createCamundaClient({
|
|
1179
|
-
fetch: async (
|
|
1657
|
+
fetch: async (_input, _init) => new Response(JSON.stringify({ ok: true }), { status: 200 }),
|
|
1180
1658
|
});
|
|
1181
1659
|
```
|
|
1182
1660
|
|