@n8n/task-runner 1.1.0 → 1.3.0
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/build.tsbuildinfo +1 -1
- package/dist/js-task-runner/errors/error-like.d.ts +5 -0
- package/dist/js-task-runner/errors/error-like.js +10 -0
- package/dist/js-task-runner/errors/error-like.js.map +1 -0
- package/dist/js-task-runner/errors/execution-error.d.ts +4 -5
- package/dist/js-task-runner/errors/execution-error.js +10 -5
- package/dist/js-task-runner/errors/execution-error.js.map +1 -1
- package/dist/js-task-runner/errors/serializable-error.d.ts +4 -0
- package/dist/js-task-runner/errors/serializable-error.js +27 -0
- package/dist/js-task-runner/errors/serializable-error.js.map +1 -0
- package/dist/js-task-runner/errors/validation-error.d.ts +2 -2
- package/dist/js-task-runner/errors/validation-error.js +2 -2
- package/dist/js-task-runner/errors/validation-error.js.map +1 -1
- package/dist/js-task-runner/js-task-runner.d.ts +12 -2
- package/dist/js-task-runner/js-task-runner.js +51 -27
- package/dist/js-task-runner/js-task-runner.js.map +1 -1
- package/dist/js-task-runner/require-resolver.d.ts +6 -0
- package/dist/js-task-runner/require-resolver.js +22 -0
- package/dist/js-task-runner/require-resolver.js.map +1 -0
- package/dist/node-types.d.ts +10 -0
- package/dist/node-types.js +45 -0
- package/dist/node-types.js.map +1 -0
- package/dist/runner-types.d.ts +6 -2
- package/dist/runner-types.js.map +1 -1
- package/dist/start.js +9 -38
- package/dist/start.js.map +1 -1
- package/dist/task-runner.d.ts +4 -0
- package/dist/task-runner.js +14 -2
- package/dist/task-runner.js.map +1 -1
- package/package.json +4 -4
- package/dist/authenticator.d.ts +0 -5
- package/dist/authenticator.js +0 -57
- package/dist/authenticator.js.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isErrorLike = isErrorLike;
|
|
4
|
+
function isErrorLike(value) {
|
|
5
|
+
if (typeof value !== 'object' || value === null)
|
|
6
|
+
return false;
|
|
7
|
+
const errorLike = value;
|
|
8
|
+
return typeof errorLike.message === 'string';
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=error-like.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-like.js","sourceRoot":"","sources":["../../../src/js-task-runner/errors/error-like.ts"],"names":[],"mappings":";;AAKA,kCAMC;AAND,SAAgB,WAAW,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE9D,MAAM,SAAS,GAAG,KAAkB,CAAC;IAErC,OAAO,OAAO,SAAS,CAAC,OAAO,KAAK,QAAQ,CAAC;AAC9C,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { ErrorLike } from './error-like';
|
|
2
|
+
import { SerializableError } from './serializable-error';
|
|
3
|
+
export declare class ExecutionError extends SerializableError {
|
|
3
4
|
description: string | null;
|
|
4
5
|
itemIndex: number | undefined;
|
|
5
6
|
context: {
|
|
@@ -7,9 +8,7 @@ export declare class ExecutionError extends ApplicationError {
|
|
|
7
8
|
} | undefined;
|
|
8
9
|
stack: string;
|
|
9
10
|
lineNumber: number | undefined;
|
|
10
|
-
constructor(error:
|
|
11
|
-
stack?: string;
|
|
12
|
-
}, itemIndex?: number);
|
|
11
|
+
constructor(error: ErrorLike, itemIndex?: number);
|
|
13
12
|
private populateFromStack;
|
|
14
13
|
private toLineNumberDisplay;
|
|
15
14
|
private toErrorDetailsAndType;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExecutionError = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const serializable_error_1 = require("./serializable-error");
|
|
5
|
+
const VM_WRAPPER_FN_NAME = 'VmCodeWrapper';
|
|
6
|
+
class ExecutionError extends serializable_error_1.SerializableError {
|
|
6
7
|
constructor(error, itemIndex) {
|
|
7
8
|
super(error.message);
|
|
8
9
|
this.description = null;
|
|
@@ -21,9 +22,10 @@ class ExecutionError extends n8n_workflow_1.ApplicationError {
|
|
|
21
22
|
const stackRows = this.stack.split('\n');
|
|
22
23
|
if (stackRows.length === 0) {
|
|
23
24
|
this.message = 'Unknown error';
|
|
25
|
+
return;
|
|
24
26
|
}
|
|
25
27
|
const messageRow = stackRows.find((line) => line.includes('Error:'));
|
|
26
|
-
const lineNumberRow = stackRows.find((line) => line.includes(
|
|
28
|
+
const lineNumberRow = stackRows.find((line) => line.includes(`at ${VM_WRAPPER_FN_NAME} `));
|
|
27
29
|
const lineNumberDisplay = this.toLineNumberDisplay(lineNumberRow);
|
|
28
30
|
if (!messageRow) {
|
|
29
31
|
this.message = `Unknown error ${lineNumberDisplay}`;
|
|
@@ -39,13 +41,16 @@ class ExecutionError extends n8n_workflow_1.ApplicationError {
|
|
|
39
41
|
this.message = `${errorDetails} ${lineNumberDisplay}`;
|
|
40
42
|
}
|
|
41
43
|
toLineNumberDisplay(lineNumberRow) {
|
|
42
|
-
|
|
44
|
+
if (!lineNumberRow)
|
|
45
|
+
return '';
|
|
46
|
+
const regex = new RegExp(`at ${VM_WRAPPER_FN_NAME} \\(evalmachine\\.<anonymous>:(?<lineNumber>\\d+):`);
|
|
47
|
+
const errorLineNumberMatch = lineNumberRow.match(regex);
|
|
43
48
|
if (!errorLineNumberMatch?.groups?.lineNumber)
|
|
44
49
|
return null;
|
|
45
50
|
const lineNumber = errorLineNumberMatch.groups.lineNumber;
|
|
46
|
-
this.lineNumber = Number(lineNumber);
|
|
47
51
|
if (!lineNumber)
|
|
48
52
|
return '';
|
|
53
|
+
this.lineNumber = Number(lineNumber);
|
|
49
54
|
return this.itemIndex === undefined
|
|
50
55
|
? `[line ${lineNumber}]`
|
|
51
56
|
: `[line ${lineNumber}, for item ${this.itemIndex}]`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-error.js","sourceRoot":"","sources":["../../../src/js-task-runner/errors/execution-error.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"execution-error.js","sourceRoot":"","sources":["../../../src/js-task-runner/errors/execution-error.ts"],"names":[],"mappings":";;;AACA,6DAAyD;AAEzD,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAE3C,MAAa,cAAe,SAAQ,sCAAiB;IAWpD,YAAY,KAAgB,EAAE,SAAkB;QAC/C,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAXtB,gBAAW,GAAkB,IAAI,CAAC;QAElC,cAAS,GAAuB,SAAS,CAAC;QAE1C,YAAO,GAAsC,SAAS,CAAC;QAEvD,UAAK,GAAG,EAAE,CAAC;QAEX,eAAU,GAAuB,SAAS,CAAC;QAI1C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;QAC9C,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QAE/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1B,CAAC;IAKO,iBAAiB;QACxB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC;YAC/B,OAAO;QACR,CAAC;QAED,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrE,MAAM,aAAa,GAAG,SAA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AU,cAAc,IAAI,CAAC,SAAS,GAAG,CAAC;IACvD,CAAC;IAEO,qBAAqB,CAAC,UAAmB;QAChD,IAAI,CAAC,UAAU;YAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAErC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,UAAU;aAC1C,KAAK,CAAC,GAAG,CAAC;aACV,OAAO,EAAE;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAEvB,OAAO,CAAC,YAAY,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;CACD;AAxFD,wCAwFC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerializableError = void 0;
|
|
4
|
+
exports.makeSerializable = makeSerializable;
|
|
5
|
+
function makeSerializable(error) {
|
|
6
|
+
Object.defineProperties(error, {
|
|
7
|
+
message: {
|
|
8
|
+
value: error.message,
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
},
|
|
12
|
+
stack: {
|
|
13
|
+
value: error.stack,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
class SerializableError extends Error {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
makeSerializable(this);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.SerializableError = SerializableError;
|
|
27
|
+
//# sourceMappingURL=serializable-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializable-error.js","sourceRoot":"","sources":["../../../src/js-task-runner/errors/serializable-error.ts"],"names":[],"mappings":";;;AAIA,4CAeC;AAfD,SAAgB,gBAAgB,CAAC,KAAY;IAC5C,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE;QAC9B,OAAO,EAAE;YACR,KAAK,EAAE,KAAK,CAAC,OAAO;YACpB,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SAClB;QACD,KAAK,EAAE;YACN,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SAClB;KACD,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACd,CAAC;AAMD,MAAsB,iBAAkB,SAAQ,KAAK;IACpD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACD;AAND,8CAMC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class ValidationError extends
|
|
1
|
+
import { SerializableError } from './serializable-error';
|
|
2
|
+
export declare class ValidationError extends SerializableError {
|
|
3
3
|
description: string;
|
|
4
4
|
itemIndex: number | undefined;
|
|
5
5
|
context: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidationError = void 0;
|
|
4
|
-
const
|
|
5
|
-
class ValidationError extends
|
|
4
|
+
const serializable_error_1 = require("./serializable-error");
|
|
5
|
+
class ValidationError extends serializable_error_1.SerializableError {
|
|
6
6
|
constructor({ message, description, itemIndex, lineNumber, }) {
|
|
7
7
|
super(message);
|
|
8
8
|
this.description = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../../src/js-task-runner/errors/validation-error.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../../src/js-task-runner/errors/validation-error.ts"],"names":[],"mappings":";;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askRunnerOpts {
|
|
44
|
+
wsUrl: string;
|
|
45
|
+
grantToken: string;
|
|
46
|
+
maxConcurrency: number;
|
|
47
|
+
name?: string;
|
|
48
|
+
allowedBuiltInModules?: string;
|
|
49
|
+
allowedExternalModules?: string;
|
|
50
|
+
}
|
|
43
51
|
export declare class JsTaskRunner extends TaskRunner {
|
|
44
|
-
|
|
52
|
+
private readonly requireResolver;
|
|
53
|
+
constructor({ grantToken, maxConcurrency, wsUrl, name, allowedBuiltInModules, allowedExternalModules, }: JsTaskRunnerOpts);
|
|
45
54
|
executeTask(task: Task<JSExecSettings>): Promise<TaskResultData>;
|
|
55
|
+
private getNativeVariables;
|
|
46
56
|
private runForAllItems;
|
|
47
57
|
private runForEachItem;
|
|
48
58
|
private createDataProxy;
|
|
49
|
-
private
|
|
59
|
+
private toExecutionErrorIfNeeded;
|
|
50
60
|
}
|
|
@@ -29,10 +29,19 @@ const n8n_workflow_1 = require("n8n-workflow");
|
|
|
29
29
|
const a = __importStar(require("node:assert"));
|
|
30
30
|
const node_vm_1 = require("node:vm");
|
|
31
31
|
const task_runner_1 = require("../task-runner");
|
|
32
|
+
const error_like_1 = require("./errors/error-like");
|
|
33
|
+
const execution_error_1 = require("./errors/execution-error");
|
|
34
|
+
const serializable_error_1 = require("./errors/serializable-error");
|
|
35
|
+
const require_resolver_1 = require("./require-resolver");
|
|
32
36
|
const result_validation_1 = require("./result-validation");
|
|
33
37
|
class JsTaskRunner extends task_runner_1.TaskRunner {
|
|
34
|
-
constructor(
|
|
35
|
-
super(
|
|
38
|
+
constructor({ grantToken, maxConcurrency, wsUrl, name = 'JS Task Runner', allowedBuiltInModules, allowedExternalModules, }) {
|
|
39
|
+
super('javascript', wsUrl, grantToken, maxConcurrency, name);
|
|
40
|
+
const parseModuleAllowList = (moduleList) => moduleList === '*' ? null : new Set(moduleList.split(',').map((x) => x.trim()));
|
|
41
|
+
this.requireResolver = (0, require_resolver_1.createRequireResolver)({
|
|
42
|
+
allowedBuiltInModules: parseModuleAllowList(allowedBuiltInModules ?? ''),
|
|
43
|
+
allowedExternalModules: parseModuleAllowList(allowedExternalModules ?? ''),
|
|
44
|
+
});
|
|
36
45
|
}
|
|
37
46
|
async executeTask(task) {
|
|
38
47
|
const allData = await this.requestData(task.taskId, 'all');
|
|
@@ -41,17 +50,7 @@ class JsTaskRunner extends task_runner_1.TaskRunner {
|
|
|
41
50
|
const workflowParams = allData.workflow;
|
|
42
51
|
const workflow = new n8n_workflow_1.Workflow({
|
|
43
52
|
...workflowParams,
|
|
44
|
-
nodeTypes:
|
|
45
|
-
getByNameAndVersion() {
|
|
46
|
-
return undefined;
|
|
47
|
-
},
|
|
48
|
-
getByName() {
|
|
49
|
-
return undefined;
|
|
50
|
-
},
|
|
51
|
-
getKnownTypes() {
|
|
52
|
-
return {};
|
|
53
|
-
},
|
|
54
|
-
},
|
|
53
|
+
nodeTypes: this.nodeTypes,
|
|
55
54
|
});
|
|
56
55
|
const customConsole = {
|
|
57
56
|
log: (...args) => {
|
|
@@ -69,29 +68,50 @@ class JsTaskRunner extends task_runner_1.TaskRunner {
|
|
|
69
68
|
customData: allData.runExecutionData.resultData.metadata,
|
|
70
69
|
};
|
|
71
70
|
}
|
|
71
|
+
getNativeVariables() {
|
|
72
|
+
return {
|
|
73
|
+
Buffer,
|
|
74
|
+
Function,
|
|
75
|
+
eval,
|
|
76
|
+
setTimeout,
|
|
77
|
+
setInterval,
|
|
78
|
+
setImmediate,
|
|
79
|
+
clearTimeout,
|
|
80
|
+
clearInterval,
|
|
81
|
+
clearImmediate,
|
|
82
|
+
btoa,
|
|
83
|
+
atob,
|
|
84
|
+
TextDecoder,
|
|
85
|
+
TextDecoderStream,
|
|
86
|
+
TextEncoder,
|
|
87
|
+
TextEncoderStream,
|
|
88
|
+
FormData,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
72
91
|
async runForAllItems(taskId, settings, allData, workflow, customConsole) {
|
|
73
92
|
const dataProxy = this.createDataProxy(allData, workflow, allData.itemIndex);
|
|
74
93
|
const inputItems = allData.connectionInputData;
|
|
75
94
|
const context = {
|
|
76
|
-
require,
|
|
95
|
+
require: this.requireResolver,
|
|
77
96
|
module: {},
|
|
78
97
|
console: customConsole,
|
|
79
98
|
items: inputItems,
|
|
99
|
+
...this.getNativeVariables(),
|
|
80
100
|
...dataProxy,
|
|
81
101
|
...this.buildRpcCallObject(taskId),
|
|
82
102
|
};
|
|
83
103
|
try {
|
|
84
|
-
const result = (await (0, node_vm_1.runInNewContext)(`module.exports = async function() {${settings.code}\n}()`, context));
|
|
104
|
+
const result = (await (0, node_vm_1.runInNewContext)(`globalThis.global = globalThis; module.exports = async function VmCodeWrapper() {${settings.code}\n}()`, context));
|
|
85
105
|
if (result === null) {
|
|
86
106
|
return [];
|
|
87
107
|
}
|
|
88
108
|
return (0, result_validation_1.validateRunForAllItemsOutput)(result);
|
|
89
109
|
}
|
|
90
|
-
catch (
|
|
110
|
+
catch (e) {
|
|
111
|
+
const error = this.toExecutionErrorIfNeeded(e);
|
|
91
112
|
if (settings.continueOnFail) {
|
|
92
|
-
return [{ json: { error:
|
|
113
|
+
return [{ json: { error: error.message } }];
|
|
93
114
|
}
|
|
94
|
-
error.node = allData.node;
|
|
95
115
|
throw error;
|
|
96
116
|
}
|
|
97
117
|
}
|
|
@@ -102,15 +122,16 @@ class JsTaskRunner extends task_runner_1.TaskRunner {
|
|
|
102
122
|
const item = inputItems[index];
|
|
103
123
|
const dataProxy = this.createDataProxy(allData, workflow, index);
|
|
104
124
|
const context = {
|
|
105
|
-
require,
|
|
125
|
+
require: this.requireResolver,
|
|
106
126
|
module: {},
|
|
107
127
|
console: customConsole,
|
|
108
128
|
item,
|
|
129
|
+
...this.getNativeVariables(),
|
|
109
130
|
...dataProxy,
|
|
110
131
|
...this.buildRpcCallObject(taskId),
|
|
111
132
|
};
|
|
112
133
|
try {
|
|
113
|
-
let result = (await (0, node_vm_1.runInNewContext)(`module.exports = async function() {${settings.code}\n}()`, context));
|
|
134
|
+
let result = (await (0, node_vm_1.runInNewContext)(`module.exports = async function VmCodeWrapper() {${settings.code}\n}()`, context));
|
|
114
135
|
if (result === null) {
|
|
115
136
|
continue;
|
|
116
137
|
}
|
|
@@ -128,13 +149,13 @@ class JsTaskRunner extends task_runner_1.TaskRunner {
|
|
|
128
149
|
});
|
|
129
150
|
}
|
|
130
151
|
}
|
|
131
|
-
catch (
|
|
152
|
+
catch (e) {
|
|
153
|
+
const error = this.toExecutionErrorIfNeeded(e);
|
|
132
154
|
if (!settings.continueOnFail) {
|
|
133
|
-
error.node = allData.node;
|
|
134
155
|
throw error;
|
|
135
156
|
}
|
|
136
157
|
returnData.push({
|
|
137
|
-
json: { error:
|
|
158
|
+
json: { error: error.message },
|
|
138
159
|
pairedItem: {
|
|
139
160
|
item: index,
|
|
140
161
|
},
|
|
@@ -150,11 +171,14 @@ class JsTaskRunner extends task_runner_1.TaskRunner {
|
|
|
150
171
|
isProcessAvailable: true,
|
|
151
172
|
}).getDataProxy();
|
|
152
173
|
}
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
return error
|
|
174
|
+
toExecutionErrorIfNeeded(error) {
|
|
175
|
+
if (error instanceof Error) {
|
|
176
|
+
return (0, serializable_error_1.makeSerializable)(error);
|
|
177
|
+
}
|
|
178
|
+
if ((0, error_like_1.isErrorLike)(error)) {
|
|
179
|
+
return new execution_error_1.ExecutionError(error);
|
|
156
180
|
}
|
|
157
|
-
return JSON.stringify(error);
|
|
181
|
+
return new execution_error_1.ExecutionError({ message: JSON.stringify(error) });
|
|
158
182
|
}
|
|
159
183
|
}
|
|
160
184
|
exports.JsTaskRunner = JsTaskRunner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js-task-runner.js","sourceRoot":"","sources":["../../src/js-task-runner/js-task-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA6C;AAC7C,+CAIsB;
|
|
1
|
+
{"version":3,"file":"js-task-runner.js","sourceRo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OAAO,IAAI,gCAAc,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;CACD;AAhPD,oCAgPC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type RequireResolverOpts = {
|
|
2
|
+
allowedBuiltInModules: Set<string> | null;
|
|
3
|
+
allowedExternalModules: Set<string> | null;
|
|
4
|
+
};
|
|
5
|
+
export type RequireResolver = (request: string) => unknown;
|
|
6
|
+
export declare function createRequireResolver({ allowedBuiltInModules, allowedExternalModules, }: RequireResolverOpts): (request: string) => unknown;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRequireResolver = createRequireResolver;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const node_module_1 = require("node:module");
|
|
6
|
+
const execution_error_1 = require("./errors/execution-error");
|
|
7
|
+
function createRequireResolver({ allowedBuiltInModules, allowedExternalModules, }) {
|
|
8
|
+
return (request) => {
|
|
9
|
+
const checkIsAllowed = (allowList, moduleName) => {
|
|
10
|
+
return allowList ? allowList.has(moduleName) : true;
|
|
11
|
+
};
|
|
12
|
+
const isAllowed = (0, node_module_1.isBuiltin)(request)
|
|
13
|
+
? checkIsAllowed(allowedBuiltInModules, request)
|
|
14
|
+
: checkIsAllowed(allowedExternalModules, request);
|
|
15
|
+
if (!isAllowed) {
|
|
16
|
+
const error = new n8n_workflow_1.ApplicationError(`Cannot find module '${request}'`);
|
|
17
|
+
throw new execution_error_1.ExecutionError(error);
|
|
18
|
+
}
|
|
19
|
+
return require(request);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=require-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-resolver.js","sourceRoot":"","sources":["../../src/js-task-runner/require-resolver.ts"],"names":[],"mappings":";;AAqBA,sDAqBC;AA1CD,+CAAgD;AAChD,6CAAwC;AAExC,8DAA0D;AAkB1D,SAAgB,qBAAqB,CAAC,EACrC,qBAAqB,EACrB,sBAAsB,GACD;IACrB,OAAO,CAAC,OAAe,EAAE,EAAE;QAC1B,MAAM,cAAc,GAAG,CAAC,SAA6B,EAAE,UAAkB,EAAE,EAAE;YAC5E,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,CAAC,CAAC;QAEF,MAAM,SAAS,GAAG,IAAA,uBAAS,EAAC,OAAO,CAAC;YACnC,CAAC,CAAC,cAAc,CAAC,qBAAqB,EAAE,OAAO,CAAC;YAChD,CAAC,CAAC,cAAc,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;QAEnD,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,MAAM,KAAK,GAAG,IAAI,+BAAgB,CAAC,uBAAuB,OAAO,GAAG,CAAC,CAAC;YACtE,MAAM,IAAI,gCAAc,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;QAGD,OAAO,OAAO,CAAC,OAAO,CAAY,CAAC;IACpC,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IDataObject, type INodeType, type INodeTypeDescription, type INodeTypes, type IVersionedNodeType } from 'n8n-workflow';
|
|
2
|
+
export declare const DEFAULT_NODETYPE_VERSION = 1;
|
|
3
|
+
export declare class TaskRunnerNodeTypes implements INodeTypes {
|
|
4
|
+
private nodeTypesByVersion;
|
|
5
|
+
constructor(nodeTypes: INodeTypeDescription[]);
|
|
6
|
+
private parseNodeTypes;
|
|
7
|
+
getByName(_nodeType: string): INodeType | IVersionedNodeType;
|
|
8
|
+
getByNameAndVersion(nodeType: string, version?: number): INodeType;
|
|
9
|
+
getKnownTypes(): IDataObject;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskRunnerNodeTypes = exports.DEFAULT_NODETYPE_VERSION = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
exports.DEFAULT_NODETYPE_VERSION = 1;
|
|
6
|
+
class TaskRunnerNodeTypes {
|
|
7
|
+
constructor(nodeTypes) {
|
|
8
|
+
this.nodeTypesByVersion = this.parseNodeTypes(nodeTypes);
|
|
9
|
+
}
|
|
10
|
+
parseNodeTypes(nodeTypes) {
|
|
11
|
+
const versionedTypes = new Map();
|
|
12
|
+
for (const nt of nodeTypes) {
|
|
13
|
+
const versions = Array.isArray(nt.version)
|
|
14
|
+
? nt.version
|
|
15
|
+
: [nt.version ?? exports.DEFAULT_NODETYPE_VERSION];
|
|
16
|
+
const versioned = versionedTypes.get(nt.name) ?? new Map();
|
|
17
|
+
for (const version of versions) {
|
|
18
|
+
versioned.set(version, { ...versioned.get(version), ...nt });
|
|
19
|
+
}
|
|
20
|
+
versionedTypes.set(nt.name, versioned);
|
|
21
|
+
}
|
|
22
|
+
return versionedTypes;
|
|
23
|
+
}
|
|
24
|
+
getByName(_nodeType) {
|
|
25
|
+
throw new n8n_workflow_1.ApplicationError('Unimplemented `getByName`', { level: 'error' });
|
|
26
|
+
}
|
|
27
|
+
getByNameAndVersion(nodeType, version) {
|
|
28
|
+
const versions = this.nodeTypesByVersion.get(nodeType);
|
|
29
|
+
if (!versions) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const nodeVersion = versions.get(version ?? Math.max(...versions.keys()));
|
|
33
|
+
if (!nodeVersion) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
description: nodeVersion,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
getKnownTypes() {
|
|
41
|
+
throw new n8n_workflow_1.ApplicationError('Unimplemented `getKnownTypes`', { level: 'error' });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.TaskRunnerNodeTypes = TaskRunnerNodeTypes;
|
|
45
|
+
//# sourceMappingURL=node-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-types.js","sourceRoot":"","sources":["../src/node-types.ts"],"names":[],"mappings":";;;AAAA,+CAOsB;AAIT,QAAA,wBAAwB,GAAG,CAAC,CAAC;AAE1C,MAAa,mBAAmB;IAG/B,YAAY,SAAiC;QAC5C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;IAEO,cAAc,CAAC,SAAiC;QACvD,MAAM,cAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;QAEzD,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;YAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;gBACzC,CAAC,CAAC,EAAE,CAAC,OAAO;gBACZ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,IAAI,gCAAwB,CAAC,CAAC;YAE5C,MAAM,SAAS,GACd,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAgC,CAAC;YACxE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAChC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YAC9D,CAAC;YAED,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,cAAc,CAAC;IACvB,CAAC;IAGD,SAAS,CAAC,SAAiB;QAC1B,MAAM,IAAI,+BAAgB,CAAC,2BAA2B,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,mBAAmB,CAAC,QAAgB,EAAE,OAAgB;QACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,OAAO,SAAiC,CAAC;QAC1C,CAAC;QACD,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,WAAW,EAAE,CAAC;YAClB,OAAO,SAAiC,CAAC;QAC1C,CAAC;QACD,OAAO;YACN,WAAW,EAAE,WAAW;SACxB,CAAC;IACH,CAAC;IAGD,aAAa;QACZ,MAAM,IAAI,+BAAgB,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACjF,CAAC;CACD;AAlDD,kDAkDC"}
|
package/dist/runner-types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { INodeExecutionData } from 'n8n-workflow';
|
|
1
|
+
import type { INodeExecutionData, INodeTypeBaseDescription } from 'n8n-workflow';
|
|
2
2
|
export type DataRequestType = 'input' | 'node' | 'all';
|
|
3
3
|
export interface TaskResultData {
|
|
4
4
|
result: INodeExecutionData[];
|
|
@@ -40,7 +40,11 @@ export declare namespace N8nMessage {
|
|
|
40
40
|
requestId: string;
|
|
41
41
|
data: unknown;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
interface NodeTypes {
|
|
44
|
+
type: 'broker:nodetypes';
|
|
45
|
+
nodeTypes: INodeTypeBaseDescription[];
|
|
46
|
+
}
|
|
47
|
+
type All = InfoRequest | TaskOfferAccept | TaskCancel | TaskSettings | RunnerRegistered | RPCResponse | TaskDataResponse | NodeTypes;
|
|
44
48
|
}
|
|
45
49
|
namespace ToRequester {
|
|
46
50
|
interface TaskReady {
|
package/dist/runner-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner-types.js","sourceRoot":"","sources":["../src/runner-types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"runner-types.js","sourceRoot":"","sources":["../src/runner-types.ts"],"names":[],"mappings":";;;AAoNa,QAAA,cAAc,GAAG;IAC7B,uCAAuC;IACvC,4CAA4C;IAI5C,6BAA6B;IAG7B,sBAAsB;IACtB,0BAA0B;IAE1B,4BAA4B;IAC5B,2BAA2B;IAC3B,6BAA6B;IAC7B,wBAAwB;IACxB,wBAAwB;IAGxB,yBAAyB;IACzB,2BAA2B;IAC3B,+BAA+B;IAC/B,qBAAqB;IACrB,eAAe;CACN,CAAC"}
|
package/dist/start.js
CHANGED
|
@@ -1,43 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
27
|
-
const a = __importStar(require("node:assert/strict"));
|
|
28
|
-
const authenticator_1 = require("./authenticator");
|
|
29
4
|
const js_task_runner_1 = require("./js-task-runner/js-task-runner");
|
|
30
5
|
let runner;
|
|
31
6
|
let isShuttingDown = false;
|
|
32
7
|
function readAndParseConfig() {
|
|
33
|
-
const authToken = process.env.N8N_RUNNERS_AUTH_TOKEN;
|
|
34
8
|
const grantToken = process.env.N8N_RUNNERS_GRANT_TOKEN;
|
|
35
|
-
if (!
|
|
36
|
-
throw new n8n_workflow_1.ApplicationError('Missing
|
|
9
|
+
if (!grantToken) {
|
|
10
|
+
throw new n8n_workflow_1.ApplicationError('Missing N8N_RUNNERS_GRANT_TOKEN environment variable');
|
|
37
11
|
}
|
|
38
12
|
return {
|
|
39
13
|
n8nUri: process.env.N8N_RUNNERS_N8N_URI ?? '127.0.0.1:5679',
|
|
40
|
-
authToken,
|
|
41
14
|
grantToken,
|
|
42
15
|
};
|
|
43
16
|
}
|
|
@@ -65,16 +38,14 @@ function createSignalHandler(signal) {
|
|
|
65
38
|
}
|
|
66
39
|
void (async function start() {
|
|
67
40
|
const config = readAndParseConfig();
|
|
68
|
-
let grantToken = config.grantToken;
|
|
69
|
-
if (!grantToken) {
|
|
70
|
-
a.ok(config.authToken);
|
|
71
|
-
grantToken = await (0, authenticator_1.authenticate)({
|
|
72
|
-
authToken: config.authToken,
|
|
73
|
-
n8nUri: config.n8nUri,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
41
|
const wsUrl = `ws://${config.n8nUri}/runners/_ws`;
|
|
77
|
-
runner = new js_task_runner_1.JsTaskRunner(
|
|
42
|
+
runner = new js_task_runner_1.JsTaskRunner({
|
|
43
|
+
wsUrl,
|
|
44
|
+
grantToken: config.grantToken,
|
|
45
|
+
maxConcurrency: 5,
|
|
46
|
+
allowedBuiltInModules: process.env.NODE_FUNCTION_ALLOW_BUILTIN,
|
|
47
|
+
allowedExternalModules: process.env.NODE_FUNCTION_ALLOW_EXTERNAL,
|
|
48
|
+
});
|
|
78
49
|
process.on('SIGINT', createSignalHandler('SIGINT'));
|
|
79
50
|
process.on('SIGTERM', createSignalHandler('SIGTERM'));
|
|
80
51
|
})().catch((e) => {
|
package/dist/start.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":";;AAAA,+CAA6D;AAE7D,oEAA+D;AAE/D,IAAI,MAAgC,CAAC;AACrC,IAAI,cAAc,GAAG,KAAK,CAAC;AAO3B,SAAS,kBAAkB;IAC1B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACvD,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,MAAM,IAAI,+BAAgB,CAAC,sDAAsD,CAAC,CAAC;IACpF,CAAC;IAED,OAAO;QACN,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,gBAAgB;QAC3D,UAAU;KACV,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc;IAC1C,OAAO,KAAK,UAAU,QAAQ;QAC7B,IAAI,cAAc,EAAE,CAAC;YACpB,OAAO;QACR,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,YAAY,MAAM,2BAA2B,CAAC,CAAC;QAE3D,cAAc,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC;YACJ,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBACpB,MAAM,GAAG,SAAS,CAAC;YACpB,CAAC;QACF,CA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|
+
import { TaskRunnerNodeTypes } from './node-types';
|
|
2
4
|
import { type RunnerMessage, type N8nMessage, type TaskResultData } from './runner-types';
|
|
3
5
|
export interface Task<T = unknown> {
|
|
4
6
|
taskId: string;
|
|
@@ -35,6 +37,7 @@ export declare abstract class TaskRunner {
|
|
|
35
37
|
openOffers: Map<TaskOffer['offerId'], TaskOffer>;
|
|
36
38
|
dataRequests: Map<DataRequest['requestId'], DataRequest>;
|
|
37
39
|
rpcCalls: Map<RPCCall['callId'], RPCCall>;
|
|
40
|
+
nodeTypes: TaskRunnerNodeTypes;
|
|
38
41
|
constructor(taskType: string, wsUrl: string, grantToken: string, maxConcurrency: number, name?: string | undefined);
|
|
39
42
|
private receiveMessage;
|
|
40
43
|
private stopTaskOffers;
|
|
@@ -43,6 +46,7 @@ export declare abstract class TaskRunner {
|
|
|
43
46
|
sendOffers(): void;
|
|
44
47
|
send(message: RunnerMessage.ToN8n.All): void;
|
|
45
48
|
onMessage(message: N8nMessage.ToRunner.All): void;
|
|
49
|
+
setNodeTypes(nodeTypes: INodeTypeDescription[]): void;
|
|
46
50
|
processDataResponse(requestId: string, data: unknown): void;
|
|
47
51
|
hasOpenTasks(): boolean;
|
|
48
52
|
offerAccepted(offerId: string, taskId: string): void;
|