@tachybase/module-workflow 1.5.1 → 1.6.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/dist/client/WorkflowCategoriesProvider.d.ts +4 -0
- package/dist/client/components/ColletionTreeSelect.d.ts +16 -0
- package/dist/client/components/EnabledStatusFilter.d.ts +2 -0
- package/dist/client/components/WorkflowCategoryColumn.d.ts +8 -0
- package/dist/client/components/index.d.ts +3 -0
- package/dist/client/features/script/Script.instruction.d.ts +136 -0
- package/dist/client/features/script/ScriptCodeEditor.d.ts +9 -0
- package/dist/client/features/script/SyncRemoteCodeButton.d.ts +6 -0
- package/dist/client/features/trigger-instruction/TriggerInstruction.d.ts +164 -5
- package/dist/client/hooks/index.d.ts +2 -0
- package/dist/client/hooks/useDumpAction.d.ts +7 -0
- package/dist/client/hooks/useRevisionAction.d.ts +7 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +85 -59
- package/dist/client/nodes/select.d.ts +235 -0
- package/dist/client/schemas/workflows.d.ts +5 -0
- package/dist/client/utils.d.ts +2 -2
- package/dist/externalVersion.js +9 -9
- package/dist/locale/en-US.json +49 -1
- package/dist/locale/es-ES.json +19 -1
- package/dist/locale/fr-FR.json +18 -0
- package/dist/locale/ja-JP.json +19 -1
- package/dist/locale/ko_KR.json +19 -1
- package/dist/locale/pt-BR.json +19 -1
- package/dist/locale/ru-RU.json +20 -2
- package/dist/locale/tr-TR.json +20 -2
- package/dist/locale/zh-CN.json +52 -1
- package/dist/node_modules/@babel/core/lib/index.js +77 -77
- package/dist/node_modules/@babel/core/node_modules/.bin/parser +4 -4
- package/dist/node_modules/@babel/core/package.json +1 -1
- package/dist/node_modules/@babel/preset-env/lib/index.js +88 -88
- package/dist/node_modules/@babel/preset-env/package.json +1 -1
- package/dist/node_modules/@babel/preset-react/lib/index.js +80 -80
- package/dist/node_modules/@babel/preset-react/package.json +1 -1
- package/dist/node_modules/@babel/preset-typescript/lib/index.js +77 -77
- package/dist/node_modules/@babel/preset-typescript/package.json +1 -1
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/form-data/package.json +1 -1
- package/dist/node_modules/jsonata/package.json +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/node_modules/qrcode/package.json +1 -1
- package/dist/server/Plugin.js +57 -1
- package/dist/server/actions/executions.d.ts +3 -3
- package/dist/server/actions/executions.js +42 -30
- package/dist/server/actions/index.js +3 -2
- package/dist/server/actions/nodes.d.ts +13 -6
- package/dist/server/actions/nodes.js +160 -34
- package/dist/server/actions/workflows.d.ts +17 -8
- package/dist/server/actions/workflows.helpers.d.ts +55 -0
- package/dist/server/actions/workflows.helpers.js +167 -0
- package/dist/server/actions/workflows.js +118 -69
- package/dist/server/features/interception/RequestInterceptionTrigger.d.ts +1 -1
- package/dist/server/features/interception/RequestInterceptionTrigger.js +12 -12
- package/dist/server/features/manual/actions.d.ts +1 -1
- package/dist/server/features/manual/actions.js +12 -12
- package/dist/server/features/notice/actions.js +19 -19
- package/dist/server/features/notice/plugin.js +0 -3
- package/dist/server/features/omni-trigger/CustomActionTrigger.d.ts +2 -2
- package/dist/server/features/omni-trigger/CustomActionTrigger.js +27 -27
- package/dist/server/features/script/script.instruction.js +146 -4
- package/dist/server/features/trigger-instruction/TriggerInstruction.d.ts +4 -0
- package/dist/server/features/trigger-instruction/TriggerInstruction.js +71 -5
- package/dist/server/instructions/SelectInstruction.d.ts +13 -0
- package/dist/server/instructions/SelectInstruction.js +126 -0
- package/dist/server/services/remote-code-fetcher.d.ts +48 -0
- package/dist/server/services/remote-code-fetcher.js +370 -0
- package/dist/server/utils/get-remote-code-fetcher.d.ts +7 -0
- package/dist/server/utils/get-remote-code-fetcher.js +39 -0
- package/dist/server/utils.d.ts +16 -0
- package/dist/server/utils.js +33 -2
- package/package.json +12 -12
- package/dist/client/provider/EventSourceProvider.d.ts +0 -7
- package/dist/server/features/trigger-instruction/index.d.ts +0 -0
- package/dist/server/features/trigger-instruction/index.js +0 -0
|
@@ -29,6 +29,7 @@ var workflows_exports = {};
|
|
|
29
29
|
__export(workflows_exports, {
|
|
30
30
|
destroy: () => destroy,
|
|
31
31
|
dump: () => dump,
|
|
32
|
+
listExtended: () => listExtended,
|
|
32
33
|
load: () => load,
|
|
33
34
|
moveWorkflow: () => moveWorkflow,
|
|
34
35
|
retry: () => retry,
|
|
@@ -41,10 +42,32 @@ __export(workflows_exports, {
|
|
|
41
42
|
module.exports = __toCommonJS(workflows_exports);
|
|
42
43
|
var import_server = require("@tego/server");
|
|
43
44
|
var import_Plugin = __toESM(require("../Plugin"));
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
var import_utils = require("../utils");
|
|
46
|
+
var import_workflows = require("./workflows.helpers");
|
|
47
|
+
async function listExtended(ctx, next) {
|
|
48
|
+
var _a;
|
|
49
|
+
await import_server.actions.list(ctx, next);
|
|
50
|
+
if (((_a = ctx.body) == null ? void 0 : _a.rows) && Array.isArray(ctx.body.rows) && ctx.body.rows.length > 0) {
|
|
51
|
+
const workflows = ctx.body.rows;
|
|
52
|
+
for (let index = 0; index < workflows.length; index++) {
|
|
53
|
+
const workflow = workflows[index];
|
|
54
|
+
const row = ctx.body.rows[index];
|
|
55
|
+
if (!row) continue;
|
|
56
|
+
const workflowData = (0, import_workflows.getWorkflowData)(workflow);
|
|
57
|
+
const executedTime = await (0, import_workflows.getLatestExecutedTimeForWorkflow)(ctx, workflowData == null ? void 0 : workflowData.id, workflowData == null ? void 0 : workflowData.key);
|
|
58
|
+
(0, import_workflows.setLatestExecutedTime)(row, executedTime);
|
|
59
|
+
const eventSourceName = await (0, import_workflows.getEventSourceNameForWorkflow)(ctx, workflowData == null ? void 0 : workflowData.key);
|
|
60
|
+
(0, import_workflows.setEventSourceName)(row, eventSourceName);
|
|
61
|
+
const categories = await (0, import_workflows.getCategoriesForWorkflow)(ctx, workflow, workflowData == null ? void 0 : workflowData.key);
|
|
62
|
+
(0, import_workflows.setCategories)(row, categories);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return ctx;
|
|
66
|
+
}
|
|
67
|
+
async function update(ctx, next) {
|
|
68
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
69
|
+
const { filterByTk, values } = ctx.action.params;
|
|
70
|
+
ctx.action.mergeParams({
|
|
48
71
|
whitelist: [
|
|
49
72
|
"title",
|
|
50
73
|
"description",
|
|
@@ -63,15 +86,15 @@ async function update(context, next) {
|
|
|
63
86
|
if (Object.keys(values).includes("config")) {
|
|
64
87
|
const workflow = await repository.findById(filterByTk);
|
|
65
88
|
if (workflow.get("executed")) {
|
|
66
|
-
return
|
|
89
|
+
return ctx.throw(400, "config of executed workflow can not be updated");
|
|
67
90
|
}
|
|
68
91
|
}
|
|
69
|
-
return import_server.actions.update(
|
|
92
|
+
return import_server.actions.update(ctx, next);
|
|
70
93
|
}
|
|
71
|
-
async function destroy(
|
|
72
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
73
|
-
const { filterByTk, filter } =
|
|
74
|
-
await
|
|
94
|
+
async function destroy(ctx, next) {
|
|
95
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
96
|
+
const { filterByTk, filter } = ctx.action.params;
|
|
97
|
+
await ctx.db.sequelize.transaction(async (transaction) => {
|
|
75
98
|
const items = await repository.find({
|
|
76
99
|
filterByTk,
|
|
77
100
|
filter,
|
|
@@ -89,7 +112,7 @@ async function destroy(context, next) {
|
|
|
89
112
|
transaction
|
|
90
113
|
});
|
|
91
114
|
revisions.forEach((item) => ids.add(item.id));
|
|
92
|
-
|
|
115
|
+
ctx.body = await repository.destroy({
|
|
93
116
|
filterByTk: Array.from(ids),
|
|
94
117
|
individualHooks: true,
|
|
95
118
|
transaction
|
|
@@ -97,15 +120,15 @@ async function destroy(context, next) {
|
|
|
97
120
|
});
|
|
98
121
|
next();
|
|
99
122
|
}
|
|
100
|
-
async function dump(
|
|
101
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
102
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
103
|
-
|
|
123
|
+
async function dump(ctx, next) {
|
|
124
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
125
|
+
const { filterByTk, filter = {}, values = {} } = ctx.action.params;
|
|
126
|
+
ctx.body = await ctx.db.sequelize.transaction(async (transaction) => {
|
|
104
127
|
const origin = await repository.findOne({
|
|
105
128
|
filterByTk,
|
|
106
129
|
filter,
|
|
107
130
|
appends: ["nodes"],
|
|
108
|
-
context,
|
|
131
|
+
context: ctx,
|
|
109
132
|
transaction
|
|
110
133
|
});
|
|
111
134
|
const revisionData = filter.key ? {
|
|
@@ -124,11 +147,11 @@ async function dump(context, next) {
|
|
|
124
147
|
});
|
|
125
148
|
await next();
|
|
126
149
|
}
|
|
127
|
-
async function load(
|
|
128
|
-
const plugin =
|
|
129
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
130
|
-
const { values = {} } =
|
|
131
|
-
|
|
150
|
+
async function load(ctx, next) {
|
|
151
|
+
const plugin = ctx.tego.pm.get(import_Plugin.default);
|
|
152
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
153
|
+
const { values = {} } = ctx.action.params;
|
|
154
|
+
ctx.body = await ctx.db.sequelize.transaction(async (transaction) => {
|
|
132
155
|
const origin = values.workflow;
|
|
133
156
|
const trigger2 = plugin.triggers.get(origin.type);
|
|
134
157
|
const instance = await repository.create({
|
|
@@ -181,47 +204,58 @@ async function load(context, next) {
|
|
|
181
204
|
});
|
|
182
205
|
await next();
|
|
183
206
|
}
|
|
184
|
-
async function test(
|
|
207
|
+
async function test(ctx, next) {
|
|
185
208
|
var _a;
|
|
186
|
-
const plugin =
|
|
187
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
188
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
189
|
-
if (!
|
|
190
|
-
|
|
209
|
+
const plugin = ctx.tego.pm.get(import_Plugin.default);
|
|
210
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
211
|
+
const { filterByTk, filter = {}, values = {} } = ctx.action.params;
|
|
212
|
+
if (!ctx.state) {
|
|
213
|
+
ctx.state = {};
|
|
191
214
|
}
|
|
192
|
-
if (!
|
|
193
|
-
|
|
215
|
+
if (!ctx.state.messages) {
|
|
216
|
+
ctx.state.messages = [];
|
|
194
217
|
}
|
|
195
218
|
const workflow = await repository.findOne({
|
|
196
219
|
filterByTk,
|
|
197
220
|
filter,
|
|
198
221
|
appends: ["nodes"],
|
|
199
|
-
context
|
|
222
|
+
context: ctx
|
|
200
223
|
});
|
|
201
|
-
|
|
224
|
+
if (!workflow) {
|
|
225
|
+
return ctx.throw(404, "Workflow not found");
|
|
226
|
+
}
|
|
227
|
+
const execution = await (0, import_utils.triggerWorkflowAndGetExecution)(
|
|
228
|
+
plugin,
|
|
202
229
|
workflow,
|
|
203
230
|
{
|
|
204
231
|
data: values.data || {},
|
|
205
|
-
user: ((_a =
|
|
232
|
+
user: ((_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) || {}
|
|
206
233
|
},
|
|
207
|
-
{ httpContext:
|
|
234
|
+
{ httpContext: ctx, transaction: ctx.transaction },
|
|
235
|
+
ctx.db
|
|
208
236
|
);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
237
|
+
if (!execution) {
|
|
238
|
+
ctx.state.messages.push({
|
|
239
|
+
message: ctx.t("Failed to create execution", { ns: "workflow" })
|
|
240
|
+
});
|
|
241
|
+
return ctx.throw(500, "Failed to create execution");
|
|
242
|
+
}
|
|
243
|
+
ctx.state.messages.push({
|
|
244
|
+
message: ctx.t("Test execution ended", { ns: "workflow" })
|
|
212
245
|
});
|
|
213
|
-
|
|
246
|
+
ctx.body = execution;
|
|
247
|
+
await next();
|
|
214
248
|
}
|
|
215
|
-
async function revision(
|
|
216
|
-
const plugin =
|
|
217
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
218
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
219
|
-
|
|
249
|
+
async function revision(ctx, next) {
|
|
250
|
+
const plugin = ctx.tego.pm.get(import_Plugin.default);
|
|
251
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
252
|
+
const { filterByTk, filter = {}, values = {} } = ctx.action.params;
|
|
253
|
+
ctx.body = await ctx.db.sequelize.transaction(async (transaction) => {
|
|
220
254
|
const origin = await repository.findOne({
|
|
221
255
|
filterByTk,
|
|
222
256
|
filter,
|
|
223
257
|
appends: ["nodes"],
|
|
224
|
-
context,
|
|
258
|
+
context: ctx,
|
|
225
259
|
transaction
|
|
226
260
|
});
|
|
227
261
|
const trigger2 = plugin.triggers.get(origin.type);
|
|
@@ -281,53 +315,67 @@ async function revision(context, next) {
|
|
|
281
315
|
});
|
|
282
316
|
await next();
|
|
283
317
|
}
|
|
284
|
-
async function retry(
|
|
285
|
-
const plugin =
|
|
286
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
287
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
288
|
-
const ExecutionRepo =
|
|
289
|
-
if (!
|
|
290
|
-
|
|
318
|
+
async function retry(ctx, next) {
|
|
319
|
+
const plugin = ctx.tego.pm.get(import_Plugin.default);
|
|
320
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
321
|
+
const { filterByTk, filter = {}, values = {} } = ctx.action.params;
|
|
322
|
+
const ExecutionRepo = ctx.db.getRepository("executions");
|
|
323
|
+
if (!ctx.state) {
|
|
324
|
+
ctx.state = {};
|
|
291
325
|
}
|
|
292
|
-
if (!
|
|
293
|
-
|
|
326
|
+
if (!ctx.state.messages) {
|
|
327
|
+
ctx.state.messages = [];
|
|
294
328
|
}
|
|
295
329
|
const workflow = await repository.findOne({
|
|
296
330
|
filterByTk,
|
|
297
331
|
filter,
|
|
298
332
|
appends: ["nodes"],
|
|
299
|
-
context
|
|
333
|
+
context: ctx
|
|
300
334
|
});
|
|
301
335
|
const execution = await ExecutionRepo.findOne({
|
|
302
336
|
filter: { key: workflow.key },
|
|
303
337
|
sort: ["-createdAt"]
|
|
304
338
|
});
|
|
305
339
|
if (!execution) {
|
|
306
|
-
|
|
307
|
-
message:
|
|
340
|
+
ctx.state.messages.push({
|
|
341
|
+
message: ctx.t("No execution records found for this workflow.", { ns: "workflow" })
|
|
308
342
|
});
|
|
309
343
|
}
|
|
310
344
|
try {
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
345
|
+
const newExecution = await (0, import_utils.triggerWorkflowAndGetExecution)(
|
|
346
|
+
plugin,
|
|
347
|
+
workflow,
|
|
348
|
+
execution.context,
|
|
349
|
+
{ httpContext: ctx, transaction: ctx.transaction },
|
|
350
|
+
ctx.db
|
|
351
|
+
);
|
|
352
|
+
if (!newExecution) {
|
|
353
|
+
ctx.state.messages.push({
|
|
354
|
+
message: ctx.t("Failed to create execution", { ns: "workflow" })
|
|
355
|
+
});
|
|
356
|
+
ctx.body = {
|
|
357
|
+
error: ctx.t("Failed to create execution", { ns: "workflow" })
|
|
358
|
+
};
|
|
359
|
+
return await next();
|
|
360
|
+
}
|
|
361
|
+
ctx.state.messages.push({ message: ctx.t("Execute ended", { ns: "workflow" }) });
|
|
362
|
+
ctx.body = newExecution;
|
|
315
363
|
} catch (error) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
message:
|
|
364
|
+
ctx.tego.logger.error(`Failed to retry execution ${execution.id}: ${error.message}`);
|
|
365
|
+
ctx.state.messages.push({
|
|
366
|
+
message: ctx.t("Failed to retry execution", { ns: "workflow" }),
|
|
319
367
|
error: error.message
|
|
320
368
|
});
|
|
321
|
-
|
|
369
|
+
ctx.body = {
|
|
322
370
|
error: error.message
|
|
323
371
|
};
|
|
324
372
|
}
|
|
325
373
|
await next();
|
|
326
374
|
}
|
|
327
|
-
async function sync(
|
|
328
|
-
const plugin =
|
|
329
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
330
|
-
const { filterByTk, filter = {} } =
|
|
375
|
+
async function sync(ctx, next) {
|
|
376
|
+
const plugin = ctx.tego.pm.get(import_Plugin.default);
|
|
377
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
378
|
+
const { filterByTk, filter = {} } = ctx.action.params;
|
|
331
379
|
const workflows = await repository.find({
|
|
332
380
|
filterByTk,
|
|
333
381
|
filter
|
|
@@ -336,13 +384,13 @@ async function sync(context, next) {
|
|
|
336
384
|
plugin.toggle(workflow, false);
|
|
337
385
|
plugin.toggle(workflow);
|
|
338
386
|
});
|
|
339
|
-
|
|
387
|
+
ctx.status = 204;
|
|
340
388
|
await next();
|
|
341
389
|
}
|
|
342
390
|
async function trigger(ctx, next) {
|
|
343
391
|
var _a, _b;
|
|
344
392
|
if (!ctx.action.params.triggerWorkflows) {
|
|
345
|
-
const plugin = ctx.
|
|
393
|
+
const plugin = ctx.tego.getPlugin(import_Plugin.default);
|
|
346
394
|
const workflow = await ctx.db.getRepository("workflows").findById(ctx.action.params.filterByTk);
|
|
347
395
|
const updateData = JSON.parse(decodeURIComponent(((_a = ctx.action.params) == null ? void 0 : _a.updateData) || ""));
|
|
348
396
|
plugin.trigger(
|
|
@@ -428,6 +476,7 @@ async function moveWorkflow(ctx, next) {
|
|
|
428
476
|
0 && (module.exports = {
|
|
429
477
|
destroy,
|
|
430
478
|
dump,
|
|
479
|
+
listExtended,
|
|
431
480
|
load,
|
|
432
481
|
moveWorkflow,
|
|
433
482
|
retry,
|
|
@@ -4,7 +4,7 @@ import Trigger from '../../triggers';
|
|
|
4
4
|
export declare class RequestInterceptionTrigger extends Trigger {
|
|
5
5
|
static TYPE: string;
|
|
6
6
|
sync: boolean;
|
|
7
|
-
middleware: (
|
|
7
|
+
middleware: (ctx: Context, next: Next) => Promise<never>;
|
|
8
8
|
constructor(workflow: PluginWorkflowServer);
|
|
9
9
|
on(): void;
|
|
10
10
|
off(): void;
|
|
@@ -46,13 +46,13 @@ const _RequestInterceptionTrigger = class _RequestInterceptionTrigger extends im
|
|
|
46
46
|
constructor(workflow) {
|
|
47
47
|
super(workflow);
|
|
48
48
|
this.sync = true;
|
|
49
|
-
this.middleware = async (
|
|
49
|
+
this.middleware = async (ctx, next) => {
|
|
50
50
|
const {
|
|
51
51
|
resourceName,
|
|
52
52
|
actionName,
|
|
53
53
|
params: { filterByTk, filter, values, triggerWorkflows = "" }
|
|
54
|
-
} =
|
|
55
|
-
const dataSourceHeader =
|
|
54
|
+
} = ctx.action;
|
|
55
|
+
const dataSourceHeader = ctx.get("x-data-source");
|
|
56
56
|
const jointCollectionName = (0, import_server.joinCollectionName)(dataSourceHeader, resourceName);
|
|
57
57
|
const triggerWorkflowsMap = /* @__PURE__ */ new Map();
|
|
58
58
|
const triggerWorkflowsArray = [];
|
|
@@ -89,18 +89,18 @@ const _RequestInterceptionTrigger = class _RequestInterceptionTrigger extends im
|
|
|
89
89
|
const processor = await this.workflow.trigger(
|
|
90
90
|
workflow,
|
|
91
91
|
{
|
|
92
|
-
user:
|
|
93
|
-
roleName:
|
|
92
|
+
user: ctx.state.currentUser,
|
|
93
|
+
roleName: ctx.state.currentRole,
|
|
94
94
|
params: {
|
|
95
95
|
filterByTk,
|
|
96
96
|
filter,
|
|
97
97
|
values
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
-
{ httpContext:
|
|
100
|
+
{ httpContext: ctx }
|
|
101
101
|
);
|
|
102
102
|
if (!processor) {
|
|
103
|
-
return
|
|
103
|
+
return ctx.throw(500);
|
|
104
104
|
}
|
|
105
105
|
const { lastSavedJob, nodesMap } = processor;
|
|
106
106
|
const lastNode = nodesMap.get(lastSavedJob == null ? void 0 : lastSavedJob.nodeId);
|
|
@@ -112,17 +112,17 @@ const _RequestInterceptionTrigger = class _RequestInterceptionTrigger extends im
|
|
|
112
112
|
}
|
|
113
113
|
if (processor.execution.status < import_constants.EXECUTION_STATUS.STARTED) {
|
|
114
114
|
if ((lastNode == null ? void 0 : lastNode.type) !== "end") {
|
|
115
|
-
return
|
|
115
|
+
return ctx.throw(
|
|
116
116
|
500,
|
|
117
|
-
|
|
117
|
+
ctx.t("Workflow on your action failed, please contact the administrator", { ns: "workflow" })
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
const err = new RequestInterceptionError("Request is intercepted by workflow");
|
|
121
121
|
err.status = 400;
|
|
122
|
-
err.messages =
|
|
123
|
-
return
|
|
122
|
+
err.messages = ctx.state.messages;
|
|
123
|
+
return ctx.throw(err.status, err);
|
|
124
124
|
}
|
|
125
|
-
return
|
|
125
|
+
return ctx.throw(500, "Workflow on your action hangs, please contact the administrator");
|
|
126
126
|
}
|
|
127
127
|
await next();
|
|
128
128
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Context } from '@tego/server';
|
|
2
|
-
export declare function submit(
|
|
2
|
+
export declare function submit(ctx: Context, next: any): Promise<never>;
|
|
@@ -32,15 +32,15 @@ __export(actions_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(actions_exports);
|
|
33
33
|
var import_server = require("@tego/server");
|
|
34
34
|
var import__ = __toESM(require("../.."));
|
|
35
|
-
async function submit(
|
|
35
|
+
async function submit(ctx, next) {
|
|
36
36
|
var _a, _b, _c;
|
|
37
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
38
|
-
const { filterByTk, values } =
|
|
39
|
-
const { currentUser } =
|
|
37
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
38
|
+
const { filterByTk, values } = ctx.action.params;
|
|
39
|
+
const { currentUser } = ctx.state;
|
|
40
40
|
if (!currentUser) {
|
|
41
|
-
return
|
|
41
|
+
return ctx.throw(401);
|
|
42
42
|
}
|
|
43
|
-
const plugin =
|
|
43
|
+
const plugin = ctx.tego.pm.get(import__.default);
|
|
44
44
|
const instruction = plugin.instructions.get("manual");
|
|
45
45
|
const userJob = await repository.findOne({
|
|
46
46
|
filterByTk,
|
|
@@ -48,24 +48,24 @@ async function submit(context, next) {
|
|
|
48
48
|
// userId: currentUser?.id
|
|
49
49
|
// },
|
|
50
50
|
appends: ["job", "node", "execution", "workflow"],
|
|
51
|
-
context
|
|
51
|
+
context: ctx
|
|
52
52
|
});
|
|
53
53
|
if (!userJob) {
|
|
54
|
-
return
|
|
54
|
+
return ctx.throw(404);
|
|
55
55
|
}
|
|
56
56
|
const { forms = {} } = userJob.node.config;
|
|
57
57
|
const [formKey] = Object.keys(values.result ?? {}).filter((key) => key !== "_");
|
|
58
58
|
const actionKey = (_a = values.result) == null ? void 0 : _a._;
|
|
59
59
|
const actionItem = (_c = (_b = forms[formKey]) == null ? void 0 : _b.actions) == null ? void 0 : _c.find((item) => item.key === actionKey);
|
|
60
60
|
if (userJob.status !== import__.JOB_STATUS.PENDING || userJob.job.status !== import__.JOB_STATUS.PENDING || userJob.execution.status !== import__.EXECUTION_STATUS.STARTED || !userJob.workflow.enabled || !actionKey || (actionItem == null ? void 0 : actionItem.status) == null) {
|
|
61
|
-
return
|
|
61
|
+
return ctx.throw(400);
|
|
62
62
|
}
|
|
63
63
|
userJob.execution.workflow = userJob.workflow;
|
|
64
64
|
const processor = plugin.createProcessor(userJob.execution);
|
|
65
65
|
await processor.prepare();
|
|
66
66
|
const assignees = processor.getParsedValue(userJob.node.config.assignees ?? [], userJob.nodeId).flat().filter(Boolean);
|
|
67
67
|
if (!assignees.includes(currentUser.id) || userJob.userId !== currentUser.id) {
|
|
68
|
-
return
|
|
68
|
+
return ctx.throw(403);
|
|
69
69
|
}
|
|
70
70
|
const presetValues = processor.getParsedValue(actionItem.values ?? {}, userJob.nodeId, {
|
|
71
71
|
// @deprecated
|
|
@@ -90,8 +90,8 @@ async function submit(context, next) {
|
|
|
90
90
|
}
|
|
91
91
|
await userJob.save();
|
|
92
92
|
await processor.exit();
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
ctx.body = userJob;
|
|
94
|
+
ctx.status = 202;
|
|
95
95
|
await next();
|
|
96
96
|
userJob.job.execution = userJob.execution;
|
|
97
97
|
userJob.job.latestUserJob = userJob;
|
|
@@ -26,37 +26,37 @@ var import_constants = require("../common/constants");
|
|
|
26
26
|
var import_workflowNotice = require("./collections/workflowNotice");
|
|
27
27
|
var import_constants2 = require("./constants");
|
|
28
28
|
const workflows = {
|
|
29
|
-
async listWorkflowNoticeFlows(
|
|
30
|
-
|
|
29
|
+
async listWorkflowNoticeFlows(ctx, next) {
|
|
30
|
+
ctx.action.mergeParams({
|
|
31
31
|
filter: {
|
|
32
32
|
type: import_constants.NOTICE_INSTRUCTION_NAMESPACE,
|
|
33
33
|
enabled: true
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
return import_server.actions.list(
|
|
36
|
+
return import_server.actions.list(ctx, next);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
const workflowNotice = {
|
|
40
|
-
async listCentralized(
|
|
41
|
-
const centralizedNoticeFlow = await
|
|
40
|
+
async listCentralized(ctx, next) {
|
|
41
|
+
const centralizedNoticeFlow = await ctx.db.getRepository(import_workflowNotice.COLLECTION_WORKFLOWS_NAME).find({
|
|
42
42
|
filter: {
|
|
43
43
|
"config.centralized": true
|
|
44
44
|
},
|
|
45
45
|
fields: ["id"]
|
|
46
46
|
});
|
|
47
|
-
|
|
47
|
+
ctx.action.mergeParams({
|
|
48
48
|
filter: {
|
|
49
49
|
workflowId: centralizedNoticeFlow.map((item) => item.id)
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
|
-
return import_server.actions.list(
|
|
52
|
+
return import_server.actions.list(ctx, next);
|
|
53
53
|
},
|
|
54
|
-
async submit(
|
|
55
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
56
|
-
const { filterByTk, values } =
|
|
57
|
-
const { currentUser } =
|
|
54
|
+
async submit(ctx, next) {
|
|
55
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
56
|
+
const { filterByTk, values } = ctx.action.params;
|
|
57
|
+
const { currentUser } = ctx.state;
|
|
58
58
|
if (!currentUser) {
|
|
59
|
-
return
|
|
59
|
+
return ctx.throw(401);
|
|
60
60
|
}
|
|
61
61
|
const workflowNotice2 = await repository.findOne({
|
|
62
62
|
filterByTk,
|
|
@@ -64,13 +64,13 @@ const workflowNotice = {
|
|
|
64
64
|
userId: currentUser == null ? void 0 : currentUser.id
|
|
65
65
|
},
|
|
66
66
|
appends: ["job", "node", "execution", "workflow"],
|
|
67
|
-
context
|
|
67
|
+
context: ctx
|
|
68
68
|
});
|
|
69
69
|
if (!workflowNotice2) {
|
|
70
|
-
return
|
|
70
|
+
return ctx.throw(404);
|
|
71
71
|
}
|
|
72
72
|
if (!workflowNotice2.workflow.enabled || workflowNotice2.execution.status || workflowNotice2.job.status || workflowNotice2.status !== import_constants2.NOTICE_ACTION_STATUS.PENDING || !(workflowNotice2.node.config.actions ?? []).includes(values.status)) {
|
|
73
|
-
return
|
|
73
|
+
return ctx.throw(400);
|
|
74
74
|
}
|
|
75
75
|
await workflowNotice2.update({
|
|
76
76
|
status: values.status
|
|
@@ -79,13 +79,13 @@ const workflowNotice = {
|
|
|
79
79
|
// summary: workflowNotice.approval.summary,
|
|
80
80
|
// collectionName: workflowNotice.approval.collectionName,
|
|
81
81
|
});
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
ctx.body = workflowNotice2.get();
|
|
83
|
+
ctx.status = 202;
|
|
84
84
|
await next();
|
|
85
85
|
workflowNotice2.execution.workflow = workflowNotice2.workflow;
|
|
86
86
|
workflowNotice2.job.execution = workflowNotice2.execution;
|
|
87
87
|
workflowNotice2.job.latestUserJob = workflowNotice2.get();
|
|
88
|
-
const workflow =
|
|
88
|
+
const workflow = ctx.tego.pm.get(import__.PluginWorkflow);
|
|
89
89
|
const processor = workflow.createProcessor(workflowNotice2.execution);
|
|
90
90
|
processor.logger.info(
|
|
91
91
|
`notice node (${workflowNotice2.nodeId}) action trigger execution (${workflowNotice2.execution.id}) to resume`
|
|
@@ -94,7 +94,7 @@ const workflowNotice = {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
function init({ app }) {
|
|
97
|
-
app.
|
|
97
|
+
app.resourcer.registerActions({
|
|
98
98
|
...make(import_workflowNotice.COLLECTION_WORKFLOWS_NAME, workflows),
|
|
99
99
|
...make(import_constants.COLLECTION_NOTICE_NAME, workflowNotice)
|
|
100
100
|
});
|
|
@@ -59,9 +59,6 @@ class PluginWorkflowNoticeServer extends import_server.Plugin {
|
|
|
59
59
|
plugin: this
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
await db.import({
|
|
63
|
-
directory: import_node_path.default.resolve(__dirname, "collections")
|
|
64
|
-
});
|
|
65
62
|
(0, import_actions.init)(this);
|
|
66
63
|
this.app.acl.allow(import_workflowNotice.COLLECTION_WORKFLOWS_NAME, ["listWorkflowNoticeFlows"], "loggedIn");
|
|
67
64
|
this.app.acl.allow(import_constants.COLLECTION_NOTICE_NAME, ["get", "list", "listCentralized", "submit"], "loggedIn");
|
|
@@ -3,8 +3,8 @@ import Trigger from '../../triggers';
|
|
|
3
3
|
export declare class OmniTrigger extends Trigger {
|
|
4
4
|
static TYPE: string;
|
|
5
5
|
constructor(workflow: any);
|
|
6
|
-
triggerAction: (
|
|
7
|
-
middleware: (
|
|
6
|
+
triggerAction: (ctx: any, next: any) => Promise<any>;
|
|
7
|
+
middleware: (ctx: Context, next: Next) => Promise<any>;
|
|
8
8
|
private trigger;
|
|
9
9
|
on(): void;
|
|
10
10
|
off(): void;
|