@letterstory/cli 0.177.163 → 0.177.164

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/lib/cli.mjs CHANGED
@@ -93,7 +93,7 @@ import {
93
93
  import { fetchParkedSections, withoutParked } from "./parked.mjs";
94
94
 
95
95
  // Matches cli/package.json; publish-cli.yml rewrites both to the published version.
96
- export const VERSION = "0.177.163";
96
+ export const VERSION = "0.177.164";
97
97
 
98
98
  /** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
99
99
  export const EXIT_PAYMENT_REQUIRED = 3;
@@ -639,7 +639,7 @@ Usage:
639
639
  ${bin} <command> [args] [--flags]
640
640
 
641
641
  Auth:
642
- login [--url <url>] Sign in via your browser (default url: https://app.letterstory.com)
642
+ login [--url <url>] Sign in via your browser; a link over SSH (default url: https://app.letterstory.com)
643
643
  login --device [--url <url>] Sign in with one link, opened in any browser (for agents and remote shells)
644
644
  login --key <ls_…> [--url <url>] Save a static API key instead (for CI/automation)
645
645
  signup --email <work email> [--agent <name>] [--url <url>]
@@ -39,10 +39,20 @@ export async function cmdLogin(ctx) {
39
39
  }
40
40
  }
41
41
 
42
- const tokens = flags.device ? await deviceLogin({ url, io }) : await browserLogin({ url, io });
42
+ const device = flags.device || browserIsElsewhere();
43
+ if (device && !flags.device) io.log("No browser on this machine, so sign in with a link instead.\n");
44
+ const tokens = device ? await deviceLogin({ url, io }) : await browserLogin({ url, io });
43
45
  return saveSession({ tokens, url, flags, io });
44
46
  }
45
47
 
48
+ // Over SSH, or on Linux with no display, the browser is on another machine and can't reach the
49
+ // loopback redirect (127.0.0.1 here), so `login` signs in with a link and a code as `--device` does.
50
+ /** @param {Record<string, string | undefined>} env @param {string} platform */
51
+ export function browserIsElsewhere(env = process.env, platform = process.platform) {
52
+ if (env.SSH_CONNECTION || env.SSH_CLIENT || env.SSH_TTY) return true;
53
+ return platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY;
54
+ }
55
+
46
56
  // An OAuth session from /token, saved the way every login saves it, then checked with one call.
47
57
  async function saveSession({ tokens, url, flags, io }) {
48
58
  const oauth = {
package/lib/oauth.mjs CHANGED
@@ -156,14 +156,15 @@ export async function browserLogin({ url, io, fetchImpl = globalThis.fetch }) {
156
156
  authUrl.searchParams.set("code_challenge_method", "S256");
157
157
 
158
158
  io.log(`Opening your browser to sign in…`);
159
- io.log(`If it doesn't open automatically, visit:\n ${authUrl.toString()}\n`);
159
+ io.log(`If it doesn't open automatically, visit:\n ${authUrl.toString()}`);
160
+ io.log("Browser on another machine? Press Ctrl+C and run `login --device`.\n");
160
161
  openBrowser(authUrl.toString());
161
162
 
162
163
  try {
163
164
  const result = await withTimeout(
164
165
  server.waitForCallback(),
165
166
  CALLBACK_TIMEOUT_MS,
166
- "Timed out waiting for the browser sign-in. Please try again."
167
+ "Timed out waiting for the browser sign-in. Browser on another machine? Run `login --device`."
167
168
  );
168
169
  if (result.error) {
169
170
  throw new CliError(`Sign-in was not completed: ${result.errorDescription || result.error}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterstory/cli",
3
- "version": "0.177.163",
3
+ "version": "0.177.164",
4
4
  "description": "Spin up and manage Letter phantom blogs from your terminal.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",