@5minds/node-red-contrib-processcube 1.5.2-feature-4b06ce-m3644zlp → 1.5.2-feature-3ce18d-m3haj4ki

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.5.2-feature-4b06ce-m3644zlp",
3
+ "version": "1.5.2-feature-3ce18d-m3haj4ki",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -7,12 +7,14 @@ module.exports = function (RED) {
7
7
  RED.nodes.createNode(this, n);
8
8
  const node = this;
9
9
  const identityChangedCallbacks = [];
10
- this.url = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
11
10
  this.identity = null;
12
11
 
13
12
  this.credentials.clientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
14
13
  this.credentials.clientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
15
14
 
15
+ // set the engine url
16
+ const stopRefreshing = periodicallyRefreshEngineClient(this, n, 10000);
17
+
16
18
  this.registerOnIdentityChanged = function (callback) {
17
19
  identityChangedCallbacks.push(callback);
18
20
  };
@@ -34,6 +36,32 @@ module.exports = function (RED) {
34
36
  }
35
37
  };
36
38
 
39
+ function periodicallyRefreshEngineClient(node, n, intervalMs) {
40
+ function refreshUrl() {
41
+ const newUrl = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
42
+
43
+ if (node.url == newUrl) {
44
+ return;
45
+ }
46
+
47
+ node.url = newUrl;
48
+ if (node.credentials.clientId && node.credentials.clientSecret) {
49
+ this.engineClient.dispose();
50
+ node.engineClient = new engine_client.EngineClient(node.url, () =>
51
+ getFreshIdentity(node.url, node)
52
+ );
53
+ } else {
54
+ this.engineClient.dispose();
55
+ node.engineClient = new engine_client.EngineClient(node.url);
56
+ }
57
+ }
58
+
59
+ refreshUrl();
60
+ const intervalId = setInterval(refreshUrl, intervalMs);
61
+
62
+ return () => clearInterval(intervalId);
63
+ }
64
+
37
65
  async function getFreshIdentity(url, node) {
38
66
  try {
39
67
  if (
@@ -77,24 +105,17 @@ module.exports = function (RED) {
77
105
 
78
106
  return freshIdentity;
79
107
  } catch (e) {
80
- console.log('Could not get fresh identity', e);
81
- node.error('Could not get fresh identity');
82
- node.error(e);
108
+ node.error(`Could not get fresh identity: ${e}`);
83
109
  }
84
110
  }
85
111
 
86
112
  node.on('close', async () => {
87
113
  if (this.engineClient) {
114
+ stopRefreshing();
88
115
  this.engineClient.dispose();
89
116
  this.engineClient = null;
90
117
  }
91
118
  });
92
-
93
- if (this.credentials.clientId && this.credentials.clientSecret) {
94
- this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url, node));
95
- } else {
96
- this.engineClient = new engine_client.EngineClient(this.url);
97
- }
98
119
  }
99
120
  RED.nodes.registerType('processcube-engine-config', ProcessCubeEngineNode, {
100
121
  credentials: {