@crawlee/utils 4.0.0-beta.8 → 4.0.0-beta.80

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 (73) hide show
  1. package/README.md +17 -13
  2. package/index.d.ts +4 -5
  3. package/index.js +3 -4
  4. package/internals/blocked.d.ts +0 -1
  5. package/internals/blocked.js +0 -1
  6. package/internals/cheerio.d.ts +3 -2
  7. package/internals/cheerio.js +4 -5
  8. package/internals/chunk.d.ts +0 -1
  9. package/internals/chunk.js +0 -1
  10. package/internals/debug.d.ts +11 -1
  11. package/internals/debug.js +34 -1
  12. package/internals/extract-urls.d.ts +5 -1
  13. package/internals/extract-urls.js +8 -5
  14. package/internals/general.d.ts +17 -15
  15. package/internals/general.js +44 -83
  16. package/internals/iterables.d.ts +126 -0
  17. package/internals/iterables.js +230 -0
  18. package/internals/open_graph_parser.d.ts +2 -3
  19. package/internals/open_graph_parser.js +8 -9
  20. package/internals/robots.d.ts +20 -4
  21. package/internals/robots.js +31 -33
  22. package/internals/sitemap.d.ts +64 -7
  23. package/internals/sitemap.js +174 -34
  24. package/internals/social.d.ts +1 -2
  25. package/internals/social.js +7 -5
  26. package/internals/typedefs.d.ts +0 -1
  27. package/internals/typedefs.js +0 -1
  28. package/internals/url.d.ts +1 -2
  29. package/internals/url.js +1 -2
  30. package/package.json +6 -6
  31. package/index.d.ts.map +0 -1
  32. package/index.js.map +0 -1
  33. package/internals/blocked.d.ts.map +0 -1
  34. package/internals/blocked.js.map +0 -1
  35. package/internals/cheerio.d.ts.map +0 -1
  36. package/internals/cheerio.js.map +0 -1
  37. package/internals/chunk.d.ts.map +0 -1
  38. package/internals/chunk.js.map +0 -1
  39. package/internals/debug.d.ts.map +0 -1
  40. package/internals/debug.js.map +0 -1
  41. package/internals/extract-urls.d.ts.map +0 -1
  42. package/internals/extract-urls.js.map +0 -1
  43. package/internals/general.d.ts.map +0 -1
  44. package/internals/general.js.map +0 -1
  45. package/internals/memory-info.d.ts +0 -26
  46. package/internals/memory-info.d.ts.map +0 -1
  47. package/internals/memory-info.js +0 -131
  48. package/internals/memory-info.js.map +0 -1
  49. package/internals/open_graph_parser.d.ts.map +0 -1
  50. package/internals/open_graph_parser.js.map +0 -1
  51. package/internals/robots.d.ts.map +0 -1
  52. package/internals/robots.js.map +0 -1
  53. package/internals/sitemap.d.ts.map +0 -1
  54. package/internals/sitemap.js.map +0 -1
  55. package/internals/social.d.ts.map +0 -1
  56. package/internals/social.js.map +0 -1
  57. package/internals/systemInfoV2/cpu-info.d.ts +0 -64
  58. package/internals/systemInfoV2/cpu-info.d.ts.map +0 -1
  59. package/internals/systemInfoV2/cpu-info.js +0 -211
  60. package/internals/systemInfoV2/cpu-info.js.map +0 -1
  61. package/internals/systemInfoV2/memory-info.d.ts +0 -28
  62. package/internals/systemInfoV2/memory-info.d.ts.map +0 -1
  63. package/internals/systemInfoV2/memory-info.js +0 -118
  64. package/internals/systemInfoV2/memory-info.js.map +0 -1
  65. package/internals/systemInfoV2/ps-tree.d.ts +0 -18
  66. package/internals/systemInfoV2/ps-tree.d.ts.map +0 -1
  67. package/internals/systemInfoV2/ps-tree.js +0 -145
  68. package/internals/systemInfoV2/ps-tree.js.map +0 -1
  69. package/internals/typedefs.d.ts.map +0 -1
  70. package/internals/typedefs.js.map +0 -1
  71. package/internals/url.d.ts.map +0 -1
  72. package/internals/url.js.map +0 -1
  73. package/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,230 @@
1
+ import { inspect } from 'node:util';
2
+ /**
3
+ * Type guard that checks if a value is iterable (has Symbol.iterator).
4
+ * @internal
5
+ *
6
+ * **Example usage:**
7
+ * ```ts
8
+ * if (isIterable(someValue)) {
9
+ * for (const item of someValue) {
10
+ * console.log(item);
11
+ * }
12
+ * }
13
+ * ```
14
+ */
15
+ export function isIterable(value) {
16
+ if (value == null || typeof value === 'string' || ArrayBuffer.isView(value)) {
17
+ return false;
18
+ }
19
+ if (Array.isArray(value)) {
20
+ return true;
21
+ }
22
+ return typeof Object(value)[Symbol.iterator] === 'function';
23
+ }
24
+ /**
25
+ * Type guard that checks if a value is async iterable (has Symbol.asyncIterator).
26
+ * @internal
27
+ *
28
+ * **Example usage:**
29
+ * ```ts
30
+ * if (isAsyncIterable(someValue)) {
31
+ * for await (const item of someValue) {
32
+ * console.log(item);
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+ export function isAsyncIterable(value) {
38
+ if (value == null || typeof value === 'string' || ArrayBuffer.isView(value)) {
39
+ return false;
40
+ }
41
+ return typeof Object(value)[Symbol.asyncIterator] === 'function';
42
+ }
43
+ /**
44
+ * Converts any iterable or async iterable to an async iterable.
45
+ * @internal
46
+ *
47
+ * @yields Each item from the input iterable
48
+ *
49
+ * **Example usage:**
50
+ * ```ts
51
+ * const syncArray = [1, 2, 3];
52
+ * for await (const item of asyncifyIterable(syncArray)) {
53
+ * console.log(item); // 1, 2, 3
54
+ * }
55
+ * ```
56
+ */
57
+ export async function* asyncifyIterable(iterable) {
58
+ yield* iterable;
59
+ }
60
+ /**
61
+ * Lazily splits the input async iterable into chunks of specified size.
62
+ * The last chunk may contain fewer items if the total number of items
63
+ * is not evenly divisible by the chunk size.
64
+ * @internal
65
+ *
66
+ * @yields Arrays of items, each containing up to chunkSize items
67
+ *
68
+ * **Example usage:**
69
+ * ```ts
70
+ * const numbers = async function* () {
71
+ * for (let i = 1; i <= 10; i++) yield i;
72
+ * };
73
+ *
74
+ * for await (const chunk of chunkedAsyncIterable(numbers(), 3)) {
75
+ * console.log(chunk); // [1, 2, 3], [4, 5, 6], [7, 8, 9], [10]
76
+ * }
77
+ * ```
78
+ */
79
+ export async function* chunkedAsyncIterable(iterable, chunkSize) {
80
+ const getChunkSize = typeof chunkSize === 'function' ? chunkSize : () => chunkSize;
81
+ if (typeof chunkSize === 'number' && chunkSize < 1) {
82
+ throw new Error(`Chunk size must be a positive number (${inspect(chunkSize)}) received`);
83
+ }
84
+ const iterator = Symbol.asyncIterator in iterable
85
+ ? iterable[Symbol.asyncIterator]()
86
+ : iterable[Symbol.iterator]();
87
+ while (true) {
88
+ const currentSize = getChunkSize();
89
+ if (currentSize < 1)
90
+ break;
91
+ const chunk = [];
92
+ for (let i = 0; i < currentSize; i++) {
93
+ const next = await iterator.next();
94
+ if (next.done) {
95
+ break;
96
+ }
97
+ chunk.push(next.value);
98
+ }
99
+ if (chunk.length === 0)
100
+ break;
101
+ yield chunk;
102
+ }
103
+ }
104
+ /**
105
+ * Wraps an async iterable to provide peek functionality, allowing you to look at
106
+ * the next value without consuming it from the iterator.
107
+ * @internal
108
+ *
109
+ * @param iterable - The async iterable to make peekable
110
+ *
111
+ * **Example usage:**
112
+ * ```ts
113
+ * const numbers = async function* () {
114
+ * yield 1; yield 2; yield 3;
115
+ * };
116
+ *
117
+ * const peekable = peekableAsyncIterable(numbers());
118
+ * const iterator = peekable[Symbol.asyncIterator]();
119
+ *
120
+ * console.log(await iterator.peek()); // 1 (doesn't consume)
121
+ * console.log(await iterator.peek()); // 1 (still doesn't consume)
122
+ * console.log(await iterator.next()); // { value: 1, done: false } (now consumed)
123
+ * console.log(await iterator.peek()); // 2 (next value)
124
+ * ```
125
+ */
126
+ export function peekableAsyncIterable(iterable) {
127
+ const iterator = asyncifyIterable(iterable)[Symbol.asyncIterator]();
128
+ let peekedValue;
129
+ let isExhausted = false;
130
+ const peekableIterator = {
131
+ async next() {
132
+ // If we have peeked a value, return it and clear the peek
133
+ if (peekedValue !== undefined) {
134
+ const result = peekedValue;
135
+ peekedValue = undefined;
136
+ if (result.done) {
137
+ isExhausted = true;
138
+ return { done: true, value: undefined };
139
+ }
140
+ return { done: false, value: result.value };
141
+ }
142
+ if (isExhausted) {
143
+ return { done: true, value: undefined };
144
+ }
145
+ const result = await iterator.next();
146
+ if (result.done) {
147
+ isExhausted = true;
148
+ }
149
+ return result;
150
+ },
151
+ async peek() {
152
+ if (peekedValue !== undefined) {
153
+ return peekedValue.done ? undefined : peekedValue.value;
154
+ }
155
+ if (isExhausted) {
156
+ return undefined;
157
+ }
158
+ const result = await iterator.next();
159
+ peekedValue = { done: result.done ?? false, value: result.value };
160
+ if (result.done) {
161
+ isExhausted = true;
162
+ return undefined;
163
+ }
164
+ return result.value;
165
+ },
166
+ [Symbol.asyncIterator]() {
167
+ return this;
168
+ },
169
+ };
170
+ return {
171
+ [Symbol.asyncIterator]() {
172
+ return peekableIterator;
173
+ },
174
+ };
175
+ }
176
+ // Source - https://stackoverflow.com/a/71288323
177
+ /**
178
+ * Merges multiple async iterables into a single async iterable, yielding values concurrently.
179
+ *
180
+ * **Example usage:**
181
+ * ```ts
182
+ * const asyncIterable1 = async function* () {
183
+ * yield 1; yield 3; yield 5;
184
+ * };
185
+ *
186
+ * const asyncIterable2 = async function* () {
187
+ * yield 2; yield 4; yield 6;
188
+ * };
189
+ *
190
+ * for await (const value of mergeAsyncIterables(asyncIterable1(), asyncIterable2())) {
191
+ * console.log(value);
192
+ * }
193
+ * ```
194
+ */
195
+ export async function* mergeAsyncIterables(...iterables) {
196
+ const asyncIterators = iterables.map((iterable) => iterable[Symbol.asyncIterator]());
197
+ const results = [];
198
+ let count = asyncIterators.length;
199
+ const never = new Promise(() => { });
200
+ async function getNext(asyncIterator, index) {
201
+ const result = await asyncIterator.next();
202
+ return {
203
+ index,
204
+ result,
205
+ };
206
+ }
207
+ const nextPromises = asyncIterators.map(getNext);
208
+ try {
209
+ while (count) {
210
+ const { index, result } = await Promise.race(nextPromises);
211
+ if (result.done) {
212
+ nextPromises[index] = never;
213
+ results[index] = result.value;
214
+ count--;
215
+ }
216
+ else {
217
+ nextPromises[index] = getNext(asyncIterators[index], index);
218
+ yield result.value;
219
+ }
220
+ }
221
+ }
222
+ finally {
223
+ for (const [index, iterator] of asyncIterators.entries()) {
224
+ // no await here - see https://github.com/tc39/proposal-async-iteration/issues/126
225
+ if (nextPromises[index] !== never && iterator.return != null)
226
+ void iterator.return();
227
+ }
228
+ }
229
+ return results;
230
+ }
@@ -14,7 +14,6 @@ type OpenGraphResult = string | string[] | Dictionary<string | Dictionary>;
14
14
  * Currently existing properties are kept up to date.
15
15
  * @returns Scraped OpenGraph properties as an object.
16
16
  */
17
- export declare function parseOpenGraph(raw: string, additionalProperties?: OpenGraphProperty[]): Dictionary<OpenGraphResult>;
18
- export declare function parseOpenGraph($: CheerioAPI, additionalProperties?: OpenGraphProperty[]): Dictionary<OpenGraphResult>;
17
+ export declare function parseOpenGraph(raw: string, additionalProperties?: OpenGraphProperty[]): Promise<Dictionary<OpenGraphResult>>;
18
+ export declare function parseOpenGraph($: CheerioAPI, additionalProperties?: OpenGraphProperty[]): Promise<Dictionary<OpenGraphResult>>;
19
19
  export {};
20
- //# sourceMappingURL=open_graph_parser.d.ts.map
@@ -1,4 +1,3 @@
1
- import { load } from 'cheerio';
2
1
  /**
3
2
  * To be used with the spread operator. Ensures that the item is defined, and is not empty.
4
3
  *
@@ -255,32 +254,32 @@ const OPEN_GRAPH_PROPERTIES = [
255
254
  outputName: 'articleInfo',
256
255
  children: [
257
256
  {
258
- name: 'music:published_time',
257
+ name: 'article:published_time',
259
258
  outputName: 'publishedTime',
260
259
  children: [],
261
260
  },
262
261
  {
263
- name: 'music:modified_time',
262
+ name: 'article:modified_time',
264
263
  outputName: 'modifiedTime',
265
264
  children: [],
266
265
  },
267
266
  {
268
- name: 'music:expiration_time',
267
+ name: 'article:expiration_time',
269
268
  outputName: 'expirationTime',
270
269
  children: [],
271
270
  },
272
271
  {
273
- name: 'music:author',
272
+ name: 'article:author',
274
273
  outputName: 'author',
275
274
  children: [],
276
275
  },
277
276
  {
278
- name: 'music:section',
277
+ name: 'article:section',
279
278
  outputName: 'section',
280
279
  children: [],
281
280
  },
282
281
  {
283
- name: 'music:tag',
282
+ name: 'article:tag',
284
283
  outputName: 'tag',
285
284
  children: [],
286
285
  },
@@ -366,7 +365,8 @@ const parseOpenGraphProperty = (property, $) => {
366
365
  }, {}),
367
366
  };
368
367
  };
369
- export function parseOpenGraph(item, additionalProperties) {
368
+ export async function parseOpenGraph(item, additionalProperties) {
369
+ const { load } = await import('cheerio');
370
370
  const $ = typeof item === 'string' ? load(item) : item;
371
371
  return [...(additionalProperties || []), ...OPEN_GRAPH_PROPERTIES].reduce((acc, curr) => {
372
372
  return {
@@ -375,4 +375,3 @@ export function parseOpenGraph(item, additionalProperties) {
375
375
  };
376
376
  }, {});
377
377
  }
378
- //# sourceMappingURL=open_graph_parser.js.map
@@ -1,3 +1,4 @@
1
+ import type { BaseHttpClient, CrawleeLogger } from '@crawlee/types';
1
2
  import { Sitemap } from './sitemap.js';
2
3
  /**
3
4
  * Loads and queries information from a [robots.txt file](https://en.wikipedia.org/wiki/Robots.txt).
@@ -20,13 +21,23 @@ import { Sitemap } from './sitemap.js';
20
21
  export declare class RobotsTxtFile {
21
22
  private robots;
22
23
  private proxyUrl?;
24
+ private logger?;
23
25
  private constructor();
24
26
  /**
25
27
  * Determine the location of a robots.txt file for a URL and fetch it.
26
28
  * @param url the URL to fetch robots.txt for
27
- * @param [proxyUrl] a proxy to be used for fetching the robots.txt file
29
+ * @param [options] additional options
30
+ * @param [options.signal] an AbortSignal to cancel the request
31
+ * @param [options.timeoutMillis] timeout in milliseconds for the request
32
+ * @param [options.proxyUrl] a proxy to be used for fetching the robots.txt file
28
33
  */
29
- static find(url: string, proxyUrl?: string): Promise<RobotsTxtFile>;
34
+ static find(url: string, options?: {
35
+ signal?: AbortSignal;
36
+ timeoutMillis?: number;
37
+ proxyUrl?: string;
38
+ httpClient?: BaseHttpClient;
39
+ logger?: CrawleeLogger;
40
+ }): Promise<RobotsTxtFile>;
30
41
  /**
31
42
  * Allows providing the URL and robots.txt content explicitly instead of loading it from the target site.
32
43
  * @param url the URL for robots.txt file
@@ -34,7 +45,13 @@ export declare class RobotsTxtFile {
34
45
  * @param [proxyUrl] a proxy to be used for fetching the robots.txt file
35
46
  */
36
47
  static from(url: string, content: string, proxyUrl?: string): RobotsTxtFile;
37
- protected static load(url: string, proxyUrl?: string): Promise<RobotsTxtFile>;
48
+ protected static load(url: string, options?: {
49
+ signal?: AbortSignal;
50
+ timeoutMillis?: number;
51
+ proxyUrl?: string;
52
+ httpClient?: BaseHttpClient;
53
+ logger?: CrawleeLogger;
54
+ }): Promise<RobotsTxtFile>;
38
55
  /**
39
56
  * Check if a URL should be crawled by robots.
40
57
  * @param url the URL to check against the rules in robots.txt
@@ -55,4 +72,3 @@ export declare class RobotsTxtFile {
55
72
  parseUrlsFromSitemaps(): Promise<string[]>;
56
73
  }
57
74
  export { RobotsTxtFile as RobotsFile };
58
- //# sourceMappingURL=robots.d.ts.map
@@ -1,7 +1,6 @@
1
- import { gotScraping } from 'got-scraping';
1
+ import { FetchHttpClient } from '@crawlee/http-client';
2
2
  import robotsParser from 'robots-parser';
3
3
  import { Sitemap } from './sitemap.js';
4
- let HTTPError;
5
4
  /**
6
5
  * Loads and queries information from a [robots.txt file](https://en.wikipedia.org/wiki/Robots.txt).
7
6
  *
@@ -23,20 +22,25 @@ let HTTPError;
23
22
  export class RobotsTxtFile {
24
23
  robots;
25
24
  proxyUrl;
26
- constructor(robots, proxyUrl) {
25
+ logger;
26
+ constructor(robots, proxyUrl, logger) {
27
27
  this.robots = robots;
28
28
  this.proxyUrl = proxyUrl;
29
+ this.logger = logger;
29
30
  }
30
31
  /**
31
32
  * Determine the location of a robots.txt file for a URL and fetch it.
32
33
  * @param url the URL to fetch robots.txt for
33
- * @param [proxyUrl] a proxy to be used for fetching the robots.txt file
34
+ * @param [options] additional options
35
+ * @param [options.signal] an AbortSignal to cancel the request
36
+ * @param [options.timeoutMillis] timeout in milliseconds for the request
37
+ * @param [options.proxyUrl] a proxy to be used for fetching the robots.txt file
34
38
  */
35
- static async find(url, proxyUrl) {
39
+ static async find(url, options) {
36
40
  const robotsTxtFileUrl = new URL(url);
37
41
  robotsTxtFileUrl.pathname = '/robots.txt';
38
42
  robotsTxtFileUrl.search = '';
39
- return RobotsTxtFile.load(robotsTxtFileUrl.toString(), proxyUrl);
43
+ return RobotsTxtFile.load(robotsTxtFileUrl.toString(), options);
40
44
  }
41
45
  /**
42
46
  * Allows providing the URL and robots.txt content explicitly instead of loading it from the target site.
@@ -48,33 +52,28 @@ export class RobotsTxtFile {
48
52
  // @ts-ignore
49
53
  return new RobotsTxtFile(robotsParser(url, content), proxyUrl);
50
54
  }
51
- static async load(url, proxyUrl) {
52
- if (!HTTPError) {
53
- HTTPError = (await import('got-scraping')).HTTPError;
54
- }
55
- try {
56
- const response = await gotScraping({
57
- url,
58
- proxyUrl,
59
- method: 'GET',
60
- responseType: 'text',
61
- });
62
- // @ts-ignore
63
- return new RobotsTxtFile(robotsParser(url.toString(), response.body), proxyUrl);
55
+ static async load(url, options) {
56
+ const { proxyUrl, logger, httpClient = new FetchHttpClient() } = options || {};
57
+ const response = await httpClient.sendRequest(new Request(url, { method: 'GET' }), {
58
+ proxyUrl,
59
+ timeoutMillis: options?.timeoutMillis,
60
+ signal: options?.signal,
61
+ });
62
+ if (response.status < 200 || response.status >= 300) {
63
+ throw new Error(`Failed to load robots.txt from ${url}: HTTP ${response.status}`);
64
64
  }
65
- catch (e) {
66
- if (e instanceof HTTPError && e.response.statusCode === 404) {
67
- return new RobotsTxtFile({
68
- isAllowed() {
69
- return true;
70
- },
71
- getSitemaps() {
72
- return [];
73
- },
74
- }, proxyUrl);
75
- }
76
- throw e;
65
+ if (response.status === 404) {
66
+ return new RobotsTxtFile({
67
+ isAllowed() {
68
+ return true;
69
+ },
70
+ getSitemaps() {
71
+ return [];
72
+ },
73
+ }, proxyUrl, logger);
77
74
  }
75
+ // @ts-ignore
76
+ return new RobotsTxtFile(robotsParser(url.toString(), await response.text()), proxyUrl, logger);
78
77
  }
79
78
  /**
80
79
  * Check if a URL should be crawled by robots.
@@ -94,7 +93,7 @@ export class RobotsTxtFile {
94
93
  * Parse all the sitemaps referenced in the robots file.
95
94
  */
96
95
  async parseSitemaps() {
97
- return Sitemap.load(this.robots.getSitemaps(), this.proxyUrl);
96
+ return Sitemap.load(this.robots.getSitemaps(), this.proxyUrl, { logger: this.logger });
98
97
  }
99
98
  /**
100
99
  * Get all URLs from all the sitemaps referenced in the robots file. A shorthand for `(await robots.parseSitemaps()).urls`.
@@ -105,4 +104,3 @@ export class RobotsTxtFile {
105
104
  }
106
105
  // to stay backwards compatible
107
106
  export { RobotsTxtFile as RobotsFile };
108
- //# sourceMappingURL=robots.js.map
@@ -1,5 +1,4 @@
1
- // @ts-ignore optional peer dependency or compatibility with es2022
2
- import type { Delays } from 'got-scraping';
1
+ import type { BaseHttpClient, CrawleeLogger } from '@crawlee/types';
3
2
  interface SitemapUrlData {
4
3
  loc: string;
5
4
  lastmod?: Date;
@@ -36,9 +35,29 @@ export interface ParseSitemapOptions {
36
35
  */
37
36
  sitemapRetries?: number;
38
37
  /**
39
- * Network timeouts for sitemap fetching. See [Got documentation](https://github.com/sindresorhus/got/blob/main/documentation/6-timeout.md) for more details.
38
+ * Timeout settings for network requests when fetching sitemaps. By default this is `30000` milliseconds (30 seconds).
40
39
  */
41
- networkTimeouts?: Delays;
40
+ timeoutMillis?: number;
41
+ /**
42
+ * If true, the parser will log a warning if it fails to fetch a sitemap due to a network error
43
+ * @default true
44
+ */
45
+ reportNetworkErrors?: boolean;
46
+ /**
47
+ * Custom HTTP client to be used for fetching sitemaps.
48
+ */
49
+ httpClient?: BaseHttpClient;
50
+ /**
51
+ * Optional filter for nested sitemap URLs discovered in sitemap index files.
52
+ * Called with the URL of each child sitemap before it is fetched.
53
+ * Return `true` to include the sitemap, `false` to skip it.
54
+ * If not provided, all nested sitemaps are followed.
55
+ */
56
+ nestedSitemapFilter?: (sitemapUrl: string) => boolean;
57
+ /**
58
+ * Optional logger for reporting warnings during sitemap parsing.
59
+ */
60
+ logger?: CrawleeLogger;
42
61
  }
43
62
  export declare function parseSitemap<T extends ParseSitemapOptions>(initialSources: SitemapSource[], proxyUrl?: string, options?: T): AsyncIterable<T['emitNestedSitemaps'] extends true ? SitemapUrl | NestedSitemap : SitemapUrl>;
44
63
  /**
@@ -62,7 +81,7 @@ export declare class Sitemap {
62
81
  * @param url The domain URL to fetch the sitemap for.
63
82
  * @param proxyUrl A proxy to be used for fetching the sitemap file.
64
83
  */
65
- static tryCommonNames(url: string, proxyUrl?: string): Promise<Sitemap>;
84
+ static tryCommonNames(url: string, proxyUrl?: string, parseSitemapOptions?: ParseSitemapOptions): Promise<Sitemap>;
66
85
  /**
67
86
  * Fetch sitemap content from given URL or URLs and return URLs of referenced pages.
68
87
  * @param urls sitemap URL(s)
@@ -74,8 +93,46 @@ export declare class Sitemap {
74
93
  * @param content XML sitemap content
75
94
  * @param proxyUrl URL of a proxy to be used for fetching sitemap contents
76
95
  */
77
- static fromXmlString(content: string, proxyUrl?: string): Promise<Sitemap>;
96
+ static fromXmlString(content: string, proxyUrl?: string, parseSitemapOptions?: ParseSitemapOptions): Promise<Sitemap>;
78
97
  protected static parse(sources: SitemapSource[], proxyUrl?: string, parseSitemapOptions?: ParseSitemapOptions): Promise<Sitemap>;
79
98
  }
99
+ /**
100
+ * Given a list of URLs, discover related sitemap files for these domains by checking the `robots.txt` file,
101
+ * the default `sitemap.xml` & `sitemap.txt` files and the URLs themselves.
102
+ * @param `urls` The list of URLs to discover sitemaps for.
103
+ * @param `options` Options for sitemap discovery
104
+ * @returns An async iterable with the discovered sitemap URLs.
105
+ */
106
+ export declare function discoverValidSitemaps(urls: string[], options?: {
107
+ /**
108
+ * Proxy URL to be used for network requests.
109
+ */
110
+ proxyUrl?: string;
111
+ /**
112
+ * Timeout in milliseconds for the entire `discoverValidSitemaps` call.
113
+ * An `AbortController` is created internally and its signal is passed to every HTTP request,
114
+ * so the whole discovery operation is cancelled once the timeout elapses.
115
+ * Defaults to `60_000` ms (60 seconds) to prevent indefinite hangs.
116
+ */
117
+ timeoutMillis?: number;
118
+ /**
119
+ * An external `AbortSignal` to cancel the entire discovery operation.
120
+ * If both `signal` and `timeout` are provided, the operation is cancelled
121
+ * when either the signal is aborted or the timeout elapses (whichever comes first).
122
+ */
123
+ signal?: AbortSignal;
124
+ /**
125
+ * Timeout in milliseconds for each individual HTTP request during discovery.
126
+ * Defaults to `20000` ms (20 seconds).
127
+ */
128
+ requestTimeoutMillis?: number;
129
+ /**
130
+ * HTTP client to be used for network requests.
131
+ */
132
+ httpClient?: BaseHttpClient;
133
+ /**
134
+ * Optional logger for reporting warnings during sitemap discovery.
135
+ */
136
+ logger?: CrawleeLogger;
137
+ }): AsyncIterable<string>;
80
138
  export {};
81
- //# sourceMappingURL=sitemap.d.ts.map