@nocobase/plugin-workflow-javascript 2.1.0-beta.8 → 2.2.0-alpha.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.
- package/build.config.ts +52 -0
- package/dist/client/615.a016da4e5f572288.js +10 -0
- package/dist/client/944.18159d8a1521708e.js +10 -0
- package/dist/client/CodeEditor.d.ts +8 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +4 -4
- package/dist/node_modules/@jitl/quickjs-ffi-types/LICENSE +21 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/README.md +5 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.d.mts +549 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.d.ts +549 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.js +2 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-ffi-types/package.json +36 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/LICENSE +47 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/README.md +93 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.browser.d.ts +15 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.browser.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.cjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.cloudflare.cjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.cloudflare.d.ts +15 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.d.ts +15 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.wasm +0 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.wasm.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.d.mts +94 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.d.ts +94 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.d.mts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.d.ts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/package.json +61 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/LICENSE +47 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/README.md +88 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.browser.d.ts +11 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.browser.mjs +5430 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.cjs +5485 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.cloudflare.cjs +5424 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.cloudflare.d.ts +11 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.d.ts +11 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.mjs +5541 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.wasm +0 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.wasm.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.d.mts +85 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.d.ts +85 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.d.mts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.d.ts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/package.json +61 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/LICENSE +47 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/README.md +89 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.browser.d.ts +15 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.browser.mjs +26 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.cjs +25 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.cloudflare.cjs +25 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.cloudflare.d.ts +15 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.d.ts +15 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.mjs +30 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.wasm +0 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.d.mts +94 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.d.ts +94 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.d.mts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.d.ts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/package.json +61 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/LICENSE +47 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/README.md +82 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.d.ts +11 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.mjs +22 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.cjs +21 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.cloudflare.cjs +21 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.cloudflare.d.ts +11 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.d.ts +11 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.mjs +25 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.wasm +0 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.d.mts +85 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.d.ts +85 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.d.mts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.d.ts +20 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.js +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.js.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.mjs +2 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.mjs.map +1 -0
- package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/package.json +61 -0
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +178 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1067 -0
- package/dist/node_modules/joi/lib/types/link.js +168 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/node_modules/quickjs-emscripten/LICENSE +21 -0
- package/dist/node_modules/quickjs-emscripten/README.md +928 -0
- package/dist/node_modules/quickjs-emscripten/dist/chunk-OHAYRCBA.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten/dist/chunk-OHAYRCBA.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.d.mts +57 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.d.ts +57 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.global.js +7309 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.js +2 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.js.map +1 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten/dist/index.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten/dist/variants.d.mts +39 -0
- package/dist/node_modules/quickjs-emscripten/dist/variants.d.ts +39 -0
- package/dist/node_modules/quickjs-emscripten/dist/variants.js +2 -0
- package/dist/node_modules/quickjs-emscripten/dist/variants.js.map +1 -0
- package/dist/node_modules/quickjs-emscripten/dist/variants.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten/dist/variants.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten/package.json +69 -0
- package/dist/node_modules/quickjs-emscripten-core/LICENSE +21 -0
- package/dist/node_modules/quickjs-emscripten-core/README.md +341 -0
- package/dist/node_modules/quickjs-emscripten-core/README.template.md +70 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/chunk-TAV5CUKK.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/chunk-TAV5CUKK.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/chunk-V2S4ZYJR.mjs +7 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/chunk-V2S4ZYJR.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/index.d.mts +2033 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/index.d.ts +2033 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/index.js +7 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/index.js.map +1 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/index.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/index.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/module-ES6BEMUI.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/module-ES6BEMUI.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/module-asyncify-2EFITU5U.mjs +2 -0
- package/dist/node_modules/quickjs-emscripten-core/dist/module-asyncify-2EFITU5U.mjs.map +1 -0
- package/dist/node_modules/quickjs-emscripten-core/package.json +49 -0
- package/dist/node_modules/winston-transport/index.js +2 -2
- package/dist/node_modules/winston-transport/package.json +1 -1
- package/dist/server/QuickJs.js +145 -0
- package/dist/server/ScriptInstruction.d.ts +24 -10
- package/dist/server/ScriptInstruction.js +51 -11
- package/dist/server/Vm.js +42 -27
- package/package.json +4 -7
- package/dist/client/907399554f340b0a.js +0 -10
- package/dist/client/d608e8e5c2f2b5cf.js +0 -10
|
@@ -43,15 +43,29 @@ var import_node_events = require("node:events");
|
|
|
43
43
|
var import_node_path = __toESM(require("node:path"));
|
|
44
44
|
var import_node_worker_threads = require("node:worker_threads");
|
|
45
45
|
var import_winston = __toESM(require("winston"));
|
|
46
|
+
var import_joi = __toESM(require("joi"));
|
|
46
47
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
47
48
|
var import_cache_logger = require("./cache-logger");
|
|
48
49
|
class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
50
|
+
/**
|
|
51
|
+
* Returns the worker script path based on whether WORKFLOW_SCRIPT_MODULES is configured.
|
|
52
|
+
* - WORKFLOW_SCRIPT_MODULES set: uses Node.js vm with require support (unsafe; not a security boundary)
|
|
53
|
+
* - WORKFLOW_SCRIPT_MODULES unset: uses QuickJS (WASM) for maximum security (no require, no Node.js APIs)
|
|
54
|
+
*/
|
|
55
|
+
static get workerScript() {
|
|
56
|
+
const hasModules = (process.env.WORKFLOW_SCRIPT_MODULES ?? "").split(",").filter(Boolean).length > 0;
|
|
57
|
+
return import_node_path.default.join(__dirname, hasModules ? "Vm.js" : "QuickJs.js");
|
|
58
|
+
}
|
|
49
59
|
static async run(source, args, options) {
|
|
50
|
-
const { logger, timeout } = options;
|
|
60
|
+
const { logger, timeout, signal } = options;
|
|
51
61
|
let result;
|
|
52
|
-
const worker = new import_node_worker_threads.Worker(
|
|
62
|
+
const worker = new import_node_worker_threads.Worker(this.workerScript, {
|
|
53
63
|
workerData: { source, args, options: timeout ? { timeout } : {} }
|
|
54
64
|
});
|
|
65
|
+
const abortListener = () => {
|
|
66
|
+
worker.terminate();
|
|
67
|
+
};
|
|
68
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortListener, { once: true });
|
|
55
69
|
worker.on("message", (message) => {
|
|
56
70
|
if (message.type === "result") {
|
|
57
71
|
result = message.result;
|
|
@@ -81,18 +95,33 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
81
95
|
try {
|
|
82
96
|
await excution;
|
|
83
97
|
} catch (e) {
|
|
84
|
-
|
|
98
|
+
signal == null ? void 0 : signal.removeEventListener("abort", abortListener);
|
|
99
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
100
|
+
throw signal.reason instanceof Error ? signal.reason : new import_plugin_workflow.WorkflowTimeoutError();
|
|
101
|
+
}
|
|
85
102
|
return {
|
|
86
103
|
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
87
|
-
result: e.message
|
|
104
|
+
result: e instanceof Error ? e.message : String(e)
|
|
88
105
|
};
|
|
89
106
|
}
|
|
107
|
+
signal == null ? void 0 : signal.removeEventListener("abort", abortListener);
|
|
90
108
|
return {
|
|
91
109
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
92
110
|
result
|
|
93
111
|
};
|
|
94
112
|
}
|
|
95
|
-
|
|
113
|
+
configSchema = import_joi.default.object({
|
|
114
|
+
content: import_joi.default.string(),
|
|
115
|
+
timeout: import_joi.default.number(),
|
|
116
|
+
continue: import_joi.default.boolean(),
|
|
117
|
+
arguments: import_joi.default.array().items(
|
|
118
|
+
import_joi.default.object({
|
|
119
|
+
name: import_joi.default.string().required(),
|
|
120
|
+
value: import_joi.default.any()
|
|
121
|
+
})
|
|
122
|
+
).optional()
|
|
123
|
+
});
|
|
124
|
+
async run(node, prevJob, processor, options) {
|
|
96
125
|
const { content = "", continue: cont, timeout } = node.config;
|
|
97
126
|
const args = processor.getParsedValue(node.config.arguments ?? [], node.id);
|
|
98
127
|
const _args = args.reduce((pre, item) => ({ ...pre, [item.name]: item.value }), {});
|
|
@@ -102,7 +131,8 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
102
131
|
if (sync) {
|
|
103
132
|
const result = await this.constructor.run(content, _args, {
|
|
104
133
|
timeout,
|
|
105
|
-
logger: processor.logger
|
|
134
|
+
logger: processor.logger,
|
|
135
|
+
signal: options == null ? void 0 : options.signal
|
|
106
136
|
});
|
|
107
137
|
if (result.status === import_plugin_workflow.JOB_STATUS.RESOLVED) {
|
|
108
138
|
processor.logger.info(`run script test success, node id: ${node.id},the result is ${result.result}`);
|
|
@@ -125,7 +155,7 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
125
155
|
const jobResult = {
|
|
126
156
|
status: import_plugin_workflow.JOB_STATUS.PENDING
|
|
127
157
|
};
|
|
128
|
-
this.constructor.run(content, _args, { timeout, logger: processor.logger }).then((res) => {
|
|
158
|
+
this.constructor.run(content, _args, { timeout, logger: processor.logger, signal: options == null ? void 0 : options.signal }).then((res) => {
|
|
129
159
|
if (res.status === import_plugin_workflow.JOB_STATUS.RESOLVED) {
|
|
130
160
|
processor.logger.info(`script (#${node.id}) get result success`);
|
|
131
161
|
jobResult.status = import_plugin_workflow.JOB_STATUS.RESOLVED;
|
|
@@ -143,14 +173,21 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
143
173
|
jobResult.status = import_plugin_workflow.JOB_STATUS.ERROR;
|
|
144
174
|
jobResult.result = res.result;
|
|
145
175
|
}).catch((e) => {
|
|
146
|
-
|
|
176
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
177
|
+
processor.logger.error(`script (#${node.id}) get result failed, the reason is ${message}`);
|
|
147
178
|
jobResult.status = import_plugin_workflow.JOB_STATUS.ERROR;
|
|
148
|
-
jobResult.result =
|
|
179
|
+
jobResult.result = message;
|
|
149
180
|
}).finally(() => {
|
|
150
181
|
processor.logger.debug(`script (#${node.id}) ended, resume workflow...`);
|
|
151
182
|
setImmediate(async () => {
|
|
152
183
|
const job = await this.workflow.db.getRepository("jobs").findOne({ filterByTk: id });
|
|
184
|
+
const execution = await job.getExecution();
|
|
185
|
+
if (execution.status !== 0) {
|
|
186
|
+
processor.logger.warn(`script (#${node.id}) result discarded because execution (${execution.id}) is ended`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
153
189
|
job.set(jobResult);
|
|
190
|
+
job.execution = execution;
|
|
154
191
|
this.workflow.resume(job);
|
|
155
192
|
});
|
|
156
193
|
});
|
|
@@ -160,12 +197,15 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
160
197
|
}
|
|
161
198
|
async test(config = {}) {
|
|
162
199
|
const { content, timeout } = config;
|
|
163
|
-
const args = (config.arguments ?? []).reduce(
|
|
200
|
+
const args = (config.arguments ?? []).reduce(
|
|
201
|
+
(pre, item) => ({ ...pre, [item.name]: item.value }),
|
|
202
|
+
{}
|
|
203
|
+
);
|
|
164
204
|
const transport = new import_cache_logger.CacheTransport();
|
|
165
205
|
const logger = import_winston.default.createLogger({
|
|
166
206
|
transports: [transport]
|
|
167
207
|
});
|
|
168
|
-
const result = await this.constructor.run(content, args, { timeout, logger });
|
|
208
|
+
const result = await this.constructor.run(content ?? "", args, { timeout, logger });
|
|
169
209
|
const log = transport.getLogs();
|
|
170
210
|
return {
|
|
171
211
|
...result,
|
package/dist/server/Vm.js
CHANGED
|
@@ -28,43 +28,58 @@ function customRequire(m) {
|
|
|
28
28
|
}
|
|
29
29
|
throw new Error(`module "${m}" not supported`);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Object.defineProperty(safe, "constructor", {
|
|
31
|
+
function hardenFunction(fn) {
|
|
32
|
+
Object.setPrototypeOf(fn, null);
|
|
33
|
+
Object.defineProperty(fn, "constructor", {
|
|
35
34
|
value: null,
|
|
36
35
|
writable: false,
|
|
37
36
|
enumerable: false,
|
|
38
37
|
configurable: false
|
|
39
38
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
return fn;
|
|
40
|
+
}
|
|
41
|
+
hardenFunction(customRequire);
|
|
42
|
+
function createSafeConsole(originalConsole) {
|
|
43
|
+
const safe = /* @__PURE__ */ Object.create(null);
|
|
44
|
+
const allowedMethods = [
|
|
45
|
+
"log",
|
|
46
|
+
"info",
|
|
47
|
+
"warn",
|
|
48
|
+
"error",
|
|
49
|
+
"debug",
|
|
50
|
+
"trace",
|
|
51
|
+
"dir",
|
|
52
|
+
"dirxml",
|
|
53
|
+
"table",
|
|
54
|
+
"time",
|
|
55
|
+
"timeEnd",
|
|
56
|
+
"timeLog",
|
|
57
|
+
"count",
|
|
58
|
+
"countReset",
|
|
59
|
+
"group",
|
|
60
|
+
"groupCollapsed",
|
|
61
|
+
"groupEnd",
|
|
62
|
+
"clear",
|
|
63
|
+
"assert"
|
|
64
|
+
];
|
|
65
|
+
for (const key of allowedMethods) {
|
|
66
|
+
if (typeof originalConsole[key] === "function") {
|
|
67
|
+
const bound = originalConsole[key].bind(originalConsole);
|
|
68
|
+
hardenFunction(bound);
|
|
69
|
+
Object.defineProperty(safe, key, {
|
|
70
|
+
value: bound,
|
|
50
71
|
writable: false,
|
|
51
|
-
enumerable:
|
|
72
|
+
enumerable: true,
|
|
52
73
|
configurable: false
|
|
53
74
|
});
|
|
54
|
-
return bound;
|
|
55
|
-
};
|
|
56
|
-
if (typeof descriptor.value === "function") {
|
|
57
|
-
descriptor.value = wrap(descriptor.value);
|
|
58
|
-
}
|
|
59
|
-
if (typeof descriptor.get === "function") {
|
|
60
|
-
descriptor.get = wrap(descriptor.get);
|
|
61
75
|
}
|
|
62
|
-
if (typeof descriptor.set === "function") {
|
|
63
|
-
descriptor.set = wrap(descriptor.set);
|
|
64
|
-
}
|
|
65
|
-
descriptor.configurable = false;
|
|
66
|
-
Object.defineProperty(safe, key, descriptor);
|
|
67
76
|
}
|
|
77
|
+
Object.defineProperty(safe, "constructor", {
|
|
78
|
+
value: null,
|
|
79
|
+
writable: false,
|
|
80
|
+
enumerable: false,
|
|
81
|
+
configurable: false
|
|
82
|
+
});
|
|
68
83
|
return Object.freeze(safe);
|
|
69
84
|
}
|
|
70
85
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-workflow-javascript",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.1",
|
|
4
4
|
"displayName": "Workflow: JavaScript",
|
|
5
5
|
"displayName.zh-CN": "工作流:JavaScript 节点",
|
|
6
6
|
"description": "Execute a piece of JavaScript in an isolated Node.js environment.",
|
|
@@ -25,16 +25,13 @@
|
|
|
25
25
|
"@codemirror/state": "^6.4.1",
|
|
26
26
|
"@codemirror/view": "^6.37.2",
|
|
27
27
|
"codemirror": "^6.0.2",
|
|
28
|
+
"joi": "^17.13.3",
|
|
28
29
|
"jshint": "^2.13.6",
|
|
29
|
-
"
|
|
30
|
-
},
|
|
31
|
-
"resolutions": {
|
|
32
|
-
"nan": "2.18.0",
|
|
33
|
-
"node-gyp": "^10.2.0"
|
|
30
|
+
"quickjs-emscripten": "^0.32.0"
|
|
34
31
|
},
|
|
35
32
|
"keywords": [
|
|
36
33
|
"Workflow"
|
|
37
34
|
],
|
|
38
35
|
"license": "Apache-2.0",
|
|
39
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "303663aba6c6eefa27e6a6435b4c0352074ec40f"
|
|
40
37
|
}
|