lazyscout 0.4.5 → 0.4.6

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/index.js CHANGED
@@ -4464,7 +4464,7 @@ async function browserProfileStatus(root, projectId) {
4464
4464
  }
4465
4465
  async function clearBrowserProfile(root, projectId) {
4466
4466
  const directory = join3(projectDirectory(root, projectId), "browser-profile");
4467
- await rm3(directory, { recursive: true, force: true });
4467
+ await rm3(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 150 });
4468
4468
  }
4469
4469
  async function readProject(root, projectId) {
4470
4470
  try {
@@ -5507,6 +5507,16 @@ function registerVersionRoutes(app, currentVersion) {
5507
5507
  // ../server/dist/routes/workspace.js
5508
5508
  import { dirname as dirname8 } from "node:path";
5509
5509
  var authSessions = /* @__PURE__ */ new Map();
5510
+ async function abandonLoginSession(projectId, log) {
5511
+ const active = authSessions.get(projectId);
5512
+ if (!active)
5513
+ return false;
5514
+ authSessions.delete(projectId);
5515
+ await active.launched.close().catch(() => void 0);
5516
+ await active.release().catch(() => void 0);
5517
+ log?.("[Auth] Sign-in window abandoned, profile released");
5518
+ return true;
5519
+ }
5510
5520
  async function projectPath(root, projectId) {
5511
5521
  return dirname8(await browserProfileDirectory(root, projectId));
5512
5522
  }
@@ -5537,25 +5547,37 @@ function registerWorkspaceRoutes(app, root) {
5537
5547
  const { projectId } = request.params;
5538
5548
  const projectDirectory2 = await projectPath(root, projectId);
5539
5549
  const log = (message) => request.log.info(message);
5550
+ await abandonLoginSession(projectId, log);
5540
5551
  let release;
5541
5552
  try {
5542
5553
  release = await acquireAuthLock(projectDirectory2, "login-browser", { log });
5543
5554
  } catch (error) {
5544
5555
  if (error instanceof AuthProfileBusyError)
5545
5556
  return reply.status(409).send({
5546
- error: { code: error.code, message: error.message, hint: "Close the other LazyScout browser and try again." }
5557
+ error: {
5558
+ code: error.code,
5559
+ message: error.message,
5560
+ hint: "Wait for it to finish, or press Cancel sign-in to release it."
5561
+ }
5547
5562
  });
5548
5563
  throw error;
5549
5564
  }
5550
- const headless = config.headless;
5565
+ const headless = false;
5551
5566
  const launched = await launchBrowser({ userDataDir: await browserProfileDirectory(root, projectId), headless });
5552
5567
  const page = launched.context.pages()[0] ?? await launched.context.newPage();
5553
5568
  await page.goto(check.url.toString(), { waitUntil: "domcontentloaded" });
5554
5569
  await updateAuthMeta(projectDirectory2, { status: "verifying", detail: "Waiting for the sign-in window to close" });
5555
5570
  authSessions.set(projectId, { launched, release, headless, projectDirectory: projectDirectory2 });
5571
+ launched.context.once("close", () => {
5572
+ void abandonLoginSession(projectId, log);
5573
+ });
5556
5574
  log("[Auth] Login browser opened");
5557
5575
  return reply.send({ opened: true, headless });
5558
5576
  });
5577
+ app.delete("/api/workspace/projects/:projectId/auth-session/login-browser", async (request, reply) => {
5578
+ const released = await abandonLoginSession(request.params.projectId, (message) => request.log.info(message));
5579
+ return reply.send({ released });
5580
+ });
5559
5581
  app.post("/api/workspace/projects/:projectId/auth-session/capture", async (request, reply) => {
5560
5582
  const { projectId } = request.params;
5561
5583
  const active = authSessions.get(projectId);
@@ -5564,22 +5586,27 @@ function registerWorkspaceRoutes(app, root) {
5564
5586
  error: { code: "no-login-browser", message: "Open the login browser before capturing a session." }
5565
5587
  });
5566
5588
  const log = (message) => request.log.info(message);
5589
+ let meta;
5590
+ let failure;
5567
5591
  try {
5568
5592
  log("[Auth] Recorded login completed");
5569
5593
  const page = active.launched.context.pages().find((candidate) => !candidate.isClosed());
5570
5594
  await waitForAuthSettle(active.launched.context, page, { log });
5571
5595
  const { snapshot, indexedDb } = await captureAuthSnapshot(active.launched.context, { log });
5572
- const meta = await saveAuthSnapshot(active.projectDirectory, snapshot, {
5596
+ meta = await saveAuthSnapshot(active.projectDirectory, snapshot, {
5573
5597
  indexedDb,
5574
5598
  capturedHeadless: active.headless,
5575
5599
  log
5576
5600
  });
5577
- return reply.send(meta);
5578
- } finally {
5579
- authSessions.delete(projectId);
5580
- await active.launched.close().catch(() => void 0);
5581
- await active.release().catch(() => void 0);
5601
+ } catch (error) {
5602
+ failure = error;
5582
5603
  }
5604
+ authSessions.delete(projectId);
5605
+ await active.launched.close().catch(() => void 0);
5606
+ await active.release().catch(() => void 0);
5607
+ if (failure)
5608
+ throw failure;
5609
+ return reply.send(meta);
5583
5610
  });
5584
5611
  app.get("/api/workspace/projects/:projectId/auth-session/status", async (request) => {
5585
5612
  const { projectId } = request.params;
@@ -5592,6 +5619,9 @@ function registerWorkspaceRoutes(app, root) {
5592
5619
  // and never means the login still works.
5593
5620
  profile: await browserProfileStatus(root, projectId),
5594
5621
  lockedBy: lock?.holder,
5622
+ // Whether a sign-in window is still open and waiting to be captured.
5623
+ // Held on the server so closing and reopening the dialog does not lose it.
5624
+ loginBrowserOpen: authSessions.has(projectId),
5595
5625
  executionHeadless: config.headless,
5596
5626
  // A snapshot taken in a different browser mode can be rejected by an app
5597
5627
  // that binds a session to the browser it was issued to.
@@ -5644,9 +5674,18 @@ function registerWorkspaceRoutes(app, root) {
5644
5674
  });
5645
5675
  app.delete("/api/workspace/projects/:projectId/auth-session", async (request, reply) => {
5646
5676
  const { projectId } = request.params;
5647
- await clearBrowserProfile(root, projectId);
5677
+ const log = (message) => request.log.info(message);
5678
+ await abandonLoginSession(projectId, log);
5648
5679
  await clearAuthSnapshot(await projectPath(root, projectId));
5649
- return reply.send({ cleared: true });
5680
+ const profileRemoved = await clearBrowserProfile(root, projectId).then(() => true).catch(() => false);
5681
+ log("[Auth] Session cleared");
5682
+ return reply.send({
5683
+ cleared: true,
5684
+ profileRemoved,
5685
+ ...profileRemoved ? {} : {
5686
+ detail: "The saved session was removed. Some browser profile files were still in use and were left behind; they are replaced on the next sign-in."
5687
+ }
5688
+ });
5650
5689
  });
5651
5690
  app.get("/api/workspace/projects/:projectId/screenshots", async (request) => readScreenshots(root, request.params.projectId));
5652
5691
  app.post("/api/workspace/projects/:projectId/screenshots", async (request) => saveScreenshot(root, request.params.projectId, request.body));
@@ -6116,7 +6155,7 @@ async function openInBrowser(url) {
6116
6155
  }
6117
6156
 
6118
6157
  // src/version.ts
6119
- var VERSION = true ? "0.4.5" : "0.0.0-dev";
6158
+ var VERSION = true ? "0.4.6" : "0.0.0-dev";
6120
6159
 
6121
6160
  // src/commands/serve.ts
6122
6161
  var DEFAULT_PORT = 4321;