attio 0.0.1-experimental.20250802 → 0.0.1-experimental.20250805
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/lib/auth/auth.js +15 -9
- package/package.json +1 -1
package/lib/auth/auth.js
CHANGED
|
@@ -9,16 +9,9 @@ import { printFetcherError, printKeychainError } from "../print-errors.js";
|
|
|
9
9
|
import { findAvailablePort } from "../util/find-available-port.js";
|
|
10
10
|
import { getKeychain } from "./keychain.js";
|
|
11
11
|
const MAX_TIMEOUT = 2_147_483_647;
|
|
12
|
-
function longTimeout(callback, delay) {
|
|
13
|
-
if (delay > MAX_TIMEOUT) {
|
|
14
|
-
return setTimeout(() => longTimeout(callback, delay - MAX_TIMEOUT), MAX_TIMEOUT);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
return setTimeout(callback, delay);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
12
|
class AuthenticatorImpl {
|
|
21
13
|
clientId = "f881c6f1-82d7-48a5-a581-649596167845";
|
|
14
|
+
isRefreshingToken = false;
|
|
22
15
|
refreshTimeout = null;
|
|
23
16
|
async ensureAuthed() {
|
|
24
17
|
const existingTokenResult = await getKeychain().load();
|
|
@@ -132,7 +125,20 @@ class AuthenticatorImpl {
|
|
|
132
125
|
if (this.refreshTimeout !== null) {
|
|
133
126
|
clearTimeout(this.refreshTimeout);
|
|
134
127
|
}
|
|
135
|
-
|
|
128
|
+
const delay = Math.min(Math.max(0, (token.expires_at - Date.now()) / 10), MAX_TIMEOUT);
|
|
129
|
+
this.refreshTimeout = setTimeout(async () => {
|
|
130
|
+
if (this.isRefreshingToken) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.isRefreshingToken = true;
|
|
134
|
+
try {
|
|
135
|
+
await this.refreshToken(token);
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
this.isRefreshingToken = false;
|
|
139
|
+
this.refreshTimeout = null;
|
|
140
|
+
}
|
|
141
|
+
}, delay);
|
|
136
142
|
}
|
|
137
143
|
async refreshToken(token) {
|
|
138
144
|
const refreshTokenResult = await api.refreshToken({
|