@veryfi/veryfi-sdk 1.3.2 → 1.4.1

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 (83) hide show
  1. package/README.md +443 -145
  2. package/lib/anydocs/deleteAnyDocument.js +12 -0
  3. package/lib/anydocs/getAnyDocument.js +22 -0
  4. package/lib/anydocs/getAnyDocuments.js +30 -0
  5. package/lib/anydocs/processAnyDocument.js +33 -0
  6. package/lib/anydocs/processAnyDocumentBase64.js +31 -0
  7. package/lib/anydocs/processAnyDocumentStream.js +33 -0
  8. package/lib/anydocs/processAnyDocumentUrl.js +30 -0
  9. package/lib/bankstatements/deleteBankStatement.js +12 -0
  10. package/lib/bankstatements/getBankStatement.js +24 -0
  11. package/lib/bankstatements/getBankStatements.js +28 -0
  12. package/lib/bankstatements/processBankStatement.js +33 -0
  13. package/lib/bankstatements/processBankStatementBase64.js +31 -0
  14. package/lib/bankstatements/processBankStatementStream.js +31 -0
  15. package/lib/bankstatements/processBankStatementUrl.js +30 -0
  16. package/lib/businesscards/deleteBusinessCard.js +12 -0
  17. package/lib/businesscards/getBusinessCard.js +24 -0
  18. package/lib/businesscards/getBusinessCards.js +28 -0
  19. package/lib/businesscards/processBusinessCard.js +27 -0
  20. package/lib/businesscards/processBusinessCardBase64.js +25 -0
  21. package/lib/businesscards/processBusinessCardStream.js +25 -0
  22. package/lib/businesscards/processBusinessCardUrl.js +24 -0
  23. package/lib/checks/deleteCheck.js +12 -0
  24. package/lib/checks/getCheck.js +24 -0
  25. package/lib/checks/getChecks.js +28 -0
  26. package/lib/checks/processCheck.js +33 -0
  27. package/lib/checks/processCheckBase64.js +31 -0
  28. package/lib/checks/processCheckStream.js +31 -0
  29. package/lib/checks/processCheckUrl.js +30 -0
  30. package/lib/client/client.js +63 -0
  31. package/lib/client/constructor.js +27 -0
  32. package/lib/client/function.js +6 -0
  33. package/lib/client/generateSignature.js +26 -0
  34. package/lib/client/getHeaders.js +21 -0
  35. package/lib/client/getUrl.js +9 -0
  36. package/lib/client/request.js +58 -0
  37. package/lib/documents/deleteDocument.js +12 -0
  38. package/lib/documents/getDocument.js +14 -0
  39. package/lib/documents/getDocuments.js +31 -0
  40. package/lib/documents/processDocument.js +37 -0
  41. package/lib/documents/processDocumentBase64.js +37 -0
  42. package/lib/documents/processDocumentStream.js +33 -0
  43. package/lib/documents/processDocumentUrl.js +41 -0
  44. package/lib/documents/tags/addTag.js +14 -0
  45. package/lib/documents/tags/addTags.js +14 -0
  46. package/lib/documents/tags/deleteTags.js +12 -0
  47. package/lib/documents/tags/replaceTags.js +14 -0
  48. package/lib/documents/updateDocument.js +17 -0
  49. package/lib/types/BillTo.ts +11 -0
  50. package/lib/types/BoundingElement.ts +6 -0
  51. package/lib/types/Client.ts +1058 -0
  52. package/lib/types/LineItem.ts +39 -0
  53. package/lib/types/Payment.ts +8 -0
  54. package/lib/types/ShipTo.ts +7 -0
  55. package/lib/types/Tag.ts +4 -0
  56. package/lib/types/TaxLine.ts +9 -0
  57. package/lib/types/Vendor.ts +35 -0
  58. package/lib/types/VeryfiDocument.ts +151 -0
  59. package/lib/types/VeryfiExtraArgs.ts +9 -0
  60. package/lib/w2s/deleteW2.js +12 -0
  61. package/lib/w2s/getW2.js +17 -0
  62. package/lib/w2s/getW2s.js +13 -0
  63. package/lib/w2s/processW2.js +28 -0
  64. package/lib/w2s/processW2Base64.js +30 -0
  65. package/lib/w2s/processW2Stream.js +30 -0
  66. package/lib/w2s/processW2Url.js +32 -0
  67. package/lib/w8bene/deleteW8BENE.js +12 -0
  68. package/lib/w8bene/getW8BENE.js +24 -0
  69. package/lib/w8bene/getW8BENEs.js +28 -0
  70. package/lib/w8bene/processW8BENE.js +33 -0
  71. package/lib/w8bene/processW8BENEBase64.js +31 -0
  72. package/lib/w8bene/processW8BENEStream.js +31 -0
  73. package/lib/w8bene/processW8BENEUrl.js +30 -0
  74. package/lib/w9s/deleteW9.js +12 -0
  75. package/lib/w9s/getW9.js +24 -0
  76. package/lib/w9s/getW9s.js +28 -0
  77. package/lib/w9s/processW9.js +30 -0
  78. package/lib/w9s/processW9Base64.js +31 -0
  79. package/lib/w9s/processW9Stream.js +31 -0
  80. package/lib/w9s/processW9Url.js +27 -0
  81. package/package.json +4 -4
  82. package/lib/main.js +0 -783
  83. package/lib/types/main.d.ts +0 -541
package/lib/main.js DELETED
@@ -1,783 +0,0 @@
1
- const {createHmac} = require('crypto');
2
- const axios = require('axios').default;
3
- const path = require('path');
4
- const FormData = require('form-data');
5
- const fs = require('fs');
6
- const {promisify} = require("util");
7
-
8
- /**
9
- * Create instance of a Client
10
- * @class
11
- * @param {string} client_id Your Veryfi client id
12
- * @param {string | undefined} client_secret Your Veryfi client secret
13
- * @param {string} username Your Veryfi username
14
- * @param {string} api_key Your Veryfi API key
15
- * @param {string} base_url
16
- * @param {string} api_version
17
- * @param {Number} timeout
18
- */
19
- function Client(
20
- client_id,
21
- client_secret,
22
- username,
23
- api_key,
24
- base_url = "https://api.veryfi.com/",
25
- api_version = "v8",
26
- timeout = 120) {
27
- this.client_id = client_id;
28
- this.client_secret = client_secret;
29
- this.username = username;
30
- this.api_key = api_key;
31
- this.base_url = base_url;
32
- this.timeout = timeout;
33
- this.api_version = api_version;
34
- this.CATEGORIES = [
35
- "Advertising & Marketing",
36
- "Automotive",
37
- "Bank Charges & Fees",
38
- "Legal & Professional Services",
39
- "Insurance",
40
- "Meals & Entertainment",
41
- "Office Supplies & Software",
42
- "Taxes & Licenses",
43
- "Travel",
44
- "Rent & Lease",
45
- "Repairs & Maintenance",
46
- "Payroll",
47
- "Utilities",
48
- "Job Supplies",
49
- "Grocery",
50
- ];
51
- }
52
-
53
- /**
54
- * Check api version for w2 documents
55
- * @private
56
- * @throws error when api_version is different to v8
57
- */
58
- Client.prototype._check_w2_version = function () {
59
- if (this.api_version !== "v8") throw Error("w2 is only supported on v8")
60
- }
61
-
62
- /**
63
- * Prepares the headers needed for a request.
64
- * @private
65
- * @param {Boolean} has_files Are there any files to be submitted as binary
66
- * @return {Object} Dictionary with headers
67
- */
68
- Client.prototype._get_headers = function (has_files = false) {
69
- let final_headers = {
70
- "User-Agent": "Node.js Veryfi-Nodejs/1.3.2",
71
- "Accept": "application/json",
72
- "Content-Type": "application/json",
73
- "Client-Id": this.client_id,
74
- "Authorization": `apikey ${this.username}:${this.api_key}`,
75
- };
76
- if (has_files) {
77
- final_headers["Content-Type"] = "application/x-www-form-urlencoded";
78
- }
79
- return final_headers;
80
- }
81
-
82
- /**
83
- * Get API Base URL with API Version
84
- * @private
85
- * @returns {string} Base URL to Veryfi API
86
- */
87
- Client.prototype._get_url = function () {
88
- return this.base_url + "api/" + this.api_version;
89
- }
90
-
91
- /**
92
- * Generate unique signature for payload params.
93
- * @private
94
- * @param {{}} payload_params JSON params to be sent to API request
95
- * @param {Number} timestamp Unix Long timestamp
96
- * @returns {string} Unique signature generated using the client_secret and the payload
97
- */
98
- Client.prototype._generate_signature = function (payload_params, timestamp) {
99
- let payload = `timestamp:${timestamp}`;
100
- for (let i = 0; i < Object.keys(payload_params).length; i++) {
101
- let key = Object.keys(payload_params)[i];
102
- let value = payload_params[key];
103
- payload = `${payload},${key}:${value}`;
104
- }
105
- const secret_bytes = encodeURI(this.client_secret);
106
- const payload_bytes = encodeURI(payload);
107
- let hmac = createHmac('sha256', secret_bytes);
108
- hmac.update(payload_bytes);
109
- let tmp_signature = hmac.digest();
110
- let base64_signature = Buffer.from(tmp_signature).toString('base64');
111
- base64_signature = Buffer.from(base64_signature).toString('utf-8').trim();
112
-
113
- return base64_signature;
114
- }
115
-
116
- /**
117
- * Submit the HTTP request.
118
- * @private
119
- * @param {string} http_verb HTTP Method
120
- * @param {string} endpoint_name Endpoint name such as 'documents', 'users', etc.
121
- * @param {{}} request_arguments JSON payload to send to Veryfi
122
- * @param params {{}} query params.
123
- * @param {Boolean} has_files Are there any files to be submitted as binary
124
- * @returns {JSON} A JSON of the response data.
125
- */
126
- Client.prototype._request = async function (http_verb, endpoint_name, request_arguments, params = {}, has_files = false) {
127
- let headers = this._get_headers(has_files);
128
- let api_url = `${this._get_url()}/partner${endpoint_name}`;
129
-
130
- if (this.client_secret) {
131
- let timestamp = Date.now();
132
- let signature = this._generate_signature(request_arguments, timestamp);
133
- headers = Object.assign(headers, {
134
- "X-Veryfi-Request-Timestamp": timestamp,
135
- "X-Veryfi-Request-Signature": signature
136
- });
137
- }
138
-
139
- if (has_files) {
140
- const formData = new FormData();
141
- for (const key in request_arguments) {
142
- if (request_arguments.hasOwnProperty(key)) {
143
- const value = request_arguments[key];
144
- formData.append(key, value);
145
- }
146
- }
147
- headers = Object.assign(headers, formData.getHeaders());
148
- const getLength = promisify(formData.getLength).bind(formData);
149
- headers['Content-Length'] = await getLength()
150
- request_arguments = formData;
151
- } else {
152
- request_arguments = JSON.stringify(request_arguments);
153
- }
154
- try {
155
- return await axios.request({
156
- method: http_verb,
157
- url: api_url,
158
- headers: headers,
159
- data: request_arguments,
160
- timeout: this.timeout * 1000,
161
- params: params
162
- });
163
- } catch (response) {
164
- let errorStatus = response?.response?.status;
165
- let errorInfo = response?.response?.data?.error;
166
- let message = response?.message;
167
- throw new Error(`Error: ${errorStatus} ${errorInfo} ${message}`);
168
- }
169
- }
170
-
171
-
172
- /**
173
- * Get JSON of documents
174
- * @memberof Client
175
- * @returns {JSON} JSON object of previously processed documents
176
- */
177
- Client.prototype.get_documents = async function (
178
- page = 1,
179
- page_size = 50,
180
- bounding_boxes = false,
181
- confidence_details = false,
182
- {...kwargs} = {}
183
- ) {
184
- let endpoint_name = "/documents/";
185
- let request_arguments = {};
186
- let documents = await this._request("GET", endpoint_name, request_arguments);
187
- if ("data" in documents) {
188
- documents = documents["data"];
189
- }
190
- return documents;
191
- }
192
-
193
- /**
194
- * Retrieve document by ID
195
- * @memberof Client
196
- * @param {string} document_id ID of the document you'd like to retrieve
197
- * @returns {JSON} Data extracted from the Document
198
- */
199
- Client.prototype.get_document = async function (document_id) {
200
- let endpoint_name = `/documents/${document_id}/`;
201
- let request_arguments = {"id": document_id};
202
- let document = await this._request("GET", endpoint_name, request_arguments);
203
- return document['data'];
204
- }
205
-
206
- /**
207
- * Process a document and extract all the fields from it
208
- * @example
209
- * veryfi_client.process_document('file/path',
210
- * ['Entertainment','Food'],
211
- * true,
212
- * {"extra":"parameters"})
213
- *
214
- * @memberof Client
215
- * @param {String} file_path Path on disk to a file to submit for data extraction
216
- * @param {Array} categories List of categories Veryfi can use to categorize the document
217
- * @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
218
- * @param {Object} kwargs Additional request parameters
219
- * @returns {JSON} Data extracted from the document
220
- */
221
- Client.prototype.process_document = async function (
222
- file_path,
223
- categories = null,
224
- delete_after_processing = false,
225
- {...kwargs} = {}
226
- ) {
227
-
228
- let endpoint_name = "/documents/";
229
- if (!categories) {
230
- categories = this.CATEGORIES;
231
- }
232
- let file_name = path.basename(file_path);
233
- const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
234
- const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
235
- let request_arguments = {
236
- "file_name": file_name,
237
- "file_data": base64_encoded_string,
238
- "categories": categories,
239
- "auto_delete": delete_after_processing,
240
- };
241
- request_arguments = Object.assign(request_arguments, kwargs);
242
- let document = await this._request("POST", endpoint_name, request_arguments);
243
- return document['data'];
244
- }
245
-
246
- /**
247
- * Process a document and extract all the fields from it
248
- * @example
249
- * veryfi_client.process_document_stream('ReadStream',
250
- * 'receipt.png',
251
- * ['Entertainment','Food'],
252
- * true,
253
- * {'extra': 'parameters'})
254
- *
255
- * @memberof Client
256
- * @param {ReadStream} file ReadStream of a file to submit for data extraction
257
- * @param {String} file_name The file name including the extension
258
- * @param {Array} categories List of categories Veryfi can use to categorize the document
259
- * @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
260
- * @param {Object} kwargs Additional request parameters
261
- * @returns {JSON} Data extracted from the document
262
- */
263
- Client.prototype.process_document_stream = async function (
264
- file,
265
- file_name,
266
- delete_after_processing = false,
267
- {...kwargs} = {}
268
- ) {
269
-
270
- let endpoint_name = "/documents/";
271
-
272
- let request_arguments = {
273
- "file_name": file_name,
274
- "file": file,
275
- "auto_delete": delete_after_processing.toString(),
276
- };
277
- request_arguments = Object.assign(request_arguments, kwargs);
278
- let document = await this._request("POST", endpoint_name, request_arguments, {}, true);
279
- return document['data'];
280
- }
281
-
282
- /**
283
- * Process a document and extract all the fields from it
284
- * @example
285
- * veryfi_client.process_document_base64string('base64_encoded_string',
286
- * 'receipt.png',
287
- * ['Entertainment','Food'],
288
- * true,
289
- * {'extra': 'parameters'})
290
- *
291
- * @memberof Client
292
- * @param {String} base64_encoded_string Buffer string of a file to submit for data extraction
293
- * @param {String} file_name The file name including the extension
294
- * @param {Array} categories List of categories Veryfi can use to categorize the document
295
- * @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
296
- * @param {Object} kwargs Additional request parameters
297
- * @returns {JSON} Data extracted from the document
298
- */
299
- Client.prototype.process_document_base64string = async function (
300
- base64_encoded_string,
301
- file_name,
302
- categories = null,
303
- delete_after_processing = false,
304
- {...kwargs} = {}
305
- ) {
306
-
307
- let endpoint_name = "/documents/";
308
- if (!categories) {
309
- categories = this.CATEGORIES;
310
- }
311
- let request_arguments = {
312
- "file_name": file_name,
313
- "file_data": base64_encoded_string,
314
- "categories": categories,
315
- "auto_delete": delete_after_processing,
316
- };
317
- request_arguments = Object.assign(request_arguments, kwargs);
318
- let document = await this._request("POST", endpoint_name, request_arguments);
319
- return document['data'];
320
- }
321
-
322
- /**
323
- * Process document from url and extract all the fields from it.
324
- * @example
325
- * veryfi_client.process_document_url('https://cdn.example.com/receipt.jpg')
326
- *
327
- * @memberof Client
328
- * @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".
329
- * @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"]
330
- * @param {Array} categories List of categories to use when categorizing the document
331
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
332
- * @param {int} 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
333
- * @param {string} external_id Optional custom document identifier. Use this if you would like to assign your own ID to documents
334
- * @param {int} 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.
335
- * @param {Object} kwargs Additional request parameters
336
- * @return {JSON} Data extracted from the document.
337
- */
338
- Client.prototype.process_document_url = async function (
339
- file_url = "",
340
- file_urls = null,
341
- categories = null,
342
- delete_after_processing = false,
343
- boost_mode = 0,
344
- external_id = "",
345
- max_pages_to_process = 1,
346
- {...kwargs} = {},
347
- ) {
348
- let endpoint_name = "/documents/";
349
- if (!categories) {
350
- categories = this.CATEGORIES;
351
- }
352
- let request_arguments = {
353
- "auto_delete": delete_after_processing,
354
- "boost_mode": boost_mode,
355
- "categories": categories,
356
- "external_id": external_id,
357
- "file_url": file_url,
358
- "file_urls": file_urls,
359
- "max_pages_to_process": max_pages_to_process,
360
- };
361
- request_arguments = Object.assign(request_arguments, kwargs);
362
- let response = await this._request("POST", endpoint_name, request_arguments);
363
- return response['data'];
364
- }
365
-
366
- /**
367
- * Delete document from Veryfi
368
- *
369
- * @memberof Client
370
- * @param {string} document_id ID of the document you'd like to delete
371
- */
372
- Client.prototype.delete_document = async function (document_id) {
373
- let endpoint_name = `/documents/${document_id}/`;
374
- let request_arguments = {"id": document_id};
375
- return this._request("DELETE", endpoint_name, request_arguments);
376
- }
377
-
378
- /**
379
- * Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` and etc.
380
- * @example
381
- * veryfi_client.update_document(id, {date:"2021-01-01", notes:"look what I did"})
382
- *
383
- * @memberof Client
384
- * @param {string} document_id ID of the document you'd like to update
385
- * @param {Object} kwargs fields to update
386
- * @return {JSON} A document json with updated fields, if fields are writable. Otherwise a document with unchanged fields.
387
- */
388
- Client.prototype.update_document = async function (document_id, {...kwargs} = {}) {
389
- let endpoint_name = `/documents/${document_id}/`;
390
- let response = await this._request("PUT", endpoint_name, kwargs);
391
- return response['data'];
392
- }
393
-
394
- /**
395
- * Get all w2 documents.
396
- * @memberOf Client
397
- * @param {int} page number, response is capped to maximum of 50 results per page.
398
- * @return {Array} An array of JSON with all w2 documents.
399
- */
400
- Client.prototype.get_w2_documents = async function (page = null) {
401
- this._check_w2_version();
402
- let endpoint_name = "/w2s/";
403
- let request_arguments = {};
404
- let params = {};
405
- if (page !== null) {
406
- params = {"page": page};
407
- }
408
- let response = await this._request("GET", endpoint_name, request_arguments, params);
409
- return response['data']['results'];
410
- }
411
-
412
- /**
413
- * Get a w2 document
414
- * @memberOf Client
415
- * @param {string} document_id ID of the document you'd like to retrieve
416
- * @returns {JSON} Data extracted from the Document
417
- */
418
- Client.prototype.get_w2_document = async function (
419
- document_id,
420
- ) {
421
- this._check_w2_version();
422
- let endpoint_name = `/w2s/${document_id}/`;
423
- let request_arguments = {"id": document_id};
424
- let response = await this._request("GET", endpoint_name, request_arguments);
425
- return response['data'];
426
- }
427
-
428
- /**
429
- * Upload a document from a buffer.
430
- * @memberOf Client
431
- * @param {String} file_name The file name including the extension
432
- * @param {String} file_buffer Buffer of a file to submit for data extraction
433
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
434
- * @param {int} 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.
435
- * @param {Object} kwargs Additional request parameters
436
- * @return {JSON} Data extracted from the document.
437
- */
438
- Client.prototype.process_w2_document_from_buffer = async function (
439
- file_name,
440
- file_buffer,
441
- delete_after_processing = null,
442
- max_pages_to_process = null,
443
- {...kwargs} = {}
444
- ) {
445
- this._check_w2_version()
446
- let endpoint_name = "/w2s/"
447
- let request_arguments = {
448
- "file_name": file_name,
449
- "file_data": file_buffer,
450
- "auto_delete": delete_after_processing,
451
- "max_pages_to_process": max_pages_to_process,
452
- }
453
- request_arguments = Object.assign(request_arguments, kwargs);
454
- let response = await this._request("POST", endpoint_name, request_arguments);
455
- return response['data'];
456
- }
457
-
458
- /**
459
- * Upload a document from a file path
460
- * @param {String} file_path Path on disk to a file to submit for data extraction
461
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
462
- * @param {int} 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.
463
- * @param {Object} kwargs Additional request parameters
464
- * @return {JSON} Data extracted from the document.
465
- */
466
- Client.prototype.process_w2_document = async function (
467
- file_path,
468
- delete_after_processing = false,
469
- max_pages_to_process = 1,
470
- {...kwargs} = {}
471
- ) {
472
- const file_name = path.basename(file_path)
473
- const image_file = fs.readFileSync(file_path, {encoding: 'base64'})
474
- const base64_encoded_string = Buffer.from(image_file).toString('utf-8')
475
- return this.process_w2_document_from_buffer(
476
- file_name,
477
- base64_encoded_string,
478
- delete_after_processing,
479
- max_pages_to_process,
480
- kwargs
481
- );
482
- }
483
-
484
- /**
485
- * Process a w2 document from an url.
486
- * @memberOf Client
487
- * @param {String} file_name The file name including the extension
488
- * @memberof Client
489
- * @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".
490
- * @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"]
491
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
492
- * @param {int} 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.
493
- * @param {Object} kwargs Additional request parameters
494
- * @return {JSON} Data extracted from the document.
495
- */
496
- Client.prototype.process_w2_document_from_url = async function (
497
- file_name,
498
- file_url,
499
- file_urls = null,
500
- delete_after_processing = false,
501
- max_pages_to_process = 1,
502
- {...kwargs} = {}
503
- ) {
504
- this._check_w2_version()
505
- let endpoint_name = "/w2s/"
506
- let request_arguments = {
507
- "file_name": file_name,
508
- "auto_delete": delete_after_processing,
509
- "file_url": file_url,
510
- "file_urls": file_urls,
511
- "max_pages_to_process": max_pages_to_process
512
- }
513
- request_arguments = Object.assign(request_arguments, kwargs);
514
- let response = await this._request("POST", endpoint_name, request_arguments);
515
- return response['data'];
516
- }
517
-
518
- /**
519
- * Add a new tag on an existing document
520
- *
521
- * @param {number} document_id ID of the document you'd like to add a Tag
522
- * @param {string} tag name to add
523
- * @return {JSON} response about tag added.
524
- */
525
- Client.prototype.add_tag = async function (document_id, tag) {
526
- let endpoint_name = `/documents/${document_id}/tags/`;
527
- let request_arguments = {"name": tag};
528
- let response = await this._request("PUT", endpoint_name, request_arguments);
529
- return response['data'];
530
- }
531
-
532
- /**
533
- * Delete all the tags on an existing document
534
- *
535
- * @param {number} document_id ID of the document you'd like to delete tags
536
- * @return {JSON} response about deleted tags.
537
- */
538
- Client.prototype.delete_tags = async function (document_id) {
539
- let endpoint_name = `/documents/${document_id}/tags/`;
540
- let request_arguments = {};
541
- return this._request("DELETE", endpoint_name, request_arguments);
542
- }
543
-
544
- /**
545
- * Replace multiple tags on an existing document
546
- *
547
- * @param {number} document_id ID of the document you'd like to add a Tag
548
- * @param {string[]} tags array of tags to be added
549
- * @return {JSON} response about tag added.
550
- */
551
- Client.prototype.replace_tags = async function (document_id, tags) {
552
- let endpoint_name = `/documents/${document_id}/`;
553
- let request_arguments = {"tags": tags};
554
- let response = await this._request("PUT", endpoint_name, request_arguments);
555
- return response['data'];
556
- }
557
-
558
- /**
559
- * Add multiple tags on an existing document
560
- *
561
- * @param {number} document_id ID of the document you'd like to add a Tag
562
- * @param {string[]} tags array of tags to be added
563
- * @return {JSON} response about tag added.
564
- */
565
- Client.prototype.add_tags = async function (document_id, tags) {
566
- let endpoint_name = `/documents/${document_id}/tags/`;
567
- let request_arguments = {"tags": tags};
568
- let response = await this._request("POST", endpoint_name, request_arguments);
569
- return response['data'];
570
- }
571
-
572
- /**
573
- * Process any document and extract all the fields from it
574
- * @example
575
- * veryfi_client.process_any_document('file/path','blue_print')
576
- *
577
- * @memberof Client
578
- * @param {String} file_path Path on disk to a file to submit for data extraction
579
- * @param {String} template_name name of the extraction templates.
580
- * @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
581
- * @param {Object} kwargs Additional request parameters
582
- * @returns {JSON} Data extracted from the document
583
- */
584
- Client.prototype.process_any_document = async function (
585
- file_path,
586
- template_name,
587
- max_pages_to_process = 20,
588
- {...kwargs} = {}
589
- ) {
590
-
591
- let endpoint_name = "/any-documents/";
592
- let file_name = path.basename(file_path);
593
- const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
594
- const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
595
- let request_arguments = {
596
- "file_name": file_name,
597
- "file_data": base64_encoded_string,
598
- "template_name": template_name,
599
- "max_pages_to_process": max_pages_to_process,
600
- };
601
- request_arguments = Object.assign(request_arguments, kwargs);
602
- let document = await this._request("POST", endpoint_name, request_arguments);
603
- return document['data'];
604
- }
605
-
606
- /**
607
- * Process any document and extract all the fields from it
608
- * @example
609
- * veryfi_client.process_any_document_url('file_url','blue_print')
610
- *
611
- * @memberof Client
612
- * @param {String} file_url url file to submit for data extraction
613
- * @param {String} template_name name of the extraction templates.
614
- * @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
615
- * @param {Object} kwargs Additional request parameters
616
- * @returns {JSON} Data extracted from the document
617
- */
618
- Client.prototype.process_any_document_url = async function (
619
- file_url,
620
- template_name,
621
- max_pages_to_process = 20,
622
- {...kwargs} = {}
623
- ) {
624
-
625
- let endpoint_name = "/any-documents/";
626
- let request_arguments = {
627
- "file_url": file_url,
628
- "template_name": template_name,
629
- "max_pages_to_process": max_pages_to_process,
630
- };
631
- request_arguments = Object.assign(request_arguments, kwargs);
632
- let document = await this._request("POST", endpoint_name, request_arguments);
633
- return document['data'];
634
- }
635
-
636
- /**
637
- * Get all any documents
638
- * @memberof Client
639
- * @param {number} page The page number. The response is capped to maximum of 50 results per page.
640
- * @param {number} page_size The number of Documents per page.
641
- * @returns {JSON} Object of previously processed any documents
642
- */
643
- Client.prototype.get_any_documents = async function (
644
- page = 1,
645
- page_size = 50) {
646
- let endpoint_name = "/any-documents/";
647
- let request_arguments = {"page": page, "page_size": page_size};
648
- let documents = await this._request("GET", endpoint_name, request_arguments);
649
- if ("data" in documents) {
650
- documents = documents["data"];
651
- }
652
- return documents;
653
- }
654
-
655
- /**
656
- * Get a specific any document
657
- * @memberof Client
658
- * @param {number} document_id The unique identifier of the document.
659
- * @returns {JSON} Object of a previously processed blueprinted document.
660
- */
661
- Client.prototype.get_any_document = async function (document_id) {
662
- let endpoint_name = `/any-documents/${document_id}/`;
663
- let request_arguments = {};
664
- let document = await this._request("GET", endpoint_name, request_arguments);
665
- return document['data'];
666
- }
667
-
668
- /**
669
- * Get a specific bank statement
670
- * @memberof Client
671
- * @param {number} document_id The unique identifier of the document.
672
- * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
673
- * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
674
- * @returns {JSON} Object of a previously processed blueprinted document.
675
- */
676
- Client.prototype.get_bank_statement = async function (
677
- document_id,
678
- bounding_boxes = false,
679
- confidence_details = false
680
- ) {
681
- let endpoint_name = `/bank-statements/${document_id}/`;
682
- let request_arguments = {
683
- "bounding_boxes": bounding_boxes,
684
- "confidence_details": confidence_details
685
- };
686
- let document = await this._request("GET", endpoint_name, request_arguments);
687
- return document['data'];
688
- }
689
-
690
- /**
691
- * Get all bank statements
692
- * @memberof Client
693
- * @param {number} page The page number. The response is capped to maximum of 50 results per page.
694
- * @param {number} page_size The number of Documents per page.
695
- * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
696
- * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
697
- * @returns {JSON} Object of previously processed any documents
698
- */
699
- Client.prototype.get_bank_statements = async function (
700
- page = 1,
701
- page_size = 50,
702
- bounding_boxes = false,
703
- confidence_details = false
704
- ) {
705
- let endpoint_name = `/bank-statements/`;
706
- let request_arguments = {
707
- "page": page,
708
- "page_size": page_size,
709
- "bounding_boxes": bounding_boxes,
710
- "confidence_details": confidence_details
711
- };
712
- let document = await this._request("GET", endpoint_name, request_arguments);
713
- return document['data'];
714
- }
715
-
716
- /**
717
- * Process bank statement and extract all the fields from it
718
- * @example
719
- * veryfi_client.process_bank_statement('file_path')
720
- *
721
- * @memberof Client
722
- * @param {String} file_path Path on disk to a file to submit for data extraction
723
- * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
724
- * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
725
- * @param {Object} kwargs Additional request parameters
726
- * @returns {JSON} Data extracted from the document
727
- */
728
- Client.prototype.process_bank_statement = async function (
729
- file_path,
730
- bounding_boxes = false,
731
- confidence_details = false,
732
- {...kwargs} = {}
733
- ) {
734
-
735
- let endpoint_name = "/bank-statements/";
736
- let file_name = path.basename(file_path);
737
- const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
738
- const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
739
- let request_arguments = {
740
- "file_name": file_name,
741
- "file_data": base64_encoded_string,
742
- "bounding_boxes": bounding_boxes,
743
- "confidence_details": confidence_details,
744
- };
745
- request_arguments = Object.assign(request_arguments, kwargs);
746
- let document = await this._request("POST", endpoint_name, request_arguments);
747
- return document['data'];
748
- }
749
-
750
- /**
751
- * Process bank statement and extract all the fields from it
752
- * @example
753
- * veryfi_client.process_bank_statement_url('file_url')
754
- *
755
- * @memberof Client
756
- * @param {String} file_url url file to submit for data extraction
757
- * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
758
- * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
759
- * @param {Object} kwargs Additional request parameters
760
- * @returns {JSON} Data extracted from the document
761
- */
762
- Client.prototype.process_bank_statement_url = async function (
763
- file_url,
764
- bounding_boxes = false,
765
- confidence_details = false,
766
- {...kwargs} = {}
767
- ) {
768
-
769
- let endpoint_name = "/bank-statements/";
770
- let request_arguments = {
771
- "file_url": file_url,
772
- "bounding_boxes": bounding_boxes,
773
- "confidence_details": confidence_details,
774
- };
775
- request_arguments = Object.assign(request_arguments, kwargs);
776
- let document = await this._request("POST", endpoint_name, request_arguments);
777
- return document['data'];
778
- }
779
-
780
-
781
- // Exports
782
-
783
- module.exports = Client;