@veryfi/veryfi-sdk 1.1.3 → 1.1.4
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/lib/main.js +45 -2
- package/package.json +1 -1
- package/test/main.test.js +24 -0
- package/types/main.d.ts +270 -0
package/lib/main.js
CHANGED
|
@@ -57,7 +57,7 @@ function Client(
|
|
|
57
57
|
*/
|
|
58
58
|
Client.prototype._get_headers = function (has_files=false){
|
|
59
59
|
let final_headers = {
|
|
60
|
-
"User-Agent": "Node.js Veryfi-Nodejs/1.1.
|
|
60
|
+
"User-Agent": "Node.js Veryfi-Nodejs/1.1.4",
|
|
61
61
|
"Accept": "application/json",
|
|
62
62
|
"Content-Type": "application/json",
|
|
63
63
|
"Client-Id": this.client_id,
|
|
@@ -214,8 +214,51 @@ Client.prototype.process_document = async function (
|
|
|
214
214
|
return document['data'];
|
|
215
215
|
}
|
|
216
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;
|
|
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
|
+
};
|
|
252
|
+
request_arguments = Object.assign(request_arguments,kwargs)
|
|
253
|
+
let document = await this._request("POST", endpoint_name, request_arguments)
|
|
254
|
+
return document['data'];
|
|
255
|
+
}
|
|
256
|
+
|
|
217
257
|
/**
|
|
218
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
|
+
*
|
|
219
262
|
* @memberof Client
|
|
220
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".
|
|
221
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"]
|
|
@@ -229,12 +272,12 @@ Client.prototype.process_document = async function (
|
|
|
229
272
|
*/
|
|
230
273
|
Client.prototype.process_document_url = async function (
|
|
231
274
|
file_url = "",
|
|
275
|
+
file_urls = null,
|
|
232
276
|
categories = null,
|
|
233
277
|
delete_after_processing = false,
|
|
234
278
|
boost_mode = 0,
|
|
235
279
|
external_id = "",
|
|
236
280
|
max_pages_to_process = 1,
|
|
237
|
-
file_urls = null,
|
|
238
281
|
{...kwargs} = {},
|
|
239
282
|
) {
|
|
240
283
|
let endpoint_name = "/documents/";
|
package/package.json
CHANGED
package/test/main.test.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const Client = require('../lib/main');
|
|
6
|
+
const fs = require('fs');
|
|
6
7
|
const client_id = 'YOUR_ID';
|
|
7
8
|
const client_secret = 'YOUR_SECRET';
|
|
8
9
|
const username = 'YOUR_USERNAME';
|
|
@@ -36,6 +37,29 @@ describe('Processing documents', () => {
|
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
test('Process document from buffer', async () => {
|
|
41
|
+
try {
|
|
42
|
+
let response;
|
|
43
|
+
if (mockResponses) {
|
|
44
|
+
const processDocumentJson = require('./processDocument.json');
|
|
45
|
+
const process_document_buffer = jest.fn();
|
|
46
|
+
process_document_buffer.mockReturnValue(processDocumentJson);
|
|
47
|
+
response = process_document_buffer();
|
|
48
|
+
} else {
|
|
49
|
+
const file_path = 'test/receipt.png';
|
|
50
|
+
const image_file = fs.readFileSync(file_path, { encoding: 'base64' });
|
|
51
|
+
const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
|
|
52
|
+
response = await veryfi_client.process_document_buffer(
|
|
53
|
+
base64_encoded_string,
|
|
54
|
+
'receipt.png'
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
expect(response['vendor']['name']).toBe('The Home Depot');
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
39
63
|
test('Process document from URL', async () => {
|
|
40
64
|
try {
|
|
41
65
|
let response;
|
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;
|