Create analytics-router.ts with ~30 tRPC endpoints for KPI management, alert rules, scheduled reports, cohort analysis, and NPS survey integration. Register router in index.ts under 'analytics' namespace. Fix pre-existing bugs in service files: snake_case to camelCase conversion, missing non-null assertions, and incorrect DB access patterns. Co-Authored-By: Paperclip <noreply@paperclip.ing>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { createHTTPServer } from '@trpc/server/adapters/standalone';
|
|
import { projectRouter } from './project-router';
|
|
import { revisionsRouter } from './revisions-router';
|
|
import { scriptsRouter } from './scripts-router';
|
|
import { waitlistRouter } from './waitlist-router';
|
|
import { betaRouter } from './beta-router';
|
|
import { mailRouter } from './mail-router';
|
|
import { teamRouter } from './team-router';
|
|
import { analyticsRouter } from './analytics-router';
|
|
import type { TRPCContext } from './types';
|
|
import type { TRPCError } from '@trpc/server';
|
|
import { t } from './router';
|
|
|
|
// App router combining all routers
|
|
export const appRouter = t.router({
|
|
project: projectRouter,
|
|
revisions: revisionsRouter,
|
|
scripts: scriptsRouter,
|
|
waitlist: waitlistRouter,
|
|
beta: betaRouter,
|
|
mail: mailRouter,
|
|
team: teamRouter,
|
|
analytics: analyticsRouter,
|
|
} as const);
|
|
|
|
export type AppRouter = typeof appRouter;
|
|
|
|
// Create tRPC HTTP server - db is loaded lazily to avoid requiring Turso env vars at import time
|
|
export function createTRPCServer(port: number = 8080) {
|
|
const server = createHTTPServer({
|
|
router: appRouter,
|
|
createContext: async (): Promise<TRPCContext> => {
|
|
const { db } = await import('../../src/db/config/migrations');
|
|
return {
|
|
userId: undefined,
|
|
db,
|
|
};
|
|
},
|
|
onError: ({ error, path }: { error: TRPCError; path: string | undefined }) => {
|
|
console.error(`tRPC error on ${path}:`, error.message);
|
|
},
|
|
});
|
|
|
|
server.listen(port, () => {
|
|
console.log(`tRPC server listening on port ${port}`);
|
|
});
|
|
|
|
return server;
|
|
}
|
|
|
|
export default appRouter;
|