Persona Inquiry JavaScript SDK

5.8.0 · active · verified Sun Apr 19

The `persona` package offers the official JavaScript SDK for integrating Persona's identity verification Inquiry Flow into web applications. As of version 5.8.0, it provides a robust client library designed to embed and manage the entire inquiry process directly within the user's browser environment. Key functionalities include configuring inquiry templates, selecting runtime environments (e.g., sandbox, production), and handling critical lifecycle events through callbacks for completion, cancellation, and errors. The SDK abstracts away the complexities of direct API interaction, offering a streamlined integration experience for front-end developers. It ships with built-in TypeScript types, enhancing developer experience and type safety. Persona maintains an active development pace, regularly releasing updates and fixes, and explicitly recommends staying up-to-date. Its primary differentiation lies in being the official, fully supported client for Persona services, ensuring compatibility with the latest features and security standards.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the Persona `Client` for an embedded inquiry flow, configure its environment, and set up essential event callbacks for `onReady`, `onComplete`, `onCancel`, and `onError` to manage the user journey.

import { Client } from 'persona';

// Initialize the Persona client for an embedded inquiry flow.
const client = new Client({
  // Replace with your actual template ID, or use the provided demo template for testing.
  templateId: 'itmpl_Ygs16MKTkA6obnF8C3Rb17dm',
  // Use 'sandbox' for development and testing, 'production' for live applications.
  environment: 'sandbox',
  // Callback executed when the Persona flow is ready to be opened.
  onReady: () => {
    console.log('Persona client is ready, opening flow...');
    client.open();
  },
  // Callback for when the inquiry process is successfully completed.
  onComplete: ({ inquiryId, status, fields }) => {
    console.log('Inquiry completed:', { inquiryId, status, fields });
    // Handle post-completion logic, e.g., notify your backend, update UI.
  },
  // Callback for when the user cancels the inquiry flow.
  onCancel: ({ inquiryId, sessionToken }) => {
    console.log('Inquiry cancelled:', { inquiryId, sessionToken });
    // Handle cancellation, e.g., log, return user to previous state.
  },
  // Callback for any errors encountered during the inquiry process.
  onError: (error) => {
    console.error('Persona inquiry error:', error);
    // Implement robust error handling and user feedback.
  },
  // Optional: Set allowed events for the onEvent callback (e.g., ['step-transitioned', 'click']).
  // eventsAllowlist: ['all']
});

console.log('Persona client initialized.');

view raw JSON →