screenshotone-api-sdk 1.0.15 → 1.0.18
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 +29 -17
- package/dist/main.js +5 -4
- package/package.json +3 -4
- package/src/main.ts +7 -5
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jssdk
|
|
2
2
|
|
|
3
|
-
[](https://github.com/screenshotone/jssdk/actions/workflows/build.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/screenshotone-api-sdk)
|
|
4
5
|
|
|
5
6
|
An official [Screenshot API](https://screenshotone.com/) client for JavaScript and TypeScript.
|
|
6
7
|
|
|
@@ -9,26 +10,37 @@ It takes minutes to start taking screenshots. Just [sign up](https://screenshoto
|
|
|
9
10
|
## Installation
|
|
10
11
|
|
|
11
12
|
```shell
|
|
12
|
-
|
|
13
|
+
npm install screenshotone-api-sdk --save
|
|
13
14
|
```
|
|
14
15
|
|
|
15
16
|
## Usage
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:
|
|
19
|
+
```javascript
|
|
20
|
+
import * as fs from 'fs';
|
|
21
|
+
import * as screenshotone from 'screenshotone-api-sdk';
|
|
22
|
+
|
|
23
|
+
// create API client
|
|
24
|
+
const client = new screenshotone.Client("<access key>", "<secret key>");
|
|
25
|
+
|
|
26
|
+
// set up options
|
|
27
|
+
const options = screenshotone.TakeOptions
|
|
28
|
+
.url("https://example.com")
|
|
29
|
+
.delay(3)
|
|
30
|
+
.blockAds(true);
|
|
31
|
+
|
|
32
|
+
// generate URL
|
|
33
|
+
const url = client.generateTakeURL(options);
|
|
34
|
+
console.log(url);
|
|
35
|
+
// expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&delay=3&block_ads=true&access_key=%3Caccess+key%3E&signature=7f3419ece2c53ed2c7923c7d5deef290d662c3643822bf69ec8259ce10b3ea61
|
|
36
|
+
|
|
37
|
+
// or download the screenshot
|
|
38
|
+
const imageBlob = await client.take(options);
|
|
39
|
+
const buffer = Buffer.from(await imageBlob.arrayBuffer());
|
|
40
|
+
fs.writeFileSync("example.png", buffer)
|
|
41
|
+
// the screenshot is store in the example.png file
|
|
30
42
|
```
|
|
31
43
|
|
|
32
44
|
## License
|
|
33
45
|
|
|
34
|
-
`screenshotone/
|
|
46
|
+
`screenshotone/jssdk` is released under [the MIT license](LICENSE).
|
package/dist/main.js
CHANGED
|
@@ -30,13 +30,13 @@ exports.TakeOptions = exports.Client = void 0;
|
|
|
30
30
|
const crypto = __importStar(require("crypto"));
|
|
31
31
|
const big_js_1 = __importDefault(require("big.js"));
|
|
32
32
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
33
|
+
const API_BASE_URL = "https://api.screenshotone.com";
|
|
34
|
+
const API_TAKE_PATH = "/take";
|
|
33
35
|
/**
|
|
34
36
|
* Represents an API client for the screenshotone.com API.
|
|
35
37
|
*/
|
|
36
38
|
class Client {
|
|
37
39
|
constructor(accessKey, secretKey) {
|
|
38
|
-
this.API_BASE_URL = "https://api.screenshotone.com";
|
|
39
|
-
this.API_TAKE_PATH = "/take";
|
|
40
40
|
this.accessKey = accessKey;
|
|
41
41
|
this.secretKey = secretKey;
|
|
42
42
|
}
|
|
@@ -48,7 +48,7 @@ class Client {
|
|
|
48
48
|
.update(queryString, 'utf-8')
|
|
49
49
|
.digest('hex');
|
|
50
50
|
queryString += '&signature=' + signature;
|
|
51
|
-
return `${
|
|
51
|
+
return `${API_BASE_URL}${API_TAKE_PATH}?${queryString}`;
|
|
52
52
|
}
|
|
53
53
|
async take(options) {
|
|
54
54
|
const url = this.generateTakeURL(options);
|
|
@@ -56,7 +56,8 @@ class Client {
|
|
|
56
56
|
if (response.ok) {
|
|
57
57
|
return await response.blob();
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
const data = await response.json();
|
|
60
|
+
throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}: ${data?.message}`);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
exports.Client = Client;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screenshotone-api-sdk",
|
|
3
3
|
"homepage": "https://screenshotone.com",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.18",
|
|
5
5
|
"description": "Use ScreenshotOne.com API to generate screenshots of any website.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/screenshotone/
|
|
8
|
+
"url": "git+https://github.com/screenshotone/jssdk.git"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"screenshot",
|
|
@@ -25,11 +25,10 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"bugs": {
|
|
27
27
|
"email": "support@screenshotone.com",
|
|
28
|
-
"url": "https://github.com/screenshotone/
|
|
28
|
+
"url": "https://github.com/screenshotone/jssdk/issues"
|
|
29
29
|
},
|
|
30
30
|
"main": "dist/main.js",
|
|
31
31
|
"types": "dist/@types/main.d.ts",
|
|
32
|
-
"type": "module",
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@types/big.js": "^6.1.3",
|
|
35
34
|
"@types/node": "^17.0.40",
|
package/src/main.ts
CHANGED
|
@@ -2,13 +2,13 @@ import * as crypto from 'crypto';
|
|
|
2
2
|
import Big from 'big.js';
|
|
3
3
|
import fetch from 'cross-fetch';
|
|
4
4
|
|
|
5
|
+
const API_BASE_URL = "https://api.screenshotone.com";
|
|
6
|
+
const API_TAKE_PATH = "/take";
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Represents an API client for the screenshotone.com API.
|
|
7
10
|
*/
|
|
8
11
|
export class Client {
|
|
9
|
-
private readonly API_BASE_URL = "https://api.screenshotone.com";
|
|
10
|
-
private readonly API_TAKE_PATH = "/take";
|
|
11
|
-
|
|
12
12
|
private readonly accessKey: string;
|
|
13
13
|
private readonly secretKey: string;
|
|
14
14
|
|
|
@@ -27,7 +27,7 @@ export class Client {
|
|
|
27
27
|
.digest('hex');
|
|
28
28
|
queryString += '&signature=' + signature;
|
|
29
29
|
|
|
30
|
-
return `${
|
|
30
|
+
return `${API_BASE_URL}${API_TAKE_PATH}?${queryString}`;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async take(options: TakeOptions): Promise<Blob> {
|
|
@@ -37,7 +37,9 @@ export class Client {
|
|
|
37
37
|
return await response.blob()
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
|
|
42
|
+
throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}: ${data?.message}`);
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|