@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
@@ -0,0 +1,31 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process Check and extract all the fields from it. https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/
4
+ *
5
+ * @memberof Client
6
+ * @param {String} file_name The file name including the extension
7
+ * @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}
8
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
9
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
10
+ * @param {Object} kwargs Additional request parameters
11
+ * @returns {JSON} Data extracted from the document
12
+ */
13
+ Client.prototype.process_check_from_base64 = async function (
14
+ file_name,
15
+ file_base64_string,
16
+ bounding_boxes = false,
17
+ confidence_details = false,
18
+ {...kwargs} = {}
19
+ ) {
20
+
21
+ let endpoint_name = "/checks/";
22
+ let request_arguments = {
23
+ "file_name": file_name,
24
+ "file_data": file_base64_string,
25
+ "bounding_boxes": bounding_boxes,
26
+ "confidence_details": confidence_details,
27
+ };
28
+ request_arguments = Object.assign(request_arguments, kwargs);
29
+ let document = await this._request("POST", endpoint_name, request_arguments, null, false);
30
+ return document['data'];
31
+ }
@@ -0,0 +1,31 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process Check and extract all the fields from it. https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/
4
+ *
5
+ * @memberof Client
6
+ * @param {fs.ReadStream} file file to submit for data extraction
7
+ * @param {String} file_name The file name including the extension
8
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
9
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
10
+ * @param {Object} kwargs Additional request parameters
11
+ * @returns {JSON} Data extracted from the document
12
+ */
13
+ Client.prototype.process_check_from_stream = async function (
14
+ file,
15
+ file_name,
16
+ bounding_boxes = false,
17
+ confidence_details = false,
18
+ {...kwargs} = {}
19
+ ) {
20
+
21
+ let endpoint_name = "/checks/";
22
+ let request_arguments = {
23
+ "file": file,
24
+ "file_name": file_name,
25
+ "bounding_boxes": bounding_boxes,
26
+ "confidence_details": confidence_details,
27
+ };
28
+ request_arguments = Object.assign(request_arguments, kwargs);
29
+ let document = await this._request("POST", endpoint_name, request_arguments, null, true);
30
+ return document['data'];
31
+ }
@@ -0,0 +1,30 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process Check and extract all the fields from it. https://docs.veryfi.com/api/checks/process-a-check/
4
+ * @example
5
+ * veryfi_client.process_check_from_url('file_url')
6
+ *
7
+ * @memberof Client
8
+ * @param {String} file_url url file to submit for data extraction
9
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
10
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
11
+ * @param {Object} kwargs Additional request parameters
12
+ * @returns {JSON} Data extracted from the document
13
+ */
14
+ Client.prototype.process_check_from_url = async function (
15
+ file_url,
16
+ bounding_boxes = false,
17
+ confidence_details = false,
18
+ {...kwargs} = {}
19
+ ) {
20
+
21
+ let endpoint_name = "/checks/";
22
+ let request_arguments = {
23
+ "file_url": file_url,
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, false);
29
+ return document['data'];
30
+ }
@@ -0,0 +1,63 @@
1
+ const Client = require('../client/function');
2
+ require('../anydocs/deleteAnyDocument');
3
+ require('../anydocs/getAnyDocument');
4
+ require('../anydocs/getAnyDocuments');
5
+ require('../anydocs/processAnyDocument');
6
+ require('../anydocs/processAnyDocumentBase64');
7
+ require('../anydocs/processAnyDocumentStream');
8
+ require('../anydocs/processAnyDocumentUrl');
9
+ require('../bankstatements/deleteBankStatement');
10
+ require('../bankstatements/getBankStatement');
11
+ require('../bankstatements/getBankStatements');
12
+ require('../bankstatements/processBankStatement');
13
+ require('../bankstatements/processBankStatementBase64');
14
+ require('../bankstatements/processBankStatementStream');
15
+ require('../bankstatements/processBankStatementUrl');
16
+ require('../businesscards/deleteBusinessCard');
17
+ require('../businesscards/getBusinessCard');
18
+ require('../businesscards/getBusinessCards');
19
+ require('../businesscards/processBusinessCard');
20
+ require('../businesscards/processBusinessCardBase64');
21
+ require('../businesscards/processBusinessCardStream');
22
+ require('../businesscards/processBusinessCardUrl');
23
+ require('../checks/deleteCheck');
24
+ require('../checks/getCheck');
25
+ require('../checks/getChecks');
26
+ require('../checks/processCheck');
27
+ require('../checks/processCheckBase64');
28
+ require('../checks/processCheckStream');
29
+ require('../checks/processCheckUrl');
30
+ require('../documents/deleteDocument');
31
+ require('../documents/getDocument');
32
+ require('../documents/getDocuments');
33
+ require('../documents/processDocument');
34
+ require('../documents/processDocumentBase64');
35
+ require('../documents/processDocumentStream');
36
+ require('../documents/processDocumentUrl');
37
+ require('../documents/updateDocument');
38
+ require('../documents/tags/addTags');
39
+ require('../documents/tags/addTag');
40
+ require('../documents/tags/deleteTags');
41
+ require('../documents/tags/replaceTags');
42
+ require('../w2s/deleteW2');
43
+ require('../w2s/getW2');
44
+ require('../w2s/getW2s');
45
+ require('../w2s/processW2');
46
+ require('../w2s/processW2Base64');
47
+ require('../w2s/processW2Stream');
48
+ require('../w2s/processW2Url');
49
+ require('../w8bene/deleteW8BENE');
50
+ require('../w8bene/getW8BENE');
51
+ require('../w8bene/getW8BENEs');
52
+ require('../w8bene/processW8BENE');
53
+ require('../w8bene/processW8BENEBase64');
54
+ require('../w8bene/processW8BENEStream');
55
+ require('../w8bene/processW8BENEUrl');
56
+ require('../w9s/deleteW9');
57
+ require('../w9s/getW9');
58
+ require('../w9s/getW9s');
59
+ require('../w9s/processW9');
60
+ require('../w9s/processW9Base64');
61
+ require('../w9s/processW9Stream');
62
+ require('../w9s/processW9Url');
63
+ module.exports = Client;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Create instance of a Client
3
+ * @class
4
+ * @param {string} client_id Your Veryfi client id
5
+ * @param {string | undefined} client_secret Your Veryfi client secret
6
+ * @param {string} username Your Veryfi username
7
+ * @param {string} api_key Your Veryfi API key
8
+ * @param {string} base_url
9
+ * @param {Number} timeout
10
+ */
11
+ function Client(
12
+ client_id,
13
+ client_secret,
14
+ username,
15
+ api_key,
16
+ base_url = "https://api.veryfi.com/",
17
+ timeout = 120) {
18
+ this.client_id = client_id;
19
+ this.client_secret = client_secret;
20
+ this.username = username;
21
+ this.api_key = api_key;
22
+ this.base_url = base_url;
23
+ this.timeout = timeout;
24
+ this.api_version = "v8";
25
+ }
26
+
27
+ module.exports = Client;
@@ -0,0 +1,6 @@
1
+ const Client = require('../client/constructor');
2
+ require('../client/generateSignature');
3
+ require('../client/getHeaders');
4
+ require('../client/getUrl');
5
+ require('../client/request');
6
+ module.exports = Client;
@@ -0,0 +1,26 @@
1
+ const Client = require('../client/constructor');
2
+ const {createHmac} = require('crypto');
3
+ /**
4
+ * Generate unique signature for payload params.
5
+ * @private
6
+ * @param {{}} payload_params JSON params to be sent to API request
7
+ * @param {Number} timestamp Unix Long timestamp
8
+ * @returns {string} Unique signature generated using the client_secret and the payload
9
+ */
10
+ Client.prototype._generate_signature = function (payload_params, timestamp) {
11
+ let payload = `timestamp:${timestamp}`;
12
+ for (let i = 0; i < Object.keys(payload_params).length; i++) {
13
+ let key = Object.keys(payload_params)[i];
14
+ let value = payload_params[key];
15
+ payload = `${payload},${key}:${value}`;
16
+ }
17
+ const secret_bytes = encodeURI(this.client_secret);
18
+ const payload_bytes = encodeURI(payload);
19
+ let hmac = createHmac('sha256', secret_bytes);
20
+ hmac.update(payload_bytes);
21
+ let tmp_signature = hmac.digest();
22
+ let base64_signature = Buffer.from(tmp_signature).toString('base64');
23
+ base64_signature = Buffer.from(base64_signature).toString('utf-8').trim();
24
+
25
+ return base64_signature;
26
+ }
@@ -0,0 +1,21 @@
1
+ const Client = require('../client/constructor');
2
+
3
+ /**
4
+ * Prepares the headers needed for a request.
5
+ * @private
6
+ * @param {Boolean} has_files Are there any files to be submitted as binary
7
+ * @return {Object} Dictionary with headers
8
+ */
9
+ Client.prototype._get_headers = function (has_files = false) {
10
+ let final_headers = {
11
+ "User-Agent": "Node.js Veryfi-Nodejs/1.4.1",
12
+ "Accept": "application/json",
13
+ "Content-Type": "application/json",
14
+ "Client-Id": this.client_id,
15
+ "Authorization": `apikey ${this.username}:${this.api_key}`,
16
+ };
17
+ if (has_files) {
18
+ final_headers["Content-Type"] = "multipart/form-data";
19
+ }
20
+ return final_headers;
21
+ }
@@ -0,0 +1,9 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Get API Base URL with API Version
4
+ * @private
5
+ * @returns {string} Base URL to Veryfi API
6
+ */
7
+ Client.prototype._get_url = function () {
8
+ return this.base_url + "api/" + this.api_version;
9
+ }
@@ -0,0 +1,58 @@
1
+ const Client = require('../client/constructor');
2
+ const axios = require('axios').default;
3
+ const FormData = require('form-data');
4
+ const {promisify} = require("util");
5
+
6
+ /**
7
+ * Submit the HTTP request.
8
+ * @private
9
+ * @param {string} http_verb HTTP Method
10
+ * @param {string} endpoint_name Endpoint name such as 'documents', 'users', etc.
11
+ * @param {{}} request_arguments JSON payload to send to Veryfi
12
+ * @param params {{}} query params.
13
+ * @param {Boolean} has_files Are there any files to be submitted as binary
14
+ * @returns {JSON} A JSON of the response data.
15
+ */
16
+ Client.prototype._request = async function (http_verb, endpoint_name, request_arguments, params = {}, has_files = false) {
17
+ let headers = this._get_headers(has_files);
18
+ let api_url = `${this._get_url()}/partner${endpoint_name}`;
19
+
20
+ if (this.client_secret) {
21
+ let timestamp = Date.now();
22
+ let signature = this._generate_signature(request_arguments, timestamp);
23
+ headers = Object.assign(headers, {
24
+ "X-Veryfi-Request-Timestamp": timestamp,
25
+ "X-Veryfi-Request-Signature": signature
26
+ });
27
+ }
28
+
29
+ if (has_files) {
30
+ const formData = new FormData();
31
+ Object.entries(request_arguments).forEach(([key, value]) => {
32
+ if (value != null) {
33
+ formData.append(key, key === "file" ? value : value.toString());
34
+ }
35
+ });
36
+ headers = Object.assign(headers, formData.getHeaders());
37
+ const getLength = promisify(formData.getLength).bind(formData);
38
+ headers['Content-Length'] = await getLength()
39
+ request_arguments = formData;
40
+ } else {
41
+ request_arguments = JSON.stringify(request_arguments);
42
+ }
43
+ try {
44
+ return await axios.request({
45
+ method: http_verb,
46
+ maxBodyLength: Infinity,
47
+ url: api_url,
48
+ headers: headers,
49
+ data: request_arguments,
50
+ timeout: this.timeout * 1000,
51
+ params: params
52
+ });
53
+ } catch (response) {
54
+ let errorStatus = response?.response?.status;
55
+ let errorInfo = response?.response?.data;
56
+ throw new Error(`Error: ${errorStatus} ${JSON.stringify(errorInfo)}`);
57
+ }
58
+ }
@@ -0,0 +1,12 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Delete document from Veryfi. https://docs.veryfi.com/api/receipts-invoices/delete-a-document/
4
+ *
5
+ * @memberof Client
6
+ * @param {string} document_id ID of the document you'd like to delete
7
+ */
8
+ Client.prototype.delete_document = async function (document_id) {
9
+ let endpoint_name = `/documents/${document_id}/`;
10
+ let request_arguments = {"id": document_id};
11
+ return this._request("DELETE", endpoint_name, request_arguments);
12
+ }
@@ -0,0 +1,14 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Retrieve document by ID. https://docs.veryfi.com/api/receipts-invoices/get-a-document/
4
+ * @memberof Client
5
+ * @param {string} document_id ID of the document you'd like to retrieve
6
+ * @param {Object} kwargs Additional request parameters
7
+ * @returns {JSON} Data extracted from the Document
8
+ */
9
+ Client.prototype.get_document = async function (document_id, {...kwargs} = {}) {
10
+ let endpoint_name = `/documents/${document_id}/`;
11
+ let request_arguments = {"id": document_id};
12
+ let document = await this._request("GET", endpoint_name, request_arguments, kwargs, false);
13
+ return document['data'];
14
+ }
@@ -0,0 +1,31 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Get JSON of documents. https://docs.veryfi.com/api/receipts-invoices/search-documents/
4
+ * @memberof Client
5
+ * @param {number} page The page number. The response is capped to maximum of 50 results per page.
6
+ * @param {number} page_size The number of Documents per page.
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} JSON object of previously processed documents
11
+ */
12
+ Client.prototype.get_documents = async function (
13
+ page = 1,
14
+ page_size = 50,
15
+ bounding_boxes = false,
16
+ confidence_details = false,
17
+ {...kwargs} = {}
18
+ ) {
19
+ let endpoint_name = "/documents/";
20
+ let request_arguments = {
21
+ "page": page,
22
+ "page_size": page_size,
23
+ "bounding_boxes": bounding_boxes,
24
+ "confidence_details": confidence_details,
25
+ };
26
+ let documents = await this._request("GET", endpoint_name, request_arguments, kwargs, false);
27
+ if ("data" in documents) {
28
+ documents = documents["data"];
29
+ }
30
+ return documents;
31
+ }
@@ -0,0 +1,37 @@
1
+ const Client = require('../client/constructor');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ /**
5
+ * Process a document and extract all the fields from it. https://docs.veryfi.com/api/receipts-invoices/process-a-document/
6
+ * @example
7
+ * veryfi_client.process_document('file/path',
8
+ * ['Entertainment','Food'],
9
+ * true,
10
+ * {"extra":"parameters"})
11
+ *
12
+ * @memberof Client
13
+ * @param {String} file_path Path on disk to a file to submit for data extraction
14
+ * @param {Array} categories List of categories Veryfi can use to categorize the document
15
+ * @param {Boolean} auto_delete Delete this document from Veryfi after data has been extracted
16
+ * @param {Object} kwargs Additional request parameters
17
+ * @returns {JSON} Data extracted from the document
18
+ */
19
+ Client.prototype.process_document = async function (
20
+ file_path,
21
+ categories = null,
22
+ auto_delete = false,
23
+ {...kwargs} = {}
24
+ ) {
25
+
26
+ let file = fs.createReadStream(file_path);
27
+ let file_name = path.basename(file_path);
28
+
29
+ return this.process_document_from_stream(
30
+ file,
31
+ file_name,
32
+ categories,
33
+ auto_delete,
34
+ kwargs
35
+ );
36
+ }
37
+ module.exports = Client;
@@ -0,0 +1,37 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process a document and extract all the fields from it. https://docs.veryfi.com/api/receipts-invoices/process-a-document/
4
+ * @example
5
+ * veryfi_client.process_document_from_base64('base64_encoded_string',
6
+ * 'receipt.png',
7
+ * ['Entertainment','Food'],
8
+ * true,
9
+ * {'extra': 'parameters'})
10
+ *
11
+ * @memberof Client
12
+ * @param {String} base64_encoded_string Buffer string of a file to submit for data extraction
13
+ * @param {String} file_name The file name including the extension
14
+ * @param {Array} categories List of categories Veryfi can use to categorize the document
15
+ * @param {Boolean} auto_delete Delete this document from Veryfi after data has been extracted
16
+ * @param {Object} kwargs Additional request parameters
17
+ * @returns {JSON} Data extracted from the document
18
+ */
19
+ Client.prototype.process_document_from_base64 = async function (
20
+ base64_encoded_string,
21
+ file_name,
22
+ categories = null,
23
+ auto_delete = false,
24
+ {...kwargs} = {}
25
+ ) {
26
+
27
+ let endpoint_name = "/documents/";
28
+ let request_arguments = {
29
+ "file_name": file_name,
30
+ "file_data": base64_encoded_string,
31
+ "categories": categories,
32
+ "auto_delete": auto_delete,
33
+ };
34
+ request_arguments = Object.assign(request_arguments, kwargs);
35
+ let document = await this._request("POST", endpoint_name, request_arguments, null, false);
36
+ return document['data'];
37
+ }
@@ -0,0 +1,33 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process a document and extract all the fields from it. https://docs.veryfi.com/api/receipts-invoices/process-a-document/
4
+ * @example
5
+ * veryfi_client.process_document_stream('ReadStream',
6
+ * 'receipt.png',
7
+ * ['Entertainment','Food'],
8
+ * true,
9
+ * {'extra': 'parameters'})
10
+ *
11
+ * @memberof Client
12
+ * @param {ReadStream} file ReadStream of a file to submit for data extraction
13
+ * @param {String} file_name The file name including the extension
14
+ * @param {Boolean} auto_delete Delete this document from Veryfi after data has been extracted
15
+ * @param {Object} kwargs Additional request parameters
16
+ * @returns {JSON} Data extracted from the document
17
+ */
18
+ Client.prototype.process_document_from_stream = async function (
19
+ file,
20
+ file_name,
21
+ auto_delete = false,
22
+ {...kwargs} = {}
23
+ ) {
24
+ let endpoint_name = "/documents/";
25
+ let request_arguments = {
26
+ "file": file,
27
+ "file_name": file_name,
28
+ "auto_delete": auto_delete
29
+ };
30
+ request_arguments = Object.assign(request_arguments, kwargs);
31
+ let document = await this._request("POST", endpoint_name, request_arguments, null, true);
32
+ return document['data'];
33
+ }
@@ -0,0 +1,41 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * Process document from url and extract all the fields from it. https://docs.veryfi.com/api/receipts-invoices/process-a-document/
4
+ * @example
5
+ * veryfi_client.process_document_from_url('https://cdn.example.com/receipt.jpg')
6
+ *
7
+ * @memberof Client
8
+ * @param {string|null} file_url Required if file_urls isn't specified. Publicly accessible URL to a file, e.g. "https://cdn.example.com/receipt.jpg".
9
+ * @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"]
10
+ * @param {Array} categories List of categories to use when categorizing the document
11
+ * @param {boolean} auto_delete Delete this document from Veryfi after data has been extracted
12
+ * @param {boolean} 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
13
+ * @param {string|null} external_id Optional custom document identifier. Use this if you would like to assign your own ID to documents
14
+ * @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.
15
+ * @param {Object} kwargs Additional request parameters
16
+ * @return {JSON} Data extracted from the document.
17
+ */
18
+ Client.prototype.process_document_from_url = async function (
19
+ file_url = null,
20
+ file_urls = null,
21
+ categories = null,
22
+ auto_delete = false,
23
+ boost_mode = false,
24
+ external_id = null,
25
+ max_pages_to_process = 1,
26
+ {...kwargs} = {},
27
+ ) {
28
+ let endpoint_name = "/documents/";
29
+ let request_arguments = {
30
+ "auto_delete": auto_delete,
31
+ "boost_mode": boost_mode,
32
+ "categories": categories,
33
+ "external_id": external_id,
34
+ "file_url": file_url,
35
+ "file_urls": file_urls,
36
+ "max_pages_to_process": max_pages_to_process,
37
+ };
38
+ request_arguments = Object.assign(request_arguments, kwargs);
39
+ let response = await this._request("POST", endpoint_name, request_arguments, null, false);
40
+ return response['data'];
41
+ }
@@ -0,0 +1,14 @@
1
+ const Client = require('../../client/constructor');
2
+ /**
3
+ * Add a new tag on an existing document. https://docs.veryfi.com/api/receipts-invoices/add-a-tag-to-a-document/
4
+ *
5
+ * @param {number} document_id ID of the document you'd like to add a Tag
6
+ * @param {string} tag name to add
7
+ * @return {JSON} response about tag added.
8
+ */
9
+ Client.prototype.add_tag = async function (document_id, tag) {
10
+ let endpoint_name = `/documents/${document_id}/tags/`;
11
+ let request_arguments = {"name": tag};
12
+ let response = await this._request("PUT", endpoint_name, request_arguments);
13
+ return response['data'];
14
+ }
@@ -0,0 +1,14 @@
1
+ const Client = require('../../client/constructor');
2
+ /**
3
+ * Add multiple tags on an existing document. https://docs.veryfi.com/api/receipts-invoices/add-tags-to-a-document/
4
+ *
5
+ * @param {number} document_id ID of the document you'd like to add a Tag
6
+ * @param {string[]} tags array of tags to be added
7
+ * @return {JSON} response about tag added.
8
+ */
9
+ Client.prototype.add_tags = async function (document_id, tags) {
10
+ let endpoint_name = `/documents/${document_id}/tags/`;
11
+ let request_arguments = {"tags": tags};
12
+ let response = await this._request("POST", endpoint_name, request_arguments);
13
+ return response['data'];
14
+ }
@@ -0,0 +1,12 @@
1
+ const Client = require('../../client/constructor');
2
+ /**
3
+ * Delete all the tags on an existing document. https://docs.veryfi.com/api/receipts-invoices/unlink-all-tags-from-a-document/
4
+ *
5
+ * @param {number} document_id ID of the document you'd like to delete tags
6
+ * @return {JSON} response about deleted tags.
7
+ */
8
+ Client.prototype.delete_tags = async function (document_id) {
9
+ let endpoint_name = `/documents/${document_id}/tags/`;
10
+ let request_arguments = {};
11
+ return this._request("DELETE", endpoint_name, request_arguments);
12
+ }
@@ -0,0 +1,14 @@
1
+ const Client = require('../../client/constructor');
2
+ /**
3
+ * Replace multiple tags on an existing document. https://docs.veryfi.com/api/receipts-invoices/add-tags-to-a-document/
4
+ *
5
+ * @param {number} document_id ID of the document you'd like to add a Tag
6
+ * @param {string[]} tags array of tags to be added
7
+ * @return {JSON} response about tag added.
8
+ */
9
+ Client.prototype.replace_tags = async function (document_id, tags) {
10
+ let endpoint_name = `/documents/${document_id}/`;
11
+ let request_arguments = {"tags": tags};
12
+ let response = await this._request("PUT", endpoint_name, request_arguments);
13
+ return response['data'];
14
+ }
@@ -0,0 +1,17 @@
1
+ const Client = require('../client/constructor');
2
+ /**
3
+ * https://docs.veryfi.com/api/receipts-invoices/update-a-document/
4
+ * Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` and etc.
5
+ * @example
6
+ * veryfi_client.update_document(id, {date:"2021-01-01", notes:"look what I did"})
7
+ *
8
+ * @memberof Client
9
+ * @param {string} document_id ID of the document you'd like to update
10
+ * @param {Object} kwargs fields to update
11
+ * @return {JSON} A document json with updated fields, if fields are writable. Otherwise a document with unchanged fields.
12
+ */
13
+ Client.prototype.update_document = async function (document_id, {...kwargs} = {}) {
14
+ let endpoint_name = `/documents/${document_id}/`;
15
+ let response = await this._request("PUT", endpoint_name, kwargs);
16
+ return response['data'];
17
+ }
@@ -0,0 +1,11 @@
1
+ import {BoundingElement} from "./BoundingElement";
2
+
3
+ export declare type BillTo = {
4
+ address?: null | string | BoundingElement;
5
+ email?: null | string | BoundingElement;
6
+ name?: null | string | BoundingElement;
7
+ parsed_address?: null | string;
8
+ phone_number?: null | number | string | BoundingElement;
9
+ reg_number?: null | number | string | BoundingElement;
10
+ vat_number?: null | number | string | BoundingElement;
11
+ };
@@ -0,0 +1,6 @@
1
+ export declare type BoundingElement = {
2
+ bounding_box?: null | number[];
3
+ bounding_region?: null | number[];
4
+ rotation?: null | number;
5
+ value?: null | number | string;
6
+ }