npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@onfido/api

v4.2.0

Published

Node.js library for the Onfido API

Downloads

108,916

Readme

Onfido Node.js Library

The official Node.js library for integrating with the Onfido API.

Documentation can be found at https://documentation.onfido.com.

This library is only for use on the backend, as it uses Onfido API tokens which must be kept secret. If you do need to collect applicant data in the frontend of your application, we recommend that you use the Onfido SDKs: iOS, Android, Web, and React Native.

This version uses Onfido API v3.6. Refer to our API versioning guide for details of which client library versions use which versions of the API.

npm version Build Status

Installation & Usage

Installation

Npm

npm install @onfido/api

Yarn

yarn add @onfido/api

Getting Started

Require the package:

const {
  DefaultApi,
  Configuration,
  WebhookEventVerifier
} = require("@onfido/api");
const { isAxiosError } = require("axios");

For TypeScript users, types are available as well:

import {
  DefaultApi,
  Configuration,
  Region,
  WebhookEventVerifier
} from "@onfido/api";
import { isAxiosError } from "axios";

Configure with your API token and region:

const onfido = new DefaultApi(
  new Configuration({
    apiToken: process.env.ONFIDO_API_TOKEN,
    region: Region.EU, // Supports Region.EU, Region.US and Region.CA
    baseOptions: { timeout: 60_000 } // Additional Axios options (timeout, etc.)
  })
);

NB: by default, timeout is set to 30 seconds.

Making a call to the API

Using async/await (in an async function):

(async () => {
  try {
    const applicant = await onfido.createApplicant({
      first_name: "Jane",
      last_name: "Doe",
      location: {
        ip_address: "127.0.0.1",
        country_of_residence: "GBR"
      }
    });

    // ...
  } catch (error) {
    if (isAxiosError(error)) {
      console.log(`status code: ${error.response?.status}`);
      const error_details = error.response?.data.error;
      // An error response was received from the Onfido API, extra info is available.
      if (error_details) {
        console.log(error_details.message);
        console.log(error_details.type);
      } else {
        // No response was received for some reason e.g. a network error.
        console.log(error.message);
      }
    } else {
      console.log(error.message);
    }
  }
})();

Please find more information regarding Axios errors in library documentation.

Using promises:

onfido
  .createApplicant({
    first_name: "Jane",
    last_name: "Doe",
    location: {
      ip_address: "127.0.0.1",
      country_of_residence: "GBR"
    }
  })
  .then(applicant =>
    onfido.createCheck({
      applicant_id: applicant.data.id,
      report_names: ["identity_enhanced"]
    })
  )
  .then(check =>
    // Handle successfully created check.
  )
  .catch(error => {
    // Handle error.
  });

File download

File downloads, for example onfido.downloadDocument(documentId), will return an instance of a FileTransfer object.

This object will have a content type, e.g. image/png.

download.headers["content-type"];

Call slice() to get a Buffer of the download:

const blob = download.data.slice();

File upload

File upload should make use of the provided FileTransfer class, e.g.:

onfido.uploadDocument(
  "passport",
  "<APPLICANT_ID>",
  new FileTransfer(Buffer.from(document.buffer), document.filename)
);

FileTransfer object can also be created from an existing file, e.g. new FileTransfer("path/to/passport.png").

Webhook event verification

Webhook events payload needs to be verified before it can be accessed. Library allows to easily decode the payload and verify its signature before returning it as an object for user convenience:

(async () => {
  try {
    const token = process.env.ONFIDO_WEBHOOK_SECRET_TOKEN;
    const verifier = new WebhookEventVerifier(token);
    const signature = "a0...760e";

    const event = verifier.readPayload(`{"payload":{"r...3"}}`, signature);
  } catch (e) {
    if (e instanceof OnfidoInvalidSignatureError) {
      // Invalid webhook signature
    }
  }
})();

Recommendations

Do not use square bracket syntax

Except for accessing Task object's outputs, retain from using the square bracket syntax (i.e. []) to access not defined properties to avoid breaking changes when these fields will appear.

Contributing

This library is automatically generated using OpenAPI Generator (version: 7.9.0); therefore all the contributions, except tests files, should target Onfido OpenAPI specification repository instead of this repository.

For contributions to the tests instead, please follow the steps below:

  1. Fork repository
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Versioning policy

Semantic Versioning policy is used for library versioning, following guidelines and limitations below:

  • MAJOR versions (x.0.0) might:
    • target a new API version
    • include non-backward compatible change
  • MINOR versions (0.x.0) might:
    • add a new functionality, non-mandatory parameter or property
    • deprecate an old functionality
    • include non-backward compatible change to a functionality which is:
      • labelled as alpha or beta
      • completely broken and not usable
  • PATCH version (0.0.x) might:
    • fix a bug
    • include backward compatible changes only

More documentation

More documentation and code examples can be found at https://documentation.onfido.com.

Support

Should you encounter any technical issues during integration, please contact Onfido's Customer Support team via the Customer Experience Portal which also includes support documentation.