screenshotone-api-sdk 1.1.25 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -49,6 +49,7 @@ try {
49
49
  // Error Code: error.errorCode
50
50
  // Error Message: error.errorMessage
51
51
  // Documentation URL: error.documentationUrl
52
+ // Site's HTTP status code for "host_returned_error": error.returnedStatusCode
52
53
  } else if (error instanceof screenshotone.ConnectionError) {
53
54
  // The connection to the API failed, for example with ECONNRESET.
54
55
  // error.message explains what happened and what usually causes it.
@@ -3,7 +3,12 @@ export default class APIError extends Error {
3
3
  readonly errorCode?: string;
4
4
  readonly errorMessage?: string;
5
5
  readonly documentationUrl?: string;
6
- constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string);
6
+ /**
7
+ * The HTTP status code the target site returned, for example 404 or 503.
8
+ * Set for the "host_returned_error" error code.
9
+ */
10
+ readonly returnedStatusCode?: number;
11
+ constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string, returnedStatusCode?: number);
7
12
  }
8
13
  /**
9
14
  * Where the connection failed: before the API responded ("request") or while
@@ -269,10 +269,6 @@ export declare class TakeOptions {
269
269
  * Sets IP country code.
270
270
  */
271
271
  ipCountryCode(countryCode: string): TakeOptions;
272
- /**
273
- * Sets the ScreenshotOne server region used for the request.
274
- */
275
- serversRegion(region: string): TakeOptions;
276
272
  /**
277
273
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
278
274
  */
@@ -358,10 +354,6 @@ export declare class TakeOptions {
358
354
  * Blocks chats.
359
355
  */
360
356
  blockChats(block: boolean): TakeOptions;
361
- /**
362
- * Blocks social widgets.
363
- */
364
- blockSocials(block: boolean): TakeOptions;
365
357
  /**
366
358
  * Blocks trackers.
367
359
  */
package/dist/errors.js CHANGED
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionError = void 0;
4
4
  class APIError extends Error {
5
- constructor(message, httpStatusCode, errorCode, errorMessage, documentationUrl) {
5
+ constructor(message, httpStatusCode, errorCode, errorMessage, documentationUrl, returnedStatusCode) {
6
6
  super(message);
7
7
  this.httpStatusCode = httpStatusCode;
8
8
  this.errorCode = errorCode;
9
9
  this.errorMessage = errorMessage;
10
10
  this.documentationUrl = documentationUrl;
11
+ this.returnedStatusCode = returnedStatusCode;
11
12
  }
12
13
  }
13
14
  exports.default = APIError;
package/dist/main.js CHANGED
@@ -81,6 +81,10 @@ function networkFailureCode(error) {
81
81
  }
82
82
  // the request URL without its query and fragment, which hold the access key
83
83
  // and the signature, whatever the URL's form
84
+ function returnedStatusCode(data) {
85
+ const code = Number(data?.returned_status_code);
86
+ return Number.isInteger(code) && code > 0 ? code : undefined;
87
+ }
84
88
  function withoutQuery(url) {
85
89
  return url.split(/[?#]/, 1)[0];
86
90
  }
@@ -281,7 +285,7 @@ class Client {
281
285
  }
282
286
  try {
283
287
  const data = await this.read(request, (r) => r.json());
284
- throw new errors_1.default(`Failed to generate screenshot, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url);
288
+ throw new errors_1.default(`Failed to generate screenshot, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url, returnedStatusCode(data));
285
289
  }
286
290
  catch (e) {
287
291
  if (e instanceof errors_1.default || e instanceof errors_1.ConnectionError) {
@@ -307,7 +311,7 @@ class Client {
307
311
  }
308
312
  try {
309
313
  const data = await this.read(request, (r) => r.json());
310
- throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url);
314
+ throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url, returnedStatusCode(data));
311
315
  }
312
316
  catch (e) {
313
317
  if (e instanceof errors_1.default || e instanceof errors_1.ConnectionError) {
@@ -353,7 +357,7 @@ class Client {
353
357
  };
354
358
  }
355
359
  const data = await this.read(request, (r) => r.json());
356
- throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url);
360
+ throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url, returnedStatusCode(data));
357
361
  });
358
362
  }
359
363
  }
@@ -674,13 +678,6 @@ class TakeOptions {
674
678
  this.put("ip_country_code", countryCode);
675
679
  return this;
676
680
  }
677
- /**
678
- * Sets the ScreenshotOne server region used for the request.
679
- */
680
- serversRegion(region) {
681
- this.put("servers_region", region);
682
- return this;
683
- }
684
681
  /**
685
682
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
686
683
  */
@@ -826,13 +823,6 @@ class TakeOptions {
826
823
  this.put("block_chats", block ? "true" : "false");
827
824
  return this;
828
825
  }
829
- /**
830
- * Blocks social widgets.
831
- */
832
- blockSocials(block) {
833
- this.put("block_socials", block ? "true" : "false");
834
- return this;
835
- }
836
826
  /**
837
827
  * Blocks trackers.
838
828
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "screenshotone-api-sdk",
3
3
  "homepage": "https://screenshotone.com",
4
- "version": "1.1.25",
4
+ "version": "1.3.0",
5
5
  "description": "Use ScreenshotOne.com API to generate screenshots of any website.",
6
6
  "repository": {
7
7
  "type": "git",
package/src/errors.ts CHANGED
@@ -4,14 +4,20 @@ export default class APIError extends Error {
4
4
  public readonly errorCode?: string;
5
5
  public readonly errorMessage?: string;
6
6
  public readonly documentationUrl?: string;
7
+ /**
8
+ * The HTTP status code the target site returned, for example 404 or 503.
9
+ * Set for the "host_returned_error" error code.
10
+ */
11
+ public readonly returnedStatusCode?: number;
7
12
 
8
- constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string) {
13
+ constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string, returnedStatusCode?: number) {
9
14
  super(message);
10
15
 
11
16
  this.httpStatusCode = httpStatusCode;
12
17
  this.errorCode = errorCode;
13
18
  this.errorMessage = errorMessage;
14
19
  this.documentationUrl = documentationUrl;
20
+ this.returnedStatusCode = returnedStatusCode;
15
21
  }
16
22
  }
17
23
 
package/src/main.ts CHANGED
@@ -97,6 +97,11 @@ function networkFailureCode(error: unknown): string | undefined {
97
97
 
98
98
  // the request URL without its query and fragment, which hold the access key
99
99
  // and the signature, whatever the URL's form
100
+ function returnedStatusCode(data: any): number | undefined {
101
+ const code = Number(data?.returned_status_code);
102
+ return Number.isInteger(code) && code > 0 ? code : undefined;
103
+ }
104
+
100
105
  function withoutQuery(url: string): string {
101
106
  return url.split(/[?#]/, 1)[0];
102
107
  }
@@ -376,7 +381,8 @@ export class Client {
376
381
  response.status,
377
382
  data?.error_code,
378
383
  data?.error_message,
379
- data?.documentation_url
384
+ data?.documentation_url,
385
+ returnedStatusCode(data)
380
386
  );
381
387
  } catch (e) {
382
388
  if (e instanceof APIError || e instanceof ConnectionError) {
@@ -413,7 +419,8 @@ export class Client {
413
419
  response.status,
414
420
  data?.error_code,
415
421
  data?.error_message,
416
- data?.documentation_url
422
+ data?.documentation_url,
423
+ returnedStatusCode(data)
417
424
  );
418
425
  } catch (e) {
419
426
  if (e instanceof APIError || e instanceof ConnectionError) {
@@ -482,7 +489,8 @@ export class Client {
482
489
  response.status,
483
490
  data?.error_code,
484
491
  data?.error_message,
485
- data?.documentation_url
492
+ data?.documentation_url,
493
+ returnedStatusCode(data)
486
494
  );
487
495
  });
488
496
  }
@@ -888,15 +896,6 @@ export class TakeOptions {
888
896
  return this;
889
897
  }
890
898
 
891
- /**
892
- * Sets the ScreenshotOne server region used for the request.
893
- */
894
- serversRegion(region: string): TakeOptions {
895
- this.put("servers_region", region);
896
-
897
- return this;
898
- }
899
-
900
899
  /**
901
900
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
902
901
  */
@@ -1088,15 +1087,6 @@ export class TakeOptions {
1088
1087
  return this;
1089
1088
  }
1090
1089
 
1091
- /**
1092
- * Blocks social widgets.
1093
- */
1094
- blockSocials(block: boolean): TakeOptions {
1095
- this.put("block_socials", block ? "true" : "false");
1096
-
1097
- return this;
1098
- }
1099
-
1100
1090
  /**
1101
1091
  * Blocks trackers.
1102
1092
  */
@@ -74,8 +74,6 @@ describe("testing client", () => {
74
74
  .fullPageSlices(true)
75
75
  .fullPageSliceHeight(3000)
76
76
  .fullPageSliceOverlapHeight(500)
77
- .serversRegion("us-east")
78
- .blockSocials(true)
79
77
  .proxy("http://proxy.example.com")
80
78
  .proxyBypassHosts(
81
79
  "cdn.example.com",
@@ -113,8 +111,6 @@ describe("testing client", () => {
113
111
  full_page_slices: ["true"],
114
112
  full_page_slice_height: ["3000"],
115
113
  full_page_slice_overlap_height: ["500"],
116
- servers_region: ["us-east"],
117
- block_socials: ["true"],
118
114
  proxy: ["http://proxy.example.com"],
119
115
  proxy_bypass_hosts: [
120
116
  "cdn.example.com",