perf: tRPC procedures and middleware refactor (#8419)
* trpc procedures an middleware refactor * allow use sessionMiddleware without a req object * sync with the new tRPC structure * tRPC refactor on routing form app * import Prisma from @prisma/client * Lazy load apps from appstore * remove unrelated changes * Add types for PaymentService * type fixes * Merge branch 'main' into roae85/cal-1514-set-the-user-session-only-on-the * fix typo * remove console.log * remove explicit types from apstore object * linter fixes --------- Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
63 files changed
+1818
-1019
No files matched your search
@@ -23,6 +23,7 @@ class MyDocument extends Document<Props> {
|
||||
// If x-csp not set by gSSP, then it's initialPropsOnly
|
||||
setHeader(ctx, "x-csp", "initialPropsOnly");
|
||||
}
|
||||
|
||||
const asPath = ctx.asPath || "";
|
||||
// Use a dummy URL as default so that URL parsing works for relative URLs as well. We care about searchParams and pathname only
|
||||
const parsedUrl = new URL(asPath, "https://dummyurl");
|
||||
|
||||
@@ -4,7 +4,6 @@ import { z } from "zod";
|
||||
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { TRPCError } from "@calcom/trpc/server";
|
||||
import { createContext } from "@calcom/trpc/server/createContext";
|
||||
import { viewerRouter } from "@calcom/trpc/server/routers/viewer/_router";
|
||||
@@ -27,32 +26,18 @@ const decryptedSchema = z.object({
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse<Response>) {
|
||||
const { action, token, reason } = querySchema.parse(req.query);
|
||||
const { bookingUid, userId } = decryptedSchema.parse(
|
||||
const { bookingUid } = decryptedSchema.parse(
|
||||
JSON.parse(symmetricDecrypt(decodeURIComponent(token), process.env.CALENDSO_ENCRYPTION_KEY || ""))
|
||||
);
|
||||
|
||||
/** We shape the session as required by tRPC router */
|
||||
async function sessionGetter() {
|
||||
return {
|
||||
user: {
|
||||
id: userId,
|
||||
username: "" /* Not used in this context */,
|
||||
role: UserPermissionRole.USER,
|
||||
},
|
||||
hasValidLicense: true,
|
||||
expires: "" /* Not used in this context */,
|
||||
};
|
||||
}
|
||||
|
||||
const booking = await prisma.booking.findUniqueOrThrow({
|
||||
where: { uid: bookingUid },
|
||||
});
|
||||
|
||||
try {
|
||||
/** @see https://trpc.io/docs/server-side-calls */
|
||||
const ctx = await createContext({ req, res }, sessionGetter);
|
||||
const ctx = await createContext({ req, res });
|
||||
const caller = viewerRouter.createCaller({ ...ctx, req, res });
|
||||
|
||||
await caller.bookings.confirm({
|
||||
bookingId: booking.id,
|
||||
recurringEventId: booking.recurringEventId || undefined,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
||||
import superjson from "superjson";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { getLocaleFromHeaders } from "@calcom/lib/i18n";
|
||||
import { createProxySSGHelpers } from "@calcom/trpc/react/ssg";
|
||||
import { createContext } from "@calcom/trpc/server/createContext";
|
||||
import { appRouter } from "@calcom/trpc/server/routers/_app";
|
||||
@@ -13,16 +14,14 @@ import { appRouter } from "@calcom/trpc/server/routers/_app";
|
||||
* Make sure to `return { props: { trpcState: ssr.dehydrate() } }` at the end.
|
||||
*/
|
||||
export async function ssrInit(context: GetServerSidePropsContext) {
|
||||
const { req, res } = context;
|
||||
|
||||
const sessionGetter = () => getServerSession({ req, res });
|
||||
|
||||
const ctx = await createContext(context, sessionGetter);
|
||||
const ctx = await createContext(context);
|
||||
const locale = getLocaleFromHeaders(context.req);
|
||||
const i18n = await serverSideTranslations(getLocaleFromHeaders(context.req), ["common", "vital"]);
|
||||
|
||||
const ssr = createProxySSGHelpers({
|
||||
router: appRouter,
|
||||
transformer: superjson,
|
||||
ctx,
|
||||
ctx: { ...ctx, locale, i18n },
|
||||
});
|
||||
|
||||
// always preload "viewer.public.i18n"
|
||||
|
||||
Reference in new issue
Block a user