Constructor
new FadSDK(token: string, options?: SDKOptions)
Creates a new instance of the FadSDK class. The constructor initializes the SDK with your authentication token and optional configuration.
Parameters
Your FAD SDK authentication token. This token is required for all SDK operations and authenticates your application with FAD services.const TOKEN = 'your-fad-sdk-token';
Configuration options for SDK behavior and appearance.
environment
FadEnvironment
default:"UATHA"
The environment to connect to. Use FadSDK.getFadEnvironments().UATHA for testing or FadSDK.getFadEnvironments().PROD for production.environment: FadSDK.getFadEnvironments().UATHA // Test environment
environment: FadSDK.getFadEnvironments().PROD // Production environment
Custom base URL for SDK services. Can be a string or an object with specific URLs.// String format
baseUrl: 'https://custom-domain.com'
// Object format
baseUrl: {
iframeUrl: 'https://custom-iframe.com',
fadWebUrl: 'https://custom-web.com',
biometricsByStepsUrl: 'https://custom-biometrics.com'
}
Security configuration options.
Allowed domain for security validation
Metrics and analytics configuration.metrics: {
// Your metrics configuration
}
Custom styling for the SDK UI container.style: {
zIndex: '999999',
backgroundColor: '#F2F2F2'
}
Return Value
Returns a new FadSDK instance that can be used to call module methods.
Examples
Basic Initialization
import FadSDK from '@fad-producto/fad-sdk';
const TOKEN = 'your-fad-sdk-token';
const options = {
environment: FadSDK.getFadEnvironments().UATHA
};
const FAD_SDK = new FadSDK(TOKEN, options);
Advanced Configuration
import FadSDK from '@fad-producto/fad-sdk';
const TOKEN = 'your-fad-sdk-token';
const options = {
environment: FadSDK.getFadEnvironments().PROD,
// Custom styling
style: {
zIndex: '999999',
backgroundColor: '#F2F2F2'
},
// Security configuration
security: {
enable: true,
domain: 'yourdomain.com'
},
// Metrics tracking
metrics: {
enabled: true,
trackingId: 'your-tracking-id'
}
};
const FAD_SDK = new FadSDK(TOKEN, options);
With Custom Base URLs
import FadSDK from '@fad-producto/fad-sdk';
const TOKEN = 'your-fad-sdk-token';
const options = {
environment: FadSDK.getFadEnvironments().PROD,
// Custom base URLs for different services
baseUrl: {
iframeUrl: 'https://custom-iframe.yourdomain.com',
fadWebUrl: 'https://custom-web.yourdomain.com',
biometricsByStepsUrl: 'https://custom-biometrics.yourdomain.com'
}
};
const FAD_SDK = new FadSDK(TOKEN, options);
Complete Usage Example
import FadSDK from '@fad-produto/fad-sdk';
// Configuration
const TOKEN = 'your-fad-sdk-token';
const credentials = {
license: 'YOUR_LICENSE_KEY',
apiBasePath: 'YOUR_API_BASE_PATH'
};
// Initialize SDK
const options = {
environment: FadSDK.getFadEnvironments().UATHA
};
const FAD_SDK = new FadSDK(TOKEN, options);
// Use the SDK
async function captureDocument() {
try {
const response = await FAD_SDK.startRegula(
credentials,
FadSDK.Constants.Regula.CaptureType.DOCUMENT_READER,
true, // idData
true, // idPhoto
{} // configuration
);
if (response.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
console.log('User closed the module');
return;
}
console.log('Document captured:', response.data);
} catch (error) {
console.error('Capture error:', error);
if (error.code === FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED) {
alert('Camera permission denied. Please enable camera access.');
}
} finally {
FAD_SDK.end();
}
}
captureDocument();
Vanilla JavaScript Example
When using Vanilla JavaScript, ensure your script tag has type="module" attribute.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FAD SDK Example</title>
</head>
<body>
<button id="start-btn">Start Capture</button>
<script src="index.js" type="module"></script>
</body>
</html>
import FadSDK from './fad-sdk.min.js';
const TOKEN = 'your-fad-sdk-token';
const options = {
environment: FadSDK.getFadEnvironments().UATHA
};
const FAD_SDK = new FadSDK(TOKEN, options);
document.getElementById('start-btn').addEventListener('click', async () => {
try {
const response = await FAD_SDK.startFacetec(
{ /* credentials */ },
{ /* configuration */ }
);
console.log('Liveness completed:', response.data);
} catch (error) {
console.error('Error:', error);
} finally {
FAD_SDK.end();
}
});
Environment Configuration
The SDK supports two environments:
UATHA
Test EnvironmentUse for development and testing. This environment allows you to test SDK functionality without affecting production data.environment: FadSDK.getFadEnvironments().UATHA
PROD
Production EnvironmentUse for live production applications. Ensure thorough testing in UATHA before deploying to PROD.environment: FadSDK.getFadEnvironments().PROD
Best Practices
Always call FAD_SDK.end() when finished, preferably in a finally block to ensure cleanup even if errors occur.try {
const response = await FAD_SDK.startRegula(...);
} catch (error) {
console.error(error);
} finally {
FAD_SDK.end(); // Always cleanup
}
Never hardcode tokens in client-side code for production. Consider fetching tokens from your backend API.// Fetch token from your backend
const response = await fetch('/api/get-fad-token');
const { token } = await response.json();
const FAD_SDK = new FadSDK(token, options);
Environment-specific configuration
Use environment variables or configuration files to manage different settings for UATHA and PROD.const isProduction = process.env.NODE_ENV === 'production';
const options = {
environment: isProduction
? FadSDK.getFadEnvironments().PROD
: FadSDK.getFadEnvironments().UATHA
};
Always implement comprehensive error handling with specific error code checks.catch (error) {
if (error.code === FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED) {
// Handle camera permission
} else if (error.code === FadSDK.Errors.Regula.OCR_NOT_FOUND) {
// Handle OCR failure
} else {
// Handle other errors
}
}
Requirements
The SDK requires HTTPS in production environments. HTTP is only allowed for localhost development.
Hardware Requirements
- Memory: 4GB+ RAM
- Camera (for modules using camera):
- Front camera: 7 MP+
- Rear camera: 12 MP+
Browser Requirements
Next Steps
Environments
Learn about environment configuration
Constants
Explore SDK constants and enums
FadSDK Class
View all available methods