@5minds/node-red-contrib-processcube 1.5.2-feature-95789a-m3625uau → 1.5.2-feature-4b06ce-m3644zlp

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.5.2-feature-95789a-m3625uau",
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,13 +34,15 @@ 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) ||
43
41
  !RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node)
44
- )
42
+ ) {
45
43
  return null;
44
+ }
45
+
46
46
  const res = await fetch(url + '/atlas_engine/api/v1/authority', {
47
47
  method: 'GET',
48
48
  headers: {
@@ -51,7 +51,9 @@ module.exports = function (RED) {
51
51
  },
52
52
  });
53
53
 
54
- const issuer = await oidc.Issuer.discover(await res.json());
54
+ const body = await res.json();
55
+
56
+ const issuer = await oidc.Issuer.discover(body);
55
57
 
56
58
  const client = new issuer.Client({
57
59
  client_id: RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node),
@@ -71,9 +73,7 @@ module.exports = function (RED) {
71
73
  userId: decodedToken.sub,
72
74
  };
73
75
 
74
- console.log('luis777', freshIdentity);
75
-
76
- configNode.setIdentity(freshIdentity);
76
+ node.setIdentity(freshIdentity);
77
77
 
78
78
  return freshIdentity;
79
79
  } catch (e) {
@@ -91,25 +91,7 @@ module.exports = function (RED) {
91
91
  });
92
92
 
93
93
  if (this.credentials.clientId && this.credentials.clientSecret) {
94
- this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url));
95
-
96
- // this.engineClient.applicationInfo
97
- // .getAuthorityAddress()
98
- // .then((authorityUrl) => {
99
- // startRefreshingIdentityCycle(
100
- // this.credentials.clientId,
101
- // this.credentials.clientSecret,
102
- // authorityUrl,
103
- // node
104
- // ).catch((reason) => {
105
- // console.error(reason);
106
- // node.error(reason);
107
- // });
108
- // })
109
- // .catch((reason) => {
110
- // console.error(reason);
111
- // node.error(reason);
112
- // });
94
+ this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url, node));
113
95
  } else {
114
96
  this.engineClient = new engine_client.EngineClient(this.url);
115
97
  }
@@ -121,85 +103,3 @@ module.exports = function (RED) {
121
103
  },
122
104
  });
123
105
  };
124
-
125
- // async function getFreshTokenSet(clientId, clientSecret, authorityUrl) {
126
- // const issuer = await oidc.Issuer.discover(authorityUrl);
127
-
128
- // const client = new issuer.Client({
129
- // client_id: clientId,
130
- // client_secret: clientSecret,
131
- // });
132
-
133
- // const tokenSet = await client.grant({
134
- // grant_type: 'client_credentials',
135
- // scope: 'engine_etw engine_read engine_write',
136
- // });
137
-
138
- // return tokenSet;
139
- // }
140
-
141
- // function getIdentityForExternalTaskWorkers(tokenSet) {
142
- // const accessToken = tokenSet.access_token;
143
- // const decodedToken = jwt.jwtDecode(accessToken);
144
-
145
- // return {
146
- // token: tokenSet.access_token,
147
- // userId: decodedToken.sub,
148
- // };
149
- // }
150
-
151
- // async function getExpiresInForExternalTaskWorkers(tokenSet) {
152
- // let expiresIn = tokenSet.expires_in;
153
-
154
- // if (!expiresIn && tokenSet.expires_at) {
155
- // expiresIn = Math.floor(tokenSet.expires_at - Date.now() / 1000);
156
- // }
157
-
158
- // if (expiresIn === undefined) {
159
- // throw new Error('Could not determine the time until the access token for external task workers expires');
160
- // }
161
-
162
- // return expiresIn;
163
- // }
164
-
165
- // /**
166
- // * Start refreshing the identity in regular intervals.
167
- // * @param {TokenSet | null} tokenSet The token set to refresh the identity for
168
- // * @returns {Promise<void>} A promise that resolves when the timer for refreshing the identity is initialized
169
- // * */
170
- // async function startRefreshingIdentityCycle(clientId, clientSecret, authorityUrl, configNode) {
171
- // let retries = 5;
172
-
173
- // const refresh = async () => {
174
- // try {
175
- // const newTokenSet = await getFreshTokenSet(clientId, clientSecret, authorityUrl);
176
- // const expiresIn = await getExpiresInForExternalTaskWorkers(newTokenSet);
177
- // const delay = expiresIn * DELAY_FACTOR * 1000;
178
-
179
- // freshIdentity = getIdentityForExternalTaskWorkers(newTokenSet);
180
-
181
- // configNode.setIdentity(freshIdentity);
182
-
183
- // retries = 5;
184
- // setTimeout(refresh, delay);
185
- // } catch (error) {
186
- // if (retries === 0) {
187
- // console.error(
188
- // 'Could not refresh identity for external task worker processes. Stopping all external task workers.',
189
- // { error }
190
- // );
191
- // return;
192
- // }
193
- // console.error('Could not refresh identity for external task worker processes.', {
194
- // error,
195
- // retryCount: retries,
196
- // });
197
- // retries--;
198
-
199
- // const delay = 2 * 1000;
200
- // setTimeout(refresh, delay);
201
- // }
202
- // };
203
-
204
- // await refresh();
205
- // }