Skip to main content

Method Signature

FAD_SDK.startRegula(
  credentials: RegulaCredentials,
  captureType: CaptureType,
  idData: boolean,
  idPhoto: boolean,
  configuration?: Configuration
): Promise<RegulaResponse>

Description

The startRegula() method initiates the Regula document reader module for capturing and validating identification documents. This method provides advanced document authentication capabilities, including OCR data extraction and photo extraction from the ID.

Parameters

credentials
RegulaCredentials
required
Regula service credentials
captureType
CaptureType
required
The capture mode to use for document scanningUse FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT for camera-based capture or FadSDK.Constants.Regula.CaptureType.DOCUMENT_READER for automated document reader
idData
boolean
required
Whether to extract OCR data from the document
  • true - Extract OCR data from the document
  • false - Skip OCR data extraction
idPhoto
boolean
required
Whether to extract the photo from the identification document
  • true - Extract the face photo from the ID
  • false - Skip photo extraction
configuration
Configuration
Optional configuration object for customizing the module’s behavior and appearance

Returns

RegulaResponse
Promise<object>
A promise that resolves with the Regula module response

Code Example

import FadSDK from '@fad-producto/fad-sdk';

const CREDENTIALS = {
  license: 'YOUR_REGULA_LICENSE',
  apiBasePath: 'YOUR_API_BASE_PATH'
};

const TOKEN = 'YOUR_FAD_TOKEN';

const CONFIGURATION = {
  views: {
    instructions: true,
    preview: true,
  },
  idValidations: {
    cardMatch: false,
  },
  customization: {
    moduleCustomization: {
      legends: {
        desktop: {
          front: {
            instruction: 'Upload the front of your ID',
            title: 'Front'
          },
          back: {
            instruction: 'Upload the back of your ID',
            title: 'Back'
          }
        }
      }
    }
  }
};

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

  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    const idData = true;  // Extract OCR data
    const idPhoto = true; // Extract face photo

    const regulaResponse = await FAD_SDK.startRegula(
      CREDENTIALS,
      FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
      idData,
      idPhoto,
      CONFIGURATION
    );

    if (regulaResponse.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
      console.log('Module closed by the user');
      return;
    }

    // Process the results
    console.log('Front image:', regulaResponse.data.id.front);
    console.log('Back image:', regulaResponse.data.id.back);
    console.log('Face photo:', regulaResponse.data.idPhoto);
    console.log('OCR data:', regulaResponse.data.idData.ocr);

  } catch (error) {
    if (error.code === FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED) {
      console.error('Camera permission denied');
    } else if (error.code === FadSDK.Errors.Regula.ID_PHOTO_NOT_FOUND) {
      console.error('ID photo not found');
    } else if (error.code === FadSDK.Errors.Regula.OCR_NOT_FOUND) {
      console.error('OCR data not found');
    } else {
      console.error('Error:', error);
    }
  } finally {
    FAD_SDK.end();
  }
}

Error Handling

The method may throw errors that can be identified using FadSDK.Errors.Regula:
  • CAMERA_PERMISSION_DENIED - Camera permission was denied
  • ID_PHOTO_NOT_FOUND - Face photo could not be extracted from the ID
  • OCR_NOT_FOUND - OCR data could not be extracted from the document
See the Regula Error Codes page for a complete list of error codes.
Always call FAD_SDK.end() in a finally block to properly clean up resources after the module completes or fails.

Build docs developers (and LLMs) love