Files
Gergő Móriczandcapy-ai[bot] 6a658149c5 chore(api): adopt @cloudflare/oxlint-config and oxfmt, fix all violations, and enforce in CI [downstream-sync] (#6108)
* chore(api): add @cloudflare/oxlint-config and lint script

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): apply oxlint autofixes and remove unused ajv dependency

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): enable strictBindCallApply and narrow oxlint overrides

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): fix oxlint violations in core types and service runtime

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): fix oxlint violations in v2 request and document schemas

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): fix oxlint violations in lib, search, routes, harness, and tests

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): fix oxlint violations in controllers, services, and remaining lib files

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): fix oxlint violations in scraper modules and tests

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): migrate from prettier to oxfmt and format codebase

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* ci(api): enforce oxlint and oxfmt checks in core unit tests workflow

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): fix oxlint violations in merged transformer test

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): restore runtime behavior in routes, engines, hooks, fetch, and nuq-fdb test

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* refactor(api): replace hand-rolled object guards with Zod schemas and fix review findings

Replace isJsonObject, isPlainObject, isLogMeta, and local object-shape type
guards across apps/api with Zod v4 schemas (jsonValueSchema, jsonObjectSchema,
jsonRecordSchema, and domain-specific schemas), and address all review findings
including:
- Fail-closed socket inspection in safeFetch
- Corrupt FDB job dequeue handling and Redis script NOSCRIPT reload/recovery
- Express 5 function-typed app.router support and null-prototype hook dispatch
- Structured logger context across controllers, search, lib, and workers
- Shared NuQ decoders, agent-interop helpers, and prompt crawler option parsing
- Re-enable markdown formatting in .oxfmtrc.json

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): allow nested undefined in jsonRecordSchema and preserve Buffer file ref in request test

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(api): harden runtime Zod decoders for backwards-compatible payloads

Relax optional and nullable fields in Zod decoders for Redis, NuQ/FDB, crawl status, Wikimedia, and error metadata payloads so stored or legacy JSON entries with null or omitted fields remain backwards-compatible across rolling deploys, isolate FDB chunk decode errors, and avoid deep recursive validation of crawl status documents.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): address review findings across fetch, NuQ, and Zod decoders

Destroy undici clients instead of throwing inside the connect listener in safeFetch, cancel 429 response bodies in ddgsearch, restore strict CategoryInput literal union, harden NuQ FDB group metadata preservation and corrupt pending/delayed entry handling and slot promotion, log and rethrow corrupt FDB chunk decodes, normalize legacy nullish ScrapeJobData fields in nuq-decoders and explicitly fail undecodable locked RabbitMQ jobs, preserve partial v0 crawl metadata fields, enforce prompt delay bounds, accept null team_id in queueJobStore, use shallow object checks in crawl-redis, include jobId on scrape no-doc 500 responses, preserve nested undefined in logMetaSchema and jobLogJson, log unhealthy Redis health at warn level, and align snips schemas with failed crawl and nullable monitor credit responses.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): preserve custom search categories while keeping CategoryOption strict

Keep CategoryInput.type strictly narrowed to known literals in search-query-builder while preserving extension-contributed category strings in transformSearchRequest and narrowing before buildSearchQuery in search/execute.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): reconcile job state and crawl slot when dropping corrupt FDB delay entries

Export failCorruptPendingEntry with support for delayed ('dl') entries (without touching teamPendingCount or backlog timeouts) and call it from sweepDelayed so corrupt delay entries fail the job, release and promote its crawl slot, and update group accounting.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): address correctness audit findings and widen exported request contracts [downstream-sync]

Resolves runtime correctness, rolling-deploy safety, performance, and exported TypeScript contract issues identified during audit:

- Preserve required string arrays in normalizeSchemaForOpenAI, preserve mixed string/object search categories per element, validate prompt-generated delay > 60 in v2 crawl, and always run queue cleanup in crawl-cancel before returning 500 on saveCrawl failure.
- Fix recursive schema validation overhead in openai-strict-schema (O(n) structural walk after entry validation) and resolveRefs cycle/DAG bounds in jsonExtract, shallow log sanitization and direct JSON.parse typing in fetch.ts, and hoisted Zod schemas in service/defaults.ts.
- Restore transient lock-renewal retry behavior in queue-worker, nuq-worker-runner, and nuq-fdb-worker; normalize legacy numeric/boolean string fields in NuQ FDB group metadata, queue-jobs, concurrency-limit, and scrape-worker.
- Isolate corrupt NuQ FDB and NuQ PG job payload decoding on reads, reconcile job status/slots/ZDR data on corrupt ready and pending FDB entries, pass shared TxContext in sweeper pending promotions, and preserve ZDR log filtering on error paths.
- Preserve page-1 results on DDG 429, filter individual direct-quote indices in query transformer, preserve empty forced-engine arrays, and support RegExp/array Express route paths in http-metrics.
- Widen exported Express request params (Request["params"]), optional Express.Request.requestTiming fields, timingSafeCompareHeader IncomingHttpHeaders, StrictJsonValue for Document.extract/json/llm_extraction, JobCrawlerOptions.allowBackwardCrawling, MapRequest typing, and AuthorizeState.req.acuc.

Downstream-Sync: required
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): address review feedback on delay normalization, JSON parsing, and lazy schemas [downstream-sync]

Fixes the five review findings from the previous commit:

- Normalize numeric-string crawl delays consistently in both getNextConcurrentJob and concurrentJobDone via shared parseCrawlDelay helper.
- Reject non-finite numbers (such as 1e400 -> Infinity) inside parseJsonString via JSON.parse reviver so robustFetch preserves strict JSON guarantees.
- Keep service/defaults.ts free of top-level runtime imports by lazily caching queueJobStore's Zod schemas on first use and keeping queueJobStore's JSDoc directly on queueJobStore.
- Remove the redundant second parse and unreachable fallback branch in scrape-worker.ts getStoredCrawlerOptions.

Downstream-Sync: required
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(api): use iterative finiteness check in parseJsonString and infer lazy queueJobStore schema types [downstream-sync]

Addresses Cubic review feedback on afdabf153:

- Replace the recursive JSON.parse reviver in parseJsonString with an iterative stack walk rejecting non-finite numbers so deeply nested valid JSON (for example, 5,000 nested arrays) cannot overflow the call stack.
- Derive queueJobStore's cached lazy schema bundle type via ReturnType<typeof buildQueueJobStoreSchemas> with a type-only import of zod instead of duplicating hand-written schema interfaces.

Downstream-Sync: required
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* [downstream-sync] feat(api): add ZDR-safe rate-limited Zod mismatch logging

Adds src/lib/zod-log.ts with safeParseLogged and zCatchLogged helpers that emit rate-limited (1 per 60s per tag/code/path key, bounded at 500 keys), ZDR-safe warnings containing only sanitized path segments and issue codes (never raw inputs or Zod messages).

Wires mismatch logging across external, cached, and persisted payload decoders (Redis crawl state, NuQ Postgres/RabbitMQ/FoundationDB records, native Rust log bridge, LLM structured outputs, and queue job store) and schema .catch() fallbacks while leaving local type-narrowing predicates and HTTP 400 validators untouched.

Downstream-Sync: required
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* [downstream-sync] fix(api): harden zod-log path sanitization and throttle overflow

Walk the schema along each Zod issue path so only static z.object shape keys are logged verbatim, redacting dynamic z.record, catchall, and unrecognized keys to <key>.

Preserve active 60-second throttle entries when the 500-entry map fills by routing overflow keys through a rate-limited overflow bucket instead of evicting active keys.

Downstream-Sync: required
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-27 18:20:25 +01:00

196 lines
6.5 KiB
JSON

{
"name": "firecrawl-scraper-js",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"exports": {
".": {
"types": "./src/service/index.ts",
"default": "./dist/src/service/index.js"
},
"./config": {
"types": "./src/exports/config.ts",
"default": "./dist/src/exports/config.js"
},
"./crawl": {
"types": "./src/exports/crawl.ts",
"default": "./dist/src/exports/crawl.js"
},
"./errors": {
"types": "./src/exports/errors.ts",
"default": "./dist/src/exports/errors.js"
},
"./http": {
"types": "./src/exports/http.ts",
"default": "./dist/src/exports/http.js"
},
"./llm": {
"types": "./src/exports/llm.ts",
"default": "./dist/src/exports/llm.js"
},
"./logger": {
"types": "./src/exports/logger.ts",
"default": "./dist/src/exports/logger.js"
},
"./queue": {
"types": "./src/exports/queue.ts",
"default": "./dist/src/exports/queue.js"
},
"./redis": {
"types": "./src/exports/redis.ts",
"default": "./dist/src/exports/redis.js"
},
"./scrape": {
"types": "./src/exports/scrape.ts",
"default": "./dist/src/exports/scrape.js"
},
"./search": {
"types": "./src/exports/search.ts",
"default": "./dist/src/exports/search.js"
},
"./telemetry": {
"types": "./src/exports/telemetry.ts",
"default": "./dist/src/exports/telemetry.js"
},
"./testing": {
"types": "./src/service/testing.ts",
"default": "./dist/src/service/testing.js"
},
"./types": {
"types": "./src/exports/types.ts",
"default": "./dist/src/exports/types.js"
},
"./util": {
"types": "./src/exports/util.ts",
"default": "./dist/src/exports/util.js"
}
},
"scripts": {
"start": "tsc && node dist/src/main.js harness --start-built",
"dev": "tsx src/main.ts harness --start",
"server": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js api\"",
"server:production": "tsc && node dist/src/main.js api",
"server:production:nobuild": "node dist/src/main.js api",
"format": "oxfmt",
"format:check": "oxfmt --check",
"flyio": "node dist/src/main.js api",
"start:dev": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js api\"",
"build": "tsc",
"lint": "oxlint .",
"test": "vitest run",
"test:prod": "vitest run --exclude='**/scraper/scrapeURL/**'",
"test:snips": "vitest run src/__tests__/snips/v2",
"test:core": "vitest run --config vitest.core.config.ts",
"harness": "tsx src/main.ts harness",
"workers": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js queue-worker\"",
"worker:production": "node dist/src/main.js queue-worker",
"nuq-worker": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js nuq-worker\"",
"nuq-worker:production": "node dist/src/main.js nuq-worker",
"nuq-fdb-worker": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js nuq-fdb-worker\"",
"nuq-fdb-worker:production": "node dist/src/main.js nuq-fdb-worker",
"nuq-prefetch-worker": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js nuq-prefetch-worker\"",
"nuq-prefetch-worker:production": "node dist/src/main.js nuq-prefetch-worker",
"nuq-reconciler-worker": "tsc-watch --compiler ./node_modules/typescript-7/bin/tsc --onSuccess \"node dist/src/main.js nuq-reconciler-worker\"",
"nuq-reconciler-worker:production": "node dist/src/main.js nuq-reconciler-worker",
"prepare": "cd ../.. && husky ./apps/api/.husky",
"knip": "knip"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@cloudflare/oxlint-config": "^0.2.0",
"@types/amqplib": "^0.10.7",
"@types/body-parser": "^1.19.2",
"@types/cors": "^2.8.13",
"@types/escape-html": "^1.0.4",
"@types/express": "^5.0.6",
"@types/express-ws": "^3.0.6",
"@types/he": "^1.2.3",
"@types/multer": "^2.1.0",
"@types/node": "^22.19.1",
"@types/pdf-parse": "^1.1.4",
"@types/pg": "^8.15.5",
"@types/supertest": "^6.0.2",
"@types/tough-cookie": "^4.0.5",
"husky": "^9.1.7",
"knip": "^6.40.0",
"lint-staged": "^16.4.0",
"oxfmt": "^0.80.0",
"oxlint": "^1.95.0",
"supertest": "^6.3.3",
"tsc-watch": "^7.1.1",
"tsrs": "^7.1.0-beta.tsrs5",
"tsx": "^4.20.3",
"undici-types": "^7.16.0",
"vitest": "^4.1.12"
},
"dependencies": {
"@ai-sdk/openai": "4.0.118",
"@ai-sdk/otel": "^1.0.173",
"@ai-sdk/xai": "^5.0.46",
"@bull-board/api": "^6.21.3",
"@bull-board/express": "^6.21.3",
"@dqbd/tiktoken": "^1.0.22",
"@mendable/firecrawl-rs": "workspace:*",
"@opentelemetry/api": "^1.9.1",
"@opentelemetry/exporter-trace-otlp-proto": "^0.222.0",
"@opentelemetry/resources": "^2.11.0",
"@opentelemetry/sdk-trace-node": "^2.11.0",
"@opentelemetry/semantic-conventions": "^1.43.0",
"@types/ws": "^8.5.12",
"ai": "7.0.173",
"amqplib": "^0.10.9",
"async-mutex": "^0.5.0",
"axios": "^1.20.0",
"body-parser": "^1.20.9",
"bullmq": "^5.56.7",
"cacheable-lookup": "^6.1.0",
"cheerio": "^1.0.0-rc.12",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"escape-html": "^1.0.3",
"express": "5.2.1",
"express-ws": "^5.0.2",
"foundationdb": "^2.0.1",
"geoip-country": "^5.0.202608010109",
"he": "^1.2.0",
"http-cookie-agent": "^7.0.1",
"ioredis": "^5.6.1",
"ipaddr.js": "^2.2.0",
"joplin-turndown-plugin-gfm": "^1.0.12",
"jsdom": "^29.1.1",
"koffi": "^2.9.0",
"marked": "^14.1.2",
"multer": "^2.5.0",
"ollama-ai-provider-v2": "^4.1.0",
"pdf-parse": "^1.1.1",
"pg": "^8.16.3",
"prom-client": "^15.1.3",
"redlock": "5.0.0-beta.2",
"response-time": "^2.3.4",
"robots-parser": "^3.0.1",
"tldts": "^7.4.10",
"tough-cookie": "^4.1.4",
"turndown": "^7.1.3",
"typescript": "npm:@typescript/typescript6@6.0.2",
"typescript-7": "npm:typescript@7.0.2",
"undici": "7.30.1",
"uuid": "^13.0.1",
"winston": "^3.14.2",
"ws": "^8.21.0",
"xml2js": "^0.6.2",
"zod": "4.6.7"
},
"nodemonConfig": {
"ignore": [
"*.docx",
"*.json",
"temp"
]
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css,md}": "oxfmt --no-error-on-unmatched-pattern"
},
"packageManager": "pnpm@11.4.0"
}