feat: complete tRPC integration and fix platform UI issues

- Implement comprehensive tRPC setup with type-safe API
- Create tRPC routers for dashboard, admin, and auth endpoints
- Migrate frontend components to use tRPC client
- Fix platform dashboard Settings button functionality
- Add platform settings page with profile and security management
- Create OpenAI API mocking infrastructure for cost-safe testing
- Update tests to work with new tRPC architecture
- Sync database schema to fix AIBatchRequest table errors
This commit is contained in:
2025-07-11 15:37:53 +02:00
committed by Kaj Kowalski
parent f2a3d87636
commit fa7e815a3b
38 changed files with 4285 additions and 518 deletions

100
lib/trpc-client.ts Normal file
View File

@ -0,0 +1,100 @@
/**
* tRPC Client Configuration
*
* This file sets up the tRPC client for use in React components.
* Provides type-safe API calls with automatic serialization.
*/
import { httpBatchLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import superjson from "superjson";
import type { AppRouter } from "@/server/routers/_app";
function getBaseUrl() {
if (typeof window !== "undefined") {
// browser should use relative path
return "";
}
if (process.env.VERCEL_URL) {
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;
}
if (process.env.RENDER_INTERNAL_HOSTNAME) {
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
}
// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
}
/**
* Main tRPC client instance
*/
export const trpc = createTRPCNext<AppRouter>({
config() {
return {
links: [
httpBatchLink({
/**
* If you want to use SSR, you need to use the server's full URL
* @link https://trpc.io/docs/ssr
**/
url: `${getBaseUrl()}/api/trpc`,
/**
* Transformer for data serialization
*/
transformer: superjson,
/**
* Set custom request headers on every request from tRPC
* @link https://trpc.io/docs/v10/header
*/
headers() {
return {
// Include credentials for authentication
credentials: "include",
};
},
}),
],
/**
* Query client configuration
* @link https://trpc.io/docs/v10/react-query-integration
*/
queryClientConfig: {
defaultOptions: {
queries: {
// Stale time of 30 seconds
staleTime: 30 * 1000,
// Cache time of 5 minutes
gcTime: 5 * 60 * 1000,
// Retry failed requests up to 3 times
retry: 3,
// Retry delay that increases exponentially
retryDelay: (attemptIndex) =>
Math.min(1000 * 2 ** attemptIndex, 30000),
},
mutations: {
// Retry mutations once on network errors
retry: 1,
},
},
},
};
},
/**
* Whether tRPC should await queries when server rendering pages
* @link https://trpc.io/docs/nextjs#ssr-boolean-default-false
*/
ssr: false,
transformer: superjson,
});
/**
* Type helper for tRPC router
*/
export type TRPCRouter = typeof trpc;