cd78f72f33
Complete rename of all technical identifiers across the codebase: Package names (11 packages): - @planarchy/* → @capakraken/* in all package.json, tsconfig, imports Import statements: 277 files, 548 occurrences replaced Database & Docker: - PostgreSQL user/db: planarchy → capakraken - Docker volumes: planarchy_pgdata → capakraken_pgdata - Connection strings updated in docker-compose, .env, CI CI/CD: - GitHub Actions workflow: all filter commands updated - Test database credentials updated Infrastructure: - Redis channel: planarchy:sse → capakraken:sse - Logger service name: planarchy-api → capakraken-api - Anonymization seed updated - Start/stop/restart scripts updated Test data: - Seed emails: @planarchy.dev → @capakraken.dev - E2E test credentials: all 11 spec files updated - Email defaults: @planarchy.app → @capakraken.app - localStorage keys: planarchy_* → capakraken_* Documentation: 30+ .md files updated Verification: - pnpm install: workspace resolution works - TypeScript: only pre-existing TS2589 (no new errors) - Engine: 310/310 tests pass - Staffing: 37/37 tests pass Co-Authored-By: claude-flow <ruv@ruv.net>
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { createTRPCContext, loadRoleDefaults } from "@capakraken/api";
|
|
import { appRouter } from "@capakraken/api/router";
|
|
import { prisma } from "@capakraken/db";
|
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
import type { NextRequest } from "next/server";
|
|
import { auth } from "~/server/auth.js";
|
|
|
|
// Throttle lastActiveAt updates: max once per 60s per user
|
|
const lastActiveCache = new Map<string, number>();
|
|
const ACTIVITY_THROTTLE_MS = 60_000;
|
|
|
|
function trackActivity(userId: string) {
|
|
const now = Date.now();
|
|
const last = lastActiveCache.get(userId) ?? 0;
|
|
if (now - last < ACTIVITY_THROTTLE_MS) return;
|
|
lastActiveCache.set(userId, now);
|
|
prisma.user.update({
|
|
where: { id: userId },
|
|
data: { lastActiveAt: new Date(now) },
|
|
}).catch(() => {/* ignore */});
|
|
}
|
|
|
|
const handler = async (req: NextRequest) => {
|
|
const session = await auth();
|
|
|
|
const dbUser = session?.user?.email
|
|
? await prisma.user.findUnique({
|
|
where: { email: session.user.email },
|
|
select: { id: true, systemRole: true, permissionOverrides: true },
|
|
})
|
|
: null;
|
|
|
|
// Track user activity (throttled, fire-and-forget)
|
|
if (dbUser) trackActivity(dbUser.id);
|
|
|
|
// Load configurable role defaults (cached, 60s TTL)
|
|
const roleDefaults = await loadRoleDefaults();
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const options: any = {
|
|
endpoint: "/api/trpc",
|
|
req,
|
|
router: appRouter,
|
|
createContext: () => createTRPCContext({ session, dbUser, roleDefaults }),
|
|
};
|
|
|
|
if (process.env["NODE_ENV"] === "development") {
|
|
options.onError = ({ path, error }: { path?: string; error: { message: string } }) => {
|
|
console.error(`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`);
|
|
};
|
|
}
|
|
|
|
return fetchRequestHandler(options);
|
|
};
|
|
|
|
export { handler as GET, handler as POST };
|