@tachybase/module-workflow 0.23.47 → 0.23.58
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/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 +10 -10
- package/dist/client/nodes/calculation.d.ts +12 -0
- package/dist/client/nodes/condition.d.ts +12 -0
- package/dist/client/nodes/end.d.ts +12 -0
- package/dist/client/variable.d.ts +1 -5
- package/dist/externalVersion.js +15 -15
- package/dist/locale/en-US.json +4 -0
- package/dist/locale/zh-CN.json +4 -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 +21 -12
- package/dist/server/Processor.d.ts +1 -0
- package/dist/server/Processor.js +2 -1
- package/dist/server/features/interception/RequestInterceptionTrigger.js +4 -1
- package/dist/server/features/omni-trigger/CustomActionTrigger.js +4 -1
- 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
|
@@ -1,286 +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 webhooks_exports = {};
|
|
29
|
-
__export(webhooks_exports, {
|
|
30
|
-
WebhookController: () => WebhookController
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(webhooks_exports);
|
|
33
|
-
var import_utils = require("@tachybase/utils");
|
|
34
|
-
var import_lodash = __toESM(require("lodash"));
|
|
35
|
-
var import__ = require("../..");
|
|
36
|
-
function isSameBasic(val1, val2) {
|
|
37
|
-
if (val1 instanceof Date || val2 instanceof Date) {
|
|
38
|
-
return new Date(val1).getTime() === new Date(val2).getTime();
|
|
39
|
-
}
|
|
40
|
-
return val1 === val2;
|
|
41
|
-
}
|
|
42
|
-
function getLostKey(smallOne, bigOne, path = "") {
|
|
43
|
-
const lostKeys = /* @__PURE__ */ new Set();
|
|
44
|
-
if (typeof bigOne !== "object" || bigOne === null) {
|
|
45
|
-
if (smallOne === void 0) {
|
|
46
|
-
return [path];
|
|
47
|
-
}
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const bigKeys = Object.keys(bigOne);
|
|
51
|
-
for (const key of bigKeys) {
|
|
52
|
-
let keyLabel = path ? `${path}.${key}` : key;
|
|
53
|
-
if (Array.isArray(bigOne)) {
|
|
54
|
-
keyLabel = path;
|
|
55
|
-
}
|
|
56
|
-
if ((smallOne == null ? void 0 : smallOne[key]) === void 0) {
|
|
57
|
-
lostKeys.add(keyLabel);
|
|
58
|
-
continue;
|
|
59
|
-
} else {
|
|
60
|
-
const result = getLostKey(smallOne == null ? void 0 : smallOne[key], bigOne == null ? void 0 : bigOne[key], keyLabel);
|
|
61
|
-
for (const item of result) {
|
|
62
|
-
lostKeys.add(item);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return [...lostKeys];
|
|
67
|
-
}
|
|
68
|
-
function getDiffKeyExceptAfter(before, after, path = "") {
|
|
69
|
-
if (after === null || after === void 0) {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
if (typeof before !== "object" || typeof after !== "object" || before === null || after === null) {
|
|
73
|
-
if (!isSameBasic(before, after)) {
|
|
74
|
-
return [path];
|
|
75
|
-
} else {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (Array.isArray(before) && Array.isArray(after) && before.length !== after.length) {
|
|
80
|
-
return [path];
|
|
81
|
-
}
|
|
82
|
-
const beforeDiffKeys = /* @__PURE__ */ new Set();
|
|
83
|
-
const beforeKeys = Object.keys(before);
|
|
84
|
-
for (const key of beforeKeys) {
|
|
85
|
-
if ((after == null ? void 0 : after[key]) === void 0) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
let keyLabel = path ? `${path}.${key}` : key;
|
|
89
|
-
if (Array.isArray(after)) {
|
|
90
|
-
keyLabel = path;
|
|
91
|
-
}
|
|
92
|
-
if ((before == null ? void 0 : before[key]) === void 0) {
|
|
93
|
-
beforeDiffKeys.add(keyLabel);
|
|
94
|
-
continue;
|
|
95
|
-
} else {
|
|
96
|
-
const result = getDiffKeyExceptAfter(before == null ? void 0 : before[key], after == null ? void 0 : after[key], keyLabel);
|
|
97
|
-
for (const item of result) {
|
|
98
|
-
beforeDiffKeys.add(item);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return [...beforeDiffKeys];
|
|
103
|
-
}
|
|
104
|
-
function getChanged(ctx) {
|
|
105
|
-
return async function() {
|
|
106
|
-
try {
|
|
107
|
-
const params = import_lodash.default.cloneDeep(ctx.action.params);
|
|
108
|
-
const repo = ctx.db.getRepository(ctx.action.resourceName);
|
|
109
|
-
const fieldsObj = {};
|
|
110
|
-
const app = ctx.app;
|
|
111
|
-
const c = app.mainDataSource.collectionManager.getCollection(ctx.action.resourceName);
|
|
112
|
-
const fields = c.getFields();
|
|
113
|
-
for (const field of fields) {
|
|
114
|
-
fieldsObj[field.options.name] = field;
|
|
115
|
-
}
|
|
116
|
-
let appendSet = /* @__PURE__ */ new Set();
|
|
117
|
-
if (params.updateAssociationValues) {
|
|
118
|
-
appendSet = new Set(params.updateAssociationValues);
|
|
119
|
-
}
|
|
120
|
-
for (const key of appendSet) {
|
|
121
|
-
if (!fieldsObj[key]) {
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
const type = fieldsObj[key].options.type;
|
|
125
|
-
if (type === "virtual") {
|
|
126
|
-
appendSet.delete(key);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
let dataBefore = (await repo.findOne({
|
|
131
|
-
filter: {
|
|
132
|
-
id: params.filterByTk
|
|
133
|
-
},
|
|
134
|
-
appends: [...appendSet]
|
|
135
|
-
})).toJSON();
|
|
136
|
-
const lostKeys = getLostKey(dataBefore, params.values);
|
|
137
|
-
for (const lostKey of lostKeys) {
|
|
138
|
-
if (lostKey.includes(".") || fieldsObj[lostKey] !== void 0 && ["belongsTo", "belongsToMany", "hasOne", "hasMany"].includes(fieldsObj[lostKey].options.type)) {
|
|
139
|
-
appendSet.add(lostKey);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
dataBefore = (await repo.findOne({
|
|
143
|
-
filter: {
|
|
144
|
-
id: params.filterByTk
|
|
145
|
-
},
|
|
146
|
-
appends: [...appendSet]
|
|
147
|
-
})).toJSON();
|
|
148
|
-
const changed = getDiffKeyExceptAfter(dataBefore, params.values);
|
|
149
|
-
return {
|
|
150
|
-
error: null,
|
|
151
|
-
data: dataBefore,
|
|
152
|
-
changed
|
|
153
|
-
};
|
|
154
|
-
} catch (err) {
|
|
155
|
-
ctx.log.error(err);
|
|
156
|
-
return {
|
|
157
|
-
error: err.stack
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
class WebhookController {
|
|
163
|
-
async getLink(ctx) {
|
|
164
|
-
const {
|
|
165
|
-
params: { name }
|
|
166
|
-
} = ctx.action;
|
|
167
|
-
const where = {};
|
|
168
|
-
if (name) {
|
|
169
|
-
where["filter"] = {
|
|
170
|
-
name,
|
|
171
|
-
type: "code",
|
|
172
|
-
enabled: true
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
if (!name) {
|
|
176
|
-
throw new Error("not support");
|
|
177
|
-
}
|
|
178
|
-
const { currentUser, currentRole } = ctx.state;
|
|
179
|
-
const { model: UserModel } = ctx.db.getCollection("users");
|
|
180
|
-
const userInfo = {
|
|
181
|
-
user: UserModel.build(currentUser).desensitize(),
|
|
182
|
-
roleName: currentRole
|
|
183
|
-
};
|
|
184
|
-
const pluginWorkflow = ctx.app.getPlugin(import__.PluginWorkflow);
|
|
185
|
-
const repo = ctx.db.getRepository("webhooks");
|
|
186
|
-
const webhook = await repo.findOne(where);
|
|
187
|
-
const webhookCtx = {
|
|
188
|
-
request: ctx.request,
|
|
189
|
-
action: ctx.action,
|
|
190
|
-
body: ""
|
|
191
|
-
};
|
|
192
|
-
run(webhook.code, {
|
|
193
|
-
ctx: webhookCtx,
|
|
194
|
-
lib: {
|
|
195
|
-
JSON,
|
|
196
|
-
Math,
|
|
197
|
-
dayjs: import_utils.dayjs
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
if (webhook == null ? void 0 : webhook.workflowKey) {
|
|
201
|
-
const wfRepo = ctx.db.getRepository("workflows");
|
|
202
|
-
const wf = await wfRepo.findOne({ filter: { key: webhook.workflowKey, enabled: true } });
|
|
203
|
-
const processor = await pluginWorkflow.trigger(wf, { data: webhookCtx.body, ...userInfo }, { httpContext: ctx });
|
|
204
|
-
if (!processor) {
|
|
205
|
-
return ctx.throw("Workflow should be sync.", 500);
|
|
206
|
-
}
|
|
207
|
-
const { lastSavedJob } = processor;
|
|
208
|
-
if (typeof ctx.body === "undefined") {
|
|
209
|
-
ctx.withoutDataWrapping = true;
|
|
210
|
-
ctx.body = lastSavedJob.result;
|
|
211
|
-
}
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (webhookCtx.body) {
|
|
215
|
-
ctx.withoutDataWrapping = true;
|
|
216
|
-
ctx.body = webhookCtx.body;
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
async test(ctx) {
|
|
221
|
-
const { name, params, body } = ctx.action.params.values;
|
|
222
|
-
ctx.request.query = params;
|
|
223
|
-
ctx.action.params = params || {};
|
|
224
|
-
ctx.action.params.name = name;
|
|
225
|
-
ctx.action.params.values = body;
|
|
226
|
-
await new WebhookController().getLink(ctx);
|
|
227
|
-
}
|
|
228
|
-
async action(ctx, action) {
|
|
229
|
-
const webhookCtx = {
|
|
230
|
-
request: ctx.request,
|
|
231
|
-
action: ctx.action,
|
|
232
|
-
body: "",
|
|
233
|
-
getChanged: getChanged(ctx)
|
|
234
|
-
};
|
|
235
|
-
try {
|
|
236
|
-
await evalSimulate(action.code, {
|
|
237
|
-
ctx: webhookCtx,
|
|
238
|
-
lib: {
|
|
239
|
-
JSON,
|
|
240
|
-
Math,
|
|
241
|
-
dayjs: import_utils.dayjs
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
return webhookCtx.body;
|
|
245
|
-
} catch (err) {
|
|
246
|
-
ctx.app.log.error(err);
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
async triggerWorkflow(ctx, action, body) {
|
|
251
|
-
const { currentUser, currentRole } = ctx.state;
|
|
252
|
-
const { model: UserModel } = ctx.db.getCollection("users");
|
|
253
|
-
if (!action.workflowKey) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const userInfo = {
|
|
257
|
-
user: UserModel.build(currentUser).desensitize(),
|
|
258
|
-
roleName: currentRole
|
|
259
|
-
};
|
|
260
|
-
const pluginWorkflow = ctx.app.getPlugin(import__.PluginWorkflow);
|
|
261
|
-
const wfRepo = ctx.db.getRepository("workflows");
|
|
262
|
-
const wf = await wfRepo.findOne({ filter: { key: action.workflowKey, enabled: true } });
|
|
263
|
-
await pluginWorkflow.trigger(wf, { data: body, ...userInfo }, { httpContext: ctx });
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function run(jsCode, { ctx, lib }) {
|
|
267
|
-
try {
|
|
268
|
-
return new Function("$root", `with($root) { ${jsCode}; }`)({ ctx, lib });
|
|
269
|
-
} catch (err) {
|
|
270
|
-
console.log("err", err);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async function evalSimulate(jsCode, { ctx, lib }) {
|
|
274
|
-
const AsyncFunction = async function() {
|
|
275
|
-
}.constructor;
|
|
276
|
-
return await new AsyncFunction("$root", `with($root) { ${jsCode}; }`)({
|
|
277
|
-
ctx,
|
|
278
|
-
// 允许用户覆盖,这个时候可以使用 _ctx
|
|
279
|
-
__ctx: ctx,
|
|
280
|
-
lib
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
284
|
-
0 && (module.exports = {
|
|
285
|
-
WebhookController
|
|
286
|
-
});
|