Socket
Socket
Sign inDemoInstall

@veryfi/veryfi-sdk

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@veryfi/veryfi-sdk - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

lib/types/main.d.ts

265

lib/main.js

@@ -5,3 +5,2 @@ const {createHmac} = require('crypto');

const fs = require('fs');
const VeryfiClientError = require('./errors');

@@ -15,14 +14,14 @@ /**

* @param {string} api_key Your Veryfi API key
* @param {string} base_url
* @param {string} api_version
* @param {Number} timeout
* @param {string} base_url
* @param {string} api_version
* @param {Number} timeout
*/
function Client(
client_id,
client_secret,
username,
api_key,
base_url="https://api.veryfi.com/api/",
api_version="v7",
timeout=120,) {
client_id,
client_secret,
username,
api_key,
base_url = "https://api.veryfi.com/",
api_version = "v8",
timeout = 120,) {
this.client_id = client_id;

@@ -53,2 +52,10 @@ this.client_secret = client_secret;

/**
* Check api version for w2 documents
* @private
* @throws if api_version is different to v8
*/
Client.prototype._check_w2_version = function () {
if (this.api_version !== "v8") throw Error("w2 is only supported on v8")
}

@@ -61,5 +68,5 @@ /**

*/
Client.prototype._get_headers = function (has_files=false){
Client.prototype._get_headers = function (has_files = false) {
let final_headers = {
"User-Agent": "Node.js Veryfi-Nodejs/1.1.4",
"User-Agent": "Node.js Veryfi-Nodejs/1.2.0",
"Accept": "application/json",

@@ -70,3 +77,3 @@ "Content-Type": "application/json",

};
if (has_files){
if (has_files) {
final_headers["Content-Type"] = "application/x-www-form-urlencoded";

@@ -82,4 +89,4 @@ }

*/
Client.prototype._get_url = function (){
return this.base_url + this.api_version;
Client.prototype._get_url = function () {
return this.base_url + "api/" + this.api_version;
}

@@ -94,5 +101,5 @@

*/
Client.prototype._generate_signature = function (payload_params, timestamp){
Client.prototype._generate_signature = function (payload_params, timestamp) {
let payload = `timestamp:${timestamp}`;
for (let i=0; i<Object.keys(payload_params).length; i++){
for (let i = 0; i < Object.keys(payload_params).length; i++) {
let key = Object.keys(payload_params)[i];

@@ -122,3 +129,3 @@ let value = payload_params[key];

*/
Client.prototype._request = async function (http_verb, endpoint_name, request_arguments, file_stream=null){
Client.prototype._request = async function (http_verb, endpoint_name, request_arguments, file_stream = null) {
let has_files = (Boolean(file_stream));

@@ -128,7 +135,9 @@ let headers = this._get_headers(has_files);

if (this.client_secret){
if (this.client_secret) {
let timestamp = Date.now();
let signature = this._generate_signature(request_arguments, timestamp);
headers = Object.assign(headers,{"X-Veryfi-Request-Timestamp": timestamp,
"X-Veryfi-Request-Signature": signature});
headers = Object.assign(headers, {
"X-Veryfi-Request-Timestamp": timestamp,
"X-Veryfi-Request-Signature": signature
});
}

@@ -139,3 +148,3 @@

} else {
Object.assign(headers,{...request_arguments});
Object.assign(headers, {...request_arguments});
}

@@ -152,5 +161,5 @@

} catch (response) {
let Err = new VeryfiClientError(response,response['response']['data']);
let err_msg = Err.from_response(response['response']);
throw new Error(err_msg['status'] + err_msg['error']);
let errorStatus = response['response']['status'];
let errorInfo = response['response']['data']['error'];
throw new Error(errorStatus + errorInfo);
}

@@ -165,8 +174,8 @@ }

*/
Client.prototype.get_documents = async function (){
Client.prototype.get_documents = async function () {
let endpoint_name = "/documents/";
let request_arguments = {};
let documents = await this._request("GET", endpoint_name, request_arguments);
if ("data" in documents){
return documents["data"];
if ("data" in documents) {
documents = documents["data"];
}

@@ -193,6 +202,6 @@ return documents;

* veryfi_client.process_document('file/path',
* ['Entertainment','Food'],
* true,
* ['Entertainment','Food'],
* true,
* {"extra":"parameters"})
*
*
* @memberof Client

@@ -206,10 +215,10 @@ * @param {String} file_path Path on disk to a file to submit for data extraction

Client.prototype.process_document = async function (
file_path,
categories = null,
delete_after_processing = false,
{...kwargs} = {}
) {
file_path,
categories = null,
delete_after_processing = false,
{...kwargs} = {}
) {
let endpoint_name = "/documents/";
if (!categories){
if (!categories) {
categories = this.CATEGORIES;

@@ -226,3 +235,3 @@ }

};
request_arguments = Object.assign(request_arguments,kwargs)
request_arguments = Object.assign(request_arguments, kwargs)
let document = await this._request("POST", endpoint_name, request_arguments)

@@ -237,6 +246,6 @@ return document['data'];

* 'receipt.png',
* ['Entertainment','Food'],
* true,
* ['Entertainment','Food'],
* true,
* {'extra': 'parameters'})
*
*
* @memberof Client

@@ -251,11 +260,11 @@ * @param {String} base64_encoded_string Buffer of a file to submit for data extraction

Client.prototype.process_document_buffer = async function (
base64_encoded_string,
file_name,
categories = null,
delete_after_processing = false,
{...kwargs} = {}
) {
base64_encoded_string,
file_name,
categories = null,
delete_after_processing = false,
{...kwargs} = {}
) {
let endpoint_name = "/documents/";
if (!categories){
if (!categories) {
categories = this.CATEGORIES;

@@ -269,3 +278,3 @@ }

};
request_arguments = Object.assign(request_arguments,kwargs)
request_arguments = Object.assign(request_arguments, kwargs)
let document = await this._request("POST", endpoint_name, request_arguments)

@@ -292,13 +301,13 @@ return document['data'];

Client.prototype.process_document_url = async function (
file_url = "",
file_urls = null,
categories = null,
delete_after_processing = false,
boost_mode = 0,
external_id = "",
max_pages_to_process = 1,
{...kwargs} = {},
) {
file_url = "",
file_urls = null,
categories = null,
delete_after_processing = false,
boost_mode = 0,
external_id = "",
max_pages_to_process = 1,
{...kwargs} = {},
) {
let endpoint_name = "/documents/";
if (!categories){
if (!categories) {
categories = this.CATEGORIES;

@@ -315,3 +324,3 @@ }

};
request_arguments = Object.assign(request_arguments,kwargs)
request_arguments = Object.assign(request_arguments, kwargs)
let response = await this._request("POST", endpoint_name, request_arguments);

@@ -323,11 +332,10 @@ return response['data'];

* Delete document from Veryfi
*
*
* @memberof Client
* @param {string} document_id ID of the document you'd like to delete
*/
Client.prototype.delete_document = async function (document_id){
Client.prototype.delete_document = async function (document_id) {
let endpoint_name = `/documents/${document_id}/`;
let request_arguments = {"id": document_id};
let response = await this._request("DELETE", endpoint_name, request_arguments);
return response;
return this._request("DELETE", endpoint_name, request_arguments);
}

@@ -339,3 +347,3 @@

* veryfi_client.update_document(id, {date:"2021-01-01", notes:"look what I did"})
*
*
* @memberof Client

@@ -346,3 +354,3 @@ * @param {string} document_id ID of the document you'd like to update

*/
Client.prototype.update_document = async function (document_id, {...kwargs} = {}){
Client.prototype.update_document = async function (document_id, {...kwargs} = {}) {
let endpoint_name = `/documents/${document_id}/`;

@@ -353,4 +361,123 @@ let response = await this._request("PUT", endpoint_name, kwargs);

/**
* Get all w2 documents.
* @memberOf Client
* @return {Array} An array of JSON with all w2 documents.
*/
Client.prototype.get_w2_documents = async function () {
this._check_w2_version()
let endpoint_name = "/w2s/"
let request_arguments = {}
let response = await this._request("GET", endpoint_name, request_arguments)
return response['data']['results']
}
/**
* Get a w2 document
* @memberOf Client
* @param {string} document_id ID of the document you'd like to retrieve
* @returns {JSON} Data extracted from the Document
*/
Client.prototype.get_w2_document = async function (
document_id,
) {
this._check_w2_version()
let endpoint_name = `/w2s/${document_id}/`
let request_arguments = {"id": document_id}
let response = await this._request("GET", endpoint_name, request_arguments)
return response['data']
}
/**
* Upload a document from a buffer.
* @memberOf Client
* @param {String} file_name The file name including the extension
* @param {String} file_buffer Buffer of a file to submit for data extraction
* @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
* @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.
* @param {Object} kwargs Additional request parameters
* @return {JSON} Data extracted from the document.
*/
Client.prototype.process_w2_document_from_buffer = async function (
file_name,
file_buffer,
delete_after_processing = null,
max_pages_to_process = null,
{...kwargs} = {}
) {
this._check_w2_version()
let endpoint_name = "/w2s/"
let request_arguments = {
"file_name": file_name,
"file_data": file_buffer,
"auto_delete": delete_after_processing,
"max_pages_to_process": max_pages_to_process,
}
request_arguments = Object.assign(request_arguments, kwargs)
let response = await this._request("POST", endpoint_name, request_arguments)
return response['data']
}
/**
* Upload a document from a file path
* @param {String} file_path Path on disk to a file to submit for data extraction
* @param {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
* @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.
* @param {Object} kwargs Additional request parameters
* @return {JSON} Data extracted from the document.
*/
Client.prototype.process_w2_document = async function (
file_path,
delete_after_processing = false,
max_pages_to_process = 1,
{...kwargs} = {}
) {
const 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')
return this.process_w2_document_from_buffer(
file_name,
base64_encoded_string,
delete_after_processing,
max_pages_to_process,
kwargs
)
}
/**
* Process a w2 document from an url.
* @memberOf Client
* @param {String} file_name The file name including the extension
* @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 {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 {boolean} delete_after_processing Delete this document from Veryfi after data has been extracted
* @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.
* @param {Object} kwargs Additional request parameters
* @return {JSON} Data extracted from the document.
*/
Client.prototype.process_w2_document_from_url = async function (
file_name,
file_url,
file_urls = null,
delete_after_processing = false,
max_pages_to_process = 1,
{...kwargs} = {}
) {
this._check_w2_version()
let endpoint_name = "/w2s/"
let request_arguments = {
"file_name": file_name,
"auto_delete": delete_after_processing,
"file_url": file_url,
"file_urls": file_urls,
"max_pages_to_process": max_pages_to_process
}
request_arguments = Object.assign(request_arguments, kwargs)
let response = await this._request("POST", endpoint_name, request_arguments)
return response['data']
}
// Exports
module.exports = Client;
{
"name": "@veryfi/veryfi-sdk",
"version": "1.1.5",
"version": "1.2.0",
"description": "Node.js module for communicating with the Veryfi OCR API",

@@ -10,3 +10,3 @@ "main": "lib/main.js",

"doc": "jsdoc -d docs --configure jsconf.json main.js",
"generate-docs": "jsdoc --configure .jsdoc.json --verbose"
"generate-docs": "jsdoc --configure jsdoc.json --verbose"
},

@@ -16,3 +16,4 @@ "author": "Veryfi <support@veryfi.com> (https://www.veryfi.com)",

"contributors": [
"Matthew Eng <matthew@veryfi.com>"
"Matthew Eng <matthew@veryfi.com>",
"Alejandro Uribe <alejandro@veryfi.com>"
],

@@ -22,3 +23,3 @@ "license": "MIT",

"lib",
"types"
"lib/types"
],

@@ -30,7 +31,13 @@ "directories": {

"devDependencies": {
"jest": "^27.0.5",
"jsdoc": "^3.6.7"
"jest": "^29.0.0",
"jsdoc": "^3.6.7",
"minami": "^1.2.3",
"ts-jest": "^29.0.1",
"typescript": "^4.8.3"
},
"dependencies": {
"axios": "^0.21.1"
"@jest/globals": "^29.0.3",
"axios": "^0.21.1",
"docdash": "^1.2.0",
"jest-config": "^29.0.3"
},

@@ -37,0 +44,0 @@ "repository": {

@@ -44,3 +44,3 @@ # Veryfi SDK for Node.js

The **veryfi** library can be used to communicate with Veryfi API. All available functionality is described here: <https://veryfi.github.io/veryfi-nodejs/Client.html>
The **veryfi** library can be used to communicate with Veryfi API. All available functionality is described here: <https://veryfi.github.io/veryfi-nodejs/>

@@ -255,2 +255,2 @@ Below is a sample script using **Veryfi** for OCR and extracting data from a document:

[![Veryfi Tutorial](https://img.youtube.com/vi/PcJdgnvyfBc/maxresdefault.jpg)](https://www.youtube.com/watch?v=PcJdgnvyfBc)
[![Veryfi Tutorial](https://img.youtube.com/vi/PcJdgnvyfBc/maxresdefault.jpg)](https://www.youtube.com/watch?v=PcJdgnvyfBc)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc