Client Configuration
This page covers all configuration options for the VaultSandbox Node.js client.
Basic Configuration
Section titled “Basic Configuration”Creating a Client
Section titled “Creating a Client”import { VaultSandboxClient } from '@vaultsandbox/client';
const client = new VaultSandboxClient({ url: 'https://mail.example.com', apiKey: 'your-api-key',});Configuration Options
Section titled “Configuration Options”Required Options
Section titled “Required Options”Type: string
Description: Base URL of your VaultSandbox Gateway
Examples:
url: 'https://mail.example.com';url: 'http://localhost:3000'; // Local developmentRequirements:
- Must include protocol (
https://orhttp://) - Should not include trailing slash
- Must be accessible from your application
apiKey
Section titled “apiKey”Type: string
Description: API key for authentication
Example:
apiKey: 'vs_1234567890abcdef...';Best practices:
- Store in environment variables
- Never commit to version control
- Rotate periodically
Optional Options
Section titled “Optional Options”strategy
Section titled “strategy”Type: 'sse' | 'polling' | 'auto'
Default: 'auto'
Description: Email delivery strategy
Options:
'auto'- Automatically choose best strategy (tries SSE first, falls back to polling)'sse'- Server-Sent Events for real-time delivery'polling'- Poll for new emails at intervals
Examples:
strategy: 'auto'; // Recommendedstrategy: 'sse'; // Force SSEstrategy: 'polling'; // Force pollingWhen to use each:
'auto': Most use cases (recommended)'sse': When you need real-time, low-latency delivery'polling': When SSE is blocked by firewall/proxy
pollingInterval
Section titled “pollingInterval”Type: number (milliseconds)
Default: 2000
Description: Polling interval when using polling strategy
Examples:
pollingInterval: 2000; // Poll every 2 seconds (default)pollingInterval: 5000; // Poll every 5 secondspollingInterval: 500; // Poll every 500ms (aggressive)Considerations:
- Lower = more responsive, more API calls
- Higher = less API calls, slower detection
- Subject to rate limiting
maxRetries
Section titled “maxRetries”Type: number
Default: 3
Description: Maximum retry attempts for failed HTTP requests
Examples:
maxRetries: 3; // DefaultmaxRetries: 5; // More resilientmaxRetries: 0; // No retriesretryDelay
Section titled “retryDelay”Type: number (milliseconds)
Default: 1000
Description: Base delay between retry attempts (uses exponential backoff)
Examples:
retryDelay: 1000; // 1s, 2s, 4s, ...retryDelay: 500; // 500ms, 1s, 2s, ...retryDelay: 2000; // 2s, 4s, 8s, ...retryOn
Section titled “retryOn”Type: number[] (HTTP status codes)
Default: [408, 429, 500, 502, 503, 504]
Description: HTTP status codes that trigger a retry
Example:
retryOn: [408, 429, 500, 502, 503, 504]; // DefaultretryOn: [500, 502, 503]; // Only server errorsretryOn: []; // Never retrysseReconnectInterval
Section titled “sseReconnectInterval”Type: number (milliseconds)
Default: 5000
Description: Initial delay before SSE reconnection attempt
Examples:
sseReconnectInterval: 5000; // DefaultsseReconnectInterval: 1000; // Faster reconnectionsseReconnectInterval: 10000; // Slower reconnectionNote: Uses exponential backoff (5s, 10s, 20s, …)
sseMaxReconnectAttempts
Section titled “sseMaxReconnectAttempts”Type: number
Default: 10
Description: Maximum SSE reconnection attempts before giving up
Examples:
sseMaxReconnectAttempts: 10; // DefaultsseMaxReconnectAttempts: Infinity; // Never give upsseMaxReconnectAttempts: 3; // Give up quicklyConfiguration Examples
Section titled “Configuration Examples”Production Configuration
Section titled “Production Configuration”const client = new VaultSandboxClient({ // Required url: process.env.VAULTSANDBOX_URL, apiKey: process.env.VAULTSANDBOX_API_KEY,
// Recommended production settings strategy: 'auto', maxRetries: 5, retryDelay: 2000, sseReconnectInterval: 5000, sseMaxReconnectAttempts: 10,});CI/CD Configuration
Section titled “CI/CD Configuration”const client = new VaultSandboxClient({ url: process.env.VAULTSANDBOX_URL, apiKey: process.env.VAULTSANDBOX_API_KEY,
// Faster polling for CI strategy: 'auto', pollingInterval: 1000, // Poll every second maxRetries: 3, retryDelay: 500,});Development Configuration
Section titled “Development Configuration”const client = new VaultSandboxClient({ url: 'http://localhost:3000', apiKey: 'dev-api-key',
// Aggressive settings for fast feedback strategy: 'polling', // More reliable in dev pollingInterval: 500, // Very responsive maxRetries: 1, // Fail fast});High-Reliability Configuration
Section titled “High-Reliability Configuration”const client = new VaultSandboxClient({ url: process.env.VAULTSANDBOX_URL, apiKey: process.env.VAULTSANDBOX_API_KEY,
// Maximum reliability maxRetries: 10, retryDelay: 2000, retryOn: [408, 429, 500, 502, 503, 504], sseReconnectInterval: 1000, sseMaxReconnectAttempts: Infinity,});Environment Variables
Section titled “Environment Variables”Store configuration in environment variables:
.env File
Section titled “.env File”VAULTSANDBOX_URL=https://mail.example.comVAULTSANDBOX_API_KEY=vs_1234567890abcdef...VAULTSANDBOX_STRATEGY=autoVAULTSANDBOX_POLLING_INTERVAL=2000import { VaultSandboxClient } from '@vaultsandbox/client';import 'dotenv/config'; // Load .env file
const client = new VaultSandboxClient({ url: process.env.VAULTSANDBOX_URL, apiKey: process.env.VAULTSANDBOX_API_KEY, strategy: process.env.VAULTSANDBOX_STRATEGY || 'auto', pollingInterval: parseInt(process.env.VAULTSANDBOX_POLLING_INTERVAL || '2000'),});Client Methods
Section titled “Client Methods”close()
Section titled “close()”Close the client and clean up resources:
await client.close();What it does:
- Terminates all active SSE connections
- Stops all polling operations
- Cleans up resources
When to use:
- After test suite completes
- Before process exit
- When client is no longer needed
Example:
const client = new VaultSandboxClient({ url, apiKey });
try { // Use client const inbox = await client.createInbox(); // ...} finally { await client.close();}Strategy Selection Guide
Section titled “Strategy Selection Guide”Auto (Recommended)
Section titled “Auto (Recommended)”Use when: You want optimal performance with automatic fallback
Behavior:
- Tries SSE first
- Falls back to polling if SSE fails
- Automatically reconnects on errors
Pros:
- Best of both worlds
- No manual configuration needed
- Resilient to network issues
Cons:
- Slightly more complex internally
SSE (Server-Sent Events)
Section titled “SSE (Server-Sent Events)”Use when: You need real-time, low-latency delivery
Behavior:
- Persistent connection to server
- Push-based email notification
- Instant delivery
Pros:
- Real-time delivery (no polling delay)
- Efficient (no repeated HTTP requests)
- Deterministic tests
Cons:
- Requires persistent connection
- May be blocked by some proxies/firewalls
- More complex error handling
Polling
Section titled “Polling”Use when: SSE is blocked or unreliable
Behavior:
- Periodic HTTP requests for new emails
- Pull-based email retrieval
- Configurable interval
Pros:
- Works in all network environments
- No persistent connection required
- Simple and predictable
Cons:
- Delay based on polling interval
- More HTTP requests
- Less efficient than SSE
Best Practices
Section titled “Best Practices”Security
Section titled “Security”✅ DO:
// Use environment variablesconst client = new VaultSandboxClient({ url: process.env.VAULTSANDBOX_URL, apiKey: process.env.VAULTSANDBOX_API_KEY,});❌ DON’T:
// Hard-code credentialsconst client = new VaultSandboxClient({ url: 'https://mail.example.com', apiKey: 'vs_1234567890...', // ❌ Never do this});Resource Management
Section titled “Resource Management”✅ DO:
const client = new VaultSandboxClient({ url, apiKey });
try { await runTests();} finally { await client.close(); // Always clean up}❌ DON’T:
const client = new VaultSandboxClient({ url, apiKey });await runTests();// ❌ Forgot to close, resources leakError Handling
Section titled “Error Handling”✅ DO:
try { const inbox = await client.createInbox();} catch (error) { if (error instanceof ApiError) { console.error('API error:', error.statusCode, error.message); } else if (error instanceof NetworkError) { console.error('Network error:', error.message); } else { console.error('Unexpected error:', error); }}Next Steps
Section titled “Next Steps”- Core Concepts: Inboxes - Learn about inboxes
- Managing Inboxes - Common inbox operations
- Testing Patterns - Integrate with your tests
- API Reference: Client - Full API documentation