@aloma.io/integration-sdk 3.3.57 → 3.3.58

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