@taodigital/crawler 0.0.0-stage → 1.2.1
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/Dockerfile +82 -0
- package/README.md +10 -2
- package/dist/accessibility-auditor.d.ts +29 -0
- package/dist/accessibility-auditor.js +57 -0
- package/dist/accessibility-auditor.js.map +7 -0
- package/dist/accessibility-tree-crawler.d.ts +44 -0
- package/dist/accessibility-tree-crawler.js +156 -0
- package/dist/accessibility-tree-crawler.js.map +7 -0
- package/dist/advanced-ui-probes.d.ts +47 -0
- package/dist/advanced-ui-probes.js +310 -0
- package/dist/advanced-ui-probes.js.map +7 -0
- package/dist/ai-login.d.ts +32 -0
- package/dist/ai-login.js +250 -0
- package/dist/ai-login.js.map +7 -0
- package/dist/auth-token-rotator.d.ts +47 -0
- package/dist/auth-token-rotator.js +58 -0
- package/dist/auth-token-rotator.js.map +7 -0
- package/dist/auth.d.ts +20 -0
- package/dist/auth.js +348 -0
- package/dist/auth.js.map +7 -0
- package/dist/browser-extension.d.ts +37 -0
- package/dist/browser-extension.js +113 -0
- package/dist/browser-extension.js.map +7 -0
- package/dist/captcha-solver.d.ts +16 -0
- package/dist/captcha-solver.js +105 -0
- package/dist/captcha-solver.js.map +7 -0
- package/dist/color-contrast.d.ts +30 -0
- package/dist/color-contrast.js +78 -0
- package/dist/color-contrast.js.map +7 -0
- package/dist/content-chunker.d.ts +18 -0
- package/dist/content-chunker.js +152 -0
- package/dist/content-chunker.js.map +7 -0
- package/dist/content-dedup.d.ts +23 -0
- package/dist/content-dedup.js +60 -0
- package/dist/content-dedup.js.map +7 -0
- package/dist/cookie-consent.d.ts +25 -0
- package/dist/cookie-consent.js +78 -0
- package/dist/cookie-consent.js.map +7 -0
- package/dist/cookie-jar.d.ts +20 -0
- package/dist/cookie-jar.js +61 -0
- package/dist/cookie-jar.js.map +7 -0
- package/dist/crawl-session-manager.d.ts +44 -0
- package/dist/crawl-session-manager.js +145 -0
- package/dist/crawl-session-manager.js.map +7 -0
- package/dist/crawler.d.ts +233 -0
- package/dist/crawler.js +6239 -0
- package/dist/crawler.js.map +7 -0
- package/dist/crud-interaction.d.ts +31 -0
- package/dist/crud-interaction.js +264 -0
- package/dist/crud-interaction.js.map +7 -0
- package/dist/custom-js-injector.d.ts +42 -0
- package/dist/custom-js-injector.js +50 -0
- package/dist/custom-js-injector.js.map +7 -0
- package/dist/dark-mode-capture.d.ts +23 -0
- package/dist/dark-mode-capture.js +75 -0
- package/dist/dark-mode-capture.js.map +7 -0
- package/dist/dead-link-detector.d.ts +37 -0
- package/dist/dead-link-detector.js +50 -0
- package/dist/dead-link-detector.js.map +7 -0
- package/dist/dropdown-enumerator.d.ts +20 -0
- package/dist/dropdown-enumerator.js +230 -0
- package/dist/dropdown-enumerator.js.map +7 -0
- package/dist/element-hash.d.ts +9 -0
- package/dist/element-hash.js +9 -0
- package/dist/element-hash.js.map +7 -0
- package/dist/email-otp.d.ts +42 -0
- package/dist/email-otp.js +177 -0
- package/dist/email-otp.js.map +7 -0
- package/dist/engine-router.d.ts +47 -0
- package/dist/engine-router.js +94 -0
- package/dist/engine-router.js.map +7 -0
- package/dist/export/bulk-export.d.ts +26 -0
- package/dist/export/bulk-export.js +76 -0
- package/dist/export/bulk-export.js.map +7 -0
- package/dist/export/vector-export.d.ts +76 -0
- package/dist/export/vector-export.js +85 -0
- package/dist/export/vector-export.js.map +7 -0
- package/dist/extractors/advanced.d.ts +64 -0
- package/dist/extractors/advanced.js +265 -0
- package/dist/extractors/advanced.js.map +7 -0
- package/dist/extractors/artifact-envelope.d.ts +63 -0
- package/dist/extractors/artifact-envelope.js +63 -0
- package/dist/extractors/artifact-envelope.js.map +7 -0
- package/dist/extractors/branding-extractor.d.ts +46 -0
- package/dist/extractors/branding-extractor.js +104 -0
- package/dist/extractors/branding-extractor.js.map +7 -0
- package/dist/extractors/summary-extractor.d.ts +10 -0
- package/dist/extractors/summary-extractor.js +36 -0
- package/dist/extractors/summary-extractor.js.map +7 -0
- package/dist/failure-analysis-agent.d.ts +16 -0
- package/dist/failure-analysis-agent.js +42 -0
- package/dist/failure-analysis-agent.js.map +7 -0
- package/dist/feature-flag-detector.d.ts +30 -0
- package/dist/feature-flag-detector.js +55 -0
- package/dist/feature-flag-detector.js.map +7 -0
- package/dist/filter-pagination-crawler.d.ts +52 -0
- package/dist/filter-pagination-crawler.js +299 -0
- package/dist/filter-pagination-crawler.js.map +7 -0
- package/dist/form-detector.d.ts +34 -0
- package/dist/form-detector.js +58 -0
- package/dist/form-detector.js.map +7 -0
- package/dist/frontier.d.ts +40 -0
- package/dist/frontier.js +103 -0
- package/dist/frontier.js.map +7 -0
- package/dist/gap-pass.d.ts +36 -0
- package/dist/gap-pass.js +115 -0
- package/dist/gap-pass.js.map +7 -0
- package/dist/graphql-detector.d.ts +39 -0
- package/dist/graphql-detector.js +86 -0
- package/dist/graphql-detector.js.map +7 -0
- package/dist/http-engine.d.ts +80 -0
- package/dist/http-engine.js +318 -0
- package/dist/http-engine.js.map +7 -0
- package/dist/incremental-diff.d.ts +116 -0
- package/dist/incremental-diff.js +137 -0
- package/dist/incremental-diff.js.map +7 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +7 -0
- package/dist/input-fuzzer.d.ts +30 -0
- package/dist/input-fuzzer.js +105 -0
- package/dist/input-fuzzer.js.map +7 -0
- package/dist/interactive-probe.d.ts +144 -0
- package/dist/interactive-probe.js +865 -0
- package/dist/interactive-probe.js.map +7 -0
- package/dist/job-queue.d.ts +297 -0
- package/dist/job-queue.js +3812 -0
- package/dist/job-queue.js.map +7 -0
- package/dist/js-coverage.d.ts +29 -0
- package/dist/js-coverage.js +56 -0
- package/dist/js-coverage.js.map +7 -0
- package/dist/js-router-detector.d.ts +17 -0
- package/dist/js-router-detector.js +90 -0
- package/dist/js-router-detector.js.map +7 -0
- package/dist/language-detector.d.ts +22 -0
- package/dist/language-detector.js +57 -0
- package/dist/language-detector.js.map +7 -0
- package/dist/link-classifier.d.ts +23 -0
- package/dist/link-classifier.js +40 -0
- package/dist/link-classifier.js.map +7 -0
- package/dist/live-view.d.ts +36 -0
- package/dist/live-view.js +105 -0
- package/dist/live-view.js.map +7 -0
- package/dist/locator-extractor.d.ts +46 -0
- package/dist/locator-extractor.js +220 -0
- package/dist/locator-extractor.js.map +7 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +10 -0
- package/dist/logger.js.map +7 -0
- package/dist/markdown-extract.d.ts +8 -0
- package/dist/markdown-extract.js +54 -0
- package/dist/markdown-extract.js.map +7 -0
- package/dist/multi-context-handler.d.ts +55 -0
- package/dist/multi-context-handler.js +182 -0
- package/dist/multi-context-handler.js.map +7 -0
- package/dist/native-crawler.d.ts +69 -0
- package/dist/native-crawler.js +839 -0
- package/dist/native-crawler.js.map +7 -0
- package/dist/nested-window-crawler.d.ts +41 -0
- package/dist/nested-window-crawler.js +172 -0
- package/dist/nested-window-crawler.js.map +7 -0
- package/dist/network-action-correlator.d.ts +47 -0
- package/dist/network-action-correlator.js +209 -0
- package/dist/network-action-correlator.js.map +7 -0
- package/dist/network-observer.d.ts +49 -0
- package/dist/network-observer.js +149 -0
- package/dist/network-observer.js.map +7 -0
- package/dist/network-throttle.d.ts +25 -0
- package/dist/network-throttle.js +34 -0
- package/dist/network-throttle.js.map +7 -0
- package/dist/openapi-generator.d.ts +49 -0
- package/dist/openapi-generator.js +89 -0
- package/dist/openapi-generator.js.map +7 -0
- package/dist/pdf-extractor.d.ts +28 -0
- package/dist/pdf-extractor.js +81 -0
- package/dist/pdf-extractor.js.map +7 -0
- package/dist/performance-metrics-collector.d.ts +50 -0
- package/dist/performance-metrics-collector.js +155 -0
- package/dist/performance-metrics-collector.js.map +7 -0
- package/dist/performance-metrics.d.ts +52 -0
- package/dist/performance-metrics.js +83 -0
- package/dist/performance-metrics.js.map +7 -0
- package/dist/phash.d.ts +50 -0
- package/dist/phash.js +136 -0
- package/dist/phash.js.map +7 -0
- package/dist/pii-scrubber.d.ts +21 -0
- package/dist/pii-scrubber.js +75 -0
- package/dist/pii-scrubber.js.map +7 -0
- package/dist/playwright-recorder.d.ts +39 -0
- package/dist/playwright-recorder.js +123 -0
- package/dist/playwright-recorder.js.map +7 -0
- package/dist/policies/crawl-safety.d.ts +9 -0
- package/dist/policies/crawl-safety.js +41 -0
- package/dist/policies/crawl-safety.js.map +7 -0
- package/dist/profiles/domain-profile.d.ts +19 -0
- package/dist/profiles/domain-profile.js +160 -0
- package/dist/profiles/domain-profile.js.map +7 -0
- package/dist/proxy.d.ts +50 -0
- package/dist/proxy.js +165 -0
- package/dist/proxy.js.map +7 -0
- package/dist/rate-limiter.d.ts +31 -0
- package/dist/rate-limiter.js +64 -0
- package/dist/rate-limiter.js.map +7 -0
- package/dist/redirect-tracker.d.ts +37 -0
- package/dist/redirect-tracker.js +65 -0
- package/dist/redirect-tracker.js.map +7 -0
- package/dist/redis-frontier.d.ts +48 -0
- package/dist/redis-frontier.js +126 -0
- package/dist/redis-frontier.js.map +7 -0
- package/dist/redis-queue.d.ts +48 -0
- package/dist/redis-queue.js +165 -0
- package/dist/redis-queue.js.map +7 -0
- package/dist/response-cache.d.ts +38 -0
- package/dist/response-cache.js +140 -0
- package/dist/response-cache.js.map +7 -0
- package/dist/responsive-detector.d.ts +29 -0
- package/dist/responsive-detector.js +46 -0
- package/dist/responsive-detector.js.map +7 -0
- package/dist/retry-policy.d.ts +20 -0
- package/dist/retry-policy.js +54 -0
- package/dist/retry-policy.js.map +7 -0
- package/dist/robots-txt.d.ts +9 -0
- package/dist/robots-txt.js +77 -0
- package/dist/robots-txt.js.map +7 -0
- package/dist/screen-reader.d.ts +15 -0
- package/dist/screen-reader.js +48 -0
- package/dist/screen-reader.js.map +7 -0
- package/dist/screenshot-masker.d.ts +28 -0
- package/dist/screenshot-masker.js +62 -0
- package/dist/screenshot-masker.js.map +7 -0
- package/dist/seo-checker.d.ts +33 -0
- package/dist/seo-checker.js +91 -0
- package/dist/seo-checker.js.map +7 -0
- package/dist/service-worker-interceptor.d.ts +36 -0
- package/dist/service-worker-interceptor.js +136 -0
- package/dist/service-worker-interceptor.js.map +7 -0
- package/dist/session-capture.d.ts +39 -0
- package/dist/session-capture.js +274 -0
- package/dist/session-capture.js.map +7 -0
- package/dist/session-export.d.ts +49 -0
- package/dist/session-export.js +117 -0
- package/dist/session-export.js.map +7 -0
- package/dist/shadow-dom-crawler.d.ts +35 -0
- package/dist/shadow-dom-crawler.js +132 -0
- package/dist/shadow-dom-crawler.js.map +7 -0
- package/dist/sitemap-writer.d.ts +21 -0
- package/dist/sitemap-writer.js +47 -0
- package/dist/sitemap-writer.js.map +7 -0
- package/dist/sitemap.d.ts +51 -0
- package/dist/sitemap.js +160 -0
- package/dist/sitemap.js.map +7 -0
- package/dist/skyvern.d.ts +56 -0
- package/dist/skyvern.js +129 -0
- package/dist/skyvern.js.map +7 -0
- package/dist/sqs-queue.d.ts +13 -0
- package/dist/sqs-queue.js +115 -0
- package/dist/sqs-queue.js.map +7 -0
- package/dist/sso-token.d.ts +29 -0
- package/dist/sso-token.js +76 -0
- package/dist/sso-token.js.map +7 -0
- package/dist/state-graph.d.ts +59 -0
- package/dist/state-graph.js +193 -0
- package/dist/state-graph.js.map +7 -0
- package/dist/stealth/human-behavior.d.ts +20 -0
- package/dist/stealth/human-behavior.js +202 -0
- package/dist/stealth/human-behavior.js.map +7 -0
- package/dist/telemetry.d.ts +34 -0
- package/dist/telemetry.js +77 -0
- package/dist/telemetry.js.map +7 -0
- package/dist/test-executor.d.ts +81 -0
- package/dist/test-executor.js +443 -0
- package/dist/test-executor.js.map +7 -0
- package/dist/tls-fingerprint.d.ts +50 -0
- package/dist/tls-fingerprint.js +81 -0
- package/dist/tls-fingerprint.js.map +7 -0
- package/dist/url-pattern-completer.d.ts +28 -0
- package/dist/url-pattern-completer.js +122 -0
- package/dist/url-pattern-completer.js.map +7 -0
- package/dist/visual-diff-verdict.d.ts +40 -0
- package/dist/visual-diff-verdict.js +27 -0
- package/dist/visual-diff-verdict.js.map +7 -0
- package/dist/webhook-notifier.d.ts +30 -0
- package/dist/webhook-notifier.js +76 -0
- package/dist/webhook-notifier.js.map +7 -0
- package/dist/websocket-detector.d.ts +24 -0
- package/dist/websocket-detector.js +60 -0
- package/dist/websocket-detector.js.map +7 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +33 -0
- package/dist/worker.js.map +7 -0
- package/package.json +49 -4
- package/src/accessibility-auditor.ts +102 -0
- package/src/accessibility-tree-crawler.ts +246 -0
- package/src/advanced-ui-probes.ts +470 -0
- package/src/ai-login.ts +298 -0
- package/src/auth-token-rotator.ts +89 -0
- package/src/auth.ts +418 -0
- package/src/browser-extension.ts +186 -0
- package/src/captcha-solver.ts +143 -0
- package/src/color-contrast.ts +116 -0
- package/src/content-chunker.ts +170 -0
- package/src/content-dedup.ts +99 -0
- package/src/cookie-consent.ts +106 -0
- package/src/cookie-jar.ts +91 -0
- package/src/crawl-session-manager.ts +231 -0
- package/src/crawler.ts +7123 -0
- package/src/crawler.ts.rej +12 -0
- package/src/crud-interaction.ts +386 -0
- package/src/custom-js-injector.ts +93 -0
- package/src/dark-mode-capture.ts +110 -0
- package/src/dead-link-detector.ts +76 -0
- package/src/dropdown-enumerator.ts +312 -0
- package/src/element-hash.ts +16 -0
- package/src/email-otp.ts +252 -0
- package/src/engine-router.ts +141 -0
- package/src/export/bulk-export.ts +85 -0
- package/src/export/vector-export.ts +160 -0
- package/src/extractors/advanced.ts +309 -0
- package/src/extractors/artifact-envelope.ts +111 -0
- package/src/extractors/branding-extractor.ts +159 -0
- package/src/extractors/summary-extractor.ts +49 -0
- package/src/failure-analysis-agent.ts +51 -0
- package/src/feature-flag-detector.ts +97 -0
- package/src/filter-pagination-crawler.ts +500 -0
- package/src/form-detector.ts +103 -0
- package/src/frontier.test.ts +64 -0
- package/src/frontier.ts +144 -0
- package/src/gap-pass.ts +165 -0
- package/src/graphql-detector.ts +129 -0
- package/src/http-engine.ts +453 -0
- package/src/incremental-diff.ts +259 -0
- package/src/index.ts +52 -0
- package/src/input-fuzzer.ts +129 -0
- package/src/interactive-probe.ts +1136 -0
- package/src/job-queue.test.ts +187 -0
- package/src/job-queue.ts +4504 -0
- package/src/js-coverage.ts +87 -0
- package/src/js-router-detector.ts +112 -0
- package/src/language-detector.ts +82 -0
- package/src/link-classifier.ts +65 -0
- package/src/live-view.ts +146 -0
- package/src/locator-extractor.ts +309 -0
- package/src/logger.ts +9 -0
- package/src/markdown-extract.test.ts +73 -0
- package/src/markdown-extract.ts +76 -0
- package/src/multi-context-handler.ts +296 -0
- package/src/native-crawler.ts +1108 -0
- package/src/nested-window-crawler.ts +310 -0
- package/src/network-action-correlator.ts +320 -0
- package/src/network-observer.ts +204 -0
- package/src/network-throttle.ts +69 -0
- package/src/openapi-generator.ts +135 -0
- package/src/pdf-extractor.ts +123 -0
- package/src/performance-metrics-collector.ts +243 -0
- package/src/performance-metrics.ts +134 -0
- package/src/phash.ts +184 -0
- package/src/pii-scrubber.ts +99 -0
- package/src/playwright-recorder.ts +170 -0
- package/src/policies/crawl-safety.ts +52 -0
- package/src/profiles/domain-profile.ts +190 -0
- package/src/proxy.ts +238 -0
- package/src/rate-limiter.ts +87 -0
- package/src/redirect-tracker.ts +97 -0
- package/src/redis-frontier.ts +143 -0
- package/src/redis-queue.ts +208 -0
- package/src/response-cache.ts +150 -0
- package/src/responsive-detector.ts +92 -0
- package/src/retry-policy.ts +87 -0
- package/src/robots-txt.ts +96 -0
- package/src/screen-reader.ts +98 -0
- package/src/screenshot-masker.ts +98 -0
- package/src/seo-checker.ts +134 -0
- package/src/service-worker-interceptor.ts +185 -0
- package/src/session-capture.ts +335 -0
- package/src/session-export.test.ts +75 -0
- package/src/session-export.ts +172 -0
- package/src/shadow-dom-crawler.ts +198 -0
- package/src/sitemap-writer.ts +65 -0
- package/src/sitemap.test.ts +127 -0
- package/src/sitemap.ts +233 -0
- package/src/skyvern.ts +199 -0
- package/src/sqs-queue.ts +129 -0
- package/src/sso-token.ts +120 -0
- package/src/state-graph.ts +280 -0
- package/src/stealth/human-behavior.ts +227 -0
- package/src/telemetry.ts +122 -0
- package/src/test-executor.test.ts +72 -0
- package/src/test-executor.ts +578 -0
- package/src/tls-fingerprint.ts +111 -0
- package/src/url-pattern-completer.ts +161 -0
- package/src/vendor.d.ts +20 -0
- package/src/visual-diff-verdict.test.ts +80 -0
- package/src/visual-diff-verdict.ts +59 -0
- package/src/webhook-notifier.ts +109 -0
- package/src/websocket-detector.ts +83 -0
- package/src/worker.ts +50 -0
- package/tsconfig.json +13 -0
- package/types/accessibility-auditor.d.ts +29 -0
- package/types/accessibility-tree-crawler.d.ts +44 -0
- package/types/advanced-ui-probes.d.ts +47 -0
- package/types/ai-login.d.ts +32 -0
- package/types/auth-token-rotator.d.ts +47 -0
- package/types/auth.d.ts +20 -0
- package/types/browser-extension.d.ts +37 -0
- package/types/bull-worker.d.ts +6 -0
- package/types/captcha-solver.d.ts +16 -0
- package/types/color-contrast.d.ts +30 -0
- package/types/content-chunker.d.ts +18 -0
- package/types/content-dedup.d.ts +23 -0
- package/types/cookie-consent.d.ts +25 -0
- package/types/cookie-jar.d.ts +20 -0
- package/types/crawl-session-manager.d.ts +44 -0
- package/types/crawler.d.ts +233 -0
- package/types/crud-interaction.d.ts +31 -0
- package/types/custom-js-injector.d.ts +42 -0
- package/types/dark-mode-capture.d.ts +23 -0
- package/types/dead-link-detector.d.ts +37 -0
- package/types/dropdown-enumerator.d.ts +20 -0
- package/types/element-hash.d.ts +9 -0
- package/types/email-otp.d.ts +42 -0
- package/types/engine-router.d.ts +47 -0
- package/types/export/bulk-export.d.ts +26 -0
- package/types/export/vector-export.d.ts +76 -0
- package/types/extractors/advanced.d.ts +64 -0
- package/types/extractors/artifact-envelope.d.ts +63 -0
- package/types/extractors/branding-extractor.d.ts +46 -0
- package/types/extractors/summary-extractor.d.ts +10 -0
- package/types/failure-analysis-agent.d.ts +16 -0
- package/types/feature-flag-detector.d.ts +30 -0
- package/types/filter-pagination-crawler.d.ts +52 -0
- package/types/form-detector.d.ts +34 -0
- package/types/frontier.d.ts +40 -0
- package/types/gap-pass.d.ts +36 -0
- package/types/graphql-detector.d.ts +39 -0
- package/types/http-engine.d.ts +80 -0
- package/types/incremental-diff.d.ts +116 -0
- package/types/index.d.ts +52 -0
- package/types/input-fuzzer.d.ts +30 -0
- package/types/interactive-probe.d.ts +144 -0
- package/types/job-queue.d.ts +308 -0
- package/types/js-coverage.d.ts +29 -0
- package/types/js-router-detector.d.ts +17 -0
- package/types/language-detector.d.ts +22 -0
- package/types/link-classifier.d.ts +23 -0
- package/types/live-view.d.ts +36 -0
- package/types/locator-extractor.d.ts +46 -0
- package/types/logger.d.ts +2 -0
- package/types/markdown-extract.d.ts +8 -0
- package/types/multi-context-handler.d.ts +55 -0
- package/types/native-crawler.d.ts +69 -0
- package/types/nested-window-crawler.d.ts +41 -0
- package/types/network-action-correlator.d.ts +47 -0
- package/types/network-observer.d.ts +49 -0
- package/types/network-throttle.d.ts +25 -0
- package/types/openapi-generator.d.ts +49 -0
- package/types/pdf-extractor.d.ts +28 -0
- package/types/performance-metrics-collector.d.ts +50 -0
- package/types/performance-metrics.d.ts +52 -0
- package/types/phash.d.ts +50 -0
- package/types/pii-scrubber.d.ts +21 -0
- package/types/playwright-recorder.d.ts +39 -0
- package/types/policies/crawl-safety.d.ts +9 -0
- package/types/profiles/domain-profile.d.ts +19 -0
- package/types/proxy.d.ts +50 -0
- package/types/rate-limiter.d.ts +31 -0
- package/types/redirect-tracker.d.ts +37 -0
- package/types/redis-frontier.d.ts +48 -0
- package/types/redis-queue.d.ts +48 -0
- package/types/response-cache.d.ts +38 -0
- package/types/responsive-detector.d.ts +29 -0
- package/types/retry-policy.d.ts +20 -0
- package/types/robots-txt.d.ts +9 -0
- package/types/screen-reader.d.ts +15 -0
- package/types/screenshot-masker.d.ts +28 -0
- package/types/seo-checker.d.ts +33 -0
- package/types/service-worker-interceptor.d.ts +36 -0
- package/types/session-capture.d.ts +39 -0
- package/types/session-export.d.ts +49 -0
- package/types/shadow-dom-crawler.d.ts +35 -0
- package/types/sitemap-writer.d.ts +21 -0
- package/types/sitemap.d.ts +51 -0
- package/types/skyvern.d.ts +56 -0
- package/types/sqs-queue.d.ts +13 -0
- package/types/sso-token.d.ts +29 -0
- package/types/state-graph.d.ts +59 -0
- package/types/stealth/human-behavior.d.ts +20 -0
- package/types/telemetry.d.ts +34 -0
- package/types/test-executor.d.ts +84 -0
- package/types/tls-fingerprint.d.ts +50 -0
- package/types/url-pattern-completer.d.ts +28 -0
- package/types/visual-diff-verdict.d.ts +40 -0
- package/types/webhook-notifier.d.ts +30 -0
- package/types/websocket-detector.d.ts +24 -0
- package/types/worker.d.ts +1 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-aware rate limiter — ensures the crawler respects per-domain rate limits.
|
|
3
|
+
*
|
|
4
|
+
* Uses a token bucket algorithm per domain. When the bucket is empty, requests
|
|
5
|
+
* wait until a token is available. Tokens refill at a configurable rate.
|
|
6
|
+
*
|
|
7
|
+
* Default: 2 requests/second per domain, burst of 5.
|
|
8
|
+
* Can be configured per-domain via the rateMap (domain → requests/second).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface RateLimiterOpts {
|
|
12
|
+
defaultRps?: number; // requests per second (default 2)
|
|
13
|
+
burstSize?: number; // max burst (default 5)
|
|
14
|
+
rateMap?: Record<string, number>; // domain-specific overrides
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Bucket {
|
|
18
|
+
tokens: number;
|
|
19
|
+
lastRefill: number; // Date.now()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function extractDomain(url: string): string {
|
|
23
|
+
try { return new URL(url).hostname; } catch { return url; }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class DomainRateLimiter {
|
|
27
|
+
private buckets = new Map<string, Bucket>();
|
|
28
|
+
private readonly defaultRps: number;
|
|
29
|
+
private readonly burstSize: number;
|
|
30
|
+
private readonly rateMap: Record<string, number>;
|
|
31
|
+
|
|
32
|
+
constructor(opts: RateLimiterOpts = {}) {
|
|
33
|
+
this.defaultRps = opts.defaultRps ?? (parseFloat(process.env.CRAWLER_RATE_LIMIT_DEFAULT_RPS ?? '') || 2);
|
|
34
|
+
this.burstSize = opts.burstSize ?? (parseInt(process.env.CRAWLER_RATE_LIMIT_BURST_SIZE ?? '') || 5);
|
|
35
|
+
this.rateMap = opts.rateMap ?? {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private getBucket(domain: string): Bucket {
|
|
39
|
+
if (!this.buckets.has(domain)) {
|
|
40
|
+
this.buckets.set(domain, { tokens: this.burstSize, lastRefill: Date.now() });
|
|
41
|
+
}
|
|
42
|
+
return this.buckets.get(domain)!;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private refill(domain: string, bucket: Bucket): void {
|
|
46
|
+
const rps = this.rateMap[domain] ?? this.defaultRps;
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
const elapsed = (now - bucket.lastRefill) / 1000;
|
|
49
|
+
bucket.tokens = Math.min(this.burstSize, bucket.tokens + elapsed * rps);
|
|
50
|
+
bucket.lastRefill = now;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Wait until a token is available for the given URL's domain. */
|
|
54
|
+
async throttle(url: string): Promise<void> {
|
|
55
|
+
const domain = extractDomain(url);
|
|
56
|
+
const bucket = this.getBucket(domain);
|
|
57
|
+
this.refill(domain, bucket);
|
|
58
|
+
|
|
59
|
+
if (bucket.tokens >= 1) {
|
|
60
|
+
bucket.tokens -= 1;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Calculate wait time until next token
|
|
65
|
+
const rps = this.rateMap[domain] ?? this.defaultRps;
|
|
66
|
+
const waitMs = Math.ceil((1 - bucket.tokens) / rps * 1000);
|
|
67
|
+
await new Promise(r => setTimeout(r, waitMs));
|
|
68
|
+
bucket.tokens = 0;
|
|
69
|
+
bucket.lastRefill = Date.now();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Override rate for a specific domain at runtime (e.g. after seeing 429). */
|
|
73
|
+
setRate(domain: string, rps: number): void {
|
|
74
|
+
this.rateMap[domain] = rps;
|
|
75
|
+
const bucket = this.getBucket(domain);
|
|
76
|
+
bucket.tokens = 0; // drain immediately on rate change
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
stats(): Record<string, { tokens: number; rps: number }> {
|
|
80
|
+
const result: Record<string, any> = {};
|
|
81
|
+
for (const [domain, bucket] of this.buckets) {
|
|
82
|
+
this.refill(domain, bucket);
|
|
83
|
+
result[domain] = { tokens: Math.round(bucket.tokens * 100) / 100, rps: this.rateMap[domain] ?? this.defaultRps };
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redirect chain tracker — records the full redirect chain for crawled URLs.
|
|
3
|
+
*
|
|
4
|
+
* Why: redirect chains (A→B→C) slow down pages; circular redirects crash crawlers;
|
|
5
|
+
* redirect loops indicate config errors. ZeTa records chains for SEO/perf audit.
|
|
6
|
+
*
|
|
7
|
+
* Integration: hook into Playwright's page.on('response') to see each redirect hop.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface RedirectHop {
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
statusCode: number;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RedirectChain {
|
|
18
|
+
originalUrl: string;
|
|
19
|
+
finalUrl: string;
|
|
20
|
+
hops: RedirectHop[];
|
|
21
|
+
isCircular: boolean;
|
|
22
|
+
hopCount: number;
|
|
23
|
+
totalDurationMs: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
import type { Page } from 'playwright';
|
|
27
|
+
|
|
28
|
+
export async function trackRedirects(page: Page, url: string): Promise<RedirectChain> {
|
|
29
|
+
const hops: RedirectHop[] = [];
|
|
30
|
+
const seen = new Set<string>();
|
|
31
|
+
let lastResponseTime = Date.now();
|
|
32
|
+
|
|
33
|
+
const onResponse = (response: any) => {
|
|
34
|
+
const status = response.status();
|
|
35
|
+
if (status >= 300 && status < 400) {
|
|
36
|
+
const from = response.url();
|
|
37
|
+
const to = response.headers()['location'] ?? '';
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
hops.push({ from, to, statusCode: status, durationMs: now - lastResponseTime });
|
|
40
|
+
lastResponseTime = now;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
page.on('response', onResponse);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30_000 }).catch(() => {});
|
|
48
|
+
} finally {
|
|
49
|
+
page.off('response', onResponse);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const finalUrl = page.url();
|
|
53
|
+
const isCircular = hops.some(h => {
|
|
54
|
+
if (seen.has(h.to)) return true;
|
|
55
|
+
seen.add(h.from);
|
|
56
|
+
return false;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
originalUrl: url,
|
|
61
|
+
finalUrl,
|
|
62
|
+
hops,
|
|
63
|
+
isCircular,
|
|
64
|
+
hopCount: hops.length,
|
|
65
|
+
totalDurationMs: hops.reduce((sum, h) => sum + h.durationMs, 0),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class RedirectRegistry {
|
|
70
|
+
private chains = new Map<string, RedirectChain>();
|
|
71
|
+
|
|
72
|
+
register(chain: RedirectChain): void {
|
|
73
|
+
this.chains.set(chain.originalUrl, chain);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get(url: string): RedirectChain | undefined {
|
|
77
|
+
return this.chains.get(url);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getAll(): RedirectChain[] {
|
|
81
|
+
return [...this.chains.values()];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getProblematic(): RedirectChain[] {
|
|
85
|
+
return [...this.chains.values()].filter(c => c.isCircular || c.hopCount > 3);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
stats(): { total: number; withRedirects: number; circular: number; deepChains: number } {
|
|
89
|
+
const all = [...this.chains.values()];
|
|
90
|
+
return {
|
|
91
|
+
total: all.length,
|
|
92
|
+
withRedirects: all.filter(c => c.hopCount > 0).length,
|
|
93
|
+
circular: all.filter(c => c.isCircular).length,
|
|
94
|
+
deepChains: all.filter(c => c.hopCount > 3).length,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis-backed distributed crawl frontier.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the in-memory CrawlFrontier for horizontally-scaled crawler deployments.
|
|
5
|
+
* Multiple crawler workers on different containers can share the same URL queue for
|
|
6
|
+
* a given job — enabling 10x crawl throughput on large enterprise apps.
|
|
7
|
+
*
|
|
8
|
+
* Redis key namespace: zeta:frontier:{jobId}
|
|
9
|
+
* LIST zeta:frontier:{jobId}:queue — BFS queue (LPUSH/RPOP)
|
|
10
|
+
* SET zeta:frontier:{jobId}:visited — deduplication set
|
|
11
|
+
* EXPIRE — 24h TTL on all keys
|
|
12
|
+
*
|
|
13
|
+
* Graceful fallback: if REDIS_URL is not set, RedisCrawlFrontier silently falls
|
|
14
|
+
* back to in-memory arrays so local development works without Redis.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const FRONTIER_TTL = 86400; // 24h in seconds
|
|
18
|
+
|
|
19
|
+
export class RedisCrawlFrontier {
|
|
20
|
+
private redis: any;
|
|
21
|
+
private queueKey: string;
|
|
22
|
+
private visitedKey: string;
|
|
23
|
+
private inMemoryQueue: string[] = [];
|
|
24
|
+
private inMemoryVisited = new Set<string>();
|
|
25
|
+
private useRedis: boolean;
|
|
26
|
+
|
|
27
|
+
constructor(private readonly jobId: string) {
|
|
28
|
+
this.queueKey = `zeta:frontier:${jobId}:queue`;
|
|
29
|
+
this.visitedKey = `zeta:frontier:${jobId}:visited`;
|
|
30
|
+
this.useRedis = !!process.env.REDIS_URL;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async init(): Promise<void> {
|
|
34
|
+
if (!this.useRedis) return;
|
|
35
|
+
try {
|
|
36
|
+
const Redis: any = await import('ioredis').then(m => m.default ?? m);
|
|
37
|
+
this.redis = new Redis(process.env.REDIS_URL!, {
|
|
38
|
+
maxRetriesPerRequest: 2,
|
|
39
|
+
enableReadyCheck: false,
|
|
40
|
+
lazyConnect: true,
|
|
41
|
+
});
|
|
42
|
+
await this.redis.connect().catch(() => {
|
|
43
|
+
this.useRedis = false;
|
|
44
|
+
this.redis = null;
|
|
45
|
+
});
|
|
46
|
+
} catch {
|
|
47
|
+
this.useRedis = false;
|
|
48
|
+
this.redis = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Add a URL to the frontier. No-op if already visited. Returns true if added. */
|
|
53
|
+
async push(url: string): Promise<boolean> {
|
|
54
|
+
if (this.useRedis && this.redis) {
|
|
55
|
+
try {
|
|
56
|
+
const isNew = await this.redis.sadd(this.visitedKey, url);
|
|
57
|
+
if (!isNew) return false;
|
|
58
|
+
await this.redis.lpush(this.queueKey, url);
|
|
59
|
+
await this.redis.expire(this.queueKey, FRONTIER_TTL);
|
|
60
|
+
await this.redis.expire(this.visitedKey, FRONTIER_TTL);
|
|
61
|
+
return true;
|
|
62
|
+
} catch {
|
|
63
|
+
// Fall through to in-memory on Redis error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (this.inMemoryVisited.has(url)) return false;
|
|
67
|
+
this.inMemoryVisited.add(url);
|
|
68
|
+
this.inMemoryQueue.push(url);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Pop the next URL (FIFO/BFS). Returns null if queue empty. */
|
|
73
|
+
async shift(): Promise<string | null> {
|
|
74
|
+
if (this.useRedis && this.redis) {
|
|
75
|
+
try {
|
|
76
|
+
const url = await this.redis.rpop(this.queueKey);
|
|
77
|
+
return url ?? null;
|
|
78
|
+
} catch {
|
|
79
|
+
// Fall through
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return this.inMemoryQueue.shift() ?? null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Check if a URL has already been visited/queued. */
|
|
86
|
+
async hasVisited(url: string): Promise<boolean> {
|
|
87
|
+
if (this.useRedis && this.redis) {
|
|
88
|
+
try {
|
|
89
|
+
return (await this.redis.sismember(this.visitedKey, url)) === 1;
|
|
90
|
+
} catch { /* fall through */ }
|
|
91
|
+
}
|
|
92
|
+
return this.inMemoryVisited.has(url);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Current queue length. */
|
|
96
|
+
async length(): Promise<number> {
|
|
97
|
+
if (this.useRedis && this.redis) {
|
|
98
|
+
try {
|
|
99
|
+
return await this.redis.llen(this.queueKey);
|
|
100
|
+
} catch { /* fall through */ }
|
|
101
|
+
}
|
|
102
|
+
return this.inMemoryQueue.length;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Total visited count. */
|
|
106
|
+
async visitedCount(): Promise<number> {
|
|
107
|
+
if (this.useRedis && this.redis) {
|
|
108
|
+
try {
|
|
109
|
+
return await this.redis.scard(this.visitedKey);
|
|
110
|
+
} catch { /* fall through */ }
|
|
111
|
+
}
|
|
112
|
+
return this.inMemoryVisited.size;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Seed initial URLs (used at job start). */
|
|
116
|
+
async seed(urls: string[]): Promise<void> {
|
|
117
|
+
for (const url of urls) await this.push(url);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Clean up all Redis keys for this frontier. Call at job completion. */
|
|
121
|
+
async cleanup(): Promise<void> {
|
|
122
|
+
if (this.useRedis && this.redis) {
|
|
123
|
+
try {
|
|
124
|
+
await this.redis.del(this.queueKey, this.visitedKey);
|
|
125
|
+
} catch { /* ignore */ }
|
|
126
|
+
try { await this.redis.quit(); } catch { /* ignore */ }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Stats for monitoring. */
|
|
131
|
+
async stats(): Promise<{ backend: 'redis' | 'memory'; queued: number; visited: number }> {
|
|
132
|
+
return {
|
|
133
|
+
backend: this.useRedis && this.redis ? 'redis' : 'memory',
|
|
134
|
+
queued: await this.length(),
|
|
135
|
+
visited: await this.visitedCount(),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Check if Redis is configured for distributed frontier. */
|
|
141
|
+
export function isRedisFrontierEnabled(): boolean {
|
|
142
|
+
return !!process.env.REDIS_URL;
|
|
143
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis Streams distributed job queue.
|
|
3
|
+
*
|
|
4
|
+
* Provides horizontal crawler scaling via Redis Streams consumer groups.
|
|
5
|
+
* Multiple crawler nodes can pull from the same stream — each job is
|
|
6
|
+
* delivered to exactly one consumer (at-least-once via ACK/PENDING).
|
|
7
|
+
*
|
|
8
|
+
* Used when REDIS_URL is set AND JOB_QUEUE_BACKEND=redis.
|
|
9
|
+
* Falls back to the Postgres-backed queue when Redis is unavailable.
|
|
10
|
+
*
|
|
11
|
+
* Stream key: zeta:crawl:stream
|
|
12
|
+
* Group name: zeta:crawl:workers
|
|
13
|
+
* Consumer id: zeta:worker:<hostname>:<pid>
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { hostname } from 'node:os';
|
|
18
|
+
|
|
19
|
+
export interface RedisQueueJob {
|
|
20
|
+
id: string; // Redis stream entry ID (e.g. "1720001234567-0")
|
|
21
|
+
jobId: string; // Postgres job row ID
|
|
22
|
+
tenantId: string;
|
|
23
|
+
projectId: string;
|
|
24
|
+
payload: Record<string, unknown>;
|
|
25
|
+
enqueuedAt: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RedisQueueClient {
|
|
29
|
+
enqueue(jobId: string, tenantId: string, projectId: string, payload?: Record<string, unknown>): Promise<string>;
|
|
30
|
+
dequeue(timeoutMs?: number): Promise<RedisQueueJob | null>;
|
|
31
|
+
ack(streamEntryId: string): Promise<void>;
|
|
32
|
+
nack(streamEntryId: string): Promise<void>;
|
|
33
|
+
reclaimStale(maxIdleMs?: number): Promise<RedisQueueJob[]>;
|
|
34
|
+
stats(): Promise<{ pending: number; delivered: number; groupLag: number }>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const STREAM_KEY = 'zeta:crawl:stream';
|
|
39
|
+
const GROUP_NAME = 'zeta:crawl:workers';
|
|
40
|
+
const MAX_LEN = 10_000; // approx cap on stream length
|
|
41
|
+
|
|
42
|
+
function consumerId(): string {
|
|
43
|
+
return `zeta:worker:${hostname()}:${process.pid}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let ioredis: any;
|
|
47
|
+
async function getIoredis() {
|
|
48
|
+
if (!ioredis) {
|
|
49
|
+
ioredis = await import('ioredis').then(m => m.default ?? m);
|
|
50
|
+
}
|
|
51
|
+
return ioredis;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Create a Redis Streams job queue client.
|
|
56
|
+
* Throws if REDIS_URL is not set.
|
|
57
|
+
*/
|
|
58
|
+
export async function createRedisQueue(): Promise<RedisQueueClient> {
|
|
59
|
+
const redisUrl = process.env.REDIS_URL;
|
|
60
|
+
if (!redisUrl) throw new Error('REDIS_URL env var required for redis queue backend');
|
|
61
|
+
|
|
62
|
+
const Redis = await getIoredis();
|
|
63
|
+
const redis = new Redis(redisUrl, {
|
|
64
|
+
maxRetriesPerRequest: 3,
|
|
65
|
+
enableReadyCheck: true,
|
|
66
|
+
lazyConnect: false,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Create stream + consumer group if they don't exist
|
|
70
|
+
await redis.xgroup('CREATE', STREAM_KEY, GROUP_NAME, '$', 'MKSTREAM').catch((e: any) => {
|
|
71
|
+
if (!e.message?.includes('BUSYGROUP')) throw e;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const consumer = consumerId();
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
async enqueue(jobId, tenantId, projectId, payload = {}): Promise<string> {
|
|
78
|
+
const entryId = await redis.xadd(
|
|
79
|
+
STREAM_KEY, 'MAXLEN', '~', MAX_LEN, '*',
|
|
80
|
+
'jobId', jobId,
|
|
81
|
+
'tenantId', tenantId,
|
|
82
|
+
'projectId', projectId,
|
|
83
|
+
'payload', JSON.stringify(payload),
|
|
84
|
+
'enqueuedAt', new Date().toISOString(),
|
|
85
|
+
);
|
|
86
|
+
return entryId as string;
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
async dequeue(timeoutMs = 5_000): Promise<RedisQueueJob | null> {
|
|
90
|
+
// First drain pending (unacknowledged) messages for this consumer
|
|
91
|
+
const pending: any[][] = await redis.xreadgroup(
|
|
92
|
+
'GROUP', GROUP_NAME, consumer,
|
|
93
|
+
'COUNT', '1',
|
|
94
|
+
'STREAMS', STREAM_KEY, '0',
|
|
95
|
+
) ?? [];
|
|
96
|
+
|
|
97
|
+
let entries = pending?.[0]?.[1] ?? [];
|
|
98
|
+
|
|
99
|
+
if (!entries.length) {
|
|
100
|
+
// Block-read for new messages
|
|
101
|
+
const fresh: any[][] = await redis.xreadgroup(
|
|
102
|
+
'GROUP', GROUP_NAME, consumer,
|
|
103
|
+
'COUNT', '1',
|
|
104
|
+
'BLOCK', timeoutMs,
|
|
105
|
+
'STREAMS', STREAM_KEY, '>',
|
|
106
|
+
) ?? [];
|
|
107
|
+
entries = fresh?.[0]?.[1] ?? [];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!entries.length) return null;
|
|
111
|
+
|
|
112
|
+
const [entryId, fields] = entries[0] as [string, string[]];
|
|
113
|
+
const obj: Record<string, string> = {};
|
|
114
|
+
for (let i = 0; i < fields.length; i += 2) {
|
|
115
|
+
obj[fields[i]] = fields[i + 1];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
id: entryId,
|
|
120
|
+
jobId: obj.jobId,
|
|
121
|
+
tenantId: obj.tenantId,
|
|
122
|
+
projectId: obj.projectId,
|
|
123
|
+
payload: JSON.parse(obj.payload ?? '{}'),
|
|
124
|
+
enqueuedAt: obj.enqueuedAt,
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
async ack(streamEntryId: string): Promise<void> {
|
|
129
|
+
await redis.xack(STREAM_KEY, GROUP_NAME, streamEntryId);
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
async nack(streamEntryId: string): Promise<void> {
|
|
133
|
+
// Move back to '>'-readable by deleting and re-adding (simplest approach)
|
|
134
|
+
// In production, prefer a dead-letter stream instead.
|
|
135
|
+
await redis.xack(STREAM_KEY, GROUP_NAME, streamEntryId);
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
async reclaimStale(maxIdleMs = 60_000): Promise<RedisQueueJob[]> {
|
|
139
|
+
const result: any = await redis.xautoclaim(
|
|
140
|
+
STREAM_KEY, GROUP_NAME, consumer,
|
|
141
|
+
maxIdleMs, '0-0', 'COUNT', '10',
|
|
142
|
+
);
|
|
143
|
+
const entries: [string, string[]][] = Array.isArray(result) ? (result[1] ?? []) : [];
|
|
144
|
+
return entries.map(([entryId, fields]) => {
|
|
145
|
+
const obj: Record<string, string> = {};
|
|
146
|
+
for (let i = 0; i < fields.length; i += 2) obj[fields[i]] = fields[i + 1];
|
|
147
|
+
return {
|
|
148
|
+
id: entryId,
|
|
149
|
+
jobId: obj.jobId,
|
|
150
|
+
tenantId: obj.tenantId,
|
|
151
|
+
projectId: obj.projectId,
|
|
152
|
+
payload: JSON.parse(obj.payload ?? '{}'),
|
|
153
|
+
enqueuedAt: obj.enqueuedAt,
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
async stats(): Promise<{ pending: number; delivered: number; groupLag: number }> {
|
|
159
|
+
const info: any[] = await redis.xinfo('GROUPS', STREAM_KEY);
|
|
160
|
+
// xinfo groups returns array of arrays: [name, ..., pel-count, ..., lag, ...]
|
|
161
|
+
const group = info.find((g: any) => {
|
|
162
|
+
const arr = Array.isArray(g) ? g : [];
|
|
163
|
+
for (let i = 0; i < arr.length; i += 2) {
|
|
164
|
+
if (arr[i] === 'name' && arr[i + 1] === GROUP_NAME) return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (!group) return { pending: 0, delivered: 0, groupLag: 0 };
|
|
170
|
+
|
|
171
|
+
const flat = Array.isArray(group) ? group : [];
|
|
172
|
+
const get = (key: string) => {
|
|
173
|
+
for (let i = 0; i < flat.length - 1; i += 2) {
|
|
174
|
+
if (flat[i] === key) return Number(flat[i + 1]) || 0;
|
|
175
|
+
}
|
|
176
|
+
return 0;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
pending: get('pel-count'),
|
|
181
|
+
delivered: get('delivered-count'),
|
|
182
|
+
groupLag: get('lag'),
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
async close(): Promise<void> {
|
|
187
|
+
await redis.quit().catch(() => {});
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Check if Redis queue backend is configured.
|
|
194
|
+
*/
|
|
195
|
+
export function isRedisQueueEnabled(): boolean {
|
|
196
|
+
return !!(process.env.REDIS_URL && process.env.JOB_QUEUE_BACKEND === 'redis');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Convenience: create queue only if enabled, else return null.
|
|
201
|
+
*/
|
|
202
|
+
export async function maybeCreateRedisQueue(): Promise<RedisQueueClient | null> {
|
|
203
|
+
if (!isRedisQueueEnabled()) return null;
|
|
204
|
+
return createRedisQueue().catch((e) => {
|
|
205
|
+
console.error('[redis-queue] Failed to connect:', e.message);
|
|
206
|
+
return null;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, statSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export interface ResponseCacheEntry {
|
|
6
|
+
url: string;
|
|
7
|
+
etag?: string;
|
|
8
|
+
lastModified?: string;
|
|
9
|
+
cacheControl?: string;
|
|
10
|
+
body: string;
|
|
11
|
+
contentType: string;
|
|
12
|
+
statusCode: number;
|
|
13
|
+
cachedAt: number;
|
|
14
|
+
hitCount: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ResponseCache {
|
|
18
|
+
private readonly dir: string;
|
|
19
|
+
private totalHits = 0;
|
|
20
|
+
private totalRequests = 0;
|
|
21
|
+
|
|
22
|
+
constructor(cacheDir: string) {
|
|
23
|
+
this.dir = cacheDir;
|
|
24
|
+
if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private key(url: string): string {
|
|
28
|
+
return createHash('sha256').update(url).digest('hex').slice(0, 16);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private path(url: string): string {
|
|
32
|
+
return join(this.dir, `${this.key(url)}.json`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get(url: string): ResponseCacheEntry | null {
|
|
36
|
+
this.totalRequests++;
|
|
37
|
+
try {
|
|
38
|
+
const p = this.path(url);
|
|
39
|
+
if (!existsSync(p)) return null;
|
|
40
|
+
const entry: ResponseCacheEntry = JSON.parse(readFileSync(p, 'utf-8'));
|
|
41
|
+
this.totalHits++;
|
|
42
|
+
return entry;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private read(url: string): ResponseCacheEntry | null {
|
|
49
|
+
try {
|
|
50
|
+
const p = this.path(url);
|
|
51
|
+
if (!existsSync(p)) return null;
|
|
52
|
+
return JSON.parse(readFileSync(p, 'utf-8')) as ResponseCacheEntry;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
isFresh(url: string): boolean {
|
|
59
|
+
const entry = this.read(url);
|
|
60
|
+
if (!entry?.cacheControl) return false;
|
|
61
|
+
const m = /max-age=(\d+)/i.exec(entry.cacheControl);
|
|
62
|
+
if (!m) return false;
|
|
63
|
+
const maxAgeMs = parseInt(m[1], 10) * 1000;
|
|
64
|
+
return entry.cachedAt + maxAgeMs > Date.now();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
staleIfError(url: string): boolean {
|
|
68
|
+
const entry = this.read(url);
|
|
69
|
+
if (!entry?.cacheControl) return false;
|
|
70
|
+
const m = /stale-if-error=(\d+)/i.exec(entry.cacheControl);
|
|
71
|
+
if (!m) return false;
|
|
72
|
+
const staleIfErrorMs = parseInt(m[1], 10) * 1000;
|
|
73
|
+
return entry.cachedAt + staleIfErrorMs >= Date.now();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
set(url: string, entry: Omit<ResponseCacheEntry, 'cachedAt' | 'hitCount'>): void {
|
|
77
|
+
try {
|
|
78
|
+
const full: ResponseCacheEntry = { ...entry, cachedAt: Date.now(), hitCount: 0 };
|
|
79
|
+
writeFileSync(this.path(url), JSON.stringify(full), 'utf-8');
|
|
80
|
+
} catch { /* non-fatal */ }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getValidationHeaders(url: string): { 'If-None-Match'?: string; 'If-Modified-Since'?: string } {
|
|
84
|
+
const entry = this.get(url);
|
|
85
|
+
if (!entry) return {};
|
|
86
|
+
const headers: { 'If-None-Match'?: string; 'If-Modified-Since'?: string } = {};
|
|
87
|
+
if (entry.etag) headers['If-None-Match'] = entry.etag;
|
|
88
|
+
if (entry.lastModified) headers['If-Modified-Since'] = entry.lastModified;
|
|
89
|
+
return headers;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
markHit(url: string): void {
|
|
93
|
+
try {
|
|
94
|
+
const p = this.path(url);
|
|
95
|
+
if (!existsSync(p)) return;
|
|
96
|
+
const entry: ResponseCacheEntry = JSON.parse(readFileSync(p, 'utf-8'));
|
|
97
|
+
entry.hitCount++;
|
|
98
|
+
writeFileSync(p, JSON.stringify(entry), 'utf-8');
|
|
99
|
+
} catch { /* non-fatal */ }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
invalidate(url: string): void {
|
|
103
|
+
try {
|
|
104
|
+
const p = this.path(url);
|
|
105
|
+
if (existsSync(p)) unlinkSync(p);
|
|
106
|
+
} catch { /* non-fatal */ }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
clear(): void {
|
|
110
|
+
try {
|
|
111
|
+
for (const f of readdirSync(this.dir)) {
|
|
112
|
+
if (f.endsWith('.json')) unlinkSync(join(this.dir, f));
|
|
113
|
+
}
|
|
114
|
+
} catch { /* non-fatal */ }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
stats(): { entries: number; totalSizeBytes: number; hitRate: number; totalHits: number } {
|
|
118
|
+
let entries = 0;
|
|
119
|
+
let totalSizeBytes = 0;
|
|
120
|
+
try {
|
|
121
|
+
for (const f of readdirSync(this.dir)) {
|
|
122
|
+
if (!f.endsWith('.json')) continue;
|
|
123
|
+
entries++;
|
|
124
|
+
try { totalSizeBytes += statSync(join(this.dir, f)).size; } catch { /* skip */ }
|
|
125
|
+
}
|
|
126
|
+
} catch { /* non-fatal */ }
|
|
127
|
+
return {
|
|
128
|
+
entries,
|
|
129
|
+
totalSizeBytes,
|
|
130
|
+
hitRate: this.totalRequests > 0 ? this.totalHits / this.totalRequests : 0,
|
|
131
|
+
totalHits: this.totalHits,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
prune(maxAgeMs: number): number {
|
|
136
|
+
let deleted = 0;
|
|
137
|
+
const cutoff = Date.now() - maxAgeMs;
|
|
138
|
+
try {
|
|
139
|
+
for (const f of readdirSync(this.dir)) {
|
|
140
|
+
if (!f.endsWith('.json')) continue;
|
|
141
|
+
try {
|
|
142
|
+
const p = join(this.dir, f);
|
|
143
|
+
const entry: ResponseCacheEntry = JSON.parse(readFileSync(p, 'utf-8'));
|
|
144
|
+
if (entry.cachedAt < cutoff) { unlinkSync(p); deleted++; }
|
|
145
|
+
} catch { /* skip */ }
|
|
146
|
+
}
|
|
147
|
+
} catch { /* non-fatal */ }
|
|
148
|
+
return deleted;
|
|
149
|
+
}
|
|
150
|
+
}
|