@hatchet-dev/typescript-sdk 0.8.0-alpha.2 → 0.8.0-alpha.3
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 +73 -11
- package/clients/admin/admin-client.js +92 -11
- package/clients/hatchet-client/hatchet-client.d.ts +1 -1
- package/clients/hatchet-client/hatchet-client.js +3 -3
- package/clients/worker/handler.d.ts +3 -1
- package/clients/worker/handler.js +43 -12
- package/clients/worker/worker.d.ts +5 -2
- package/clients/worker/worker.js +17 -11
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/workflows/workflows.js +1 -1
- package/step.d.ts +1 -1
- package/step.js +1 -1
- package/workflow.d.ts +12 -12
- package/workflow.js +1 -1
|
@@ -3,7 +3,7 @@ import { CreateWorkflowVersionOpts, RateLimitDuration, WorkflowServiceClient } f
|
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
5
|
import { Api } from '../rest';
|
|
6
|
-
import { WebhookWorkerCreateRequest, WorkflowRunStatus } from '../rest/generated/data-contracts';
|
|
6
|
+
import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
|
|
7
7
|
type WorkflowMetricsQuery = {
|
|
8
8
|
workflowId?: string;
|
|
9
9
|
workflowName?: string;
|
|
@@ -33,71 +33,133 @@ export declare class AdminClient {
|
|
|
33
33
|
tenantId: string;
|
|
34
34
|
logger: Logger;
|
|
35
35
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api, tenantId: string);
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated use putWorkflow instead
|
|
38
|
+
*/
|
|
39
|
+
put_workflow(opts: CreateWorkflowVersionOpts): Promise<void>;
|
|
36
40
|
/**
|
|
37
41
|
* Creates a new workflow or updates an existing workflow. If the workflow already exists, Hatchet will automatically
|
|
38
42
|
* determine if the workflow definition has changed and create a new version if necessary.
|
|
39
43
|
* @param workflow a workflow definition to create
|
|
40
44
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
putWorkflow(workflow: CreateWorkflowVersionOpts): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated use putRateLimit instead
|
|
48
|
+
*/
|
|
49
|
+
put_rate_limit(key: string, limit: number, duration: RateLimitDuration): Promise<void>;
|
|
50
|
+
putRateLimit(key: string, limit: number, duration?: RateLimitDuration): Promise<void>;
|
|
43
51
|
webhook_create(data: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WebhookWorker, any>>;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated use runWorkflow instead
|
|
54
|
+
*/
|
|
55
|
+
run_workflow<T = object>(workflowName: string, input: T, options?: {
|
|
56
|
+
parentId?: string | undefined;
|
|
57
|
+
parentStepRunId?: string | undefined;
|
|
58
|
+
childIndex?: number | undefined;
|
|
59
|
+
childKey?: string | undefined;
|
|
60
|
+
additionalMetadata?: Record<string, string> | undefined;
|
|
61
|
+
}): Promise<string>;
|
|
44
62
|
/**
|
|
45
63
|
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
46
64
|
* new run.
|
|
47
65
|
* @param workflowName the name of the workflow to run
|
|
48
66
|
* @param input an object containing the input to the workflow
|
|
67
|
+
* @param options an object containing the options to run the workflow
|
|
49
68
|
* @returns the ID of the new workflow run
|
|
50
69
|
*/
|
|
51
|
-
|
|
70
|
+
runWorkflow<T = object>(workflowName: string, input: T, options?: {
|
|
52
71
|
parentId?: string | undefined;
|
|
53
72
|
parentStepRunId?: string | undefined;
|
|
54
73
|
childIndex?: number | undefined;
|
|
55
74
|
childKey?: string | undefined;
|
|
56
75
|
additionalMetadata?: Record<string, string> | undefined;
|
|
57
76
|
}): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated use listWorkflows instead
|
|
79
|
+
*/
|
|
80
|
+
list_workflows(): Promise<import("../rest/generated/data-contracts").WorkflowList>;
|
|
58
81
|
/**
|
|
59
82
|
* List workflows in the tenant associated with the API token.
|
|
60
83
|
* @returns a list of all workflows in the tenant
|
|
61
84
|
*/
|
|
62
|
-
|
|
85
|
+
listWorkflows(): Promise<import("../rest/generated/data-contracts").WorkflowList>;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated use getWorkflow instead
|
|
88
|
+
*/
|
|
89
|
+
get_workflow(workflowId: string): Promise<import("../rest/generated/data-contracts").Workflow>;
|
|
63
90
|
/**
|
|
64
91
|
* Get a workflow by its ID.
|
|
65
92
|
* @param workflowId the workflow ID (**note:** this is not the same as the workflow version id)
|
|
66
93
|
* @returns
|
|
67
94
|
*/
|
|
68
|
-
|
|
95
|
+
getWorkflow(workflowId: string): Promise<import("../rest/generated/data-contracts").Workflow>;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated use getWorkflowVersion instead
|
|
98
|
+
*/
|
|
99
|
+
get_workflow_version(workflowId: string, version?: string): Promise<import("../rest/generated/data-contracts").WorkflowVersion>;
|
|
69
100
|
/**
|
|
70
101
|
* Get a workflow version.
|
|
71
102
|
* @param workflowId the workflow ID
|
|
72
103
|
* @param version the version of the workflow to get. If not provided, the latest version will be returned.
|
|
73
104
|
* @returns the workflow version
|
|
74
105
|
*/
|
|
75
|
-
|
|
106
|
+
getWorkflowVersion(workflowId: string, version?: string): Promise<import("../rest/generated/data-contracts").WorkflowVersion>;
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated use getWorkflowRun instead
|
|
109
|
+
*/
|
|
110
|
+
get_workflow_run(workflowRunId: string): Promise<import("../rest/generated/data-contracts").WorkflowRun>;
|
|
76
111
|
/**
|
|
77
112
|
* Get a workflow run.
|
|
78
113
|
* @param workflowRunId the id of the workflow run to get
|
|
79
114
|
* @returns the workflow run
|
|
80
115
|
*/
|
|
81
|
-
|
|
116
|
+
getWorkflowRun(workflowRunId: string): Promise<import("../rest/generated/data-contracts").WorkflowRun>;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated use listWorkflowRuns instead
|
|
119
|
+
*/
|
|
120
|
+
list_workflow_runs(query: {
|
|
121
|
+
offset?: number | undefined;
|
|
122
|
+
limit?: number | undefined;
|
|
123
|
+
eventId?: string | undefined;
|
|
124
|
+
workflowId?: string | undefined;
|
|
125
|
+
parentWorkflowRunId?: string | undefined;
|
|
126
|
+
parentStepRunId?: string | undefined;
|
|
127
|
+
statuses?: WorkflowRunStatusList | undefined;
|
|
128
|
+
additionalMetadata?: string[] | undefined;
|
|
129
|
+
}): Promise<import("../rest/generated/data-contracts").WorkflowRunList>;
|
|
82
130
|
/**
|
|
83
131
|
* List workflow runs in the tenant associated with the API token.
|
|
84
132
|
* @param query the query to filter the list of workflow runs
|
|
85
133
|
* @returns
|
|
86
134
|
*/
|
|
87
|
-
|
|
135
|
+
listWorkflowRuns(query: {
|
|
88
136
|
offset?: number | undefined;
|
|
89
137
|
limit?: number | undefined;
|
|
90
138
|
eventId?: string | undefined;
|
|
91
139
|
workflowId?: string | undefined;
|
|
140
|
+
parentWorkflowRunId?: string | undefined;
|
|
141
|
+
parentStepRunId?: string | undefined;
|
|
142
|
+
statuses?: WorkflowRunStatusList | undefined;
|
|
143
|
+
additionalMetadata?: string[] | undefined;
|
|
92
144
|
}): Promise<import("../rest/generated/data-contracts").WorkflowRunList>;
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated use scheduleWorkflow instead
|
|
147
|
+
*/
|
|
148
|
+
schedule_workflow(name: string, options?: {
|
|
149
|
+
schedules?: Date[];
|
|
150
|
+
}): Promise<void>;
|
|
93
151
|
/**
|
|
94
152
|
* Schedule a workflow to run at a specific time or times.
|
|
95
153
|
* @param name the name of the workflow to schedule
|
|
96
154
|
* @param options an object containing the schedules to set
|
|
97
155
|
*/
|
|
98
|
-
|
|
156
|
+
scheduleWorkflow(name: string, options?: {
|
|
99
157
|
schedules?: Date[];
|
|
100
158
|
}): void;
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated use getWorkflowMetrics instead
|
|
161
|
+
*/
|
|
162
|
+
get_workflow_metrics(data: WorkflowMetricsQuery): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WorkflowMetrics, any>>;
|
|
101
163
|
/**
|
|
102
164
|
* Get the metrics for a workflow.
|
|
103
165
|
*
|
|
@@ -105,6 +167,6 @@ export declare class AdminClient {
|
|
|
105
167
|
* @param workflowName the name of the workflow to get metrics for
|
|
106
168
|
* @param query an object containing query parameters to filter the metrics
|
|
107
169
|
*/
|
|
108
|
-
|
|
170
|
+
getWorkflowMetrics({ workflowId, workflowName, status, groupKey }: WorkflowMetricsQuery): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WorkflowMetrics, any>>;
|
|
109
171
|
}
|
|
110
172
|
export {};
|
|
@@ -41,12 +41,20 @@ class AdminClient {
|
|
|
41
41
|
this.tenantId = tenantId;
|
|
42
42
|
this.logger = new logger_1.Logger(`Admin`, config.log_level);
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated use putWorkflow instead
|
|
46
|
+
*/
|
|
47
|
+
put_workflow(opts) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this.putWorkflow(opts);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
44
52
|
/**
|
|
45
53
|
* Creates a new workflow or updates an existing workflow. If the workflow already exists, Hatchet will automatically
|
|
46
54
|
* determine if the workflow definition has changed and create a new version if necessary.
|
|
47
55
|
* @param workflow a workflow definition to create
|
|
48
56
|
*/
|
|
49
|
-
|
|
57
|
+
putWorkflow(workflow) {
|
|
50
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
59
|
try {
|
|
52
60
|
yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.putWorkflow({ opts: workflow }); }), this.logger);
|
|
@@ -56,7 +64,15 @@ class AdminClient {
|
|
|
56
64
|
}
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
|
-
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated use putRateLimit instead
|
|
69
|
+
*/
|
|
70
|
+
put_rate_limit(key, limit, duration) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return this.putRateLimit(key, limit, duration);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
putRateLimit(key_1, limit_1) {
|
|
60
76
|
return __awaiter(this, arguments, void 0, function* (key, limit, duration = workflows_1.RateLimitDuration.SECOND) {
|
|
61
77
|
try {
|
|
62
78
|
yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -77,14 +93,23 @@ class AdminClient {
|
|
|
77
93
|
return this.api.webhookCreate(this.tenantId, data);
|
|
78
94
|
});
|
|
79
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated use runWorkflow instead
|
|
98
|
+
*/
|
|
99
|
+
run_workflow(workflowName, input, options) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return this.runWorkflow(workflowName, input, options);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
80
104
|
/**
|
|
81
105
|
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
82
106
|
* new run.
|
|
83
107
|
* @param workflowName the name of the workflow to run
|
|
84
108
|
* @param input an object containing the input to the workflow
|
|
109
|
+
* @param options an object containing the options to run the workflow
|
|
85
110
|
* @returns the ID of the new workflow run
|
|
86
111
|
*/
|
|
87
|
-
|
|
112
|
+
runWorkflow(workflowName, input, options) {
|
|
88
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
114
|
let computedName = workflowName;
|
|
90
115
|
try {
|
|
@@ -102,34 +127,58 @@ class AdminClient {
|
|
|
102
127
|
}
|
|
103
128
|
});
|
|
104
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated use listWorkflows instead
|
|
132
|
+
*/
|
|
133
|
+
list_workflows() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
return this.listWorkflows();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
105
138
|
/**
|
|
106
139
|
* List workflows in the tenant associated with the API token.
|
|
107
140
|
* @returns a list of all workflows in the tenant
|
|
108
141
|
*/
|
|
109
|
-
|
|
142
|
+
listWorkflows() {
|
|
110
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
144
|
const res = yield this.api.workflowList(this.tenantId);
|
|
112
145
|
return res.data;
|
|
113
146
|
});
|
|
114
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated use getWorkflow instead
|
|
150
|
+
*/
|
|
151
|
+
get_workflow(workflowId) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
return this.getWorkflow(workflowId);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
115
156
|
/**
|
|
116
157
|
* Get a workflow by its ID.
|
|
117
158
|
* @param workflowId the workflow ID (**note:** this is not the same as the workflow version id)
|
|
118
159
|
* @returns
|
|
119
160
|
*/
|
|
120
|
-
|
|
161
|
+
getWorkflow(workflowId) {
|
|
121
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
163
|
const res = yield this.api.workflowGet(workflowId);
|
|
123
164
|
return res.data;
|
|
124
165
|
});
|
|
125
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated use getWorkflowVersion instead
|
|
169
|
+
*/
|
|
170
|
+
get_workflow_version(workflowId, version) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
return this.getWorkflowVersion(workflowId, version);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
126
175
|
/**
|
|
127
176
|
* Get a workflow version.
|
|
128
177
|
* @param workflowId the workflow ID
|
|
129
178
|
* @param version the version of the workflow to get. If not provided, the latest version will be returned.
|
|
130
179
|
* @returns the workflow version
|
|
131
180
|
*/
|
|
132
|
-
|
|
181
|
+
getWorkflowVersion(workflowId, version) {
|
|
133
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
183
|
const res = yield this.api.workflowVersionGet(workflowId, {
|
|
135
184
|
version,
|
|
@@ -137,34 +186,58 @@ class AdminClient {
|
|
|
137
186
|
return res.data;
|
|
138
187
|
});
|
|
139
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated use getWorkflowRun instead
|
|
191
|
+
*/
|
|
192
|
+
get_workflow_run(workflowRunId) {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
return this.getWorkflowRun(workflowRunId);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
140
197
|
/**
|
|
141
198
|
* Get a workflow run.
|
|
142
199
|
* @param workflowRunId the id of the workflow run to get
|
|
143
200
|
* @returns the workflow run
|
|
144
201
|
*/
|
|
145
|
-
|
|
202
|
+
getWorkflowRun(workflowRunId) {
|
|
146
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
204
|
const res = yield this.api.workflowRunGet(this.tenantId, workflowRunId);
|
|
148
205
|
return res.data;
|
|
149
206
|
});
|
|
150
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* @deprecated use listWorkflowRuns instead
|
|
210
|
+
*/
|
|
211
|
+
list_workflow_runs(query) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
return this.listWorkflowRuns(query);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
151
216
|
/**
|
|
152
217
|
* List workflow runs in the tenant associated with the API token.
|
|
153
218
|
* @param query the query to filter the list of workflow runs
|
|
154
219
|
* @returns
|
|
155
220
|
*/
|
|
156
|
-
|
|
221
|
+
listWorkflowRuns(query) {
|
|
157
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
223
|
const res = yield this.api.workflowRunList(this.tenantId, query);
|
|
159
224
|
return res.data;
|
|
160
225
|
});
|
|
161
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* @deprecated use scheduleWorkflow instead
|
|
229
|
+
*/
|
|
230
|
+
schedule_workflow(name, options) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return this.scheduleWorkflow(name, options);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
162
235
|
/**
|
|
163
236
|
* Schedule a workflow to run at a specific time or times.
|
|
164
237
|
* @param name the name of the workflow to schedule
|
|
165
238
|
* @param options an object containing the schedules to set
|
|
166
239
|
*/
|
|
167
|
-
|
|
240
|
+
scheduleWorkflow(name, options) {
|
|
168
241
|
try {
|
|
169
242
|
this.client.scheduleWorkflow({
|
|
170
243
|
name,
|
|
@@ -175,6 +248,14 @@ class AdminClient {
|
|
|
175
248
|
throw new hatchet_error_1.default(e.message);
|
|
176
249
|
}
|
|
177
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* @deprecated use getWorkflowMetrics instead
|
|
253
|
+
*/
|
|
254
|
+
get_workflow_metrics(data) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
return this.getWorkflowMetrics(data);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
178
259
|
/**
|
|
179
260
|
* Get the metrics for a workflow.
|
|
180
261
|
*
|
|
@@ -182,13 +263,13 @@ class AdminClient {
|
|
|
182
263
|
* @param workflowName the name of the workflow to get metrics for
|
|
183
264
|
* @param query an object containing query parameters to filter the metrics
|
|
184
265
|
*/
|
|
185
|
-
|
|
266
|
+
getWorkflowMetrics({ workflowId, workflowName, status, groupKey }) {
|
|
186
267
|
const params = {
|
|
187
268
|
status,
|
|
188
269
|
groupKey,
|
|
189
270
|
};
|
|
190
271
|
if (workflowName) {
|
|
191
|
-
this.
|
|
272
|
+
this.listWorkflows().then((res) => {
|
|
192
273
|
var _a;
|
|
193
274
|
const workflow = (_a = res.rows) === null || _a === void 0 ? void 0 : _a.find((row) => row.name === workflowName);
|
|
194
275
|
if (workflow) {
|
|
@@ -29,5 +29,5 @@ export declare class HatchetClient {
|
|
|
29
29
|
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
|
|
30
30
|
run(workflow: string | Workflow): Promise<Worker>;
|
|
31
31
|
worker(workflow: string | Workflow, maxRuns?: number): Promise<Worker>;
|
|
32
|
-
webhooks(
|
|
32
|
+
webhooks(workflows: Workflow[]): import("../worker/handler").WebhookHandler;
|
|
33
33
|
}
|
|
@@ -142,11 +142,11 @@ class HatchetClient {
|
|
|
142
142
|
return worker;
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
webhooks(
|
|
145
|
+
webhooks(workflows) {
|
|
146
146
|
const worker = new worker_1.Worker(this, {
|
|
147
|
-
name:
|
|
147
|
+
name: 'webhook-worker',
|
|
148
148
|
});
|
|
149
|
-
return worker.getHandler(
|
|
149
|
+
return worker.getHandler(workflows);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
exports.HatchetClient = HatchetClient;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { Workflow } from '../../workflow';
|
|
3
4
|
import { Worker } from './worker';
|
|
4
5
|
export interface HandlerOpts {
|
|
5
6
|
secret: string;
|
|
6
7
|
}
|
|
7
8
|
export declare class WebhookHandler {
|
|
8
9
|
private worker;
|
|
9
|
-
|
|
10
|
+
private workflows;
|
|
11
|
+
constructor(worker: Worker, workflows: Workflow[]);
|
|
10
12
|
/**
|
|
11
13
|
* Handles a request with a provided body, secret, and signature.
|
|
12
14
|
*
|
|
@@ -17,9 +17,12 @@ const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error
|
|
|
17
17
|
const crypto_1 = require("crypto");
|
|
18
18
|
const action_listener_1 = require("../dispatcher/action-listener");
|
|
19
19
|
class WebhookHandler {
|
|
20
|
-
// eslint-disable-next-line no-useless-constructor
|
|
21
|
-
constructor(worker
|
|
20
|
+
// eslint-disable-next-line no-useless-constructor
|
|
21
|
+
constructor(worker, workflows
|
|
22
|
+
// eslint-disable-next-line no-empty-function
|
|
23
|
+
) {
|
|
22
24
|
this.worker = worker;
|
|
25
|
+
this.workflows = workflows;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Handles a request with a provided body, secret, and signature.
|
|
@@ -53,9 +56,14 @@ class WebhookHandler {
|
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
58
|
getHealthcheckResponse() {
|
|
56
|
-
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
for (const workflow of this.workflows) {
|
|
61
|
+
yield this.worker.registerWorkflow(workflow);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
actions: Object.keys(this.worker.action_registry),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
61
69
|
* Express Handler
|
|
@@ -72,7 +80,7 @@ class WebhookHandler {
|
|
|
72
80
|
return (req, res) => {
|
|
73
81
|
if (req.method === 'GET') {
|
|
74
82
|
res.sendStatus(200);
|
|
75
|
-
res.
|
|
83
|
+
res.send('OK!');
|
|
76
84
|
return;
|
|
77
85
|
}
|
|
78
86
|
if (req.method !== 'POST') {
|
|
@@ -80,13 +88,25 @@ class WebhookHandler {
|
|
|
80
88
|
res.json({ error: 'Method not allowed' });
|
|
81
89
|
return;
|
|
82
90
|
}
|
|
91
|
+
if (req.headers['x-healthcheck']) {
|
|
92
|
+
this.getHealthcheckResponse()
|
|
93
|
+
.then((resp) => {
|
|
94
|
+
res.sendStatus(200);
|
|
95
|
+
res.json(resp);
|
|
96
|
+
})
|
|
97
|
+
.catch((err) => {
|
|
98
|
+
res.sendStatus(500);
|
|
99
|
+
this.worker.logger.error(`Error handling request: ${err.message}`);
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
83
103
|
this.handle(req.body, req.headers['x-hatchet-signature'], secret)
|
|
84
104
|
.then(() => {
|
|
85
105
|
res.sendStatus(200);
|
|
86
106
|
})
|
|
87
|
-
.catch((
|
|
107
|
+
.catch((err) => {
|
|
88
108
|
res.sendStatus(500);
|
|
89
|
-
this.worker.logger.error(`Error handling request: ${
|
|
109
|
+
this.worker.logger.error(`Error handling request: ${err.message}`);
|
|
90
110
|
});
|
|
91
111
|
};
|
|
92
112
|
}
|
|
@@ -102,7 +122,7 @@ class WebhookHandler {
|
|
|
102
122
|
const handle = () => __awaiter(this, void 0, void 0, function* () {
|
|
103
123
|
if (req.method === 'GET') {
|
|
104
124
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
105
|
-
res.write(
|
|
125
|
+
res.write('OK!');
|
|
106
126
|
res.end();
|
|
107
127
|
return;
|
|
108
128
|
}
|
|
@@ -112,6 +132,13 @@ class WebhookHandler {
|
|
|
112
132
|
res.end();
|
|
113
133
|
return;
|
|
114
134
|
}
|
|
135
|
+
if (req.headers['x-healthcheck']) {
|
|
136
|
+
const resp = yield this.getHealthcheckResponse();
|
|
137
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
138
|
+
res.write(JSON.stringify(resp));
|
|
139
|
+
res.end();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
115
142
|
const body = yield this.getBody(req);
|
|
116
143
|
yield this.handle(body, secret, req.headers['x-hatchet-signature']);
|
|
117
144
|
res.writeHead(200, 'OK');
|
|
@@ -132,15 +159,19 @@ class WebhookHandler {
|
|
|
132
159
|
* @return {Promise<Response>} - A Promise that resolves with a Response object.
|
|
133
160
|
*/
|
|
134
161
|
nextJSHandler({ secret }) {
|
|
135
|
-
const
|
|
136
|
-
return new Response(
|
|
162
|
+
const ok = () => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
return new Response('OK!', { status: 200 });
|
|
137
164
|
});
|
|
138
165
|
const f = (req) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
if (req.headers.get('x-healthcheck')) {
|
|
167
|
+
const resp = yield this.getHealthcheckResponse();
|
|
168
|
+
return new Response(JSON.stringify(resp), { status: 200 });
|
|
169
|
+
}
|
|
139
170
|
yield this.handle(yield req.text(), secret, req.headers.get('x-hatchet-signature'));
|
|
140
171
|
return new Response('ok', { status: 200 });
|
|
141
172
|
});
|
|
142
173
|
return {
|
|
143
|
-
GET:
|
|
174
|
+
GET: ok,
|
|
144
175
|
POST: f,
|
|
145
176
|
PUT: f,
|
|
146
177
|
};
|
|
@@ -27,10 +27,13 @@ export declare class Worker {
|
|
|
27
27
|
maxRuns?: number;
|
|
28
28
|
});
|
|
29
29
|
private registerActions;
|
|
30
|
-
getHandler(
|
|
30
|
+
getHandler(workflows: Workflow[]): WebhookHandler;
|
|
31
31
|
registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WebhookWorker, any>>;
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated use registerWorkflow instead
|
|
34
|
+
*/
|
|
33
35
|
register_workflow(initWorkflow: Workflow): Promise<void>;
|
|
36
|
+
registerWorkflow(initWorkflow: Workflow): Promise<void>;
|
|
34
37
|
registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
|
|
35
38
|
handleStartStepRun(action: Action): Promise<void>;
|
|
36
39
|
handleStartGroupKeyRun(action: Action): Promise<void>;
|
package/clients/worker/worker.js
CHANGED
|
@@ -58,23 +58,27 @@ class Worker {
|
|
|
58
58
|
this.action_registry = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
59
59
|
? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
|
|
60
60
|
}
|
|
61
|
-
getHandler(
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
getHandler(workflows) {
|
|
62
|
+
for (const workflow of workflows) {
|
|
63
|
+
const wf = Object.assign(Object.assign({}, workflow), { id: this.client.config.namespace + workflow.id });
|
|
64
|
+
this.registerActions(wf);
|
|
65
|
+
}
|
|
66
|
+
return new handler_1.WebhookHandler(this, workflows);
|
|
65
67
|
}
|
|
66
68
|
registerWebhook(webhook) {
|
|
67
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
70
|
return this.client.admin.webhook_create(Object.assign(Object.assign({}, webhook), { workflows: this.registeredWorkflowIds }));
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated use registerWorkflow instead
|
|
75
|
+
*/
|
|
76
|
+
register_workflow(initWorkflow) {
|
|
73
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return this.
|
|
78
|
+
return this.registerWorkflow(initWorkflow);
|
|
75
79
|
});
|
|
76
80
|
}
|
|
77
|
-
|
|
81
|
+
registerWorkflow(initWorkflow) {
|
|
78
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
83
|
var _a, _b;
|
|
80
84
|
const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
|
|
@@ -105,12 +109,14 @@ class Worker {
|
|
|
105
109
|
}
|
|
106
110
|
: undefined;
|
|
107
111
|
this.registeredWorkflowIds.push(workflow.id);
|
|
108
|
-
const registeredWorkflow = this.client.admin.
|
|
112
|
+
const registeredWorkflow = this.client.admin.putWorkflow({
|
|
109
113
|
name: workflow.id,
|
|
110
114
|
description: workflow.description,
|
|
111
115
|
version: workflow.version || '',
|
|
112
|
-
eventTriggers: workflow.on
|
|
113
|
-
|
|
116
|
+
eventTriggers: workflow.on && workflow.on.event
|
|
117
|
+
? [this.client.config.namespace + workflow.on.event]
|
|
118
|
+
: [],
|
|
119
|
+
cronTriggers: workflow.on && workflow.on.cron ? [workflow.on.cron] : [],
|
|
114
120
|
scheduledTriggers: [],
|
|
115
121
|
concurrency,
|
|
116
122
|
scheduleTimeout: workflow.scheduleTimeout,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: dispatcher/dispatcher.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
package/protoc/events/events.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: events/events.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: google/protobuf/timestamp.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v1.
|
|
4
|
+
// protoc-gen-ts_proto v1.180.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: workflows/workflows.proto
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
package/step.d.ts
CHANGED
package/step.js
CHANGED
|
@@ -229,7 +229,7 @@ class Context {
|
|
|
229
229
|
spawnWorkflow(workflowName, input, key) {
|
|
230
230
|
const { workflowRunId, stepRunId } = this.action;
|
|
231
231
|
const name = this.client.config.namespace + workflowName;
|
|
232
|
-
const childWorkflowRunIdPromise = this.client.admin.
|
|
232
|
+
const childWorkflowRunIdPromise = this.client.admin.runWorkflow(name, input, {
|
|
233
233
|
parentId: workflowRunId,
|
|
234
234
|
parentStepRunId: stepRunId,
|
|
235
235
|
childKey: key,
|
package/workflow.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
60
60
|
* @deprecated Workflow timeout is deprecated. Use step timeouts instead.
|
|
61
61
|
*/
|
|
62
62
|
timeout: z.ZodOptional<z.ZodString>;
|
|
63
|
-
on: z.ZodUnion<[z.ZodObject<{
|
|
63
|
+
on: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
64
64
|
cron: z.ZodString;
|
|
65
65
|
event: z.ZodUndefined;
|
|
66
66
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -78,7 +78,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
78
78
|
}, {
|
|
79
79
|
event: string;
|
|
80
80
|
cron?: undefined;
|
|
81
|
-
}>]
|
|
81
|
+
}>]>>;
|
|
82
82
|
steps: z.ZodArray<z.ZodObject<{
|
|
83
83
|
name: z.ZodString;
|
|
84
84
|
parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -160,16 +160,16 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
160
160
|
}[] | undefined;
|
|
161
161
|
}[];
|
|
162
162
|
id: string;
|
|
163
|
-
|
|
163
|
+
version?: string | undefined;
|
|
164
|
+
scheduleTimeout?: string | undefined;
|
|
165
|
+
timeout?: string | undefined;
|
|
166
|
+
on?: {
|
|
164
167
|
cron: string;
|
|
165
168
|
event?: undefined;
|
|
166
169
|
} | {
|
|
167
170
|
event: string;
|
|
168
171
|
cron?: undefined;
|
|
169
|
-
};
|
|
170
|
-
version?: string | undefined;
|
|
171
|
-
scheduleTimeout?: string | undefined;
|
|
172
|
-
timeout?: string | undefined;
|
|
172
|
+
} | undefined;
|
|
173
173
|
onFailure?: {
|
|
174
174
|
name: string;
|
|
175
175
|
timeout?: string | undefined;
|
|
@@ -193,16 +193,16 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
|
193
193
|
}[] | undefined;
|
|
194
194
|
}[];
|
|
195
195
|
id: string;
|
|
196
|
-
|
|
196
|
+
version?: string | undefined;
|
|
197
|
+
scheduleTimeout?: string | undefined;
|
|
198
|
+
timeout?: string | undefined;
|
|
199
|
+
on?: {
|
|
197
200
|
cron: string;
|
|
198
201
|
event?: undefined;
|
|
199
202
|
} | {
|
|
200
203
|
event: string;
|
|
201
204
|
cron?: undefined;
|
|
202
|
-
};
|
|
203
|
-
version?: string | undefined;
|
|
204
|
-
scheduleTimeout?: string | undefined;
|
|
205
|
-
timeout?: string | undefined;
|
|
205
|
+
} | undefined;
|
|
206
206
|
onFailure?: {
|
|
207
207
|
name: string;
|
|
208
208
|
timeout?: string | undefined;
|
package/workflow.js
CHANGED
|
@@ -35,7 +35,7 @@ const EventConfigSchema = z.object({
|
|
|
35
35
|
cron: z.undefined(),
|
|
36
36
|
event: z.string(),
|
|
37
37
|
});
|
|
38
|
-
const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]);
|
|
38
|
+
const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]).optional();
|
|
39
39
|
const StepsSchema = z.array(step_1.CreateStepSchema);
|
|
40
40
|
exports.ConcurrencyLimitStrategy = workflows_1.ConcurrencyLimitStrategy;
|
|
41
41
|
exports.WorkflowConcurrency = z.object({
|