import { useState, useEffect, type ReactNode } from 'react'; import { motion } from 'motion/react'; import { ArrowRight } from 'lucide-react'; import { ShieldFilled, DatabaseFilled, ServerFilled, BoltFilled, EyeFilled, EyeOffFilled, CopyFilled, CheckFilled, CrossFilled, WarningFilled, RefreshFilled, FlowFilled, CoinFilled, LinkExternalFilled, GlobeFilled, PrismFilled, YoutubeFilled, VideoFilled, MegaphoneFilled, } from '../components/icons/FilledIcons'; /* ───────────────────────────── Types ───────────────────────────── */ type ApiStatus = 'connected' | 'missing' | 'error'; type ApiLayer = 'frontend' | 'edge-function' | 'both'; interface ApiConfig { id: string; name: string; description: string; envKeys: string[]; layer: ApiLayer; docsUrl: string; IconComponent: (props: { size?: number; className?: string }) => ReactNode; category: 'ai' | 'scraping' | 'social' | 'platform'; pricingModel: string; usedInPhases: string[]; estimatedCostPerRun?: string; rateLimit?: string; notes?: string; } interface ApiStatusInfo extends ApiConfig { status: ApiStatus; keyPresent: Record; } /* ──────────────────── API Registry (source of truth) ──────────── */ const API_REGISTRY: ApiConfig[] = [ { id: 'supabase', name: 'Supabase', description: 'PostgreSQL DB + Auth + Edge Functions 호스팅', envKeys: ['VITE_SUPABASE_URL', 'VITE_SUPABASE_ANON_KEY'], layer: 'both', docsUrl: 'https://supabase.com/docs', IconComponent: BoltFilled, category: 'platform', pricingModel: 'Free tier → Pro $25/mo', usedInPhases: ['All phases'], rateLimit: 'Edge Functions: 500K invocations/mo (free)', notes: '모든 데이터 저장 및 Edge Function 실행 플랫폼', }, { id: 'perplexity', name: 'Perplexity AI', description: 'LLM 기반 시장 분석 및 리포트 생성', envKeys: ['PERPLEXITY_API_KEY'], layer: 'edge-function', docsUrl: 'https://docs.perplexity.ai', IconComponent: PrismFilled, category: 'ai', pricingModel: 'Sonar: $1/1K requests', usedInPhases: ['Phase 1: discover', 'Phase 2: collect', 'Phase 3: generate'], estimatedCostPerRun: '~$0.05-0.15', rateLimit: '50 RPM (rate limit)', notes: 'discover(2회) + collect(4회 병렬) + generate(1회) = 분석당 ~7회 호출', }, { id: 'firecrawl', name: 'Firecrawl', description: '웹 스크래핑, 스크린샷 캡처, 구조화 데이터 추출', envKeys: ['FIRECRAWL_API_KEY'], layer: 'edge-function', docsUrl: 'https://docs.firecrawl.dev', IconComponent: GlobeFilled, category: 'scraping', pricingModel: 'Free 500 credits → $19/mo', usedInPhases: ['Phase 1: discover', 'Phase 2: collect'], estimatedCostPerRun: '~5-10 credits', rateLimit: '3 RPM (free), 20 RPM (paid)', notes: 'scrape + map + search + fullPage screenshot', }, { id: 'apify', name: 'Apify', description: 'Instagram/Facebook 데이터 수집', envKeys: ['APIFY_API_TOKEN'], layer: 'edge-function', docsUrl: 'https://docs.apify.com', IconComponent: ServerFilled, category: 'scraping', pricingModel: 'Free $5/mo → Starter $49/mo', usedInPhases: ['Phase 1: discover', 'Phase 2: collect', 'Enrich'], estimatedCostPerRun: '~$0.10-0.30', rateLimit: 'Actor-dependent (30-120s timeout)', notes: 'IG profile/posts/reels + FB pages actors', }, { id: 'google-places', name: 'Google Places API (New)', description: 'Google Maps 장소 검색, 평점, 리뷰, 연락처 데이터', envKeys: ['GOOGLE_PLACES_API_KEY'], layer: 'edge-function', docsUrl: 'https://developers.google.com/maps/documentation/places/web-service', IconComponent: GlobeFilled, category: 'social', pricingModel: '$200/mo 무료 크레딧 포함', usedInPhases: ['Phase 2: collect', 'Enrich', 'Registry enrichment'], estimatedCostPerRun: '~$0.04', rateLimit: 'No hard limit (pay-as-you-go)', notes: 'Text Search + Place Details (1-2초 응답, Apify 대비 30x 빠름)', }, { id: 'youtube', name: 'YouTube Data API v3', description: 'YouTube 채널 검색, 통계, 영상 데이터', envKeys: ['YOUTUBE_API_KEY'], layer: 'edge-function', docsUrl: 'https://developers.google.com/youtube/v3', IconComponent: YoutubeFilled, category: 'social', pricingModel: 'Free (10,000 units/day)', usedInPhases: ['Phase 1: discover', 'Phase 2: collect'], estimatedCostPerRun: '~200-400 units', rateLimit: '10,000 units/day', notes: 'search(100u) + channels(5u) + videos(5u each)', }, { id: 'naver', name: 'Naver Search API', description: '네이버 블로그/웹/플레이스 검색', envKeys: ['NAVER_CLIENT_ID', 'NAVER_CLIENT_SECRET'], layer: 'edge-function', docsUrl: 'https://developers.naver.com/docs/serviceapi/search/blog/blog.md', IconComponent: MegaphoneFilled, category: 'social', pricingModel: 'Free (25,000/day)', usedInPhases: ['Phase 1: discover', 'Phase 2: collect'], estimatedCostPerRun: 'Free', rateLimit: '25,000 calls/day', notes: 'blog.json + webkr.json + local.json', }, { id: 'gemini', name: 'Google Gemini', description: 'AI 이미지 생성 + Vision 분석 (스크린샷 OCR)', envKeys: ['GEMINI_API_KEY'], layer: 'edge-function', docsUrl: 'https://ai.google.dev/docs', IconComponent: DatabaseFilled, category: 'ai', pricingModel: 'Free tier → Pay-as-you-go', usedInPhases: ['Phase 2: collect (Vision)', 'Studio (Image Gen)'], estimatedCostPerRun: '~$0.01-0.05', rateLimit: '15 RPM (free), 1000 RPM (paid)', notes: 'gemini-2.5-flash-image 모델 사용', }, { id: 'creatomate', name: 'Creatomate', description: '마케팅 영상 자동 생성 (템플릿 기반)', envKeys: ['CREATOMATE_API_KEY'], layer: 'edge-function', docsUrl: 'https://creatomate.com/docs/api/introduction', IconComponent: VideoFilled, category: 'ai', pricingModel: 'Free 5 renders → Pro $39/mo', usedInPhases: ['Studio'], estimatedCostPerRun: '1 render credit', rateLimit: '2 concurrent renders (free)', notes: 'POST /renders → poll until complete', }, ]; /* ────────────────── Environment Variable Checker ─────────────── */ // 브라우저에서 확인할 수 있는 값은 공개를 전제로 만든 변수뿐이다. import.meta.env 를 이름으로 동적 조회하면 // Vite 가 VITE_ 변수 전체를 번들에 넣으므로(2026-10-07 VITE_CREATOMATE_API_KEY 노출 원인), 여기 적은 것만 읽는다. const PUBLIC_ENV: Record = { VITE_SUPABASE_URL: import.meta.env.VITE_SUPABASE_URL, VITE_SUPABASE_ANON_KEY: import.meta.env.VITE_SUPABASE_ANON_KEY, }; function checkEnvVars(): ApiStatusInfo[] { return API_REGISTRY.map((api) => { const keyPresent: Record = {}; for (const key of api.envKeys) { if (key.startsWith('VITE_')) { const val = PUBLIC_ENV[key]; keyPresent[key] = !!val && val.length > 0; } else { keyPresent[key] = true; } } const allPresent = Object.values(keyPresent).every(Boolean); const nonePresent = Object.values(keyPresent).every((v) => !v); return { ...api, status: nonePresent ? 'missing' : allPresent ? 'connected' : 'error', keyPresent, }; }); } /* ──────────────────────── Sub-components ──────────────────────── */ function StatusDot({ status }: { status: ApiStatus }) { const styles = { connected: 'bg-status-good-dot', missing: 'bg-status-critical-dot', error: 'bg-status-warning-dot', }; return ( {status === 'connected' && ( )} ); } function StatusBadge({ status }: { status: ApiStatus }) { const config = { connected: { bg: 'bg-status-good-bg', text: 'text-status-good-text', border: 'border-status-good-border', label: 'Connected', Icon: CheckFilled }, missing: { bg: 'bg-status-critical-bg', text: 'text-status-critical-text', border: 'border-status-critical-border', label: 'Missing Key', Icon: CrossFilled }, error: { bg: 'bg-status-warning-bg', text: 'text-status-warning-text', border: 'border-status-warning-border', label: 'Partial', Icon: WarningFilled }, }; const c = config[status]; return ( {c.label} ); } function LayerBadge({ layer }: { layer: ApiLayer }) { const config = { frontend: { bg: 'bg-status-info-bg', text: 'text-status-info-text', border: 'border-status-info-border', label: 'Frontend', Icon: GlobeFilled }, 'edge-function': { bg: 'bg-status-good-bg', text: 'text-status-good-text', border: 'border-status-good-border', label: 'Edge Function', Icon: ServerFilled }, both: { bg: 'bg-status-warning-bg', text: 'text-status-warning-text', border: 'border-status-warning-border', label: 'Both', Icon: BoltFilled }, }; const c = config[layer]; return ( {c.label} ); } function CategoryBadge({ category }: { category: ApiConfig['category'] }) { const config = { ai: { bg: 'bg-status-good-bg', text: 'text-status-good-text', label: 'AI' }, scraping: { bg: 'bg-status-warning-bg', text: 'text-status-warning-text', label: 'Scraping' }, social: { bg: 'bg-status-info-bg', text: 'text-status-info-text', label: 'Social' }, platform: { bg: 'bg-primary-50', text: 'text-primary-800', label: 'Platform' }, }; const c = config[category]; return ( {c.label} ); } function EnvKeyRow({ envKey, present, isServerSide }: { key?: string; envKey: string; present: boolean; isServerSide: boolean }) { const [showKey, setShowKey] = useState(false); const [copied, setCopied] = useState(false); const value = isServerSide ? '(Edge Function 환경변수 — 프론트엔드에서 확인 불가)' : showKey ? PUBLIC_ENV[envKey] || '' : '••••••••••••••••'; const handleCopy = () => { if (!isServerSide) { navigator.clipboard.writeText(PUBLIC_ENV[envKey] || ''); setCopied(true); setTimeout(() => setCopied(false), 1500); } }; return (
{envKey} {value} {!isServerSide && (
)}
); } function ApiCard({ api, index }: { key?: string; api: ApiStatusInfo; index: number }) { const [expanded, setExpanded] = useState(false); return ( {/* Header */} {/* Expandable detail */} {expanded && ( {/* Env Keys */}

Environment Variables

{api.envKeys.map((key) => ( ))}
{/* Info Grid */}
Pricing
{api.pricingModel}
{api.estimatedCostPerRun && (
Cost / Run
{api.estimatedCostPerRun}
)} {api.rateLimit && (
Rate Limit
{api.rateLimit}
)}
Used In
{api.usedInPhases.join(', ')}
{/* Notes + Docs link */}
{api.notes && (

{api.notes}

)} API Docs
)}
); } /* ──────────────────── Pipeline Flow Diagram ───────────────────── */ function PipelineFlow({ apis }: { apis: ApiStatusInfo[] }) { const phases = [ { name: 'Phase 1', label: 'Discover Channels', apis: ['firecrawl', 'youtube', 'naver', 'perplexity', 'apify'] }, { name: 'Phase 2', label: 'Collect Data', apis: ['apify', 'youtube', 'firecrawl', 'naver', 'perplexity', 'gemini'] }, { name: 'Phase 3', label: 'Generate Report', apis: ['perplexity'] }, { name: 'Studio', label: 'Content Creation', apis: ['gemini', 'creatomate'] }, ]; const apiMap = Object.fromEntries(apis.map((a) => [a.id, a])); return (

Pipeline API Flow

{phases.map((phase, idx) => (
{phase.name}: {phase.label}
{phase.apis.map((apiId) => { const api = apiMap[apiId]; if (!api) return null; return (
{api.name}
); })}
{idx < phases.length - 1 && (
)}
))}
); } /* ────────────────────── Cost Estimator ────────────────────────── */ function CostEstimator({ apis }: { apis: ApiStatusInfo[] }) { const costItems = apis .filter((a) => a.estimatedCostPerRun) .map((a) => ({ name: a.name, IconComponent: a.IconComponent, cost: a.estimatedCostPerRun!, })); return (

Estimated Cost per Analysis Run

{costItems.map((item) => (
{item.name} {item.cost}
))}
Total (estimated) ~$0.26-0.80 / run
); } /* ──────────────────────── Main Page ───────────────────────────── */ export default function ApiDashboardPage() { const [apis, setApis] = useState([]); const [lastChecked, setLastChecked] = useState(null); const [filter, setFilter] = useState<'all' | 'connected' | 'missing'>('all'); const refreshStatus = () => { setApis(checkEnvVars()); setLastChecked(new Date()); }; useEffect(() => { refreshStatus(); }, []); const connectedCount = apis.filter((a) => a.status === 'connected').length; const missingCount = apis.filter((a) => a.status === 'missing').length; const errorCount = apis.filter((a) => a.status === 'error').length; const filteredApis = filter === 'all' ? apis : apis.filter((a) => a.status === filter); return (
{/* Page Header */}

API Dashboard

API 연결 상태, 환경변수, 사용량, 비용 현황

{/* Summary Cards */}
Total APIs
{apis.length}
Connected
{connectedCount}
Missing
{missingCount}
Partial
{errorCount}
{/* Pipeline Flow */} {/* Filter + Refresh */}
{(['all', 'connected', 'missing'] as const).map((f) => ( ))}
{lastChecked && ( Last checked: {lastChecked.toLocaleTimeString('ko-KR')} )}
{/* API Cards */}
{filteredApis.map((api, idx) => ( ))}
{/* Cost Estimator */} {/* Footer note */}
VITE_ 접두사 키만 프론트엔드에서 확인 가능합니다. Edge Function 키는 Supabase Dashboard에서 확인하세요.
); }