@tinycloud/cli 1.3.0-beta.45 → 1.3.0-beta.47

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.
@@ -10600,6 +10600,7 @@ init_types();
10600
10600
  // src/auth/browser-auth.ts
10601
10601
  init_constants();
10602
10602
  init_errors();
10603
+ init_formatter();
10603
10604
  import { createServer } from "http";
10604
10605
  import { randomBytes as randomBytes3 } from "crypto";
10605
10606
  import { createInterface } from "readline";
@@ -10614,6 +10615,9 @@ var PRIVATE_JWK_FIELDS = /* @__PURE__ */ new Set([
10614
10615
  "k"
10615
10616
  ]);
10616
10617
  var MAX_CALLBACK_BODY_BYTES = 1024 * 1024;
10618
+ var CALLBACK_DEADLINE_MS = 5 * 60 * 1e3;
10619
+ var CALLBACK_HINT_DELAY_MS = 15 * 1e3;
10620
+ var CALLBACK_HINT = "Still waiting. If your browser asked to connect to devices on your network, choose Allow. Or press Ctrl+C and run `tinycloud auth login --paste` to enter a code instead.";
10617
10621
  function publicJwkForDelegation(jwk) {
10618
10622
  const publicJwk = {};
10619
10623
  for (const [key, value] of Object.entries(jwk)) {
@@ -10755,15 +10759,21 @@ function shouldOpenBrowser(options) {
10755
10759
  const env = process.env.TC_AUTH_NO_POPUP ?? process.env.TC_NO_POPUP;
10756
10760
  return env !== "1" && env !== "true";
10757
10761
  }
10758
- async function callbackFlow(did, options = {}) {
10762
+ async function callbackFlow(did, options = {}, env = {}) {
10759
10763
  return new Promise((resolve8, reject) => {
10760
10764
  let timeout;
10765
+ let hintTimer;
10766
+ const deadlineMs = env.deadlineMs ?? CALLBACK_DEADLINE_MS;
10767
+ const hintDelayMs = env.hintDelayMs ?? CALLBACK_HINT_DELAY_MS;
10768
+ const interactive = env.interactive ?? Boolean(process.stdin.isTTY);
10769
+ const jsonOutput2 = env.jsonOutput ?? shouldOutputJson();
10761
10770
  let settled = false;
10762
10771
  let rl;
10763
10772
  function settle(result) {
10764
10773
  if (settled) return;
10765
10774
  settled = true;
10766
10775
  clearTimeout(timeout);
10776
+ clearTimeout(hintTimer);
10767
10777
  server.close();
10768
10778
  server.closeAllConnections();
10769
10779
  if (rl) {
@@ -10828,8 +10838,9 @@ async function callbackFlow(did, options = {}) {
10828
10838
  res.end();
10829
10839
  }
10830
10840
  });
10831
- server.headersTimeout = 1e4;
10832
- server.requestTimeout = 1e4;
10841
+ server.headersTimeout = deadlineMs;
10842
+ server.requestTimeout = deadlineMs;
10843
+ server.keepAliveTimeout = deadlineMs;
10833
10844
  server.listen(0, "127.0.0.1", async () => {
10834
10845
  const addr = server.address();
10835
10846
  if (!addr || typeof addr === "string") {
@@ -10838,6 +10849,7 @@ async function callbackFlow(did, options = {}) {
10838
10849
  }
10839
10850
  const port = addr.port;
10840
10851
  const callbackUrl = `http://127.0.0.1:${port}${callbackPath}`;
10852
+ env.onListening?.(callbackUrl);
10841
10853
  const authUrl = buildAuthUrl(did, { ...options, callback: callbackUrl });
10842
10854
  const openBrowser = shouldOpenBrowser(options);
10843
10855
  const hasTerminal = Boolean(process.stdin.isTTY || process.stderr.isTTY);
@@ -10856,7 +10868,7 @@ async function callbackFlow(did, options = {}) {
10856
10868
  return;
10857
10869
  }
10858
10870
  }
10859
- if (process.stdin.isTTY) {
10871
+ if (interactive) {
10860
10872
  console.error(`
10861
10873
  If the browser can't connect back, enter the short code or paste the full delegation code here:`);
10862
10874
  rl = createInterface({
@@ -10880,7 +10892,12 @@ If the browser can't connect back, enter the short code or paste the full delega
10880
10892
  });
10881
10893
  timeout = setTimeout(() => {
10882
10894
  settle({ error: new Error("Authentication timed out after 5 minutes") });
10883
- }, 5 * 60 * 1e3);
10895
+ }, deadlineMs);
10896
+ if (interactive && !jsonOutput2) {
10897
+ hintTimer = setTimeout(() => {
10898
+ console.error(CALLBACK_HINT);
10899
+ }, hintDelayMs);
10900
+ }
10884
10901
  });
10885
10902
  }
10886
10903
  async function pasteFlow(did, options = {}) {