@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,17 @@
1
+ import * as getInputConnectionDataLegacy from "./lib/InputConnectionDataLegacy";
2
+ import * as NodeExecuteFunctions from "./lib/NodeExecuteFunctions";
3
+ import * as UserSettings from "./lib/UserSettings";
4
+ export * from "./lib/ActiveWebhooks";
5
+ export * from "./lib/ActiveWorkflows";
6
+ export * from "./lib/BinaryDataManager";
7
+ export * from "./lib/ChangeCase";
8
+ export * from "./lib/Constants";
9
+ export * from "./lib/Credentials";
10
+ export * from "./lib/Interfaces";
11
+ export * from "./lib/LoadNodeParameterOptions";
12
+ export * from "./lib/NodeExecuteFunctions";
13
+ export * from "./lib/NodesLoader";
14
+ export * from "./lib/RedisLeaderElectionManager";
15
+ export * from "./lib/RequestTypes";
16
+ export * from "./lib/WorkflowExecute";
17
+ export { NodeExecuteFunctions, UserSettings, getInputConnectionDataLegacy };
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
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
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getInputConnectionDataLegacy = exports.UserSettings = exports.NodeExecuteFunctions = void 0;
40
+ const getInputConnectionDataLegacy = __importStar(require("./lib/InputConnectionDataLegacy"));
41
+ exports.getInputConnectionDataLegacy = getInputConnectionDataLegacy;
42
+ /* eslint-disable import/no-cycle */
43
+ const NodeExecuteFunctions = __importStar(require("./lib/NodeExecuteFunctions"));
44
+ exports.NodeExecuteFunctions = NodeExecuteFunctions;
45
+ const UserSettings = __importStar(require("./lib/UserSettings"));
46
+ exports.UserSettings = UserSettings;
47
+ // @ts-expect-error - optional dependency, may not be installed
48
+ Promise.resolve().then(() => __importStar(require("source-map-support"))).then((s) => s.install()).catch(() => { });
49
+ __exportStar(require("./lib/ActiveWebhooks"), exports);
50
+ __exportStar(require("./lib/ActiveWorkflows"), exports);
51
+ __exportStar(require("./lib/BinaryDataManager"), exports);
52
+ __exportStar(require("./lib/ChangeCase"), exports);
53
+ __exportStar(require("./lib/Constants"), exports);
54
+ __exportStar(require("./lib/Credentials"), exports);
55
+ __exportStar(require("./lib/Interfaces"), exports);
56
+ __exportStar(require("./lib/LoadNodeParameterOptions"), exports);
57
+ __exportStar(require("./lib/NodeExecuteFunctions"), exports);
58
+ __exportStar(require("./lib/NodesLoader"), exports);
59
+ __exportStar(require("./lib/RedisLeaderElectionManager"), exports);
60
+ __exportStar(require("./lib/RequestTypes"), exports);
61
+ __exportStar(require("./lib/WorkflowExecute"), exports);
@@ -1,4 +1,4 @@
1
- import { IWebhookData, WebhookHttpMethod, Workflow, WorkflowActivateMode, WorkflowExecuteMode } from '@fsai-flow/workflow';
1
+ import type { IWebhookData, WebhookHttpMethod, Workflow, WorkflowActivateMode, WorkflowExecuteMode } from "@fsai-flow/workflow";
2
2
  export declare class ActiveWebhooks {
3
3
  private workflowWebhooks;
4
4
  private webhookUrls;
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActiveWebhooks = void 0;
4
+ // eslint-disable-next-line import/no-cycle
5
+ const __1 = require("..");
6
+ class ActiveWebhooks {
7
+ constructor() {
8
+ this.workflowWebhooks = {};
9
+ this.webhookUrls = {};
10
+ this.testWebhooks = false;
11
+ }
12
+ /**
13
+ * Adds a new webhook
14
+ *
15
+ * @param {IWebhookData} webhookData
16
+ * @param {WorkflowExecuteMode} mode
17
+ * @returns {Promise<void>}
18
+ * @memberof ActiveWebhooks
19
+ */
20
+ async add(workflow, webhookData, mode, activation) {
21
+ if (workflow.id === undefined) {
22
+ throw new Error("Webhooks can only be added for saved workflows as an id is needed!");
23
+ }
24
+ if (webhookData.path.endsWith("/")) {
25
+ // eslint-disable-next-line no-param-reassign
26
+ webhookData.path = webhookData.path.slice(0, -1);
27
+ }
28
+ const webhookKey = this.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId);
29
+ // check that there is not a webhook already registed with that path/method
30
+ if (this.webhookUrls[webhookKey] && !webhookData.webhookId) {
31
+ throw new Error(`The URL path that the "${webhookData.node}" node uses is already taken. Please change it to something else.`);
32
+ }
33
+ if (this.workflowWebhooks[webhookData.workflowId] === undefined) {
34
+ this.workflowWebhooks[webhookData.workflowId] = [];
35
+ }
36
+ // Make the webhook available directly because sometimes to create it successfully
37
+ // it gets called
38
+ if (!this.webhookUrls[webhookKey]) {
39
+ this.webhookUrls[webhookKey] = [];
40
+ }
41
+ this.webhookUrls[webhookKey].push(webhookData);
42
+ try {
43
+ const webhookExists = await workflow.runWebhookMethod("checkExists", webhookData, __1.NodeExecuteFunctions, mode, activation, this.testWebhooks);
44
+ if (webhookExists !== true) {
45
+ // If webhook does not exist yet create it
46
+ await workflow.runWebhookMethod("create", webhookData, __1.NodeExecuteFunctions, mode, activation, this.testWebhooks);
47
+ }
48
+ }
49
+ catch (error) {
50
+ // If there was a problem unregister the webhook again
51
+ if (this.webhookUrls[webhookKey].length <= 1) {
52
+ delete this.webhookUrls[webhookKey];
53
+ }
54
+ else {
55
+ this.webhookUrls[webhookKey] = this.webhookUrls[webhookKey].filter((webhook) => webhook.path !== webhookData.path);
56
+ }
57
+ throw error;
58
+ }
59
+ this.workflowWebhooks[webhookData.workflowId].push(webhookData);
60
+ }
61
+ /**
62
+ * Returns webhookData if a webhook with matches is currently registered
63
+ *
64
+ * @param {WebhookHttpMethod} httpMethod
65
+ * @param {string} path
66
+ * @param {(string | undefined)} webhookId
67
+ * @returns {(IWebhookData | undefined)}
68
+ * @memberof ActiveWebhooks
69
+ */
70
+ get(httpMethod, path, webhookId) {
71
+ const webhookKey = this.getWebhookKey(httpMethod, path, webhookId);
72
+ if (this.webhookUrls[webhookKey] === undefined) {
73
+ return undefined;
74
+ }
75
+ let webhook;
76
+ let maxMatches = 0;
77
+ const pathElementsSet = new Set(path.split("/"));
78
+ // check if static elements match in path
79
+ // if more results have been returned choose the one with the most static-route matches
80
+ for (const dynamicWebhook of this.webhookUrls[webhookKey]) {
81
+ const staticElements = dynamicWebhook.path
82
+ .split("/")
83
+ .filter((ele) => !ele.startsWith(":"));
84
+ const allStaticExist = staticElements.every((staticEle) => pathElementsSet.has(staticEle));
85
+ if (allStaticExist && staticElements.length > maxMatches) {
86
+ maxMatches = staticElements.length;
87
+ webhook = dynamicWebhook;
88
+ }
89
+ // handle routes with no static elements
90
+ else if (staticElements.length === 0 && !webhook) {
91
+ webhook = dynamicWebhook;
92
+ }
93
+ }
94
+ return webhook;
95
+ }
96
+ /**
97
+ * Gets all request methods associated with a single webhook
98
+ * @param path
99
+ */
100
+ getWebhookMethods(path) {
101
+ const methods = [];
102
+ for (const key of Object.keys(this.webhookUrls)) {
103
+ if (key.includes(path)) {
104
+ methods.push(key.split("|")[0]);
105
+ }
106
+ }
107
+ return methods;
108
+ }
109
+ /**
110
+ * Returns the ids of all the workflows which have active webhooks
111
+ *
112
+ * @returns {string[]}
113
+ * @memberof ActiveWebhooks
114
+ */
115
+ getWorkflowIds() {
116
+ return Object.keys(this.workflowWebhooks);
117
+ }
118
+ /**
119
+ * Returns key to uniquely identify a webhook
120
+ *
121
+ * @param {WebhookHttpMethod} httpMethod
122
+ * @param {string} path
123
+ * @param {(string | undefined)} webhookId
124
+ * @returns {string}
125
+ * @memberof ActiveWebhooks
126
+ */
127
+ getWebhookKey(httpMethod, path, webhookId) {
128
+ let webhookPath = path;
129
+ if (webhookId) {
130
+ if (webhookPath.startsWith(webhookId)) {
131
+ const cutFromIndex = webhookPath.indexOf("/") + 1;
132
+ webhookPath = webhookPath.slice(cutFromIndex);
133
+ }
134
+ return `${httpMethod}|${webhookId}|${webhookPath.split("/").length}`;
135
+ }
136
+ return `${httpMethod}|${webhookPath}`;
137
+ }
138
+ /**
139
+ * Removes all webhooks of a workflow
140
+ *
141
+ * @param {Workflow} workflow
142
+ * @returns {boolean}
143
+ * @memberof ActiveWebhooks
144
+ */
145
+ async removeWorkflow(workflow) {
146
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
147
+ const workflowId = workflow.id.toString();
148
+ if (this.workflowWebhooks[workflowId] === undefined) {
149
+ // If it did not exist then there is nothing to remove
150
+ return false;
151
+ }
152
+ const webhooks = this.workflowWebhooks[workflowId];
153
+ const mode = "internal";
154
+ // Go through all the registered webhooks of the workflow and remove them
155
+ // eslint-disable-next-line no-restricted-syntax
156
+ for (const webhookData of webhooks) {
157
+ // eslint-disable-next-line no-await-in-loop
158
+ await workflow.runWebhookMethod("delete", webhookData, __1.NodeExecuteFunctions, mode, "update", this.testWebhooks);
159
+ delete this.webhookUrls[this.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId)];
160
+ }
161
+ // Remove also the workflow-webhook entry
162
+ delete this.workflowWebhooks[workflowId];
163
+ return true;
164
+ }
165
+ /**
166
+ * Removes all the webhooks of the given workflows
167
+ */
168
+ async removeAll(workflows) {
169
+ const removePromises = [];
170
+ // eslint-disable-next-line no-restricted-syntax
171
+ for (const workflow of workflows) {
172
+ removePromises.push(this.removeWorkflow(workflow));
173
+ }
174
+ await Promise.all(removePromises);
175
+ }
176
+ }
177
+ exports.ActiveWebhooks = ActiveWebhooks;
@@ -1,6 +1,6 @@
1
- import { IGetExecutePollFunctions, IGetExecuteTriggerFunctions, INode, IPollResponse, IWorkflowExecuteAdditionalData, Workflow, WorkflowActivateMode, WorkflowExecuteMode } from '@fsai-flow/workflow';
2
- import { IWorkflowData } from '..';
3
- import { RedisOptions } from 'ioredis';
1
+ import { type IGetExecutePollFunctions, type IGetExecuteTriggerFunctions, type INode, type IPollResponse, type IWorkflowExecuteAdditionalData, type Workflow, type WorkflowActivateMode, type WorkflowExecuteMode } from "@fsai-flow/workflow";
2
+ import type { RedisOptions } from "ioredis";
3
+ import type { IWorkflowData } from "..";
4
4
  export declare class ActiveWorkflows {
5
5
  private workflowData;
6
6
  private redisConfig;