{
  "$schema": "./schemas/config.schema.json",
  "version": "2.0.0",
  "metadata": {
    "projectName": "PackCDN",
    "environment": "production",
    "lastUpdated": "2024-01-01T00:00:00.000Z",
    "configId": "config_packcdn_" + Math.random().toString(36).substr(2, 9),
    "siteUrl": "https://pack-cdn.vercel.app",
    "workerUrl": "https://packcdn.firefly-worker.workers.dev"
  },
  
  "security": {
    "encryption": {
      "enabled": true,
      "algorithm": "aes-256-gcm",
      "keyRotationDays": 30,
      "encryptedFields": ["urls.private", "apiKeys", "secrets", "supabase.url", "admin.password"]
    },
    "authentication": {
      "required": true,
      "jwtExpiry": "24h",
      "rateLimit": {
        "maxRequests": 100,
        "windowMs": 900000
      }
    },
    "cors": {
      "allowedOrigins": [
        "https://pack-cdn.vercel.app",
        "https://packcdn.firefly-worker.workers.dev",
        "http://localhost:3000",
        "http://localhost:5173",
        "http://127.0.0.1:3000",
        "http://127.0.0.1:5173"
      ],
      "allowedMethods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
    },
    "admin": {
      "passwordHash": "ENC[AES256_GCM,data:...iv:...tag:...]",
      "sessionTimeout": "1h",
      "maxLoginAttempts": 5,
      "ipWhitelist": []
    }
  },
  
  "urls": {
    "public": {
      "api": "https://packcdn.firefly-worker.workers.dev",
      "cdn": "https://packcdn.firefly-worker.workers.dev/cdn",
      "site": "https://pack-cdn.vercel.app",
      "docs": "https://pack-cdn.vercel.app/docs.html",
      "editor": "https://pack-cdn.vercel.app/editor.html",
      "explore": "https://pack-cdn.vercel.app/explore.html"
    },
    "private": {
      "encrypted": true,
      "endpoints": [
        {
          "name": "admin",
          "url": "https://pack-cdn.vercel.app/admin.html",
          "description": "Admin database interface",
          "accessLevel": "admin"
        },
        {
          "name": "supabase",
          "url": "ENC[AES256_GCM,data:...iv:...tag:...]",
          "description": "Supabase database URL",
          "accessLevel": "system"
        },
        {
          "name": "workerAdmin",
          "url": "ENC[AES256_GCM,data:...iv:...tag:...]",
          "description": "Cloudflare Worker admin panel",
          "accessLevel": "admin"
        }
      ]
    },
    "dynamic": {
      "enabled": true,
      "resolver": "vercel",
      "fallbackUrls": ["https://backup.pack-cdn.vercel.app", "https://backup-cdn.firefly-worker.workers.dev"]
    }
  },
  
  "packs": {
    "defaults": {
      "type": "basic",
      "capabilities": ["execute", "log", "fetch"],
      "environment": "browser",
      "timeout": 30000,
      "memoryLimit": "256MB"
    },
    "creation": {
      "autoStart": true,
      "healthCheck": true,
      "persistent": false,
      "maxPacksPerUser": 50,
      "maxFilesPerPack": 100,
      "maxSizePerPack": "25MB",
      "packageTypes": ["basic", "standard", "advanced"]
    },
    "cdn": {
      "workerUrl": "https://packcdn.firefly-worker.workers.dev",
      "cdnPath": "/cdn",
      "packPath": "/pack",
      "searchPath": "/search",
      "supportedFormats": ["js", "mjs", "cjs", "py", "wasm", "json", "html", "css", "md", "txt"]
    },
    "networking": {
      "allowedDomains": ["*.vercel.app", "*.workers.dev", "*.github.com", "*.supabase.co"],
      "blockedDomains": ["*.malicious.com", "*.phishing.com"],
      "proxySupport": true,
      "maxConcurrentRequests": 10
    }
  },
  
  "api": {
    "endpoints": {
      "health": "/api/health",
      "analyze": "/api/analyze.js",
      "getPack": "/api/get-pack.js",
      "publish": "/api/publish.js",
      "search": "/api/search.js",
      "adminDatabase": "/api/admin/database.js"
    },
    "version": "v1",
    "timeout": 15000,
    "retry": {
      "attempts": 3,
      "delay": 1000,
      "backoff": true
    },
    "limits": {
      "maxPayloadSize": "50MB",
      "maxFileSize": "10MB",
      "rateLimit": "100/15min"
    }
  },
  
  "database": {
    "type": "supabase",
    "url": "ENC[AES256_GCM,data:...iv:...tag:...]",
    "key": "ENC[AES256_GCM,data:...iv:...tag:...]",
    "serviceKey": "ENC[AES256_GCM,data:...iv:...tag:...]",
    "tables": {
      "packs": "packs",
      "pack_versions": "pack_versions",
      "pack_metadata": "pack_metadata",
      "pack_dependencies": "pack_dependencies",
      "pack_collaborators": "pack_collaborators",
      "pack_changes": "pack_changes",
      "edit_tokens": "edit_tokens"
    },
    "persistence": {
      "enabled": true,
      "strategy": "supabase",
      "ttl": 86400
    },
    "encryption": {
      "atRest": true,
      "inTransit": true
    }
  },
  
  "features": {
    "editor": {
      "autoComplete": true,
      "linting": true,
      "snippets": true,
      "themes": ["monokai", "dracula", "solarized"],
      "supportedLanguages": ["javascript", "typescript", "python", "json", "html", "css", "markdown"]
    },
    "console": {
      "theme": "dark",
      "maxHistory": 1000,
      "autoScroll": true,
      "syntaxHighlighting": true
    },
    "monitoring": {
      "enabled": true,
      "metrics": ["requests", "errors", "publishes", "cdn_hits"],
      "alerting": {
        "enabled": true,
        "webhook": "ENC[AES256_GCM,data:...iv:...tag:...]"
      }
    },
    "adminPanel": {
      "enabled": true,
      "path": "/admin.html",
      "requiresPassword": true,
      "securityLevel": "high",
      "encryption": "quantum-grade",
      "logging": true
    }
  },
  
  "logging": {
    "level": "info",
    "transport": ["console", "supabase", "file"],
    "format": "json",
    "retention": "30d",
    "sensitiveFields": ["password", "token", "secret", "key", "url", "signature"]
  },
  
  "maintenance": {
    "mode": false,
    "message": "PackCDN is under maintenance. We'll be back soon!",
    "schedule": "02:00-04:00 UTC",
    "autoUpdates": true
  },
  
  "extensions": {
    "plugins": {
      "enabled": true,
      "directory": "./plugins",
      "autoLoad": ["metrics", "security", "backup", "cdn", "validation"]
    },
    "webhooks": {
      "enabled": true,
      "events": ["pack.created", "pack.published", "pack.deleted", "error", "alert", "admin.login"]
    }
  },
  
  "performance": {
    "caching": {
      "enabled": true,
      "ttl": 86400,
      "strategy": "stale-while-revalidate",
      "cdn": "cloudflare"
    },
    "compression": true,
    "minify": true,
    "cdn": {
      "enabled": true,
      "provider": "cloudflare-workers",
      "worker": "packcdn.firefly-worker.workers.dev"
    }
  },
  
  "secrets": {
    "apiKeys": {
      "supabase": "ENC[AES256_GCM,data:...iv:...tag:...]",
      "supabaseService": "ENC[AES256_GCM,data:...iv:...tag:...]",
      "worker": "ENC[AES256_GCM,data:...iv:...tag:...]"
    },
    "tokens": {
      "encryption": "ENC[AES256_GCM,data:...iv:...tag:...]",
      "jwt": "ENC[AES256_GCM,data:...iv:...tag:...]",
      "admin": "ENC[AES256_GCM,data:...iv:...tag:...]"
    },
    "passwords": {
      "admin": "ENC[AES256_GCM,data:...iv:...tag:...]",
      "database": "ENC[AES256_GCM,data:...iv:...tag:...]"
    }
  },
  
  "environments": {
    "development": {
      "siteUrl": "http://localhost:3000",
      "workerUrl": "http://localhost:8787",
      "cors": {
        "allowedOrigins": ["http://localhost:3000", "http://localhost:5173", "http://localhost:8787"]
      }
    },
    "staging": {
      "siteUrl": "https://pack-cdn.vercel.app",
      "workerUrl": "https://packcdn.firefly-worker.workers.dev"
    },
    "production": {
      "siteUrl": "https://pack-cdn.vercel.app",
      "workerUrl": "https://packcdn.firefly-worker.workers.dev"
    }
  },
  
  "custom": {
    "modules": ["cdn-worker", "publish-api", "admin-interface", "pack-analytics"],
    "scripts": {
      "build": "npm run build",
      "deploy": "vercel deploy --prod",
      "deploy-worker": "wrangler publish",
      "test": "npm test"
    },
    "variables": {
      "SUPABASE_URL": "${supabase.url}",
      "SUPABASE_ANON_KEY": "${secrets.apiKeys.supabase}",
      "SUPABASE_SERVICE_ROLE_KEY": "${secrets.apiKeys.supabaseService}",
      "ADMIN_PASSWORD": "${secrets.passwords.admin}",
      "ENCRYPTION_KEY": "${secrets.tokens.encryption}"
    },
    "overrides": {
      "cdn": {
        "worker": "Cloudflare_Workers/cdn_worker.js",
        "config": "wrangler.toml"
      },
      "api": {
        "directory": "/api",
        "handlers": ["analyze.js", "get-pack.js", "publish.js", "search.js", "admin/database.js"]
      }
    }
  }
}
