@fsai-flow/core 0.0.5 → 0.1.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.
Files changed (92) hide show
  1. package/dist/index.d.ts +17 -0
  2. package/dist/index.js +61 -0
  3. package/dist/lib/ActiveWebhooks.d.ts +59 -0
  4. package/dist/lib/ActiveWebhooks.js +177 -0
  5. package/dist/lib/ActiveWorkflows.d.ts +87 -0
  6. package/dist/lib/ActiveWorkflows.js +465 -0
  7. package/dist/lib/BinaryDataManager/FileSystem.d.ts +26 -0
  8. package/dist/lib/BinaryDataManager/FileSystem.js +180 -0
  9. package/dist/lib/BinaryDataManager/index.d.ts +21 -0
  10. package/dist/lib/BinaryDataManager/index.js +129 -0
  11. package/dist/lib/ChangeCase.d.ts +9 -0
  12. package/dist/lib/ChangeCase.js +43 -0
  13. package/dist/lib/Constants.d.ts +14 -0
  14. package/dist/lib/Constants.js +18 -0
  15. package/dist/lib/Credentials.d.ts +27 -0
  16. package/dist/lib/Credentials.js +88 -0
  17. package/dist/lib/FileSystem.d.ts +26 -0
  18. package/dist/lib/FileSystem.js +180 -0
  19. package/dist/lib/InputConnectionDataLegacy.d.ts +2 -0
  20. package/dist/lib/InputConnectionDataLegacy.js +72 -0
  21. package/dist/lib/Interfaces.d.ts +147 -0
  22. package/dist/lib/Interfaces.js +2 -0
  23. package/dist/lib/LoadNodeParameterOptions.d.ts +39 -0
  24. package/dist/lib/LoadNodeParameterOptions.js +152 -0
  25. package/dist/lib/NodeExecuteFunctions.d.ts +225 -0
  26. package/dist/lib/NodeExecuteFunctions.js +2467 -0
  27. package/dist/lib/NodesLoader/constants.d.ts +5 -0
  28. package/dist/lib/NodesLoader/constants.js +105 -0
  29. package/dist/lib/NodesLoader/custom-directory-loader.d.ts +9 -0
  30. package/dist/lib/NodesLoader/custom-directory-loader.js +35 -0
  31. package/dist/lib/NodesLoader/directory-loader.d.ts +66 -0
  32. package/dist/lib/NodesLoader/directory-loader.js +367 -0
  33. package/dist/lib/NodesLoader/index.d.ts +5 -0
  34. package/dist/lib/NodesLoader/index.js +11 -0
  35. package/dist/lib/NodesLoader/lazy-package-directory-loader.d.ts +7 -0
  36. package/dist/lib/NodesLoader/lazy-package-directory-loader.js +44 -0
  37. package/dist/lib/NodesLoader/load-class-in-isolation.d.ts +1 -0
  38. package/dist/lib/NodesLoader/load-class-in-isolation.js +17 -0
  39. package/dist/lib/NodesLoader/package-directory-loader.d.ts +17 -0
  40. package/dist/lib/NodesLoader/package-directory-loader.js +92 -0
  41. package/dist/lib/NodesLoader/types.d.ts +14 -0
  42. package/dist/lib/NodesLoader/types.js +2 -0
  43. package/dist/lib/RedisLeaderElectionManager.d.ts +53 -0
  44. package/dist/lib/RedisLeaderElectionManager.js +279 -0
  45. package/dist/lib/RequestTypes.d.ts +58 -0
  46. package/dist/lib/RequestTypes.js +8 -0
  47. package/dist/lib/UserSettings.d.ts +80 -0
  48. package/dist/lib/UserSettings.js +269 -0
  49. package/dist/lib/WorkflowExecute.d.ts +53 -0
  50. package/dist/lib/WorkflowExecute.js +906 -0
  51. package/dist/lib/index.d.ts +21 -0
  52. package/dist/lib/index.js +129 -0
  53. package/dist/utils/crypto.d.ts +1 -0
  54. package/dist/utils/crypto.js +7 -0
  55. package/package.json +52 -52
  56. package/dist/README.md +0 -31
  57. package/dist/package.json +0 -54
  58. package/eslint.config.js +0 -19
  59. package/jest.config.ts +0 -10
  60. package/project.json +0 -19
  61. package/src/index.ts +0 -28
  62. package/src/lib/ActiveWebhooks.ts +0 -245
  63. package/src/lib/ActiveWorkflows.ts +0 -575
  64. package/src/lib/BinaryDataManager/FileSystem.ts +0 -214
  65. package/src/lib/BinaryDataManager/index.ts +0 -187
  66. package/src/lib/ChangeCase.ts +0 -45
  67. package/src/lib/Constants.ts +0 -16
  68. package/src/lib/Credentials.ts +0 -108
  69. package/src/lib/FileSystem.ts +0 -214
  70. package/src/lib/InputConnectionDataLegacy.ts +0 -123
  71. package/src/lib/Interfaces.ts +0 -338
  72. package/src/lib/LoadNodeParameterOptions.ts +0 -235
  73. package/src/lib/NodeExecuteFunctions.ts +0 -3700
  74. package/src/lib/NodesLoader/constants.ts +0 -112
  75. package/src/lib/NodesLoader/custom-directory-loader.ts +0 -31
  76. package/src/lib/NodesLoader/directory-loader.ts +0 -458
  77. package/src/lib/NodesLoader/index.ts +0 -5
  78. package/src/lib/NodesLoader/lazy-package-directory-loader.ts +0 -55
  79. package/src/lib/NodesLoader/load-class-in-isolation.ts +0 -19
  80. package/src/lib/NodesLoader/package-directory-loader.ts +0 -107
  81. package/src/lib/NodesLoader/types.ts +0 -14
  82. package/src/lib/RedisLeaderElectionManager.ts +0 -334
  83. package/src/lib/UserSettings.ts +0 -292
  84. package/src/lib/WorkflowExecute.ts +0 -1128
  85. package/src/lib/index.ts +0 -187
  86. package/src/utils/crypto.ts +0 -5
  87. package/tests/Credentials.test.ts +0 -88
  88. package/tests/Helpers.ts +0 -808
  89. package/tests/WorkflowExecute.test.ts +0 -1242
  90. package/tsconfig.json +0 -41
  91. package/tsconfig.lib.json +0 -10
  92. package/tsconfig.spec.json +0 -14
@@ -0,0 +1,269 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.prepareUserSettings = prepareUserSettings;
37
+ exports.getEncryptionKey = getEncryptionKey;
38
+ exports.getInstanceId = getInstanceId;
39
+ exports.addToUserSettings = addToUserSettings;
40
+ exports.writeUserSettings = writeUserSettings;
41
+ exports.getUserSettings = getUserSettings;
42
+ exports.getUserSettingsPath = getUserSettingsPath;
43
+ exports.getUserN8nFolderPath = getUserN8nFolderPath;
44
+ exports.getUserN8nFolderCustomExtensionPath = getUserN8nFolderCustomExtensionPath;
45
+ exports.getUserHome = getUserHome;
46
+ const node_crypto_1 = require("node:crypto");
47
+ /* eslint-disable no-param-reassign */
48
+ /* eslint-disable @typescript-eslint/no-use-before-define */
49
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
50
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
51
+ const fs = __importStar(require("node:fs"));
52
+ const path = __importStar(require("node:path"));
53
+ const node_util_1 = require("node:util");
54
+ // eslint-disable-next-line import/no-cycle
55
+ const __1 = require("..");
56
+ const fsAccess = (0, node_util_1.promisify)(fs.access);
57
+ const fsReadFile = (0, node_util_1.promisify)(fs.readFile);
58
+ const fsMkdir = (0, node_util_1.promisify)(fs.mkdir);
59
+ const fsWriteFile = (0, node_util_1.promisify)(fs.writeFile);
60
+ let settingsCache;
61
+ /**
62
+ * Creates the user settings if they do not exist yet
63
+ *
64
+ * @export
65
+ */
66
+ async function prepareUserSettings() {
67
+ const settingsPath = getUserSettingsPath();
68
+ let userSettings = await getUserSettings(settingsPath);
69
+ if (userSettings !== undefined) {
70
+ // Settings already exist, check if they contain the encryptionKey
71
+ if (userSettings.encryptionKey !== undefined) {
72
+ // Key already exists
73
+ if (userSettings.instanceId === undefined) {
74
+ userSettings.instanceId = await generateInstanceId(userSettings.encryptionKey);
75
+ settingsCache = userSettings;
76
+ }
77
+ return userSettings;
78
+ }
79
+ }
80
+ else {
81
+ userSettings = {};
82
+ }
83
+ if (process.env[__1.ENCRYPTION_KEY_ENV_OVERWRITE] !== undefined) {
84
+ // Use the encryption key which got set via environment
85
+ userSettings.encryptionKey = process.env[__1.ENCRYPTION_KEY_ENV_OVERWRITE];
86
+ }
87
+ else {
88
+ // Generate a new encryption key
89
+ userSettings.encryptionKey = (0, node_crypto_1.randomBytes)(24).toString("base64");
90
+ }
91
+ userSettings.instanceId = await generateInstanceId(userSettings.encryptionKey);
92
+ // eslint-disable-next-line no-console
93
+ console.log(`UserSettings were generated and saved to: ${settingsPath}`);
94
+ return writeUserSettings(userSettings, settingsPath);
95
+ }
96
+ /**
97
+ * Returns the encryption key which is used to encrypt
98
+ * the credentials.
99
+ *
100
+ * @export
101
+ * @returns
102
+ */
103
+ async function getEncryptionKey() {
104
+ if (process.env[__1.ENCRYPTION_KEY_ENV_OVERWRITE] !== undefined) {
105
+ return process.env[__1.ENCRYPTION_KEY_ENV_OVERWRITE];
106
+ }
107
+ const userSettings = await getUserSettings();
108
+ if (userSettings === undefined) {
109
+ return undefined;
110
+ }
111
+ if (userSettings.encryptionKey === undefined) {
112
+ return undefined;
113
+ }
114
+ return userSettings.encryptionKey;
115
+ }
116
+ /**
117
+ * Returns the instance ID
118
+ *
119
+ * @export
120
+ * @returns
121
+ */
122
+ async function getInstanceId() {
123
+ const userSettings = await getUserSettings();
124
+ if (userSettings === undefined) {
125
+ return "";
126
+ }
127
+ if (userSettings.instanceId === undefined) {
128
+ return "";
129
+ }
130
+ return userSettings.instanceId;
131
+ }
132
+ async function generateInstanceId(key) {
133
+ const hash = key
134
+ ? (0, node_crypto_1.createHash)("sha256")
135
+ .update(key.slice(Math.round(key.length / 2)))
136
+ .digest("hex")
137
+ : undefined;
138
+ return hash;
139
+ }
140
+ /**
141
+ * Adds/Overwrite the given settings in the currently
142
+ * saved user settings
143
+ *
144
+ * @export
145
+ * @param {IUserSettings} addSettings The settings to add/overwrite
146
+ * @param {string} [settingsPath] Optional settings file path
147
+ * @returns {Promise<IUserSettings>}
148
+ */
149
+ async function addToUserSettings(addSettings, settingsPath) {
150
+ const resolvedSettingsPath = settingsPath ?? getUserSettingsPath();
151
+ let userSettings = await getUserSettings(resolvedSettingsPath);
152
+ if (userSettings === undefined) {
153
+ userSettings = {};
154
+ }
155
+ // Add the settings
156
+ Object.assign(userSettings, addSettings);
157
+ return writeUserSettings(userSettings, resolvedSettingsPath);
158
+ }
159
+ /**
160
+ * Writes a user settings file
161
+ *
162
+ * @export
163
+ * @param {IUserSettings} userSettings The settings to write
164
+ * @param {string} [settingsPath] Optional settings file path
165
+ * @returns {Promise<IUserSettings>}
166
+ */
167
+ async function writeUserSettings(userSettings, settingsPath) {
168
+ const resolvedSettingsPath = settingsPath ?? getUserSettingsPath();
169
+ const resolvedUserSettings = userSettings ?? {};
170
+ // Check if parent folder exists if not create it.
171
+ try {
172
+ await fsAccess(path.dirname(resolvedSettingsPath));
173
+ }
174
+ catch (_error) {
175
+ // Parent folder does not exist so create
176
+ await fsMkdir(path.dirname(resolvedSettingsPath));
177
+ }
178
+ const settingsToWrite = { ...resolvedUserSettings };
179
+ if (settingsToWrite.instanceId !== undefined) {
180
+ settingsToWrite.instanceId = undefined;
181
+ }
182
+ await fsWriteFile(resolvedSettingsPath, JSON.stringify(settingsToWrite, null, "\t"));
183
+ settingsCache = JSON.parse(JSON.stringify(resolvedUserSettings));
184
+ return resolvedUserSettings;
185
+ }
186
+ /**
187
+ * Returns the content of the user settings
188
+ *
189
+ * @export
190
+ * @returns {UserSettings}
191
+ */
192
+ async function getUserSettings(settingsPath, ignoreCache) {
193
+ if (settingsCache !== undefined && ignoreCache !== true) {
194
+ return settingsCache;
195
+ }
196
+ const resolvedSettingsPath = settingsPath ?? getUserSettingsPath();
197
+ try {
198
+ await fsAccess(resolvedSettingsPath);
199
+ }
200
+ catch (_error) {
201
+ // The file does not exist
202
+ return undefined;
203
+ }
204
+ const settingsFile = await fsReadFile(resolvedSettingsPath, "utf8");
205
+ try {
206
+ settingsCache = JSON.parse(settingsFile);
207
+ }
208
+ catch (_error) {
209
+ throw new Error(`Error parsing n8n-config file "${resolvedSettingsPath}". It does not seem to be valid JSON.`);
210
+ }
211
+ return settingsCache;
212
+ }
213
+ /**
214
+ * Returns the path to the user settings
215
+ *
216
+ * @export
217
+ * @returns {string}
218
+ */
219
+ function getUserSettingsPath() {
220
+ const n8nFolder = getUserN8nFolderPath();
221
+ return path.join(n8nFolder, __1.USER_SETTINGS_FILE_NAME);
222
+ }
223
+ /**
224
+ * Retruns the path to the n8n folder in which all n8n
225
+ * related data gets saved
226
+ *
227
+ * @export
228
+ * @returns {string}
229
+ */
230
+ function getUserN8nFolderPath() {
231
+ let userFolder;
232
+ if (process.env[__1.USER_FOLDER_ENV_OVERWRITE] !== undefined) {
233
+ userFolder = process.env[__1.USER_FOLDER_ENV_OVERWRITE];
234
+ }
235
+ else {
236
+ userFolder = getUserHome();
237
+ }
238
+ return path.join(userFolder, __1.USER_SETTINGS_SUBFOLDER);
239
+ }
240
+ /**
241
+ * Returns the path to the n8n user folder with the custom
242
+ * extensions like nodes and credentials
243
+ *
244
+ * @export
245
+ * @returns {string}
246
+ */
247
+ function getUserN8nFolderCustomExtensionPath() {
248
+ return path.join(getUserN8nFolderPath(), __1.EXTENSIONS_SUBDIRECTORY);
249
+ }
250
+ /**
251
+ * Returns the home folder path of the user if
252
+ * none can be found it falls back to the current
253
+ * working directory
254
+ *
255
+ * @export
256
+ * @returns {string}
257
+ */
258
+ function getUserHome() {
259
+ let variableName = "HOME";
260
+ if (process.platform === "win32") {
261
+ variableName = "USERPROFILE";
262
+ }
263
+ if (process.env[variableName] === undefined) {
264
+ // If for some reason the variable does not exist
265
+ // fall back to current folder
266
+ return process.cwd();
267
+ }
268
+ return process.env[variableName];
269
+ }
@@ -0,0 +1,53 @@
1
+ import { type ExecutionError, type IConnection, type INode, type INodeExecutionData, type IRun, type IRunData, type IRunExecutionData, type IWorkflowExecuteAdditionalData, type Workflow, type WorkflowExecuteMode } from "@fsai-flow/workflow";
2
+ import PCancelable from "p-cancelable";
3
+ export declare class WorkflowExecute {
4
+ runExecutionData: IRunExecutionData;
5
+ private additionalData;
6
+ private mode;
7
+ constructor(additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode, runExecutionData?: IRunExecutionData);
8
+ /**
9
+ * Executes the given workflow.
10
+ *
11
+ * @param {Workflow} workflow The workflow to execute
12
+ * @param {INode[]} [startNodes] Node to start execution from
13
+ * @param {string} [destinationNode] Node to stop execution at
14
+ * @returns {(Promise<string>)}
15
+ * @memberof WorkflowExecute
16
+ */
17
+ run(workflow: Workflow, startNode?: INode, destinationNode?: string): PCancelable<IRun>;
18
+ /**
19
+ * Executes the given workflow but only
20
+ *
21
+ * @param {Workflow} workflow The workflow to execute
22
+ * @param {IRunData} runData
23
+ * @param {string[]} startNodes Nodes to start execution from
24
+ * @param {string} destinationNode Node to stop execution at
25
+ * @returns {(Promise<string>)}
26
+ * @memberof WorkflowExecute
27
+ */
28
+ runPartialWorkflow(workflow: Workflow, runData: IRunData, startNodes: string[], destinationNode: string): PCancelable<IRun>;
29
+ /**
30
+ * Executes the hook with the given name
31
+ *
32
+ * @param {string} hookName
33
+ * @param {unknown[]} parameters
34
+ * @returns {Promise<IRun>}
35
+ * @memberof WorkflowExecute
36
+ */
37
+ executeHook(hookName: string, parameters: unknown[]): Promise<void>;
38
+ /**
39
+ * Checks the incoming connection does not receive any data
40
+ */
41
+ incomingConnectionIsEmpty(runData: IRunData, inputConnections: IConnection[], runIndex: number): boolean;
42
+ addNodeToBeExecuted(workflow: Workflow, connectionData: IConnection, outputIndex: number, parentNodeName: string, nodeSuccessData: INodeExecutionData[][], runIndex: number): void;
43
+ /**
44
+ * Runs the given execution data.
45
+ *
46
+ * @param {Workflow} workflow
47
+ * @returns {Promise<string>}
48
+ * @memberof WorkflowExecute
49
+ */
50
+ processRunExecutionData(workflow: Workflow): PCancelable<IRun>;
51
+ processSuccessExecution(startedAt: Date, workflow: Workflow, executionError?: ExecutionError): Promise<IRun>;
52
+ getFullRunData(startedAt: Date): IRun;
53
+ }