@ysgao/web-cli 0.3.1 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +29 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -51494,6 +51494,8 @@ async function attemptSilentRefresh(opts, deps, credentials) {
51494
51494
  const connect = deps.connect ?? connectCdpSession;
51495
51495
  const now = deps.now ?? (() => Date.now());
51496
51496
  const sleep = deps.sleep ?? defaultSleep;
51497
+ const notify = deps.notify ?? ((message) => process.stderr.write(`${message}
51498
+ `));
51497
51499
  try {
51498
51500
  return await withChrome({ headless: true }, async (chrome) => {
51499
51501
  const session = await connect(chrome.port);
@@ -51502,24 +51504,40 @@ async function attemptSilentRefresh(opts, deps, credentials) {
51502
51504
  await session.navigate(opts.loginUrl);
51503
51505
  } catch {
51504
51506
  }
51505
- await attemptAutoFill(opts.site, session, deps, credentials);
51507
+ const firstAutoFillResult = await attemptAutoFill(opts.site, session, deps, credentials);
51506
51508
  const silentTimeoutMs = deps.silentRefreshTimeoutMs ?? (credentials ? SILENT_REFRESH_TIMEOUT_MS : SILENT_REFRESH_NO_CREDENTIAL_TIMEOUT_MS);
51507
- const deadline = now() + silentTimeoutMs;
51509
+ const startedAt = now();
51510
+ const deadline = startedAt + silentTimeoutMs;
51511
+ const retryAtMs = startedAt + Math.floor(silentTimeoutMs / 2);
51512
+ let retried = false;
51513
+ let retryAutoFillResult;
51514
+ let lastCookieCount = 0;
51508
51515
  for (; ; ) {
51509
51516
  const jar = await getLoginPageCookies(session, opts.loginUrl);
51510
- if (Object.keys(jar).length > 0 && await opts.isSessionReady(jar)) {
51517
+ lastCookieCount = Object.keys(jar).length;
51518
+ if (lastCookieCount > 0 && await opts.isSessionReady(jar)) {
51511
51519
  return jar;
51512
51520
  }
51513
51521
  if (now() >= deadline) {
51522
+ notify(
51523
+ `web-cli: silent session refresh for "${opts.site}" (${opts.intent}) did not establish a working session \u2014 credential stored: ${credentials ? "yes" : "no"}; auto-fill found a form to submit: ${firstAutoFillResult ? "yes" : "no"}` + (retried ? `; retried mid-wait, found a form that time: ${retryAutoFillResult ? "yes" : "no"}` : "") + `; cookies present when giving up: ${lastCookieCount}. If a credential is saved and this keeps happening, a CAPTCHA/2FA page or a changed login layout the auto-fill heuristic can't handle is the likely cause \u2014 try "web-cli login ${opts.site}" to sign in by hand and see what it actually shows.`
51524
+ );
51514
51525
  return null;
51515
51526
  }
51527
+ if (!retried && silentTimeoutMs > 0 && now() >= retryAtMs) {
51528
+ retried = true;
51529
+ retryAutoFillResult = await attemptAutoFill(opts.site, session, deps, credentials);
51530
+ }
51516
51531
  await sleep(SILENT_REFRESH_POLL_INTERVAL_MS);
51517
51532
  }
51518
51533
  } finally {
51519
51534
  await session.close();
51520
51535
  }
51521
51536
  });
51522
- } catch {
51537
+ } catch (err) {
51538
+ notify(
51539
+ `web-cli: silent session refresh for "${opts.site}" (${opts.intent}) did not run to completion (${err instanceof Error ? err.message : String(err)}).`
51540
+ );
51523
51541
  return null;
51524
51542
  }
51525
51543
  }
@@ -51804,8 +51822,9 @@ function callOptionsFor(intent, signal) {
51804
51822
  }
51805
51823
  async function attemptReplay(site, intent, param, jarOverride, signal) {
51806
51824
  const config2 = getSiteConfig(site);
51825
+ const siteSupportsLogin = config2.requiresLogin !== false;
51807
51826
  const cookieJar = jarOverride ?? getEstablishedSession(site) ?? mergeStoredSession(await getLiveCookieJar(config2.host), await loadSessionJar(site));
51808
- if (Object.keys(cookieJar).length === 0) {
51827
+ if (Object.keys(cookieJar).length === 0 && siteSupportsLogin) {
51809
51828
  throw new AuthRequiredError(
51810
51829
  `No live session cookies found for ${config2.host} in web-cli's Chrome profile`,
51811
51830
  site
@@ -51823,7 +51842,7 @@ async function attemptReplay(site, intent, param, jarOverride, signal) {
51823
51842
  if (isAbortError(err)) {
51824
51843
  throw err;
51825
51844
  }
51826
- if (isAuthFailure(err)) {
51845
+ if (isAuthFailure(err) && siteSupportsLogin) {
51827
51846
  throw err;
51828
51847
  }
51829
51848
  }
@@ -51836,7 +51855,10 @@ async function attemptReplay(site, intent, param, jarOverride, signal) {
51836
51855
  persistTemplateBestEffort(site, intent, preseed);
51837
51856
  return { data, discovered: false };
51838
51857
  } catch (err) {
51839
- if (isAuthFailure(err) || isAbortError(err)) {
51858
+ if (isAbortError(err)) {
51859
+ throw err;
51860
+ }
51861
+ if (isAuthFailure(err) && siteSupportsLogin) {
51840
51862
  throw err;
51841
51863
  }
51842
51864
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgao/web-cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Self-discovering REST API CLI for subscription medical-knowledge sites, driven by an AI agent",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {