@tachybase/module-workflow 0.23.48 → 1.0.6
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/NodeContext.d.ts +3 -0
- package/dist/client/features/dynamic-calculation/DynamicCalculation.d.ts +12 -0
- package/dist/client/features/loop/LoopInstruction.d.ts +12 -0
- package/dist/client/features/parallel/ParallelInstruction.d.ts +12 -0
- package/dist/client/features/request/RequestInstruction.d.ts +1 -2
- package/dist/client/features/sql/SQLInstruction.d.ts +12 -0
- package/dist/client/features/variables/VariablesInstruction.d.ts +12 -0
- package/dist/client/index.js +52 -52
- package/dist/client/nodes/calculation.d.ts +12 -0
- package/dist/client/nodes/condition.d.ts +12 -0
- package/dist/client/nodes/default-node/components/AddButton.props.d.ts +3 -0
- package/dist/client/nodes/default-node/components/ViewUploadForm.d.ts +1 -0
- package/dist/client/nodes/default-node/components/ViewUploadForm.schema.d.ts +46 -0
- package/dist/client/nodes/default-node/hooks/useCancelActionProps.d.ts +3 -0
- package/dist/client/nodes/default-node/hooks/useCreateActionProps.d.ts +3 -0
- package/dist/client/nodes/end.d.ts +12 -0
- package/dist/client/nodes/updateOrCreate.d.ts +82 -0
- package/dist/client/variable.d.ts +1 -5
- package/dist/externalVersion.js +15 -15
- package/dist/locale/en-US.json +2 -0
- package/dist/locale/zh-CN.json +13 -0
- package/dist/node_modules/@babel/core/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 +27 -15
- package/dist/server/Processor.d.ts +1 -0
- package/dist/server/Processor.js +2 -1
- package/dist/server/features/omni-trigger/CustomActionTrigger.js +17 -6
- package/dist/server/instructions/ConditionInstruction.js +16 -0
- package/dist/server/instructions/UpdateOrCreateInstruction.d.ts +10 -0
- package/dist/server/instructions/UpdateOrCreateInstruction.js +232 -0
- package/package.json +17 -17
- package/dist/server/features/webhook/Plugin.d.ts +0 -4
- package/dist/server/features/webhook/Plugin.js +0 -109
- package/dist/server/features/webhook/index.d.ts +0 -1
- package/dist/server/features/webhook/index.js +0 -27
- package/dist/server/features/webhook/webhooks.d.ts +0 -9
- package/dist/server/features/webhook/webhooks.js +0 -286
|
@@ -87,6 +87,22 @@ calculators.register("startsWith", startsWith);
|
|
|
87
87
|
calculators.register("notStartsWith", notStartsWith);
|
|
88
88
|
calculators.register("endsWith", endsWith);
|
|
89
89
|
calculators.register("notEndsWith", notEndsWith);
|
|
90
|
+
function isEmpty(a) {
|
|
91
|
+
return a == null;
|
|
92
|
+
}
|
|
93
|
+
function isNotEmpty(a) {
|
|
94
|
+
return !isEmpty(a);
|
|
95
|
+
}
|
|
96
|
+
function isTrue(a) {
|
|
97
|
+
return a === true;
|
|
98
|
+
}
|
|
99
|
+
function isFalse(a) {
|
|
100
|
+
return a === false;
|
|
101
|
+
}
|
|
102
|
+
calculators.register("isEmpty", isEmpty);
|
|
103
|
+
calculators.register("isNotEmpty", isNotEmpty);
|
|
104
|
+
calculators.register("isTrue", isTrue);
|
|
105
|
+
calculators.register("isFalse", isFalse);
|
|
90
106
|
function calculate(calculation = {}) {
|
|
91
107
|
let fn;
|
|
92
108
|
if (!(calculation.calculator && (fn = calculators.get(calculation.calculator)))) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Instruction } from '.';
|
|
2
|
+
import type Processor from '../Processor';
|
|
3
|
+
import type { FlowNodeModel } from '../types';
|
|
4
|
+
export declare class UpdateOrCreateInstruction extends Instruction {
|
|
5
|
+
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
6
|
+
result: any;
|
|
7
|
+
status: 1;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export default UpdateOrCreateInstruction;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var UpdateOrCreateInstruction_exports = {};
|
|
29
|
+
__export(UpdateOrCreateInstruction_exports, {
|
|
30
|
+
UpdateOrCreateInstruction: () => UpdateOrCreateInstruction,
|
|
31
|
+
default: () => UpdateOrCreateInstruction_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(UpdateOrCreateInstruction_exports);
|
|
34
|
+
var import_data_source = require("@tachybase/data-source");
|
|
35
|
+
var import_server = require("@tachybase/server");
|
|
36
|
+
var import_utils = require("@tachybase/utils");
|
|
37
|
+
var import_axios = __toESM(require("axios"));
|
|
38
|
+
var import_form_data = __toESM(require("form-data"));
|
|
39
|
+
var import_lodash = __toESM(require("lodash"));
|
|
40
|
+
var import_mime_types = __toESM(require("mime-types"));
|
|
41
|
+
var import__ = require(".");
|
|
42
|
+
var import_constants = require("../constants");
|
|
43
|
+
var import_utils2 = require("../utils");
|
|
44
|
+
class UpdateOrCreateInstruction extends import__.Instruction {
|
|
45
|
+
async run(node, input, processor) {
|
|
46
|
+
var _a, _b, _c, _d;
|
|
47
|
+
const { collection, params: { appends = [], ...params } = {} } = node.config;
|
|
48
|
+
const [dataSourceName, collectionName] = (0, import_data_source.parseCollectionName)(collection);
|
|
49
|
+
const { repository, filterTargetKey } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
|
|
50
|
+
const options = processor.getParsedValue(params, node.id);
|
|
51
|
+
const transaction = this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction);
|
|
52
|
+
const c = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
|
|
53
|
+
const fields = c.getFields();
|
|
54
|
+
const fieldNames = Object.keys(params.values);
|
|
55
|
+
const includesFields = fields.filter((field) => fieldNames.includes(field.options.name));
|
|
56
|
+
const userId = import_lodash.default.get(processor.getScope(node.id), "$context.user.id", "");
|
|
57
|
+
const token = this.workflow.app.authManager.jwt.sign({ userId });
|
|
58
|
+
const isJSON = (str) => {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(str);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const handleResource = async (resource) => {
|
|
66
|
+
if (typeof resource === "object" && (resource == null ? void 0 : resource.url) && (resource == null ? void 0 : resource.filename)) {
|
|
67
|
+
const {
|
|
68
|
+
id,
|
|
69
|
+
createdAt,
|
|
70
|
+
updatedAt,
|
|
71
|
+
title,
|
|
72
|
+
filename,
|
|
73
|
+
extname,
|
|
74
|
+
size,
|
|
75
|
+
mimetype,
|
|
76
|
+
path,
|
|
77
|
+
meta,
|
|
78
|
+
url,
|
|
79
|
+
createById,
|
|
80
|
+
updatedById,
|
|
81
|
+
storageId
|
|
82
|
+
} = resource;
|
|
83
|
+
return {
|
|
84
|
+
id,
|
|
85
|
+
createdAt,
|
|
86
|
+
updatedAt,
|
|
87
|
+
title,
|
|
88
|
+
filename,
|
|
89
|
+
extname,
|
|
90
|
+
size,
|
|
91
|
+
mimetype,
|
|
92
|
+
path,
|
|
93
|
+
meta,
|
|
94
|
+
url,
|
|
95
|
+
createById,
|
|
96
|
+
updatedById,
|
|
97
|
+
storageId
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const parseRes = isJSON(resource);
|
|
101
|
+
const config = {
|
|
102
|
+
method: "get",
|
|
103
|
+
url: resource,
|
|
104
|
+
responseType: "stream"
|
|
105
|
+
};
|
|
106
|
+
const form = new import_form_data.default();
|
|
107
|
+
if (resource.startsWith("data:")) {
|
|
108
|
+
const matches = resource.match(/^data:(.+);base64,(.+)$/);
|
|
109
|
+
if (matches) {
|
|
110
|
+
const contentType = matches[1];
|
|
111
|
+
const base64Data = matches[2];
|
|
112
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
113
|
+
const ext = import_mime_types.default.extension(contentType);
|
|
114
|
+
const filename = `${(0, import_utils.uid)()}.${ext}`;
|
|
115
|
+
form.append("file", buffer, {
|
|
116
|
+
filename,
|
|
117
|
+
contentType
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error("Invalid data URL format");
|
|
121
|
+
}
|
|
122
|
+
} else if (parseRes) {
|
|
123
|
+
const {
|
|
124
|
+
url: resourceUrl,
|
|
125
|
+
params: resourceParams,
|
|
126
|
+
headers: resourceHeaders,
|
|
127
|
+
body: resourceBody,
|
|
128
|
+
filename
|
|
129
|
+
} = parseRes;
|
|
130
|
+
config.url = resourceUrl;
|
|
131
|
+
config.params = resourceParams;
|
|
132
|
+
config.headers = resourceHeaders;
|
|
133
|
+
if (resourceHeaders["content-type"] === "multipart/form-data") {
|
|
134
|
+
const formData = new import_form_data.default();
|
|
135
|
+
Object.entries(resourceBody).forEach(([key, value]) => {
|
|
136
|
+
formData.append(key, value);
|
|
137
|
+
});
|
|
138
|
+
config.data = formData;
|
|
139
|
+
} else {
|
|
140
|
+
config.data = resourceBody;
|
|
141
|
+
}
|
|
142
|
+
const response = await (0, import_axios.default)(config);
|
|
143
|
+
const contentType = response.headers["content-type"];
|
|
144
|
+
const ext = import_mime_types.default.extension(contentType);
|
|
145
|
+
const fullFilename = `${filename || (0, import_utils.uid)()}.${ext}`;
|
|
146
|
+
form.append("file", response.data, {
|
|
147
|
+
filename: fullFilename,
|
|
148
|
+
contentType: response.headers["content-type"]
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
const response = await (0, import_axios.default)(config);
|
|
152
|
+
const contentType = response.headers["content-type"];
|
|
153
|
+
const ext = import_mime_types.default.extension(contentType);
|
|
154
|
+
const filename = `${(0, import_utils.uid)()}.${ext}`;
|
|
155
|
+
form.append("file", response.data, {
|
|
156
|
+
filename,
|
|
157
|
+
contentType: response.headers["content-type"]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const origin = import_server.Gateway.getInstance().runAtLoop;
|
|
161
|
+
const uploadResponse = await (0, import_axios.default)({
|
|
162
|
+
method: "post",
|
|
163
|
+
url: origin + "/api/attachments:create",
|
|
164
|
+
data: form,
|
|
165
|
+
headers: {
|
|
166
|
+
...form.getHeaders(),
|
|
167
|
+
Authorization: "Bearer " + token
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
return uploadResponse.data.data;
|
|
171
|
+
};
|
|
172
|
+
for (const attachmentField of includesFields) {
|
|
173
|
+
if (attachmentField.options.interface === "attachment") {
|
|
174
|
+
let targetField = options.values[attachmentField.options.name];
|
|
175
|
+
if (Array.isArray(targetField)) {
|
|
176
|
+
for (const i in targetField) {
|
|
177
|
+
targetField[i] = await handleResource(targetField[i]);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
options.values[attachmentField.options.name] = [await handleResource(targetField)];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const instance = await repository.findOne({ filter: options.filter, transaction });
|
|
185
|
+
if (instance) {
|
|
186
|
+
const result = await repository.update({
|
|
187
|
+
...options,
|
|
188
|
+
context: {
|
|
189
|
+
stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id))),
|
|
190
|
+
state: (_b = (_a = processor.options) == null ? void 0 : _a.httpContext) == null ? void 0 : _b.state
|
|
191
|
+
},
|
|
192
|
+
transaction
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
result: result.length ?? result,
|
|
196
|
+
status: import_constants.JOB_STATUS.RESOLVED
|
|
197
|
+
};
|
|
198
|
+
} else {
|
|
199
|
+
const created = await repository.create({
|
|
200
|
+
...options,
|
|
201
|
+
context: {
|
|
202
|
+
stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id))),
|
|
203
|
+
state: (_d = (_c = processor.options) == null ? void 0 : _c.httpContext) == null ? void 0 : _d.state
|
|
204
|
+
},
|
|
205
|
+
transaction
|
|
206
|
+
});
|
|
207
|
+
let result = created;
|
|
208
|
+
if (created && appends.length) {
|
|
209
|
+
const includeFields = appends.reduce((set, field) => {
|
|
210
|
+
set.add(field.split(".")[0]);
|
|
211
|
+
set.add(field);
|
|
212
|
+
return set;
|
|
213
|
+
}, /* @__PURE__ */ new Set());
|
|
214
|
+
result = await repository.findOne({
|
|
215
|
+
filterByTk: created[filterTargetKey],
|
|
216
|
+
appends: Array.from(includeFields),
|
|
217
|
+
transaction
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
// NOTE: get() for non-proxied instance (#380)
|
|
222
|
+
result: (0, import_utils2.toJSON)(result),
|
|
223
|
+
status: import_constants.JOB_STATUS.RESOLVED
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
var UpdateOrCreateInstruction_default = UpdateOrCreateInstruction;
|
|
229
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
230
|
+
0 && (module.exports = {
|
|
231
|
+
UpdateOrCreateInstruction
|
|
232
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/module-workflow",
|
|
3
3
|
"displayName": "Workflow",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"description": "A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Workflow"
|
|
@@ -35,24 +35,24 @@
|
|
|
35
35
|
"react-js-cron": "^3.2.0",
|
|
36
36
|
"react-router-dom": "6.28.1",
|
|
37
37
|
"sequelize": "^6.37.5",
|
|
38
|
-
"@tachybase/
|
|
39
|
-
"@tachybase/
|
|
38
|
+
"@tachybase/components": "1.0.6",
|
|
39
|
+
"@tachybase/plugin-workflow-test": "1.0.6"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@tachybase/actions": "0.
|
|
43
|
-
"@tachybase/
|
|
44
|
-
"@tachybase/
|
|
45
|
-
"@tachybase/
|
|
46
|
-
"@tachybase/logger": "0.
|
|
47
|
-
"@tachybase/
|
|
48
|
-
"@tachybase/
|
|
49
|
-
"@tachybase/module-
|
|
50
|
-
"@tachybase/
|
|
51
|
-
"@tachybase/
|
|
52
|
-
"@tachybase/server": "0.
|
|
53
|
-
"@tachybase/
|
|
54
|
-
"@tachybase/test": "0.
|
|
55
|
-
"@tachybase/utils": "0.
|
|
42
|
+
"@tachybase/actions": "1.0.6",
|
|
43
|
+
"@tachybase/client": "1.0.6",
|
|
44
|
+
"@tachybase/database": "1.0.6",
|
|
45
|
+
"@tachybase/data-source": "1.0.6",
|
|
46
|
+
"@tachybase/logger": "1.0.6",
|
|
47
|
+
"@tachybase/module-collection": "1.0.6",
|
|
48
|
+
"@tachybase/evaluators": "1.0.6",
|
|
49
|
+
"@tachybase/module-error-handler": "1.0.6",
|
|
50
|
+
"@tachybase/module-user": "1.0.6",
|
|
51
|
+
"@tachybase/schema": "1.0.6",
|
|
52
|
+
"@tachybase/server": "1.0.6",
|
|
53
|
+
"@tachybase/resourcer": "1.0.6",
|
|
54
|
+
"@tachybase/test": "1.0.6",
|
|
55
|
+
"@tachybase/utils": "1.0.6"
|
|
56
56
|
},
|
|
57
57
|
"description.zh-CN": "一个强大的 BPM 工具,为业务自动化提供基础支持,并且可任意扩展更多的触发器和节点。",
|
|
58
58
|
"displayName.zh-CN": "工作流",
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var Plugin_exports = {};
|
|
29
|
-
__export(Plugin_exports, {
|
|
30
|
-
PluginWebhook: () => PluginWebhook
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(Plugin_exports);
|
|
33
|
-
var import_path = __toESM(require("path"));
|
|
34
|
-
var import_server = require("@tachybase/server");
|
|
35
|
-
var import_lodash = __toESM(require("lodash"));
|
|
36
|
-
var import_webhooks = require("./webhooks");
|
|
37
|
-
class PluginWebhook extends import_server.Plugin {
|
|
38
|
-
async load() {
|
|
39
|
-
this.app.on("afterStart", async () => {
|
|
40
|
-
const webhooksRepo = this.db.getRepository("webhooks");
|
|
41
|
-
const resources = await webhooksRepo.find({
|
|
42
|
-
filter: {
|
|
43
|
-
enabled: true,
|
|
44
|
-
type: "resource"
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
for (const resourceDef of resources) {
|
|
48
|
-
if (!this.app.resourcer.isDefined(resourceDef.resourceName)) {
|
|
49
|
-
this.app.resourcer.define({ name: resourceDef.resourceName });
|
|
50
|
-
}
|
|
51
|
-
this.app.resourcer.getResource(resourceDef.resourceName).addAction(resourceDef.actionName, async (ctx) => {
|
|
52
|
-
const body = await new import_webhooks.WebhookController().action(ctx, resourceDef);
|
|
53
|
-
await new import_webhooks.WebhookController().triggerWorkflow(ctx, resourceDef, body);
|
|
54
|
-
});
|
|
55
|
-
this.app.acl.allow(resourceDef.resourceName, resourceDef.actionName, "loggedIn");
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
await this.db.import({
|
|
59
|
-
directory: import_path.default.resolve(__dirname, "collections")
|
|
60
|
-
});
|
|
61
|
-
this.app.resourcer.define({
|
|
62
|
-
name: "webhooks",
|
|
63
|
-
actions: {
|
|
64
|
-
trigger: new import_webhooks.WebhookController().getLink,
|
|
65
|
-
test: new import_webhooks.WebhookController().test
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
this.app.acl.allow("webhooks", ["trigger", "test"], "loggedIn");
|
|
69
|
-
const app = this.app;
|
|
70
|
-
this.app.acl.use(
|
|
71
|
-
async (ctx, next) => {
|
|
72
|
-
if (import_lodash.default.isEmpty(ctx.action.params)) {
|
|
73
|
-
await next();
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const { resourceName, actionName } = ctx.action;
|
|
77
|
-
const webhooksRepo = ctx.db.getRepository("webhooks");
|
|
78
|
-
const actions = await app.cache.wrap(
|
|
79
|
-
"webhooks",
|
|
80
|
-
async () => {
|
|
81
|
-
return await webhooksRepo.find({
|
|
82
|
-
filter: {
|
|
83
|
-
enabled: true,
|
|
84
|
-
type: "action"
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
30 * 60 * 1e3
|
|
89
|
-
);
|
|
90
|
-
const actionObj = {};
|
|
91
|
-
const actionList = actions.filter((action) => {
|
|
92
|
-
return resourceName === action["resourceName"] && actionName === action["actionName"];
|
|
93
|
-
});
|
|
94
|
-
for (const action of actionList) {
|
|
95
|
-
actionObj[action.id] = await new import_webhooks.WebhookController().action(ctx, action);
|
|
96
|
-
}
|
|
97
|
-
await next();
|
|
98
|
-
for (const action of actionList) {
|
|
99
|
-
await new import_webhooks.WebhookController().triggerWorkflow(ctx, action, actionObj[action.id]);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
{ tag: "api-webhook", after: "core" }
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
-
0 && (module.exports = {
|
|
108
|
-
PluginWebhook
|
|
109
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PluginWebhook } from './Plugin';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var webhook_exports = {};
|
|
19
|
-
__export(webhook_exports, {
|
|
20
|
-
PluginWebhook: () => import_Plugin.PluginWebhook
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(webhook_exports);
|
|
23
|
-
var import_Plugin = require("./Plugin");
|
|
24
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
-
0 && (module.exports = {
|
|
26
|
-
PluginWebhook
|
|
27
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Context } from '@tachybase/actions';
|
|
2
|
-
export declare class WebhookController {
|
|
3
|
-
getLink(ctx: Context): Promise<never>;
|
|
4
|
-
test(ctx: Context): Promise<void>;
|
|
5
|
-
action(ctx: Context, action: {
|
|
6
|
-
code: string;
|
|
7
|
-
}): Promise<string>;
|
|
8
|
-
triggerWorkflow(ctx: any, action: any, body: any): Promise<void>;
|
|
9
|
-
}
|