@apiverve/websitetopdf 1.2.0 → 1.2.2

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.
Files changed (5) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +144 -147
  3. package/index.d.ts +33 -33
  4. package/index.js +209 -209
  5. package/package.json +4 -4
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 APIVerve, and EvlarSoft LLC
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 APIVerve and EvlarSoft LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,64 +1,61 @@
1
- # Website to PDF API
2
-
3
- Website to PDF is a simple tool for converting a website to PDF. It returns the PDF file generated from the website.
4
-
5
- ![Build Status](https://img.shields.io/badge/build-passing-green)
6
- ![Code Climate](https://img.shields.io/badge/maintainability-B-purple)
7
- ![Prod Ready](https://img.shields.io/badge/production-ready-blue)
8
- [![npm version](https://img.shields.io/npm/v/@apiverve/websitetopdf.svg)](https://www.npmjs.com/package/@apiverve/websitetopdf)
9
-
10
- This is a Javascript Wrapper for the [Website to PDF API](https://apiverve.com/marketplace/websitetopdf?utm_source=npm&utm_medium=readme)
11
-
12
- ---
13
-
14
- ## Installation
15
-
16
- Using npm:
17
- ```shell
18
- npm install @apiverve/websitetopdf
19
- ```
20
-
21
- Using yarn:
22
- ```shell
23
- yarn add @apiverve/websitetopdf
24
- ```
25
-
26
- ---
27
-
28
- ## Configuration
29
-
30
- Before using the Website to PDF API client, you have to setup your account and obtain your API Key.
31
- You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=readme)
32
-
33
- ---
34
-
35
- ## Quick Start
36
-
37
- [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=readme)
38
-
39
- The Website to PDF API documentation is found here: [https://docs.apiverve.com/ref/websitetopdf](https://docs.apiverve.com/ref/websitetopdf?utm_source=npm&utm_medium=readme).
40
- You can find parameters, example responses, and status codes documented here.
41
-
42
- ### Setup
43
-
44
- ```javascript
45
- const websitetopdfAPI = require('@apiverve/websitetopdf');
46
- const api = new websitetopdfAPI({
47
- api_key: '[YOUR_API_KEY]'
48
- });
49
- ```
50
-
51
- ---
52
-
53
- ## Usage
54
-
55
- ---
56
-
57
- ### Perform Request
58
-
59
- 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.
60
-
61
- ```javascript
1
+ # Website to PDF API
2
+
3
+ Website to PDF renders any public web page into a PDF document from a submitted URL. It returns a temporary signed download link, unique filename, and expiration timestamp, with paid plans adding custom margins and landscape layout.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@apiverve/websitetopdf.svg)](https://www.npmjs.com/package/@apiverve/websitetopdf)
6
+
7
+ This is a JavaScript wrapper for the [Website to PDF API](https://apiverve.com/marketplace/websitetopdf?utm_source=npm&utm_medium=referral&utm_content=readme)
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ Using npm:
14
+ ```shell
15
+ npm install @apiverve/websitetopdf
16
+ ```
17
+
18
+ Using yarn:
19
+ ```shell
20
+ yarn add @apiverve/websitetopdf
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Configuration
26
+
27
+ Before using the Website to PDF API client, you have to setup your account and obtain your API Key.
28
+ You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=referral&utm_content=readme)
29
+
30
+ ---
31
+
32
+ ## Quick Start
33
+
34
+ [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=referral&utm_content=readme)
35
+
36
+ The Website to PDF API documentation is found here: [https://docs.apiverve.com/ref/websitetopdf](https://docs.apiverve.com/ref/websitetopdf?utm_source=npm&utm_medium=referral&utm_content=readme).
37
+ You can find parameters, example responses, and status codes documented here.
38
+
39
+ ### Setup
40
+
41
+ ```javascript
42
+ const websitetopdfAPI = require('@apiverve/websitetopdf');
43
+ const api = new websitetopdfAPI({
44
+ api_key: '[YOUR_API_KEY]'
45
+ });
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Usage
51
+
52
+ ---
53
+
54
+ ### Perform Request
55
+
56
+ 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.
57
+
58
+ ```javascript
62
59
  var query = {
63
60
  "marginTop": 0.4,
64
61
  "marginBottom": 0.4,
@@ -66,24 +63,24 @@ var query = {
66
63
  "marginRight": 0.4,
67
64
  "landscape": false,
68
65
  "url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
69
- };
70
-
71
- api.execute(query, function (error, data) {
72
- if (error) {
73
- return console.error(error);
74
- } else {
75
- console.log(data);
76
- }
77
- });
78
- ```
79
-
80
- ---
81
-
82
- ### Using Promises
83
-
84
- You can also use promises to make requests. The API returns a promise that you can use to handle the response.
85
-
86
- ```javascript
66
+ };
67
+
68
+ api.execute(query, function (error, data) {
69
+ if (error) {
70
+ return console.error(error);
71
+ } else {
72
+ console.log(data);
73
+ }
74
+ });
75
+ ```
76
+
77
+ ---
78
+
79
+ ### Using Promises
80
+
81
+ You can also use promises to make requests. The API returns a promise that you can use to handle the response.
82
+
83
+ ```javascript
87
84
  var query = {
88
85
  "marginTop": 0.4,
89
86
  "marginBottom": 0.4,
@@ -91,25 +88,25 @@ var query = {
91
88
  "marginRight": 0.4,
92
89
  "landscape": false,
93
90
  "url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
94
- };
95
-
96
- api.execute(query)
97
- .then(data => {
98
- console.log(data);
99
- })
100
- .catch(error => {
101
- console.error(error);
102
- });
103
- ```
104
-
105
- ---
106
-
107
- ### Using Async/Await
108
-
109
- You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
110
-
111
- ```javascript
112
- async function makeRequest() {
91
+ };
92
+
93
+ api.execute(query)
94
+ .then(data => {
95
+ console.log(data);
96
+ })
97
+ .catch(error => {
98
+ console.error(error);
99
+ });
100
+ ```
101
+
102
+ ---
103
+
104
+ ### Using Async/Await
105
+
106
+ You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
107
+
108
+ ```javascript
109
+ async function makeRequest() {
113
110
  var query = {
114
111
  "marginTop": 0.4,
115
112
  "marginBottom": 0.4,
@@ -117,22 +114,22 @@ async function makeRequest() {
117
114
  "marginRight": 0.4,
118
115
  "landscape": false,
119
116
  "url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts"
120
- };
121
-
122
- try {
123
- const data = await api.execute(query);
124
- console.log(data);
125
- } catch (error) {
126
- console.error(error);
127
- }
128
- }
129
- ```
130
-
131
- ---
132
-
133
- ## Example Response
134
-
135
- ```json
117
+ };
118
+
119
+ try {
120
+ const data = await api.execute(query);
121
+ console.log(data);
122
+ } catch (error) {
123
+ console.error(error);
124
+ }
125
+ }
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Example Response
131
+
132
+ ```json
136
133
  {
137
134
  "status": "ok",
138
135
  "error": null,
@@ -147,36 +144,36 @@ async function makeRequest() {
147
144
  "url": "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts",
148
145
  "downloadURL": "https://storage.googleapis.com/apiverve-helpers.appspot.com/websitetopdf/128deceb-c515-444b-8863-82cb3f6ba632.pdf?GoogleAccessId=1089020767582-compute%40developer.gserviceaccount.com&Expires=1766097122&Signature=LI747FKqKj5i5TYX3KIoVy%2FHgXsLOSXfVEUM0Ekqz2SiiYOZWuk3Of7QBDUklSrcbjiHV0AjbzFTKt6oDU83UkN282HbmhxwrolN6v1Zb9twVi1y7gmTpapCiJi%2BpA1r89ioe%2Fe0%2FV7KrIWaqsorzpdJrnMqe2izMWBaZq%2FYkSO2qlwSyhg2R8EsfxYNAANtd%2FuNS0RuIzqTdhNCiTrRirnDAKS3dMCySQJRznHFnyqzNj1OXwVjvdpSMn9XhWCUa%2FDRR8q%2BE9B0yF8eTvIrDSe2OzJT%2FJLc9rxcLfXAny21gtNqrzMJPU4yM9Ge%2BEbepmDnNZf9xpODNsnq5eLF0g%3D%3D"
149
146
  }
150
- }
151
- ```
152
-
153
- ---
154
-
155
- ## Customer Support
156
-
157
- Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=readme).
158
-
159
- ---
160
-
161
- ## Updates
162
-
163
- Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
164
-
165
- ---
166
-
167
- ## Legal
168
-
169
- All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=readme), [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=readme), and [Refund Policy](https://apiverve.com/refund?utm_source=npm&utm_medium=readme).
170
-
171
- ---
172
-
173
- ## License
174
- Licensed under the The MIT License (MIT)
175
-
176
- Copyright (©) 2026 APIVerve, and EvlarSoft LLC
177
-
178
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
179
-
180
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
181
-
182
- 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.
147
+ }
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Customer Support
153
+
154
+ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=referral&utm_content=readme).
155
+
156
+ ---
157
+
158
+ ## Updates
159
+
160
+ Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
161
+
162
+ ---
163
+
164
+ ## Legal
165
+
166
+ All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=referral&utm_content=readme) and [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=referral&utm_content=readme).
167
+
168
+ ---
169
+
170
+ ## License
171
+ Licensed under the MIT License (MIT)
172
+
173
+ Copyright (©) 2026 APIVerve, and EvlarSoft LLC
174
+
175
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
176
+
177
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
178
+
179
+ 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.
package/index.d.ts CHANGED
@@ -1,28 +1,28 @@
1
- declare module '@apiverve/websitetopdf' {
2
- export interface websitetopdfOptions {
3
- api_key: string;
4
- secure?: boolean;
5
- }
6
-
7
- /**
8
- * Describes fields the current plan does not unlock. Locked fields arrive as null
9
- * in `data`; `locked_fields` names them, using dot paths for nested fields.
10
- * Absent when the plan unlocks everything.
11
- */
12
- export interface PremiumInfo {
13
- message: string;
14
- upgrade_url: string;
15
- locked_fields: string[];
16
- }
17
-
18
- export interface websitetopdfResponse {
19
- status: string;
20
- error: string | null;
21
- data: WebsitetoPDFData;
22
- code?: number;
23
- premium?: PremiumInfo;
24
- }
25
-
1
+ declare module '@apiverve/websitetopdf' {
2
+ export interface websitetopdfOptions {
3
+ api_key: string;
4
+ secure?: boolean;
5
+ }
6
+
7
+ /**
8
+ * Describes fields the current plan does not unlock. Locked fields arrive as null
9
+ * in `data`; `locked_fields` names them, using dot paths for nested fields.
10
+ * Absent when the plan unlocks everything.
11
+ */
12
+ export interface PremiumInfo {
13
+ message: string;
14
+ upgrade_url: string;
15
+ locked_fields: string[];
16
+ }
17
+
18
+ export interface websitetopdfResponse {
19
+ status: string;
20
+ error: string | null;
21
+ data: WebsitetoPDFData;
22
+ code?: number;
23
+ premium?: PremiumInfo;
24
+ }
25
+
26
26
 
27
27
  interface WebsitetoPDFData {
28
28
  marginLeft: null | string;
@@ -36,11 +36,11 @@ declare module '@apiverve/websitetopdf' {
36
36
  downloadURL: null | string;
37
37
  }
38
38
 
39
- export default class websitetopdfWrapper {
40
- constructor(options: websitetopdfOptions);
41
-
42
- execute(callback: (error: any, data: websitetopdfResponse | null) => void): Promise<websitetopdfResponse>;
43
- execute(query: Record<string, any>, callback: (error: any, data: websitetopdfResponse | null) => void): Promise<websitetopdfResponse>;
44
- execute(query?: Record<string, any>): Promise<websitetopdfResponse>;
45
- }
46
- }
39
+ export default class websitetopdfWrapper {
40
+ constructor(options: websitetopdfOptions);
41
+
42
+ execute(callback: (error: any, data: websitetopdfResponse | null) => void): Promise<websitetopdfResponse>;
43
+ execute(query: Record<string, any>, callback: (error: any, data: websitetopdfResponse | null) => void): Promise<websitetopdfResponse>;
44
+ execute(query?: Record<string, any>): Promise<websitetopdfResponse>;
45
+ }
46
+ }
package/index.js CHANGED
@@ -1,209 +1,209 @@
1
- const axios = require('axios');
2
-
3
- class websitetopdfWrapper {
4
-
5
- constructor(options) {
6
- if (!options || typeof options !== 'object') {
7
- throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/websitetopdf');
8
- }
9
-
10
- const { api_key, secure = true } = options;
11
-
12
- if (!api_key || typeof api_key !== 'string') {
13
- throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
14
- }
15
-
16
- // Validate API key format (GUID, prefixed keys like apv_xxx, or alphanumeric)
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 and underscores. Get your API key at: https://apiverve.com');
20
- }
21
-
22
- if (typeof secure !== 'boolean') {
23
- throw new Error('Secure parameter must be a boolean value.');
24
- }
25
-
26
- this.APIKey = api_key;
27
- this.IsSecure = secure;
28
-
29
- // secure is deprecated, all requests must be made over HTTPS
30
- this.baseURL = 'https://api.apiverve.com/v1/websitetopdf';
31
-
32
- // Validation rules for parameters (generated from schema)
33
- this.validationRules = {"url":{"type":"string","required":true,"format":"url"},"marginTop":{"type":"number","required":false,"default":"0.4"},"marginRight":{"type":"number","required":false,"default":"0.4"},"marginBottom":{"type":"number","required":false,"default":"0.4"},"marginLeft":{"type":"number","required":false,"default":"0.4"},"landscape":{"type":"boolean","required":false,"default":false}};
34
- }
35
-
36
- /**
37
- * Validate query parameters against schema rules
38
- * @param {Object} query - The query parameters to validate
39
- * @throws {Error} - If validation fails
40
- */
41
- validateParams(query) {
42
- const errors = [];
43
-
44
- for (const [paramName, rules] of Object.entries(this.validationRules)) {
45
- const value = query[paramName];
46
-
47
- // Check required
48
- if (rules.required && (value === undefined || value === null || value === '')) {
49
- errors.push(`Required parameter [${paramName}] is missing.`);
50
- continue;
51
- }
52
-
53
- // Skip validation if value is not provided and not required
54
- if (value === undefined || value === null) {
55
- continue;
56
- }
57
-
58
- // Type validation
59
- if (rules.type === 'integer' || rules.type === 'number') {
60
- const numValue = Number(value);
61
- if (isNaN(numValue)) {
62
- errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
63
- continue;
64
- }
65
-
66
- if (rules.type === 'integer' && !Number.isInteger(numValue)) {
67
- errors.push(`Parameter [${paramName}] must be an integer.`);
68
- continue;
69
- }
70
-
71
- // Min/max validation for numbers
72
- if (rules.min !== undefined && numValue < rules.min) {
73
- errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
74
- }
75
- if (rules.max !== undefined && numValue > rules.max) {
76
- errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
77
- }
78
- } else if (rules.type === 'string') {
79
- if (typeof value !== 'string') {
80
- errors.push(`Parameter [${paramName}] must be a string.`);
81
- continue;
82
- }
83
-
84
- // Length validation for strings
85
- if (rules.minLength !== undefined && value.length < rules.minLength) {
86
- errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
87
- }
88
- if (rules.maxLength !== undefined && value.length > rules.maxLength) {
89
- errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
90
- }
91
-
92
- // Format validation
93
- if (rules.format) {
94
- const formatPatterns = {
95
- 'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
96
- 'url': /^https?:\/\/.+/i,
97
- 'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
98
- 'date': /^\d{4}-\d{2}-\d{2}$/,
99
- 'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
100
- };
101
-
102
- if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
103
- errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
104
- }
105
- }
106
- } else if (rules.type === 'boolean') {
107
- if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
108
- errors.push(`Parameter [${paramName}] must be a boolean.`);
109
- }
110
- } else if (rules.type === 'array') {
111
- if (!Array.isArray(value)) {
112
- errors.push(`Parameter [${paramName}] must be an array.`);
113
- }
114
- }
115
-
116
- // Enum validation
117
- if (rules.enum && Array.isArray(rules.enum)) {
118
- if (!rules.enum.includes(value)) {
119
- errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
120
- }
121
- }
122
- }
123
-
124
- if (errors.length > 0) {
125
- throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/websitetopdf`);
126
- }
127
- }
128
-
129
- async execute(query, callback) {
130
- // Handle different argument patterns
131
- if(arguments.length === 0) {
132
- // execute() - no args
133
- query = {};
134
- callback = null;
135
- } else if(arguments.length === 1) {
136
- if (typeof query === 'function') {
137
- // execute(callback)
138
- callback = query;
139
- query = {};
140
- } else {
141
- // execute(query)
142
- callback = null;
143
- }
144
- } else {
145
- // execute(query, callback)
146
- if (!query || typeof query !== 'object') {
147
- throw new Error('Query parameters must be provided as an object.');
148
- }
149
- }
150
-
151
- // Validate parameters against schema rules
152
- this.validateParams(query);
153
-
154
- const method = 'POST';
155
- const url = method === 'POST' ? this.baseURL : this.constructURL(query);
156
-
157
- try {
158
- const response = await axios({
159
- method,
160
- url,
161
- headers: {
162
- 'Content-Type': 'application/json',
163
- 'x-api-key': this.APIKey,
164
- 'auth-mode': 'npm-package'
165
- },
166
- data: method === 'POST' ? query : undefined
167
- });
168
-
169
- const data = response.data;
170
- if (callback) callback(null, data);
171
- return data;
172
- } catch (error) {
173
- let apiError;
174
-
175
- if (error.response && error.response.data) {
176
- apiError = error.response.data;
177
- } else if (error.message) {
178
- apiError = { error: error.message, status: 'error' };
179
- } else {
180
- apiError = { error: 'An unknown error occurred', status: 'error' };
181
- }
182
-
183
- if (callback) {
184
- callback(apiError, null);
185
- return; // Don't throw if callback is provided
186
- }
187
-
188
- throw apiError;
189
- }
190
- }
191
-
192
- constructURL(query) {
193
- let url = this.baseURL;
194
-
195
- if(query && typeof query === 'object')
196
- {
197
- if (Object.keys(query).length > 0) {
198
- const queryString = Object.keys(query)
199
- .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
200
- .join('&');
201
- url += `?${queryString}`;
202
- }
203
- }
204
- return url;
205
- }
206
-
207
- }
208
-
209
- module.exports = websitetopdfWrapper;
1
+ const axios = require('axios');
2
+
3
+ class websitetopdfWrapper {
4
+
5
+ constructor(options) {
6
+ if (!options || typeof options !== 'object') {
7
+ throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/websitetopdf');
8
+ }
9
+
10
+ const { api_key, secure = true } = options;
11
+
12
+ if (!api_key || typeof api_key !== 'string') {
13
+ throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
14
+ }
15
+
16
+ // Validate API key format (GUID, prefixed keys like apv_xxx, or alphanumeric)
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 and underscores. Get your API key at: https://apiverve.com');
20
+ }
21
+
22
+ if (typeof secure !== 'boolean') {
23
+ throw new Error('Secure parameter must be a boolean value.');
24
+ }
25
+
26
+ this.APIKey = api_key;
27
+ this.IsSecure = secure;
28
+
29
+ // secure is deprecated, all requests must be made over HTTPS
30
+ this.baseURL = 'https://api.apiverve.com/v1/websitetopdf';
31
+
32
+ // Validation rules for parameters (generated from schema)
33
+ this.validationRules = {"url":{"type":"string","required":true,"format":"url"},"marginTop":{"type":"number","required":false,"default":"0.4"},"marginRight":{"type":"number","required":false,"default":"0.4"},"marginBottom":{"type":"number","required":false,"default":"0.4"},"marginLeft":{"type":"number","required":false,"default":"0.4"},"landscape":{"type":"boolean","required":false,"default":false}};
34
+ }
35
+
36
+ /**
37
+ * Validate query parameters against schema rules
38
+ * @param {Object} query - The query parameters to validate
39
+ * @throws {Error} - If validation fails
40
+ */
41
+ validateParams(query) {
42
+ const errors = [];
43
+
44
+ for (const [paramName, rules] of Object.entries(this.validationRules)) {
45
+ const value = query[paramName];
46
+
47
+ // Check required
48
+ if (rules.required && (value === undefined || value === null || value === '')) {
49
+ errors.push(`Required parameter [${paramName}] is missing.`);
50
+ continue;
51
+ }
52
+
53
+ // Skip validation if value is not provided and not required
54
+ if (value === undefined || value === null) {
55
+ continue;
56
+ }
57
+
58
+ // Type validation
59
+ if (rules.type === 'integer' || rules.type === 'number') {
60
+ const numValue = Number(value);
61
+ if (isNaN(numValue)) {
62
+ errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
63
+ continue;
64
+ }
65
+
66
+ if (rules.type === 'integer' && !Number.isInteger(numValue)) {
67
+ errors.push(`Parameter [${paramName}] must be an integer.`);
68
+ continue;
69
+ }
70
+
71
+ // Min/max validation for numbers
72
+ if (rules.min !== undefined && numValue < rules.min) {
73
+ errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
74
+ }
75
+ if (rules.max !== undefined && numValue > rules.max) {
76
+ errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
77
+ }
78
+ } else if (rules.type === 'string') {
79
+ if (typeof value !== 'string') {
80
+ errors.push(`Parameter [${paramName}] must be a string.`);
81
+ continue;
82
+ }
83
+
84
+ // Length validation for strings
85
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
86
+ errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
87
+ }
88
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
89
+ errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
90
+ }
91
+
92
+ // Format validation
93
+ if (rules.format) {
94
+ const formatPatterns = {
95
+ 'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
96
+ 'url': /^https?:\/\/.+/i,
97
+ 'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
98
+ 'date': /^\d{4}-\d{2}-\d{2}$/,
99
+ 'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
100
+ };
101
+
102
+ if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
103
+ errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
104
+ }
105
+ }
106
+ } else if (rules.type === 'boolean') {
107
+ if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
108
+ errors.push(`Parameter [${paramName}] must be a boolean.`);
109
+ }
110
+ } else if (rules.type === 'array') {
111
+ if (!Array.isArray(value)) {
112
+ errors.push(`Parameter [${paramName}] must be an array.`);
113
+ }
114
+ }
115
+
116
+ // Enum validation
117
+ if (rules.enum && Array.isArray(rules.enum)) {
118
+ if (!rules.enum.includes(value)) {
119
+ errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
120
+ }
121
+ }
122
+ }
123
+
124
+ if (errors.length > 0) {
125
+ throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/websitetopdf`);
126
+ }
127
+ }
128
+
129
+ async execute(query, callback) {
130
+ // Handle different argument patterns
131
+ if(arguments.length === 0) {
132
+ // execute() - no args
133
+ query = {};
134
+ callback = null;
135
+ } else if(arguments.length === 1) {
136
+ if (typeof query === 'function') {
137
+ // execute(callback)
138
+ callback = query;
139
+ query = {};
140
+ } else {
141
+ // execute(query)
142
+ callback = null;
143
+ }
144
+ } else {
145
+ // execute(query, callback)
146
+ if (!query || typeof query !== 'object') {
147
+ throw new Error('Query parameters must be provided as an object.');
148
+ }
149
+ }
150
+
151
+ // Validate parameters against schema rules
152
+ this.validateParams(query);
153
+
154
+ const method = 'POST';
155
+ const url = method === 'POST' ? this.baseURL : this.constructURL(query);
156
+
157
+ try {
158
+ const response = await axios({
159
+ method,
160
+ url,
161
+ headers: {
162
+ 'Content-Type': 'application/json',
163
+ 'x-api-key': this.APIKey,
164
+ 'auth-mode': 'npm-package'
165
+ },
166
+ data: method === 'POST' ? query : undefined
167
+ });
168
+
169
+ const data = response.data;
170
+ if (callback) callback(null, data);
171
+ return data;
172
+ } catch (error) {
173
+ let apiError;
174
+
175
+ if (error.response && error.response.data) {
176
+ apiError = error.response.data;
177
+ } else if (error.message) {
178
+ apiError = { error: error.message, status: 'error' };
179
+ } else {
180
+ apiError = { error: 'An unknown error occurred', status: 'error' };
181
+ }
182
+
183
+ if (callback) {
184
+ callback(apiError, null);
185
+ return; // Don't throw if callback is provided
186
+ }
187
+
188
+ throw apiError;
189
+ }
190
+ }
191
+
192
+ constructURL(query) {
193
+ let url = this.baseURL;
194
+
195
+ if(query && typeof query === 'object')
196
+ {
197
+ if (Object.keys(query).length > 0) {
198
+ const queryString = Object.keys(query)
199
+ .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
200
+ .join('&');
201
+ url += `?${queryString}`;
202
+ }
203
+ }
204
+ return url;
205
+ }
206
+
207
+ }
208
+
209
+ module.exports = websitetopdfWrapper;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@apiverve/websitetopdf",
3
- "version": "1.2.0",
4
- "description": "Website to PDF is a simple tool for converting a website to PDF. It returns the PDF file generated from the website.",
3
+ "version": "1.2.2",
4
+ "description": "Website to PDF renders any public web page into a PDF document from a submitted URL. It returns a temporary signed download link, unique filename, and expiration timestamp, with paid plans adding custom margins and landscape layout.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "sideEffects": false,
@@ -23,7 +23,7 @@
23
23
  "directory": "npm"
24
24
  },
25
25
  "keywords": [
26
- "website to pdf", "website to pdf api", "website to pdf tool", "website to pdf software", "website to pdf service"
26
+ "website to pdf api", "url to pdf api", "webpage to pdf api", "web page to pdf api", "pdf api"
27
27
  ],
28
28
  "author": {
29
29
  "name": "APIVerve",
@@ -34,7 +34,7 @@
34
34
  "bugs": {
35
35
  "url": "https://github.com/apiverve/websitetopdf-api/issues"
36
36
  },
37
- "homepage": "https://apiverve.com/marketplace/websitetopdf?utm_source=npm&utm_medium=homepage",
37
+ "homepage": "https://apiverve.com/marketplace/websitetopdf?utm_source=npm&utm_medium=referral&utm_content=homepage",
38
38
  "devDependencies": {
39
39
  "mocha": "^11.0.1",
40
40
  "chai": "^5.1.2",