@hatchet-dev/typescript-sdk 1.11.0 → 1.12.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/clients/admin/admin-client.d.ts +38 -0
- package/clients/admin/admin-client.js +19 -6
- package/clients/dispatcher/action-listener.d.ts +6 -2
- package/clients/dispatcher/action-listener.js +2 -2
- package/clients/dispatcher/dispatcher-client.d.ts +22 -3
- package/clients/dispatcher/dispatcher-client.js +41 -4
- package/clients/event/event-client.d.ts +2 -2
- package/clients/event/event-client.js +4 -4
- package/clients/hatchet-client/hatchet-logger.js +2 -2
- package/clients/rest/generated/Api.d.ts +9 -1
- package/clients/rest/generated/data-contracts.d.ts +44 -8
- package/clients/rest/generated/data-contracts.js +13 -2
- package/clients/worker/worker.js +11 -11
- package/examples/webhooks.d.ts +1 -0
- package/examples/webhooks.js +45 -0
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +70 -25
- package/protoc/dispatcher/dispatcher.js +323 -97
- package/protoc/events/events.d.ts +4 -4
- package/protoc/events/events.js +20 -16
- package/protoc/v1/workflows.d.ts +18 -7
- package/protoc/v1/workflows.js +122 -2
- package/protoc/workflows/workflows.d.ts +22 -22
- package/protoc/workflows/workflows.js +18 -18
- package/step.d.ts +6 -0
- package/step.js +27 -19
- package/util/workflow-run-ref.js +1 -1
- package/v1/client/admin.d.ts +30 -0
- package/v1/client/admin.js +21 -6
- package/v1/client/client.d.ts +8 -1
- package/v1/client/client.js +13 -2
- package/v1/client/features/runs.d.ts +9 -1
- package/v1/client/features/runs.js +4 -2
- package/v1/client/features/webhooks.d.ts +28 -0
- package/v1/client/features/webhooks.js +97 -0
- package/v1/client/worker/context.d.ts +6 -0
- package/v1/client/worker/context.js +30 -22
- package/v1/client/worker/deprecated/deprecation.d.ts +44 -0
- package/v1/client/worker/deprecated/deprecation.js +95 -0
- package/v1/client/worker/deprecated/index.d.ts +4 -0
- package/v1/client/worker/deprecated/index.js +15 -0
- package/v1/client/worker/deprecated/legacy-registration.d.ts +18 -0
- package/v1/client/worker/deprecated/legacy-registration.js +35 -0
- package/v1/client/worker/deprecated/legacy-v1-worker.d.ts +15 -0
- package/v1/client/worker/deprecated/legacy-v1-worker.js +39 -0
- package/v1/client/worker/deprecated/legacy-worker.d.ts +41 -0
- package/v1/client/worker/deprecated/legacy-worker.js +148 -0
- package/v1/client/worker/slot-utils.d.ts +21 -0
- package/v1/client/worker/slot-utils.js +73 -0
- package/v1/client/worker/worker-internal.d.ts +16 -5
- package/v1/client/worker/worker-internal.js +54 -37
- package/v1/client/worker/worker.d.ts +12 -15
- package/v1/client/worker/worker.js +45 -49
- package/v1/declaration.js +1 -1
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/parent-run-context-vars.d.ts +4 -1
- package/v1/parent-run-context-vars.js +1 -0
- package/v1/slot-types.d.ts +5 -0
- package/v1/slot-types.js +9 -0
- package/v1/task.d.ts +2 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +2 -2
package/step.js
CHANGED
|
@@ -267,7 +267,7 @@ class V0Context {
|
|
|
267
267
|
* @returns The name of the task.
|
|
268
268
|
*/
|
|
269
269
|
taskName() {
|
|
270
|
-
return this.action.
|
|
270
|
+
return this.action.taskName;
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
273
|
* Gets the ID of the current workflow run.
|
|
@@ -280,8 +280,16 @@ class V0Context {
|
|
|
280
280
|
* Gets the ID of the current task run.
|
|
281
281
|
* @returns The task run ID.
|
|
282
282
|
*/
|
|
283
|
+
taskRunExternalId() {
|
|
284
|
+
return this.action.taskRunExternalId;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Gets the ID of the current task run.
|
|
288
|
+
* @returns The task run ID.
|
|
289
|
+
* @deprecated use taskRunExternalId() instead
|
|
290
|
+
*/
|
|
283
291
|
taskRunId() {
|
|
284
|
-
return this.
|
|
292
|
+
return this.taskRunExternalId();
|
|
285
293
|
}
|
|
286
294
|
/**
|
|
287
295
|
* Gets the number of times the current task has been retried.
|
|
@@ -296,13 +304,13 @@ class V0Context {
|
|
|
296
304
|
* @param level - The log level (optional).
|
|
297
305
|
*/
|
|
298
306
|
log(message, level) {
|
|
299
|
-
const {
|
|
300
|
-
if (!
|
|
307
|
+
const { taskRunExternalId } = this.action;
|
|
308
|
+
if (!taskRunExternalId) {
|
|
301
309
|
// log a warning
|
|
302
310
|
this.logger.warn('cannot log from context without stepRunId');
|
|
303
311
|
return;
|
|
304
312
|
}
|
|
305
|
-
this.v0.event.putLog(
|
|
313
|
+
this.v0.event.putLog(taskRunExternalId, message, level, this.retryCount());
|
|
306
314
|
}
|
|
307
315
|
/**
|
|
308
316
|
* Refreshes the timeout for the current task.
|
|
@@ -311,13 +319,13 @@ class V0Context {
|
|
|
311
319
|
*/
|
|
312
320
|
refreshTimeout(incrementBy) {
|
|
313
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
314
|
-
const {
|
|
315
|
-
if (!
|
|
322
|
+
const { taskRunExternalId } = this.action;
|
|
323
|
+
if (!taskRunExternalId) {
|
|
316
324
|
// log a warning
|
|
317
325
|
this.logger.warn('cannot refresh timeout from context without stepRunId');
|
|
318
326
|
return;
|
|
319
327
|
}
|
|
320
|
-
yield this.v0.dispatcher.refreshTimeout(incrementBy,
|
|
328
|
+
yield this.v0.dispatcher.refreshTimeout(incrementBy, taskRunExternalId);
|
|
321
329
|
});
|
|
322
330
|
}
|
|
323
331
|
/**
|
|
@@ -328,7 +336,7 @@ class V0Context {
|
|
|
328
336
|
releaseSlot() {
|
|
329
337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
330
338
|
yield this.v0.dispatcher.client.releaseSlot({
|
|
331
|
-
|
|
339
|
+
taskRunExternalId: this.action.taskRunExternalId,
|
|
332
340
|
});
|
|
333
341
|
});
|
|
334
342
|
}
|
|
@@ -339,13 +347,13 @@ class V0Context {
|
|
|
339
347
|
*/
|
|
340
348
|
putStream(data) {
|
|
341
349
|
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
-
const {
|
|
343
|
-
if (!
|
|
350
|
+
const { taskRunExternalId } = this.action;
|
|
351
|
+
if (!taskRunExternalId) {
|
|
344
352
|
// log a warning
|
|
345
353
|
this.logger.warn('cannot log from context without stepRunId');
|
|
346
354
|
return;
|
|
347
355
|
}
|
|
348
|
-
yield this.v0.event.putStream(
|
|
356
|
+
yield this.v0.event.putStream(taskRunExternalId, data, undefined);
|
|
349
357
|
});
|
|
350
358
|
}
|
|
351
359
|
/**
|
|
@@ -378,7 +386,7 @@ class V0Context {
|
|
|
378
386
|
*/
|
|
379
387
|
spawnWorkflows(workflows) {
|
|
380
388
|
return __awaiter(this, void 0, void 0, function* () {
|
|
381
|
-
const { workflowRunId,
|
|
389
|
+
const { workflowRunId, taskRunExternalId } = this.action;
|
|
382
390
|
const workflowRuns = workflows.map(({ workflow, input, options }) => {
|
|
383
391
|
let workflowName;
|
|
384
392
|
if (typeof workflow === 'string') {
|
|
@@ -396,7 +404,7 @@ class V0Context {
|
|
|
396
404
|
const resp = {
|
|
397
405
|
workflowName: name,
|
|
398
406
|
input,
|
|
399
|
-
options: Object.assign(Object.assign({}, opts), { parentId: workflowRunId, parentStepRunId:
|
|
407
|
+
options: Object.assign(Object.assign({}, opts), { parentId: workflowRunId, parentStepRunId: taskRunExternalId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }),
|
|
400
408
|
};
|
|
401
409
|
this.spawnIndex += 1;
|
|
402
410
|
return resp;
|
|
@@ -463,7 +471,7 @@ class V0Context {
|
|
|
463
471
|
*/
|
|
464
472
|
spawnWorkflow(workflow, input, options) {
|
|
465
473
|
return __awaiter(this, void 0, void 0, function* () {
|
|
466
|
-
const { workflowRunId,
|
|
474
|
+
const { workflowRunId, taskRunExternalId } = this.action;
|
|
467
475
|
let workflowName = '';
|
|
468
476
|
if (typeof workflow === 'string') {
|
|
469
477
|
workflowName = workflow;
|
|
@@ -478,7 +486,7 @@ class V0Context {
|
|
|
478
486
|
throw new hatchet_error_1.default(`cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
479
487
|
}
|
|
480
488
|
try {
|
|
481
|
-
const resp = yield this.v0.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentStepRunId:
|
|
489
|
+
const resp = yield this.v0.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentStepRunId: taskRunExternalId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }, opts));
|
|
482
490
|
this.spawnIndex += 1;
|
|
483
491
|
if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
484
492
|
resp._standaloneTaskName = workflow._standalone_task_name;
|
|
@@ -565,13 +573,13 @@ class V0DurableContext extends V0Context {
|
|
|
565
573
|
// eslint-disable-next-line no-plusplus
|
|
566
574
|
const key = `waitFor-${this.waitKey++}`;
|
|
567
575
|
yield this.v0.durableListener.registerDurableEvent({
|
|
568
|
-
taskId: this.action.
|
|
576
|
+
taskId: this.action.taskRunExternalId,
|
|
569
577
|
signalKey: key,
|
|
570
578
|
sleepConditions: pbConditions.sleepConditions,
|
|
571
579
|
userEventConditions: pbConditions.userEventConditions,
|
|
572
580
|
});
|
|
573
581
|
const listener = this.v0.durableListener.subscribe({
|
|
574
|
-
taskId: this.action.
|
|
582
|
+
taskId: this.action.taskRunExternalId,
|
|
575
583
|
signalKey: key,
|
|
576
584
|
});
|
|
577
585
|
const event = yield listener.get();
|
|
@@ -646,7 +654,7 @@ function mapRateLimit(limits) {
|
|
|
646
654
|
});
|
|
647
655
|
}
|
|
648
656
|
// Helper function to validate CEL expressions
|
|
649
|
-
function validateCelExpression(
|
|
657
|
+
function validateCelExpression(_expr) {
|
|
650
658
|
// This is a placeholder. In a real implementation, you'd need to use a CEL parser or validator.
|
|
651
659
|
// For now, we'll just return true to mimic the behavior.
|
|
652
660
|
return true;
|
package/util/workflow-run-ref.js
CHANGED
|
@@ -126,7 +126,7 @@ class WorkflowRunRef {
|
|
|
126
126
|
resolve(outputs[this._standaloneTaskName]);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.
|
|
129
|
+
const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.taskName]: JSON.parse(r.output || '{}') })), {});
|
|
130
130
|
if (!this._standaloneTaskName) {
|
|
131
131
|
resolve(result);
|
|
132
132
|
return;
|
package/v1/client/admin.d.ts
CHANGED
|
@@ -10,6 +10,16 @@ export type WorkflowRun<T = object> = {
|
|
|
10
10
|
input: T;
|
|
11
11
|
options?: {
|
|
12
12
|
parentId?: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* (optional) the parent task run external id.
|
|
15
|
+
*
|
|
16
|
+
* This is the field understood by the workflows gRPC API (`parent_task_run_external_id`).
|
|
17
|
+
*/
|
|
18
|
+
parentTaskRunExternalId?: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
21
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
22
|
+
*/
|
|
13
23
|
parentStepRunId?: string | undefined;
|
|
14
24
|
childIndex?: number | undefined;
|
|
15
25
|
childKey?: string | undefined;
|
|
@@ -33,6 +43,16 @@ export declare class AdminClient {
|
|
|
33
43
|
*/
|
|
34
44
|
runWorkflow<Q = object, P = object>(workflowName: string, input: Q, options?: {
|
|
35
45
|
parentId?: string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* (optional) the parent task run external id.
|
|
48
|
+
*
|
|
49
|
+
* This is the field understood by the workflows gRPC API (`parent_task_run_external_id`).
|
|
50
|
+
*/
|
|
51
|
+
parentTaskRunExternalId?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
54
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
55
|
+
*/
|
|
36
56
|
parentStepRunId?: string | undefined;
|
|
37
57
|
childIndex?: number | undefined;
|
|
38
58
|
childKey?: string | undefined;
|
|
@@ -52,6 +72,16 @@ export declare class AdminClient {
|
|
|
52
72
|
input: Q;
|
|
53
73
|
options?: {
|
|
54
74
|
parentId?: string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* (optional) the parent task run external id.
|
|
77
|
+
*
|
|
78
|
+
* This is the field understood by the workflows gRPC API (`parent_task_run_external_id`).
|
|
79
|
+
*/
|
|
80
|
+
parentTaskRunExternalId?: string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
83
|
+
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
84
|
+
*/
|
|
55
85
|
parentStepRunId?: string | undefined;
|
|
56
86
|
childIndex?: number | undefined;
|
|
57
87
|
childKey?: string | undefined;
|
package/v1/client/admin.js
CHANGED
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -43,9 +54,11 @@ class AdminClient {
|
|
|
43
54
|
try {
|
|
44
55
|
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
|
|
45
56
|
const inputStr = JSON.stringify(input);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
58
|
+
const { additionalMetadata, parentStepRunId, parentTaskRunExternalId } = opts, rest = __rest(opts, ["additionalMetadata", "parentStepRunId", "parentTaskRunExternalId"]);
|
|
59
|
+
const request = Object.assign(Object.assign({ name: computedName, input: inputStr }, rest), {
|
|
60
|
+
// API expects `parentTaskRunExternalId`; accept old names as aliases.
|
|
61
|
+
parentTaskRunExternalId: parentTaskRunExternalId !== null && parentTaskRunExternalId !== void 0 ? parentTaskRunExternalId : parentStepRunId, additionalMetadata: additionalMetadata ? JSON.stringify(additionalMetadata) : undefined, priority: opts.priority });
|
|
49
62
|
const resp = yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.grpc.triggerWorkflow(request); }), this.logger);
|
|
50
63
|
const id = resp.workflowRunId;
|
|
51
64
|
const ref = new workflow_run_ref_1.default(id, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId,
|
|
@@ -71,9 +84,11 @@ class AdminClient {
|
|
|
71
84
|
const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
|
|
72
85
|
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
|
|
73
86
|
const inputStr = JSON.stringify(input);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
88
|
+
const { additionalMetadata, parentStepRunId, parentTaskRunExternalId } = opts, rest = __rest(opts, ["additionalMetadata", "parentStepRunId", "parentTaskRunExternalId"]);
|
|
89
|
+
return Object.assign(Object.assign({ name: computedName, input: inputStr }, rest), {
|
|
90
|
+
// API expects `parentTaskRunExternalId`; accept old names as aliases.
|
|
91
|
+
parentTaskRunExternalId: parentTaskRunExternalId !== null && parentTaskRunExternalId !== void 0 ? parentTaskRunExternalId : parentStepRunId, additionalMetadata: additionalMetadata ? JSON.stringify(additionalMetadata) : undefined });
|
|
77
92
|
});
|
|
78
93
|
const limit = 4 * 1024 * 1024; // FIXME configurable GRPC limit
|
|
79
94
|
const batches = (0, batch_1.batch)(workflowRequests, batchSize, limit);
|
package/v1/client/client.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { ScheduleClient } from './features/schedules';
|
|
|
20
20
|
import { CronClient } from './features/crons';
|
|
21
21
|
import { CELClient } from './features/cel';
|
|
22
22
|
import { TenantClient } from './features/tenant';
|
|
23
|
+
import { WebhooksClient } from './features/webhooks';
|
|
23
24
|
/**
|
|
24
25
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
25
26
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -193,6 +194,12 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
193
194
|
* @returns A tenant client instance
|
|
194
195
|
*/
|
|
195
196
|
get tenant(): TenantClient;
|
|
197
|
+
private _webhooks;
|
|
198
|
+
/**
|
|
199
|
+
* Get the webhooks client for creating and managing webhooks
|
|
200
|
+
* @returns A webhooks client instance
|
|
201
|
+
*/
|
|
202
|
+
get webhooks(): WebhooksClient;
|
|
196
203
|
private _ratelimits;
|
|
197
204
|
/**
|
|
198
205
|
* Get the rate limits client for creating and managing rate limits
|
|
@@ -245,6 +252,6 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
245
252
|
* @param workflows - The workflows to register on the webhooks
|
|
246
253
|
* @returns A promise that resolves when the webhook is registered
|
|
247
254
|
*/
|
|
248
|
-
|
|
255
|
+
v0webhooks(workflows: V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
|
|
249
256
|
runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
|
|
250
257
|
}
|
package/v1/client/client.js
CHANGED
|
@@ -37,6 +37,7 @@ const schedules_1 = require("./features/schedules");
|
|
|
37
37
|
const crons_1 = require("./features/crons");
|
|
38
38
|
const cel_1 = require("./features/cel");
|
|
39
39
|
const tenant_1 = require("./features/tenant");
|
|
40
|
+
const webhooks_1 = require("./features/webhooks");
|
|
40
41
|
/**
|
|
41
42
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
42
43
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -94,7 +95,7 @@ class HatchetClient {
|
|
|
94
95
|
.warn('🚨⚠️‼️ YOU ARE USING A V0 ENGINE WITH A V1 SDK, WHICH IS NOT SUPPORTED. PLEASE UPGRADE YOUR ENGINE TO V1.🚨⚠️‼️');
|
|
95
96
|
}
|
|
96
97
|
})
|
|
97
|
-
.catch((
|
|
98
|
+
.catch(() => {
|
|
98
99
|
// Do nothing here
|
|
99
100
|
});
|
|
100
101
|
}
|
|
@@ -289,6 +290,16 @@ class HatchetClient {
|
|
|
289
290
|
}
|
|
290
291
|
return this._tenant;
|
|
291
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Get the webhooks client for creating and managing webhooks
|
|
295
|
+
* @returns A webhooks client instance
|
|
296
|
+
*/
|
|
297
|
+
get webhooks() {
|
|
298
|
+
if (!this._webhooks) {
|
|
299
|
+
this._webhooks = new webhooks_1.WebhooksClient(this);
|
|
300
|
+
}
|
|
301
|
+
return this._webhooks;
|
|
302
|
+
}
|
|
292
303
|
/**
|
|
293
304
|
* Get the rate limits client for creating and managing rate limits
|
|
294
305
|
* @returns A rate limits client instance
|
|
@@ -374,7 +385,7 @@ class HatchetClient {
|
|
|
374
385
|
* @param workflows - The workflows to register on the webhooks
|
|
375
386
|
* @returns A promise that resolves when the webhook is registered
|
|
376
387
|
*/
|
|
377
|
-
|
|
388
|
+
v0webhooks(workflows) {
|
|
378
389
|
return this._v0.webhooks(workflows);
|
|
379
390
|
}
|
|
380
391
|
runRef(id) {
|
|
@@ -40,12 +40,20 @@ export interface ListRunsOpts extends RunFilter {
|
|
|
40
40
|
/** Whether to include DAGs or only to include tasks */
|
|
41
41
|
onlyTasks: boolean;
|
|
42
42
|
/**
|
|
43
|
-
* The parent task external id to filter by
|
|
43
|
+
* The parent task run external id to filter by
|
|
44
|
+
* @deprecated use parentTaskRunExternalId instead
|
|
44
45
|
* @format uuid
|
|
45
46
|
* @minLength 36
|
|
46
47
|
* @maxLength 36
|
|
47
48
|
*/
|
|
48
49
|
parentTaskExternalId?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The parent task run external id to filter by
|
|
52
|
+
* @format uuid
|
|
53
|
+
* @minLength 36
|
|
54
|
+
* @maxLength 36
|
|
55
|
+
*/
|
|
56
|
+
parentTaskRunExternalId?: string;
|
|
49
57
|
/**
|
|
50
58
|
* The triggering event external id to filter by
|
|
51
59
|
* @format uuid
|
|
@@ -62,7 +62,9 @@ class RunsClient {
|
|
|
62
62
|
}
|
|
63
63
|
list(opts) {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const
|
|
65
|
+
const normalizedOpts = (opts === null || opts === void 0 ? void 0 : opts.parentTaskExternalId) && !(opts === null || opts === void 0 ? void 0 : opts.parentTaskRunExternalId)
|
|
66
|
+
? Object.assign(Object.assign({}, opts), { parentTaskRunExternalId: opts.parentTaskExternalId }) : opts;
|
|
67
|
+
const { data } = yield this.api.v1WorkflowRunList(this.tenantId, Object.assign({}, (yield this.prepareListFilter(normalizedOpts || {}))));
|
|
66
68
|
return data;
|
|
67
69
|
});
|
|
68
70
|
}
|
|
@@ -114,7 +116,7 @@ class RunsClient {
|
|
|
114
116
|
workflow_ids: yield Promise.all(((_b = opts.workflowNames) === null || _b === void 0 ? void 0 : _b.map((name) => __awaiter(this, void 0, void 0, function* () { return (yield this.workflows.get(name)).metadata.id; }))) || []),
|
|
115
117
|
additional_metadata: am,
|
|
116
118
|
only_tasks: opts.onlyTasks || false,
|
|
117
|
-
parent_task_external_id: opts.
|
|
119
|
+
parent_task_external_id: opts.parentTaskRunExternalId,
|
|
118
120
|
triggering_event_external_id: opts.triggeringEventExternalId,
|
|
119
121
|
include_payloads: opts.includePayloads,
|
|
120
122
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { V1CreateWebhookRequestBase, V1UpdateWebhookRequest, V1Webhook, V1WebhookList, V1WebhookSourceName, V1WebhookAPIKeyAuth, V1WebhookBasicAuth, V1WebhookHMACAuth } from '../../../clients/rest/generated/data-contracts';
|
|
2
|
+
import { HatchetClient } from '../client';
|
|
3
|
+
export type CreateWebhookOptions = V1CreateWebhookRequestBase & {
|
|
4
|
+
auth: V1WebhookBasicAuth | V1WebhookAPIKeyAuth | V1WebhookHMACAuth;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Client for managing incoming webhooks in Hatchet.
|
|
8
|
+
*
|
|
9
|
+
* Webhooks allow external systems to trigger Hatchet workflows by sending HTTP
|
|
10
|
+
* requests to dedicated endpoints. This enables real-time integration with
|
|
11
|
+
* third-party services like GitHub, Stripe, Slack, or any system that can send
|
|
12
|
+
* webhook events.
|
|
13
|
+
*/
|
|
14
|
+
export declare class WebhooksClient {
|
|
15
|
+
api: HatchetClient['api'];
|
|
16
|
+
tenantId: string;
|
|
17
|
+
constructor(client: HatchetClient);
|
|
18
|
+
list(options?: {
|
|
19
|
+
limit?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
webhookNames?: string[];
|
|
22
|
+
sourceNames?: V1WebhookSourceName[];
|
|
23
|
+
}): Promise<V1WebhookList>;
|
|
24
|
+
get(webhookName: string): Promise<V1Webhook>;
|
|
25
|
+
create(request: CreateWebhookOptions): Promise<V1Webhook>;
|
|
26
|
+
update(webhookName: string, options?: Partial<V1UpdateWebhookRequest>): Promise<V1Webhook>;
|
|
27
|
+
delete(webhookName: string): Promise<V1Webhook>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.WebhooksClient = void 0;
|
|
24
|
+
const data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
|
|
25
|
+
function getAuthType(auth) {
|
|
26
|
+
if ('username' in auth && 'password' in auth)
|
|
27
|
+
return data_contracts_1.V1WebhookAuthType.BASIC;
|
|
28
|
+
if ('headerName' in auth && 'apiKey' in auth)
|
|
29
|
+
return data_contracts_1.V1WebhookAuthType.API_KEY;
|
|
30
|
+
if ('signingSecret' in auth &&
|
|
31
|
+
'signatureHeaderName' in auth &&
|
|
32
|
+
'algorithm' in auth &&
|
|
33
|
+
'encoding' in auth) {
|
|
34
|
+
return data_contracts_1.V1WebhookAuthType.HMAC;
|
|
35
|
+
}
|
|
36
|
+
throw new Error('Invalid webhook auth');
|
|
37
|
+
}
|
|
38
|
+
function toCreateWebhookRequest(options) {
|
|
39
|
+
const { auth } = options, base = __rest(options, ["auth"]);
|
|
40
|
+
const authType = getAuthType(auth);
|
|
41
|
+
return Object.assign(Object.assign({}, base), { authType, auth });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Client for managing incoming webhooks in Hatchet.
|
|
45
|
+
*
|
|
46
|
+
* Webhooks allow external systems to trigger Hatchet workflows by sending HTTP
|
|
47
|
+
* requests to dedicated endpoints. This enables real-time integration with
|
|
48
|
+
* third-party services like GitHub, Stripe, Slack, or any system that can send
|
|
49
|
+
* webhook events.
|
|
50
|
+
*/
|
|
51
|
+
class WebhooksClient {
|
|
52
|
+
constructor(client) {
|
|
53
|
+
this.api = client.api;
|
|
54
|
+
this.tenantId = client.tenantId;
|
|
55
|
+
}
|
|
56
|
+
list(options) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const response = yield this.api.v1WebhookList(this.tenantId, {
|
|
59
|
+
limit: options === null || options === void 0 ? void 0 : options.limit,
|
|
60
|
+
offset: options === null || options === void 0 ? void 0 : options.offset,
|
|
61
|
+
webhookNames: options === null || options === void 0 ? void 0 : options.webhookNames,
|
|
62
|
+
sourceNames: options === null || options === void 0 ? void 0 : options.sourceNames,
|
|
63
|
+
});
|
|
64
|
+
return response.data;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
get(webhookName) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const response = yield this.api.v1WebhookGet(this.tenantId, webhookName);
|
|
70
|
+
return response.data;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
create(request) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const payload = toCreateWebhookRequest(request);
|
|
76
|
+
const response = yield this.api.v1WebhookCreate(this.tenantId, payload);
|
|
77
|
+
return response.data;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
update(webhookName_1) {
|
|
81
|
+
return __awaiter(this, arguments, void 0, function* (webhookName, options = {}) {
|
|
82
|
+
const response = yield this.api.v1WebhookUpdate(this.tenantId, webhookName, {
|
|
83
|
+
eventKeyExpression: options.eventKeyExpression,
|
|
84
|
+
scopeExpression: options.scopeExpression,
|
|
85
|
+
staticPayload: options.staticPayload,
|
|
86
|
+
});
|
|
87
|
+
return response.data;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
delete(webhookName) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const response = yield this.api.v1WebhookDelete(this.tenantId, webhookName);
|
|
93
|
+
return response.data;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.WebhooksClient = WebhooksClient;
|
|
@@ -112,6 +112,12 @@ export declare class Context<T, K = {}> {
|
|
|
112
112
|
* Gets the ID of the current task run.
|
|
113
113
|
* @returns The task run ID.
|
|
114
114
|
*/
|
|
115
|
+
taskRunExternalId(): string;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the ID of the current task run.
|
|
118
|
+
* @returns The task run ID.
|
|
119
|
+
* @deprecated use taskRunExternalId() instead
|
|
120
|
+
*/
|
|
115
121
|
taskRunId(): string;
|
|
116
122
|
/**
|
|
117
123
|
* Gets the number of times the current task has been retried.
|