@5minds/node-red-contrib-processcube 1.2.3-feature-241db2-m21w1ewd → 1.3.0-feature-92414d-m21x3yqt

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.2.3-feature-241db2-m21w1ewd",
3
+ "version": "1.3.0-feature-92414d-m21x3yqt",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -72,5 +72,6 @@ Waiting for Usertasks of the connected ProcessCube Engine.
72
72
 
73
73
  ### References
74
74
 
75
- - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube© Plattform
75
+ - [The ProcessCube© Developer Network](https://processcube.io) - All documentation for the ProcessCube© platform
76
+ - [ProcessCube© LowCode Integration](https://processcube.io/docs/node-red) - LowCode integration in ProcessCube©
76
77
  </script>
@@ -1,91 +1,89 @@
1
- const process = require('process');
2
-
3
- const engine_client = require('@5minds/processcube_engine_client');
4
- const { userInfo } = require('os');
5
-
6
1
  module.exports = function (RED) {
7
2
  function WaitForUsertask(config) {
8
3
  RED.nodes.createNode(this, config);
9
4
  var node = this;
10
- var nodeContext = node.context();
11
-
12
- this.engine = this.server = RED.nodes.getNode(config.engine);
13
-
14
- const engineUrl = this.engine?.url || process.env.ENGINE_URL || 'http://engine:8000';
15
5
 
16
- var client = nodeContext.get('client');
6
+ const engine = RED.nodes.getNode(config.engine);
17
7
 
18
- if (!client) {
19
- nodeContext.set('client', new engine_client.EngineClient(engineUrl));
20
- client = nodeContext.get('client');
21
- }
8
+ const client = engine.engineClient;
22
9
 
23
-
24
- let currentIdentity = null;
25
10
  let subscription = null;
11
+ let currentIdentity = engine.identity;
12
+ let subscribe = null;
26
13
 
27
14
  node.on('input', async function (msg) {
28
- if (node.server) {
29
- currentIdentity = node.server.identity;
30
- } else {
31
- node.error("No processcube_config node found.")
32
- return;
33
- }
15
+ subscribe = async () => {
16
+ if (!client) {
17
+ node.error('No engine configured.');
18
+ return;
19
+ }
34
20
 
35
- const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
21
+ const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
36
22
 
37
- subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
23
+ subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
38
24
 
39
- const newQuery = {
40
- 'flowNodeInstanceId': userTaskWaitingNotification.flowNodeInstanceId,
41
- ...query
42
- };
25
+ const newQuery = {
26
+ 'flowNodeInstanceId': userTaskWaitingNotification.flowNodeInstanceId,
27
+ ...query
28
+ };
43
29
 
44
- const matchingFlowNodes = await client.userTasks.query(newQuery, { identity: currentIdentity });
30
+ const matchingFlowNodes = await client.userTasks.query(newQuery, { identity: currentIdentity });
45
31
 
46
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
47
- const userTask = matchingFlowNodes.userTasks[0];
32
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
33
+ const userTask = matchingFlowNodes.userTasks[0];
48
34
 
49
- msg.payload = { userTask: userTask };
50
- node.send(msg);
51
- } else {
52
- // nothing todo - wait for next notification
53
- }
35
+ msg.payload = { userTask: userTask };
36
+ node.send(msg);
37
+ } else {
38
+ // nothing todo - wait for next notification
39
+ }
54
40
 
55
- // remove subscription
56
- client.userTasks.removeSubscription(subscription, currentIdentity);
57
- }, { identity: currentIdentity });
41
+ // remove subscription
42
+ client.userTasks.removeSubscription(subscription, currentIdentity);
43
+ }, { identity: currentIdentity });
58
44
 
59
- console.debug('Handling old userTasks config.only_for_new', config.only_for_new);
45
+ node.log({"Handling old userTasks config.only_for_new": config.only_for_new});
60
46
 
61
- if (config.only_for_new === false) {
62
- // only check suspended user tasks
63
- const suspendedQuery = {
64
- 'state': 'suspended',
65
- ...query
66
- };
47
+ if (config.only_for_new === false) {
48
+ // only check suspended user tasks
49
+ const suspendedQuery = {
50
+ 'state': 'suspended',
51
+ ...query
52
+ };
67
53
 
68
- const matchingFlowNodes = await client.userTasks.query(suspendedQuery, { identity: currentIdentity });
54
+ const matchingFlowNodes = await client.userTasks.query(suspendedQuery, { identity: currentIdentity });
69
55
 
70
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
71
- const userTask = matchingFlowNodes.userTasks[0];
56
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
57
+ const userTask = matchingFlowNodes.userTasks[0];
72
58
 
73
- msg.payload = { userTask: userTask };
74
- node.send(msg);
59
+ msg.payload = { userTask: userTask };
60
+ node.send(msg);
75
61
 
76
- // remove subscription
77
- client.userTasks.removeSubscription(subscription, currentIdentity);
78
- } else {
79
- // let the *currentIdentity* be active
62
+ // remove subscription
63
+ client.userTasks.removeSubscription(subscription, currentIdentity);
64
+ } else {
65
+ // let the *currentIdentity* be active
66
+ }
80
67
  }
68
+ };
69
+
70
+ subscribe();
71
+ });
72
+
73
+ node.engine.registerOnIdentityChanged(async (identity) => {
74
+
75
+ if (subscription) {
76
+ client.userTasks.removeSubscription(subscription, currentIdentity);
77
+ currentIdentity = identity;
78
+ subscribe();
79
+ } else {
80
+ currentIdentity = identity;
81
81
  }
82
82
  });
83
83
 
84
84
  node.on("close", async () => {
85
- if (client != null) {
85
+ if (client != null && subscription != null) {
86
86
  client.userTasks.removeSubscription(subscription, currentIdentity);
87
- client.dispose();
88
- client = null;
89
87
  }
90
88
  });
91
89
  }