@aloma.io/integration-sdk 3.3.65 → 3.3.66
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 +28 -12
- package/package.json +1 -1
- package/src/internal/index.mjs +34 -12
package/build/internal/index.mjs
CHANGED
@@ -48,7 +48,7 @@ class Fetcher {
|
|
48
48
|
this.onResponse = onResponse;
|
49
49
|
}
|
50
50
|
async customize(options, args = {}) { }
|
51
|
-
async onError(e, url, options, retries, args) {
|
51
|
+
async onError(e, url, options, retries, args, rateLimit) {
|
52
52
|
var local = this;
|
53
53
|
return new Promise((resolve, reject) => {
|
54
54
|
setTimeout(async () => {
|
@@ -58,7 +58,7 @@ class Fetcher {
|
|
58
58
|
catch (e) {
|
59
59
|
reject(e);
|
60
60
|
}
|
61
|
-
}, 500);
|
61
|
+
}, rateLimit ? 10000 : 500);
|
62
62
|
});
|
63
63
|
}
|
64
64
|
async fetch(url, options = {}, retries, args = {}) {
|
@@ -125,15 +125,22 @@ class OAuthFetcher extends Fetcher {
|
|
125
125
|
if (!force && oauth.accessToken())
|
126
126
|
return oauth.accessToken();
|
127
127
|
const refreshToken = oauth.refreshToken();
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
oauth.
|
133
|
-
|
128
|
+
try {
|
129
|
+
if (!refreshToken) {
|
130
|
+
throw new Error("have no access_token and no refresh_token");
|
131
|
+
}
|
132
|
+
const ret = await oauth.obtainViaRefreshToken(oauth.refreshToken());
|
133
|
+
if (ret.access_token) {
|
134
|
+
oauth.update(ret.access_token, ret.refresh_token);
|
135
|
+
return ret.access_token;
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
throw new Error("could not obtain access token via refresh token");
|
139
|
+
}
|
134
140
|
}
|
135
|
-
|
136
|
-
|
141
|
+
catch (e) {
|
142
|
+
oauth.invalidate(e);
|
143
|
+
throw (e);
|
137
144
|
}
|
138
145
|
}
|
139
146
|
async onError(e, url, options, retries, args, rateLimit) {
|
@@ -198,6 +205,10 @@ class OAuth {
|
|
198
205
|
await client.periodicRefresh();
|
199
206
|
}
|
200
207
|
}
|
208
|
+
async invalidate(err) {
|
209
|
+
console.log('could not obtain access token, marking connector as disconnected', err);
|
210
|
+
await this.upate(null, null);
|
211
|
+
}
|
201
212
|
getClient(arg = {}) {
|
202
213
|
const client = new OAuthFetcher({ ...arg, oauth: this });
|
203
214
|
this.clients.push(client);
|
@@ -410,11 +421,16 @@ ${text}
|
|
410
421
|
return { value: await jwe.encrypt(data, "none", config.id()) };
|
411
422
|
};
|
412
423
|
const saveOAuthResult = async (what) => {
|
413
|
-
|
424
|
+
let value = null;
|
425
|
+
if (what) {
|
426
|
+
const jwe = await config.validateKeys("RSA-OAEP-256");
|
427
|
+
value = await jwe.encrypt(what, "none", config.id());
|
428
|
+
}
|
429
|
+
;
|
414
430
|
const packet = transport.newPacket({});
|
415
431
|
packet.method("connector.config-update");
|
416
432
|
packet.args({
|
417
|
-
value
|
433
|
+
value
|
418
434
|
});
|
419
435
|
transport.send(packet);
|
420
436
|
};
|
package/package.json
CHANGED
package/src/internal/index.mjs
CHANGED
@@ -59,7 +59,7 @@ class Fetcher {
|
|
59
59
|
|
60
60
|
async customize(options, args = {}) {}
|
61
61
|
|
62
|
-
async onError(e, url, options, retries, args) {
|
62
|
+
async onError(e, url, options, retries, args, rateLimit) {
|
63
63
|
var local = this;
|
64
64
|
|
65
65
|
return new Promise((resolve, reject) => {
|
@@ -69,7 +69,7 @@ class Fetcher {
|
|
69
69
|
} catch (e) {
|
70
70
|
reject(e);
|
71
71
|
}
|
72
|
-
}, 500);
|
72
|
+
}, rateLimit?10000:500);
|
73
73
|
});
|
74
74
|
}
|
75
75
|
|
@@ -159,17 +159,26 @@ class OAuthFetcher extends Fetcher {
|
|
159
159
|
if (!force && oauth.accessToken()) return oauth.accessToken();
|
160
160
|
|
161
161
|
const refreshToken = oauth.refreshToken();
|
162
|
-
|
163
|
-
|
162
|
+
|
163
|
+
try
|
164
|
+
{
|
165
|
+
if (!refreshToken) {
|
166
|
+
throw new Error("have no access_token and no refresh_token");
|
167
|
+
}
|
164
168
|
|
165
|
-
|
169
|
+
const ret = await oauth.obtainViaRefreshToken(oauth.refreshToken());
|
166
170
|
|
167
|
-
|
168
|
-
|
171
|
+
if (ret.access_token) {
|
172
|
+
oauth.update(ret.access_token, ret.refresh_token);
|
169
173
|
|
170
|
-
|
171
|
-
|
172
|
-
|
174
|
+
return ret.access_token;
|
175
|
+
} else {
|
176
|
+
throw new Error("could not obtain access token via refresh token");
|
177
|
+
}
|
178
|
+
} catch(e) {
|
179
|
+
oauth.invalidate(e);
|
180
|
+
|
181
|
+
throw(e);
|
173
182
|
}
|
174
183
|
}
|
175
184
|
|
@@ -197,6 +206,7 @@ class OAuthFetcher extends Fetcher {
|
|
197
206
|
async periodicRefresh() {
|
198
207
|
const local = this,
|
199
208
|
oauth = local.oauth;
|
209
|
+
|
200
210
|
if (!oauth.refreshToken()) return;
|
201
211
|
|
202
212
|
await local.getToken(true);
|
@@ -255,6 +265,12 @@ class OAuth {
|
|
255
265
|
await client.periodicRefresh();
|
256
266
|
}
|
257
267
|
}
|
268
|
+
|
269
|
+
async invalidate(err) {
|
270
|
+
console.log('could not obtain access token, marking connector as disconnected', err);
|
271
|
+
|
272
|
+
await this.upate(null, null);
|
273
|
+
}
|
258
274
|
|
259
275
|
getClient(arg = {}) {
|
260
276
|
const client = new OAuthFetcher({ ...arg, oauth: this });
|
@@ -509,12 +525,18 @@ ${text}
|
|
509
525
|
};
|
510
526
|
|
511
527
|
const saveOAuthResult = async (what) => {
|
512
|
-
|
528
|
+
let value = null;
|
529
|
+
|
530
|
+
if (what) {
|
531
|
+
const jwe = await config.validateKeys("RSA-OAEP-256");
|
532
|
+
value = await jwe.encrypt(what, "none", config.id())
|
533
|
+
};
|
534
|
+
|
513
535
|
const packet = transport.newPacket({});
|
514
536
|
|
515
537
|
packet.method("connector.config-update");
|
516
538
|
packet.args({
|
517
|
-
value
|
539
|
+
value
|
518
540
|
});
|
519
541
|
|
520
542
|
transport.send(packet);
|