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 The base path for the Regula API
The capture mode to use for document scanning Use FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT for camera-based capture or FadSDK.Constants.Regula.CaptureType.DOCUMENT_READER for automated document reader
Whether to extract OCR data from the document
true - Extract OCR data from the document
false - Skip OCR data extraction
Whether to extract the photo from the identification document
true - Extract the face photo from the ID
false - Skip photo extraction
Optional configuration object for customizing the module’s behavior and appearance Control which views are displayed
instructions - Show/hide instruction screen
preview - Show/hide preview screen
Customize colors, fonts, legends, and styles for the module
Configure ID validation options
cardMatch - Enable/disable card matching validation
Configure capture settings including camera controls and timeouts
Returns
A promise that resolves with the Regula module response The event type (e.g., MODULE_CLOSED if user closed the module)
The captured document data Document images
front - Front side image (base64 encoded)
back - Back side image (base64 encoded, if applicable)
OCR data extracted from the document (if idData was true)
ocr - Object containing extracted text fields
Base64 encoded face photo extracted from the ID (if idPhoto was true)
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.