import type { AppMode } from './types'; /** * Detect the current app mode */ export function detectMode(): AppMode { // Check explicit mode from env const envMode = import.meta.env.VITE_MODE; if (envMode === 'standalone' || envMode === 'embedded') { return envMode; } // Default to library mode // Note: Embedded SDK mode is just library mode with RemoteAuthProvider return 'library'; } /** * Check if origin is allowed (for CORS configuration) */ export function isOriginAllowed(origin: string, allowedOrigins: string[]): boolean { if (allowedOrigins.includes('*')) return true; return allowedOrigins.some(allowed => { // Exact match if (allowed === origin) return true; // Wildcard subdomain match (e.g., "*.example.com") if (allowed.startsWith('*.')) { const domain = allowed.slice(2); return origin.endsWith(domain); } return false; }); } /** * Get Keycloak configuration from environment */ export function getKeycloakConfig() { return { url: import.meta.env.VITE_KEYCLOAK_URL || '', realm: import.meta.env.VITE_KEYCLOAK_REALM || '', clientId: import.meta.env.VITE_KEYCLOAK_CLIENT_ID || '', }; } /** * Get allowed origins from environment */ export function getAllowedOrigins(): string[] { const origins = import.meta.env.VITE_ALLOWED_ORIGINS || '*'; return origins.split(',').map((o: string) => o.trim()); }