@persistmemory/cli 0.2.1 → 0.2.3

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/bin.js CHANGED
@@ -1527,7 +1527,7 @@ function shortDate(iso) {
1527
1527
  }
1528
1528
 
1529
1529
  // src/help.ts
1530
- var VERSION = true ? "0.2.1" : versionFromManifest();
1530
+ var VERSION = true ? "0.2.3" : versionFromManifest();
1531
1531
  var PACKAGE = "@persistmemory/cli";
1532
1532
  var HELP = `
1533
1533
  pm \u2014 PersistMemory from your terminal
@@ -1746,7 +1746,17 @@ async function startLoopback(options = {}) {
1746
1746
  // This page is one-use and holds a result; nothing should keep it.
1747
1747
  "cache-control": "no-store",
1748
1748
  // It never loads anything, so it is not allowed to.
1749
- "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'"
1749
+ "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'",
1750
+ /*
1751
+ Not kept alive, because a kept socket keeps the PROCESS alive.
1752
+
1753
+ `server.close()` stops new connections and leaves established ones
1754
+ open, and a browser holds this one open by default — so `pm auth login`
1755
+ printed "Signed in" and then sat there until somebody pressed Ctrl+C.
1756
+ The page is the last thing this server ever serves; there is nothing to
1757
+ reuse the connection for.
1758
+ */
1759
+ connection: "close"
1750
1760
  });
1751
1761
  response.end(donePage(callback));
1752
1762
  resolveCallback?.(callback);
@@ -1778,7 +1788,9 @@ async function startLoopback(options = {}) {
1778
1788
  },
1779
1789
  close() {
1780
1790
  clearTimeout(timer);
1791
+ server.closeAllConnections?.();
1781
1792
  server.close();
1793
+ server.unref();
1782
1794
  }
1783
1795
  };
1784
1796
  }
@@ -2064,7 +2076,7 @@ async function clientFor(resolved, deps) {
2064
2076
  });
2065
2077
  }
2066
2078
  async function currentCredential(resolved, deps) {
2067
- const credential = resolved.credential;
2079
+ const credential = resolved.fromEnvironment ? resolved.credential : readCredentials(deps.paths)[resolved.profile] ?? resolved.credential;
2068
2080
  if (!credential) throw new NotSignedIn();
2069
2081
  if (!isExpired(credential, deps.now?.() ?? Date.now())) return credential;
2070
2082
  if (!credential.refreshToken || !resolved.clientId) {
@@ -2085,14 +2097,18 @@ async function currentCredential(resolved, deps) {
2085
2097
 
2086
2098
  // src/context.ts
2087
2099
  import { createInterface } from "node:readline";
2088
- async function askOnTty(prompt) {
2100
+ async function askOnTty(prompt, input = process.stdin, output = process.stdout) {
2089
2101
  return new Promise((resolve8) => {
2090
- const readline = createInterface({ input: process.stdin, output: process.stdout });
2102
+ const readline = createInterface({ input, output });
2103
+ let answered = false;
2091
2104
  readline.question(prompt, (answer3) => {
2092
- readline.close();
2105
+ answered = true;
2093
2106
  resolve8(answer3.trim());
2107
+ readline.close();
2108
+ });
2109
+ readline.once("close", () => {
2110
+ if (!answered) resolve8("");
2094
2111
  });
2095
- readline.once("close", () => resolve8(""));
2096
2112
  });
2097
2113
  }
2098
2114
  var ETX = "";
@@ -2103,11 +2119,15 @@ async function readSecretFromTty(prompt) {
2103
2119
  if (!input.isTTY) {
2104
2120
  return new Promise((resolve8) => {
2105
2121
  const readline = createInterface({ input });
2122
+ let answered = false;
2106
2123
  readline.once("line", (line) => {
2107
- readline.close();
2124
+ answered = true;
2108
2125
  resolve8(line.trim());
2126
+ readline.close();
2127
+ });
2128
+ readline.once("close", () => {
2129
+ if (!answered) resolve8("");
2109
2130
  });
2110
- readline.once("close", () => resolve8(""));
2111
2131
  });
2112
2132
  }
2113
2133
  process.stdout.write(prompt);