@veryfi/veryfi-sdk 1.1.2 → 1.1.5
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 +16 -11
- package/lib/main.js +80 -37
- package/package.json +6 -1
- package/types/main.d.ts +270 -0
- package/test/main.test.js +0 -90
- package/test/receipt.png +0 -0
package/README.md
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# Veryfi SDK for Node.js
|
|
2
2
|
|
|
3
|
-
[](https://
|
|
4
|
-
[](https://
|
|
3
|
+
[](https://www.npmjs.com/package/@veryfi/veryfi-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/@veryfi/veryfi-sdk)
|
|
5
5
|
[](https://github.com/psf/black)
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
- [Veryfi SDK for Node.js](#veryfi-sdk-for-nodejs)
|
|
13
12
|
- [Table of Contents](#table-of-contents)
|
|
14
13
|
- [Installation](#installation)
|
|
@@ -19,6 +18,8 @@
|
|
|
19
18
|
- [Response](#response)
|
|
20
19
|
- [Updating a document](#updating-a-document)
|
|
21
20
|
- [Need help?](#need-help)
|
|
21
|
+
- [Learn more at our blog](#learn-more-at-our-blog)
|
|
22
|
+
- [Tutorial Video](#tutorial-video)
|
|
22
23
|
|
|
23
24
|
**veryfi-nodejs** is a Node.js module for communicating with the [Veryfi OCR API](https://veryfi.com/api/)
|
|
24
25
|
|
|
@@ -40,9 +41,9 @@ If you don't have an account with Veryfi, please go ahead and register here: [ht
|
|
|
40
41
|
|
|
41
42
|
### Node.js API Client Library
|
|
42
43
|
|
|
43
|
-
The **veryfi** library can be used to communicate with Veryfi API. All available functionality is described here <https://veryfi.github.io/veryfi-nodejs/Client.html>
|
|
44
|
+
The **veryfi** library can be used to communicate with Veryfi API. All available functionality is described here: <https://veryfi.github.io/veryfi-nodejs/Client.html>
|
|
44
45
|
|
|
45
|
-
Below is
|
|
46
|
+
Below is a sample script using **Veryfi** for OCR and extracting data from a document:
|
|
46
47
|
|
|
47
48
|
### Extracting Data
|
|
48
49
|
|
|
@@ -53,8 +54,8 @@ const client_secret = 'your_client_secret';
|
|
|
53
54
|
const username = 'your_username';
|
|
54
55
|
const api_key = 'your_password';
|
|
55
56
|
|
|
56
|
-
const categories = ['Grocery', 'Utilities', 'Travel']
|
|
57
|
-
const file_path = './test/receipt.png'
|
|
57
|
+
const categories = ['Grocery', 'Utilities', 'Travel'];
|
|
58
|
+
const file_path = './test/receipt.png';
|
|
58
59
|
```
|
|
59
60
|
|
|
60
61
|
This submits a document for processing (3-5 seconds for a response)
|
|
@@ -229,9 +230,9 @@ console.log(response);
|
|
|
229
230
|
### Updating a document
|
|
230
231
|
|
|
231
232
|
```js
|
|
232
|
-
let
|
|
233
|
-
let category = "Meals & Entertainment"
|
|
234
|
-
let new_total = 11.23
|
|
233
|
+
let new_vendor = {"name": "Starbucks", "address": "123 Easy Str, San Francisco, CA 94158"};
|
|
234
|
+
let category = "Meals & Entertainment";
|
|
235
|
+
let new_total = 11.23;
|
|
235
236
|
veryfi_client.update_document(id=12345,
|
|
236
237
|
{
|
|
237
238
|
'vendor': new_vendor,
|
|
@@ -246,4 +247,8 @@ If you run into any issue or need help installing or using the library, please c
|
|
|
246
247
|
|
|
247
248
|
If you found a bug in this library or would like new features added, then open an issue or pull requests against this repo!
|
|
248
249
|
|
|
249
|
-
|
|
250
|
+
### [Learn more at our blog](https://www.veryfi.com/nodejs/)
|
|
251
|
+
|
|
252
|
+
## Tutorial Video
|
|
253
|
+
|
|
254
|
+
[](https://www.youtube.com/watch?v=PcJdgnvyfBc)
|
package/lib/main.js
CHANGED
|
@@ -28,10 +28,8 @@ function Client(
|
|
|
28
28
|
this.username = username;
|
|
29
29
|
this.api_key = api_key;
|
|
30
30
|
this.base_url = base_url;
|
|
31
|
-
this.timeout = timeout;
|
|
32
31
|
this.api_version = api_version;
|
|
33
|
-
this.
|
|
34
|
-
CATEGORIES = [
|
|
32
|
+
this.CATEGORIES = [
|
|
35
33
|
"Advertising & Marketing",
|
|
36
34
|
"Automotive",
|
|
37
35
|
"Bank Charges & Fees",
|
|
@@ -47,7 +45,7 @@ function Client(
|
|
|
47
45
|
"Utilities",
|
|
48
46
|
"Job Supplies",
|
|
49
47
|
"Grocery",
|
|
50
|
-
|
|
48
|
+
];
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
|
|
@@ -59,7 +57,7 @@ function Client(
|
|
|
59
57
|
*/
|
|
60
58
|
Client.prototype._get_headers = function (has_files=false){
|
|
61
59
|
let final_headers = {
|
|
62
|
-
"User-Agent": "
|
|
60
|
+
"User-Agent": "Node.js Veryfi-Nodejs/1.1.4",
|
|
63
61
|
"Accept": "application/json",
|
|
64
62
|
"Content-Type": "application/json",
|
|
65
63
|
"Client-Id": this.client_id,
|
|
@@ -83,12 +81,12 @@ Client.prototype._get_url = function (){
|
|
|
83
81
|
/**
|
|
84
82
|
* Generate unique signature for payload params.
|
|
85
83
|
* @private
|
|
86
|
-
* @param {
|
|
84
|
+
* @param {{}} payload_params JSON params to be sent to API request
|
|
87
85
|
* @param {Number} timestamp Unix Long timestamp
|
|
88
86
|
* @returns {string} Unique signature generated using the client_secret and the payload
|
|
89
87
|
*/
|
|
90
88
|
Client.prototype._generate_signature = function (payload_params, timestamp){
|
|
91
|
-
|
|
89
|
+
let payload = `timestamp:${timestamp}`;
|
|
92
90
|
for (let i=0; i<Object.keys(payload_params).length; i++){
|
|
93
91
|
let key = Object.keys(payload_params)[i];
|
|
94
92
|
let value = payload_params[key];
|
|
@@ -98,8 +96,8 @@ Client.prototype._generate_signature = function (payload_params, timestamp){
|
|
|
98
96
|
const payload_bytes = encodeURI(payload);
|
|
99
97
|
let hmac = createHmac('sha256', secret_bytes);
|
|
100
98
|
hmac.update(payload_bytes);
|
|
101
|
-
let tmp_signature = hmac.digest(
|
|
102
|
-
|
|
99
|
+
let tmp_signature = hmac.digest();
|
|
100
|
+
let base64_signature = Buffer.from(tmp_signature).toString('base64');
|
|
103
101
|
base64_signature = Buffer.from(base64_signature).toString('utf-8').trim();
|
|
104
102
|
|
|
105
103
|
return base64_signature;
|
|
@@ -110,41 +108,40 @@ Client.prototype._generate_signature = function (payload_params, timestamp){
|
|
|
110
108
|
* @private
|
|
111
109
|
* @param {string} http_verb HTTP Method
|
|
112
110
|
* @param {string} endpoint_name Endpoint name such as 'documents', 'users', etc.
|
|
113
|
-
* @param {
|
|
111
|
+
* @param {{}} request_arguments JSON payload to send to Veryfi
|
|
112
|
+
* @param file_stream file stream of the document
|
|
114
113
|
* @returns {JSON} A JSON of the response data.
|
|
115
114
|
*/
|
|
116
115
|
Client.prototype._request = async function (http_verb, endpoint_name, request_arguments, file_stream=null){
|
|
117
116
|
let has_files = (Boolean(file_stream));
|
|
118
|
-
let headers = this._get_headers(has_files
|
|
117
|
+
let headers = this._get_headers(has_files);
|
|
119
118
|
let api_url = `${this._get_url()}/partner${endpoint_name}`;
|
|
120
119
|
|
|
121
120
|
if (this.client_secret){
|
|
122
121
|
let timestamp = Date.now();
|
|
123
|
-
let signature = this._generate_signature(request_arguments, timestamp
|
|
122
|
+
let signature = this._generate_signature(request_arguments, timestamp);
|
|
124
123
|
headers = Object.assign(headers,{"X-Veryfi-Request-Timestamp": timestamp,
|
|
125
124
|
"X-Veryfi-Request-Signature": signature});
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
if (has_files
|
|
127
|
+
if (has_files === false) {
|
|
129
128
|
request_arguments = JSON.stringify(request_arguments);
|
|
130
129
|
} else {
|
|
131
|
-
Object.assign(headers,{...request_arguments
|
|
130
|
+
Object.assign(headers,{...request_arguments});
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
try {
|
|
135
|
-
|
|
136
|
-
method
|
|
137
|
-
url
|
|
138
|
-
headers
|
|
139
|
-
data
|
|
140
|
-
timeout
|
|
134
|
+
return await axios.request({
|
|
135
|
+
method: http_verb,
|
|
136
|
+
url: api_url,
|
|
137
|
+
headers: headers,
|
|
138
|
+
data: request_arguments,
|
|
139
|
+
timeout: this.timeout * 1000
|
|
141
140
|
});
|
|
142
|
-
return response;
|
|
143
141
|
} catch (response) {
|
|
144
|
-
console.log(response);
|
|
145
142
|
let Err = new VeryfiClientError(response,response['response']['data']);
|
|
146
143
|
let err_msg = Err.from_response(response['response']);
|
|
147
|
-
throw new Error(err_msg['status']
|
|
144
|
+
throw new Error(err_msg['status'] + err_msg['error']);
|
|
148
145
|
}
|
|
149
146
|
}
|
|
150
147
|
|
|
@@ -167,7 +164,7 @@ Client.prototype.get_documents = async function (){
|
|
|
167
164
|
/**
|
|
168
165
|
* Retrieve document by ID
|
|
169
166
|
* @memberof Client
|
|
170
|
-
* @param {
|
|
167
|
+
* @param {string} document_id ID of the document you'd like to retrieve
|
|
171
168
|
* @returns {JSON} Data extracted from the Document
|
|
172
169
|
*/
|
|
173
170
|
Client.prototype.get_document = async function (document_id) {
|
|
@@ -201,17 +198,57 @@ Client.prototype.process_document = async function (
|
|
|
201
198
|
|
|
202
199
|
let endpoint_name = "/documents/";
|
|
203
200
|
if (!categories){
|
|
204
|
-
categories = CATEGORIES;
|
|
201
|
+
categories = this.CATEGORIES;
|
|
205
202
|
}
|
|
206
203
|
let file_name = path.basename(file_path)
|
|
207
204
|
const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
|
|
206
|
+
let request_arguments = {
|
|
210
207
|
"file_name": file_name,
|
|
211
208
|
"file_data": base64_encoded_string,
|
|
212
209
|
"categories": categories,
|
|
213
210
|
"auto_delete": delete_after_processing,
|
|
211
|
+
};
|
|
212
|
+
request_arguments = Object.assign(request_arguments,kwargs)
|
|
213
|
+
let document = await this._request("POST", endpoint_name, request_arguments)
|
|
214
|
+
return document['data'];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Process a document and extract all the fields from it
|
|
219
|
+
* @example
|
|
220
|
+
* veryfi_client.process_document_buffer('base64_encoded_string',
|
|
221
|
+
* 'receipt.png',
|
|
222
|
+
* ['Entertainment','Food'],
|
|
223
|
+
* true,
|
|
224
|
+
* {'extra': 'parameters'})
|
|
225
|
+
*
|
|
226
|
+
* @memberof Client
|
|
227
|
+
* @param {String} base64_encoded_string Buffer of a file to submit for data extraction
|
|
228
|
+
* @param {String} file_name The file name including the extension
|
|
229
|
+
* @param {Array} categories List of categories Veryfi can use to categorize the document
|
|
230
|
+
* @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
|
|
231
|
+
* @param {Object} kwargs Additional request parameters
|
|
232
|
+
* @returns {JSON} Data extracted from the document
|
|
233
|
+
*/
|
|
234
|
+
Client.prototype.process_document_buffer = async function (
|
|
235
|
+
base64_encoded_string,
|
|
236
|
+
file_name,
|
|
237
|
+
categories = null,
|
|
238
|
+
delete_after_processing = false,
|
|
239
|
+
{...kwargs} = {}
|
|
240
|
+
) {
|
|
241
|
+
|
|
242
|
+
let endpoint_name = "/documents/";
|
|
243
|
+
if (!categories){
|
|
244
|
+
categories = this.CATEGORIES;
|
|
214
245
|
}
|
|
246
|
+
let request_arguments = {
|
|
247
|
+
"file_name": file_name,
|
|
248
|
+
"file_data": base64_encoded_string,
|
|
249
|
+
"categories": categories,
|
|
250
|
+
"auto_delete": delete_after_processing,
|
|
251
|
+
};
|
|
215
252
|
request_arguments = Object.assign(request_arguments,kwargs)
|
|
216
253
|
let document = await this._request("POST", endpoint_name, request_arguments)
|
|
217
254
|
return document['data'];
|
|
@@ -219,6 +256,9 @@ Client.prototype.process_document = async function (
|
|
|
219
256
|
|
|
220
257
|
/**
|
|
221
258
|
* Process document from url and extract all the fields from it.
|
|
259
|
+
* @example
|
|
260
|
+
* veryfi_client.process_document_url('https://cdn.example.com/receipt.jpg')
|
|
261
|
+
*
|
|
222
262
|
* @memberof Client
|
|
223
263
|
* @param {string} file_url Required if file_urls isn't specified. Publicly accessible URL to a file, e.g. "https://cdn.example.com/receipt.jpg".
|
|
224
264
|
* @param {Array} file_urls Required if file_url isn't specified. List of publicly accessible URLs to multiple files, e.g. ["https://cdn.example.com/receipt1.jpg", "https://cdn.example.com/receipt2.jpg"]
|
|
@@ -231,17 +271,20 @@ Client.prototype.process_document = async function (
|
|
|
231
271
|
* @return {JSON} Data extracted from the document.
|
|
232
272
|
*/
|
|
233
273
|
Client.prototype.process_document_url = async function (
|
|
234
|
-
file_url =
|
|
274
|
+
file_url = "",
|
|
275
|
+
file_urls = null,
|
|
235
276
|
categories = null,
|
|
236
277
|
delete_after_processing = false,
|
|
237
278
|
boost_mode = 0,
|
|
238
|
-
external_id =
|
|
239
|
-
max_pages_to_process =
|
|
240
|
-
file_urls = null,
|
|
279
|
+
external_id = "",
|
|
280
|
+
max_pages_to_process = 1,
|
|
241
281
|
{...kwargs} = {},
|
|
242
282
|
) {
|
|
243
283
|
let endpoint_name = "/documents/";
|
|
244
|
-
|
|
284
|
+
if (!categories){
|
|
285
|
+
categories = this.CATEGORIES;
|
|
286
|
+
}
|
|
287
|
+
let request_arguments = {
|
|
245
288
|
"auto_delete": delete_after_processing,
|
|
246
289
|
"boost_mode": boost_mode,
|
|
247
290
|
"categories": categories,
|
|
@@ -259,13 +302,13 @@ Client.prototype.process_document_url = async function (
|
|
|
259
302
|
* Delete document from Veryfi
|
|
260
303
|
*
|
|
261
304
|
* @memberof Client
|
|
262
|
-
* @param {
|
|
305
|
+
* @param {string} document_id ID of the document you'd like to delete
|
|
263
306
|
*/
|
|
264
307
|
Client.prototype.delete_document = async function (document_id){
|
|
265
|
-
|
|
266
308
|
let endpoint_name = `/documents/${document_id}/`;
|
|
267
309
|
let request_arguments = {"id": document_id};
|
|
268
|
-
await this._request("DELETE", endpoint_name, request_arguments);
|
|
310
|
+
let response = await this._request("DELETE", endpoint_name, request_arguments);
|
|
311
|
+
return response;
|
|
269
312
|
}
|
|
270
313
|
|
|
271
314
|
/**
|
|
@@ -274,7 +317,7 @@ Client.prototype.delete_document = async function (document_id){
|
|
|
274
317
|
* veryfi_client.update_document(id, {date:"2021-01-01", notes:"look what I did"})
|
|
275
318
|
*
|
|
276
319
|
* @memberof Client
|
|
277
|
-
* @param {
|
|
320
|
+
* @param {string} document_id ID of the document you'd like to update
|
|
278
321
|
* @param {Object} kwargs fields to update
|
|
279
322
|
* @return {JSON} A document json with updated fields, if fields are writable. Otherwise a document with unchanged fields.
|
|
280
323
|
*/
|
|
@@ -286,4 +329,4 @@ Client.prototype.update_document = async function (document_id, {...kwargs} = {}
|
|
|
286
329
|
|
|
287
330
|
// Exports
|
|
288
331
|
|
|
289
|
-
module.exports = Client;
|
|
332
|
+
module.exports = Client;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfi/veryfi-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Node.js module for communicating with the Veryfi OCR API",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
|
+
"typings": "types/main.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "jest",
|
|
8
9
|
"doc": "jsdoc -d docs --configure jsconf.json main.js",
|
|
@@ -14,6 +15,10 @@
|
|
|
14
15
|
"Matthew Eng <matthew@veryfi.com>"
|
|
15
16
|
],
|
|
16
17
|
"license": "MIT",
|
|
18
|
+
"files": [
|
|
19
|
+
"lib",
|
|
20
|
+
"types"
|
|
21
|
+
],
|
|
17
22
|
"directories": {
|
|
18
23
|
"lib": "lib",
|
|
19
24
|
"test": "test"
|
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Additional request parameters type
|
|
3
|
+
*/
|
|
4
|
+
export declare type VeryfiExtraArgs = Record<
|
|
5
|
+
string | number | symbol,
|
|
6
|
+
string | number | boolean
|
|
7
|
+
>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Object of data extracted from the document
|
|
11
|
+
*/
|
|
12
|
+
export declare type VeryfiDocument = {
|
|
13
|
+
abn_number?: null | string;
|
|
14
|
+
account_number?: null | string;
|
|
15
|
+
bill_to_address?: null | string;
|
|
16
|
+
bill_to_name?: null | string;
|
|
17
|
+
bill_to_vat_number?: null | string;
|
|
18
|
+
card_number?: null | string;
|
|
19
|
+
cashback?: null | number;
|
|
20
|
+
category?: null | string;
|
|
21
|
+
created?: null | string;
|
|
22
|
+
currency_code?: null | string;
|
|
23
|
+
date?: null | string;
|
|
24
|
+
delivery_date?: null | string;
|
|
25
|
+
discount?: null | number;
|
|
26
|
+
document_reference_number?: null | string;
|
|
27
|
+
document_title?: null | string;
|
|
28
|
+
document_type?: null | string;
|
|
29
|
+
due_date?: null | string;
|
|
30
|
+
duplicate_of?: null | number;
|
|
31
|
+
external_id?: null | string;
|
|
32
|
+
id?: null | number;
|
|
33
|
+
img_file_name?: null | string;
|
|
34
|
+
img_thumbnail_url?: null | string;
|
|
35
|
+
img_url?: null | string;
|
|
36
|
+
insurance?: null | number;
|
|
37
|
+
invoice_number?: null | string;
|
|
38
|
+
is_duplicate?: null | number;
|
|
39
|
+
line_items?: null | LineItem[];
|
|
40
|
+
notes?: null | string;
|
|
41
|
+
ocr_text?: null | string;
|
|
42
|
+
order_date?: null | string;
|
|
43
|
+
payment_display_name?: null | string;
|
|
44
|
+
payment_terms?: null | string;
|
|
45
|
+
payment_type?: null | string;
|
|
46
|
+
phone_number?: null | string;
|
|
47
|
+
purchase_order_number?: null | string;
|
|
48
|
+
rounding?: null | number;
|
|
49
|
+
service_end_date?: null | string;
|
|
50
|
+
service_start_date?: null | string;
|
|
51
|
+
ship_date?: null | string;
|
|
52
|
+
ship_to_address?: null | string;
|
|
53
|
+
ship_to_name?: null | string;
|
|
54
|
+
shipping?: null | number;
|
|
55
|
+
store_number?: null | string;
|
|
56
|
+
subtotal?: null | number;
|
|
57
|
+
tax?: null | number;
|
|
58
|
+
tax_lines?: null | TaxLine[];
|
|
59
|
+
tip?: null | number;
|
|
60
|
+
total?: null | number;
|
|
61
|
+
total_weight?: null | string;
|
|
62
|
+
tracking_number?: null | string;
|
|
63
|
+
updated?: null | string;
|
|
64
|
+
vat_number?: null | string;
|
|
65
|
+
vendor?: null | Vendor;
|
|
66
|
+
vendor_account_number?: null | string;
|
|
67
|
+
vendor_bank_name?: null | string;
|
|
68
|
+
vendor_bank_number?: null | string;
|
|
69
|
+
vendor_bank_swift?: null | string;
|
|
70
|
+
vendor_iban?: null | string;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
declare type LineItem = {
|
|
74
|
+
date?: null | string;
|
|
75
|
+
description?: null | string;
|
|
76
|
+
discount?: null | number;
|
|
77
|
+
end_date?: null | string;
|
|
78
|
+
hsn?: null | string;
|
|
79
|
+
id?: null | number;
|
|
80
|
+
order?: null | number;
|
|
81
|
+
price?: null | number;
|
|
82
|
+
quantity?: null | number;
|
|
83
|
+
reference?: null | string;
|
|
84
|
+
section?: null | string;
|
|
85
|
+
sku?: null | string;
|
|
86
|
+
start_date?: null | string;
|
|
87
|
+
tags?: null | null[];
|
|
88
|
+
tax?: null | number;
|
|
89
|
+
tax_rate?: null | number;
|
|
90
|
+
total?: null | number;
|
|
91
|
+
type?: null | string;
|
|
92
|
+
unit_of_measure?: null | string;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
declare type TaxLine = {
|
|
96
|
+
base?: null | number;
|
|
97
|
+
name?: null | string;
|
|
98
|
+
order?: null | number;
|
|
99
|
+
rate?: null | number;
|
|
100
|
+
total?: null | number;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
declare type Vendor = {
|
|
104
|
+
address?: null | string;
|
|
105
|
+
category?: null | string;
|
|
106
|
+
email?: null | string;
|
|
107
|
+
fax_number?: null | string;
|
|
108
|
+
name?: null | string;
|
|
109
|
+
phone_number?: null | string;
|
|
110
|
+
raw_name?: null | string;
|
|
111
|
+
vendor_logo?: null | string;
|
|
112
|
+
vendor_reg_number?: null | string;
|
|
113
|
+
vendor_type?: null | string;
|
|
114
|
+
web?: null | string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export declare class Client {
|
|
118
|
+
/**
|
|
119
|
+
* Create instance of a Client
|
|
120
|
+
* @class
|
|
121
|
+
* @param {string} client_id Your Veryfi client id
|
|
122
|
+
* @param {string} client_secret Your Veryfi client secret
|
|
123
|
+
* @param {string} username Your Veryfi username
|
|
124
|
+
* @param {string} api_key Your Veryfi API key
|
|
125
|
+
* @param {string} base_url
|
|
126
|
+
* @param {string} api_version
|
|
127
|
+
* @param {number} timeout
|
|
128
|
+
*/
|
|
129
|
+
constructor(
|
|
130
|
+
client_id: string,
|
|
131
|
+
client_secret: string,
|
|
132
|
+
username: string,
|
|
133
|
+
api_key: string,
|
|
134
|
+
base_url?: string,
|
|
135
|
+
api_version?: string,
|
|
136
|
+
timeout?: number
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
client_id: string;
|
|
140
|
+
|
|
141
|
+
client_secret: string;
|
|
142
|
+
|
|
143
|
+
username: string;
|
|
144
|
+
|
|
145
|
+
api_key: string;
|
|
146
|
+
|
|
147
|
+
base_url: string;
|
|
148
|
+
|
|
149
|
+
api_version: string;
|
|
150
|
+
|
|
151
|
+
CATEGORIES: string[];
|
|
152
|
+
|
|
153
|
+
private _get_headers;
|
|
154
|
+
|
|
155
|
+
private _get_url;
|
|
156
|
+
|
|
157
|
+
private _generate_signature;
|
|
158
|
+
|
|
159
|
+
private _request;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get all documents
|
|
163
|
+
* @memberof Client
|
|
164
|
+
* @returns {Promise<VeryfiDocument>} Object of previously processed documents
|
|
165
|
+
*/
|
|
166
|
+
public get_documents(): Promise<VeryfiDocument[]>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Retrieve document by ID
|
|
170
|
+
* @memberof Client
|
|
171
|
+
* @param {string} document_id ID of the document you'd like to retrieve
|
|
172
|
+
* @returns {Promise<VeryfiDocument>} Object of data extracted from the document
|
|
173
|
+
*/
|
|
174
|
+
public get_document(document_id: string): Promise<VeryfiDocument>;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Process a document and extract all the fields from it
|
|
178
|
+
* @example
|
|
179
|
+
* veryfi_client.process_document(
|
|
180
|
+
* 'file/path',
|
|
181
|
+
* ['Entertainment', 'Food'],
|
|
182
|
+
* true,
|
|
183
|
+
* { extra: 'parameters' }
|
|
184
|
+
* )
|
|
185
|
+
* @memberof Client
|
|
186
|
+
* @param {string} file_path Path on disk to a file to submit for data extraction
|
|
187
|
+
* @param {string[]} categories List of categories Veryfi can use to categorize the document
|
|
188
|
+
* @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
|
|
189
|
+
* @param {VeryfiExtraArgs} kwargs Additional request parameters
|
|
190
|
+
* @returns {Promise<VeryfiDocument>} Object of data extracted from the document
|
|
191
|
+
*/
|
|
192
|
+
public process_document(
|
|
193
|
+
file_path: string,
|
|
194
|
+
categories?: string[],
|
|
195
|
+
delete_after_processing?: boolean,
|
|
196
|
+
{ ...kwargs }?: VeryfiExtraArgs
|
|
197
|
+
): Promise<VeryfiDocument>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Process document from url and extract all the fields from it.
|
|
201
|
+
* @memberof Client
|
|
202
|
+
* @param {string} file_url Required if file_urls isn't specified. Publicly accessible URL to a file, e.g. 'https://cdn.example.com/receipt.jpg'.
|
|
203
|
+
* @param {string[]} file_urls Required if file_url isn't specified. List of publicly accessible URLs to multiple files, e.g. ['https://cdn.example.com/receipt1.jpg', 'https://cdn.example.com/receipt2.jpg']
|
|
204
|
+
* @param {string[]} categories List of categories to use when categorizing the document
|
|
205
|
+
* @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
|
|
206
|
+
* @param {number} max_pages_to_process When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1.
|
|
207
|
+
* @param {number} boost_mode Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0
|
|
208
|
+
* @param {string} external_id Optional custom document identifier. Use this if you would like to assign your own ID to documents
|
|
209
|
+
* @param {VeryfiExtraArgs} kwargs Additional request parameters
|
|
210
|
+
* @return {Promise<VeryfiDocument>} Object of data extracted from the document
|
|
211
|
+
*/
|
|
212
|
+
public process_document_url(
|
|
213
|
+
file_url?: string,
|
|
214
|
+
categories?: string[],
|
|
215
|
+
delete_after_processing?: boolean,
|
|
216
|
+
boost_mode?: number,
|
|
217
|
+
external_id?: string,
|
|
218
|
+
max_pages_to_process?: number,
|
|
219
|
+
file_urls?: string[],
|
|
220
|
+
{ ...kwargs }?: VeryfiExtraArgs
|
|
221
|
+
): Promise<VeryfiDocument>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Delete document from Veryfi
|
|
225
|
+
* @memberof Client
|
|
226
|
+
* @param {string} document_id ID of the document you'd like to delete
|
|
227
|
+
* @returns {Promise<VeryfiDocument>} Object of data extracted from the document
|
|
228
|
+
*/
|
|
229
|
+
public delete_document(document_id: string): Promise<VeryfiDocument>;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` and etc.
|
|
233
|
+
* @example
|
|
234
|
+
* veryfi_client.update_document(
|
|
235
|
+
* id,
|
|
236
|
+
* { date: '2021-01-01', notes: 'look what I did' }
|
|
237
|
+
* )
|
|
238
|
+
* @memberof Client
|
|
239
|
+
* @param {string} document_id ID of the document you'd like to update
|
|
240
|
+
* @param {VeryfiExtraArgs} kwargs fields to update
|
|
241
|
+
* @return {Promise<VeryfiDocument>} Object of data extracted from the document with updated fields, if fields are writable. Otherwise, a document with unchanged fields.
|
|
242
|
+
*/
|
|
243
|
+
public update_document(
|
|
244
|
+
document_id: string,
|
|
245
|
+
{ ...kwargs }?: VeryfiExtraArgs
|
|
246
|
+
): Promise<VeryfiDocument>;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Create instance of a Client
|
|
251
|
+
* @class
|
|
252
|
+
* @param {string} client_id Your Veryfi client id
|
|
253
|
+
* @param {string} client_secret Your Veryfi client secret
|
|
254
|
+
* @param {string} username Your Veryfi username
|
|
255
|
+
* @param {string} api_key Your Veryfi API key
|
|
256
|
+
* @param {string} base_url
|
|
257
|
+
* @param {string} api_version
|
|
258
|
+
* @param {number} timeout
|
|
259
|
+
*/
|
|
260
|
+
export declare function Client(
|
|
261
|
+
client_id: string,
|
|
262
|
+
client_secret: string,
|
|
263
|
+
username: string,
|
|
264
|
+
api_key: string,
|
|
265
|
+
base_url?: string,
|
|
266
|
+
api_version?: string,
|
|
267
|
+
timeout?: number
|
|
268
|
+
): Client;
|
|
269
|
+
|
|
270
|
+
export default Client;
|
package/test/main.test.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test main functions and input parameters
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const Client = require('../lib/main');
|
|
6
|
-
const client_id = 'YOUR_ID';
|
|
7
|
-
const client_secret = 'YOUR_SECRET';
|
|
8
|
-
const username = 'YOUR_USERNAME';
|
|
9
|
-
const api_key = 'YOUR_API_KEY';
|
|
10
|
-
|
|
11
|
-
const doc_id = 'ID_TO_MODIFY';
|
|
12
|
-
const delete_id = 'ID_TO_DELETE';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//Creating the Client
|
|
16
|
-
let veryfi_client = new Client(client_id, client_secret, username, api_key);
|
|
17
|
-
|
|
18
|
-
describe('Processing documents', () => {
|
|
19
|
-
jest.setTimeout(10000)
|
|
20
|
-
test('Upload invoice for processing', async () => {
|
|
21
|
-
try {
|
|
22
|
-
const request = await veryfi_client.process_document('test/receipt.png');
|
|
23
|
-
expect(request['vendor']['name']).toBe('The Home Depot');
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.log(error);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('Process document from URL', async () => {
|
|
30
|
-
try {
|
|
31
|
-
const request = await veryfi_client.process_document_url('https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2.pdf');
|
|
32
|
-
expect(request['vendor']['name']).toBe('Rumpke');
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.log(error);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('Managing documents', () => {
|
|
40
|
-
test('Get documents', async () => {
|
|
41
|
-
try {
|
|
42
|
-
const docs = await veryfi_client.get_documents();
|
|
43
|
-
expect(docs.length).toBeGreaterThan(0);
|
|
44
|
-
|
|
45
|
-
expect(docs).toEqual(
|
|
46
|
-
expect.arrayContaining([
|
|
47
|
-
expect.objectContaining({
|
|
48
|
-
'id': expect.any(Number),
|
|
49
|
-
'category': expect.any(String)
|
|
50
|
-
})
|
|
51
|
-
])
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.log(error);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test(`Get document with id ${doc_id}`, async () => {
|
|
60
|
-
try {
|
|
61
|
-
const doc = await veryfi_client.get_document(doc_id);
|
|
62
|
-
expect(doc['id']).toBe(doc_id)
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.log(error);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('Editing Documents', () => {
|
|
70
|
-
test('Update a document\'s entries', async () => {
|
|
71
|
-
let params = {'category':'Education'};
|
|
72
|
-
const new_doc = await veryfi_client.update_document(doc_id,params);
|
|
73
|
-
expect(new_doc).toEqual(expect.objectContaining(params));
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('Delete a document by id', async () => {
|
|
77
|
-
const docs_prev = await veryfi_client.get_documents();
|
|
78
|
-
await veryfi_client.delete_document(delete_id);
|
|
79
|
-
const docs_new = await veryfi_client.get_documents();
|
|
80
|
-
expect(docs_new).toEqual(
|
|
81
|
-
expect.arrayContaining([
|
|
82
|
-
expect.not.objectContaining({
|
|
83
|
-
'id':`${delete_id}`
|
|
84
|
-
})
|
|
85
|
-
])
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
expect(docs_prev.length).toBeGreaterThan(docs_new.length);
|
|
89
|
-
});
|
|
90
|
-
})
|
package/test/receipt.png
DELETED
|
Binary file
|