@fsai-flow/core 0.0.4 → 0.1.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.
Files changed (136) hide show
  1. package/dist/index.d.ts +17 -0
  2. package/dist/index.js +61 -0
  3. package/dist/{src/lib → lib}/ActiveWebhooks.d.ts +1 -1
  4. package/dist/lib/ActiveWebhooks.js +177 -0
  5. package/dist/{src/lib → lib}/ActiveWorkflows.d.ts +3 -3
  6. package/dist/lib/ActiveWorkflows.js +465 -0
  7. package/dist/{src/lib → lib}/BinaryDataManager/FileSystem.d.ts +1 -1
  8. package/dist/lib/BinaryDataManager/FileSystem.js +180 -0
  9. package/dist/{src/lib → lib}/BinaryDataManager/index.d.ts +2 -2
  10. package/dist/lib/BinaryDataManager/index.js +129 -0
  11. package/dist/{src/lib → lib}/ChangeCase.js +11 -11
  12. package/dist/lib/Constants.js +18 -0
  13. package/dist/{src/lib → lib}/Credentials.d.ts +1 -1
  14. package/dist/{src/lib → lib}/Credentials.js +7 -8
  15. package/dist/{src/lib → lib}/FileSystem.d.ts +1 -1
  16. package/dist/lib/FileSystem.js +180 -0
  17. package/dist/{src/lib → lib}/InputConnectionDataLegacy.d.ts +1 -1
  18. package/dist/lib/InputConnectionDataLegacy.js +72 -0
  19. package/dist/{src/lib → lib}/Interfaces.d.ts +47 -48
  20. package/dist/{src/lib → lib}/Interfaces.js +0 -1
  21. package/dist/{src/lib → lib}/LoadNodeParameterOptions.d.ts +1 -1
  22. package/dist/lib/LoadNodeParameterOptions.js +152 -0
  23. package/dist/{src/lib → lib}/NodeExecuteFunctions.d.ts +9 -10
  24. package/dist/lib/NodeExecuteFunctions.js +2467 -0
  25. package/dist/{src/lib → lib}/NodesLoader/constants.d.ts +1 -1
  26. package/dist/lib/NodesLoader/constants.js +105 -0
  27. package/dist/{src/lib → lib}/NodesLoader/custom-directory-loader.d.ts +1 -1
  28. package/dist/lib/NodesLoader/custom-directory-loader.js +35 -0
  29. package/dist/{src/lib → lib}/NodesLoader/directory-loader.d.ts +1 -1
  30. package/dist/{src/lib → lib}/NodesLoader/directory-loader.js +80 -38
  31. package/dist/lib/NodesLoader/index.d.ts +5 -0
  32. package/dist/{src/lib → lib}/NodesLoader/index.js +5 -6
  33. package/dist/{src/lib → lib}/NodesLoader/lazy-package-directory-loader.d.ts +1 -1
  34. package/dist/lib/NodesLoader/lazy-package-directory-loader.js +44 -0
  35. package/dist/{src/lib → lib}/NodesLoader/load-class-in-isolation.js +6 -11
  36. package/dist/{src/lib → lib}/NodesLoader/package-directory-loader.d.ts +2 -2
  37. package/dist/{src/lib → lib}/NodesLoader/package-directory-loader.js +28 -36
  38. package/dist/{src/lib → lib}/NodesLoader/types.js +0 -1
  39. package/dist/{src/lib → lib}/RedisLeaderElectionManager.d.ts +1 -1
  40. package/dist/lib/RedisLeaderElectionManager.js +279 -0
  41. package/dist/lib/RequestTypes.d.ts +58 -0
  42. package/dist/lib/RequestTypes.js +8 -0
  43. package/dist/{src/lib → lib}/UserSettings.d.ts +1 -1
  44. package/dist/lib/UserSettings.js +269 -0
  45. package/dist/{src/lib → lib}/WorkflowExecute.d.ts +4 -4
  46. package/dist/{src/lib → lib}/WorkflowExecute.js +230 -178
  47. package/dist/{src/lib → lib}/index.d.ts +2 -2
  48. package/dist/lib/index.js +129 -0
  49. package/dist/{src/utils → utils}/crypto.js +2 -3
  50. package/package.json +59 -52
  51. package/dist/README.md +0 -31
  52. package/dist/package.json +0 -54
  53. package/dist/src/index.d.ts +0 -16
  54. package/dist/src/index.js +0 -30
  55. package/dist/src/index.js.map +0 -1
  56. package/dist/src/lib/ActiveWebhooks.js +0 -184
  57. package/dist/src/lib/ActiveWebhooks.js.map +0 -1
  58. package/dist/src/lib/ActiveWorkflows.js +0 -456
  59. package/dist/src/lib/ActiveWorkflows.js.map +0 -1
  60. package/dist/src/lib/BinaryDataManager/FileSystem.js +0 -179
  61. package/dist/src/lib/BinaryDataManager/FileSystem.js.map +0 -1
  62. package/dist/src/lib/BinaryDataManager/index.js +0 -146
  63. package/dist/src/lib/BinaryDataManager/index.js.map +0 -1
  64. package/dist/src/lib/ChangeCase.js.map +0 -1
  65. package/dist/src/lib/Constants.js +0 -19
  66. package/dist/src/lib/Constants.js.map +0 -1
  67. package/dist/src/lib/Credentials.js.map +0 -1
  68. package/dist/src/lib/FileSystem.js +0 -179
  69. package/dist/src/lib/FileSystem.js.map +0 -1
  70. package/dist/src/lib/InputConnectionDataLegacy.js +0 -79
  71. package/dist/src/lib/InputConnectionDataLegacy.js.map +0 -1
  72. package/dist/src/lib/Interfaces.js.map +0 -1
  73. package/dist/src/lib/LoadNodeParameterOptions.js +0 -150
  74. package/dist/src/lib/LoadNodeParameterOptions.js.map +0 -1
  75. package/dist/src/lib/NodeExecuteFunctions.js +0 -2479
  76. package/dist/src/lib/NodeExecuteFunctions.js.map +0 -1
  77. package/dist/src/lib/NodesLoader/constants.js +0 -106
  78. package/dist/src/lib/NodesLoader/constants.js.map +0 -1
  79. package/dist/src/lib/NodesLoader/custom-directory-loader.js +0 -36
  80. package/dist/src/lib/NodesLoader/custom-directory-loader.js.map +0 -1
  81. package/dist/src/lib/NodesLoader/directory-loader.js.map +0 -1
  82. package/dist/src/lib/NodesLoader/index.d.ts +0 -5
  83. package/dist/src/lib/NodesLoader/index.js.map +0 -1
  84. package/dist/src/lib/NodesLoader/lazy-package-directory-loader.js +0 -52
  85. package/dist/src/lib/NodesLoader/lazy-package-directory-loader.js.map +0 -1
  86. package/dist/src/lib/NodesLoader/load-class-in-isolation.js.map +0 -1
  87. package/dist/src/lib/NodesLoader/package-directory-loader.js.map +0 -1
  88. package/dist/src/lib/NodesLoader/types.js.map +0 -1
  89. package/dist/src/lib/RedisLeaderElectionManager.js +0 -294
  90. package/dist/src/lib/RedisLeaderElectionManager.js.map +0 -1
  91. package/dist/src/lib/UserSettings.js +0 -261
  92. package/dist/src/lib/UserSettings.js.map +0 -1
  93. package/dist/src/lib/WorkflowExecute.js.map +0 -1
  94. package/dist/src/lib/index.js +0 -146
  95. package/dist/src/lib/index.js.map +0 -1
  96. package/dist/src/utils/crypto.js.map +0 -1
  97. package/eslint.config.js +0 -19
  98. package/jest.config.ts +0 -10
  99. package/project.json +0 -19
  100. package/src/index.ts +0 -28
  101. package/src/lib/ActiveWebhooks.ts +0 -245
  102. package/src/lib/ActiveWorkflows.ts +0 -575
  103. package/src/lib/BinaryDataManager/FileSystem.ts +0 -214
  104. package/src/lib/BinaryDataManager/index.ts +0 -187
  105. package/src/lib/ChangeCase.ts +0 -45
  106. package/src/lib/Constants.ts +0 -16
  107. package/src/lib/Credentials.ts +0 -108
  108. package/src/lib/FileSystem.ts +0 -214
  109. package/src/lib/InputConnectionDataLegacy.ts +0 -123
  110. package/src/lib/Interfaces.ts +0 -338
  111. package/src/lib/LoadNodeParameterOptions.ts +0 -235
  112. package/src/lib/NodeExecuteFunctions.ts +0 -3700
  113. package/src/lib/NodesLoader/constants.ts +0 -112
  114. package/src/lib/NodesLoader/custom-directory-loader.ts +0 -31
  115. package/src/lib/NodesLoader/directory-loader.ts +0 -458
  116. package/src/lib/NodesLoader/index.ts +0 -5
  117. package/src/lib/NodesLoader/lazy-package-directory-loader.ts +0 -55
  118. package/src/lib/NodesLoader/load-class-in-isolation.ts +0 -19
  119. package/src/lib/NodesLoader/package-directory-loader.ts +0 -107
  120. package/src/lib/NodesLoader/types.ts +0 -14
  121. package/src/lib/RedisLeaderElectionManager.ts +0 -334
  122. package/src/lib/UserSettings.ts +0 -292
  123. package/src/lib/WorkflowExecute.ts +0 -1128
  124. package/src/lib/index.ts +0 -187
  125. package/src/utils/crypto.ts +0 -5
  126. package/tests/Credentials.test.ts +0 -88
  127. package/tests/Helpers.ts +0 -808
  128. package/tests/WorkflowExecute.test.ts +0 -1242
  129. package/tsconfig.json +0 -41
  130. package/tsconfig.lib.json +0 -10
  131. package/tsconfig.spec.json +0 -14
  132. /package/dist/{src/lib → lib}/ChangeCase.d.ts +0 -0
  133. /package/dist/{src/lib → lib}/Constants.d.ts +0 -0
  134. /package/dist/{src/lib → lib}/NodesLoader/load-class-in-isolation.d.ts +0 -0
  135. /package/dist/{src/lib → lib}/NodesLoader/types.d.ts +0 -0
  136. /package/dist/{src/utils → utils}/crypto.d.ts +0 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinaryDataManager = void 0;
4
+ const Constants_1 = require("../Constants");
5
+ const FileSystem_1 = require("./FileSystem");
6
+ class BinaryDataManager {
7
+ constructor(config) {
8
+ this.binaryDataMode = config.mode;
9
+ this.availableModes = config.availableModes.split(",");
10
+ this.managers = {};
11
+ }
12
+ static async init(config, mainManager = false) {
13
+ if (BinaryDataManager.instance) {
14
+ throw new Error("Binary Data Manager already initialized");
15
+ }
16
+ BinaryDataManager.instance = new BinaryDataManager(config);
17
+ if (BinaryDataManager.instance.availableModes.includes("filesystem")) {
18
+ BinaryDataManager.instance.managers["filesystem"] =
19
+ new FileSystem_1.BinaryDataFileSystem(config);
20
+ await BinaryDataManager.instance.managers["filesystem"].init(mainManager);
21
+ }
22
+ return undefined;
23
+ }
24
+ static getInstance() {
25
+ if (!BinaryDataManager.instance) {
26
+ throw new Error("Binary Data Manager not initialized");
27
+ }
28
+ return BinaryDataManager.instance;
29
+ }
30
+ async storeBinaryData(binaryData, binaryBuffer, executionId) {
31
+ const retBinaryData = binaryData;
32
+ if (this.managers[this.binaryDataMode]) {
33
+ return this.managers[this.binaryDataMode]
34
+ .storeBinaryData(binaryBuffer, executionId)
35
+ .then((filename) => {
36
+ retBinaryData.id = this.generateBinaryId(filename);
37
+ return retBinaryData;
38
+ });
39
+ }
40
+ retBinaryData.data = binaryBuffer.toString(Constants_1.BINARY_ENCODING);
41
+ return binaryData;
42
+ }
43
+ async retrieveBinaryData(binaryData) {
44
+ if (binaryData.id) {
45
+ return this.retrieveBinaryDataByIdentifier(binaryData.id);
46
+ }
47
+ return Buffer.from(binaryData.data, Constants_1.BINARY_ENCODING);
48
+ }
49
+ async retrieveBinaryDataByIdentifier(identifier) {
50
+ const { mode, id } = this.splitBinaryModeFileId(identifier);
51
+ if (this.managers[mode]) {
52
+ return this.managers[mode].retrieveBinaryDataByIdentifier(id);
53
+ }
54
+ throw new Error("Storage mode used to store binary data not available");
55
+ }
56
+ async markDataForDeletionByExecutionId(executionId) {
57
+ if (this.managers[this.binaryDataMode]) {
58
+ return this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(executionId);
59
+ }
60
+ return Promise.resolve();
61
+ }
62
+ async persistBinaryDataForExecutionId(executionId) {
63
+ if (this.managers[this.binaryDataMode]) {
64
+ return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
65
+ }
66
+ return Promise.resolve();
67
+ }
68
+ async deleteBinaryDataByExecutionId(executionId) {
69
+ if (this.managers[this.binaryDataMode]) {
70
+ return this.managers[this.binaryDataMode].deleteBinaryDataByExecutionId(executionId);
71
+ }
72
+ return Promise.resolve();
73
+ }
74
+ async duplicateBinaryData(inputData, executionId) {
75
+ if (inputData && this.managers[this.binaryDataMode]) {
76
+ const returnInputData = inputData.map(async (executionDataArray) => {
77
+ if (executionDataArray) {
78
+ return Promise.all(executionDataArray.map((executionData) => {
79
+ if (executionData.binary) {
80
+ return this.duplicateBinaryDataInExecData(executionData, executionId);
81
+ }
82
+ return executionData;
83
+ }));
84
+ }
85
+ return executionDataArray;
86
+ });
87
+ return Promise.all(returnInputData);
88
+ }
89
+ return Promise.resolve(inputData);
90
+ }
91
+ generateBinaryId(filename) {
92
+ return `${this.binaryDataMode}:${filename}`;
93
+ }
94
+ splitBinaryModeFileId(fileId) {
95
+ const [mode, id] = fileId.split(":");
96
+ return { mode, id };
97
+ }
98
+ async duplicateBinaryDataInExecData(executionData, executionId) {
99
+ const binaryManager = this.managers[this.binaryDataMode];
100
+ if (executionData.binary) {
101
+ const binaryDataKeys = Object.keys(executionData.binary);
102
+ const bdPromises = binaryDataKeys.map(async (key) => {
103
+ if (!executionData.binary) {
104
+ return { key, newId: undefined };
105
+ }
106
+ const binaryDataId = executionData.binary[key].id;
107
+ if (!binaryDataId) {
108
+ return { key, newId: undefined };
109
+ }
110
+ return binaryManager
111
+ ?.duplicateBinaryDataByIdentifier(this.splitBinaryModeFileId(binaryDataId).id, executionId)
112
+ .then((filename) => ({
113
+ newId: this.generateBinaryId(filename),
114
+ key,
115
+ }));
116
+ });
117
+ return Promise.all(bdPromises).then((b) => {
118
+ return b.reduce((acc, curr) => {
119
+ if (acc.binary && curr) {
120
+ acc.binary[curr.key].id = curr.newId;
121
+ }
122
+ return acc;
123
+ }, executionData);
124
+ });
125
+ }
126
+ return executionData;
127
+ }
128
+ }
129
+ exports.BinaryDataManager = BinaryDataManager;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChangeCase = void 0;
4
+ // biome-ignore lint/complexity/noStaticOnlyClass: Exported as a utility namespace
4
5
  class ChangeCase {
5
6
  static transformInput(input) {
6
7
  return input
@@ -10,20 +11,20 @@ class ChangeCase {
10
11
  }
11
12
  static toCamelCase(str) {
12
13
  const words = ChangeCase.transformInput(str);
13
- return words[0].toLowerCase() + words.slice(1).join('');
14
+ return words[0].toLowerCase() + words.slice(1).join("");
14
15
  }
15
16
  static toPascalCase(str) {
16
17
  const words = str
17
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2') // insert space before capital letters in camelCase
18
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2") // insert space before capital letters in camelCase
18
19
  .split(/[^a-zA-Z0-9]+|[\s]+/) // split by non-alphanumerics and added spaces
19
- .filter(word => word.length > 0)
20
- .map(word => word[0].toUpperCase() + word.slice(1).toLowerCase());
21
- return words.join('');
20
+ .filter((word) => word.length > 0)
21
+ .map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase());
22
+ return words.join("");
22
23
  }
23
24
  static toSnakeCase(str) {
24
25
  return str
25
- .replace(/([a-z])([A-Z])/g, '$1_$2')
26
- .replace(/[\W_]+/g, '_')
26
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
27
+ .replace(/[\W_]+/g, "_")
27
28
  .toLowerCase();
28
29
  }
29
30
  static toCapitalCase(str) {
@@ -31,13 +32,12 @@ class ChangeCase {
31
32
  }
32
33
  static toParamCase(str) {
33
34
  return str
34
- .replace(/([a-z])([A-Z])/g, '$1-$2')
35
- .replace(/[\W_]+/g, '-')
35
+ .replace(/([a-z])([A-Z])/g, "$1-$2")
36
+ .replace(/[\W_]+/g, "-")
36
37
  .toLowerCase();
37
38
  }
38
39
  static noCase(str) {
39
- return str.replace(/[^\w\s]/g, '').toLowerCase();
40
+ return str.replace(/[^\w\s]/g, "").toLowerCase();
40
41
  }
41
42
  }
42
43
  exports.ChangeCase = ChangeCase;
43
- //# sourceMappingURL=ChangeCase.js.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WAIT_TIME_UNLIMITED = exports.TUNNEL_SUBDOMAIN_ENV = exports.PLACEHOLDER_EMPTY_WORKFLOW_ID = exports.PLACEHOLDER_EMPTY_EXECUTION_ID = exports.USER_SETTINGS_SUBFOLDER = exports.USER_SETTINGS_FILE_NAME = exports.USER_FOLDER_ENV_OVERWRITE = exports.EXTENSIONS_SUBDIRECTORY = exports.ENCRYPTION_KEY_ENV_OVERWRITE = exports.CUSTOM_EXTENSION_ENV = exports.BINARY_ENCODING = exports.inTest = exports.inDevelopment = exports.inProduction = void 0;
4
+ const { NODE_ENV } = process.env;
5
+ exports.inProduction = NODE_ENV === "production";
6
+ exports.inDevelopment = !NODE_ENV || NODE_ENV === "development";
7
+ exports.inTest = NODE_ENV === "test";
8
+ exports.BINARY_ENCODING = "base64";
9
+ exports.CUSTOM_EXTENSION_ENV = "N8N_CUSTOM_EXTENSIONS";
10
+ exports.ENCRYPTION_KEY_ENV_OVERWRITE = "FSAI_FLOW_ENCRYPTION_KEY";
11
+ exports.EXTENSIONS_SUBDIRECTORY = "custom";
12
+ exports.USER_FOLDER_ENV_OVERWRITE = "N8N_USER_FOLDER";
13
+ exports.USER_SETTINGS_FILE_NAME = "config";
14
+ exports.USER_SETTINGS_SUBFOLDER = ".n8n";
15
+ exports.PLACEHOLDER_EMPTY_EXECUTION_ID = "__UNKOWN__";
16
+ exports.PLACEHOLDER_EMPTY_WORKFLOW_ID = "__EMPTY__";
17
+ exports.TUNNEL_SUBDOMAIN_ENV = "N8N_TUNNEL_SUBDOMAIN";
18
+ exports.WAIT_TIME_UNLIMITED = "3000-01-01T00:00:00.000Z";
@@ -1,4 +1,4 @@
1
- import { CredentialInformation, ICredentialDataDecryptedObject, ICredentials, ICredentialsEncrypted } from '@fsai-flow/workflow';
1
+ import { type CredentialInformation, type ICredentialDataDecryptedObject, ICredentials, type ICredentialsEncrypted } from "@fsai-flow/workflow";
2
2
  export declare class Credentials extends ICredentials {
3
3
  /**
4
4
  * Returns if the given nodeType has access to data
@@ -30,11 +30,11 @@ class Credentials extends workflow_1.ICredentials {
30
30
  try {
31
31
  fullData = this.getData(encryptionKey);
32
32
  }
33
- catch (e) {
33
+ catch (_e) {
34
34
  fullData = {};
35
35
  }
36
36
  fullData[key] = data;
37
- return this.setData(fullData, encryptionKey);
37
+ this.setData(fullData, encryptionKey);
38
38
  }
39
39
  /**
40
40
  * Returns the decrypted credential object
@@ -44,14 +44,14 @@ class Credentials extends workflow_1.ICredentials {
44
44
  throw new Error(`The node of type "${nodeType}" does not have access to credentials "${this.name}" of type "${this.type}".`);
45
45
  }
46
46
  if (this.data === undefined) {
47
- throw new Error('No data is set so nothing can be returned.');
47
+ throw new Error("No data is set so nothing can be returned.");
48
48
  }
49
49
  const decryptedData = crypto_js_1.AES.decrypt(this.data, encryptionKey);
50
50
  try {
51
51
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
52
52
  return JSON.parse(decryptedData.toString(crypto_js_1.enc.Utf8));
53
53
  }
54
- catch (e) {
54
+ catch (_e) {
55
55
  throw new Error('Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data.');
56
56
  }
57
57
  }
@@ -61,10 +61,10 @@ class Credentials extends workflow_1.ICredentials {
61
61
  getDataKey(key, encryptionKey, nodeType) {
62
62
  const fullData = this.getData(encryptionKey, nodeType);
63
63
  if (fullData === null) {
64
- throw new Error(`No data was set.`);
64
+ throw new Error("No data was set.");
65
65
  }
66
66
  // eslint-disable-next-line no-prototype-builtins
67
- if (!fullData.hasOwnProperty(key)) {
67
+ if (!Object.hasOwn(fullData, key)) {
68
68
  throw new Error(`No data for key "${key}" exists.`);
69
69
  }
70
70
  return fullData[key];
@@ -74,7 +74,7 @@ class Credentials extends workflow_1.ICredentials {
74
74
  */
75
75
  getDataToSave() {
76
76
  if (this.data === undefined) {
77
- throw new Error(`No credentials were set to save.`);
77
+ throw new Error("No credentials were set to save.");
78
78
  }
79
79
  return {
80
80
  id: this.id,
@@ -86,4 +86,3 @@ class Credentials extends workflow_1.ICredentials {
86
86
  }
87
87
  }
88
88
  exports.Credentials = Credentials;
89
- //# sourceMappingURL=Credentials.js.map
@@ -1,4 +1,4 @@
1
- import { IBinaryDataConfig, IBinaryDataManager } from './Interfaces';
1
+ import type { IBinaryDataConfig, IBinaryDataManager } from "./Interfaces";
2
2
  export declare class BinaryDataFileSystem implements IBinaryDataManager {
3
3
  private storagePath;
4
4
  private binaryDataTTL;
@@ -0,0 +1,180 @@
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.BinaryDataFileSystem = void 0;
37
+ const node_fs_1 = require("node:fs");
38
+ const path = __importStar(require("node:path"));
39
+ const uuid_1 = require("uuid");
40
+ const PREFIX_METAFILE = "binarymeta";
41
+ const PREFIX_PERSISTED_METAFILE = "persistedmeta";
42
+ class BinaryDataFileSystem {
43
+ constructor(config) {
44
+ this.storagePath = config.localStoragePath;
45
+ this.binaryDataTTL = config.binaryDataTTL;
46
+ this.persistedBinaryDataTTL = config.persistedBinaryDataTTL;
47
+ }
48
+ async init(startPurger = false) {
49
+ if (startPurger) {
50
+ setInterval(async () => {
51
+ await this.deleteMarkedFiles();
52
+ }, this.binaryDataTTL * 30000);
53
+ setInterval(async () => {
54
+ await this.deleteMarkedPersistedFiles();
55
+ }, this.persistedBinaryDataTTL * 30000);
56
+ }
57
+ return node_fs_1.promises
58
+ .readdir(this.storagePath)
59
+ .catch(async () => node_fs_1.promises.mkdir(this.storagePath, { recursive: true }))
60
+ .then(async () => node_fs_1.promises.readdir(this.getBinaryDataMetaPath()))
61
+ .catch(async () => node_fs_1.promises.mkdir(this.getBinaryDataMetaPath(), { recursive: true }))
62
+ .then(async () => node_fs_1.promises.readdir(this.getBinaryDataPersistMetaPath()))
63
+ .catch(async () => node_fs_1.promises.mkdir(this.getBinaryDataPersistMetaPath(), { recursive: true }))
64
+ .then(async () => this.deleteMarkedFiles())
65
+ .then(async () => this.deleteMarkedPersistedFiles())
66
+ .then(() => { });
67
+ }
68
+ async storeBinaryData(binaryBuffer, executionId) {
69
+ const binaryDataId = this.generateFileName(executionId);
70
+ return this.addBinaryIdToPersistMeta(executionId, binaryDataId).then(async () => this.saveToLocalStorage(binaryBuffer, binaryDataId).then(() => binaryDataId));
71
+ }
72
+ async retrieveBinaryDataByIdentifier(identifier) {
73
+ return this.retrieveFromLocalStorage(identifier);
74
+ }
75
+ async markDataForDeletionByExecutionId(executionId) {
76
+ const tt = new Date(Date.now() + this.binaryDataTTL * 60000);
77
+ return node_fs_1.promises.writeFile(path.join(this.getBinaryDataMetaPath(), `${PREFIX_METAFILE}_${executionId}_${tt.valueOf()}`), "");
78
+ }
79
+ async deleteMarkedFiles() {
80
+ return this.deleteMarkedFilesByMeta(this.getBinaryDataMetaPath(), PREFIX_METAFILE);
81
+ }
82
+ async deleteMarkedPersistedFiles() {
83
+ return this.deleteMarkedFilesByMeta(this.getBinaryDataPersistMetaPath(), PREFIX_PERSISTED_METAFILE);
84
+ }
85
+ async addBinaryIdToPersistMeta(executionId, identifier) {
86
+ const currentTime = Date.now();
87
+ const timeAtNextHour = currentTime + 3600000 - (currentTime % 3600000);
88
+ const timeoutTime = timeAtNextHour + this.persistedBinaryDataTTL * 60000;
89
+ const filePath = path.join(this.getBinaryDataPersistMetaPath(), `${PREFIX_PERSISTED_METAFILE}_${executionId}_${timeoutTime}`);
90
+ return node_fs_1.promises
91
+ .readFile(filePath)
92
+ .catch(async () => node_fs_1.promises.writeFile(filePath, identifier))
93
+ .then(() => { });
94
+ }
95
+ async deleteMarkedFilesByMeta(metaPath, filePrefix) {
96
+ const currentTimeValue = Date.now();
97
+ const metaFileNames = await node_fs_1.promises.readdir(metaPath);
98
+ const execsAdded = {};
99
+ const proms = metaFileNames.reduce((prev, curr) => {
100
+ const [prefix, executionId, ts] = curr.split("_");
101
+ if (prefix !== filePrefix) {
102
+ return prev;
103
+ }
104
+ const execTimestamp = Number.parseInt(ts, 10);
105
+ if (execTimestamp < currentTimeValue) {
106
+ if (execsAdded[executionId]) {
107
+ // do not delete data, only meta file
108
+ prev.push(this.deleteMetaFileByPath(path.join(metaPath, curr)));
109
+ return prev;
110
+ }
111
+ execsAdded[executionId] = 1;
112
+ prev.push(this.deleteBinaryDataByExecutionId(executionId).then(async () => this.deleteMetaFileByPath(path.join(metaPath, curr))));
113
+ }
114
+ return prev;
115
+ }, [Promise.resolve()]);
116
+ return Promise.all(proms).then(() => { });
117
+ }
118
+ async duplicateBinaryDataByIdentifier(binaryDataId, prefix) {
119
+ const newBinaryDataId = this.generateFileName(prefix);
120
+ return node_fs_1.promises
121
+ .copyFile(path.join(this.storagePath, binaryDataId), path.join(this.storagePath, newBinaryDataId))
122
+ .then(() => newBinaryDataId);
123
+ }
124
+ async deleteBinaryDataByExecutionId(executionId) {
125
+ const regex = new RegExp(`${executionId}_*`);
126
+ const filenames = await node_fs_1.promises.readdir(path.join(this.storagePath));
127
+ const proms = filenames.reduce((allProms, filename) => {
128
+ if (regex.test(filename)) {
129
+ allProms.push(node_fs_1.promises.rm(path.join(this.storagePath, filename)));
130
+ }
131
+ return allProms;
132
+ }, [Promise.resolve()]);
133
+ return Promise.all(proms).then(async () => Promise.resolve());
134
+ }
135
+ async deleteBinaryDataByIdentifier(identifier) {
136
+ return this.deleteFromLocalStorage(identifier);
137
+ }
138
+ async persistBinaryDataForExecutionId(executionId) {
139
+ return node_fs_1.promises
140
+ .readdir(this.getBinaryDataPersistMetaPath())
141
+ .then(async (metafiles) => {
142
+ const proms = metafiles.reduce((prev, curr) => {
143
+ if (curr.startsWith(`${PREFIX_PERSISTED_METAFILE}_${executionId}_`)) {
144
+ prev.push(node_fs_1.promises.rm(path.join(this.getBinaryDataPersistMetaPath(), curr)));
145
+ return prev;
146
+ }
147
+ return prev;
148
+ }, [Promise.resolve()]);
149
+ return Promise.all(proms).then(() => { });
150
+ });
151
+ }
152
+ generateFileName(prefix) {
153
+ return `${prefix}_${(0, uuid_1.v4)()}`;
154
+ }
155
+ getBinaryDataMetaPath() {
156
+ return path.join(this.storagePath, "meta");
157
+ }
158
+ getBinaryDataPersistMetaPath() {
159
+ return path.join(this.storagePath, "persistMeta");
160
+ }
161
+ async deleteMetaFileByPath(metafilePath) {
162
+ return node_fs_1.promises.rm(metafilePath);
163
+ }
164
+ async deleteFromLocalStorage(identifier) {
165
+ return node_fs_1.promises.rm(path.join(this.storagePath, identifier));
166
+ }
167
+ async saveToLocalStorage(data, identifier) {
168
+ await node_fs_1.promises.writeFile(path.join(this.storagePath, identifier), data);
169
+ }
170
+ async retrieveFromLocalStorage(identifier) {
171
+ const filePath = path.join(this.storagePath, identifier);
172
+ try {
173
+ return await node_fs_1.promises.readFile(filePath);
174
+ }
175
+ catch (_e) {
176
+ throw new Error(`Error finding file: ${filePath}`);
177
+ }
178
+ }
179
+ }
180
+ exports.BinaryDataFileSystem = BinaryDataFileSystem;
@@ -1,2 +1,2 @@
1
- import { INodeType, ISupplyDataFunctions, Workflow, NodeConnectionType, IWebhookFunctions } from '@fsai-flow/workflow';
1
+ import { type INodeType, type ISupplyDataFunctions, type IWebhookFunctions, type NodeConnectionType, type Workflow } from "@fsai-flow/workflow";
2
2
  export declare function getInputConnectionDataLegacy(this: ISupplyDataFunctions | IWebhookFunctions, workflow: Workflow, connectionType: NodeConnectionType, itemIndex: number, nodeTypeData: INodeType): Promise<unknown>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInputConnectionDataLegacy = getInputConnectionDataLegacy;
4
+ const workflow_1 = require("@fsai-flow/workflow");
5
+ async function getInputConnectionDataLegacy(workflow, connectionType, itemIndex, nodeTypeData) {
6
+ const parentNode = this.getNode();
7
+ const nodeInputs = getNodeInputs(workflow, parentNode, nodeTypeData.description).map((input) => typeof input === "string" ? { type: input } : input);
8
+ const inputConfiguration = nodeInputs.find((input) => input.type === connectionType);
9
+ if (inputConfiguration === undefined) {
10
+ throw new workflow_1.NodeOperationError(parentNode, "Node does not have input of type", {
11
+ description: `Node ${parentNode.name} does not have input of type ${connectionType}`,
12
+ });
13
+ }
14
+ const connectedNodes = getConnectedNodes(workflow, parentNode, connectionType);
15
+ if (connectedNodes.length === 0) {
16
+ if (inputConfiguration.required) {
17
+ throw new workflow_1.NodeOperationError(parentNode, `A ${inputConfiguration?.displayName ?? connectionType} sub-node must be connected and enabled`);
18
+ }
19
+ return inputConfiguration.maxConnections === 1 ? undefined : [];
20
+ }
21
+ if (inputConfiguration.maxConnections !== undefined &&
22
+ connectedNodes.length > inputConfiguration.maxConnections) {
23
+ throw new workflow_1.NodeOperationError(parentNode, `Only ${inputConfiguration.maxConnections} ${connectionType} sub-nodes are/is allowed to be connected`);
24
+ }
25
+ const nodes = [];
26
+ for (const connectedNode of connectedNodes) {
27
+ const connectedNodeType = workflow.nodeTypes.getByNameAndVersion(connectedNode.type, connectedNode.typeVersion);
28
+ if (!connectedNodeType) {
29
+ continue;
30
+ }
31
+ if (connectedNodeType && !connectedNodeType.supplyData) {
32
+ throw new workflow_1.NodeOperationError(connectedNode, "Node does not have a `supplyData` method defined", {
33
+ itemIndex,
34
+ });
35
+ }
36
+ try {
37
+ const supplyData = await connectedNodeType.supplyData?.call(this, itemIndex);
38
+ if (supplyData) {
39
+ nodes.push(supplyData);
40
+ }
41
+ }
42
+ catch (error) {
43
+ throw new workflow_1.NodeOperationError(connectedNode, `Error in sub-node ${connectedNode.name}`, {
44
+ itemIndex,
45
+ description: error instanceof Error ? error.message : "Unknown error",
46
+ });
47
+ }
48
+ }
49
+ return inputConfiguration.maxConnections === 1
50
+ ? (nodes || [])[0]?.response
51
+ : nodes.map((node) => node.response);
52
+ }
53
+ function getNodeInputs(workflow, node, nodeTypeData) {
54
+ if (Array.isArray(nodeTypeData?.inputs)) {
55
+ return nodeTypeData.inputs;
56
+ }
57
+ // Calculate the outputs dynamically
58
+ try {
59
+ return (workflow.expression.getSimpleParameterValue(node, nodeTypeData.inputs, "internal", {}) || []);
60
+ }
61
+ catch (_e) {
62
+ console.warn("Could not calculate inputs dynamically for node: ", node.name);
63
+ return [];
64
+ }
65
+ }
66
+ function getConnectedNodes(workflow, node, connectionType) {
67
+ return workflow
68
+ .getParentNodes(node.name, connectionType, 1)
69
+ .map((nodeName) => workflow.getNode(nodeName))
70
+ .filter((node) => !!node)
71
+ .filter((node) => node !== null && node.disabled !== true);
72
+ }