@aloma.io/integration-sdk 3.3.57 → 3.3.59

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.
@@ -147,6 +147,12 @@ class OAuthFetcher extends Fetcher {
147
147
  }, 500);
148
148
  });
149
149
  }
150
+ async periodicRefresh() {
151
+ const local = this, oauth = local.oauth;
152
+ if (!oauth.refreshToken())
153
+ return;
154
+ await local.getToken(true);
155
+ }
150
156
  async customize(options, args = {}) {
151
157
  const local = this;
152
158
  const token = await local.getToken(args.forceTokenRefresh);
@@ -162,7 +168,7 @@ class OAuth {
162
168
  this._data = data || {};
163
169
  this.saveOAuthResult = saveOAuthResult;
164
170
  this.obtainViaRefreshToken = getRefreshToken;
165
- this.clients = {};
171
+ this.clients = [];
166
172
  }
167
173
  data() {
168
174
  return this._data;
@@ -180,8 +186,18 @@ class OAuth {
180
186
  }
181
187
  await this.saveOAuthResult(this._data);
182
188
  }
189
+ async periodicRefresh() {
190
+ const clients = this.clients;
191
+ console.log('refreshing oauth clients', clients.length);
192
+ for (let i = 0; i < clients.length; ++i) {
193
+ const client = clients[0];
194
+ await client.periodicRefresh();
195
+ }
196
+ }
183
197
  getClient(arg = {}) {
184
- return new OAuthFetcher({ ...arg, oauth: this });
198
+ const client = new OAuthFetcher({ ...arg, oauth: this });
199
+ this.clients.push(client);
200
+ return client;
185
201
  }
186
202
  }
187
203
  class Connector {
@@ -444,7 +460,6 @@ ${text}
444
460
  const theOAuth = decrypted.oauthResult
445
461
  ? new OAuth(decrypted.oauthResult, saveOAuthResult, getRefreshToken)
446
462
  : null;
447
- console.log('restarting');
448
463
  if (theOAuth) {
449
464
  clearInterval(this._refreshOAuthToken);
450
465
  if (!(this._oauth.noPeriodicTokenRefresh === false)) {
@@ -453,9 +468,9 @@ ${text}
453
468
  await theOAuth.periodicRefresh();
454
469
  }
455
470
  catch (e) {
456
- //console.log('periodic refresh', e);
471
+ console.log('periodic refresh', e);
457
472
  }
458
- }, /*4 * 60 * 60 **/ 1000);
473
+ }, 4 * 60 * 60 * 15000);
459
474
  }
460
475
  }
461
476
  start({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloma.io/integration-sdk",
3
- "version": "3.3.57",
3
+ "version": "3.3.59",
4
4
  "description": "",
5
5
  "author": "aloma.io",
6
6
  "license": "Apache-2.0",
@@ -188,6 +188,13 @@ class OAuthFetcher extends Fetcher {
188
188
  });
189
189
  }
190
190
 
191
+ async periodicRefresh() {
192
+ const local = this, oauth = local.oauth;
193
+ if (!oauth.refreshToken()) return;
194
+
195
+ await local.getToken(true);
196
+ }
197
+
191
198
  async customize(options, args = {}) {
192
199
  const local = this;
193
200
  const token = await local.getToken(args.forceTokenRefresh);
@@ -205,7 +212,7 @@ class OAuth {
205
212
  this._data = data || {};
206
213
  this.saveOAuthResult = saveOAuthResult;
207
214
  this.obtainViaRefreshToken = getRefreshToken;
208
- this.clients = {};
215
+ this.clients = [];
209
216
  }
210
217
 
211
218
  data() {
@@ -230,8 +237,22 @@ class OAuth {
230
237
  await this.saveOAuthResult(this._data);
231
238
  }
232
239
 
240
+ async periodicRefresh() {
241
+ const clients = this.clients;
242
+
243
+ console.log('refreshing oauth clients', clients.length)
244
+
245
+ for (let i = 0; i < clients.length; ++i) {
246
+ const client = clients[0];
247
+
248
+ await client.periodicRefresh();
249
+ }
250
+ }
251
+
233
252
  getClient(arg = {}) {
234
- return new OAuthFetcher({ ...arg, oauth: this });
253
+ const client = new OAuthFetcher({ ...arg, oauth: this });
254
+ this.clients.push(client);
255
+ return client;
235
256
  }
236
257
  }
237
258
 
@@ -548,19 +569,19 @@ ${text}
548
569
  ? new OAuth(decrypted.oauthResult, saveOAuthResult, getRefreshToken)
549
570
  : null;
550
571
 
551
- console.log('restarting')
552
572
  if (theOAuth) {
553
573
  clearInterval(this._refreshOAuthToken);
554
574
 
555
575
  if (!(this._oauth.noPeriodicTokenRefresh === false)) {
556
576
  this._refreshOAuthToken = setInterval(async () => {
577
+
557
578
  try
558
579
  {
559
580
  await theOAuth.periodicRefresh();
560
581
  } catch(e) {
561
- //console.log('periodic refresh', e);
582
+ console.log('periodic refresh', e);
562
583
  }
563
- }, /*4 * 60 * 60 **/ 1000);
584
+ }, 4 * 60 * 60 * 15000);
564
585
  }
565
586
 
566
587
  }