Skip to main content

Overview

The FAD SDK supports multiple environments for different stages of your application lifecycle. You can configure which environment to use during SDK initialization.

Getting Available Environments

Use the static getFadEnvironments() method to retrieve available environment configurations:
import FadSDK from '@fad-producto/fad-sdk';

const environments = FadSDK.getFadEnvironments();
console.log(environments);

Configuring Environment

Specify the environment during SDK initialization by passing it in the options object:
const options = {
  environment: FadSDK.getFadEnvironments().UATHA
};

const FAD_SDK = new FadSDK(TOKEN, options);

Available Environments

UATHA (UAT High Availability)

The User Acceptance Testing environment with high availability configuration. This is commonly used for testing and staging purposes.
const options = {
  environment: FadSDK.getFadEnvironments().UATHA
};
Use Cases:
  • Pre-production testing
  • User acceptance testing
  • Staging environment
  • QA validation
UATHA is the most commonly used environment in the SDK examples and is suitable for testing integrations before moving to production.

Additional Environments

The SDK may provide additional environments depending on your deployment needs. Use getFadEnvironments() to retrieve the complete list of available environments:
const environments = FadSDK.getFadEnvironments();

// Access specific environment
const selectedEnv = environments.UATHA;

// List all available environments
Object.keys(environments).forEach(env => {
  console.log(`Environment: ${env}`);
});

Environment Selection by Use Case

During development, use the UAT environment for testing:
const options = {
  environment: FadSDK.getFadEnvironments().UATHA
};
Benefits:
  • Safe testing environment
  • No impact on production data
  • Full SDK functionality

Dynamic Environment Configuration

You can dynamically select environments based on your application’s configuration:
// Environment configuration based on build/runtime
const ENV_CONFIG = {
  development: FadSDK.getFadEnvironments().UATHA,
  staging: FadSDK.getFadEnvironments().UATHA,
  production: FadSDK.getFadEnvironments().PRODUCTION
};

// Get current environment from your config
const currentEnv = process.env.NODE_ENV || 'development';

// Initialize with appropriate environment
const options = {
  environment: ENV_CONFIG[currentEnv]
};

const FAD_SDK = new FadSDK(TOKEN, options);

Environment-Specific Configuration

Combine environment selection with other configuration options:
const getSDKOptions = (env) => {
  const baseOptions = {
    environment: FadSDK.getFadEnvironments()[env]
  };
  
  // Add environment-specific settings
  if (env === 'DEVELOPMENT') {
    return {
      ...baseOptions,
      debug: true,
      verbose: true
    };
  }
  
  return baseOptions;
};

// Usage
const options = getSDKOptions('UATHA');
const FAD_SDK = new FadSDK(TOKEN, options);

Complete Example with Environment

Here’s a complete example showing environment configuration in a real-world scenario:
import FadSDK from '@fad-producto/fad-sdk';

class DocumentVerificationService {
  constructor(token, environmentName = 'UATHA') {
    this.token = token;
    this.environmentName = environmentName;
    this.sdk = null;
  }
  
  initialize() {
    const options = {
      environment: FadSDK.getFadEnvironments()[this.environmentName]
    };
    
    this.sdk = new FadSDK(this.token, options);
    console.log(`SDK initialized with environment: ${this.environmentName}`);
  }
  
  async captureDocument(credentials, configuration) {
    if (!this.sdk) {
      throw new Error('SDK not initialized. Call initialize() first.');
    }
    
    try {
      const response = await this.sdk.startRegula(
        credentials,
        FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
        true,
        true,
        configuration
      );
      
      if (response.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
        return { cancelled: true };
      }
      
      return { success: true, data: response.data };
      
    } catch (error) {
      console.error('Document capture error:', error);
      return { success: false, error };
    }
  }
  
  cleanup() {
    if (this.sdk) {
      this.sdk.end();
      this.sdk = null;
    }
  }
}

// Usage
const TOKEN = 'your-token';
const service = new DocumentVerificationService(TOKEN, 'UATHA');

service.initialize();

try {
  const result = await service.captureDocument(CREDENTIALS, CONFIGURATION);
  
  if (result.success) {
    console.log('Document captured:', result.data);
  } else if (result.cancelled) {
    console.log('User cancelled');
  } else {
    console.error('Capture failed:', result.error);
  }
} finally {
  service.cleanup();
}

Best Practices

Store environment configuration in environment variables:
// .env.development
VITE_FAD_ENV=UATHA
VITE_FAD_TOKEN=your-dev-token

// .env.production
VITE_FAD_ENV=PRODUCTION
VITE_FAD_TOKEN=your-prod-token

// In your code
const options = {
  environment: FadSDK.getFadEnvironments()[import.meta.env.VITE_FAD_ENV]
};
Validate that the environment exists before using it:
const environmentName = 'UATHA';
const environments = FadSDK.getFadEnvironments();

if (!environments[environmentName]) {
  throw new Error(`Invalid environment: ${environmentName}`);
}

const options = {
  environment: environments[environmentName]
};
Document which environment should be used for each deployment:
/**
 * FAD SDK Environment Configuration
 * 
 * - Development: UATHA (UAT High Availability)
 * - Staging: UATHA (UAT High Availability)
 * - Production: PRODUCTION (configured by DevOps)
 * 
 * Contact: sdk-support@example.com for environment questions
 */
const SDK_ENVIRONMENTS = {
  development: 'UATHA',
  staging: 'UATHA',
  production: 'PRODUCTION'
};
Test environment connectivity during initialization:
async function testEnvironmentConnection() {
  const options = {
    environment: FadSDK.getFadEnvironments().UATHA
  };
  
  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    // Attempt a simple operation to verify connectivity
    console.log(`SDK Version: v${FadSDK.version}`);
    console.log('Environment configured successfully');
  } catch (error) {
    console.error('Environment configuration failed:', error);
  } finally {
    FAD_SDK.end();
  }
}

Troubleshooting

Invalid Environment Error

If you receive an error about an invalid environment:
// Check available environments
const environments = FadSDK.getFadEnvironments();
console.log('Available environments:', Object.keys(environments));

// Verify your environment exists
const envName = 'UATHA';
if (environments[envName]) {
  console.log('Environment found:', envName);
} else {
  console.error('Environment not found:', envName);
  console.log('Available:', Object.keys(environments));
}

Environment Connection Issues

If you experience connectivity issues:
  1. Verify your authentication token is valid
  2. Check network connectivity
  3. Confirm the environment is accessible from your network
  4. Contact your FAD SDK administrator for environment status
Environment URLs and configurations may change. Always use getFadEnvironments() rather than hardcoding environment URLs.

Next Steps

Initialization

Learn more about SDK initialization options

Quick Start

Get started with a complete example

Error Handling

Handle environment-related errors

Modules

Explore available SDK modules

Build docs developers (and LLMs) love