@ironflow/node 0.20.2 → 0.21.0

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.
Files changed (145) hide show
  1. package/dist/agent/agent.d.ts +60 -0
  2. package/dist/agent/agent.d.ts.map +1 -0
  3. package/dist/agent/agent.js +133 -0
  4. package/dist/agent/agent.js.map +1 -0
  5. package/dist/agent/approve.d.ts +23 -0
  6. package/dist/agent/approve.d.ts.map +1 -0
  7. package/dist/agent/approve.js +42 -0
  8. package/dist/agent/approve.js.map +1 -0
  9. package/dist/agent/dispatch.d.ts +63 -0
  10. package/dist/agent/dispatch.d.ts.map +1 -0
  11. package/dist/agent/dispatch.js +130 -0
  12. package/dist/agent/dispatch.js.map +1 -0
  13. package/dist/agent/errors.d.ts +90 -0
  14. package/dist/agent/errors.d.ts.map +1 -0
  15. package/dist/agent/errors.js +136 -0
  16. package/dist/agent/errors.js.map +1 -0
  17. package/dist/agent/index.d.ts +35 -0
  18. package/dist/agent/index.d.ts.map +1 -0
  19. package/dist/agent/index.js +32 -0
  20. package/dist/agent/index.js.map +1 -0
  21. package/dist/agent/internal-registry.d.ts +27 -0
  22. package/dist/agent/internal-registry.d.ts.map +1 -0
  23. package/dist/agent/internal-registry.js +36 -0
  24. package/dist/agent/internal-registry.js.map +1 -0
  25. package/dist/agent/internal.d.ts +24 -0
  26. package/dist/agent/internal.d.ts.map +1 -0
  27. package/dist/agent/internal.js +29 -0
  28. package/dist/agent/internal.js.map +1 -0
  29. package/dist/agent/llm.d.ts +39 -0
  30. package/dist/agent/llm.d.ts.map +1 -0
  31. package/dist/agent/llm.js +59 -0
  32. package/dist/agent/llm.js.map +1 -0
  33. package/dist/agent/mcp.d.ts +51 -0
  34. package/dist/agent/mcp.d.ts.map +1 -0
  35. package/dist/agent/mcp.js +155 -0
  36. package/dist/agent/mcp.js.map +1 -0
  37. package/dist/agent/memory.d.ts +74 -0
  38. package/dist/agent/memory.d.ts.map +1 -0
  39. package/dist/agent/memory.js +130 -0
  40. package/dist/agent/memory.js.map +1 -0
  41. package/dist/agent/spawn.d.ts +20 -0
  42. package/dist/agent/spawn.d.ts.map +1 -0
  43. package/dist/agent/spawn.js +29 -0
  44. package/dist/agent/spawn.js.map +1 -0
  45. package/dist/agent/tool.d.ts +39 -0
  46. package/dist/agent/tool.d.ts.map +1 -0
  47. package/dist/agent/tool.js +103 -0
  48. package/dist/agent/tool.js.map +1 -0
  49. package/dist/agent/types.d.ts +363 -0
  50. package/dist/agent/types.d.ts.map +1 -0
  51. package/dist/agent/types.js +9 -0
  52. package/dist/agent/types.js.map +1 -0
  53. package/dist/client.d.ts +942 -0
  54. package/dist/client.d.ts.map +1 -0
  55. package/dist/client.js +1557 -0
  56. package/dist/client.js.map +1 -0
  57. package/dist/command-dedup.d.ts +61 -0
  58. package/dist/command-dedup.d.ts.map +1 -0
  59. package/dist/command-dedup.js +129 -0
  60. package/dist/command-dedup.js.map +1 -0
  61. package/dist/config-client.d.ts +58 -0
  62. package/dist/config-client.d.ts.map +1 -0
  63. package/dist/config-client.js +171 -0
  64. package/dist/config-client.js.map +1 -0
  65. package/dist/function.d.ts +53 -0
  66. package/dist/function.d.ts.map +1 -0
  67. package/dist/function.js +72 -0
  68. package/dist/function.js.map +1 -0
  69. package/dist/index.d.ts +71 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +70 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/internal/assert-defined.d.ts +10 -0
  74. package/dist/internal/assert-defined.d.ts.map +1 -0
  75. package/dist/internal/assert-defined.js +15 -0
  76. package/dist/internal/assert-defined.js.map +1 -0
  77. package/dist/internal/context.d.ts +142 -0
  78. package/dist/internal/context.d.ts.map +1 -0
  79. package/dist/internal/context.js +306 -0
  80. package/dist/internal/context.js.map +1 -0
  81. package/dist/internal/errors.d.ts +66 -0
  82. package/dist/internal/errors.d.ts.map +1 -0
  83. package/dist/internal/errors.js +29 -0
  84. package/dist/internal/errors.js.map +1 -0
  85. package/dist/internal/run-context.d.ts +10 -0
  86. package/dist/internal/run-context.d.ts.map +1 -0
  87. package/dist/internal/run-context.js +23 -0
  88. package/dist/internal/run-context.js.map +1 -0
  89. package/dist/kv.d.ts +86 -0
  90. package/dist/kv.d.ts.map +1 -0
  91. package/dist/kv.js +261 -0
  92. package/dist/kv.js.map +1 -0
  93. package/dist/projection-runner.d.ts +83 -0
  94. package/dist/projection-runner.d.ts.map +1 -0
  95. package/dist/projection-runner.js +498 -0
  96. package/dist/projection-runner.js.map +1 -0
  97. package/dist/projection.d.ts +36 -0
  98. package/dist/projection.d.ts.map +1 -0
  99. package/dist/projection.js +55 -0
  100. package/dist/projection.js.map +1 -0
  101. package/dist/secrets.d.ts +6 -0
  102. package/dist/secrets.d.ts.map +1 -0
  103. package/dist/secrets.js +19 -0
  104. package/dist/secrets.js.map +1 -0
  105. package/dist/serve.d.ts +71 -0
  106. package/dist/serve.d.ts.map +1 -0
  107. package/dist/serve.js +460 -0
  108. package/dist/serve.js.map +1 -0
  109. package/dist/step.d.ts +18 -0
  110. package/dist/step.d.ts.map +1 -0
  111. package/dist/step.js +581 -0
  112. package/dist/step.js.map +1 -0
  113. package/dist/subscribe.d.ts +164 -0
  114. package/dist/subscribe.d.ts.map +1 -0
  115. package/dist/subscribe.js +487 -0
  116. package/dist/subscribe.js.map +1 -0
  117. package/dist/test/index.d.ts +22 -0
  118. package/dist/test/index.d.ts.map +1 -0
  119. package/dist/test/index.js +112 -0
  120. package/dist/test/index.js.map +1 -0
  121. package/dist/test/test-step.d.ts +21 -0
  122. package/dist/test/test-step.d.ts.map +1 -0
  123. package/dist/test/test-step.js +83 -0
  124. package/dist/test/test-step.js.map +1 -0
  125. package/dist/types.d.ts +108 -0
  126. package/dist/types.d.ts.map +1 -0
  127. package/dist/types.js +5 -0
  128. package/dist/types.js.map +1 -0
  129. package/dist/version.d.ts +2 -0
  130. package/dist/version.d.ts.map +1 -0
  131. package/dist/version.js +4 -0
  132. package/dist/version.js.map +1 -0
  133. package/dist/webhook.d.ts +22 -0
  134. package/dist/webhook.d.ts.map +1 -0
  135. package/dist/webhook.js +23 -0
  136. package/dist/webhook.js.map +1 -0
  137. package/dist/worker-streaming.d.ts +17 -0
  138. package/dist/worker-streaming.d.ts.map +1 -0
  139. package/dist/worker-streaming.js +510 -0
  140. package/dist/worker-streaming.js.map +1 -0
  141. package/dist/worker.d.ts +28 -0
  142. package/dist/worker.d.ts.map +1 -0
  143. package/dist/worker.js +559 -0
  144. package/dist/worker.js.map +1 -0
  145. package/package.json +3 -3
@@ -0,0 +1,942 @@
1
+ /**
2
+ * Ironflow Node.js Client
3
+ *
4
+ * HTTP client for interacting with the Ironflow server.
5
+ * Provides methods for registering functions, triggering events, and managing runs.
6
+ */
7
+ import { type EmitSyncResult, type RunStatus, type Trigger, type ExecutionMode, type RetryConfig, type ConcurrencyConfig, type DebounceConfig, type AppendEventInput, type AppendOptions, type AppendResult, type ReadStreamOptions, type StreamEvent, type StreamInfo, type StreamSnapshot, type CreateSQLProjectionInput, type QuerySQLProjectionOptions, type SQLProjectionQueryResult, type PublishOptions, type PublishResult, type TopicInfo, type TopicStats, type APIKey, type APIKeyWithSecret, type CreateAPIKeyInput, type Organization, type CreateOrgInput, type UpdateOrgInput, type Role, type CreateRoleInput, type UpdateRoleInput, type Policy, type CreatePolicyInput, type UpdatePolicyInput, type ProjectionStateResult, type GetProjectionOptions, type ProjectionStatusInfo, type RebuildJob, type WaitResult, type TimeTravelRunState, type TimeTravelTimelineEvent, type TimeTravelStepOutput, type AuditTrailEntry, type Secret, type SecretListEntry, type StreamListEntry, type EntityHistoryEntry, type Project, type Environment, type EventSchema, type RegisterSchemaInput, type TestUpcastInput, type UpcastResult, type WebhookSource, type CreateWebhookSourceInput, type WebhookDelivery, type ListWebhookDeliveriesOptions, type User, type CreateUserInput, type UpdateUserInput, type Tenant } from "@ironflow/core";
8
+ import { KVClient } from "./kv.js";
9
+ import { CommandDedup, type CommandDedupOptions } from "./command-dedup.js";
10
+ import { ConfigClient } from "./config-client.js";
11
+ import type { OnErrorHandler } from "./types.js";
12
+ /**
13
+ * Configuration for the Ironflow client
14
+ */
15
+ export interface IronflowClientConfig {
16
+ /** Server URL (default: http://localhost:9123 or IRONFLOW_SERVER_URL env var) */
17
+ serverUrl?: string;
18
+ /** API key for authentication (optional for local dev) */
19
+ apiKey?: string;
20
+ /** Request timeout in milliseconds (default: 30000) */
21
+ timeout?: number;
22
+ /** Global error handler called on every client error (fires before re-throw) */
23
+ onError?: OnErrorHandler;
24
+ }
25
+ /**
26
+ * Function registration request
27
+ */
28
+ export interface RegisterFunctionRequest {
29
+ /** Unique function identifier */
30
+ id: string;
31
+ /** Display name */
32
+ name?: string;
33
+ /** Description */
34
+ description?: string;
35
+ /** Event triggers */
36
+ triggers?: Trigger[];
37
+ /** Retry configuration */
38
+ retry?: RetryConfig;
39
+ /** Timeout in milliseconds */
40
+ timeoutMs?: number;
41
+ /** Concurrency configuration */
42
+ concurrency?: ConcurrencyConfig;
43
+ /** Debounce configuration — collapse rapid events (issue #545) */
44
+ debounce?: DebounceConfig;
45
+ /** Preferred execution mode */
46
+ preferredMode?: ExecutionMode;
47
+ /** Endpoint URL for push mode */
48
+ endpointUrl?: string;
49
+ /** Actor key for sticky routing */
50
+ actorKey?: string;
51
+ /** Pause behavior for scoped injection ("hold" or "release") */
52
+ pauseBehavior?: string;
53
+ /** Compensate-on-cancel flag (issue #546 P2). Pull-mode only. */
54
+ compensateOnCancel?: boolean;
55
+ /** Cancel-on-event specs (issue #546 P3 / #572). */
56
+ cancelOn?: {
57
+ event: string;
58
+ match: string;
59
+ }[];
60
+ }
61
+ /**
62
+ * Result from registering a function
63
+ */
64
+ export interface RegisterFunctionResult {
65
+ /** Whether the function was newly created (vs updated) */
66
+ created: boolean;
67
+ }
68
+ /**
69
+ * Result from emitting an event
70
+ */
71
+ export interface EmitResult {
72
+ /** IDs of runs created by this event */
73
+ runIds: string[];
74
+ /** ID of the stored event */
75
+ eventId: string;
76
+ }
77
+ /**
78
+ * Options for emitting an event
79
+ */
80
+ export interface EmitOptions {
81
+ /** Event schema version (default 1) */
82
+ version?: number;
83
+ /** Idempotency key to prevent duplicate processing */
84
+ idempotencyKey?: string;
85
+ /** Additional metadata */
86
+ metadata?: Record<string, unknown>;
87
+ }
88
+ /**
89
+ * Run information
90
+ */
91
+ export interface Run {
92
+ /** Run ID */
93
+ id: string;
94
+ /** Function ID */
95
+ functionId: string;
96
+ /** Event ID that triggered this run */
97
+ eventId: string;
98
+ /** Current status */
99
+ status: RunStatus;
100
+ /** Current attempt number */
101
+ attempt: number;
102
+ /** Maximum attempts allowed */
103
+ maxAttempts: number;
104
+ /** Input data */
105
+ input?: unknown;
106
+ /** Output data (if completed) */
107
+ output?: unknown;
108
+ /** Error information (if failed) */
109
+ error?: {
110
+ message: string;
111
+ code: string;
112
+ };
113
+ /** When the run started */
114
+ startedAt?: string;
115
+ /** When the run ended */
116
+ endedAt?: string;
117
+ /** When the run was created */
118
+ createdAt: string;
119
+ /** When the run was last updated */
120
+ updatedAt: string;
121
+ }
122
+ /**
123
+ * Options for listing runs
124
+ */
125
+ export interface ListRunsOptions {
126
+ /** Filter by function ID */
127
+ functionId?: string;
128
+ /** Filter by status */
129
+ status?: RunStatus;
130
+ /** Maximum number of results */
131
+ limit?: number;
132
+ /** Pagination cursor */
133
+ cursor?: string;
134
+ }
135
+ /**
136
+ * Result from listing runs
137
+ */
138
+ export interface ListRunsResult {
139
+ /** List of runs */
140
+ runs: Run[];
141
+ /** Cursor for next page */
142
+ nextCursor?: string;
143
+ /** Total count of matching runs */
144
+ totalCount: number;
145
+ }
146
+ /**
147
+ * Ironflow client for server-side operations
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { createClient } from "@ironflow/node";
152
+ *
153
+ * const client = createClient({
154
+ * serverUrl: "http://localhost:9123",
155
+ * });
156
+ *
157
+ * // Register a function
158
+ * await client.registerFunction({
159
+ * id: "my-function",
160
+ * name: "My Function",
161
+ * triggers: [{ event: "my.event" }],
162
+ * endpointUrl: "http://localhost:3000/api/ironflow",
163
+ * preferredMode: "push",
164
+ * });
165
+ *
166
+ * // Emit an event
167
+ * const result = await client.emit("my.event", { data: "value" });
168
+ * console.log("Created runs:", result.runIds);
169
+ * ```
170
+ */
171
+ export declare class IronflowClient {
172
+ private readonly serverUrl;
173
+ private readonly apiKey?;
174
+ private readonly timeout;
175
+ private readonly onErrorHandler?;
176
+ constructor(config?: IronflowClientConfig);
177
+ /**
178
+ * Register a function with the Ironflow server
179
+ */
180
+ registerFunction(request: RegisterFunctionRequest): Promise<RegisterFunctionResult>;
181
+ /**
182
+ * Emit an event to trigger workflows
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const result = await client.emit("order.placed", {
187
+ * orderId: "123",
188
+ * total: 99.99,
189
+ * });
190
+ * console.log("Created runs:", result.runIds);
191
+ * ```
192
+ */
193
+ emit(eventName: string, data: unknown, options?: EmitOptions): Promise<EmitResult>;
194
+ /**
195
+ * Emit an event synchronously — waits for the triggered run to complete and returns the result.
196
+ *
197
+ * Calls the TriggerSync endpoint, which blocks until the run finishes or the timeout elapses.
198
+ * Throws RunFailedError if the run fails, RunCancelledError if it is cancelled.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const result = await client.emitSync("order.placed", { orderId: "123" });
203
+ * console.log("Output:", result.output);
204
+ * ```
205
+ */
206
+ emitSync(eventName: string, data: unknown, options?: {
207
+ timeout?: number;
208
+ }): Promise<EmitSyncResult>;
209
+ /**
210
+ * Publish a message to a developer pub/sub topic.
211
+ * Unlike emit(), this does NOT trigger workflow functions.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const result = await client.publish("notifications", {
216
+ * userId: "123",
217
+ * message: "Hello!",
218
+ * });
219
+ * console.log("Published:", result.eventId, result.sequence);
220
+ * ```
221
+ */
222
+ publish(topic: string, data: unknown, options?: PublishOptions): Promise<PublishResult>;
223
+ /**
224
+ * List all active developer pub/sub topics.
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const topics = await client.listTopics();
229
+ * for (const t of topics) {
230
+ * console.log(t.name, t.messageCount);
231
+ * }
232
+ * ```
233
+ */
234
+ listTopics(): Promise<TopicInfo[]>;
235
+ /**
236
+ * Get detailed statistics for a topic.
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const stats = await client.getTopicStats("notifications");
241
+ * console.log("Messages:", stats.messageCount, "Lag:", stats.lag);
242
+ * ```
243
+ */
244
+ getTopicStats(topic: string): Promise<TopicStats>;
245
+ /**
246
+ * Get a run by ID
247
+ */
248
+ getRun(runId: string): Promise<Run>;
249
+ /**
250
+ * List runs with optional filtering
251
+ */
252
+ listRuns(options?: ListRunsOptions): Promise<ListRunsResult>;
253
+ /**
254
+ * Cancel a running workflow
255
+ */
256
+ cancelRun(runId: string, reason?: string): Promise<Run>;
257
+ /**
258
+ * Retry a failed run
259
+ */
260
+ retryRun(runId: string, fromStep?: string): Promise<Run>;
261
+ /**
262
+ * Health check
263
+ */
264
+ health(): Promise<string>;
265
+ /**
266
+ * Entity stream operations
267
+ *
268
+ * @example
269
+ * ```typescript
270
+ * // Append an event to a stream
271
+ * const result = await client.streams.append("order-123", {
272
+ * name: "order.created",
273
+ * data: { total: 100 },
274
+ * entityType: "order",
275
+ * });
276
+ *
277
+ * // Read events from a stream
278
+ * const { events } = await client.streams.read("order-123", { limit: 10 });
279
+ *
280
+ * // Get stream info
281
+ * const info = await client.streams.getInfo("order-123");
282
+ * ```
283
+ */
284
+ streams: {
285
+ /**
286
+ * Append an event to an entity stream
287
+ */
288
+ append: (entityId: string, input: AppendEventInput, options?: AppendOptions) => Promise<AppendResult>;
289
+ /**
290
+ * Read events from an entity stream
291
+ */
292
+ read: (entityId: string, options?: ReadStreamOptions) => Promise<{
293
+ events: StreamEvent[];
294
+ totalCount: number;
295
+ }>;
296
+ /**
297
+ * Get information about an entity stream.
298
+ *
299
+ * Returns `null` if no events have been written to this stream yet — safe to
300
+ * pass `expectedVersion: 0` to `append()` in that case to create the first event.
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * const info = await client.streams.getInfo("order-123");
305
+ * await client.streams.append("order-123", event, {
306
+ * expectedVersion: info ? info.version : 0,
307
+ * });
308
+ * ```
309
+ */
310
+ getInfo: (entityId: string) => Promise<StreamInfo | null>;
311
+ /**
312
+ * Create a snapshot of the materialized state at a specific stream version.
313
+ * Use snapshots to speed up state reconstruction for long-lived entity streams.
314
+ */
315
+ createSnapshot: (entityId: string, input: {
316
+ entityType: string;
317
+ entityVersion: number;
318
+ state: Record<string, unknown>;
319
+ }) => Promise<{
320
+ snapshotId: string;
321
+ }>;
322
+ /**
323
+ * Get the latest snapshot at or before a given version.
324
+ * Returns the snapshot closest to the requested version without exceeding it.
325
+ */
326
+ getSnapshot: (entityId: string, options?: {
327
+ beforeVersion?: number;
328
+ }) => Promise<StreamSnapshot>;
329
+ /**
330
+ * List all entity streams.
331
+ */
332
+ listStreams: () => Promise<StreamListEntry[]>;
333
+ /**
334
+ * Get the full event history for an entity.
335
+ */
336
+ getEntityHistory: (entityId: string) => Promise<EntityHistoryEntry[]>;
337
+ };
338
+ /**
339
+ * SQL-backed projections
340
+ *
341
+ * Create materialized SQL tables from event streams. Events are processed
342
+ * server-side using parameterized SQL handlers.
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * // Create a SQL projection
347
+ * await client.sqlProjections.create({
348
+ * name: "board",
349
+ * tableSql: "CREATE TABLE proj_board (id TEXT PRIMARY KEY, title TEXT, status TEXT)",
350
+ * eventHandlers: {
351
+ * "issue.created": "INSERT INTO proj_board (id, title, status) VALUES (:entity_id, :data.title, 'OPEN')",
352
+ * "issue.status_changed": "UPDATE proj_board SET status = :data.to WHERE id = :entity_id",
353
+ * },
354
+ * events: ["issue.created", "issue.status_changed"],
355
+ * });
356
+ *
357
+ * // Query the projection
358
+ * const result = await client.sqlProjections.query("board", {
359
+ * where: "status = 'OPEN'",
360
+ * orderBy: "title ASC",
361
+ * limit: 50,
362
+ * });
363
+ * ```
364
+ */
365
+ readonly sqlProjections: {
366
+ /**
367
+ * Create a SQL-backed projection with a materialized table and event handlers.
368
+ */
369
+ create: (input: CreateSQLProjectionInput) => Promise<{
370
+ name: string;
371
+ status: string;
372
+ }>;
373
+ /**
374
+ * Query a SQL-backed projection table with optional filtering, ordering, and pagination.
375
+ */
376
+ query: (name: string, options?: QuerySQLProjectionOptions) => Promise<SQLProjectionQueryResult>;
377
+ };
378
+ /**
379
+ * API key management
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * // Create an API key
384
+ * const { key } = await client.apiKeys.create({ name: "ci-key" });
385
+ *
386
+ * // List all API keys
387
+ * const keys = await client.apiKeys.list();
388
+ *
389
+ * // Rotate a key
390
+ * const rotated = await client.apiKeys.rotate(keys[0].id);
391
+ * ```
392
+ */
393
+ readonly apiKeys: {
394
+ /** Create a new API key */
395
+ create: (input: CreateAPIKeyInput) => Promise<APIKeyWithSecret>;
396
+ /** List all API keys */
397
+ list: () => Promise<APIKey[]>;
398
+ /** Get an API key by ID */
399
+ get: (id: string) => Promise<APIKey>;
400
+ /** Delete an API key */
401
+ delete: (id: string) => Promise<void>;
402
+ /** Rotate an API key (generates a new secret) */
403
+ rotate: (id: string) => Promise<APIKeyWithSecret>;
404
+ };
405
+ /**
406
+ * Organization management (enterprise)
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * const org = await client.orgs.create({ name: "Acme Corp" });
411
+ * const orgs = await client.orgs.list();
412
+ * await client.orgs.update(org.id, { name: "Acme Inc" });
413
+ * ```
414
+ */
415
+ readonly orgs: {
416
+ /** Create a new organization */
417
+ create: (input: CreateOrgInput) => Promise<Organization>;
418
+ /** List all organizations */
419
+ list: () => Promise<Organization[]>;
420
+ /** Get an organization by ID */
421
+ get: (id: string) => Promise<Organization>;
422
+ /** Update an organization */
423
+ update: (id: string, input: UpdateOrgInput) => Promise<Organization>;
424
+ /** Delete an organization */
425
+ delete: (id: string) => Promise<void>;
426
+ };
427
+ /**
428
+ * Role management (enterprise)
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * const role = await client.roles.create({ name: "deployer", org_id: orgId });
433
+ * await client.roles.assignPolicy(role.id, policyId);
434
+ * const roles = await client.roles.list(orgId);
435
+ * ```
436
+ */
437
+ readonly roles: {
438
+ /** Create a new role */
439
+ create: (input: CreateRoleInput) => Promise<Role>;
440
+ /** List roles, optionally filtered by organization */
441
+ list: (orgId?: string) => Promise<Role[]>;
442
+ /** Get a role by ID */
443
+ get: (id: string) => Promise<Role>;
444
+ /** Update a role */
445
+ update: (id: string, input: UpdateRoleInput) => Promise<Role>;
446
+ /** Delete a role */
447
+ delete: (id: string) => Promise<void>;
448
+ /** Assign a policy to a role */
449
+ assignPolicy: (roleId: string, policyId: string) => Promise<void>;
450
+ /** Remove a policy from a role */
451
+ removePolicy: (roleId: string, policyId: string) => Promise<void>;
452
+ };
453
+ /**
454
+ * Policy management (enterprise)
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * const policy = await client.policies.create({
459
+ * name: "allow-emit",
460
+ * effect: "allow",
461
+ * actions: "emit:*",
462
+ * resources: "*",
463
+ * org_id: orgId,
464
+ * });
465
+ * const policies = await client.policies.list(orgId);
466
+ * ```
467
+ */
468
+ readonly policies: {
469
+ /** Create a new policy */
470
+ create: (input: CreatePolicyInput) => Promise<Policy>;
471
+ /** List policies, optionally filtered by organization */
472
+ list: (orgId?: string) => Promise<Policy[]>;
473
+ /** Get a policy by ID */
474
+ get: (id: string) => Promise<Policy>;
475
+ /** Update a policy */
476
+ update: (id: string, input: UpdatePolicyInput) => Promise<Policy>;
477
+ /** Delete a policy */
478
+ delete: (id: string) => Promise<void>;
479
+ };
480
+ /**
481
+ * Projection management
482
+ *
483
+ * @example
484
+ * ```typescript
485
+ * const state = await client.projections.get("order-summary");
486
+ * const statuses = await client.projections.list();
487
+ * await client.projections.rebuild("order-summary");
488
+ * ```
489
+ */
490
+ readonly projections: {
491
+ /**
492
+ * Get the current materialized state of a projection.
493
+ *
494
+ * Returns a flat `ProjectionStateResult<TState>` (see `@ironflow/core`).
495
+ * The server returns a wrapped envelope and this method peels it via
496
+ * `peelProjectionEnvelope`. See issue #610 / CHANGELOG 0.20.0.
497
+ *
498
+ * For a freshly registered projection with no events applied, returns
499
+ * empty `state`, `lastEventTime: undefined`, `version: 0`.
500
+ */
501
+ get: <TState = unknown>(name: string, options?: GetProjectionOptions) => Promise<ProjectionStateResult<TState>>;
502
+ /** List all projection statuses */
503
+ list: () => Promise<ProjectionStatusInfo[]>;
504
+ /** Get operational status for a projection */
505
+ getStatus: (name: string) => Promise<ProjectionStatusInfo>;
506
+ /** Trigger a full rebuild of a projection */
507
+ rebuild: (name: string) => Promise<RebuildJob>;
508
+ /** Get the status of an in-progress or completed rebuild job */
509
+ getRebuildJob: (name: string) => Promise<RebuildJob>;
510
+ /** Delete a projection */
511
+ delete: (name: string) => Promise<void>;
512
+ /** Pause a projection (stop consuming new events) */
513
+ pause: (name: string) => Promise<void>;
514
+ /** Resume a paused projection */
515
+ resume: (name: string) => Promise<void>;
516
+ /** Cancel an in-progress rebuild */
517
+ cancelRebuild: (name: string) => Promise<void>;
518
+ /**
519
+ * Wait until the named projection has processed events up to `minSeq`,
520
+ * or the timeout elapses. Read-your-writes primitive for CQRS: pair
521
+ * with `sequence` from a `streams.append` response.
522
+ *
523
+ * ```typescript
524
+ * const { sequence } = await client.streams.append(orderId, event);
525
+ * await client.projections.waitForCatchup("order-detail-view", {
526
+ * minSeq: sequence,
527
+ * partition: orderId,
528
+ * timeoutMs: 5000,
529
+ * });
530
+ * ```
531
+ *
532
+ * Errors: 404 (projection not found), 409 (paused/rebuilding/partition
533
+ * unsupported for external), 429 (wait capacity exceeded).
534
+ *
535
+ * Issue #473.
536
+ */
537
+ waitForCatchup: (name: string, opts: {
538
+ minSeq: bigint | number;
539
+ timeoutMs?: number;
540
+ partition?: string;
541
+ }) => Promise<WaitResult>;
542
+ /**
543
+ * Wait on multiple projections in a single request. All items share
544
+ * a single timeout deadline and a single atomic slot reservation on
545
+ * the server — if the server's cap cannot absorb N items, the whole
546
+ * batch is rejected with 429. Per-item failures are returned per
547
+ * element via `error` fields.
548
+ *
549
+ * Max 16 items. Issue #473.
550
+ */
551
+ waitForCatchupBatch: (items: Array<{
552
+ name: string;
553
+ minSeq: bigint | number;
554
+ partition?: string;
555
+ }>, opts?: {
556
+ timeoutMs?: number;
557
+ }) => Promise<Array<{
558
+ result?: WaitResult;
559
+ error?: string;
560
+ }>>;
561
+ /**
562
+ * Wait for a specific event (identified by `eventId` from a
563
+ * `streams.append` response) to be processed by the given projection.
564
+ * The server resolves eventId → NATS seq internally.
565
+ *
566
+ * Errors: 404 (event not found), 409 (event predates sequence
567
+ * tracking — fall back to waitForCatchup with minSeq from a
568
+ * fresh write), plus the standard wait errors.
569
+ *
570
+ * Issue #473.
571
+ */
572
+ waitForEvent: (eventId: string, projection: string, opts?: {
573
+ timeoutMs?: number;
574
+ partition?: string;
575
+ }) => Promise<WaitResult>;
576
+ };
577
+ /**
578
+ * Secrets management
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * await client.secrets.set("stripe-key", "sk_live_...");
583
+ * const secret = await client.secrets.get("stripe-key");
584
+ * const all = await client.secrets.list();
585
+ * await client.secrets.delete("stripe-key");
586
+ * ```
587
+ */
588
+ readonly secrets: {
589
+ /** Get a secret by name (returns value) */
590
+ get: (name: string) => Promise<Secret>;
591
+ /** Create a new secret */
592
+ set: (name: string, value: string) => Promise<Secret>;
593
+ /** Update an existing secret's value */
594
+ update: (name: string, value: string) => Promise<Secret>;
595
+ /** List all secrets (names only, no values) */
596
+ list: () => Promise<SecretListEntry[]>;
597
+ /** Delete a secret */
598
+ delete: (name: string) => Promise<void>;
599
+ };
600
+ /**
601
+ * Project management
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * const project = await client.projects.create({ name: "my-service" });
606
+ * const projects = await client.projects.list();
607
+ * await client.projects.update(project.id, { name: "renamed-service" });
608
+ * await client.projects.delete(project.id);
609
+ * ```
610
+ */
611
+ readonly projects: {
612
+ /** List all projects */
613
+ list: () => Promise<Project[]>;
614
+ /** Create a new project */
615
+ create: (input: {
616
+ name: string;
617
+ description?: string;
618
+ }) => Promise<Project>;
619
+ /** Update a project */
620
+ update: (id: string, input: {
621
+ name?: string;
622
+ description?: string;
623
+ }) => Promise<Project>;
624
+ /** Delete a project */
625
+ delete: (id: string) => Promise<void>;
626
+ };
627
+ /**
628
+ * Environment management
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * const env = await client.environments.create({ name: "staging", projectId: "proj_..." });
633
+ * const envs = await client.environments.list();
634
+ * await client.environments.update(env.id, { name: "staging-v2" });
635
+ * await client.environments.delete(env.id);
636
+ * ```
637
+ */
638
+ readonly environments: {
639
+ /** List all environments */
640
+ list: () => Promise<Environment[]>;
641
+ /** Create a new environment */
642
+ create: (input: {
643
+ name: string;
644
+ project_id: string;
645
+ }) => Promise<Environment>;
646
+ /** Update an environment */
647
+ update: (id: string, input: {
648
+ name?: string;
649
+ }) => Promise<Environment>;
650
+ /** Delete an environment */
651
+ delete: (id: string) => Promise<void>;
652
+ };
653
+ /**
654
+ * Event schema registry operations
655
+ *
656
+ * @example
657
+ * ```typescript
658
+ * // Register a schema
659
+ * const schema = await client.schemas.register({
660
+ * name: "order.placed",
661
+ * version: 1,
662
+ * schema: { type: "object", properties: { orderId: { type: "string" } } },
663
+ * });
664
+ *
665
+ * // List all schemas
666
+ * const schemas = await client.schemas.list();
667
+ *
668
+ * // Get latest version of a schema
669
+ * const latest = await client.schemas.get("order.placed");
670
+ *
671
+ * // Get a specific version
672
+ * const v1 = await client.schemas.getVersion("order.placed", 1);
673
+ *
674
+ * // Test an upcast transformation
675
+ * const result = await client.schemas.testUpcast({
676
+ * eventName: "order.placed",
677
+ * fromVersion: 1,
678
+ * toVersion: 2,
679
+ * data: { orderId: "123" },
680
+ * });
681
+ * ```
682
+ */
683
+ readonly schemas: {
684
+ /** Register a new event schema (or a new version of an existing schema) */
685
+ register: (input: RegisterSchemaInput) => Promise<EventSchema>;
686
+ /** List all registered event schemas */
687
+ list: () => Promise<EventSchema[]>;
688
+ /** Get the latest version of an event schema by name */
689
+ get: (name: string) => Promise<EventSchema>;
690
+ /** Get a specific version of an event schema */
691
+ getVersion: (name: string, version: number) => Promise<EventSchema>;
692
+ /** Delete a specific version of an event schema */
693
+ delete: (name: string, version: number) => Promise<void>;
694
+ /** Test an upcast transformation between two schema versions */
695
+ testUpcast: (input: TestUpcastInput) => Promise<UpcastResult>;
696
+ };
697
+ /**
698
+ * Get the reconstructed state of a run at a specific point in time.
699
+ *
700
+ * @param runId The run ID to query
701
+ * @param timestamp The point in time to reconstruct state at
702
+ */
703
+ getRunStateAt(runId: string, timestamp: Date): Promise<TimeTravelRunState>;
704
+ /**
705
+ * Get the timeline of events for a run (for time-travel debugging).
706
+ *
707
+ * @param runId The run ID to query
708
+ */
709
+ getRunTimeline(runId: string): Promise<TimeTravelTimelineEvent[]>;
710
+ /**
711
+ * Get the output of a specific step at a point in time.
712
+ *
713
+ * @param runId The run ID
714
+ * @param stepId The step ID
715
+ * @param timestamp The point in time to query
716
+ */
717
+ getStepOutputAt(runId: string, stepId: string, timestamp: Date): Promise<TimeTravelStepOutput>;
718
+ /**
719
+ * Get the audit trail for a run.
720
+ *
721
+ * @param runId The run ID to retrieve the audit trail for
722
+ */
723
+ getAuditTrail(runId: string): Promise<AuditTrailEntry[]>;
724
+ /**
725
+ * Webhook management operations
726
+ *
727
+ * @example
728
+ * ```typescript
729
+ * // List all webhook sources
730
+ * const sources = await client.webhooks.listSources();
731
+ *
732
+ * // Delete a webhook source
733
+ * await client.webhooks.deleteSource("my-webhook");
734
+ *
735
+ * // List deliveries for a source
736
+ * const { deliveries } = await client.webhooks.listDeliveries({ sourceId: "my-webhook" });
737
+ * ```
738
+ */
739
+ readonly webhooks: {
740
+ /** Create a new webhook source */
741
+ create: (input: CreateWebhookSourceInput) => Promise<WebhookSource>;
742
+ /** List all registered webhook sources */
743
+ listSources: () => Promise<WebhookSource[]>;
744
+ /** Delete a webhook source by ID */
745
+ deleteSource: (id: string) => Promise<void>;
746
+ /** List webhook deliveries with optional filtering */
747
+ listDeliveries: (opts?: ListWebhookDeliveriesOptions) => Promise<{
748
+ deliveries: WebhookDelivery[];
749
+ totalCount: number;
750
+ }>;
751
+ };
752
+ /**
753
+ * User management operations
754
+ *
755
+ * @example
756
+ * ```typescript
757
+ * // Create a user
758
+ * const user = await client.users.create({ email: "alice@example.com", password: "secret", roles: ["admin"] });
759
+ *
760
+ * // List users
761
+ * const users = await client.users.list();
762
+ *
763
+ * // Update a user
764
+ * await client.users.update(user.id, { name: "Alice" });
765
+ *
766
+ * // Delete a user
767
+ * await client.users.delete(user.id);
768
+ * ```
769
+ */
770
+ readonly users: {
771
+ /** Create a new user (admin only) */
772
+ create: (input: CreateUserInput) => Promise<User>;
773
+ /** List all users in the current organization (admin only) */
774
+ list: () => Promise<User[]>;
775
+ /** Get a user by ID */
776
+ get: (id: string) => Promise<User>;
777
+ /** Update a user's profile (admin only) */
778
+ update: (id: string, input: UpdateUserInput) => Promise<User>;
779
+ /** Delete a user (admin only) */
780
+ delete: (id: string) => Promise<void>;
781
+ };
782
+ /**
783
+ * Tenant management operations (enterprise-only)
784
+ *
785
+ * @example
786
+ * ```typescript
787
+ * // List all tenants
788
+ * const tenants = await client.tenants.list();
789
+ * console.log(tenants.map(t => t.name));
790
+ * ```
791
+ */
792
+ readonly tenants: {
793
+ /** List all tenants (enterprise-only) */
794
+ list: () => Promise<Tenant[]>;
795
+ };
796
+ /**
797
+ * KV store operations
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * const kv = client.kv();
802
+ * const bucket = await kv.createBucket({ name: "sessions", ttlSeconds: 3600 });
803
+ * const handle = kv.bucket("sessions");
804
+ * const { revision } = await handle.put("user.123", { token: "abc" });
805
+ * const entry = await handle.get("user.123");
806
+ * ```
807
+ */
808
+ kv(): KVClient;
809
+ /**
810
+ * Create a CommandDedup instance for atomic command-level idempotency.
811
+ *
812
+ * Uses the claim-first pattern backed by NATS KV. The KV bucket is created
813
+ * lazily on the first operation. Store the returned instance and reuse it
814
+ * across requests — do not call commandDedup() per request.
815
+ *
816
+ * @example
817
+ * ```typescript
818
+ * const dedup = client.commandDedup<OrderResult>("order-commands");
819
+ * const prior = await dedup.tryClaim(commandId, { orderId, claimedAt: new Date().toISOString() });
820
+ * if (prior !== null) return prior;
821
+ * try {
822
+ * const result = await runOrderHandler();
823
+ * await dedup.finalize(commandId, result);
824
+ * return result;
825
+ * } catch (err) {
826
+ * await dedup.release(commandId).catch(() => {}); // swallow — don't mask the original error
827
+ * throw err;
828
+ * }
829
+ * ```
830
+ */
831
+ commandDedup<T>(bucketName: string, options?: CommandDedupOptions): CommandDedup<T>;
832
+ /**
833
+ * Config management operations
834
+ *
835
+ * @example
836
+ * ```typescript
837
+ * const config = client.config();
838
+ * await config.set("app", { featureX: true });
839
+ * const { data } = await config.get("app");
840
+ * await config.patch("app", { maxRetries: 5 });
841
+ * const configs = await config.list();
842
+ * await config.delete("app");
843
+ * ```
844
+ */
845
+ config(): ConfigClient;
846
+ /**
847
+ * Patch a step's output (hot patching)
848
+ */
849
+ patchStep(stepId: string, output: Record<string, unknown>, reason?: string): Promise<void>;
850
+ /**
851
+ * Resume a paused or failed run
852
+ */
853
+ resumeRun(runId: string, fromStep?: string): Promise<Run>;
854
+ /**
855
+ * Pause a running workflow run (scoped injection).
856
+ *
857
+ * @example
858
+ * ```typescript
859
+ * const result = await client.pauseRun("run_abc123");
860
+ * console.log(result.status); // "paused"
861
+ * ```
862
+ */
863
+ pauseRun(runId: string): Promise<{
864
+ status: string;
865
+ }>;
866
+ /**
867
+ * Get the paused state of a run, including completed steps and next step hint.
868
+ *
869
+ * @example
870
+ * ```typescript
871
+ * const state = await client.getPausedState("run_abc123");
872
+ * for (const step of state.steps) {
873
+ * console.log(step.name, step.output, step.injected);
874
+ * }
875
+ * console.log("Next step:", state.nextStepHint);
876
+ * ```
877
+ */
878
+ getPausedState(runId: string): Promise<{
879
+ steps: Array<{
880
+ id: string;
881
+ name: string;
882
+ output: unknown;
883
+ injected: boolean;
884
+ completedAt: string;
885
+ }>;
886
+ nextStepHint: string;
887
+ pauseReason: string;
888
+ }>;
889
+ /**
890
+ * Inject new output for a step in a paused run (scoped injection).
891
+ *
892
+ * @example
893
+ * ```typescript
894
+ * const result = await client.injectStepOutput(
895
+ * "run_abc123",
896
+ * "step_xyz",
897
+ * { corrected: true },
898
+ * "Manual correction"
899
+ * );
900
+ * console.log("Previous output:", result.previousOutput);
901
+ * ```
902
+ */
903
+ injectStepOutput(runId: string, stepId: string, newOutput: unknown, reason?: string): Promise<{
904
+ stepId: string;
905
+ previousOutput: unknown;
906
+ }>;
907
+ /**
908
+ * List registered functions
909
+ */
910
+ listFunctions(): Promise<unknown[]>;
911
+ /**
912
+ * List connected workers
913
+ */
914
+ listWorkers(): Promise<unknown[]>;
915
+ /**
916
+ * Make an HTTP request to the server
917
+ */
918
+ private request;
919
+ /**
920
+ * Throw a typed error based on HTTP status code.
921
+ */
922
+ private throwTypedError;
923
+ /**
924
+ * Make a REST HTTP request to the server (supports GET, POST, PATCH, DELETE)
925
+ */
926
+ private restRequest;
927
+ /**
928
+ * Call the global onError handler if registered.
929
+ * Swallows any errors thrown by the callback.
930
+ */
931
+ private callOnError;
932
+ }
933
+ /**
934
+ * Create a new Ironflow client
935
+ *
936
+ * @example
937
+ * ```typescript
938
+ * const client = createClient({ serverUrl: "http://localhost:9123" });
939
+ * ```
940
+ */
941
+ export declare function createClient(config?: IronflowClientConfig): IronflowClient;
942
+ //# sourceMappingURL=client.d.ts.map