@aloma.io/integration-sdk 3.3.56 → 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.
- package/build/internal/index.mjs +21 -5
- package/package.json +1 -1
- package/src/internal/index.mjs +27 -5
package/build/internal/index.mjs
CHANGED
@@ -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
|
-
|
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 =
|
467
|
+
this._refreshOAuthToken = setTimeout(async () => {
|
452
468
|
try {
|
453
469
|
await theOAuth.periodicRefresh();
|
454
470
|
}
|
455
471
|
catch (e) {
|
456
472
|
console.log('periodic refresh', e);
|
457
473
|
}
|
458
|
-
}, /*4 * 60 * 60 **/
|
474
|
+
}, /*4 * 60 * 60 **/ 15000);
|
459
475
|
}
|
460
476
|
}
|
461
477
|
start({
|
package/package.json
CHANGED
package/src/internal/index.mjs
CHANGED
@@ -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
|
-
|
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 =
|
577
|
+
this._refreshOAuthToken = setTimeout(async () => {
|
578
|
+
|
557
579
|
try
|
558
580
|
{
|
559
581
|
await theOAuth.periodicRefresh();
|
560
582
|
} catch(e) {
|
561
583
|
console.log('periodic refresh', e);
|
562
584
|
}
|
563
|
-
}, /*4 * 60 * 60 **/
|
585
|
+
}, /*4 * 60 * 60 **/ 15000);
|
564
586
|
}
|
565
587
|
|
566
588
|
}
|