Scheduling infrastructure for absolutely everyone.
fix: atoms making requests to customers' domains (#20084)
Lauris Skraucisdb52f44293bf
diff --git a/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.ts b/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.tsindex c36db1b615b..0a082cbc35a 100644--- a/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.ts+++ b/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.ts@@ -29,19 +29,12 @@ import {NotFoundException,BadRequestException,} from "@nestjs/common";-import {- ApiOperation as DocsOperation,- ApiCreatedResponse as DocsCreatedResponse,- ApiTags,-} from "@nestjs/swagger";+import { ApiCreatedResponse as DocsCreatedResponse, ApiTags } from "@nestjs/swagger";import { User, MembershipRole } from "@prisma/client";import { SUCCESS_STATUS } from "@calcom/platform-constants";import { CreateOAuthClientInput, UpdateOAuthClientInput, Pagination } from "@calcom/platform-types";-const AUTH_DOCUMENTATION = `⚠️ First, this endpoint requires \`Cookie: next-auth.session-token=eyJhbGciOiJ\` header. Log into Cal web app using owner of organization that was created after visiting \`/settings/organizations/new\`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.-Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.`;-@Controller({path: "/v2/oauth-clients",version: API_VERSIONS_VALUES,@@ -61,7 +54,6 @@ export class OAuthClientsController {@Post("/")@HttpCode(HttpStatus.CREATED)@MembershipRoles([MembershipRole.ADMIN, MembershipRole.OWNER])- @DocsOperation({ description: AUTH_DOCUMENTATION })@DocsCreatedResponse({description: "Create an OAuth client",type: CreateOAuthClientResponseDto,@@ -90,7 +82,6 @@ export class OAuthClientsController {@Get("/")@HttpCode(HttpStatus.OK)@MembershipRoles([MembershipRole.ADMIN, MembershipRole.OWNER, MembershipRole.MEMBER])- @DocsOperation({ description: AUTH_DOCUMENTATION })async getOAuthClients(@GetOrgId() organizationId: number): Promise<GetOAuthClientsResponseDto> {const clients = await this.oAuthClientsService.getOAuthClients(organizationId);return { status: SUCCESS_STATUS, data: clients };@@ -99,7 +90,6 @@ export class OAuthClientsController {@Get("/:clientId")@HttpCode(HttpStatus.OK)@MembershipRoles([MembershipRole.ADMIN, MembershipRole.OWNER, MembershipRole.MEMBER])- @DocsOperation({ description: AUTH_DOCUMENTATION })@UseGuards(OAuthClientGuard)async getOAuthClientById(@Param("clientId") clientId: string): Promise<GetOAuthClientResponseDto> {const client = await this.oAuthClientsService.getOAuthClientById(clientId);@@ -109,7 +99,6 @@ export class OAuthClientsController {@Get("/:clientId/managed-users")@HttpCode(HttpStatus.OK)@MembershipRoles([MembershipRole.ADMIN, MembershipRole.OWNER, MembershipRole.MEMBER])- @DocsOperation({ description: AUTH_DOCUMENTATION })@UseGuards(OAuthClientGuard)async getOAuthClientManagedUsersById(@Param("clientId") clientId: string,@@ -128,7 +117,6 @@ export class OAuthClientsController {@Patch("/:clientId")@HttpCode(HttpStatus.OK)@MembershipRoles([MembershipRole.ADMIN, MembershipRole.OWNER])- @DocsOperation({ description: AUTH_DOCUMENTATION })@UseGuards(OAuthClientGuard)async updateOAuthClient(@Param("clientId") clientId: string,@@ -142,7 +130,6 @@ export class OAuthClientsController {@Delete("/:clientId")@HttpCode(HttpStatus.OK)@MembershipRoles([MembershipRole.ADMIN, MembershipRole.OWNER])- @DocsOperation({ description: AUTH_DOCUMENTATION })@UseGuards(OAuthClientGuard)async deleteOAuthClient(@Param("clientId") clientId: string): Promise<GetOAuthClientResponseDto> {this.logger.log(`Deleting OAuth Client with ID: ${clientId}`);diff --git a/apps/api/v2/swagger/documentation.json b/apps/api/v2/swagger/documentation.jsonindex 16c8cd96726..cbc2fdeab15 100644--- a/apps/api/v2/swagger/documentation.json+++ b/apps/api/v2/swagger/documentation.json@@ -5516,8 +5516,6 @@"/v2/oauth-clients": {"post": {"operationId": "OAuthClientsController_createOAuthClient",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [],"requestBody": {"required": true,@@ -5547,8 +5545,6 @@},"get": {"operationId": "OAuthClientsController_getOAuthClients",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [],"responses": {"200": {@@ -5570,8 +5566,6 @@"/v2/oauth-clients/{clientId}": {"get": {"operationId": "OAuthClientsController_getOAuthClientById",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",@@ -5600,8 +5594,6 @@},"patch": {"operationId": "OAuthClientsController_updateOAuthClient",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",@@ -5640,8 +5632,6 @@},"delete": {"operationId": "OAuthClientsController_deleteOAuthClient",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",@@ -5672,8 +5662,6 @@"/v2/oauth-clients/{clientId}/managed-users": {"get": {"operationId": "OAuthClientsController_getOAuthClientManagedUsersById",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",diff --git a/docs/api-reference/v2/openapi.json b/docs/api-reference/v2/openapi.jsonindex 1dae8168edb..40ff69c6831 100644--- a/docs/api-reference/v2/openapi.json+++ b/docs/api-reference/v2/openapi.json@@ -5204,8 +5204,6 @@"/v2/oauth-clients": {"post": {"operationId": "OAuthClientsController_createOAuthClient",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [],"requestBody": {"required": true,@@ -5233,8 +5231,6 @@},"get": {"operationId": "OAuthClientsController_getOAuthClients",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [],"responses": {"200": {@@ -5254,8 +5250,6 @@"/v2/oauth-clients/{clientId}": {"get": {"operationId": "OAuthClientsController_getOAuthClientById",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",@@ -5282,8 +5276,6 @@},"patch": {"operationId": "OAuthClientsController_updateOAuthClient",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",@@ -5320,8 +5312,6 @@},"delete": {"operationId": "OAuthClientsController_deleteOAuthClient",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",@@ -5350,8 +5340,6 @@"/v2/oauth-clients/{clientId}/managed-users": {"get": {"operationId": "OAuthClientsController_getOAuthClientManagedUsersById",- "summary": "",- "description": "⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard.\nSecond, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard.","parameters": [{"name": "clientId",diff --git a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx b/packages/platform/atoms/booker/BookerPlatformWrapper.tsxindex c928667f3a9..8ddb3b3f42e 100644--- a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx+++ b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx@@ -501,7 +501,7 @@ export const BookerPlatformWrapper = (}}rescheduleUid={props.rescheduleUid ?? null}- rescheduledBy={props.rescheduledBy}+ rescheduledBy={props.rescheduledBy ?? null}bookingUid={props.bookingUid ?? null}isRedirect={false}fromUserNameRedirected=""diff --git a/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts b/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.tsindex a27f1ca846d..ca7e8e4b165 100644--- a/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts+++ b/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts@@ -32,7 +32,7 @@ import {EventTypeMetaDataSchema,} from "@calcom/prisma/zod-utils";-import type { BookerPlatformWrapperAtomProps } from "../../booker/BookerPlatformWrapper";+import type { BookerPlatformWrapperAtomProps } from "../../booker/types";export function transformApiEventTypeForAtom(eventType: Omit<EventTypeOutput_2024_06_14, "ownerId"> & { bannerUrl?: string },diff --git a/packages/platform/atoms/event-types/hooks/useSchedule.ts b/packages/platform/atoms/event-types/hooks/useSchedule.tsdeleted file mode 100644index 32aa492ddbc..00000000000--- a/packages/platform/atoms/event-types/hooks/useSchedule.ts+++ /dev/null@@ -1,36 +0,0 @@-import { useQuery } from "@tanstack/react-query";--import {- V2_ENDPOINTS,- SUCCESS_STATUS,- VERSION_2024_06_11,- CAL_API_VERSION_HEADER,-} from "@calcom/platform-constants";-import type { GetScheduleOutput_2024_06_11 } from "@calcom/platform-types";--import http from "../../lib/http";--export const QUERY_KEY = "event-type-user-schedule";--export const useSchedule = (id?: number) => {- const pathname = id ? `/${V2_ENDPOINTS.availability}/${id}` : `/${V2_ENDPOINTS.availability}/default`;-- const { isLoading, error, data } = useQuery({- queryKey: [QUERY_KEY, id],- queryFn: () => {- return http- .get<GetScheduleOutput_2024_06_11>(pathname, {- headers: { [CAL_API_VERSION_HEADER]: VERSION_2024_06_11 },- })- .then((res) => {- if (res.data.status === SUCCESS_STATUS) {- return res.data.data;- }- throw new Error(res.data.error?.message);- });- },- enabled: !!id,- });-- return { isLoading, error, data };-};diff --git a/packages/platform/atoms/event-types/hooks/useSchedules.ts b/packages/platform/atoms/event-types/hooks/useSchedules.tsdeleted file mode 100644index 665179fec3e..00000000000--- a/packages/platform/atoms/event-types/hooks/useSchedules.ts+++ /dev/null@@ -1,35 +0,0 @@-import { useQuery } from "@tanstack/react-query";--import {- V2_ENDPOINTS,- SUCCESS_STATUS,- VERSION_2024_06_11,- CAL_API_VERSION_HEADER,-} from "@calcom/platform-constants";-import type { GetSchedulesOutput_2024_06_11 } from "@calcom/platform-types";--import http from "../../lib/http";--export const QUERY_KEY = "event-type-user-schedules";--export const useSchedules = () => {- const pathname = `/${V2_ENDPOINTS.availability}`;-- const { isLoading, error, data } = useQuery({- queryKey: [QUERY_KEY],- queryFn: () => {- return http- .get<GetSchedulesOutput_2024_06_11>(pathname, {- headers: { [CAL_API_VERSION_HEADER]: VERSION_2024_06_11 },- })- .then((res) => {- if (res.data.status === SUCCESS_STATUS) {- return res.data.data;- }- throw new Error(res.data.error?.message);- });- },- });-- return { isLoading, error, data };-};diff --git a/packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx b/packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsxindex 8202dc05481..aa9bc5c9cfa 100644--- a/packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx+++ b/packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx@@ -7,10 +7,10 @@ import type { User } from "@calcom/prisma/client";import type { Availability } from "../../availability/AvailabilitySettings";import { transformApiScheduleForAtom } from "../../availability/atom-api-transformers/transformApiScheduleForAtom";+import { useSchedule } from "../../hooks/schedules/useSchedule";+import { useSchedules } from "../../hooks/schedules/useSchedules";import { useTeamMembers } from "../../hooks/teams/useTeamMembers";import { useAtomHostSchedules } from "../hooks/useAtomHostSchedules";-import { useSchedule } from "../hooks/useSchedule";-import { useSchedules } from "../hooks/useSchedules";type EventAvailabilityTabPlatformWrapperProps = {user?: Pick<User, "id" | "defaultScheduleId" | "timeZone" | "timeFormat" | "weekStart">;diff --git a/packages/platform/atoms/hooks/schedules/useSchedule.ts b/packages/platform/atoms/hooks/schedules/useSchedule.tsindex 21f553c8f61..48670a86530 100644--- a/packages/platform/atoms/hooks/schedules/useSchedule.ts+++ b/packages/platform/atoms/hooks/schedules/useSchedule.ts@@ -1,25 +1,38 @@import { useQuery } from "@tanstack/react-query";-import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import {+ V2_ENDPOINTS,+ SUCCESS_STATUS,+ VERSION_2024_06_11,+ CAL_API_VERSION_HEADER,+} from "@calcom/platform-constants";import type { GetScheduleOutput_2024_06_11 } from "@calcom/platform-types";import http from "../../lib/http";+import { useAtomsContext } from "../useAtomsContext";export const QUERY_KEY = "user-schedule";-export const useSchedule = (id?: string) => {+export const useSchedule = (id?: number | string) => {+ const { isInit } = useAtomsContext();+const pathname = id ? `/${V2_ENDPOINTS.availability}/${id}` : `/${V2_ENDPOINTS.availability}/default`;const { isLoading, error, data } = useQuery({- queryKey: [QUERY_KEY, id],+ queryKey: [QUERY_KEY, `${id}`],queryFn: () => {- return http.get<GetScheduleOutput_2024_06_11>(pathname).then((res) => {- if (res.data.status === SUCCESS_STATUS) {- return res.data.data;- }- throw new Error(res.data.error?.message);- });+ return http+ .get<GetScheduleOutput_2024_06_11>(pathname, {+ headers: { [CAL_API_VERSION_HEADER]: VERSION_2024_06_11 },+ })+ .then((res) => {+ if (res.data.status === SUCCESS_STATUS) {+ return res.data.data;+ }+ throw new Error(res.data.error?.message);+ });},+ enabled: isInit,});return { isLoading, error, data };diff --git a/packages/platform/atoms/hooks/schedules/useSchedules.ts b/packages/platform/atoms/hooks/schedules/useSchedules.tsindex 20c61cadd97..5ed16d638f8 100644--- a/packages/platform/atoms/hooks/schedules/useSchedules.ts+++ b/packages/platform/atoms/hooks/schedules/useSchedules.ts@@ -1,25 +1,38 @@import { useQuery } from "@tanstack/react-query";-import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import {+ V2_ENDPOINTS,+ SUCCESS_STATUS,+ VERSION_2024_06_11,+ CAL_API_VERSION_HEADER,+} from "@calcom/platform-constants";import type { GetSchedulesOutput_2024_06_11 } from "@calcom/platform-types";import http from "../../lib/http";+import { useAtomsContext } from "../useAtomsContext";export const QUERY_KEY = "user-schedules";export const useSchedules = () => {+ const { isInit } = useAtomsContext();+const pathname = `/${V2_ENDPOINTS.availability}`;const { isLoading, error, data } = useQuery({queryKey: [QUERY_KEY],queryFn: () => {- return http.get<GetSchedulesOutput_2024_06_11>(pathname).then((res) => {- if (res.data.status === SUCCESS_STATUS) {- return res.data.data;- }- throw new Error(res.data.error?.message);- });+ return http+ .get<GetSchedulesOutput_2024_06_11>(pathname, {+ headers: { [CAL_API_VERSION_HEADER]: VERSION_2024_06_11 },+ })+ .then((res) => {+ if (res.data.status === SUCCESS_STATUS) {+ return res.data.data;+ }+ throw new Error(res.data.error?.message);+ });},+ enabled: isInit,});return { isLoading, error, data };diff --git a/packages/platform/atoms/hooks/useAvailableSlots.ts b/packages/platform/atoms/hooks/useAvailableSlots.tsindex 93065aee97d..158dac96fc8 100644--- a/packages/platform/atoms/hooks/useAvailableSlots.ts+++ b/packages/platform/atoms/hooks/useAvailableSlots.ts@@ -2,7 +2,11 @@ import { useQuery } from "@tanstack/react-query";import { SUCCESS_STATUS } from "@calcom/platform-constants";import type { AvailableSlotsType } from "@calcom/platform-libraries";-import type { GetAvailableSlotsInput, ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";+import type {+ GetAvailableSlotsInput_2024_04_15,+ ApiResponse,+ ApiSuccessResponse,+} from "@calcom/platform-types";import http from "../lib/http";@@ -11,7 +15,7 @@ export const QUERY_KEY = "get-available-slots";export const useAvailableSlots = ({enabled,...rest-}: GetAvailableSlotsInput & { enabled: boolean; isTeamEvent?: boolean; teamId?: number }) => {+}: GetAvailableSlotsInput_2024_04_15 & { enabled: boolean; isTeamEvent?: boolean; teamId?: number }) => {const availableSlots = useQuery({queryKey: [QUERY_KEY,diff --git a/packages/platform/atoms/hooks/useConnectedCalendars.tsx b/packages/platform/atoms/hooks/useConnectedCalendars.tsxindex 40902cbd9d1..2b95ee411bf 100644--- a/packages/platform/atoms/hooks/useConnectedCalendars.tsx+++ b/packages/platform/atoms/hooks/useConnectedCalendars.tsx@@ -5,9 +5,12 @@ import type { ConnectedDestinationCalendars } from "@calcom/platform-libraries";import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";import http from "../lib/http";+import { useAtomsContext } from "./useAtomsContext";export const QUERY_KEY = "get-connected-calendars";export const useConnectedCalendars = (props: { enabled?: boolean }) => {+ const { isInit } = useAtomsContext();+const calendars = useQuery({queryKey: [QUERY_KEY],queryFn: () => {@@ -18,7 +21,7 @@ export const useConnectedCalendars = (props: { enabled?: boolean }) => {throw new Error(res.data.error.message);});},- enabled: props?.enabled ?? true,+ enabled: props?.enabled !== undefined ? props.enabled && isInit : isInit,});return calendars;