@resistantai/resistant-documents-client
v3.3.0
Published
Client library to connect to Resistant Documents service.
Downloads
2,518
Readme
Resistant documents client
This library provides a Typescript client for a Resistant.AI document forgery analysis service. For a detailed description of the API please see API reference docs.
Prerequisites
During the customer onboarding process, you should be provided with the following:
CLIENT_ID
: strCLIENT_SECRET
: str
Note: Those credentials are connected with specific environment (e.g. test, production etc.). Together with secret credentials for non-production environment you should be provided with the following URLs:
API_URL
TOKEN_URL
TOKEN_URL
is used to authenticate with an identity provider, this library
does not use it. Once authenticated, use `Bearer ${accessToken}`
as API key.
Installation
Package can be installed using npm
:
$ npm add @resistantai/resistant-documents-client
Usage
Import and init
Package can be imported as
import ResistantDocumentsApi from "@resistantai/resistant-documents-client";
or in Node
as
const ResistantDocumentsApi = require("@resistantai/resistant-documents-client");
Client instance can be then initialized using
const client = new ResistantDocumentsApi(() => "YOUR_API_KEY", API_URL);
or if you wish to use it against the production environment you can skip the second parameter:
const client = new ResistantDocumentsApi(() => "YOUR_API_KEY");
Examples
Submit document for analysis and wait for results
client.analyze(file).then(results => console.log(results));
Information about original file name is not stored in the backed. You can manually store this information
using query_id
parameter:
client.analyze(file, file.name).then(analysisResponse => console.log(analysisResponse));
Provided query_id
is always returned with AnalysisResponse
.
Submit document and fetch results manually
client.submit(file, file.name)
.then(submissionId => client.results(submissionId))
.then(analysisResponse => console.log(analysisResponse));
Analysis is asynchronous, therefore the client needs to poll for the result until it is available. If desired, it is possible to change number of retries when fetching the result:
client.submit(file, file.name)
.then(submissionId => client.results(submissionId, 10)) // will retry at most 10 times
.then(analysisResponse => console.log(analysisResponse));
Submit document and fetch fraud analysis results, parsed content and quality information
Besides analysis result, one can also fetch quality information for the submitted document, if quality analysis was requested. By default, only fraud analysis is performed. To also request quality analysis, the submit method accepts an additional argument
// will perform quality and fraud analysis
const submissionId = await client.submit(file, PipelineConfiguration.QUALITY_AND_FRAUD)
// will perform only quality analysis
const submissionId = await client.submit(file, PipelineConfiguration.QUALITY_ONLY)
// TODO: what does this do?
const submissionId = await client.submit(file, PipelineConfiguration.CONTENT_AFTER_FRAUD_AFTER_QUALITY)
Analysis, quality and content results can then be fetched as follows:
const analysisResponse = await client.results(submissionId);
const qualityResponse = await client.quality(submissionId);
const contentResponse = await client.content(submissionId);
Please note that parsing content is available only for selected document types.
Download submitted file
Once file has been submitted, it can be downloaded as long as its retention period hasn't expired, after which it is permanently deleted.
const submissionId = await client.submit(file);
const rawFileContent = await client.data(submissionId);