@nocobase/plugin-workflow-manual 2.1.0-beta.9 → 2.2.0-beta.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.
Files changed (48) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/client/instruction/index.d.ts +1 -6
  3. package/dist/common/constants.d.ts +1 -0
  4. package/dist/common/constants.js +6 -0
  5. package/dist/externalVersion.js +10 -10
  6. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  7. package/dist/node_modules/joi/lib/annotate.js +175 -0
  8. package/dist/node_modules/joi/lib/base.js +1069 -0
  9. package/dist/node_modules/joi/lib/cache.js +143 -0
  10. package/dist/node_modules/joi/lib/common.js +216 -0
  11. package/dist/node_modules/joi/lib/compile.js +283 -0
  12. package/dist/node_modules/joi/lib/errors.js +271 -0
  13. package/dist/node_modules/joi/lib/extend.js +312 -0
  14. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  15. package/dist/node_modules/joi/lib/index.js +1 -0
  16. package/dist/node_modules/joi/lib/manifest.js +476 -0
  17. package/dist/node_modules/joi/lib/messages.js +178 -0
  18. package/dist/node_modules/joi/lib/modify.js +267 -0
  19. package/dist/node_modules/joi/lib/ref.js +414 -0
  20. package/dist/node_modules/joi/lib/schemas.js +302 -0
  21. package/dist/node_modules/joi/lib/state.js +166 -0
  22. package/dist/node_modules/joi/lib/template.js +463 -0
  23. package/dist/node_modules/joi/lib/trace.js +346 -0
  24. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  25. package/dist/node_modules/joi/lib/types/any.js +174 -0
  26. package/dist/node_modules/joi/lib/types/array.js +809 -0
  27. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  28. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  29. package/dist/node_modules/joi/lib/types/date.js +233 -0
  30. package/dist/node_modules/joi/lib/types/function.js +93 -0
  31. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  32. package/dist/node_modules/joi/lib/types/link.js +168 -0
  33. package/dist/node_modules/joi/lib/types/number.js +363 -0
  34. package/dist/node_modules/joi/lib/types/object.js +22 -0
  35. package/dist/node_modules/joi/lib/types/string.js +850 -0
  36. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  37. package/dist/node_modules/joi/lib/validator.js +750 -0
  38. package/dist/node_modules/joi/lib/values.js +263 -0
  39. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  40. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  41. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  42. package/dist/node_modules/joi/package.json +1 -0
  43. package/dist/server/ManualInstruction.js +2 -4
  44. package/dist/server/Plugin.d.ts +1 -0
  45. package/dist/server/Plugin.js +58 -45
  46. package/dist/server/actions.js +12 -2
  47. package/dist/server/collections/workflowManualTasks.js +3 -0
  48. package/package.json +5 -3
@@ -45,6 +45,51 @@ var jobActions = __toESM(require("./actions"));
45
45
  var import_ManualInstruction = __toESM(require("./ManualInstruction"));
46
46
  var import_constants = require("../common/constants");
47
47
  class Plugin_default extends import_server.Plugin {
48
+ async updateManualTaskStats(userIds, transaction) {
49
+ if (!userIds.length) {
50
+ return;
51
+ }
52
+ const workflowPlugin = this.app.pm.get(import_plugin_workflow.default);
53
+ const WorkflowManualTaskModel = this.db.getModel("workflowManualTasks");
54
+ const uniqueUserIds = Array.from(new Set(userIds.filter(Boolean)));
55
+ const userStatsMap = new Map(uniqueUserIds.map((userId) => [userId, { pending: 0, all: 0 }]));
56
+ const pendingCounts = await WorkflowManualTaskModel.count({
57
+ where: {
58
+ status: import_constants.TASK_STATUS.PENDING,
59
+ userId: uniqueUserIds
60
+ },
61
+ include: [
62
+ {
63
+ association: "execution",
64
+ attributes: [],
65
+ where: {
66
+ status: import_plugin_workflow.EXECUTION_STATUS.STARTED
67
+ },
68
+ required: true
69
+ }
70
+ ],
71
+ col: "id",
72
+ group: ["userId"],
73
+ transaction
74
+ });
75
+ const allCounts = await WorkflowManualTaskModel.count({
76
+ where: {
77
+ userId: uniqueUserIds
78
+ },
79
+ col: "id",
80
+ group: ["userId"],
81
+ transaction
82
+ });
83
+ for (const row of pendingCounts) {
84
+ userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), pending: Number(row.count) || 0 });
85
+ }
86
+ for (const row of allCounts) {
87
+ userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), all: Number(row.count) || 0 });
88
+ }
89
+ for (const [userId, stats] of userStatsMap.entries()) {
90
+ await workflowPlugin.updateTasksStats(userId, import_constants.TASK_TYPE_MANUAL, stats, { transaction });
91
+ }
92
+ }
48
93
  onTaskSave = async (task, { transaction }) => {
49
94
  const workflowPlugin = this.app.pm.get(import_plugin_workflow.default);
50
95
  const ModelClass = task.constructor;
@@ -104,54 +149,22 @@ class Plugin_default extends import_server.Plugin {
104
149
  },
105
150
  transaction
106
151
  });
107
- const userStatsMap = /* @__PURE__ */ new Map();
108
- const userId = [];
109
- for (const item of manualTasks) {
110
- userId.push(item.userId);
111
- userStatsMap.set(item.userId, { pending: 0, all: 0 });
112
- }
113
- const pendingCounts = await WorkflowManualTaskModel.count({
114
- where: {
115
- status: import_constants.TASK_STATUS.PENDING,
116
- userId
117
- },
118
- include: [
152
+ const userIds = manualTasks.map((item) => item.userId).filter(Boolean);
153
+ if (execution.status === import_plugin_workflow.EXECUTION_STATUS.ABORTED) {
154
+ await WorkflowManualTaskModel.update(
155
+ {
156
+ status: import_constants.TASK_STATUS.ABORTED
157
+ },
119
158
  {
120
- association: "execution",
121
- attributes: [],
122
159
  where: {
123
- status: import_plugin_workflow.EXECUTION_STATUS.STARTED
160
+ id: manualTasks.map((item) => item.id),
161
+ status: import_constants.TASK_STATUS.PENDING
124
162
  },
125
- required: true
163
+ transaction
126
164
  }
127
- ],
128
- col: "id",
129
- group: ["userId"],
130
- transaction
131
- });
132
- const allCounts = await WorkflowManualTaskModel.count({
133
- where: {
134
- userId
135
- },
136
- col: "id",
137
- group: ["userId"],
138
- transaction
139
- });
140
- for (const row of pendingCounts) {
141
- if (!userStatsMap.get(row.userId)) {
142
- userStatsMap.set(row.userId, { pending: 0, all: 0 });
143
- }
144
- userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), pending: row.count });
145
- }
146
- for (const row of allCounts) {
147
- if (!userStatsMap.get(row.userId)) {
148
- userStatsMap.set(row.userId, { pending: 0, all: 0 });
149
- }
150
- userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), all: row.count });
151
- }
152
- for (const [userId2, stats] of userStatsMap.entries()) {
153
- await workflowPlugin.updateTasksStats(userId2, import_constants.TASK_TYPE_MANUAL, stats, { transaction });
165
+ );
154
166
  }
167
+ await this.updateManualTaskStats(userIds, transaction);
155
168
  };
156
169
  onWorkflowStatusChange = async (workflow, { transaction }) => {
157
170
  const workflowPlugin = this.app.pm.get(import_plugin_workflow.default);
@@ -242,13 +255,13 @@ class Plugin_default extends import_server.Plugin {
242
255
  if (!userStatsMap.get(row.userId)) {
243
256
  userStatsMap.set(row.userId, { pending: 0, all: 0 });
244
257
  }
245
- userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), pending: row.count });
258
+ userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), pending: Number(row.count) || 0 });
246
259
  }
247
260
  for (const row of allCounts) {
248
261
  if (!userStatsMap.get(row.userId)) {
249
262
  userStatsMap.set(row.userId, { pending: 0, all: 0 });
250
263
  }
251
- userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), all: row.count });
264
+ userStatsMap.set(row.userId, { ...userStatsMap.get(row.userId), all: Number(row.count) || 0 });
252
265
  }
253
266
  for (const [userId, stats] of userStatsMap.entries()) {
254
267
  await workflowPlugin.updateTasksStats(userId, import_constants.TASK_TYPE_MANUAL, stats, { transaction });
@@ -50,7 +50,7 @@ async function submit(context, next) {
50
50
  if (!currentUser) {
51
51
  return context.throw(401);
52
52
  }
53
- const plugin = context.app.getPlugin(import_plugin_workflow.default);
53
+ const plugin = context.app.pm.get(import_plugin_workflow.default);
54
54
  const instruction = plugin.instructions.get("manual");
55
55
  const task = await repository.findOne({
56
56
  filterByTk,
@@ -66,6 +66,12 @@ async function submit(context, next) {
66
66
  const { forms = {} } = task.node.config;
67
67
  const [formKey] = Object.keys(values.result ?? {}).filter((key) => key !== "_");
68
68
  const actionKey = (_a = values.result) == null ? void 0 : _a._;
69
+ if (!task.execution) {
70
+ return context.throw(400);
71
+ }
72
+ if (task.execution.status === import_plugin_workflow.EXECUTION_STATUS.STARTED && plugin.timeoutManager.isExpired(task.execution) && await plugin.timeoutManager.abort(task.execution)) {
73
+ return context.throw(400, context.t("Execution timed out", { ns: "workflow" }));
74
+ }
69
75
  const actionItem = (_c = (_b = forms[formKey]) == null ? void 0 : _b.actions) == null ? void 0 : _c.find((item) => item.key === actionKey);
70
76
  if (task.status !== import_plugin_workflow.JOB_STATUS.PENDING || task.job.status !== import_plugin_workflow.JOB_STATUS.PENDING || task.execution.status !== import_plugin_workflow.EXECUTION_STATUS.STARTED || // !task.workflow.enabled ||
71
77
  !actionKey || (actionItem == null ? void 0 : actionItem.status) == null) {
@@ -95,8 +101,9 @@ async function submit(context, next) {
95
101
  });
96
102
  task.set({
97
103
  status: actionItem.status,
98
- result: actionItem.status ? { [formKey]: Object.assign(values.result[formKey], presetValues), _: actionKey } : Object.assign(task.result ?? {}, values.result)
104
+ result: actionItem.status ? { [formKey]: { ...values.result[formKey], ...presetValues }, _: actionKey } : { ...task.result ?? {}, ...values.result }
99
105
  });
106
+ task.changed("result", true);
100
107
  const handler = instruction.formTypes.get(forms[formKey].type);
101
108
  if (handler && task.status) {
102
109
  await handler.call(instruction, task, forms[formKey], processor);
@@ -106,6 +113,9 @@ async function submit(context, next) {
106
113
  context.body = task;
107
114
  context.status = 202;
108
115
  await next();
116
+ if (task.execution.status !== import_plugin_workflow.EXECUTION_STATUS.STARTED) {
117
+ return;
118
+ }
109
119
  task.job.execution = task.execution;
110
120
  task.job.latestTask = task;
111
121
  processor.logger.info(`manual node (${task.nodeId}) action trigger execution (${task.execution.id}) to resume`);
@@ -33,6 +33,9 @@ var import_database = require("@nocobase/database");
33
33
  var import_constants = require("../../common/constants");
34
34
  var workflowManualTasks_default = (0, import_database.defineCollection)({
35
35
  name: "workflowManualTasks",
36
+ dataCategory: "business",
37
+ filterTargetKey: "id",
38
+ simplePaginate: true,
36
39
  dumpRules: {
37
40
  group: "log"
38
41
  },
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Could be used for workflows which some of decisions are made by users.",
7
7
  "description.ru-RU": "Может использоваться в рабочих процессах, где какие-то решения принимаются пользователями.",
8
8
  "description.zh-CN": "用于人工控制部分决策的流程。",
9
- "version": "2.1.0-beta.9",
9
+ "version": "2.2.0-beta.1",
10
10
  "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "homepage": "https://docs.nocobase.com/handbook/workflow-manual",
@@ -18,7 +18,8 @@
18
18
  "@formily/core": "2.x",
19
19
  "@formily/react": "2.x",
20
20
  "antd": "5.x",
21
- "lodash": "4.17.21",
21
+ "joi": "^17.13.3",
22
+ "lodash": "4.x",
22
23
  "react": "18.x",
23
24
  "react-i18next": "^11.15.1",
24
25
  "react-router-dom": "^6.11.2"
@@ -27,13 +28,14 @@
27
28
  "@nocobase/client": "2.x",
28
29
  "@nocobase/database": "2.x",
29
30
  "@nocobase/plugin-data-source-main": "2.x",
31
+ "@nocobase/plugin-mobile": "2.x",
30
32
  "@nocobase/plugin-users": "2.x",
31
33
  "@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
32
34
  "@nocobase/server": "2.x",
33
35
  "@nocobase/test": "2.x",
34
36
  "@nocobase/utils": "2.x"
35
37
  },
36
- "gitHead": "c3a2875e4cbbb43b1f2361e6f9f5f84a7d3f3c3c",
38
+ "gitHead": "f82fa9d0c3aa8e00e53dd94e404a312483b4866b",
37
39
  "keywords": [
38
40
  "Workflow"
39
41
  ]