@crawlbrulee/sdk 1.4.0 → 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/README.md +137 -26
- package/dist/index.cjs +14 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +303 -59
- package/dist/index.d.ts +303 -59
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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` —
|
|
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. */
|
|
@@ -357,17 +370,20 @@ type ScrapeElementValue = string | ScrapeElementObject | (string | ScrapeElement
|
|
|
357
370
|
/**
|
|
358
371
|
* Which content formats to extract from the scraped page. Every field is
|
|
359
372
|
* optional; the server defaults are noted on each field. The default request
|
|
360
|
-
* extracts `{
|
|
373
|
+
* extracts `{ markdown: true, metadata: true }`. Naming other formats keeps
|
|
374
|
+
* these two on; set `markdown: false` or `metadata: false` to turn one off.
|
|
361
375
|
*
|
|
362
376
|
* `extract` only selects what is returned — changing it does not change whether
|
|
363
|
-
* 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.
|
|
364
380
|
*/
|
|
365
381
|
interface ScrapeExtract {
|
|
366
382
|
/** Extract page metadata (title, description, OG/Twitter tags, etc.). Default `true`. */
|
|
367
383
|
metadata?: boolean;
|
|
368
|
-
/** Extract cleaned HTML: the page body with scripts, styles, ads and cookie banners removed. Default `
|
|
384
|
+
/** Extract cleaned HTML: the page body with scripts, styles, ads and cookie banners removed. Default `false`. */
|
|
369
385
|
cleaned_html?: boolean;
|
|
370
|
-
/** Extract the page as clean Markdown. Default `
|
|
386
|
+
/** Extract the page as clean Markdown. Default `true`. */
|
|
371
387
|
markdown?: boolean;
|
|
372
388
|
/**
|
|
373
389
|
* Return the raw, unprocessed HTML. Default `false`. Capped at 10 000 000
|
|
@@ -399,6 +415,77 @@ interface ScrapeExtract {
|
|
|
399
415
|
elements?: ScrapeElements;
|
|
400
416
|
/** Capture a screenshot. Omit to skip; set to a `ScreenshotRequest` to enable. */
|
|
401
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;
|
|
402
489
|
}
|
|
403
490
|
/**
|
|
404
491
|
* What is removed from the page before any output is built.
|
|
@@ -426,11 +513,11 @@ interface ScrapeCleanup {
|
|
|
426
513
|
/**
|
|
427
514
|
* Cache settings for a scrape request. `max_age` is the only cache control.
|
|
428
515
|
* A cached result has to match the url, the screenshot setup (type, viewport,
|
|
429
|
-
* device mode), `cleanup.ads_and_popups`,
|
|
430
|
-
* `location.locale`, and `require_js: true`
|
|
431
|
-
* results. A non-zero `actions_before` wait or
|
|
432
|
-
* request. A request with `headers` or
|
|
433
|
-
* the cache.
|
|
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.
|
|
434
521
|
*/
|
|
435
522
|
interface ScrapeCache {
|
|
436
523
|
/**
|
|
@@ -470,7 +557,7 @@ interface ScrapeRequest {
|
|
|
470
557
|
* parameter is kept verbatim.
|
|
471
558
|
*/
|
|
472
559
|
url: string;
|
|
473
|
-
/** Which content formats to extract. Defaults to `
|
|
560
|
+
/** Which content formats to extract. Defaults to `markdown + metadata`. */
|
|
474
561
|
extract?: ScrapeExtract;
|
|
475
562
|
/** Cache settings for this request. */
|
|
476
563
|
cache?: ScrapeCache;
|
|
@@ -614,6 +701,17 @@ interface ScreenshotResult {
|
|
|
614
701
|
/** Tile slices, present only when the `slice` `actions_after` was requested. */
|
|
615
702
|
slices?: ScreenshotSlice[];
|
|
616
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
|
+
}
|
|
617
715
|
/** A single inline image discovered on the page. */
|
|
618
716
|
interface PageInlineImage {
|
|
619
717
|
/**
|
|
@@ -679,6 +777,8 @@ interface ScrapeMetadata {
|
|
|
679
777
|
* - `elements_truncated` — at least one `elements` value hit a limit: a list
|
|
680
778
|
* was cut, or a value too large to return is `null` (never cut short). See
|
|
681
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.
|
|
682
782
|
*
|
|
683
783
|
* Unavailability — that section's extraction failed, so the field is omitted
|
|
684
784
|
* or empty while the rest of the scrape succeeded. These let you tell "the page
|
|
@@ -689,6 +789,10 @@ interface ScrapeMetadata {
|
|
|
689
789
|
* - `metadata_unavailable` — metadata extraction failed.
|
|
690
790
|
* - `screenshot_unavailable` — a screenshot was asked for, but the page came
|
|
691
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.
|
|
692
796
|
*
|
|
693
797
|
* Request notices:
|
|
694
798
|
*
|
|
@@ -702,7 +806,7 @@ interface ScrapeMetadata {
|
|
|
702
806
|
* its own, so new scrapes never send it. It stays in the union because results
|
|
703
807
|
* stored before that change can still carry it. Don't rely on it in new code.
|
|
704
808
|
*/
|
|
705
|
-
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' | 'custom_user_agent';
|
|
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';
|
|
706
810
|
/**
|
|
707
811
|
* Successful response from `POST /api/scrape` and `GET /api/scrape/result/:jobId`.
|
|
708
812
|
*
|
|
@@ -743,7 +847,7 @@ interface ScrapeResponse {
|
|
|
743
847
|
* content type (e.g. asking for `metadata` or `elements` of a JSON file).
|
|
744
848
|
*/
|
|
745
849
|
unsupported_fields?: string[];
|
|
746
|
-
/** Page content converted to clean Markdown (when `extract.markdown
|
|
850
|
+
/** Page content converted to clean Markdown (when `extract.markdown`, on by default). */
|
|
747
851
|
markdown?: string;
|
|
748
852
|
/** Cleaned HTML of the main page content (when `extract.cleaned_html`). */
|
|
749
853
|
cleaned_html?: string;
|
|
@@ -767,17 +871,42 @@ interface ScrapeResponse {
|
|
|
767
871
|
* can't be captured; when you also requested other outputs those are still
|
|
768
872
|
* returned and this field is left out (so it reads back as `undefined`), with
|
|
769
873
|
* a `screenshot_unavailable` warning on `warnings` to tell this case apart —
|
|
770
|
-
* guard with `page.screenshot?.url`. A screenshot-only request
|
|
771
|
-
*
|
|
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`
|
|
772
878
|
* with `unsupported_screenshot_output` when the content type can't be
|
|
773
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.
|
|
774
886
|
*/
|
|
775
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;
|
|
776
904
|
/** Extracted page metadata (when `extract.metadata`, on by default). */
|
|
777
905
|
metadata?: ScrapeMetadata;
|
|
778
906
|
/**
|
|
779
|
-
* Non-error notices about the scrape
|
|
780
|
-
* or could not be extracted (`*_unavailable`);
|
|
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}
|
|
781
910
|
* for what each one means. The codes are stable and safe to switch on, but
|
|
782
911
|
* the array stays widened to `string` so a newly introduced code doesn't
|
|
783
912
|
* break your build.
|
|
@@ -826,30 +955,92 @@ interface MapLocation {
|
|
|
826
955
|
/** ISO 3166-1 alpha-2 country code (e.g. `US`). Case-insensitive. */
|
|
827
956
|
country?: string;
|
|
828
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';
|
|
829
963
|
/** Request body for `POST /api/map`. */
|
|
830
964
|
interface MapRequest {
|
|
831
|
-
/**
|
|
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
|
+
*/
|
|
832
969
|
url: string;
|
|
833
970
|
/**
|
|
834
971
|
* Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
|
|
835
972
|
* first, escalates to advanced on failure; billed at the delivered tier).
|
|
836
973
|
*/
|
|
837
974
|
proxy?: ProxyTier;
|
|
838
|
-
/**
|
|
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
|
+
*/
|
|
839
980
|
sitemap_only?: boolean;
|
|
840
981
|
/** Filter which link types to include. */
|
|
841
982
|
types?: MapTypes;
|
|
842
|
-
/**
|
|
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
|
+
*/
|
|
843
987
|
cache?: MapCache;
|
|
844
988
|
/**
|
|
845
|
-
*
|
|
846
|
-
* `
|
|
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.
|
|
847
1033
|
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
|
|
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.
|
|
853
1044
|
*/
|
|
854
1045
|
max_urls?: number;
|
|
855
1046
|
/** 1-based page number for paginated results. Defaults to 1. */
|
|
@@ -868,6 +1059,13 @@ interface MapRequest {
|
|
|
868
1059
|
*/
|
|
869
1060
|
zero_data_retention?: boolean;
|
|
870
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';
|
|
871
1069
|
/** Single discovered URL in a map result. */
|
|
872
1070
|
interface MapLinkItem {
|
|
873
1071
|
/**
|
|
@@ -875,12 +1073,26 @@ interface MapLinkItem {
|
|
|
875
1073
|
* it returns.
|
|
876
1074
|
*/
|
|
877
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;
|
|
878
1087
|
}
|
|
879
1088
|
/** Pagination details on a map response. */
|
|
880
1089
|
interface MapPagination {
|
|
881
1090
|
page: number;
|
|
882
1091
|
limit: number;
|
|
883
|
-
/**
|
|
1092
|
+
/**
|
|
1093
|
+
* How many links this answer holds across all its pages, after `entries`,
|
|
1094
|
+
* `types` and `max_results` are applied.
|
|
1095
|
+
*/
|
|
884
1096
|
total: number;
|
|
885
1097
|
total_pages: number;
|
|
886
1098
|
has_more: boolean;
|
|
@@ -889,34 +1101,47 @@ interface MapPagination {
|
|
|
889
1101
|
* Which limit stopped sitemap discovery first, or `null` when nothing stopped
|
|
890
1102
|
* it.
|
|
891
1103
|
*
|
|
892
|
-
* - `
|
|
893
|
-
*
|
|
894
|
-
*
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
* - `
|
|
899
|
-
* - `
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
*
|
|
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.
|
|
903
1123
|
*/
|
|
904
|
-
type MapDiscoveryCapReason = '
|
|
1124
|
+
type MapDiscoveryCapReason = 'max_results' | 'time' | 'file_budget' | 'depth' | 'file_size' | 'unread_files';
|
|
905
1125
|
/** Information about whether the stored or returned map was truncated. */
|
|
906
1126
|
interface MapTruncation {
|
|
907
|
-
/** Whether the
|
|
1127
|
+
/** Whether the map found more than 100 000 URLs, the most one map holds, so some were left out. */
|
|
908
1128
|
storage_capped: boolean;
|
|
909
1129
|
/**
|
|
910
|
-
* Whether more links were eligible than `
|
|
911
|
-
* Discovery itself stops at `
|
|
912
|
-
* home-page links pushed the total past it. A
|
|
913
|
-
*
|
|
914
|
-
* 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.
|
|
915
1134
|
*/
|
|
916
1135
|
response_capped: boolean;
|
|
917
|
-
/** Total
|
|
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
|
+
*/
|
|
918
1143
|
total_before_max_urls: number;
|
|
919
|
-
/** Total URLs
|
|
1144
|
+
/** Total URLs found, before the 100 000-URL limit of one map. */
|
|
920
1145
|
total_detected_before_storage_cap: number;
|
|
921
1146
|
/**
|
|
922
1147
|
* Whether sitemap discovery stopped before it had read every sitemap file it
|
|
@@ -924,15 +1149,24 @@ interface MapTruncation {
|
|
|
924
1149
|
*/
|
|
925
1150
|
discovery_capped: boolean;
|
|
926
1151
|
/**
|
|
927
|
-
* How many sitemap files were skipped or only partly read during discovery
|
|
928
|
-
*
|
|
929
|
-
* was reached. Integer `>= 0`.
|
|
1152
|
+
* How many sitemap files were skipped or only partly read during discovery.
|
|
1153
|
+
* Integer `>= 0`.
|
|
930
1154
|
*/
|
|
931
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[];
|
|
932
1167
|
/**
|
|
933
1168
|
* Which limit stopped sitemap discovery first, or `null` when nothing did.
|
|
934
|
-
*
|
|
935
|
-
* is often temporary, so asking again later can return more.
|
|
1169
|
+
* See {@link MapDiscoveryCapReason}.
|
|
936
1170
|
*/
|
|
937
1171
|
discovery_cap_reason: MapDiscoveryCapReason | null;
|
|
938
1172
|
}
|
|
@@ -989,9 +1223,10 @@ interface MapResponseMeta {
|
|
|
989
1223
|
/** Success response from `POST /api/map`. */
|
|
990
1224
|
interface MapResponse {
|
|
991
1225
|
/**
|
|
992
|
-
* The current page of discovered URLs
|
|
1226
|
+
* The current page of discovered URLs, each with its `type` and `lastmod`.
|
|
993
1227
|
*
|
|
994
|
-
* 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.
|
|
995
1230
|
*/
|
|
996
1231
|
links: MapLinkItem[];
|
|
997
1232
|
/** Usage, pagination, and truncation metadata for the result set. */
|
|
@@ -1269,8 +1504,17 @@ declare class Crawlbrulee {
|
|
|
1269
1504
|
*/
|
|
1270
1505
|
waitForScrape(jobId: string, options?: WaitForScrapeOptions): Promise<ScrapeResponse>;
|
|
1271
1506
|
/**
|
|
1272
|
-
* Build (or return a cached)
|
|
1273
|
-
*
|
|
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.
|
|
1274
1518
|
*/
|
|
1275
1519
|
map(request: MapRequest, options?: RequestOptions): Promise<MapResponse>;
|
|
1276
1520
|
/**
|
|
@@ -1614,5 +1858,5 @@ interface VerifyWebhookSignatureOptions {
|
|
|
1614
1858
|
*/
|
|
1615
1859
|
declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
|
|
1616
1860
|
//#endregion
|
|
1617
|
-
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, ScrapeCookie, 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 };
|
|
1618
1862
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const DEFAULT_REQUEST_TIMEOUT_MS = 0;
|
|
|
10
10
|
/** Environment variable read by `Crawlbrulee.fromEnv()` to source the API key. */
|
|
11
11
|
const ENV_API_KEY = "CRAWLBRULEE_API_KEY";
|
|
12
12
|
/** Identifies the SDK in the `User-Agent` header. Kept in one place for easy bumping. */
|
|
13
|
-
const USER_AGENT = "@crawlbrulee/sdk/1.
|
|
13
|
+
const USER_AGENT = "@crawlbrulee/sdk/1.5.0 (node)";
|
|
14
14
|
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/errors.ts
|
|
@@ -321,7 +321,8 @@ function createApiError(body, status) {
|
|
|
321
321
|
case "url_credentials_not_supported":
|
|
322
322
|
case "blocked_url":
|
|
323
323
|
case "unsupported_content":
|
|
324
|
-
case "unsupported_screenshot_output":
|
|
324
|
+
case "unsupported_screenshot_output":
|
|
325
|
+
case "unsupported_pdf_output": return new ValidationError(message, {
|
|
325
326
|
status,
|
|
326
327
|
errorName: name,
|
|
327
328
|
response
|
|
@@ -763,8 +764,17 @@ var Crawlbrulee = class Crawlbrulee {
|
|
|
763
764
|
}
|
|
764
765
|
}
|
|
765
766
|
/**
|
|
766
|
-
* Build (or return a cached)
|
|
767
|
-
*
|
|
767
|
+
* Build (or return a cached) link map of a site from its sitemaps, plus the
|
|
768
|
+
* links on its home page. Every link is `{ url, type, lastmod }`.
|
|
769
|
+
*
|
|
770
|
+
* By default the map reads the site's top sitemap files and two levels of
|
|
771
|
+
* nested ones, and returns pages. Use `sitemap_url` to read one sitemap file,
|
|
772
|
+
* so a very large site can be mapped in several calls. When the site answers
|
|
773
|
+
* `429` for the file in `sitemap_url`, for its robots.txt or for one of its
|
|
774
|
+
* top sitemap files, the map raises
|
|
775
|
+
* {@link RateLimitError} and is not billed.
|
|
776
|
+
*
|
|
777
|
+
* See https://crawlbrulee.com/docs/map/sitemaps#map-a-very-large-or-deep-site-in-several-calls.
|
|
768
778
|
*/
|
|
769
779
|
map(request, options) {
|
|
770
780
|
return this.http.post("/api/map", request, options);
|