@5minds/node-red-contrib-processcube 1.5.11-develop-0a7a7c-m4r8trh2 → 1.5.11-feature-e8accd-m4sa259r

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/process-start.js CHANGED
@@ -22,8 +22,8 @@ module.exports = function (RED) {
22
22
  return;
23
23
  }
24
24
 
25
- const engine = RED.nodes.getNode(config.engine);
26
- const client = engine.engineClient;
25
+ node.engine = RED.nodes.getNode(config.engine);
26
+ const client = node.engine.engineClient;
27
27
 
28
28
  if (!client) {
29
29
  node.error('No engine configured.');
@@ -31,7 +31,7 @@ module.exports = function (RED) {
31
31
  }
32
32
 
33
33
  client.processDefinitions
34
- .startProcessInstance(startParameters, engine.identity)
34
+ .startProcessInstance(startParameters)
35
35
  .then((result) => {
36
36
  msg.payload = result;
37
37
 
@@ -4,8 +4,8 @@ module.exports = function (RED) {
4
4
  var node = this;
5
5
 
6
6
  node.on('input', function (msg) {
7
- const engine = RED.nodes.getNode(config.engine);
8
- const client = engine.engineClient;
7
+ node.engine = RED.nodes.getNode(config.engine);
8
+ const client = node.engine.engineClient;
9
9
 
10
10
  if (!client) {
11
11
  node.error('No engine configured.');
@@ -13,7 +13,7 @@ module.exports = function (RED) {
13
13
  }
14
14
 
15
15
  client.processInstances
16
- .terminateProcessInstance(msg.payload, engine.identity)
16
+ .terminateProcessInstance(msg.payload)
17
17
  .then(() => {
18
18
  node.send(msg);
19
19
  })
@@ -4,7 +4,7 @@
4
4
  defaults: {
5
5
  name: { value: '' },
6
6
  url: { value: 'http://engine:8000', required: true },
7
- urlType: { type: 'str'},
7
+ urlType: { type: 'str' },
8
8
  clientId: { value: '' },
9
9
  clientIdType: { type: 'str' },
10
10
  clientSecret: { value: '' },
@@ -16,17 +16,17 @@
16
16
  oneditprepare: function () {
17
17
  $('#node-config-input-url').typedInput({
18
18
  default: 'str',
19
- types: ['str', 'global', 'flow', 'env', 'msg', 'cred'],
19
+ types: ['str', 'env', 'cred'],
20
20
  });
21
21
 
22
22
  $('#node-config-input-clientId').typedInput({
23
23
  default: 'str',
24
- types: ['str', 'global', 'flow', 'env', 'msg', 'cred'],
24
+ types: ['str', 'env', 'cred'],
25
25
  });
26
26
 
27
27
  $('#node-config-input-clientSecret').typedInput({
28
28
  default: 'str',
29
- types: ['str', 'global', 'flow', 'env', 'msg', 'cred'],
29
+ types: ['str', 'env', 'cred'],
30
30
  });
31
31
 
32
32
  $('#node-config-input-url').typedInput('value', this.url);
@@ -66,7 +66,7 @@
66
66
  </div>
67
67
  <div class="form-row">
68
68
  <label for="node-config-input-clientSecret"><i class="fa fa-bookmark"></i> Client secret</label>
69
- <input type="password" id="node-config-input-clientSecret" />
69
+ <input type="text" id="node-config-input-clientSecret" />
70
70
  </div>
71
71
  </script>
72
72
 
@@ -81,6 +81,6 @@ The configuration for the ProcessCube engine.
81
81
 
82
82
  ### References
83
83
 
84
- - [The ProcessCube&copy; Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
85
- - [ProcessCube&copy; LowCode Integration](https://processcube.io/docs/node-red) - LowCode integration in ProcessCube&copy;
84
+ - [The ProcessCube&copy; Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
85
+ - [ProcessCube&copy; LowCode Integration](https://processcube.io/docs/node-red) - LowCode integration in ProcessCube&copy;
86
86
  </script>
@@ -1,4 +1,3 @@
1
- const EventEmitter = require('node:events');
2
1
  const engine_client = require('@5minds/processcube_engine_client');
3
2
  const jwt = require('jwt-decode');
4
3
  const oidc = require('openid-client');
@@ -7,138 +6,33 @@ module.exports = function (RED) {
7
6
  function ProcessCubeEngineNode(n) {
8
7
  RED.nodes.createNode(this, n);
9
8
  const node = this;
10
- const identityChangedCallbacks = [];
11
- this.identity = null;
12
9
 
13
- this.credentials.clientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
14
- this.credentials.clientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
10
+ node.url = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
11
+ node.credentials.clientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
12
+ node.credentials.clientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
15
13
 
16
- node.eventEmitter = new EventEmitter();
17
-
18
- // set the engine url
19
- const stopRefreshing = periodicallyRefreshEngineClient(this, n, 10000);
20
-
21
- this.registerOnIdentityChanged = function (callback) {
22
- identityChangedCallbacks.push(callback);
23
- };
24
-
25
- this.isIdentityReady = function () {
26
- if (this.credentials.clientId && this.credentials.clientSecret) {
27
- return this.identity != null;
28
- } else {
29
- return true;
30
- }
31
- };
32
-
33
- this.setIdentity = (identity) => {
34
- node.log(`setIdentity: ${JSON.stringify(identity)}`);
35
- this.identity = identity;
36
-
37
- for (const callback of identityChangedCallbacks) {
38
- callback(identity);
39
- }
40
- };
41
-
42
- function periodicallyRefreshEngineClient(node, n, intervalMs) {
43
- function refreshUrl() {
44
- const newUrl = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
45
- const newClientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
46
- const newClientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
47
-
48
- if (
49
- node.url === newUrl &&
50
- node.credentials.clientId === newClientId &&
51
- node.credentials.clientSecret === newClientSecret
52
- ) {
53
- return;
54
- }
55
-
56
- node.url = newUrl;
57
- node.credentials.clientId = newClientId;
58
- node.credentials.clientSecret = newClientSecret;
59
-
60
- if (node.credentials.clientId && node.credentials.clientSecret) {
61
- if (node.engineClient) {
62
- node.eventEmitter.emit('engine-client-dispose');
63
- node.engineClient.dispose();
64
- }
65
- node.engineClient = new engine_client.EngineClient(node.url, () =>
66
- getFreshIdentity(node.url, node)
67
- );
68
-
69
- node.eventEmitter.emit('engine-client-changed');
70
- } else {
71
- if (node.engineClient) {
72
- node.eventEmitter.emit('engine-client-dispose');
73
- node.engineClient.dispose();
74
- }
75
- node.engineClient = new engine_client.EngineClient(node.url);
76
-
77
- node.eventEmitter.emit('engine-client-changed');
78
- }
79
- }
80
-
81
- refreshUrl();
82
- const intervalId = setInterval(refreshUrl, intervalMs);
83
-
84
- return () => clearInterval(intervalId);
85
- }
86
-
87
- async function getFreshIdentity(url, node) {
88
- try {
89
- if (
90
- !RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node) ||
91
- !RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node)
92
- ) {
93
- return null;
94
- }
95
-
96
- const res = await fetch(url + '/atlas_engine/api/v1/authority', {
97
- method: 'GET',
98
- headers: {
99
- Authorization: `Bearer ZHVtbXlfdG9rZW4=`,
100
- 'Content-Type': 'application/json',
101
- },
102
- });
103
-
104
- const body = await res.json();
105
-
106
- const issuer = await oidc.Issuer.discover(body);
107
-
108
- const client = new issuer.Client({
109
- client_id: RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node),
110
- client_secret: RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node),
111
- });
112
-
113
- const tokenSet = await client.grant({
114
- grant_type: 'client_credentials',
14
+ try {
15
+ if (node.credentials.clientId && node.credentials.clientSecret) {
16
+ node.engineClient = new engine_client.EngineClient(node.url, {
17
+ clientId: node.credentials.clientId,
18
+ clientSecret: node.credentials.clientSecret,
115
19
  scope: 'engine_etw engine_read engine_write',
116
20
  });
117
-
118
- const accessToken = tokenSet.access_token;
119
- const decodedToken = jwt.jwtDecode(accessToken);
120
-
121
- const freshIdentity = {
122
- token: tokenSet.access_token,
123
- userId: decodedToken.sub,
124
- };
125
-
126
- node.setIdentity(freshIdentity);
127
-
128
- return freshIdentity;
129
- } catch (e) {
130
- node.error(`Could not get fresh identity: ${JSON.stringify(e)}`);
21
+ } else {
22
+ node.engineClient = new engine_client.EngineClient(node.url);
131
23
  }
24
+ } catch (error) {
25
+ node.error(JSON.stringify(error));
132
26
  }
133
27
 
134
28
  node.on('close', async () => {
135
- if (this.engineClient) {
136
- stopRefreshing();
137
- this.engineClient.dispose();
138
- this.engineClient = null;
29
+ if (node.engineClient) {
30
+ node.engineClient.dispose();
31
+ node.engineClient = null;
139
32
  }
140
33
  });
141
34
  }
35
+
142
36
  RED.nodes.registerType('processcube-engine-config', ProcessCubeEngineNode, {
143
37
  credentials: {
144
38
  clientId: { type: 'text' },
@@ -4,8 +4,7 @@ module.exports = function (RED) {
4
4
  var node = this;
5
5
 
6
6
  node.on('input', function (msg) {
7
-
8
- const engine = RED.nodes.getNode(config.engine);
7
+ node.engine = RED.nodes.getNode(config.engine);
9
8
  const client = engine.engineClient;
10
9
 
11
10
  if (!client) {
@@ -14,37 +13,34 @@ module.exports = function (RED) {
14
13
  }
15
14
 
16
15
  let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
17
-
18
- query = {
19
- ...query,
20
- identity: engine.identity,
21
- };
22
16
 
23
17
  node.log(`Querying process definitions with query: ${JSON.stringify(query)}`);
24
-
25
- client.processDefinitions.getAll(query).then((matchingProcessDefinitions) => {
26
18
 
27
- if (config.models_only && matchingProcessDefinitions.totalCount > 0) {
28
- let models = [];
19
+ client.processDefinitions
20
+ .getAll(query)
21
+ .then((matchingProcessDefinitions) => {
22
+ if (config.models_only && matchingProcessDefinitions.totalCount > 0) {
23
+ let models = [];
29
24
 
30
- matchingProcessDefinitions.processDefinitions.forEach((processDefinition) => {
31
- processDefinition.processModels.forEach((model) => {
32
- models.push(model);
25
+ matchingProcessDefinitions.processDefinitions.forEach((processDefinition) => {
26
+ processDefinition.processModels.forEach((model) => {
27
+ models.push(model);
28
+ });
33
29
  });
34
- });
35
-
36
- msg.payload = {
37
- models: models,
38
- totalCount: models.length,
39
- };
40
- } else {
41
- msg.payload = matchingProcessDefinitions;
42
- }
43
-
44
- node.send(msg);
45
- }).catch((error) => {
46
- node.error(JSON.stringify(error));
47
- });
30
+
31
+ msg.payload = {
32
+ models: models,
33
+ totalCount: models.length,
34
+ };
35
+ } else {
36
+ msg.payload = matchingProcessDefinitions;
37
+ }
38
+
39
+ node.send(msg);
40
+ })
41
+ .catch((error) => {
42
+ node.error(JSON.stringify(error));
43
+ });
48
44
  });
49
45
  }
50
46
  RED.nodes.registerType('processdefinition-query', ProcessdefinitionQuery);
@@ -4,8 +4,8 @@ module.exports = function (RED) {
4
4
  var node = this;
5
5
 
6
6
  node.on('input', async function (msg) {
7
- const engine = RED.nodes.getNode(config.engine);
8
- const client = engine.engineClient;
7
+ node.engine = RED.nodes.getNode(config.engine);
8
+ const client = node.engine.engineClient;
9
9
 
10
10
  if (!client) {
11
11
  node.error('No engine configured.');
@@ -33,7 +33,7 @@ module.exports = function (RED) {
33
33
  try {
34
34
  const result = await client.processInstances.query({
35
35
  processModelId: modelId
36
- }, { identity: engine.identity });
36
+ }, { identity: node.engine.identity });
37
37
 
38
38
  let allInstances = result.processInstances.filter((instance) => instance.state != 'suspended' && instance.state != 'running');
39
39
 
@@ -64,7 +64,6 @@ module.exports = function (RED) {
64
64
  node.warn(`Failed to delete process instances in batch: ${batch.join(', ')}. Error: ${deleteError.message}`);
65
65
  }
66
66
  }
67
-
68
67
  node.send(msg);
69
68
  } catch (queryError) {
70
69
  node.error(`Failed to query process instances: ${queryError.message}`);
@@ -6,8 +6,8 @@ module.exports = function (RED) {
6
6
  node.on('input', function (msg) {
7
7
  let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
8
8
 
9
- const engine = RED.nodes.getNode(config.engine);
10
- const client = engine.engineClient;
9
+ node.engine = RED.nodes.getNode(config.engine);
10
+ const client = node.engine.engineClient;
11
11
 
12
12
  if (!client) {
13
13
  node.error('No engine configured.');
@@ -15,7 +15,7 @@ module.exports = function (RED) {
15
15
  }
16
16
 
17
17
  client.processInstances
18
- .query(query, { identity: engine.identity })
18
+ .query(query)
19
19
  .then((matchingInstances) => {
20
20
  msg.payload = matchingInstances;
21
21
 
@@ -4,20 +4,19 @@ module.exports = function (RED) {
4
4
  var node = this;
5
5
 
6
6
  node.on('input', function (msg) {
7
- const engine = RED.nodes.getNode(config.engine);
7
+ node.engine = RED.nodes.getNode(config.engine);
8
8
 
9
- const client = engine.engineClient;
9
+ const client = node.engine.engineClient;
10
10
 
11
11
  if (!client) {
12
12
  node.error('No engine configured.');
13
13
  return;
14
14
  }
15
-
15
+
16
16
  client.events
17
17
  .triggerSignalEvent(config.signalname, {
18
18
  processInstanceId: msg.processinstanceid,
19
19
  payload: msg.payload,
20
- identity: engine.identity,
21
20
  })
22
21
  .then((result) => {
23
22
  msg.payload = result;
@@ -6,20 +6,7 @@ module.exports = function (RED) {
6
6
 
7
7
  let subscription;
8
8
 
9
- const eventEmitter = node.engine.eventEmitter;
10
-
11
- eventEmitter.on('engine-client-dispose', () => {
12
- node.engine.engineClient.userTasks.removeSubscription(subscription, node.engine.identity);
13
- });
14
-
15
- eventEmitter.on('engine-client-changed', () => {
16
- node.log('new engineClient received');
17
- register();
18
- });
19
-
20
9
  const register = async () => {
21
- let currentIdentity = node.engine.identity;
22
-
23
10
  const client = node.engine.engineClient;
24
11
 
25
12
  if (!client) {
@@ -39,9 +26,7 @@ module.exports = function (RED) {
39
26
  };
40
27
 
41
28
  try {
42
- const matchingFlowNodes = await client.userTasks.query(newQuery, {
43
- identity: currentIdentity,
44
- });
29
+ const matchingFlowNodes = await client.userTasks.query(newQuery);
45
30
 
46
31
  if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
47
32
  const userTask = matchingFlowNodes.userTasks[0];
@@ -65,42 +50,23 @@ module.exports = function (RED) {
65
50
  async function subscribe() {
66
51
  switch (config.eventtype) {
67
52
  case 'new':
68
- return await client.userTasks.onUserTaskWaiting(userTaskCallback(), {
69
- identity: currentIdentity,
70
- });
53
+ return await client.userTasks.onUserTaskWaiting(userTaskCallback());
71
54
  case 'finished':
72
- return await client.userTasks.onUserTaskFinished(userTaskCallback(), {
73
- identity: currentIdentity,
74
- });
55
+ return await client.userTasks.onUserTaskFinished(userTaskCallback());
75
56
  case 'reserved':
76
- return await client.userTasks.onUserTaskReserved(userTaskCallback(), {
77
- identity: currentIdentity,
78
- });
57
+ return await client.userTasks.onUserTaskReserved(userTaskCallback());
79
58
  case 'reservation-canceled':
80
- return await client.userTasks.onUserTaskReservationCanceled(userTaskCallback(), {
81
- identity: currentIdentity,
82
- });
59
+ return await client.userTasks.onUserTaskReservationCanceled(userTaskCallback());
83
60
  default:
84
61
  console.error('no such event: ' + config.eventtype);
85
62
  }
86
63
  }
87
64
 
88
- if (node.engine.isIdentityReady()) {
89
- subscription = subscribe();
90
- }
91
-
92
- node.engine.registerOnIdentityChanged(async (identity) => {
93
- if (subscription) {
94
- client.userTasks.removeSubscription(subscription, currentIdentity);
95
- }
96
- currentIdentity = identity;
97
-
98
- subscription = subscribe();
99
- });
65
+ subscription = subscribe();
100
66
 
101
67
  node.on('close', async () => {
102
68
  if (node.engine && node.engine.engineClient && client) {
103
- client.userTasks.removeSubscription(subscription, currentIdentity);
69
+ client.userTasks.removeSubscription(subscription);
104
70
  }
105
71
  });
106
72
  };
package/usertask-input.js CHANGED
@@ -4,9 +4,9 @@ module.exports = function (RED) {
4
4
  var node = this;
5
5
 
6
6
  node.on('input', function (msg) {
7
- const engine = RED.nodes.getNode(config.engine);
7
+ node.engine = RED.nodes.getNode(config.engine);
8
8
 
9
- const client = engine.engineClient;
9
+ const client = node.engine.engineClient;
10
10
 
11
11
  if (!client) {
12
12
  node.error('No engine configured.');
@@ -15,12 +15,8 @@ module.exports = function (RED) {
15
15
 
16
16
  let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
17
17
 
18
- query = {
19
- ...query,
20
- };
21
-
22
18
  client.userTasks
23
- .query(query, { identity: engine.identity })
19
+ .query(query)
24
20
  .then((matchingFlowNodes) => {
25
21
  if (config.sendtype === 'array') {
26
22
  msg.payload = { userTasks: matchingFlowNodes.userTasks || [] };
@@ -9,17 +9,17 @@ module.exports = function (RED) {
9
9
 
10
10
  const userTaskResult = RED.util.evaluateNodeProperty(config.result, config.result_type, node, msg);
11
11
 
12
- const engine = RED.nodes.getNode(config.engine);
12
+ node.engine = RED.nodes.getNode(config.engine);
13
13
 
14
- const client = engine.engineClient;
14
+ const client = node.engine.engineClient;
15
15
 
16
16
  if (!client) {
17
17
  node.error('No engine configured.');
18
18
  return;
19
19
  }
20
-
20
+
21
21
  client.userTasks
22
- .finishUserTask(flowNodeInstanceId, userTaskResult, engine.identity)
22
+ .finishUserTask(flowNodeInstanceId, userTaskResult)
23
23
  .then(() => {
24
24
  node.send(msg);
25
25
  })
@@ -6,7 +6,6 @@ module.exports = function (RED) {
6
6
  node.engine = RED.nodes.getNode(config.engine);
7
7
 
8
8
  let subscription = null;
9
- let currentIdentity = node.engine.identity;
10
9
  let subscribe = null;
11
10
 
12
11
  node.on('input', async function (msg) {
@@ -19,35 +18,30 @@ module.exports = function (RED) {
19
18
 
20
19
  const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
21
20
 
22
- subscription = await client.userTasks.onUserTaskWaiting(
23
- async (userTaskWaitingNotification) => {
24
- const newQuery = {
25
- flowNodeInstanceId: userTaskWaitingNotification.flowNodeInstanceId,
26
- ...query,
27
- };
28
-
29
- try {
30
- const matchingFlowNodes = await client.userTasks.query(newQuery, {
31
- identity: currentIdentity,
32
- });
33
-
34
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
35
- // remove subscription
36
- client.userTasks.removeSubscription(subscription, currentIdentity);
37
-
38
- const userTask = matchingFlowNodes.userTasks[0];
39
-
40
- msg.payload = { userTask: userTask };
41
- node.send(msg);
42
- } else {
43
- // nothing todo - wait for next notification
44
- }
45
- } catch (error) {
46
- node.error(JSON.stringify(error));
21
+ subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
22
+ const newQuery = {
23
+ flowNodeInstanceId: userTaskWaitingNotification.flowNodeInstanceId,
24
+ ...query,
25
+ };
26
+
27
+ try {
28
+ const matchingFlowNodes = await client.userTasks.query(newQuery);
29
+
30
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
31
+ // remove subscription
32
+ client.userTasks.removeSubscription(subscription);
33
+
34
+ const userTask = matchingFlowNodes.userTasks[0];
35
+
36
+ msg.payload = { userTask: userTask };
37
+ node.send(msg);
38
+ } else {
39
+ // nothing todo - wait for next notification
47
40
  }
48
- },
49
- { identity: currentIdentity }
50
- );
41
+ } catch (error) {
42
+ node.error(JSON.stringify(error));
43
+ }
44
+ });
51
45
 
52
46
  node.log({ 'Handling old userTasks config.only_for_new': config.only_for_new });
53
47
 
@@ -59,9 +53,7 @@ module.exports = function (RED) {
59
53
  };
60
54
 
61
55
  try {
62
- const matchingFlowNodes = await client.userTasks.query(suspendedQuery, {
63
- identity: currentIdentity,
64
- });
56
+ const matchingFlowNodes = await client.userTasks.query(suspendedQuery);
65
57
 
66
58
  if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
67
59
  const userTask = matchingFlowNodes.userTasks[0];
@@ -70,7 +62,7 @@ module.exports = function (RED) {
70
62
  node.send(msg);
71
63
 
72
64
  // remove subscription
73
- client.userTasks.removeSubscription(subscription, currentIdentity);
65
+ client.userTasks.removeSubscription(subscription);
74
66
  } else {
75
67
  // let the *currentIdentity* be active
76
68
  }
@@ -83,19 +75,9 @@ module.exports = function (RED) {
83
75
  subscribe();
84
76
  });
85
77
 
86
- node.engine.registerOnIdentityChanged(async (identity) => {
87
- if (subscription) {
88
- client.userTasks.removeSubscription(subscription, currentIdentity);
89
- currentIdentity = identity;
90
- subscribe();
91
- } else {
92
- currentIdentity = identity;
93
- }
94
- });
95
-
96
78
  node.on('close', async () => {
97
79
  if (client != null && subscription != null) {
98
- client.userTasks.removeSubscription(subscription, currentIdentity);
80
+ client.userTasks.removeSubscription(subscription);
99
81
  }
100
82
  });
101
83
  }