@5minds/node-red-contrib-processcube 1.5.2-feature-bdcb95-m362ojnw → 1.5.2-feature-4b06ce-m3644zlp

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-bdcb95-m362ojnw",
3
+ "version": "1.5.2-feature-4b06ce-m3644zlp",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -2,8 +2,6 @@ const engine_client = require('@5minds/processcube_engine_client');
2
2
  const jwt = require('jwt-decode');
3
3
  const oidc = require('openid-client');
4
4
 
5
- const DELAY_FACTOR = 0.85;
6
-
7
5
  module.exports = function (RED) {
8
6
  function ProcessCubeEngineNode(n) {
9
7
  RED.nodes.createNode(this, n);
@@ -36,7 +34,7 @@ module.exports = function (RED) {
36
34
  }
37
35
  };
38
36
 
39
- async function getFreshIdentity(url) {
37
+ async function getFreshIdentity(url, node) {
40
38
  try {
41
39
  if (
42
40
  !RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node) ||
@@ -45,9 +43,6 @@ module.exports = function (RED) {
45
43
  return null;
46
44
  }
47
45
 
48
- node.log(RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node));
49
- node.log(RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node));
50
-
51
46
  const res = await fetch(url + '/atlas_engine/api/v1/authority', {
52
47
  method: 'GET',
53
48
  headers: {
@@ -56,24 +51,20 @@ module.exports = function (RED) {
56
51
  },
57
52
  });
58
53
 
59
- const issuer = await oidc.Issuer.discover(await res.json());
54
+ const body = await res.json();
60
55
 
61
- node.log('after issuer');
56
+ const issuer = await oidc.Issuer.discover(body);
62
57
 
63
58
  const client = new issuer.Client({
64
59
  client_id: RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node),
65
60
  client_secret: RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node),
66
61
  });
67
62
 
68
- node.log('after client');
69
-
70
63
  const tokenSet = await client.grant({
71
64
  grant_type: 'client_credentials',
72
65
  scope: 'engine_etw engine_read engine_write',
73
66
  });
74
67
 
75
- node.log('after grant');
76
-
77
68
  const accessToken = tokenSet.access_token;
78
69
  const decodedToken = jwt.jwtDecode(accessToken);
79
70
 
@@ -82,9 +73,7 @@ module.exports = function (RED) {
82
73
  userId: decodedToken.sub,
83
74
  };
84
75
 
85
- console.log('luis777', freshIdentity);
86
-
87
- configNode.setIdentity(freshIdentity);
76
+ node.setIdentity(freshIdentity);
88
77
 
89
78
  return freshIdentity;
90
79
  } catch (e) {
@@ -102,25 +91,7 @@ module.exports = function (RED) {
102
91
  });
103
92
 
104
93
  if (this.credentials.clientId && this.credentials.clientSecret) {
105
- this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url));
106
-
107
- // this.engineClient.applicationInfo
108
- // .getAuthorityAddress()
109
- // .then((authorityUrl) => {
110
- // startRefreshingIdentityCycle(
111
- // this.credentials.clientId,
112
- // this.credentials.clientSecret,
113
- // authorityUrl,
114
- // node
115
- // ).catch((reason) => {
116
- // console.error(reason);
117
- // node.error(reason);
118
- // });
119
- // })
120
- // .catch((reason) => {
121
- // console.error(reason);
122
- // node.error(reason);
123
- // });
94
+ this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url, node));
124
95
  } else {
125
96
  this.engineClient = new engine_client.EngineClient(this.url);
126
97
  }
@@ -132,85 +103,3 @@ module.exports = function (RED) {
132
103
  },
133
104
  });
134
105
  };
135
-
136
- // async function getFreshTokenSet(clientId, clientSecret, authorityUrl) {
137
- // const issuer = await oidc.Issuer.discover(authorityUrl);
138
-
139
- // const client = new issuer.Client({
140
- // client_id: clientId,
141
- // client_secret: clientSecret,
142
- // });
143
-
144
- // const tokenSet = await client.grant({
145
- // grant_type: 'client_credentials',
146
- // scope: 'engine_etw engine_read engine_write',
147
- // });
148
-
149
- // return tokenSet;
150
- // }
151
-
152
- // function getIdentityForExternalTaskWorkers(tokenSet) {
153
- // const accessToken = tokenSet.access_token;
154
- // const decodedToken = jwt.jwtDecode(accessToken);
155
-
156
- // return {
157
- // token: tokenSet.access_token,
158
- // userId: decodedToken.sub,
159
- // };
160
- // }
161
-
162
- // async function getExpiresInForExternalTaskWorkers(tokenSet) {
163
- // let expiresIn = tokenSet.expires_in;
164
-
165
- // if (!expiresIn && tokenSet.expires_at) {
166
- // expiresIn = Math.floor(tokenSet.expires_at - Date.now() / 1000);
167
- // }
168
-
169
- // if (expiresIn === undefined) {
170
- // throw new Error('Could not determine the time until the access token for external task workers expires');
171
- // }
172
-
173
- // return expiresIn;
174
- // }
175
-
176
- // /**
177
- // * Start refreshing the identity in regular intervals.
178
- // * @param {TokenSet | null} tokenSet The token set to refresh the identity for
179
- // * @returns {Promise<void>} A promise that resolves when the timer for refreshing the identity is initialized
180
- // * */
181
- // async function startRefreshingIdentityCycle(clientId, clientSecret, authorityUrl, configNode) {
182
- // let retries = 5;
183
-
184
- // const refresh = async () => {
185
- // try {
186
- // const newTokenSet = await getFreshTokenSet(clientId, clientSecret, authorityUrl);
187
- // const expiresIn = await getExpiresInForExternalTaskWorkers(newTokenSet);
188
- // const delay = expiresIn * DELAY_FACTOR * 1000;
189
-
190
- // freshIdentity = getIdentityForExternalTaskWorkers(newTokenSet);
191
-
192
- // configNode.setIdentity(freshIdentity);
193
-
194
- // retries = 5;
195
- // setTimeout(refresh, delay);
196
- // } catch (error) {
197
- // if (retries === 0) {
198
- // console.error(
199
- // 'Could not refresh identity for external task worker processes. Stopping all external task workers.',
200
- // { error }
201
- // );
202
- // return;
203
- // }
204
- // console.error('Could not refresh identity for external task worker processes.', {
205
- // error,
206
- // retryCount: retries,
207
- // });
208
- // retries--;
209
-
210
- // const delay = 2 * 1000;
211
- // setTimeout(refresh, delay);
212
- // }
213
- // };
214
-
215
- // await refresh();
216
- // }