scrapfly-sdk 0.10.4 → 0.10.6
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/esm/batch.d.ts.map +1 -1
- package/esm/batch.js +6 -0
- package/esm/browserconfig.d.ts +80 -1
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +54 -1
- package/esm/client.d.ts +65 -0
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +157 -5
- package/esm/crawl.d.ts +4 -0
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +4 -0
- package/esm/crawlerresult.d.ts +7 -0
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/errors.d.ts +43 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +43 -16
- package/esm/extractionconfig.d.ts +54 -9
- package/esm/extractionconfig.d.ts.map +1 -1
- package/esm/extractionconfig.js +37 -13
- package/esm/logger.d.ts +1 -0
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +1 -0
- package/esm/main.d.ts +29 -0
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +28 -0
- package/esm/monitoringconfig.d.ts +48 -11
- package/esm/monitoringconfig.d.ts.map +1 -1
- package/esm/monitoringconfig.js +14 -0
- package/esm/result.d.ts +2 -0
- package/esm/result.d.ts.map +1 -1
- package/esm/schedule.d.ts +93 -0
- package/esm/schedule.d.ts.map +1 -0
- package/esm/schedule.js +40 -0
- package/esm/scrapeconfig.d.ts +10 -8
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +10 -8
- package/esm/screenshotconfig.d.ts +59 -26
- package/esm/screenshotconfig.d.ts.map +1 -1
- package/esm/screenshotconfig.js +38 -26
- package/esm/webhookserver.d.ts +28 -0
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +34 -3
- package/package.json +1 -1
- package/script/batch.d.ts.map +1 -1
- package/script/batch.js +6 -0
- package/script/browserconfig.d.ts +80 -1
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +54 -1
- package/script/client.d.ts +65 -0
- package/script/client.d.ts.map +1 -1
- package/script/client.js +157 -5
- package/script/crawl.d.ts +4 -0
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +4 -0
- package/script/crawlerresult.d.ts +7 -0
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/errors.d.ts +43 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +43 -16
- package/script/extractionconfig.d.ts +54 -9
- package/script/extractionconfig.d.ts.map +1 -1
- package/script/extractionconfig.js +37 -13
- package/script/logger.d.ts +1 -0
- package/script/logger.d.ts.map +1 -1
- package/script/logger.js +1 -0
- package/script/main.d.ts +29 -0
- package/script/main.d.ts.map +1 -1
- package/script/main.js +30 -1
- package/script/monitoringconfig.d.ts +48 -11
- package/script/monitoringconfig.d.ts.map +1 -1
- package/script/monitoringconfig.js +14 -0
- package/script/result.d.ts +2 -0
- package/script/result.d.ts.map +1 -1
- package/script/schedule.d.ts +93 -0
- package/script/schedule.d.ts.map +1 -0
- package/script/schedule.js +44 -0
- package/script/scrapeconfig.d.ts +10 -8
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +10 -8
- package/script/screenshotconfig.d.ts +59 -26
- package/script/screenshotconfig.d.ts.map +1 -1
- package/script/screenshotconfig.js +38 -26
- package/script/webhookserver.d.ts +28 -0
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +34 -3
- package/src/batch.ts +7 -1
- package/src/browserconfig.ts +82 -1
- package/src/client.ts +227 -7
- package/src/crawl.ts +4 -0
- package/src/crawlerresult.ts +7 -0
- package/src/errors.ts +43 -16
- package/src/extractionconfig.ts +58 -16
- package/src/logger.ts +2 -0
- package/src/main.ts +37 -0
- package/src/monitoringconfig.ts +49 -11
- package/src/result.ts +2 -0
- package/src/schedule.ts +101 -0
- package/src/scrapeconfig.ts +10 -8
- package/src/screenshotconfig.ts +59 -26
- package/src/webhookserver.ts +34 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public schedule client for the Scrapfly API.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `/scrape/schedules`, `/screenshot/schedules`, `/crawl/schedules`
|
|
5
|
+
* and the cross-kind `/schedules` endpoints. The server returns fully-formed
|
|
6
|
+
* Schedule objects; we surface them as-is so callers always see the live
|
|
7
|
+
* server shape.
|
|
8
|
+
*/
|
|
9
|
+
/** Bounds a recurring schedule by either a date or a fire count. */
|
|
10
|
+
export interface ScheduleEnd {
|
|
11
|
+
type: 'date' | 'count';
|
|
12
|
+
date?: string;
|
|
13
|
+
count?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* When a schedule fires next. Cron mode wins when `cron` is set; otherwise
|
|
17
|
+
* `interval` + `unit` drive the cadence.
|
|
18
|
+
*/
|
|
19
|
+
export interface ScheduleRecurrence {
|
|
20
|
+
cron?: string;
|
|
21
|
+
interval?: number;
|
|
22
|
+
unit?: 'minute' | 'hour' | 'day' | 'week' | 'month';
|
|
23
|
+
days?: string[];
|
|
24
|
+
ends?: ScheduleEnd;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Public-facing request envelope for creating a schedule. The kind-specific
|
|
28
|
+
* config (`scrape_config` / `screenshot_config` / `crawler_config`) is
|
|
29
|
+
* supplied as a separate argument by the matching `create*Schedule` method.
|
|
30
|
+
*/
|
|
31
|
+
export interface CreateScheduleRequest {
|
|
32
|
+
webhook_name: string;
|
|
33
|
+
recurrence?: ScheduleRecurrence;
|
|
34
|
+
scheduled_date?: string;
|
|
35
|
+
allow_concurrency?: boolean;
|
|
36
|
+
retry_on_failure?: boolean;
|
|
37
|
+
max_retries?: number;
|
|
38
|
+
notes?: string;
|
|
39
|
+
}
|
|
40
|
+
/** PATCH payload. Only fields explicitly set are forwarded. */
|
|
41
|
+
export interface UpdateScheduleRequest {
|
|
42
|
+
recurrence?: ScheduleRecurrence;
|
|
43
|
+
scheduled_date?: string;
|
|
44
|
+
allow_concurrency?: boolean;
|
|
45
|
+
retry_on_failure?: boolean;
|
|
46
|
+
max_retries?: number;
|
|
47
|
+
notes?: string;
|
|
48
|
+
scrape_config?: Record<string, unknown>;
|
|
49
|
+
screenshot_config?: Record<string, unknown>;
|
|
50
|
+
crawler_config?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/** Server-side schedule record. Returned by every read or mutation endpoint. */
|
|
53
|
+
export interface Schedule {
|
|
54
|
+
id: string;
|
|
55
|
+
kind: string;
|
|
56
|
+
status: string;
|
|
57
|
+
next_scheduled_date?: string;
|
|
58
|
+
scheduled_date?: string;
|
|
59
|
+
recurrence?: ScheduleRecurrence;
|
|
60
|
+
metadata?: Record<string, unknown>;
|
|
61
|
+
notes?: string | null;
|
|
62
|
+
created_by?: string | null;
|
|
63
|
+
created_at: string;
|
|
64
|
+
updated_at: string;
|
|
65
|
+
cancelled_at?: string | null;
|
|
66
|
+
allow_concurrency: boolean;
|
|
67
|
+
retry_on_failure: boolean;
|
|
68
|
+
max_retries: number;
|
|
69
|
+
webhook_uuid?: string | null;
|
|
70
|
+
user_uuid?: string | null;
|
|
71
|
+
consecutive_failures?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface ListSchedulesOptions {
|
|
74
|
+
status?: string;
|
|
75
|
+
kind?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Raised on any non-2xx response from a `/schedules/*` endpoint. The
|
|
79
|
+
* `code` property carries the public `ERR::SCHEDULER::*` identifier so
|
|
80
|
+
* callers can branch on it without parsing the message string.
|
|
81
|
+
*/
|
|
82
|
+
export declare class ScheduleAPIError extends Error {
|
|
83
|
+
code: string;
|
|
84
|
+
httpStatusCode: number;
|
|
85
|
+
details: unknown;
|
|
86
|
+
constructor(args: {
|
|
87
|
+
code: string;
|
|
88
|
+
message: string;
|
|
89
|
+
httpStatusCode: number;
|
|
90
|
+
details?: unknown;
|
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MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;CAO/F"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Public schedule client for the Scrapfly API.
|
|
4
|
+
*
|
|
5
|
+
* Wraps `/scrape/schedules`, `/screenshot/schedules`, `/crawl/schedules`
|
|
6
|
+
* and the cross-kind `/schedules` endpoints. The server returns fully-formed
|
|
7
|
+
* Schedule objects; we surface them as-is so callers always see the live
|
|
8
|
+
* server shape.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ScheduleAPIError = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Raised on any non-2xx response from a `/schedules/*` endpoint. The
|
|
14
|
+
* `code` property carries the public `ERR::SCHEDULER::*` identifier so
|
|
15
|
+
* callers can branch on it without parsing the message string.
|
|
16
|
+
*/
|
|
17
|
+
class ScheduleAPIError extends Error {
|
|
18
|
+
constructor(args) {
|
|
19
|
+
super(args.message);
|
|
20
|
+
Object.defineProperty(this, "code", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "httpStatusCode", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "details", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
this.name = 'ScheduleAPIError';
|
|
39
|
+
this.code = args.code;
|
|
40
|
+
this.httpStatusCode = args.httpStatusCode;
|
|
41
|
+
this.details = args.details;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ScheduleAPIError = ScheduleAPIError;
|
package/script/scrapeconfig.d.ts
CHANGED
|
@@ -14,24 +14,26 @@ export declare enum ScreenshotFlags {
|
|
|
14
14
|
PRINT_MEDIA_FORMAT = "print_media_format",
|
|
15
15
|
HIGH_QUALITY = "high_quality"
|
|
16
16
|
}
|
|
17
|
+
/** Output format requested for the scraped content. */
|
|
17
18
|
export declare enum Format {
|
|
18
|
-
/**
|
|
19
|
-
Format of the scraped content.
|
|
20
|
-
Attributes:
|
|
21
|
-
JSON: JSON format.
|
|
22
|
-
TEXT: Text format.
|
|
23
|
-
MARKDOWN: Markdown format.
|
|
24
|
-
CLEAN_HTML: Clean HTML format.
|
|
25
|
-
*/
|
|
19
|
+
/** Structured JSON. */
|
|
26
20
|
JSON = "json",
|
|
21
|
+
/** Plain text with markup stripped. */
|
|
27
22
|
TEXT = "text",
|
|
23
|
+
/** Markdown rendering of the page. */
|
|
28
24
|
MARKDOWN = "markdown",
|
|
25
|
+
/** Readability-cleaned HTML. */
|
|
29
26
|
CLEAN_HTML = "clean_html",
|
|
27
|
+
/** Raw HTML as returned by the target. */
|
|
30
28
|
RAW = "raw"
|
|
31
29
|
}
|
|
30
|
+
/** Additional filters applied to the chosen {@link Format}. */
|
|
32
31
|
export declare enum FormatOption {
|
|
32
|
+
/** Strip hyperlinks from the output. */
|
|
33
33
|
NO_LINKS = "no_links",
|
|
34
|
+
/** Strip images from the output. */
|
|
34
35
|
NO_IMAGES = "no_images",
|
|
36
|
+
/** Keep only the "content" section (drop navigation, sidebars, footers). */
|
|
35
37
|
ONLY_CONTENT = "only_content"
|
|
36
38
|
}
|
|
37
39
|
type ScrapeConfigOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeconfig.d.ts","sourceRoot":"","sources":["../src/scrapeconfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGlD,oBAAY,eAAe;IACz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MEDIA_FORMAT"] = "print_media_format";
|
|
21
21
|
ScreenshotFlags["HIGH_QUALITY"] = "high_quality";
|
|
22
22
|
})(ScreenshotFlags || (exports.ScreenshotFlags = ScreenshotFlags = {}));
|
|
23
|
+
/** Output format requested for the scraped content. */
|
|
23
24
|
var Format;
|
|
24
25
|
(function (Format) {
|
|
25
|
-
/**
|
|
26
|
-
Format of the scraped content.
|
|
27
|
-
Attributes:
|
|
28
|
-
JSON: JSON format.
|
|
29
|
-
TEXT: Text format.
|
|
30
|
-
MARKDOWN: Markdown format.
|
|
31
|
-
CLEAN_HTML: Clean HTML format.
|
|
32
|
-
*/
|
|
26
|
+
/** Structured JSON. */
|
|
33
27
|
Format["JSON"] = "json";
|
|
28
|
+
/** Plain text with markup stripped. */
|
|
34
29
|
Format["TEXT"] = "text";
|
|
30
|
+
/** Markdown rendering of the page. */
|
|
35
31
|
Format["MARKDOWN"] = "markdown";
|
|
32
|
+
/** Readability-cleaned HTML. */
|
|
36
33
|
Format["CLEAN_HTML"] = "clean_html";
|
|
34
|
+
/** Raw HTML as returned by the target. */
|
|
37
35
|
Format["RAW"] = "raw";
|
|
38
36
|
})(Format || (exports.Format = Format = {}));
|
|
37
|
+
/** Additional filters applied to the chosen {@link Format}. */
|
|
39
38
|
var FormatOption;
|
|
40
39
|
(function (FormatOption) {
|
|
40
|
+
/** Strip hyperlinks from the output. */
|
|
41
41
|
FormatOption["NO_LINKS"] = "no_links";
|
|
42
|
+
/** Strip images from the output. */
|
|
42
43
|
FormatOption["NO_IMAGES"] = "no_images";
|
|
44
|
+
/** Keep only the "content" section (drop navigation, sidebars, footers). */
|
|
43
45
|
FormatOption["ONLY_CONTENT"] = "only_content";
|
|
44
46
|
})(FormatOption || (exports.FormatOption = FormatOption = {}));
|
|
45
47
|
class ScrapeConfig {
|
|
@@ -1,72 +1,98 @@
|
|
|
1
|
+
/** Toggles that customize how the screenshot is captured. */
|
|
1
2
|
export declare enum Options {
|
|
2
|
-
/**
|
|
3
|
-
Options to customize the screenshot behavior
|
|
4
|
-
Attributes:
|
|
5
|
-
LOAD_IMAGES: Enable image rendering with the request, add extra usage for the bandwidth consumed.
|
|
6
|
-
DARK_MODE: Enable dark mode display.
|
|
7
|
-
BLOCK_BANNERS: Block cookies banners and overlay that cover the screen.
|
|
8
|
-
PRINT_MEDIA_FORMAT: Render the page in the print mode.
|
|
9
|
-
*/
|
|
3
|
+
/** Render images before capturing. Consumes additional bandwidth. */
|
|
10
4
|
LOAD_IMAGES = "load_images",
|
|
5
|
+
/** Render the page in dark mode. */
|
|
11
6
|
DARK_MODE = "dark_mode",
|
|
7
|
+
/** Block cookie banners and overlays that would otherwise occlude the page. */
|
|
12
8
|
BLOCK_BANNERS = "block_banners",
|
|
9
|
+
/** Render the page using the `print` media query. */
|
|
13
10
|
PRINT_MEDIA_FORMAT = "print_media_format"
|
|
14
11
|
}
|
|
12
|
+
/** Output format of the screenshot image. */
|
|
15
13
|
export declare enum Format {
|
|
16
|
-
/**
|
|
17
|
-
Format of the screenshot image.
|
|
18
|
-
Attributes:
|
|
19
|
-
JPG: JPG format.
|
|
20
|
-
PNG: PNG format.
|
|
21
|
-
WEBP: WEBP format.
|
|
22
|
-
GIF: GIF format.
|
|
23
|
-
*/
|
|
14
|
+
/** JPEG encoding. */
|
|
24
15
|
JPG = "jpg",
|
|
16
|
+
/** PNG encoding. */
|
|
25
17
|
PNG = "png",
|
|
18
|
+
/** WebP encoding. */
|
|
26
19
|
WEBP = "webp",
|
|
20
|
+
/** Animated GIF encoding. */
|
|
27
21
|
GIF = "gif"
|
|
28
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Visual impairments to simulate when capturing the screenshot.
|
|
25
|
+
* Useful for WCAG accessibility testing.
|
|
26
|
+
*/
|
|
29
27
|
export declare enum VisionDeficiency {
|
|
30
|
-
/**
|
|
31
|
-
Simulate vision deficiency for accessibility testing (WCAG compliance)
|
|
32
|
-
Attributes:
|
|
33
|
-
DEUTERANOPIA: Difficulty distinguishing green from red; green appears beige/gray
|
|
34
|
-
PROTANOPIA: Reduced sensitivity to red light; red appears dark/black
|
|
35
|
-
TRITANOPIA: Difficulty distinguishing blue from yellow and violet from red
|
|
36
|
-
ACHROMATOPSIA: Complete inability to perceive color; sees only in grayscale
|
|
37
|
-
REDUCED_CONTRAST: Simulates reduced contrast due to aging, low light, or other factors
|
|
38
|
-
BLURRED_VISION: Simulates uncorrected refractive errors or age-related vision loss
|
|
39
|
-
*/
|
|
28
|
+
/** Difficulty distinguishing green from red; green appears beige/gray. */
|
|
40
29
|
DEUTERANOPIA = "deuteranopia",
|
|
30
|
+
/** Reduced sensitivity to red light; red appears dark/black. */
|
|
41
31
|
PROTANOPIA = "protanopia",
|
|
32
|
+
/** Difficulty distinguishing blue from yellow and violet from red. */
|
|
42
33
|
TRITANOPIA = "tritanopia",
|
|
34
|
+
/** Complete color blindness; the image is grayscale. */
|
|
43
35
|
ACHROMATOPSIA = "achromatopsia",
|
|
36
|
+
/** Reduced contrast (aging, low light). */
|
|
44
37
|
REDUCED_CONTRAST = "reducedContrast",
|
|
38
|
+
/** Blurred vision (uncorrected refractive errors). */
|
|
45
39
|
BLURRED_VISION = "blurredVision"
|
|
46
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* User-facing options accepted by {@link ScreenshotConfig}. See the
|
|
43
|
+
* [Screenshot API reference](https://scrapfly.io/docs/screenshot-api)
|
|
44
|
+
* for the authoritative list of valid values.
|
|
45
|
+
*/
|
|
47
46
|
type ScreenshotConfigOptions = {
|
|
47
|
+
/** URL of the page to screenshot. Required. */
|
|
48
48
|
url: string;
|
|
49
|
+
/** Output image format. Defaults to JPG. */
|
|
49
50
|
format?: 'jpg' | 'png' | 'webp' | 'gif' | Format;
|
|
51
|
+
/** Capture area: `fullpage`, `viewport`, or a CSS selector. */
|
|
50
52
|
capture?: string;
|
|
53
|
+
/** Viewport resolution, formatted as "widthxheight". */
|
|
51
54
|
resolution?: string;
|
|
55
|
+
/** ISO country code for geo-targeting the rendering browser. */
|
|
52
56
|
country?: string;
|
|
57
|
+
/** Request timeout in milliseconds. */
|
|
53
58
|
timeout?: number;
|
|
59
|
+
/** Additional delay (ms) after load before capturing. */
|
|
54
60
|
rendering_wait?: number;
|
|
61
|
+
/** CSS selector to wait for before capturing. */
|
|
55
62
|
wait_for_selector?: string;
|
|
63
|
+
/** Behavior toggles. See {@link Options}. */
|
|
56
64
|
options?: ('load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | Options)[];
|
|
65
|
+
/** Scroll to the bottom of the page before capture. */
|
|
57
66
|
auto_scroll?: boolean;
|
|
67
|
+
/** Custom JavaScript to run on the page before capture. */
|
|
58
68
|
js?: string;
|
|
69
|
+
/** Serve from Scrapfly's cache when possible. */
|
|
59
70
|
cache?: boolean;
|
|
71
|
+
/** TTL in seconds for the cached entry. Ignored if cache is disabled. */
|
|
60
72
|
cache_ttl?: number;
|
|
73
|
+
/** Invalidate the existing cache entry before capturing. */
|
|
61
74
|
cache_clear?: boolean;
|
|
75
|
+
/** Vision deficiency to simulate. See {@link VisionDeficiency}. */
|
|
62
76
|
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
77
|
+
/** Webhook name to notify when the screenshot completes. */
|
|
63
78
|
webhook?: string;
|
|
64
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Configuration for a single screenshot request. Instances are passed
|
|
82
|
+
* to {@link ScrapflyClient.screenshot}; this class is responsible for
|
|
83
|
+
* validating options and encoding them into Scrapfly's query string
|
|
84
|
+
* format.
|
|
85
|
+
*/
|
|
65
86
|
export declare class ScreenshotConfig {
|
|
87
|
+
/** URL of the page to screenshot. */
|
|
66
88
|
url: string;
|
|
89
|
+
/** Output image format. */
|
|
67
90
|
format?: 'jpg' | 'png' | 'webp' | 'gif' | Format;
|
|
91
|
+
/** Capture area (`fullpage`, `viewport`, or a CSS selector). */
|
|
68
92
|
capture?: string;
|
|
93
|
+
/** Viewport resolution (`widthxheight`). */
|
|
69
94
|
resolution?: string;
|
|
95
|
+
/** Geo-targeting country (ISO code). */
|
|
70
96
|
country?: string;
|
|
71
97
|
timeout?: number;
|
|
72
98
|
rendering_wait?: number;
|
|
@@ -81,6 +107,13 @@ export declare class ScreenshotConfig {
|
|
|
81
107
|
webhook?: string;
|
|
82
108
|
constructor(options: ScreenshotConfigOptions);
|
|
83
109
|
private validateOptions;
|
|
110
|
+
/**
|
|
111
|
+
* Encode this config as the query-string parameters sent to the
|
|
112
|
+
* Screenshot API.
|
|
113
|
+
*
|
|
114
|
+
* @param options.key Scrapfly API key.
|
|
115
|
+
* @returns A record suitable for `URLSearchParams` construction.
|
|
116
|
+
*/
|
|
84
117
|
toApiParams(options: {
|
|
85
118
|
key: string;
|
|
86
119
|
}): Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotconfig.d.ts","sourceRoot":"","sources":["../src/screenshotconfig.ts"],"names":[],"mappings":"AAIA,oBAAY,OAAO;IACjB
|
|
1
|
+
{"version":3,"file":"screenshotconfig.d.ts","sourceRoot":"","sources":["../src/screenshotconfig.ts"],"names":[],"mappings":"AAIA,6DAA6D;AAC7D,oBAAY,OAAO;IACjB,qEAAqE;IACrE,WAAW,gBAAgB;IAC3B,oCAAoC;IACpC,SAAS,cAAc;IACvB,+EAA+E;IAC/E,aAAa,kBAAkB;IAC/B,qDAAqD;IACrD,kBAAkB,uBAAuB;CAC1C;AAED,6CAA6C;AAC7C,oBAAY,MAAM;IAChB,qBAAqB;IACrB,GAAG,QAAQ;IACX,oBAAoB;IACpB,GAAG,QAAQ;IACX,qBAAqB;IACrB,IAAI,SAAS;IACb,6BAA6B;IAC7B,GAAG,QAAQ;CACZ;AAED;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,0EAA0E;IAC1E,YAAY,iBAAiB;IAC7B,gEAAgE;IAChE,UAAU,eAAe;IACzB,sEAAsE;IACtE,UAAU,eAAe;I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;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,2BAA2B;IAC3B,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IACjD,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAa;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC,aAAa,GAAG,WAAW,GAAG,eAAe,GAAG,oBAAoB,GAAG,OAAO,CAAC,EAAE,CAAC;IAC7F,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iBAAiB,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,eAAe,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;IAC5I,OAAO,CAAC,EAAE,MAAM,CAAC;gBAEL,OAAO,EAAE,uBAAuB;IA+B5C,OAAO,CAAC,eAAe;IASvB;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAyE3D"}
|
|
@@ -4,81 +4,86 @@ exports.ScreenshotConfig = exports.VisionDeficiency = exports.Format = exports.O
|
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const logger_js_1 = require("./logger.js");
|
|
7
|
+
/** Toggles that customize how the screenshot is captured. */
|
|
7
8
|
var Options;
|
|
8
9
|
(function (Options) {
|
|
9
|
-
/**
|
|
10
|
-
Options to customize the screenshot behavior
|
|
11
|
-
Attributes:
|
|
12
|
-
LOAD_IMAGES: Enable image rendering with the request, add extra usage for the bandwidth consumed.
|
|
13
|
-
DARK_MODE: Enable dark mode display.
|
|
14
|
-
BLOCK_BANNERS: Block cookies banners and overlay that cover the screen.
|
|
15
|
-
PRINT_MEDIA_FORMAT: Render the page in the print mode.
|
|
16
|
-
*/
|
|
10
|
+
/** Render images before capturing. Consumes additional bandwidth. */
|
|
17
11
|
Options["LOAD_IMAGES"] = "load_images";
|
|
12
|
+
/** Render the page in dark mode. */
|
|
18
13
|
Options["DARK_MODE"] = "dark_mode";
|
|
14
|
+
/** Block cookie banners and overlays that would otherwise occlude the page. */
|
|
19
15
|
Options["BLOCK_BANNERS"] = "block_banners";
|
|
16
|
+
/** Render the page using the `print` media query. */
|
|
20
17
|
Options["PRINT_MEDIA_FORMAT"] = "print_media_format";
|
|
21
18
|
})(Options || (exports.Options = Options = {}));
|
|
19
|
+
/** Output format of the screenshot image. */
|
|
22
20
|
var Format;
|
|
23
21
|
(function (Format) {
|
|
24
|
-
/**
|
|
25
|
-
Format of the screenshot image.
|
|
26
|
-
Attributes:
|
|
27
|
-
JPG: JPG format.
|
|
28
|
-
PNG: PNG format.
|
|
29
|
-
WEBP: WEBP format.
|
|
30
|
-
GIF: GIF format.
|
|
31
|
-
*/
|
|
22
|
+
/** JPEG encoding. */
|
|
32
23
|
Format["JPG"] = "jpg";
|
|
24
|
+
/** PNG encoding. */
|
|
33
25
|
Format["PNG"] = "png";
|
|
26
|
+
/** WebP encoding. */
|
|
34
27
|
Format["WEBP"] = "webp";
|
|
28
|
+
/** Animated GIF encoding. */
|
|
35
29
|
Format["GIF"] = "gif";
|
|
36
30
|
})(Format || (exports.Format = Format = {}));
|
|
31
|
+
/**
|
|
32
|
+
* Visual impairments to simulate when capturing the screenshot.
|
|
33
|
+
* Useful for WCAG accessibility testing.
|
|
34
|
+
*/
|
|
37
35
|
var VisionDeficiency;
|
|
38
36
|
(function (VisionDeficiency) {
|
|
39
|
-
/**
|
|
40
|
-
Simulate vision deficiency for accessibility testing (WCAG compliance)
|
|
41
|
-
Attributes:
|
|
42
|
-
DEUTERANOPIA: Difficulty distinguishing green from red; green appears beige/gray
|
|
43
|
-
PROTANOPIA: Reduced sensitivity to red light; red appears dark/black
|
|
44
|
-
TRITANOPIA: Difficulty distinguishing blue from yellow and violet from red
|
|
45
|
-
ACHROMATOPSIA: Complete inability to perceive color; sees only in grayscale
|
|
46
|
-
REDUCED_CONTRAST: Simulates reduced contrast due to aging, low light, or other factors
|
|
47
|
-
BLURRED_VISION: Simulates uncorrected refractive errors or age-related vision loss
|
|
48
|
-
*/
|
|
37
|
+
/** Difficulty distinguishing green from red; green appears beige/gray. */
|
|
49
38
|
VisionDeficiency["DEUTERANOPIA"] = "deuteranopia";
|
|
39
|
+
/** Reduced sensitivity to red light; red appears dark/black. */
|
|
50
40
|
VisionDeficiency["PROTANOPIA"] = "protanopia";
|
|
41
|
+
/** Difficulty distinguishing blue from yellow and violet from red. */
|
|
51
42
|
VisionDeficiency["TRITANOPIA"] = "tritanopia";
|
|
43
|
+
/** Complete color blindness; the image is grayscale. */
|
|
52
44
|
VisionDeficiency["ACHROMATOPSIA"] = "achromatopsia";
|
|
45
|
+
/** Reduced contrast (aging, low light). */
|
|
53
46
|
VisionDeficiency["REDUCED_CONTRAST"] = "reducedContrast";
|
|
47
|
+
/** Blurred vision (uncorrected refractive errors). */
|
|
54
48
|
VisionDeficiency["BLURRED_VISION"] = "blurredVision";
|
|
55
49
|
})(VisionDeficiency || (exports.VisionDeficiency = VisionDeficiency = {}));
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for a single screenshot request. Instances are passed
|
|
52
|
+
* to {@link ScrapflyClient.screenshot}; this class is responsible for
|
|
53
|
+
* validating options and encoding them into Scrapfly's query string
|
|
54
|
+
* format.
|
|
55
|
+
*/
|
|
56
56
|
class ScreenshotConfig {
|
|
57
57
|
constructor(options) {
|
|
58
|
+
/** URL of the page to screenshot. */
|
|
58
59
|
Object.defineProperty(this, "url", {
|
|
59
60
|
enumerable: true,
|
|
60
61
|
configurable: true,
|
|
61
62
|
writable: true,
|
|
62
63
|
value: void 0
|
|
63
64
|
});
|
|
65
|
+
/** Output image format. */
|
|
64
66
|
Object.defineProperty(this, "format", {
|
|
65
67
|
enumerable: true,
|
|
66
68
|
configurable: true,
|
|
67
69
|
writable: true,
|
|
68
70
|
value: void 0
|
|
69
71
|
});
|
|
72
|
+
/** Capture area (`fullpage`, `viewport`, or a CSS selector). */
|
|
70
73
|
Object.defineProperty(this, "capture", {
|
|
71
74
|
enumerable: true,
|
|
72
75
|
configurable: true,
|
|
73
76
|
writable: true,
|
|
74
77
|
value: void 0
|
|
75
78
|
});
|
|
79
|
+
/** Viewport resolution (`widthxheight`). */
|
|
76
80
|
Object.defineProperty(this, "resolution", {
|
|
77
81
|
enumerable: true,
|
|
78
82
|
configurable: true,
|
|
79
83
|
writable: true,
|
|
80
84
|
value: void 0
|
|
81
85
|
});
|
|
86
|
+
/** Geo-targeting country (ISO code). */
|
|
82
87
|
Object.defineProperty(this, "country", {
|
|
83
88
|
enumerable: true,
|
|
84
89
|
configurable: true,
|
|
@@ -188,6 +193,13 @@ class ScreenshotConfig {
|
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Encode this config as the query-string parameters sent to the
|
|
198
|
+
* Screenshot API.
|
|
199
|
+
*
|
|
200
|
+
* @param options.key Scrapfly API key.
|
|
201
|
+
* @returns A record suitable for `URLSearchParams` construction.
|
|
202
|
+
*/
|
|
191
203
|
toApiParams(options) {
|
|
192
204
|
const params = {
|
|
193
205
|
key: options.key,
|
|
@@ -3,6 +3,34 @@ export declare enum ResourceType {
|
|
|
3
3
|
SCRAPE = "scrape",
|
|
4
4
|
PING = "ping"
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Verify that a webhook request was sent by Scrapfly by comparing the
|
|
8
|
+
* HMAC-SHA256 signature on the request body against the configured
|
|
9
|
+
* signing secret.
|
|
10
|
+
*
|
|
11
|
+
* @param body Raw request body as received (verify BEFORE any decompression
|
|
12
|
+
* or JSON parsing — the signature is computed on the bytes
|
|
13
|
+
* Scrapfly sent on the wire).
|
|
14
|
+
* @param signature Value of the `X-Scrapfly-Webhook-Signature` header
|
|
15
|
+
* (uppercase hex digest).
|
|
16
|
+
* @param signingSecret Webhook signing secret from the dashboard, passed as-is
|
|
17
|
+
* (UTF-8 string; not hex-encoded).
|
|
18
|
+
* @returns `true` if the signature matches.
|
|
19
|
+
*/
|
|
6
20
|
export declare function verifySignature(body: Buffer, signature: string, signingSecret: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Start a tiny Express server that receives Scrapfly webhook callbacks
|
|
23
|
+
* and dispatches them to the provided `callback`. Intended for quick
|
|
24
|
+
* integration and local development; production setups should wire
|
|
25
|
+
* Scrapfly webhooks directly into their own HTTP stack via
|
|
26
|
+
* {@link verifySignature}.
|
|
27
|
+
*
|
|
28
|
+
* Requires the `express` package to be installed.
|
|
29
|
+
*
|
|
30
|
+
* @param callback Invoked with the parsed webhook body, its resource
|
|
31
|
+
* type (`scrape` or `ping`), and the raw Express request.
|
|
32
|
+
* @param app Optional pre-configured Express app to mount on.
|
|
33
|
+
* @returns The underlying Express app (for further configuration or `.listen()`).
|
|
34
|
+
*/
|
|
7
35
|
export declare function createServer(callback: (data: any, resourceType: string, request: any) => void, app?: any): Promise<any>;
|
|
8
36
|
//# sourceMappingURL=webhookserver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhookserver.d.ts","sourceRoot":"","sources":["../src/webhookserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"webhookserver.d.ts","sourceRoot":"","sources":["../src/webhookserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAS/F;AAGD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,EACjE,GAAG,CAAC,EAAE,GAAG,GACR,OAAO,CAAC,GAAG,CAAC,CA4Cd"}
|
package/script/webhookserver.js
CHANGED
|
@@ -37,13 +37,44 @@ var ResourceType;
|
|
|
37
37
|
ResourceType["SCRAPE"] = "scrape";
|
|
38
38
|
ResourceType["PING"] = "ping";
|
|
39
39
|
})(ResourceType || (exports.ResourceType = ResourceType = {}));
|
|
40
|
+
/**
|
|
41
|
+
* Verify that a webhook request was sent by Scrapfly by comparing the
|
|
42
|
+
* HMAC-SHA256 signature on the request body against the configured
|
|
43
|
+
* signing secret.
|
|
44
|
+
*
|
|
45
|
+
* @param body Raw request body as received (verify BEFORE any decompression
|
|
46
|
+
* or JSON parsing — the signature is computed on the bytes
|
|
47
|
+
* Scrapfly sent on the wire).
|
|
48
|
+
* @param signature Value of the `X-Scrapfly-Webhook-Signature` header
|
|
49
|
+
* (uppercase hex digest).
|
|
50
|
+
* @param signingSecret Webhook signing secret from the dashboard, passed as-is
|
|
51
|
+
* (UTF-8 string; not hex-encoded).
|
|
52
|
+
* @returns `true` if the signature matches.
|
|
53
|
+
*/
|
|
40
54
|
function verifySignature(body, signature, signingSecret) {
|
|
41
|
-
const
|
|
42
|
-
const hmac = node_crypto_1.default.createHmac('sha256', secret);
|
|
55
|
+
const hmac = node_crypto_1.default.createHmac('sha256', node_buffer_1.Buffer.from(signingSecret, 'utf8'));
|
|
43
56
|
hmac.update(body);
|
|
44
57
|
const computed = hmac.digest('hex').toUpperCase();
|
|
45
|
-
|
|
58
|
+
const received = signature.toUpperCase();
|
|
59
|
+
if (computed.length !== received.length) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return node_crypto_1.default.timingSafeEqual(node_buffer_1.Buffer.from(computed), node_buffer_1.Buffer.from(received));
|
|
46
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Start a tiny Express server that receives Scrapfly webhook callbacks
|
|
66
|
+
* and dispatches them to the provided `callback`. Intended for quick
|
|
67
|
+
* integration and local development; production setups should wire
|
|
68
|
+
* Scrapfly webhooks directly into their own HTTP stack via
|
|
69
|
+
* {@link verifySignature}.
|
|
70
|
+
*
|
|
71
|
+
* Requires the `express` package to be installed.
|
|
72
|
+
*
|
|
73
|
+
* @param callback Invoked with the parsed webhook body, its resource
|
|
74
|
+
* type (`scrape` or `ping`), and the raw Express request.
|
|
75
|
+
* @param app Optional pre-configured Express app to mount on.
|
|
76
|
+
* @returns The underlying Express app (for further configuration or `.listen()`).
|
|
77
|
+
*/
|
|
47
78
|
async function createServer(callback, app) {
|
|
48
79
|
let express;
|
|
49
80
|
try {
|
package/src/batch.ts
CHANGED
|
@@ -26,7 +26,13 @@ function indexOf(buf: Uint8Array, needle: Uint8Array, start = 0): number {
|
|
|
26
26
|
return -1;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
// concat sidesteps the TS 5.7+ generic-Uint8Array vs dnt-Node legacy
|
|
30
|
+
// Uint8Array mismatch by accepting `any` and returning a freshly
|
|
31
|
+
// allocated buffer. The fresh allocation guarantees the result is a
|
|
32
|
+
// `Uint8Array<ArrayBuffer>` at runtime under TS 5.7+ and a plain
|
|
33
|
+
// non-generic `Uint8Array` under dnt's Node target.
|
|
34
|
+
// deno-lint-ignore no-explicit-any
|
|
35
|
+
function concat(a: any, b: any): any {
|
|
30
36
|
const out = new Uint8Array(a.length + b.length);
|
|
31
37
|
out.set(a, 0);
|
|
32
38
|
out.set(b, a.length);
|