Node.js

@veriseclabs/node is the official library for Node.js 18 and later, with full TypeScript types. It has no runtime dependencies. npm

Install#

Terminal
npm install @veriseclabs/node

Create a client#

Node.js
import { VeriSec } from "@veriseclabs/node";

const client = new VeriSec({ apiKey: process.env.VERISEC_API_KEY }); // sk_test_…

Leave apiKey out and the client reads VERISEC_API_KEY. Other options: timeout in milliseconds (default 300,000), maxRetries (default 2) and defaultHeaders.

Make a call#

Every endpoint is a method named after its operation: face.verify is client.face.verify, cheques.micrLine is client.cheques.micrLine. Field names are exactly the API's (image_front, minAge).

Node.js
const result = await client.face.verify({ image1: "selfie.jpg", image2: "id-photo.jpg", threshold: 0.8 });
console.log(result.match, result.similarity);

const doc = await client.documents.read({ image_front: "id-front.jpg", image_back: "id-back.jpg" });

const cheque = await client.cheques.read({ image: "cheque.jpg" });
const bin = await client.bin.lookup("424242");

An image can be a file path, a Buffer, a Blob, a data: URI or base64 you already have. The library sends it the way the API expects.

Errors#

Node.js
import { InsufficientCreditsError, InvalidRequestError, RateLimitError, APIError } from "@veriseclabs/node";

try {
  await client.face.verify({ image1: "selfie.jpg", image2: "id-photo.jpg" });
} catch (err) {
  if (err instanceof InsufficientCreditsError) console.log("Top up credits.");
  else if (err instanceof InvalidRequestError) console.log(err.code, err.param, err.message);
  else if (err instanceof RateLimitError) console.log(`Wait ${err.retryAfter} s.`);
  else if (err instanceof APIError) console.log(err.status, err.code, err.requestId);
  else throw err;
}

Classes: InvalidRequestError (400, 413, 415, 422), AuthenticationError (401), InsufficientCreditsError (402), PermissionError (403), NotFoundError (404), RateLimitError (429), APIServerError (5xx), plus APIConnectionError and APITimeoutError, all from VeriSecError.

Webhooks#

Node.js
const event = client.webhooks.constructEvent(rawBody, req.headers, process.env.VERISEC_WEBHOOK_SECRET);

See Webhooks for a full handler.