@apiverve/websitetopdf 1.1.9 → 1.1.10
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/LICENSE +1 -1
- package/README.md +96 -36
- package/examples/basic.js +43 -0
- package/index.d.ts +21 -0
- package/index.js +48 -14
- package/package.json +7 -5
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 APIVerve, and EvlarSoft LLC
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
Website to PDF API
|
|
2
|
-
============
|
|
1
|
+
# Website to PDF API
|
|
3
2
|
|
|
4
3
|
Website to PDF is a simple tool for converting a website to PDF. It returns the PDF file generated from the website.
|
|
5
4
|
|
|
@@ -7,46 +6,58 @@ Website to PDF is a simple tool for converting a website to PDF. It returns the
|
|
|
7
6
|

|
|
8
7
|

|
|
9
8
|
|
|
10
|
-
This is a Javascript Wrapper for the [Website to PDF API](https://apiverve.com/marketplace/
|
|
9
|
+
This is a Javascript Wrapper for the [Website to PDF API](https://apiverve.com/marketplace/websitetopdf)
|
|
11
10
|
|
|
12
11
|
---
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
Using npm:
|
|
16
|
+
```shell
|
|
17
|
+
npm install @apiverve/websitetopdf
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Using yarn:
|
|
21
|
+
```shell
|
|
22
|
+
yarn add @apiverve/websitetopdf
|
|
23
|
+
```
|
|
16
24
|
|
|
17
25
|
---
|
|
18
26
|
|
|
19
27
|
## Configuration
|
|
20
28
|
|
|
21
|
-
Before using the
|
|
29
|
+
Before using the Website to PDF API client, you have to setup your account and obtain your API Key.
|
|
22
30
|
You can get it by signing up at [https://apiverve.com](https://apiverve.com)
|
|
23
31
|
|
|
24
32
|
---
|
|
25
33
|
|
|
26
|
-
##
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
[Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
|
|
27
37
|
|
|
28
|
-
The Website to PDF API documentation is found here: [https://docs.apiverve.com/
|
|
38
|
+
The Website to PDF API documentation is found here: [https://docs.apiverve.com/ref/websitetopdf](https://docs.apiverve.com/ref/websitetopdf).
|
|
29
39
|
You can find parameters, example responses, and status codes documented here.
|
|
30
40
|
|
|
31
41
|
### Setup
|
|
32
42
|
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
api_key: [YOUR_API_KEY]
|
|
37
|
-
secure: true //(Optional, defaults to true)
|
|
43
|
+
```javascript
|
|
44
|
+
const websitetopdfAPI = require('@apiverve/websitetopdf');
|
|
45
|
+
const api = new websitetopdfAPI({
|
|
46
|
+
api_key: '[YOUR_API_KEY]'
|
|
38
47
|
});
|
|
39
48
|
```
|
|
40
49
|
|
|
41
50
|
---
|
|
42
51
|
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
---
|
|
43
55
|
|
|
44
56
|
### Perform Request
|
|
45
|
-
Using the API client, you can perform requests to the API.
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
|
|
48
59
|
|
|
49
|
-
```
|
|
60
|
+
```javascript
|
|
50
61
|
var query = {
|
|
51
62
|
"marginTop": 0.4,
|
|
52
63
|
"marginBottom": 0.4,
|
|
@@ -55,11 +66,7 @@ var query = {
|
|
|
55
66
|
"landscape": false,
|
|
56
67
|
"url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
|
|
57
68
|
};
|
|
58
|
-
```
|
|
59
69
|
|
|
60
|
-
###### Simple Request (using Callback)
|
|
61
|
-
|
|
62
|
-
```
|
|
63
70
|
api.execute(query, function (error, data) {
|
|
64
71
|
if (error) {
|
|
65
72
|
return console.error(error);
|
|
@@ -69,24 +76,76 @@ api.execute(query, function (error, data) {
|
|
|
69
76
|
});
|
|
70
77
|
```
|
|
71
78
|
|
|
72
|
-
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### Using Promises
|
|
82
|
+
|
|
83
|
+
You can also use promises to make requests. The API returns a promise that you can use to handle the response.
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
var query = {
|
|
87
|
+
"marginTop": 0.4,
|
|
88
|
+
"marginBottom": 0.4,
|
|
89
|
+
"marginLeft": 0.4,
|
|
90
|
+
"marginRight": 0.4,
|
|
91
|
+
"landscape": false,
|
|
92
|
+
"url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
api.execute(query)
|
|
96
|
+
.then(data => {
|
|
97
|
+
console.log(data);
|
|
98
|
+
})
|
|
99
|
+
.catch(error => {
|
|
100
|
+
console.error(error);
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### Using Async/Await
|
|
107
|
+
|
|
108
|
+
You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
async function makeRequest() {
|
|
112
|
+
var query = {
|
|
113
|
+
"marginTop": 0.4,
|
|
114
|
+
"marginBottom": 0.4,
|
|
115
|
+
"marginLeft": 0.4,
|
|
116
|
+
"marginRight": 0.4,
|
|
117
|
+
"landscape": false,
|
|
118
|
+
"url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
|
|
119
|
+
};
|
|
73
120
|
|
|
121
|
+
try {
|
|
122
|
+
const data = await api.execute(query);
|
|
123
|
+
console.log(data);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
74
128
|
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Example Response
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"status": "ok",
|
|
137
|
+
"error": null,
|
|
138
|
+
"data": {
|
|
139
|
+
"marginLeft": "0.4in",
|
|
140
|
+
"marginRight": "0.4in",
|
|
141
|
+
"marginTop": "0.4in",
|
|
142
|
+
"marginBottom": "0.4in",
|
|
143
|
+
"landscape": false,
|
|
144
|
+
"pdfName": "75a31d2a-c96d-428d-9c1e-63795d54f74c.pdf",
|
|
145
|
+
"expires": 1740260149292,
|
|
146
|
+
"url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts",
|
|
147
|
+
"downloadURL": "https://storage.googleapis.com/apiverve-helpers.appspot.com/websitetopdf/75a31d2a-c96d-428d-9c1e-63795d54f74c.pdf?GoogleAccessId=1089020767582-compute%40developer.gserviceaccount.com&Expires=1740260149&Signature=GSNCajtyCCkRJEd2n%2FEJ7z6a6E5oa3VmeK5Qkk9P3uYEAFsz4xVNnqZpZ4LDPJhKY9ea8ii1jNX5iKQabiTikwz%2Bg9g1kTxB5572oFPnsWAiaCreKeim3MzuczZRXtLnKpoCEMZWf6aGbYn7kRfKc47tFFbicx74isqxx6Lzs%2BMjKa3k33NUxH9JjQYeStWtnvI9DZorXgpUvjH8QL2H%2FU8wpZSIgpZAY8LMBo07PfWAO2ulinprBnTGhqIErIs71E6CPXnYuRo8r2ZOenQKkTsYNPXXt8vRK9eBh70dBVMEjfYQQA5tyauKvBNdpAmG3DLiKLATut55aKeicioejA%3D%3D"
|
|
148
|
+
}
|
|
90
149
|
}
|
|
91
150
|
```
|
|
92
151
|
|
|
@@ -99,6 +158,7 @@ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/c
|
|
|
99
158
|
---
|
|
100
159
|
|
|
101
160
|
## Updates
|
|
161
|
+
|
|
102
162
|
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
103
163
|
|
|
104
164
|
---
|
|
@@ -118,4 +178,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
118
178
|
|
|
119
179
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
120
180
|
|
|
121
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
181
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Example - Website to PDF API
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the Website to PDF API.
|
|
5
|
+
* Make sure to set your API key in the .env file or replace '[YOUR_API_KEY]' below.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
require('dotenv').config();
|
|
9
|
+
const websitetopdfAPI = require('../index.js');
|
|
10
|
+
|
|
11
|
+
// Initialize the API client
|
|
12
|
+
const api = new websitetopdfAPI({
|
|
13
|
+
api_key: process.env.API_KEY || '[YOUR_API_KEY]'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Example query
|
|
17
|
+
var query = {
|
|
18
|
+
"marginTop": 0.4,
|
|
19
|
+
"marginBottom": 0.4,
|
|
20
|
+
"marginLeft": 0.4,
|
|
21
|
+
"marginRight": 0.4,
|
|
22
|
+
"landscape": false,
|
|
23
|
+
"url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Make the API request using callback
|
|
27
|
+
console.log('Making request to Website to PDF API...\n');
|
|
28
|
+
|
|
29
|
+
api.execute(query, function (error, data) {
|
|
30
|
+
if (error) {
|
|
31
|
+
console.error('Error occurred:');
|
|
32
|
+
if (error.error) {
|
|
33
|
+
console.error('Message:', error.error);
|
|
34
|
+
console.error('Status:', error.status);
|
|
35
|
+
} else {
|
|
36
|
+
console.error(JSON.stringify(error, null, 2));
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log('Response:');
|
|
42
|
+
console.log(JSON.stringify(data, null, 2));
|
|
43
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare module '@apiverve/websitetopdf' {
|
|
2
|
+
export interface websitetopdfOptions {
|
|
3
|
+
api_key: string;
|
|
4
|
+
secure?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface websitetopdfResponse {
|
|
8
|
+
status: string;
|
|
9
|
+
error: string | null;
|
|
10
|
+
data: any;
|
|
11
|
+
code?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default class websitetopdfWrapper {
|
|
15
|
+
constructor(options: websitetopdfOptions);
|
|
16
|
+
|
|
17
|
+
execute(callback: (error: any, data: websitetopdfResponse | null) => void): Promise<websitetopdfResponse>;
|
|
18
|
+
execute(query: Record<string, any>, callback: (error: any, data: websitetopdfResponse | null) => void): Promise<websitetopdfResponse>;
|
|
19
|
+
execute(query?: Record<string, any>): Promise<websitetopdfResponse>;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/index.js
CHANGED
|
@@ -4,14 +4,27 @@ class websitetopdfWrapper {
|
|
|
4
4
|
|
|
5
5
|
constructor(options) {
|
|
6
6
|
if (!options || typeof options !== 'object') {
|
|
7
|
-
throw new Error('Options object must be provided.');
|
|
7
|
+
throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/websitetopdf');
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const { api_key, secure = true } = options;
|
|
11
11
|
|
|
12
12
|
if (!api_key || typeof api_key !== 'string') {
|
|
13
|
-
throw new Error('API key must be provided as a non-empty string.');
|
|
13
|
+
throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
// Validate API key format (GUID or alphanumeric with hyphens)
|
|
17
|
+
const apiKeyPattern = /^[a-zA-Z0-9-]+$/;
|
|
18
|
+
if (!apiKeyPattern.test(api_key)) {
|
|
19
|
+
throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens. Get your API key at: https://apiverve.com');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check minimum length (GUIDs are typically 36 chars with hyphens, or 32 without)
|
|
23
|
+
const trimmedKey = api_key.replace(/-/g, '');
|
|
24
|
+
if (trimmedKey.length < 32) {
|
|
25
|
+
throw new Error('Invalid API key. API key appears to be too short. Get your API key at: https://apiverve.com');
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
if (typeof secure !== 'boolean') {
|
|
16
29
|
throw new Error('Secure parameter must be a boolean value.');
|
|
17
30
|
}
|
|
@@ -24,20 +37,32 @@ class websitetopdfWrapper {
|
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
async execute(query, callback) {
|
|
27
|
-
|
|
40
|
+
// Handle different argument patterns
|
|
41
|
+
if(arguments.length === 0) {
|
|
42
|
+
// execute() - no args
|
|
43
|
+
query = {};
|
|
44
|
+
callback = null;
|
|
45
|
+
} else if(arguments.length === 1) {
|
|
46
|
+
if (typeof query === 'function') {
|
|
47
|
+
// execute(callback)
|
|
48
|
+
callback = query;
|
|
49
|
+
query = {};
|
|
50
|
+
} else {
|
|
51
|
+
// execute(query)
|
|
52
|
+
callback = null;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// execute(query, callback)
|
|
28
56
|
if (!query || typeof query !== 'object') {
|
|
29
57
|
throw new Error('Query parameters must be provided as an object.');
|
|
30
58
|
}
|
|
31
|
-
} else {
|
|
32
|
-
callback = query;
|
|
33
|
-
query = {};
|
|
34
59
|
}
|
|
35
60
|
|
|
36
61
|
var requiredParams = ["url"];
|
|
37
62
|
if (requiredParams.length > 0) {
|
|
38
63
|
for (var i = 0; i < requiredParams.length; i++) {
|
|
39
64
|
if (!query[requiredParams[i]]) {
|
|
40
|
-
throw new Error(`Required parameter [${requiredParams[i]}] is missing
|
|
65
|
+
throw new Error(`Required parameter [${requiredParams[i]}] is missing. See documentation: https://docs.apiverve.com/ref/websitetopdf`);
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
68
|
}
|
|
@@ -58,16 +83,25 @@ class websitetopdfWrapper {
|
|
|
58
83
|
});
|
|
59
84
|
|
|
60
85
|
const data = response.data;
|
|
61
|
-
callback(null, data);
|
|
86
|
+
if (callback) callback(null, data);
|
|
62
87
|
return data;
|
|
63
88
|
} catch (error) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
let apiError;
|
|
90
|
+
|
|
91
|
+
if (error.response && error.response.data) {
|
|
92
|
+
apiError = error.response.data;
|
|
93
|
+
} else if (error.message) {
|
|
94
|
+
apiError = { error: error.message, status: 'error' };
|
|
67
95
|
} else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
96
|
+
apiError = { error: 'An unknown error occurred', status: 'error' };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (callback) {
|
|
100
|
+
callback(apiError, null);
|
|
101
|
+
return; // Don't throw if callback is provided
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw apiError;
|
|
71
105
|
}
|
|
72
106
|
}
|
|
73
107
|
|
package/package.json
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apiverve/websitetopdf",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Website to PDF is a simple tool for converting a website to PDF. It returns the PDF file generated from the website.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "mocha"
|
|
8
|
+
"test": "mocha",
|
|
9
|
+
"example": "node examples/basic.js"
|
|
8
10
|
},
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "git+https://github.com/apiverve/websitetopdf-API.git"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
|
-
"website to pdf","website to pdf api","website to pdf tool","website to pdf software","website to pdf service"
|
|
16
|
+
"website to pdf", "website to pdf api", "website to pdf tool", "website to pdf software", "website to pdf service"
|
|
15
17
|
],
|
|
16
18
|
"author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
|
|
17
19
|
"license": "MIT",
|
|
18
20
|
"bugs": {
|
|
19
21
|
"url": "https://github.com/apiverve/websitetopdf-API/issues"
|
|
20
22
|
},
|
|
21
|
-
"homepage": "https://apiverve.com/marketplace/
|
|
23
|
+
"homepage": "https://apiverve.com/marketplace/websitetopdf?utm_source=npm",
|
|
22
24
|
"devDependencies": {
|
|
23
25
|
"mocha": "^11.0.1",
|
|
24
26
|
"chai": "^5.1.2",
|
|
@@ -27,6 +29,6 @@
|
|
|
27
29
|
"dependencies": {
|
|
28
30
|
"node-fetch": "^3.3.2",
|
|
29
31
|
"promise": "^8.3.0",
|
|
30
|
-
"axios": "1.
|
|
32
|
+
"axios": "1.13.2"
|
|
31
33
|
}
|
|
32
34
|
}
|