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.
During the customer onboarding process, you should be provided with the following:
-
CLIENT_ID
: str -
CLIENT_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.
Package can be installed using npm
:
$ npm add @resistantai/resistant-documents-client
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");
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
.
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));
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.
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);