@5minds/node-red-contrib-processcube 0.14.0 → 0.15.0-develop-2d3c96-lz098cox

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 120,
4
+ "arrowParens": "always",
5
+ "tabWidth": 4
6
+ }
@@ -1,45 +1,45 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('externaltask-error',{
2
+ RED.nodes.registerType('externaltask-error', {
3
3
  category: 'ProcessCube',
4
4
  color: '#F6A923',
5
5
  defaults: {
6
- name: {value:""},
7
- error: {value:""}
6
+ name: { value: '' },
7
+ error: { value: '' },
8
8
  },
9
9
  inputs: 1,
10
10
  outputs: 1,
11
- icon: "font-awesome/fa-exclamation-triangle",
12
- label: function() {
13
- return this.name || "externaltask-error";
14
- }
11
+ icon: 'font-awesome/fa-exclamation-triangle',
12
+ label: function () {
13
+ return this.name || 'externaltask-error';
14
+ },
15
15
  });
16
16
  </script>
17
17
 
18
18
  <script type="text/html" data-template-name="externaltask-error">
19
19
  <div class="form-row">
20
20
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
21
- <input type="text" id="node-input-name" placeholder="Name">
21
+ <input type="text" id="node-input-name" placeholder="Name" />
22
22
  </div>
23
23
  <div class="form-row">
24
24
  <label for="node-input-error"><i class="fa fa-tag"></i> Error Code</label>
25
- <input type="text" id="node-input-error" placeholder="Error Code of ExternalTask">
25
+ <input type="text" id="node-input-error" placeholder="Error Code of ExternalTask" />
26
26
  </div>
27
27
  </script>
28
28
 
29
29
  <script type="text/markdown" data-help-name="externaltask-error">
30
- Used for reporting errors in the processing of external tasks. The error
31
- code `Error` in the configuration is forwarded to the ProcessCube engine for
32
- handling within *Error-Boundary-Events*.
30
+ Used for reporting errors in the processing of external tasks. The error
31
+ code `Error` in the configuration is forwarded to the ProcessCube engine for
32
+ handling within _Error-Boundary-Events_.
33
33
 
34
- ## Inputs
34
+ ## Inputs
35
35
 
36
- : msg (Object) : Passed as `ErrorDetails` to the engine
37
- : Error (string) : From the configuration
38
- : Message (string) : The caught exception message
39
- : StackTrace (string) : The stack trace of the exception
36
+ : msg (Object) : Passed as `ErrorDetails` to the engine
37
+ : Error (string) : From the configuration
38
+ : Message (string) : The caught exception message
39
+ : StackTrace (string) : The stack trace of the exception
40
40
 
41
- ### References
41
+ ### References
42
42
 
43
- - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
44
- - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
45
- </script>
43
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
44
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
45
+ </script>
@@ -1,19 +1,18 @@
1
- module.exports = function(RED) {
1
+ module.exports = function (RED) {
2
2
  function ExternalTaskError(config) {
3
- RED.nodes.createNode(this,config);
3
+ RED.nodes.createNode(this, config);
4
4
  var node = this;
5
5
 
6
6
  var flowContext = node.context().flow;
7
- var eventEmitter = flowContext.get('emitter');
8
-
9
- node.on('input', function(msg) {
7
+ var eventEmitter = flowContext.get('emitter');
10
8
 
9
+ node.on('input', function (msg) {
11
10
  const flowNodeInstanceId = msg.flowNodeInstanceId;
12
11
 
13
12
  let msgError = msg.error;
14
13
 
15
14
  if (msgError === undefined) {
16
- msgError.message = "An error occurred";
15
+ msgError.message = 'An error occurred';
17
16
  }
18
17
 
19
18
  const error = new Error(msgError.message);
@@ -24,9 +23,9 @@ module.exports = function(RED) {
24
23
  msg.errorMessage = msgError.message;
25
24
 
26
25
  eventEmitter.emit(`handle-${flowNodeInstanceId}`, error, true);
27
-
26
+
28
27
  node.send(msg);
29
- });
28
+ });
30
29
  }
31
- RED.nodes.registerType("externaltask-error", ExternalTaskError);
32
- }
30
+ RED.nodes.registerType('externaltask-error', ExternalTaskError);
31
+ };
@@ -1,53 +1,53 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('externaltask-input',{
2
+ RED.nodes.registerType('externaltask-input', {
3
3
  category: 'ProcessCube',
4
4
  color: '#02AFD6',
5
5
  defaults: {
6
- name: {value: ""},
7
- engine: {value: "", type: "processcube-engine-config"},
8
- topic: {value: ""}
6
+ name: { value: '' },
7
+ engine: { value: '', type: 'processcube-engine-config' },
8
+ topic: { value: '' },
9
9
  },
10
10
  inputs: 0,
11
11
  outputs: 1,
12
- icon: "font-awesome/fa-envelope-open",
13
- label: function() {
14
- return this.name||"externaltask-input";
15
- }
12
+ icon: 'font-awesome/fa-envelope-open',
13
+ label: function () {
14
+ return this.name || 'externaltask-input';
15
+ },
16
16
  });
17
17
  </script>
18
18
 
19
19
  <script type="text/html" data-template-name="externaltask-input">
20
20
  <div class="form-row">
21
21
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
22
- <input type="text" id="node-input-name" placeholder="Name">
22
+ <input type="text" id="node-input-name" placeholder="Name" />
23
23
  </div>
24
24
  <div class="form-row">
25
25
  <label for="node-input-engine"><i class="fa fa-tag"></i> Engine</label>
26
- <input type="text" id="node-input-engine" placeholder="Engine">
26
+ <input type="text" id="node-input-engine" placeholder="Engine" />
27
27
  </div>
28
28
  <div class="form-row">
29
29
  <label for="node-input-topic"><i class="fa fa-tag"></i> Topic</label>
30
- <input type="text" id="node-input-topic" placeholder="Topic of ExternalTask">
30
+ <input type="text" id="node-input-topic" placeholder="Topic of ExternalTask" />
31
31
  </div>
32
32
  </script>
33
33
 
34
34
  <script type="text/markdown" data-help-name="externaltask-input">
35
- Waiting for external tasks that correspond to the `Topic` configured in
36
- the connected ProcessCube Engine for processing.
35
+ Waiting for external tasks that correspond to the `Topic` configured in
36
+ the connected ProcessCube Engine for processing.
37
37
 
38
- ## Outputs
38
+ ## Outputs
39
39
 
40
- : payload (string) : Defines the input of the external task token
41
- : task (object) : The external task object
42
- : flowNodeInstanceId : The Id of the external task, which is needed to complete the task
40
+ : payload (string) : Defines the input of the external task token
41
+ : task (object) : The external task object
42
+ : flowNodeInstanceId : The Id of the external task, which is needed to complete the task
43
43
 
44
- ### Details
44
+ ### Details
45
45
 
46
- - To finish the external task the `externaltask-output` node is required.
47
- - For handling a error while executing a flow as external task the `externaltask-error` node is required.
46
+ - To finish the external task the `externaltask-output` node is required.
47
+ - For handling a error while executing a flow as external task the `externaltask-error` node is required.
48
48
 
49
- ### References
49
+ ### References
50
50
 
51
- - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; Plattform
52
- - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED Integration in ProcessCube&copy;
53
- </script>
51
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; Plattform
52
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED Integration in ProcessCube&copy;
53
+ </script>
@@ -2,20 +2,20 @@ const EventEmitter = require('node:events');
2
2
 
3
3
  function showStatus(node, msgCounter) {
4
4
  if (msgCounter >= 1) {
5
- node.status({fill: "blue", shape: "dot", text: `handling tasks ${msgCounter}.`});
5
+ node.status({ fill: 'blue', shape: 'dot', text: `handling tasks ${msgCounter}.` });
6
6
  } else {
7
- node.status({fill: "blue", shape: "ring", text: `subcribed.`});
7
+ node.status({ fill: 'blue', shape: 'ring', text: `subcribed.` });
8
8
  }
9
9
  }
10
10
 
11
11
  const started_external_tasks = {};
12
12
 
13
- module.exports = function(RED) {
13
+ module.exports = function (RED) {
14
14
  function ExternalTaskInput(config) {
15
- RED.nodes.createNode(this,config);
15
+ RED.nodes.createNode(this, config);
16
16
  var node = this;
17
17
  var flowContext = node.context().flow;
18
-
18
+
19
19
  this.engine = this.server = RED.nodes.getNode(config.engine);
20
20
 
21
21
  const client = this.engine.getEngineClient();
@@ -27,10 +27,8 @@ module.exports = function(RED) {
27
27
  eventEmitter = flowContext.get('emitter');
28
28
  }
29
29
 
30
- client.externalTasks.subscribeToExternalTaskTopic(
31
- config.topic,
32
- async (payload, externalTask) => {
33
-
30
+ client.externalTasks
31
+ .subscribeToExternalTaskTopic(config.topic, async (payload, externalTask) => {
34
32
  const saveHandleCallback = (data, callback) => {
35
33
  try {
36
34
  callback(data);
@@ -38,13 +36,14 @@ module.exports = function(RED) {
38
36
  node.error(`Error in callback 'saveHandleCallback': ${error.message}`);
39
37
  }
40
38
  };
41
-
42
- return await new Promise((resolve, reject) => {
43
39
 
40
+ return await new Promise((resolve, reject) => {
44
41
  const handleFinishTask = (msg) => {
45
42
  let result = RED.util.encodeObject(msg.payload);
46
43
 
47
- node.log(`handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* ${externalTask.processInstanceId} with result ${result} on msg._msgid ${msg._msgid}.`);
44
+ node.log(
45
+ `handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* ${externalTask.processInstanceId} with result ${result} on msg._msgid ${msg._msgid}.`,
46
+ );
48
47
 
49
48
  if (externalTask.flowNodeInstanceId) {
50
49
  delete started_external_tasks[externalTask.flowNodeInstanceId];
@@ -52,14 +51,14 @@ module.exports = function(RED) {
52
51
 
53
52
  showStatus(node, Object.keys(started_external_tasks).length);
54
53
 
55
-
56
54
  //resolve(result);
57
- saveHandleCallback(result, resolve)
55
+ saveHandleCallback(result, resolve);
58
56
  };
59
57
 
60
58
  const handleErrorTask = (msg) => {
61
-
62
- node.log(`handle error event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' on *msg._msgid* '${msg._msgid}'.`);
59
+ node.log(
60
+ `handle error event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' on *msg._msgid* '${msg._msgid}'.`,
61
+ );
63
62
 
64
63
  if (externalTask.flowNodeInstanceId) {
65
64
  delete started_external_tasks[externalTask.flowNodeInstanceId];
@@ -67,8 +66,7 @@ module.exports = function(RED) {
67
66
 
68
67
  showStatus(node, Object.keys(started_external_tasks).length);
69
68
 
70
-
71
- // TODO: with reject, the default error handling is proceed
69
+ // TODO: with reject, the default error handling is proceed
72
70
  // SEE: https://github.com/5minds/ProcessCube.Engine.Client.ts/blob/develop/src/ExternalTaskWorker.ts#L180
73
71
  // reject(result);
74
72
  //resolve(msg);
@@ -76,7 +74,9 @@ module.exports = function(RED) {
76
74
  };
77
75
 
78
76
  eventEmitter.once(`handle-${externalTask.flowNodeInstanceId}`, (msg, isError = false) => {
79
- node.log(`handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}' and *isError* '${isError}'`);
77
+ node.log(
78
+ `handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}' and *isError* '${isError}'`,
79
+ );
80
80
 
81
81
  if (isError) {
82
82
  handleErrorTask(msg);
@@ -93,21 +93,23 @@ module.exports = function(RED) {
93
93
  _msgid: RED.util.generateId(),
94
94
  task: RED.util.encodeObject(externalTask),
95
95
  payload: payload,
96
- flowNodeInstanceId: externalTask.flowNodeInstanceId
96
+ flowNodeInstanceId: externalTask.flowNodeInstanceId,
97
97
  };
98
-
99
- node.log(`Received *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}'`);
100
-
98
+
99
+ node.log(
100
+ `Received *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}'`,
101
+ );
102
+
101
103
  node.send(msg);
102
104
  });
103
- },
104
- ).then(async externalTaskWorker => {
105
- node.status({fill: "blue", shape: "ring", text: "subcribed"});
105
+ })
106
+ .then(async (externalTaskWorker) => {
107
+ node.status({ fill: 'blue', shape: 'ring', text: 'subcribed' });
106
108
 
107
109
  externalTaskWorker.identity = node.server.identity;
108
110
  node.server.registerOnIdentityChanged((identity) => {
109
111
  externalTaskWorker.identity = identity;
110
- });
112
+ });
111
113
 
112
114
  // export type WorkerErrorHandler = (errorType: 'fetchAndLock' | 'extendLock' | 'processExternalTask' | 'finishExternalTask', error: Error, externalTask?: ExternalTask<any>) => void;
113
115
  externalTaskWorker.onWorkerError((errorType, error, externalTask) => {
@@ -115,8 +117,10 @@ module.exports = function(RED) {
115
117
  case 'extendLock':
116
118
  case 'finishExternalTask':
117
119
  case 'processExternalTask':
118
- node.error(`Worker error ${errorType} for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}': ${error.message}`);
119
-
120
+ node.error(
121
+ `Worker error ${errorType} for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}': ${error.message}`,
122
+ );
123
+
120
124
  if (externalTask) {
121
125
  delete started_external_tasks[externalTask.flowNodeInstanceId];
122
126
  }
@@ -135,18 +139,18 @@ module.exports = function(RED) {
135
139
  node.error(`Worker start 'externalTaskWorker.start' failed: ${error.message}`);
136
140
  }
137
141
 
138
- node.on("close", () => {
142
+ node.on('close', () => {
139
143
  try {
140
144
  externalTaskWorker.stop();
141
145
  } catch {
142
146
  node.error('Client close failed');
143
147
  }
144
148
  });
145
- }
146
- ).catch((error) => {
147
- node.error(`Error in subscribeToExternalTaskTopic: ${error.message}`);
148
- });
149
+ })
150
+ .catch((error) => {
151
+ node.error(`Error in subscribeToExternalTaskTopic: ${error.message}`);
152
+ });
149
153
  }
150
154
 
151
- RED.nodes.registerType("externaltask-input", ExternalTaskInput);
152
- }
155
+ RED.nodes.registerType('externaltask-input', ExternalTaskInput);
156
+ };
@@ -1,36 +1,36 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('externaltask-output',{
2
+ RED.nodes.registerType('externaltask-output', {
3
3
  category: 'ProcessCube',
4
4
  color: '#02AFD6',
5
5
  defaults: {
6
- name: {value:""}
6
+ name: { value: '' },
7
7
  },
8
8
  inputs: 1,
9
9
  outputs: 0,
10
- icon: "font-awesome/fa-envelope",
11
- label: function() {
12
- return this.name||"externaltask-output";
13
- }
10
+ icon: 'font-awesome/fa-envelope',
11
+ label: function () {
12
+ return this.name || 'externaltask-output';
13
+ },
14
14
  });
15
15
  </script>
16
16
 
17
17
  <script type="text/html" data-template-name="externaltask-output">
18
18
  <div class="form-row">
19
19
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
20
- <input type="text" id="node-input-name" placeholder="Name">
20
+ <input type="text" id="node-input-name" placeholder="Name" />
21
21
  </div>
22
22
  </script>
23
23
 
24
24
  <script type="text/markdown" data-help-name="externaltask-output">
25
- Used to complete the external task. The `msg.payload` is returned to the ProcessCube
26
- engine as the result of the external task.
25
+ Used to complete the external task. The `msg.payload` is returned to the ProcessCube
26
+ engine as the result of the external task.
27
27
 
28
- ## Inputs
28
+ ## Inputs
29
29
 
30
- : payload (Object) : Returned to the ProcessCube engine as the result of the external task
30
+ : payload (Object) : Returned to the ProcessCube engine as the result of the external task
31
31
 
32
- ### References
32
+ ### References
33
33
 
34
- - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
35
- - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
36
- </script>
34
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
35
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
36
+ </script>
@@ -1,21 +1,20 @@
1
- module.exports = function(RED) {
1
+ module.exports = function (RED) {
2
2
  function ExternalTaskOutput(config) {
3
- RED.nodes.createNode(this,config);
3
+ RED.nodes.createNode(this, config);
4
4
  var node = this;
5
5
 
6
6
  var flowContext = node.context().flow;
7
7
  var eventEmitter = flowContext.get('emitter');
8
8
 
9
- node.on('input', function(msg) {
10
-
9
+ node.on('input', function (msg) {
11
10
  const flowNodeInstanceId = msg.flowNodeInstanceId;
12
11
 
13
12
  if (!flowNodeInstanceId) {
14
- node.error('Error: The message did not contain the required external task id.', msg);
15
- }
13
+ node.error('Error: The message did not contain the required external task id.', msg);
14
+ }
16
15
 
17
16
  eventEmitter.emit(`handle-${flowNodeInstanceId}`, msg, false);
18
- });
17
+ });
19
18
  }
20
- RED.nodes.registerType("externaltask-output", ExternalTaskOutput);
21
- }
19
+ RED.nodes.registerType('externaltask-output', ExternalTaskOutput);
20
+ };
@@ -1,41 +1,41 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('message-event-trigger',{
2
+ RED.nodes.registerType('message-event-trigger', {
3
3
  category: 'ProcessCube',
4
4
  color: '#02AFD6',
5
5
  defaults: {
6
- name: {value: ""},
7
- engine: {value: "", type: "processcube-engine-config"},
8
- messagename: {value: "", required: true},
9
- processInstanceId: {value:""}
6
+ name: { value: '' },
7
+ engine: { value: '', type: 'processcube-engine-config' },
8
+ messagename: { value: '', required: true },
9
+ processInstanceId: { value: '' },
10
10
  },
11
11
  inputs: 1,
12
12
  outputs: 1,
13
- icon: "font-awesome/fa-envelope-open",
14
- label: function() {
15
- return this.name||"message-event-trigger";
16
- }
13
+ icon: 'font-awesome/fa-envelope-open',
14
+ label: function () {
15
+ return this.name || 'message-event-trigger';
16
+ },
17
17
  });
18
18
  </script>
19
19
 
20
20
  <script type="text/html" data-template-name="message-event-trigger">
21
21
  <div class="form-row">
22
22
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
- <input type="text" id="node-input-name" placeholder="Name">
23
+ <input type="text" id="node-input-name" placeholder="Name" />
24
24
  </div>
25
25
  <div class="form-row">
26
26
  <label for="node-input-engine"><i class="fa fa-tag"></i> Engine</label>
27
- <input type="text" id="node-input-engine" placeholder="Engine">
27
+ <input type="text" id="node-input-engine" placeholder="Engine" />
28
28
  </div>
29
29
  <div class="form-row">
30
30
  <label for="node-input-messagename"><i class="fa fa-tag"></i> Message Name</label>
31
- <input type="text" id="node-input-messagename" placeholder="Name of the Message-Event">
31
+ <input type="text" id="node-input-messagename" placeholder="Name of the Message-Event" />
32
32
  </div>
33
33
  <div class="form-row">
34
34
  <label for="node-input-processinstanceid"><i class="fa fa-tag"></i> Process Instance Id</label>
35
- <input type="text" id="node-input-processinstanceid" placeholder="Id of the recipient process instance">
35
+ <input type="text" id="node-input-processinstanceid" placeholder="Id of the recipient process instance" />
36
36
  </div>
37
37
  </script>
38
38
 
39
39
  <script type="text/html" data-help-name="externaltask-input">
40
40
  <p>A node which emmits an message event to the Engine.</p>
41
- </script>
41
+ </script>
@@ -1,6 +1,6 @@
1
- const process = require("process");
1
+ const process = require('process');
2
2
 
3
- const engine_client = require("@5minds/processcube_engine_client");
3
+ const engine_client = require('@5minds/processcube_engine_client');
4
4
 
5
5
  module.exports = function (RED) {
6
6
  function MessageEventTrigger(config) {
@@ -11,7 +11,7 @@ module.exports = function (RED) {
11
11
 
12
12
  const client = this.engine.getEngineClient();
13
13
 
14
- node.on("input", function (msg) {
14
+ node.on('input', function (msg) {
15
15
  client.events
16
16
  .triggerMessageEvent(config.messagename, {
17
17
  processInstanceId: config.processinstanceid,
@@ -23,8 +23,8 @@ module.exports = function (RED) {
23
23
 
24
24
  node.send(msg);
25
25
  node.status({
26
- fill: "blue",
27
- shape: "dot",
26
+ fill: 'blue',
27
+ shape: 'dot',
28
28
  text: `message event triggered`,
29
29
  });
30
30
  })
@@ -33,5 +33,5 @@ module.exports = function (RED) {
33
33
  });
34
34
  });
35
35
  }
36
- RED.nodes.registerType("message-event-trigger", MessageEventTrigger);
36
+ RED.nodes.registerType('message-event-trigger', MessageEventTrigger);
37
37
  };