Skip to content

Commit 3ac0d86

Browse files
authored
Merge pull request #43 from veryfi/feature/LP-949-update-nodejs
Feature/lp 949 update nodejs
2 parents f5dcc78 + 2bfac5c commit 3ac0d86

7 files changed

Lines changed: 517 additions & 15 deletions

File tree

lib/main.js

Lines changed: 216 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Client.prototype._check_w2_version = function () {
6767
*/
6868
Client.prototype._get_headers = function (has_files = false) {
6969
let final_headers = {
70-
"User-Agent": "Node.js Veryfi-Nodejs/1.3.1",
70+
"User-Agent": "Node.js Veryfi-Nodejs/1.3.2",
7171
"Accept": "application/json",
7272
"Content-Type": "application/json",
7373
"Client-Id": this.client_id,
@@ -174,7 +174,13 @@ Client.prototype._request = async function (http_verb, endpoint_name, request_ar
174174
* @memberof Client
175175
* @returns {JSON} JSON object of previously processed documents
176176
*/
177-
Client.prototype.get_documents = async function () {
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+
) {
178184
let endpoint_name = "/documents/";
179185
let request_arguments = {};
180186
let documents = await this._request("GET", endpoint_name, request_arguments);
@@ -563,6 +569,214 @@ Client.prototype.add_tags = async function (document_id, tags) {
563569
return response['data'];
564570
}
565571

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+
566780

567781
// Exports
568782

0 commit comments

Comments
 (0)