attio 0.0.1-experimental.20250802 → 0.0.1-experimental.20250807

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.
Files changed (2) hide show
  1. package/lib/auth/auth.js +15 -9
  2. package/package.json +2 -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
- this.refreshTimeout = longTimeout(async () => await this.refreshToken(token), Math.max(0, token.expires_at - Date.now() - 5_000));
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({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attio",
3
- "version": "0.0.1-experimental.20250802",
3
+ "version": "0.0.1-experimental.20250807",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib",
@@ -58,6 +58,7 @@
58
58
  "tiny-cursor": "^2.0.0",
59
59
  "tmp-promise": "^3.0.3",
60
60
  "ts-morph": "^24.0.0",
61
+ "typescript": "5.6.3",
61
62
  "zod": "^3.25.64"
62
63
  },
63
64
  "bin": "lib/attio.js"