@detiq/crawler 0.2.14 → 1.0.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/dist/crawler.js CHANGED
@@ -3,7 +3,7 @@ import { chromium } from "rebrowser-playwright-core";
3
3
  import { chromium as stealthChromium } from "playwright-extra";
4
4
  import StealthPlugin from "puppeteer-extra-plugin-stealth";
5
5
  import { execSync } from "node:child_process";
6
- import { readFileSync } from "node:fs";
6
+ import { readFileSync, existsSync as existsSyncFs } from "node:fs";
7
7
  import { createRequire } from "node:module";
8
8
  stealthChromium.use(StealthPlugin());
9
9
  import { z } from "zod";
@@ -316,6 +316,7 @@ async function crawlProject(opts, onProgress) {
316
316
  if (opts.screenshotDir) await fs.mkdir(opts.screenshotDir, { recursive: true });
317
317
  const uploadToCloud = async (localPath, key) => {
318
318
  if (!opts.storageConfig) return void 0;
319
+ if (!existsSyncFs(localPath)) return void 0;
319
320
  try {
320
321
  const { uploadScreenshotToTenantStorage } = await import("@detiq/app-brain");
321
322
  return await uploadScreenshotToTenantStorage(opts.storageConfig, localPath, key);
@@ -1024,7 +1025,7 @@ async function crawlProject(opts, onProgress) {
1024
1025
  }
1025
1026
  let checkpointSuccessCount = 0;
1026
1027
  let maxSeenTotal = 0;
1027
- let lastEmittedPct = 5;
1028
+ let lastEmittedPct = 20;
1028
1029
  const crawlLoopStart = Date.now();
1029
1030
  const startUrl = page.url();
1030
1031
  const resumeUrls = opts.resumeUrls ?? [];
@@ -1426,7 +1427,7 @@ async function crawlProject(opts, onProgress) {
1426
1427
  throw new Error("[AUTH_FAILURE] Re-authentication failed. Session is unrecoverable. Re-capture the session in project settings and retry the crawl.");
1427
1428
  }
1428
1429
  } else {
1429
- logger.warn("[crawler] Session expired mid-crawl, no credentials to recover \u2014 stopping BFS");
1430
+ logger.warn("[crawler] Session expired mid-crawl, no credentials to recover \u2014 skipping URL");
1430
1431
  AppBrain.saveCrawlEvidence(opts.tenantId, opts.projectId, {
1431
1432
  jobId: opts.jobId,
1432
1433
  type: "AUTH_FAILURE",
@@ -3661,15 +3662,17 @@ async function captureAuthDiscoveryScreen(page, opts, requestedUrl, source, ordi
3661
3662
  const screen = await AppBrain.saveScreen(opts.tenantId, opts.projectId, name, screenUrl, opts.jobId, source === "entry" ? "ENTRY_POINT" : "SEED_URL").catch(() => null);
3662
3663
  if (!screen) return { captured: false, finalUrl, flowType };
3663
3664
  let authCloudUrl;
3664
- if (opts.storageConfig) {
3665
+ if (opts.storageConfig && existsSyncFs(shotPath)) {
3665
3666
  try {
3666
3667
  const { uploadScreenshotToTenantStorage } = await import("@detiq/app-brain");
3667
3668
  authCloudUrl = await uploadScreenshotToTenantStorage(opts.storageConfig, shotPath, `${opts.tenantId}/${opts.projectId}/screenshots/${path.basename(shotPath)}`);
3668
3669
  } catch {
3669
3670
  }
3670
3671
  }
3671
- await AppBrain.saveScreenshot(opts.tenantId, opts.projectId, screen.id, shotPath, screen.version, "DESKTOP", authCloudUrl).catch(() => {
3672
- });
3672
+ if (existsSyncFs(shotPath)) {
3673
+ await AppBrain.saveScreenshot(opts.tenantId, opts.projectId, screen.id, shotPath, screen.version, "DESKTOP", authCloudUrl).catch(() => {
3674
+ });
3675
+ }
3673
3676
  await AppBrain.saveCrawlEvidence(opts.tenantId, opts.projectId, {
3674
3677
  screenId: screen.id,
3675
3678
  jobId: opts.jobId,