@aloth/olcli 0.17.0 → 0.18.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.
package/README.md CHANGED
@@ -63,7 +63,7 @@ olcli auth status # instance, account, where the credential comes fr
63
63
 
64
64
  **Get your session cookie:** sign in to Overleaf in a browser, open the developer tools (F12), then Application (Chrome, Edge) or Storage (Firefox), Cookies, and copy the value of `overleaf_session2` (`overleaf.sid` on most self-hosted instances). A value on the command line also works but lands in your shell history.
65
65
 
66
- Self-hosted instances without reCAPTCHA also accept `olcli auth --email you@example.com`, which prompts for the password. Scripts can set `OVERLEAF_SESSION`, or `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`, and skip `olcli auth` entirely.
66
+ Self-hosted instances without reCAPTCHA also accept `olcli auth --email you@example.com`, which prompts for the password. overleaf.com requires a captcha for password sign-in, which olcli cannot complete, so use `olcli auth --browser` or `olcli auth --cookie` there; on a terminal, a refused password sign-in offers the browser sign-in instead. Scripts can set `OVERLEAF_SESSION`, or on self-hosted instances without reCAPTCHA `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`, and skip `olcli auth` entirely.
67
67
 
68
68
  ### Self-hosted Overleaf
69
69
 
@@ -0,0 +1,57 @@
1
+ /**
2
+ * What `olcli auth` does when a password sign-in is refused because the
3
+ * instance requires a captcha: on a terminal, offer the browser sign-in
4
+ * instead; everywhere else, only report it.
5
+ *
6
+ * Kept apart from cli.ts so the decision can be tested without a terminal,
7
+ * a browser or the network.
8
+ */
9
+ export interface BrowserFallbackDeps {
10
+ /** True when a person is at the terminal (see `canOfferBrowserSignIn`). */
11
+ interactive: boolean;
12
+ /** Throws with a reason when `auth --browser` cannot run here (no browser, old Node). */
13
+ checkBrowser: () => void;
14
+ /** Asks the question; resolves to true for yes. */
15
+ ask: (question: string) => Promise<boolean>;
16
+ /** Runs the same flow as `olcli auth --browser`. */
17
+ runBrowser: () => Promise<void>;
18
+ }
19
+ /**
20
+ * - `browser`: the user said yes and the browser sign-in ran
21
+ * - `declined`: the user said no
22
+ * - `unavailable`: interactive, but `auth --browser` cannot run here; `reason` says why
23
+ * - `not-offered`: not a captcha error, or nobody to ask
24
+ */
25
+ export type BrowserFallbackOutcome = {
26
+ outcome: 'browser';
27
+ } | {
28
+ outcome: 'declined';
29
+ } | {
30
+ outcome: 'unavailable';
31
+ reason: string;
32
+ } | {
33
+ outcome: 'not-offered';
34
+ };
35
+ export declare const BROWSER_FALLBACK_QUESTION = "Sign in in the browser instead?";
36
+ /**
37
+ * True when stdin and stdout are both terminals and no CI system is driving
38
+ * the run. Only then can a question be answered by a person.
39
+ */
40
+ export declare function canOfferBrowserSignIn(streams?: {
41
+ stdin: {
42
+ isTTY?: boolean;
43
+ };
44
+ stdout: {
45
+ isTTY?: boolean;
46
+ };
47
+ }, env?: NodeJS.ProcessEnv): boolean;
48
+ export declare function offerBrowserSignIn(error: unknown, deps: BrowserFallbackDeps): Promise<BrowserFallbackOutcome>;
49
+ /**
50
+ * Warnings for `auth status` about the credential that would be used.
51
+ * Password credentials on overleaf.com cannot sign in, because Overleaf
52
+ * requires a captcha for password sign-in there. Self-hosted instances are
53
+ * not judged: whether they have reCAPTCHA switched on is only known after a
54
+ * sign-in attempt.
55
+ */
56
+ export declare function passwordSignInWarnings(usesPassword: boolean, baseUrl: string): string[];
57
+ //# sourceMappingURL=auth-fallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fallback.d.ts","sourceRoot":"","sources":["../src/auth-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,mBAAmB;IAClC,2EAA2E;IAC3E,WAAW,EAAE,OAAO,CAAC;IACrB,yFAAyF;IACzF,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,mDAAmD;IACnD,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,oDAAoD;IACpD,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GACtB;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,GACvB;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,CAAC;AAE/B,eAAO,MAAM,yBAAyB,oCAAoC,CAAC;AAE3E;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE;IAAE,KAAK,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAqD,EACvH,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAGT;AAED,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAUnH;AAKD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAUvF"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * What `olcli auth` does when a password sign-in is refused because the
3
+ * instance requires a captcha: on a terminal, offer the browser sign-in
4
+ * instead; everywhere else, only report it.
5
+ *
6
+ * Kept apart from cli.ts so the decision can be tested without a terminal,
7
+ * a browser or the network.
8
+ */
9
+ import { CaptchaRequiredError } from './errors.js';
10
+ export const BROWSER_FALLBACK_QUESTION = 'Sign in in the browser instead?';
11
+ /**
12
+ * True when stdin and stdout are both terminals and no CI system is driving
13
+ * the run. Only then can a question be answered by a person.
14
+ */
15
+ export function canOfferBrowserSignIn(streams = { stdin: process.stdin, stdout: process.stdout }, env = process.env) {
16
+ const ci = env.CI !== undefined && env.CI !== '' && env.CI !== '0' && env.CI.toLowerCase() !== 'false';
17
+ return Boolean(streams.stdin.isTTY) && Boolean(streams.stdout.isTTY) && !ci;
18
+ }
19
+ export async function offerBrowserSignIn(error, deps) {
20
+ if (!(error instanceof CaptchaRequiredError) || !deps.interactive)
21
+ return { outcome: 'not-offered' };
22
+ try {
23
+ deps.checkBrowser();
24
+ }
25
+ catch (reason) {
26
+ return { outcome: 'unavailable', reason: reason instanceof Error ? reason.message : String(reason) };
27
+ }
28
+ if (!(await deps.ask(BROWSER_FALLBACK_QUESTION)))
29
+ return { outcome: 'declined' };
30
+ await deps.runBrowser();
31
+ return { outcome: 'browser' };
32
+ }
33
+ /** Hosts where password sign-in is known to need a captcha. */
34
+ const CAPTCHA_HOSTS = new Set(['www.overleaf.com', 'overleaf.com']);
35
+ /**
36
+ * Warnings for `auth status` about the credential that would be used.
37
+ * Password credentials on overleaf.com cannot sign in, because Overleaf
38
+ * requires a captcha for password sign-in there. Self-hosted instances are
39
+ * not judged: whether they have reCAPTCHA switched on is only known after a
40
+ * sign-in attempt.
41
+ */
42
+ export function passwordSignInWarnings(usesPassword, baseUrl) {
43
+ if (!usesPassword)
44
+ return [];
45
+ let host;
46
+ try {
47
+ host = new URL(baseUrl).hostname.toLowerCase();
48
+ }
49
+ catch {
50
+ return [];
51
+ }
52
+ if (!CAPTCHA_HOSTS.has(host))
53
+ return [];
54
+ return ['overleaf.com requires a captcha for password sign-in, which olcli cannot complete. Sign in with: olcli auth --browser'];
55
+ }
56
+ //# sourceMappingURL=auth-fallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fallback.js","sourceRoot":"","sources":["../src/auth-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAyBnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,iCAAiC,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAA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CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,YAAqB,EAAE,OAAe;IAC3E,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IAC7B,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACxC,OAAO,CAAC,uHAAuH,CAAC,CAAC;AACnI,CAAC"}
package/dist/cli.js CHANGED
@@ -8,7 +8,7 @@
8
8
  import { Command } from 'commander';
9
9
  import chalk from 'chalk';
10
10
  import { colorDisabled, createSpinner as ora, icon } from './term.js';
11
- import { ProjectOwnerOnlyError, formatError } from './errors.js';
11
+ import { CaptchaRequiredError, ProjectOwnerOnlyError, formatError } from './errors.js';
12
12
  import { writeFileSync, readFileSync, existsSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs';
13
13
  import { join, dirname, basename } from 'node:path';
14
14
  import { tmpdir } from 'node:os';
@@ -26,7 +26,8 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
26
26
  const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
27
27
  const VERSION = pkg.version;
28
28
  import { getSessionCookie, setSessionCookie, setLastProject, getConfigPath, saveOlAuth, clearConfig, getBaseUrl, setBaseUrl, getSessionCookieName, setSessionCookieName, getTimeout, setTimeout, getPasswordCredentials, setPasswordCredentials, clearOlAuth, inspectStoredCredentials, parseCookieInput, resolveSessionCookie, maskSecret } from './config.js';
29
- import { promptHidden, PromptCancelled, NotATerminal } from './prompt.js';
29
+ import { promptHidden, promptYesNo, PromptCancelled, NotATerminal } from './prompt.js';
30
+ import { canOfferBrowserSignIn, offerBrowserSignIn, passwordSignInWarnings } from './auth-fallback.js';
30
31
  import { BrowserSignInAborted, browserSignIn, chromiumLauncher, findBrowser, requireWebSocket } from './browser-auth.js';
31
32
  // NO_COLOR (no-color.org) and --no-color. chalk handles --no-color and a
32
33
  // non-TTY stdout by itself, but not NO_COLOR; ora and log-symbols share this
@@ -47,7 +48,9 @@ program
47
48
  Environment:
48
49
  OVERLEAF_SESSION session cookie (instead of olcli auth)
49
50
  OVERLEAF_EMAIL, OVERLEAF_PASSWORD
50
- password login when no session cookie works
51
+ password login when no session cookie works;
52
+ self-hosted servers without reCAPTCHA only
53
+ (overleaf.com: olcli auth --browser)
51
54
  OVERLEAF_BASE_URL instance URL, like --base-url
52
55
  OVERLEAF_COOKIE_NAME session cookie name, like --cookie-name
53
56
  OVERLEAF_TIMEOUT HTTP timeout in milliseconds, like --timeout
@@ -192,7 +195,7 @@ const authCmd = program
192
195
  .command('auth')
193
196
  .description('Authenticate with Overleaf using a session cookie or email/password')
194
197
  .option('--cookie [session]', 'Session cookie; omit the value to be prompted, "-" reads stdin')
195
- .option('--email <email>', 'Account email for password login')
198
+ .option('--email <email>', 'Account email for password login (self-hosted servers without reCAPTCHA)')
196
199
  .option('--password <password>', 'Account password (omit to be prompted; see warning below)')
197
200
  .option('--save-password', 'Persist the password in the config file, in plaintext')
198
201
  .option('--no-save-password', 'Do not persist the password (the default; kept for existing scripts)')
@@ -215,13 +218,18 @@ instances). Then either:
215
218
  pbpaste | olcli auth --cookie - reads the cookie from stdin
216
219
  A value given on the command line works too, but lands in your shell history.
217
220
 
221
+ Password sign-in (--email) works only on self-hosted servers without
222
+ reCAPTCHA. overleaf.com requires a captcha for it, which olcli cannot
223
+ complete; use --browser or --cookie there.
224
+
218
225
  The password is not stored unless you ask for it with --save-password. A
219
226
  session cookie is stored either way, and that is what later commands use; the
220
227
  password only buys an automatic re-login once the cookie expires.
221
228
 
222
229
  Passing --password puts the password in your shell history. Omit it to be
223
230
  prompted instead, or set OVERLEAF_EMAIL and OVERLEAF_PASSWORD, which every
224
- command reads without needing 'auth' at all.`)
231
+ command reads without needing 'auth' at all (self-hosted servers without
232
+ reCAPTCHA only).`)
225
233
  .action(async (options) => {
226
234
  if (options.browser) {
227
235
  if (options.cookie || options.email || options.password) {
@@ -246,7 +254,7 @@ command reads without needing 'auth' at all.`)
246
254
  console.log(chalk.cyan(' olcli auth --cookie'));
247
255
  console.log(chalk.dim(' (or pipe it: pbpaste | olcli auth --cookie -)'));
248
256
  console.log();
249
- console.log('Or log in with email/password:');
257
+ console.log('Or log in with email/password (self-hosted servers without reCAPTCHA):');
250
258
  console.log(chalk.cyan(' olcli auth --email "you@example.com"'));
251
259
  console.log(chalk.dim(' (prompts for the password, so it stays out of your shell history)'));
252
260
  console.log();
@@ -314,8 +322,8 @@ command reads without needing 'auth' at all.`)
314
322
  catch (error) {
315
323
  if (error instanceof NotATerminal) {
316
324
  console.error(chalk.red('No terminal available to prompt for a password.'));
317
- console.error('Set OVERLEAF_EMAIL and OVERLEAF_PASSWORD instead — every command reads them,');
318
- console.error("so a scripted run does not need 'olcli auth' at all.");
325
+ console.error('Set OVERLEAF_EMAIL and OVERLEAF_PASSWORD instead - every command reads them,');
326
+ console.error("so a scripted run does not need 'olcli auth' at all (self-hosted servers without reCAPTCHA only).");
319
327
  process.exit(1);
320
328
  }
321
329
  if (error instanceof PromptCancelled) {
@@ -376,6 +384,23 @@ command reads without needing 'auth' at all.`)
376
384
  printNextSteps(projects);
377
385
  }
378
386
  catch (error) {
387
+ if (error instanceof CaptchaRequiredError) {
388
+ const [first, ...rest] = formatError(error, { verbose: Boolean(program.opts().verbose) });
389
+ spinner.fail(first);
390
+ for (const line of rest)
391
+ console.error(chalk.dim(` ${line}`));
392
+ const offer = await offerBrowserSignIn(error, {
393
+ interactive: canOfferBrowserSignIn(),
394
+ checkBrowser: () => { requireWebSocket(); findBrowser(); },
395
+ ask: (question) => promptYesNo(question, true).catch(() => false),
396
+ runBrowser: () => authWithBrowser({ saveLocal: options.saveLocal }),
397
+ });
398
+ if (offer.outcome === 'browser')
399
+ return;
400
+ if (offer.outcome === 'unavailable')
401
+ console.error(chalk.dim(` Browser sign-in is not available here: ${offer.reason}`));
402
+ process.exit(1);
403
+ }
379
404
  failWith(spinner, error);
380
405
  }
381
406
  });
@@ -480,6 +505,7 @@ async function authStatus(options) {
480
505
  configFile: getConfigPath(),
481
506
  passwordStored: stored.password,
482
507
  signedIn: false,
508
+ warnings: passwordSignInWarnings(Boolean(password), baseUrl),
483
509
  };
484
510
  const print = () => {
485
511
  if (options.json) {
@@ -498,6 +524,9 @@ async function authStatus(options) {
498
524
  if (report.signedIn) {
499
525
  row('Session', chalk.green(`valid, ${report.projects} project(s)`));
500
526
  }
527
+ for (const warning of report.warnings) {
528
+ row('Warning', chalk.yellow(warning));
529
+ }
501
530
  };
502
531
  let failure;
503
532
  if (!resolved && !password) {