@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
@@ -1,245 +0,0 @@
1
- import {
2
- IWebhookData,
3
- WebhookHttpMethod,
4
- Workflow,
5
- WorkflowActivateMode,
6
- WorkflowExecuteMode,
7
- } from '@fsai-flow/workflow';
8
-
9
- // eslint-disable-next-line import/no-cycle
10
- import { NodeExecuteFunctions } from '..';
11
-
12
- export class ActiveWebhooks {
13
- private workflowWebhooks: {
14
- [key: string]: IWebhookData[];
15
- } = {};
16
-
17
- private webhookUrls: {
18
- [key: string]: IWebhookData[];
19
- } = {};
20
-
21
- testWebhooks = false;
22
-
23
- /**
24
- * Adds a new webhook
25
- *
26
- * @param {IWebhookData} webhookData
27
- * @param {WorkflowExecuteMode} mode
28
- * @returns {Promise<void>}
29
- * @memberof ActiveWebhooks
30
- */
31
- async add(
32
- workflow: Workflow,
33
- webhookData: IWebhookData,
34
- mode: WorkflowExecuteMode,
35
- activation: WorkflowActivateMode,
36
- ): Promise<void> {
37
- if (workflow.id === undefined) {
38
- throw new Error('Webhooks can only be added for saved workflows as an id is needed!');
39
- }
40
- if (webhookData.path.endsWith('/')) {
41
- // eslint-disable-next-line no-param-reassign
42
- webhookData.path = webhookData.path.slice(0, -1);
43
- }
44
-
45
- const webhookKey = this.getWebhookKey(
46
- webhookData.httpMethod,
47
- webhookData.path,
48
- webhookData.webhookId,
49
- );
50
-
51
- // check that there is not a webhook already registed with that path/method
52
- if (this.webhookUrls[webhookKey] && !webhookData.webhookId) {
53
- throw new Error(
54
- `The URL path that the "${webhookData.node}" node uses is already taken. Please change it to something else.`,
55
- );
56
- }
57
-
58
- if (this.workflowWebhooks[webhookData.workflowId] === undefined) {
59
- this.workflowWebhooks[webhookData.workflowId] = [];
60
- }
61
-
62
- // Make the webhook available directly because sometimes to create it successfully
63
- // it gets called
64
- if (!this.webhookUrls[webhookKey]) {
65
- this.webhookUrls[webhookKey] = [];
66
- }
67
- this.webhookUrls[webhookKey].push(webhookData);
68
-
69
- try {
70
- const webhookExists = await workflow.runWebhookMethod(
71
- 'checkExists',
72
- webhookData,
73
- NodeExecuteFunctions,
74
- mode,
75
- activation,
76
- this.testWebhooks,
77
- );
78
- if (webhookExists !== true) {
79
- // If webhook does not exist yet create it
80
- await workflow.runWebhookMethod(
81
- 'create',
82
- webhookData,
83
- NodeExecuteFunctions,
84
- mode,
85
- activation,
86
- this.testWebhooks,
87
- );
88
- }
89
- } catch (error) {
90
- // If there was a problem unregister the webhook again
91
- if (this.webhookUrls[webhookKey].length <= 1) {
92
- delete this.webhookUrls[webhookKey];
93
- } else {
94
- this.webhookUrls[webhookKey] = this.webhookUrls[webhookKey].filter(
95
- (webhook) => webhook.path !== webhookData.path,
96
- );
97
- }
98
-
99
- throw error;
100
- }
101
- this.workflowWebhooks[webhookData.workflowId].push(webhookData);
102
- }
103
-
104
- /**
105
- * Returns webhookData if a webhook with matches is currently registered
106
- *
107
- * @param {WebhookHttpMethod} httpMethod
108
- * @param {string} path
109
- * @param {(string | undefined)} webhookId
110
- * @returns {(IWebhookData | undefined)}
111
- * @memberof ActiveWebhooks
112
- */
113
- get(httpMethod: WebhookHttpMethod, path: string, webhookId?: string): IWebhookData | undefined {
114
- const webhookKey = this.getWebhookKey(httpMethod, path, webhookId);
115
- if (this.webhookUrls[webhookKey] === undefined) {
116
- return undefined;
117
- }
118
-
119
- let webhook: IWebhookData | undefined;
120
- let maxMatches = 0;
121
- const pathElementsSet = new Set(path.split('/'));
122
- // check if static elements match in path
123
- // if more results have been returned choose the one with the most static-route matches
124
- this.webhookUrls[webhookKey].forEach((dynamicWebhook) => {
125
- const staticElements = dynamicWebhook.path.split('/').filter((ele) => !ele.startsWith(':'));
126
- const allStaticExist = staticElements.every((staticEle) => pathElementsSet.has(staticEle));
127
-
128
- if (allStaticExist && staticElements.length > maxMatches) {
129
- maxMatches = staticElements.length;
130
- webhook = dynamicWebhook;
131
- }
132
- // handle routes with no static elements
133
- else if (staticElements.length === 0 && !webhook) {
134
- webhook = dynamicWebhook;
135
- }
136
- });
137
-
138
- return webhook;
139
- }
140
-
141
- /**
142
- * Gets all request methods associated with a single webhook
143
- * @param path
144
- */
145
- getWebhookMethods(path: string): string[] {
146
- const methods: string[] = [];
147
-
148
- Object.keys(this.webhookUrls)
149
- .filter((key) => key.includes(path))
150
- // eslint-disable-next-line array-callback-return
151
- .map((key) => {
152
- methods.push(key.split('|')[0]);
153
- });
154
-
155
- return methods;
156
- }
157
-
158
- /**
159
- * Returns the ids of all the workflows which have active webhooks
160
- *
161
- * @returns {string[]}
162
- * @memberof ActiveWebhooks
163
- */
164
- getWorkflowIds(): string[] {
165
- return Object.keys(this.workflowWebhooks);
166
- }
167
-
168
- /**
169
- * Returns key to uniquely identify a webhook
170
- *
171
- * @param {WebhookHttpMethod} httpMethod
172
- * @param {string} path
173
- * @param {(string | undefined)} webhookId
174
- * @returns {string}
175
- * @memberof ActiveWebhooks
176
- */
177
- getWebhookKey(httpMethod: WebhookHttpMethod, path: string, webhookId?: string): string {
178
- if (webhookId) {
179
- if (path.startsWith(webhookId)) {
180
- const cutFromIndex = path.indexOf('/') + 1;
181
- // eslint-disable-next-line no-param-reassign
182
- path = path.slice(cutFromIndex);
183
- }
184
- return `${httpMethod}|${webhookId}|${path.split('/').length}`;
185
- }
186
- return `${httpMethod}|${path}`;
187
- }
188
-
189
- /**
190
- * Removes all webhooks of a workflow
191
- *
192
- * @param {Workflow} workflow
193
- * @returns {boolean}
194
- * @memberof ActiveWebhooks
195
- */
196
- async removeWorkflow(workflow: Workflow): Promise<boolean> {
197
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
198
- const workflowId = workflow.id!.toString();
199
-
200
- if (this.workflowWebhooks[workflowId] === undefined) {
201
- // If it did not exist then there is nothing to remove
202
- return false;
203
- }
204
-
205
- const webhooks = this.workflowWebhooks[workflowId];
206
-
207
- const mode = 'internal';
208
-
209
- // Go through all the registered webhooks of the workflow and remove them
210
- // eslint-disable-next-line no-restricted-syntax
211
- for (const webhookData of webhooks) {
212
- // eslint-disable-next-line no-await-in-loop
213
- await workflow.runWebhookMethod(
214
- 'delete',
215
- webhookData,
216
- NodeExecuteFunctions,
217
- mode,
218
- 'update',
219
- this.testWebhooks,
220
- );
221
-
222
- delete this.webhookUrls[
223
- this.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId)
224
- ];
225
- }
226
-
227
- // Remove also the workflow-webhook entry
228
- delete this.workflowWebhooks[workflowId];
229
-
230
- return true;
231
- }
232
-
233
- /**
234
- * Removes all the webhooks of the given workflows
235
- */
236
- async removeAll(workflows: Workflow[]): Promise<void> {
237
- const removePromises = [];
238
- // eslint-disable-next-line no-restricted-syntax
239
- for (const workflow of workflows) {
240
- removePromises.push(this.removeWorkflow(workflow));
241
- }
242
-
243
- await Promise.all(removePromises);
244
- }
245
- }