scrapfly-sdk 0.7.3 → 0.9.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.
Files changed (69) hide show
  1. package/esm/browserconfig.d.ts +59 -0
  2. package/esm/browserconfig.d.ts.map +1 -0
  3. package/esm/browserconfig.js +207 -0
  4. package/esm/client.d.ts +193 -1
  5. package/esm/client.d.ts.map +1 -1
  6. package/esm/client.js +786 -5
  7. package/esm/crawl.d.ts +118 -0
  8. package/esm/crawl.d.ts.map +1 -0
  9. package/esm/crawl.js +230 -0
  10. package/esm/crawlerconfig.d.ts +119 -0
  11. package/esm/crawlerconfig.d.ts.map +1 -0
  12. package/esm/crawlerconfig.js +398 -0
  13. package/esm/crawlerresult.d.ts +253 -0
  14. package/esm/crawlerresult.d.ts.map +1 -0
  15. package/esm/crawlerresult.js +327 -0
  16. package/esm/errors.d.ts +4 -0
  17. package/esm/errors.d.ts.map +1 -1
  18. package/esm/errors.js +6 -0
  19. package/esm/extractionconfig.d.ts +2 -0
  20. package/esm/extractionconfig.d.ts.map +1 -1
  21. package/esm/extractionconfig.js +10 -0
  22. package/esm/main.d.ts +8 -1
  23. package/esm/main.d.ts.map +1 -1
  24. package/esm/main.js +6 -1
  25. package/esm/polyfill.d.ts +2 -0
  26. package/esm/polyfill.d.ts.map +1 -1
  27. package/esm/polyfill.js +12 -0
  28. package/esm/scrapeconfig.d.ts +27 -0
  29. package/esm/scrapeconfig.d.ts.map +1 -1
  30. package/esm/scrapeconfig.js +44 -1
  31. package/esm/screenshotconfig.d.ts +2 -2
  32. package/esm/screenshotconfig.d.ts.map +1 -1
  33. package/esm/utils.d.ts.map +1 -1
  34. package/esm/utils.js +16 -2
  35. package/package.json +1 -1
  36. package/script/browserconfig.d.ts +59 -0
  37. package/script/browserconfig.d.ts.map +1 -0
  38. package/script/browserconfig.js +211 -0
  39. package/script/client.d.ts +193 -1
  40. package/script/client.d.ts.map +1 -1
  41. package/script/client.js +785 -4
  42. package/script/crawl.d.ts +118 -0
  43. package/script/crawl.d.ts.map +1 -0
  44. package/script/crawl.js +257 -0
  45. package/script/crawlerconfig.d.ts +119 -0
  46. package/script/crawlerconfig.d.ts.map +1 -0
  47. package/script/crawlerconfig.js +402 -0
  48. package/script/crawlerresult.d.ts +253 -0
  49. package/script/crawlerresult.d.ts.map +1 -0
  50. package/script/crawlerresult.js +335 -0
  51. package/script/errors.d.ts +4 -0
  52. package/script/errors.d.ts.map +1 -1
  53. package/script/errors.js +9 -1
  54. package/script/extractionconfig.d.ts +2 -0
  55. package/script/extractionconfig.d.ts.map +1 -1
  56. package/script/extractionconfig.js +10 -0
  57. package/script/main.d.ts +8 -1
  58. package/script/main.d.ts.map +1 -1
  59. package/script/main.js +17 -1
  60. package/script/polyfill.d.ts +2 -0
  61. package/script/polyfill.d.ts.map +1 -1
  62. package/script/polyfill.js +14 -1
  63. package/script/scrapeconfig.d.ts +27 -0
  64. package/script/scrapeconfig.d.ts.map +1 -1
  65. package/script/scrapeconfig.js +44 -1
  66. package/script/screenshotconfig.d.ts +2 -2
  67. package/script/screenshotconfig.d.ts.map +1 -1
  68. package/script/utils.d.ts.map +1 -1
  69. package/script/utils.js +16 -2
@@ -0,0 +1,118 @@
1
+ import type { ScrapflyClient } from './client.js';
2
+ import type { CrawlerConfig, CrawlerContentFormat } from './crawlerconfig.js';
3
+ import type { CrawlerArtifact, CrawlerStatus, CrawlerUrls } from './crawlerresult.js';
4
+ /**
5
+ * High-level fluent wrapper around a single crawler job lifecycle.
6
+ *
7
+ * Mirrors the Python SDK's `Crawl` class. Internally calls into `ScrapflyClient`'s
8
+ * lower-level crawler methods, but adds:
9
+ *
10
+ * - polling helpers (`wait()`)
11
+ * - per-instance caching of the most recent status and downloaded artifacts
12
+ * - convenience methods that pre-fill the crawler UUID
13
+ *
14
+ * Use this when you want a simple `start → wait → read` flow. Use the lower-level
15
+ * `client.crawl*` methods directly if you need finer control (e.g. polling at
16
+ * irregular intervals or reusing a status response across calls).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const crawl = new Crawl(client, new CrawlerConfig({
21
+ * url: 'https://web-scraping.dev/products',
22
+ * page_limit: 10,
23
+ * content_formats: ['markdown'],
24
+ * }));
25
+ *
26
+ * await crawl.start();
27
+ * await crawl.wait({ pollInterval: 2 });
28
+ *
29
+ * for (const entry of (await crawl.urls({ status: 'visited' })).urls) {
30
+ * const md = await crawl.read(entry.url, 'markdown');
31
+ * console.log(entry.url, md?.length);
32
+ * }
33
+ * ```
34
+ */
35
+ export declare class Crawl {
36
+ private readonly client;
37
+ private readonly config;
38
+ private _uuid?;
39
+ private _status?;
40
+ private readonly _artifactCache;
41
+ constructor(client: ScrapflyClient, config: CrawlerConfig);
42
+ /** The crawler UUID returned by the API after `start()`, or undefined before. */
43
+ get uuid(): string | undefined;
44
+ /** True once `start()` has been called and the crawler has a UUID. */
45
+ get started(): boolean;
46
+ /**
47
+ * Schedule the crawl on the Scrapfly API.
48
+ *
49
+ * Returns `this` for chaining. Throws `ScrapflyCrawlerError` if `start()` has
50
+ * already been called on this instance.
51
+ */
52
+ start(): Promise<this>;
53
+ private requireUuid;
54
+ /**
55
+ * Fetch (or return cached) status for this crawl.
56
+ *
57
+ * @param refresh — when true (default), always re-query the API. When false,
58
+ * return the cached status from the previous call (or fetch fresh if none).
59
+ */
60
+ status(refresh?: boolean): Promise<CrawlerStatus>;
61
+ /**
62
+ * Block until the crawler reaches a terminal state, polling status periodically.
63
+ *
64
+ * Returns `this` for chaining when the job completes successfully. Throws
65
+ * `ScrapflyCrawlerError` if the job fails, is cancelled, or `maxWait` is exceeded.
66
+ *
67
+ * @param opts.pollInterval — seconds between polls (default 5)
68
+ * @param opts.maxWait — maximum total seconds to wait (default: no limit)
69
+ * @param opts.verbose — log progress on every poll
70
+ * @param opts.allowCancelled — when `true`, return normally if the crawler
71
+ * reaches CANCELLED instead of throwing. Useful for the cancel-then-wait
72
+ * pattern where the caller already triggered the cancellation. Defaults
73
+ * to `false`, preserving the prior throw-on-cancel behavior for callers
74
+ * that observe external interrupts.
75
+ */
76
+ wait(opts?: {
77
+ pollInterval?: number;
78
+ maxWait?: number;
79
+ verbose?: boolean;
80
+ allowCancelled?: boolean;
81
+ }): Promise<this>;
82
+ /** Cancel the crawl. Returns `true` on success. */
83
+ cancel(): Promise<boolean>;
84
+ /**
85
+ * List crawled URLs (paginated, optionally filtered by status).
86
+ *
87
+ * Convenience wrapper around `client.crawlUrls(uuid, opts)`. **New endpoint** —
88
+ * not available in the Python SDK as of 0.8.27.
89
+ */
90
+ urls(opts?: {
91
+ status?: 'visited' | 'pending' | 'failed';
92
+ page?: number;
93
+ per_page?: number;
94
+ }): Promise<CrawlerUrls>;
95
+ /**
96
+ * Read raw content for a single crawled URL using `plain=true` mode.
97
+ *
98
+ * Returns `null` if the URL has no content for that format. Throws
99
+ * `ScrapflyCrawlerError` for any non-404 error. **New mode** — not available in
100
+ * the Python SDK as of 0.8.27.
101
+ */
102
+ read(url: string, format?: CrawlerContentFormat): Promise<string | null>;
103
+ /**
104
+ * Batch-read content for multiple URLs in one round-trip.
105
+ *
106
+ * Convenience wrapper around `client.crawlContentsBatch`. Limited to 100 URLs.
107
+ */
108
+ readBatch(urls: string[], formats?: CrawlerContentFormat[]): Promise<Record<string, Record<string, string>>>;
109
+ /**
110
+ * Download the WARC artifact (cached after first call).
111
+ */
112
+ warc(): Promise<CrawlerArtifact>;
113
+ /**
114
+ * Download the HAR artifact (cached after first call).
115
+ */
116
+ har(): Promise<CrawlerArtifact>;
117
+ }
118
+ //# sourceMappingURL=crawl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crawl.d.ts","sourceRoot":"","sources":["../src/crawl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EACV,eAAe,EAGf,aA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oBAA6B,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAetF;;;;OAIG;IACG,SAAS,CACb,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE,oBAAoB,EAAa,GACzC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAKlD;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC;IAStC;;OAEG;IACG,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC;CAQtC"}
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Crawl = void 0;
27
+ const errors = __importStar(require("./errors.js"));
28
+ const logger_js_1 = require("./logger.js");
29
+ /**
30
+ * High-level fluent wrapper around a single crawler job lifecycle.
31
+ *
32
+ * Mirrors the Python SDK's `Crawl` class. Internally calls into `ScrapflyClient`'s
33
+ * lower-level crawler methods, but adds:
34
+ *
35
+ * - polling helpers (`wait()`)
36
+ * - per-instance caching of the most recent status and downloaded artifacts
37
+ * - convenience methods that pre-fill the crawler UUID
38
+ *
39
+ * Use this when you want a simple `start → wait → read` flow. Use the lower-level
40
+ * `client.crawl*` methods directly if you need finer control (e.g. polling at
41
+ * irregular intervals or reusing a status response across calls).
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const crawl = new Crawl(client, new CrawlerConfig({
46
+ * url: 'https://web-scraping.dev/products',
47
+ * page_limit: 10,
48
+ * content_formats: ['markdown'],
49
+ * }));
50
+ *
51
+ * await crawl.start();
52
+ * await crawl.wait({ pollInterval: 2 });
53
+ *
54
+ * for (const entry of (await crawl.urls({ status: 'visited' })).urls) {
55
+ * const md = await crawl.read(entry.url, 'markdown');
56
+ * console.log(entry.url, md?.length);
57
+ * }
58
+ * ```
59
+ */
60
+ class Crawl {
61
+ constructor(client, config) {
62
+ Object.defineProperty(this, "client", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: client
67
+ });
68
+ Object.defineProperty(this, "config", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: config
73
+ });
74
+ Object.defineProperty(this, "_uuid", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
80
+ Object.defineProperty(this, "_status", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
86
+ Object.defineProperty(this, "_artifactCache", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: new Map()
91
+ });
92
+ }
93
+ /** The crawler UUID returned by the API after `start()`, or undefined before. */
94
+ get uuid() {
95
+ return this._uuid;
96
+ }
97
+ /** True once `start()` has been called and the crawler has a UUID. */
98
+ get started() {
99
+ return this._uuid !== undefined;
100
+ }
101
+ /**
102
+ * Schedule the crawl on the Scrapfly API.
103
+ *
104
+ * Returns `this` for chaining. Throws `ScrapflyCrawlerError` if `start()` has
105
+ * already been called on this instance.
106
+ */
107
+ async start() {
108
+ if (this._uuid) {
109
+ throw new errors.ScrapflyCrawlerError('Crawl already started', { code: 'ALREADY_STARTED' });
110
+ }
111
+ const response = await this.client.crawl(this.config);
112
+ this._uuid = response.crawler_uuid;
113
+ logger_js_1.log.debug('crawl started', { crawler_uuid: this._uuid });
114
+ return this;
115
+ }
116
+ requireUuid() {
117
+ if (!this._uuid) {
118
+ throw new errors.ScrapflyCrawlerError('Crawl has not been started yet. Call start() first.', { code: 'NOT_STARTED' });
119
+ }
120
+ return this._uuid;
121
+ }
122
+ /**
123
+ * Fetch (or return cached) status for this crawl.
124
+ *
125
+ * @param refresh — when true (default), always re-query the API. When false,
126
+ * return the cached status from the previous call (or fetch fresh if none).
127
+ */
128
+ async status(refresh = true) {
129
+ const uuid = this.requireUuid();
130
+ if (refresh || !this._status) {
131
+ this._status = await this.client.crawlStatus(uuid);
132
+ }
133
+ return this._status;
134
+ }
135
+ /**
136
+ * Block until the crawler reaches a terminal state, polling status periodically.
137
+ *
138
+ * Returns `this` for chaining when the job completes successfully. Throws
139
+ * `ScrapflyCrawlerError` if the job fails, is cancelled, or `maxWait` is exceeded.
140
+ *
141
+ * @param opts.pollInterval — seconds between polls (default 5)
142
+ * @param opts.maxWait — maximum total seconds to wait (default: no limit)
143
+ * @param opts.verbose — log progress on every poll
144
+ * @param opts.allowCancelled — when `true`, return normally if the crawler
145
+ * reaches CANCELLED instead of throwing. Useful for the cancel-then-wait
146
+ * pattern where the caller already triggered the cancellation. Defaults
147
+ * to `false`, preserving the prior throw-on-cancel behavior for callers
148
+ * that observe external interrupts.
149
+ */
150
+ async wait(opts) {
151
+ const pollInterval = opts?.pollInterval ?? 5;
152
+ const maxWait = opts?.maxWait;
153
+ const verbose = opts?.verbose ?? false;
154
+ const allowCancelled = opts?.allowCancelled ?? false;
155
+ const start = Date.now();
156
+ while (true) {
157
+ const status = await this.status(true);
158
+ if (verbose) {
159
+ logger_js_1.log.info(`crawl ${this._uuid} status=${status.status} visited=${status.state.urls_visited}/${status.state.urls_extracted}`);
160
+ }
161
+ if (status.is_finished || status.status === 'CANCELLED') {
162
+ if (status.isFailed) {
163
+ throw new errors.ScrapflyCrawlerError(`Crawl ${this._uuid} failed: ${status.state.stop_reason ?? 'unknown reason'}`, { code: 'FAILED', stop_reason: status.state.stop_reason, status });
164
+ }
165
+ if (status.isCancelled) {
166
+ if (allowCancelled) {
167
+ if (verbose) {
168
+ logger_js_1.log.info(`crawl ${this._uuid} was cancelled (allowCancelled=true)`);
169
+ }
170
+ return this;
171
+ }
172
+ throw new errors.ScrapflyCrawlerError(`Crawl ${this._uuid} was cancelled (reason: ${status.state.stop_reason ?? 'unknown'})`, { code: 'CANCELLED', stop_reason: status.state.stop_reason, status });
173
+ }
174
+ // status.isComplete
175
+ return this;
176
+ }
177
+ if (maxWait !== undefined) {
178
+ const elapsedSeconds = (Date.now() - start) / 1000;
179
+ if (elapsedSeconds + pollInterval > maxWait) {
180
+ throw new errors.ScrapflyCrawlerError(`Timed out waiting for crawl ${this._uuid} after ${maxWait}s`, { code: 'TIMEOUT', status });
181
+ }
182
+ }
183
+ await new Promise((resolve) => setTimeout(resolve, pollInterval * 1000));
184
+ }
185
+ }
186
+ /** Cancel the crawl. Returns `true` on success. */
187
+ async cancel() {
188
+ const uuid = this.requireUuid();
189
+ return await this.client.crawlCancel(uuid);
190
+ }
191
+ /**
192
+ * List crawled URLs (paginated, optionally filtered by status).
193
+ *
194
+ * Convenience wrapper around `client.crawlUrls(uuid, opts)`. **New endpoint** —
195
+ * not available in the Python SDK as of 0.8.27.
196
+ */
197
+ async urls(opts) {
198
+ const uuid = this.requireUuid();
199
+ return await this.client.crawlUrls(uuid, opts);
200
+ }
201
+ /**
202
+ * Read raw content for a single crawled URL using `plain=true` mode.
203
+ *
204
+ * Returns `null` if the URL has no content for that format. Throws
205
+ * `ScrapflyCrawlerError` for any non-404 error. **New mode** — not available in
206
+ * the Python SDK as of 0.8.27.
207
+ */
208
+ async read(url, format = 'html') {
209
+ const uuid = this.requireUuid();
210
+ try {
211
+ const result = await this.client.crawlContents(uuid, { url, format, plain: true });
212
+ // crawlContents in plain mode always returns string
213
+ return typeof result === 'string' ? result : JSON.stringify(result);
214
+ }
215
+ catch (e) {
216
+ // Treat 404 as "no content for this URL" rather than re-throwing
217
+ if (e instanceof errors.ScrapflyError && (e.args?.http_status_code === 404)) {
218
+ return null;
219
+ }
220
+ throw e;
221
+ }
222
+ }
223
+ /**
224
+ * Batch-read content for multiple URLs in one round-trip.
225
+ *
226
+ * Convenience wrapper around `client.crawlContentsBatch`. Limited to 100 URLs.
227
+ */
228
+ async readBatch(urls, formats = ['html']) {
229
+ const uuid = this.requireUuid();
230
+ return await this.client.crawlContentsBatch(uuid, urls, formats);
231
+ }
232
+ /**
233
+ * Download the WARC artifact (cached after first call).
234
+ */
235
+ async warc() {
236
+ const uuid = this.requireUuid();
237
+ const cached = this._artifactCache.get('warc');
238
+ if (cached)
239
+ return cached;
240
+ const artifact = await this.client.crawlArtifact(uuid, 'warc');
241
+ this._artifactCache.set('warc', artifact);
242
+ return artifact;
243
+ }
244
+ /**
245
+ * Download the HAR artifact (cached after first call).
246
+ */
247
+ async har() {
248
+ const uuid = this.requireUuid();
249
+ const cached = this._artifactCache.get('har');
250
+ if (cached)
251
+ return cached;
252
+ const artifact = await this.client.crawlArtifact(uuid, 'har');
253
+ this._artifactCache.set('har', artifact);
254
+ return artifact;
255
+ }
256
+ }
257
+ exports.Crawl = Crawl;
@@ -0,0 +1,119 @@
1
+ import type { Rec } from './types.js';
2
+ /**
3
+ * Content formats supported by the Crawler API.
4
+ *
5
+ * - `html` — original HTML
6
+ * - `clean_html` — sanitized/cleaned HTML
7
+ * - `markdown` — LLM-ready markdown
8
+ * - `text` — plain-text extraction
9
+ * - `json` — parse as JSON (for API responses)
10
+ * - `extracted_data` — structured data from extraction rules
11
+ * - `page_metadata` — title, description, etc.
12
+ */
13
+ export type CrawlerContentFormat = 'html' | 'clean_html' | 'markdown' | 'text' | 'json' | 'extracted_data' | 'page_metadata';
14
+ /**
15
+ * Webhook event names emitted by the crawler.
16
+ *
17
+ * Source of truth: `apps/scrapfly/scrape-engine/scrape_engine/scrape_engine/crawler/webhook_manager.py`
18
+ * lines 11-20. Verified to match the public docs and the JSON example payloads.
19
+ */
20
+ export type CrawlerWebhookEventName = 'crawler_started' | 'crawler_url_visited' | 'crawler_url_skipped' | 'crawler_url_discovered' | 'crawler_url_failed' | 'crawler_stopped' | 'crawler_cancelled' | 'crawler_finished';
21
+ /**
22
+ * Constructor options for {@link CrawlerConfig}.
23
+ *
24
+ * Every field except `url` is optional. Fields left unset are NOT sent to the API,
25
+ * which lets the server apply its documented defaults (e.g. `respect_robots_txt=true`).
26
+ */
27
+ export type CrawlerConfigOptions = {
28
+ url: string;
29
+ page_limit?: number;
30
+ max_depth?: number;
31
+ max_duration?: number;
32
+ max_api_credit?: number;
33
+ exclude_paths?: string[];
34
+ include_only_paths?: string[];
35
+ ignore_base_path_restriction?: boolean;
36
+ follow_external_links?: boolean;
37
+ allowed_external_domains?: string[];
38
+ follow_internal_subdomains?: boolean;
39
+ allowed_internal_subdomains?: string[];
40
+ headers?: Rec<string>;
41
+ delay?: number;
42
+ user_agent?: string;
43
+ max_concurrency?: number;
44
+ rendering_delay?: number;
45
+ use_sitemaps?: boolean;
46
+ respect_robots_txt?: boolean;
47
+ ignore_no_follow?: boolean;
48
+ cache?: boolean;
49
+ cache_ttl?: number;
50
+ cache_clear?: boolean;
51
+ content_formats?: CrawlerContentFormat[];
52
+ extraction_rules?: Rec<any>;
53
+ asp?: boolean;
54
+ proxy_pool?: string;
55
+ country?: string;
56
+ webhook_name?: string;
57
+ webhook_events?: CrawlerWebhookEventName[];
58
+ };
59
+ /**
60
+ * Configuration for a Scrapfly Crawler API job.
61
+ *
62
+ * Mirrors the documented `POST /crawl` request body field-for-field. Fields left
63
+ * unset are dropped from the serialized output so the server applies its own defaults.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const config = new CrawlerConfig({
68
+ * url: 'https://web-scraping.dev/products',
69
+ * page_limit: 10,
70
+ * content_formats: ['markdown'],
71
+ * });
72
+ * ```
73
+ */
74
+ export declare class CrawlerConfig {
75
+ url: string;
76
+ page_limit?: number;
77
+ max_depth?: number;
78
+ max_duration?: number;
79
+ max_api_credit?: number;
80
+ exclude_paths?: string[];
81
+ include_only_paths?: string[];
82
+ ignore_base_path_restriction?: boolean;
83
+ follow_external_links?: boolean;
84
+ allowed_external_domains?: string[];
85
+ follow_internal_subdomains?: boolean;
86
+ allowed_internal_subdomains?: string[];
87
+ headers?: Rec<string>;
88
+ delay?: number;
89
+ user_agent?: string;
90
+ max_concurrency?: number;
91
+ rendering_delay?: number;
92
+ use_sitemaps?: boolean;
93
+ respect_robots_txt?: boolean;
94
+ ignore_no_follow?: boolean;
95
+ cache?: boolean;
96
+ cache_ttl?: number;
97
+ cache_clear?: boolean;
98
+ content_formats?: CrawlerContentFormat[];
99
+ extraction_rules?: Rec<any>;
100
+ asp?: boolean;
101
+ proxy_pool?: string;
102
+ country?: string;
103
+ webhook_name?: string;
104
+ webhook_events?: CrawlerWebhookEventName[];
105
+ constructor(options: CrawlerConfigOptions);
106
+ private validateOptions;
107
+ /**
108
+ * Serialize to a flat object suitable for `JSON.stringify()` as a `POST /crawl` body.
109
+ *
110
+ * Unlike `ScrapeConfig.toApiParams()`, the crawler API takes its config as a JSON
111
+ * **body**, not URL query parameters. The API key is therefore NOT included here —
112
+ * it's added to the URL by the client.
113
+ *
114
+ * Fields left undefined are dropped so the server applies its own documented
115
+ * defaults (e.g. `respect_robots_txt=true`).
116
+ */
117
+ toApiParams(): Rec<any>;
118
+ }
119
+ //# sourceMappingURL=crawlerconfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crawlerconfig.d.ts","sourceRoot":"","sources":["../src/crawlerconfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,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