@aiwayds/dsh-opentui 0.23.2 → 0.24.0

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.
@@ -574,6 +574,19 @@ var init_client_lifecycle = __esm(() => {
574
574
  import { createHash, createHmac } from "node:crypto";
575
575
  import { readFileSync as readFileSync2, statSync } from "node:fs";
576
576
  import { join as join3 } from "node:path";
577
+ function resolveRetryWindow(option) {
578
+ if (option !== undefined && Number.isFinite(option) && option > 0)
579
+ return option;
580
+ const env = Number(process.env[RETRY_WINDOW_ENV]);
581
+ if (Number.isFinite(env) && env > 0)
582
+ return env;
583
+ return DEFAULT_RETRY_WINDOW_MS;
584
+ }
585
+ function resolveRetryInterval(option) {
586
+ if (option !== undefined && Number.isFinite(option) && option > 0)
587
+ return option;
588
+ return DEFAULT_RETRY_INTERVAL_MS;
589
+ }
577
590
  function ownerCookieName(authority) {
578
591
  return "dsh-auth-" + base64url(createHash("sha256").update(authority).digest());
579
592
  }
@@ -582,7 +595,7 @@ function mintOwnerCookie(options) {
582
595
  if (typeof authority !== "string" || authority.length === 0 || /[\r\n/]/.test(authority)) {
583
596
  throw new OwnerCookieError("authority must be a non-empty host:port without scheme or path separators");
584
597
  }
585
- const secret = readGrantSecret(options.home);
598
+ const secret = readGrantSecret(options.home, resolveRetryWindow(options.timeoutMs), resolveRetryInterval(options.retryIntervalMs));
586
599
  const issuedAt = Date.now();
587
600
  const maxAgeMs = options.maxAgeMs ?? DEFAULT_MAX_AGE_MS;
588
601
  const expiresAt = issuedAt + Math.min(maxAgeMs, DEFAULT_MAX_AGE_MS);
@@ -590,9 +603,9 @@ function mintOwnerCookie(options) {
590
603
  const signature = base64url(createHmac("sha256", secret).update(body).digest());
591
604
  return `${ownerCookieName(authority)}=v1.${body}.${signature}`;
592
605
  }
593
- function readGrantSecret(home) {
606
+ function readGrantSecret(home, timeoutMs, retryIntervalMs) {
594
607
  const path = join3(home, ".credentials.yaml");
595
- const deadline = Date.now() + RETRY_WINDOW_MS;
608
+ const deadline = Date.now() + timeoutMs;
596
609
  let sawFile = false;
597
610
  while (true) {
598
611
  let file = "";
@@ -612,11 +625,11 @@ function readGrantSecret(home) {
612
625
  }
613
626
  if (Date.now() >= deadline) {
614
627
  if (!sawFile) {
615
- throw new CredentialsFileMissingError(`no credentials file at ${path} within ${RETRY_WINDOW_MS}ms (host first boot still pending?)`);
628
+ throw new CredentialsFileMissingError(`no credentials file at ${path} within ${timeoutMs}ms (host first boot still pending?)`);
616
629
  }
617
- throw new CredentialsGrantMissingError(`credentials record "${RECORD_KEY}" absent in ${path} within ${RETRY_WINDOW_MS}ms (host first boot still pending?)`);
630
+ throw new CredentialsGrantMissingError(`credentials record "${RECORD_KEY}" absent in ${path} within ${timeoutMs}ms (host first boot still pending?)`);
618
631
  }
619
- sleepSync(RETRY_INTERVAL_MS);
632
+ sleepSync(retryIntervalMs);
620
633
  }
621
634
  }
622
635
  function assertOwnerOnly(path) {
@@ -785,7 +798,7 @@ function sleepSync(ms) {
785
798
  while (Date.now() < until) {}
786
799
  }
787
800
  }
788
- var RECORD_KEY = "client-connection/browser-session", DEFAULT_MAX_AGE_MS, RETRY_INTERVAL_MS = 100, RETRY_WINDOW_MS = 2000, SECRET_PATTERN, OwnerCookieError, CredentialsFileMissingError, CredentialsGrantMissingError, CredentialsGrantInvalidError, CredentialsFileInsecureError, CredentialsParseError;
801
+ var RECORD_KEY = "client-connection/browser-session", DEFAULT_MAX_AGE_MS, DEFAULT_RETRY_INTERVAL_MS = 100, DEFAULT_RETRY_WINDOW_MS = 30000, RETRY_WINDOW_ENV = "DSH_OPENTUI_COOKIE_MINT_TIMEOUT_MS", SECRET_PATTERN, OwnerCookieError, CredentialsFileMissingError, CredentialsGrantMissingError, CredentialsGrantInvalidError, CredentialsFileInsecureError, CredentialsParseError;
789
802
  var init_cookie_mint = __esm(() => {
790
803
  DEFAULT_MAX_AGE_MS = 30 * 86400000;
791
804
  SECRET_PATTERN = /^[A-Za-z0-9_-]{43}$/;
@@ -1276,5 +1289,5 @@ export {
1276
1289
  readRegistry
1277
1290
  };
1278
1291
 
1279
- //# debugId=5785637837263AC664756E2164756E21
1292
+ //# debugId=B9D181B6BE36DFCE64756E2164756E21
1280
1293
  //# sourceMappingURL=host-launch.mjs.map