Build a synthetic partner integration lab that simulates third-party API behaviors,…
- User
Build a synthetic partner integration lab that simulates third-party API behaviors, error patterns, and schema evolution scenarios.
Assistant
This is a sophisticated developer tool request. The user wants a "synthetic partner integration lab" - essentially a simulation environment for testing how their systems handle third-party API integrations. This needs to handle:
- Third-party API behaviors - Simulating realistic API responses, latencies, rate limiting, etc.
- Error patterns - Different types of errors (network, auth, validation, server errors) with realistic patterns
- Schema evolution - Testing how systems handle API changes over time (field additions/removals, type changes, versioning)
This is a professional tool, so I need a design that feels:
- Technical/industrial
- Data-focused
- Sophisticated without being flashy
- Dark theme with high contrast for long coding sessions
Design Direction:
- Dark, technical aesthetic (think IDE/terminal vibes)
- Monospace elements for code-like feel
- Color scheme: Dark base (#0a0a0f or similar), with accent colors for different error types
- Grid/data visualization feel
- Terminal/console inspired elements
Font choices:
- Display: "JetBrains Mono" or "IBM Plex Mono" for that developer feel
- UI: "Inter" or "IBM Plex Sans" for readability
Wait, I'm supposed to avoid Inter. Let me use "Space Grotesk" as the UI font - it has a nice technical feel.
Features to implement:
-
Partner API Simulator
- Multiple simulated partner APIs (Payment, CRM, Analytics, etc.)
- Toggle different behaviors (normal, degraded, failing)
- Adjustable latency, error rates
-
Error Pattern Generator
- Configurable error scenarios
- Network timeouts, 5xx errors, rate limiting
- Cascade failures, intermittent issues
- Visual timeline of errors
-
Schema Evolution Sandbox
- Version switcher (v1, v2, v3)
- Show schema diffs
- Breaking vs non-breaking changes
- Migration testing
-
Request/Response Inspector
- Live request log
- Response visualization
- Performance metrics
-
Integration Health Dashboard
- Status of all partners
- Error rates, latency percentiles
- Circuit breaker status
Interactions:
- Run simulation with configurable parameters
- Schema version switching with diff visualization
- Real-time request/response logging
- Partner status toggling
- Error injection controls
Let me build this out with a rich, functional interface. This is a powerful tool concept for engineering teams. I'll create a sophisticated simulation environment with real-time API behavior control, error pattern injection, and schema evolution testing.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Partner Integration Lab</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&display=swap" rel="stylesheet"> <style> :root { --bg: #08090d; --bg-elevated: #0d0f14; --card: #12151c; --card-hover: #181c25; --border: #1e232e; --border-active: #2a3142; --fg: #e4e7ed; --fg-muted: #6b7280; --fg-dim: #404758; --accent: #22d3ee; --accent-dim: rgba(34, 211, 238, 0.15); --success: #34d399; --success-dim: rgba(52, 211, 153, 0.15); --warning: #fbbf24; --warning-dim: rgba(251, 191, 36, 0.15); --error: #f87171; --error-dim: rgba(248, 113, 113, 0.15); --purple: #a78bfa; --purple-dim: rgba(167, 139, 250, 0.15); } * { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); } *::-webkit-scrollbar { width: 6px; height: 6px; } *::-webkit-scrollbar-track { background: var(--bg); } *::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; } body { font-family: 'Space Grotesk', sans-serif; background: var(--bg); color: var(--fg); } .font-mono { font-family: 'JetBrains Mono', monospace; } .bg-grid { background-image: linear-gradient(rgba(34, 211, 238, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(34, 211, 238, 0.03) 1px, transparent 1px); background-size: 24px 24px; } .card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; transition: all 0.2s ease; } .card:hover { border-color: var(--border-active); } .btn { padding: 8px 16px; border-radius: 6px; font-weight: 500; font-size: 13px; transition: all 0.15s ease; cursor: pointer; border: 1px solid transparent; } .btn-primary { background: var(--accent); color: var(--bg); } .btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); } .btn-secondary { background: var(--card); border-color: var(--border); color: var(--fg); } .btn-secondary:hover { background: var(--card-hover); border-color: var(--border-active); } .btn-danger { background: var(--error-dim); border-color: var(--error); color: var(--error); } .btn-danger:hover { background: var(--error); color: var(--bg); } .toggle { width: 40px; height: 22px; background: var(--border); border-radius: 11px; position: relative; cursor: pointer; transition: background 0.2s ease; } .toggle.active { background: var(--accent); } .toggle::after { content: ''; position: absolute; width: 16px; height: 16px; background: var(--fg); border-radius: 50%; top: 3px; left: 3px; transition: transform 0.2s ease; } .toggle.active::after { transform: translateX(18px); } .slider { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--border); border-radius: 2px; outline: none; } .slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; background: var(--accent); border-radius: 50%; cursor: pointer; transition: transform 0.15s ease; } .slider::-webkit-slider-thumb:hover { transform: scale(1.2); } .status-dot { width: 8px; height: 8px; border-radius: 50%; animation: pulse 2s ease-in-out infinite; } @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } } .fade-in { animation: fadeIn 0.3s ease forwards; } @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .slide-in { animation: slideIn 0.4s ease forwards; } @keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } } @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } } .schema-diff-add { background: var(--success-dim); border-left: 3px solid var(--success); } .schema-diff-remove { background: var(--error-dim); border-left: 3px solid var(--error); text-decoration: line-through; opacity: 0.6; } .schema-diff-modified { background: var(--warning-dim); border-left: 3px solid var(--warning); } .request-log-entry { border-left: 3px solid var(--border); transition: all 0.15s ease; } .request-log-entry:hover { border-left-color: var(--accent); background: var(--card-hover); } .request-log-entry.error { border-left-color: var(--error); } .request-log-entry.success { border-left-color: var(--success); } .request-log-entry.warning { border-left-color: var(--warning); } .tab { padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--fg-muted); border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.15s ease; } .tab:hover { color: var(--fg); } .tab.active { color: var(--accent); border-bottom-color: var(--accent); } .metric-card { background: linear-gradient(135deg, var(--card) 0%, var(--bg-elevated) 100%); } .glow-line { height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: 0.5; } </style> </head> <body class="min-h-screen bg-grid"> <div class="flex h-screen overflow-hidden"> <!-- Sidebar --> <aside class="w-64 border-r border-[var(--border)] bg-[var(--bg-elevated)] flex flex-col"> <div class="p-4 border-b border-[var(--border)]"> <div class="flex items-center gap-3"> <div class="w-8 h-8 rounded-lg bg-[var(--accent-dim)] flex items-center justify-center"> <svg class="w-4 h-4 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/> </svg> </div> <div> <h1 class="font-semibold text-sm">Integration Lab</h1> <p class="text-[10px] text-[var(--fg-muted)]">v2.4.1</p> </div> </div> </div> <!-- Partner List --> <div class="flex-1 overflow-y-auto p-3"> <p class="text-[10px] uppercase tracking-wider text-[var(--fg-dim)] mb-3 px-2">Partners</p> <div id="partnerList" class="space-y-1"></div> </div> <!-- Lab Status --> <div class="p-4 border-t border-[var(--border)]"> <div class="flex items-center justify-between mb-3"> <span class="text-xs text-[var(--fg-muted)]">Lab Status</span> <div id="labStatus" class="flex items-center gap-2"> <div class="status-dot bg-[var(--success)]"></div> <span class="text-xs text-[var(--success)]">Running</span> </div> </div> <button id="resetLabBtn" class="btn btn-secondary w-full text-xs"> Reset All Simulations </button> </div> </aside> <!-- Main Content --> <main class="flex-1 flex flex-col overflow-hidden"> <!-- Header --> <header class="h-14 border-b border-[var(--border)] bg-[var(--bg-elevated)] flex items-center justify-between px-6"> <div class="flex items-center gap-4"> <h2 id="selectedPartnerName" class="font-semibold">Select a Partner</h2> <span id="selectedPartnerVersion" class="font-mono text-xs text-[var(--fg-muted)] bg-[var(--card)] px-2 py-1 rounded"></span> </div> <div class="flex items-center gap-3"> <button id="runTestBtn" class="btn btn-primary flex items-center gap-2"> <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/> </svg> Run Test Suite </button> </div> </header> <!-- Content Area --> <div class="flex-1 overflow-hidden flex"> <!-- Left Panel - Controls --> <div class="w-96 border-r border-[var(--border)] overflow-y-auto bg-[var(--bg-elevated)]"> <div id="controlPanel" class="p-4 space-y-4"> <!-- Tabs --> <div class="flex border-b border-[var(--border)]"> <button class="tab active" data-tab="behavior">Behavior</button> <button class="tab" data-tab="errors">Errors</button> <button class="tab" data-tab="schema">Schema</button> </div> <!-- Behavior Tab --> <div id="behaviorTab" class="tab-content space-y-4"> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Response Latency</h3> <div class="space-y-3"> <div> <div class="flex justify-between text-xs mb-2"> <span class="text-[var(--fg-muted)]">Base Latency</span> <span id="latencyValue" class="font-mono">150ms</span> </div> <input type="range" id="latencySlider" class="slider" min="0" max="2000" value="150"> </div> <div> <div class="flex justify-between text-xs mb-2"> <span class="text-[var(--fg-muted)]">Jitter</span> <span id="jitterValue" class="font-mono">50ms</span> </div> <input type="range" id="jitterSlider" class="slider" min="0" max="500" value="50"> </div> </div> </div> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Rate Limiting</h3> <div class="space-y-3"> <div class="flex items-center justify-between"> <span class="text-sm">Enable Rate Limit</span> <div id="rateLimitToggle" class="toggle active"></div> </div> <div> <div class="flex justify-between text-xs mb-2"> <span class="text-[var(--fg-muted)]">Requests/min</span> <span id="rateLimitValue" class="font-mono">60</span> </div> <input type="range" id="rateLimitSlider" class="slider" min="10" max="200" value="60"> </div> </div> </div> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Availability</h3> <div class="space-y-3"> <div> <div class="flex justify-between text-xs mb-2"> <span class="text-[var(--fg-muted)]">Uptime %</span> <span id="uptimeValue" class="font-mono">99.9%</span> </div> <input type="range" id="uptimeSlider" class="slider" min="50" max="100" value="99.9" step="0.1"> </div> </div> </div> </div> <!-- Errors Tab --> <div id="errorsTab" class="tab-content space-y-4 hidden"> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Error Injection</h3> <div class="space-y-3"> <div class="flex items-center justify-between"> <div> <span class="text-sm">Network Timeouts</span> <p class="text-[10px] text-[var(--fg-dim)]">Simulate connection drops</p> </div> <div id="timeoutErrorToggle" class="toggle"></div> </div> <div class="flex items-center justify-between"> <div> <span class="text-sm">5xx Server Errors</span> <p class="text-[10px] text-[var(--fg-dim)]">Internal server failures</p> </div> <div id="serverErrorToggle" class="toggle"></div> </div> <div class="flex items-center justify-between"> <div> <span class="text-sm">4xx Client Errors</span> <p class="text-[10px] text-[var(--fg-dim)]">Auth/validation failures</p> </div> <div id="clientErrorToggle" class="toggle"></div> </div> <div class="flex items-center justify-between"> <div> <span class="text-sm">Malformed Responses</span> <p class="text-[10px] text-[var(--fg-dim)]">Invalid JSON schemas</p> </div> <div id="malformedToggle" class="toggle"></div> </div> </div> </div> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Error Rate</h3> <div> <div class="flex justify-between text-xs mb-2"> <span class="text-[var(--fg-muted)]">Probability</span> <span id="errorRateValue" class="font-mono">5%</span> </div> <input type="range" id="errorRateSlider" class="slider" min="0" max="50" value="5"> </div> </div> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Cascade Scenarios</h3> <div class="space-y-2"> <button class="btn btn-secondary w-full text-xs text-left" data-scenario="thundering-herd"> Thundering Herd </button> <button class="btn btn-secondary w-full text-xs text-left" data-scenario="slow-burn"> Slow Burn (Memory Leak) </button> <button class="btn btn-secondary w-full text-xs text-left" data-scenario="flapping"> Flapping Service </button> </div> </div> </div> <!-- Schema Tab --> <div id="schemaTab" class="tab-content space-y-4 hidden"> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Schema Version</h3> <div class="space-y-2"> <select id="schemaVersionSelect" class="w-full bg-[var(--bg)] border border-[var(--border)] rounded px-3 py-2 text-sm"> <option value="v1">v1.0.0 - Baseline</option> <option value="v2">v2.0.0 - Breaking Changes</option> <option value="v3">v3.0.0 - Extended Schema</option> </select> </div> </div> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-4">Evolution Scenarios</h3> <div class="space-y-3"> <div class="flex items-center justify-between"> <div> <span class="text-sm">Field Addition</span> <p class="text-[10px] text-[var(--fg-dim)]">New optional fields</p> </div> <div id="fieldAddToggle" class="toggle active"></div> </div> <div class="flex items-center justify-between"> <div> <span class="text-sm">Field Deprecation</span> <p class="text-[10px] text-[var(--fg-dim)]">Mark fields as deprecated</p> </div> <div id="fieldDeprecateToggle" class="toggle"></div> </div> <div class="flex items-center justify-between"> <div> <span class="text-sm">Type Changes</span> <p class="text-[10px] text-[var(--fg-dim)]">Breaking type mutations</p> </div> <div id="typeChangeToggle" class="toggle"></div> </div> <div class="flex items-center justify-between"> <div> <span class="text-sm">Nested Restructure</span> <p class="text-[10px] text-[var(--fg-dim)]">Deep schema changes</p> </div> <div id="nestedToggle" class="toggle"></div> </div> </div> </div> <div class="card p-4"> <h3 class="text-xs font-semibold uppercase tracking-wider text-[var(--fg-muted)] mb-3">Migration Path</h3> <div class="text-xs text-[var(--fg-muted)] space-y-2"> <p>Test backwards compatibility by enabling multiple versions simultaneously.</p> <div class="flex gap-2"> <span class="px-2 py-1 rounded bg-[var(--accent-dim)] text-[var(--accent)]">v1</span> <span class="text-[var(--fg-dim)]">→</span> <span class="px-2 py-1 rounded bg-[var(--warning-dim)] text-[var(--warning)]">v2</span> <span class="text-[var(--fg-dim)]">→</span> <span class="px-2 py-1 rounded bg-[var(--success-dim)] text-[var(--success)]">v3</span> </div> </div> </div> </div> </div> </div> <!-- Right Panel - Visualization --> <div class="flex-1 flex flex-col overflow-hidden"> <!-- Metrics Bar --> <div id="metricsBar" class="grid grid-cols-4 gap-4 p-4 border-b border-[var(--border)]"> <div class="metric-card card p-3"> <p class="text-[10px] uppercase tracking-wider text-[var(--fg-dim)]">Avg Latency</p> <p id="metricLatency" class="text-xl font-semibold font-mono mt-1">--</p> </div> <div class="metric-card card p-3"> <p class="text-[10px] uppercase tracking-wider text-[var(--fg-dim)]">Success Rate</p> <p id="metricSuccess" class="text-xl font-semibold font-mono mt-1 text-[var(--success)]">--</p> </div> <div class="metric-card card p-3"> <p class="text-[10px] uppercase tracking-wider text-[var(--fg-dim)]">Error Count</p> <p id="metricErrors" class="text-xl font-semibold font-mono mt-1 text-[var(--error)]">--</p> </div> <div class="metric-card card p-3"> <p class="text-[10px] uppercase tracking-wider text-[var(--fg-dim)]">P99 Latency</p> <p id="metricP99" class="text-xl font-semibold font-mono mt-1">--</p> </div> </div> <!-- Main Visualization Area --> <div class="flex-1 overflow-hidden flex flex-col"> <!-- Tabs for different views --> <div class="flex border-b border-[var(--border)] bg-[var(--bg-elevated)]"> <button class="tab active" data-view="requests">Request Log</button> <button class="tab" data-view="schema">Schema Diff</button> <button class="tab" data-view="response">Response Preview</button> </div> <!-- Request Log View --> <div id="requestsView" class="flex-1 overflow-y-auto p-4"> <div id="requestLog" class="space-y-2"></div> <div id="emptyRequestLog" class="flex flex-col items-center justify-center h-full text-[var(--fg-dim)]"> <svg class="w-12 h-12 mb-4 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/> </svg> <p class="text-sm">Run a test to see request logs</p> </div> </div> <!-- Schema Diff View --> <div id="schemaView" class="flex-1 overflow-y-auto p-4 hidden"> <div class="grid grid-cols-2 gap-4 h-full"> <div class="card p-4 overflow-auto"> <div class="flex items-center justify-between mb-4"> <h3 class="font-semibold text-sm">Current Schema</h3> <span id="currentSchemaVersion" class="font-mono text-xs bg-[var(--accent-dim)] text-[var(--accent)] px-2 py-1 rounded">v1</span> </div> <pre id="currentSchema" class="font-mono text-xs text-[var(--fg-muted)] leading-relaxed"></pre> </div> <div class="card p-4 overflow-auto"> <div class="flex items-center justify-between mb-4"> <h3 class="font-semibold text-sm">Diff Preview</h3> <span id="targetSchemaVersion" class="font-mono text-xs bg-[var(--warning-dim)] text-[var(--warning)] px-2 py-1 rounded">v2</span> </div> <div id="schemaDiff" class="font-mono text-xs leading-relaxed"></div> </div> </div> </div> <!-- Response Preview View --> <div id="responseView" class="flex-1 overflow-y-auto p-4 hidden"> <div class="card p-4 h-full"> <div class="flex items-center justify-between mb-4"> <h3 class="font-semibold text-sm">Sample Response</h3> <div class="flex items-center gap-2"> <span id="responseStatus" class="font-mono text-xs px-2 py-1 rounded bg-[var(--success-dim)] text-[var(--success)]">200 OK</span> <span id="responseTime" class="font-mono text-xs text-[var(--fg-muted)]">142ms</span> </div> </div> <pre id="responseBody" class="font-mono text-xs text-[var(--fg-muted)] leading-relaxed overflow-auto max-h-96"></pre> </div> </div> </div> </div> </div> </main> </div> <script> // Initialize state before any function calls const state = { selectedPartner: null, isRunning: false, requestLog: [], metrics: { totalRequests: 0, successCount: 0, errorCount: 0, latencies: [] }, simulation: null, labActive: true }; // Partner data const partners = [ { id: 'payment-gateway', name: 'Payment Gateway', icon: '💳', status: 'healthy', version: 'v2.4.0', endpoints: ['/charge', '/refund', '/capture'], config: { latency: 150, jitter: 50, rateLimit: 60, uptime: 99.9, errorRate: 2 } }, { id: 'crm-service', name: 'CRM Service', icon: '👥', status: 'healthy', version: 'v1.8.2', endpoints: ['/contacts', '/deals', '/activities'], config: { latency: 200, jitter: 80, rateLimit: 100, uptime: 99.5, errorRate: 3 } }, { id: 'analytics-api', name: 'Analytics API', icon: '📊', status: 'degraded', version: 'v3.1.0', endpoints: ['/events', '/reports', '/dashboards'], config: { latency: 350, jitter: 150, rateLimit: 30, uptime: 95.0, errorRate: 8 } }, { id: 'email-provider', name: 'Email Provider', icon: '✉️', status: 'healthy', version: 'v2.0.1', endpoints: ['/send', '/templates', '/webhooks'], config: { latency: 100, jitter: 30, rateLimit: 200, uptime: 99.8, errorRate: 1 } }, { id: 'storage-service', name: 'Storage Service', icon: '💾', status: 'outage', version: 'v1.2.0', endpoints: ['/upload', '/download', '/delete'], config: { latency: 500, jitter: 200, rateLimit: 50, uptime: 85.0, errorRate: 15 } } ]; // Schema definitions const schemas = { v1: { type: 'object', properties: { id: { type: 'string' }, amount: { type: 'number' }, currency: { type: 'string' }, status: { type: 'string', enum: ['pending', 'completed', 'failed'] } }, required: ['id', 'amount', 'currency'] }, v2: { type: 'object', properties: { id: { type: 'string' }, amount: { type: 'string' }, currency: { type: 'string' }, status: { type: 'string', enum: ['pending', 'processing', 'completed', 'failed', 'refunded'] }, metadata: { type: 'object' } }, required: ['id', 'amount', 'currency', 'status'] }, v3: { type: 'object', properties: { id: { type: 'string' }, amount: { type: 'string' }, currency: { type: 'string' }, status: { type: 'string', enum: ['pending', 'processing', 'completed', 'failed', 'refunded', 'cancelled'] }, metadata: { type: 'object' }, created_at: { type: 'string', format: 'date-time' }, updated_at: { type: 'string', format: 'date-time' }, fees: { type: 'object', properties: { processing: { type: 'number' }, platform: { type: 'number' }, total: { type: 'number' } } }, risk_score: { type: 'number', minimum: 0, maximum: 100 } }, required: ['id', 'amount', 'currency', 'status', 'created_at'] } }; // DOM elements - initialize after DOM is ready let elements = {}; // Helper functions function getStatusColor(status) { switch(status) { case 'healthy': return 'var(--success)'; case 'degraded': return 'var(--warning)'; case 'outage': return 'var(--error)'; default: return 'var(--fg-muted)'; } } function formatBytes(bytes) { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; } function generateRequestId() { return 'req_' + Math.random().toString(36).substr(2, 9); } function generateResponse(partner, config, schemaVersion) { const isSuccess = Math.random() * 100 > config.errorRate; const baseLatency = config.latency; const jitter = Math.random() * config.jitter * 2 - config.jitter; const latency = Math.max(0, Math.round(baseLatency + jitter)); if (!isSuccess) { const errors = [ { status: 500, message: 'Internal Server Error' }, { status: 502, message: 'Bad Gateway' }, { status: 503, message: 'Service Unavailable' }, { status: 504, message: 'Gateway Timeout' }, { status: 401, message: 'Unauthorized' }, { status: 403, message: 'Forbidden' }, { status: 422, message: 'Validation Error' }, { status: 429, message: 'Rate Limit Exceeded' } ]; const error = errors[Math.floor(Math.random() * errors.length)]; return { success: false, status: error.status, latency, body: { error: error.message, request_id: generateRequestId() } }; } // Generate success response based on schema version const responses = { v1: { id: 'txn_' + Math.random().toString(36).substr(2, 12), amount: Math.round(Math.random() * 10000) / 100, currency: 'USD', status: ['pending', 'completed', 'failed'][Math.floor(Math.random() * 3)] }, v2: { id: 'txn_' + Math.random().toString(36).substr(2, 12), amount: (Math.round(Math.random() * 10000) / 100).toFixed(2), currency: 'USD', status: ['pending', 'processing', 'completed', 'failed', 'refunded'][Math.floor(Math.random() * 5)], metadata: { source: 'integration_lab', test: true } }, v3: { id: 'txn_' + Math.random().toString(36).substr(2, 12), amount: (Math.round(Math.random() * 10000) / 100).toFixed(2), currency: 'USD', status: ['pending', 'processing', 'completed', 'failed', 'refunded', 'cancelled'][Math.floor(Math.random() * 6)], metadata: { source: 'integration_lab', test: true }, created_at: new Date().toISOString(), updated_at: new Date().toISOString(), fees: { processing: Math.round(Math.random() * 100) / 100, platform: Math.round(Math.random() * 50) / 100, total: Math.round(Math.random() * 150) / 100 }, risk_score: Math.floor(Math.random() * 100) } }; return { success: true, status: 200, latency, body: responses[schemaVersion] || responses.v1 }; } function renderPartnerList() { const container = elements.partnerList; if (!container) return; container.innerHTML = partners.map((partner, index) => ` <button class="w-full p-3 rounded-lg text-left transition-all slide-in partner-card ${state.selectedPartner?.id === partner.id ? 'bg-[var(--card)] border border-[var(--accent)]' : 'hover:bg-[var(--card)] border border-transparent'}" data-partner="${partner.id}" style="animation-delay: ${index * 50}ms" > <div class="flex items-center gap-3"> <div class="w-8 h-8 rounded-lg bg-[var(--bg)] flex items-center justify-center text-sm"> ${partner.icon} </div> <div class="flex-1 min-w-0"> <div class="flex items-center gap-2"> <span class="text-sm font-medium truncate">${partner.name}</span> </div> <div class="flex items-center gap-2 mt-1"> <div class="status-dot" style="background: ${getStatusColor(partner.status)}"></div> <span class="font-mono text-[10px] text-[var(--fg-dim)]">${partner.version}</span> </div> </div> </div> </button> `).join(''); // Add click handlers container.querySelectorAll('.partner-card').forEach(card => { card.addEventListener('click', () => { const partnerId = card.dataset.partner; selectPartner(partnerId); }); }); } function selectPartner(partnerId) { state.selectedPartner = partners.find(p => p.id === partnerId); if (!state.selectedPartner) return; // Update UI elements.selectedPartnerName.textContent = state.selectedPartner.name; elements.selectedPartnerVersion.textContent = state.selectedPartner.version; // Update config sliders elements.latencySlider.value = state.selectedPartner.config.latency; elements.latencyValue.textContent = state.selectedPartner.config.latency + 'ms'; elements.jitterSlider.value = state.selectedPartner.config.jitter; elements.jitterValue.textContent = state.selectedPartner.config.jitter + 'ms'; elements.rateLimitSlider.value = state.selectedPartner.config.rateLimit; elements.rateLimitValue.textContent = state.selectedPartner.config.rateLimit; elements.uptimeSlider.value = state.selectedPartner.config.uptime; elements.uptimeValue.textContent = state.selectedPartner.config.uptime + '%'; elements.errorRateSlider.value = state.selectedPartner.config.errorRate; elements.errorRateValue.textContent = state.selectedPartner.config.errorRate + '%'; // Update schema updateSchemaDisplay(); // Re-render partner list to show selection renderPartnerList(); } function updateSchemaDisplay() { const currentVersion = 'v1'; const targetVersion = elements.schemaVersionSelect.value; elements.currentSchemaVersion.textContent = currentVersion; elements.targetSchemaVersion.textContent = targetVersion; elements.currentSchema.textContent = JSON.stringify(schemas[currentVersion], null, 2); // Generate diff const diffHtml = generateSchemaDiff(schemas[currentVersion], schemas[targetVersion]); elements.schemaDiff.innerHTML = diffHtml; } function generateSchemaDiff(oldSchema, newSchema) { const lines = []; // Check for type changes if (oldSchema.properties.amount.type !== newSchema.properties.amount.type) { lines.push(`<div class="schema-diff-remove p-2 rounded mb-1">"amount": { "type": "${oldSchema.properties.amount.type}" }</div>`); lines.push(`<div class="schema-diff-add p-2 rounded mb-1">"amount": { "type": "${newSchema.properties.amount.type}" }</div>`); } // Check for new fields Object.keys(newSchema.properties).forEach(key => { if (!oldSchema.properties[key]) { lines.push(`<div class="schema-diff-add p-2 rounded mb-1">"${key}": ${JSON.stringify(newSchema.properties[key], null, 2)}</div>`); } }); // Check for enum changes if (newSchema.properties.status.enum) { const addedEnums = newSchema.properties.status.enum.filter(e => !oldSchema.properties.status.enum.includes(e) ); if (addedEnums.length > 0) { lines.push(`<div class="schema-diff-modified p-2 rounded mb-1">"status": new values [${addedEnums.join(', ')}]</div>`); } } return lines.join('') || '<div class="text-[var(--fg-dim)] p-2">No changes detected</div>'; } function updateMetrics() { const { totalRequests, successCount, errorCount, latencies } = state.metrics; if (totalRequests === 0) { elements.metricLatency.textContent = '--'; elements.metricSuccess.textContent = '--'; elements.metricErrors.textContent = '--'; elements.metricP99.textContent = '--'; return; } const avgLatency = Math.round(latencies.reduce((a, b) => a + b, 0) / latencies.length); const successRate = ((successCount / totalRequests) * 100).toFixed(1); const sortedLatencies = [...latencies].sort((a, b) => a - b); const p99Index = Math.floor(sortedLatencies.length * 0.99); const p99 = sortedLatencies[p99Index] || 0; elements.metricLatency.textContent = avgLatency + 'ms'; elements.metricSuccess.textContent = successRate + '%'; elements.metricErrors.textContent = errorCount; elements.metricP99.textContent = p99 + 'ms'; } function addRequestToLog(request) { state.requestLog.unshift(request); if (state.requestLog.length > 50) { state.requestLog.pop(); } renderRequestLog(); } function renderRequestLog() { const container = elements.requestLog; const emptyState = elements.emptyRequestLog; if (state.requestLog.length === 0) { emptyState.classList.remove('hidden'); container.innerHTML = ''; return; } emptyState.classList.add('hidden'); container.innerHTML = state.requestLog.map((req, index) => ` <div class="request-log-entry ${req.response.success ? 'success' : 'error'} card p-3 fade-in" style="animation-delay: ${index * 30}ms"> <div class="flex items-center justify-between mb-2"> <div class="flex items-center gap-2"> <span class="font-mono text-xs text-[var(--accent)]">${req.method}</span> <span class="font-mono text-xs">${req.endpoint}</span> </div> <div class="flex items-center gap-3"> <span class="font-mono text-[10px] ${req.response.success ? 'text-[var(--success)]' : 'text-[var(--error)]'}">${req.response.status}</span> <span class="font-mono text-[10px] text-[var(--fg-dim)]">${req.response.latency}ms</span> </div> </div> <div class="flex items-center gap-2"> <span class="font-mono text-[10px] text-[var(--fg-dim)]">${req.id}</span> <span class="text-[var(--fg-dim)]">|</span> <span class="text-[10px] text-[var(--fg-dim)]">${req.timestamp}</span> </div> </div> `).join(''); } function runSimulation() { if (!state.selectedPartner) { alert('Please select a partner first'); return; } if (state.isRunning) { stopSimulation(); return; } state.isRunning = true; elements.runTestBtn.innerHTML = ` <svg class="w-4 h-4 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/> </svg> Stop Test `; const config = { latency: parseInt(elements.latencySlider.value), jitter: parseInt(elements.jitterSlider.value), rateLimit: parseInt(elements.rateLimitSlider.value), uptime: parseFloat(elements.uptimeSlider.value), errorRate: parseInt(elements.errorRateSlider.value) }; const schemaVersion = elements.schemaVersionSelect.value; let requestCount = 0; const maxRequests = 20; state.simulation = setInterval(() => { if (requestCount >= maxRequests) { stopSimulation(); return; } const endpoint = state.selectedPartner.endpoints[Math.floor(Math.random() * state.selectedPartner.endpoints.length)]; const response = generateResponse(state.selectedPartner, config, schemaVersion); const request = { id: generateRequestId(), method: 'POST', endpoint: endpoint, timestamp: new Date().toLocaleTimeString(), response: response }; // Update metrics state.metrics.totalRequests++; state.metrics.latencies.push(response.latency); if (response.success) { state.metrics.successCount++; } else { state.metrics.errorCount++; } addRequestToLog(request); updateMetrics(); updateResponsePreview(request.response, schemaVersion); requestCount++; }, 500); } function stopSimulation() { state.isRunning = false; if (state.simulation) { clearInterval(state.simulation); state.simulation = null; } elements.runTestBtn.innerHTML = ` <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/> </svg> Run Test Suite `; } function updateResponsePreview(response, schemaVersion) { elements.responseStatus.textContent = response.status + (response.success ? ' OK' : ' Error'); elements.responseStatus.className = 'font-mono text-xs px-2 py-1 rounded ' + (response.success ? 'bg-[var(--success-dim)] text-[var(--success)]' : 'bg-[var(--error-dim)] text-[var(--error)]'); elements.responseTime.textContent = response.latency + 'ms'; elements.responseBody.textContent = JSON.stringify(response.body, null, 2); } function resetLab() { stopSimulation(); state.requestLog = []; state.metrics = { totalRequests: 0, successCount: 0, errorCount: 0, latencies: [] }; // Reset all toggles document.querySelectorAll('.toggle').forEach(toggle => { toggle.classList.remove('active'); }); document.querySelector('#rateLimitToggle').classList.add('active'); document.querySelector('#fieldAddToggle').classList.add('active'); // Reset sliders elements.latencySlider.value = 150; elements.jitterSlider.value = 50; elements.rateLimitSlider.value = 60; elements.uptimeSlider.value = 99.9; elements.errorRateSlider.value = 5; elements.schemaVersionSelect.value = 'v1'; // Update displays elements.latencyValue.textContent = '150ms'; elements.jitterValue.textContent = '50ms'; elements.rateLimitValue.textContent = '60'; elements.uptimeValue.textContent = '99.9%'; elements.errorRateValue.textContent = '5%'; updateMetrics(); renderRequestLog(); updateSchemaDisplay(); } // Initialize after DOM is loaded document.addEventListener('DOMContentLoaded', () => { // Cache DOM elements elements = { partnerList: document.getElementById('partnerList'), selectedPartnerName: document.getElementById('selectedPartnerName'), selectedPartnerVersion: document.getElementById('selectedPartnerVersion'), latencySlider: document.getElementById('latencySlider'), latencyValue: document.getElementById('latencyValue'), jitterSlider: document.getElementById('jitterSlider'), jitterValue: document.getElementById('jitterValue'), rateLimitSlider: document.getElementById('rateLimitSlider'), rateLimitValue: document.getElementById('rateLimitValue'), rateLimitToggle: document.getElementById('rateLimitToggle'), uptimeSlider: document.getElementById('uptimeSlider'), uptimeValue: document.getElementById('uptimeValue'), errorRateSlider: document.getElementById('errorRateSlider'), errorRateValue: document.getElementById('errorRateValue'), schemaVersionSelect: document.getElementById('schemaVersionSelect'), currentSchemaVersion: document.getElementById('currentSchemaVersion'), targetSchemaVersion: document.getElementById('targetSchemaVersion'), currentSchema: document.getElementById('currentSchema'), schemaDiff: document.getElementById('schemaDiff'), requestLog: document.getElementById('requestLog'), emptyRequestLog: document.getElementById('emptyRequestLog'), runTestBtn: document.getElementById('runTestBtn'), resetLabBtn: document.getElementById('resetLabBtn'), metricLatency: document.getElementById('metricLatency'), metricSuccess: document.getElementById('metricSuccess'), metricErrors: document.getElementById('metricErrors'), metricP99: document.getElementById('metricP99'), responseStatus: document.getElementById('responseStatus'), responseTime: document.getElementById('responseTime'), responseBody: document.getElementById('responseBody') }; // Tab switching document.querySelectorAll('.tab[data-tab]').forEach(tab => { tab.addEventListener('click', () => { const tabName = tab.dataset.tab; document.querySelectorAll('.tab[data-tab]').forEach(t => t.classList.remove('active')); tab.classList.add('active'); document.querySelectorAll('.tab-content').forEach(content => { content.classList.add('hidden'); }); document.getElementById(tabName + 'Tab').classList.remove('hidden'); }); }); // View switching document.querySelectorAll('.tab[data-view]').forEach(tab => { tab.addEventListener('click', () => { const viewName = tab.dataset.view; document.querySelectorAll('.tab[data-view]').forEach(t => t.classList.remove('active')); tab.classList.add('active'); document.getElementById('requestsView').classList.add('hidden'); document.getElementById('schemaView').classList.add('hidden'); document.getElementById('responseView').classList.add('hidden'); document.getElementById(viewName + 'View').classList.remove('hidden'); }); }); // Toggle handlers document.querySelectorAll('.toggle').forEach(toggle => { toggle.addEventListener('click', () => { toggle.classList.toggle('active'); }); }); // Slider handlers elements.latencySlider.addEventListener('input', (e) => { elements.latencyValue.textContent = e.target.value + 'ms'; }); elements.jitterSlider.addEventListener('input', (e) => { elements.jitterValue.textContent = e.target.value + 'ms'; }); elements.rateLimitSlider.addEventListener('input', (e) => { elements.rateLimitValue.textContent = e.target.value; }); elements.uptimeSlider.addEventListener('input', (e) => { elements.uptimeValue.textContent = e.target.value + '%'; }); elements.errorRateSlider.addEventListener('input', (e) => { elements.errorRateValue.textContent = e.target.value + '%'; }); elements.schemaVersionSelect.addEventListener('change', updateSchemaDisplay); // Button handlers elements.runTestBtn.addEventListener('click', runSimulation); elements.resetLabBtn.addEventListener('click', resetLab); // Scenario buttons document.querySelectorAll('[data-scenario]').forEach(btn => { btn.addEventListener('click', () => { const scenario = btn.dataset.scenario; runScenario(scenario); }); }); // Initialize renderPartnerList(); updateSchemaDisplay(); // Select first partner selectPartner('payment-gateway'); }); function runScenario(scenario) { switch(scenario) { case 'thundering-herd': elements.latencySlider.value = 2000; elements.latencyValue.textContent = '2000ms'; elements.errorRateSlider.value = 30; elements.errorRateValue.textContent = '30%'; break; case 'slow-burn': elements.latencySlider.value = 100; elements.jitterSlider.value = 0; elements.errorRateSlider.value = 2; elements.latencyValue.textContent = '100ms'; elements.jitterValue.textContent = '0ms'; elements.errorRateValue.textContent = '2%'; // Gradually increase latency let currentLatency = 100; const burnInterval = setInterval(() => { currentLatency += 50; elements.latencySlider.value = Math.min(currentLatency, 2000); elements.latencyValue.textContent = Math.min(currentLatency, 2000) + 'ms'; if (currentLatency > 2000) { clearInterval(burnInterval); } }, 1000); break; case 'flapping': let isUp = true; const flapInterval = setInterval(() => { isUp = !isUp; elements.errorRateSlider.value = isUp ? 5 : 80; elements.errorRateValue.textContent = (isUp ? 5 : 80) + '%'; }, 2000); setTimeout(() => { clearInterval(flapInterval); elements.errorRateSlider.value = 5; elements.errorRateValue.textContent = '5%'; }, 20000); break; } } </script> </body> </html>Key Features
Partner Simulation System:
- 5 realistic partner APIs (Payment Gateway, CRM, Analytics, Email, Storage) with different health states
- Configurable latency, jitter, rate limiting, and uptime percentages
- Real-time status indicators showing healthy/degraded/outage states
Error Pattern Injection:
- Toggle individual error types: timeouts, 5xx errors, 4xx errors, malformed responses
- Adjustable error rate probability
- Pre-built cascade scenarios:
- Thundering Herd - sudden load spike with high latency and errors
- Slow Burn - memory leak simulation with gradually increasing latency
- Flapping Service - intermittent availability switching
Schema Evolution Sandbox:
- Three schema versions (v1, v2, v3) with realistic breaking changes
- Side-by-side diff visualization showing:
- Field additions (green)
- Field removals (red)
- Type changes and enum expansions (yellow)
- Toggle individual evolution scenarios (field addition, deprecation, type changes, nested restructures)
Live Testing:
- Run test suites with configurable parameters
- Real-time request log with status indicators
- Live metrics (average latency, success rate, error count, P99)
- Response preview with schema-aware payload generation
Design Approach:
- Dark, technical aesthetic inspired by IDEs and monitoring tools
- JetBrains Mono for code/data, Space Grotesk for UI
- Subtle grid background with cyan accent color
- Status indicators with pulse animations
- Staggered reveal animations for list items
- Respects
prefers-reduced-motion