feat: Upgrade to Next 15 (#18834)

* wip

* update layoutHOC

* wip

* remove app router related code no longer used

* remove more

* await cookies, headers, params, serachparams

* update yarn.lock

* await cookies, headers, params, serachparams more

* update yarn lock again

* downgrade next-auth to 4.22.1

* update yarn lock

* fix

* update yarn lock

* fix type checks

* update yarn lock

* await headers and cookies

* restore pages folder

* restore yarn.lock

* update yarn.lock

* await headers and cookies

* remove

* await params in API routes

* updates

* restore next.config.js

* remove i18n from next.config.js

* Fixed tests

* Fixed types

* Removed duplicate favicon.ico

* Fixing more types

* ImageResponse moved to next/og

* Fixed prisma import issues

* dynamic import for @ewsjs/xhr

* remove deasync dep

* dynamic import for @tryvital/vital-node

* fix type checks

* add back turbopack command

* Type fix

* Removed unneeded file

* fix turbopack relative path errors

* add comments

* remove unneeded code

* Fixed build errors

* await apis

* use Promise<Params> type in defaultResponderForAppDir util

* refactor scim api route

* fix type checks

* separate app-routing.config into client-config and server-config

* wip

* refactor routing forms components

* revert unneeded changes for easier review

* fix

* fix

* use CustomTrans

* fix type

* fix unit tests

* fix type error

* fix build error

* fix build error

* fix build error

* fix warnings

* fix warnings

* upgrade @tremor/react and tailwindcss

* numCols -> numItems

* fix forgot-password e2e test

* fix 1 more e2e test

* fix login e2e test

* fix e2e tests

* fix e2e tests

* clean up

* remove error

* use tremor/react 2.11.0

* fix

* rename CustomTrans to ServerTrans

* address comment

* fix test

* fix ServerTrans

* fix

* fix type

* fix ServerTrans usages 1

* fix translations

* fix type checks

* fix type checks

* link styling

* fix

---------

Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-03-20 21:30:51 -03:00
1 parent 695a4d7a59
commit 8ad442f2be
263 files changed
+2002 -1663

No files matched your search

@@ -16,7 +16,7 @@ import { buildLegacyRequest } from "@lib/buildLegacyCtx";
async function handler(req: NextRequest) {
const body = await parseRequestData(req);
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
if (!session) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
@@ -14,7 +14,7 @@ import { buildLegacyRequest } from "@lib/buildLegacyCtx";
async function postHandler(req: NextRequest) {
const body = await parseRequestData(req);
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
if (!session) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
@@ -18,7 +18,7 @@ import { buildLegacyRequest } from "@lib/buildLegacyCtx";
async function postHandler(req: NextRequest) {
const body = await parseRequestData(req);
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
if (!session) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
@@ -23,7 +23,7 @@ const selectedCalendarSelectSchema = z.object({
});
async function authMiddleware() {
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
if (!session?.user?.id) {
throw new HttpError({ statusCode: 401, message: "Not authenticated" });
+2 -2
View File
@@ -26,8 +26,8 @@ const handleValidationError = (error: z.ZodError): NextResponse => {
);
};
async function handler(req: NextRequest, { params }: { params: Params }) {
const result = querySchema.safeParse(params);
async function handler(req: NextRequest, { params }: { params: Promise<Params> }) {
const result = querySchema.safeParse(await params);
if (!result.success) {
return handleValidationError(result.error);
}
+1 -1
View File
@@ -15,7 +15,7 @@ async function handler(req: NextRequest) {
} catch (error) {
return NextResponse.json({ success: false, message: "Invalid JSON" }, { status: 400 });
}
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
const result = await handleCancelBooking({
appDirRequestBody,
userId: session?.user?.id || -1,
+1 -1
View File
@@ -457,7 +457,7 @@ const inputSchema = z.object({
});
async function handler(request: NextRequest) {
const headersList = headers();
const headersList = await headers();
const requestBody = await request.json();
// HMAC verification
@@ -1,3 +1,4 @@
import type { Params } from "app/_types";
import { NextResponse, type NextRequest } from "next/server";
import { describe, expect, it, vi } from "vitest";
@@ -21,7 +22,7 @@ describe("defaultResponderForAppDir", () => {
it("should return a JSON response when handler resolves with a result", async () => {
const f = vi.fn().mockResolvedValue(NextResponse.json({ success: true }));
const req = { method: "GET", url: "/api/test" } as unknown as NextRequest;
const params = {};
const params = Promise.resolve<Params>({})
const response = await defaultResponderForAppDir(f)(req, { params });
const json = await response.json();
@@ -33,7 +34,7 @@ describe("defaultResponderForAppDir", () => {
it("should return an empty JSON response when handler resolves with no result", async () => {
const f = vi.fn().mockResolvedValue(null);
const req = { method: "GET", url: "/api/test" } as unknown as NextRequest;
const params = {};
const params = Promise.resolve<Params>({})
const response = await defaultResponderForAppDir(f)(req, { params });
const json = await response.json();
@@ -45,7 +46,7 @@ describe("defaultResponderForAppDir", () => {
it("should respond with status code 409 for NoAvailableUsersFound", async () => {
const f = vi.fn().mockRejectedValue(new Error(ErrorCode.NoAvailableUsersFound));
const req = { method: "GET", url: "/api/test" } as unknown as NextRequest;
const params = {};
const params = Promise.resolve<Params>({})
const response = await defaultResponderForAppDir(f)(req, { params });
const json = await response.json();
@@ -61,7 +62,7 @@ describe("defaultResponderForAppDir", () => {
it("should respond with a 429 status code for rate limit errors", async () => {
const f = vi.fn().mockRejectedValue(new TRPCError({ code: "TOO_MANY_REQUESTS" }));
const req = { method: "POST", url: "/api/test" } as unknown as NextRequest;
const params = {};
const params = Promise.resolve<Params>({})
const response = await defaultResponderForAppDir(f)(req, { params });
const json = await response.json();
@@ -9,14 +9,14 @@ import { performance } from "@calcom/lib/server/perfObserver";
type Handler<T extends NextResponse | Response = NextResponse> = (
req: NextRequest,
{ params }: { params: Params }
{ params }: { params: Promise<Params> }
) => Promise<T>;
export const defaultResponderForAppDir = <T extends NextResponse | Response = NextResponse>(
handler: Handler<T>,
endpointRoute?: string
) => {
return async (req: NextRequest, { params }: { params: Params }) => {
return async (req: NextRequest, { params }: { params: Promise<Params> }) => {
let ok = false;
try {
performance.mark("Start");
-40
View File
@@ -1,40 +0,0 @@
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
import { cookies, headers } from "next/headers";
import { NextResponse } from "next/server";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { FUTURE_ROUTES_OVERRIDE_COOKIE_NAME as COOKIE_NAME } from "@calcom/lib/constants";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
async function getHandler() {
const headersList = headers();
const cookiesList = cookies();
const legacyReq = buildLegacyRequest(headersList, cookiesList);
const session = await getServerSession({ req: legacyReq });
if (!session || !session.user || !session.user.email) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
}
let redirectUrl = "/";
// We take you back where you came from if possible
const referer = headersList.get("referer");
if (referer) redirectUrl = referer;
const response = NextResponse.redirect(redirectUrl);
// If has the cookie, Opt-out of V2
if (cookiesList.has(COOKIE_NAME) && cookiesList.get(COOKIE_NAME)?.value === "1") {
response.cookies.set(COOKIE_NAME, "0", { maxAge: 0, path: "/" });
} else {
/* Opt-in to V2 */
response.cookies.set(COOKIE_NAME, "1", { path: "/" });
}
return response;
}
export const GET = defaultResponderForAppDir(getHandler);
@@ -9,8 +9,8 @@ import prisma from "@calcom/prisma";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
async function postHandler() {
const headersList = headers();
const cookiesList = cookies();
const headersList = await headers();
const cookiesList = await cookies();
const legacyReq = buildLegacyRequest(headersList, cookiesList);
const session = await getServerSession({ req: legacyReq });
+1 -1
View File
@@ -3,7 +3,7 @@ import { headers } from "next/headers";
import { NextResponse } from "next/server";
async function getHandler() {
const headersList = headers();
const headersList = await headers();
const country = headersList.get("x-vercel-ip-country") || "Unknown";
const response = NextResponse.json({ country });
+2 -2
View File
@@ -8,8 +8,8 @@ import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
async function getHandler() {
const headersList = headers();
const cookiesList = cookies();
const headersList = await headers();
const cookiesList = await cookies();
const legacyReq = buildLegacyRequest(headersList, cookiesList);
const session = await getServerSession({ req: legacyReq });
+1 -1
View File
@@ -79,7 +79,7 @@ async function handler(request: NextRequest) {
try {
/** @see https://trpc.io/docs/server-side-calls */
// Create a legacy request object for compatibility
const legacyReq = buildLegacyRequest(headers(), cookies());
const legacyReq = buildLegacyRequest(await headers(), await cookies());
const res = {} as any; // Response is still mocked as it's not used in this context
const ctx = await createContext({ req: legacyReq, res }, sessionGetter);
+1 -1
View File
@@ -168,7 +168,7 @@ async function getHandler(request: NextRequest) {
const parsedQuery = logoApiSchema.parse(Object.fromEntries(searchParams.entries()));
// Create a legacy request object for compatibility
const legacyReq = buildLegacyRequest(headers(), cookies());
const legacyReq = buildLegacyRequest(await headers(), await cookies());
const { isValidOrgDomain } = orgDomainConfig(legacyReq);
const hostname = request.headers.get("host");
+1 -1
View File
@@ -15,7 +15,7 @@ async function getHandler() {
const preSessionDate = performance.now();
// Create a legacy request object for compatibility
const legacyReq = buildLegacyRequest(headers(), cookies());
const legacyReq = buildLegacyRequest(await headers(), await cookies());
const session = await getServerSession({ req: legacyReq });
if (!session) {
+1 -1
View File
@@ -26,7 +26,7 @@ async function handler() {
return NextResponse.json({ error: "Plain Chat is not enabled" }, { status: 404 });
}
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
if (!session?.user?.email) {
return NextResponse.json({ error: "Unauthorized - No session email found" }, { status: 401 });
}
@@ -62,7 +62,7 @@ export async function postHandler(request: NextRequest) {
return NextResponse.json({ message: "Test request successful" });
}
const headersList = headers();
const headersList = await headers();
const testMode = process.env.NEXT_PUBLIC_IS_E2E || process.env.INTEGRATION_TEST_MODE;
if (!testMode) {
@@ -1,7 +1,9 @@
import type { DirectorySyncEvent, DirectorySyncRequest } from "@boxyhq/saml-jackson";
import type { Params } from "app/_types";
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { z } from "zod";
import handleGroupEvents from "@calcom/features/ee/dsync/lib/handleGroupEvents";
import handleUserEvents from "@calcom/features/ee/dsync/lib/handleUserEvents";
@@ -51,35 +53,40 @@ const handleEvents = async (event: DirectorySyncEvent) => {
}
};
const querySchema = z.object({
directory: z.string().array(),
});
// This is the handler for the SCIM API requests
async function getHandler(request: NextRequest, { params }: { params: { directory?: string[] } }) {
return handleScimRequest(request, "GET", params.directory);
async function getHandler(request: NextRequest, { params }: { params: Promise<Params> }) {
return handleScimRequest(request, "GET", params);
}
async function postHandler(request: NextRequest, { params }: { params: { directory?: string[] } }) {
return handleScimRequest(request, "POST", params.directory);
async function postHandler(request: NextRequest, { params }: { params: Promise<Params> }) {
return handleScimRequest(request, "POST", params);
}
async function putHandler(request: NextRequest, { params }: { params: { directory?: string[] } }) {
return handleScimRequest(request, "PUT", params.directory);
async function putHandler(request: NextRequest, { params }: { params: Promise<Params> }) {
return handleScimRequest(request, "PUT", params);
}
async function patchHandler(request: NextRequest, { params }: { params: { directory?: string[] } }) {
return handleScimRequest(request, "PATCH", params.directory);
async function patchHandler(request: NextRequest, { params }: { params: Promise<Params> }) {
return handleScimRequest(request, "PATCH", params);
}
async function deleteHandler(request: NextRequest, { params }: { params: { directory?: string[] } }) {
return handleScimRequest(request, "DELETE", params.directory);
async function deleteHandler(request: NextRequest, { params }: { params: Promise<Params> }) {
return handleScimRequest(request, "DELETE", params);
}
async function handleScimRequest(request: NextRequest, method: string, directoryParams?: string[]) {
const { dsyncController } = await jackson();
if (!directoryParams || directoryParams.length === 0) {
async function handleScimRequest(request: NextRequest, method: string, params: Promise<Params>) {
const parsed = querySchema.safeParse(await params);
if (!parsed.success || parsed.data.directory.length === 0) {
return NextResponse.json({ error: "Missing directory parameters" }, { status: 400 });
}
const [directoryId, path, resourceId] = directoryParams;
const { dsyncController } = await jackson();
const [directoryId, path, resourceId] = parsed.data.directory;
const shouldLog = DIRECTORY_IDS_TO_LOG.includes(directoryId);
const searchParams = request.nextUrl.searchParams;
@@ -90,7 +97,7 @@ async function handleScimRequest(request: NextRequest, method: string, directory
safeStringify({
method,
url: request.url,
params: directoryParams,
params: parsed.data.directory,
searchParams: Object.fromEntries(searchParams.entries()),
body: request.body
? await request
+4 -12
View File
@@ -1,19 +1,11 @@
import { ImageResponse } from "next/og";
import type { NextRequest } from "next/server";
import { ImageResponse } from "next/server";
import type { SatoriOptions } from "satori";
import { z } from "zod";
import { Meeting, App, Generic } from "@calcom/lib/OgImages";
import { WEBAPP_URL } from "@calcom/lib/constants";
const calFont = fetch(new URL("/fonts/cal.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer());
const interFont = fetch(new URL("/fonts/Inter-Regular.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer());
const interFontMedium = fetch(new URL("/fonts/Inter-Medium.ttf", WEBAPP_URL)).then((res) =>
res.arrayBuffer()
);
export const runtime = "edge";
const meetingSchema = z.object({
@@ -43,9 +35,9 @@ async function handler(req: NextRequest) {
const imageType = searchParams.get("type");
const [calFontData, interFontData, interFontMediumData] = await Promise.all([
calFont,
interFont,
interFontMedium,
fetch(new URL("/fonts/cal.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer()),
fetch(new URL("/fonts/Inter-Regular.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer()),
fetch(new URL("/fonts/Inter-Medium.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer()),
]);
const ogConfig = {
width: 1200,
+1 -1
View File
@@ -29,7 +29,7 @@ async function postHandler(request: NextRequest) {
if (!process.env.CALENDSO_ENCRYPTION_KEY)
return NextResponse.json({ message: "Missing encryption key" }, { status: 500 });
const legacyRequest = buildLegacyRequest(headers(), cookies());
const legacyRequest = buildLegacyRequest(await headers(), await cookies());
// Get the raw request body
const rawBody = await getRawBody(legacyRequest);
@@ -21,11 +21,11 @@ const querySchema = z.object({
session_id: z.string().min(1),
});
async function getHandler(req: NextRequest, { params }: { params: Params }) {
async function getHandler(req: NextRequest, { params }: { params: Promise<Params> }) {
try {
const searchParams = req.nextUrl.searchParams;
const { team: id, session_id } = querySchema.parse({
team: params.team,
team: (await params).team,
session_id: searchParams.get("session_id"),
});
@@ -86,7 +86,7 @@ async function getHandler(req: NextRequest, { params }: { params: Params }) {
}
}
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
if (!session) {
return NextResponse.json({ message: "Team upgraded successfully" });
@@ -20,8 +20,8 @@ const stateSchema = z.object({
async function getHandler(request: NextRequest) {
try {
const headersList = headers();
const cookiesList = cookies();
const headersList = await headers();
const cookiesList = await cookies();
const legacyReq = buildLegacyRequest(headersList, cookiesList);
const session = await getServerSession({ req: legacyReq });
+1 -1
View File
@@ -19,7 +19,7 @@ async function postHandler(request: NextRequest) {
const body = await request.json();
const { username, orgSlug } = bodySchema.parse(body);
const legacyReq = buildLegacyRequest(headers(), cookies());
const legacyReq = buildLegacyRequest(await headers(), await cookies());
// Get current org domain from request headers
const { currentOrgDomain } = orgDomainConfig(legacyReq);
@@ -118,7 +118,7 @@ async function handleBookingAction(
const createCaller = createCallerFactory(bookingsRouter);
// Use buildLegacyRequest to create a request object compatible with Pages Router
const legacyReq = request ? buildLegacyRequest(headers(), cookies()) : ({} as any);
const legacyReq = request ? buildLegacyRequest(await headers(), await cookies()) : ({} as any);
const res = {} as any;
const ctx = await createContext({ req: legacyReq, res }, sessionGetter);