@nocobase/plugin-workflow-action-trigger 2.1.0-beta.8 → 2.2.0-alpha.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/ActionTrigger.d.ts +10 -1
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +12 -12
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +178 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1067 -0
- package/dist/node_modules/joi/lib/types/link.js +168 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/ActionTrigger.d.ts +4 -0
- package/dist/server/ActionTrigger.js +80 -5
- package/package.json +4 -2
|
@@ -42,8 +42,10 @@ module.exports = __toCommonJS(ActionTrigger_exports);
|
|
|
42
42
|
var import_lodash = require("lodash");
|
|
43
43
|
var import_database = require("@nocobase/database");
|
|
44
44
|
var import_plugin_error_handler = __toESM(require("@nocobase/plugin-error-handler"));
|
|
45
|
+
var import_joi = __toESM(require("joi"));
|
|
45
46
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
46
47
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
48
|
+
const ASYNC_WORKFLOW_TRIGGER_DELAY_MS = 200;
|
|
47
49
|
class RequestOnActionTriggerError extends Error {
|
|
48
50
|
status = 400;
|
|
49
51
|
messages = [];
|
|
@@ -54,6 +56,16 @@ class RequestOnActionTriggerError extends Error {
|
|
|
54
56
|
}
|
|
55
57
|
class ActionTrigger_default extends import_plugin_workflow.Trigger {
|
|
56
58
|
static TYPE = "action";
|
|
59
|
+
configSchema = import_joi.default.object({
|
|
60
|
+
collection: import_joi.default.string().required()
|
|
61
|
+
});
|
|
62
|
+
validateConfig(config) {
|
|
63
|
+
const errors = super.validateConfig(config);
|
|
64
|
+
if (errors) {
|
|
65
|
+
return errors;
|
|
66
|
+
}
|
|
67
|
+
return (0, import_plugin_workflow.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
|
|
68
|
+
}
|
|
57
69
|
constructor(workflow) {
|
|
58
70
|
super(workflow);
|
|
59
71
|
const self = this;
|
|
@@ -203,33 +215,96 @@ class ActionTrigger_default extends import_plugin_workflow.Trigger {
|
|
|
203
215
|
(workflow.sync ? syncGroup : asyncGroup).push([workflow, { data, ...userInfo }]);
|
|
204
216
|
}
|
|
205
217
|
}
|
|
206
|
-
for (const event of syncGroup) {
|
|
207
|
-
const
|
|
218
|
+
for (const [index, event] of syncGroup.entries()) {
|
|
219
|
+
const workflow = event[0];
|
|
220
|
+
const remainingSyncWorkflows = syncGroup.length - index - 1;
|
|
221
|
+
const syncLogMeta = {
|
|
222
|
+
workflowId: workflow.id,
|
|
223
|
+
workflowKey: workflow.key,
|
|
224
|
+
workflowTitle: workflow.title,
|
|
225
|
+
resourceName,
|
|
226
|
+
actionName,
|
|
227
|
+
currentSyncOrder: index + 1,
|
|
228
|
+
totalSyncWorkflows: syncGroup.length,
|
|
229
|
+
remainingSyncWorkflows,
|
|
230
|
+
pendingAsyncWorkflows: asyncGroup.length
|
|
231
|
+
};
|
|
232
|
+
context.logger.debug("[Workflow post-action]: executing sync workflow", syncLogMeta);
|
|
233
|
+
const processor = await this.workflow.trigger(workflow, event[1], { httpContext: context });
|
|
208
234
|
if (!processor) {
|
|
209
|
-
|
|
235
|
+
context.logger.error(
|
|
236
|
+
"[Workflow post-action]: sync workflow trigger failed before execution created",
|
|
237
|
+
syncLogMeta
|
|
238
|
+
);
|
|
239
|
+
return context.throw(500, "Workflow on your action failed, please contact the administrator");
|
|
210
240
|
}
|
|
211
241
|
const { lastSavedJob, nodesMap } = processor;
|
|
212
242
|
const lastNode = nodesMap.get(lastSavedJob == null ? void 0 : lastSavedJob.nodeId);
|
|
213
243
|
if (processor.execution.status === import_plugin_workflow.EXECUTION_STATUS.RESOLVED) {
|
|
214
244
|
if ((lastNode == null ? void 0 : lastNode.type) === "end") {
|
|
245
|
+
context.logger.debug("[Workflow post-action]: sync workflow ended request chain on end node", {
|
|
246
|
+
...syncLogMeta,
|
|
247
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
248
|
+
});
|
|
215
249
|
return;
|
|
216
250
|
}
|
|
251
|
+
context.logger.debug("[Workflow post-action]: sync workflow finished successfully", {
|
|
252
|
+
...syncLogMeta,
|
|
253
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
254
|
+
});
|
|
217
255
|
continue;
|
|
218
256
|
}
|
|
219
257
|
if (processor.execution.status < import_plugin_workflow.EXECUTION_STATUS.STARTED) {
|
|
220
258
|
if ((lastNode == null ? void 0 : lastNode.type) !== "end") {
|
|
259
|
+
context.logger.error("[Workflow post-action]: sync workflow failed", {
|
|
260
|
+
...syncLogMeta,
|
|
261
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
262
|
+
});
|
|
221
263
|
return context.throw(500, "Workflow on your action failed, please contact the administrator");
|
|
222
264
|
}
|
|
265
|
+
context.logger.warn("[Workflow post-action]: sync workflow intercepted request on end node", {
|
|
266
|
+
...syncLogMeta,
|
|
267
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
268
|
+
});
|
|
223
269
|
const err = new RequestOnActionTriggerError("Request failed");
|
|
224
270
|
err.status = 400;
|
|
225
271
|
err.messages = context.state.messages;
|
|
226
272
|
return context.throw(err.status, err);
|
|
227
273
|
}
|
|
274
|
+
context.logger.error("[Workflow post-action]: sync workflow is still pending after trigger", {
|
|
275
|
+
...syncLogMeta,
|
|
276
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
277
|
+
});
|
|
228
278
|
return context.throw(500, "Workflow on your action hangs, please contact the administrator");
|
|
229
279
|
}
|
|
230
|
-
|
|
231
|
-
|
|
280
|
+
this.scheduleAsyncWorkflowTriggers(context, asyncGroup);
|
|
281
|
+
}
|
|
282
|
+
scheduleAsyncWorkflowTriggers(context, events) {
|
|
283
|
+
if (!events.length) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const triggerAsyncWorkflows = () => {
|
|
287
|
+
const triggerAsyncWorkflow = async (workflow, values) => {
|
|
288
|
+
await this.workflow.trigger(workflow, values);
|
|
289
|
+
};
|
|
290
|
+
setTimeout(() => {
|
|
291
|
+
for (const [workflow, values] of events) {
|
|
292
|
+
triggerAsyncWorkflow(workflow, values).catch((error) => {
|
|
293
|
+
context.logger.error("[Workflow post-action]: async workflow trigger failed", {
|
|
294
|
+
error,
|
|
295
|
+
workflowId: workflow.id,
|
|
296
|
+
workflowKey: workflow.key,
|
|
297
|
+
workflowTitle: workflow.title
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}, ASYNC_WORKFLOW_TRIGGER_DELAY_MS);
|
|
302
|
+
};
|
|
303
|
+
if (context.res.writableEnded) {
|
|
304
|
+
triggerAsyncWorkflows();
|
|
305
|
+
return;
|
|
232
306
|
}
|
|
307
|
+
context.res.once("finish", triggerAsyncWorkflows);
|
|
233
308
|
}
|
|
234
309
|
async execute(workflow, values, options) {
|
|
235
310
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description": "Triggered after the completion of a request initiated through an action button or API, such as after adding, updating, deleting data, or \"submit to workflow\". Suitable for data processing, sending notifications, etc., after actions are completed.",
|
|
7
7
|
"description.ru-RU": "Срабатывает после завершения запроса, инициированного кнопкой действия или API, например после добавления, обновления, удаления данных или «отправки в рабочий процесс». Подходит для обработки данных, отправки уведомлений и т.д. после выполнения действий.",
|
|
8
8
|
"description.zh-CN": "通过操作按钮或 API 发起请求并在执行完成后触发,比如新增、更新、删除数据或者“提交至工作流”之后。适用于在操作完成后进行数据处理、发送通知等。",
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.2.0-alpha.1",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"homepage": "https://docs.nocobase.com/plugins/workflow-action-trigger",
|
|
@@ -14,17 +14,19 @@
|
|
|
14
14
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/plugins/workflow-action-trigger",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"antd": "5.x",
|
|
17
|
+
"joi": "^17.13.3",
|
|
17
18
|
"react": "18.x",
|
|
18
19
|
"react-i18next": "^11.15.1"
|
|
19
20
|
},
|
|
20
21
|
"peerDependencies": {
|
|
21
22
|
"@nocobase/client": "2.x",
|
|
22
23
|
"@nocobase/database": "2.x",
|
|
24
|
+
"@nocobase/plugin-error-handler": "2.x",
|
|
23
25
|
"@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
|
|
24
26
|
"@nocobase/server": "2.x",
|
|
25
27
|
"@nocobase/test": "2.x"
|
|
26
28
|
},
|
|
27
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "303663aba6c6eefa27e6a6435b4c0352074ec40f",
|
|
28
30
|
"keywords": [
|
|
29
31
|
"Workflow"
|
|
30
32
|
]
|