@5minds/node-red-contrib-processcube 1.2.2 → 1.2.3-feature-241db2-m21w1ewd

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.2",
3
+ "version": "1.2.3-feature-241db2-m21w1ewd",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -52,12 +52,13 @@
52
52
  "UserTaskNewListener": "usertask-new-listener.js",
53
53
  "UserTaskFinishedListener": "usertask-finished-listener.js",
54
54
  "UserTaskInput": "usertask-input.js",
55
- "UserTaskOutput": "usertask-output.js"
55
+ "UserTaskOutput": "usertask-output.js",
56
+ "WaitForUsertask": "wait-for-usertask.js"
56
57
  },
57
58
  "examples": "examples"
58
59
  },
59
60
  "dependencies": {
60
- "@5minds/processcube_engine_client": "^5.0.2",
61
+ "@5minds/processcube_engine_client": "^5.1.0",
61
62
  "jwt-decode": "^4.0.0",
62
63
  "openid-client": "^5.5.0"
63
64
  },
@@ -0,0 +1,76 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('wait-for-usertask',{
3
+ category: 'ProcessCube',
4
+ color: '#02AFD6',
5
+ defaults: {
6
+ name: {value: ""},
7
+ engine: {value: "", type: "processcube-engine-config"},
8
+ query: {value: "payload"},
9
+ query_type: {value: "msg"},
10
+ only_for_new: {value: false}
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: "font-awesome/fa-envelope-open",
15
+ label: function() {
16
+ return this.name || "wait-for-usertask";
17
+ },
18
+ oneditprepare: function() {
19
+ $("#node-input-query").typedInput({
20
+ default: 'msg',
21
+ types: ['msg', 'json']
22
+ });
23
+
24
+ $("#node-input-query").typedInput('value', this.query);
25
+ $("#node-input-query").typedInput('type', this.query_type);
26
+ },
27
+ oneditsave: function() {
28
+ this.query = $("#node-input-query").typedInput('value'),
29
+ this.query_type = $("#node-input-query").typedInput('type')
30
+
31
+ }
32
+ });
33
+ </script>
34
+
35
+ <script type="text/html" data-template-name="wait-for-usertask">
36
+ <div class="form-row">
37
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
38
+ <input type="text" id="node-input-name" placeholder="Name">
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-engine"><i class="fa fa-tag"></i> Engine-URL</label>
42
+ <input type="text" id="node-input-engine" placeholder="http://engine:8000">
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
46
+ <input type="text" id="node-input-query">
47
+ </div>
48
+ <div class="form-row" style="display:flex; margin-bottom: 3px;">
49
+ <label for="node-input-only_for_new" style="vertical-align:top"><i class="fa fa-list-alt"></i> Only for new</label>
50
+ <div>
51
+ <input type="checkbox" checked id="node-input-only_for_new" style="display: inline-block; width: auto; margin: 0px 0px 0px 4px;">
52
+ <label style="width:auto" for="node-input-multisend">Trigger only for new user task or *checked* also for old ones?</label>
53
+ </div>
54
+ </div>
55
+ </script>
56
+
57
+ <script type="text/markdown" data-help-name="wait-for-usertask">
58
+ Waiting for Usertasks of the connected ProcessCube Engine.
59
+
60
+ ### Inputs
61
+
62
+ : payload (json) : the query to filter the usertasks.
63
+
64
+ ## Outputs
65
+
66
+ : payload.userTask (string) : The filtered UserTask
67
+
68
+ ### Details
69
+
70
+ - `msg.payload` or a constant json to filter the UserTasks for Waiting for
71
+ - `Only for new` will trigger only for new UserTasks if checked and also for old ones if not checked.
72
+
73
+ ### References
74
+
75
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; Plattform
76
+ </script>
@@ -0,0 +1,93 @@
1
+ const process = require('process');
2
+
3
+ const engine_client = require('@5minds/processcube_engine_client');
4
+ const { userInfo } = require('os');
5
+
6
+ module.exports = function (RED) {
7
+ function WaitForUsertask(config) {
8
+ RED.nodes.createNode(this, config);
9
+ 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
+
16
+ var client = nodeContext.get('client');
17
+
18
+ if (!client) {
19
+ nodeContext.set('client', new engine_client.EngineClient(engineUrl));
20
+ client = nodeContext.get('client');
21
+ }
22
+
23
+
24
+ let currentIdentity = null;
25
+ let subscription = null;
26
+
27
+ 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
+ }
34
+
35
+ const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
36
+
37
+ subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
38
+
39
+ const newQuery = {
40
+ 'flowNodeInstanceId': userTaskWaitingNotification.flowNodeInstanceId,
41
+ ...query
42
+ };
43
+
44
+ const matchingFlowNodes = await client.userTasks.query(newQuery, { identity: currentIdentity });
45
+
46
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
47
+ const userTask = matchingFlowNodes.userTasks[0];
48
+
49
+ msg.payload = { userTask: userTask };
50
+ node.send(msg);
51
+ } else {
52
+ // nothing todo - wait for next notification
53
+ }
54
+
55
+ // remove subscription
56
+ client.userTasks.removeSubscription(subscription, currentIdentity);
57
+ }, { identity: currentIdentity });
58
+
59
+ console.debug('Handling old userTasks config.only_for_new', config.only_for_new);
60
+
61
+ if (config.only_for_new === false) {
62
+ // only check suspended user tasks
63
+ const suspendedQuery = {
64
+ 'state': 'suspended',
65
+ ...query
66
+ };
67
+
68
+ const matchingFlowNodes = await client.userTasks.query(suspendedQuery, { identity: currentIdentity });
69
+
70
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
71
+ const userTask = matchingFlowNodes.userTasks[0];
72
+
73
+ msg.payload = { userTask: userTask };
74
+ node.send(msg);
75
+
76
+ // remove subscription
77
+ client.userTasks.removeSubscription(subscription, currentIdentity);
78
+ } else {
79
+ // let the *currentIdentity* be active
80
+ }
81
+ }
82
+ });
83
+
84
+ node.on("close", async () => {
85
+ if (client != null) {
86
+ client.userTasks.removeSubscription(subscription, currentIdentity);
87
+ client.dispose();
88
+ client = null;
89
+ }
90
+ });
91
+ }
92
+ RED.nodes.registerType("wait-for-usertask", WaitForUsertask);
93
+ }