@ironflow/node 0.12.0 → 0.13.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/README.md +3 -3
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +108 -46
- package/dist/client.js.map +1 -1
- package/dist/config-client.d.ts +3 -0
- package/dist/config-client.d.ts.map +1 -1
- package/dist/config-client.js +39 -8
- package/dist/config-client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kv.d.ts +4 -0
- package/dist/kv.d.ts.map +1 -1
- package/dist/kv.js +66 -17
- package/dist/kv.js.map +1 -1
- package/dist/serve.js +1 -1
- package/dist/serve.js.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +2 -0
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -572,7 +572,6 @@ Workers poll the Ironflow server for jobs via REST HTTP. Use for long-running ta
|
|
|
572
572
|
| `heartbeatInterval` | `number` | `30000` | Heartbeat interval in ms. |
|
|
573
573
|
| `reconnectDelay` | `number` | `5000` | Reconnect delay in ms. |
|
|
574
574
|
| `labels` | `Record<string, string>` | -- | Worker labels for routing. |
|
|
575
|
-
| `transport` | `"polling" \| "streaming"` | `"polling"` | Transport type. |
|
|
576
575
|
| `logger` | `Logger \| false` | -- | Custom logger or `false` to disable. |
|
|
577
576
|
| `environment` | `string` | `IRONFLOW_ENV` or `"default"` | Target environment. |
|
|
578
577
|
| `eventDefinitions` | `EventDefinitionRegistry` | -- | Registry for automatic event upcasting. |
|
|
@@ -650,6 +649,7 @@ The HTTP client for interacting with the Ironflow server from your backend code.
|
|
|
650
649
|
| `serverUrl` | `string` | `http://localhost:9123` or `IRONFLOW_SERVER_URL` | Server URL. |
|
|
651
650
|
| `apiKey` | `string` | -- | API key for authentication. |
|
|
652
651
|
| `timeout` | `number` | `30000` | Request timeout in ms. |
|
|
652
|
+
| `onError` | `OnErrorHandler` | -- | Global error handler (optional). |
|
|
653
653
|
|
|
654
654
|
### Creating a client
|
|
655
655
|
|
|
@@ -1048,7 +1048,7 @@ const client = createClient({
|
|
|
1048
1048
|
|
|
1049
1049
|
// Create an API key
|
|
1050
1050
|
const newKey = await client.apiKeys.create({ name: 'ci-key', envId: 'env_default' });
|
|
1051
|
-
console.log(newKey.
|
|
1051
|
+
console.log(newKey.key); // Only returned on create/rotate
|
|
1052
1052
|
|
|
1053
1053
|
// List all API keys
|
|
1054
1054
|
const keys = await client.apiKeys.list();
|
|
@@ -1058,7 +1058,7 @@ const key = await client.apiKeys.get(keys[0].id);
|
|
|
1058
1058
|
|
|
1059
1059
|
// Rotate (generates new secret)
|
|
1060
1060
|
const rotated = await client.apiKeys.rotate(key.id);
|
|
1061
|
-
console.log(rotated.
|
|
1061
|
+
console.log(rotated.key);
|
|
1062
1062
|
|
|
1063
1063
|
// Delete
|
|
1064
1064
|
await client.apiKeys.delete(key.id);
|
package/dist/client.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { type RunStatus, type Trigger, type ExecutionMode, type RetryConfig, type ConcurrencyConfig, type AppendEventInput, type AppendOptions, type AppendResult, type ReadStreamOptions, type StreamEvent, type StreamInfo, 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 } from "@ironflow/core";
|
|
8
8
|
import { KVClient } from "./kv.js";
|
|
9
9
|
import { ConfigClient } from "./config-client.js";
|
|
10
|
+
import type { OnErrorHandler } from "./types.js";
|
|
10
11
|
/**
|
|
11
12
|
* Configuration for the Ironflow client
|
|
12
13
|
*/
|
|
@@ -17,6 +18,8 @@ export interface IronflowClientConfig {
|
|
|
17
18
|
apiKey?: string;
|
|
18
19
|
/** Request timeout in milliseconds (default: 30000) */
|
|
19
20
|
timeout?: number;
|
|
21
|
+
/** Global error handler called on every client error (fires before re-throw) */
|
|
22
|
+
onError?: OnErrorHandler;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Function registration request
|
|
@@ -159,6 +162,7 @@ export declare class IronflowClient {
|
|
|
159
162
|
private readonly serverUrl;
|
|
160
163
|
private readonly apiKey?;
|
|
161
164
|
private readonly timeout;
|
|
165
|
+
private readonly onErrorHandler?;
|
|
162
166
|
constructor(config?: IronflowClientConfig);
|
|
163
167
|
/**
|
|
164
168
|
* Register a function with the Ironflow server
|
|
@@ -484,6 +488,11 @@ export declare class IronflowClient {
|
|
|
484
488
|
* Make a REST HTTP request to the server (supports GET, POST, PATCH, DELETE)
|
|
485
489
|
*/
|
|
486
490
|
private restRequest;
|
|
491
|
+
/**
|
|
492
|
+
* Call the global onError handler if registered.
|
|
493
|
+
* Swallows any errors thrown by the callback.
|
|
494
|
+
*/
|
|
495
|
+
private callOnError;
|
|
487
496
|
}
|
|
488
497
|
/**
|
|
489
498
|
* Create a new Ironflow client
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAQL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,Y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,EAAE,MAAM,CAAC;YACX,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,OAAO,CAAC;YAChB,QAAQ,EAAE,OAAO,CAAC;YAClB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC,CAAC;QACH,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IA0BF;;;;;;;;;;;;;OAaG;IACG,gBAAgB,CACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,OAAO,EAClB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IAmBvD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAoCzC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAoCvC;;OAEG;YACW,OAAO;IA6DrB;;OAEG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;YACW,WAAW;IAsDzB;;;OAGG;YACW,WAAW;CAQ1B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,cAAc,CAE1E"}
|
package/dist/client.js
CHANGED
|
@@ -39,10 +39,12 @@ export class IronflowClient {
|
|
|
39
39
|
serverUrl;
|
|
40
40
|
apiKey;
|
|
41
41
|
timeout;
|
|
42
|
+
onErrorHandler;
|
|
42
43
|
constructor(config = {}) {
|
|
43
44
|
this.serverUrl = config.serverUrl || getServerUrl() || DEFAULT_SERVER_URL;
|
|
44
45
|
this.apiKey = config.apiKey;
|
|
45
46
|
this.timeout = config.timeout ?? 30000;
|
|
47
|
+
this.onErrorHandler = config.onError;
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* Register a function with the Ironflow server
|
|
@@ -71,7 +73,7 @@ export class IronflowClient {
|
|
|
71
73
|
body.actorKey = request.actorKey;
|
|
72
74
|
if (request.pauseBehavior)
|
|
73
75
|
body.pauseBehavior = request.pauseBehavior;
|
|
74
|
-
const response = await this.request(API_ENDPOINTS.REGISTER_FUNCTION, body);
|
|
76
|
+
const response = await this.request(API_ENDPOINTS.REGISTER_FUNCTION, body, "registerFunction");
|
|
75
77
|
return { created: response.created };
|
|
76
78
|
}
|
|
77
79
|
/**
|
|
@@ -97,7 +99,7 @@ export class IronflowClient {
|
|
|
97
99
|
body.idempotencyKey = options.idempotencyKey;
|
|
98
100
|
if (options?.metadata)
|
|
99
101
|
body.metadata = options.metadata;
|
|
100
|
-
const response = await this.request(API_ENDPOINTS.TRIGGER, body);
|
|
102
|
+
const response = await this.request(API_ENDPOINTS.TRIGGER, body, "emit");
|
|
101
103
|
return {
|
|
102
104
|
runIds: response.runIds || [],
|
|
103
105
|
eventId: response.eventId,
|
|
@@ -131,7 +133,7 @@ export class IronflowClient {
|
|
|
131
133
|
if (options?.idempotencyKey) {
|
|
132
134
|
body.idempotencyKey = options.idempotencyKey;
|
|
133
135
|
}
|
|
134
|
-
const response = await this.request("/ironflow.v1.PubSubService/Publish", body);
|
|
136
|
+
const response = await this.request("/ironflow.v1.PubSubService/Publish", body, "publish");
|
|
135
137
|
return {
|
|
136
138
|
eventId: response.eventId,
|
|
137
139
|
sequence: parseInt(response.sequence, 10) || 0,
|
|
@@ -149,7 +151,7 @@ export class IronflowClient {
|
|
|
149
151
|
* ```
|
|
150
152
|
*/
|
|
151
153
|
async listTopics() {
|
|
152
|
-
const response = await this.request("/ironflow.v1.PubSubService/ListTopics", {});
|
|
154
|
+
const response = await this.request("/ironflow.v1.PubSubService/ListTopics", {}, "listTopics");
|
|
153
155
|
return (response.topics ?? []).map((t) => ({
|
|
154
156
|
name: String(t.name ?? ""),
|
|
155
157
|
messageCount: Number(t.messageCount ?? 0),
|
|
@@ -168,7 +170,7 @@ export class IronflowClient {
|
|
|
168
170
|
* ```
|
|
169
171
|
*/
|
|
170
172
|
async getTopicStats(topic) {
|
|
171
|
-
const response = await this.request("/ironflow.v1.PubSubService/GetTopicStats", { topic });
|
|
173
|
+
const response = await this.request("/ironflow.v1.PubSubService/GetTopicStats", { topic }, "getTopicStats");
|
|
172
174
|
return {
|
|
173
175
|
name: String(response.name ?? ""),
|
|
174
176
|
messageCount: Number(response.messageCount ?? 0),
|
|
@@ -182,7 +184,7 @@ export class IronflowClient {
|
|
|
182
184
|
* Get a run by ID
|
|
183
185
|
*/
|
|
184
186
|
async getRun(runId) {
|
|
185
|
-
return this.request(API_ENDPOINTS.GET_RUN, { id: runId });
|
|
187
|
+
return this.request(API_ENDPOINTS.GET_RUN, { id: runId }, "getRun");
|
|
186
188
|
}
|
|
187
189
|
/**
|
|
188
190
|
* List runs with optional filtering
|
|
@@ -197,7 +199,7 @@ export class IronflowClient {
|
|
|
197
199
|
body.limit = options.limit;
|
|
198
200
|
if (options?.cursor)
|
|
199
201
|
body.cursor = options.cursor;
|
|
200
|
-
return this.request(API_ENDPOINTS.LIST_RUNS, body);
|
|
202
|
+
return this.request(API_ENDPOINTS.LIST_RUNS, body, "listRuns");
|
|
201
203
|
}
|
|
202
204
|
/**
|
|
203
205
|
* Cancel a running workflow
|
|
@@ -206,7 +208,7 @@ export class IronflowClient {
|
|
|
206
208
|
return this.request(API_ENDPOINTS.CANCEL_RUN, {
|
|
207
209
|
id: runId,
|
|
208
210
|
reason: reason || "",
|
|
209
|
-
});
|
|
211
|
+
}, "cancelRun");
|
|
210
212
|
}
|
|
211
213
|
/**
|
|
212
214
|
* Retry a failed run
|
|
@@ -215,13 +217,13 @@ export class IronflowClient {
|
|
|
215
217
|
const body = { id: runId };
|
|
216
218
|
if (fromStep)
|
|
217
219
|
body.fromStep = fromStep;
|
|
218
|
-
return this.request(API_ENDPOINTS.RETRY_RUN, body);
|
|
220
|
+
return this.request(API_ENDPOINTS.RETRY_RUN, body, "retryRun");
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
223
|
* Health check
|
|
222
224
|
*/
|
|
223
225
|
async health() {
|
|
224
|
-
const response = await this.request(API_ENDPOINTS.HEALTH, {});
|
|
226
|
+
const response = await this.request(API_ENDPOINTS.HEALTH, {}, "health");
|
|
225
227
|
return response.status;
|
|
226
228
|
}
|
|
227
229
|
/**
|
|
@@ -256,7 +258,7 @@ export class IronflowClient {
|
|
|
256
258
|
expected_version: options?.expectedVersion ?? -1,
|
|
257
259
|
idempotency_key: options?.idempotencyKey ?? "",
|
|
258
260
|
version: options?.version ?? 1,
|
|
259
|
-
});
|
|
261
|
+
}, "streams.append");
|
|
260
262
|
return {
|
|
261
263
|
entityVersion: response.entity_version,
|
|
262
264
|
eventId: response.event_id,
|
|
@@ -271,7 +273,7 @@ export class IronflowClient {
|
|
|
271
273
|
from_version: options?.fromVersion ?? 0,
|
|
272
274
|
limit: options?.limit ?? 0,
|
|
273
275
|
direction: options?.direction ?? "forward",
|
|
274
|
-
});
|
|
276
|
+
}, "streams.read");
|
|
275
277
|
return {
|
|
276
278
|
events: (response.events ?? []).map((e) => ({
|
|
277
279
|
id: e.id,
|
|
@@ -292,7 +294,7 @@ export class IronflowClient {
|
|
|
292
294
|
getInfo: async (entityId) => {
|
|
293
295
|
const response = await this.request("/ironflow.v1.EntityStreamService/GetStreamInfo", {
|
|
294
296
|
entity_id: entityId,
|
|
295
|
-
});
|
|
297
|
+
}, "streams.getInfo");
|
|
296
298
|
return {
|
|
297
299
|
entityId: response.entity_id,
|
|
298
300
|
entityType: response.entity_type,
|
|
@@ -321,23 +323,23 @@ export class IronflowClient {
|
|
|
321
323
|
apiKeys = {
|
|
322
324
|
/** Create a new API key */
|
|
323
325
|
create: async (input) => {
|
|
324
|
-
return this.restRequest("POST", "/api/v1/apikeys", input);
|
|
326
|
+
return this.restRequest("POST", "/api/v1/apikeys", input, "apiKeys.create");
|
|
325
327
|
},
|
|
326
328
|
/** List all API keys */
|
|
327
329
|
list: async () => {
|
|
328
|
-
return this.restRequest("GET", "/api/v1/apikeys");
|
|
330
|
+
return this.restRequest("GET", "/api/v1/apikeys", undefined, "apiKeys.list");
|
|
329
331
|
},
|
|
330
332
|
/** Get an API key by ID */
|
|
331
333
|
get: async (id) => {
|
|
332
|
-
return this.restRequest("GET", `/api/v1/apikeys/${id}
|
|
334
|
+
return this.restRequest("GET", `/api/v1/apikeys/${id}`, undefined, "apiKeys.get");
|
|
333
335
|
},
|
|
334
336
|
/** Delete an API key */
|
|
335
337
|
delete: async (id) => {
|
|
336
|
-
await this.restRequest("DELETE", `/api/v1/apikeys/${id}
|
|
338
|
+
await this.restRequest("DELETE", `/api/v1/apikeys/${id}`, undefined, "apiKeys.delete");
|
|
337
339
|
},
|
|
338
340
|
/** Rotate an API key (generates a new secret) */
|
|
339
341
|
rotate: async (id) => {
|
|
340
|
-
return this.restRequest("POST", `/api/v1/apikeys/${id}/rotate
|
|
342
|
+
return this.restRequest("POST", `/api/v1/apikeys/${id}/rotate`, undefined, "apiKeys.rotate");
|
|
341
343
|
},
|
|
342
344
|
};
|
|
343
345
|
/**
|
|
@@ -353,23 +355,23 @@ export class IronflowClient {
|
|
|
353
355
|
orgs = {
|
|
354
356
|
/** Create a new organization */
|
|
355
357
|
create: async (input) => {
|
|
356
|
-
return this.restRequest("POST", "/api/v1/orgs", input);
|
|
358
|
+
return this.restRequest("POST", "/api/v1/orgs", input, "orgs.create");
|
|
357
359
|
},
|
|
358
360
|
/** List all organizations */
|
|
359
361
|
list: async () => {
|
|
360
|
-
return this.restRequest("GET", "/api/v1/orgs");
|
|
362
|
+
return this.restRequest("GET", "/api/v1/orgs", undefined, "orgs.list");
|
|
361
363
|
},
|
|
362
364
|
/** Get an organization by ID */
|
|
363
365
|
get: async (id) => {
|
|
364
|
-
return this.restRequest("GET", `/api/v1/orgs/${id}
|
|
366
|
+
return this.restRequest("GET", `/api/v1/orgs/${id}`, undefined, "orgs.get");
|
|
365
367
|
},
|
|
366
368
|
/** Update an organization */
|
|
367
369
|
update: async (id, input) => {
|
|
368
|
-
return this.restRequest("PATCH", `/api/v1/orgs/${id}`, input);
|
|
370
|
+
return this.restRequest("PATCH", `/api/v1/orgs/${id}`, input, "orgs.update");
|
|
369
371
|
},
|
|
370
372
|
/** Delete an organization */
|
|
371
373
|
delete: async (id) => {
|
|
372
|
-
await this.restRequest("DELETE", `/api/v1/orgs/${id}
|
|
374
|
+
await this.restRequest("DELETE", `/api/v1/orgs/${id}`, undefined, "orgs.delete");
|
|
373
375
|
},
|
|
374
376
|
};
|
|
375
377
|
/**
|
|
@@ -385,34 +387,34 @@ export class IronflowClient {
|
|
|
385
387
|
roles = {
|
|
386
388
|
/** Create a new role */
|
|
387
389
|
create: async (input) => {
|
|
388
|
-
return this.restRequest("POST", "/api/v1/roles", input);
|
|
390
|
+
return this.restRequest("POST", "/api/v1/roles", input, "roles.create");
|
|
389
391
|
},
|
|
390
392
|
/** List roles, optionally filtered by organization */
|
|
391
393
|
list: async (orgId) => {
|
|
392
394
|
const query = orgId ? `?org_id=${orgId}` : "";
|
|
393
|
-
return this.restRequest("GET", `/api/v1/roles${query}
|
|
395
|
+
return this.restRequest("GET", `/api/v1/roles${query}`, undefined, "roles.list");
|
|
394
396
|
},
|
|
395
397
|
/** Get a role by ID */
|
|
396
398
|
get: async (id) => {
|
|
397
|
-
return this.restRequest("GET", `/api/v1/roles/${id}
|
|
399
|
+
return this.restRequest("GET", `/api/v1/roles/${id}`, undefined, "roles.get");
|
|
398
400
|
},
|
|
399
401
|
/** Update a role */
|
|
400
402
|
update: async (id, input) => {
|
|
401
|
-
return this.restRequest("PATCH", `/api/v1/roles/${id}`, input);
|
|
403
|
+
return this.restRequest("PATCH", `/api/v1/roles/${id}`, input, "roles.update");
|
|
402
404
|
},
|
|
403
405
|
/** Delete a role */
|
|
404
406
|
delete: async (id) => {
|
|
405
|
-
await this.restRequest("DELETE", `/api/v1/roles/${id}
|
|
407
|
+
await this.restRequest("DELETE", `/api/v1/roles/${id}`, undefined, "roles.delete");
|
|
406
408
|
},
|
|
407
409
|
/** Assign a policy to a role */
|
|
408
410
|
assignPolicy: async (roleId, policyId) => {
|
|
409
411
|
await this.restRequest("POST", `/api/v1/roles/${roleId}/policies`, {
|
|
410
412
|
policy_id: policyId,
|
|
411
|
-
});
|
|
413
|
+
}, "roles.assignPolicy");
|
|
412
414
|
},
|
|
413
415
|
/** Remove a policy from a role */
|
|
414
416
|
removePolicy: async (roleId, policyId) => {
|
|
415
|
-
await this.restRequest("DELETE", `/api/v1/roles/${roleId}/policies/${policyId}
|
|
417
|
+
await this.restRequest("DELETE", `/api/v1/roles/${roleId}/policies/${policyId}`, undefined, "roles.removePolicy");
|
|
416
418
|
},
|
|
417
419
|
};
|
|
418
420
|
/**
|
|
@@ -433,24 +435,24 @@ export class IronflowClient {
|
|
|
433
435
|
policies = {
|
|
434
436
|
/** Create a new policy */
|
|
435
437
|
create: async (input) => {
|
|
436
|
-
return this.restRequest("POST", "/api/v1/policies", input);
|
|
438
|
+
return this.restRequest("POST", "/api/v1/policies", input, "policies.create");
|
|
437
439
|
},
|
|
438
440
|
/** List policies, optionally filtered by organization */
|
|
439
441
|
list: async (orgId) => {
|
|
440
442
|
const query = orgId ? `?org_id=${orgId}` : "";
|
|
441
|
-
return this.restRequest("GET", `/api/v1/policies${query}
|
|
443
|
+
return this.restRequest("GET", `/api/v1/policies${query}`, undefined, "policies.list");
|
|
442
444
|
},
|
|
443
445
|
/** Get a policy by ID */
|
|
444
446
|
get: async (id) => {
|
|
445
|
-
return this.restRequest("GET", `/api/v1/policies/${id}
|
|
447
|
+
return this.restRequest("GET", `/api/v1/policies/${id}`, undefined, "policies.get");
|
|
446
448
|
},
|
|
447
449
|
/** Update a policy */
|
|
448
450
|
update: async (id, input) => {
|
|
449
|
-
return this.restRequest("PATCH", `/api/v1/policies/${id}`, input);
|
|
451
|
+
return this.restRequest("PATCH", `/api/v1/policies/${id}`, input, "policies.update");
|
|
450
452
|
},
|
|
451
453
|
/** Delete a policy */
|
|
452
454
|
delete: async (id) => {
|
|
453
|
-
await this.restRequest("DELETE", `/api/v1/policies/${id}
|
|
455
|
+
await this.restRequest("DELETE", `/api/v1/policies/${id}`, undefined, "policies.delete");
|
|
454
456
|
},
|
|
455
457
|
};
|
|
456
458
|
/**
|
|
@@ -470,6 +472,7 @@ export class IronflowClient {
|
|
|
470
472
|
serverUrl: this.serverUrl,
|
|
471
473
|
apiKey: this.apiKey,
|
|
472
474
|
timeout: this.timeout,
|
|
475
|
+
onError: this.onErrorHandler,
|
|
473
476
|
});
|
|
474
477
|
}
|
|
475
478
|
/**
|
|
@@ -490,13 +493,15 @@ export class IronflowClient {
|
|
|
490
493
|
serverUrl: this.serverUrl,
|
|
491
494
|
apiKey: this.apiKey,
|
|
492
495
|
timeout: this.timeout,
|
|
496
|
+
onError: this.onErrorHandler,
|
|
493
497
|
});
|
|
494
498
|
}
|
|
495
499
|
/**
|
|
496
500
|
* Patch a step's output (hot patching)
|
|
497
501
|
*/
|
|
498
502
|
async patchStep(stepId, output, reason) {
|
|
499
|
-
const
|
|
503
|
+
const endpoint = "/api/v1/steps/patch";
|
|
504
|
+
const url = `${this.serverUrl}${endpoint}`;
|
|
500
505
|
const headers = {
|
|
501
506
|
"Content-Type": "application/json",
|
|
502
507
|
};
|
|
@@ -505,6 +510,7 @@ export class IronflowClient {
|
|
|
505
510
|
}
|
|
506
511
|
const controller = new AbortController();
|
|
507
512
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
513
|
+
let status;
|
|
508
514
|
try {
|
|
509
515
|
const response = await fetch(url, {
|
|
510
516
|
method: "POST",
|
|
@@ -512,11 +518,16 @@ export class IronflowClient {
|
|
|
512
518
|
body: JSON.stringify({ step_id: stepId, output, reason: reason || "" }),
|
|
513
519
|
signal: controller.signal,
|
|
514
520
|
});
|
|
521
|
+
status = response.status;
|
|
515
522
|
if (!response.ok) {
|
|
516
523
|
const errorBody = await response.text();
|
|
517
524
|
throw new Error(errorBody || `Patch step failed: ${response.status}`);
|
|
518
525
|
}
|
|
519
526
|
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
await this.callOnError(error, { method: "patchStep", endpoint, statusCode: status });
|
|
529
|
+
throw error;
|
|
530
|
+
}
|
|
520
531
|
finally {
|
|
521
532
|
clearTimeout(timeoutId);
|
|
522
533
|
}
|
|
@@ -525,7 +536,8 @@ export class IronflowClient {
|
|
|
525
536
|
* Resume a paused or failed run
|
|
526
537
|
*/
|
|
527
538
|
async resumeRun(runId, fromStep) {
|
|
528
|
-
const
|
|
539
|
+
const endpoint = "/api/v1/runs/resume";
|
|
540
|
+
const url = `${this.serverUrl}${endpoint}`;
|
|
529
541
|
const headers = {
|
|
530
542
|
"Content-Type": "application/json",
|
|
531
543
|
};
|
|
@@ -534,6 +546,7 @@ export class IronflowClient {
|
|
|
534
546
|
}
|
|
535
547
|
const controller = new AbortController();
|
|
536
548
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
549
|
+
let status;
|
|
537
550
|
try {
|
|
538
551
|
const response = await fetch(url, {
|
|
539
552
|
method: "POST",
|
|
@@ -541,12 +554,17 @@ export class IronflowClient {
|
|
|
541
554
|
body: JSON.stringify({ run_id: runId, from_step: fromStep || "" }),
|
|
542
555
|
signal: controller.signal,
|
|
543
556
|
});
|
|
557
|
+
status = response.status;
|
|
544
558
|
if (!response.ok) {
|
|
545
559
|
const errorBody = await response.text();
|
|
546
560
|
throw new Error(errorBody || `Resume run failed: ${response.status}`);
|
|
547
561
|
}
|
|
548
562
|
return response.json();
|
|
549
563
|
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
await this.callOnError(error, { method: "resumeRun", endpoint, statusCode: status });
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
550
568
|
finally {
|
|
551
569
|
clearTimeout(timeoutId);
|
|
552
570
|
}
|
|
@@ -561,7 +579,7 @@ export class IronflowClient {
|
|
|
561
579
|
* ```
|
|
562
580
|
*/
|
|
563
581
|
async pauseRun(runId) {
|
|
564
|
-
return this.request("/ironflow.v1.IronflowService/PauseRun", { run_id: runId });
|
|
582
|
+
return this.request("/ironflow.v1.IronflowService/PauseRun", { run_id: runId }, "pauseRun");
|
|
565
583
|
}
|
|
566
584
|
/**
|
|
567
585
|
* Get the paused state of a run, including completed steps and next step hint.
|
|
@@ -576,7 +594,7 @@ export class IronflowClient {
|
|
|
576
594
|
* ```
|
|
577
595
|
*/
|
|
578
596
|
async getPausedState(runId) {
|
|
579
|
-
const response = await this.request("/ironflow.v1.IronflowService/GetPausedState", { run_id: runId });
|
|
597
|
+
const response = await this.request("/ironflow.v1.IronflowService/GetPausedState", { run_id: runId }, "getPausedState");
|
|
580
598
|
return {
|
|
581
599
|
steps: (response.steps || []).map((s) => ({
|
|
582
600
|
id: s.id,
|
|
@@ -609,7 +627,7 @@ export class IronflowClient {
|
|
|
609
627
|
step_id: stepId,
|
|
610
628
|
new_output: JSON.stringify(newOutput),
|
|
611
629
|
reason: reason ?? "",
|
|
612
|
-
});
|
|
630
|
+
}, "injectStepOutput");
|
|
613
631
|
return {
|
|
614
632
|
stepId: response.step_id,
|
|
615
633
|
previousOutput: response.previous_output
|
|
@@ -621,25 +639,32 @@ export class IronflowClient {
|
|
|
621
639
|
* List registered functions
|
|
622
640
|
*/
|
|
623
641
|
async listFunctions() {
|
|
624
|
-
const
|
|
642
|
+
const endpoint = "/api/v1/functions";
|
|
643
|
+
const url = `${this.serverUrl}${endpoint}`;
|
|
625
644
|
const headers = {};
|
|
626
645
|
if (this.apiKey) {
|
|
627
646
|
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
628
647
|
}
|
|
629
648
|
const controller = new AbortController();
|
|
630
649
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
650
|
+
let status;
|
|
631
651
|
try {
|
|
632
652
|
const response = await fetch(url, {
|
|
633
653
|
method: "GET",
|
|
634
654
|
headers,
|
|
635
655
|
signal: controller.signal,
|
|
636
656
|
});
|
|
657
|
+
status = response.status;
|
|
637
658
|
if (!response.ok) {
|
|
638
659
|
throw new Error(`List functions failed: ${response.status}`);
|
|
639
660
|
}
|
|
640
661
|
const data = (await response.json());
|
|
641
662
|
return data.functions || [];
|
|
642
663
|
}
|
|
664
|
+
catch (error) {
|
|
665
|
+
await this.callOnError(error, { method: "listFunctions", endpoint, statusCode: status });
|
|
666
|
+
throw error;
|
|
667
|
+
}
|
|
643
668
|
finally {
|
|
644
669
|
clearTimeout(timeoutId);
|
|
645
670
|
}
|
|
@@ -648,25 +673,32 @@ export class IronflowClient {
|
|
|
648
673
|
* List connected workers
|
|
649
674
|
*/
|
|
650
675
|
async listWorkers() {
|
|
651
|
-
const
|
|
676
|
+
const endpoint = "/api/v1/workers";
|
|
677
|
+
const url = `${this.serverUrl}${endpoint}`;
|
|
652
678
|
const headers = {};
|
|
653
679
|
if (this.apiKey) {
|
|
654
680
|
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
655
681
|
}
|
|
656
682
|
const controller = new AbortController();
|
|
657
683
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
684
|
+
let status;
|
|
658
685
|
try {
|
|
659
686
|
const response = await fetch(url, {
|
|
660
687
|
method: "GET",
|
|
661
688
|
headers,
|
|
662
689
|
signal: controller.signal,
|
|
663
690
|
});
|
|
691
|
+
status = response.status;
|
|
664
692
|
if (!response.ok) {
|
|
665
693
|
throw new Error(`List workers failed: ${response.status}`);
|
|
666
694
|
}
|
|
667
695
|
const data = (await response.json());
|
|
668
696
|
return data.workers || [];
|
|
669
697
|
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
await this.callOnError(error, { method: "listWorkers", endpoint, statusCode: status });
|
|
700
|
+
throw error;
|
|
701
|
+
}
|
|
670
702
|
finally {
|
|
671
703
|
clearTimeout(timeoutId);
|
|
672
704
|
}
|
|
@@ -674,7 +706,7 @@ export class IronflowClient {
|
|
|
674
706
|
/**
|
|
675
707
|
* Make an HTTP request to the server
|
|
676
708
|
*/
|
|
677
|
-
async request(endpoint, body) {
|
|
709
|
+
async request(endpoint, body, method) {
|
|
678
710
|
const url = `${this.serverUrl}${endpoint}`;
|
|
679
711
|
const headers = {
|
|
680
712
|
"Content-Type": "application/json",
|
|
@@ -684,6 +716,7 @@ export class IronflowClient {
|
|
|
684
716
|
}
|
|
685
717
|
const controller = new AbortController();
|
|
686
718
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
719
|
+
let status;
|
|
687
720
|
try {
|
|
688
721
|
const response = await fetch(url, {
|
|
689
722
|
method: "POST",
|
|
@@ -691,6 +724,7 @@ export class IronflowClient {
|
|
|
691
724
|
body: JSON.stringify(body),
|
|
692
725
|
signal: controller.signal,
|
|
693
726
|
});
|
|
727
|
+
status = response.status;
|
|
694
728
|
if (!response.ok) {
|
|
695
729
|
const errorBody = await response.text();
|
|
696
730
|
let errorMessage = `Request failed with status ${response.status}`;
|
|
@@ -716,6 +750,12 @@ export class IronflowClient {
|
|
|
716
750
|
}
|
|
717
751
|
return response.json();
|
|
718
752
|
}
|
|
753
|
+
catch (error) {
|
|
754
|
+
if (method) {
|
|
755
|
+
await this.callOnError(error, { method, endpoint, statusCode: status });
|
|
756
|
+
}
|
|
757
|
+
throw error;
|
|
758
|
+
}
|
|
719
759
|
finally {
|
|
720
760
|
clearTimeout(timeoutId);
|
|
721
761
|
}
|
|
@@ -738,24 +778,26 @@ export class IronflowClient {
|
|
|
738
778
|
/**
|
|
739
779
|
* Make a REST HTTP request to the server (supports GET, POST, PATCH, DELETE)
|
|
740
780
|
*/
|
|
741
|
-
async restRequest(
|
|
781
|
+
async restRequest(httpMethod, path, body, method) {
|
|
742
782
|
const url = `${this.serverUrl}${path}`;
|
|
743
783
|
const headers = {};
|
|
744
784
|
if (this.apiKey) {
|
|
745
785
|
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
746
786
|
}
|
|
747
|
-
const options = { method, headers };
|
|
748
|
-
if (body && (
|
|
787
|
+
const options = { method: httpMethod, headers };
|
|
788
|
+
if (body && (httpMethod === "POST" || httpMethod === "PATCH" || httpMethod === "PUT")) {
|
|
749
789
|
headers["Content-Type"] = "application/json";
|
|
750
790
|
options.body = JSON.stringify(body);
|
|
751
791
|
}
|
|
752
792
|
const controller = new AbortController();
|
|
753
793
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
794
|
+
let status;
|
|
754
795
|
try {
|
|
755
796
|
const response = await fetch(url, {
|
|
756
797
|
...options,
|
|
757
798
|
signal: controller.signal,
|
|
758
799
|
});
|
|
800
|
+
status = response.status;
|
|
759
801
|
if (!response.ok) {
|
|
760
802
|
const errBody = await response
|
|
761
803
|
.json()
|
|
@@ -769,10 +811,30 @@ export class IronflowClient {
|
|
|
769
811
|
return undefined;
|
|
770
812
|
return response.json();
|
|
771
813
|
}
|
|
814
|
+
catch (error) {
|
|
815
|
+
if (method) {
|
|
816
|
+
await this.callOnError(error, { method, endpoint: path, statusCode: status });
|
|
817
|
+
}
|
|
818
|
+
throw error;
|
|
819
|
+
}
|
|
772
820
|
finally {
|
|
773
821
|
clearTimeout(timeoutId);
|
|
774
822
|
}
|
|
775
823
|
}
|
|
824
|
+
/**
|
|
825
|
+
* Call the global onError handler if registered.
|
|
826
|
+
* Swallows any errors thrown by the callback.
|
|
827
|
+
*/
|
|
828
|
+
async callOnError(error, context) {
|
|
829
|
+
if (!this.onErrorHandler)
|
|
830
|
+
return;
|
|
831
|
+
try {
|
|
832
|
+
await this.onErrorHandler(error, context);
|
|
833
|
+
}
|
|
834
|
+
catch (callbackError) {
|
|
835
|
+
console.error("[ironflow] onError callback threw:", callbackError);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
776
838
|
}
|
|
777
839
|
/**
|
|
778
840
|
* Create a new Ironflow client
|