@websitescreenshotworld/sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +42 -0
- package/LICENSE +21 -0
- package/README.md +399 -2
- package/dist/cjs/auto-schedule.d.ts +20 -0
- package/dist/cjs/auto-schedule.js +34 -0
- package/dist/cjs/client.d.ts +41 -0
- package/dist/cjs/client.js +58 -0
- package/dist/cjs/error-codes.d.ts +54 -0
- package/dist/cjs/error-codes.js +94 -0
- package/dist/cjs/errors.d.ts +56 -0
- package/dist/cjs/errors.js +112 -0
- package/dist/cjs/files.d.ts +6 -0
- package/dist/cjs/files.js +45 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/instant-snap.d.ts +99 -0
- package/dist/cjs/instant-snap.js +205 -0
- package/dist/cjs/models/capture-file.d.ts +35 -0
- package/dist/cjs/models/capture-file.js +34 -0
- package/dist/cjs/models/capture-options.d.ts +144 -0
- package/dist/cjs/models/capture-options.js +2 -0
- package/dist/cjs/models/capture.d.ts +108 -0
- package/dist/cjs/models/capture.js +63 -0
- package/dist/cjs/models/defaults.d.ts +82 -0
- package/dist/cjs/models/defaults.js +46 -0
- package/dist/cjs/models/tokens.d.ts +92 -0
- package/dist/cjs/models/tokens.js +85 -0
- package/dist/cjs/models/trigger-result.d.ts +20 -0
- package/dist/cjs/models/trigger-result.js +13 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/transport.d.ts +55 -0
- package/dist/cjs/transport.js +206 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/webhooks/events.d.ts +128 -0
- package/dist/cjs/webhooks/events.js +13 -0
- package/dist/cjs/webhooks/parse-event.d.ts +10 -0
- package/dist/cjs/webhooks/parse-event.js +149 -0
- package/dist/cjs/webhooks/webhook.d.ts +26 -0
- package/dist/cjs/webhooks/webhook.js +78 -0
- package/dist/cjs/wire.d.ts +15 -0
- package/dist/cjs/wire.js +71 -0
- package/dist/esm/auto-schedule.d.ts +20 -0
- package/dist/esm/auto-schedule.js +30 -0
- package/dist/esm/client.d.ts +41 -0
- package/dist/esm/client.js +54 -0
- package/dist/esm/error-codes.d.ts +54 -0
- package/dist/esm/error-codes.js +91 -0
- package/dist/esm/errors.d.ts +56 -0
- package/dist/esm/errors.js +98 -0
- package/dist/esm/files.d.ts +6 -0
- package/dist/esm/files.js +41 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/instant-snap.d.ts +99 -0
- package/dist/esm/instant-snap.js +201 -0
- package/dist/esm/models/capture-file.d.ts +35 -0
- package/dist/esm/models/capture-file.js +31 -0
- package/dist/esm/models/capture-options.d.ts +144 -0
- package/dist/esm/models/capture-options.js +1 -0
- package/dist/esm/models/capture.d.ts +108 -0
- package/dist/esm/models/capture.js +57 -0
- package/dist/esm/models/defaults.d.ts +82 -0
- package/dist/esm/models/defaults.js +42 -0
- package/dist/esm/models/tokens.d.ts +92 -0
- package/dist/esm/models/tokens.js +82 -0
- package/dist/esm/models/trigger-result.d.ts +20 -0
- package/dist/esm/models/trigger-result.js +10 -0
- package/dist/esm/transport.d.ts +55 -0
- package/dist/esm/transport.js +201 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/webhooks/events.d.ts +128 -0
- package/dist/esm/webhooks/events.js +10 -0
- package/dist/esm/webhooks/parse-event.d.ts +10 -0
- package/dist/esm/webhooks/parse-event.js +146 -0
- package/dist/esm/webhooks/webhook.d.ts +26 -0
- package/dist/esm/webhooks/webhook.js +75 -0
- package/dist/esm/wire.d.ts +15 -0
- package/dist/esm/wire.js +66 -0
- package/package.json +68 -4
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { CaptureFormat, DeviceCategory, MediaCategory, PageSourceFormat, ScrollMode, WatermarkLocation } from "./tokens.js";
|
|
2
|
+
/** The browser window the page is rendered in. */
|
|
3
|
+
export interface ViewportOptions {
|
|
4
|
+
/** Width in CSS pixels, 250 to 7680. Default 1920. */
|
|
5
|
+
width?: number;
|
|
6
|
+
/** Height in CSS pixels, 250 to 7680. Default 1080. */
|
|
7
|
+
height?: number;
|
|
8
|
+
/** Device pixel ratio, 1 to 3. Default 1. */
|
|
9
|
+
deviceScaleFactor?: number;
|
|
10
|
+
}
|
|
11
|
+
/** The position the browser reports. Latitude and longitude are sent together or not at all. */
|
|
12
|
+
export interface GeolocationOptions {
|
|
13
|
+
/** -90 to 90. */
|
|
14
|
+
latitude?: number;
|
|
15
|
+
/** -180 to 180. */
|
|
16
|
+
longitude?: number;
|
|
17
|
+
/** In metres, 1 to 10000. Default 100. */
|
|
18
|
+
accuracy?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Elements to act on before the capture. */
|
|
21
|
+
export interface SelectorOptions {
|
|
22
|
+
/** Capture only the element this XPath selects. At most 512 characters. */
|
|
23
|
+
xpath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Elements to hide: up to 25 comma-separated CSS selectors (an XPath starting with `//` works
|
|
26
|
+
* too), at most 2000 characters. Each is applied on its own; one the browser rejects is skipped.
|
|
27
|
+
*/
|
|
28
|
+
hide?: string;
|
|
29
|
+
/** CSS selector of an element to click. At most 512 characters. */
|
|
30
|
+
click?: string;
|
|
31
|
+
/** CSS selector of an element to hover. At most 512 characters. */
|
|
32
|
+
hover?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Route the capture through a proxy. Requires the ProxyLocation plan feature. */
|
|
35
|
+
export interface ProxyOptions {
|
|
36
|
+
/** A country from the `proxyCountries` of `instantSnap.catalog()`. */
|
|
37
|
+
country: string;
|
|
38
|
+
}
|
|
39
|
+
/** A strip with the capture time and URL. Passing this turns it on. Not available for video. */
|
|
40
|
+
export interface TimestampWatermarkOptions {
|
|
41
|
+
/** Default `true`. */
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
/** Default `"top"`. */
|
|
44
|
+
location?: WatermarkLocation;
|
|
45
|
+
/** Hex colour. Default `"#000000"`. */
|
|
46
|
+
fontColor?: string;
|
|
47
|
+
/** Hex colour. Default `"#FFFFFF"`. */
|
|
48
|
+
backgroundColor?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Also keep the page source. Charged as a second capture, capped at 10 MB, not available with
|
|
52
|
+
* `captureFile`.
|
|
53
|
+
*/
|
|
54
|
+
export interface PageSourceOptions {
|
|
55
|
+
/** Default `"html"`. */
|
|
56
|
+
format?: PageSourceFormat;
|
|
57
|
+
}
|
|
58
|
+
/** The bucket `captureToBucket` uploads to. Needs `region` or `endpointUrl`. */
|
|
59
|
+
export interface S3DeliveryOptions {
|
|
60
|
+
accessKeyId: string;
|
|
61
|
+
/** Sent to the API but never returned. */
|
|
62
|
+
secretAccessKey: string;
|
|
63
|
+
bucket: string;
|
|
64
|
+
region?: string;
|
|
65
|
+
/** An https endpoint for S3-compatible storage. */
|
|
66
|
+
endpointUrl?: string;
|
|
67
|
+
/** Default `false`. */
|
|
68
|
+
forcePathStyle?: boolean;
|
|
69
|
+
keyPrefix?: string;
|
|
70
|
+
/** Wait up to 30 seconds for the upload before answering. Default `false`. */
|
|
71
|
+
waitForSync?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What to capture and how. Only `url` is required; anything left out takes the API's default,
|
|
75
|
+
* which `instantSnap.defaults()` lists.
|
|
76
|
+
*/
|
|
77
|
+
export interface CaptureOptions {
|
|
78
|
+
/** The page to capture: absolute http or https, without credentials, at most 2048 characters. */
|
|
79
|
+
url: string;
|
|
80
|
+
/** Default `"image"`. */
|
|
81
|
+
mediaCategory?: MediaCategory;
|
|
82
|
+
/** Must belong to `mediaCategory`. */
|
|
83
|
+
format?: CaptureFormat;
|
|
84
|
+
viewport?: ViewportOptions;
|
|
85
|
+
/** Default `"desktop"`. */
|
|
86
|
+
deviceCategory?: DeviceCategory;
|
|
87
|
+
/** A device from `instantSnap.catalog()`, case-insensitive. Mobile defaults to "iPhone 13". */
|
|
88
|
+
emulatedDevice?: string;
|
|
89
|
+
/** Default `"viewport"`, or `"scroll"` for video. */
|
|
90
|
+
scrollMode?: ScrollMode;
|
|
91
|
+
/** Default `false`. */
|
|
92
|
+
autoHeight?: boolean;
|
|
93
|
+
/** 250 to 100000, and within the format's own ceiling. */
|
|
94
|
+
maxHeight?: number;
|
|
95
|
+
/** Percent, 50 to 100. Default 100. */
|
|
96
|
+
zoom?: number;
|
|
97
|
+
/** Default `true`. */
|
|
98
|
+
blockAds?: boolean;
|
|
99
|
+
/** Default `true`. */
|
|
100
|
+
blockPopUps?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Press Escape after the pop-up pass and again after scrolling (once in a video), for a modal
|
|
103
|
+
* that closes on Escape. Default `false`.
|
|
104
|
+
*/
|
|
105
|
+
pressEscape?: boolean;
|
|
106
|
+
/** 1000 to 60000. Default 30000. */
|
|
107
|
+
pageTimeoutMs?: number;
|
|
108
|
+
/** The pause after each scroll step of a full-page capture, 0 to 10000. Default 500. */
|
|
109
|
+
scrollingDelayMs?: number;
|
|
110
|
+
userAgent?: string;
|
|
111
|
+
/** A BCP 47 language tag. */
|
|
112
|
+
locale?: string;
|
|
113
|
+
/** An IANA time zone. */
|
|
114
|
+
timeZone?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Sent with every request the page makes, with names exactly as given. Requires the
|
|
117
|
+
* RequestHeadersCookies plan feature.
|
|
118
|
+
*/
|
|
119
|
+
headers?: Record<string, string>;
|
|
120
|
+
/**
|
|
121
|
+
* Set for the URL's origin, with names exactly as given. Requires the RequestHeadersCookies plan
|
|
122
|
+
* feature.
|
|
123
|
+
*/
|
|
124
|
+
cookies?: Record<string, string>;
|
|
125
|
+
geolocation?: GeolocationOptions;
|
|
126
|
+
selectors?: SelectorOptions;
|
|
127
|
+
proxy?: ProxyOptions;
|
|
128
|
+
timestampWatermark?: TimestampWatermarkOptions;
|
|
129
|
+
pageSource?: PageSourceOptions;
|
|
130
|
+
/** Also receives the `capture.succeeded` or `capture.failed` webhook. Requires the Webhooks plan feature. */
|
|
131
|
+
callbackUrl?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Async only (`submit` and `submitToBucket`): the seconds the capture may take in the browser,
|
|
134
|
+
* 30 to 300; time in the queue does not count. Server default 120. The server refuses it on the
|
|
135
|
+
* other capture operations.
|
|
136
|
+
*/
|
|
137
|
+
timeout?: number;
|
|
138
|
+
}
|
|
139
|
+
/** Options for `instantSnap.captureFile()`, which cannot keep the page source. */
|
|
140
|
+
export type CaptureFileOptions = Omit<CaptureOptions, "pageSource">;
|
|
141
|
+
/** Options for `instantSnap.captureToBucket()`. */
|
|
142
|
+
export interface CaptureToBucketOptions extends CaptureOptions {
|
|
143
|
+
s3Delivery: S3DeliveryOptions;
|
|
144
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ErrorCode } from "../error-codes.js";
|
|
2
|
+
import type { CaptureFormat, CaptureStatus, MediaCategory, PageSourceFormat, ResponseType, S3DeliveryStatus } from "./tokens.js";
|
|
3
|
+
/** The page source kept alongside a capture. */
|
|
4
|
+
export interface PageSource {
|
|
5
|
+
format: PageSourceFormat;
|
|
6
|
+
contentType: string | null;
|
|
7
|
+
sizeBytes: number | null;
|
|
8
|
+
/** Lowercase hex SHA-256 of the source. */
|
|
9
|
+
sha256: string | null;
|
|
10
|
+
/** Short-lived; reissued on every read. */
|
|
11
|
+
downloadUrl: string | null;
|
|
12
|
+
}
|
|
13
|
+
/** How the upload to your bucket went. Present for `captureToBucket` only. */
|
|
14
|
+
export interface S3Delivery {
|
|
15
|
+
status: S3DeliveryStatus;
|
|
16
|
+
bucket: string;
|
|
17
|
+
key: string | null;
|
|
18
|
+
/** Masked to its last four characters. */
|
|
19
|
+
accessKeyId: string | null;
|
|
20
|
+
error: string | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A capture, as `capture`, `captureToBucket`, `submit`, `submitToBucket`, `get` and `wait` return
|
|
24
|
+
* it.
|
|
25
|
+
*/
|
|
26
|
+
export interface Capture {
|
|
27
|
+
id: string;
|
|
28
|
+
/**
|
|
29
|
+
* `succeeded`, `failed` and the other end states; an async capture from `submit` or
|
|
30
|
+
* `submitToBucket` reads `queued` until a browser takes it and `running` while it is captured.
|
|
31
|
+
*/
|
|
32
|
+
status: CaptureStatus;
|
|
33
|
+
responseType: ResponseType;
|
|
34
|
+
mediaCategory: MediaCategory;
|
|
35
|
+
/** The format written. */
|
|
36
|
+
format: CaptureFormat | null;
|
|
37
|
+
contentType: string | null;
|
|
38
|
+
sizeBytes: number | null;
|
|
39
|
+
width: number | null;
|
|
40
|
+
height: number | null;
|
|
41
|
+
/** How long the capture took. */
|
|
42
|
+
durationMs: number | null;
|
|
43
|
+
/** The status the website answered with. */
|
|
44
|
+
pageHttpStatus: number | null;
|
|
45
|
+
capturedAt: Date | null;
|
|
46
|
+
/** Where the browser ended up, when the page redirected. */
|
|
47
|
+
finalUrl: string | null;
|
|
48
|
+
/** Lowercase hex SHA-256 of the file. */
|
|
49
|
+
mediaSha256: string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Valid for 60 minutes and reissued on every `get`. `null` for `captureToBucket` and for captures
|
|
52
|
+
* without a file.
|
|
53
|
+
*/
|
|
54
|
+
downloadUrl: string | null;
|
|
55
|
+
/** When the file is deleted, 24 hours after the capture. */
|
|
56
|
+
expiresAt: Date | null;
|
|
57
|
+
pageSource: PageSource | null;
|
|
58
|
+
s3Delivery: S3Delivery | null;
|
|
59
|
+
callbackUrl: string | null;
|
|
60
|
+
/** Why a `failed` or `timed_out` capture ended. */
|
|
61
|
+
errorCode: ErrorCode | null;
|
|
62
|
+
/** The default set the capture was taken under, such as `v1`. */
|
|
63
|
+
specVersion: string;
|
|
64
|
+
}
|
|
65
|
+
/** A capture as the API sends it. */
|
|
66
|
+
export interface WireCapture {
|
|
67
|
+
id: string;
|
|
68
|
+
status: string;
|
|
69
|
+
response_type: string;
|
|
70
|
+
media_category: string;
|
|
71
|
+
format?: string | null;
|
|
72
|
+
content_type?: string | null;
|
|
73
|
+
size_bytes?: number | null;
|
|
74
|
+
width?: number | null;
|
|
75
|
+
height?: number | null;
|
|
76
|
+
duration_ms?: number | null;
|
|
77
|
+
page_http_status?: number | null;
|
|
78
|
+
captured_at?: string | null;
|
|
79
|
+
final_url?: string | null;
|
|
80
|
+
media_sha256?: string | null;
|
|
81
|
+
download_url?: string | null;
|
|
82
|
+
expires_at?: string | null;
|
|
83
|
+
page_source?: WirePageSource | null;
|
|
84
|
+
s3_delivery?: WireS3Delivery | null;
|
|
85
|
+
callback_url?: string | null;
|
|
86
|
+
error_code?: string | null;
|
|
87
|
+
spec_version: string;
|
|
88
|
+
}
|
|
89
|
+
export interface WirePageSource {
|
|
90
|
+
format: string;
|
|
91
|
+
content_type?: string | null;
|
|
92
|
+
size_bytes?: number | null;
|
|
93
|
+
sha256?: string | null;
|
|
94
|
+
download_url?: string | null;
|
|
95
|
+
}
|
|
96
|
+
export interface WireS3Delivery {
|
|
97
|
+
status: string;
|
|
98
|
+
bucket: string;
|
|
99
|
+
key?: string | null;
|
|
100
|
+
access_key_id?: string | null;
|
|
101
|
+
error?: string | null;
|
|
102
|
+
}
|
|
103
|
+
/** The fields every form of a capture shares, webhooks included. */
|
|
104
|
+
export type CaptureFields = Omit<Capture, "downloadUrl" | "pageSource" | "s3Delivery">;
|
|
105
|
+
export declare function parseCaptureFields(wire: WireCapture): CaptureFields;
|
|
106
|
+
export declare function parseCapture(wire: WireCapture): Capture;
|
|
107
|
+
export declare function parsePageSourceFields(wire: WirePageSource): Omit<PageSource, "downloadUrl">;
|
|
108
|
+
export declare function parseS3DeliveryFields(wire: WireS3Delivery): Omit<S3Delivery, "accessKeyId">;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parseDate } from "../wire.js";
|
|
2
|
+
export function parseCaptureFields(wire) {
|
|
3
|
+
return {
|
|
4
|
+
id: wire.id,
|
|
5
|
+
status: wire.status,
|
|
6
|
+
responseType: wire.response_type,
|
|
7
|
+
mediaCategory: wire.media_category,
|
|
8
|
+
format: wire.format ?? null,
|
|
9
|
+
contentType: wire.content_type ?? null,
|
|
10
|
+
sizeBytes: wire.size_bytes ?? null,
|
|
11
|
+
width: wire.width ?? null,
|
|
12
|
+
height: wire.height ?? null,
|
|
13
|
+
durationMs: wire.duration_ms ?? null,
|
|
14
|
+
pageHttpStatus: wire.page_http_status ?? null,
|
|
15
|
+
capturedAt: parseDate(wire.captured_at),
|
|
16
|
+
finalUrl: wire.final_url ?? null,
|
|
17
|
+
mediaSha256: wire.media_sha256 ?? null,
|
|
18
|
+
expiresAt: parseDate(wire.expires_at),
|
|
19
|
+
callbackUrl: wire.callback_url ?? null,
|
|
20
|
+
errorCode: wire.error_code ?? null,
|
|
21
|
+
specVersion: wire.spec_version,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function parseCapture(wire) {
|
|
25
|
+
return {
|
|
26
|
+
...parseCaptureFields(wire),
|
|
27
|
+
downloadUrl: wire.download_url ?? null,
|
|
28
|
+
pageSource: wire.page_source
|
|
29
|
+
? {
|
|
30
|
+
...parsePageSourceFields(wire.page_source),
|
|
31
|
+
downloadUrl: wire.page_source.download_url ?? null,
|
|
32
|
+
}
|
|
33
|
+
: null,
|
|
34
|
+
s3Delivery: wire.s3_delivery
|
|
35
|
+
? {
|
|
36
|
+
...parseS3DeliveryFields(wire.s3_delivery),
|
|
37
|
+
accessKeyId: wire.s3_delivery.access_key_id ?? null,
|
|
38
|
+
}
|
|
39
|
+
: null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function parsePageSourceFields(wire) {
|
|
43
|
+
return {
|
|
44
|
+
format: wire.format,
|
|
45
|
+
contentType: wire.content_type ?? null,
|
|
46
|
+
sizeBytes: wire.size_bytes ?? null,
|
|
47
|
+
sha256: wire.sha256 ?? null,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function parseS3DeliveryFields(wire) {
|
|
51
|
+
return {
|
|
52
|
+
status: wire.status,
|
|
53
|
+
bucket: wire.bucket,
|
|
54
|
+
key: wire.key ?? null,
|
|
55
|
+
error: wire.error ?? null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** The viewport a capture uses when it does not set one. */
|
|
2
|
+
export interface DefaultViewport {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
deviceScaleFactor: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The values a capture takes for fields it does not send, and the limits it is checked against.
|
|
9
|
+
* Every field is optional because the set is versioned by `specVersion` and may change.
|
|
10
|
+
*/
|
|
11
|
+
export interface Defaults {
|
|
12
|
+
specVersion?: string;
|
|
13
|
+
responseType?: string;
|
|
14
|
+
mediaCategory?: string;
|
|
15
|
+
/** The default format of each media category. */
|
|
16
|
+
format?: Record<string, string>;
|
|
17
|
+
/** The formats each media category accepts. */
|
|
18
|
+
formats?: Record<string, string[]>;
|
|
19
|
+
deviceCategory?: string;
|
|
20
|
+
emulatedDevice?: string;
|
|
21
|
+
viewport?: DefaultViewport;
|
|
22
|
+
zoom?: number;
|
|
23
|
+
scrollMode?: string;
|
|
24
|
+
autoHeight?: boolean;
|
|
25
|
+
autoHeightMaxHeight?: number | null;
|
|
26
|
+
autoHeightMaxHeightWebp?: number;
|
|
27
|
+
blockAds?: boolean;
|
|
28
|
+
blockPopUps?: boolean;
|
|
29
|
+
pressEscape?: boolean;
|
|
30
|
+
pageTimeoutMs?: number;
|
|
31
|
+
scrollingDelayMs?: number;
|
|
32
|
+
geolocation?: boolean;
|
|
33
|
+
geolocationAccuracy?: number;
|
|
34
|
+
waitForCloudSync?: boolean;
|
|
35
|
+
timestampWatermark?: Record<string, unknown>;
|
|
36
|
+
pageSource?: Record<string, unknown>;
|
|
37
|
+
limits?: Record<string, unknown>;
|
|
38
|
+
/** Settings the API leaves to the browser rather than fixing a value. */
|
|
39
|
+
leftToTheBrowser?: string[];
|
|
40
|
+
}
|
|
41
|
+
/** What `emulatedDevice` and `proxy.country` accept. */
|
|
42
|
+
export interface Catalog {
|
|
43
|
+
emulatedDevices: string[];
|
|
44
|
+
proxyCountries: string[];
|
|
45
|
+
}
|
|
46
|
+
export interface WireDefaults {
|
|
47
|
+
spec_version?: string;
|
|
48
|
+
response_type?: string;
|
|
49
|
+
media_category?: string;
|
|
50
|
+
format?: Record<string, string>;
|
|
51
|
+
formats?: Record<string, string[]>;
|
|
52
|
+
device_category?: string;
|
|
53
|
+
emulated_device?: string;
|
|
54
|
+
viewport?: {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
device_scale_factor: number;
|
|
58
|
+
};
|
|
59
|
+
zoom?: number;
|
|
60
|
+
scroll_mode?: string;
|
|
61
|
+
auto_height?: boolean;
|
|
62
|
+
auto_height_max_height?: number | null;
|
|
63
|
+
auto_height_max_height_webp?: number;
|
|
64
|
+
block_ads?: boolean;
|
|
65
|
+
block_pop_ups?: boolean;
|
|
66
|
+
press_escape?: boolean;
|
|
67
|
+
page_timeout_ms?: number;
|
|
68
|
+
scrolling_delay_ms?: number;
|
|
69
|
+
geolocation?: boolean;
|
|
70
|
+
geolocation_accuracy?: number;
|
|
71
|
+
wait_for_cloud_sync?: boolean;
|
|
72
|
+
timestamp_watermark?: Record<string, unknown>;
|
|
73
|
+
page_source?: Record<string, unknown>;
|
|
74
|
+
limits?: Record<string, unknown>;
|
|
75
|
+
left_to_the_browser?: string[];
|
|
76
|
+
}
|
|
77
|
+
export interface WireCatalog {
|
|
78
|
+
emulated_devices: string[];
|
|
79
|
+
proxy_countries: string[];
|
|
80
|
+
}
|
|
81
|
+
export declare function parseDefaults(wire: WireDefaults): Defaults;
|
|
82
|
+
export declare function parseCatalog(wire: WireCatalog): Catalog;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { camelCaseKeys } from "../wire.js";
|
|
2
|
+
export function parseDefaults(wire) {
|
|
3
|
+
const defaults = {
|
|
4
|
+
specVersion: wire.spec_version,
|
|
5
|
+
responseType: wire.response_type,
|
|
6
|
+
mediaCategory: wire.media_category,
|
|
7
|
+
format: wire.format,
|
|
8
|
+
formats: wire.formats,
|
|
9
|
+
deviceCategory: wire.device_category,
|
|
10
|
+
emulatedDevice: wire.emulated_device,
|
|
11
|
+
viewport: wire.viewport && {
|
|
12
|
+
width: wire.viewport.width,
|
|
13
|
+
height: wire.viewport.height,
|
|
14
|
+
deviceScaleFactor: wire.viewport.device_scale_factor,
|
|
15
|
+
},
|
|
16
|
+
zoom: wire.zoom,
|
|
17
|
+
scrollMode: wire.scroll_mode,
|
|
18
|
+
autoHeight: wire.auto_height,
|
|
19
|
+
autoHeightMaxHeight: wire.auto_height_max_height,
|
|
20
|
+
autoHeightMaxHeightWebp: wire.auto_height_max_height_webp,
|
|
21
|
+
blockAds: wire.block_ads,
|
|
22
|
+
blockPopUps: wire.block_pop_ups,
|
|
23
|
+
pressEscape: wire.press_escape,
|
|
24
|
+
pageTimeoutMs: wire.page_timeout_ms,
|
|
25
|
+
scrollingDelayMs: wire.scrolling_delay_ms,
|
|
26
|
+
geolocation: wire.geolocation,
|
|
27
|
+
geolocationAccuracy: wire.geolocation_accuracy,
|
|
28
|
+
waitForCloudSync: wire.wait_for_cloud_sync,
|
|
29
|
+
timestampWatermark: camelCaseKeys(wire.timestamp_watermark),
|
|
30
|
+
pageSource: camelCaseKeys(wire.page_source),
|
|
31
|
+
limits: camelCaseKeys(wire.limits),
|
|
32
|
+
leftToTheBrowser: wire.left_to_the_browser,
|
|
33
|
+
};
|
|
34
|
+
// Fields the API did not send stay absent rather than showing up as `undefined`.
|
|
35
|
+
return Object.fromEntries(Object.entries(defaults).filter(([, value]) => value !== undefined));
|
|
36
|
+
}
|
|
37
|
+
export function parseCatalog(wire) {
|
|
38
|
+
return {
|
|
39
|
+
emulatedDevices: wire.emulated_devices,
|
|
40
|
+
proxyCountries: wire.proxy_countries,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Where a capture is in its life. */
|
|
2
|
+
export declare const CaptureStatus: {
|
|
3
|
+
readonly Pending: "pending";
|
|
4
|
+
/** An async capture accepted and waiting for a browser. */
|
|
5
|
+
readonly Queued: "queued";
|
|
6
|
+
/** An async capture a browser is taking now. */
|
|
7
|
+
readonly Running: "running";
|
|
8
|
+
readonly Succeeded: "succeeded";
|
|
9
|
+
/** The end state of `captureFile`: the file went back in the answer and is not kept. */
|
|
10
|
+
readonly Delivered: "delivered";
|
|
11
|
+
readonly Failed: "failed";
|
|
12
|
+
readonly TimedOut: "timed_out";
|
|
13
|
+
readonly Expired: "expired";
|
|
14
|
+
};
|
|
15
|
+
export type CaptureStatus = (typeof CaptureStatus)[keyof typeof CaptureStatus] | (string & {});
|
|
16
|
+
/** How the API answered a capture. */
|
|
17
|
+
export declare const ResponseType: {
|
|
18
|
+
readonly Json: "json";
|
|
19
|
+
readonly ByFormat: "by_format";
|
|
20
|
+
readonly CloudStorage: "cloud_storage";
|
|
21
|
+
};
|
|
22
|
+
export type ResponseType = (typeof ResponseType)[keyof typeof ResponseType] | (string & {});
|
|
23
|
+
export declare const MediaCategory: {
|
|
24
|
+
readonly Image: "image";
|
|
25
|
+
readonly Video: "video";
|
|
26
|
+
readonly Pdf: "pdf";
|
|
27
|
+
};
|
|
28
|
+
export type MediaCategory = (typeof MediaCategory)[keyof typeof MediaCategory] | (string & {});
|
|
29
|
+
/** The file format. It must belong to the capture's media category. */
|
|
30
|
+
export declare const CaptureFormat: {
|
|
31
|
+
readonly Png: "png";
|
|
32
|
+
readonly Jpeg: "jpeg";
|
|
33
|
+
readonly Webp: "webp";
|
|
34
|
+
readonly Tiff: "tiff";
|
|
35
|
+
readonly Mp4: "mp4";
|
|
36
|
+
readonly Webm: "webm";
|
|
37
|
+
readonly Mov: "mov";
|
|
38
|
+
readonly Gif: "gif";
|
|
39
|
+
readonly ImagePdf: "image_pdf";
|
|
40
|
+
readonly DocumentPdf: "document_pdf";
|
|
41
|
+
};
|
|
42
|
+
export type CaptureFormat = (typeof CaptureFormat)[keyof typeof CaptureFormat] | (string & {});
|
|
43
|
+
export declare const DeviceCategory: {
|
|
44
|
+
readonly Desktop: "desktop";
|
|
45
|
+
readonly Mobile: "mobile";
|
|
46
|
+
};
|
|
47
|
+
export type DeviceCategory = (typeof DeviceCategory)[keyof typeof DeviceCategory] | (string & {});
|
|
48
|
+
export declare const ScrollMode: {
|
|
49
|
+
/** Only what fits in the viewport. */
|
|
50
|
+
readonly Viewport: "viewport";
|
|
51
|
+
/** The full page. */
|
|
52
|
+
readonly Scroll: "scroll";
|
|
53
|
+
};
|
|
54
|
+
export type ScrollMode = (typeof ScrollMode)[keyof typeof ScrollMode] | (string & {});
|
|
55
|
+
export declare const WatermarkLocation: {
|
|
56
|
+
readonly Top: "top";
|
|
57
|
+
readonly Bottom: "bottom";
|
|
58
|
+
};
|
|
59
|
+
export type WatermarkLocation = (typeof WatermarkLocation)[keyof typeof WatermarkLocation] | (string & {});
|
|
60
|
+
export declare const PageSourceFormat: {
|
|
61
|
+
readonly Html: "html";
|
|
62
|
+
readonly Json: "json";
|
|
63
|
+
readonly Text: "text";
|
|
64
|
+
};
|
|
65
|
+
export type PageSourceFormat = (typeof PageSourceFormat)[keyof typeof PageSourceFormat] | (string & {});
|
|
66
|
+
/** Where an upload to your bucket stands. */
|
|
67
|
+
export declare const S3DeliveryStatus: {
|
|
68
|
+
readonly NotStarted: "not_started";
|
|
69
|
+
readonly InProgress: "in_progress";
|
|
70
|
+
readonly Completed: "completed";
|
|
71
|
+
readonly Failed: "failed";
|
|
72
|
+
};
|
|
73
|
+
export type S3DeliveryStatus = (typeof S3DeliveryStatus)[keyof typeof S3DeliveryStatus] | (string & {});
|
|
74
|
+
/** What a trigger-now call did. */
|
|
75
|
+
export declare const TriggerStatus: {
|
|
76
|
+
readonly Triggered: "triggered";
|
|
77
|
+
/** A capture was already queued or running; nothing new was started or charged. */
|
|
78
|
+
readonly AlreadyPending: "already_pending";
|
|
79
|
+
};
|
|
80
|
+
export type TriggerStatus = (typeof TriggerStatus)[keyof typeof TriggerStatus] | (string & {});
|
|
81
|
+
/** Who started a scheduled web page's pending capture. */
|
|
82
|
+
export declare const TriggeredBy: {
|
|
83
|
+
readonly Api: "api";
|
|
84
|
+
readonly Ui: "ui";
|
|
85
|
+
};
|
|
86
|
+
export type TriggeredBy = (typeof TriggeredBy)[keyof typeof TriggeredBy] | (string & {});
|
|
87
|
+
/** The product a webhook event comes from. */
|
|
88
|
+
export declare const Product: {
|
|
89
|
+
readonly InstantSnap: "instant_snap";
|
|
90
|
+
readonly AutoSchedule: "auto_schedule";
|
|
91
|
+
};
|
|
92
|
+
export type Product = (typeof Product)[keyof typeof Product] | (string & {});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Each token is a set of named constants plus a type that also accepts any other string, so a value
|
|
2
|
+
// the API adds later still comes through while the known ones keep their autocompletion.
|
|
3
|
+
/** Where a capture is in its life. */
|
|
4
|
+
export const CaptureStatus = {
|
|
5
|
+
Pending: "pending",
|
|
6
|
+
/** An async capture accepted and waiting for a browser. */
|
|
7
|
+
Queued: "queued",
|
|
8
|
+
/** An async capture a browser is taking now. */
|
|
9
|
+
Running: "running",
|
|
10
|
+
Succeeded: "succeeded",
|
|
11
|
+
/** The end state of `captureFile`: the file went back in the answer and is not kept. */
|
|
12
|
+
Delivered: "delivered",
|
|
13
|
+
Failed: "failed",
|
|
14
|
+
TimedOut: "timed_out",
|
|
15
|
+
Expired: "expired",
|
|
16
|
+
};
|
|
17
|
+
/** How the API answered a capture. */
|
|
18
|
+
export const ResponseType = {
|
|
19
|
+
Json: "json",
|
|
20
|
+
ByFormat: "by_format",
|
|
21
|
+
CloudStorage: "cloud_storage",
|
|
22
|
+
};
|
|
23
|
+
export const MediaCategory = {
|
|
24
|
+
Image: "image",
|
|
25
|
+
Video: "video",
|
|
26
|
+
Pdf: "pdf",
|
|
27
|
+
};
|
|
28
|
+
/** The file format. It must belong to the capture's media category. */
|
|
29
|
+
export const CaptureFormat = {
|
|
30
|
+
Png: "png",
|
|
31
|
+
Jpeg: "jpeg",
|
|
32
|
+
Webp: "webp",
|
|
33
|
+
Tiff: "tiff",
|
|
34
|
+
Mp4: "mp4",
|
|
35
|
+
Webm: "webm",
|
|
36
|
+
Mov: "mov",
|
|
37
|
+
Gif: "gif",
|
|
38
|
+
ImagePdf: "image_pdf",
|
|
39
|
+
DocumentPdf: "document_pdf",
|
|
40
|
+
};
|
|
41
|
+
export const DeviceCategory = {
|
|
42
|
+
Desktop: "desktop",
|
|
43
|
+
Mobile: "mobile",
|
|
44
|
+
};
|
|
45
|
+
export const ScrollMode = {
|
|
46
|
+
/** Only what fits in the viewport. */
|
|
47
|
+
Viewport: "viewport",
|
|
48
|
+
/** The full page. */
|
|
49
|
+
Scroll: "scroll",
|
|
50
|
+
};
|
|
51
|
+
export const WatermarkLocation = {
|
|
52
|
+
Top: "top",
|
|
53
|
+
Bottom: "bottom",
|
|
54
|
+
};
|
|
55
|
+
export const PageSourceFormat = {
|
|
56
|
+
Html: "html",
|
|
57
|
+
Json: "json",
|
|
58
|
+
Text: "text",
|
|
59
|
+
};
|
|
60
|
+
/** Where an upload to your bucket stands. */
|
|
61
|
+
export const S3DeliveryStatus = {
|
|
62
|
+
NotStarted: "not_started",
|
|
63
|
+
InProgress: "in_progress",
|
|
64
|
+
Completed: "completed",
|
|
65
|
+
Failed: "failed",
|
|
66
|
+
};
|
|
67
|
+
/** What a trigger-now call did. */
|
|
68
|
+
export const TriggerStatus = {
|
|
69
|
+
Triggered: "triggered",
|
|
70
|
+
/** A capture was already queued or running; nothing new was started or charged. */
|
|
71
|
+
AlreadyPending: "already_pending",
|
|
72
|
+
};
|
|
73
|
+
/** Who started a scheduled web page's pending capture. */
|
|
74
|
+
export const TriggeredBy = {
|
|
75
|
+
Api: "api",
|
|
76
|
+
Ui: "ui",
|
|
77
|
+
};
|
|
78
|
+
/** The product a webhook event comes from. */
|
|
79
|
+
export const Product = {
|
|
80
|
+
InstantSnap: "instant_snap",
|
|
81
|
+
AutoSchedule: "auto_schedule",
|
|
82
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TriggerStatus, TriggeredBy } from "./tokens.js";
|
|
2
|
+
/** What `autoSchedule.triggerNow` did. The capture's outcome arrives later by webhook. */
|
|
3
|
+
export interface TriggerResult {
|
|
4
|
+
/** `triggered`, or `already_pending` when a capture was already queued or running. */
|
|
5
|
+
status: TriggerStatus;
|
|
6
|
+
webPageId: string;
|
|
7
|
+
triggeredBy: TriggeredBy;
|
|
8
|
+
/** When the capture was queued; for `already_pending`, when the earlier trigger was. */
|
|
9
|
+
triggeredAt: Date;
|
|
10
|
+
/** One sentence for a person. */
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
export interface WireTriggerResult {
|
|
14
|
+
status: string;
|
|
15
|
+
web_page_id: string;
|
|
16
|
+
triggered_by: string;
|
|
17
|
+
triggered_at: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseTriggerResult(wire: WireTriggerResult): TriggerResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { parseDate } from "../wire.js";
|
|
2
|
+
export function parseTriggerResult(wire) {
|
|
3
|
+
return {
|
|
4
|
+
status: wire.status,
|
|
5
|
+
webPageId: wire.web_page_id,
|
|
6
|
+
triggeredBy: wire.triggered_by,
|
|
7
|
+
triggeredAt: parseDate(wire.triggered_at),
|
|
8
|
+
message: wire.message,
|
|
9
|
+
};
|
|
10
|
+
}
|