@pxp-nd/flow 1.1.21 → 1.1.23
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/controllers/Flow.d.ts +2 -2
- package/dist/controllers/Flow.js +72 -28
- package/dist/controllers/FlowInstance.d.ts +1 -0
- package/dist/controllers/FlowInstance.js +21 -0
- package/dist/controllers/NodeInstance.js +16 -1
- package/dist/entity/ActionType.d.ts +1 -0
- package/dist/entity/ActionType.js +4 -0
- package/dist/entity/NodeInstance.d.ts +1 -0
- package/dist/entity/NodeInstance.js +4 -0
- package/package.json +1 -1
|
@@ -25,8 +25,8 @@ import { EntityManager } from 'typeorm';
|
|
|
25
25
|
import { Controller } from '@pxp-nd/core';
|
|
26
26
|
declare class Flow extends Controller {
|
|
27
27
|
get(params: Record<string, any>): Promise<unknown>;
|
|
28
|
-
copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager): Promise<void>;
|
|
29
|
-
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean): Promise<{
|
|
28
|
+
copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager, isCopy?: boolean): Promise<void>;
|
|
29
|
+
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean, isCopy?: boolean): Promise<{
|
|
30
30
|
nodeId: any;
|
|
31
31
|
}>;
|
|
32
32
|
createFlowFromFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
package/dist/controllers/Flow.js
CHANGED
|
@@ -66,7 +66,6 @@ const Action_1 = __importDefault(require("../entity/Action"));
|
|
|
66
66
|
const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
|
|
67
67
|
const Flow_1 = __importDefault(require("../entity/Flow"));
|
|
68
68
|
const FlowInstance_1 = __importDefault(require("../entity/FlowInstance"));
|
|
69
|
-
const NodeInstance_1 = __importDefault(require("../entity/NodeInstance"));
|
|
70
69
|
const Node_2 = __importDefault(require("./Node"));
|
|
71
70
|
const axios_1 = __importDefault(require("axios"));
|
|
72
71
|
//import {configFacebookStrategy} from "./passport-facebook";
|
|
@@ -94,22 +93,55 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
94
93
|
}
|
|
95
94
|
return restNodes;
|
|
96
95
|
}
|
|
97
|
-
async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
|
|
96
|
+
async copyNodeConnections(nodeId, newNodeId, newFlowId, manager, isCopy = false) {
|
|
98
97
|
const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId, isActive: true }));
|
|
99
98
|
for (let connection of connections) {
|
|
100
99
|
const newNodeConnection = new NodeConnection_1.default();
|
|
101
100
|
const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
|
|
102
101
|
// get node from nodeIdChild
|
|
103
102
|
const dataNodeChild = await Node_1.default.findOne({ nodeId: connection.nodeIdChild });
|
|
104
|
-
const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager);
|
|
103
|
+
const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager, false, isCopy);
|
|
105
104
|
Object.assign(newNodeConnection, { ...nodeConnectionToCopy, nodeIdMaster: newNodeId, nodeIdChild: newNodeIdChild });
|
|
106
105
|
const insertNewNodeConnection = await (0, core_1.__)(manager.save(NodeConnection_1.default, newNodeConnection));
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
async copyNode(node, newFlowId, manager, isFirst = false) {
|
|
108
|
+
async copyNode(node, newFlowId, manager, isFirst = false, isCopy = false) {
|
|
109
|
+
var _a, _b, _c, _d;
|
|
110
110
|
// insert new node
|
|
111
111
|
const newNode = new Node_1.default();
|
|
112
112
|
const { nodeId, flowId, createdAt, modifiedAt, ...nodeToCopy } = node;
|
|
113
|
+
if (isCopy && ((_b = (_a = nodeToCopy === null || nodeToCopy === void 0 ? void 0 : nodeToCopy.action) === null || _a === void 0 ? void 0 : _a.actionType) === null || _b === void 0 ? void 0 : _b.onDuplicate) === 'duplicateChainedFlow') {
|
|
114
|
+
if ((_c = nodeToCopy === null || nodeToCopy === void 0 ? void 0 : nodeToCopy.action) === null || _c === void 0 ? void 0 : _c.configJsonTemplate) {
|
|
115
|
+
try {
|
|
116
|
+
const parsedConfig = JSON.parse(nodeToCopy.action.configJsonTemplate);
|
|
117
|
+
if (parsedConfig.addController && parsedConfig.template) {
|
|
118
|
+
const params = {
|
|
119
|
+
template: parsedConfig.template,
|
|
120
|
+
flowId: newFlowId,
|
|
121
|
+
};
|
|
122
|
+
const config = {
|
|
123
|
+
method: "post",
|
|
124
|
+
url: `http://localhost:${process.env.PORT}/api/${parsedConfig.addController}`,
|
|
125
|
+
headers: {
|
|
126
|
+
Authorization: "" + process.env.TOKEN_PXP_ND + "",
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
},
|
|
129
|
+
data: params,
|
|
130
|
+
};
|
|
131
|
+
const resControllerAxios = await (0, axios_1.default)(config);
|
|
132
|
+
const chainedFlowId = (_d = resControllerAxios.data) === null || _d === void 0 ? void 0 : _d.flowId;
|
|
133
|
+
const parsedValues = {
|
|
134
|
+
flowId: chainedFlowId
|
|
135
|
+
};
|
|
136
|
+
const newConfigJson = JSON.stringify(parsedValues);
|
|
137
|
+
nodeToCopy.actionConfigJson = newConfigJson;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error("Not valid json", error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
113
145
|
Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
|
|
114
146
|
const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
|
|
115
147
|
if (isFirst) {
|
|
@@ -121,7 +153,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
121
153
|
await manager.save(duplicatedConnection);
|
|
122
154
|
}
|
|
123
155
|
// insert connection
|
|
124
|
-
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
|
|
156
|
+
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager, isCopy);
|
|
125
157
|
return { nodeId: insertNewNode.nodeId };
|
|
126
158
|
}
|
|
127
159
|
async createFlowFromFlow(params, manager) {
|
|
@@ -218,15 +250,16 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
218
250
|
status: 'off'
|
|
219
251
|
};
|
|
220
252
|
let flowDataClone;
|
|
221
|
-
|
|
222
|
-
if
|
|
223
|
-
|
|
253
|
+
let isCopy = false;
|
|
254
|
+
//if we have a name as parameter the origin is a template
|
|
255
|
+
if (params.name) {
|
|
256
|
+
flowDataClone = await (0, typeorm_1.getManager)().save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
|
|
224
257
|
}
|
|
225
258
|
else {
|
|
226
|
-
flowDataClone = await
|
|
259
|
+
flowDataClone = await (0, typeorm_1.getManager)().save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
|
|
227
260
|
}
|
|
228
261
|
const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId, isInit: 'Y', isActive: true }, order: { nodeId: "ASC" } });
|
|
229
|
-
dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true);
|
|
262
|
+
dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true, isCopy);
|
|
230
263
|
return { success: true, flowId: flowDataClone.flowId };
|
|
231
264
|
}
|
|
232
265
|
else {
|
|
@@ -234,7 +267,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
234
267
|
}
|
|
235
268
|
}
|
|
236
269
|
async saveFlow(params, manager) {
|
|
237
|
-
var _a, _b;
|
|
270
|
+
var _a, _b, _c, _d;
|
|
238
271
|
let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
|
|
239
272
|
let nodes = params.board.tasks ? params.board.tasks : [];
|
|
240
273
|
let masterId = null;
|
|
@@ -289,7 +322,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
289
322
|
});
|
|
290
323
|
if (connectionsToDel) {
|
|
291
324
|
const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
|
|
292
|
-
let flowNodeC = await
|
|
325
|
+
let flowNodeC = await manager.query(`DELETE
|
|
293
326
|
from twf_node_connection
|
|
294
327
|
WHERE node_connection_id = ${originalNodeCIds}`);
|
|
295
328
|
}
|
|
@@ -349,7 +382,14 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
349
382
|
}
|
|
350
383
|
}
|
|
351
384
|
catch (error) {
|
|
352
|
-
|
|
385
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
386
|
+
const message = ((_c = (_b = error.response.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error';
|
|
387
|
+
throw new core_1.PxpError(400, message);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
console.error("Not valid json", error);
|
|
391
|
+
throw new core_1.PxpError(500, 'Unexpected error while processing the request');
|
|
392
|
+
}
|
|
353
393
|
}
|
|
354
394
|
}
|
|
355
395
|
}
|
|
@@ -397,7 +437,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
397
437
|
data: params,
|
|
398
438
|
};
|
|
399
439
|
const resControllerAxios = await (0, axios_1.default)(config);
|
|
400
|
-
const chainedFlowId = (
|
|
440
|
+
const chainedFlowId = (_d = resControllerAxios.data) === null || _d === void 0 ? void 0 : _d.flowId;
|
|
401
441
|
const parsedValues = {
|
|
402
442
|
flowId: chainedFlowId
|
|
403
443
|
};
|
|
@@ -706,21 +746,25 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
706
746
|
validFlowInstances.push(flowInstance.flowInstanceId);
|
|
707
747
|
}
|
|
708
748
|
else {
|
|
749
|
+
/*Commented because scheduled nodes shouldn't be affected by stopping
|
|
709
750
|
let flowInstanceId = flowInstance.flowInstanceId;
|
|
710
|
-
const totalNI = await
|
|
711
|
-
const nodeInstances = await
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
751
|
+
const totalNI = await NodeInstanceModel.find({ flowInstanceId, isActive: true});
|
|
752
|
+
const nodeInstances = await getManager().transaction(async (transactionalEntityManager) => {
|
|
753
|
+
const queryBuilder: SelectQueryBuilder<NodeInstanceModel> = transactionalEntityManager.createQueryBuilder(NodeInstanceModel, 'node_instance');
|
|
754
|
+
queryBuilder
|
|
755
|
+
.where('node_instance.flowInstanceId = :flowInstanceId', { flowInstanceId })
|
|
756
|
+
.andWhere('((node_instance.status IS NULL AND (node_instance.schedule = :schedule OR node_instance.schedule IS NULL)) OR (node_instance.status = :status AND node_instance.schedule != :schedule AND node_instance.schedule IS NOT NULL))', {
|
|
757
|
+
status: 'executed',
|
|
758
|
+
schedule: '0000-00-00 00:00:00',
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
return queryBuilder.getMany();
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
if (totalNI.length > nodeInstances.length ) {
|
|
766
|
+
validFlowInstances.push(flowInstanceId);
|
|
767
|
+
}*/
|
|
724
768
|
}
|
|
725
769
|
}
|
|
726
770
|
if (validFlowInstances.length > 0) {
|
|
@@ -18,5 +18,6 @@ declare class FlowInstance extends Controller {
|
|
|
18
18
|
processPending(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
19
19
|
eventProcesss(manager: EntityManager): Promise<void>;
|
|
20
20
|
checkConditions(viewData: Record<string, any>, flowId: number, actionId: number): Promise<boolean>;
|
|
21
|
+
insert(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
21
22
|
}
|
|
22
23
|
export default FlowInstance;
|
|
@@ -135,6 +135,18 @@ class FlowInstance extends core_1.Controller {
|
|
|
135
135
|
}
|
|
136
136
|
return res;
|
|
137
137
|
}
|
|
138
|
+
async insert(params, manager) {
|
|
139
|
+
const { flowId, dataId, status, actionId, originName = '', originKey = '' } = params;
|
|
140
|
+
let flowInstance = new FlowInstance_1.default();
|
|
141
|
+
flowInstance.flowId = flowId;
|
|
142
|
+
flowInstance.dataId = dataId;
|
|
143
|
+
flowInstance.originName = originName;
|
|
144
|
+
flowInstance.originKey = originKey;
|
|
145
|
+
flowInstance.actionId = actionId;
|
|
146
|
+
flowInstance.status = status;
|
|
147
|
+
flowInstance = await manager.save(FlowInstance_1.default, flowInstance);
|
|
148
|
+
return flowInstance;
|
|
149
|
+
}
|
|
138
150
|
}
|
|
139
151
|
__decorate([
|
|
140
152
|
(0, core_1.Post)(),
|
|
@@ -145,4 +157,13 @@ __decorate([
|
|
|
145
157
|
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
146
158
|
__metadata("design:returntype", Promise)
|
|
147
159
|
], FlowInstance.prototype, "processPending", null);
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, core_1.Post)(),
|
|
162
|
+
(0, core_1.DbSettings)('Orm'),
|
|
163
|
+
(0, core_1.ReadOnly)(false),
|
|
164
|
+
(0, core_1.Log)(true),
|
|
165
|
+
__metadata("design:type", Function),
|
|
166
|
+
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
167
|
+
__metadata("design:returntype", Promise)
|
|
168
|
+
], FlowInstance.prototype, "insert", null);
|
|
148
169
|
exports.default = FlowInstance;
|
|
@@ -42,6 +42,7 @@ const FlowInstance_1 = __importDefault(require("../entity/FlowInstance"));
|
|
|
42
42
|
const common_1 = require("@pxp-nd/common");
|
|
43
43
|
let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
44
44
|
async RecursiveInstance(params, manager) {
|
|
45
|
+
console.log("==========node instance en MZM===========");
|
|
45
46
|
//https://lodash.com/docs/4.17.15#template
|
|
46
47
|
lodash_1.default.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
47
48
|
//todo after this we need to get the json variables and execute the view and conditions configured in the database
|
|
@@ -52,6 +53,7 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
52
53
|
const resExecuteView = await (0, core_1.__)((0, typeorm_1.getManager)().query(executeView));
|
|
53
54
|
const resultFromOrigin = resExecuteView[0];
|
|
54
55
|
console.log("**** resultFromOrigin:", resultFromOrigin);
|
|
56
|
+
//let mergeJson = {};
|
|
55
57
|
let mergeJson = {};
|
|
56
58
|
const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson }, }, } = node;
|
|
57
59
|
if (configJsonTemplate !== "" || actionConfigJson !== "") {
|
|
@@ -86,6 +88,12 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
86
88
|
else {
|
|
87
89
|
if (node.action.actionType.controller) {
|
|
88
90
|
const data = "";
|
|
91
|
+
const res = await manager.save(NodeInstance_1.default, nodeInstance);
|
|
92
|
+
const nodeInstanceId = res.nodeInstanceId;
|
|
93
|
+
console.log("el id q tenemos q mandarrrrrr:::", nodeInstanceId);
|
|
94
|
+
if (nodeInstanceId) {
|
|
95
|
+
mergeJson.nodeInstanceId = nodeInstanceId;
|
|
96
|
+
}
|
|
89
97
|
const config = {
|
|
90
98
|
method: "post",
|
|
91
99
|
url: `http://localhost:${process.env.PORT}/api/${node.action.actionType.controller}`,
|
|
@@ -97,8 +105,15 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
97
105
|
};
|
|
98
106
|
// @ts-ignore
|
|
99
107
|
const resControllerAxios = await (0, core_1.__)((0, axios_1.default)(config));
|
|
108
|
+
if ('data' in resControllerAxios && resControllerAxios.data) {
|
|
109
|
+
const response = resControllerAxios.data;
|
|
110
|
+
if ('tokenId' in response && response.tokenId) {
|
|
111
|
+
nodeInstance.extraArgs = { tokenId: response.tokenId };
|
|
112
|
+
await manager.save(NodeInstance_1.default, nodeInstance);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
console.log("la respuesta del Axiossss:", resControllerAxios.data);
|
|
100
116
|
}
|
|
101
|
-
await manager.save(NodeInstance_1.default, nodeInstance);
|
|
102
117
|
// @ts-ignore
|
|
103
118
|
const nodeConnectionList = await (0, core_1.__)(NodeConnection_1.default.find({ where: { nodeIdMaster: node.nodeId } }));
|
|
104
119
|
for (const nodeConnection of nodeConnectionList) {
|
|
@@ -73,6 +73,10 @@ __decorate([
|
|
|
73
73
|
(0, typeorm_1.Column)({ name: 'actions_json', type: 'text' }),
|
|
74
74
|
__metadata("design:type", String)
|
|
75
75
|
], ActionType.prototype, "actionsJson", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, typeorm_1.Column)({ name: 'on_duplicate', type: 'varchar' }),
|
|
78
|
+
__metadata("design:type", String)
|
|
79
|
+
], ActionType.prototype, "onDuplicate", void 0);
|
|
76
80
|
__decorate([
|
|
77
81
|
(0, typeorm_1.Column)({ name: 'validation_controller', type: 'text' }),
|
|
78
82
|
__metadata("design:type", String)
|
|
@@ -42,6 +42,10 @@ __decorate([
|
|
|
42
42
|
(0, typeorm_1.Column)({ name: 'status', type: 'varchar', nullable: false, length: 50 }),
|
|
43
43
|
__metadata("design:type", String)
|
|
44
44
|
], NodeInstance.prototype, "status", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typeorm_1.Column)({ name: 'extra_args', type: 'json', nullable: true }),
|
|
47
|
+
__metadata("design:type", Object)
|
|
48
|
+
], NodeInstance.prototype, "extraArgs", void 0);
|
|
45
49
|
__decorate([
|
|
46
50
|
(0, typeorm_1.ManyToOne)(() => FlowInstance_1.default, flowInstance => flowInstance.nodeInstances),
|
|
47
51
|
(0, typeorm_1.JoinColumn)({ name: 'flow_instance_id' }),
|