Skip to content
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
29 changes: 29 additions & 0 deletions lib/classify/classifyDocumentBase64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Client = require('../client/constructor');
/**
* Classify a document and extract all the fields from it. https://docs.veryfi.com/api/classify/classify-a-document/
* @example
* veryfi_client.classify_document_from_base64('base64_encoded_string',
* 'receipt.png',
* {'extra': 'parameters'})
*
* @memberof Client
* @param {String} base64_encoded_string Buffer string of a file to submit for classify extraction
* @param {String} file_name The file name including the extension
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the document
*/
Client.prototype.classify_document_from_base64 = async function (
base64_encoded_string,
file_name,
{...kwargs} = {}
) {

let endpoint_name = "/classify/";
let request_arguments = {
"file_name": file_name,
"file_data": base64_encoded_string,
};
request_arguments = Object.assign(request_arguments, kwargs);
let document = await this._request("POST", endpoint_name, request_arguments, null, false);
return document['data'];
}
26 changes: 26 additions & 0 deletions lib/classify/classifyDocumentUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Client = require('../client/constructor');
/**
* Classify document from url and extract all the fields from it. https://docs.veryfi.com/api/classify/classify-a-document/
* @example
* veryfi_client.classify_document_from_url('https://cdn.example.com/receipt.jpg')
*
* @memberof Client
* @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".
* @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"]
* @param {Object} kwargs Additional request parameters
* @return {JSON} Data extracted from the document.
*/
Client.prototype.classify_document_from_url = async function (
file_url = null,
file_urls = null,
{...kwargs} = {},
) {
let endpoint_name = "/classify/";
let request_arguments = {
"file_url": file_url,
"file_urls": file_urls,
};
request_arguments = Object.assign(request_arguments, kwargs);
let response = await this._request("POST", endpoint_name, request_arguments, null, false);
return response['data'];
}
6 changes: 6 additions & 0 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ require('../checks/processCheck');
require('../checks/processCheckBase64');
require('../checks/processCheckStream');
require('../checks/processCheckUrl');
require('../classify/classifyDocumentBase64');
require('../classify/classifyDocumentUrl');
require('../documents/deleteDocument');
require('../documents/getDocument');
require('../documents/getDocuments');
Expand All @@ -39,6 +41,10 @@ require('../documents/tags/addTags');
require('../documents/tags/addTag');
require('../documents/tags/deleteTags');
require('../documents/tags/replaceTags');
require('../split/splitDocumentBase64');
require('../split/splitDocumentUrl');
require('../split/getSplitDocument');
require('../split/getSplitDocuments');
require('../w2s/deleteW2');
require('../w2s/getW2');
require('../w2s/getW2s');
Expand Down
2 changes: 1 addition & 1 deletion lib/client/getHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Client = require('../client/constructor');
*/
Client.prototype._get_headers = function (has_files = false) {
let final_headers = {
"User-Agent": "Node.js Veryfi-Nodejs/1.4.5",
"User-Agent": "Node.js Veryfi-Nodejs/1.4.6",
"Accept": "application/json",
"Content-Type": "application/json",
"Client-Id": this.client_id,
Expand Down
14 changes: 14 additions & 0 deletions lib/split/getSplitDocument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Client = require('../client/constructor');
/**
* Veryfi's Get a Documents from PDF endpoint allows you to retrieve a collection of previously processed documents. https://docs.veryfi.com/api/receipts-invoices/get-documents-from-pdf/
* @memberof Client
* @param {string} document_id ID of the document you'd like to retrieve
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the Document
*/
Client.prototype.get_split_document = async function (document_id, {...kwargs} = {}) {
let endpoint_name = `/documents-set//${document_id}/`;
let request_arguments = {"id": document_id};
let document = await this._request("GET", endpoint_name, request_arguments, kwargs, false);
return document['data'];
}
25 changes: 25 additions & 0 deletions lib/split/getSplitDocuments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Client = require('../client/constructor');
/**
* Veryfi's Get a Submitted PDF endpoint allows you to retrieve a collection of previously processed documents. https://docs.veryfi.com/api/receipts-invoices/get-submitted-pdf/
* @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 {Object} kwargs Additional request parameters
* @returns {JSON} JSON object of previously processed documents
*/
Client.prototype.get_split_documents = async function (
page = 1,
page_size = 50,
{...kwargs} = {}
) {
let endpoint_name = "/documents-set/";
let request_arguments = {
"page": page,
"page_size": page_size
};
let documents = await this._request("GET", endpoint_name, request_arguments, kwargs, false);
if ("data" in documents) {
documents = documents["data"];
}
return documents;
}
29 changes: 29 additions & 0 deletions lib/split/splitDocumentBase64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Client = require('../client/constructor');
/**
* Split document PDF from url and extract all the fields from it. https://docs.veryfi.com/api/receipts-invoices/split-and-process-a-pdf/
* @example
* veryfi_client.split_document_from_base64('base64_encoded_string',
* 'receipt.png',
* {'extra': 'parameters'})
*
* @memberof Client
* @param {String} base64_encoded_string Buffer string of a file to submit for classify extraction
* @param {String} file_name The file name including the extension
* @param {Object} kwargs Additional request parameters
* @returns {JSON} Data extracted from the document
*/
Client.prototype.split_document_from_base64 = async function (
base64_encoded_string,
file_name,
{...kwargs} = {}
) {

let endpoint_name = "/documents-set/";
let request_arguments = {
"file_name": file_name,
"file_data": base64_encoded_string,
};
request_arguments = Object.assign(request_arguments, kwargs);
let document = await this._request("POST", endpoint_name, request_arguments, null, false);
return document['data'];
}
26 changes: 26 additions & 0 deletions lib/split/splitDocumentUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Client = require('../client/constructor');
/**
* Split document PDF from url and extract all the fields from it. https://docs.veryfi.com/api/receipts-invoices/split-and-process-a-pdf/
* @example
* veryfi_client.split_document_from_url('https://cdn.example.com/receipts.pdf')
*
* @memberof Client
* @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".
* @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"]
* @param {Object} kwargs Additional request parameters
* @return {JSON} Data extracted from the document.
*/
Client.prototype.split_document_from_url = async function (
file_url = null,
file_urls = null,
{...kwargs} = {},
) {
let endpoint_name = "/documents-set/";
let request_arguments = {
"file_url": file_url,
"file_urls": file_urls
};
request_arguments = Object.assign(request_arguments, kwargs);
let response = await this._request("POST", endpoint_name, request_arguments, null, false);
return response['data'];
}
89 changes: 89 additions & 0 deletions lib/types/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,95 @@ export declare class Client {
*/
public _request(http_verb: String, endpoint_name: String, request_arguments: Object, params: Object, has_files: boolean): Promise<any>;

/**
* Classify a document. https://docs.veryfi.com/api/classify/classify-a-document/
* @example
* veryfi_client.classify_document_from_base64('base64_encoded_string',
* 'receipt.png',
* {'extra': 'parameters'})
*
* @memberof Client
* @param {String} base64_encoded_string Buffer string of a file to submit for classify and data extraction
* @param {String} file_name The file name including the extension
* @param {Object} kwargs Additional request parameters
* @returns {JSON} JSON of document classification
*/
public classify_document_from_base64(
base64_encoded_string: string,
file_name: string,
{...kwargs}?: VeryfiExtraArgs
): Promise<JsonObject>;

/**
* Classify document. https://docs.veryfi.com/api/receipts-invoices/process-a-document/
* @memberof Client
* @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'.
* @param {string[]} 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']
* @param {VeryfiExtraArgs} kwargs Additional request parameters
* @returns {JSON} JSON of document classification
*/
public classify_document_from_url(
file_url?: string,
file_urls?: string[],
{...kwargs}?: VeryfiExtraArgs
): Promise<JsonObject>;

/**
* Veryfi's PDF Splitter allows you to split a multipage PDF with different receipts and invoices inside into multiple Documents. This API supports .pdf,.zip. Min file size is 250bytes. The max pdf file size is 50mb. https://docs.veryfi.com/api/receipts-invoices/split-and-process-a-pdf/
* @memberof Client
* @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'.
* @param {string[]} 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']
* @param {VeryfiExtraArgs} kwargs Additional request parameters
* @returns {JSON} JSON of document classification
*/
public split_document_from_url(
file_url?: string,
file_urls?: string[],
{...kwargs}?: VeryfiExtraArgs
): Promise<JsonObject>;

/**
* Veryfi's PDF Splitter allows you to split a multipage PDF with different receipts and invoices inside into multiple Documents. This API supports .pdf,.zip. Min file size is 250bytes. The max pdf file size is 50mb. https://docs.veryfi.com/api/receipts-invoices/split-and-process-a-pdf/
* @example
* veryfi_client.split_document_from_base64('base64_encoded_string',
* 'receipt.png',
* {'extra': 'parameters'})
*
* @memberof Client
* @param {String} base64_encoded_string Buffer string of a file to submit for classify and data extraction
* @param {String} file_name The file name including the extension
* @param {Object} kwargs Additional request parameters
* @returns {JSON} JSON of document classification
*/
public split_document_from_base64(
base64_encoded_string: string,
file_name: string,
{...kwargs}?: VeryfiExtraArgs
): Promise<JsonObject>;

/**
* Veryfi's Get a Documents from PDF endpoint allows you to retrieve a collection of previously processed documents. https://docs.veryfi.com/api/receipts-invoices/get-documents-from-pdf/
* @memberof Client
* @param {string} document_id ID of the document you'd like to retrieve
* @param {Object} kwargs Additional request parameters
* @returns {Promise<JsonObject>} Object of data extracted from the document
*/
public get_split_document(document_id: string,
{...kwargs}?: VeryfiExtraArgs): Promise<JsonObject>;

/**
* Veryfi's Get a Submitted PDF endpoint allows you to retrieve a collection of previously processed documents. https://docs.veryfi.com/api/receipts-invoices/get-submitted-pdf/
* @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 {Object} kwargs Additional request parameters
* @returns {Promise<JsonObject>} Object of previously processed documents
*/
public get_split_documents(
page?: number,
page_size?: number,
{...kwargs}?: VeryfiExtraArgs
): Promise<JsonObject>;

/**
* Delete document from Veryfi. https://docs.veryfi.com/api/receipts-invoices/delete-a-document/
Expand Down
8 changes: 8 additions & 0 deletions mocks/classify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": {
"document_type": {
"value": "receipt",
"score": 0.97
}
}
}
10 changes: 10 additions & 0 deletions mocks/getSplit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"id": 351609,
"documents_id": [
337479740,
337479769
],
"status": "processed"
}
}
72 changes: 72 additions & 0 deletions mocks/getSplits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"data": {
"count": 8,
"next": "",
"previous": "",
"results": [
{
"id": 351628,
"documents_id": [
337482927
],
"status": "processed"
},
{
"id": 351623,
"documents_id": [
337482669,
337482689
],
"status": "processed"
},
{
"id": 351622,
"documents_id": [
337482309,
337482338
],
"status": "processed"
},
{
"id": 351620,
"documents_id": [
337481974,
337481997
],
"status": "processed"
},
{
"id": 351619,
"documents_id": [
337481287,
337481307
],
"status": "processed"
},
{
"id": 351609,
"documents_id": [
337479740,
337479769
],
"status": "processed"
},
{
"id": 2098,
"documents_id": [
126516809,
126516810
],
"status": "processed"
},
{
"id": 2085,
"documents_id": [
126254495,
126254497
],
"status": "processed"
}
]
}
}
5 changes: 5 additions & 0 deletions mocks/split.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"id": 351609
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@veryfi/veryfi-sdk",
"version": "1.4.5",
"version": "1.4.6",
"description": "Node.js module for communicating with the Veryfi OCR API",
"main": "lib/client/client.js",
"typings": "lib/types/Client.ts",
Expand Down
Binary file added resources/split.pdf
Binary file not shown.
Loading