screenshotone-api-sdk 1.1.6 → 1.1.8
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/dist/@types/main.d.ts +24 -1
- package/dist/main.js +33 -4
- package/package.json +1 -1
- package/src/main.ts +42 -8
package/dist/@types/main.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
export declare class Client {
|
|
5
5
|
private readonly accessKey;
|
|
6
6
|
private readonly secretKey;
|
|
7
|
-
|
|
7
|
+
private readonly apiBaseUrl;
|
|
8
|
+
constructor(accessKey: string, secretKey: string, apiBaseUrl?: string);
|
|
8
9
|
/**
|
|
9
10
|
* Generates an URL that can be used to send GET requests for taking screenshots.
|
|
10
11
|
*
|
|
@@ -148,6 +149,28 @@ export declare class TakeOptions {
|
|
|
148
149
|
* Sets response format, one of: "png", "jpeg", "webp" or "jpg".
|
|
149
150
|
*/
|
|
150
151
|
format(format: string): TakeOptions;
|
|
152
|
+
/**
|
|
153
|
+
* When the site responds within the range of 200-299 status code,
|
|
154
|
+
* you can ignore errors and take a screenshot of the error page anyway.
|
|
155
|
+
* To do that, set the option ignore_host_errors to true.
|
|
156
|
+
* It is false by default.
|
|
157
|
+
*
|
|
158
|
+
* It is helpful when you want to create a gallery of error pages or,
|
|
159
|
+
* for some reason, you need to render error pages.
|
|
160
|
+
*/
|
|
161
|
+
ignoreHostErrors(ignore: boolean): TakeOptions;
|
|
162
|
+
/**
|
|
163
|
+
* Use wait_until to wait until an event occurred before taking a screenshot or rendering HTML or PDF.
|
|
164
|
+
*
|
|
165
|
+
* The default value of wait_until is ['load']. Allowed values are:
|
|
166
|
+
* - load: the navigation is successful when the load even is fired;
|
|
167
|
+
* - domcontentloaded: the navigation is finished when the DOMContentLoaded even is fired;
|
|
168
|
+
* - networkidle0: the navigation is finished when there are no more than 0 network connections for at least 500 ms;
|
|
169
|
+
* - networkidle2: consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
|
|
170
|
+
*
|
|
171
|
+
* The parameter accepts many values. It means that screenshots will be taken after all events occur altogether.
|
|
172
|
+
*/
|
|
173
|
+
waitUntil(...until: string[]): TakeOptions;
|
|
151
174
|
/**
|
|
152
175
|
* Sets IP country code.
|
|
153
176
|
*/
|
package/dist/main.js
CHANGED
|
@@ -14,12 +14,13 @@ const API_ANIMATE_PATH = "/animate";
|
|
|
14
14
|
* Represents an API client for the ScreenshotOne.com API.
|
|
15
15
|
*/
|
|
16
16
|
class Client {
|
|
17
|
-
constructor(accessKey, secretKey) {
|
|
17
|
+
constructor(accessKey, secretKey, apiBaseUrl) {
|
|
18
18
|
if (!accessKey || !secretKey) {
|
|
19
19
|
throw new Error("Both non-empty access and secret keys are required");
|
|
20
20
|
}
|
|
21
21
|
this.accessKey = accessKey;
|
|
22
22
|
this.secretKey = secretKey;
|
|
23
|
+
this.apiBaseUrl = apiBaseUrl ? apiBaseUrl : API_BASE_URL;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Generates an URL that can be used to send GET requests for taking screenshots.
|
|
@@ -33,7 +34,7 @@ class Client {
|
|
|
33
34
|
const query = options.toQuery();
|
|
34
35
|
query.append("access_key", this.accessKey);
|
|
35
36
|
let queryString = query.toString();
|
|
36
|
-
return `${
|
|
37
|
+
return `${this.apiBaseUrl}${API_TAKE_PATH}?${queryString}`;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* Generates the link that can be publicly available, but make sure
|
|
@@ -48,7 +49,7 @@ class Client {
|
|
|
48
49
|
let queryString = query.toString();
|
|
49
50
|
const signature = await (0, signature_1.signQueryString)(queryString, this.secretKey);
|
|
50
51
|
queryString += "&signature=" + signature;
|
|
51
|
-
return `${
|
|
52
|
+
return `${this.apiBaseUrl}${API_TAKE_PATH}?${queryString}`;
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
55
|
* Generates the link that can be publicly available, but make sure
|
|
@@ -63,7 +64,7 @@ class Client {
|
|
|
63
64
|
let queryString = query.toString();
|
|
64
65
|
const signature = await (0, signature_1.signQueryString)(queryString, this.secretKey);
|
|
65
66
|
queryString += "&signature=" + signature;
|
|
66
|
-
return `${
|
|
67
|
+
return `${this.apiBaseUrl}${API_ANIMATE_PATH}?${queryString}`;
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Generates a screenshot and return the image blob.
|
|
@@ -301,6 +302,34 @@ class TakeOptions {
|
|
|
301
302
|
this.put("format", format);
|
|
302
303
|
return this;
|
|
303
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* When the site responds within the range of 200-299 status code,
|
|
307
|
+
* you can ignore errors and take a screenshot of the error page anyway.
|
|
308
|
+
* To do that, set the option ignore_host_errors to true.
|
|
309
|
+
* It is false by default.
|
|
310
|
+
*
|
|
311
|
+
* It is helpful when you want to create a gallery of error pages or,
|
|
312
|
+
* for some reason, you need to render error pages.
|
|
313
|
+
*/
|
|
314
|
+
ignoreHostErrors(ignore) {
|
|
315
|
+
this.put("ignore_host_errors", ignore ? "true" : "false");
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Use wait_until to wait until an event occurred before taking a screenshot or rendering HTML or PDF.
|
|
320
|
+
*
|
|
321
|
+
* The default value of wait_until is ['load']. Allowed values are:
|
|
322
|
+
* - load: the navigation is successful when the load even is fired;
|
|
323
|
+
* - domcontentloaded: the navigation is finished when the DOMContentLoaded even is fired;
|
|
324
|
+
* - networkidle0: the navigation is finished when there are no more than 0 network connections for at least 500 ms;
|
|
325
|
+
* - networkidle2: consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
|
|
326
|
+
*
|
|
327
|
+
* The parameter accepts many values. It means that screenshots will be taken after all events occur altogether.
|
|
328
|
+
*/
|
|
329
|
+
waitUntil(...until) {
|
|
330
|
+
this.put("wait_until", ...until);
|
|
331
|
+
return this;
|
|
332
|
+
}
|
|
304
333
|
/**
|
|
305
334
|
* Sets IP country code.
|
|
306
335
|
*/
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -12,8 +12,9 @@ const API_ANIMATE_PATH = "/animate";
|
|
|
12
12
|
export class Client {
|
|
13
13
|
private readonly accessKey: string;
|
|
14
14
|
private readonly secretKey: string;
|
|
15
|
+
private readonly apiBaseUrl: string;
|
|
15
16
|
|
|
16
|
-
constructor(accessKey: string, secretKey: string) {
|
|
17
|
+
constructor(accessKey: string, secretKey: string, apiBaseUrl?: string) {
|
|
17
18
|
if (!accessKey || !secretKey) {
|
|
18
19
|
throw new Error(
|
|
19
20
|
"Both non-empty access and secret keys are required"
|
|
@@ -22,6 +23,7 @@ export class Client {
|
|
|
22
23
|
|
|
23
24
|
this.accessKey = accessKey;
|
|
24
25
|
this.secretKey = secretKey;
|
|
26
|
+
this.apiBaseUrl = apiBaseUrl ? apiBaseUrl : API_BASE_URL;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -37,7 +39,7 @@ export class Client {
|
|
|
37
39
|
query.append("access_key", this.accessKey);
|
|
38
40
|
let queryString = query.toString();
|
|
39
41
|
|
|
40
|
-
return `${
|
|
42
|
+
return `${this.apiBaseUrl}${API_TAKE_PATH}?${queryString}`;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -55,7 +57,7 @@ export class Client {
|
|
|
55
57
|
const signature = await signQueryString(queryString, this.secretKey);
|
|
56
58
|
queryString += "&signature=" + signature;
|
|
57
59
|
|
|
58
|
-
return `${
|
|
60
|
+
return `${this.apiBaseUrl}${API_TAKE_PATH}?${queryString}`;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/**
|
|
@@ -73,7 +75,7 @@ export class Client {
|
|
|
73
75
|
const signature = await signQueryString(queryString, this.secretKey);
|
|
74
76
|
queryString += "&signature=" + signature;
|
|
75
77
|
|
|
76
|
-
return `${
|
|
78
|
+
return `${this.apiBaseUrl}${API_ANIMATE_PATH}?${queryString}`;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/**
|
|
@@ -139,9 +141,9 @@ export class Client {
|
|
|
139
141
|
path: string,
|
|
140
142
|
bucket?: string,
|
|
141
143
|
acl?: "public-read" | "",
|
|
142
|
-
storageClass?: string,
|
|
144
|
+
storageClass?: string,
|
|
143
145
|
accessKeyId?: string,
|
|
144
|
-
secretAccessKey?: string
|
|
146
|
+
secretAccessKey?: string
|
|
145
147
|
): Promise<{ bucket: string | null; key: string | null }> {
|
|
146
148
|
options.store(true).storagePath(path).responseType("empty");
|
|
147
149
|
|
|
@@ -155,10 +157,10 @@ export class Client {
|
|
|
155
157
|
options.storageClass(storageClass);
|
|
156
158
|
}
|
|
157
159
|
if (accessKeyId) {
|
|
158
|
-
options.storageAccessKeyId(accessKeyId)
|
|
160
|
+
options.storageAccessKeyId(accessKeyId);
|
|
159
161
|
}
|
|
160
162
|
if (secretAccessKey) {
|
|
161
|
-
options.storageSecretAccessKey(secretAccessKey)
|
|
163
|
+
options.storageSecretAccessKey(secretAccessKey);
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
const url =
|
|
@@ -378,6 +380,38 @@ export class TakeOptions {
|
|
|
378
380
|
return this;
|
|
379
381
|
}
|
|
380
382
|
|
|
383
|
+
/**
|
|
384
|
+
* When the site responds within the range of 200-299 status code,
|
|
385
|
+
* you can ignore errors and take a screenshot of the error page anyway.
|
|
386
|
+
* To do that, set the option ignore_host_errors to true.
|
|
387
|
+
* It is false by default.
|
|
388
|
+
*
|
|
389
|
+
* It is helpful when you want to create a gallery of error pages or,
|
|
390
|
+
* for some reason, you need to render error pages.
|
|
391
|
+
*/
|
|
392
|
+
ignoreHostErrors(ignore: boolean): TakeOptions {
|
|
393
|
+
this.put("ignore_host_errors", ignore ? "true" : "false");
|
|
394
|
+
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Use wait_until to wait until an event occurred before taking a screenshot or rendering HTML or PDF.
|
|
400
|
+
*
|
|
401
|
+
* The default value of wait_until is ['load']. Allowed values are:
|
|
402
|
+
* - load: the navigation is successful when the load even is fired;
|
|
403
|
+
* - domcontentloaded: the navigation is finished when the DOMContentLoaded even is fired;
|
|
404
|
+
* - networkidle0: the navigation is finished when there are no more than 0 network connections for at least 500 ms;
|
|
405
|
+
* - networkidle2: consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
|
|
406
|
+
*
|
|
407
|
+
* The parameter accepts many values. It means that screenshots will be taken after all events occur altogether.
|
|
408
|
+
*/
|
|
409
|
+
waitUntil(...until: string[]): TakeOptions {
|
|
410
|
+
this.put("wait_until", ...until);
|
|
411
|
+
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
|
|
381
415
|
/**
|
|
382
416
|
* Sets IP country code.
|
|
383
417
|
*/
|