@apiverve/invoicegenerator 1.1.8 → 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/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Invoice Generator API
2
- ============
1
+ # Invoice Generator API
3
2
 
4
3
  Invoice Generator is a simple tool for generating invoices. It returns a PDF of the generated invoice.
5
4
 
@@ -7,51 +6,62 @@ Invoice Generator is a simple tool for generating invoices. It returns a PDF of
7
6
  ![Code Climate](https://img.shields.io/badge/maintainability-B-purple)
8
7
  ![Prod Ready](https://img.shields.io/badge/production-ready-blue)
9
8
 
10
- This is a Javascript Wrapper for the [Invoice Generator API](https://apiverve.com/marketplace/api/invoicegenerator)
9
+ This is a Javascript Wrapper for the [Invoice Generator API](https://apiverve.com/marketplace/invoicegenerator)
11
10
 
12
11
  ---
13
12
 
14
13
  ## Installation
15
- npm install @apiverve/invoicegenerator --save
14
+
15
+ Using npm:
16
+ ```shell
17
+ npm install @apiverve/invoicegenerator
18
+ ```
19
+
20
+ Using yarn:
21
+ ```shell
22
+ yarn add @apiverve/invoicegenerator
23
+ ```
16
24
 
17
25
  ---
18
26
 
19
27
  ## Configuration
20
28
 
21
- Before using the invoicegenerator API client, you have to setup your account and obtain your API Key.
29
+ Before using the Invoice Generator 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
- ## Usage
34
+ ## Quick Start
35
+
36
+ [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
27
37
 
28
- The Invoice Generator API documentation is found here: [https://docs.apiverve.com/api/invoicegenerator](https://docs.apiverve.com/api/invoicegenerator).
38
+ The Invoice Generator API documentation is found here: [https://docs.apiverve.com/ref/invoicegenerator](https://docs.apiverve.com/ref/invoicegenerator).
29
39
  You can find parameters, example responses, and status codes documented here.
30
40
 
31
41
  ### Setup
32
42
 
33
- ```
34
- var invoicegeneratorAPI = require('@apiverve/invoicegenerator');
35
- var api = new invoicegeneratorAPI({
36
- api_key: [YOUR_API_KEY],
37
- secure: true //(Optional, defaults to true)
43
+ ```javascript
44
+ const invoicegeneratorAPI = require('@apiverve/invoicegenerator');
45
+ const api = new invoicegeneratorAPI({
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
- ###### Define Query
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
  "invoiceNumber": "INV000001",
52
63
  "date": "2025-02-01",
53
64
  "dueDate": "2025-11-30",
54
-
55
65
  "from": {
56
66
  "from_name": "John Doe",
57
67
  "from_street": "123 Elm St",
@@ -59,7 +69,6 @@ var query = {
59
69
  "from_state": "IL",
60
70
  "from_zip": "62701"
61
71
  },
62
-
63
72
  "to": {
64
73
  "to_name": "Jane Smith",
65
74
  "to_street": "456 Oak St",
@@ -67,7 +76,6 @@ var query = {
67
76
  "to_state": "IL",
68
77
  "to_zip": "62702"
69
78
  },
70
-
71
79
  "job": "Web Development",
72
80
  "paymentTerms": "Net 30",
73
81
  "discount": 10,
@@ -77,20 +85,16 @@ var query = {
77
85
  {
78
86
  "qty": 2,
79
87
  "description": "Web Design Services",
80
- "unit_price": 500.00
88
+ "unit_price": 500
81
89
  },
82
90
  {
83
91
  "qty": 1,
84
92
  "description": "Domain Registration",
85
- "unit_price": 100.00
93
+ "unit_price": 100
86
94
  }
87
95
  ]
88
96
  };
89
- ```
90
-
91
- ###### Simple Request (using Callback)
92
97
 
93
- ```
94
98
  api.execute(query, function (error, data) {
95
99
  if (error) {
96
100
  return console.error(error);
@@ -100,18 +104,126 @@ api.execute(query, function (error, data) {
100
104
  });
101
105
  ```
102
106
 
103
- ###### Example Response
107
+ ---
108
+
109
+ ### Using Promises
110
+
111
+ You can also use promises to make requests. The API returns a promise that you can use to handle the response.
112
+
113
+ ```javascript
114
+ var query = {
115
+ "invoiceNumber": "INV000001",
116
+ "date": "2025-02-01",
117
+ "dueDate": "2025-11-30",
118
+ "from": {
119
+ "from_name": "John Doe",
120
+ "from_street": "123 Elm St",
121
+ "from_city": "Springfield",
122
+ "from_state": "IL",
123
+ "from_zip": "62701"
124
+ },
125
+ "to": {
126
+ "to_name": "Jane Smith",
127
+ "to_street": "456 Oak St",
128
+ "to_city": "Springfield",
129
+ "to_state": "IL",
130
+ "to_zip": "62702"
131
+ },
132
+ "job": "Web Development",
133
+ "paymentTerms": "Net 30",
134
+ "discount": 10,
135
+ "salesTax": 37.07,
136
+ "currency": "USD",
137
+ "items": [
138
+ {
139
+ "qty": 2,
140
+ "description": "Web Design Services",
141
+ "unit_price": 500
142
+ },
143
+ {
144
+ "qty": 1,
145
+ "description": "Domain Registration",
146
+ "unit_price": 100
147
+ }
148
+ ]
149
+ };
150
+
151
+ api.execute(query)
152
+ .then(data => {
153
+ console.log(data);
154
+ })
155
+ .catch(error => {
156
+ console.error(error);
157
+ });
158
+ ```
159
+
160
+ ---
161
+
162
+ ### Using Async/Await
163
+
164
+ You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
165
+
166
+ ```javascript
167
+ async function makeRequest() {
168
+ var query = {
169
+ "invoiceNumber": "INV000001",
170
+ "date": "2025-02-01",
171
+ "dueDate": "2025-11-30",
172
+ "from": {
173
+ "from_name": "John Doe",
174
+ "from_street": "123 Elm St",
175
+ "from_city": "Springfield",
176
+ "from_state": "IL",
177
+ "from_zip": "62701"
178
+ },
179
+ "to": {
180
+ "to_name": "Jane Smith",
181
+ "to_street": "456 Oak St",
182
+ "to_city": "Springfield",
183
+ "to_state": "IL",
184
+ "to_zip": "62702"
185
+ },
186
+ "job": "Web Development",
187
+ "paymentTerms": "Net 30",
188
+ "discount": 10,
189
+ "salesTax": 37.07,
190
+ "currency": "USD",
191
+ "items": [
192
+ {
193
+ "qty": 2,
194
+ "description": "Web Design Services",
195
+ "unit_price": 500
196
+ },
197
+ {
198
+ "qty": 1,
199
+ "description": "Domain Registration",
200
+ "unit_price": 100
201
+ }
202
+ ]
203
+ };
104
204
 
205
+ try {
206
+ const data = await api.execute(query);
207
+ console.log(data);
208
+ } catch (error) {
209
+ console.error(error);
210
+ }
211
+ }
105
212
  ```
106
- {
107
- "status": "ok",
108
- "error": null,
109
- "data": {
110
- "pdfName": "f9210db5-8be3-4de4-8b20-d58019b0600a.pdf",
111
- "expires": 1740259902629,
112
- "downloadURL": "https://storage.googleapis.com/apiverve-helpers.appspot.com/htmltopdf/f9210db5-8be3-4de4-8b20-d58019b0600a.pdf?GoogleAccessId=1089020767582-compute%40developer.gserviceaccount.com&Expires=1740259902&Signature=PVHHoAfVg%2BUOXCC1kt3m3ttRAns6UTrYPm8%2BVS19hEFAH27VG%2FnZHgUl75iUYpZozqycZw7etohyekZIBPeqozfFWkkodkMvi487x2onk%2B3S9nQN5J0gmPxhcfWVjT4jPxk7ggQMhG2rl7QCxjAhG9OGo1U9OuhSYdJXaQqEmOMhTDkhW%2BB3RFMHqXmgYZHBLo8kh1aLLK%2FdKbGOF5ofR33W0w%2F5ywdykG%2BAnk0Rv3oxTIppAR%2F4NsDeqhYBgq3yXyRubOgcZGBEEtAj2bpYPuzNtqKgF7aENTQe4MkghWct8P4qs%2F8MDSSMCZCN1B24Xz8TxGGem814qThfv3DLOw%3D%3D"
113
- },
114
- "code": 200
213
+
214
+ ---
215
+
216
+ ## Example Response
217
+
218
+ ```json
219
+ {
220
+ "status": "ok",
221
+ "error": null,
222
+ "data": {
223
+ "pdfName": "f9210db5-8be3-4de4-8b20-d58019b0600a.pdf",
224
+ "expires": 1740259902629,
225
+ "downloadURL": "https://storage.googleapis.com/apiverve-helpers.appspot.com/htmltopdf/f9210db5-8be3-4de4-8b20-d58019b0600a.pdf?GoogleAccessId=1089020767582-compute%40developer.gserviceaccount.com&Expires=1740259902&Signature=PVHHoAfVg%2BUOXCC1kt3m3ttRAns6UTrYPm8%2BVS19hEFAH27VG%2FnZHgUl75iUYpZozqycZw7etohyekZIBPeqozfFWkkodkMvi487x2onk%2B3S9nQN5J0gmPxhcfWVjT4jPxk7ggQMhG2rl7QCxjAhG9OGo1U9OuhSYdJXaQqEmOMhTDkhW%2BB3RFMHqXmgYZHBLo8kh1aLLK%2FdKbGOF5ofR33W0w%2F5ywdykG%2BAnk0Rv3oxTIppAR%2F4NsDeqhYBgq3yXyRubOgcZGBEEtAj2bpYPuzNtqKgF7aENTQe4MkghWct8P4qs%2F8MDSSMCZCN1B24Xz8TxGGem814qThfv3DLOw%3D%3D"
226
+ }
115
227
  }
116
228
  ```
117
229
 
@@ -124,6 +236,7 @@ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/c
124
236
  ---
125
237
 
126
238
  ## Updates
239
+
127
240
  Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
128
241
 
129
242
  ---
@@ -143,4 +256,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
143
256
 
144
257
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
145
258
 
146
- 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.
259
+ 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,71 @@
1
+ /**
2
+ * Basic Example - Invoice Generator API
3
+ *
4
+ * This example demonstrates how to use the Invoice Generator 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 invoicegeneratorAPI = require('../index.js');
10
+
11
+ // Initialize the API client
12
+ const api = new invoicegeneratorAPI({
13
+ api_key: process.env.API_KEY || '[YOUR_API_KEY]'
14
+ });
15
+
16
+ // Example query
17
+ var query = {
18
+ "invoiceNumber": "INV000001",
19
+ "date": "2025-02-01",
20
+ "dueDate": "2025-11-30",
21
+ "from": {
22
+ "from_name": "John Doe",
23
+ "from_street": "123 Elm St",
24
+ "from_city": "Springfield",
25
+ "from_state": "IL",
26
+ "from_zip": "62701"
27
+ },
28
+ "to": {
29
+ "to_name": "Jane Smith",
30
+ "to_street": "456 Oak St",
31
+ "to_city": "Springfield",
32
+ "to_state": "IL",
33
+ "to_zip": "62702"
34
+ },
35
+ "job": "Web Development",
36
+ "paymentTerms": "Net 30",
37
+ "discount": 10,
38
+ "salesTax": 37.07,
39
+ "currency": "USD",
40
+ "items": [
41
+ {
42
+ "qty": 2,
43
+ "description": "Web Design Services",
44
+ "unit_price": 500
45
+ },
46
+ {
47
+ "qty": 1,
48
+ "description": "Domain Registration",
49
+ "unit_price": 100
50
+ }
51
+ ]
52
+ };
53
+
54
+ // Make the API request using callback
55
+ console.log('Making request to Invoice Generator API...\n');
56
+
57
+ api.execute(query, function (error, data) {
58
+ if (error) {
59
+ console.error('Error occurred:');
60
+ if (error.error) {
61
+ console.error('Message:', error.error);
62
+ console.error('Status:', error.status);
63
+ } else {
64
+ console.error(JSON.stringify(error, null, 2));
65
+ }
66
+ return;
67
+ }
68
+
69
+ console.log('Response:');
70
+ console.log(JSON.stringify(data, null, 2));
71
+ });
package/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ declare module '@apiverve/invoicegenerator' {
2
+ export interface invoicegeneratorOptions {
3
+ api_key: string;
4
+ secure?: boolean;
5
+ }
6
+
7
+ export interface invoicegeneratorResponse {
8
+ status: string;
9
+ error: string | null;
10
+ data: any;
11
+ code?: number;
12
+ }
13
+
14
+ export default class invoicegeneratorWrapper {
15
+ constructor(options: invoicegeneratorOptions);
16
+
17
+ execute(callback: (error: any, data: invoicegeneratorResponse | null) => void): Promise<invoicegeneratorResponse>;
18
+ execute(query: Record<string, any>, callback: (error: any, data: invoicegeneratorResponse | null) => void): Promise<invoicegeneratorResponse>;
19
+ execute(query?: Record<string, any>): Promise<invoicegeneratorResponse>;
20
+ }
21
+ }
package/index.js CHANGED
@@ -4,14 +4,27 @@ class invoicegeneratorWrapper {
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/invoicegenerator');
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 invoicegeneratorWrapper {
24
37
  }
25
38
 
26
39
  async execute(query, callback) {
27
- if(arguments.length > 1) {
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
- var requiredParams = ["invoiceNumber", "from_name", "from_street", "from_city", "from_state", "from_zip", "to_name", "to_street", "to_city", "to_state", "to_zip", "items"];
61
+ var requiredParams = ["invoiceNumber","from_name","from_street","from_city","from_state","from_zip","to_name","to_street","to_city","to_state","to_zip","items"];
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/invoicegenerator`);
41
66
  }
42
67
  }
43
68
  }
@@ -58,16 +83,25 @@ class invoicegeneratorWrapper {
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
- if (error.response.data) {
65
- callback(error.response.data, null);
66
- throw error.response.data;
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
- callback(error, null);
69
- throw error;
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/invoicegenerator",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Invoice Generator is a simple tool for generating invoices. It returns a PDF of the generated invoice.",
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/invoicegenerator-API.git"
12
14
  },
13
15
  "keywords": [
14
- "invoice generator","invoice generator api","invoice generator tool","invoice generator software","invoice generator service"
16
+ "invoice generator", "invoice generator api", "invoice generator tool", "invoice generator software", "invoice generator 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/invoicegenerator-API/issues"
20
22
  },
21
- "homepage": "https://apiverve.com/marketplace/api/invoicegenerator?utm_source=npm",
23
+ "homepage": "https://apiverve.com/marketplace/invoicegenerator?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.7.9"
32
+ "axios": "1.13.2"
31
33
  }
32
34
  }