@pagesift/node 0.81.5 → 0.90.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 CHANGED
@@ -45,6 +45,10 @@ await scraper.close()
45
45
  | `scraper.scrape(url, options?)` | `Promise<Page>` | Rejects with `PagesiftError` |
46
46
  | `scraper.scrapeMany(urls, options?)` | `Promise<BatchItem[]>` | Same order as input; one failure only affects its own item |
47
47
  | `scraper.scrapeStream(urls, options?)` | async iterable of `BatchItem` | Completion order; leaving the loop cancels pending work |
48
+ | `scraper.crawl(url, options?)` | `CrawlStream`, async iterable of `CrawlItem` | Whole-site crawl, one item per finished page; leaving the loop or `cancel()` stops the crawl |
49
+ | `scraper.map(url, options?)` | `Promise<MapLink[]>` | The site's links: `{ url, title?, description? }` |
50
+ | `scraper.parse(data, filename, options?)` | `Promise<Page>` | Parse a local file (PDF, HTML, Word, Excel, PowerPoint, EPUB, CSV); rejects with `PagesiftError` |
51
+ | `scraper.parseStream(files, options?)` | async iterable of `BatchItem` | `files` are `{ data, filename, contentType?, url? }`; completion order, same concurrency and cancellation as `scrapeStream`; `url` of each item is the file name |
48
52
  | `scraper.close()` | `Promise<void>` | Stops browser processes |
49
53
 
50
54
  `html` is a `string` or UTF-8 bytes (`Uint8Array` / `Buffer`). Don't modify a buffer while a call that uses it is running.
@@ -57,6 +61,20 @@ await scraper.close()
57
61
  (title, description, language, `statusCode`, `og*` keys, and `metadata.pagesift`: content hashes, redirect chain, ETag, engine used, timings).
58
62
  Each property read copies that one field into JS; fields you never read are never copied. `toJSON()` returns everything as a plain object.
59
63
 
64
+ **Crawl, map, parse.** `crawl` options: `limit` (default: the HTTP API's), `maxDepth`, `includePaths` / `excludePaths` (path regexes),
65
+ `crawlEntireDomain`, `allowSubdomains`, `sitemap` (`include` (default) / `skip` / `only`), `query`, `adaptive` (needs `query`),
66
+ `ignoreRobotsTxt` (the crawl and every page), `maxConcurrency`, and per-page `formats`, `onlyMainContent`, `engine`.
67
+ Invalid options throw `PagesiftError` from `crawl()` itself. Results go through a bounded channel whose capacity is the crawl's concurrency:
68
+ when the consumer is slower, the crawl waits instead of dropping pages. A `CrawlItem` is `{ url, page?, error? }` (failed pages look like failed
69
+ `BatchItem`s, without `index`). An error in the crawl itself (for example an invalid path regex) rejects the iteration with an `Error` whose
70
+ message starts with the code (`INVALID_REQUEST: …`). `stream.summary` is `null` until the crawl ends, then `{ stopReason, pages, coverage?, termEvidence }`;
71
+ crawls with `query` get it from the engine, other crawls report `limit_reached`, `exhausted` or `cancelled` from the page counts.
72
+ `stream.total`, `stream.pages` and `stream.errors` are live counters.
73
+ `map` options: `limit`, `search` (links containing more of its terms come first), `sitemap`, `ignoreRobotsTxt`.
74
+ `parse` takes a `Uint8Array` / `Buffer`; the type is detected from the content, then the file name extension and `contentType`.
75
+ `parse` options are the scrape options plus `contentType` and `url` (resolves relative links in HTML, never fetched); unknown types and URL-only options
76
+ (`engine: 'browser'`, `waitFor`, `mobile`, conditional requests) reject with `UNSUPPORTED_OPTION`.
77
+
60
78
  **`BatchItem`.** `{ index, url, page?, error? }`, with exactly one of `page` or `error`.
61
79
  `error` is `{ code, message, details?, retryAfter? }`, a plain object rather than an `Error`, so a big batch doesn't collect stack traces.
62
80
 
package/index.d.ts CHANGED
@@ -104,6 +104,31 @@ declare global {
104
104
  }
105
105
  }
106
106
 
107
+ /**
108
+ * 进行中的整站爬取,每完成一页产出一个 `CrawlItem`(`for await`)。提前 `break` 或 `cancel()` 停止爬取;
109
+ * 结束后 `summary` 给出停止原因。爬取本身出错(比如路径正则写错)时迭代以 Error 拒绝,
110
+ * 消息以错误码开头(如 `INVALID_REQUEST: …`)。
111
+ *
112
+ * This type implements JavaScript's async iterable protocol.
113
+ * It can be used with `for await...of` loops.
114
+ *
115
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
116
+ */
117
+ export declare class CrawlStream {
118
+ /** 停止爬取:引擎不再调度新页面,之后迭代立即结束,已完成、还没取出的页面也丢弃。 */
119
+ cancel(): void
120
+ /** 已经确定要抓的页面数(随着发现新链接增长,不超过 `limit`)。 */
121
+ get total(): number
122
+ /** 引擎已经交付的成功页数(含还没取出的)。 */
123
+ get pages(): number
124
+ /** 引擎已经交付的失败页数(含还没取出的)。 */
125
+ get errors(): number
126
+ /** 爬取结束后的说明;结束前为 null。 */
127
+ get summary(): CrawlSummary | null
128
+
129
+ [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<CrawlStream, CrawlItem, void, undefined>
130
+ }
131
+
107
132
  /** 一页的转换或抓取结果。每次读属性都会新建一个 JS 值,需要多次使用时先存到变量里。 */
108
133
  export declare class Page {
109
134
  /** 正文的 Markdown;`formats` 里没有 `markdown`、或条件请求命中(`notModified`)时为 null。 */
@@ -131,12 +156,23 @@ export declare class Scraper {
131
156
  scrapeMany(urls: Array<string>, options?: BatchOptions | undefined | null): Promise<BatchItem[]>
132
157
  /** 抓取一批 URL,按完成顺序逐个产出(`for await`)。提前 `break` 会取消还没完成的抓取。 */
133
158
  scrapeStream(urls: Array<string>, options?: BatchOptions | undefined | null): ScrapeStream
159
+ /** 整站爬取,每完成一页产出一项(`for await`);提前 `break` 或 `cancel()` 停止爬取。 */
160
+ crawl(url: string, options?: CrawlOptions | undefined | null): CrawlStream
161
+ /** 站点的链接列表(sitemap 加页面上的链接)。失败时 Promise 以 `PagesiftError` 拒绝。 */
162
+ map(url: string, options?: MapOptions | undefined | null): Promise<MapLink[]>
163
+ /**
164
+ * 解析一个文件(PDF、HTML、Word、Excel、PowerPoint、EPUB、CSV),结果和 `scrape` 一样。
165
+ * 类型按内容识别,认不出时再看文件名的扩展名和 `contentType`。失败时 Promise 以 `PagesiftError` 拒绝。
166
+ */
167
+ parse(data: Uint8Array, filename: string, options?: ParseOptions | undefined | null): Promise<Page>
168
+ /** 解析一批文件,按完成顺序逐个产出(`for await`),`url` 是文件名;并发和取消语义同 `scrapeStream`。 */
169
+ parseStream(files: Array<ParseFile>, options?: BatchOptions | undefined | null): ScrapeStream
134
170
  /** 关闭浏览器进程。之后再调用抓取方法会报错。 */
135
171
  close(): Promise<void>
136
172
  }
137
173
 
138
174
  /**
139
- * 按完成顺序产出 `BatchItem` 的异步迭代器。
175
+ * 按完成顺序产出 `BatchItem` 的异步迭代器(`scrapeStream`、`parseStream`)。
140
176
  *
141
177
  * This type implements JavaScript's async iterable protocol.
142
178
  * It can be used with `for await...of` loops.
@@ -157,10 +193,11 @@ export interface BatchError {
157
193
  retryAfter?: number
158
194
  }
159
195
 
160
- /** 批量抓取里一个 URL 的结果:`page` 和 `error` 恰好有一个。 */
196
+ /** 批量抓取(或批量解析)里一项的结果:`page` 和 `error` 恰好有一个。 */
161
197
  export interface BatchItem {
162
198
  /** 在输入数组里的下标。 */
163
199
  index: number
200
+ /** 抓取时是 URL,解析时是文件名。 */
164
201
  url: string
165
202
  page?: Page
166
203
  error?: BatchError
@@ -192,6 +229,8 @@ export interface BatchOptions {
192
229
  ifNoneMatch?: string
193
230
  /** 条件请求:`If-Modified-Since`(HTTP 日期)。 */
194
231
  ifModifiedSince?: string
232
+ /** 出口代理(http://, https://, socks5://)。 */
233
+ proxy?: string
195
234
  }
196
235
 
197
236
  /** 把一段 HTML 转成 Markdown,在当前线程上同步执行(会阻塞事件循环,适合脚本和小页面)。 */
@@ -217,6 +256,122 @@ export interface ConvertOptions {
217
256
  formats?: Format[]
218
257
  }
219
258
 
259
+ /** 爬取里一页的结果:`page` 和 `error` 恰好有一个(失败项和 `scrapeMany` 的一样)。 */
260
+ export interface CrawlItem {
261
+ url: string
262
+ page?: Page
263
+ error?: BatchError
264
+ }
265
+
266
+ /** `Scraper.crawl` 的选项:爬取范围,加上每页的抓取选项(`formats`、`onlyMainContent`、`engine`)。 */
267
+ export interface CrawlOptions {
268
+ /** 最多抓多少页;不给时和 HTTP 接口的默认值一样。带 `adaptive` 时只是上限。 */
269
+ limit?: number
270
+ /** 从起始页算起最多跟几层链接。 */
271
+ maxDepth?: number
272
+ /** 只抓路径匹配这些正则的页面。 */
273
+ includePaths?: Array<string>
274
+ /** 不抓路径匹配这些正则的页面。 */
275
+ excludePaths?: Array<string>
276
+ /** 不限于起始页所在目录,整个主机都爬。 */
277
+ crawlEntireDomain?: boolean
278
+ /** 也爬同一站点的子域名。 */
279
+ allowSubdomains?: boolean
280
+ /** `include`(默认,sitemap 和页面链接都用)、`skip`(不读 sitemap)、`only`(只抓 sitemap 里的)。 */
281
+ sitemap?: 'include' | 'skip' | 'only'
282
+ /** 按和查询的相关性优先爬取。 */
283
+ query?: string
284
+ /** 内容覆盖查询后自动停止(需要 `query`)。 */
285
+ adaptive?: boolean
286
+ /** 不检查 robots.txt(整个爬取和每一页)。 */
287
+ ignoreRobotsTxt?: boolean
288
+ /** 这次爬取同时在抓的页面数上限。 */
289
+ maxConcurrency?: number
290
+ /** 每页计算哪些输出,默认 `['markdown']`。 */
291
+ formats?: Format[]
292
+ /** 每页只保留正文,默认 true。 */
293
+ onlyMainContent?: boolean
294
+ /** `auto`(默认)、`http` 或 `browser`。 */
295
+ engine?: 'auto' | 'http' | 'browser'
296
+ }
297
+
298
+ /** 爬取结束后的说明。 */
299
+ export interface CrawlSummary {
300
+ /**
301
+ * `limit_reached`、`exhausted`、`cancelled`;带 `query` 时还有 `coverage_reached`、
302
+ * `saturated`、`no_relevant_pages`。
303
+ */
304
+ stopReason: string
305
+ /** 自适应爬取结束时的覆盖度(0–1)。 */
306
+ coverage?: number
307
+ /** 自适应爬取里每个查询词收集到的证据块数。 */
308
+ termEvidence: Record<string, number>
309
+ pages: number
310
+ }
311
+
312
+ /** 站点里的一个链接。 */
313
+ export interface MapLink {
314
+ url: string
315
+ title?: string
316
+ description?: string
317
+ }
318
+
319
+ /** `Scraper.map` 的选项。 */
320
+ export interface MapOptions {
321
+ /** 最多返回多少个链接;不给时和 HTTP 接口的默认值一样。 */
322
+ limit?: number
323
+ /** 地址里命中搜索词多的链接排在前面,没命中的保留在后面。 */
324
+ search?: string
325
+ /** 取值同 `CrawlOptions.sitemap`。 */
326
+ sitemap?: 'include' | 'skip' | 'only'
327
+ /** 不检查 robots.txt。 */
328
+ ignoreRobotsTxt?: boolean
329
+ }
330
+
331
+ /** `parseStream` 的一个输入文件。 */
332
+ export interface ParseFile {
333
+ /** 文件内容(`Buffer` 也可以)。 */
334
+ data: Uint8Array
335
+ /** 文件名:内容认不出类型时按扩展名判断,也作为结果的 `metadata.sourceURL`。 */
336
+ filename: string
337
+ /** 文件的 Content-Type,按内容和扩展名都认不出时再看它。 */
338
+ contentType?: string
339
+ /** 页面原地址:HTML 的相对链接按它解析,也作为 `metadata.sourceURL`;不会去抓。 */
340
+ url?: string
341
+ }
342
+
343
+ /** `parse` 的选项:`ScrapeOptions` 的字段(浏览器渲染、条件请求等只对网址有意义的选项会被拒绝),加上文件的 Content-Type 和原地址。 */
344
+ export interface ParseOptions {
345
+ /** 文件的 Content-Type,按内容和扩展名都认不出类型时再看它。 */
346
+ contentType?: string
347
+ /** 页面原地址:HTML 的相对链接按它解析,也作为 `metadata.sourceURL`;不会去抓。 */
348
+ url?: string
349
+ /** 计算哪些输出,默认 `['markdown']`;只算需要的,越少越快。 */
350
+ formats?: Format[]
351
+ /** 只保留正文,去掉导航、页眉页脚、侧边栏,默认 true。 */
352
+ onlyMainContent?: boolean
353
+ /** `auto`(默认,正文太少时改用浏览器渲染)、`http` 或 `browser`。 */
354
+ engine?: 'auto' | 'http' | 'browser'
355
+ /** 总超时,毫秒,至少 1000。 */
356
+ timeout?: number
357
+ /** 浏览器渲染时页面加载后再等待多久,毫秒。 */
358
+ waitFor?: number
359
+ /** 额外的请求头。 */
360
+ headers?: Record<string, string>
361
+ /** 这一页不检查 robots.txt(只对单页抓取有效)。 */
362
+ ignoreRobotsTxt?: boolean
363
+ /** 浏览器渲染时模拟手机。 */
364
+ mobile?: boolean
365
+ /** 浏览器渲染时屏蔽广告,默认 true。 */
366
+ blockAds?: boolean
367
+ /** 条件请求:`If-None-Match`。 */
368
+ ifNoneMatch?: string
369
+ /** 条件请求:`If-Modified-Since`(HTTP 日期)。 */
370
+ ifModifiedSince?: string
371
+ /** 出口代理(http://, https://, socks5://)。 */
372
+ proxy?: string
373
+ }
374
+
220
375
  /** 单页抓取选项。 */
221
376
  export interface ScrapeOptions {
222
377
  /** 计算哪些输出,默认 `['markdown']`;只算需要的,越少越快。 */
@@ -241,6 +396,8 @@ export interface ScrapeOptions {
241
396
  ifNoneMatch?: string
242
397
  /** 条件请求:`If-Modified-Since`(HTTP 日期)。 */
243
398
  ifModifiedSince?: string
399
+ /** 出口代理(http://, https://, socks5://)。 */
400
+ proxy?: string
244
401
  }
245
402
 
246
403
  /** `Scraper` 的构造参数。 */
@@ -249,6 +406,10 @@ export interface ScraperConfig {
249
406
  userAgent?: string
250
407
  /** 允许抓取内网、回环地址(默认拒绝,防 SSRF;只作用于 HTTP 抓取)。 */
251
408
  allowPrivateNetwork?: boolean
409
+ /** 单独放行的 CIDR 网段(如 10.0.0.0/8, 198.18.0.0/15)。 */
410
+ allowCidrs?: Array<string>
411
+ /** 出口代理(http://, https://, socks5://)。 */
412
+ proxy?: string
252
413
  /** 同一主机两次请求之间的最小间隔,毫秒,默认 1000;robots.txt 的 Crawl-delay 优先。 */
253
414
  requestIntervalMs?: number
254
415
  /** 同一主机同时进行的请求数,默认 2。 */
package/index.js CHANGED
@@ -778,6 +778,7 @@ function __napiStampBindingTarget(exportsObject, target) {
778
778
  // linked import resolves to `undefined`.
779
779
  module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
780
780
  module.exports = nativeBinding
781
+ module.exports.CrawlStream = nativeBinding.CrawlStream
781
782
  module.exports.Page = nativeBinding.Page
782
783
  module.exports.Scraper = nativeBinding.Scraper
783
784
  module.exports.ScrapeStream = nativeBinding.ScrapeStream
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagesift/node",
3
- "version": "0.81.5",
3
+ "version": "0.90.0",
4
4
  "description": "Turn web pages into clean Markdown for LLMs: a polite, Firecrawl-compatible scraping engine written in Rust.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -51,11 +51,11 @@
51
51
  "@napi-rs/cli": "3.10.8"
52
52
  },
53
53
  "optionalDependencies": {
54
- "@pagesift/node-linux-x64-gnu": "0.81.5",
55
- "@pagesift/node-linux-arm64-gnu": "0.81.5",
56
- "@pagesift/node-darwin-x64": "0.81.5",
57
- "@pagesift/node-darwin-arm64": "0.81.5",
58
- "@pagesift/node-linux-x64-musl": "0.81.5",
59
- "@pagesift/node-win32-x64-msvc": "0.81.5"
54
+ "@pagesift/node-linux-x64-gnu": "0.90.0",
55
+ "@pagesift/node-linux-arm64-gnu": "0.90.0",
56
+ "@pagesift/node-darwin-x64": "0.90.0",
57
+ "@pagesift/node-darwin-arm64": "0.90.0",
58
+ "@pagesift/node-linux-x64-musl": "0.90.0",
59
+ "@pagesift/node-win32-x64-msvc": "0.90.0"
60
60
  }
61
61
  }