Skip to content

Commit

Permalink
Merge pull request #124 from agrattan0820/feat/upgrade-and-test
Browse files Browse the repository at this point in the history
Feat/upgrade-and-test
  • Loading branch information
agrattan0820 authored Jun 28, 2024
2 parents 2ecc945 + 1ecb7cc commit 20fac69
Show file tree
Hide file tree
Showing 31 changed files with 2,742 additions and 1,716 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: 🏗 Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20.15.0
cache: "pnpm"

- name: 👷 Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.17.1
nodejs 20.15.0
54 changes: 27 additions & 27 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@
"test:e2e": "playwright test"
},
"dependencies": {
"@auth/drizzle-adapter": "^0.8.2",
"@sentry/nextjs": "^7.109.0",
"@tanstack/react-query": "^5.29.0",
"@upstash/ratelimit": "^1.0.3",
"@upstash/redis": "^1.29.0",
"@vercel/analytics": "^1.2.2",
"@xstate/react": "^4.1.0",
"@auth/drizzle-adapter": "^1.4.1",
"@sentry/nextjs": "^8.13.0",
"@tanstack/react-query": "^5.48.0",
"@upstash/ratelimit": "^1.2.1",
"@upstash/redis": "^1.31.6",
"@vercel/analytics": "^1.3.1",
"@xstate/react": "^4.1.1",
"autoprefixer": "10.4.19",
"clsx": "^2.1.0",
"clsx": "^2.1.1",
"database": "workspace:*",
"drizzle-orm": "^0.30.7",
"framer-motion": "^11.0.25",
"next": "^14.1.4",
"drizzle-orm": "^0.31.2",
"framer-motion": "^11.2.12",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"postcss": "8.4.38",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
"react-icons": "^5.0.1",
"react-icons": "^5.2.1",
"server-only": "^0.0.1",
"sharp": "^0.33.3",
"sharp": "^0.33.4",
"socket.io-client": "^4.7.5",
"tailwind-merge": "^2.2.2",
"tailwindcss": "^3.4.3",
"tailwind-merge": "^2.3.0",
"tailwindcss": "^3.4.4",
"typescript": "5.4.4",
"use-sound": "^4.0.1",
"xstate": "^5.9.1"
"use-sound": "^4.0.3",
"xstate": "^5.14.0"
},
"devDependencies": {
"@playwright/test": "^1.43.0",
"@tailwindcss/typography": "^0.5.12",
"@types/node": "^20.12.5",
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.24",
"@playwright/test": "^1.45.0",
"@tailwindcss/typography": "^0.5.13",
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"eslint-config-custom": "workspace:*",
"prettier-plugin-tailwindcss": "^0.5.13",
"prettier-plugin-tailwindcss": "^0.6.5",
"tsconfig": "workspace:*"
},
"engines": {
"node": "18"
"node": "20.15.0"
},
"optionalDependencies": {
"bufferutil": "^4.0.8",
"utf-8-validate": "^6.0.3"
"utf-8-validate": "^6.0.4"
}
}
4 changes: 2 additions & 2 deletions apps/client/src/components/my-drizzle-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
integer,
PgTableFn,
} from "drizzle-orm/pg-core";
import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
import { Adapter, AdapterAccount } from "next-auth/adapters";
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
import type { Adapter, AdapterAccount } from "next-auth/adapters";

export function createTables(pgTable: PgTableFn) {
const users = pgTable("users", {
Expand Down
9 changes: 9 additions & 0 deletions apps/client/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("../sentry.server.config");
}

if (process.env.NEXT_RUNTIME === "edge") {
await import("../sentry.edge.config");
}
}
1 change: 0 additions & 1 deletion apps/client/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const authOptions = (
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID ?? "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
checks: ["none"],
profile(profile) {
const cookieNickname =
req && "cookies" in req && typeof req.cookies === "object"
Expand Down
9 changes: 6 additions & 3 deletions apps/client/src/utils/server-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export async function getRunningGame({ session }: { session: Session }) {
)
.orderBy(desc(games.createdAt))
.groupBy(games.id)
.having(({ playerCount }) => gt(playerCount, 0));
.having(({ playerCount }) => gt(playerCount, 0))
.limit(1);

return runningGame[0];
}
Expand All @@ -33,7 +34,8 @@ export async function isUserInGame({
.select()
.from(games)
.innerJoin(usersToGames, eq(games.id, usersToGames.gameId))
.where(and(eq(usersToGames.userId, session.user.id), eq(games.id, gameId)));
.where(and(eq(usersToGames.userId, session.user.id), eq(games.id, gameId)))
.limit(1);

return userInGame[0];
}
Expand All @@ -51,7 +53,8 @@ export async function isUserInRoom({
.innerJoin(usersToRooms, eq(rooms.code, usersToRooms.roomCode))
.where(
and(eq(usersToRooms.userId, session.user.id), eq(rooms.code, roomCode)),
);
)
.limit(1);

return userInRoom[0];
}
2 changes: 1 addition & 1 deletion apps/client/src/utils/socket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { EventFrom } from "xstate";
import { Socket, io } from "socket.io-client";

import { RoomInfo, UserVote } from "@ai/utils/queries";
import type { RoomInfo, UserVote } from "@ai/utils/queries";
import { gameMachine } from "@ai/components/game/game-machine";

export interface ServerToClientEvents {
Expand Down
23 changes: 12 additions & 11 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,42 @@
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org alexander-grattan --project artificial-unintelligence-server ./dist && sentry-cli sourcemaps upload --org alexander-grattan --project artificial-unintelligence-server ./dist"
},
"dependencies": {
"@sentry/node": "^7.109.0",
"@sentry/node": "^8.13.0",
"@sentry/profiling-node": "^8.13.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"database": "workspace:*",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.30.7",
"drizzle-orm": "^0.31.2",
"express": "^4.19.2",
"helmet": "^7.1.0",
"ioredis": "^5.3.2",
"ioredis": "^5.4.1",
"morgan": "^1.10.0",
"replicate": "^0.29.1",
"replicate": "^0.30.2",
"socket.io": "^4.7.5"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@sentry/cli": "^2.31.0",
"@sentry/cli": "^2.32.1",
"@types/cookie-parser": "^1.4.7",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/morgan": "^1.9.9",
"@types/node": "^20.12.5",
"@types/node": "^20.14.9",
"cross-env": "^7.0.3",
"eslint-config-custom": "workspace:*",
"jest": "^29.7.0",
"nodemon": "^3.1.0",
"ts-jest": "^29.1.2",
"nodemon": "^3.1.4",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"tsconfig": "workspace:*",
"typescript": "^5.4.4"
"typescript": "5.4.4"
},
"engines": {
"node": "18"
"node": "20.15.0"
},
"optionalDependencies": {
"bufferutil": "^4.0.8",
"utf-8-validate": "^6.0.3"
"utf-8-validate": "^6.0.4"
}
}
4 changes: 2 additions & 2 deletions apps/server/src/handlers/connection.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Server, Socket } from "socket.io";
import type { Server, Socket } from "socket.io";

import { ClientToServerEvents, ServerToClientEvents } from "../types";
import {
checkRoomForUserAndAdd,
findNextHost,
Expand All @@ -10,6 +9,7 @@ import {
} from "../services/room.service";
import { handleSocketError } from "../utils";
import redis from "../redis";
import type { ClientToServerEvents, ServerToClientEvents } from "../types";

export async function checkIfExistingUser(
io: Server<ClientToServerEvents, ServerToClientEvents>,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/handlers/game.handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Server, Socket } from "socket.io";
import type { Server, Socket } from "socket.io";

import {
createGame,
Expand All @@ -7,7 +7,7 @@ import {
} from "../services/game.service";
import { assignQuestionsToPlayers } from "../services/question.service";
import { getRoom } from "../services/room.service";
import { ClientToServerEvents, ServerToClientEvents } from "../types";
import type { ClientToServerEvents, ServerToClientEvents } from "../types";
import { handleSocketError } from "../utils";
import redis from "../redis";

Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/handlers/generation.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Server, Socket } from "socket.io";
import type { Server, Socket } from "socket.io";

import { ClientToServerEvents, ServerToClientEvents } from "../types";
import type { ClientToServerEvents, ServerToClientEvents } from "../types";
import { handleSocketError } from "../utils";
import {
getFaceOffGenerations,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/handlers/room.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Server, Socket } from "socket.io";
import type { Server, Socket } from "socket.io";

import { ClientToServerEvents, ServerToClientEvents } from "../types";
import type { ClientToServerEvents, ServerToClientEvents } from "../types";
import {
findNextHost,
getRoom,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/handlers/vote.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Server, Socket } from "socket.io";
import type { Server, Socket } from "socket.io";

import { ClientToServerEvents, ServerToClientEvents } from "../types";
import type { ClientToServerEvents, ServerToClientEvents } from "../types";
import { handleSocketError } from "../utils";
import { getGameInfo } from "../services/game.service";
import {
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

Sentry.init({
dsn: "https://94861f92f5354fe0ae1a921b9a55d909@o4505598670209024.ingest.sentry.io/4505598751211520",
integrations: [nodeProfilingIntegration()],
tracesSampleRate: process.env.NODE_ENV === "production" ? 0.5 : 1.0,
profilesSampleRate: 1.0,
});
4 changes: 2 additions & 2 deletions apps/server/src/middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Server } from "socket.io";
import { ClientToServerEvents, ServerToClientEvents } from "../types";
import type { Server } from "socket.io";
import { parseCookie } from "../utils";
import { checkUserSession } from "../services/user.service";
import type { ClientToServerEvents, ServerToClientEvents } from "../types";

export function authSocketMiddleware(
io: Server<ClientToServerEvents, ServerToClientEvents>
Expand Down
23 changes: 3 additions & 20 deletions apps/server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./instrument";
import express, {
ErrorRequestHandler,
Express,
Expand All @@ -14,7 +15,7 @@ import * as Sentry from "@sentry/node";

import { userRoutes } from "./routes/user.route";
import { roomRoutes } from "./routes/room.route";
import { ClientToServerEvents, ServerToClientEvents } from "./types";
import type { ClientToServerEvents, ServerToClientEvents } from "./types";
import { gameRoutes } from "./routes/game.route";
import { generationRoutes } from "./routes/generation.route";
import {
Expand All @@ -33,25 +34,7 @@ export function buildServer() {
const app: Express = express();
const server = createServer(app);

Sentry.init({
dsn: "https://94861f92f5354fe0ae1a921b9a55d909@o4505598670209024.ingest.sentry.io/4505598751211520",
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({
tracing: true,
}),
// enable Express.js middleware tracing
new Sentry.Integrations.Express({
app,
}),
],
// Performance Monitoring
tracesSampleRate: process.env.NODE_ENV === "production" ? 0.5 : 1.0,
});

// Express middleware
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(express.json());
app.use(
cors({
Expand Down Expand Up @@ -172,7 +155,7 @@ export function buildServer() {
generationRoutes(app);

// Error handlers
app.use(Sentry.Handlers.errorHandler());
Sentry.setupExpressErrorHandler(app);
const expressErrorHandler: ErrorRequestHandler = (err, req, res, next) => {
if (res.headersSent) {
return next(err);
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/services/generation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
questionsToGames,
users,
} from "database";
import { GameRoundGeneration, QuestionGenerations } from "../types";
import { replicate } from "../replicate";
import type { GameRoundGeneration, QuestionGenerations } from "../types";

export async function getGameRoundGenerations({
gameId,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db, sessions, users } from "database";
import crypto from "crypto";
import { and, eq, gt } from "drizzle-orm";
import { db, sessions, users } from "database";

export async function createUser({ nickname }: { nickname: string }) {
const newUser = await db
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/services/vote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
votes,
questionsToGames,
} from "database";
import { UserVote } from "../types";
import type { UserVote } from "../types";

export async function createVote({
userId,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/tests/generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import crypto from "crypto";
import { describe, expect, test } from "@jest/globals";

import { filterFaceOffGenerationsByQuestionId } from "../services/generation.service";
import { GameRoundGeneration } from "../types";
import type { GameRoundGeneration } from "../types";

describe("filterGameRoundGenerationsByQuestionId", () => {
test("expects the filtered array to not have any generations from other questions", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/tests/question.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from "crypto";
import { User } from "database";
import type { User } from "database";
import { describe, expect, test } from "@jest/globals";

import { prepareQuestionsForGame } from "../services/question.service";
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/tests/room.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from "crypto";
import { User } from "database";
import type { User } from "database";
import { describe, expect, test } from "@jest/globals";

import { findNextHost } from "../services/room.service";
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/tests/vote.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from "crypto";
import { describe, expect, test } from "@jest/globals";
import { Generation } from "database";
import type { Generation } from "database";

import { calculateVotePoints, createVoteMap } from "../services/vote.service";
import { UserVote } from "../types";
Expand Down
Loading

0 comments on commit 20fac69

Please sign in to comment.