@fsai-flow/core 0.1.1 → 0.2.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 (58) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/lib/NodeExecuteFunctions.js +11 -5
  4. package/dist/src/index.d.ts +17 -0
  5. package/dist/src/index.js +61 -0
  6. package/dist/src/lib/ActiveWebhooks.d.ts +59 -0
  7. package/dist/src/lib/ActiveWebhooks.js +177 -0
  8. package/dist/src/lib/ActiveWorkflows.d.ts +87 -0
  9. package/dist/src/lib/ActiveWorkflows.js +465 -0
  10. package/dist/src/lib/BinaryDataManager/FileSystem.d.ts +26 -0
  11. package/dist/src/lib/BinaryDataManager/FileSystem.js +180 -0
  12. package/dist/src/lib/BinaryDataManager/index.d.ts +21 -0
  13. package/dist/src/lib/BinaryDataManager/index.js +129 -0
  14. package/dist/src/lib/ChangeCase.d.ts +9 -0
  15. package/dist/src/lib/ChangeCase.js +43 -0
  16. package/dist/src/lib/Constants.d.ts +14 -0
  17. package/dist/src/lib/Constants.js +18 -0
  18. package/dist/src/lib/Credentials.d.ts +27 -0
  19. package/dist/src/lib/Credentials.js +88 -0
  20. package/dist/src/lib/FileSystem.d.ts +26 -0
  21. package/dist/src/lib/FileSystem.js +180 -0
  22. package/dist/src/lib/InputConnectionDataLegacy.d.ts +2 -0
  23. package/dist/src/lib/InputConnectionDataLegacy.js +72 -0
  24. package/dist/src/lib/Interfaces.d.ts +147 -0
  25. package/dist/src/lib/Interfaces.js +2 -0
  26. package/dist/src/lib/LoadNodeParameterOptions.d.ts +39 -0
  27. package/dist/src/lib/LoadNodeParameterOptions.js +152 -0
  28. package/dist/src/lib/NodeExecuteFunctions.d.ts +225 -0
  29. package/dist/src/lib/NodeExecuteFunctions.js +2473 -0
  30. package/dist/src/lib/NodesLoader/constants.d.ts +5 -0
  31. package/dist/src/lib/NodesLoader/constants.js +105 -0
  32. package/dist/src/lib/NodesLoader/custom-directory-loader.d.ts +9 -0
  33. package/dist/src/lib/NodesLoader/custom-directory-loader.js +35 -0
  34. package/dist/src/lib/NodesLoader/directory-loader.d.ts +66 -0
  35. package/dist/src/lib/NodesLoader/directory-loader.js +367 -0
  36. package/dist/src/lib/NodesLoader/index.d.ts +5 -0
  37. package/dist/src/lib/NodesLoader/index.js +11 -0
  38. package/dist/src/lib/NodesLoader/lazy-package-directory-loader.d.ts +7 -0
  39. package/dist/src/lib/NodesLoader/lazy-package-directory-loader.js +44 -0
  40. package/dist/src/lib/NodesLoader/load-class-in-isolation.d.ts +1 -0
  41. package/dist/src/lib/NodesLoader/load-class-in-isolation.js +17 -0
  42. package/dist/src/lib/NodesLoader/package-directory-loader.d.ts +17 -0
  43. package/dist/src/lib/NodesLoader/package-directory-loader.js +92 -0
  44. package/dist/src/lib/NodesLoader/types.d.ts +14 -0
  45. package/dist/src/lib/NodesLoader/types.js +2 -0
  46. package/dist/src/lib/RedisLeaderElectionManager.d.ts +53 -0
  47. package/dist/src/lib/RedisLeaderElectionManager.js +279 -0
  48. package/dist/src/lib/RequestTypes.d.ts +58 -0
  49. package/dist/src/lib/RequestTypes.js +8 -0
  50. package/dist/src/lib/UserSettings.d.ts +80 -0
  51. package/dist/src/lib/UserSettings.js +269 -0
  52. package/dist/src/lib/WorkflowExecute.d.ts +53 -0
  53. package/dist/src/lib/WorkflowExecute.js +906 -0
  54. package/dist/src/lib/index.d.ts +21 -0
  55. package/dist/src/lib/index.js +129 -0
  56. package/dist/src/utils/crypto.d.ts +1 -0
  57. package/dist/src/utils/crypto.js +7 -0
  58. package/package.json +15 -14
package/dist/index.d.ts CHANGED
@@ -14,4 +14,4 @@ export * from "./lib/NodesLoader";
14
14
  export * from "./lib/RedisLeaderElectionManager";
15
15
  export * from "./lib/RequestTypes";
16
16
  export * from "./lib/WorkflowExecute";
17
- export { NodeExecuteFunctions, UserSettings, getInputConnectionDataLegacy };
17
+ export { getInputConnectionDataLegacy, NodeExecuteFunctions, UserSettings };
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getInputConnectionDataLegacy = exports.UserSettings = exports.NodeExecuteFunctions = void 0;
39
+ exports.UserSettings = exports.NodeExecuteFunctions = exports.getInputConnectionDataLegacy = void 0;
40
40
  const getInputConnectionDataLegacy = __importStar(require("./lib/InputConnectionDataLegacy"));
41
41
  exports.getInputConnectionDataLegacy = getInputConnectionDataLegacy;
42
42
  /* eslint-disable import/no-cycle */
@@ -154,7 +154,7 @@ function searchForHeader(headers, headerName) {
154
154
  return headerNames.find((thisHeader) => thisHeader.toLowerCase() === lowerHeaderName);
155
155
  }
156
156
  async function generateContentLengthHeader(formData, headers) {
157
- if (!formData || !formData.getLength) {
157
+ if (!formData?.getLength) {
158
158
  return;
159
159
  }
160
160
  try {
@@ -880,7 +880,7 @@ async function getCurrentOAuth2AccessToken(credentialsType, node, additionalData
880
880
  oauthTokenData["expiresAt"] = expiresAt;
881
881
  oauthTokenData["expiresIn"] = expiresIn;
882
882
  oauthTokenData["tokenType"] = tokenType;
883
- if (!node.credentials || !node.credentials[credentialsType]) {
883
+ if (!node.credentials?.[credentialsType]) {
884
884
  throw new Error(`Node "${node.name}" has no credentials of type "${credentialsType}"`);
885
885
  }
886
886
  await additionalData.credentialsHelper.updateCredentials(node.credentials[credentialsType], credentialsType, credentials);
@@ -971,7 +971,7 @@ async function requestOAuth2(credentialsType, requestOptions, node, additionalDa
971
971
  tokenType: refreshedToken.token["token_type"],
972
972
  };
973
973
  // Persist new token
974
- if (!node.credentials || !node.credentials[credentialsType]) {
974
+ if (!node.credentials?.[credentialsType]) {
975
975
  throw new Error(`Node "${node.name}" has no credentials of type "${credentialsType}"`);
976
976
  }
977
977
  await additionalData.credentialsHelper.updateCredentials(node.credentials[credentialsType], credentialsType, credentials);
@@ -1209,7 +1209,7 @@ async function getCredentials(workflow, node, type, additionalData, mode, runExe
1209
1209
  }
1210
1210
  }
1211
1211
  // Check if node has any credentials defined
1212
- if (!fullAccess && (!node.credentials || !node.credentials[type])) {
1212
+ if (!fullAccess && !node.credentials?.[type]) {
1213
1213
  // If none are defined check if the credentials are required or not
1214
1214
  if (nodeCredentialDescription?.required === true) {
1215
1215
  // Credentials are required so error
@@ -1225,7 +1225,7 @@ async function getCredentials(workflow, node, type, additionalData, mode, runExe
1225
1225
  return undefined;
1226
1226
  }
1227
1227
  }
1228
- if (fullAccess && (!node.credentials || !node.credentials[type])) {
1228
+ if (fullAccess && !node.credentials?.[type]) {
1229
1229
  // Make sure that fullAccess nodes still behave like before that if they
1230
1230
  // request access to credentials that are currently not set it returns undefined
1231
1231
  return undefined;
@@ -1732,6 +1732,9 @@ function getExecuteFunctions(workflow, runExecutionData, runIndex, connectionInp
1732
1732
  getExecutionCancelSignal: () => {
1733
1733
  return undefined;
1734
1734
  },
1735
+ logAiEvent: (_event, _data) => {
1736
+ return;
1737
+ },
1735
1738
  };
1736
1739
  })(workflow, runExecutionData, connectionInputData, inputData, node, nodeTypeData, closeFunctions);
1737
1740
  }
@@ -2353,6 +2356,9 @@ function getSupplyDataFunctions(workflow, runExecutionData, runIndex, connection
2353
2356
  };
2354
2357
  return { outputExecutionData };
2355
2358
  },
2359
+ logAiEvent: (_event, _data) => {
2360
+ return;
2361
+ },
2356
2362
  async getInputConnectionData(connectionType, itemIndex) {
2357
2363
  return await getInputConnectionData.call(this, workflow, runExecutionData, runIndex, connectionInputData, inputData, additionalData, connectionType, mode, itemIndex, nodeTypeData, closeFunctions);
2358
2364
  },
@@ -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 { getInputConnectionDataLegacy, NodeExecuteFunctions, UserSettings };
@@ -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.UserSettings = exports.NodeExecuteFunctions = exports.getInputConnectionDataLegacy = 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);
@@ -0,0 +1,59 @@
1
+ import type { IWebhookData, WebhookHttpMethod, Workflow, WorkflowActivateMode, WorkflowExecuteMode } from "@fsai-flow/workflow";
2
+ export declare class ActiveWebhooks {
3
+ private workflowWebhooks;
4
+ private webhookUrls;
5
+ testWebhooks: boolean;
6
+ /**
7
+ * Adds a new webhook
8
+ *
9
+ * @param {IWebhookData} webhookData
10
+ * @param {WorkflowExecuteMode} mode
11
+ * @returns {Promise<void>}
12
+ * @memberof ActiveWebhooks
13
+ */
14
+ add(workflow: Workflow, webhookData: IWebhookData, mode: WorkflowExecuteMode, activation: WorkflowActivateMode): Promise<void>;
15
+ /**
16
+ * Returns webhookData if a webhook with matches is currently registered
17
+ *
18
+ * @param {WebhookHttpMethod} httpMethod
19
+ * @param {string} path
20
+ * @param {(string | undefined)} webhookId
21
+ * @returns {(IWebhookData | undefined)}
22
+ * @memberof ActiveWebhooks
23
+ */
24
+ get(httpMethod: WebhookHttpMethod, path: string, webhookId?: string): IWebhookData | undefined;
25
+ /**
26
+ * Gets all request methods associated with a single webhook
27
+ * @param path
28
+ */
29
+ getWebhookMethods(path: string): string[];
30
+ /**
31
+ * Returns the ids of all the workflows which have active webhooks
32
+ *
33
+ * @returns {string[]}
34
+ * @memberof ActiveWebhooks
35
+ */
36
+ getWorkflowIds(): string[];
37
+ /**
38
+ * Returns key to uniquely identify a webhook
39
+ *
40
+ * @param {WebhookHttpMethod} httpMethod
41
+ * @param {string} path
42
+ * @param {(string | undefined)} webhookId
43
+ * @returns {string}
44
+ * @memberof ActiveWebhooks
45
+ */
46
+ getWebhookKey(httpMethod: WebhookHttpMethod, path: string, webhookId?: string): string;
47
+ /**
48
+ * Removes all webhooks of a workflow
49
+ *
50
+ * @param {Workflow} workflow
51
+ * @returns {boolean}
52
+ * @memberof ActiveWebhooks
53
+ */
54
+ removeWorkflow(workflow: Workflow): Promise<boolean>;
55
+ /**
56
+ * Removes all the webhooks of the given workflows
57
+ */
58
+ removeAll(workflows: Workflow[]): Promise<void>;
59
+ }
@@ -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;
@@ -0,0 +1,87 @@
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
+ export declare class ActiveWorkflows {
5
+ private workflowData;
6
+ private redisConfig;
7
+ private instanceLeaderElection;
8
+ private pollingWorkflows;
9
+ private isLeader;
10
+ private isInitializingLeaderElection;
11
+ private leaderElectionInitialized;
12
+ private leaderElectionEnabled;
13
+ constructor(redisConfig?: string | RedisOptions);
14
+ /**
15
+ * Returns if the workflow is active
16
+ *
17
+ * @param {string} id The id of the workflow to check
18
+ * @returns {boolean}
19
+ * @memberof ActiveWorkflows
20
+ */
21
+ isActive(id: string): boolean;
22
+ /**
23
+ * Returns the ids of the currently active workflows
24
+ *
25
+ * @returns {string[]}
26
+ * @memberof ActiveWorkflows
27
+ */
28
+ allActiveWorkflows(): string[];
29
+ /**
30
+ * Returns the Workflow data for the workflow with
31
+ * the given id if it is currently active
32
+ *
33
+ * @param {string} id
34
+ * @returns {(WorkflowData | undefined)}
35
+ * @memberof ActiveWorkflows
36
+ */
37
+ get(id: string): IWorkflowData | undefined;
38
+ /**
39
+ * Makes a workflow active
40
+ *
41
+ * @param {string} id The id of the workflow to activate
42
+ * @param {Workflow} workflow The workflow to activate
43
+ * @param {IWorkflowExecuteAdditionalData} additionalData The additional data which is needed to run workflows
44
+ * @returns {Promise<void>}
45
+ * @memberof ActiveWorkflows
46
+ */
47
+ add(id: string, workflow: Workflow, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode, activation: WorkflowActivateMode, getTriggerFunctions: IGetExecuteTriggerFunctions, getPollFunctions: IGetExecutePollFunctions): Promise<void>;
48
+ /**
49
+ * Initialize global leader election (called once per instance)
50
+ */
51
+ private initializeLeaderElection;
52
+ /**
53
+ * Start all registered polling workflows (called when becoming leader)
54
+ */
55
+ private startAllPollingWorkflows;
56
+ /**
57
+ * Stop all polling workflows (called when losing leadership)
58
+ */
59
+ private stopAllPollingWorkflows;
60
+ /**
61
+ * Activates polling for the given node with global Redis leader election
62
+ *
63
+ * @param {INode} node
64
+ * @param {Workflow} workflow
65
+ * @param {IWorkflowExecuteAdditionalData} additionalData
66
+ * @param {IGetExecutePollFunctions} getPollFunctions
67
+ * @returns {Promise<IPollResponse>}
68
+ * @memberof ActiveWorkflows
69
+ */
70
+ activatePolling(node: INode, workflow: Workflow, additionalData: IWorkflowExecuteAdditionalData, getPollFunctions: IGetExecutePollFunctions, mode: WorkflowExecuteMode, activation: WorkflowActivateMode): Promise<IPollResponse>;
71
+ /**
72
+ * Extract cron time building logic (same as original)
73
+ */
74
+ private buildCronTimes;
75
+ /**
76
+ * Validate cron times (same as original)
77
+ */
78
+ private validateCronTimes;
79
+ /**
80
+ * Makes a workflow inactive
81
+ *
82
+ * @param {string} id The id of the workflow to deactivate
83
+ * @returns {Promise<void>}
84
+ * @memberof ActiveWorkflows
85
+ */
86
+ remove(id: string): Promise<void>;
87
+ }