@veryfi/veryfi-sdk 1.3.1 → 1.4.0

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 +24 -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 +15 -0
  58. package/lib/types/VeryfiDocument.ts +93 -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 -569
  83. package/lib/types/main.d.ts +0 -413
@@ -0,0 +1,31 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Upload a w9 document from a buffer. https://docs.veryfi.com/api/w9s/process-a-w-9/
4
+ * @memberof Client
5
+ * @param {String} file_name The file name including the extension
6
+ * @param {String} file_base64_string To submit a file for data extraction, encode the file in Base64 format and ensure it includes the MIME type. The Base64 string should follow this structure: data:${mimeType};base64,${base64String}
7
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
8
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
9
+ * @param {Object} kwargs Additional request parameters
10
+ * @returns {JSON} Data extracted from the document
11
+ */
12
+ Client.prototype.process_w9_from_base64 = async function (
13
+ file_name,
14
+ file_base64_string,
15
+ bounding_boxes = false,
16
+ confidence_details = false,
17
+ {...kwargs} = {}
18
+ ) {
19
+
20
+ let endpoint_name = "/w9s/";
21
+ let request_arguments = {
22
+ "file_name": file_name,
23
+ "file_data": file_base64_string,
24
+ "bounding_boxes": bounding_boxes,
25
+ "confidence_details": confidence_details,
26
+ };
27
+ request_arguments = Object.assign(request_arguments, kwargs);
28
+ let document = await this._request("POST", endpoint_name, request_arguments);
29
+ return document['data'];
30
+ }
31
+
@@ -0,0 +1,31 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Upload a w9 document from a buffer. https://docs.veryfi.com/api/w9s/process-a-w-9/
4
+ * @memberof Client
5
+ * @param {fs.ReadStream} file file to submit for data extraction
6
+ * @param {String} file_name The file name including the extension
7
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
8
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
9
+ * @param {Object} kwargs Additional request parameters
10
+ * @returns {JSON} Data extracted from the document
11
+ */
12
+ Client.prototype.process_w9_from_stream = async function (
13
+ file,
14
+ file_name,
15
+ bounding_boxes = false,
16
+ confidence_details = false,
17
+ {...kwargs} = {}
18
+ ) {
19
+
20
+ let endpoint_name = "/w9s/";
21
+ let request_arguments = {
22
+ "file": file,
23
+ "file_name": file_name,
24
+ "bounding_boxes": bounding_boxes,
25
+ "confidence_details": confidence_details,
26
+ };
27
+ request_arguments = Object.assign(request_arguments, kwargs);
28
+ let document = await this._request("POST", endpoint_name, request_arguments, null, true);
29
+ return document['data'];
30
+ }
31
+
@@ -0,0 +1,27 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process a w9 document from an url. https://docs.veryfi.com/api/w9s/process-a-w-9/
4
+ * @memberof Client
5
+ * @param {String} file_url url file to submit for data extraction
6
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
7
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
8
+ * @param {Object} kwargs Additional request parameters
9
+ * @returns {JSON} Data extracted from the document
10
+ */
11
+ Client.prototype.process_w9_from_url = async function (
12
+ file_url,
13
+ bounding_boxes = false,
14
+ confidence_details = false,
15
+ {...kwargs} = {}
16
+ ) {
17
+
18
+ let endpoint_name = "/w9s/";
19
+ let request_arguments = {
20
+ "file_url": file_url,
21
+ "bounding_boxes": bounding_boxes,
22
+ "confidence_details": confidence_details,
23
+ };
24
+ request_arguments = Object.assign(request_arguments, kwargs);
25
+ let document = await this._request("POST", endpoint_name, request_arguments, null, false);
26
+ return document['data'];
27
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@veryfi/veryfi-sdk",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Node.js module for communicating with the Veryfi OCR API",
5
- "main": "lib/main.js",
6
- "typings": "lib/types/main.d.ts",
5
+ "main": "lib/client/client.js",
6
+ "typings": "lib/types/Client.ts",
7
7
  "scripts": {
8
8
  "test": "jest",
9
9
  "doc": "jsdoc -d docs --configure jsconf.json main.js",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@jest/globals": "^29.0.3",
36
- "axios": "^1.7.2",
36
+ "axios": "^1.7.4",
37
37
  "docdash": "^1.2.0",
38
38
  "form-data": "^4.0.0",
39
39
  "jest-config": "^29.0.3"
package/lib/main.js DELETED
@@ -1,569 +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.1",
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
- let endpoint_name = "/documents/";
179
- let request_arguments = {};
180
- let documents = await this._request("GET", endpoint_name, request_arguments);
181
- if ("data" in documents) {
182
- documents = documents["data"];
183
- }
184
- return documents;
185
- }
186
-
187
- /**
188
- * Retrieve document by ID
189
- * @memberof Client
190
- * @param {string} document_id ID of the document you'd like to retrieve
191
- * @returns {JSON} Data extracted from the Document
192
- */
193
- Client.prototype.get_document = async function (document_id) {
194
- let endpoint_name = `/documents/${document_id}/`;
195
- let request_arguments = {"id": document_id};
196
- let document = await this._request("GET", endpoint_name, request_arguments);
197
- return document['data'];
198
- }
199
-
200
- /**
201
- * Process a document and extract all the fields from it
202
- * @example
203
- * veryfi_client.process_document('file/path',
204
- * ['Entertainment','Food'],
205
- * true,
206
- * {"extra":"parameters"})
207
- *
208
- * @memberof Client
209
- * @param {String} file_path Path on disk to a file to submit for data extraction
210
- * @param {Array} categories List of categories Veryfi can use to categorize the document
211
- * @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
212
- * @param {Object} kwargs Additional request parameters
213
- * @returns {JSON} Data extracted from the document
214
- */
215
- Client.prototype.process_document = async function (
216
- file_path,
217
- categories = null,
218
- delete_after_processing = false,
219
- {...kwargs} = {}
220
- ) {
221
-
222
- let endpoint_name = "/documents/";
223
- if (!categories) {
224
- categories = this.CATEGORIES;
225
- }
226
- let file_name = path.basename(file_path);
227
- const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
228
- const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
229
- let request_arguments = {
230
- "file_name": file_name,
231
- "file_data": base64_encoded_string,
232
- "categories": categories,
233
- "auto_delete": delete_after_processing,
234
- };
235
- request_arguments = Object.assign(request_arguments, kwargs);
236
- let document = await this._request("POST", endpoint_name, request_arguments);
237
- return document['data'];
238
- }
239
-
240
- /**
241
- * Process a document and extract all the fields from it
242
- * @example
243
- * veryfi_client.process_document_stream('ReadStream',
244
- * 'receipt.png',
245
- * ['Entertainment','Food'],
246
- * true,
247
- * {'extra': 'parameters'})
248
- *
249
- * @memberof Client
250
- * @param {ReadStream} file ReadStream of a file to submit for data extraction
251
- * @param {String} file_name The file name including the extension
252
- * @param {Array} categories List of categories Veryfi can use to categorize the document
253
- * @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
254
- * @param {Object} kwargs Additional request parameters
255
- * @returns {JSON} Data extracted from the document
256
- */
257
- Client.prototype.process_document_stream = async function (
258
- file,
259
- file_name,
260
- delete_after_processing = false,
261
- {...kwargs} = {}
262
- ) {
263
-
264
- let endpoint_name = "/documents/";
265
-
266
- let request_arguments = {
267
- "file_name": file_name,
268
- "file": file,
269
- "auto_delete": delete_after_processing.toString(),
270
- };
271
- request_arguments = Object.assign(request_arguments, kwargs);
272
- let document = await this._request("POST", endpoint_name, request_arguments, {}, true);
273
- return document['data'];
274
- }
275
-
276
- /**
277
- * Process a document and extract all the fields from it
278
- * @example
279
- * veryfi_client.process_document_base64string('base64_encoded_string',
280
- * 'receipt.png',
281
- * ['Entertainment','Food'],
282
- * true,
283
- * {'extra': 'parameters'})
284
- *
285
- * @memberof Client
286
- * @param {String} base64_encoded_string Buffer string of a file to submit for data extraction
287
- * @param {String} file_name The file name including the extension
288
- * @param {Array} categories List of categories Veryfi can use to categorize the document
289
- * @param {Boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
290
- * @param {Object} kwargs Additional request parameters
291
- * @returns {JSON} Data extracted from the document
292
- */
293
- Client.prototype.process_document_base64string = async function (
294
- base64_encoded_string,
295
- file_name,
296
- categories = null,
297
- delete_after_processing = false,
298
- {...kwargs} = {}
299
- ) {
300
-
301
- let endpoint_name = "/documents/";
302
- if (!categories) {
303
- categories = this.CATEGORIES;
304
- }
305
- let request_arguments = {
306
- "file_name": file_name,
307
- "file_data": base64_encoded_string,
308
- "categories": categories,
309
- "auto_delete": delete_after_processing,
310
- };
311
- request_arguments = Object.assign(request_arguments, kwargs);
312
- let document = await this._request("POST", endpoint_name, request_arguments);
313
- return document['data'];
314
- }
315
-
316
- /**
317
- * Process document from url and extract all the fields from it.
318
- * @example
319
- * veryfi_client.process_document_url('https://cdn.example.com/receipt.jpg')
320
- *
321
- * @memberof Client
322
- * @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".
323
- * @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"]
324
- * @param {Array} categories List of categories to use when categorizing the document
325
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
326
- * @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
327
- * @param {string} external_id Optional custom document identifier. Use this if you would like to assign your own ID to documents
328
- * @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.
329
- * @param {Object} kwargs Additional request parameters
330
- * @return {JSON} Data extracted from the document.
331
- */
332
- Client.prototype.process_document_url = async function (
333
- file_url = "",
334
- file_urls = null,
335
- categories = null,
336
- delete_after_processing = false,
337
- boost_mode = 0,
338
- external_id = "",
339
- max_pages_to_process = 1,
340
- {...kwargs} = {},
341
- ) {
342
- let endpoint_name = "/documents/";
343
- if (!categories) {
344
- categories = this.CATEGORIES;
345
- }
346
- let request_arguments = {
347
- "auto_delete": delete_after_processing,
348
- "boost_mode": boost_mode,
349
- "categories": categories,
350
- "external_id": external_id,
351
- "file_url": file_url,
352
- "file_urls": file_urls,
353
- "max_pages_to_process": max_pages_to_process,
354
- };
355
- request_arguments = Object.assign(request_arguments, kwargs);
356
- let response = await this._request("POST", endpoint_name, request_arguments);
357
- return response['data'];
358
- }
359
-
360
- /**
361
- * Delete document from Veryfi
362
- *
363
- * @memberof Client
364
- * @param {string} document_id ID of the document you'd like to delete
365
- */
366
- Client.prototype.delete_document = async function (document_id) {
367
- let endpoint_name = `/documents/${document_id}/`;
368
- let request_arguments = {"id": document_id};
369
- return this._request("DELETE", endpoint_name, request_arguments);
370
- }
371
-
372
- /**
373
- * Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` and etc.
374
- * @example
375
- * veryfi_client.update_document(id, {date:"2021-01-01", notes:"look what I did"})
376
- *
377
- * @memberof Client
378
- * @param {string} document_id ID of the document you'd like to update
379
- * @param {Object} kwargs fields to update
380
- * @return {JSON} A document json with updated fields, if fields are writable. Otherwise a document with unchanged fields.
381
- */
382
- Client.prototype.update_document = async function (document_id, {...kwargs} = {}) {
383
- let endpoint_name = `/documents/${document_id}/`;
384
- let response = await this._request("PUT", endpoint_name, kwargs);
385
- return response['data'];
386
- }
387
-
388
- /**
389
- * Get all w2 documents.
390
- * @memberOf Client
391
- * @param {int} page number, response is capped to maximum of 50 results per page.
392
- * @return {Array} An array of JSON with all w2 documents.
393
- */
394
- Client.prototype.get_w2_documents = async function (page = null) {
395
- this._check_w2_version();
396
- let endpoint_name = "/w2s/";
397
- let request_arguments = {};
398
- let params = {};
399
- if (page !== null) {
400
- params = {"page": page};
401
- }
402
- let response = await this._request("GET", endpoint_name, request_arguments, params);
403
- return response['data']['results'];
404
- }
405
-
406
- /**
407
- * Get a w2 document
408
- * @memberOf Client
409
- * @param {string} document_id ID of the document you'd like to retrieve
410
- * @returns {JSON} Data extracted from the Document
411
- */
412
- Client.prototype.get_w2_document = async function (
413
- document_id,
414
- ) {
415
- this._check_w2_version();
416
- let endpoint_name = `/w2s/${document_id}/`;
417
- let request_arguments = {"id": document_id};
418
- let response = await this._request("GET", endpoint_name, request_arguments);
419
- return response['data'];
420
- }
421
-
422
- /**
423
- * Upload a document from a buffer.
424
- * @memberOf Client
425
- * @param {String} file_name The file name including the extension
426
- * @param {String} file_buffer Buffer of a file to submit for data extraction
427
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
428
- * @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.
429
- * @param {Object} kwargs Additional request parameters
430
- * @return {JSON} Data extracted from the document.
431
- */
432
- Client.prototype.process_w2_document_from_buffer = async function (
433
- file_name,
434
- file_buffer,
435
- delete_after_processing = null,
436
- max_pages_to_process = null,
437
- {...kwargs} = {}
438
- ) {
439
- this._check_w2_version()
440
- let endpoint_name = "/w2s/"
441
- let request_arguments = {
442
- "file_name": file_name,
443
- "file_data": file_buffer,
444
- "auto_delete": delete_after_processing,
445
- "max_pages_to_process": max_pages_to_process,
446
- }
447
- request_arguments = Object.assign(request_arguments, kwargs);
448
- let response = await this._request("POST", endpoint_name, request_arguments);
449
- return response['data'];
450
- }
451
-
452
- /**
453
- * Upload a document from a file path
454
- * @param {String} file_path Path on disk to a file to submit for data extraction
455
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
456
- * @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.
457
- * @param {Object} kwargs Additional request parameters
458
- * @return {JSON} Data extracted from the document.
459
- */
460
- Client.prototype.process_w2_document = async function (
461
- file_path,
462
- delete_after_processing = false,
463
- max_pages_to_process = 1,
464
- {...kwargs} = {}
465
- ) {
466
- const file_name = path.basename(file_path)
467
- const image_file = fs.readFileSync(file_path, {encoding: 'base64'})
468
- const base64_encoded_string = Buffer.from(image_file).toString('utf-8')
469
- return this.process_w2_document_from_buffer(
470
- file_name,
471
- base64_encoded_string,
472
- delete_after_processing,
473
- max_pages_to_process,
474
- kwargs
475
- );
476
- }
477
-
478
- /**
479
- * Process a w2 document from an url.
480
- * @memberOf Client
481
- * @param {String} file_name The file name including the extension
482
- * @memberof Client
483
- * @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".
484
- * @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"]
485
- * @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
486
- * @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.
487
- * @param {Object} kwargs Additional request parameters
488
- * @return {JSON} Data extracted from the document.
489
- */
490
- Client.prototype.process_w2_document_from_url = async function (
491
- file_name,
492
- file_url,
493
- file_urls = null,
494
- delete_after_processing = false,
495
- max_pages_to_process = 1,
496
- {...kwargs} = {}
497
- ) {
498
- this._check_w2_version()
499
- let endpoint_name = "/w2s/"
500
- let request_arguments = {
501
- "file_name": file_name,
502
- "auto_delete": delete_after_processing,
503
- "file_url": file_url,
504
- "file_urls": file_urls,
505
- "max_pages_to_process": max_pages_to_process
506
- }
507
- request_arguments = Object.assign(request_arguments, kwargs);
508
- let response = await this._request("POST", endpoint_name, request_arguments);
509
- return response['data'];
510
- }
511
-
512
- /**
513
- * Add a new tag on an existing document
514
- *
515
- * @param {number} document_id ID of the document you'd like to add a Tag
516
- * @param {string} tag name to add
517
- * @return {JSON} response about tag added.
518
- */
519
- Client.prototype.add_tag = async function (document_id, tag) {
520
- let endpoint_name = `/documents/${document_id}/tags/`;
521
- let request_arguments = {"name": tag};
522
- let response = await this._request("PUT", endpoint_name, request_arguments);
523
- return response['data'];
524
- }
525
-
526
- /**
527
- * Delete all the tags on an existing document
528
- *
529
- * @param {number} document_id ID of the document you'd like to delete tags
530
- * @return {JSON} response about deleted tags.
531
- */
532
- Client.prototype.delete_tags = async function (document_id) {
533
- let endpoint_name = `/documents/${document_id}/tags/`;
534
- let request_arguments = {};
535
- return this._request("DELETE", endpoint_name, request_arguments);
536
- }
537
-
538
- /**
539
- * Replace multiple tags on an existing document
540
- *
541
- * @param {number} document_id ID of the document you'd like to add a Tag
542
- * @param {string[]} tags array of tags to be added
543
- * @return {JSON} response about tag added.
544
- */
545
- Client.prototype.replace_tags = async function (document_id, tags) {
546
- let endpoint_name = `/documents/${document_id}/`;
547
- let request_arguments = {"tags": tags};
548
- let response = await this._request("PUT", endpoint_name, request_arguments);
549
- return response['data'];
550
- }
551
-
552
- /**
553
- * Add multiple tags on an existing document
554
- *
555
- * @param {number} document_id ID of the document you'd like to add a Tag
556
- * @param {string[]} tags array of tags to be added
557
- * @return {JSON} response about tag added.
558
- */
559
- Client.prototype.add_tags = async function (document_id, tags) {
560
- let endpoint_name = `/documents/${document_id}/tags/`;
561
- let request_arguments = {"tags": tags};
562
- let response = await this._request("POST", endpoint_name, request_arguments);
563
- return response['data'];
564
- }
565
-
566
-
567
- // Exports
568
-
569
- module.exports = Client;