@nocobase/plugin-workflow-javascript 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 (81) 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/907399554f340b0a.js +10 -0
  6. package/dist/client/CodeEditor.d.ts +8 -0
  7. package/dist/client/ScriptInstruction.d.ts +129 -0
  8. package/dist/client/d608e8e5c2f2b5cf.js +10 -0
  9. package/dist/client/index.d.ts +5 -0
  10. package/dist/client/index.js +10 -0
  11. package/dist/externalVersion.js +23 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +48 -0
  14. package/dist/locale/de-DE.json +33 -0
  15. package/dist/locale/en-US.json +33 -0
  16. package/dist/locale/es-ES.json +33 -0
  17. package/dist/locale/fr-FR.json +33 -0
  18. package/dist/locale/hu-HU.json +33 -0
  19. package/dist/locale/id-ID.json +33 -0
  20. package/dist/locale/index.d.ts +12 -0
  21. package/dist/locale/index.js +54 -0
  22. package/dist/locale/it-IT.json +33 -0
  23. package/dist/locale/ja-JP.json +33 -0
  24. package/dist/locale/ko-KR.json +33 -0
  25. package/dist/locale/ko_KR.json +25 -0
  26. package/dist/locale/nl-NL.json +33 -0
  27. package/dist/locale/pt-BR.json +33 -0
  28. package/dist/locale/ru-RU.json +33 -0
  29. package/dist/locale/tr-TR.json +33 -0
  30. package/dist/locale/uk-UA.json +33 -0
  31. package/dist/locale/vi-VN.json +33 -0
  32. package/dist/locale/zh-CN.json +33 -0
  33. package/dist/locale/zh-TW.json +33 -0
  34. package/dist/node_modules/winston-transport/.babelrc +3 -0
  35. package/dist/node_modules/winston-transport/.eslintrc +7 -0
  36. package/dist/node_modules/winston-transport/.gitattributes +1 -0
  37. package/dist/node_modules/winston-transport/.nyc_output/c1bd7935-644d-4c7a-89c1-24531a04e4cc.json +1 -0
  38. package/dist/node_modules/winston-transport/.nyc_output/processinfo/c1bd7935-644d-4c7a-89c1-24531a04e4cc.json +1 -0
  39. package/dist/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
  40. package/dist/node_modules/winston-transport/LICENSE +22 -0
  41. package/dist/node_modules/winston-transport/dist/index.js +8 -0
  42. package/dist/node_modules/winston-transport/dist/legacy.js +116 -0
  43. package/dist/node_modules/winston-transport/dist/modern.js +212 -0
  44. package/dist/node_modules/winston-transport/index.d.ts +39 -0
  45. package/dist/node_modules/winston-transport/index.js +3 -0
  46. package/dist/node_modules/winston-transport/legacy.js +119 -0
  47. package/dist/node_modules/winston-transport/modern.js +211 -0
  48. package/dist/node_modules/winston-transport/node_modules/readable-stream/errors-browser.js +127 -0
  49. package/dist/node_modules/winston-transport/node_modules/readable-stream/errors.js +116 -0
  50. package/dist/node_modules/winston-transport/node_modules/readable-stream/experimentalWarning.js +17 -0
  51. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
  52. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
  53. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
  54. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/_stream_transform.js +190 -0
  55. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/_stream_writable.js +641 -0
  56. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
  57. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
  58. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
  59. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
  60. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  61. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
  62. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
  63. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
  64. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  65. package/dist/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  66. package/dist/node_modules/winston-transport/node_modules/readable-stream/package.json +68 -0
  67. package/dist/node_modules/winston-transport/node_modules/readable-stream/readable-browser.js +9 -0
  68. package/dist/node_modules/winston-transport/node_modules/readable-stream/readable.js +16 -0
  69. package/dist/node_modules/winston-transport/package.json +1 -0
  70. package/dist/server/ScriptInstruction.d.ts +45 -0
  71. package/dist/server/ScriptInstruction.js +175 -0
  72. package/dist/server/Vm.js +100 -0
  73. package/dist/server/cache-logger.d.ts +6 -0
  74. package/dist/server/cache-logger.js +56 -0
  75. package/dist/server/index.d.ts +1 -0
  76. package/dist/server/index.js +42 -0
  77. package/dist/server/plugin.d.ts +11 -0
  78. package/dist/server/plugin.js +68 -0
  79. package/package.json +40 -0
  80. package/server.d.ts +2 -0
  81. package/server.js +1 -0
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
4
+ function highWaterMarkFrom(options, isDuplex, duplexKey) {
5
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
6
+ }
7
+ function getHighWaterMark(state, options, duplexKey, isDuplex) {
8
+ var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
9
+ if (hwm != null) {
10
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
11
+ var name = isDuplex ? duplexKey : 'highWaterMark';
12
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
13
+ }
14
+ return Math.floor(hwm);
15
+ }
16
+
17
+ // Default value
18
+ return state.objectMode ? 16 : 16 * 1024;
19
+ }
20
+ module.exports = {
21
+ getHighWaterMark: getHighWaterMark
22
+ };
@@ -0,0 +1 @@
1
+ module.exports = require('events').EventEmitter;
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "readable-stream",
3
+ "version": "3.6.2",
4
+ "description": "Streams3, a user-land copy of the stream library from Node.js",
5
+ "main": "readable.js",
6
+ "engines": {
7
+ "node": ">= 6"
8
+ },
9
+ "dependencies": {
10
+ "inherits": "^2.0.3",
11
+ "string_decoder": "^1.1.1",
12
+ "util-deprecate": "^1.0.1"
13
+ },
14
+ "devDependencies": {
15
+ "@babel/cli": "^7.2.0",
16
+ "@babel/core": "^7.2.0",
17
+ "@babel/polyfill": "^7.0.0",
18
+ "@babel/preset-env": "^7.2.0",
19
+ "airtap": "0.0.9",
20
+ "assert": "^1.4.0",
21
+ "bl": "^2.0.0",
22
+ "deep-strict-equal": "^0.2.0",
23
+ "events.once": "^2.0.2",
24
+ "glob": "^7.1.2",
25
+ "gunzip-maybe": "^1.4.1",
26
+ "hyperquest": "^2.1.3",
27
+ "lolex": "^2.6.0",
28
+ "nyc": "^11.0.0",
29
+ "pump": "^3.0.0",
30
+ "rimraf": "^2.6.2",
31
+ "tap": "^12.0.0",
32
+ "tape": "^4.9.0",
33
+ "tar-fs": "^1.16.2",
34
+ "util-promisify": "^2.1.0"
35
+ },
36
+ "scripts": {
37
+ "test": "tap -J --no-esm test/parallel/*.js test/ours/*.js",
38
+ "ci": "TAP=1 tap --no-esm test/parallel/*.js test/ours/*.js | tee test.tap",
39
+ "test-browsers": "airtap --sauce-connect --loopback airtap.local -- test/browser.js",
40
+ "test-browser-local": "airtap --open --local -- test/browser.js",
41
+ "cover": "nyc npm test",
42
+ "report": "nyc report --reporter=lcov",
43
+ "update-browser-errors": "babel -o errors-browser.js errors.js"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git://github.com/nodejs/readable-stream"
48
+ },
49
+ "keywords": [
50
+ "readable",
51
+ "stream",
52
+ "pipe"
53
+ ],
54
+ "browser": {
55
+ "util": false,
56
+ "worker_threads": false,
57
+ "./errors": "./errors-browser.js",
58
+ "./readable.js": "./readable-browser.js",
59
+ "./lib/internal/streams/from.js": "./lib/internal/streams/from-browser.js",
60
+ "./lib/internal/streams/stream.js": "./lib/internal/streams/stream-browser.js"
61
+ },
62
+ "nyc": {
63
+ "include": [
64
+ "lib/**.js"
65
+ ]
66
+ },
67
+ "license": "MIT"
68
+ }
@@ -0,0 +1,9 @@
1
+ exports = module.exports = require('./lib/_stream_readable.js');
2
+ exports.Stream = exports;
3
+ exports.Readable = exports;
4
+ exports.Writable = require('./lib/_stream_writable.js');
5
+ exports.Duplex = require('./lib/_stream_duplex.js');
6
+ exports.Transform = require('./lib/_stream_transform.js');
7
+ exports.PassThrough = require('./lib/_stream_passthrough.js');
8
+ exports.finished = require('./lib/internal/streams/end-of-stream.js');
9
+ exports.pipeline = require('./lib/internal/streams/pipeline.js');
@@ -0,0 +1,16 @@
1
+ var Stream = require('stream');
2
+ if (process.env.READABLE_STREAM === 'disable' && Stream) {
3
+ module.exports = Stream.Readable;
4
+ Object.assign(module.exports, Stream);
5
+ module.exports.Stream = Stream;
6
+ } else {
7
+ exports = module.exports = require('./lib/_stream_readable.js');
8
+ exports.Stream = Stream || exports;
9
+ exports.Readable = exports;
10
+ exports.Writable = require('./lib/_stream_writable.js');
11
+ exports.Duplex = require('./lib/_stream_duplex.js');
12
+ exports.Transform = require('./lib/_stream_transform.js');
13
+ exports.PassThrough = require('./lib/_stream_passthrough.js');
14
+ exports.finished = require('./lib/internal/streams/end-of-stream.js');
15
+ exports.pipeline = require('./lib/internal/streams/pipeline.js');
16
+ }
@@ -0,0 +1 @@
1
+ {"name":"winston-transport","description":"Base stream implementations for winston@3 and up.","version":"4.7.0","main":"index.js","browser":"dist/index.js","scripts":{"lint":"eslint test/*.js index.js --resolve-plugins-relative-to ./node_modules/@dabh/eslint-config-populist","pretest":"npm run lint && npm run build","test":"nyc mocha test/*.test.js","report":"nyc report --reporter=lcov","build":"rimraf dist && babel *.js -d ./dist","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git@github.com:winstonjs/winston-transport.git"},"keywords":["winston","transport","winston3"],"author":"Charlie Robbins <charlie.robbins@gmail.com>","license":"MIT","bugs":{"url":"https://github.com/winstonjs/winston-transport/issues"},"homepage":"https://github.com/winstonjs/winston-transport#readme","dependencies":{"logform":"^2.3.2","readable-stream":"^3.6.0","triple-beam":"^1.3.0"},"devDependencies":{"@types/node":"^20.8.6","abstract-winston-transport":">=0.5.1","assume":"^2.3.0","babel-cli":"^6.26.0","babel-preset-env":"^1.7.0","deep-equal":"^2.0.5","eslint":"^8.8.0","@dabh/eslint-config-populist":"^5.0.0","mocha":"^10.0.0","nyc":"^15.1.0","rimraf":"^5.0.5","winston-compat":"^0.1.5"},"engines":{"node":">= 12.0.0"},"_lastModified":"2026-02-24T17:03:17.609Z"}
@@ -0,0 +1,45 @@
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 { Logger } from 'winston';
10
+ import { Processor, Instruction, FlowNodeModel } from '@nocobase/plugin-workflow';
11
+ type ScriptConfig = {
12
+ content?: string;
13
+ timeout?: number;
14
+ continue?: boolean;
15
+ arguments?: {
16
+ [key: string]: any;
17
+ }[];
18
+ };
19
+ export default class ScriptInstruction extends Instruction {
20
+ static run(source: any, args: any, options: {
21
+ logger: Logger;
22
+ timeout?: number;
23
+ }): Promise<{
24
+ status: -2;
25
+ result: any;
26
+ } | {
27
+ status: 1;
28
+ result: any;
29
+ }>;
30
+ run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
31
+ result: any;
32
+ status: -2 | 1;
33
+ }>;
34
+ resume(node: FlowNodeModel, job: any, processor: Processor): Promise<any>;
35
+ test(config?: ScriptConfig): Promise<{
36
+ log: string;
37
+ status: -2;
38
+ result: any;
39
+ } | {
40
+ log: string;
41
+ status: 1;
42
+ result: any;
43
+ }>;
44
+ }
45
+ export {};
@@ -0,0 +1,175 @@
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 ScriptInstruction_exports = {};
38
+ __export(ScriptInstruction_exports, {
39
+ default: () => ScriptInstruction
40
+ });
41
+ module.exports = __toCommonJS(ScriptInstruction_exports);
42
+ var import_node_events = require("node:events");
43
+ var import_node_path = __toESM(require("node:path"));
44
+ var import_node_worker_threads = require("node:worker_threads");
45
+ var import_winston = __toESM(require("winston"));
46
+ var import_plugin_workflow = require("@nocobase/plugin-workflow");
47
+ var import_cache_logger = require("./cache-logger");
48
+ class ScriptInstruction extends import_plugin_workflow.Instruction {
49
+ static async run(source, args, options) {
50
+ const { logger, timeout } = options;
51
+ let result;
52
+ const worker = new import_node_worker_threads.Worker(import_node_path.default.join(__dirname, "Vm.js"), {
53
+ workerData: { source, args, options: timeout ? { timeout } : {} }
54
+ });
55
+ worker.on("message", (message) => {
56
+ if (message.type === "result") {
57
+ result = message.result;
58
+ }
59
+ });
60
+ worker.stdout.on("data", (data) => {
61
+ logger.info(data.toString());
62
+ });
63
+ worker.stderr.on("data", (data) => {
64
+ logger.error(data.toString());
65
+ });
66
+ const excution = new Promise((resolve, reject) => {
67
+ worker.on("error", (error) => {
68
+ reject(error);
69
+ });
70
+ const stdoutPromise = (0, import_node_events.once)(worker.stdout, "close");
71
+ const stderrPromise = (0, import_node_events.once)(worker.stderr, "close");
72
+ worker.on("exit", (code) => {
73
+ Promise.all([stdoutPromise, stderrPromise]).then(() => {
74
+ if (code !== 0) {
75
+ reject(new Error(`Worker stopped with exit code ${code}`));
76
+ }
77
+ resolve(result);
78
+ }).catch(reject);
79
+ });
80
+ });
81
+ try {
82
+ await excution;
83
+ } catch (e) {
84
+ console.log(e);
85
+ return {
86
+ status: import_plugin_workflow.JOB_STATUS.ERROR,
87
+ result: e.message
88
+ };
89
+ }
90
+ return {
91
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED,
92
+ result
93
+ };
94
+ }
95
+ async run(node, prevJob, processor) {
96
+ const { content = "", continue: cont, timeout } = node.config;
97
+ const args = processor.getParsedValue(node.config.arguments ?? [], node.id);
98
+ const _args = args.reduce((pre, item) => ({ ...pre, [item.name]: item.value }), {});
99
+ const { workflow } = processor.execution;
100
+ const sync = this.workflow.isWorkflowSync(workflow);
101
+ processor.logger.info(`run script execution node id: ${node.id}, start in ${(/* @__PURE__ */ new Date()).toLocaleString()}`);
102
+ if (sync) {
103
+ const result = await this.constructor.run(content, _args, {
104
+ timeout,
105
+ logger: processor.logger
106
+ });
107
+ if (result.status === import_plugin_workflow.JOB_STATUS.RESOLVED) {
108
+ processor.logger.info(`run script test success, node id: ${node.id},the result is ${result.result}`);
109
+ } else {
110
+ processor.logger.error(`run script test failed, node id: ${node.id},the reason is ${result.result}`);
111
+ }
112
+ return {
113
+ result: result.result,
114
+ status: cont ? import_plugin_workflow.JOB_STATUS.RESOLVED : result.status === import_plugin_workflow.JOB_STATUS.RESOLVED ? import_plugin_workflow.JOB_STATUS.RESOLVED : import_plugin_workflow.JOB_STATUS.ERROR
115
+ };
116
+ }
117
+ const { id } = processor.saveJob({
118
+ status: import_plugin_workflow.JOB_STATUS.PENDING,
119
+ nodeId: node.id,
120
+ nodeKey: node.key,
121
+ upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
122
+ });
123
+ processor.logger.info(`script (#${node.id}) has been started, waiting for response...`);
124
+ await processor.exit();
125
+ const jobResult = {
126
+ status: import_plugin_workflow.JOB_STATUS.PENDING
127
+ };
128
+ this.constructor.run(content, _args, { timeout, logger: processor.logger }).then((res) => {
129
+ if (res.status === import_plugin_workflow.JOB_STATUS.RESOLVED) {
130
+ processor.logger.info(`script (#${node.id}) get result success`);
131
+ jobResult.status = import_plugin_workflow.JOB_STATUS.RESOLVED;
132
+ jobResult.result = res.result;
133
+ processor.logger.info(`run script execution success, node id: ${node.id},the result is ${res.result}`);
134
+ return;
135
+ }
136
+ if (cont) {
137
+ processor.logger.warn(`script (#${node.id}) get result failed, the reason is ${res.result}`);
138
+ jobResult.status = import_plugin_workflow.JOB_STATUS.RESOLVED;
139
+ jobResult.result = res.result;
140
+ return;
141
+ }
142
+ processor.logger.info(`script (#${node.id}) get result failed, the reason is ${res.result}`);
143
+ jobResult.status = import_plugin_workflow.JOB_STATUS.ERROR;
144
+ jobResult.result = res.result;
145
+ }).catch((e) => {
146
+ processor.logger.error(`script (#${node.id}) get result failed, the reason is ${e.message}`);
147
+ jobResult.status = import_plugin_workflow.JOB_STATUS.ERROR;
148
+ jobResult.result = e.message;
149
+ }).finally(() => {
150
+ processor.logger.debug(`script (#${node.id}) ended, resume workflow...`);
151
+ setImmediate(async () => {
152
+ const job = await this.workflow.db.getRepository("jobs").findOne({ filterByTk: id });
153
+ job.set(jobResult);
154
+ this.workflow.resume(job);
155
+ });
156
+ });
157
+ }
158
+ async resume(node, job, processor) {
159
+ return job;
160
+ }
161
+ async test(config = {}) {
162
+ const { content, timeout } = config;
163
+ const args = (config.arguments ?? []).reduce((pre, item) => ({ ...pre, [item.name]: item.value }), {});
164
+ const transport = new import_cache_logger.CacheTransport();
165
+ const logger = import_winston.default.createLogger({
166
+ transports: [transport]
167
+ });
168
+ const result = await this.constructor.run(content, args, { timeout, logger });
169
+ const log = transport.getLogs();
170
+ return {
171
+ ...result,
172
+ log: log == null ? void 0 : log.join("")
173
+ };
174
+ }
175
+ }
@@ -0,0 +1,100 @@
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
+ const { parentPort, workerData } = require("node:worker_threads");
11
+ const { Script } = require("node:vm");
12
+ const Path = require("node:path");
13
+ let timer = null;
14
+ function customRequire(m) {
15
+ var _a;
16
+ const configuredModules = (((_a = process.env.WORKFLOW_SCRIPT_MODULES) == null ? void 0 : _a.split(",")) ?? []).filter(Boolean);
17
+ let mainName;
18
+ if (m.startsWith("/")) {
19
+ mainName = m;
20
+ } else if (m.startsWith(".")) {
21
+ mainName = m;
22
+ m = Path.resolve(process.cwd(), m);
23
+ } else {
24
+ mainName = m.split("/").slice(0, m.startsWith("@") ? 2 : 1).join("/");
25
+ }
26
+ if (configuredModules.includes(mainName)) {
27
+ return require(m);
28
+ }
29
+ throw new Error(`module "${m}" not supported`);
30
+ }
31
+ customRequire.constructor = null;
32
+ function createSafeConsole(originalConsole) {
33
+ const safe = /* @__PURE__ */ Object.create(null);
34
+ Object.defineProperty(safe, "constructor", {
35
+ value: null,
36
+ writable: false,
37
+ enumerable: false,
38
+ configurable: false
39
+ });
40
+ const allKeys = Reflect.ownKeys(originalConsole);
41
+ for (const key of allKeys) {
42
+ const descriptor = Object.getOwnPropertyDescriptor(originalConsole, key);
43
+ if (!descriptor) {
44
+ continue;
45
+ }
46
+ const wrap = (fn) => {
47
+ const bound = fn.bind(originalConsole);
48
+ Object.defineProperty(bound, "constructor", {
49
+ value: null,
50
+ writable: false,
51
+ enumerable: false,
52
+ configurable: false
53
+ });
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
+ }
62
+ if (typeof descriptor.set === "function") {
63
+ descriptor.set = wrap(descriptor.set);
64
+ }
65
+ descriptor.configurable = false;
66
+ Object.defineProperty(safe, key, descriptor);
67
+ }
68
+ return Object.freeze(safe);
69
+ }
70
+ async function main() {
71
+ const { source, args = {}, options = {} } = workerData;
72
+ const code = `
73
+ this.constructor = null;
74
+ async function __main() {
75
+ ${source}
76
+ }
77
+ __main();
78
+ `;
79
+ const script = new Script(code);
80
+ const context = {
81
+ ...args,
82
+ require: customRequire,
83
+ console: createSafeConsole(console)
84
+ };
85
+ if (options.timeout) {
86
+ timer = setTimeout(() => {
87
+ throw new Error(`Script execution timed out after ${options.timeout}ms`);
88
+ }, options.timeout);
89
+ }
90
+ const result = script.runInNewContext(context, { timeout: options.timeout });
91
+ return result;
92
+ }
93
+ main().then((result) => {
94
+ parentPort.postMessage({ type: "result", result });
95
+ }).catch((error) => {
96
+ throw error;
97
+ }).finally(() => {
98
+ clearTimeout(timer);
99
+ timer = null;
100
+ });
@@ -0,0 +1,6 @@
1
+ import Transport from 'winston-transport';
2
+ export declare class CacheTransport extends Transport {
3
+ private logs;
4
+ log(info: any, next: () => void): any;
5
+ getLogs(): string[];
6
+ }
@@ -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 cache_logger_exports = {};
38
+ __export(cache_logger_exports, {
39
+ CacheTransport: () => CacheTransport
40
+ });
41
+ module.exports = __toCommonJS(cache_logger_exports);
42
+ var import_winston_transport = __toESM(require("winston-transport"));
43
+ class CacheTransport extends import_winston_transport.default {
44
+ logs = [];
45
+ log(info, next) {
46
+ this.logs.push(info.message);
47
+ next();
48
+ }
49
+ getLogs() {
50
+ return this.logs.slice();
51
+ }
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ CacheTransport
56
+ });
@@ -0,0 +1 @@
1
+ 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,11 @@
1
+ import { Plugin } from '@nocobase/server';
2
+ export declare class PluginWorkflowScriptServer extends Plugin {
3
+ afterAdd(): Promise<void>;
4
+ beforeLoad(): Promise<void>;
5
+ load(): Promise<void>;
6
+ install(): Promise<void>;
7
+ afterEnable(): Promise<void>;
8
+ afterDisable(): Promise<void>;
9
+ remove(): Promise<void>;
10
+ }
11
+ export default PluginWorkflowScriptServer;
@@ -0,0 +1,68 @@
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
+ PluginWorkflowScriptServer: () => PluginWorkflowScriptServer,
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_ScriptInstruction = __toESM(require("./ScriptInstruction"));
46
+ class PluginWorkflowScriptServer extends import_server.Plugin {
47
+ async afterAdd() {
48
+ }
49
+ async beforeLoad() {
50
+ }
51
+ async load() {
52
+ const workflowPlugin = this.app.pm.get(import_plugin_workflow.default);
53
+ workflowPlugin.registerInstruction("script", import_ScriptInstruction.default);
54
+ }
55
+ async install() {
56
+ }
57
+ async afterEnable() {
58
+ }
59
+ async afterDisable() {
60
+ }
61
+ async remove() {
62
+ }
63
+ }
64
+ var plugin_default = PluginWorkflowScriptServer;
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ PluginWorkflowScriptServer
68
+ });