@nocobase/plugin-workflow-custom-action-trigger 2.0.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.
Files changed (48) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +99 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +1 -0
  5. package/dist/client/CustomActionTrigger.d.ts +186 -0
  6. package/dist/client/components.d.ts +11 -0
  7. package/dist/client/flows.d.ts +25 -0
  8. package/dist/client/hooks.d.ts +20 -0
  9. package/dist/client/index.d.ts +22 -0
  10. package/dist/client/index.js +10 -0
  11. package/dist/client/initializers.d.ts +52 -0
  12. package/dist/client/locale.d.ts +11 -0
  13. package/dist/client/settings.d.ts +12 -0
  14. package/dist/common/constants.d.ts +20 -0
  15. package/dist/common/constants.js +65 -0
  16. package/dist/externalVersion.js +28 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +42 -0
  19. package/dist/locale/de-DE.json +25 -0
  20. package/dist/locale/en-US.json +25 -0
  21. package/dist/locale/es-ES.json +25 -0
  22. package/dist/locale/fr-FR.json +25 -0
  23. package/dist/locale/hu-HU.json +25 -0
  24. package/dist/locale/id-ID.json +25 -0
  25. package/dist/locale/it-IT.json +25 -0
  26. package/dist/locale/ja-JP.json +25 -0
  27. package/dist/locale/ko-KR.json +25 -0
  28. package/dist/locale/nl-NL.json +25 -0
  29. package/dist/locale/pt-BR.json +25 -0
  30. package/dist/locale/ru-RU.json +25 -0
  31. package/dist/locale/tr-TR.json +25 -0
  32. package/dist/locale/uk-UA.json +25 -0
  33. package/dist/locale/vi-VN.json +25 -0
  34. package/dist/locale/zh-CN.json +25 -0
  35. package/dist/locale/zh-TW.json +25 -0
  36. package/dist/server/CustomActionTrigger.d.ts +25 -0
  37. package/dist/server/CustomActionTrigger.js +308 -0
  38. package/dist/server/Plugin.d.ts +13 -0
  39. package/dist/server/Plugin.js +56 -0
  40. package/dist/server/index.d.ts +9 -0
  41. package/dist/server/index.js +42 -0
  42. package/dist/server/migrations/20250212223011-add-config-type.d.ts +13 -0
  43. package/dist/server/migrations/20250212223011-add-config-type.js +62 -0
  44. package/dist/server/migrations/20250228142643-trigger-workflow-action-schema.d.ts +13 -0
  45. package/dist/server/migrations/20250228142643-trigger-workflow-action-schema.js +67 -0
  46. package/package.json +32 -0
  47. package/server.d.ts +2 -0
  48. package/server.js +1 -0
@@ -0,0 +1,308 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var CustomActionTrigger_exports = {};
38
+ __export(CustomActionTrigger_exports, {
39
+ default: () => CustomActionTrigger
40
+ });
41
+ module.exports = __toCommonJS(CustomActionTrigger_exports);
42
+ var import_plugin_error_handler = __toESM(require("@nocobase/plugin-error-handler"));
43
+ var import_plugin_workflow = require("@nocobase/plugin-workflow");
44
+ var import_data_source_manager = require("@nocobase/data-source-manager");
45
+ var import_lodash = require("lodash");
46
+ var import_constants = require("../common/constants");
47
+ class CustomActionInterceptionError extends Error {
48
+ status = 400;
49
+ messages = [];
50
+ constructor(message) {
51
+ super(message);
52
+ this.name = "CustomActionInterceptionError";
53
+ }
54
+ }
55
+ class CustomActionTrigger extends import_plugin_workflow.Trigger {
56
+ static TYPE = import_constants.EVENT_TYPE;
57
+ async globalTriggerAction(context, next) {
58
+ var _a, _b;
59
+ const { triggerWorkflows, values = {} } = context.action.params;
60
+ const { currentUser, currentRole } = context.state;
61
+ const { model: UserModel } = this.workflow.db.getCollection("users");
62
+ const userInfo = {
63
+ user: UserModel.build(currentUser).desensitize(),
64
+ roleName: currentRole
65
+ };
66
+ const triggerWorkflowsMap = /* @__PURE__ */ new Map();
67
+ const triggerWorkflowsArray = [];
68
+ for (const trigger of triggerWorkflows.split(",")) {
69
+ if (!trigger.trim()) {
70
+ continue;
71
+ }
72
+ const [key, path] = trigger.split("!");
73
+ triggerWorkflowsMap.set(key, path);
74
+ triggerWorkflowsArray.push(key);
75
+ }
76
+ const enabledWorkflows = Array.from(this.workflow.enabledCache.values());
77
+ const workflows = [];
78
+ for (const key of triggerWorkflowsArray) {
79
+ const workflow = enabledWorkflows.find((item) => item.key === key);
80
+ if (workflow && workflow.type === this.constructor.TYPE && (((_a = workflow.config) == null ? void 0 : _a.type) === import_constants.CONTEXT_TYPE.GLOBAL || ((_b = workflow.config) == null ? void 0 : _b.type) == null)) {
81
+ workflows.push(workflow);
82
+ }
83
+ }
84
+ const syncGroup = [];
85
+ const asyncGroup = [];
86
+ for (const workflow of workflows) {
87
+ const event = [workflow];
88
+ event.push({ data: values, ...userInfo });
89
+ (workflow.sync ? syncGroup : asyncGroup).push(event);
90
+ }
91
+ await this.processEvents({
92
+ events: [syncGroup, asyncGroup],
93
+ context,
94
+ next
95
+ });
96
+ }
97
+ triggerAction = async (context, next) => {
98
+ var _a;
99
+ const {
100
+ resourceName,
101
+ params: { filterByTk, values, triggerWorkflows = "", associatedIndex }
102
+ } = context.action;
103
+ if (!triggerWorkflows) {
104
+ return context.throw(400, 'parameter "triggerWorkflows" is required');
105
+ }
106
+ if (resourceName === "workflows") {
107
+ return this.globalTriggerAction(context, next);
108
+ }
109
+ const { currentUser, currentRole } = context.state;
110
+ const { model: UserModel } = this.workflow.db.getCollection("users");
111
+ const userInfo = {
112
+ user: UserModel.build(currentUser).desensitize(),
113
+ roleName: currentRole
114
+ };
115
+ const dataSourceHeader = context.get("x-data-source") || "main";
116
+ const { collectionManager } = context.app.dataSourceManager.dataSources.get(dataSourceHeader) ?? {};
117
+ if (!collectionManager) {
118
+ return context.throw(400, "Data source not found");
119
+ }
120
+ const repository = collectionManager.getRepository(resourceName, associatedIndex);
121
+ const jointCollectionName = (0, import_data_source_manager.joinCollectionName)(dataSourceHeader, repository.collection.name);
122
+ const triggerWorkflowsMap = /* @__PURE__ */ new Map();
123
+ const triggerWorkflowsArray = [];
124
+ for (const trigger of triggerWorkflows.split(",")) {
125
+ if (!trigger.trim()) {
126
+ continue;
127
+ }
128
+ const [key, path] = trigger.split("!");
129
+ triggerWorkflowsMap.set(key, path);
130
+ triggerWorkflowsArray.push(key);
131
+ }
132
+ const enabledWorkflows = Array.from(this.workflow.enabledCache.values());
133
+ const workflows = [];
134
+ for (const key of triggerWorkflowsArray) {
135
+ const workflow = enabledWorkflows.find((item) => item.key === key);
136
+ if (workflow && workflow.type === this.constructor.TYPE && ((_a = workflow.config) == null ? void 0 : _a.collection) === jointCollectionName) {
137
+ workflows.push(workflow);
138
+ }
139
+ }
140
+ const syncGroup = [];
141
+ const asyncGroup = [];
142
+ for (const workflow of workflows) {
143
+ const event = [workflow];
144
+ const { appends = [] } = workflow.config;
145
+ const dataPath = triggerWorkflowsMap.get(workflow.key);
146
+ const formData = dataPath ? (0, import_lodash.get)(values, dataPath) : values;
147
+ let data = formData;
148
+ if (filterByTk != null) {
149
+ if (Array.isArray(filterByTk)) {
150
+ data = (await repository.find({ filterByTk, appends, context })).map(
151
+ (item) => Object.assign(item.toJSON(), formData)
152
+ );
153
+ } else {
154
+ data = await repository.findOne({ filterByTk, appends, context });
155
+ if (!data) {
156
+ continue;
157
+ }
158
+ if (typeof data.toJSON === "function") {
159
+ data = data.toJSON();
160
+ Object.assign(data, formData);
161
+ }
162
+ }
163
+ }
164
+ event.push({ data, ...userInfo });
165
+ (workflow.sync ? syncGroup : asyncGroup).push(event);
166
+ }
167
+ await this.processEvents({
168
+ events: [syncGroup, asyncGroup],
169
+ context,
170
+ next
171
+ });
172
+ };
173
+ constructor(workflow) {
174
+ super(workflow);
175
+ this.workflow.app.dataSourceManager.afterAddDataSource((dataSource) => {
176
+ dataSource.resourceManager.registerActionHandler("trigger", this.triggerAction);
177
+ dataSource.acl.allow("*", ["trigger"], "loggedIn");
178
+ });
179
+ workflow.app.pm.get(import_plugin_error_handler.default).errorHandler.register(
180
+ (err) => err.name === "CustomActionInterceptionError",
181
+ async (err, ctx) => {
182
+ ctx.body = {
183
+ errors: err.messages
184
+ };
185
+ ctx.status = err.status;
186
+ }
187
+ );
188
+ }
189
+ async processEvents({
190
+ events: [syncGroup = [], asyncGroup = []],
191
+ context,
192
+ next
193
+ }) {
194
+ for (const event of syncGroup) {
195
+ const processor = await this.workflow.trigger(event[0], event[1], { httpContext: context });
196
+ if (!processor) {
197
+ return context.throw(500);
198
+ }
199
+ const { lastSavedJob, nodesMap } = processor;
200
+ const lastNode = nodesMap.get(lastSavedJob == null ? void 0 : lastSavedJob.nodeId);
201
+ if (processor.execution.status === import_plugin_workflow.EXECUTION_STATUS.RESOLVED) {
202
+ if ((lastNode == null ? void 0 : lastNode.type) === "end") {
203
+ return;
204
+ }
205
+ continue;
206
+ }
207
+ if (processor.execution.status < import_plugin_workflow.EXECUTION_STATUS.STARTED) {
208
+ if ((lastNode == null ? void 0 : lastNode.type) !== "end") {
209
+ return context.throw(500, "Workflow on your action failed, please contact the administrator");
210
+ }
211
+ const err = new CustomActionInterceptionError("Request is intercepted by workflow");
212
+ err.status = 400;
213
+ err.messages = context.state.messages;
214
+ return context.throw(err.status, err);
215
+ }
216
+ return context.throw(500, "Workflow on your action hangs, please contact the administrator");
217
+ }
218
+ await next();
219
+ for (const event of asyncGroup) {
220
+ this.workflow.trigger(event[0], event[1]);
221
+ }
222
+ }
223
+ validateContext(values, workflow) {
224
+ var _a;
225
+ const { type } = workflow.config;
226
+ if (type === import_constants.CONTEXT_TYPE.SINGLE_RECORD) {
227
+ if (!values.data) {
228
+ return {
229
+ data: "Data is required"
230
+ };
231
+ }
232
+ }
233
+ if (type === import_constants.CONTEXT_TYPE.MULTIPLE_RECORDS) {
234
+ if (!((_a = values.filterByTk) == null ? void 0 : _a.length)) {
235
+ return {
236
+ filterByTk: "filterByTk is required"
237
+ };
238
+ }
239
+ }
240
+ return null;
241
+ }
242
+ async execute(workflow, values, options) {
243
+ var _a;
244
+ const UserRepo = this.workflow.app.db.getRepository("users");
245
+ const actor = await UserRepo.findOne({
246
+ filterByTk: values.userId,
247
+ appends: ["roles"]
248
+ });
249
+ if (!actor) {
250
+ throw new Error("user not found");
251
+ }
252
+ const { roles, ...user } = actor.desensitize().get();
253
+ const userInfo = {
254
+ user,
255
+ roleName: values.roleName || ((_a = roles == null ? void 0 : roles[0]) == null ? void 0 : _a.name)
256
+ };
257
+ let { data, filterByTk } = values;
258
+ const { type, collection: jointCollectionName, appends } = workflow.config;
259
+ if (!type) {
260
+ return this.workflow.trigger(
261
+ workflow,
262
+ {
263
+ data,
264
+ ...userInfo
265
+ },
266
+ options
267
+ );
268
+ }
269
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(jointCollectionName);
270
+ const dataSource = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName);
271
+ if (!dataSource) {
272
+ throw new Error(`Data source ${dataSourceName} not found`);
273
+ }
274
+ const collection = dataSource.collectionManager.getCollection(collectionName);
275
+ if (!collection) {
276
+ throw new Error(`Collection ${collectionName} not found`);
277
+ }
278
+ const { filterTargetKey, repository } = collection;
279
+ if (type === import_constants.CONTEXT_TYPE.MULTIPLE_RECORDS) {
280
+ data = (await repository.find({ filterByTk, appends })).map((item) => item.toJSON());
281
+ } else {
282
+ let loadNeeded = false;
283
+ if (data && typeof data === "object") {
284
+ filterByTk = collection.isMultiFilterTargetKey() ? (0, import_lodash.pick)(
285
+ data,
286
+ collection.filterTargetKey.sort((a, b) => a.localeCompare(b))
287
+ ) : (0, import_lodash.get)(data, collection.filterTargetKey);
288
+ } else {
289
+ filterByTk = data;
290
+ loadNeeded = true;
291
+ }
292
+ if (loadNeeded || (appends == null ? void 0 : appends.length)) {
293
+ data = await repository.findOne({
294
+ filterByTk,
295
+ appends
296
+ });
297
+ }
298
+ }
299
+ return this.workflow.trigger(
300
+ workflow,
301
+ {
302
+ data,
303
+ ...userInfo
304
+ },
305
+ options
306
+ );
307
+ }
308
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This program is offered under a commercial license.
7
+ * For more information, see <https://www.nocobase.com/agreement>
8
+ */
9
+ import { Plugin } from '@nocobase/server';
10
+ export declare class PluginWorkflowCustomActionTriggerServer extends Plugin {
11
+ load(): Promise<void>;
12
+ }
13
+ export default PluginWorkflowCustomActionTriggerServer;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var Plugin_exports = {};
38
+ __export(Plugin_exports, {
39
+ PluginWorkflowCustomActionTriggerServer: () => PluginWorkflowCustomActionTriggerServer,
40
+ default: () => Plugin_default
41
+ });
42
+ module.exports = __toCommonJS(Plugin_exports);
43
+ var import_server = require("@nocobase/server");
44
+ var import_plugin_workflow = __toESM(require("@nocobase/plugin-workflow"));
45
+ var import_CustomActionTrigger = __toESM(require("./CustomActionTrigger"));
46
+ class PluginWorkflowCustomActionTriggerServer extends import_server.Plugin {
47
+ async load() {
48
+ const workflowPlugin = this.app.pm.get(import_plugin_workflow.default);
49
+ workflowPlugin.registerTrigger("custom-action", import_CustomActionTrigger.default);
50
+ }
51
+ }
52
+ var Plugin_default = PluginWorkflowCustomActionTriggerServer;
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ PluginWorkflowCustomActionTriggerServer
56
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This program is offered under a commercial license.
7
+ * For more information, see <https://www.nocobase.com/agreement>
8
+ */
9
+ export { default } from './Plugin';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var server_exports = {};
38
+ __export(server_exports, {
39
+ default: () => import_Plugin.default
40
+ });
41
+ module.exports = __toCommonJS(server_exports);
42
+ var import_Plugin = __toESM(require("./Plugin"));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ appVersion: string;
12
+ up(): Promise<void>;
13
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var add_config_type_exports = {};
28
+ __export(add_config_type_exports, {
29
+ default: () => add_config_type_default
30
+ });
31
+ module.exports = __toCommonJS(add_config_type_exports);
32
+ var import_server = require("@nocobase/server");
33
+ var import_constants = require("../../common/constants");
34
+ class add_config_type_default extends import_server.Migration {
35
+ appVersion = "<1.6.0-beta";
36
+ async up() {
37
+ const { db } = this.context;
38
+ const WorkflowRepo = db.getRepository("workflows");
39
+ await db.sequelize.transaction(async (transaction) => {
40
+ const workflows = await WorkflowRepo.find({
41
+ filter: {
42
+ type: "custom-action"
43
+ },
44
+ transaction
45
+ });
46
+ await workflows.reduce(
47
+ (promise, item) => promise.then(() => {
48
+ if (item.config.type != null) {
49
+ return Promise.resolve();
50
+ }
51
+ item.set("config", { ...item.config, type: import_constants.CONTEXT_TYPE.SINGLE_RECORD });
52
+ item.changed("config", true);
53
+ return item.save({
54
+ silent: true,
55
+ transaction
56
+ });
57
+ }),
58
+ Promise.resolve()
59
+ );
60
+ });
61
+ }
62
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ appVersion: string;
12
+ up(): Promise<void>;
13
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var trigger_workflow_action_schema_exports = {};
28
+ __export(trigger_workflow_action_schema_exports, {
29
+ default: () => trigger_workflow_action_schema_default
30
+ });
31
+ module.exports = __toCommonJS(trigger_workflow_action_schema_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class trigger_workflow_action_schema_default extends import_server.Migration {
34
+ appVersion = "<1.6.0";
35
+ async up() {
36
+ const { db } = this.context;
37
+ const UISchemaRepo = db.getRepository("uiSchemas");
38
+ await db.sequelize.transaction(async (transaction) => {
39
+ const customButtons = await UISchemaRepo.find({
40
+ filter: {
41
+ "schema.x-designer": "Action.Designer",
42
+ "schema.x-action": "customize:triggerWorkflows"
43
+ },
44
+ transaction
45
+ });
46
+ console.log("%d nodes need to be migrated.", customButtons.length);
47
+ await customButtons.reduce(
48
+ (promise, node) => promise.then(() => {
49
+ const { schema } = node;
50
+ delete schema["x-desiger"];
51
+ schema["x-settings"] = "actionSettings:submitToWorkflow";
52
+ schema["x-toolbar-props"] = {
53
+ initializer: false,
54
+ showBorder: false
55
+ };
56
+ node.set("schema", schema);
57
+ node.changed("schema", true);
58
+ return node.save({
59
+ silent: true,
60
+ transaction
61
+ });
62
+ }),
63
+ Promise.resolve()
64
+ );
65
+ });
66
+ }
67
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@nocobase/plugin-workflow-custom-action-trigger",
3
+ "version": "2.0.3",
4
+ "displayName": "Workflow: Custom action event",
5
+ "displayName.zh-CN": "工作流:自定义操作事件",
6
+ "description": "Triggers after click a custom action button.",
7
+ "description.zh-CN": "在点击绑定了自定义事件的按钮后触发。适用于对数据行的自定义操作编排。",
8
+ "main": "./dist/server/index.js",
9
+ "homepage": "https://docs.nocobase.com/handbook/workflow-custom-action-trigger",
10
+ "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-custom-action-trigger",
11
+ "peerDependencies": {
12
+ "@nocobase/client": "2.x",
13
+ "@nocobase/plugin-error-handler": "2.x",
14
+ "@nocobase/plugin-users": "2.x",
15
+ "@nocobase/plugin-workflow": "2.x",
16
+ "@nocobase/server": "2.x",
17
+ "@nocobase/test": "2.x",
18
+ "@nocobase/utils": "2.x"
19
+ },
20
+ "keywords": [
21
+ "Workflow"
22
+ ],
23
+ "nocobase": {
24
+ "supportedVersions": [
25
+ "1.x",
26
+ "2.x"
27
+ ],
28
+ "editionLevel": 0
29
+ },
30
+ "gitHead": "5bcb42fc092f85adb9511c1a351b388bd7aaf66e",
31
+ "license": "Apache-2.0"
32
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');