@veryfi/veryfi-sdk
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -10,3 +10,3 @@ const {createHmac} = require('crypto'); | ||
* @param {string} client_id Your Veryfi client id | ||
* @param {string} client_secret Your Veryfi client secret | ||
* @param {string | undefined} client_secret Your Veryfi client secret | ||
* @param {string} username Your Veryfi username | ||
@@ -54,3 +54,3 @@ * @param {string} api_key Your Veryfi API key | ||
* @private | ||
* @throws if api_version is different to v8 | ||
* @throws error when api_version is different to v8 | ||
*/ | ||
@@ -69,3 +69,3 @@ Client.prototype._check_w2_version = function () { | ||
let final_headers = { | ||
"User-Agent": "Node.js Veryfi-Nodejs/1.2.0", | ||
"User-Agent": "Node.js Veryfi-Nodejs/1.2.3", | ||
"Accept": "application/json", | ||
@@ -217,3 +217,3 @@ "Content-Type": "application/json", | ||
} | ||
let file_name = path.basename(file_path) | ||
let file_name = path.basename(file_path); | ||
const image_file = fs.readFileSync(file_path, {encoding: 'base64'}); | ||
@@ -227,4 +227,4 @@ const base64_encoded_string = Buffer.from(image_file).toString('utf-8'); | ||
}; | ||
request_arguments = Object.assign(request_arguments, kwargs) | ||
let document = await this._request("POST", endpoint_name, request_arguments) | ||
request_arguments = Object.assign(request_arguments, kwargs); | ||
let document = await this._request("POST", endpoint_name, request_arguments); | ||
return document['data']; | ||
@@ -268,4 +268,4 @@ } | ||
}; | ||
request_arguments = Object.assign(request_arguments, kwargs) | ||
let document = await this._request("POST", endpoint_name, request_arguments) | ||
request_arguments = Object.assign(request_arguments, kwargs); | ||
let document = await this._request("POST", endpoint_name, request_arguments); | ||
return document['data']; | ||
@@ -313,3 +313,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); | ||
@@ -354,11 +354,11 @@ return response['data']; | ||
Client.prototype.get_w2_documents = async function (page = null) { | ||
this._check_w2_version() | ||
let endpoint_name = "/w2s/" | ||
let request_arguments = {} | ||
let params = {} | ||
this._check_w2_version(); | ||
let endpoint_name = "/w2s/"; | ||
let request_arguments = {}; | ||
let params = {}; | ||
if (page !== null) { | ||
params = {"page": page} | ||
params = {"page": page}; | ||
} | ||
let response = await this._request("GET", endpoint_name, request_arguments, params) | ||
return response['data']['results'] | ||
let response = await this._request("GET", endpoint_name, request_arguments, params); | ||
return response['data']['results']; | ||
} | ||
@@ -375,7 +375,7 @@ | ||
) { | ||
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'] | ||
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']; | ||
} | ||
@@ -408,5 +408,5 @@ | ||
} | ||
request_arguments = Object.assign(request_arguments, kwargs) | ||
let response = await this._request("POST", endpoint_name, request_arguments) | ||
return response['data'] | ||
request_arguments = Object.assign(request_arguments, kwargs); | ||
let response = await this._request("POST", endpoint_name, request_arguments); | ||
return response['data']; | ||
} | ||
@@ -437,3 +437,3 @@ | ||
kwargs | ||
) | ||
); | ||
} | ||
@@ -470,9 +470,36 @@ | ||
} | ||
request_arguments = Object.assign(request_arguments, kwargs) | ||
let response = await this._request("POST", endpoint_name, request_arguments) | ||
return response['data'] | ||
request_arguments = Object.assign(request_arguments, kwargs); | ||
let response = await this._request("POST", endpoint_name, request_arguments); | ||
return response['data']; | ||
} | ||
/** | ||
* Add a new tag on an existing document | ||
* | ||
* @param {number} document_id ID of the document you'd like to add a Tag | ||
* @param {string} tag name to add | ||
* @return {JSON} response about tag added. | ||
*/ | ||
Client.prototype.add_tag = async function (document_id, tag) { | ||
let endpoint_name = `/documents/${document_id}/tags/`; | ||
let request_arguments = {"name": tag}; | ||
let response = await this._request("PUT", endpoint_name, request_arguments); | ||
return response['data']; | ||
} | ||
/** | ||
* Delete all the tags on an existing document | ||
* | ||
* @param {number} document_id ID of the document you'd like to delete tags | ||
* @return {JSON} response about deleted tags. | ||
*/ | ||
Client.prototype.delete_tags = async function (document_id) { | ||
let endpoint_name = `/documents/${document_id}/tags/`; | ||
let request_arguments = {}; | ||
return this._request("DELETE", endpoint_name, request_arguments); | ||
} | ||
// Exports | ||
module.exports = Client; |
@@ -125,2 +125,7 @@ /** | ||
declare type Tag = { | ||
id?: null | number; | ||
name?: null | string; | ||
}; | ||
export declare class Client { | ||
@@ -131,3 +136,3 @@ /** | ||
* @param {string} client_id Your Veryfi client id | ||
* @param {string} client_secret Your Veryfi client secret | ||
* @param {string | undefined} client_secret Your Veryfi client secret | ||
* @param {string} username Your Veryfi username | ||
@@ -141,3 +146,3 @@ * @param {string} api_key Your Veryfi API key | ||
client_id: string, | ||
client_secret: string, | ||
client_secret: string | undefined, | ||
username: string, | ||
@@ -152,3 +157,3 @@ api_key: string, | ||
client_secret: string; | ||
client_secret: string | undefined; | ||
@@ -241,6 +246,6 @@ username: string; | ||
*/ | ||
public delete_document(document_id: string): Promise<VeryfiDocument>; | ||
public delete_document(document_id: string): Promise<any>; | ||
/** | ||
* Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` and etc. | ||
* Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` etc. | ||
* @example | ||
@@ -260,2 +265,20 @@ * veryfi_client.update_document( | ||
): Promise<VeryfiDocument>; | ||
/** | ||
* Add a new tag on an existing document | ||
* | ||
* @param {number} document_id ID of the document you'd like to add a Tag | ||
* @param {string} tag name to add | ||
* @return {Promise<Tag>} response about tag added. | ||
*/ | ||
public add_tag(document_id: string, tag: string): Promise<Tag>; | ||
/** | ||
* Delete all tags on an existing document | ||
* | ||
* @param {number} document_id ID of the document you'd like to delete all Tags | ||
* @return {Promise<any>} response about deleted tags. | ||
*/ | ||
public delete_tags(document_id: string): Promise<any>; | ||
} | ||
@@ -267,3 +290,3 @@ | ||
* @param {string} client_id Your Veryfi client id | ||
* @param {string} client_secret Your Veryfi client secret | ||
* @param {string | undefined} client_secret Your Veryfi client secret | ||
* @param {string} username Your Veryfi username | ||
@@ -277,3 +300,3 @@ * @param {string} api_key Your Veryfi API key | ||
client_id: string, | ||
client_secret: string, | ||
client_secret: string | undefined, | ||
username: string, | ||
@@ -280,0 +303,0 @@ api_key: string, |
{ | ||
"name": "@veryfi/veryfi-sdk", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Node.js module for communicating with the Veryfi OCR API", | ||
"main": "lib/main.js", | ||
"typings": "types/main.d.ts", | ||
"typings": "lib/types/main.d.ts", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "test": "jest", |
# Veryfi SDK for Node.js | ||
<img src="https://user-images.githubusercontent.com/30125790/212157461-58bdc714-2f89-44c2-8e4d-d42bee74854e.png#gh-dark-mode-only" width="200"> | ||
<img src="https://user-images.githubusercontent.com/30125790/212157486-bfd08c5d-9337-4b78-be6f-230dc63838ba.png#gh-light-mode-only" width="200"> | ||
[![Node.js - version](https://img.shields.io/badge/node-%3E%3D%206.0.0-brightgreen)](https://www.npmjs.com/package/@veryfi/veryfi-sdk) | ||
@@ -7,4 +10,2 @@ [![npm](https://img.shields.io/badge/npm-v7.0.0-blue)](https://www.npmjs.com/package/@veryfi/veryfi-sdk) | ||
![Veryfi Logo](https://cdn.veryfi.com/logos/veryfi-logo-wide-github.png) | ||
## Table of Contents | ||
@@ -66,4 +67,5 @@ | ||
let veryfi_client = new Client(client_id, client_secret, username, api_key); | ||
let response = veryfi_client.process_document(file_path, categories=categories); | ||
console.log(response); | ||
let response = veryfi_client.process_document(file_path, categories=categories).then(response => { | ||
console.log(response) | ||
}); | ||
``` | ||
@@ -74,4 +76,5 @@ | ||
```js | ||
let response = veryfi_client.process_document_url(url, external_id=some_id); | ||
console.log(response); | ||
let response = veryfi_client.process_document_url(url, external_id=some_id).then(response => { | ||
console.log(response) | ||
}); | ||
``` | ||
@@ -244,3 +247,6 @@ | ||
'total': new_total | ||
}); | ||
}) | ||
.then(response => { | ||
console.log(response) | ||
}); | ||
``` | ||
@@ -247,0 +253,0 @@ |
36793
735
261