zenrows 2.1.1 → 2.2.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 +93 -0
- package/dist/index.cjs +287 -24
- package/dist/index.d.cts +207 -1
- package/dist/index.d.ts +207 -1
- package/dist/index.js +284 -24
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -711,6 +711,187 @@ declare class ZenRowsBatchClient {
|
|
|
711
711
|
}): Promise<Job>;
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
+
/** `running` until the crawl ends; the other three are terminal. */
|
|
715
|
+
type CrawlStatus = "running" | "completed" | "stopped" | "failed";
|
|
716
|
+
/** What ended a crawl early: a limit (`status: completed`) or `stop()` (`status: stopped`). */
|
|
717
|
+
type CrawlStopReason = "max_items" | "max_pages" | "user";
|
|
718
|
+
/** Why a crawl failed (`status: failed`). */
|
|
719
|
+
type CrawlErrorCode = "insufficient_credits" | "seed_unreachable" | "domain_not_allowed" | "no_items_found" | "internal_error";
|
|
720
|
+
/** Where a kept URL's page stands, when the crawl has an `output_format`. */
|
|
721
|
+
type CrawlContentStatus = "pending" | "fetched" | "failed";
|
|
722
|
+
/** Return each kept URL's page as fetched. Absent means URLs only. */
|
|
723
|
+
type CrawlOutputFormat = "html";
|
|
724
|
+
interface CrawlCoverage {
|
|
725
|
+
pages_fetched: number;
|
|
726
|
+
pages_failed: number;
|
|
727
|
+
items_found: number;
|
|
728
|
+
}
|
|
729
|
+
/** Why a crawl failed. Part of the crawl, not an error response. */
|
|
730
|
+
interface CrawlRunError {
|
|
731
|
+
code: Extensible<CrawlErrorCode>;
|
|
732
|
+
detail: string;
|
|
733
|
+
}
|
|
734
|
+
interface Crawl {
|
|
735
|
+
crawl_id: string;
|
|
736
|
+
status: Extensible<CrawlStatus>;
|
|
737
|
+
url: string;
|
|
738
|
+
/** The depth limit the crawl was created with. Absent when it was created without one: no depth limit. */
|
|
739
|
+
depth?: number;
|
|
740
|
+
max_items: number;
|
|
741
|
+
max_pages: number;
|
|
742
|
+
coverage: CrawlCoverage;
|
|
743
|
+
created_at: string;
|
|
744
|
+
stop_reason?: Extensible<CrawlStopReason>;
|
|
745
|
+
error?: CrawlRunError;
|
|
746
|
+
include_patterns?: string[];
|
|
747
|
+
exclude_patterns?: string[];
|
|
748
|
+
output_format?: Extensible<CrawlOutputFormat>;
|
|
749
|
+
duplicates_removed?: number;
|
|
750
|
+
/** Absent while the crawl runs. */
|
|
751
|
+
finished_at?: string;
|
|
752
|
+
}
|
|
753
|
+
interface CrawlResult {
|
|
754
|
+
url: string;
|
|
755
|
+
content_status?: Extensible<CrawlContentStatus>;
|
|
756
|
+
/** The page's path, e.g. `/v1/crawls/c_x/contents/ct_y`. Present when `content_status` is `fetched`. */
|
|
757
|
+
content_url?: string;
|
|
758
|
+
}
|
|
759
|
+
interface CrawlWithResults extends Crawl {
|
|
760
|
+
results: CrawlResult[];
|
|
761
|
+
/** Never null while the crawl runs; null once it ended and this page holds its last URLs. */
|
|
762
|
+
next_cursor: string | null;
|
|
763
|
+
}
|
|
764
|
+
interface CrawlList {
|
|
765
|
+
crawls: Crawl[];
|
|
766
|
+
/** Absent on the last page. */
|
|
767
|
+
next_cursor?: string;
|
|
768
|
+
}
|
|
769
|
+
/** What `stop()` returns: where the crawl stands, without counts. */
|
|
770
|
+
interface CrawlStop {
|
|
771
|
+
crawl_id: string;
|
|
772
|
+
status: Extensible<CrawlStatus>;
|
|
773
|
+
stop_reason?: Extensible<CrawlStopReason>;
|
|
774
|
+
error?: CrawlRunError;
|
|
775
|
+
finished_at?: string;
|
|
776
|
+
}
|
|
777
|
+
/** One line of a crawl's download. */
|
|
778
|
+
interface CrawlExportLine {
|
|
779
|
+
url: string;
|
|
780
|
+
content_status?: Extensible<CrawlContentStatus>;
|
|
781
|
+
/** The page, present when `content_status` is `fetched`: HTML text, or an object for a JSON crawl. */
|
|
782
|
+
content?: string | Record<string, unknown>;
|
|
783
|
+
}
|
|
784
|
+
/** What `download()` returns. */
|
|
785
|
+
interface CrawlDownload {
|
|
786
|
+
/**
|
|
787
|
+
* The crawl's status when the file was read (`X-Crawl-Status`; undefined without it).
|
|
788
|
+
* `running` means a later download may hold more lines.
|
|
789
|
+
*/
|
|
790
|
+
status: Extensible<CrawlStatus> | undefined;
|
|
791
|
+
lines: AsyncIterable<CrawlExportLine>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
interface CrawlClientConfig {
|
|
795
|
+
/** Override the Crawl API base URL. Default `https://api.zenrows.com/v1`. */
|
|
796
|
+
baseURL?: string;
|
|
797
|
+
/**
|
|
798
|
+
* Retries for transient failures (502/503/504, network errors, 429 on reads) on idempotent
|
|
799
|
+
* requests, and for a `stop()` answered 429, 502, 503 or 504. Default 3.
|
|
800
|
+
*/
|
|
801
|
+
retries?: number;
|
|
802
|
+
/** Seconds each HTTP request may take. Default 30. Does not limit reading a `download()` body. */
|
|
803
|
+
timeout?: number;
|
|
804
|
+
}
|
|
805
|
+
interface CreateCrawlParams {
|
|
806
|
+
/** The page the crawl starts from: an absolute public `http`/`https` URL. */
|
|
807
|
+
url: string;
|
|
808
|
+
/**
|
|
809
|
+
* Link hops to follow from the start URL, 1–100000. Omit it for no depth limit: the crawl
|
|
810
|
+
* follows links until `maxPages` or `maxItems` stops it, or no link is left to open.
|
|
811
|
+
*/
|
|
812
|
+
depth?: number;
|
|
813
|
+
/** Stop once this many URLs are kept, 1–100000. Server default 100. */
|
|
814
|
+
maxItems?: number;
|
|
815
|
+
/** Stop once this many pages are fetched, 1–100000; bounds the cost. Server default 100. */
|
|
816
|
+
maxPages?: number;
|
|
817
|
+
/** Keep a URL only if it contains at least one of these substrings. */
|
|
818
|
+
includePatterns?: string[];
|
|
819
|
+
/** Drop a URL that contains any of these substrings, even if it matches an include pattern. */
|
|
820
|
+
excludePatterns?: string[];
|
|
821
|
+
/** Also fetch each kept URL's page. Absent means URLs only. */
|
|
822
|
+
outputFormat?: CrawlOutputFormat;
|
|
823
|
+
}
|
|
824
|
+
interface WaitForCrawlOptions {
|
|
825
|
+
/** Seconds to poll before returning the crawl as it stands. Default 600. */
|
|
826
|
+
timeout?: number;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Client for the Zenrows Crawl API (new): give it one start URL, read back the URLs behind it.
|
|
830
|
+
* Usable standalone (`new ZenRowsCrawlClient(apiKey)`) or via `client.crawl` on a `ZenRows`
|
|
831
|
+
* instance. A crawl runs asynchronously: `create()` returns at once, `wait()` polls until it
|
|
832
|
+
* ends, and `results()` / `download()` read what it kept.
|
|
833
|
+
* Crawl is still evolving: new features are coming, limits may be tuned, and the changelog announces each change.
|
|
834
|
+
*/
|
|
835
|
+
declare class ZenRowsCrawlClient {
|
|
836
|
+
readonly apiKey: string;
|
|
837
|
+
private readonly transport;
|
|
838
|
+
private readonly retries;
|
|
839
|
+
constructor(apiKey: string, config?: CrawlClientConfig);
|
|
840
|
+
/**
|
|
841
|
+
* Start a crawl. Sends only the fields you set. With an `idempotencyKey`, a retry returns the
|
|
842
|
+
* crawl the first request created instead of starting another, and 5xx and network failures
|
|
843
|
+
* are retried. A 429 `too_many_crawls` is never retried: it throws `ZenRowsCrawlError` with
|
|
844
|
+
* `retryAfter` set.
|
|
845
|
+
*/
|
|
846
|
+
create(params: CreateCrawlParams, opts?: {
|
|
847
|
+
idempotencyKey?: string;
|
|
848
|
+
}): Promise<Crawl>;
|
|
849
|
+
/** Read a crawl's status, coverage and one page of results (`limit` 1–10000, default 1000). */
|
|
850
|
+
get(crawlId: string, options?: {
|
|
851
|
+
cursor?: string;
|
|
852
|
+
limit?: number;
|
|
853
|
+
}): Promise<CrawlWithResults>;
|
|
854
|
+
/** One page of the account's crawls, newest first (`limit` 1–100, default 20). */
|
|
855
|
+
list(options?: {
|
|
856
|
+
cursor?: string;
|
|
857
|
+
limit?: number;
|
|
858
|
+
}): Promise<CrawlList>;
|
|
859
|
+
/**
|
|
860
|
+
* Every URL the crawl kept, following `next_cursor` (`limit` is the page size). On a running
|
|
861
|
+
* crawl it yields the URLs kept so far and returns at the first empty page; it does not poll.
|
|
862
|
+
* Call `wait()` first to read every result.
|
|
863
|
+
*/
|
|
864
|
+
results(crawlId: string, options?: {
|
|
865
|
+
limit?: number;
|
|
866
|
+
}): AsyncGenerator<CrawlResult>;
|
|
867
|
+
/**
|
|
868
|
+
* Stop a running crawl. Idempotent: a crawl that already ended answers as it ended.
|
|
869
|
+
* Because a stop is safe to repeat, `stop()` retries a 429, 502, 503 (including `crawl_busy`,
|
|
870
|
+
* which means the stop was not saved and the crawl is still running) or 504 up to `retries`
|
|
871
|
+
* times, waiting `Retry-After` seconds (at most 30; 1 when the header is missing or unusable)
|
|
872
|
+
* each time, then throws the last error.
|
|
873
|
+
*/
|
|
874
|
+
stop(crawlId: string): Promise<CrawlStop>;
|
|
875
|
+
/**
|
|
876
|
+
* One kept URL's page as fetched (HTML). Pass the content id, a `content_url`, or the
|
|
877
|
+
* `CrawlResult` itself (its `content_url` is present once `content_status` is `fetched`).
|
|
878
|
+
* Throws `TypeError` when no content id can be read.
|
|
879
|
+
*/
|
|
880
|
+
content(crawlId: string, contentId: string | CrawlResult): Promise<string>;
|
|
881
|
+
/**
|
|
882
|
+
* Every result of the crawl in one download: its `status` and the parsed lines (with the
|
|
883
|
+
* page when the crawl has an `output_format`). On a running crawl, `status` is `running` and
|
|
884
|
+
* the lines hold only what was kept so far.
|
|
885
|
+
*/
|
|
886
|
+
download(crawlId: string): Promise<CrawlDownload>;
|
|
887
|
+
/**
|
|
888
|
+
* Poll until the crawl ends (any status but `running`) or `timeout` seconds pass, and return
|
|
889
|
+
* it, without results. A `failed` crawl resolves too: read `error`. On timeout the crawl is
|
|
890
|
+
* returned with status `running` and keeps running.
|
|
891
|
+
*/
|
|
892
|
+
wait(crawlId: string, options?: WaitForCrawlOptions): Promise<Crawl>;
|
|
893
|
+
}
|
|
894
|
+
|
|
714
895
|
/**
|
|
715
896
|
* A non-2xx response from the Batch API, decoded as RFC 7807 `application/problem+json`
|
|
716
897
|
* where possible. `code` is the stable Problem `code` member (e.g. `file_input_not_found`) —
|
|
@@ -759,12 +940,35 @@ interface PollUntilOptions<T> {
|
|
|
759
940
|
*/
|
|
760
941
|
declare function pollUntil<T>(fetch: () => Promise<T> | T, { isDone, isFailure, timeout, initialInterval, maxInterval, backoff, jitter, }: PollUntilOptions<T>): Promise<T>;
|
|
761
942
|
|
|
943
|
+
/**
|
|
944
|
+
* The API's code for an account Crawl is not enabled on (403).
|
|
945
|
+
*/
|
|
946
|
+
declare const CRAWL_NOT_ENABLED_CODE = "REQS008";
|
|
947
|
+
/**
|
|
948
|
+
* A non-2xx response from the Crawl API, decoded as RFC 9457 `application/problem+json`
|
|
949
|
+
* where possible. Branch on `status` and `code` (e.g. `crawl_not_found`, `too_many_crawls`,
|
|
950
|
+
* or `REQS008` when Crawl is not enabled for the account); `code` is undefined when the body
|
|
951
|
+
* has none.
|
|
952
|
+
*/
|
|
953
|
+
declare class ZenRowsCrawlError extends Error {
|
|
954
|
+
readonly status: number;
|
|
955
|
+
readonly problem: ProblemJson | undefined;
|
|
956
|
+
readonly code: string | undefined;
|
|
957
|
+
readonly detail: string | undefined;
|
|
958
|
+
readonly extras: Record<string, unknown> | undefined;
|
|
959
|
+
/** Seconds from the `Retry-After` header, e.g. 30 on a 429 `too_many_crawls`. */
|
|
960
|
+
readonly retryAfter: number | undefined;
|
|
961
|
+
constructor(status: number, problem: ProblemJson | undefined, extras?: Record<string, unknown>, retryAfter?: number);
|
|
962
|
+
}
|
|
963
|
+
|
|
762
964
|
type HttpMethods = "GET" | "POST" | "PUT";
|
|
763
965
|
/** Extract mode — see https://docs.zenrows.com for what each mode returns. */
|
|
764
966
|
type ExtractMode = "auto" | "native" | "standard";
|
|
765
967
|
interface ClientConfig {
|
|
766
968
|
concurrency?: number;
|
|
767
969
|
retries?: number;
|
|
970
|
+
/** Config for `client.crawl`: its own `baseURL`, `retries` and `timeout`. */
|
|
971
|
+
crawl?: CrawlClientConfig;
|
|
768
972
|
}
|
|
769
973
|
interface ZenRowsConfig {
|
|
770
974
|
/** Set to "auto" to enable Adaptive Stealth Mode — Zenrows starts with the cheapest
|
|
@@ -802,6 +1006,8 @@ declare class ZenRows {
|
|
|
802
1006
|
readonly fetchWithRetry: (input: string | URL | Request, init?: (RequestInit & fetch_retry.RequestInitRetryParams<typeof fetch>) | undefined) => Promise<Response>;
|
|
803
1007
|
/** Client for the Batch API (async job/run/task model) — see `./batch.ts`. */
|
|
804
1008
|
readonly batch: ZenRowsBatchClient;
|
|
1009
|
+
/** Client for the Crawl API (new; one start URL in, the URLs behind it out). See `./crawl/client.ts`. */
|
|
1010
|
+
readonly crawl: ZenRowsCrawlClient;
|
|
805
1011
|
constructor(apiKey: string, clientConfig?: ClientConfig);
|
|
806
1012
|
/**
|
|
807
1013
|
* Fetch a URL through Zenrows — the main page-scraping product. This is the primary entry
|
|
@@ -844,4 +1050,4 @@ declare class ZenRows {
|
|
|
844
1050
|
private worker;
|
|
845
1051
|
}
|
|
846
1052
|
|
|
847
|
-
export { AUTO_MAX_CREDITS, AUTO_MIN_CREDITS, type AddTasksResponse, At, BASE_CREDITS, type BatchClientConfig, type BatchTask, type BatchWebhookConfig, type Cadence, Calendar, type CostEstimate, type CostLine, type CreateJobInputResponse, CurrentRun, DEFAULT_MAX_BYTES_PER_FILE, DEFAULT_MAX_COUNT_IN_MEMORY, DEFAULT_MAX_FILES, DEFAULT_MAX_TOTAL_BYTES_IN_MEMORY, Daily, type DownloadToDirOptions, type DownloadToMemoryOptions, type DownloadedResult, type EstimateTask, type Export, ExportHandle, ExportRef, type ExportStatus, type Extensible, type ExtractMode, type FileInputUploadTarget, type GetResultsOptions, type HMACKeyCreated, type HMACKeyFinalized, type HMACKeyList, type HMACKeyMeta, type IngestStatus, JS_AND_PROXY_CREDITS, JS_CREDITS, type Job, JobHandle, JobRef, type JobSchedule, type JobStatus, type JobType, type ListJobRunsResponse, type ListJobsOptions, type ListJobsResponse, type ListResultsResponse, Monthly, PREMIUM_PROXY_CREDITS, type ParamMap, type ParamValue, type PauseState, type PollUntilOptions, type ProblemJson, Rate, type RerunJobResponse, type Run, type RunFailureReason, RunHandle, RunRef, type RunStats, type RunStatus, type Schedule, type ScheduleState, type Spend, type StartExportResponse, type SubmitJobOptions, type SubmitJobResponse, type SubmitTypedOptions, type TaskHistoryEvent, type TaskHistoryResponse, type TaskLike, type TaskResult, type TaskSpend, type TaskStatus, type TestWebhookResponse, type Tier, type WaitForRunOptions, WaiterFailureError, WaiterTimeoutError, type WebhookConfig, Weekly, ZenRows, ZenRowsBatchClient, ZenRowsBatchError, type ZenRowsConfig, downloadTaskToFile, downloadTaskToMemory, downloadToDir, downloadToMemory, estimateCost, parseProblem, pollUntil };
|
|
1053
|
+
export { AUTO_MAX_CREDITS, AUTO_MIN_CREDITS, type AddTasksResponse, At, BASE_CREDITS, type BatchClientConfig, type BatchTask, type BatchWebhookConfig, CRAWL_NOT_ENABLED_CODE, type Cadence, Calendar, type CostEstimate, type CostLine, type Crawl, type CrawlClientConfig, type CrawlContentStatus, type CrawlCoverage, type CrawlDownload, type CrawlErrorCode, type CrawlExportLine, type CrawlList, type CrawlOutputFormat, type CrawlResult, type CrawlRunError, type CrawlStatus, type CrawlStop, type CrawlStopReason, type CrawlWithResults, type CreateCrawlParams, type CreateJobInputResponse, CurrentRun, DEFAULT_MAX_BYTES_PER_FILE, DEFAULT_MAX_COUNT_IN_MEMORY, DEFAULT_MAX_FILES, DEFAULT_MAX_TOTAL_BYTES_IN_MEMORY, Daily, type DownloadToDirOptions, type DownloadToMemoryOptions, type DownloadedResult, type EstimateTask, type Export, ExportHandle, ExportRef, type ExportStatus, type Extensible, type ExtractMode, type FileInputUploadTarget, type GetResultsOptions, type HMACKeyCreated, type HMACKeyFinalized, type HMACKeyList, type HMACKeyMeta, type IngestStatus, JS_AND_PROXY_CREDITS, JS_CREDITS, type Job, JobHandle, JobRef, type JobSchedule, type JobStatus, type JobType, type ListJobRunsResponse, type ListJobsOptions, type ListJobsResponse, type ListResultsResponse, Monthly, PREMIUM_PROXY_CREDITS, type ParamMap, type ParamValue, type PauseState, type PollUntilOptions, type ProblemJson, Rate, type RerunJobResponse, type Run, type RunFailureReason, RunHandle, RunRef, type RunStats, type RunStatus, type Schedule, type ScheduleState, type Spend, type StartExportResponse, type SubmitJobOptions, type SubmitJobResponse, type SubmitTypedOptions, type TaskHistoryEvent, type TaskHistoryResponse, type TaskLike, type TaskResult, type TaskSpend, type TaskStatus, type TestWebhookResponse, type Tier, type WaitForCrawlOptions, type WaitForRunOptions, WaiterFailureError, WaiterTimeoutError, type WebhookConfig, Weekly, ZenRows, ZenRowsBatchClient, ZenRowsBatchError, type ZenRowsConfig, ZenRowsCrawlClient, ZenRowsCrawlError, downloadTaskToFile, downloadTaskToMemory, downloadToDir, downloadToMemory, estimateCost, parseProblem, pollUntil };
|
package/dist/index.d.ts
CHANGED
|
@@ -711,6 +711,187 @@ declare class ZenRowsBatchClient {
|
|
|
711
711
|
}): Promise<Job>;
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
+
/** `running` until the crawl ends; the other three are terminal. */
|
|
715
|
+
type CrawlStatus = "running" | "completed" | "stopped" | "failed";
|
|
716
|
+
/** What ended a crawl early: a limit (`status: completed`) or `stop()` (`status: stopped`). */
|
|
717
|
+
type CrawlStopReason = "max_items" | "max_pages" | "user";
|
|
718
|
+
/** Why a crawl failed (`status: failed`). */
|
|
719
|
+
type CrawlErrorCode = "insufficient_credits" | "seed_unreachable" | "domain_not_allowed" | "no_items_found" | "internal_error";
|
|
720
|
+
/** Where a kept URL's page stands, when the crawl has an `output_format`. */
|
|
721
|
+
type CrawlContentStatus = "pending" | "fetched" | "failed";
|
|
722
|
+
/** Return each kept URL's page as fetched. Absent means URLs only. */
|
|
723
|
+
type CrawlOutputFormat = "html";
|
|
724
|
+
interface CrawlCoverage {
|
|
725
|
+
pages_fetched: number;
|
|
726
|
+
pages_failed: number;
|
|
727
|
+
items_found: number;
|
|
728
|
+
}
|
|
729
|
+
/** Why a crawl failed. Part of the crawl, not an error response. */
|
|
730
|
+
interface CrawlRunError {
|
|
731
|
+
code: Extensible<CrawlErrorCode>;
|
|
732
|
+
detail: string;
|
|
733
|
+
}
|
|
734
|
+
interface Crawl {
|
|
735
|
+
crawl_id: string;
|
|
736
|
+
status: Extensible<CrawlStatus>;
|
|
737
|
+
url: string;
|
|
738
|
+
/** The depth limit the crawl was created with. Absent when it was created without one: no depth limit. */
|
|
739
|
+
depth?: number;
|
|
740
|
+
max_items: number;
|
|
741
|
+
max_pages: number;
|
|
742
|
+
coverage: CrawlCoverage;
|
|
743
|
+
created_at: string;
|
|
744
|
+
stop_reason?: Extensible<CrawlStopReason>;
|
|
745
|
+
error?: CrawlRunError;
|
|
746
|
+
include_patterns?: string[];
|
|
747
|
+
exclude_patterns?: string[];
|
|
748
|
+
output_format?: Extensible<CrawlOutputFormat>;
|
|
749
|
+
duplicates_removed?: number;
|
|
750
|
+
/** Absent while the crawl runs. */
|
|
751
|
+
finished_at?: string;
|
|
752
|
+
}
|
|
753
|
+
interface CrawlResult {
|
|
754
|
+
url: string;
|
|
755
|
+
content_status?: Extensible<CrawlContentStatus>;
|
|
756
|
+
/** The page's path, e.g. `/v1/crawls/c_x/contents/ct_y`. Present when `content_status` is `fetched`. */
|
|
757
|
+
content_url?: string;
|
|
758
|
+
}
|
|
759
|
+
interface CrawlWithResults extends Crawl {
|
|
760
|
+
results: CrawlResult[];
|
|
761
|
+
/** Never null while the crawl runs; null once it ended and this page holds its last URLs. */
|
|
762
|
+
next_cursor: string | null;
|
|
763
|
+
}
|
|
764
|
+
interface CrawlList {
|
|
765
|
+
crawls: Crawl[];
|
|
766
|
+
/** Absent on the last page. */
|
|
767
|
+
next_cursor?: string;
|
|
768
|
+
}
|
|
769
|
+
/** What `stop()` returns: where the crawl stands, without counts. */
|
|
770
|
+
interface CrawlStop {
|
|
771
|
+
crawl_id: string;
|
|
772
|
+
status: Extensible<CrawlStatus>;
|
|
773
|
+
stop_reason?: Extensible<CrawlStopReason>;
|
|
774
|
+
error?: CrawlRunError;
|
|
775
|
+
finished_at?: string;
|
|
776
|
+
}
|
|
777
|
+
/** One line of a crawl's download. */
|
|
778
|
+
interface CrawlExportLine {
|
|
779
|
+
url: string;
|
|
780
|
+
content_status?: Extensible<CrawlContentStatus>;
|
|
781
|
+
/** The page, present when `content_status` is `fetched`: HTML text, or an object for a JSON crawl. */
|
|
782
|
+
content?: string | Record<string, unknown>;
|
|
783
|
+
}
|
|
784
|
+
/** What `download()` returns. */
|
|
785
|
+
interface CrawlDownload {
|
|
786
|
+
/**
|
|
787
|
+
* The crawl's status when the file was read (`X-Crawl-Status`; undefined without it).
|
|
788
|
+
* `running` means a later download may hold more lines.
|
|
789
|
+
*/
|
|
790
|
+
status: Extensible<CrawlStatus> | undefined;
|
|
791
|
+
lines: AsyncIterable<CrawlExportLine>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
interface CrawlClientConfig {
|
|
795
|
+
/** Override the Crawl API base URL. Default `https://api.zenrows.com/v1`. */
|
|
796
|
+
baseURL?: string;
|
|
797
|
+
/**
|
|
798
|
+
* Retries for transient failures (502/503/504, network errors, 429 on reads) on idempotent
|
|
799
|
+
* requests, and for a `stop()` answered 429, 502, 503 or 504. Default 3.
|
|
800
|
+
*/
|
|
801
|
+
retries?: number;
|
|
802
|
+
/** Seconds each HTTP request may take. Default 30. Does not limit reading a `download()` body. */
|
|
803
|
+
timeout?: number;
|
|
804
|
+
}
|
|
805
|
+
interface CreateCrawlParams {
|
|
806
|
+
/** The page the crawl starts from: an absolute public `http`/`https` URL. */
|
|
807
|
+
url: string;
|
|
808
|
+
/**
|
|
809
|
+
* Link hops to follow from the start URL, 1–100000. Omit it for no depth limit: the crawl
|
|
810
|
+
* follows links until `maxPages` or `maxItems` stops it, or no link is left to open.
|
|
811
|
+
*/
|
|
812
|
+
depth?: number;
|
|
813
|
+
/** Stop once this many URLs are kept, 1–100000. Server default 100. */
|
|
814
|
+
maxItems?: number;
|
|
815
|
+
/** Stop once this many pages are fetched, 1–100000; bounds the cost. Server default 100. */
|
|
816
|
+
maxPages?: number;
|
|
817
|
+
/** Keep a URL only if it contains at least one of these substrings. */
|
|
818
|
+
includePatterns?: string[];
|
|
819
|
+
/** Drop a URL that contains any of these substrings, even if it matches an include pattern. */
|
|
820
|
+
excludePatterns?: string[];
|
|
821
|
+
/** Also fetch each kept URL's page. Absent means URLs only. */
|
|
822
|
+
outputFormat?: CrawlOutputFormat;
|
|
823
|
+
}
|
|
824
|
+
interface WaitForCrawlOptions {
|
|
825
|
+
/** Seconds to poll before returning the crawl as it stands. Default 600. */
|
|
826
|
+
timeout?: number;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Client for the Zenrows Crawl API (new): give it one start URL, read back the URLs behind it.
|
|
830
|
+
* Usable standalone (`new ZenRowsCrawlClient(apiKey)`) or via `client.crawl` on a `ZenRows`
|
|
831
|
+
* instance. A crawl runs asynchronously: `create()` returns at once, `wait()` polls until it
|
|
832
|
+
* ends, and `results()` / `download()` read what it kept.
|
|
833
|
+
* Crawl is still evolving: new features are coming, limits may be tuned, and the changelog announces each change.
|
|
834
|
+
*/
|
|
835
|
+
declare class ZenRowsCrawlClient {
|
|
836
|
+
readonly apiKey: string;
|
|
837
|
+
private readonly transport;
|
|
838
|
+
private readonly retries;
|
|
839
|
+
constructor(apiKey: string, config?: CrawlClientConfig);
|
|
840
|
+
/**
|
|
841
|
+
* Start a crawl. Sends only the fields you set. With an `idempotencyKey`, a retry returns the
|
|
842
|
+
* crawl the first request created instead of starting another, and 5xx and network failures
|
|
843
|
+
* are retried. A 429 `too_many_crawls` is never retried: it throws `ZenRowsCrawlError` with
|
|
844
|
+
* `retryAfter` set.
|
|
845
|
+
*/
|
|
846
|
+
create(params: CreateCrawlParams, opts?: {
|
|
847
|
+
idempotencyKey?: string;
|
|
848
|
+
}): Promise<Crawl>;
|
|
849
|
+
/** Read a crawl's status, coverage and one page of results (`limit` 1–10000, default 1000). */
|
|
850
|
+
get(crawlId: string, options?: {
|
|
851
|
+
cursor?: string;
|
|
852
|
+
limit?: number;
|
|
853
|
+
}): Promise<CrawlWithResults>;
|
|
854
|
+
/** One page of the account's crawls, newest first (`limit` 1–100, default 20). */
|
|
855
|
+
list(options?: {
|
|
856
|
+
cursor?: string;
|
|
857
|
+
limit?: number;
|
|
858
|
+
}): Promise<CrawlList>;
|
|
859
|
+
/**
|
|
860
|
+
* Every URL the crawl kept, following `next_cursor` (`limit` is the page size). On a running
|
|
861
|
+
* crawl it yields the URLs kept so far and returns at the first empty page; it does not poll.
|
|
862
|
+
* Call `wait()` first to read every result.
|
|
863
|
+
*/
|
|
864
|
+
results(crawlId: string, options?: {
|
|
865
|
+
limit?: number;
|
|
866
|
+
}): AsyncGenerator<CrawlResult>;
|
|
867
|
+
/**
|
|
868
|
+
* Stop a running crawl. Idempotent: a crawl that already ended answers as it ended.
|
|
869
|
+
* Because a stop is safe to repeat, `stop()` retries a 429, 502, 503 (including `crawl_busy`,
|
|
870
|
+
* which means the stop was not saved and the crawl is still running) or 504 up to `retries`
|
|
871
|
+
* times, waiting `Retry-After` seconds (at most 30; 1 when the header is missing or unusable)
|
|
872
|
+
* each time, then throws the last error.
|
|
873
|
+
*/
|
|
874
|
+
stop(crawlId: string): Promise<CrawlStop>;
|
|
875
|
+
/**
|
|
876
|
+
* One kept URL's page as fetched (HTML). Pass the content id, a `content_url`, or the
|
|
877
|
+
* `CrawlResult` itself (its `content_url` is present once `content_status` is `fetched`).
|
|
878
|
+
* Throws `TypeError` when no content id can be read.
|
|
879
|
+
*/
|
|
880
|
+
content(crawlId: string, contentId: string | CrawlResult): Promise<string>;
|
|
881
|
+
/**
|
|
882
|
+
* Every result of the crawl in one download: its `status` and the parsed lines (with the
|
|
883
|
+
* page when the crawl has an `output_format`). On a running crawl, `status` is `running` and
|
|
884
|
+
* the lines hold only what was kept so far.
|
|
885
|
+
*/
|
|
886
|
+
download(crawlId: string): Promise<CrawlDownload>;
|
|
887
|
+
/**
|
|
888
|
+
* Poll until the crawl ends (any status but `running`) or `timeout` seconds pass, and return
|
|
889
|
+
* it, without results. A `failed` crawl resolves too: read `error`. On timeout the crawl is
|
|
890
|
+
* returned with status `running` and keeps running.
|
|
891
|
+
*/
|
|
892
|
+
wait(crawlId: string, options?: WaitForCrawlOptions): Promise<Crawl>;
|
|
893
|
+
}
|
|
894
|
+
|
|
714
895
|
/**
|
|
715
896
|
* A non-2xx response from the Batch API, decoded as RFC 7807 `application/problem+json`
|
|
716
897
|
* where possible. `code` is the stable Problem `code` member (e.g. `file_input_not_found`) —
|
|
@@ -759,12 +940,35 @@ interface PollUntilOptions<T> {
|
|
|
759
940
|
*/
|
|
760
941
|
declare function pollUntil<T>(fetch: () => Promise<T> | T, { isDone, isFailure, timeout, initialInterval, maxInterval, backoff, jitter, }: PollUntilOptions<T>): Promise<T>;
|
|
761
942
|
|
|
943
|
+
/**
|
|
944
|
+
* The API's code for an account Crawl is not enabled on (403).
|
|
945
|
+
*/
|
|
946
|
+
declare const CRAWL_NOT_ENABLED_CODE = "REQS008";
|
|
947
|
+
/**
|
|
948
|
+
* A non-2xx response from the Crawl API, decoded as RFC 9457 `application/problem+json`
|
|
949
|
+
* where possible. Branch on `status` and `code` (e.g. `crawl_not_found`, `too_many_crawls`,
|
|
950
|
+
* or `REQS008` when Crawl is not enabled for the account); `code` is undefined when the body
|
|
951
|
+
* has none.
|
|
952
|
+
*/
|
|
953
|
+
declare class ZenRowsCrawlError extends Error {
|
|
954
|
+
readonly status: number;
|
|
955
|
+
readonly problem: ProblemJson | undefined;
|
|
956
|
+
readonly code: string | undefined;
|
|
957
|
+
readonly detail: string | undefined;
|
|
958
|
+
readonly extras: Record<string, unknown> | undefined;
|
|
959
|
+
/** Seconds from the `Retry-After` header, e.g. 30 on a 429 `too_many_crawls`. */
|
|
960
|
+
readonly retryAfter: number | undefined;
|
|
961
|
+
constructor(status: number, problem: ProblemJson | undefined, extras?: Record<string, unknown>, retryAfter?: number);
|
|
962
|
+
}
|
|
963
|
+
|
|
762
964
|
type HttpMethods = "GET" | "POST" | "PUT";
|
|
763
965
|
/** Extract mode — see https://docs.zenrows.com for what each mode returns. */
|
|
764
966
|
type ExtractMode = "auto" | "native" | "standard";
|
|
765
967
|
interface ClientConfig {
|
|
766
968
|
concurrency?: number;
|
|
767
969
|
retries?: number;
|
|
970
|
+
/** Config for `client.crawl`: its own `baseURL`, `retries` and `timeout`. */
|
|
971
|
+
crawl?: CrawlClientConfig;
|
|
768
972
|
}
|
|
769
973
|
interface ZenRowsConfig {
|
|
770
974
|
/** Set to "auto" to enable Adaptive Stealth Mode — Zenrows starts with the cheapest
|
|
@@ -802,6 +1006,8 @@ declare class ZenRows {
|
|
|
802
1006
|
readonly fetchWithRetry: (input: string | URL | Request, init?: (RequestInit & fetch_retry.RequestInitRetryParams<typeof fetch>) | undefined) => Promise<Response>;
|
|
803
1007
|
/** Client for the Batch API (async job/run/task model) — see `./batch.ts`. */
|
|
804
1008
|
readonly batch: ZenRowsBatchClient;
|
|
1009
|
+
/** Client for the Crawl API (new; one start URL in, the URLs behind it out). See `./crawl/client.ts`. */
|
|
1010
|
+
readonly crawl: ZenRowsCrawlClient;
|
|
805
1011
|
constructor(apiKey: string, clientConfig?: ClientConfig);
|
|
806
1012
|
/**
|
|
807
1013
|
* Fetch a URL through Zenrows — the main page-scraping product. This is the primary entry
|
|
@@ -844,4 +1050,4 @@ declare class ZenRows {
|
|
|
844
1050
|
private worker;
|
|
845
1051
|
}
|
|
846
1052
|
|
|
847
|
-
export { AUTO_MAX_CREDITS, AUTO_MIN_CREDITS, type AddTasksResponse, At, BASE_CREDITS, type BatchClientConfig, type BatchTask, type BatchWebhookConfig, type Cadence, Calendar, type CostEstimate, type CostLine, type CreateJobInputResponse, CurrentRun, DEFAULT_MAX_BYTES_PER_FILE, DEFAULT_MAX_COUNT_IN_MEMORY, DEFAULT_MAX_FILES, DEFAULT_MAX_TOTAL_BYTES_IN_MEMORY, Daily, type DownloadToDirOptions, type DownloadToMemoryOptions, type DownloadedResult, type EstimateTask, type Export, ExportHandle, ExportRef, type ExportStatus, type Extensible, type ExtractMode, type FileInputUploadTarget, type GetResultsOptions, type HMACKeyCreated, type HMACKeyFinalized, type HMACKeyList, type HMACKeyMeta, type IngestStatus, JS_AND_PROXY_CREDITS, JS_CREDITS, type Job, JobHandle, JobRef, type JobSchedule, type JobStatus, type JobType, type ListJobRunsResponse, type ListJobsOptions, type ListJobsResponse, type ListResultsResponse, Monthly, PREMIUM_PROXY_CREDITS, type ParamMap, type ParamValue, type PauseState, type PollUntilOptions, type ProblemJson, Rate, type RerunJobResponse, type Run, type RunFailureReason, RunHandle, RunRef, type RunStats, type RunStatus, type Schedule, type ScheduleState, type Spend, type StartExportResponse, type SubmitJobOptions, type SubmitJobResponse, type SubmitTypedOptions, type TaskHistoryEvent, type TaskHistoryResponse, type TaskLike, type TaskResult, type TaskSpend, type TaskStatus, type TestWebhookResponse, type Tier, type WaitForRunOptions, WaiterFailureError, WaiterTimeoutError, type WebhookConfig, Weekly, ZenRows, ZenRowsBatchClient, ZenRowsBatchError, type ZenRowsConfig, downloadTaskToFile, downloadTaskToMemory, downloadToDir, downloadToMemory, estimateCost, parseProblem, pollUntil };
|
|
1053
|
+
export { AUTO_MAX_CREDITS, AUTO_MIN_CREDITS, type AddTasksResponse, At, BASE_CREDITS, type BatchClientConfig, type BatchTask, type BatchWebhookConfig, CRAWL_NOT_ENABLED_CODE, type Cadence, Calendar, type CostEstimate, type CostLine, type Crawl, type CrawlClientConfig, type CrawlContentStatus, type CrawlCoverage, type CrawlDownload, type CrawlErrorCode, type CrawlExportLine, type CrawlList, type CrawlOutputFormat, type CrawlResult, type CrawlRunError, type CrawlStatus, type CrawlStop, type CrawlStopReason, type CrawlWithResults, type CreateCrawlParams, type CreateJobInputResponse, CurrentRun, DEFAULT_MAX_BYTES_PER_FILE, DEFAULT_MAX_COUNT_IN_MEMORY, DEFAULT_MAX_FILES, DEFAULT_MAX_TOTAL_BYTES_IN_MEMORY, Daily, type DownloadToDirOptions, type DownloadToMemoryOptions, type DownloadedResult, type EstimateTask, type Export, ExportHandle, ExportRef, type ExportStatus, type Extensible, type ExtractMode, type FileInputUploadTarget, type GetResultsOptions, type HMACKeyCreated, type HMACKeyFinalized, type HMACKeyList, type HMACKeyMeta, type IngestStatus, JS_AND_PROXY_CREDITS, JS_CREDITS, type Job, JobHandle, JobRef, type JobSchedule, type JobStatus, type JobType, type ListJobRunsResponse, type ListJobsOptions, type ListJobsResponse, type ListResultsResponse, Monthly, PREMIUM_PROXY_CREDITS, type ParamMap, type ParamValue, type PauseState, type PollUntilOptions, type ProblemJson, Rate, type RerunJobResponse, type Run, type RunFailureReason, RunHandle, RunRef, type RunStats, type RunStatus, type Schedule, type ScheduleState, type Spend, type StartExportResponse, type SubmitJobOptions, type SubmitJobResponse, type SubmitTypedOptions, type TaskHistoryEvent, type TaskHistoryResponse, type TaskLike, type TaskResult, type TaskSpend, type TaskStatus, type TestWebhookResponse, type Tier, type WaitForCrawlOptions, type WaitForRunOptions, WaiterFailureError, WaiterTimeoutError, type WebhookConfig, Weekly, ZenRows, ZenRowsBatchClient, ZenRowsBatchError, type ZenRowsConfig, ZenRowsCrawlClient, ZenRowsCrawlError, downloadTaskToFile, downloadTaskToMemory, downloadToDir, downloadToMemory, estimateCost, parseProblem, pollUntil };
|