@keynv/cli 0.1.0-rc.19 → 0.1.0-rc.20

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/dist/index.js CHANGED
@@ -1057,7 +1057,7 @@ var require_lib = __commonJS({
1057
1057
  var VERSION, AGENT;
1058
1058
  var init_version = __esm({
1059
1059
  "src/version.ts"() {
1060
- VERSION = "0.1.0-rc.19" ;
1060
+ VERSION = "0.1.0-rc.20" ;
1061
1061
  AGENT = `keynv-cli/${VERSION}`;
1062
1062
  }
1063
1063
  });
@@ -9537,7 +9537,7 @@ async function runBrowserAuth(serverUrl) {
9537
9537
  );
9538
9538
  }
9539
9539
  const deadline = Date.now() + start.expires_in * 1e3;
9540
- const intervalMs = Math.max(1, start.interval) * 1e3;
9540
+ let intervalMs = Math.max(1, start.interval) * 1e3;
9541
9541
  while (Date.now() < deadline) {
9542
9542
  await sleep(intervalMs);
9543
9543
  const pollRes = await fetch(new URL("/v1/auth/cli/browser/poll", serverUrl).toString(), {
@@ -9546,6 +9546,14 @@ async function runBrowserAuth(serverUrl) {
9546
9546
  body: JSON.stringify({ device_code: start.device_code })
9547
9547
  });
9548
9548
  if (pollRes.status === 202) continue;
9549
+ if (pollRes.status === 429) {
9550
+ await pollRes.text().catch(() => "");
9551
+ const retryAfterRaw = pollRes.headers.get("retry-after");
9552
+ const retryAfterMs = parseRetryAfterMs(retryAfterRaw);
9553
+ const nextInterval = Math.max(intervalMs * 2, retryAfterMs ?? 0, 5e3);
9554
+ intervalMs = Math.min(nextInterval, 6e4);
9555
+ continue;
9556
+ }
9549
9557
  if (!pollRes.ok) {
9550
9558
  throw new BrowserAuthError(
9551
9559
  await errorMessage(pollRes, `Browser auth failed (${pollRes.status}).`)
@@ -9566,6 +9574,19 @@ async function runBrowserAuth(serverUrl) {
9566
9574
  }
9567
9575
  throw new BrowserAuthError("Browser auth timed out. Run `keynv` to try again.");
9568
9576
  }
9577
+ function parseRetryAfterMs(header) {
9578
+ if (!header) return null;
9579
+ const trimmed = header.trim();
9580
+ if (trimmed === "") return null;
9581
+ if (/^\d+$/.test(trimmed)) {
9582
+ const seconds = Number.parseInt(trimmed, 10);
9583
+ if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
9584
+ return null;
9585
+ }
9586
+ const parsed = Date.parse(trimmed);
9587
+ if (!Number.isFinite(parsed)) return null;
9588
+ return Math.max(0, parsed - Date.now());
9589
+ }
9569
9590
  var BrowserAuthError;
9570
9591
  var init_browser_auth = __esm({
9571
9592
  "src/client/browser-auth.ts"() {