refactor: Uses withReporting to force named functions for tracing (#21219)
This commit is contained in:
1 parent
79d695236f
commit
b3d3cb1dee
35 files changed
+853
-393
No files matched your search
+7
-3
@@ -2,6 +2,7 @@ import async from "async";
|
||||
|
||||
import { isDelegationCredential } from "@calcom/lib/delegationCredential/clientAndServer";
|
||||
import { buildAllCredentials } from "@calcom/lib/delegationCredential/server";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
|
||||
import { refreshCredential } from "./refreshCredential";
|
||||
@@ -11,9 +12,10 @@ import { refreshCredential } from "./refreshCredential";
|
||||
*
|
||||
* @param credentials
|
||||
*/
|
||||
export async function refreshCredentials(
|
||||
// Define the function with underscore prefix
|
||||
const _refreshCredentials = async (
|
||||
credentials: Array<CredentialForCalendarService>
|
||||
): Promise<Array<CredentialForCalendarService>> {
|
||||
): Promise<Array<CredentialForCalendarService>> => {
|
||||
const nonDelegationCredentials = credentials.filter(
|
||||
(cred) => !isDelegationCredential({ credentialId: cred.id })
|
||||
);
|
||||
@@ -22,4 +24,6 @@ export async function refreshCredentials(
|
||||
);
|
||||
const refreshedDbCredentials = await async.mapLimit(nonDelegationCredentials, 5, refreshCredential);
|
||||
return buildAllCredentials({ delegationCredentials, existingCredentials: refreshedDbCredentials });
|
||||
}
|
||||
};
|
||||
|
||||
export const refreshCredentials = withReporting(_refreshCredentials, "refreshCredentials");
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
} from "@calcom/emails";
|
||||
import getICalUID from "@calcom/emails/lib/getICalUID";
|
||||
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
||||
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
||||
import { getShouldServeCache } from "@calcom/features/calendar-cache/lib/getShouldServeCache";
|
||||
@@ -46,7 +45,7 @@ import {
|
||||
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
||||
import EventManager from "@calcom/lib/EventManager";
|
||||
import { shouldIgnoreContactOwner } from "@calcom/lib/bookings/routing/utils";
|
||||
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import {
|
||||
enrichHostsWithDelegationCredentials,
|
||||
getFirstDelegationConferencingCredentialAppLocation,
|
||||
@@ -64,7 +63,6 @@ import logger from "@calcom/lib/logger";
|
||||
import { handlePayment } from "@calcom/lib/payment/handlePayment";
|
||||
import { getPiiFreeCalendarEvent, getPiiFreeEventType } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import monitorCallbackAsync from "@calcom/lib/sentryWrapper";
|
||||
import { getLuckyUser } from "@calcom/lib/server/getLuckyUser";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
@@ -94,7 +92,7 @@ import type { Booking } from "./handleNewBooking/createBooking";
|
||||
import { ensureAvailableUsers } from "./handleNewBooking/ensureAvailableUsers";
|
||||
import { getBookingData } from "./handleNewBooking/getBookingData";
|
||||
import { getCustomInputsResponses } from "./handleNewBooking/getCustomInputsResponses";
|
||||
import { getEventTypesFromDB } from "./handleNewBooking/getEventTypesFromDB";
|
||||
import { getEventType } from "./handleNewBooking/getEventType";
|
||||
import type { getEventTypeResponse } from "./handleNewBooking/getEventTypesFromDB";
|
||||
import { getLocationValuesForDb } from "./handleNewBooking/getLocationValuesForDb";
|
||||
import { getRequiresConfirmationFlags } from "./handleNewBooking/getRequiresConfirmationFlags";
|
||||
@@ -140,25 +138,6 @@ function getICalSequence(originalRescheduledBooking: BookingType | null) {
|
||||
return originalRescheduledBooking.iCalSequence + 1;
|
||||
}
|
||||
|
||||
const getEventType = async ({
|
||||
eventTypeId,
|
||||
eventTypeSlug,
|
||||
}: {
|
||||
eventTypeId: number;
|
||||
eventTypeSlug?: string;
|
||||
}) => {
|
||||
// handle dynamic user
|
||||
const eventType =
|
||||
!eventTypeId && !!eventTypeSlug ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);
|
||||
|
||||
const isOrgTeamEvent = !!eventType?.team && !!eventType?.team?.parentId;
|
||||
|
||||
return {
|
||||
...eventType,
|
||||
bookingFields: getBookingFieldsWithSystemFields({ ...eventType, isOrgTeamEvent }),
|
||||
};
|
||||
};
|
||||
|
||||
type BookingDataSchemaGetter =
|
||||
| typeof getBookingDataSchema
|
||||
| typeof import("@calcom/features/bookings/lib/getBookingDataSchemaForApi").default;
|
||||
@@ -347,7 +326,7 @@ async function handler(
|
||||
|
||||
const isPlatformBooking = !!platformClientId;
|
||||
|
||||
const eventType = await monitorCallbackAsync(getEventType, {
|
||||
const eventType = await getEventType({
|
||||
eventTypeId: rawBookingData.eventTypeId,
|
||||
eventTypeSlug: rawBookingData.eventTypeSlug,
|
||||
});
|
||||
@@ -551,22 +530,19 @@ async function handler(
|
||||
});
|
||||
}
|
||||
|
||||
const { qualifiedRRUsers, additionalFallbackRRUsers, fixedUsers } = await monitorCallbackAsync(
|
||||
loadAndValidateUsers,
|
||||
{
|
||||
hostname,
|
||||
forcedSlug,
|
||||
isPlatform: isPlatformBooking,
|
||||
eventType,
|
||||
eventTypeId,
|
||||
dynamicUserList,
|
||||
logger: loggerWithEventDetails,
|
||||
routedTeamMemberIds: routedTeamMemberIds ?? null,
|
||||
contactOwnerEmail,
|
||||
rescheduleUid: reqBody.rescheduleUid || null,
|
||||
routingFormResponse,
|
||||
}
|
||||
);
|
||||
const { qualifiedRRUsers, additionalFallbackRRUsers, fixedUsers } = await loadAndValidateUsers({
|
||||
hostname,
|
||||
forcedSlug,
|
||||
isPlatform: isPlatformBooking,
|
||||
eventType,
|
||||
eventTypeId,
|
||||
dynamicUserList,
|
||||
logger: loggerWithEventDetails,
|
||||
routedTeamMemberIds: routedTeamMemberIds ?? null,
|
||||
contactOwnerEmail,
|
||||
rescheduleUid: reqBody.rescheduleUid || null,
|
||||
routingFormResponse,
|
||||
});
|
||||
|
||||
// We filter out users but ensure allHostUsers remain same.
|
||||
let users = [...qualifiedRRUsers, ...additionalFallbackRRUsers, ...fixedUsers];
|
||||
@@ -579,7 +555,7 @@ async function handler(
|
||||
location,
|
||||
});
|
||||
|
||||
await monitorCallbackAsync(checkBookingAndDurationLimits, {
|
||||
await checkBookingAndDurationLimits({
|
||||
eventType,
|
||||
reqBodyStart: reqBody.start,
|
||||
reqBodyRescheduleUid: reqBody.rescheduleUid,
|
||||
@@ -1289,7 +1265,7 @@ async function handler(
|
||||
|
||||
try {
|
||||
if (!isDryRun) {
|
||||
booking = await monitorCallbackAsync(createBooking, {
|
||||
booking = await createBooking({
|
||||
uid,
|
||||
rescheduledBy: reqBody.rescheduledBy,
|
||||
routingFormResponseId: routingFormResponseId,
|
||||
@@ -1327,7 +1303,7 @@ async function handler(
|
||||
// If it's a round robin event, record the reason for the host assignment
|
||||
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
|
||||
if (reqBody.crmOwnerRecordType && reqBody.crmAppSlug && contactOwnerEmail && routingFormResponseId) {
|
||||
await monitorCallbackAsync(AssignmentReasonRecorder.CRMOwnership, {
|
||||
await AssignmentReasonRecorder.CRMOwnership({
|
||||
bookingId: booking.id,
|
||||
crmAppSlug: reqBody.crmAppSlug,
|
||||
teamMemberEmail: contactOwnerEmail,
|
||||
@@ -1335,7 +1311,7 @@ async function handler(
|
||||
routingFormResponseId,
|
||||
});
|
||||
} else if (routingFormResponseId && teamId) {
|
||||
await monitorCallbackAsync(AssignmentReasonRecorder.routingFormRoute, {
|
||||
await AssignmentReasonRecorder.routingFormRoute({
|
||||
bookingId: booking.id,
|
||||
routingFormResponseId,
|
||||
organizerId: organizerUser.id,
|
||||
@@ -1417,7 +1393,7 @@ async function handler(
|
||||
}
|
||||
|
||||
// After polling videoBusyTimes, credentials might have been changed due to refreshment, so query them again.
|
||||
const credentials = await monitorCallbackAsync(refreshCredentials, allCredentials);
|
||||
const credentials = await refreshCredentials(allCredentials);
|
||||
const apps = eventTypeAppMetadataOptionalSchema.parse(eventType?.metadata?.apps);
|
||||
const eventManager = !isDryRun
|
||||
? new EventManager({ ...organizerUser, credentials }, apps)
|
||||
@@ -1798,8 +1774,7 @@ async function handler(
|
||||
);
|
||||
|
||||
if (!isDryRun) {
|
||||
await monitorCallbackAsync(
|
||||
sendScheduledEmailsAndSMS,
|
||||
await sendScheduledEmailsAndSMS(
|
||||
{
|
||||
...evt,
|
||||
additionalInformation,
|
||||
@@ -1840,13 +1815,8 @@ async function handler(
|
||||
})
|
||||
);
|
||||
if (!isDryRun) {
|
||||
await monitorCallbackAsync(sendOrganizerRequestEmail, { ...evt, additionalNotes }, eventType.metadata);
|
||||
await monitorCallbackAsync(
|
||||
sendAttendeeRequestEmailAndSMS,
|
||||
{ ...evt, additionalNotes },
|
||||
attendeesList[0],
|
||||
eventType.metadata
|
||||
);
|
||||
await sendOrganizerRequestEmail({ ...evt, additionalNotes }, eventType.metadata);
|
||||
await sendAttendeeRequestEmailAndSMS({ ...evt, additionalNotes }, attendeesList[0], eventType.metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1969,11 +1939,8 @@ async function handler(
|
||||
|
||||
// We are here so, booking doesn't require payment and booking is also created in DB already, through createBooking call
|
||||
if (isConfirmedByDefault) {
|
||||
const subscribersMeetingEnded = await monitorCallbackAsync(getWebhooks, subscriberOptionsMeetingEnded);
|
||||
const subscribersMeetingStarted = await monitorCallbackAsync(
|
||||
getWebhooks,
|
||||
subscriberOptionsMeetingStarted
|
||||
);
|
||||
const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);
|
||||
const subscribersMeetingStarted = await getWebhooks(subscriberOptionsMeetingStarted);
|
||||
|
||||
let deleteWebhookScheduledTriggerPromise: Promise<unknown> = Promise.resolve();
|
||||
const scheduleTriggerPromises = [];
|
||||
@@ -2024,7 +1991,7 @@ async function handler(
|
||||
});
|
||||
|
||||
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
|
||||
await monitorCallbackAsync(handleWebhookTrigger, {
|
||||
await handleWebhookTrigger({
|
||||
subscriberOptions,
|
||||
eventTrigger,
|
||||
webhookData,
|
||||
@@ -2035,7 +2002,7 @@ async function handler(
|
||||
const eventTrigger: WebhookTriggerEvents = WebhookTriggerEvents.BOOKING_REQUESTED;
|
||||
subscriberOptions.triggerEvent = eventTrigger;
|
||||
webhookData.status = "PENDING";
|
||||
await monitorCallbackAsync(handleWebhookTrigger, {
|
||||
await handleWebhookTrigger({
|
||||
subscriberOptions,
|
||||
eventTrigger,
|
||||
webhookData,
|
||||
@@ -2099,7 +2066,7 @@ async function handler(
|
||||
}
|
||||
|
||||
try {
|
||||
await monitorCallbackAsync(scheduleWorkflowReminders, {
|
||||
await scheduleWorkflowReminders({
|
||||
workflows,
|
||||
smsReminderNumber: smsReminderNumber || null,
|
||||
calendarEvent: evtWithMetadata,
|
||||
@@ -2118,7 +2085,7 @@ async function handler(
|
||||
|
||||
try {
|
||||
if (isConfirmedByDefault) {
|
||||
await monitorCallbackAsync(scheduleNoShowTriggers, {
|
||||
await scheduleNoShowTriggers({
|
||||
booking: { startTime: booking.startTime, id: booking.id, location: booking.location },
|
||||
triggerForUser,
|
||||
organizerUser: { id: organizerUser.id },
|
||||
|
||||
@@ -2,6 +2,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||
import { checkBookingLimits } from "@calcom/lib/intervalLimits/server/checkBookingLimits";
|
||||
import { checkDurationLimits } from "@calcom/lib/intervalLimits/server/checkDurationLimits";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
||||
|
||||
@@ -13,7 +14,7 @@ type InputProps = {
|
||||
reqBodyRescheduleUid?: string;
|
||||
};
|
||||
|
||||
export const checkBookingAndDurationLimits = async ({
|
||||
const _checkBookingAndDurationLimits = async ({
|
||||
eventType,
|
||||
reqBodyStart,
|
||||
reqBodyRescheduleUid,
|
||||
@@ -42,3 +43,8 @@ export const checkBookingAndDurationLimits = async ({
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const checkBookingAndDurationLimits = withReporting(
|
||||
_checkBookingAndDurationLimits,
|
||||
"checkBookingAndDurationLimits"
|
||||
);
|
||||
@@ -5,6 +5,7 @@ import type { z } from "zod";
|
||||
import type { routingFormResponseInDbSchema } from "@calcom/app-store/routing-forms/zod";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { CreationSource } from "@calcom/prisma/enums";
|
||||
@@ -71,7 +72,8 @@ async function getAssociatedBookingForFormResponse(formResponseId: number) {
|
||||
return formResponse?.routedToBookingUid ?? null;
|
||||
}
|
||||
|
||||
export async function createBooking({
|
||||
// Define the function with underscore prefix
|
||||
const _createBooking = async ({
|
||||
uid,
|
||||
reqBody,
|
||||
eventType,
|
||||
@@ -83,7 +85,7 @@ export async function createBooking({
|
||||
rescheduledBy,
|
||||
creationSource,
|
||||
tracking,
|
||||
}: CreateBookingParams & { rescheduledBy: string | undefined }) {
|
||||
}: CreateBookingParams & { rescheduledBy: string | undefined }) => {
|
||||
updateEventDetails(evt, originalRescheduledBooking);
|
||||
const associatedBookingForFormResponse = routingFormResponseId
|
||||
? await getAssociatedBookingForFormResponse(routingFormResponseId)
|
||||
@@ -126,7 +128,9 @@ export async function createBooking({
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const createBooking = withReporting(_createBooking, "createBooking");
|
||||
|
||||
async function saveBooking(
|
||||
bookingAndAssociatedData: ReturnType<typeof buildNewBookingData>,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { parseBookingLimit } from "@calcom/lib/intervalLimits/isBookingLimits";
|
||||
import { parseDurationLimit } from "@calcom/lib/intervalLimits/isDurationLimits";
|
||||
import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
import type { BookingType } from "./originalRescheduledBookingUtils";
|
||||
@@ -50,7 +51,7 @@ const hasDateRangeForBooking = (
|
||||
return dateRangeForBooking;
|
||||
};
|
||||
|
||||
export async function ensureAvailableUsers(
|
||||
const _ensureAvailableUsers = async (
|
||||
eventType: Omit<getEventTypeResponse, "users"> & {
|
||||
users: IsFixedAwareUser[];
|
||||
},
|
||||
@@ -58,7 +59,7 @@ export async function ensureAvailableUsers(
|
||||
loggerWithEventDetails: Logger<unknown>,
|
||||
shouldServeCache?: boolean
|
||||
// ReturnType hint of at least one IsFixedAwareUser, as it's made sure at least one entry exists
|
||||
): Promise<[IsFixedAwareUser, ...IsFixedAwareUser[]]> {
|
||||
): Promise<[IsFixedAwareUser, ...IsFixedAwareUser[]]> => {
|
||||
const availableUsers: IsFixedAwareUser[] = [];
|
||||
|
||||
const startDateTimeUtc = getDateTimeInUtc(input.dateFrom, input.timeZone);
|
||||
@@ -162,4 +163,6 @@ export async function ensureAvailableUsers(
|
||||
}
|
||||
// make sure TypeScript understands availableUsers is at least one.
|
||||
return availableUsers.length === 1 ? [availableUsers[0]] : [availableUsers[0], ...availableUsers.slice(1)];
|
||||
}
|
||||
};
|
||||
|
||||
export const ensureAvailableUsers = withReporting(_ensureAvailableUsers, "ensureAvailableUsers");
|
||||
@@ -1,6 +1,8 @@
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export const findBookingQuery = async (bookingId: number) => {
|
||||
// Define the function with underscore prefix
|
||||
const _findBookingQuery = async (bookingId: number) => {
|
||||
const foundBooking = await prisma.booking.findUnique({
|
||||
where: {
|
||||
id: bookingId,
|
||||
@@ -46,3 +48,5 @@ export const findBookingQuery = async (bookingId: number) => {
|
||||
// Don't leak any sensitive data
|
||||
return foundBooking;
|
||||
};
|
||||
|
||||
export const findBookingQuery = withReporting(_findBookingQuery, "findBookingQuery");
|
||||
@@ -4,6 +4,7 @@ import type z from "zod";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { bookingCreateSchemaLegacyPropsForApi } from "@calcom/prisma/zod/custom/booking";
|
||||
|
||||
import type { TgetBookingDataSchema } from "../getBookingDataSchema";
|
||||
@@ -12,7 +13,8 @@ import { handleCustomInputs } from "./handleCustomInputs";
|
||||
|
||||
type ReqBodyWithEnd = TgetBookingDataSchema & { end: string };
|
||||
|
||||
export async function getBookingData<T extends z.ZodType>({
|
||||
// Define the function with underscore prefix
|
||||
const _getBookingData = async <T extends z.ZodType>({
|
||||
reqBody,
|
||||
eventType,
|
||||
schema,
|
||||
@@ -20,7 +22,7 @@ export async function getBookingData<T extends z.ZodType>({
|
||||
reqBody: Record<string, any>;
|
||||
eventType: getEventTypeResponse;
|
||||
schema: T;
|
||||
}) {
|
||||
}) => {
|
||||
const parsedBody = await schema.parseAsync(reqBody);
|
||||
const parsedBodyWithEnd = (body: TgetBookingDataSchema): body is ReqBodyWithEnd => {
|
||||
// Use the event length to auto-set the event end time.
|
||||
@@ -78,9 +80,11 @@ export async function getBookingData<T extends z.ZodType>({
|
||||
// So TS doesn't complain about unknown properties
|
||||
customInputs: undefined,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export type AwaitedBookingData = Awaited<ReturnType<typeof getBookingData>>;
|
||||
export const getBookingData = withReporting(_getBookingData, "getBookingData");
|
||||
|
||||
export type AwaitedBookingData = Awaited<ReturnType<typeof _getBookingData>>;
|
||||
export type RescheduleReason = AwaitedBookingData["rescheduleReason"];
|
||||
export type NoEmail = AwaitedBookingData["noEmail"];
|
||||
export type AdditionalNotes = AwaitedBookingData["notes"];
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
import { getBookingFieldsWithSystemFields } from "../getBookingFields";
|
||||
import { getEventTypesFromDB } from "./getEventTypesFromDB";
|
||||
|
||||
const _getEventType = async ({
|
||||
eventTypeId,
|
||||
eventTypeSlug,
|
||||
}: {
|
||||
eventTypeId: number;
|
||||
eventTypeSlug?: string;
|
||||
}) => {
|
||||
// handle dynamic user
|
||||
const eventType =
|
||||
!eventTypeId && !!eventTypeSlug ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);
|
||||
|
||||
const isOrgTeamEvent = !!eventType?.team && !!eventType?.team?.parentId;
|
||||
|
||||
return {
|
||||
...eventType,
|
||||
bookingFields: getBookingFieldsWithSystemFields({ ...eventType, isOrgTeamEvent }),
|
||||
};
|
||||
};
|
||||
|
||||
export const getEventType = withReporting(_getEventType, "getEventType");
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getFirstDelegationConferencingCredentialAppLocation } from "@calcom/lib/delegationCredential/server";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
@@ -14,7 +15,7 @@ const sortUsersByDynamicList = <TUser extends { username: string | null }>(
|
||||
});
|
||||
};
|
||||
|
||||
export const getLocationValuesForDb = <
|
||||
const _getLocationValuesForDb = <
|
||||
TUser extends {
|
||||
username: string | null;
|
||||
metadata: Prisma.JsonValue;
|
||||
@@ -53,3 +54,5 @@ export const getLocationValuesForDb = <
|
||||
organizerOrFirstDynamicGroupMemberDefaultLocationUrl: firstDynamicGroupMemberDefaultLocationUrl,
|
||||
};
|
||||
};
|
||||
|
||||
export const getLocationValuesForDb = withReporting(_getLocationValuesForDb, "getLocationValuesForDb");
|
||||
@@ -1,5 +1,6 @@
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { checkIfFreeEmailDomain } from "@calcom/lib/freeEmailDomainCheck/checkIfFreeEmailDomain";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
|
||||
@@ -44,11 +45,12 @@ export async function getRequiresConfirmationFlags({
|
||||
};
|
||||
}
|
||||
|
||||
async function determineRequiresConfirmation(
|
||||
// Define the function with underscore prefix
|
||||
const _determineRequiresConfirmation = async (
|
||||
eventType: EventType,
|
||||
bookingStartTime: string,
|
||||
bookerEmail: string
|
||||
): Promise<boolean> {
|
||||
): Promise<boolean> => {
|
||||
let requiresConfirmation = eventType?.requiresConfirmation;
|
||||
const rcThreshold = eventType?.metadata?.requiresConfirmationThreshold;
|
||||
const requiresConfirmationForFreeEmail = eventType?.requiresConfirmationForFreeEmail;
|
||||
@@ -65,7 +67,12 @@ async function determineRequiresConfirmation(
|
||||
}
|
||||
|
||||
return requiresConfirmation;
|
||||
}
|
||||
};
|
||||
|
||||
export const determineRequiresConfirmation = withReporting(
|
||||
_determineRequiresConfirmation,
|
||||
"determineRequiresConfirmation"
|
||||
);
|
||||
|
||||
function isUserReschedulingOwner(
|
||||
userId: number | undefined,
|
||||
|
||||
@@ -8,6 +8,7 @@ import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import type { RoutingFormResponse } from "@calcom/lib/server/getLuckyUser";
|
||||
import { withSelectedCalendars } from "@calcom/lib/server/repository/user";
|
||||
import { userSelect } from "@calcom/prisma";
|
||||
@@ -67,7 +68,7 @@ type InputProps = {
|
||||
forcedSlug: string | undefined;
|
||||
};
|
||||
|
||||
export async function loadAndValidateUsers({
|
||||
const _loadAndValidateUsers = async ({
|
||||
eventType,
|
||||
eventTypeId,
|
||||
dynamicUserList,
|
||||
@@ -83,7 +84,7 @@ export async function loadAndValidateUsers({
|
||||
qualifiedRRUsers: UsersWithDelegationCredentials;
|
||||
additionalFallbackRRUsers: UsersWithDelegationCredentials;
|
||||
fixedUsers: UsersWithDelegationCredentials;
|
||||
}> {
|
||||
}> => {
|
||||
let users: Users = await loadUsers({
|
||||
eventType,
|
||||
dynamicUserList,
|
||||
@@ -222,4 +223,6 @@ export async function loadAndValidateUsers({
|
||||
additionalFallbackRRUsers, // without qualified
|
||||
fixedUsers,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const loadAndValidateUsers = withReporting(_loadAndValidateUsers, "loadAndValidateUsers");
|
||||
@@ -2,6 +2,7 @@ import { DailyLocationType } from "@calcom/app-store/locations";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import tasker from "@calcom/features/tasker";
|
||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
|
||||
type ScheduleNoShowTriggersArgs = {
|
||||
@@ -19,7 +20,7 @@ type ScheduleNoShowTriggersArgs = {
|
||||
isDryRun?: boolean;
|
||||
};
|
||||
|
||||
export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => {
|
||||
const _scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => {
|
||||
const {
|
||||
booking,
|
||||
triggerForUser,
|
||||
@@ -110,3 +111,5 @@ export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) =
|
||||
// (workflow) => workflow.trigger === WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW
|
||||
// );
|
||||
};
|
||||
|
||||
export const scheduleNoShowTriggers = withReporting(_scheduleNoShowTriggers, "scheduleNoShowTriggers");
|
||||
+8
-1
@@ -4,6 +4,7 @@ import { getUTCOffsetByTimezone } from "@calcom/lib/dayjs";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
|
||||
type ValidateBookingTimeEventType = Pick<
|
||||
@@ -19,7 +20,8 @@ type ValidateBookingTimeEventType = Pick<
|
||||
| "title"
|
||||
>;
|
||||
|
||||
export const validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBookingTimeEventType>(
|
||||
// Define the function with underscore prefix
|
||||
const _validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBookingTimeEventType>(
|
||||
reqBodyStartTime: string,
|
||||
reqBodyTimeZone: string,
|
||||
eventType: T,
|
||||
@@ -54,3 +56,8 @@ export const validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBook
|
||||
|
||||
if (timeOutOfBounds) throw new HttpError({ statusCode: 400, message: ErrorCode.BookingTimeOutOfBounds });
|
||||
};
|
||||
|
||||
export const validateBookingTimeIsNotOutOfBounds = withReporting(
|
||||
_validateBookingTimeIsNotOutOfBounds,
|
||||
"validateBookingTimeIsNotOutOfBounds"
|
||||
);
|
||||
@@ -2,6 +2,7 @@ import type { Logger } from "tslog";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
type Props = {
|
||||
reqBodyStart: string;
|
||||
@@ -11,7 +12,8 @@ type Props = {
|
||||
logger: Logger<unknown>;
|
||||
};
|
||||
|
||||
export const validateEventLength = ({
|
||||
// Define the function with underscore prefix
|
||||
const _validateEventLength = ({
|
||||
reqBodyStart,
|
||||
reqBodyEnd,
|
||||
eventTypeMultipleDuration,
|
||||
@@ -25,3 +27,5 @@ export const validateEventLength = ({
|
||||
throw new HttpError({ statusCode: 400, message: "Invalid event length" });
|
||||
}
|
||||
};
|
||||
|
||||
export const validateEventLength = withReporting(_validateEventLength, "validateEventLength");
|
||||
@@ -4,8 +4,9 @@ import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||
import { isEventPayload, type WebhookPayloadType } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
export async function handleWebhookTrigger(args: {
|
||||
async function _handleWebhookTrigger(args: {
|
||||
subscriberOptions: GetSubscriberOptions;
|
||||
eventTrigger: string;
|
||||
webhookData: WebhookPayloadType;
|
||||
@@ -32,3 +33,5 @@ export async function handleWebhookTrigger(args: {
|
||||
logger.error("Error while sending webhook", error);
|
||||
}
|
||||
}
|
||||
|
||||
export const handleWebhookTrigger = withReporting(_handleWebhookTrigger, "handleWebhookTrigger");
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { FormResponse, Fields } from "@calcom/app-store/routing-forms/types/types";
|
||||
import { zodRoutes } from "@calcom/app-store/routing-forms/zod";
|
||||
import { acrossQueryValueCompatiblity } from "@calcom/lib/raqb/raqbUtils";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { getUsersAttributes } from "@calcom/lib/service/attribute/server/getAttributes";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { AssignmentReasonEnum } from "@calcom/prisma/enums";
|
||||
@@ -13,7 +14,16 @@ export enum RRReassignmentType {
|
||||
}
|
||||
|
||||
export default class AssignmentReasonRecorder {
|
||||
static async routingFormRoute({
|
||||
/**
|
||||
* We should use decorators to wrap the methods with withReporting
|
||||
* but we can't don't have support for static methods in decorators
|
||||
* so this is a workaround to wrap the methods with withReporting.
|
||||
*/
|
||||
static routingFormRoute = withReporting(
|
||||
AssignmentReasonRecorder._routingFormRoute,
|
||||
"AssignmentReasonRecorder.routingFormRoute"
|
||||
);
|
||||
static async _routingFormRoute({
|
||||
bookingId,
|
||||
routingFormResponseId,
|
||||
organizerId,
|
||||
@@ -113,8 +123,11 @@ export default class AssignmentReasonRecorder {
|
||||
}
|
||||
|
||||
// Separate method to handle rerouting
|
||||
|
||||
static async CRMOwnership({
|
||||
static CRMOwnership = withReporting(
|
||||
AssignmentReasonRecorder._CRMOwnership,
|
||||
"AssignmentReasonRecorder.CRMOwnership"
|
||||
);
|
||||
static async _CRMOwnership({
|
||||
bookingId,
|
||||
crmAppSlug,
|
||||
teamMemberEmail,
|
||||
@@ -143,8 +156,11 @@ export default class AssignmentReasonRecorder {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static async roundRobinReassignment({
|
||||
static roundRobinReassignment = withReporting(
|
||||
AssignmentReasonRecorder._roundRobinReassignment,
|
||||
"AssignmentReasonRecorder.roundRobinReassignment"
|
||||
);
|
||||
static async _roundRobinReassignment({
|
||||
bookingId,
|
||||
reassignById,
|
||||
reassignReason,
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import type { Workflow, WorkflowStep } from "@calcom/features/ee/workflows/lib/types";
|
||||
import { checkSMSRateLimit } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { SENDER_NAME } from "@calcom/lib/constants";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SchedulingType, WorkflowActions, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
@@ -177,7 +178,7 @@ const processWorkflowStep = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const scheduleWorkflowReminders = async (args: ScheduleWorkflowRemindersArgs) => {
|
||||
const _scheduleWorkflowReminders = async (args: ScheduleWorkflowRemindersArgs) => {
|
||||
const {
|
||||
workflows,
|
||||
smsReminderNumber,
|
||||
@@ -232,7 +233,7 @@ export interface SendCancelledRemindersArgs {
|
||||
hideBranding?: boolean;
|
||||
}
|
||||
|
||||
export const sendCancelledReminders = async (args: SendCancelledRemindersArgs) => {
|
||||
const _sendCancelledReminders = async (args: SendCancelledRemindersArgs) => {
|
||||
const { smsReminderNumber, evt, workflows, hideBranding } = args;
|
||||
|
||||
if (!workflows.length) return;
|
||||
@@ -241,7 +242,7 @@ export const sendCancelledReminders = async (args: SendCancelledRemindersArgs) =
|
||||
if (workflow.trigger !== WorkflowTriggerEvents.EVENT_CANCELLED) continue;
|
||||
|
||||
for (const step of workflow.steps) {
|
||||
processWorkflowStep(workflow, step, {
|
||||
await processWorkflowStep(workflow, step, {
|
||||
smsReminderNumber,
|
||||
hideBranding,
|
||||
calendarEvent: evt,
|
||||
@@ -249,3 +250,10 @@ export const sendCancelledReminders = async (args: SendCancelledRemindersArgs) =
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Export functions wrapped with withReporting
|
||||
export const scheduleWorkflowReminders = withReporting(
|
||||
_scheduleWorkflowReminders,
|
||||
"scheduleWorkflowReminders"
|
||||
);
|
||||
export const sendCancelledReminders = withReporting(_sendCancelledReminders, "sendCancelledReminders");
|
||||
@@ -3,6 +3,7 @@ import { scheduleEmailReminder } from "@calcom/features/ee/workflows/lib/reminde
|
||||
import type { Workflow } from "@calcom/features/ee/workflows/lib/types";
|
||||
import type { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { WorkflowTriggerEvents, TimeUnit, WorkflowActions, WorkflowTemplates } from "@calcom/prisma/enums";
|
||||
|
||||
import type { ExtendedCalendarEvent } from "./reminderScheduler";
|
||||
@@ -11,7 +12,7 @@ const log = logger.getSubLogger({ prefix: ["[scheduleMandatoryReminder]"] });
|
||||
|
||||
export type NewBookingEventType = Awaited<ReturnType<typeof getDefaultEvent>> | getEventTypeResponse;
|
||||
|
||||
export async function scheduleMandatoryReminder({
|
||||
async function _scheduleMandatoryReminder({
|
||||
evt,
|
||||
workflows,
|
||||
requiresConfirmation,
|
||||
@@ -75,3 +76,8 @@ export async function scheduleMandatoryReminder({
|
||||
log.error("Error while scheduling mandatory reminders", JSON.stringify({ error }));
|
||||
}
|
||||
}
|
||||
|
||||
export const scheduleMandatoryReminder = withReporting(
|
||||
_scheduleMandatoryReminder,
|
||||
"scheduleMandatoryReminder"
|
||||
);
|
||||
@@ -1,3 +1,4 @@
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import defaultPrisma from "@calcom/prisma";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
@@ -80,4 +81,4 @@ const getWebhooks = async (options: GetSubscriberOptions, prisma: PrismaClient =
|
||||
return allWebhooks;
|
||||
};
|
||||
|
||||
export default getWebhooks;
|
||||
export default withReporting(getWebhooks, "getWebhooks");
|
||||
@@ -6,6 +6,7 @@ import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventR
|
||||
import { getHumanReadableLocationValue } from "@calcom/lib/location";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { ApiKey } from "@calcom/prisma/client";
|
||||
@@ -304,7 +305,7 @@ export async function scheduleTrigger({
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteWebhookScheduledTriggers({
|
||||
async function _deleteWebhookScheduledTriggers({
|
||||
booking,
|
||||
appId,
|
||||
triggerEvent,
|
||||
@@ -361,6 +362,11 @@ export async function deleteWebhookScheduledTriggers({
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteWebhookScheduledTriggers = withReporting(
|
||||
_deleteWebhookScheduledTriggers,
|
||||
"deleteWebhookScheduledTriggers"
|
||||
);
|
||||
|
||||
export async function updateTriggerForExistingBookings(
|
||||
webhook: Webhook,
|
||||
existingEventTriggers: WebhookTriggerEvents[],
|
||||
|
||||
Reference in new issue
Block a user