- Add complete dark mode system with theme context and toggle - Implement dark mode toggle component in navigation menu - Add client-side routing with SSR-safe signal handling - Fix language selector styling for better dark mode compatibility - Add documentation system with mdBook integration - Improve navigation menu with proper external/internal link handling - Add comprehensive project documentation and configuration - Enhance theme system with localStorage persistence - Fix arena panic issues during server-side rendering - Add proper TypeScript configuration and build optimizations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
360 lines
11 KiB
Rust
360 lines
11 KiB
Rust
//! Enterprise Multi-Tenant - Ejemplo de uso del wizard para empresa multi-tenant
|
|
//!
|
|
//! Este ejemplo muestra cómo una empresa con múltiples tenants y requirements complejos
|
|
//! se beneficia más del wizard avanzado (Rhai)
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
|
|
/// Configuración compleja para empresa multi-tenant
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct EnterpriseConfig {
|
|
pub tenant_id: String,
|
|
pub tier: ServiceTier,
|
|
pub features: Vec<String>,
|
|
pub database_config: DatabaseConfig,
|
|
pub integrations: Vec<Integration>,
|
|
pub compliance: ComplianceConfig,
|
|
pub scaling: ScalingConfig,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub enum ServiceTier {
|
|
Basic,
|
|
Professional,
|
|
Enterprise,
|
|
Custom(String),
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct DatabaseConfig {
|
|
pub primary_url: String,
|
|
pub read_replicas: Vec<String>,
|
|
pub backup_config: BackupConfig,
|
|
pub encryption: EncryptionConfig,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct BackupConfig {
|
|
pub enabled: bool,
|
|
pub schedule: String,
|
|
pub retention_days: u32,
|
|
pub storage_type: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct EncryptionConfig {
|
|
pub at_rest: bool,
|
|
pub in_transit: bool,
|
|
pub key_management: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Integration {
|
|
pub name: String,
|
|
pub config: HashMap<String, String>,
|
|
pub enabled: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ComplianceConfig {
|
|
pub gdpr: bool,
|
|
pub hipaa: bool,
|
|
pub sox: bool,
|
|
pub custom_policies: Vec<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ScalingConfig {
|
|
pub auto_scale: bool,
|
|
pub min_instances: u32,
|
|
pub max_instances: u32,
|
|
pub cpu_threshold: u32,
|
|
pub memory_threshold: u32,
|
|
}
|
|
|
|
/// Ejemplo de configuración con wizard avanzado (Rhai)
|
|
pub fn configure_with_rhai_wizard() -> EnterpriseConfig {
|
|
// ✅ VENTAJAS del wizard Rhai para empresa:
|
|
|
|
// 1. Lógica condicional compleja
|
|
// 2. Integración con APIs externas
|
|
// 3. Validación de compliance automática
|
|
// 4. Configuración dinámica por tenant
|
|
// 5. Flujos de configuración personalizados
|
|
|
|
println!("=== Configuración Avanzada para Empresa Multi-Tenant ===");
|
|
|
|
// Ejemplo de lógica compleja que requiere Rhai:
|
|
let tenant_tier = determine_tenant_tier();
|
|
let features = get_features_for_tier(&tenant_tier);
|
|
let compliance = get_compliance_requirements();
|
|
let integrations = get_required_integrations(&tenant_tier);
|
|
|
|
EnterpriseConfig {
|
|
tenant_id: "enterprise-client-001".to_string(),
|
|
tier: tenant_tier,
|
|
features,
|
|
database_config: DatabaseConfig {
|
|
primary_url: "postgresql://enterprise-primary:5432/tenant_001".to_string(),
|
|
read_replicas: vec![
|
|
"postgresql://read-replica-1:5432/tenant_001".to_string(),
|
|
"postgresql://read-replica-2:5432/tenant_001".to_string(),
|
|
],
|
|
backup_config: BackupConfig {
|
|
enabled: true,
|
|
schedule: "0 2 * * *".to_string(),
|
|
retention_days: 90,
|
|
storage_type: "s3".to_string(),
|
|
},
|
|
encryption: EncryptionConfig {
|
|
at_rest: true,
|
|
in_transit: true,
|
|
key_management: "aws-kms".to_string(),
|
|
},
|
|
},
|
|
integrations,
|
|
compliance,
|
|
scaling: ScalingConfig {
|
|
auto_scale: true,
|
|
min_instances: 3,
|
|
max_instances: 100,
|
|
cpu_threshold: 70,
|
|
memory_threshold: 80,
|
|
},
|
|
}
|
|
}
|
|
|
|
fn determine_tenant_tier() -> ServiceTier {
|
|
// Lógica compleja que consulta APIs externas
|
|
// En Rhai esto sería mucho más flexible
|
|
println!("🔍 Determinando tier del tenant...");
|
|
println!("📞 Consultando sistema de billing...");
|
|
println!("📊 Verificando uso histórico...");
|
|
|
|
ServiceTier::Enterprise
|
|
}
|
|
|
|
fn get_features_for_tier(tier: &ServiceTier) -> Vec<String> {
|
|
match tier {
|
|
ServiceTier::Basic => vec!["auth".to_string(), "content-db".to_string()],
|
|
ServiceTier::Professional => vec![
|
|
"auth".to_string(),
|
|
"rbac".to_string(),
|
|
"content-db".to_string(),
|
|
"email".to_string(),
|
|
"metrics".to_string(),
|
|
],
|
|
ServiceTier::Enterprise => vec![
|
|
"auth".to_string(),
|
|
"rbac".to_string(),
|
|
"content-db".to_string(),
|
|
"email".to_string(),
|
|
"metrics".to_string(),
|
|
"tls".to_string(),
|
|
"crypto".to_string(),
|
|
"production".to_string(),
|
|
],
|
|
ServiceTier::Custom(_) => {
|
|
// Configuración completamente personalizada
|
|
vec!["all".to_string()]
|
|
}
|
|
}
|
|
}
|
|
|
|
fn get_compliance_requirements() -> ComplianceConfig {
|
|
// Lógica compleja de compliance
|
|
println!("⚖️ Evaluando requirements de compliance...");
|
|
println!("🌍 Verificando jurisdicción...");
|
|
println!("🏥 Verificando tipo de datos...");
|
|
|
|
ComplianceConfig {
|
|
gdpr: true,
|
|
hipaa: true,
|
|
sox: false,
|
|
custom_policies: vec![
|
|
"data-residency-eu".to_string(),
|
|
"audit-trail-complete".to_string(),
|
|
],
|
|
}
|
|
}
|
|
|
|
fn get_required_integrations(tier: &ServiceTier) -> Vec<Integration> {
|
|
let mut integrations = Vec::new();
|
|
|
|
// Integraciones base
|
|
integrations.push(Integration {
|
|
name: "auth0".to_string(),
|
|
config: HashMap::from([
|
|
("domain".to_string(), "enterprise.auth0.com".to_string()),
|
|
("client_id".to_string(), "enterprise_client_123".to_string()),
|
|
]),
|
|
enabled: true,
|
|
});
|
|
|
|
// Integraciones según tier
|
|
match tier {
|
|
ServiceTier::Enterprise | ServiceTier::Custom(_) => {
|
|
integrations.push(Integration {
|
|
name: "datadog".to_string(),
|
|
config: HashMap::from([
|
|
("api_key".to_string(), "dd_api_key".to_string()),
|
|
("site".to_string(), "datadoghq.eu".to_string()),
|
|
]),
|
|
enabled: true,
|
|
});
|
|
|
|
integrations.push(Integration {
|
|
name: "okta".to_string(),
|
|
config: HashMap::from([
|
|
("domain".to_string(), "enterprise.okta.com".to_string()),
|
|
("client_id".to_string(), "okta_client_456".to_string()),
|
|
]),
|
|
enabled: true,
|
|
});
|
|
}
|
|
_ => {}
|
|
}
|
|
|
|
integrations
|
|
}
|
|
|
|
/// Lo que una empresa multi-tenant SÍ necesita
|
|
pub fn what_enterprise_needs() {
|
|
println!("✅ Una empresa multi-tenant SÍ necesita:");
|
|
println!("- Configuración dinámica por tenant");
|
|
println!("- Integración con múltiples APIs externas");
|
|
println!("- Validación de compliance automática");
|
|
println!("- Configuración condicional compleja");
|
|
println!("- Flujos de configuración personalizados");
|
|
println!("- Lógica de negocio específica por cliente");
|
|
println!("- Configuración que cambia según el contexto");
|
|
}
|
|
|
|
/// Ventajas específicas de Rhai para este caso
|
|
pub fn rhai_advantages_for_enterprise() {
|
|
println!("🧙 Ventajas específicas de Rhai:");
|
|
println!("- Scripts modificables sin recompilación");
|
|
println!("- Lógica de configuración versionada");
|
|
println!("- Configuración A/B testing");
|
|
println!("- Rollback rápido de configuraciones");
|
|
println!("- Configuración por cliente sin rebuild");
|
|
println!("- Integración con sistemas externos");
|
|
println!("- Validación compleja de datos");
|
|
}
|
|
|
|
/// Ejemplo de script Rhai para configuración dinámica
|
|
pub fn example_rhai_script() -> &'static str {
|
|
r#"
|
|
// Script Rhai para configuración enterprise
|
|
let tenant_info = api_call("GET", "https://billing.company.com/api/tenants/" + tenant_id);
|
|
|
|
let config = #{
|
|
features: [],
|
|
tier: tenant_info.tier,
|
|
compliance: #{}
|
|
};
|
|
|
|
// Lógica condicional compleja
|
|
if tenant_info.tier == "enterprise" {
|
|
config.features = ["auth", "rbac", "tls", "crypto", "metrics"];
|
|
|
|
// Verificar compliance requirements
|
|
if tenant_info.industry == "healthcare" {
|
|
config.compliance.hipaa = true;
|
|
config.features.push("audit-logging");
|
|
}
|
|
|
|
if tenant_info.region == "eu" {
|
|
config.compliance.gdpr = true;
|
|
config.features.push("data-residency");
|
|
}
|
|
}
|
|
|
|
// Integración con APIs externas
|
|
let auth_config = api_call("GET", "https://auth.company.com/api/config/" + tenant_id);
|
|
config.auth = auth_config;
|
|
|
|
// Validación compleja
|
|
if !validate_compliance(config.compliance) {
|
|
throw "Compliance validation failed";
|
|
}
|
|
|
|
config
|
|
"#
|
|
}
|
|
|
|
/// Métricas de rendimiento para empresa (Rhai es aceptable)
|
|
pub fn performance_metrics() {
|
|
println!("📊 Métricas con wizard Rhai:");
|
|
println!("- Tiempo de configuración: ~5-10 minutos");
|
|
println!("- Tamaño del binario: +2MB");
|
|
println!("- Tiempo de startup: <500ms");
|
|
println!("- Memoria adicional: <10MB");
|
|
println!("- Flexibilidad: MÁXIMA");
|
|
}
|
|
|
|
/// Comparación de complejidad
|
|
pub fn complexity_comparison() {
|
|
println!("📈 Comparación de complejidad:");
|
|
println!("Simple Wizard:");
|
|
println!(" - Configuraciones: ~10");
|
|
println!(" - Líneas de código: ~500");
|
|
println!(" - Tiempo de desarrollo: 2-3 días");
|
|
println!();
|
|
println!("Rhai Wizard:");
|
|
println!(" - Configuraciones: ~100+");
|
|
println!(" - Líneas de código: ~2000+");
|
|
println!(" - Tiempo de desarrollo: 1-2 semanas");
|
|
println!(" - Pero: Infinitamente más flexible");
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_enterprise_config() {
|
|
let config = configure_with_rhai_wizard();
|
|
|
|
// Validar configuración enterprise
|
|
assert!(matches!(config.tier, ServiceTier::Enterprise));
|
|
assert!(config.features.len() > 5);
|
|
assert!(config.database_config.encryption.at_rest);
|
|
assert!(config.compliance.gdpr);
|
|
assert!(config.scaling.auto_scale);
|
|
}
|
|
|
|
#[test]
|
|
fn test_features_for_tier() {
|
|
let enterprise_features = get_features_for_tier(&ServiceTier::Enterprise);
|
|
let basic_features = get_features_for_tier(&ServiceTier::Basic);
|
|
|
|
assert!(enterprise_features.len() > basic_features.len());
|
|
assert!(enterprise_features.contains(&"tls".to_string()));
|
|
assert!(!basic_features.contains(&"tls".to_string()));
|
|
}
|
|
}
|
|
|
|
// Ejemplo de uso
|
|
fn main() {
|
|
println!("🏢 Ejemplo: Empresa Multi-Tenant");
|
|
println!("=================================");
|
|
|
|
let config = configure_with_rhai_wizard();
|
|
println!("✅ Configuración generada:");
|
|
println!(" Tenant: {}", config.tenant_id);
|
|
println!(" Tier: {:?}", config.tier);
|
|
println!(" Features: {:?}", config.features);
|
|
println!(" Integraciones: {}", config.integrations.len());
|
|
|
|
what_enterprise_needs();
|
|
rhai_advantages_for_enterprise();
|
|
performance_metrics();
|
|
complexity_comparison();
|
|
|
|
println!("\n🎉 Resultado: Wizard Rhai es ESENCIAL para este caso");
|
|
println!("📝 Script de ejemplo:");
|
|
println!("{}", example_rhai_script());
|
|
}
|