UNPKG

failover-sdk

Version:

One-line API failover with zero downtime. Native Rust performance with TypeScript interface.

43 lines (42 loc) 2.03 kB
'use strict'; // Main registration hook - runs immediately when imported Object.defineProperty(exports, '__esModule', { value: true }); exports.initializeFailover = initializeFailover; const config_loader_1 = require('./config-loader'); const provider_override_1 = require('./provider-override'); /** * Initialize Failover system * This runs automatically when 'failover/register' is imported */ async function initializeFailover() { try { console.log('[Failover] Initializing intelligent API failover system...'); // Get project ID from environment or default const projectId = process.env.FAILOVER_PROJECT_ID || 'default'; if (projectId === 'default') { console.warn('[Failover] No FAILOVER_PROJECT_ID found, using default config'); } // Step 1: Start background config refresh (every 60 seconds) console.log('[Failover] Starting config refresh...'); await (0, config_loader_1.startConfigRefresh)(projectId); // Step 2: Setup fast path - override provider selection based on cached config console.log('[Failover] Setting up provider overrides...'); (0, provider_override_1.setupProviderOverrides)(); // Step 3: Setup safety net - HTTP interceptor for double failures console.log('[Failover] Setting up fallback interceptor...'); (0, provider_override_1.setupFallbackInterceptor)(); console.log('[Failover] ✅ Initialization complete! Your APIs now have intelligent failover.'); console.log('[Failover] 🔍 Monitor your failover events at https://dashboard.failover.dev'); } catch (error) { console.error('[Failover] ❌ Initialization failed:', error); console.error( '[Failover] Your APIs will continue to work normally without failover protection.' ); } } // Auto-initialize when this module is imported // This is the "magic" that happens when user adds: import 'failover/register' initializeFailover().catch(error => { console.error('[Failover] Critical initialization error:', error); }); //# sourceMappingURL=register.js.map