Scheduling infrastructure for absolutely everyone.
refactor: migrate `verifyCodeUnAuthenticated` from TRPC layer to features layer (#25639)
Benny Joobecae27b457e
diff --git a/packages/trpc/server/routers/viewer/auth/util.ts b/packages/features/auth/lib/verifyCodeUnAuthenticated.tssimilarity index 100%rename from packages/trpc/server/routers/viewer/auth/util.tsrename to packages/features/auth/lib/verifyCodeUnAuthenticated.tsdiff --git a/packages/features/bookings/lib/handleNewBooking/checkIfBookerEmailIsBlocked.ts b/packages/features/bookings/lib/handleNewBooking/checkIfBookerEmailIsBlocked.tsindex 1e019f66155..689be8d2d1e 100644--- a/packages/features/bookings/lib/handleNewBooking/checkIfBookerEmailIsBlocked.ts+++ b/packages/features/bookings/lib/handleNewBooking/checkIfBookerEmailIsBlocked.ts@@ -1,8 +1,8 @@+import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";import { ErrorCode } from "@calcom/lib/errorCodes";import { ErrorWithCode } from "@calcom/lib/errors";import { extractBaseEmail } from "@calcom/lib/extract-base-email";import prisma from "@calcom/prisma";-import { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";export const checkIfBookerEmailIsBlocked = async ({bookerEmail,diff --git a/packages/features/bookings/lib/handleNewBooking/test/booking-validations.test.ts b/packages/features/bookings/lib/handleNewBooking/test/booking-validations.test.tsindex 5a1962dac9b..79e9ea06cfc 100644--- a/packages/features/bookings/lib/handleNewBooking/test/booking-validations.test.ts+++ b/packages/features/bookings/lib/handleNewBooking/test/booking-validations.test.ts@@ -24,7 +24,7 @@ import { test } from "@calcom/web/test/fixtures/fixtures";import { getNewBookingHandler } from "./getNewBookingHandler";-vi.mock("@calcom/trpc/server/routers/viewer/auth/util", () => ({+vi.mock("@calcom/features/auth/lib/verifyCodeUnAuthenticated", () => ({verifyCodeUnAuthenticated: vi.fn(),}));@@ -554,7 +554,9 @@ describe("Booking Validation Specifications", () => {test("should create booking when main booker provides valid verification code", async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(true);@@ -1067,7 +1069,9 @@ describe("Booking Validation Specifications", () => {test("should throw error when invalid verification code is provided", async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(false);diff --git a/packages/features/bookings/lib/handleNewBooking/test/email-verification-booking.test.ts b/packages/features/bookings/lib/handleNewBooking/test/email-verification-booking.test.tsindex 1925ec45a1b..46b6f0e60bd 100644--- a/packages/features/bookings/lib/handleNewBooking/test/email-verification-booking.test.ts+++ b/packages/features/bookings/lib/handleNewBooking/test/email-verification-booking.test.ts@@ -21,7 +21,7 @@ import { test } from "@calcom/web/test/fixtures/fixtures";import { getNewBookingHandler } from "./getNewBookingHandler";-vi.mock("@calcom/trpc/server/routers/viewer/auth/util", () => ({+vi.mock("@calcom/features/auth/lib/verifyCodeUnAuthenticated", () => ({verifyCodeUnAuthenticated: vi.fn(),}));@@ -39,7 +39,9 @@ describe("handleNewBooking - Email Verification", () => {"should throw error when email verification is required but no verification code is provided",async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );const booker = getBooker({email: "[email protected]",@@ -99,7 +101,9 @@ describe("handleNewBooking - Email Verification", () => {"should throw error when email verification is required and verification code is invalid",async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );vi.mocked(verifyCodeUnAuthenticated).mockRejectedValue(new Error("Invalid verification code"));@@ -162,7 +166,9 @@ describe("handleNewBooking - Email Verification", () => {"should successfully create booking when email verification is required and valid verification code is provided",async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(undefined);@@ -223,7 +229,9 @@ describe("handleNewBooking - Email Verification", () => {"should handle rate limiting error from verification service",async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );const rateLimitError = new Error("Rate limit exceeded");rateLimitError.name = "RateLimitError";@@ -288,7 +296,9 @@ describe("handleNewBooking - Email Verification", () => {"should proceed normally when email verification is not required",async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );const booker = getBooker({email: "[email protected]",@@ -346,7 +356,9 @@ describe("handleNewBooking - Email Verification", () => {"should allow rescheduling without email verification even when requiresBookerEmailVerification is true",async () => {const handleNewBooking = getNewBookingHandler();- const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");+ const { verifyCodeUnAuthenticated } = await import(+ "@calcom/features/auth/lib/verifyCodeUnAuthenticated"+ );const booker = getBooker({email: "[email protected]",diff --git a/packages/features/bookings/lib/service/RegularBookingService.ts b/packages/features/bookings/lib/service/RegularBookingService.tsindex 9b1de598fbc..01c3cce1ac0 100644--- a/packages/features/bookings/lib/service/RegularBookingService.ts+++ b/packages/features/bookings/lib/service/RegularBookingService.ts@@ -22,6 +22,7 @@ import dayjs from "@calcom/dayjs";import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";import getICalUID from "@calcom/emails/lib/getICalUID";import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";+import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";import EventManager, { placeholderCreatedEvent } from "@calcom/features/bookings/lib/EventManager";import type { BookingDataSchemaGetter } from "@calcom/features/bookings/lib/dto/types";import type {@@ -85,7 +86,6 @@ import {CreationSource,} from "@calcom/prisma/enums";import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";-import { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";import type {AdditionalInformation,diff --git a/packages/platform/libraries/index.ts b/packages/platform/libraries/index.tsindex 1f7fa378d20..37ac05ec700 100644--- a/packages/platform/libraries/index.ts+++ b/packages/platform/libraries/index.ts@@ -119,7 +119,7 @@ export { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";export { verifyPhoneNumber, sendVerificationCode };-export { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";+export { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";export { verifyCode as verifyCodeAuthenticated } from "@calcom/trpc/server/routers/viewer/organizations/verifyCode.handler";diff --git a/packages/trpc/server/routers/viewer/auth/verifyCodeUnAuthenticated.handler.ts b/packages/trpc/server/routers/viewer/auth/verifyCodeUnAuthenticated.handler.tsindex 72bc0e82faa..d41c679e7bc 100644--- a/packages/trpc/server/routers/viewer/auth/verifyCodeUnAuthenticated.handler.ts+++ b/packages/trpc/server/routers/viewer/auth/verifyCodeUnAuthenticated.handler.ts@@ -1,9 +1,8 @@+import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";import type { ZVerifyCodeInputSchema } from "@calcom/prisma/zod-utils";import { TRPCError } from "@trpc/server";-import { verifyCodeUnAuthenticated } from "./util";-type VerifyTokenOptions = {input: ZVerifyCodeInputSchema;};