Skip to content

Feature/lp 949 update nodejs #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 216 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Client.prototype._check_w2_version = function () {
*/
Client.prototype._get_headers = function (has_files = false) {
let final_headers = {
"User-Agent": "Node.js Veryfi-Nodejs/1.3.1",
"User-Agent": "Node.js Veryfi-Nodejs/1.3.2",
"Accept": "application/json",
"Content-Type": "application/json",
"Client-Id": this.client_id,
Expand Down Expand Up @@ -174,7 +174,13 @@ Client.prototype._request = async function (http_verb, endpoint_name, request_ar
* @memberof Client
* @returns {JSON} JSON object of previously processed documents
*/
Client.prototype.get_documents = async function () {
Client.prototype.get_documents = async function (
page = 1,
page_size = 50,
bounding_boxes = false,
confidence_details = false,
{...kwargs} = {}
) {
let endpoint_name = "/documents/";
let request_arguments = {};
let documents = await this._request("GET", endpoint_name, request_arguments);
Expand Down Expand Up @@ -563,6 +569,214 @@ Client.prototype.add_tags = async function (document_id, tags) {
return response['data'];
}

/**
* Process any document and extract all the fields from it
* @example
* veryfi_client.process_any_document('file/path','blue_print')
*
* @memberof Client
* @param {String} file_path Path on disk to a file to submit for data extraction
* @param {String} template_name name of the extraction templates.
* @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_any_document = async function (
file_path,
template_name,
max_pages_to_process = 20,
{...kwargs} = {}
) {

let endpoint_name = "/any-documents/";
let file_name = path.basename(file_path);
const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
let request_arguments = {
"file_name": file_name,
"file_data": base64_encoded_string,
"template_name": template_name,
"max_pages_to_process": max_pages_to_process,
};
request_arguments = Object.assign(request_arguments, kwargs);
let document = await this._request("POST", endpoint_name, request_arguments);
return document['data'];
}

/**
* Process any document and extract all the fields from it
* @example
* veryfi_client.process_any_document_url('file_url','blue_print')
*
* @memberof Client
* @param {String} file_url url file to submit for data extraction
* @param {String} template_name name of the extraction templates.
* @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_any_document_url = async function (
file_url,
template_name,
max_pages_to_process = 20,
{...kwargs} = {}
) {

let endpoint_name = "/any-documents/";
let request_arguments = {
"file_url": file_url,
"template_name": template_name,
"max_pages_to_process": max_pages_to_process,
};
request_arguments = Object.assign(request_arguments, kwargs);
let document = await this._request("POST", endpoint_name, request_arguments);
return document['data'];
}

/**
* Get all any documents
* @memberof Client
* @param {number} page The page number. The response is capped to maximum of 50 results per page.
* @param {number} page_size The number of Documents per page.
* @returns {JSON} Object of previously processed any documents
*/
Client.prototype.get_any_documents = async function (
page = 1,
page_size = 50) {
let endpoint_name = "/any-documents/";
let request_arguments = {"page": page, "page_size": page_size};
let documents = await this._request("GET", endpoint_name, request_arguments);
if ("data" in documents) {
documents = documents["data"];
}
return documents;
}

/**
* Get a specific any document
* @memberof Client
* @param {number} document_id The unique identifier of the document.
* @returns {JSON} Object of a previously processed blueprinted document.
*/
Client.prototype.get_any_document = async function (document_id) {
let endpoint_name = `/any-documents/${document_id}/`;
let request_arguments = {};
let document = await this._request("GET", endpoint_name, request_arguments);
return document['data'];
}

/**
* Get a specific bank statement
* @memberof Client
* @param {number} document_id The unique identifier of the document.
* @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
* @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
* @returns {JSON} Object of a previously processed blueprinted document.
*/
Client.prototype.get_bank_statement = async function (
document_id,
bounding_boxes = false,
confidence_details = false
) {
let endpoint_name = `/bank-statements/${document_id}/`;
let request_arguments = {
"bounding_boxes": bounding_boxes,
"confidence_details": confidence_details
};
let document = await this._request("GET", endpoint_name, request_arguments);
return document['data'];
}

/**
* Get all bank statements
* @memberof Client
* @param {number} page The page number. The response is capped to maximum of 50 results per page.
* @param {number} page_size The number of Documents per page.
* @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
* @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
* @returns {JSON} Object of previously processed any documents
*/
Client.prototype.get_bank_statements = async function (
page = 1,
page_size = 50,
bounding_boxes = false,
confidence_details = false
) {
let endpoint_name = `/bank-statements/`;
let request_arguments = {
"page": page,
"page_size": page_size,
"bounding_boxes": bounding_boxes,
"confidence_details": confidence_details
};
let document = await this._request("GET", endpoint_name, request_arguments);
return document['data'];
}

/**
* Process bank statement and extract all the fields from it
* @example
* veryfi_client.process_bank_statement('file_path')
*
* @memberof Client
* @param {String} file_path Path on disk to a file to submit for data extraction
* @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
* @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_bank_statement = async function (
file_path,
bounding_boxes = false,
confidence_details = false,
{...kwargs} = {}
) {

let endpoint_name = "/bank-statements/";
let file_name = path.basename(file_path);
const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
let request_arguments = {
"file_name": file_name,
"file_data": base64_encoded_string,
"bounding_boxes": bounding_boxes,
"confidence_details": confidence_details,
};
request_arguments = Object.assign(request_arguments, kwargs);
let document = await this._request("POST", endpoint_name, request_arguments);
return document['data'];
}

/**
* Process bank statement and extract all the fields from it
* @example
* veryfi_client.process_bank_statement_url('file_url')
*
* @memberof Client
* @param {String} file_url url file to submit for data extraction
* @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
* @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_bank_statement_url = async function (
file_url,
bounding_boxes = false,
confidence_details = false,
{...kwargs} = {}
) {

let endpoint_name = "/bank-statements/";
let request_arguments = {
"file_url": file_url,
"bounding_boxes": bounding_boxes,
"confidence_details": confidence_details,
};
request_arguments = Object.assign(request_arguments, kwargs);
let document = await this._request("POST", endpoint_name, request_arguments);
return document['data'];
}


// Exports

Expand Down
Loading