import { StackedColumnChart } from "@/components/dashboard/charts"; import { EmptyPlaceholder } from "@/components/dashboard/empty-placeholder"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { Separator } from "@/components/ui/separator"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { getTenantId } from "@/lib/auth"; // import { and, db, eq, isNull, schema } from "@/lib/db"; import { formatNumber } from "@/lib/fmt"; // import { // getLastUsed, // getLatestVerifications, // getVerificationsDaily, // getVerificationsHourly, // } from "@/lib/tinybird"; import { BarChart, Minus } from "lucide-react"; // import ms from "ms"; import { notFound } from "next/navigation"; import { type Interval, IntervalSelect } from "../../../apis/[apiId]/select"; import { AccessTable } from "./table"; export const dynamic = "force-dynamic"; export const runtime = "edge"; export default async function KeyPage(props: { params: { keyId: string }; searchParams: { interval?: Interval; }; }) { const tenantId = getTenantId(); // const key = await db.query.keys.findFirst({ // where: and(eq(schema.keys.id, props.params.keyId), isNull(schema.keys.deletedAt)), // with: { // workspace: true, // }, // }); // if (!key || key.workspace.tenantId !== tenantId) { // return notFound(); // } // const api = await db.query.apis.findFirst({ // where: (table, { eq, and, isNull }) => // and(eq(table.keyAuthId, key.keyAuthId), isNull(table.deletedAt)), // }); // if (!api) { // return notFound(); // } const interval = props.searchParams.interval ?? "7d"; const { getVerificationsPerInterval, start, end, granularity } = prepareInterval(interval); // const query = { // workspaceId: api.workspaceId, // apiId: api.id, // keyId: key.id, // start, // end, // }; // const [verifications, totalUsage, latestVerifications, lastUsed] = await Promise.all([ // getVerificationsPerInterval(query), // getVerificationsPerInterval({ // workspaceId: api.workspaceId, // apiId: api.id, // keyId: key.id, // }).then((res) => res.data.at(0) ?? { success: 0, rateLimited: 0, usageExceeded: 0 }), // no interval -> a // getLatestVerifications({ // workspaceId: key.workspaceId, // apiId: api.id, // keyId: key.id, // }), // getLastUsed({ keyId: key.id }).then((res) => res.data.at(0)?.lastUsed ?? 0), // ]); const successOverTime: { x: string; y: number }[] = []; const ratelimitedOverTime: { x: string; y: number }[] = []; const usageExceededOverTime: { x: string; y: number }[] = []; // for (const d of verifications.data.sort((a, b) => a.time - b.time)) { // const x = new Date(d.time).toISOString(); // successOverTime.push({ x, y: d.success }); // ratelimitedOverTime.push({ x, y: d.rateLimited }); // usageExceededOverTime.push({ x, y: d.usageExceeded }); // } const verificationsData = [ ...successOverTime.map((d) => ({ ...d, category: "Successful Verifications", })), ...ratelimitedOverTime.map((d) => ({ ...d, category: "Ratelimited" })), ...usageExceededOverTime.map((d) => ({ ...d, category: "Usage Exceeded" })), ]; return (
{label}
{tooltip}