@crawlbrulee/sdk 1.3.1 → 1.5.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.ts CHANGED
@@ -72,7 +72,7 @@ declare class HttpClient {
72
72
  /**
73
73
  * Proxy tier used to route the fetch.
74
74
  *
75
- * - `basic` — datacenter proxy, lowest cost.
75
+ * - `basic` — basic proxy, lowest cost.
76
76
  * - `advanced` — enhanced proxy tier with a higher success rate.
77
77
  * - `auto` — start at the basic tier and escalate to advanced on failure;
78
78
  * billed at the delivered tier. This is the default when `proxy` is omitted.
@@ -157,6 +157,11 @@ interface ResponseMeta {
157
157
  type ScreenshotType = 'viewport' | 'full_page';
158
158
  /** Emulated device class for the viewport (drives default width/height). */
159
159
  type ScreenshotDeviceMode = 'desktop' | 'mobile';
160
+ /**
161
+ * Which theme to ask the site for: `light` (the default) or `dark`. See
162
+ * {@link ScreenshotRequest.color_scheme}.
163
+ */
164
+ type ScreenshotColorScheme = 'light' | 'dark';
160
165
  /** A `wait` action: pause for `ms` milliseconds before the next step. */
161
166
  interface ScreenshotWaitAction {
162
167
  type: 'wait';
@@ -205,6 +210,14 @@ interface ScreenshotRequest {
205
210
  viewport?: ScreenshotViewport;
206
211
  /** Emulate desktop or mobile. Defaults to `desktop`. */
207
212
  device_mode?: ScreenshotDeviceMode;
213
+ /**
214
+ * `light` (the default) or `dark`. `dark` asks the site for its dark theme,
215
+ * if it has one, and the screenshot shows it. A site without a dark theme,
216
+ * or whose dark theme is only a switch on the page, looks the same as with
217
+ * `light`. When the request also asks for `extract.pdf`, the PDF shows the
218
+ * dark theme too. No extra credits.
219
+ */
220
+ color_scheme?: ScreenshotColorScheme;
208
221
  /** Pre-capture actions (waits and scrolls). Maximum 5 entries. */
209
222
  actions_before?: ScreenshotBeforeAction[];
210
223
  /** Post-capture actions (e.g. slice into tiles). Maximum 1 entry. */
@@ -214,7 +227,7 @@ interface ScreenshotRequest {
214
227
  * Machine-readable error names returned by the crawlbrulee API. Stable
215
228
  * identifiers — clients can switch on them.
216
229
  */
217
- 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' | 'target_unreachable' | 'zero_data_retention_not_enabled';
230
+ 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' | 'unsupported_pdf_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large' | 'target_unreachable' | 'zero_data_retention_not_enabled';
218
231
  /** Reason a usage allocation was denied (when `error_name = usage_allocation_error`). */
219
232
  type UsageAllocationReason = 'credit_limit' | 'concurrency_limit' | 'duplicate_reservation' | 'internal_error';
220
233
  /** Snapshot of the org's current usage at the moment the error was raised. */
@@ -274,7 +287,7 @@ interface ScrapeElementSpecBase {
274
287
  * innermost spec: {@link ScrapeElementSpec} nests `fields` up to 3 levels, and a
275
288
  * spec inside the third `fields` must be this one.
276
289
  *
277
- * See https://crawlbrulee.com/docs/scrape/elements for the selector rules and limits.
290
+ * See https://crawlbrulee.com/docs/scrape/targeted-extraction for the selector rules and limits.
278
291
  */
279
292
  interface ScrapeElementLeafSpec extends ScrapeElementSpecBase {
280
293
  /** What to read from the match. Default `text`. */
@@ -294,7 +307,7 @@ interface ScrapeElementLeafSpec extends ScrapeElementSpecBase {
294
307
  * combined with `output` or `attribute`, and an empty `fields` is refused.
295
308
  */
296
309
  interface ScrapeElementSpecWithFields<Field> extends ScrapeElementSpecBase {
297
- /** Values read inside each match, by name. At least one. */
310
+ /** Values read inside each match, by name; `:scope` reads the match itself. At least one. */
298
311
  fields: Record<string, string | Field>;
299
312
  /** Not allowed with `fields`. */
300
313
  output?: never;
@@ -313,11 +326,12 @@ type ScrapeElementFieldSpec = ScrapeElementLeafSpec | ScrapeElementSpecWithField
313
326
  *
314
327
  * With `fields` (instead of `output` and `attribute`, never both), each match
315
328
  * becomes an object: every field is a name and a selector read inside that
316
- * match only. So a list of product cards can return a title, price and url per
317
- * card. An empty `fields` is refused. Fields nest up to 3 levels; the types
329
+ * match; the selector `:scope` reads the match itself, for example the matched
330
+ * element's own `href`. So a list of products can return a title, price and url per
331
+ * product. An empty `fields` is refused. Fields nest up to 3 levels; the types
318
332
  * stop you from going deeper.
319
333
  *
320
- * See https://crawlbrulee.com/docs/scrape/elements for the selector rules and limits.
334
+ * See https://crawlbrulee.com/docs/scrape/targeted-extraction for the selector rules and limits.
321
335
  */
322
336
  type ScrapeElementSpec = ScrapeElementLeafSpec | ScrapeElementSpecWithFields<ScrapeElementFieldSpec>;
323
337
  /**
@@ -330,17 +344,17 @@ type ScrapeElementSpec = ScrapeElementLeafSpec | ScrapeElementSpecWithFields<Scr
330
344
  * const elements: ScrapeElements = {
331
345
  * heading: 'h1',
332
346
  * books: {
333
- * selector: 'article.product_pod',
347
+ * selector: 'article.book',
334
348
  * all: true,
335
349
  * fields: {
336
350
  * title: { selector: 'h3 a', output: 'attribute', attribute: 'title' },
337
- * price: '.price_color',
351
+ * price: '.price',
338
352
  * },
339
353
  * },
340
354
  * }
341
355
  * ```
342
356
  *
343
- * See https://crawlbrulee.com/docs/scrape/elements.
357
+ * See https://crawlbrulee.com/docs/scrape/targeted-extraction.
344
358
  */
345
359
  type ScrapeElements = Record<string, string | ScrapeElementSpec>;
346
360
  /** One match read with `fields`: field name → value. */
@@ -356,17 +370,20 @@ type ScrapeElementValue = string | ScrapeElementObject | (string | ScrapeElement
356
370
  /**
357
371
  * Which content formats to extract from the scraped page. Every field is
358
372
  * optional; the server defaults are noted on each field. The default request
359
- * extracts `{ metadata: true, cleaned_html: true }`.
373
+ * extracts `{ markdown: true, metadata: true }`. Naming other formats keeps
374
+ * these two on; set `markdown: false` or `metadata: false` to turn one off.
360
375
  *
361
376
  * `extract` only selects what is returned — changing it does not change whether
362
- * an otherwise identical request can be served from cache.
377
+ * an otherwise identical request can be served from cache. The exceptions are
378
+ * `screenshot` and `pdf`: a cached copy answers them only when it has a
379
+ * screenshot or PDF made with the same settings.
363
380
  */
364
381
  interface ScrapeExtract {
365
382
  /** Extract page metadata (title, description, OG/Twitter tags, etc.). Default `true`. */
366
383
  metadata?: boolean;
367
- /** Extract cleaned HTML: the page body with scripts, styles, ads and cookie banners removed. Default `true`. */
384
+ /** Extract cleaned HTML: the page body with scripts, styles, ads and cookie banners removed. Default `false`. */
368
385
  cleaned_html?: boolean;
369
- /** Extract the page as clean Markdown. Default `false`. */
386
+ /** Extract the page as clean Markdown. Default `true`. */
370
387
  markdown?: boolean;
371
388
  /**
372
389
  * Return the raw, unprocessed HTML. Default `false`. Capped at 10 000 000
@@ -393,11 +410,82 @@ interface ScrapeExtract {
393
410
  * top-level `elements` field under the same names. Read after `cleanup`, from
394
411
  * the same page as `links` and `images`. No extra credits, also when the
395
412
  * page comes from cache. See {@link ScrapeElements} and
396
- * https://crawlbrulee.com/docs/scrape/elements.
413
+ * https://crawlbrulee.com/docs/scrape/targeted-extraction.
397
414
  */
398
415
  elements?: ScrapeElements;
399
416
  /** Capture a screenshot. Omit to skip; set to a `ScreenshotRequest` to enable. */
400
417
  screenshot?: ScreenshotRequest;
418
+ /**
419
+ * Save the page as a PDF. Omit to skip; set to a {@link PdfRequest} to
420
+ * enable, where `{}` takes every default. The PDF comes back on the
421
+ * top-level `pdf` field. See {@link PdfRequest}.
422
+ */
423
+ pdf?: PdfRequest;
424
+ }
425
+ /**
426
+ * How a PDF lays out the page:
427
+ *
428
+ * - `pages` (the default): the page on sheets of paper, laid out as in the
429
+ * browser window and shrunk to fit the paper width.
430
+ * - `single_page`: one page as wide as the browser window and as tall as the
431
+ * web page, up to 15 000 px.
432
+ */
433
+ type PdfLayout = 'pages' | 'single_page';
434
+ /** Paper size for a PDF with `layout: 'pages'`. */
435
+ type PdfPaper = 'a4' | 'letter';
436
+ /**
437
+ * Which style of the site a PDF shows: `screen` (the default), the page as it
438
+ * looks on screen, or `print`, the site's own print style.
439
+ */
440
+ type PdfMedia = 'screen' | 'print';
441
+ /**
442
+ * PDF settings. Pass this on `extract.pdf`; `{}` takes every default.
443
+ *
444
+ * The PDF is a real document with selectable text and working links,
445
+ * backgrounds printed, and no header or footer added. The request runs in a
446
+ * browser. It costs what a screenshot costs, and a PDF and a screenshot in one
447
+ * request are billed once. When the PDF can't be made (it would be over 50 MB,
448
+ * it takes too long, or the page could not be loaded), the rest of the scrape
449
+ * still comes back with the `pdf_unavailable` warning, and the request costs
450
+ * what it costs without the PDF.
451
+ *
452
+ * A cached copy of the page answers only when it has a PDF made with the same
453
+ * settings, in the same browser window (the screenshot's `device_mode`,
454
+ * `viewport` and `color_scheme`, when the request also asks for a screenshot).
455
+ * `cache.max_age: 0` always makes a new one.
456
+ *
457
+ * A PDF on its own is made with the light theme: the PDF has no color setting
458
+ * of its own.
459
+ * When the same request also asks for a screenshot with
460
+ * `color_scheme: 'dark'`, the PDF is dark too.
461
+ *
462
+ * ```ts
463
+ * const pdf: PdfRequest = { paper: 'letter', landscape: true }
464
+ * ```
465
+ */
466
+ interface PdfRequest {
467
+ /**
468
+ * `pages` (default): the page on sheets of paper, laid out as in the browser
469
+ * window (the desktop default, or the screenshot's device and viewport when
470
+ * the request also asks for one) and shrunk to fit the paper width.
471
+ * `single_page`: one page as wide as the browser window and as tall as the
472
+ * web page, up to 15 000 px; a taller page goes on over more pages, with the
473
+ * `pdf_single_page_overflow` warning.
474
+ */
475
+ layout?: PdfLayout;
476
+ /** Paper size for `layout: 'pages'`. Defaults to `a4`. Not allowed with `single_page`. */
477
+ paper?: PdfPaper;
478
+ /**
479
+ * Turn the paper sideways, for `layout: 'pages'`. Defaults to `false`. Not
480
+ * allowed with `single_page`.
481
+ */
482
+ landscape?: boolean;
483
+ /**
484
+ * `screen` (default): the page as it looks on screen. `print`: the site's
485
+ * own print style, which on many sites hides menus and images; a site
486
+ * without one looks as on screen.
487
+ */
488
+ media?: PdfMedia;
401
489
  }
402
490
  /**
403
491
  * What is removed from the page before any output is built.
@@ -425,10 +513,11 @@ interface ScrapeCleanup {
425
513
  /**
426
514
  * Cache settings for a scrape request. `max_age` is the only cache control.
427
515
  * A cached result has to match the url, the screenshot setup (type, viewport,
428
- * device mode), `cleanup.ads_and_popups`, `cleanup.exclude_selectors` and
429
- * `location.locale`, and `require_js: true` only matches browser-rendered
430
- * results. A non-zero `actions_before` wait or scroll disables caching for that
431
- * request.
516
+ * device mode, color scheme), the PDF settings, `cleanup.ads_and_popups`,
517
+ * `cleanup.exclude_selectors` and `location.locale`, and `require_js: true`
518
+ * only matches browser-rendered results. A non-zero `actions_before` wait or
519
+ * scroll disables caching for that request. A request with `headers` or
520
+ * `cookies` never reads from or writes to the cache.
432
521
  */
433
522
  interface ScrapeCache {
434
523
  /**
@@ -441,8 +530,8 @@ interface ScrapeCache {
441
530
  /** Optional locale + country emulation for the scrape. */
442
531
  interface ScrapeLocation {
443
532
  /**
444
- * BCP-47 locale (e.g. `en-US`, `de-DE`, `pt-BR`). Sent as `Accept-Language`
445
- * and reflected in `navigator.language` when JS rendering is requested.
533
+ * BCP-47 locale (e.g. `en-US`, `de-DE`, `pt-BR`): the language to ask the
534
+ * site for.
446
535
  */
447
536
  locale?: string;
448
537
  /**
@@ -451,6 +540,15 @@ interface ScrapeLocation {
451
540
  */
452
541
  country?: string;
453
542
  }
543
+ /**
544
+ * One cookie to send to the site, sent as `cookies` on a scrape request. The
545
+ * `name` can't be empty. The `value` may not hold `;` or start or end with a
546
+ * space. See https://crawlbrulee.com/docs/scrape/custom-headers-and-cookies.
547
+ */
548
+ interface ScrapeCookie {
549
+ name: string;
550
+ value: string;
551
+ }
454
552
  /** Request body for `POST /api/scrape` (and `POST /api/scrape/async`). */
455
553
  interface ScrapeRequest {
456
554
  /**
@@ -459,7 +557,7 @@ interface ScrapeRequest {
459
557
  * parameter is kept verbatim.
460
558
  */
461
559
  url: string;
462
- /** Which content formats to extract. Defaults to `metadata + cleaned_html`. */
560
+ /** Which content formats to extract. Defaults to `markdown + metadata`. */
463
561
  extract?: ScrapeExtract;
464
562
  /** Cache settings for this request. */
465
563
  cache?: ScrapeCache;
@@ -490,6 +588,38 @@ interface ScrapeRequest {
490
588
  * See https://crawlbrulee.com/docs/zero-data-retention.
491
589
  */
492
590
  zero_data_retention?: boolean;
591
+ /**
592
+ * Your own HTTP headers to send to the site with the request, for example
593
+ * `Authorization`, an api key, or a fixed `User-Agent` that the site has on
594
+ * an allowlist. Sent only to the origin of `url`
595
+ * (same scheme, host and port), or to its https version when `url` is http,
596
+ * and not on a redirect to another origin.
597
+ *
598
+ * Up to 10 headers; headers and cookies together up to 16384 bytes. Values
599
+ * are printable ASCII, with no space or tab at either end. A `Referer` must be
600
+ * the full http or https url of a public page, with no username or password.
601
+ * Use `cookies` for cookies and `location.locale` for the language. `Range`,
602
+ * conditional headers such as `If-None-Match`, and headers a browser doesn't
603
+ * let a web page set can't be set here either: a `400`
604
+ * ({@link ValidationError}) names the header. Your own `User-Agent` can lower
605
+ * the success rate and adds the `custom_user_agent` warning. Never put
606
+ * secrets in the `User-Agent`.
607
+ *
608
+ * A request with headers or cookies never reads from or writes to the
609
+ * cache. On a plain http url they travel unencrypted.
610
+ * See https://crawlbrulee.com/docs/scrape/custom-headers-and-cookies.
611
+ */
612
+ headers?: Record<string, string>;
613
+ /**
614
+ * Your own cookies to send to the site with the request. Sent only to
615
+ * the host of `url`. Cookies the site sets while redirecting are not kept.
616
+ *
617
+ * Up to 20 cookies, each up to 4096 bytes (name and value), counted toward
618
+ * the limit on `headers`. A `__Secure-`, `__Host-` or `__Http-` cookie needs
619
+ * an https url. A request with headers or cookies never reads from or writes
620
+ * to the cache. See https://crawlbrulee.com/docs/scrape/custom-headers-and-cookies.
621
+ */
622
+ cookies?: ScrapeCookie[];
493
623
  }
494
624
  /**
495
625
  * Per-job completion webhook, attached when submitting an ASYNC scrape via
@@ -571,6 +701,17 @@ interface ScreenshotResult {
571
701
  /** Tile slices, present only when the `slice` `actions_after` was requested. */
572
702
  slices?: ScreenshotSlice[];
573
703
  }
704
+ /** Result block returned when a PDF was requested and could be made. */
705
+ interface PdfResult {
706
+ /**
707
+ * Signed URL to download the PDF. Expires 24 hours after the scrape (for an
708
+ * async scrape, 24 hours after it was submitted; fetching the result again
709
+ * does not extend it). Download the file; don't keep the link.
710
+ */
711
+ url: string;
712
+ /** Size of the PDF file in bytes. */
713
+ bytes: number;
714
+ }
574
715
  /** A single inline image discovered on the page. */
575
716
  interface PageInlineImage {
576
717
  /**
@@ -624,7 +765,7 @@ interface ScrapeMetadata {
624
765
  }
625
766
  /**
626
767
  * Non-error notices returned on {@link ScrapeResponse.warnings}. Stable codes —
627
- * safe to switch on. They come in two families.
768
+ * safe to switch on. They come in three groups.
628
769
  *
629
770
  * Truncation — the output is there, but capped:
630
771
  *
@@ -635,7 +776,9 @@ interface ScrapeMetadata {
635
776
  * - `raw_html_truncated` — the page body exceeded 10 000 000 characters of HTML.
636
777
  * - `elements_truncated` — at least one `elements` value hit a limit: a list
637
778
  * was cut, or a value too large to return is `null` (never cut short). See
638
- * https://crawlbrulee.com/docs/scrape/elements for the limits.
779
+ * https://crawlbrulee.com/docs/scrape/targeted-extraction for the limits.
780
+ * - `pdf_single_page_overflow` — a `single_page` PDF was taller than the
781
+ * 15 000 px page limit, so it goes on over more pages.
639
782
  *
640
783
  * Unavailability — that section's extraction failed, so the field is omitted
641
784
  * or empty while the rest of the scrape succeeded. These let you tell "the page
@@ -646,6 +789,15 @@ interface ScrapeMetadata {
646
789
  * - `metadata_unavailable` — metadata extraction failed.
647
790
  * - `screenshot_unavailable` — a screenshot was asked for, but the page came
648
791
  * back without one. The rest of the result is there.
792
+ * - `pdf_unavailable` — a PDF was asked for, but the page came back without
793
+ * one: it would have been over 50 MB, it did not finish in time, or the page
794
+ * could not be loaded in a browser (the site answered an empty error page,
795
+ * for example). The rest of the result is there.
796
+ *
797
+ * Request notices:
798
+ *
799
+ * - `custom_user_agent`: the request set its own `User-Agent` header; this
800
+ * can lower the success rate.
649
801
  *
650
802
  * The page body has no such code: if it can't be extracted the scrape fails
651
803
  * outright rather than returning a hollow `200`, and isn't billed.
@@ -654,7 +806,7 @@ interface ScrapeMetadata {
654
806
  * its own, so new scrapes never send it. It stays in the union because results
655
807
  * stored before that change can still carry it. Don't rely on it in new code.
656
808
  */
657
- type ScrapeWarningCode = 'screenshot_truncated' | 'links_truncated' | 'inline_images_truncated' | 'raw_html_truncated' | 'metadata_truncated' | 'elements_truncated' | 'links_unavailable' | 'inline_images_unavailable' | 'metadata_unavailable' | 'screenshot_unavailable';
809
+ type ScrapeWarningCode = 'screenshot_truncated' | 'links_truncated' | 'inline_images_truncated' | 'raw_html_truncated' | 'metadata_truncated' | 'elements_truncated' | 'pdf_single_page_overflow' | 'links_unavailable' | 'inline_images_unavailable' | 'metadata_unavailable' | 'screenshot_unavailable' | 'pdf_unavailable' | 'custom_user_agent';
658
810
  /**
659
811
  * Successful response from `POST /api/scrape` and `GET /api/scrape/result/:jobId`.
660
812
  *
@@ -695,7 +847,7 @@ interface ScrapeResponse {
695
847
  * content type (e.g. asking for `metadata` or `elements` of a JSON file).
696
848
  */
697
849
  unsupported_fields?: string[];
698
- /** Page content converted to clean Markdown (when `extract.markdown`). */
850
+ /** Page content converted to clean Markdown (when `extract.markdown`, on by default). */
699
851
  markdown?: string;
700
852
  /** Cleaned HTML of the main page content (when `extract.cleaned_html`). */
701
853
  cleaned_html?: string;
@@ -719,17 +871,42 @@ interface ScrapeResponse {
719
871
  * can't be captured; when you also requested other outputs those are still
720
872
  * returned and this field is left out (so it reads back as `undefined`), with
721
873
  * a `screenshot_unavailable` warning on `warnings` to tell this case apart —
722
- * guard with `page.screenshot?.url`. A screenshot-only request
723
- * that can't deliver fails instead of returning an empty response: a `422`
874
+ * guard with `page.screenshot?.url`. A screenshot-only request (every other
875
+ * format off: `markdown: false` and `metadata: false`, and no `cleaned_html`,
876
+ * `raw_html`, `links`, `images` or `elements`) that can't deliver fails
877
+ * instead of returning an empty response: a `422`
724
878
  * with `unsupported_screenshot_output` when the content type can't be
725
879
  * screenshotted, a `500` when the capture itself failed — and isn't billed.
880
+ * A request with only a screenshot and a PDF counts as screenshot-only here.
881
+ *
882
+ * An async job like that ends `failed` and isn't billed either: reading its
883
+ * result throws the same `422` ({@link ValidationError}) when the content
884
+ * type can't be captured, or a `400` `job_failed` when no capture could be
885
+ * made.
726
886
  */
727
887
  screenshot?: ScreenshotResult;
888
+ /**
889
+ * The PDF of the page (when `extract.pdf` and it could be made). When it
890
+ * can't be made, this field is left out and `warnings` carries
891
+ * `pdf_unavailable`, while the rest of the scrape comes back. Guard with
892
+ * `page.pdf?.url`. A PDF-only request (every other format off:
893
+ * `markdown: false` and `metadata: false`, and no `cleaned_html`,
894
+ * `raw_html`, `links`, `images`, `elements` or screenshot) whose content
895
+ * type can't be made into a PDF fails with a `422`
896
+ * `unsupported_pdf_output` ({@link ValidationError}) and isn't billed; when
897
+ * no PDF could be made, it fails with a `500` and isn't billed.
898
+ *
899
+ * An async job like that ends `failed` and isn't billed either: reading its
900
+ * result throws the same `422` when the content type can't be made into a
901
+ * PDF, or a `400` `job_failed` when no PDF could be made.
902
+ */
903
+ pdf?: PdfResult;
728
904
  /** Extracted page metadata (when `extract.metadata`, on by default). */
729
905
  metadata?: ScrapeMetadata;
730
906
  /**
731
- * Non-error notices about the scrape — an output was capped (`*_truncated`)
732
- * or could not be extracted (`*_unavailable`); see {@link ScrapeWarningCode}
907
+ * Non-error notices about the scrape: an output was capped (`*_truncated`,
908
+ * `pdf_single_page_overflow`) or could not be extracted (`*_unavailable`);
909
+ * see {@link ScrapeWarningCode}
733
910
  * for what each one means. The codes are stable and safe to switch on, but
734
911
  * the array stays widened to `string` so a newly introduced code doesn't
735
912
  * break your build.
@@ -778,30 +955,92 @@ interface MapLocation {
778
955
  /** ISO 3166-1 alpha-2 country code (e.g. `US`). Case-insensitive. */
779
956
  country?: string;
780
957
  }
958
+ /**
959
+ * What a map returns, sent as {@link MapRequest.entries}: `pages` (page
960
+ * addresses, the default), `sitemaps` (sitemap files) or `all` (both).
961
+ */
962
+ type MapEntries = 'pages' | 'sitemaps' | 'all';
781
963
  /** Request body for `POST /api/map`. */
782
964
  interface MapRequest {
783
- /** The website URL to map. */
965
+ /**
966
+ * The website URL to map. A map always covers the whole site, so the path,
967
+ * query string and fragment are dropped.
968
+ */
784
969
  url: string;
785
970
  /**
786
971
  * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
787
972
  * first, escalates to advanced on failure; billed at the delivered tier).
788
973
  */
789
974
  proxy?: ProxyTier;
790
- /** Only use sitemap.xml — skip homepage link extraction. Default `false`. */
975
+ /**
976
+ * Use the sitemaps only: leave out the links found on the home page.
977
+ * Default `false`. A map with `modified_since` or `sitemap_url` never adds
978
+ * home page links.
979
+ */
791
980
  sitemap_only?: boolean;
792
981
  /** Filter which link types to include. */
793
982
  types?: MapTypes;
794
- /** Cache settings for this request. */
983
+ /**
984
+ * Cache settings for this request. A request with `modified_since` is always
985
+ * mapped fresh, so `cache.max_age` does nothing there.
986
+ */
795
987
  cache?: MapCache;
796
988
  /**
797
- * Maximum number of URLs to discover and store in the map. Must be in
798
- * `(0, 100 000]`. Defaults to 5 000.
989
+ * Start from this sitemap file, as a full http or https address. It must be
990
+ * on the same site as `url`, or on a host the site's robots.txt names, such
991
+ * as a CDN. Left out, the map starts from
992
+ * the site's own top sitemap files.
993
+ *
994
+ * Use it to map a very large site in several calls: list the site's sitemap
995
+ * files first, then read each one with `sitemap_url`.
996
+ */
997
+ sitemap_url?: string;
998
+ /**
999
+ * How many levels of nested sitemaps to follow: `0` to `3`, default `3`.
1000
+ * The sdk does not check the range: the api answers a higher value with a
1001
+ * `400`, which raises {@link ValidationError}.
1002
+ *
1003
+ * With `sitemap_url`, level 0 is that file, and it is read. Without it,
1004
+ * level 0 is the list of the site's top sitemap files, which `depth: 0`
1005
+ * returns without reading them: `{ depth: 0, entries: 'sitemaps' }` lists a
1006
+ * site's top sitemap files.
1007
+ *
1008
+ * A sitemap index holds only sitemap files, so reading one at a low depth
1009
+ * with `entries: 'pages'` returns no pages. Ask with `entries: 'sitemaps'`
1010
+ * or a higher depth.
1011
+ */
1012
+ depth?: number;
1013
+ /**
1014
+ * What to return: `pages` (the default), `sitemaps` or `all`. See
1015
+ * {@link MapEntries}.
1016
+ */
1017
+ entries?: MapEntries;
1018
+ /**
1019
+ * An ISO 8601 date and time with a zone, such as `2026-11-01T00:00:00Z`.
1020
+ * Only entries whose `lastmod` is at or after it come back. An entry with no
1021
+ * `lastmod` is left out, so every entry returned matches; links found on the
1022
+ * home page have no `lastmod`, so none of them is returned. A nested sitemap
1023
+ * whose own `lastmod` is older is not read, so a site that does not update
1024
+ * the dates in its sitemap index can hide changed pages.
1025
+ *
1026
+ * A request with this field is always mapped fresh: it never reads from or
1027
+ * adds to the cache, and each call is priced as a fresh map.
1028
+ */
1029
+ modified_since?: string;
1030
+ /**
1031
+ * The most entries the map finds, counting only the kind asked for in
1032
+ * `entries`. Must be in `(0, 100 000]`. Defaults to 5 000.
799
1033
  *
800
- * Sitemap discovery stops as soon as this many URLs have been found, so a
801
- * smaller value is a cheaper and faster crawl, not just a shorter answer. A
802
- * map that stopped this way comes back with exactly `max_urls` links and
803
- * {@link MapTruncation.discovery_cap_reason} set to `max_urls` — ask again
804
- * with a higher `max_urls` to get more.
1034
+ * Discovery stops as soon as this many have been found, so a smaller value
1035
+ * is a faster and lighter map, not just a shorter answer. A map that stopped
1036
+ * this way has {@link MapTruncation.discovery_cap_reason} set to
1037
+ * `max_results`; ask again with a higher `max_results` to get more.
1038
+ */
1039
+ max_results?: number;
1040
+ /**
1041
+ * @deprecated Use {@link MapRequest.max_results}, which means the same. When
1042
+ * both are sent, only `max_results` is used. The api removes `max_urls` on
1043
+ * 2027-02-01.
805
1044
  */
806
1045
  max_urls?: number;
807
1046
  /** 1-based page number for paginated results. Defaults to 1. */
@@ -820,6 +1059,13 @@ interface MapRequest {
820
1059
  */
821
1060
  zero_data_retention?: boolean;
822
1061
  }
1062
+ /**
1063
+ * What a link in a map result is: `page` for a page address, `sitemap` for a
1064
+ * sitemap file, which you can read with `sitemap_url` in another call. A file
1065
+ * on another site is read that way only when the site's robots.txt names its
1066
+ * host.
1067
+ */
1068
+ type MapLinkType = 'page' | 'sitemap';
823
1069
  /** Single discovered URL in a map result. */
824
1070
  interface MapLinkItem {
825
1071
  /**
@@ -827,12 +1073,26 @@ interface MapLinkItem {
827
1073
  * it returns.
828
1074
  */
829
1075
  url: string;
1076
+ /**
1077
+ * `page` for a page address, `sitemap` for a sitemap file you can read with
1078
+ * `sitemap_url` in another call. A link found on the home page is a `page`.
1079
+ */
1080
+ type: MapLinkType;
1081
+ /**
1082
+ * The entry's `lastmod` from the sitemap, as an ISO 8601 date and time in
1083
+ * UTC, or `null` when the sitemap gives none or it can't be read. Always
1084
+ * `null` for a link found on the home page.
1085
+ */
1086
+ lastmod: string | null;
830
1087
  }
831
1088
  /** Pagination details on a map response. */
832
1089
  interface MapPagination {
833
1090
  page: number;
834
1091
  limit: number;
835
- /** Total number of URLs in the stored map. */
1092
+ /**
1093
+ * How many links this answer holds across all its pages, after `entries`,
1094
+ * `types` and `max_results` are applied.
1095
+ */
836
1096
  total: number;
837
1097
  total_pages: number;
838
1098
  has_more: boolean;
@@ -841,34 +1101,47 @@ interface MapPagination {
841
1101
  * Which limit stopped sitemap discovery first, or `null` when nothing stopped
842
1102
  * it.
843
1103
  *
844
- * - `max_urls` — your own {@link MapRequest.max_urls} was reached. This is the
845
- * only reason you can do something about from the request: ask again with a
846
- * higher one.
847
- * - `time` — discovery ran out of its time budget.
848
- * - `file_budget` — the site has more sitemap files than one request reads.
849
- * - `depth` — the site's sitemap indexes nest too deeply.
850
- * - `file_size` — a sitemap file was too large to read.
851
- * - `unread_files` — a sitemap file the site publishes could not be read at all
852
- * this time: the request for it failed or was rate limited, or the file was
853
- * not a readable sitemap. This one is often temporary, so asking again later
854
- * can return more.
1104
+ * - `max_results`: your own {@link MapRequest.max_results} was reached. Ask
1105
+ * again with a higher one to get more.
1106
+ * - `depth`: there are sitemap files past the `depth` you asked for. That is
1107
+ * the answer to the depth you chose, not a fault: with `depth: 0` it is how
1108
+ * a site's top sitemap files are listed. The files past it are in
1109
+ * {@link MapTruncation.unread_sitemaps}; read each one with `sitemap_url`.
1110
+ * - `time`: discovery ran out of its time budget.
1111
+ * - `file_budget`: the site has more sitemap files than one request reads.
1112
+ * - `file_size`: a sitemap file was too large. A file that says up front
1113
+ * that it is over the size limit is not downloaded: nothing comes back from
1114
+ * it, and it is listed in {@link MapTruncation.unread_sitemaps}. A file of
1115
+ * pages that turns out too large while it is read returns the links in its
1116
+ * first part. Any other file that turns out too large, such as a sitemap
1117
+ * index, returns nothing and is listed.
1118
+ * - `unread_files`: a sitemap file the site publishes could not be read whole
1119
+ * this time (the request failed or was rate limited, the download broke off,
1120
+ * or the file was not a readable sitemap). When a download broke off, the
1121
+ * links received before the break are returned, and the file is listed in
1122
+ * `unread_sitemaps`. Asking again later can return more.
855
1123
  */
856
- type MapDiscoveryCapReason = 'max_urls' | 'time' | 'file_budget' | 'depth' | 'file_size' | 'unread_files';
1124
+ type MapDiscoveryCapReason = 'max_results' | 'time' | 'file_budget' | 'depth' | 'file_size' | 'unread_files';
857
1125
  /** Information about whether the stored or returned map was truncated. */
858
1126
  interface MapTruncation {
859
- /** Whether the stored map hit the 100 000-URL storage cap. */
1127
+ /** Whether the map found more than 100 000 URLs, the most one map holds, so some were left out. */
860
1128
  storage_capped: boolean;
861
1129
  /**
862
- * Whether more links were eligible than `max_urls`, so the list was trimmed.
863
- * Discovery itself stops at `max_urls`, so this is normally `true` only when
864
- * home-page links pushed the total past it. A map that ran into the
865
- * `max_urls` limit during discovery reports `response_capped: false` and
866
- * signals the stop through {@link discovery_cap_reason} instead.
1130
+ * Whether more links were eligible than `max_results`, so the list was
1131
+ * trimmed. Discovery itself stops at `max_results`, so this is normally
1132
+ * `true` only when home-page links pushed the total past it. A discovery
1133
+ * stop shows on {@link discovery_cap_reason} instead.
867
1134
  */
868
1135
  response_capped: boolean;
869
- /** Total URLs found before the `max_urls` cap was applied. */
1136
+ /** Total links found before `max_results` was applied. */
1137
+ total_before_max_results: number;
1138
+ /**
1139
+ * @deprecated Use {@link MapTruncation.total_before_max_results}, which
1140
+ * always has the same value. The api removes `total_before_max_urls` on
1141
+ * 2027-02-01.
1142
+ */
870
1143
  total_before_max_urls: number;
871
- /** Total URLs detected during discovery before the storage cap was applied. */
1144
+ /** Total URLs found, before the 100 000-URL limit of one map. */
872
1145
  total_detected_before_storage_cap: number;
873
1146
  /**
874
1147
  * Whether sitemap discovery stopped before it had read every sitemap file it
@@ -876,15 +1149,24 @@ interface MapTruncation {
876
1149
  */
877
1150
  discovery_capped: boolean;
878
1151
  /**
879
- * How many sitemap files were skipped or only partly read during discovery,
880
- * because a file was too large, could not be fetched, or a discovery limit
881
- * was reached. Integer `>= 0`.
1152
+ * How many sitemap files were skipped or only partly read during discovery.
1153
+ * Integer `>= 0`.
882
1154
  */
883
1155
  sitemaps_skipped: number;
1156
+ /**
1157
+ * The sitemap files this call knew about but did not read whole, because a
1158
+ * limit stopped it, the file could not be read, or its download broke off.
1159
+ * Read each one with `sitemap_url` in another call, except a file that says
1160
+ * it is over the size limit: no call reads that one. Up to 1 000 addresses;
1161
+ * empty when every file was read.
1162
+ *
1163
+ * When this list is full, send the same request with `entries: 'sitemaps'`
1164
+ * to get every sitemap file as a link, paged.
1165
+ */
1166
+ unread_sitemaps: string[];
884
1167
  /**
885
1168
  * Which limit stopped sitemap discovery first, or `null` when nothing did.
886
- * Only `max_urls` is something you can change from the request. `unread_files`
887
- * is often temporary, so asking again later can return more.
1169
+ * See {@link MapDiscoveryCapReason}.
888
1170
  */
889
1171
  discovery_cap_reason: MapDiscoveryCapReason | null;
890
1172
  }
@@ -941,9 +1223,10 @@ interface MapResponseMeta {
941
1223
  /** Success response from `POST /api/map`. */
942
1224
  interface MapResponse {
943
1225
  /**
944
- * The current page of discovered URLs.
1226
+ * The current page of discovered URLs, each with its `type` and `lastmod`.
945
1227
  *
946
- * Ordering is stable, with the most useful links first.
1228
+ * Ordering is stable, with the most useful links first. The site root is
1229
+ * listed only when a sitemap lists it.
947
1230
  */
948
1231
  links: MapLinkItem[];
949
1232
  /** Usage, pagination, and truncation metadata for the result set. */
@@ -1221,8 +1504,17 @@ declare class Crawlbrulee {
1221
1504
  */
1222
1505
  waitForScrape(jobId: string, options?: WaitForScrapeOptions): Promise<ScrapeResponse>;
1223
1506
  /**
1224
- * Build (or return a cached) site link-map for a domain. Combines sitemap
1225
- * discovery with the freshest cached homepage scrape when available.
1507
+ * Build (or return a cached) link map of a site from its sitemaps, plus the
1508
+ * links on its home page. Every link is `{ url, type, lastmod }`.
1509
+ *
1510
+ * By default the map reads the site's top sitemap files and two levels of
1511
+ * nested ones, and returns pages. Use `sitemap_url` to read one sitemap file,
1512
+ * so a very large site can be mapped in several calls. When the site answers
1513
+ * `429` for the file in `sitemap_url`, for its robots.txt or for one of its
1514
+ * top sitemap files, the map raises
1515
+ * {@link RateLimitError} and is not billed.
1516
+ *
1517
+ * See https://crawlbrulee.com/docs/map/sitemaps#map-a-very-large-or-deep-site-in-several-calls.
1226
1518
  */
1227
1519
  map(request: MapRequest, options?: RequestOptions): Promise<MapResponse>;
1228
1520
  /**
@@ -1566,5 +1858,5 @@ interface VerifyWebhookSignatureOptions {
1566
1858
  */
1567
1859
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
1568
1860
  //#endregion
1569
- 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, ScrapeElementFieldSpec, ScrapeElementLeafSpec, ScrapeElementNestedFieldSpec, ScrapeElementObject, ScrapeElementOutput, ScrapeElementSpec, ScrapeElementValue, ScrapeElements, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TargetUnreachableError, 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, ZeroDataRetentionNotEnabledError, isCrawlbruleeError, verifyWebhookSignature };
1861
+ 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, MapEntries, MapLinkItem, MapLinkType, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, PdfLayout, PdfMedia, PdfPaper, PdfRequest, PdfResult, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeCookie, ScrapeElementFieldSpec, ScrapeElementLeafSpec, ScrapeElementNestedFieldSpec, ScrapeElementObject, ScrapeElementOutput, ScrapeElementSpec, ScrapeElementValue, ScrapeElements, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotColorScheme, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TargetUnreachableError, 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, ZeroDataRetentionNotEnabledError, isCrawlbruleeError, verifyWebhookSignature };
1570
1862
  //# sourceMappingURL=index.d.ts.map