"use client"; /** * OverviewTab (TASK-0130) — the developer-hub "Overview" tab. * * Base URL, a copyable curl quickstart (API-key auth + a page create), an * API-key example, an OAuth2 token example, and links to the public docs * (markdown `/docs/api` if present, always the OpenAPI UI `/api/v1/docs`). * * All snippets use the REAL runtime base URL (API_BASE) and a * `` / `` placeholder — never a real credential. */ import { useState } from "react"; import { Check, Copy, FileText, Webhook as WebhookIcon } from "lucide-react"; import { API_BASE } from "@/lib/constants"; import { cn } from "@/lib/utils"; const KEY_PLACEHOLDER = "$FACTORY_API_KEY"; const TOKEN_PLACEHOLDER = "$ACCESS_TOKEN"; function CodeBlock({ title, code, testId }: { title: string; code: string; testId?: string; }) { const [copied, setCopied] = useState(false); const doCopy = async () => { let ok = false; try { await navigator.clipboard.writeText(code); ok = true; } catch { try { const ta = document.createElement("textarea"); ta.value = code; ta.setAttribute("readonly", ""); ta.style.position = "fixed"; ta.style.opacity = "0"; document.body.appendChild(ta); ta.select(); ok = document.execCommand("copy"); document.body.removeChild(ta); } catch { ok = false; } } setCopied(ok); setTimeout(() => setCopied(false), 2000); }; return (

{title}

{copied ? `${title} copied` : ""}
{code}
); } export function OverviewTab({ workspaceSlug }: { workspaceSlug: string }) { const quickstart = `# 1. List your pages (API-key auth) curl -s ${API_BASE}/workspaces/${workspaceSlug}/pages \\ -H "Authorization: Bearer ${KEY_PLACEHOLDER}" # 2. Create a page curl -s -X POST ${API_BASE}/workspaces/${workspaceSlug}/pages \\ -H "Authorization: Bearer ${KEY_PLACEHOLDER}" \\ -H 'Content-Type: application/json' \\ -d '{"title":"Hello from the API"}'`; const apiKey = `# API keys are created in this hub (API keys tab) and shown ONCE. # Use them server-to-server with the Authorization header: curl -s ${API_BASE}/workspaces/${workspaceSlug}/pages/\\ \\ -H "Authorization: Bearer ${KEY_PLACEHOLDER}" # Scopes: READ < WRITE < ADMIN (ADMIN implies the lower scopes).`; const oauth = `# 1. Exchange the authorization code (server-side, secret kept private) curl -s -X POST ${API_BASE}/oauth/token \\ -H 'Content-Type: application/x-www-form-urlencoded' \\ -d 'grant_type=authorization_code&code=\\&client_id=\\&client_secret=\\&redirect_uri=\\' # 2. Use the access token curl -s ${API_BASE}/workspaces/${workspaceSlug}/pages \\ -H "Authorization: Bearer $ACCESS_TOKEN"`; const webhook = `# Verify a webhook signature (Node): const crypto = require("node:crypto"); function verify(req, secret) { const header = req.headers["x-factory-signature"]; // "t=,v1=" const m = header.match(/^t=(\\d+),v1=([0-9a-f]{64})$/); if (!m) return false; const [t, v1] = m.slice(1, 3); if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false; // ±5 min const expected = crypto.createHmac("sha256", secret).update(t + "." + rawBody).digest("hex"); return crypto.timingSafeEqual(Buffer.from(v1, "hex"), Buffer.from(expected, "hex")); }`; return (

Base URL

All Factory API endpoints are under this prefix. The OpenAPI UI is at{" "} {API_BASE}/docs , the markdown reference at{" "} /docs/api .

{API_BASE}
); }