Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): add developer dashboard components and pages
Richie McIlroy5cfd616e094a
diff --git a/apps/web/app/(org)/dashboard/developers/DevelopersContext.tsx b/apps/web/app/(org)/dashboard/developers/DevelopersContext.tsxnew file mode 100644index 000000000..fb602b840--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/DevelopersContext.tsx@@ -0,0 +1,28 @@+"use client";++import { createContext, type ReactNode, useContext } from "react";+import type { DeveloperApp } from "./developer-data";++type DevelopersContextType = {+ apps: DeveloperApp[];+};++const DevelopersContext = createContext<DevelopersContextType>({+ apps: [],+});++export const useDevelopersContext = () => useContext(DevelopersContext);++export function DevelopersProvider({+ children,+ apps,+}: {+ children: ReactNode;+ apps: DeveloperApp[];+}) {+ return (+ <DevelopersContext.Provider value={{ apps }}>+ {children}+ </DevelopersContext.Provider>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/ApiKeyDisplay.tsx b/apps/web/app/(org)/dashboard/developers/_components/ApiKeyDisplay.tsxnew file mode 100644index 000000000..4a8b8922b--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/ApiKeyDisplay.tsx@@ -0,0 +1,61 @@+"use client";++import { Label } from "@cap/ui";+import { Check, Copy, Eye, EyeOff } from "lucide-react";+import { useState } from "react";+import { toast } from "sonner";++export function ApiKeyDisplay({+ label,+ value,+ sensitive = false,+}: {+ label: string;+ value: string;+ sensitive?: boolean;+}) {+ const [visible, setVisible] = useState(!sensitive);+ const [copied, setCopied] = useState(false);++ const handleCopy = async () => {+ await navigator.clipboard.writeText(value);+ setCopied(true);+ toast.success("Copied to clipboard");+ setTimeout(() => setCopied(false), 2000);+ };++ const displayValue = visible+ ? value+ : `${value.slice(0, 8)}${"•".repeat(20)}`;++ return (+ <div className="flex flex-col gap-1.5">+ <Label className="text-xs">{label}</Label>+ <div className="flex gap-2 items-center">+ <code className="flex-1 px-3 py-2 text-xs rounded-lg bg-gray-3 text-gray-11 font-mono truncate">+ {displayValue}+ </code>+ {sensitive && (+ <button+ type="button"+ onClick={() => setVisible(!visible)}+ className="p-1.5 rounded-md hover:bg-gray-3 text-gray-10 transition-colors"+ >+ {visible ? <EyeOff size={14} /> : <Eye size={14} />}+ </button>+ )}+ <button+ type="button"+ onClick={handleCopy}+ className="p-1.5 rounded-md hover:bg-gray-3 text-gray-10 transition-colors"+ >+ {copied ? (+ <Check size={14} className="text-green-400" />+ ) : (+ <Copy size={14} />+ )}+ </button>+ </div>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/AppCard.tsx b/apps/web/app/(org)/dashboard/developers/_components/AppCard.tsxnew file mode 100644index 000000000..448bca637--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/AppCard.tsx@@ -0,0 +1,34 @@+"use client";++import { ArrowRight } from "lucide-react";+import Link from "next/link";+import type { DeveloperApp } from "../developer-data";+import { EnvironmentBadge } from "./EnvironmentBadge";++export function AppCard({ app }: { app: DeveloperApp }) {+ return (+ <Link+ href={`/dashboard/developers/apps/${app.id}/settings`}+ className="group flex flex-col gap-4 p-4 rounded-xl border border-gray-3 bg-gray-2 hover:border-gray-6 transition-colors"+ >+ <div className="flex justify-between items-start">+ <div className="flex flex-col gap-1.5">+ <h3 className="text-sm font-medium text-gray-12">{app.name}</h3>+ <EnvironmentBadge environment={app.environment} />+ </div>+ <ArrowRight+ size={16}+ className="text-gray-8 group-hover:text-gray-11 transition-colors mt-0.5"+ />+ </div>+ <div className="flex gap-4 text-xs text-gray-10">+ <span>{app.videoCount} videos</span>+ <span>+ {app.creditAccount+ ? `$${((app.creditAccount.balanceMicroCredits ?? 0) / 100_000).toFixed(2)} credits`+ : "$0.00 credits"}+ </span>+ </div>+ </Link>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/CreateAppDialog.tsx b/apps/web/app/(org)/dashboard/developers/_components/CreateAppDialog.tsxnew file mode 100644index 000000000..8c7e3f4aa--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/CreateAppDialog.tsx@@ -0,0 +1,144 @@+"use client";++import {+ Button,+ Dialog,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ Input,+ Label,+} from "@cap/ui";+import { useMutation } from "@tanstack/react-query";+import { useRouter } from "next/navigation";+import { useId, useState } from "react";+import { toast } from "sonner";+import { createDeveloperApp } from "@/actions/developers/create-app";+import { ApiKeyDisplay } from "./ApiKeyDisplay";++export function CreateAppDialog({+ open,+ onOpenChange,+}: {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}) {+ const router = useRouter();+ const appNameId = useId();+ const [step, setStep] = useState<"create" | "keys">("create");+ const [name, setName] = useState("");+ const [environment, setEnvironment] = useState<"development" | "production">(+ "development",+ );+ const [keys, setKeys] = useState<{+ publicKey: string;+ secretKey: string;+ } | null>(null);++ const createMutation = useMutation({+ mutationFn: () => createDeveloperApp({ name, environment }),+ onSuccess: (result) => {+ setKeys({+ publicKey: result.publicKey,+ secretKey: result.secretKey,+ });+ setStep("keys");+ router.refresh();+ },+ onError: (error) => {+ toast.error(+ error instanceof Error ? error.message : "Failed to create app",+ );+ },+ });++ const handleClose = () => {+ setStep("create");+ setName("");+ setEnvironment("development");+ setKeys(null);+ onOpenChange(false);+ };++ return (+ <Dialog open={open} onOpenChange={handleClose}>+ <DialogContent className="max-w-md">+ {step === "create" && (+ <>+ <DialogHeader>+ <DialogTitle>Create Developer App</DialogTitle>+ </DialogHeader>+ <div className="flex flex-col gap-4 p-5">+ <div className="flex flex-col gap-2">+ <Label htmlFor={appNameId}>App Name</Label>+ <Input+ id={appNameId}+ value={name}+ onChange={(e) => setName(e.target.value)}+ placeholder="My App"+ />+ </div>+ <div className="flex flex-col gap-2">+ <Label>Environment</Label>+ <div className="flex gap-2">+ <Button+ variant={environment === "development" ? "dark" : "gray"}+ size="sm"+ onClick={() => setEnvironment("development")}+ >+ Development+ </Button>+ <Button+ variant={environment === "production" ? "dark" : "gray"}+ size="sm"+ onClick={() => setEnvironment("production")}+ >+ Production+ </Button>+ </div>+ </div>+ </div>+ <DialogFooter>+ <Button variant="gray" size="sm" onClick={handleClose}>+ Cancel+ </Button>+ <Button+ variant="dark"+ size="sm"+ disabled={!name.trim() || createMutation.isPending}+ spinner={createMutation.isPending}+ onClick={() => createMutation.mutate()}+ >+ Create+ </Button>+ </DialogFooter>+ </>+ )}+ {step === "keys" && keys && (+ <>+ <DialogHeader>+ <DialogTitle>API Keys Created</DialogTitle>+ </DialogHeader>+ <div className="flex flex-col gap-4 p-5">+ <p className="text-sm text-gray-10">+ Save your secret key now. You won't be able to see it again.+ </p>+ <ApiKeyDisplay label="Public Key" value={keys.publicKey} />+ <ApiKeyDisplay+ label="Secret Key"+ value={keys.secretKey}+ sensitive+ />+ </div>+ <DialogFooter>+ <Button variant="dark" size="sm" onClick={handleClose}>+ Done+ </Button>+ </DialogFooter>+ </>+ )}+ </DialogContent>+ </Dialog>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/CreditTransactionTable.tsx b/apps/web/app/(org)/dashboard/developers/_components/CreditTransactionTable.tsxnew file mode 100644index 000000000..cc7bdbf80--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/CreditTransactionTable.tsx@@ -0,0 +1,71 @@+"use client";++import type { DeveloperTransaction } from "../developer-data";++const typeLabels: Record<string, string> = {+ topup: "Top Up",+ video_create: "Recording",+ storage_daily: "Storage",+ refund: "Refund",+ adjustment: "Adjustment",+};++export function CreditTransactionTable({+ transactions,+}: {+ transactions: DeveloperTransaction[];+}) {+ if (transactions.length === 0) {+ return (+ <p className="py-8 text-sm text-center text-gray-10">+ No transactions yet+ </p>+ );+ }++ return (+ <div className="overflow-x-auto rounded-lg border border-gray-3">+ <table className="w-full text-sm">+ <thead>+ <tr className="border-b border-gray-3 bg-gray-3/50">+ <th className="px-4 py-2.5 text-left text-xs font-medium text-gray-10">+ Type+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Amount+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Balance+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Date+ </th>+ </tr>+ </thead>+ <tbody>+ {transactions.map((tx) => (+ <tr key={tx.id} className="border-b border-gray-3 last:border-0">+ <td className="px-4 py-2.5 text-gray-12">+ {typeLabels[tx.type] ?? tx.type}+ </td>+ <td+ className={`px-4 py-2.5 text-right tabular-nums ${+ tx.amountMicroCredits >= 0 ? "text-green-400" : "text-red-400"+ }`}+ >+ {tx.amountMicroCredits >= 0 ? "+" : ""}$+ {(Math.abs(tx.amountMicroCredits) / 100_000).toFixed(4)}+ </td>+ <td className="px-4 py-2.5 text-right text-gray-11 tabular-nums">+ ${(tx.balanceAfterMicroCredits / 100_000).toFixed(2)}+ </td>+ <td className="px-4 py-2.5 text-right text-gray-10">+ {new Date(tx.createdAt).toLocaleDateString()}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/DeveloperSidebarContent.tsx b/apps/web/app/(org)/dashboard/developers/_components/DeveloperSidebarContent.tsxnew file mode 100644index 000000000..cc6c3b633--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/DeveloperSidebarContent.tsx@@ -0,0 +1,214 @@+"use client";++import clsx from "clsx";+import { motion } from "framer-motion";+import {+ BarChart3,+ Box,+ CreditCard,+ Globe,+ Key,+ Settings,+ Video,+} from "lucide-react";+import Link from "next/link";+import { useParams, usePathname } from "next/navigation";+import { Tooltip } from "@/components/Tooltip";+import { useDashboardContext } from "../../Contexts";+import { EnvironmentBadge } from "./EnvironmentBadge";++const mainNav = [+ { name: "Apps", href: "/dashboard/developers/apps", icon: Box },+ { name: "Usage", href: "/dashboard/developers/usage", icon: BarChart3 },+ {+ name: "Credits",+ href: "/dashboard/developers/credits",+ icon: CreditCard,+ },+];++const appNav = [+ { name: "Settings", href: "settings", icon: Settings },+ { name: "API Keys", href: "api-keys", icon: Key },+ { name: "Domains", href: "domains", icon: Globe },+ { name: "Videos", href: "videos", icon: Video },+];++export function DeveloperSidebarContent() {+ const pathname = usePathname();+ const params = useParams<{ appId?: string }>();+ const { sidebarCollapsed, developerApps } = useDashboardContext();++ const currentApp =+ params.appId && developerApps+ ? developerApps.find((a) => a.id === params.appId)+ : null;++ const basePath = params.appId+ ? `/dashboard/developers/apps/${params.appId}`+ : null;++ const isActive = (href: string) =>+ pathname === href || pathname.startsWith(`${href}/`);++ return (+ <nav className="flex flex-col justify-between w-full h-full">+ <div+ className={clsx(+ "mt-1",+ sidebarCollapsed ? "flex flex-col justify-center items-center" : "",+ )}+ >+ {mainNav.map((item) => {+ const active = isActive(item.href);+ const Icon = item.icon;+ return (+ <div+ key={item.name}+ className="flex relative justify-center items-center mb-1 w-full"+ >+ {active && (+ <motion.div+ animate={{+ width: sidebarCollapsed ? 36 : "100%",+ }}+ transition={{+ layout: { type: "tween", duration: 0.15 },+ width: { type: "tween", duration: 0.05 },+ }}+ layoutId="devnavlinks"+ className="absolute h-[36px] w-full rounded-xl pointer-events-none bg-gray-3"+ />+ )}+ <Tooltip+ disable={!sidebarCollapsed}+ content={item.name}+ position="right"+ >+ <Link+ href={item.href}+ prefetch={true}+ className={clsx(+ "relative border border-transparent transition z-3 flex overflow-hidden justify-start items-center tracking-tight rounded-xl outline-none",+ sidebarCollapsed+ ? "justify-center px-0 w-full size-9"+ : "px-3 py-2 w-full",+ active+ ? "bg-transparent pointer-events-none"+ : "hover:bg-gray-2",+ )}+ >+ <Icon+ size={sidebarCollapsed ? 18 : 16}+ className={clsx(+ sidebarCollapsed+ ? "text-gray-12 mx-auto"+ : "text-gray-10",+ )}+ />+ <span+ className={clsx(+ "text-sm text-gray-12 truncate",+ sidebarCollapsed ? "hidden" : "ml-2.5",+ )}+ >+ {item.name}+ </span>+ </Link>+ </Tooltip>+ </div>+ );+ })}++ {currentApp && basePath && (+ <>+ <div+ className={clsx(+ "my-3 h-px bg-gray-4",+ sidebarCollapsed ? "mx-2" : "mx-1",+ )}+ />+ {!sidebarCollapsed && (+ <div className="flex items-center gap-2 px-3 mb-2">+ <span className="text-xs font-medium text-gray-12 truncate">+ {currentApp.name}+ </span>+ <EnvironmentBadge+ environment={currentApp.environment}+ size="xs"+ />+ </div>+ )}+ {appNav.map((item) => {+ const href = `${basePath}/${item.href}`;+ const active = isActive(href);+ const Icon = item.icon;+ return (+ <div+ key={item.href}+ className="flex relative justify-center items-center mb-1 w-full"+ >+ {active && (+ <motion.div+ animate={{+ width: sidebarCollapsed ? 36 : "100%",+ }}+ transition={{+ layout: {+ type: "tween",+ duration: 0.15,+ },+ width: {+ type: "tween",+ duration: 0.05,+ },+ }}+ layoutId="devappnavlinks"+ className="absolute h-[36px] w-full rounded-xl pointer-events-none bg-gray-3"+ />+ )}+ <Tooltip+ disable={!sidebarCollapsed}+ content={item.name}+ position="right"+ >+ <Link+ href={href}+ prefetch={true}+ className={clsx(+ "relative border border-transparent transition z-3 flex overflow-hidden justify-start items-center tracking-tight rounded-xl outline-none",+ sidebarCollapsed+ ? "justify-center px-0 w-full size-9"+ : "px-3 py-2 w-full",+ active+ ? "bg-transparent pointer-events-none"+ : "hover:bg-gray-2",+ )}+ >+ <Icon+ size={sidebarCollapsed ? 18 : 16}+ className={clsx(+ sidebarCollapsed+ ? "text-gray-12 mx-auto"+ : "text-gray-10",+ )}+ />+ <span+ className={clsx(+ "text-sm text-gray-12 truncate",+ sidebarCollapsed ? "hidden" : "ml-2.5",+ )}+ >+ {item.name}+ </span>+ </Link>+ </Tooltip>+ </div>+ );+ })}+ </>+ )}+ </div>+ </nav>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/DeveloperSidebarRegistrar.tsx b/apps/web/app/(org)/dashboard/developers/_components/DeveloperSidebarRegistrar.tsxnew file mode 100644index 000000000..a544d8092--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/DeveloperSidebarRegistrar.tsx@@ -0,0 +1,18 @@+"use client";++import { useEffect } from "react";+import { useDashboardContext } from "../../Contexts";+import type { DeveloperApp } from "../developer-data";++export function DeveloperSidebarRegistrar({ apps }: { apps: DeveloperApp[] }) {+ const { setDeveloperApps } = useDashboardContext();++ useEffect(() => {+ setDeveloperApps(apps);+ return () => {+ setDeveloperApps(null);+ };+ }, [apps, setDeveloperApps]);++ return null;+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/DeveloperThemeForcer.tsx b/apps/web/app/(org)/dashboard/developers/_components/DeveloperThemeForcer.tsxnew file mode 100644index 000000000..d57578714--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/DeveloperThemeForcer.tsx@@ -0,0 +1,34 @@+"use client";++import Cookies from "js-cookie";+import { useEffect, useRef } from "react";+import { useTheme } from "../../Contexts";++export function DeveloperThemeForcer({+ children,+}: {+ children: React.ReactNode;+}) {+ const { theme, setThemeHandler } = useTheme();+ const previousTheme = useRef<"light" | "dark">(+ (Cookies.get("theme") as "light" | "dark") ?? "light",+ );++ useEffect(() => {+ if (theme !== "dark") {+ setThemeHandler("dark");+ }+ }, [theme, setThemeHandler]);++ useEffect(() => {+ const saved = previousTheme.current;+ return () => {+ if (saved !== "dark") {+ document.body.className = saved;+ Cookies.set("theme", saved, { expires: 365 });+ }+ };+ }, []);++ return <>{children}</>;+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/DomainRow.tsx b/apps/web/app/(org)/dashboard/developers/_components/DomainRow.tsxnew file mode 100644index 000000000..91672dda3--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/DomainRow.tsx@@ -0,0 +1,43 @@+"use client";++import { useMutation } from "@tanstack/react-query";+import { X } from "lucide-react";+import { useRouter } from "next/navigation";+import { toast } from "sonner";+import { removeDeveloperDomain } from "@/actions/developers/remove-domain";++export function DomainRow({+ appId,+ domainId,+ domain,+}: {+ appId: string;+ domainId: string;+ domain: string;+}) {+ const router = useRouter();+ const removeMutation = useMutation({+ mutationFn: () => removeDeveloperDomain(appId, domainId),+ onSuccess: () => {+ toast.success("Domain removed");+ router.refresh();+ },+ onError: () => {+ toast.error("Failed to remove domain");+ },+ });++ return (+ <div className="flex justify-between items-center px-3 py-2 rounded-lg bg-gray-3">+ <code className="text-sm text-gray-11 font-mono">{domain}</code>+ <button+ type="button"+ onClick={() => removeMutation.mutate()}+ disabled={removeMutation.isPending}+ className="p-1 rounded-md hover:bg-gray-4 text-gray-10 hover:text-red-400 transition-colors"+ >+ <X size={14} />+ </button>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/EnvironmentBadge.tsx b/apps/web/app/(org)/dashboard/developers/_components/EnvironmentBadge.tsxnew file mode 100644index 000000000..fe913b837--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/EnvironmentBadge.tsx@@ -0,0 +1,24 @@+import clsx from "clsx";++export function EnvironmentBadge({+ environment,+ size = "sm",+}: {+ environment: string;+ size?: "sm" | "xs";+}) {+ const isProduction = environment === "production";+ return (+ <span+ className={clsx(+ "inline-flex items-center rounded-md font-medium",+ size === "sm" ? "px-1.5 py-0.5 text-xs" : "px-1 py-px text-[10px]",+ isProduction+ ? "bg-blue-400/15 text-blue-11"+ : "bg-yellow-400/15 text-yellow-11",+ )}+ >+ {isProduction ? "prod" : "dev"}+ </span>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/_components/StatBox.tsx b/apps/web/app/(org)/dashboard/developers/_components/StatBox.tsxnew file mode 100644index 000000000..3a271e5f5--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/_components/StatBox.tsx@@ -0,0 +1,21 @@+"use client";++export function StatBox({+ label,+ value,+ subtext,+}: {+ label: string;+ value: string | number;+ subtext?: string;+}) {+ return (+ <div className="flex flex-col gap-1 p-4 rounded-xl border border-gray-3 bg-gray-2">+ <span className="text-xs font-medium text-gray-10">{label}</span>+ <span className="text-xl font-semibold text-gray-12 tabular-nums">+ {value}+ </span>+ {subtext && <span className="text-xs text-gray-9">{subtext}</span>}+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/AppsListClient.tsx b/apps/web/app/(org)/dashboard/developers/apps/AppsListClient.tsxnew file mode 100644index 000000000..d8d4f72a5--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/AppsListClient.tsx@@ -0,0 +1,45 @@+"use client";++import { Button } from "@cap/ui";+import { Plus } from "lucide-react";+import { useState } from "react";+import { AppCard } from "../_components/AppCard";+import { CreateAppDialog } from "../_components/CreateAppDialog";+import { useDevelopersContext } from "../DevelopersContext";++export function AppsListClient() {+ const { apps } = useDevelopersContext();+ const [createOpen, setCreateOpen] = useState(false);++ return (+ <>+ <div className="flex justify-between items-center mb-5">+ <h2 className="text-base font-medium text-gray-12">Your Apps</h2>+ <Button variant="dark" size="sm" onClick={() => setCreateOpen(true)}>+ <Plus className="w-4 h-4 mr-1" />+ Create App+ </Button>+ </div>++ {apps.length === 0 ? (+ <div className="flex flex-col items-center justify-center py-16 rounded-xl border border-dashed border-gray-6">+ <p className="mb-2 text-sm text-gray-11">No apps yet</p>+ <p className="mb-4 text-xs text-gray-9">+ Create your first app to get started with the Cap Developer SDK+ </p>+ <Button variant="dark" size="sm" onClick={() => setCreateOpen(true)}>+ Create your first app+ </Button>+ </div>+ ) : (+ <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">+ {apps.map((app) => (+ <AppCard key={app.id} app={app} />+ ))}+ </div>+ )}++ <CreateAppDialog open={createOpen} onOpenChange={setCreateOpen} />+ </>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/api-keys/ApiKeysClient.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/api-keys/ApiKeysClient.tsxnew file mode 100644index 000000000..f38663a83--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/api-keys/ApiKeysClient.tsx@@ -0,0 +1,127 @@+"use client";++import { Button, Card, CardHeader, CardTitle } from "@cap/ui";+import { useMutation } from "@tanstack/react-query";+import { RefreshCw } from "lucide-react";+import { useParams, useRouter } from "next/navigation";+import { useState } from "react";+import { toast } from "sonner";+import { regenerateDeveloperKeys } from "@/actions/developers/regenerate-keys";+import { ApiKeyDisplay } from "../../../_components/ApiKeyDisplay";+import { useDevelopersContext } from "../../../DevelopersContext";++export function ApiKeysClient() {+ const { appId } = useParams<{ appId: string }>();+ const { apps } = useDevelopersContext();+ const app = apps.find((a) => a.id === appId);+ const router = useRouter();++ const [newKeys, setNewKeys] = useState<{+ publicKey: string;+ secretKey: string;+ } | null>(null);+ const [confirmRegenerate, setConfirmRegenerate] = useState(false);++ const regenerateMutation = useMutation({+ mutationFn: () => regenerateDeveloperKeys(appId),+ onSuccess: (result) => {+ setNewKeys(result);+ setConfirmRegenerate(false);+ toast.success("Keys regenerated");+ router.refresh();+ },+ onError: () => toast.error("Failed to regenerate keys"),+ });++ if (!app) {+ return <p className="text-sm text-gray-10">App not found</p>;+ }++ const publicKey = app.apiKeys.find((k) => k.keyType === "public");+ const secretKey = app.apiKeys.find((k) => k.keyType === "secret");++ return (+ <div className="flex flex-col gap-5 max-w-xl">+ {newKeys && (+ <Card className="border-green-400/20 bg-green-400/5">+ <p className="text-sm font-medium text-green-400 mb-4">+ New keys generated. Save your secret key now!+ </p>+ <div className="flex flex-col gap-4">+ <ApiKeyDisplay label="Public Key" value={newKeys.publicKey} />+ <ApiKeyDisplay+ label="Secret Key"+ value={newKeys.secretKey}+ sensitive+ />+ </div>+ </Card>+ )}++ <Card>+ <CardHeader>+ <CardTitle>Current Keys</CardTitle>+ </CardHeader>+ <div className="flex flex-col gap-3 mt-4">+ {publicKey && (+ <ApiKeyDisplay+ label="Public Key"+ value={publicKey.fullKey ?? `${publicKey.keyPrefix}...`}+ />+ )}+ {secretKey && (+ <div className="flex flex-col gap-1.5">+ <span className="text-xs font-medium text-gray-10">+ Secret Key+ </span>+ <code className="px-3 py-2 text-xs rounded-lg bg-gray-3 text-gray-11 font-mono">+ {"•".repeat(24)}+ </code>+ <p className="text-xs text-gray-10">+ Regenerate to reveal a new secret key+ </p>+ </div>+ )}+ </div>+ </Card>++ <Card className="border-red-400/20">+ <CardHeader>+ <CardTitle className="text-red-400">Regenerate Keys</CardTitle>+ </CardHeader>+ <div className="mt-4">+ {!confirmRegenerate ? (+ <Button+ variant="gray"+ size="sm"+ onClick={() => setConfirmRegenerate(true)}+ >+ <RefreshCw size={14} className="mr-1" />+ Regenerate Keys+ </Button>+ ) : (+ <div className="flex gap-2">+ <Button+ variant="gray"+ size="sm"+ onClick={() => setConfirmRegenerate(false)}+ >+ Cancel+ </Button>+ <Button+ variant="dark"+ size="sm"+ className="!bg-red-400 hover:!bg-red-300"+ spinner={regenerateMutation.isPending}+ disabled={regenerateMutation.isPending}+ onClick={() => regenerateMutation.mutate()}+ >+ Confirm Regenerate+ </Button>+ </div>+ )}+ </div>+ </Card>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/api-keys/page.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/api-keys/page.tsxnew file mode 100644index 000000000..e215a7631--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/api-keys/page.tsx@@ -0,0 +1,10 @@+import type { Metadata } from "next";+import { ApiKeysClient } from "./ApiKeysClient";++export const metadata: Metadata = {+ title: "API Keys — Cap",+};++export default async function ApiKeysPage() {+ return <ApiKeysClient />;+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/domains/DomainsClient.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/domains/DomainsClient.tsxnew file mode 100644index 000000000..0ccce19d3--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/domains/DomainsClient.tsx@@ -0,0 +1,117 @@+"use client";++import {+ Button,+ Card,+ CardDescription,+ CardHeader,+ CardTitle,+ Input,+ Label,+} from "@cap/ui";+import { useMutation } from "@tanstack/react-query";+import { AlertTriangle, Plus } from "lucide-react";+import { useParams, useRouter } from "next/navigation";+import { useId, useState } from "react";+import { toast } from "sonner";+import { addDeveloperDomain } from "@/actions/developers/add-domain";+import { DomainRow } from "../../../_components/DomainRow";+import { useDevelopersContext } from "../../../DevelopersContext";++export function DomainsClient() {+ const { appId } = useParams<{ appId: string }>();+ const { apps } = useDevelopersContext();+ const app = apps.find((a) => a.id === appId);+ const router = useRouter();+ const domainInputId = useId();+ const [newDomain, setNewDomain] = useState("");++ const addMutation = useMutation({+ mutationFn: () => addDeveloperDomain(appId, newDomain),+ onSuccess: () => {+ setNewDomain("");+ toast.success("Domain added");+ router.refresh();+ },+ onError: (error) => {+ toast.error(+ error instanceof Error ? error.message : "Failed to add domain",+ );+ },+ });++ if (!app) {+ return <p className="text-sm text-gray-10">App not found</p>;+ }++ return (+ <div className="flex flex-col gap-5 max-w-xl">+ {app.environment === "development" && (+ <div className="flex items-start gap-2.5 p-3 text-xs rounded-lg bg-yellow-400/10 text-yellow-200">+ <AlertTriangle+ size={14}+ className="mt-0.5 shrink-0 text-yellow-400"+ />+ Development apps allow all localhost origins automatically.+ </div>+ )}++ <Card>+ <CardHeader>+ <CardTitle>Allowed Domains</CardTitle>+ <CardDescription>+ Restrict which domains can use your public API key.+ </CardDescription>+ </CardHeader>+ <form+ onSubmit={(e) => {+ e.preventDefault();+ addMutation.mutate();+ }}+ className="flex gap-2 items-end mt-4"+ >+ <div className="flex flex-col flex-1 gap-1.5">+ <Label htmlFor={domainInputId} className="text-xs">+ Add Domain+ </Label>+ <Input+ id={domainInputId}+ value={newDomain}+ onChange={(e) => setNewDomain(e.target.value)}+ placeholder="https://myapp.com"+ />+ </div>+ <Button+ type="submit"+ variant="dark"+ size="sm"+ disabled={!newDomain.trim() || addMutation.isPending}+ spinner={addMutation.isPending}+ >+ <Plus size={14} className="mr-1" />+ Add+ </Button>+ </form>++ {app.domains.length > 0 && (+ <div className="flex flex-col gap-2 mt-4 pt-4 border-t border-gray-3">+ {app.domains.map((d) => (+ <DomainRow+ key={d.id}+ appId={appId}+ domainId={d.id}+ domain={d.domain}+ />+ ))}+ </div>+ )}++ {app.domains.length === 0 && (+ <p className="mt-4 pt-4 border-t border-gray-3 text-sm text-center text-gray-10 py-4">+ No domains configured+ </p>+ )}+ </Card>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/domains/page.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/domains/page.tsxnew file mode 100644index 000000000..db25636b3--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/domains/page.tsx@@ -0,0 +1,10 @@+import type { Metadata } from "next";+import { DomainsClient } from "./DomainsClient";++export const metadata: Metadata = {+ title: "Allowed Domains — Cap",+};++export default async function DomainsPage() {+ return <DomainsClient />;+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/layout.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/layout.tsxnew file mode 100644index 000000000..388507f63--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/layout.tsx@@ -0,0 +1,27 @@+"use client";++import { useParams } from "next/navigation";+import { EnvironmentBadge } from "../../_components/EnvironmentBadge";+import { useDevelopersContext } from "../../DevelopersContext";++export default function AppDetailLayout({+ children,+}: {+ children: React.ReactNode;+}) {+ const { appId } = useParams<{ appId: string }>();+ const { apps } = useDevelopersContext();+ const app = apps.find((a) => a.id === appId);++ return (+ <div className="flex flex-col gap-5">+ <div className="flex items-center gap-2">+ <h2 className="text-base font-medium text-gray-12">+ {app?.name ?? "App"}+ </h2>+ {app && <EnvironmentBadge environment={app.environment} />}+ </div>+ {children}+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/settings/AppSettingsClient.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/settings/AppSettingsClient.tsxnew file mode 100644index 000000000..43bddcd98--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/settings/AppSettingsClient.tsx@@ -0,0 +1,163 @@+"use client";++import {+ Button,+ Card,+ CardDescription,+ CardHeader,+ CardTitle,+ Input,+ Label,+} from "@cap/ui";+import { useMutation } from "@tanstack/react-query";+import { Trash2 } from "lucide-react";+import { useParams, useRouter } from "next/navigation";+import { useId, useState } from "react";+import { toast } from "sonner";+import { deleteDeveloperApp } from "@/actions/developers/delete-app";+import { updateDeveloperApp } from "@/actions/developers/update-app";+import { useDevelopersContext } from "../../../DevelopersContext";++export function AppSettingsClient() {+ const { appId } = useParams<{ appId: string }>();+ const { apps } = useDevelopersContext();+ const app = apps.find((a) => a.id === appId);+ const router = useRouter();+ const nameInputId = useId();++ const [name, setName] = useState(app?.name ?? "");+ const [environment, setEnvironment] = useState(+ app?.environment ?? "development",+ );+ const [confirmDelete, setConfirmDelete] = useState(false);++ const updateMutation = useMutation({+ mutationFn: () =>+ updateDeveloperApp({+ appId,+ name,+ environment: environment as "development" | "production",+ }),+ onSuccess: () => {+ toast.success("App updated");+ router.refresh();+ },+ onError: () => toast.error("Failed to update app"),+ });++ const deleteMutation = useMutation({+ mutationFn: () => deleteDeveloperApp(appId),+ onSuccess: () => {+ toast.success("App deleted");+ router.push("/dashboard/developers/apps");+ router.refresh();+ },+ onError: () => toast.error("Failed to delete app"),+ });++ if (!app) {+ return <p className="text-sm text-gray-10">App not found</p>;+ }++ return (+ <div className="flex flex-col gap-5 max-w-xl">+ <Card>+ <CardHeader>+ <CardTitle>General</CardTitle>+ <CardDescription>+ Update your app name and environment.+ </CardDescription>+ </CardHeader>+ <form+ onSubmit={(e) => {+ e.preventDefault();+ updateMutation.mutate();+ }}+ className="flex flex-col gap-4 mt-4"+ >+ <div className="flex flex-col gap-2">+ <Label htmlFor={nameInputId}>App Name</Label>+ <Input+ id={nameInputId}+ value={name}+ onChange={(e) => setName(e.target.value)}+ />+ </div>+ <div className="flex flex-col gap-2">+ <Label>Environment</Label>+ <div className="flex gap-2">+ <Button+ type="button"+ variant={environment === "development" ? "dark" : "gray"}+ size="sm"+ onClick={() => setEnvironment("development")}+ >+ Development+ </Button>+ <Button+ type="button"+ variant={environment === "production" ? "dark" : "gray"}+ size="sm"+ onClick={() => setEnvironment("production")}+ >+ Production+ </Button>+ </div>+ </div>+ <Button+ type="submit"+ variant="dark"+ size="sm"+ className="self-start"+ spinner={updateMutation.isPending}+ disabled={updateMutation.isPending}+ >+ Save Changes+ </Button>+ </form>+ </Card>++ <Card className="border-red-400/20">+ <CardHeader>+ <CardTitle className="text-red-400">Danger Zone</CardTitle>+ <CardDescription>+ Deleting an app will revoke all API keys and stop all SDK+ integrations.+ </CardDescription>+ </CardHeader>+ <div className="mt-4">+ {!confirmDelete ? (+ <Button+ variant="gray"+ size="sm"+ onClick={() => setConfirmDelete(true)}+ >+ <Trash2 size={14} className="mr-1" />+ Delete App+ </Button>+ ) : (+ <div className="flex gap-2">+ <Button+ variant="gray"+ size="sm"+ onClick={() => setConfirmDelete(false)}+ >+ Cancel+ </Button>+ <Button+ variant="dark"+ size="sm"+ className="!bg-red-400 hover:!bg-red-300"+ spinner={deleteMutation.isPending}+ disabled={deleteMutation.isPending}+ onClick={() => deleteMutation.mutate()}+ >+ Confirm Delete+ </Button>+ </div>+ )}+ </div>+ </Card>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/settings/page.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/settings/page.tsxnew file mode 100644index 000000000..8b8b6684f--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/settings/page.tsx@@ -0,0 +1,10 @@+import type { Metadata } from "next";+import { AppSettingsClient } from "./AppSettingsClient";++export const metadata: Metadata = {+ title: "App Settings — Cap",+};++export default async function AppSettingsPage() {+ return <AppSettingsClient />;+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/videos/VideosClient.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/videos/VideosClient.tsxnew file mode 100644index 000000000..9675def82--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/videos/VideosClient.tsx@@ -0,0 +1,138 @@+"use client";++import type { developerVideos } from "@cap/database/schema";+import {+ Button,+ Card,+ CardDescription,+ CardHeader,+ CardTitle,+ Input,+} from "@cap/ui";+import { useMutation } from "@tanstack/react-query";+import { Search, Trash2 } from "lucide-react";+import { useRouter, useSearchParams } from "next/navigation";+import { useState } from "react";+import { toast } from "sonner";+import { deleteDeveloperVideo } from "@/actions/developers/delete-video";++type Video = typeof developerVideos.$inferSelect;++export function VideosClient({+ appId,+ videos,+}: {+ appId: string;+ videos: Video[];+}) {+ const router = useRouter();+ const searchParams = useSearchParams();+ const [userIdFilter, setUserIdFilter] = useState(+ searchParams.get("userId") ?? "",+ );++ const handleFilter = () => {+ const params = new URLSearchParams();+ if (userIdFilter.trim()) params.set("userId", userIdFilter.trim());+ router.push(+ `/dashboard/developers/apps/${appId}/videos?${params.toString()}`,+ );+ };++ return (+ <div className="flex flex-col gap-5">+ <Card>+ <CardHeader>+ <CardTitle>Videos</CardTitle>+ <CardDescription>+ Videos recorded through the SDK for this app.+ </CardDescription>+ </CardHeader>++ <div className="flex gap-2 items-end mt-4">+ <div className="flex-1">+ <Input+ value={userIdFilter}+ onChange={(e) => setUserIdFilter(e.target.value)}+ placeholder="Filter by user ID..."+ />+ </div>+ <Button variant="gray" size="sm" onClick={handleFilter}>+ <Search size={14} className="mr-1" />+ Filter+ </Button>+ </div>++ {videos.length === 0 ? (+ <p className="py-8 text-sm text-center text-gray-10 mt-4">+ No videos found+ </p>+ ) : (+ <div className="overflow-x-auto rounded-lg border border-gray-3 mt-4">+ <table className="w-full text-sm">+ <thead>+ <tr className="border-b border-gray-3 bg-gray-3/50">+ <th className="px-4 py-2.5 text-left text-xs font-medium text-gray-10">+ Name+ </th>+ <th className="px-4 py-2.5 text-left text-xs font-medium text-gray-10">+ User ID+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Duration+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Created+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10" />+ </tr>+ </thead>+ <tbody>+ {videos.map((video) => (+ <VideoRow key={video.id} video={video} appId={appId} />+ ))}+ </tbody>+ </table>+ </div>+ )}+ </Card>+ </div>+ );+}++function VideoRow({ video, appId }: { video: Video; appId: string }) {+ const router = useRouter();+ const deleteMutation = useMutation({+ mutationFn: () => deleteDeveloperVideo(appId, video.id),+ onSuccess: () => {+ toast.success("Video deleted");+ router.refresh();+ },+ onError: () => toast.error("Failed to delete video"),+ });++ return (+ <tr className="border-b border-gray-3 last:border-0">+ <td className="px-4 py-2.5 text-gray-12">{video.name}</td>+ <td className="px-4 py-2.5 text-gray-10 font-mono text-xs">+ {video.externalUserId ?? "\u2014"}+ </td>+ <td className="px-4 py-2.5 text-right text-gray-11">+ {video.duration ? `${(video.duration / 60).toFixed(1)}m` : "\u2014"}+ </td>+ <td className="px-4 py-2.5 text-right text-gray-10">+ {new Date(video.createdAt).toLocaleDateString()}+ </td>+ <td className="px-4 py-2.5 text-right">+ <button+ type="button"+ onClick={() => deleteMutation.mutate()}+ disabled={deleteMutation.isPending}+ className="p-1.5 rounded-md hover:bg-gray-3 text-gray-10 hover:text-red-400 transition-colors"+ >+ <Trash2 size={14} />+ </button>+ </td>+ </tr>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/[appId]/videos/page.tsx b/apps/web/app/(org)/dashboard/developers/apps/[appId]/videos/page.tsxnew file mode 100644index 000000000..7b810b935--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/[appId]/videos/page.tsx@@ -0,0 +1,44 @@+import { db } from "@cap/database";+import { getCurrentUser } from "@cap/database/auth/session";+import { developerApps } from "@cap/database/schema";+import { and, eq, isNull } from "drizzle-orm";+import type { Metadata } from "next";+import { redirect } from "next/navigation";+import { getDeveloperAppVideos } from "../../../developer-data";+import { VideosClient } from "./VideosClient";++export const metadata: Metadata = {+ title: "Developer Videos — Cap",+};++export default async function VideosPage({+ params,+ searchParams,+}: {+ params: Promise<{ appId: string }>;+ searchParams: Promise<{ userId?: string }>;+}) {+ const user = await getCurrentUser();+ if (!user) redirect("/auth/signin");++ const { appId } = await params;+ const { userId } = await searchParams;++ const [app] = await db()+ .select()+ .from(developerApps)+ .where(+ and(+ eq(developerApps.id, appId),+ eq(developerApps.ownerId, user.id),+ isNull(developerApps.deletedAt),+ ),+ )+ .limit(1);++ if (!app) redirect("/dashboard/developers/apps");++ const videos = await getDeveloperAppVideos(appId, { userId });++ return <VideosClient appId={appId} videos={videos} />;+}diff --git a/apps/web/app/(org)/dashboard/developers/apps/page.tsx b/apps/web/app/(org)/dashboard/developers/apps/page.tsxnew file mode 100644index 000000000..0de507cd2--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/apps/page.tsx@@ -0,0 +1,10 @@+import type { Metadata } from "next";+import { AppsListClient } from "./AppsListClient";++export const metadata: Metadata = {+ title: "Developer Apps — Cap",+};++export default async function AppsPage() {+ return <AppsListClient />;+}diff --git a/apps/web/app/(org)/dashboard/developers/credits/CreditsClient.tsx b/apps/web/app/(org)/dashboard/developers/credits/CreditsClient.tsxnew file mode 100644index 000000000..5cf927542--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/credits/CreditsClient.tsx@@ -0,0 +1,193 @@+"use client";++import {+ Button,+ Card,+ CardDescription,+ CardHeader,+ CardTitle,+ Input,+} from "@cap/ui";+import { useMutation } from "@tanstack/react-query";+import { useRouter, useSearchParams } from "next/navigation";+import { useEffect, useState } from "react";+import { toast } from "sonner";+import { updateDeveloperAutoTopUp } from "@/actions/developers/update-auto-topup";+import { CreditTransactionTable } from "../_components/CreditTransactionTable";+import { StatBox } from "../_components/StatBox";+import { useDevelopersContext } from "../DevelopersContext";+import type { DeveloperTransaction } from "../developer-data";++const presets = [+ { label: "$10", cents: 1000 },+ { label: "$25", cents: 2500 },+ { label: "$50", cents: 5000 },+];++export function CreditsClient({+ transactions,+}: {+ transactions: DeveloperTransaction[];+}) {+ const { apps } = useDevelopersContext();+ const router = useRouter();+ const searchParams = useSearchParams();+ const [selectedApp, setSelectedApp] = useState(apps[0]?.id ?? "");+ const [customAmount, setCustomAmount] = useState("");++ const app = apps.find((a) => a.id === selectedApp);+ const balance = app?.creditAccount?.balanceMicroCredits ?? 0;+ const autoTopUp = app?.creditAccount?.autoTopUpEnabled ?? false;++ useEffect(() => {+ if (searchParams.get("purchase") === "success") {+ toast.success("Credits purchased successfully!");+ router.replace("/dashboard/developers/credits");+ }+ }, [searchParams, router]);++ const purchaseMutation = useMutation({+ mutationFn: async (amountCents: number) => {+ const res = await fetch("/api/developer/credits/checkout", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ appId: selectedApp, amountCents }),+ });++ if (!res.ok) {+ const data = await res.json();+ throw new Error(data.error ?? "Failed to start checkout");+ }++ const { url } = await res.json();+ window.location.href = url;+ },+ onError: (error) => {+ toast.error(+ error instanceof Error ? error.message : "Failed to purchase credits",+ );+ },+ });++ const autoTopUpMutation = useMutation({+ mutationFn: (enabled: boolean) =>+ updateDeveloperAutoTopUp({+ appId: selectedApp,+ enabled,+ thresholdMicroCredits: 500_000,+ amountCents: 2500,+ }),+ onSuccess: () => {+ toast.success("Auto top-up updated");+ router.refresh();+ },+ onError: () => toast.error("Failed to update auto top-up"),+ });++ return (+ <div className="flex flex-col gap-5">+ <div className="flex items-center justify-between">+ <h2 className="text-base font-medium text-gray-12">Credits</h2>+ {apps.length > 1 && (+ <select+ value={selectedApp}+ onChange={(e) => setSelectedApp(e.target.value)}+ className="px-3 py-1.5 text-sm rounded-lg bg-gray-3 border border-gray-6 text-gray-12"+ >+ {apps.map((a) => (+ <option key={a.id} value={a.id}>+ {a.name}+ </option>+ ))}+ </select>+ )}+ </div>++ <div className="grid gap-3 sm:grid-cols-3">+ <StatBox label="Balance" value={`$${(balance / 100_000).toFixed(2)}`} />+ <StatBox label="Recording Rate" value="$0.05/min" />+ <StatBox label="Storage Rate" value="$0.001/min/mo" />+ </div>++ <div className="grid gap-3 sm:grid-cols-2">+ <Card>+ <CardHeader>+ <CardTitle>Purchase Credits</CardTitle>+ <CardDescription>Add credits to your account.</CardDescription>+ </CardHeader>+ <div className="flex flex-wrap gap-2 mt-4">+ {presets.map((preset) => (+ <Button+ key={preset.cents}+ variant="gray"+ size="sm"+ spinner={+ purchaseMutation.isPending &&+ purchaseMutation.variables === preset.cents+ }+ disabled={purchaseMutation.isPending || !selectedApp}+ onClick={() => purchaseMutation.mutate(preset.cents)}+ >+ {preset.label}+ </Button>+ ))}+ </div>+ <div className="flex gap-2 items-center mt-3">+ <Input+ value={customAmount}+ onChange={(e) => setCustomAmount(e.target.value)}+ placeholder="$"+ className="w-20"+ />+ <Button+ variant="dark"+ size="sm"+ disabled={+ !customAmount || purchaseMutation.isPending || !selectedApp+ }+ onClick={() => {+ const cents = Math.round(Number.parseFloat(customAmount) * 100);+ if (cents >= 500) {+ purchaseMutation.mutate(cents);+ } else {+ toast.error("Minimum purchase is $5.00");+ }+ }}+ >+ Purchase+ </Button>+ </div>+ </Card>++ <Card>+ <CardHeader>+ <CardTitle>Auto Top-Up</CardTitle>+ <CardDescription>+ Automatically add $25 when balance drops below $5.+ </CardDescription>+ </CardHeader>+ <div className="mt-4">+ <Button+ variant={autoTopUp ? "dark" : "gray"}+ size="sm"+ spinner={autoTopUpMutation.isPending}+ disabled={autoTopUpMutation.isPending || !selectedApp}+ onClick={() => autoTopUpMutation.mutate(!autoTopUp)}+ >+ {autoTopUp ? "Disable Auto Top-Up" : "Enable Auto Top-Up"}+ </Button>+ </div>+ </Card>+ </div>++ <Card>+ <CardHeader>+ <CardTitle>Transaction History</CardTitle>+ </CardHeader>+ <div className="mt-4">+ <CreditTransactionTable transactions={transactions} />+ </div>+ </Card>+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/credits/page.tsx b/apps/web/app/(org)/dashboard/developers/credits/page.tsxnew file mode 100644index 000000000..9dedda42d--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/credits/page.tsx@@ -0,0 +1,35 @@+import { db } from "@cap/database";+import { getCurrentUser } from "@cap/database/auth/session";+import { developerCreditTransactions } from "@cap/database/schema";+import { desc, inArray } from "drizzle-orm";+import type { Metadata } from "next";+import { redirect } from "next/navigation";+import { getDeveloperApps } from "../developer-data";+import { CreditsClient } from "./CreditsClient";++export const metadata: Metadata = {+ title: "Developer Credits — Cap",+};++export default async function CreditsPage() {+ const user = await getCurrentUser();+ if (!user) redirect("/auth/signin");++ const apps = await getDeveloperApps(user);++ const accountIds = apps+ .map((a) => a.creditAccount?.id)+ .filter((id): id is string => Boolean(id));++ const transactions =+ accountIds.length > 0+ ? await db()+ .select()+ .from(developerCreditTransactions)+ .where(inArray(developerCreditTransactions.accountId, accountIds))+ .orderBy(desc(developerCreditTransactions.createdAt))+ .limit(50)+ : [];++ return <CreditsClient transactions={transactions} />;+}diff --git a/apps/web/app/(org)/dashboard/developers/developer-data.ts b/apps/web/app/(org)/dashboard/developers/developer-data.tsnew file mode 100644index 000000000..66bc539d2--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/developer-data.ts@@ -0,0 +1,151 @@+import { db } from "@cap/database";+import type { userSelectProps } from "@cap/database/auth/session";+import {+ developerApiKeys,+ developerAppDomains,+ developerApps,+ developerCreditAccounts,+ developerCreditTransactions,+ developerVideos,+} from "@cap/database/schema";+import { and, count, desc, eq, inArray, isNull, sql } from "drizzle-orm";++export type DeveloperApiKey = Pick<+ typeof developerApiKeys.$inferSelect,+ "id" | "keyType" | "keyPrefix" | "createdAt" | "revokedAt"+> & {+ fullKey?: string;+};++export type DeveloperApp = typeof developerApps.$inferSelect & {+ domains: (typeof developerAppDomains.$inferSelect)[];+ apiKeys: DeveloperApiKey[];+ creditAccount: typeof developerCreditAccounts.$inferSelect | null;+ videoCount: number;+};++export type DeveloperTransaction =+ typeof developerCreditTransactions.$inferSelect;++export async function getDeveloperApps(+ user: typeof userSelectProps,+): Promise<DeveloperApp[]> {+ const apps = await db()+ .select()+ .from(developerApps)+ .where(+ and(eq(developerApps.ownerId, user.id), isNull(developerApps.deletedAt)),+ )+ .orderBy(desc(developerApps.createdAt));++ if (apps.length === 0) return [];++ const appIds = apps.map((a) => a.id);++ const [allDomains, allApiKeys, allCreditAccounts, allVideoCounts] =+ await Promise.all([+ db()+ .select()+ .from(developerAppDomains)+ .where(inArray(developerAppDomains.appId, appIds)),+ db()+ .select({+ id: developerApiKeys.id,+ appId: developerApiKeys.appId,+ keyType: developerApiKeys.keyType,+ keyPrefix: developerApiKeys.keyPrefix,+ encryptedKey: developerApiKeys.encryptedKey,+ createdAt: developerApiKeys.createdAt,+ revokedAt: developerApiKeys.revokedAt,+ })+ .from(developerApiKeys)+ .where(+ and(+ inArray(developerApiKeys.appId, appIds),+ isNull(developerApiKeys.revokedAt),+ ),+ ),+ db()+ .select()+ .from(developerCreditAccounts)+ .where(inArray(developerCreditAccounts.appId, appIds)),+ db()+ .select({+ appId: developerVideos.appId,+ count: count(),+ })+ .from(developerVideos)+ .where(+ and(+ inArray(developerVideos.appId, appIds),+ isNull(developerVideos.deletedAt),+ ),+ )+ .groupBy(developerVideos.appId),+ ]);++ return apps.map((app) => ({+ ...app,+ domains: allDomains.filter((d) => d.appId === app.id),+ apiKeys: allApiKeys+ .filter((k) => k.appId === app.id)+ .map((k) => ({+ id: k.id,+ keyType: k.keyType,+ keyPrefix: k.keyPrefix,+ createdAt: k.createdAt,+ revokedAt: k.revokedAt,+ fullKey: k.keyType === "public" ? k.encryptedKey : undefined,+ })),+ creditAccount: allCreditAccounts.find((c) => c.appId === app.id) ?? null,+ videoCount: allVideoCounts.find((v) => v.appId === app.id)?.count ?? 0,+ }));+}++export async function getDeveloperAppVideos(+ appId: string,+ options?: { userId?: string; limit?: number; offset?: number },+) {+ const conditions = [+ eq(developerVideos.appId, appId),+ isNull(developerVideos.deletedAt),+ ];++ if (options?.userId) {+ conditions.push(eq(developerVideos.externalUserId, options.userId));+ }++ return db()+ .select()+ .from(developerVideos)+ .where(and(...conditions))+ .orderBy(desc(developerVideos.createdAt))+ .limit(options?.limit ?? 50)+ .offset(options?.offset ?? 0);+}++export async function getDeveloperTransactions(accountId: string, limit = 50) {+ return db()+ .select()+ .from(developerCreditTransactions)+ .where(eq(developerCreditTransactions.accountId, accountId))+ .orderBy(desc(developerCreditTransactions.createdAt))+ .limit(limit);+}++export async function getDeveloperUsageSummary(appId: string) {+ const [videoStats] = await db()+ .select({+ totalVideos: count(),+ totalDurationMinutes: sql<number>`COALESCE(SUM(${developerVideos.duration}) / 60, 0)`,+ })+ .from(developerVideos)+ .where(+ and(eq(developerVideos.appId, appId), isNull(developerVideos.deletedAt)),+ );++ return {+ totalVideos: videoStats?.totalVideos ?? 0,+ totalDurationMinutes: videoStats?.totalDurationMinutes ?? 0,+ };+}diff --git a/apps/web/app/(org)/dashboard/developers/layout.tsx b/apps/web/app/(org)/dashboard/developers/layout.tsxnew file mode 100644index 000000000..84a4a10b8--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/layout.tsx@@ -0,0 +1,31 @@+import { getCurrentUser } from "@cap/database/auth/session";+import type { Metadata } from "next";+import { redirect } from "next/navigation";+import { DeveloperSidebarRegistrar } from "./_components/DeveloperSidebarRegistrar";+import { DeveloperThemeForcer } from "./_components/DeveloperThemeForcer";+import { DevelopersProvider } from "./DevelopersContext";+import { getDeveloperApps } from "./developer-data";++export const metadata: Metadata = {+ title: "Developers — Cap",+};++export default async function DevelopersLayout({+ children,+}: {+ children: React.ReactNode;+}) {+ const user = await getCurrentUser();+ if (!user) redirect("/auth/signin");++ const apps = await getDeveloperApps(user);++ return (+ <DevelopersProvider apps={apps}>+ <DeveloperThemeForcer>+ <DeveloperSidebarRegistrar apps={apps} />+ {children}+ </DeveloperThemeForcer>+ </DevelopersProvider>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/page.tsx b/apps/web/app/(org)/dashboard/developers/page.tsxnew file mode 100644index 000000000..7a92dc8f0--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/page.tsx@@ -0,0 +1,5 @@+import { redirect } from "next/navigation";++export default function DevelopersPage() {+ redirect("/dashboard/developers/apps");+}diff --git a/apps/web/app/(org)/dashboard/developers/usage/UsageClient.tsx b/apps/web/app/(org)/dashboard/developers/usage/UsageClient.tsxnew file mode 100644index 000000000..7b0269938--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/usage/UsageClient.tsx@@ -0,0 +1,81 @@+"use client";++import { Card, CardHeader, CardTitle } from "@cap/ui";+import { EnvironmentBadge } from "../_components/EnvironmentBadge";+import { StatBox } from "../_components/StatBox";+import { useDevelopersContext } from "../DevelopersContext";++export function UsageClient() {+ const { apps } = useDevelopersContext();++ const totalVideos = apps.reduce((sum, app) => sum + app.videoCount, 0);+ const totalBalance = apps.reduce(+ (sum, app) => sum + (app.creditAccount?.balanceMicroCredits ?? 0),+ 0,+ );++ return (+ <div className="flex flex-col gap-5">+ <h2 className="text-base font-medium text-gray-12">Usage Overview</h2>++ <div className="grid gap-3 sm:grid-cols-3">+ <StatBox label="Total Videos" value={totalVideos} />+ <StatBox label="Total Apps" value={apps.length} />+ <StatBox+ label="Credit Balance"+ value={`$${(totalBalance / 100_000).toFixed(2)}`}+ />+ </div>++ {apps.length > 0 && (+ <Card>+ <CardHeader>+ <CardTitle>Usage by App</CardTitle>+ </CardHeader>+ <div className="overflow-x-auto rounded-lg border border-gray-3 mt-4">+ <table className="w-full text-sm">+ <thead>+ <tr className="border-b border-gray-3 bg-gray-3/50">+ <th className="px-4 py-2.5 text-left text-xs font-medium text-gray-10">+ App+ </th>+ <th className="px-4 py-2.5 text-left text-xs font-medium text-gray-10">+ Environment+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Videos+ </th>+ <th className="px-4 py-2.5 text-right text-xs font-medium text-gray-10">+ Balance+ </th>+ </tr>+ </thead>+ <tbody>+ {apps.map((app) => (+ <tr+ key={app.id}+ className="border-b border-gray-3 last:border-0"+ >+ <td className="px-4 py-2.5 text-gray-12">{app.name}</td>+ <td className="px-4 py-2.5">+ <EnvironmentBadge environment={app.environment} />+ </td>+ <td className="px-4 py-2.5 text-right text-gray-11 tabular-nums">+ {app.videoCount}+ </td>+ <td className="px-4 py-2.5 text-right text-gray-11 tabular-nums">+ $+ {(+ (app.creditAccount?.balanceMicroCredits ?? 0) / 100_000+ ).toFixed(2)}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ </Card>+ )}+ </div>+ );+}diff --git a/apps/web/app/(org)/dashboard/developers/usage/page.tsx b/apps/web/app/(org)/dashboard/developers/usage/page.tsxnew file mode 100644index 000000000..3bb1b6694--- /dev/null+++ b/apps/web/app/(org)/dashboard/developers/usage/page.tsx@@ -0,0 +1,10 @@+import type { Metadata } from "next";+import { UsageClient } from "./UsageClient";++export const metadata: Metadata = {+ title: "Developer Usage — Cap",+};++export default async function UsagePage() {+ return <UsageClient />;+}