@crawlbrulee/sdk 0.13.1 → 0.15.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/index.d.cts CHANGED
@@ -129,14 +129,6 @@ interface ResponseMeta {
129
129
  type ScreenshotType = 'viewport' | 'full_page';
130
130
  /** Emulated device class for the viewport (drives default width/height). */
131
131
  type ScreenshotDeviceMode = 'desktop' | 'mobile';
132
- /** Pre-capture cleanup options applied to the page before the screenshot. */
133
- interface ScreenshotCleanup {
134
- /**
135
- * Remove ads, cookie banners, and popups before capturing. Defaults to
136
- * `true` server-side.
137
- */
138
- ads_and_popups?: boolean;
139
- }
140
132
  /** A `wait` action: pause for `ms` milliseconds before the next step. */
141
133
  interface ScreenshotWaitAction {
142
134
  type: 'wait';
@@ -185,8 +177,6 @@ interface ScreenshotRequest {
185
177
  viewport?: ScreenshotViewport;
186
178
  /** Emulate desktop or mobile. Defaults to `desktop`. */
187
179
  device_mode?: ScreenshotDeviceMode;
188
- /** Page cleanup applied before capture. */
189
- cleanup?: ScreenshotCleanup;
190
180
  /** Pre-capture actions (waits and scrolls). Maximum 5 entries. */
191
181
  actions_before?: ScreenshotBeforeAction[];
192
182
  /** Post-capture actions (e.g. slice into tiles). Maximum 1 entry. */
@@ -196,7 +186,7 @@ interface ScreenshotRequest {
196
186
  * Machine-readable error names returned by the crawlbrulee API. Stable
197
187
  * identifiers — clients can switch on them.
198
188
  */
199
- type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked';
189
+ type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large';
200
190
  /** Reason a usage allocation was denied (when `error_name = usage_allocation_error`). */
201
191
  type UsageAllocationReason = 'credit_limit' | 'concurrency_limit' | 'duplicate_reservation' | 'internal_error';
202
192
  /** Snapshot of the org's current usage at the moment the error was raised. */
@@ -243,6 +233,9 @@ interface ApiErrorResponse {
243
233
  * Which content formats to extract from the scraped page. Every field is
244
234
  * optional; the server defaults are noted on each field. The default request
245
235
  * extracts `{ metadata: true, cleaned_html: true }`.
236
+ *
237
+ * `extract` only selects what is returned — changing it does not change whether
238
+ * an otherwise identical request can be served from cache.
246
239
  */
247
240
  interface ScrapeExtract {
248
241
  /** Extract page metadata (title, description, OG/Twitter tags, etc.). Default `true`. */
@@ -274,7 +267,37 @@ interface ScrapeExtract {
274
267
  /** Capture a screenshot. Omit to skip; set to a `ScreenshotRequest` to enable. */
275
268
  screenshot?: ScreenshotRequest;
276
269
  }
277
- /** Cache settings for a scrape request. */
270
+ /**
271
+ * What is removed from the page before any output is built.
272
+ *
273
+ * Applies to `markdown`, `cleaned_html`, `links` and `images` on every engine,
274
+ * and to the screenshot. It never applies to `raw_html` — that is always the
275
+ * page as it arrived, before anything was removed.
276
+ */
277
+ interface ScrapeCleanup {
278
+ /**
279
+ * Remove ads, cookie banners, consent dialogs and chat widgets. Defaults to
280
+ * `true` server-side. Set it to `false` to capture the page as-is, or to get
281
+ * past a site that refuses to serve content to an ad-blocking client.
282
+ */
283
+ ads_and_popups?: boolean;
284
+ /**
285
+ * CSS selectors whose elements are removed before anything is captured. Use
286
+ * it for a banner or widget `ads_and_popups` does not recognise.
287
+ *
288
+ * At most 100 selectors, each at most 500 characters. Sending any selector
289
+ * here makes the request skip the cache, so it always costs a live fetch.
290
+ */
291
+ exclude_selectors?: string[];
292
+ }
293
+ /**
294
+ * Cache settings for a scrape request. `max_age` is the only cache control.
295
+ * A cached result has to match the url, the screenshot setup (type, viewport,
296
+ * device mode), `cleanup.ads_and_popups` and `location.locale`, and
297
+ * `require_js: true` only matches browser-rendered results.
298
+ * `cleanup.exclude_selectors` and a non-zero `actions_before` wait or scroll
299
+ * disable caching for that request.
300
+ */
278
301
  interface ScrapeCache {
279
302
  /**
280
303
  * Maximum cache age. Either a number of seconds (non-negative integer) or
@@ -299,10 +322,9 @@ interface ScrapeLocation {
299
322
  /** Request body for `POST /api/scrape` (and `POST /api/scrape/async`). */
300
323
  interface ScrapeRequest {
301
324
  /**
302
- * The URL to scrape. Known tracking parameters (`utm_*`, `mtm_*`, `ga_*`, `pk_*`, `gclid`,
303
- * `fbclid`, `msclkid`, and more) are removed before the page is fetched, so they reach
304
- * neither the target site nor the cache key. Every other query parameter is kept verbatim
305
- * and is part of the cache key.
325
+ * The URL to scrape. Known tracking parameters are removed before the page is
326
+ * fetched, so they reach neither the target site nor the cache. Every other query
327
+ * parameter is kept verbatim.
306
328
  */
307
329
  url: string;
308
330
  /** Which content formats to extract. Defaults to `metadata + cleaned_html`. */
@@ -314,8 +336,14 @@ interface ScrapeRequest {
314
336
  * and credits — only enable when the page requires it. Default `false`.
315
337
  */
316
338
  require_js?: boolean;
317
- /** CSS selectors to strip from the extracted content. */
318
- exclude_selectors?: string[];
339
+ /**
340
+ * What is removed from the page before any output is built. Shapes
341
+ * `markdown`, `cleaned_html`, `links`, `images` and the screenshot.
342
+ *
343
+ * Never applies to `raw_html`, which is always the page before anything was
344
+ * removed.
345
+ */
346
+ cleanup?: ScrapeCleanup;
319
347
  /**
320
348
  * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
321
349
  * first, escalates to advanced on failure; billed at the delivered tier).
@@ -527,9 +555,7 @@ interface ScrapeResponse {
527
555
  * Warnings are stored with the result, so cache hits and async result
528
556
  * fetches carry them too, filtered to the outputs you requested —
529
557
  * `raw_html_truncated` always surfaces, since a truncated body also feeds
530
- * `markdown` and `cleaned_html`. The `*_unavailable` codes only ever reach
531
- * the request whose own scrape degraded: a cached result missing a field you
532
- * asked for is re-scraped rather than served.
558
+ * `markdown` and `cleaned_html`.
533
559
  */
534
560
  warnings?: (ScrapeWarningCode | (string & {}))[];
535
561
  /**
@@ -542,7 +568,13 @@ interface ScrapeResponse {
542
568
  //#region src/types/map.d.ts
543
569
  /** Filter which link types appear in the map result. */
544
570
  interface MapTypes {
545
- /** Include internal links (same domain). Default `true`. */
571
+ /**
572
+ * Include internal links (same domain; `www.` and the bare domain count as
573
+ * the same site). Default `true`.
574
+ *
575
+ * Note this is only about *classifying* a link — the URLs that come back keep
576
+ * the host exactly as the site publishes it. See {@link MapLinkItem.url}.
577
+ */
546
578
  internal?: boolean;
547
579
  /** Include links to subdomains of the target. Default `true`. */
548
580
  internal_subdomains?: boolean;
@@ -578,14 +610,20 @@ interface MapRequest {
578
610
  /** Cache settings for this request. */
579
611
  cache?: MapCache;
580
612
  /**
581
- * Maximum number of URLs to store in the map. Must be in `(0, 100 000]`.
582
- * Defaults to 100 000.
613
+ * Maximum number of URLs to discover and store in the map. Must be in
614
+ * `(0, 100 000]`. Defaults to 5 000.
615
+ *
616
+ * Sitemap discovery stops as soon as this many URLs have been found, so a
617
+ * smaller value is a cheaper and faster crawl, not just a shorter answer. A
618
+ * map that stopped this way comes back with exactly `max_urls` links and
619
+ * {@link MapTruncation.discovery_cap_reason} set to `max_urls` — ask again
620
+ * with a higher `max_urls` to get more.
583
621
  */
584
622
  max_urls?: number;
585
623
  /** 1-based page number for paginated results. Defaults to 1. */
586
624
  page?: number;
587
625
  /**
588
- * Number of URLs per page. Must be in `(0, 10 000]`. Defaults to 10 000.
626
+ * Number of URLs per page. Must be in `(0, 10 000]`. Defaults to 5 000.
589
627
  */
590
628
  limit?: number;
591
629
  /** Optional country emulation. */
@@ -593,7 +631,10 @@ interface MapRequest {
593
631
  }
594
632
  /** Single discovered URL in a map result. */
595
633
  interface MapLinkItem {
596
- /** The discovered URL. */
634
+ /**
635
+ * The discovered URL, normalised the same way `/scrape` normalises the `url`
636
+ * it returns.
637
+ */
597
638
  url: string;
598
639
  }
599
640
  /** Pagination details on a map response. */
@@ -605,16 +646,50 @@ interface MapPagination {
605
646
  total_pages: number;
606
647
  has_more: boolean;
607
648
  }
649
+ /**
650
+ * Which limit stopped sitemap discovery first, or `null` when nothing stopped
651
+ * it.
652
+ *
653
+ * - `max_urls` — your own {@link MapRequest.max_urls} was reached. This is the
654
+ * only reason you can do something about: ask again with a higher one.
655
+ * - `time` — discovery ran out of its time budget.
656
+ * - `file_budget` — the site has more sitemap files than one request reads.
657
+ * - `depth` — the site's sitemap indexes nest too deeply.
658
+ * - `file_size` — a sitemap file was too large to read.
659
+ */
660
+ type MapDiscoveryCapReason = 'max_urls' | 'time' | 'file_budget' | 'depth' | 'file_size';
608
661
  /** Information about whether the stored or returned map was truncated. */
609
662
  interface MapTruncation {
610
- /** Whether the stored map was capped by `max_urls`. */
663
+ /** Whether the stored map hit the 100 000-URL storage cap. */
611
664
  storage_capped: boolean;
612
- /** Whether the response was capped by pagination. */
665
+ /**
666
+ * Whether more links were eligible than `max_urls`, so the list was trimmed.
667
+ * Discovery itself stops at `max_urls`, so this is normally `true` only when
668
+ * home-page links pushed the total past it. A map that ran into the
669
+ * `max_urls` limit during discovery reports `response_capped: false` and
670
+ * signals the stop through {@link discovery_cap_reason} instead.
671
+ */
613
672
  response_capped: boolean;
614
673
  /** Total URLs found before the `max_urls` cap was applied. */
615
674
  total_before_max_urls: number;
616
675
  /** Total URLs detected during discovery before the storage cap was applied. */
617
676
  total_detected_before_storage_cap: number;
677
+ /**
678
+ * Whether sitemap discovery stopped before it had read every sitemap file it
679
+ * found. When `true`, the site has more pages than this map lists.
680
+ */
681
+ discovery_capped: boolean;
682
+ /**
683
+ * How many sitemap files were skipped or only partly read during discovery,
684
+ * because a file was too large, could not be fetched, or a discovery limit
685
+ * was reached. Integer `>= 0`.
686
+ */
687
+ sitemaps_skipped: number;
688
+ /**
689
+ * Which limit stopped sitemap discovery first, or `null` when nothing did.
690
+ * Only `max_urls` is something you can change from the request.
691
+ */
692
+ discovery_cap_reason: MapDiscoveryCapReason | null;
618
693
  }
619
694
  /** Billing engine reported by map: fresh discovery or a cached result. */
620
695
  type MapBillingEngine = 'text' | 'cache';
@@ -638,7 +713,11 @@ interface MapResponseMeta {
638
713
  }
639
714
  /** Success response from `POST /api/map`. */
640
715
  interface MapResponse {
641
- /** The current page of discovered URLs. */
716
+ /**
717
+ * The current page of discovered URLs.
718
+ *
719
+ * Ordering is stable, with the most useful links first.
720
+ */
642
721
  links: MapLinkItem[];
643
722
  /** Usage, pagination, and truncation metadata for the result set. */
644
723
  response_meta: MapResponseMeta;
@@ -947,7 +1026,14 @@ declare class CrawlbruleeError extends Error {
947
1026
  cause?: unknown;
948
1027
  });
949
1028
  }
950
- /** Raised for 401 / 403 responses (missing, invalid, or unauthorized API key). */
1029
+ /**
1030
+ * Raised when the API rejects your credentials — a missing, invalid, or
1031
+ * unauthorized API key (`invalid_credentials`, `access_denied`).
1032
+ *
1033
+ * Not every 403 is a key problem: a 403 carrying `antibot_blocked` is the
1034
+ * *target site* blocking us and raises {@link AntibotBlockedError} instead.
1035
+ * Only an unrecognized 403 name falls back to this class.
1036
+ */
951
1037
  declare class AuthenticationError extends CrawlbruleeError {
952
1038
  constructor(message: string, options: {
953
1039
  status: number;
@@ -955,14 +1041,53 @@ declare class AuthenticationError extends CrawlbruleeError {
955
1041
  response?: ApiErrorResponse;
956
1042
  });
957
1043
  }
1044
+ /**
1045
+ * Raised when the target site's anti-bot protection blocked the request
1046
+ * (HTTP 403, `antibot_blocked`). Not an API-key problem — retrying the same
1047
+ * tier rarely helps; try a higher proxy tier or skip the site.
1048
+ */
1049
+ declare class AntibotBlockedError extends CrawlbruleeError {
1050
+ constructor(message: string, options: {
1051
+ status: number;
1052
+ errorName: ApiErrorName;
1053
+ response?: ApiErrorResponse;
1054
+ });
1055
+ }
1056
+ /**
1057
+ * Raised when the target site redirected the request in a loop, or through
1058
+ * more hops than the API follows (HTTP 422, `too_many_redirects`). Like
1059
+ * {@link AntibotBlockedError} this is the target's doing — not a key problem
1060
+ * and not a bad request — so it is neither an `AuthenticationError` nor a
1061
+ * `ValidationError`. Retrying rarely helps. Returned by both `scrape` and `map`.
1062
+ */
1063
+ declare class TooManyRedirectsError extends CrawlbruleeError {
1064
+ constructor(message: string, options: {
1065
+ status: number;
1066
+ errorName: ApiErrorName;
1067
+ response?: ApiErrorResponse;
1068
+ });
1069
+ }
1070
+ /**
1071
+ * Raised when the page's HTML was too large to process (HTTP 422,
1072
+ * `page_too_large`). Like {@link TooManyRedirectsError} this is about the page,
1073
+ * not your request — so it is neither an `AuthenticationError` nor a
1074
+ * `ValidationError`. It is terminal: the same URL fails the same way, so do not
1075
+ * retry it. Returned by `scrape`.
1076
+ */
1077
+ declare class PageTooLargeError extends CrawlbruleeError {
1078
+ constructor(message: string, options: {
1079
+ status: number;
1080
+ errorName: ApiErrorName;
1081
+ response?: ApiErrorResponse;
1082
+ });
1083
+ }
958
1084
  /**
959
1085
  * Raised for HTTP 429 responses. When the server included a `retry_after_ms`
960
1086
  * hint in `details` it is surfaced directly on the instance.
961
1087
  *
962
1088
  * `errorName` is always the literal `'too_many_requests'` — the SDK normalizes
963
- * this even when the server returns a 429 with a different `name` field
964
- * (e.g. a CDN coalescing upstream rate limiting). The original body is still
965
- * available on `response`.
1089
+ * this even when the server returns a 429 with a different `name` field. The
1090
+ * original body is still available on `response`.
966
1091
  */
967
1092
  declare class RateLimitError extends CrawlbruleeError {
968
1093
  readonly errorName: 'too_many_requests';
@@ -1149,5 +1274,5 @@ interface VerifyWebhookSignatureOptions {
1149
1274
  */
1150
1275
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
1151
1276
  //#endregion
1152
- export { ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotCleanup, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1277
+ export { AntibotBlockedError, ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapDiscoveryCapReason, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TooManyRedirectsError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1153
1278
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -129,14 +129,6 @@ interface ResponseMeta {
129
129
  type ScreenshotType = 'viewport' | 'full_page';
130
130
  /** Emulated device class for the viewport (drives default width/height). */
131
131
  type ScreenshotDeviceMode = 'desktop' | 'mobile';
132
- /** Pre-capture cleanup options applied to the page before the screenshot. */
133
- interface ScreenshotCleanup {
134
- /**
135
- * Remove ads, cookie banners, and popups before capturing. Defaults to
136
- * `true` server-side.
137
- */
138
- ads_and_popups?: boolean;
139
- }
140
132
  /** A `wait` action: pause for `ms` milliseconds before the next step. */
141
133
  interface ScreenshotWaitAction {
142
134
  type: 'wait';
@@ -185,8 +177,6 @@ interface ScreenshotRequest {
185
177
  viewport?: ScreenshotViewport;
186
178
  /** Emulate desktop or mobile. Defaults to `desktop`. */
187
179
  device_mode?: ScreenshotDeviceMode;
188
- /** Page cleanup applied before capture. */
189
- cleanup?: ScreenshotCleanup;
190
180
  /** Pre-capture actions (waits and scrolls). Maximum 5 entries. */
191
181
  actions_before?: ScreenshotBeforeAction[];
192
182
  /** Post-capture actions (e.g. slice into tiles). Maximum 1 entry. */
@@ -196,7 +186,7 @@ interface ScreenshotRequest {
196
186
  * Machine-readable error names returned by the crawlbrulee API. Stable
197
187
  * identifiers — clients can switch on them.
198
188
  */
199
- type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked';
189
+ type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large';
200
190
  /** Reason a usage allocation was denied (when `error_name = usage_allocation_error`). */
201
191
  type UsageAllocationReason = 'credit_limit' | 'concurrency_limit' | 'duplicate_reservation' | 'internal_error';
202
192
  /** Snapshot of the org's current usage at the moment the error was raised. */
@@ -243,6 +233,9 @@ interface ApiErrorResponse {
243
233
  * Which content formats to extract from the scraped page. Every field is
244
234
  * optional; the server defaults are noted on each field. The default request
245
235
  * extracts `{ metadata: true, cleaned_html: true }`.
236
+ *
237
+ * `extract` only selects what is returned — changing it does not change whether
238
+ * an otherwise identical request can be served from cache.
246
239
  */
247
240
  interface ScrapeExtract {
248
241
  /** Extract page metadata (title, description, OG/Twitter tags, etc.). Default `true`. */
@@ -274,7 +267,37 @@ interface ScrapeExtract {
274
267
  /** Capture a screenshot. Omit to skip; set to a `ScreenshotRequest` to enable. */
275
268
  screenshot?: ScreenshotRequest;
276
269
  }
277
- /** Cache settings for a scrape request. */
270
+ /**
271
+ * What is removed from the page before any output is built.
272
+ *
273
+ * Applies to `markdown`, `cleaned_html`, `links` and `images` on every engine,
274
+ * and to the screenshot. It never applies to `raw_html` — that is always the
275
+ * page as it arrived, before anything was removed.
276
+ */
277
+ interface ScrapeCleanup {
278
+ /**
279
+ * Remove ads, cookie banners, consent dialogs and chat widgets. Defaults to
280
+ * `true` server-side. Set it to `false` to capture the page as-is, or to get
281
+ * past a site that refuses to serve content to an ad-blocking client.
282
+ */
283
+ ads_and_popups?: boolean;
284
+ /**
285
+ * CSS selectors whose elements are removed before anything is captured. Use
286
+ * it for a banner or widget `ads_and_popups` does not recognise.
287
+ *
288
+ * At most 100 selectors, each at most 500 characters. Sending any selector
289
+ * here makes the request skip the cache, so it always costs a live fetch.
290
+ */
291
+ exclude_selectors?: string[];
292
+ }
293
+ /**
294
+ * Cache settings for a scrape request. `max_age` is the only cache control.
295
+ * A cached result has to match the url, the screenshot setup (type, viewport,
296
+ * device mode), `cleanup.ads_and_popups` and `location.locale`, and
297
+ * `require_js: true` only matches browser-rendered results.
298
+ * `cleanup.exclude_selectors` and a non-zero `actions_before` wait or scroll
299
+ * disable caching for that request.
300
+ */
278
301
  interface ScrapeCache {
279
302
  /**
280
303
  * Maximum cache age. Either a number of seconds (non-negative integer) or
@@ -299,10 +322,9 @@ interface ScrapeLocation {
299
322
  /** Request body for `POST /api/scrape` (and `POST /api/scrape/async`). */
300
323
  interface ScrapeRequest {
301
324
  /**
302
- * The URL to scrape. Known tracking parameters (`utm_*`, `mtm_*`, `ga_*`, `pk_*`, `gclid`,
303
- * `fbclid`, `msclkid`, and more) are removed before the page is fetched, so they reach
304
- * neither the target site nor the cache key. Every other query parameter is kept verbatim
305
- * and is part of the cache key.
325
+ * The URL to scrape. Known tracking parameters are removed before the page is
326
+ * fetched, so they reach neither the target site nor the cache. Every other query
327
+ * parameter is kept verbatim.
306
328
  */
307
329
  url: string;
308
330
  /** Which content formats to extract. Defaults to `metadata + cleaned_html`. */
@@ -314,8 +336,14 @@ interface ScrapeRequest {
314
336
  * and credits — only enable when the page requires it. Default `false`.
315
337
  */
316
338
  require_js?: boolean;
317
- /** CSS selectors to strip from the extracted content. */
318
- exclude_selectors?: string[];
339
+ /**
340
+ * What is removed from the page before any output is built. Shapes
341
+ * `markdown`, `cleaned_html`, `links`, `images` and the screenshot.
342
+ *
343
+ * Never applies to `raw_html`, which is always the page before anything was
344
+ * removed.
345
+ */
346
+ cleanup?: ScrapeCleanup;
319
347
  /**
320
348
  * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
321
349
  * first, escalates to advanced on failure; billed at the delivered tier).
@@ -527,9 +555,7 @@ interface ScrapeResponse {
527
555
  * Warnings are stored with the result, so cache hits and async result
528
556
  * fetches carry them too, filtered to the outputs you requested —
529
557
  * `raw_html_truncated` always surfaces, since a truncated body also feeds
530
- * `markdown` and `cleaned_html`. The `*_unavailable` codes only ever reach
531
- * the request whose own scrape degraded: a cached result missing a field you
532
- * asked for is re-scraped rather than served.
558
+ * `markdown` and `cleaned_html`.
533
559
  */
534
560
  warnings?: (ScrapeWarningCode | (string & {}))[];
535
561
  /**
@@ -542,7 +568,13 @@ interface ScrapeResponse {
542
568
  //#region src/types/map.d.ts
543
569
  /** Filter which link types appear in the map result. */
544
570
  interface MapTypes {
545
- /** Include internal links (same domain). Default `true`. */
571
+ /**
572
+ * Include internal links (same domain; `www.` and the bare domain count as
573
+ * the same site). Default `true`.
574
+ *
575
+ * Note this is only about *classifying* a link — the URLs that come back keep
576
+ * the host exactly as the site publishes it. See {@link MapLinkItem.url}.
577
+ */
546
578
  internal?: boolean;
547
579
  /** Include links to subdomains of the target. Default `true`. */
548
580
  internal_subdomains?: boolean;
@@ -578,14 +610,20 @@ interface MapRequest {
578
610
  /** Cache settings for this request. */
579
611
  cache?: MapCache;
580
612
  /**
581
- * Maximum number of URLs to store in the map. Must be in `(0, 100 000]`.
582
- * Defaults to 100 000.
613
+ * Maximum number of URLs to discover and store in the map. Must be in
614
+ * `(0, 100 000]`. Defaults to 5 000.
615
+ *
616
+ * Sitemap discovery stops as soon as this many URLs have been found, so a
617
+ * smaller value is a cheaper and faster crawl, not just a shorter answer. A
618
+ * map that stopped this way comes back with exactly `max_urls` links and
619
+ * {@link MapTruncation.discovery_cap_reason} set to `max_urls` — ask again
620
+ * with a higher `max_urls` to get more.
583
621
  */
584
622
  max_urls?: number;
585
623
  /** 1-based page number for paginated results. Defaults to 1. */
586
624
  page?: number;
587
625
  /**
588
- * Number of URLs per page. Must be in `(0, 10 000]`. Defaults to 10 000.
626
+ * Number of URLs per page. Must be in `(0, 10 000]`. Defaults to 5 000.
589
627
  */
590
628
  limit?: number;
591
629
  /** Optional country emulation. */
@@ -593,7 +631,10 @@ interface MapRequest {
593
631
  }
594
632
  /** Single discovered URL in a map result. */
595
633
  interface MapLinkItem {
596
- /** The discovered URL. */
634
+ /**
635
+ * The discovered URL, normalised the same way `/scrape` normalises the `url`
636
+ * it returns.
637
+ */
597
638
  url: string;
598
639
  }
599
640
  /** Pagination details on a map response. */
@@ -605,16 +646,50 @@ interface MapPagination {
605
646
  total_pages: number;
606
647
  has_more: boolean;
607
648
  }
649
+ /**
650
+ * Which limit stopped sitemap discovery first, or `null` when nothing stopped
651
+ * it.
652
+ *
653
+ * - `max_urls` — your own {@link MapRequest.max_urls} was reached. This is the
654
+ * only reason you can do something about: ask again with a higher one.
655
+ * - `time` — discovery ran out of its time budget.
656
+ * - `file_budget` — the site has more sitemap files than one request reads.
657
+ * - `depth` — the site's sitemap indexes nest too deeply.
658
+ * - `file_size` — a sitemap file was too large to read.
659
+ */
660
+ type MapDiscoveryCapReason = 'max_urls' | 'time' | 'file_budget' | 'depth' | 'file_size';
608
661
  /** Information about whether the stored or returned map was truncated. */
609
662
  interface MapTruncation {
610
- /** Whether the stored map was capped by `max_urls`. */
663
+ /** Whether the stored map hit the 100 000-URL storage cap. */
611
664
  storage_capped: boolean;
612
- /** Whether the response was capped by pagination. */
665
+ /**
666
+ * Whether more links were eligible than `max_urls`, so the list was trimmed.
667
+ * Discovery itself stops at `max_urls`, so this is normally `true` only when
668
+ * home-page links pushed the total past it. A map that ran into the
669
+ * `max_urls` limit during discovery reports `response_capped: false` and
670
+ * signals the stop through {@link discovery_cap_reason} instead.
671
+ */
613
672
  response_capped: boolean;
614
673
  /** Total URLs found before the `max_urls` cap was applied. */
615
674
  total_before_max_urls: number;
616
675
  /** Total URLs detected during discovery before the storage cap was applied. */
617
676
  total_detected_before_storage_cap: number;
677
+ /**
678
+ * Whether sitemap discovery stopped before it had read every sitemap file it
679
+ * found. When `true`, the site has more pages than this map lists.
680
+ */
681
+ discovery_capped: boolean;
682
+ /**
683
+ * How many sitemap files were skipped or only partly read during discovery,
684
+ * because a file was too large, could not be fetched, or a discovery limit
685
+ * was reached. Integer `>= 0`.
686
+ */
687
+ sitemaps_skipped: number;
688
+ /**
689
+ * Which limit stopped sitemap discovery first, or `null` when nothing did.
690
+ * Only `max_urls` is something you can change from the request.
691
+ */
692
+ discovery_cap_reason: MapDiscoveryCapReason | null;
618
693
  }
619
694
  /** Billing engine reported by map: fresh discovery or a cached result. */
620
695
  type MapBillingEngine = 'text' | 'cache';
@@ -638,7 +713,11 @@ interface MapResponseMeta {
638
713
  }
639
714
  /** Success response from `POST /api/map`. */
640
715
  interface MapResponse {
641
- /** The current page of discovered URLs. */
716
+ /**
717
+ * The current page of discovered URLs.
718
+ *
719
+ * Ordering is stable, with the most useful links first.
720
+ */
642
721
  links: MapLinkItem[];
643
722
  /** Usage, pagination, and truncation metadata for the result set. */
644
723
  response_meta: MapResponseMeta;
@@ -947,7 +1026,14 @@ declare class CrawlbruleeError extends Error {
947
1026
  cause?: unknown;
948
1027
  });
949
1028
  }
950
- /** Raised for 401 / 403 responses (missing, invalid, or unauthorized API key). */
1029
+ /**
1030
+ * Raised when the API rejects your credentials — a missing, invalid, or
1031
+ * unauthorized API key (`invalid_credentials`, `access_denied`).
1032
+ *
1033
+ * Not every 403 is a key problem: a 403 carrying `antibot_blocked` is the
1034
+ * *target site* blocking us and raises {@link AntibotBlockedError} instead.
1035
+ * Only an unrecognized 403 name falls back to this class.
1036
+ */
951
1037
  declare class AuthenticationError extends CrawlbruleeError {
952
1038
  constructor(message: string, options: {
953
1039
  status: number;
@@ -955,14 +1041,53 @@ declare class AuthenticationError extends CrawlbruleeError {
955
1041
  response?: ApiErrorResponse;
956
1042
  });
957
1043
  }
1044
+ /**
1045
+ * Raised when the target site's anti-bot protection blocked the request
1046
+ * (HTTP 403, `antibot_blocked`). Not an API-key problem — retrying the same
1047
+ * tier rarely helps; try a higher proxy tier or skip the site.
1048
+ */
1049
+ declare class AntibotBlockedError extends CrawlbruleeError {
1050
+ constructor(message: string, options: {
1051
+ status: number;
1052
+ errorName: ApiErrorName;
1053
+ response?: ApiErrorResponse;
1054
+ });
1055
+ }
1056
+ /**
1057
+ * Raised when the target site redirected the request in a loop, or through
1058
+ * more hops than the API follows (HTTP 422, `too_many_redirects`). Like
1059
+ * {@link AntibotBlockedError} this is the target's doing — not a key problem
1060
+ * and not a bad request — so it is neither an `AuthenticationError` nor a
1061
+ * `ValidationError`. Retrying rarely helps. Returned by both `scrape` and `map`.
1062
+ */
1063
+ declare class TooManyRedirectsError extends CrawlbruleeError {
1064
+ constructor(message: string, options: {
1065
+ status: number;
1066
+ errorName: ApiErrorName;
1067
+ response?: ApiErrorResponse;
1068
+ });
1069
+ }
1070
+ /**
1071
+ * Raised when the page's HTML was too large to process (HTTP 422,
1072
+ * `page_too_large`). Like {@link TooManyRedirectsError} this is about the page,
1073
+ * not your request — so it is neither an `AuthenticationError` nor a
1074
+ * `ValidationError`. It is terminal: the same URL fails the same way, so do not
1075
+ * retry it. Returned by `scrape`.
1076
+ */
1077
+ declare class PageTooLargeError extends CrawlbruleeError {
1078
+ constructor(message: string, options: {
1079
+ status: number;
1080
+ errorName: ApiErrorName;
1081
+ response?: ApiErrorResponse;
1082
+ });
1083
+ }
958
1084
  /**
959
1085
  * Raised for HTTP 429 responses. When the server included a `retry_after_ms`
960
1086
  * hint in `details` it is surfaced directly on the instance.
961
1087
  *
962
1088
  * `errorName` is always the literal `'too_many_requests'` — the SDK normalizes
963
- * this even when the server returns a 429 with a different `name` field
964
- * (e.g. a CDN coalescing upstream rate limiting). The original body is still
965
- * available on `response`.
1089
+ * this even when the server returns a 429 with a different `name` field. The
1090
+ * original body is still available on `response`.
966
1091
  */
967
1092
  declare class RateLimitError extends CrawlbruleeError {
968
1093
  readonly errorName: 'too_many_requests';
@@ -1149,5 +1274,5 @@ interface VerifyWebhookSignatureOptions {
1149
1274
  */
1150
1275
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
1151
1276
  //#endregion
1152
- export { ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotCleanup, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1277
+ export { AntibotBlockedError, ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapDiscoveryCapReason, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TooManyRedirectsError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1153
1278
  //# sourceMappingURL=index.d.ts.map