@tachybase/module-event-source 0.23.8
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/.turbo/turbo-build.log +6 -0
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/customEventSources/CustomEventSourcePane.d.ts +2 -0
- package/dist/client/customEventSources/CustomEventSourcePane.schema.d.ts +213 -0
- package/dist/client/customEventSources/customEventSourcePane.collection.d.ts +51 -0
- package/dist/client/customEventSources/useSyncCustomEventSource.d.ts +3 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +9 -0
- package/dist/client/locale.d.ts +4 -0
- package/dist/client/webhook/WebhookManager.d.ts +10 -0
- package/dist/client/webhook/collections/dispatchers.d.ts +2 -0
- package/dist/externalVersion.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +5 -0
- package/dist/locale/zh-CN.json +5 -0
- package/dist/server/actions/CustomEventSourceController.d.ts +5 -0
- package/dist/server/actions/CustomEventSourceController.js +196 -0
- package/dist/server/collections/customEventSources.d.ts +14 -0
- package/dist/server/collections/customEventSources.js +58 -0
- package/dist/server/collections/webhooks.d.ts +2 -0
- package/dist/server/collections/webhooks.js +69 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/plugin.d.ts +5 -0
- package/dist/server/plugin.js +89 -0
- package/dist/server/services/ActionAPIService.d.ts +4 -0
- package/dist/server/services/ActionAPIService.js +122 -0
- package/dist/server/services/ApplicationEventService.d.ts +5 -0
- package/dist/server/services/ApplicationEventService.js +124 -0
- package/dist/server/services/BeforeResourceService.d.ts +5 -0
- package/dist/server/services/BeforeResourceService.js +123 -0
- package/dist/server/services/DatabaseEventService.d.ts +5 -0
- package/dist/server/services/DatabaseEventService.js +135 -0
- package/dist/server/services/ResourceService.d.ts +5 -0
- package/dist/server/services/ResourceService.js +114 -0
- package/dist/server/utils/eval-simulate.d.ts +4 -0
- package/dist/server/utils/eval-simulate.js +37 -0
- package/dist/server/webhooks/Plugin.d.ts +4 -0
- package/dist/server/webhooks/Plugin.js +103 -0
- package/dist/server/webhooks/webhooks.d.ts +15 -0
- package/dist/server/webhooks/webhooks.js +272 -0
- package/package.json +29 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
26
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
27
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
28
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
29
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
30
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
31
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
35
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
36
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
37
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
38
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
39
|
+
return __privateGet(this, extra);
|
|
40
|
+
}, set [name](x) {
|
|
41
|
+
return __privateSet(this, extra, x);
|
|
42
|
+
} }, name));
|
|
43
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
44
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
45
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
46
|
+
if (k) {
|
|
47
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
48
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
49
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
50
|
+
}
|
|
51
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
52
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
53
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
54
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
55
|
+
}
|
|
56
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
57
|
+
};
|
|
58
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
59
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
60
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
61
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
62
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
63
|
+
var Plugin_exports = {};
|
|
64
|
+
__export(Plugin_exports, {
|
|
65
|
+
PluginWebhook: () => PluginWebhook
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(Plugin_exports);
|
|
68
|
+
var import_server = require("@tachybase/server");
|
|
69
|
+
var import_ActionAPIService = require("../services/ActionAPIService");
|
|
70
|
+
var import_ApplicationEventService = require("../services/ApplicationEventService");
|
|
71
|
+
var import_BeforeResourceService = require("../services/BeforeResourceService");
|
|
72
|
+
var import_DatabaseEventService = require("../services/DatabaseEventService");
|
|
73
|
+
var import_ResourceService = require("../services/ResourceService");
|
|
74
|
+
var import_webhooks = require("./webhooks");
|
|
75
|
+
var _PluginWebhook_decorators, _init, _a;
|
|
76
|
+
_PluginWebhook_decorators = [(0, import_server.InjectedPlugin)({
|
|
77
|
+
Services: [
|
|
78
|
+
import_ResourceService.ResourceService,
|
|
79
|
+
import_DatabaseEventService.DatabaseEventService,
|
|
80
|
+
import_ApplicationEventService.ApplicationEventService,
|
|
81
|
+
import_BeforeResourceService.BeforeAfterResourceService,
|
|
82
|
+
import_ActionAPIService.ActionAPIService
|
|
83
|
+
]
|
|
84
|
+
})];
|
|
85
|
+
class PluginWebhook extends (_a = import_server.Plugin) {
|
|
86
|
+
async load() {
|
|
87
|
+
this.app.resourcer.define({
|
|
88
|
+
name: "webhooks",
|
|
89
|
+
actions: {
|
|
90
|
+
trigger: new import_webhooks.WebhookController().getLink,
|
|
91
|
+
test: new import_webhooks.WebhookController().test
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.app.acl.allow("webhooks", ["trigger", "test"], "loggedIn");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
_init = __decoratorStart(_a);
|
|
98
|
+
PluginWebhook = __decorateElement(_init, 0, "PluginWebhook", _PluginWebhook_decorators, PluginWebhook);
|
|
99
|
+
__runInitializers(_init, 1, PluginWebhook);
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
PluginWebhook
|
|
103
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Context } from '@tachybase/actions';
|
|
2
|
+
/** 获得真正变动的数据库字段 */
|
|
3
|
+
export declare function getChanged(ctx: Context): () => Promise<{
|
|
4
|
+
changed?: string[];
|
|
5
|
+
data?: any;
|
|
6
|
+
error: Error;
|
|
7
|
+
}>;
|
|
8
|
+
export declare class WebhookController {
|
|
9
|
+
getLink(ctx: Context): Promise<never>;
|
|
10
|
+
test(ctx: Context): Promise<void>;
|
|
11
|
+
action(ctx: Context, action: {
|
|
12
|
+
code: string;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
triggerWorkflow(ctx: any, action: any, body: any): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
getChanged: () => getChanged
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(webhooks_exports);
|
|
34
|
+
var import_module_workflow = require("@tachybase/module-workflow");
|
|
35
|
+
var import_utils = require("@tachybase/utils");
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
var import_eval_simulate = require("../utils/eval-simulate");
|
|
38
|
+
function isSameBasic(val1, val2) {
|
|
39
|
+
if (val1 instanceof Date || val2 instanceof Date) {
|
|
40
|
+
return new Date(val1).getTime() === new Date(val2).getTime();
|
|
41
|
+
}
|
|
42
|
+
return val1 === val2;
|
|
43
|
+
}
|
|
44
|
+
function getLostKey(smallOne, bigOne, path = "") {
|
|
45
|
+
const lostKeys = /* @__PURE__ */ new Set();
|
|
46
|
+
if (typeof bigOne !== "object" || bigOne === null) {
|
|
47
|
+
if (smallOne === void 0) {
|
|
48
|
+
return [path];
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
const bigKeys = Object.keys(bigOne);
|
|
53
|
+
for (const key of bigKeys) {
|
|
54
|
+
let keyLabel = path ? `${path}.${key}` : key;
|
|
55
|
+
if (Array.isArray(bigOne)) {
|
|
56
|
+
keyLabel = path;
|
|
57
|
+
}
|
|
58
|
+
if ((smallOne == null ? void 0 : smallOne[key]) === void 0) {
|
|
59
|
+
lostKeys.add(keyLabel);
|
|
60
|
+
continue;
|
|
61
|
+
} else {
|
|
62
|
+
const result = getLostKey(smallOne == null ? void 0 : smallOne[key], bigOne == null ? void 0 : bigOne[key], keyLabel);
|
|
63
|
+
for (const item of result) {
|
|
64
|
+
lostKeys.add(item);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return [...lostKeys];
|
|
69
|
+
}
|
|
70
|
+
function getDiffKeyExceptAfter(before, after, path = "") {
|
|
71
|
+
if (after === null || after === void 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
if (typeof before !== "object" || typeof after !== "object" || before === null || after === null) {
|
|
75
|
+
if (!isSameBasic(before, after)) {
|
|
76
|
+
return [path];
|
|
77
|
+
} else {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (Array.isArray(before) && Array.isArray(after) && before.length !== after.length) {
|
|
82
|
+
return [path];
|
|
83
|
+
}
|
|
84
|
+
const beforeDiffKeys = /* @__PURE__ */ new Set();
|
|
85
|
+
const beforeKeys = Object.keys(before);
|
|
86
|
+
for (const key of beforeKeys) {
|
|
87
|
+
if ((after == null ? void 0 : after[key]) === void 0) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
let keyLabel = path ? `${path}.${key}` : key;
|
|
91
|
+
if (Array.isArray(after)) {
|
|
92
|
+
keyLabel = path;
|
|
93
|
+
}
|
|
94
|
+
if ((before == null ? void 0 : before[key]) === void 0) {
|
|
95
|
+
beforeDiffKeys.add(keyLabel);
|
|
96
|
+
continue;
|
|
97
|
+
} else {
|
|
98
|
+
const result = getDiffKeyExceptAfter(before == null ? void 0 : before[key], after == null ? void 0 : after[key], keyLabel);
|
|
99
|
+
for (const item of result) {
|
|
100
|
+
beforeDiffKeys.add(item);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return [...beforeDiffKeys];
|
|
105
|
+
}
|
|
106
|
+
function getChanged(ctx) {
|
|
107
|
+
return async function() {
|
|
108
|
+
try {
|
|
109
|
+
const params = import_lodash.default.cloneDeep(ctx.action.params);
|
|
110
|
+
const repo = ctx.db.getRepository(ctx.action.resourceName);
|
|
111
|
+
const fieldsObj = {};
|
|
112
|
+
const app = ctx.app;
|
|
113
|
+
const c = app.mainDataSource.collectionManager.getCollection(ctx.action.resourceName);
|
|
114
|
+
const fields = c.getFields();
|
|
115
|
+
for (const field of fields) {
|
|
116
|
+
fieldsObj[field.options.name] = field;
|
|
117
|
+
}
|
|
118
|
+
let appendSet = /* @__PURE__ */ new Set();
|
|
119
|
+
if (params.updateAssociationValues) {
|
|
120
|
+
appendSet = new Set(params.updateAssociationValues);
|
|
121
|
+
}
|
|
122
|
+
for (const key of appendSet) {
|
|
123
|
+
if (!fieldsObj[key]) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const type = fieldsObj[key].options.type;
|
|
127
|
+
if (type === "virtual") {
|
|
128
|
+
appendSet.delete(key);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let dataBefore = (await repo.findOne({
|
|
133
|
+
filter: {
|
|
134
|
+
id: params.filterByTk
|
|
135
|
+
},
|
|
136
|
+
appends: [...appendSet]
|
|
137
|
+
})).toJSON();
|
|
138
|
+
const lostKeys = getLostKey(dataBefore, params.values);
|
|
139
|
+
for (const lostKey of lostKeys) {
|
|
140
|
+
if (lostKey.includes(".") || fieldsObj[lostKey] !== void 0 && ["belongsTo", "belongsToMany", "hasOne", "hasMany"].includes(fieldsObj[lostKey].options.type)) {
|
|
141
|
+
appendSet.add(lostKey);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
dataBefore = (await repo.findOne({
|
|
145
|
+
filter: {
|
|
146
|
+
id: params.filterByTk
|
|
147
|
+
},
|
|
148
|
+
appends: [...appendSet]
|
|
149
|
+
})).toJSON();
|
|
150
|
+
const changed = getDiffKeyExceptAfter(dataBefore, params.values);
|
|
151
|
+
return {
|
|
152
|
+
error: null,
|
|
153
|
+
data: dataBefore,
|
|
154
|
+
changed
|
|
155
|
+
};
|
|
156
|
+
} catch (err) {
|
|
157
|
+
ctx.log.error(err);
|
|
158
|
+
return {
|
|
159
|
+
error: err.stack
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
class WebhookController {
|
|
165
|
+
async getLink(ctx) {
|
|
166
|
+
const {
|
|
167
|
+
params: { name }
|
|
168
|
+
} = ctx.action;
|
|
169
|
+
const where = {};
|
|
170
|
+
if (name) {
|
|
171
|
+
where["filter"] = {
|
|
172
|
+
name,
|
|
173
|
+
type: "code",
|
|
174
|
+
enabled: true
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (!name) {
|
|
178
|
+
throw new Error("not support");
|
|
179
|
+
}
|
|
180
|
+
const { currentUser, currentRole } = ctx.state;
|
|
181
|
+
const { model: UserModel } = ctx.db.getCollection("users");
|
|
182
|
+
const userInfo = {
|
|
183
|
+
user: UserModel.build(currentUser).desensitize(),
|
|
184
|
+
roleName: currentRole
|
|
185
|
+
};
|
|
186
|
+
const pluginWorkflow = ctx.app.getPlugin(import_module_workflow.PluginWorkflow);
|
|
187
|
+
const repo = ctx.db.getRepository("webhooks");
|
|
188
|
+
const webhook = await repo.findOne(where);
|
|
189
|
+
const webhookCtx = {
|
|
190
|
+
request: ctx.request,
|
|
191
|
+
action: ctx.action,
|
|
192
|
+
body: ""
|
|
193
|
+
};
|
|
194
|
+
await (0, import_eval_simulate.evalSimulate)(webhook.code, {
|
|
195
|
+
ctx: webhookCtx,
|
|
196
|
+
lib: {
|
|
197
|
+
JSON,
|
|
198
|
+
Math,
|
|
199
|
+
dayjs: import_utils.dayjs
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
if (webhook == null ? void 0 : webhook.workflowKey) {
|
|
203
|
+
const wfRepo = ctx.db.getRepository("workflows");
|
|
204
|
+
const wf = await wfRepo.findOne({ filter: { key: webhook.workflowKey, enabled: true } });
|
|
205
|
+
const processor = await pluginWorkflow.trigger(wf, { data: webhookCtx.body, ...userInfo }, { httpContext: ctx });
|
|
206
|
+
if (!processor) {
|
|
207
|
+
return ctx.throw("Workflow should be sync.", 500);
|
|
208
|
+
}
|
|
209
|
+
const { lastSavedJob } = processor;
|
|
210
|
+
if (typeof ctx.body === "undefined") {
|
|
211
|
+
ctx.withoutDataWrapping = true;
|
|
212
|
+
ctx.body = lastSavedJob.result;
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (webhookCtx.body) {
|
|
217
|
+
ctx.withoutDataWrapping = true;
|
|
218
|
+
ctx.body = webhookCtx.body;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async test(ctx) {
|
|
223
|
+
const { name, params, body } = ctx.action.params.values;
|
|
224
|
+
ctx.request.query = params;
|
|
225
|
+
ctx.action.params = params || {};
|
|
226
|
+
ctx.action.params.name = name;
|
|
227
|
+
ctx.action.params.values = body;
|
|
228
|
+
await new WebhookController().getLink(ctx);
|
|
229
|
+
}
|
|
230
|
+
async action(ctx, action) {
|
|
231
|
+
const webhookCtx = {
|
|
232
|
+
request: ctx.request,
|
|
233
|
+
action: ctx.action,
|
|
234
|
+
body: "",
|
|
235
|
+
getChanged: getChanged(ctx)
|
|
236
|
+
};
|
|
237
|
+
try {
|
|
238
|
+
await (0, import_eval_simulate.evalSimulate)(action.code, {
|
|
239
|
+
ctx: webhookCtx,
|
|
240
|
+
lib: {
|
|
241
|
+
JSON,
|
|
242
|
+
Math,
|
|
243
|
+
dayjs: import_utils.dayjs
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return webhookCtx.body;
|
|
247
|
+
} catch (err) {
|
|
248
|
+
ctx.app.log.error(err);
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async triggerWorkflow(ctx, action, body) {
|
|
253
|
+
const { currentUser, currentRole } = ctx.state;
|
|
254
|
+
const { model: UserModel } = ctx.db.getCollection("users");
|
|
255
|
+
if (!action.workflowKey) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const userInfo = {
|
|
259
|
+
user: UserModel.build(currentUser).desensitize(),
|
|
260
|
+
roleName: currentRole
|
|
261
|
+
};
|
|
262
|
+
const pluginWorkflow = ctx.app.getPlugin(import_module_workflow.PluginWorkflow);
|
|
263
|
+
const wfRepo = ctx.db.getRepository("workflows");
|
|
264
|
+
const wf = await wfRepo.findOne({ filter: { key: action.workflowKey, enabled: true } });
|
|
265
|
+
await pluginWorkflow.trigger(wf, { data: body, ...userInfo }, { httpContext: ctx });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
270
|
+
WebhookController,
|
|
271
|
+
getChanged
|
|
272
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/module-event-source",
|
|
3
|
+
"version": "0.23.8",
|
|
4
|
+
"main": "dist/server/index.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"antd": "5.22.5",
|
|
7
|
+
"lodash": "4.17.21",
|
|
8
|
+
"sequelize": "6.37.5"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/lodash": "4.17.13"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@tachybase/actions": "0.23.8",
|
|
15
|
+
"@tachybase/client": "0.23.8",
|
|
16
|
+
"@tachybase/components": "0.23.8",
|
|
17
|
+
"@tachybase/schema": "0.23.8",
|
|
18
|
+
"@tachybase/database": "0.23.8",
|
|
19
|
+
"@tachybase/server": "0.23.8",
|
|
20
|
+
"@tachybase/module-workflow": "0.23.8",
|
|
21
|
+
"@tachybase/test": "0.23.8",
|
|
22
|
+
"@tachybase/utils": "0.23.8",
|
|
23
|
+
"@tachybase/data-source": "0.23.8",
|
|
24
|
+
"@tachybase/resourcer": "0.23.8"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tachybase-build --no-dts @tachybase/module-event-source"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|