@fsai-flow/core 0.0.5 → 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.
- package/dist/index.d.ts +17 -0
- package/dist/index.js +61 -0
- package/dist/lib/ActiveWebhooks.d.ts +59 -0
- package/dist/lib/ActiveWebhooks.js +177 -0
- package/dist/lib/ActiveWorkflows.d.ts +87 -0
- package/dist/lib/ActiveWorkflows.js +465 -0
- package/dist/lib/BinaryDataManager/FileSystem.d.ts +26 -0
- package/dist/lib/BinaryDataManager/FileSystem.js +180 -0
- package/dist/lib/BinaryDataManager/index.d.ts +21 -0
- package/dist/lib/BinaryDataManager/index.js +129 -0
- package/dist/lib/ChangeCase.d.ts +9 -0
- package/dist/lib/ChangeCase.js +43 -0
- package/dist/lib/Constants.d.ts +14 -0
- package/dist/lib/Constants.js +18 -0
- package/dist/lib/Credentials.d.ts +27 -0
- package/dist/lib/Credentials.js +88 -0
- package/dist/lib/FileSystem.d.ts +26 -0
- package/dist/lib/FileSystem.js +180 -0
- package/dist/lib/InputConnectionDataLegacy.d.ts +2 -0
- package/dist/lib/InputConnectionDataLegacy.js +72 -0
- package/dist/lib/Interfaces.d.ts +147 -0
- package/dist/lib/Interfaces.js +2 -0
- package/dist/lib/LoadNodeParameterOptions.d.ts +39 -0
- package/dist/lib/LoadNodeParameterOptions.js +152 -0
- package/dist/lib/NodeExecuteFunctions.d.ts +225 -0
- package/dist/lib/NodeExecuteFunctions.js +2467 -0
- package/dist/lib/NodesLoader/constants.d.ts +5 -0
- package/dist/lib/NodesLoader/constants.js +105 -0
- package/dist/lib/NodesLoader/custom-directory-loader.d.ts +9 -0
- package/dist/lib/NodesLoader/custom-directory-loader.js +35 -0
- package/dist/lib/NodesLoader/directory-loader.d.ts +66 -0
- package/dist/lib/NodesLoader/directory-loader.js +367 -0
- package/dist/lib/NodesLoader/index.d.ts +5 -0
- package/dist/lib/NodesLoader/index.js +11 -0
- package/dist/lib/NodesLoader/lazy-package-directory-loader.d.ts +7 -0
- package/dist/lib/NodesLoader/lazy-package-directory-loader.js +44 -0
- package/dist/lib/NodesLoader/load-class-in-isolation.d.ts +1 -0
- package/dist/lib/NodesLoader/load-class-in-isolation.js +17 -0
- package/dist/lib/NodesLoader/package-directory-loader.d.ts +17 -0
- package/dist/lib/NodesLoader/package-directory-loader.js +92 -0
- package/dist/lib/NodesLoader/types.d.ts +14 -0
- package/dist/lib/NodesLoader/types.js +2 -0
- package/dist/lib/RedisLeaderElectionManager.d.ts +53 -0
- package/dist/lib/RedisLeaderElectionManager.js +279 -0
- package/dist/lib/RequestTypes.d.ts +58 -0
- package/dist/lib/RequestTypes.js +8 -0
- package/dist/lib/UserSettings.d.ts +80 -0
- package/dist/lib/UserSettings.js +269 -0
- package/dist/lib/WorkflowExecute.d.ts +53 -0
- package/dist/lib/WorkflowExecute.js +906 -0
- package/dist/lib/index.d.ts +21 -0
- package/dist/lib/index.js +129 -0
- package/dist/utils/crypto.d.ts +1 -0
- package/dist/utils/crypto.js +7 -0
- package/package.json +59 -52
- package/dist/README.md +0 -31
- package/dist/package.json +0 -54
- package/eslint.config.js +0 -19
- package/jest.config.ts +0 -10
- package/project.json +0 -19
- package/src/index.ts +0 -28
- package/src/lib/ActiveWebhooks.ts +0 -245
- package/src/lib/ActiveWorkflows.ts +0 -575
- package/src/lib/BinaryDataManager/FileSystem.ts +0 -214
- package/src/lib/BinaryDataManager/index.ts +0 -187
- package/src/lib/ChangeCase.ts +0 -45
- package/src/lib/Constants.ts +0 -16
- package/src/lib/Credentials.ts +0 -108
- package/src/lib/FileSystem.ts +0 -214
- package/src/lib/InputConnectionDataLegacy.ts +0 -123
- package/src/lib/Interfaces.ts +0 -338
- package/src/lib/LoadNodeParameterOptions.ts +0 -235
- package/src/lib/NodeExecuteFunctions.ts +0 -3700
- package/src/lib/NodesLoader/constants.ts +0 -112
- package/src/lib/NodesLoader/custom-directory-loader.ts +0 -31
- package/src/lib/NodesLoader/directory-loader.ts +0 -458
- package/src/lib/NodesLoader/index.ts +0 -5
- package/src/lib/NodesLoader/lazy-package-directory-loader.ts +0 -55
- package/src/lib/NodesLoader/load-class-in-isolation.ts +0 -19
- package/src/lib/NodesLoader/package-directory-loader.ts +0 -107
- package/src/lib/NodesLoader/types.ts +0 -14
- package/src/lib/RedisLeaderElectionManager.ts +0 -334
- package/src/lib/UserSettings.ts +0 -292
- package/src/lib/WorkflowExecute.ts +0 -1128
- package/src/lib/index.ts +0 -187
- package/src/utils/crypto.ts +0 -5
- package/tests/Credentials.test.ts +0 -88
- package/tests/Helpers.ts +0 -808
- package/tests/WorkflowExecute.test.ts +0 -1242
- package/tsconfig.json +0 -41
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -14
package/dist/index.d.ts
ADDED
|
@@ -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);
|
|
@@ -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
|
+
}
|