@fsai-flow/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/README.md +11 -0
- package/dist/package.json +44 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.js +29 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/ActiveWebhooks.d.ts +59 -0
- package/dist/src/lib/ActiveWebhooks.js +184 -0
- package/dist/src/lib/ActiveWebhooks.js.map +1 -0
- package/dist/src/lib/ActiveWorkflows.d.ts +58 -0
- package/dist/src/lib/ActiveWorkflows.js +244 -0
- package/dist/src/lib/ActiveWorkflows.js.map +1 -0
- package/dist/src/lib/BinaryDataManager/FileSystem.d.ts +26 -0
- package/dist/src/lib/BinaryDataManager/FileSystem.js +179 -0
- package/dist/src/lib/BinaryDataManager/FileSystem.js.map +1 -0
- package/dist/src/lib/BinaryDataManager/index.d.ts +21 -0
- package/dist/src/lib/BinaryDataManager/index.js +146 -0
- package/dist/src/lib/BinaryDataManager/index.js.map +1 -0
- package/dist/src/lib/ChangeCase.d.ts +9 -0
- package/dist/src/lib/ChangeCase.js +43 -0
- package/dist/src/lib/ChangeCase.js.map +1 -0
- package/dist/src/lib/Constants.d.ts +14 -0
- package/dist/src/lib/Constants.js +19 -0
- package/dist/src/lib/Constants.js.map +1 -0
- package/dist/src/lib/Credentials.d.ts +27 -0
- package/dist/src/lib/Credentials.js +89 -0
- package/dist/src/lib/Credentials.js.map +1 -0
- package/dist/src/lib/FileSystem.d.ts +26 -0
- package/dist/src/lib/FileSystem.js +179 -0
- package/dist/src/lib/FileSystem.js.map +1 -0
- package/dist/src/lib/InputConnectionDataLegacy.d.ts +2 -0
- package/dist/src/lib/InputConnectionDataLegacy.js +79 -0
- package/dist/src/lib/InputConnectionDataLegacy.js.map +1 -0
- package/dist/src/lib/Interfaces.d.ts +148 -0
- package/dist/src/lib/Interfaces.js +3 -0
- package/dist/src/lib/Interfaces.js.map +1 -0
- package/dist/src/lib/LoadNodeParameterOptions.d.ts +39 -0
- package/dist/src/lib/LoadNodeParameterOptions.js +150 -0
- package/dist/src/lib/LoadNodeParameterOptions.js.map +1 -0
- package/dist/src/lib/NodeExecuteFunctions.d.ts +226 -0
- package/dist/src/lib/NodeExecuteFunctions.js +2483 -0
- package/dist/src/lib/NodeExecuteFunctions.js.map +1 -0
- package/dist/src/lib/NodesLoader/constants.d.ts +5 -0
- package/dist/src/lib/NodesLoader/constants.js +106 -0
- package/dist/src/lib/NodesLoader/constants.js.map +1 -0
- package/dist/src/lib/NodesLoader/custom-directory-loader.d.ts +9 -0
- package/dist/src/lib/NodesLoader/custom-directory-loader.js +36 -0
- package/dist/src/lib/NodesLoader/custom-directory-loader.js.map +1 -0
- package/dist/src/lib/NodesLoader/directory-loader.d.ts +66 -0
- package/dist/src/lib/NodesLoader/directory-loader.js +325 -0
- package/dist/src/lib/NodesLoader/directory-loader.js.map +1 -0
- package/dist/src/lib/NodesLoader/index.d.ts +5 -0
- package/dist/src/lib/NodesLoader/index.js +12 -0
- package/dist/src/lib/NodesLoader/index.js.map +1 -0
- package/dist/src/lib/NodesLoader/lazy-package-directory-loader.d.ts +7 -0
- package/dist/src/lib/NodesLoader/lazy-package-directory-loader.js +52 -0
- package/dist/src/lib/NodesLoader/lazy-package-directory-loader.js.map +1 -0
- package/dist/src/lib/NodesLoader/load-class-in-isolation.d.ts +1 -0
- package/dist/src/lib/NodesLoader/load-class-in-isolation.js +22 -0
- package/dist/src/lib/NodesLoader/load-class-in-isolation.js.map +1 -0
- package/dist/src/lib/NodesLoader/package-directory-loader.d.ts +17 -0
- package/dist/src/lib/NodesLoader/package-directory-loader.js +100 -0
- package/dist/src/lib/NodesLoader/package-directory-loader.js.map +1 -0
- package/dist/src/lib/NodesLoader/types.d.ts +14 -0
- package/dist/src/lib/NodesLoader/types.js +3 -0
- package/dist/src/lib/NodesLoader/types.js.map +1 -0
- package/dist/src/lib/UserSettings.d.ts +80 -0
- package/dist/src/lib/UserSettings.js +261 -0
- package/dist/src/lib/UserSettings.js.map +1 -0
- package/dist/src/lib/WorkflowExecute.d.ts +53 -0
- package/dist/src/lib/WorkflowExecute.js +835 -0
- package/dist/src/lib/WorkflowExecute.js.map +1 -0
- package/dist/src/lib/index.d.ts +21 -0
- package/dist/src/lib/index.js +146 -0
- package/dist/src/lib/index.js.map +1 -0
- package/dist/src/utils/crypto.d.ts +1 -0
- package/dist/src/utils/crypto.js +8 -0
- package/dist/src/utils/crypto.js.map +1 -0
- package/eslint.config.js +19 -0
- package/jest.config.ts +10 -0
- package/package.json +44 -0
- package/project.json +19 -0
- package/src/index.ts +27 -0
- package/src/lib/ActiveWebhooks.ts +245 -0
- package/src/lib/ActiveWorkflows.ts +304 -0
- package/src/lib/BinaryDataManager/FileSystem.ts +214 -0
- package/src/lib/BinaryDataManager/index.ts +187 -0
- package/src/lib/ChangeCase.ts +45 -0
- package/src/lib/Constants.ts +16 -0
- package/src/lib/Credentials.ts +108 -0
- package/src/lib/FileSystem.ts +214 -0
- package/src/lib/InputConnectionDataLegacy.ts +123 -0
- package/src/lib/Interfaces.ts +338 -0
- package/src/lib/LoadNodeParameterOptions.ts +235 -0
- package/src/lib/NodeExecuteFunctions.ts +3704 -0
- package/src/lib/NodesLoader/constants.ts +112 -0
- package/src/lib/NodesLoader/custom-directory-loader.ts +31 -0
- package/src/lib/NodesLoader/directory-loader.ts +458 -0
- package/src/lib/NodesLoader/index.ts +5 -0
- package/src/lib/NodesLoader/lazy-package-directory-loader.ts +55 -0
- package/src/lib/NodesLoader/load-class-in-isolation.ts +19 -0
- package/src/lib/NodesLoader/package-directory-loader.ts +107 -0
- package/src/lib/NodesLoader/types.ts +14 -0
- package/src/lib/UserSettings.ts +292 -0
- package/src/lib/WorkflowExecute.ts +1108 -0
- package/src/lib/index.ts +187 -0
- package/src/utils/crypto.ts +5 -0
- package/tests/Credentials.test.ts +88 -0
- package/tests/Helpers.ts +808 -0
- package/tests/WorkflowExecute.test.ts +1242 -0
- package/tsconfig.json +42 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +14 -0
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { IBinaryData, INodeExecutionData } from '@fsai-flow/workflow';
|
|
2
|
+
import { BINARY_ENCODING } from './Constants';
|
|
3
|
+
import { IBinaryDataConfig, IBinaryDataManager } from './Interfaces';
|
|
4
|
+
import { BinaryDataFileSystem } from './FileSystem';
|
|
5
|
+
|
|
6
|
+
export class BinaryDataManager {
|
|
7
|
+
private static instance: BinaryDataManager;
|
|
8
|
+
|
|
9
|
+
private managers: {
|
|
10
|
+
[key: string]: IBinaryDataManager;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
private binaryDataMode: string;
|
|
14
|
+
|
|
15
|
+
private availableModes: string[];
|
|
16
|
+
|
|
17
|
+
constructor(config: IBinaryDataConfig) {
|
|
18
|
+
this.binaryDataMode = config.mode;
|
|
19
|
+
this.availableModes = config.availableModes.split(',');
|
|
20
|
+
this.managers = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static async init(config: IBinaryDataConfig, mainManager = false): Promise<void> {
|
|
24
|
+
if (BinaryDataManager.instance) {
|
|
25
|
+
throw new Error('Binary Data Manager already initialized');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
BinaryDataManager.instance = new BinaryDataManager(config);
|
|
29
|
+
|
|
30
|
+
if (BinaryDataManager.instance.availableModes.includes('filesystem')) {
|
|
31
|
+
BinaryDataManager.instance.managers['filesystem'] = new BinaryDataFileSystem(config);
|
|
32
|
+
await BinaryDataManager.instance.managers['filesystem'].init(mainManager);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static getInstance(): BinaryDataManager {
|
|
39
|
+
if (!BinaryDataManager.instance) {
|
|
40
|
+
throw new Error('Binary Data Manager not initialized');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return BinaryDataManager.instance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async storeBinaryData(
|
|
47
|
+
binaryData: IBinaryData,
|
|
48
|
+
binaryBuffer: Buffer,
|
|
49
|
+
executionId: string,
|
|
50
|
+
): Promise<IBinaryData> {
|
|
51
|
+
const retBinaryData = binaryData;
|
|
52
|
+
|
|
53
|
+
if (this.managers[this.binaryDataMode]) {
|
|
54
|
+
return this.managers[this.binaryDataMode]
|
|
55
|
+
.storeBinaryData(binaryBuffer, executionId)
|
|
56
|
+
.then((filename) => {
|
|
57
|
+
retBinaryData.id = this.generateBinaryId(filename);
|
|
58
|
+
return retBinaryData;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
retBinaryData.data = binaryBuffer.toString(BINARY_ENCODING);
|
|
63
|
+
return binaryData;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async retrieveBinaryData(binaryData: IBinaryData): Promise<Buffer> {
|
|
67
|
+
if (binaryData.id) {
|
|
68
|
+
return this.retrieveBinaryDataByIdentifier(binaryData.id);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return Buffer.from(binaryData.data, BINARY_ENCODING);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async retrieveBinaryDataByIdentifier(identifier: string): Promise<Buffer> {
|
|
75
|
+
const { mode, id } = this.splitBinaryModeFileId(identifier);
|
|
76
|
+
if (this.managers[mode]) {
|
|
77
|
+
return this.managers[mode].retrieveBinaryDataByIdentifier(id);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
throw new Error('Storage mode used to store binary data not available');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async markDataForDeletionByExecutionId(executionId: string): Promise<void> {
|
|
84
|
+
if (this.managers[this.binaryDataMode]) {
|
|
85
|
+
return this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(executionId);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return Promise.resolve();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async persistBinaryDataForExecutionId(executionId: string): Promise<void> {
|
|
92
|
+
if (this.managers[this.binaryDataMode]) {
|
|
93
|
+
return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return Promise.resolve();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async deleteBinaryDataByExecutionId(executionId: string): Promise<void> {
|
|
100
|
+
if (this.managers[this.binaryDataMode]) {
|
|
101
|
+
return this.managers[this.binaryDataMode].deleteBinaryDataByExecutionId(executionId);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Promise.resolve();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async duplicateBinaryData(
|
|
108
|
+
inputData: Array<INodeExecutionData[] | null> | unknown,
|
|
109
|
+
executionId: string,
|
|
110
|
+
): Promise<INodeExecutionData[][]> {
|
|
111
|
+
if (inputData && this.managers[this.binaryDataMode]) {
|
|
112
|
+
const returnInputData = (inputData as INodeExecutionData[][]).map(
|
|
113
|
+
async (executionDataArray) => {
|
|
114
|
+
if (executionDataArray) {
|
|
115
|
+
return Promise.all(
|
|
116
|
+
executionDataArray.map((executionData) => {
|
|
117
|
+
if (executionData.binary) {
|
|
118
|
+
return this.duplicateBinaryDataInExecData(executionData, executionId);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return executionData;
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return executionDataArray;
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return Promise.all(returnInputData);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return Promise.resolve(inputData as INodeExecutionData[][]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private generateBinaryId(filename: string) {
|
|
137
|
+
return `${this.binaryDataMode}:${filename}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private splitBinaryModeFileId(fileId: string): { mode: string; id: string } {
|
|
141
|
+
const [mode, id] = fileId.split(':');
|
|
142
|
+
return { mode, id };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private async duplicateBinaryDataInExecData(
|
|
146
|
+
executionData: INodeExecutionData,
|
|
147
|
+
executionId: string,
|
|
148
|
+
): Promise<INodeExecutionData> {
|
|
149
|
+
const binaryManager = this.managers[this.binaryDataMode];
|
|
150
|
+
|
|
151
|
+
if (executionData.binary) {
|
|
152
|
+
const binaryDataKeys = Object.keys(executionData.binary);
|
|
153
|
+
const bdPromises = binaryDataKeys.map(async (key: string) => {
|
|
154
|
+
if (!executionData.binary) {
|
|
155
|
+
return { key, newId: undefined };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const binaryDataId = executionData.binary[key].id;
|
|
159
|
+
if (!binaryDataId) {
|
|
160
|
+
return { key, newId: undefined };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return binaryManager
|
|
164
|
+
?.duplicateBinaryDataByIdentifier(
|
|
165
|
+
this.splitBinaryModeFileId(binaryDataId).id,
|
|
166
|
+
executionId,
|
|
167
|
+
)
|
|
168
|
+
.then((filename) => ({
|
|
169
|
+
newId: this.generateBinaryId(filename),
|
|
170
|
+
key,
|
|
171
|
+
}));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return Promise.all(bdPromises).then((b) => {
|
|
175
|
+
return b.reduce((acc, curr) => {
|
|
176
|
+
if (acc.binary && curr) {
|
|
177
|
+
acc.binary[curr.key].id = curr.newId;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return acc;
|
|
181
|
+
}, executionData);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return executionData;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Credentials } from '../src';
|
|
2
|
+
|
|
3
|
+
describe('Credentials', () => {
|
|
4
|
+
describe('without nodeType set', () => {
|
|
5
|
+
test('should be able to set and read key data without initial data set', () => {
|
|
6
|
+
const credentials = new Credentials({ id: null, name: 'testName' }, 'testType', []);
|
|
7
|
+
|
|
8
|
+
const key = 'key1';
|
|
9
|
+
const password = '';
|
|
10
|
+
// const nodeType = 'base.noOp';
|
|
11
|
+
const newData = 1234;
|
|
12
|
+
|
|
13
|
+
credentials.setDataKey(key, newData, password);
|
|
14
|
+
|
|
15
|
+
expect(credentials.getDataKey(key, password)).toEqual(newData);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should be able to set and read key data with initial data set', () => {
|
|
19
|
+
const key = 'key2';
|
|
20
|
+
const password = '';
|
|
21
|
+
|
|
22
|
+
// Saved under "key1"
|
|
23
|
+
const initialData = 4321;
|
|
24
|
+
const initialDataEncoded = 'U2FsdGVkX1+0baznXt+Ag/ub8A2kHLyoLxn/rR9h4XQ=';
|
|
25
|
+
|
|
26
|
+
const credentials = new Credentials(
|
|
27
|
+
{ id: null, name: 'testName' },
|
|
28
|
+
'testType',
|
|
29
|
+
[],
|
|
30
|
+
initialDataEncoded,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const newData = 1234;
|
|
34
|
+
|
|
35
|
+
// Set and read new data
|
|
36
|
+
credentials.setDataKey(key, newData, password);
|
|
37
|
+
expect(credentials.getDataKey(key, password)).toEqual(newData);
|
|
38
|
+
|
|
39
|
+
// Read the data which got provided encrypted on init
|
|
40
|
+
expect(credentials.getDataKey('key1', password)).toEqual(initialData);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('with nodeType set', () => {
|
|
45
|
+
test('should be able to set and read key data without initial data set', () => {
|
|
46
|
+
const nodeAccess = [
|
|
47
|
+
{
|
|
48
|
+
nodeType: 'base.noOp',
|
|
49
|
+
user: 'userName',
|
|
50
|
+
date: new Date(),
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const credentials = new Credentials({ id: null, name: 'testName' }, 'testType', nodeAccess);
|
|
55
|
+
|
|
56
|
+
const key = 'key1';
|
|
57
|
+
const password = '';
|
|
58
|
+
const nodeType = 'base.noOp';
|
|
59
|
+
const newData = 1234;
|
|
60
|
+
|
|
61
|
+
credentials.setDataKey(key, newData, password);
|
|
62
|
+
|
|
63
|
+
// Should be able to read with nodeType which has access
|
|
64
|
+
expect(credentials.getDataKey(key, password, nodeType)).toEqual(newData);
|
|
65
|
+
|
|
66
|
+
// Should not be able to read with nodeType which does NOT have access
|
|
67
|
+
// expect(credentials.getDataKey(key, password, 'base.otherNode')).toThrowError(Error);
|
|
68
|
+
try {
|
|
69
|
+
credentials.getDataKey(key, password, 'base.otherNode');
|
|
70
|
+
expect(true).toBe(false);
|
|
71
|
+
} catch (e: any) {
|
|
72
|
+
expect(e.message).toBe(
|
|
73
|
+
'The node of type "base.otherNode" does not have access to credentials "testName" of type "testType".',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Get the data which will be saved in database
|
|
78
|
+
const dbData = credentials.getDataToSave();
|
|
79
|
+
expect(dbData.name).toEqual('testName');
|
|
80
|
+
expect(dbData.type).toEqual('testType');
|
|
81
|
+
expect(dbData.nodesAccess).toEqual(nodeAccess);
|
|
82
|
+
// Compare only the first 6 characters as the rest seems to change with each execution
|
|
83
|
+
expect(dbData.data!.slice(0, 6)).toEqual(
|
|
84
|
+
'U2FsdGVkX1+wpQWkj+YTzaPSNTFATjnlmFKIsUTZdhk='.slice(0, 6),
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|