Skip to main content

Overview

The FAD SDK must be initialized before you can use any of its modules. Initialization involves creating an instance of the FadSDK class with your authentication token and optional configuration settings.

Basic Initialization

The simplest way to initialize the SDK is by providing your authentication token:
import FadSDK from './fad-sdk.min.js';

const TOKEN = 'your-authentication-token';
const FAD_SDK = new FadSDK(TOKEN);
For Vanilla JS implementations, remember to specify the script type as module in your HTML:
<script src="index.js" type="module"></script>

Initialization with Options

You can customize the SDK behavior by passing an options object as the second parameter:
const options = {
  environment: FadSDK.getFadEnvironments().UATHA
};

const FAD_SDK = new FadSDK(TOKEN, options);

Constructor Parameters

token
string
required
Your FAD SDK authentication token. This token is required to authenticate your application with the FAD services.
options
object
Configuration options for the SDK instance.
environment
string
The FAD environment to connect to. Use FadSDK.getFadEnvironments() to get available environments.Available environments:
  • UATHA - UAT High Availability environment
  • Other environments (see Environments for full list)

Complete Initialization Example

Here’s a complete example showing initialization with all recommended practices:
import FadSDK from '@fad-producto/fad-sdk';

const TOKEN = 'your-authentication-token';

async function initProcess() {
  const options = {
    environment: FadSDK.getFadEnvironments().UATHA
  };

  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    const CREDENTIALS = {
      license: 'your-regula-license',
      apiBasePath: 'your-api-base-path'
    };
    
    const idData = true;  // Include OCR data
    const idPhoto = true; // Include face photo from ID
    
    const response = await FAD_SDK.startRegula(
      CREDENTIALS,
      FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
      idData,
      idPhoto
    );
    
    console.log('Process completed:', response);
  } catch (error) {
    console.error('Process failed:', error);
  } finally {
    FAD_SDK.end();
  }
}

initProcess();

SDK Version

You can check the SDK version using the static version property:
import FadSDK from '@fad-producto/fad-sdk';

console.log(`SDK Version: v${FadSDK.version}`);

Cleanup

Always call the end() method when you’re done with the SDK to properly clean up resources:
finally {
  FAD_SDK.end();
}
Failing to call end() may result in memory leaks or resources not being properly released. Always use a finally block to ensure cleanup happens even if errors occur.

Installation Methods

Install the SDK via npm:
npm install @fad-producto/fad-sdk
Then import it in your project:
import FadSDK from '@fad-producto/fad-sdk';

Next Steps

Available Modules

Explore the different modules available in the FAD SDK

Error Handling

Learn how to handle errors and exceptions

Environments

Configure different environments for your SDK

Quick Start

Get started with a complete example

Build docs developers (and LLMs) love