@veryfi/veryfi-sdk 1.2.2 → 1.2.3
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 +13 -7
- package/lib/main.js +55 -28
- package/lib/types/main.d.ts +30 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# Veryfi SDK for Node.js
|
|
2
2
|
|
|
3
|
+
<img src="https://user-images.githubusercontent.com/30125790/212157461-58bdc714-2f89-44c2-8e4d-d42bee74854e.png#gh-dark-mode-only" width="200">
|
|
4
|
+
<img src="https://user-images.githubusercontent.com/30125790/212157486-bfd08c5d-9337-4b78-be6f-230dc63838ba.png#gh-light-mode-only" width="200">
|
|
5
|
+
|
|
3
6
|
[](https://www.npmjs.com/package/@veryfi/veryfi-sdk)
|
|
4
7
|
[](https://www.npmjs.com/package/@veryfi/veryfi-sdk)
|
|
5
8
|
[](https://github.com/psf/black)
|
|
6
9
|
|
|
7
|
-

|
|
8
|
-
|
|
9
10
|
## Table of Contents
|
|
10
11
|
|
|
11
12
|
- [Veryfi SDK for Node.js](#veryfi-sdk-for-nodejs)
|
|
@@ -62,15 +63,17 @@ This submits a document for processing (3-5 seconds for a response)
|
|
|
62
63
|
|
|
63
64
|
```js
|
|
64
65
|
let veryfi_client = new Client(client_id, client_secret, username, api_key);
|
|
65
|
-
let response = veryfi_client.process_document(file_path, categories=categories)
|
|
66
|
-
console.log(response)
|
|
66
|
+
let response = veryfi_client.process_document(file_path, categories=categories).then(response => {
|
|
67
|
+
console.log(response)
|
|
68
|
+
});
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
...or with a URL
|
|
70
72
|
|
|
71
73
|
```js
|
|
72
|
-
let response = veryfi_client.process_document_url(url, external_id=some_id)
|
|
73
|
-
console.log(response)
|
|
74
|
+
let response = veryfi_client.process_document_url(url, external_id=some_id).then(response => {
|
|
75
|
+
console.log(response)
|
|
76
|
+
});
|
|
74
77
|
```
|
|
75
78
|
|
|
76
79
|
### Response
|
|
@@ -238,7 +241,10 @@ veryfi_client.update_document(id=12345,
|
|
|
238
241
|
'vendor': new_vendor,
|
|
239
242
|
'category': new_category,
|
|
240
243
|
'total': new_total
|
|
241
|
-
})
|
|
244
|
+
})
|
|
245
|
+
.then(response => {
|
|
246
|
+
console.log(response)
|
|
247
|
+
});
|
|
242
248
|
```
|
|
243
249
|
|
|
244
250
|
## Need help?
|
package/lib/main.js
CHANGED
|
@@ -7,7 +7,7 @@ const fs = require('fs');
|
|
|
7
7
|
* Create instance of a Client
|
|
8
8
|
* @class
|
|
9
9
|
* @param {string} client_id Your Veryfi client id
|
|
10
|
-
* @param {string} client_secret Your Veryfi client secret
|
|
10
|
+
* @param {string | undefined} client_secret Your Veryfi client secret
|
|
11
11
|
* @param {string} username Your Veryfi username
|
|
12
12
|
* @param {string} api_key Your Veryfi API key
|
|
13
13
|
* @param {string} base_url
|
|
@@ -50,7 +50,7 @@ function Client(
|
|
|
50
50
|
/**
|
|
51
51
|
* Check api version for w2 documents
|
|
52
52
|
* @private
|
|
53
|
-
* @throws
|
|
53
|
+
* @throws error when api_version is different to v8
|
|
54
54
|
*/
|
|
55
55
|
Client.prototype._check_w2_version = function () {
|
|
56
56
|
if (this.api_version !== "v8") throw Error("w2 is only supported on v8")
|
|
@@ -64,7 +64,7 @@ Client.prototype._check_w2_version = function () {
|
|
|
64
64
|
*/
|
|
65
65
|
Client.prototype._get_headers = function (has_files = false) {
|
|
66
66
|
let final_headers = {
|
|
67
|
-
"User-Agent": "Node.js Veryfi-Nodejs/1.2.
|
|
67
|
+
"User-Agent": "Node.js Veryfi-Nodejs/1.2.3",
|
|
68
68
|
"Accept": "application/json",
|
|
69
69
|
"Content-Type": "application/json",
|
|
70
70
|
"Client-Id": this.client_id,
|
|
@@ -211,7 +211,7 @@ Client.prototype.process_document = async function (
|
|
|
211
211
|
if (!categories) {
|
|
212
212
|
categories = this.CATEGORIES;
|
|
213
213
|
}
|
|
214
|
-
let file_name = path.basename(file_path)
|
|
214
|
+
let file_name = path.basename(file_path);
|
|
215
215
|
const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
|
|
216
216
|
const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
|
|
217
217
|
let request_arguments = {
|
|
@@ -220,8 +220,8 @@ Client.prototype.process_document = async function (
|
|
|
220
220
|
"categories": categories,
|
|
221
221
|
"auto_delete": delete_after_processing,
|
|
222
222
|
};
|
|
223
|
-
request_arguments = Object.assign(request_arguments, kwargs)
|
|
224
|
-
let document = await this._request("POST", endpoint_name, request_arguments)
|
|
223
|
+
request_arguments = Object.assign(request_arguments, kwargs);
|
|
224
|
+
let document = await this._request("POST", endpoint_name, request_arguments);
|
|
225
225
|
return document['data'];
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -260,8 +260,8 @@ Client.prototype.process_document_buffer = async function (
|
|
|
260
260
|
"categories": categories,
|
|
261
261
|
"auto_delete": delete_after_processing,
|
|
262
262
|
};
|
|
263
|
-
request_arguments = Object.assign(request_arguments, kwargs)
|
|
264
|
-
let document = await this._request("POST", endpoint_name, request_arguments)
|
|
263
|
+
request_arguments = Object.assign(request_arguments, kwargs);
|
|
264
|
+
let document = await this._request("POST", endpoint_name, request_arguments);
|
|
265
265
|
return document['data'];
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -304,7 +304,7 @@ Client.prototype.process_document_url = async function (
|
|
|
304
304
|
"file_urls": file_urls,
|
|
305
305
|
"max_pages_to_process": max_pages_to_process,
|
|
306
306
|
};
|
|
307
|
-
request_arguments = Object.assign(request_arguments, kwargs)
|
|
307
|
+
request_arguments = Object.assign(request_arguments, kwargs);
|
|
308
308
|
let response = await this._request("POST", endpoint_name, request_arguments);
|
|
309
309
|
return response['data'];
|
|
310
310
|
}
|
|
@@ -344,15 +344,15 @@ Client.prototype.update_document = async function (document_id, {...kwargs} = {}
|
|
|
344
344
|
* @return {Array} An array of JSON with all w2 documents.
|
|
345
345
|
*/
|
|
346
346
|
Client.prototype.get_w2_documents = async function (page = null) {
|
|
347
|
-
this._check_w2_version()
|
|
348
|
-
let endpoint_name = "/w2s/"
|
|
349
|
-
let request_arguments = {}
|
|
350
|
-
let params = {}
|
|
347
|
+
this._check_w2_version();
|
|
348
|
+
let endpoint_name = "/w2s/";
|
|
349
|
+
let request_arguments = {};
|
|
350
|
+
let params = {};
|
|
351
351
|
if (page !== null) {
|
|
352
|
-
params = {"page": page}
|
|
352
|
+
params = {"page": page};
|
|
353
353
|
}
|
|
354
|
-
let response = await this._request("GET", endpoint_name, request_arguments, params)
|
|
355
|
-
return response['data']['results']
|
|
354
|
+
let response = await this._request("GET", endpoint_name, request_arguments, params);
|
|
355
|
+
return response['data']['results'];
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
@@ -364,11 +364,11 @@ Client.prototype.get_w2_documents = async function (page = null) {
|
|
|
364
364
|
Client.prototype.get_w2_document = async function (
|
|
365
365
|
document_id,
|
|
366
366
|
) {
|
|
367
|
-
this._check_w2_version()
|
|
368
|
-
let endpoint_name = `/w2s/${document_id}
|
|
369
|
-
let request_arguments = {"id": document_id}
|
|
370
|
-
let response = await this._request("GET", endpoint_name, request_arguments)
|
|
371
|
-
return response['data']
|
|
367
|
+
this._check_w2_version();
|
|
368
|
+
let endpoint_name = `/w2s/${document_id}/`;
|
|
369
|
+
let request_arguments = {"id": document_id};
|
|
370
|
+
let response = await this._request("GET", endpoint_name, request_arguments);
|
|
371
|
+
return response['data'];
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
/**
|
|
@@ -396,9 +396,9 @@ Client.prototype.process_w2_document_from_buffer = async function (
|
|
|
396
396
|
"auto_delete": delete_after_processing,
|
|
397
397
|
"max_pages_to_process": max_pages_to_process,
|
|
398
398
|
}
|
|
399
|
-
request_arguments = Object.assign(request_arguments, kwargs)
|
|
400
|
-
let response = await this._request("POST", endpoint_name, request_arguments)
|
|
401
|
-
return response['data']
|
|
399
|
+
request_arguments = Object.assign(request_arguments, kwargs);
|
|
400
|
+
let response = await this._request("POST", endpoint_name, request_arguments);
|
|
401
|
+
return response['data'];
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
/**
|
|
@@ -424,7 +424,7 @@ Client.prototype.process_w2_document = async function (
|
|
|
424
424
|
delete_after_processing,
|
|
425
425
|
max_pages_to_process,
|
|
426
426
|
kwargs
|
|
427
|
-
)
|
|
427
|
+
);
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
/**
|
|
@@ -456,11 +456,38 @@ Client.prototype.process_w2_document_from_url = async function (
|
|
|
456
456
|
"file_urls": file_urls,
|
|
457
457
|
"max_pages_to_process": max_pages_to_process
|
|
458
458
|
}
|
|
459
|
-
request_arguments = Object.assign(request_arguments, kwargs)
|
|
460
|
-
let response = await this._request("POST", endpoint_name, request_arguments)
|
|
461
|
-
return response['data']
|
|
459
|
+
request_arguments = Object.assign(request_arguments, kwargs);
|
|
460
|
+
let response = await this._request("POST", endpoint_name, request_arguments);
|
|
461
|
+
return response['data'];
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Add a new tag on an existing document
|
|
466
|
+
*
|
|
467
|
+
* @param {number} document_id ID of the document you'd like to add a Tag
|
|
468
|
+
* @param {string} tag name to add
|
|
469
|
+
* @return {JSON} response about tag added.
|
|
470
|
+
*/
|
|
471
|
+
Client.prototype.add_tag = async function (document_id, tag) {
|
|
472
|
+
let endpoint_name = `/documents/${document_id}/tags/`;
|
|
473
|
+
let request_arguments = {"name": tag};
|
|
474
|
+
let response = await this._request("PUT", endpoint_name, request_arguments);
|
|
475
|
+
return response['data'];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Delete all the tags on an existing document
|
|
480
|
+
*
|
|
481
|
+
* @param {number} document_id ID of the document you'd like to delete tags
|
|
482
|
+
* @return {JSON} response about deleted tags.
|
|
483
|
+
*/
|
|
484
|
+
Client.prototype.delete_tags = async function (document_id) {
|
|
485
|
+
let endpoint_name = `/documents/${document_id}/tags/`;
|
|
486
|
+
let request_arguments = {};
|
|
487
|
+
return this._request("DELETE", endpoint_name, request_arguments);
|
|
462
488
|
}
|
|
463
489
|
|
|
490
|
+
|
|
464
491
|
// Exports
|
|
465
492
|
|
|
466
493
|
module.exports = Client;
|
package/lib/types/main.d.ts
CHANGED
|
@@ -122,12 +122,17 @@ declare type Payment = {
|
|
|
122
122
|
type?: null | string;
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
declare type Tag = {
|
|
126
|
+
id?: null | number;
|
|
127
|
+
name?: null | string;
|
|
128
|
+
};
|
|
129
|
+
|
|
125
130
|
export declare class Client {
|
|
126
131
|
/**
|
|
127
132
|
* Create instance of a Client
|
|
128
133
|
* @class
|
|
129
134
|
* @param {string} client_id Your Veryfi client id
|
|
130
|
-
* @param {string} client_secret Your Veryfi client secret
|
|
135
|
+
* @param {string | undefined} client_secret Your Veryfi client secret
|
|
131
136
|
* @param {string} username Your Veryfi username
|
|
132
137
|
* @param {string} api_key Your Veryfi API key
|
|
133
138
|
* @param {string} base_url
|
|
@@ -136,7 +141,7 @@ export declare class Client {
|
|
|
136
141
|
*/
|
|
137
142
|
constructor(
|
|
138
143
|
client_id: string,
|
|
139
|
-
client_secret: string,
|
|
144
|
+
client_secret: string | undefined,
|
|
140
145
|
username: string,
|
|
141
146
|
api_key: string,
|
|
142
147
|
base_url?: string,
|
|
@@ -146,7 +151,7 @@ export declare class Client {
|
|
|
146
151
|
|
|
147
152
|
client_id: string;
|
|
148
153
|
|
|
149
|
-
client_secret: string;
|
|
154
|
+
client_secret: string | undefined;
|
|
150
155
|
|
|
151
156
|
username: string;
|
|
152
157
|
|
|
@@ -234,10 +239,10 @@ export declare class Client {
|
|
|
234
239
|
* @param {string} document_id ID of the document you'd like to delete
|
|
235
240
|
* @returns {Promise<VeryfiDocument>} Object of data extracted from the document
|
|
236
241
|
*/
|
|
237
|
-
public delete_document(document_id: string): Promise<
|
|
242
|
+
public delete_document(document_id: string): Promise<any>;
|
|
238
243
|
|
|
239
244
|
/**
|
|
240
|
-
* Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes`
|
|
245
|
+
* Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` etc.
|
|
241
246
|
* @example
|
|
242
247
|
* veryfi_client.update_document(
|
|
243
248
|
* id,
|
|
@@ -252,13 +257,31 @@ export declare class Client {
|
|
|
252
257
|
document_id: string,
|
|
253
258
|
{ ...kwargs }?: VeryfiExtraArgs
|
|
254
259
|
): Promise<VeryfiDocument>;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Add a new tag on an existing document
|
|
263
|
+
*
|
|
264
|
+
* @param {number} document_id ID of the document you'd like to add a Tag
|
|
265
|
+
* @param {string} tag name to add
|
|
266
|
+
* @return {Promise<Tag>} response about tag added.
|
|
267
|
+
*/
|
|
268
|
+
public add_tag(document_id: string, tag: string): Promise<Tag>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Delete all tags on an existing document
|
|
272
|
+
*
|
|
273
|
+
* @param {number} document_id ID of the document you'd like to delete all Tags
|
|
274
|
+
* @return {Promise<any>} response about deleted tags.
|
|
275
|
+
*/
|
|
276
|
+
public delete_tags(document_id: string): Promise<any>;
|
|
277
|
+
|
|
255
278
|
}
|
|
256
279
|
|
|
257
280
|
/**
|
|
258
281
|
* Create instance of a Client
|
|
259
282
|
* @class
|
|
260
283
|
* @param {string} client_id Your Veryfi client id
|
|
261
|
-
* @param {string} client_secret Your Veryfi client secret
|
|
284
|
+
* @param {string | undefined} client_secret Your Veryfi client secret
|
|
262
285
|
* @param {string} username Your Veryfi username
|
|
263
286
|
* @param {string} api_key Your Veryfi API key
|
|
264
287
|
* @param {string} base_url
|
|
@@ -267,7 +290,7 @@ export declare class Client {
|
|
|
267
290
|
*/
|
|
268
291
|
export declare function Client(
|
|
269
292
|
client_id: string,
|
|
270
|
-
client_secret: string,
|
|
293
|
+
client_secret: string | undefined,
|
|
271
294
|
username: string,
|
|
272
295
|
api_key: string,
|
|
273
296
|
base_url?: string,
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfi/veryfi-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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
|
+
"typings": "lib/types/main.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "jest",
|
|
9
9
|
"doc": "jsdoc -d docs --configure jsconf.json main.js",
|