scrapfly-sdk 0.7.3 → 0.10.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 (75) 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 +209 -1
  5. package/esm/client.d.ts.map +1 -1
  6. package/esm/client.js +902 -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 +9 -1
  23. package/esm/main.d.ts.map +1 -1
  24. package/esm/main.js +6 -1
  25. package/esm/monitoringconfig.d.ts +36 -0
  26. package/esm/monitoringconfig.d.ts.map +1 -0
  27. package/esm/monitoringconfig.js +10 -0
  28. package/esm/polyfill.d.ts +2 -0
  29. package/esm/polyfill.d.ts.map +1 -1
  30. package/esm/polyfill.js +12 -0
  31. package/esm/scrapeconfig.d.ts +27 -0
  32. package/esm/scrapeconfig.d.ts.map +1 -1
  33. package/esm/scrapeconfig.js +44 -1
  34. package/esm/screenshotconfig.d.ts +2 -2
  35. package/esm/screenshotconfig.d.ts.map +1 -1
  36. package/esm/utils.d.ts.map +1 -1
  37. package/esm/utils.js +16 -2
  38. package/package.json +1 -1
  39. package/script/browserconfig.d.ts +59 -0
  40. package/script/browserconfig.d.ts.map +1 -0
  41. package/script/browserconfig.js +211 -0
  42. package/script/client.d.ts +209 -1
  43. package/script/client.d.ts.map +1 -1
  44. package/script/client.js +901 -4
  45. package/script/crawl.d.ts +118 -0
  46. package/script/crawl.d.ts.map +1 -0
  47. package/script/crawl.js +257 -0
  48. package/script/crawlerconfig.d.ts +119 -0
  49. package/script/crawlerconfig.d.ts.map +1 -0
  50. package/script/crawlerconfig.js +402 -0
  51. package/script/crawlerresult.d.ts +253 -0
  52. package/script/crawlerresult.d.ts.map +1 -0
  53. package/script/crawlerresult.js +335 -0
  54. package/script/errors.d.ts +4 -0
  55. package/script/errors.d.ts.map +1 -1
  56. package/script/errors.js +9 -1
  57. package/script/extractionconfig.d.ts +2 -0
  58. package/script/extractionconfig.d.ts.map +1 -1
  59. package/script/extractionconfig.js +10 -0
  60. package/script/main.d.ts +9 -1
  61. package/script/main.d.ts.map +1 -1
  62. package/script/main.js +17 -1
  63. package/script/monitoringconfig.d.ts +36 -0
  64. package/script/monitoringconfig.d.ts.map +1 -0
  65. package/script/monitoringconfig.js +13 -0
  66. package/script/polyfill.d.ts +2 -0
  67. package/script/polyfill.d.ts.map +1 -1
  68. package/script/polyfill.js +14 -1
  69. package/script/scrapeconfig.d.ts +27 -0
  70. package/script/scrapeconfig.d.ts.map +1 -1
  71. package/script/scrapeconfig.js +44 -1
  72. package/script/screenshotconfig.d.ts +2 -2
  73. package/script/screenshotconfig.d.ts.map +1 -1
  74. package/script/utils.d.ts.map +1 -1
  75. package/script/utils.js +16 -2
@@ -0,0 +1,327 @@
1
+ import { writeFile } from './polyfill.js';
2
+ /**
3
+ * Pull a required field out of an API response body and fail loud if it's
4
+ * missing or the wrong type. Using this consistently across the response
5
+ * classes means a server-side contract change surfaces as a clear error at
6
+ * parse time instead of a silent fallback to 0/null/empty later.
7
+ */
8
+ function requireField(data, key, typeName, contextClass) {
9
+ if (!(key in data)) {
10
+ throw new Error(`${contextClass}: required field '${key}' is missing from API response`);
11
+ }
12
+ const value = data[key];
13
+ if (value === null || value === undefined) {
14
+ throw new Error(`${contextClass}: required field '${key}' is null/undefined`);
15
+ }
16
+ const actual = Array.isArray(value) ? 'array' : typeof value;
17
+ if (typeName === 'array' ? actual !== 'array' : actual !== typeName) {
18
+ throw new Error(`${contextClass}: field '${key}' must be ${typeName}, got ${actual} (${JSON.stringify(value).slice(0, 100)})`);
19
+ }
20
+ return value;
21
+ }
22
+ /**
23
+ * Like `requireField` but for optional fields that the server may legitimately
24
+ * omit or send as `null`. Returns `null` when absent; validates type otherwise.
25
+ */
26
+ function optionalField(data, key, typeName, contextClass) {
27
+ if (!(key in data))
28
+ return null;
29
+ const value = data[key];
30
+ if (value === null || value === undefined)
31
+ return null;
32
+ const actual = Array.isArray(value) ? 'array' : typeof value;
33
+ if (typeName === 'array' ? actual !== 'array' : actual !== typeName) {
34
+ throw new Error(`${contextClass}: field '${key}' must be ${typeName} or null, got ${actual}`);
35
+ }
36
+ return value;
37
+ }
38
+ /**
39
+ * Wraps the JSON response of `GET /crawl/{uuid}/status`.
40
+ *
41
+ * Strict parsing: every field documented in the public API contract is
42
+ * required. A missing or wrong-typed field throws a clear error at parse
43
+ * time so API contract drift surfaces loud and early instead of silently
44
+ * producing zero-valued metrics.
45
+ */
46
+ export class CrawlerStatus {
47
+ constructor(data) {
48
+ Object.defineProperty(this, "crawler_uuid", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "status", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "is_finished", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ /** `null` while the crawler is still running; bool once terminal. */
67
+ Object.defineProperty(this, "is_success", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
73
+ Object.defineProperty(this, "state", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+ // Canonical API field name is `crawler_uuid`; accept short `uuid` as a
80
+ // legacy fallback but throw if neither is present.
81
+ if ('crawler_uuid' in data && typeof data.crawler_uuid === 'string' && data.crawler_uuid) {
82
+ this.crawler_uuid = data.crawler_uuid;
83
+ }
84
+ else if ('uuid' in data && typeof data.uuid === 'string' && data.uuid) {
85
+ this.crawler_uuid = data.uuid;
86
+ }
87
+ else {
88
+ throw new Error("CrawlerStatus: required field 'crawler_uuid' (or legacy 'uuid') is missing from API response");
89
+ }
90
+ this.status = requireField(data, 'status', 'string', 'CrawlerStatus');
91
+ this.is_finished = requireField(data, 'is_finished', 'boolean', 'CrawlerStatus');
92
+ // `is_success` is documented as nullable while the crawler is running.
93
+ const isSuccessRaw = 'is_success' in data ? data.is_success : null;
94
+ if (isSuccessRaw !== null && typeof isSuccessRaw !== 'boolean') {
95
+ throw new Error(`CrawlerStatus: field 'is_success' must be bool or null, got ${typeof isSuccessRaw}`);
96
+ }
97
+ this.is_success = isSuccessRaw;
98
+ const state = requireField(data, 'state', 'object', 'CrawlerStatus');
99
+ this.state = {
100
+ // URL counters and `duration` are always present and numeric (0 during PENDING).
101
+ urls_visited: requireField(state, 'urls_visited', 'number', 'CrawlerStatus.state'),
102
+ urls_extracted: requireField(state, 'urls_extracted', 'number', 'CrawlerStatus.state'),
103
+ urls_failed: requireField(state, 'urls_failed', 'number', 'CrawlerStatus.state'),
104
+ urls_skipped: requireField(state, 'urls_skipped', 'number', 'CrawlerStatus.state'),
105
+ urls_to_crawl: requireField(state, 'urls_to_crawl', 'number', 'CrawlerStatus.state'),
106
+ api_credit_used: requireField(state, 'api_credit_used', 'number', 'CrawlerStatus.state'),
107
+ duration: requireField(state, 'duration', 'number', 'CrawlerStatus.state'),
108
+ // `start_time` / `stop_time` / `stop_reason` are null until the crawler
109
+ // actually starts / stops — verified against the live server behavior.
110
+ start_time: optionalField(state, 'start_time', 'number', 'CrawlerStatus.state'),
111
+ stop_time: optionalField(state, 'stop_time', 'number', 'CrawlerStatus.state'),
112
+ stop_reason: optionalField(state, 'stop_reason', 'string', 'CrawlerStatus.state'),
113
+ };
114
+ }
115
+ /** True while the crawler is still working (PENDING or RUNNING). */
116
+ get isRunning() {
117
+ return this.status === 'PENDING' || this.status === 'RUNNING';
118
+ }
119
+ /** True if the crawler reached a terminal state successfully. */
120
+ get isComplete() {
121
+ return this.status === 'DONE' && this.is_success === true;
122
+ }
123
+ /** True if the crawler reached a terminal state but failed. */
124
+ get isFailed() {
125
+ return this.status === 'DONE' && this.is_success === false;
126
+ }
127
+ /** True if the crawler was cancelled by the user. */
128
+ get isCancelled() {
129
+ return this.status === 'CANCELLED';
130
+ }
131
+ /**
132
+ * Rough progress estimate based on visited vs. extracted URLs (0–100).
133
+ * Returns 0 when nothing has been extracted yet.
134
+ */
135
+ get progressPct() {
136
+ return this.state.urls_extracted > 0 ? (this.state.urls_visited / this.state.urls_extracted) * 100 : 0;
137
+ }
138
+ }
139
+ /**
140
+ * Wraps the streaming text response of `GET /crawl/{uuid}/urls`.
141
+ *
142
+ * The server returns one record per line with `Content-Type: text/plain`;
143
+ * this class parses that stream into a materialised list for caller
144
+ * convenience. For very large jobs, prefer {@link ScrapflyClient.crawlUrlsStream}
145
+ * (if provided) or call the endpoint via `client.fetch` directly and iterate
146
+ * the body as a stream.
147
+ *
148
+ * Pagination metadata fields (`page`, `per_page`) are echoes of the caller's
149
+ * request parameters — the wire protocol carries no global `total`, only the
150
+ * records in the current page. Use `urls.length` for the page size and
151
+ * request further pages by incrementing `page` until an empty response.
152
+ */
153
+ export class CrawlerUrls {
154
+ constructor(urls, page, perPage) {
155
+ Object.defineProperty(this, "urls", {
156
+ enumerable: true,
157
+ configurable: true,
158
+ writable: true,
159
+ value: void 0
160
+ });
161
+ Object.defineProperty(this, "page", {
162
+ enumerable: true,
163
+ configurable: true,
164
+ writable: true,
165
+ value: void 0
166
+ });
167
+ Object.defineProperty(this, "per_page", {
168
+ enumerable: true,
169
+ configurable: true,
170
+ writable: true,
171
+ value: void 0
172
+ });
173
+ this.urls = urls;
174
+ this.page = page;
175
+ this.per_page = perPage;
176
+ }
177
+ /**
178
+ * Parse the raw text body returned by `GET /crawl/{uuid}/urls`.
179
+ *
180
+ * - Empty lines are ignored (trailing newlines, blank records).
181
+ * - `visited` status → one URL per line, record has `{url, status: 'visited'}`.
182
+ * - `failed`/`skipped` status → `url,reason`, record includes `reason`.
183
+ * - When the caller didn't pass a `status` filter, the server defaults to
184
+ * `visited`; we pass that as the `statusHint` so every parsed record gets
185
+ * the right status tag.
186
+ *
187
+ * @param body Raw text body of the response.
188
+ * @param statusHint The status filter passed on the request (for tagging).
189
+ * @param page Caller-provided page (echoed on the response object).
190
+ * @param perPage Caller-provided per_page (echoed on the response object).
191
+ */
192
+ static fromText(body, statusHint, page, perPage) {
193
+ const urls = [];
194
+ for (const rawLine of body.split(/\r?\n/)) {
195
+ const line = rawLine.trim();
196
+ if (!line)
197
+ continue;
198
+ if (statusHint === 'visited' || statusHint === 'pending') {
199
+ // Plain URL per line.
200
+ urls.push({ url: line, status: statusHint });
201
+ }
202
+ else {
203
+ // `url,reason` — split on the first comma.
204
+ const commaIdx = line.indexOf(',');
205
+ if (commaIdx === -1) {
206
+ urls.push({ url: line, status: statusHint });
207
+ }
208
+ else {
209
+ urls.push({
210
+ url: line.slice(0, commaIdx),
211
+ status: statusHint,
212
+ reason: line.slice(commaIdx + 1),
213
+ });
214
+ }
215
+ }
216
+ }
217
+ return new CrawlerUrls(urls, page, perPage);
218
+ }
219
+ }
220
+ /**
221
+ * Wraps the JSON-mode response of `GET /crawl/{uuid}/contents` (i.e. `plain=false`).
222
+ *
223
+ * The `contents` field maps each URL to a map of format → content. When
224
+ * `plain=true` is used instead, {@link ScrapflyClient.crawlContents} returns
225
+ * a raw `string` directly rather than this class.
226
+ *
227
+ * Strict parsing: `contents` and `links` are both required per the documented
228
+ * contract. A response missing either field indicates an API contract change
229
+ * and throws at parse time rather than producing an empty envelope that looks
230
+ * valid.
231
+ */
232
+ export class CrawlerContents {
233
+ constructor(data) {
234
+ Object.defineProperty(this, "contents", {
235
+ enumerable: true,
236
+ configurable: true,
237
+ writable: true,
238
+ value: void 0
239
+ });
240
+ Object.defineProperty(this, "links", {
241
+ enumerable: true,
242
+ configurable: true,
243
+ writable: true,
244
+ value: void 0
245
+ });
246
+ this.contents = requireField(data, 'contents', 'object', 'CrawlerContents');
247
+ this.links = requireField(data, 'links', 'object', 'CrawlerContents');
248
+ }
249
+ }
250
+ /**
251
+ * Holds the raw bytes of a downloaded WARC or HAR artifact.
252
+ *
253
+ * **Note on parsing:** the SDK does NOT bundle WARC or HAR parsers. Use a dedicated
254
+ * library (e.g. `warcio` on npm for WARC) if you need to walk the records. The
255
+ * `save()` method is provided for the common case of writing the artifact to disk.
256
+ */
257
+ export class CrawlerArtifact {
258
+ constructor(type, data) {
259
+ Object.defineProperty(this, "type", {
260
+ enumerable: true,
261
+ configurable: true,
262
+ writable: true,
263
+ value: void 0
264
+ });
265
+ Object.defineProperty(this, "data", {
266
+ enumerable: true,
267
+ configurable: true,
268
+ writable: true,
269
+ value: void 0
270
+ });
271
+ this.type = type;
272
+ this.data = data;
273
+ }
274
+ /** Write the artifact to a file on disk. */
275
+ async save(filepath) {
276
+ await writeFile(filepath, this.data);
277
+ }
278
+ }
279
+ const LIFECYCLE_EVENTS = new Set([
280
+ 'crawler_started',
281
+ 'crawler_stopped',
282
+ 'crawler_cancelled',
283
+ 'crawler_finished',
284
+ ]);
285
+ /**
286
+ * Parse a raw webhook body (JSON-decoded object) into a typed crawler webhook payload.
287
+ *
288
+ * Throws `Error` if the body is not an object, has no `event` field, or carries an
289
+ * unknown event name. Use this in your webhook handler after `JSON.parse()`.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * import { parseCrawlerWebhook } from '@scrapfly/scrapfly-sdk';
294
+ *
295
+ * app.post('/webhook', async (req, res) => {
296
+ * const body = await req.json();
297
+ * const webhook = parseCrawlerWebhook(body);
298
+ * if (webhook.event === 'crawler_finished') {
299
+ * console.log('done', webhook.payload.state.urls_visited);
300
+ * }
301
+ * });
302
+ * ```
303
+ */
304
+ export function parseCrawlerWebhook(body) {
305
+ if (typeof body !== 'object' || body === null) {
306
+ throw new Error('Crawler webhook body must be a JSON object');
307
+ }
308
+ const obj = body;
309
+ const event = obj.event;
310
+ if (typeof event !== 'string') {
311
+ throw new Error('Crawler webhook body is missing required `event` string field');
312
+ }
313
+ if (typeof obj.payload !== 'object' || obj.payload === null) {
314
+ throw new Error('Crawler webhook body is missing required `payload` object field');
315
+ }
316
+ if (LIFECYCLE_EVENTS.has(event) ||
317
+ event === 'crawler_url_visited' ||
318
+ event === 'crawler_url_skipped' ||
319
+ event === 'crawler_url_discovered' ||
320
+ event === 'crawler_url_failed') {
321
+ // The body has already been validated to have an `event` and `payload`. The
322
+ // narrower per-event field shapes are runtime-checked by the discriminated union
323
+ // — TypeScript users get the typed view; runtime users get a permissive bag.
324
+ return obj;
325
+ }
326
+ throw new Error(`Unknown crawler webhook event: ${event}`);
327
+ }
package/esm/errors.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare class ScreenshotConfigError extends ScrapflyError {
8
8
  }
9
9
  export declare class ExtractionConfigError extends ScrapflyError {
10
10
  }
11
+ export declare class CrawlerConfigError extends ScrapflyError {
12
+ }
11
13
  export declare class EncodeError extends ScrapflyError {
12
14
  }
13
15
  export declare class ContentTypeError extends ScrapflyError {
@@ -50,4 +52,6 @@ export declare class ScreenshotApiError extends ApiHttpClientError {
50
52
  }
51
53
  export declare class ExtractionApiError extends ApiHttpClientError {
52
54
  }
55
+ export declare class ScrapflyCrawlerError extends HttpError {
56
+ }
53
57
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAA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 +19,9 @@ export class ScreenshotConfigError extends ScrapflyError {
19
19
  // raised when extraction config is invalid
20
20
  export class ExtractionConfigError extends ScrapflyError {
21
21
  }
22
+ // raised when crawler config is invalid
23
+ export class CrawlerConfigError extends ScrapflyError {
24
+ }
22
25
  // raised when scrape parameters cannot be encoded
23
26
  export class EncodeError extends ScrapflyError {
24
27
  }
@@ -72,3 +75,6 @@ export class ScreenshotApiError extends ApiHttpClientError {
72
75
  // raised with Scrapfly extraction API related errors
73
76
  export class ExtractionApiError extends ApiHttpClientError {
74
77
  }
78
+ // raised with Scrapfly crawler API related errors (job lifecycle: ALREADY_STARTED, NOT_STARTED, FAILED, CANCELLED, TIMEOUT, etc.)
79
+ export class ScrapflyCrawlerError extends HttpError {
80
+ }
@@ -24,6 +24,7 @@ type ExtractionConfigOptions = {
24
24
  is_document_compressed?: boolean;
25
25
  document_compression_format?: 'gzip' | 'zstd' | 'deflate' | CompressionFormat;
26
26
  webhook?: string;
27
+ timeout?: number;
27
28
  template?: string;
28
29
  ephemeral_template?: object;
29
30
  };
@@ -39,6 +40,7 @@ export declare class ExtractionConfig {
39
40
  is_document_compressed?: boolean;
40
41
  document_compression_format?: 'gzip' | 'zstd' | 'deflate' | CompressionFormat;
41
42
  webhook?: string;
43
+ timeout?: number;
42
44
  template?: string;
43
45
  ephemeral_template?: object;
44
46
  constructor(options: ExtractionConfigOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"extractionconfig.d.ts","sourceRoot":"","sources":["../src/extractionconfig.ts"],"names":[],"mappings":"AAIA,oBAAY,iBAAiB;IAC3B;;;;;;;;SAQK;IACL,IAAI,SAAS;IACb,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,KAAK,uBAAuB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MA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AEhB,OAAO,EAAE,uBAAuB;IAyC5C,OAAO,CAAC,eAAe;IASvB,WAAW,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAoE3D"}
@@ -84,6 +84,12 @@ export class ExtractionConfig {
84
84
  writable: true,
85
85
  value: void 0
86
86
  });
87
+ Object.defineProperty(this, "timeout", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
87
93
  // // deprecated options
88
94
  Object.defineProperty(this, "template", {
89
95
  enumerable: true,
@@ -127,6 +133,7 @@ export class ExtractionConfig {
127
133
  this.is_document_compressed = options.is_document_compressed ?? this.is_document_compressed;
128
134
  this.document_compression_format = options.document_compression_format ?? this.document_compression_format;
129
135
  this.webhook = options.webhook ?? this.webhook;
136
+ this.timeout = options.timeout ?? this.timeout;
130
137
  }
131
138
  validateOptions(options) {
132
139
  const validKeys = new Set(Object.keys(this));
@@ -183,6 +190,9 @@ export class ExtractionConfig {
183
190
  if (this.webhook) {
184
191
  params.webhook_name = this.webhook;
185
192
  }
193
+ if (this.timeout) {
194
+ params.timeout = this.timeout;
195
+ }
186
196
  return params;
187
197
  }
188
198
  }
package/esm/main.d.ts CHANGED
@@ -1,10 +1,18 @@
1
1
  export { ScrapflyClient } from './client.js';
2
2
  export { Format as ScrapeFormat, FormatOption as ScrapeFormatOptions, ScrapeConfig, ScreenshotFlags, } from './scrapeconfig.js';
3
- export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig } from './screenshotconfig.js';
3
+ export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig, VisionDeficiency, } from './screenshotconfig.js';
4
4
  export { ExtractionConfig } from './extractionconfig.js';
5
+ export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
6
+ export type { BrowserConfigOptions } from './browserconfig.js';
5
7
  export * as errors from './errors.js';
6
8
  export { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
7
9
  export type { AccountData, ConfigData, ContextData, ResultData, ScreenshotMetadata } from './result.js';
10
+ export { CrawlerConfig } from './crawlerconfig.js';
11
+ export type { CrawlerConfigOptions, CrawlerContentFormat, CrawlerWebhookEventName } from './crawlerconfig.js';
12
+ export { Crawl } from './crawl.js';
13
+ export { CrawlerArtifact, CrawlerContents, CrawlerStatus, CrawlerUrls, parseCrawlerWebhook, } from './crawlerresult.js';
14
+ export type { CrawlerArtifactType, CrawlerLifecycleWebhook, CrawlerState, CrawlerStatusValue, CrawlerStopReason, CrawlerUrlDiscoveredWebhook, CrawlerUrlEntry, CrawlerUrlFailedWebhook, CrawlerUrlSkippedWebhook, CrawlerUrlVisitedWebhook, CrawlerWebhookCommon, CrawlerWebhookPayload, } from './crawlerresult.js';
15
+ export type { CloudBrowserMonitoringOptions, MonitoringAggregation, MonitoringDataFormat, MonitoringMetricsOptions, MonitoringPeriod, MonitoringTargetMetricsOptions, } from './monitoringconfig.js';
8
16
  export { log } from './logger.js';
9
17
  export { createServer, verifySignature } from './webhookserver.js';
10
18
  //# sourceMappingURL=main.d.ts.map
package/esm/main.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,MAAM,IAAI,YAAY,EACtB,YAAY,IAAI,mBAAmB,EACnC,YAAY,EACZ,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,OAAO,IAAI,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACnH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,M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B,GACpB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,6BAA6B,EAC7B,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
package/esm/main.js CHANGED
@@ -1,8 +1,13 @@
1
1
  export { ScrapflyClient } from './client.js';
2
2
  export { Format as ScrapeFormat, FormatOption as ScrapeFormatOptions, ScrapeConfig, ScreenshotFlags, } from './scrapeconfig.js';
3
- export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig } from './screenshotconfig.js';
3
+ export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig, VisionDeficiency, } from './screenshotconfig.js';
4
4
  export { ExtractionConfig } from './extractionconfig.js';
5
+ export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
5
6
  export * as errors from './errors.js';
6
7
  export { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
8
+ // Crawler API
9
+ export { CrawlerConfig } from './crawlerconfig.js';
10
+ export { Crawl } from './crawl.js';
11
+ export { CrawlerArtifact, CrawlerContents, CrawlerStatus, CrawlerUrls, parseCrawlerWebhook, } from './crawlerresult.js';
7
12
  export { log } from './logger.js';
8
13
  export { createServer, verifySignature } from './webhookserver.js';
@@ -0,0 +1,36 @@
1
+ export type MonitoringDataFormat = 'structured' | 'prometheus';
2
+ export type MonitoringPeriod = 'subscription' | 'last7d' | 'last24h' | 'last1h' | 'last5m';
3
+ export type MonitoringAggregation = 'account' | 'project' | 'target';
4
+ export interface MonitoringMetricsOptions {
5
+ format?: MonitoringDataFormat;
6
+ period?: MonitoringPeriod;
7
+ aggregation?: MonitoringAggregation[];
8
+ /** Fold WEBHOOK origin events (callbacks executed by the webhook
9
+ * worker) into this product's totals. Defaults to false to match
10
+ * the dashboard's default view. */
11
+ includeWebhook?: boolean;
12
+ }
13
+ export interface MonitoringTargetMetricsOptions {
14
+ domain: string;
15
+ groupSubdomain?: boolean;
16
+ period?: MonitoringPeriod;
17
+ start?: Date;
18
+ end?: Date;
19
+ /** Fold WEBHOOK origin events into this product's totals. */
20
+ includeWebhook?: boolean;
21
+ }
22
+ /** Options for the Cloud Browser monitoring endpoints. Cloud Browser
23
+ * is session-based (one allocation = one long-lived browser, billed
24
+ * by runtime + bandwidth) and exposes a distinct shape from the
25
+ * request-based products. There is no `domain`/`target` and no
26
+ * `includeWebhook`. */
27
+ export interface CloudBrowserMonitoringOptions {
28
+ period?: MonitoringPeriod;
29
+ /** Optional filter to a single proxy pool
30
+ * (e.g. `public_datacenter_pool`, `public_residential_pool`, `byop`). */
31
+ proxyPool?: string;
32
+ start?: Date;
33
+ end?: Date;
34
+ }
35
+ export declare function formatMonitoringDate(d: Date): string;
36
+ //# sourceMappingURL=monitoringconfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitoringconfig.d.ts","sourceRoot":"","sources":["../src/monitoringconfig.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,YAAY,CAAC;AAE/D,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE3F,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,WAAW,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACtC;;uCAEmC;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,6DAA6D;IAC7D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;uBAIuB;AACvB,MAAM,WAAW,6BAA6B;IAC5C,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;8EAC0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CASpD"}
@@ -0,0 +1,10 @@
1
+ export function formatMonitoringDate(d) {
2
+ const pad = (n) => n.toString().padStart(2, '0');
3
+ const y = d.getUTCFullYear();
4
+ const mo = pad(d.getUTCMonth() + 1);
5
+ const da = pad(d.getUTCDate());
6
+ const h = pad(d.getUTCHours());
7
+ const mi = pad(d.getUTCMinutes());
8
+ const s = pad(d.getUTCSeconds());
9
+ return `${y}-${mo}-${da} ${h}:${mi}:${s}`;
10
+ }
package/esm/polyfill.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as dntShim from "./_dnt.shims.js";
2
2
  export declare const isDeno: boolean;
3
+ export declare const isBun: boolean;
4
+ export declare function readFileSync(path: string): Uint8Array;
3
5
  export declare function mkdir(path: string | URL, options: dntShim.Deno.MkdirOptions): Promise<void>;
4
6
  export declare function writeFile(path: string | URL, data: Uint8Array, options?: dntShim.Deno.WriteFileOptions): Promise<void>;
5
7
  //# sourceMappingURL=polyfill.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,eAAO,MAAM,MAAM,SAAsC,CAAC;AAE1D,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjG;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,GAAG,GAAG,EAClB,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,gBAAqB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAOf"}
1
+ {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,eAAO,MAAM,MAAM,SAAsC,CAAC;AAE1D,eAAO,MAAM,KAAK,SAA6B,CAAC;AAEhD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CASrD;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjG;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,GAAG,GAAG,EAClB,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,gBAAqB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAOf"}
package/esm/polyfill.js CHANGED
@@ -1,5 +1,17 @@
1
1
  import * as dntShim from "./_dnt.shims.js";
2
2
  export const isDeno = typeof dntShim.Deno !== 'undefined';
3
+ // @ts-ignore: Bun global
4
+ export const isBun = typeof Bun !== 'undefined';
5
+ export function readFileSync(path) {
6
+ if (isDeno) {
7
+ return dntShim.Deno.readFileSync(path);
8
+ }
9
+ // Node.js / Bun — both support require('fs')
10
+ // deno-lint-ignore no-var
11
+ // @ts-ignore: dynamic require for Node/Bun
12
+ var fs = require('fs');
13
+ return new Uint8Array(fs.readFileSync(path));
14
+ }
3
15
  export async function mkdir(path, options) {
4
16
  if (isDeno) {
5
17
  await dntShim.Deno.mkdir(path, options);
@@ -75,6 +75,29 @@ type ScrapeConfigOptions = {
75
75
  os?: string;
76
76
  lang?: string[];
77
77
  auto_scroll?: boolean;
78
+ /**
79
+ * Chromium-based browser brand used for fingerprint generation.
80
+ * One of "chrome" | "edge" | "brave" | "opera". Defaults to "chrome"
81
+ * when omitted. Invalid values are silently dropped by the server.
82
+ */
83
+ browser_brand?: string;
84
+ /**
85
+ * Return the raw upstream response (target's status, headers, body)
86
+ * instead of the JSON envelope. When true, ScrapflyClient.scrape()
87
+ * returns the raw fetch Response so callers can drive it like any
88
+ * HTTP response. Scrapfly metadata is on the X-Scrapfly-* headers.
89
+ */
90
+ proxified_response?: boolean;
91
+ /**
92
+ * Controls when the browser considers the page loaded.
93
+ * "complete" (default) or "domcontentloaded" for faster scrapes.
94
+ */
95
+ rendering_stage?: 'complete' | 'domcontentloaded';
96
+ /**
97
+ * Spoof browser geolocation. Format: "latitude,longitude"
98
+ * e.g. "48.856614,2.3522219" for Paris.
99
+ */
100
+ geolocation?: string;
78
101
  };
79
102
  export declare class ScrapeConfig {
80
103
  static PUBLIC_DATACENTER_POOL: string;
@@ -119,6 +142,10 @@ export declare class ScrapeConfig {
119
142
  lang?: string[];
120
143
  os?: string;
121
144
  auto_scroll?: boolean;
145
+ browser_brand?: string;
146
+ proxified_response?: boolean;
147
+ rendering_stage?: 'complete' | 'domcontentloaded';
148
+ geolocation?: string;
122
149
  constructor(options: ScrapeConfigOptions);
123
150
  private validateOptions;
124
151
  toApiParams(options: {
@@ -1 +1 @@
1
- {"version":3,"file":"scrapecon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