@tachybase/module-workflow 1.6.0 → 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/components/ColletionTreeSelect.d.ts +16 -0
- package/dist/client/components/EnabledStatusFilter.d.ts +2 -0
- package/dist/client/components/index.d.ts +1 -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/index.js +85 -59
- package/dist/client/nodes/select.d.ts +235 -0
- package/dist/externalVersion.js +9 -9
- package/dist/locale/en-US.json +47 -1
- package/dist/locale/es-ES.json +17 -1
- package/dist/locale/fr-FR.json +16 -0
- package/dist/locale/ja-JP.json +17 -1
- package/dist/locale/ko_KR.json +17 -1
- package/dist/locale/pt-BR.json +17 -1
- package/dist/locale/ru-RU.json +18 -2
- package/dist/locale/tr-TR.json +18 -2
- package/dist/locale/zh-CN.json +50 -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 +33 -33
- 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 +9 -9
- package/dist/server/actions/workflows.helpers.d.ts +6 -6
- package/dist/server/actions/workflows.helpers.js +14 -14
- package/dist/server/actions/workflows.js +85 -85
- 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/package.json +12 -12
- package/dist/server/features/trigger-instruction/index.d.ts +0 -0
- package/dist/server/features/trigger-instruction/index.js +0 -0
|
@@ -44,30 +44,30 @@ var import_server = require("@tego/server");
|
|
|
44
44
|
var import_Plugin = __toESM(require("../Plugin"));
|
|
45
45
|
var import_utils = require("../utils");
|
|
46
46
|
var import_workflows = require("./workflows.helpers");
|
|
47
|
-
async function listExtended(
|
|
47
|
+
async function listExtended(ctx, next) {
|
|
48
48
|
var _a;
|
|
49
|
-
await import_server.actions.list(
|
|
50
|
-
if (((_a =
|
|
51
|
-
const workflows =
|
|
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
52
|
for (let index = 0; index < workflows.length; index++) {
|
|
53
53
|
const workflow = workflows[index];
|
|
54
|
-
const row =
|
|
54
|
+
const row = ctx.body.rows[index];
|
|
55
55
|
if (!row) continue;
|
|
56
56
|
const workflowData = (0, import_workflows.getWorkflowData)(workflow);
|
|
57
|
-
const executedTime = await (0, import_workflows.getLatestExecutedTimeForWorkflow)(
|
|
57
|
+
const executedTime = await (0, import_workflows.getLatestExecutedTimeForWorkflow)(ctx, workflowData == null ? void 0 : workflowData.id, workflowData == null ? void 0 : workflowData.key);
|
|
58
58
|
(0, import_workflows.setLatestExecutedTime)(row, executedTime);
|
|
59
|
-
const eventSourceName = await (0, import_workflows.getEventSourceNameForWorkflow)(
|
|
59
|
+
const eventSourceName = await (0, import_workflows.getEventSourceNameForWorkflow)(ctx, workflowData == null ? void 0 : workflowData.key);
|
|
60
60
|
(0, import_workflows.setEventSourceName)(row, eventSourceName);
|
|
61
|
-
const categories = await (0, import_workflows.getCategoriesForWorkflow)(
|
|
61
|
+
const categories = await (0, import_workflows.getCategoriesForWorkflow)(ctx, workflow, workflowData == null ? void 0 : workflowData.key);
|
|
62
62
|
(0, import_workflows.setCategories)(row, categories);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
return
|
|
65
|
+
return ctx;
|
|
66
66
|
}
|
|
67
|
-
async function update(
|
|
68
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
69
|
-
const { filterByTk, values } =
|
|
70
|
-
|
|
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({
|
|
71
71
|
whitelist: [
|
|
72
72
|
"title",
|
|
73
73
|
"description",
|
|
@@ -86,15 +86,15 @@ async function update(context, next) {
|
|
|
86
86
|
if (Object.keys(values).includes("config")) {
|
|
87
87
|
const workflow = await repository.findById(filterByTk);
|
|
88
88
|
if (workflow.get("executed")) {
|
|
89
|
-
return
|
|
89
|
+
return ctx.throw(400, "config of executed workflow can not be updated");
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
return import_server.actions.update(
|
|
92
|
+
return import_server.actions.update(ctx, next);
|
|
93
93
|
}
|
|
94
|
-
async function destroy(
|
|
95
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
96
|
-
const { filterByTk, filter } =
|
|
97
|
-
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) => {
|
|
98
98
|
const items = await repository.find({
|
|
99
99
|
filterByTk,
|
|
100
100
|
filter,
|
|
@@ -112,7 +112,7 @@ async function destroy(context, next) {
|
|
|
112
112
|
transaction
|
|
113
113
|
});
|
|
114
114
|
revisions.forEach((item) => ids.add(item.id));
|
|
115
|
-
|
|
115
|
+
ctx.body = await repository.destroy({
|
|
116
116
|
filterByTk: Array.from(ids),
|
|
117
117
|
individualHooks: true,
|
|
118
118
|
transaction
|
|
@@ -120,15 +120,15 @@ async function destroy(context, next) {
|
|
|
120
120
|
});
|
|
121
121
|
next();
|
|
122
122
|
}
|
|
123
|
-
async function dump(
|
|
124
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
125
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
126
|
-
|
|
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) => {
|
|
127
127
|
const origin = await repository.findOne({
|
|
128
128
|
filterByTk,
|
|
129
129
|
filter,
|
|
130
130
|
appends: ["nodes"],
|
|
131
|
-
context,
|
|
131
|
+
context: ctx,
|
|
132
132
|
transaction
|
|
133
133
|
});
|
|
134
134
|
const revisionData = filter.key ? {
|
|
@@ -147,11 +147,11 @@ async function dump(context, next) {
|
|
|
147
147
|
});
|
|
148
148
|
await next();
|
|
149
149
|
}
|
|
150
|
-
async function load(
|
|
151
|
-
const plugin =
|
|
152
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
153
|
-
const { values = {} } =
|
|
154
|
-
|
|
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) => {
|
|
155
155
|
const origin = values.workflow;
|
|
156
156
|
const trigger2 = plugin.triggers.get(origin.type);
|
|
157
157
|
const instance = await repository.create({
|
|
@@ -204,58 +204,58 @@ async function load(context, next) {
|
|
|
204
204
|
});
|
|
205
205
|
await next();
|
|
206
206
|
}
|
|
207
|
-
async function test(
|
|
207
|
+
async function test(ctx, next) {
|
|
208
208
|
var _a;
|
|
209
|
-
const plugin =
|
|
210
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
211
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
212
|
-
if (!
|
|
213
|
-
|
|
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 = {};
|
|
214
214
|
}
|
|
215
|
-
if (!
|
|
216
|
-
|
|
215
|
+
if (!ctx.state.messages) {
|
|
216
|
+
ctx.state.messages = [];
|
|
217
217
|
}
|
|
218
218
|
const workflow = await repository.findOne({
|
|
219
219
|
filterByTk,
|
|
220
220
|
filter,
|
|
221
221
|
appends: ["nodes"],
|
|
222
|
-
context
|
|
222
|
+
context: ctx
|
|
223
223
|
});
|
|
224
224
|
if (!workflow) {
|
|
225
|
-
return
|
|
225
|
+
return ctx.throw(404, "Workflow not found");
|
|
226
226
|
}
|
|
227
227
|
const execution = await (0, import_utils.triggerWorkflowAndGetExecution)(
|
|
228
228
|
plugin,
|
|
229
229
|
workflow,
|
|
230
230
|
{
|
|
231
231
|
data: values.data || {},
|
|
232
|
-
user: ((_a =
|
|
232
|
+
user: ((_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) || {}
|
|
233
233
|
},
|
|
234
|
-
{ httpContext:
|
|
235
|
-
|
|
234
|
+
{ httpContext: ctx, transaction: ctx.transaction },
|
|
235
|
+
ctx.db
|
|
236
236
|
);
|
|
237
237
|
if (!execution) {
|
|
238
|
-
|
|
239
|
-
message:
|
|
238
|
+
ctx.state.messages.push({
|
|
239
|
+
message: ctx.t("Failed to create execution", { ns: "workflow" })
|
|
240
240
|
});
|
|
241
|
-
return
|
|
241
|
+
return ctx.throw(500, "Failed to create execution");
|
|
242
242
|
}
|
|
243
|
-
|
|
244
|
-
message:
|
|
243
|
+
ctx.state.messages.push({
|
|
244
|
+
message: ctx.t("Test execution ended", { ns: "workflow" })
|
|
245
245
|
});
|
|
246
|
-
|
|
246
|
+
ctx.body = execution;
|
|
247
247
|
await next();
|
|
248
248
|
}
|
|
249
|
-
async function revision(
|
|
250
|
-
const plugin =
|
|
251
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
252
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
253
|
-
|
|
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) => {
|
|
254
254
|
const origin = await repository.findOne({
|
|
255
255
|
filterByTk,
|
|
256
256
|
filter,
|
|
257
257
|
appends: ["nodes"],
|
|
258
|
-
context,
|
|
258
|
+
context: ctx,
|
|
259
259
|
transaction
|
|
260
260
|
});
|
|
261
261
|
const trigger2 = plugin.triggers.get(origin.type);
|
|
@@ -315,30 +315,30 @@ async function revision(context, next) {
|
|
|
315
315
|
});
|
|
316
316
|
await next();
|
|
317
317
|
}
|
|
318
|
-
async function retry(
|
|
319
|
-
const plugin =
|
|
320
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
321
|
-
const { filterByTk, filter = {}, values = {} } =
|
|
322
|
-
const ExecutionRepo =
|
|
323
|
-
if (!
|
|
324
|
-
|
|
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 = {};
|
|
325
325
|
}
|
|
326
|
-
if (!
|
|
327
|
-
|
|
326
|
+
if (!ctx.state.messages) {
|
|
327
|
+
ctx.state.messages = [];
|
|
328
328
|
}
|
|
329
329
|
const workflow = await repository.findOne({
|
|
330
330
|
filterByTk,
|
|
331
331
|
filter,
|
|
332
332
|
appends: ["nodes"],
|
|
333
|
-
context
|
|
333
|
+
context: ctx
|
|
334
334
|
});
|
|
335
335
|
const execution = await ExecutionRepo.findOne({
|
|
336
336
|
filter: { key: workflow.key },
|
|
337
337
|
sort: ["-createdAt"]
|
|
338
338
|
});
|
|
339
339
|
if (!execution) {
|
|
340
|
-
|
|
341
|
-
message:
|
|
340
|
+
ctx.state.messages.push({
|
|
341
|
+
message: ctx.t("No execution records found for this workflow.", { ns: "workflow" })
|
|
342
342
|
});
|
|
343
343
|
}
|
|
344
344
|
try {
|
|
@@ -346,36 +346,36 @@ async function retry(context, next) {
|
|
|
346
346
|
plugin,
|
|
347
347
|
workflow,
|
|
348
348
|
execution.context,
|
|
349
|
-
{ httpContext:
|
|
350
|
-
|
|
349
|
+
{ httpContext: ctx, transaction: ctx.transaction },
|
|
350
|
+
ctx.db
|
|
351
351
|
);
|
|
352
352
|
if (!newExecution) {
|
|
353
|
-
|
|
354
|
-
message:
|
|
353
|
+
ctx.state.messages.push({
|
|
354
|
+
message: ctx.t("Failed to create execution", { ns: "workflow" })
|
|
355
355
|
});
|
|
356
|
-
|
|
357
|
-
error:
|
|
356
|
+
ctx.body = {
|
|
357
|
+
error: ctx.t("Failed to create execution", { ns: "workflow" })
|
|
358
358
|
};
|
|
359
359
|
return await next();
|
|
360
360
|
}
|
|
361
|
-
|
|
362
|
-
|
|
361
|
+
ctx.state.messages.push({ message: ctx.t("Execute ended", { ns: "workflow" }) });
|
|
362
|
+
ctx.body = newExecution;
|
|
363
363
|
} catch (error) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
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" }),
|
|
367
367
|
error: error.message
|
|
368
368
|
});
|
|
369
|
-
|
|
369
|
+
ctx.body = {
|
|
370
370
|
error: error.message
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
373
|
await next();
|
|
374
374
|
}
|
|
375
|
-
async function sync(
|
|
376
|
-
const plugin =
|
|
377
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
378
|
-
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;
|
|
379
379
|
const workflows = await repository.find({
|
|
380
380
|
filterByTk,
|
|
381
381
|
filter
|
|
@@ -384,13 +384,13 @@ async function sync(context, next) {
|
|
|
384
384
|
plugin.toggle(workflow, false);
|
|
385
385
|
plugin.toggle(workflow);
|
|
386
386
|
});
|
|
387
|
-
|
|
387
|
+
ctx.status = 204;
|
|
388
388
|
await next();
|
|
389
389
|
}
|
|
390
390
|
async function trigger(ctx, next) {
|
|
391
391
|
var _a, _b;
|
|
392
392
|
if (!ctx.action.params.triggerWorkflows) {
|
|
393
|
-
const plugin = ctx.
|
|
393
|
+
const plugin = ctx.tego.getPlugin(import_Plugin.default);
|
|
394
394
|
const workflow = await ctx.db.getRepository("workflows").findById(ctx.action.params.filterByTk);
|
|
395
395
|
const updateData = JSON.parse(decodeURIComponent(((_a = ctx.action.params) == null ? void 0 : _a.updateData) || ""));
|
|
396
396
|
plugin.trigger(
|
|
@@ -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;
|