Skip to content

Commit 3a7122d

Browse files
fix: revert assignmentReason breaking change in webhook payloads (calcom#27891)
* fix: revert assignmentReason breaking change in webhook payloads Remove the new { category, details } format from EventPayloadType to maintain backward compatibility for webhook consumers. The new format is stripped at all webhook payload construction sites by destructuring assignmentReason out of CalendarEvent before spreading into the payload. A sanitizeAssignmentReasonForWebhook function provides an additional safety net in sendPayload itself. Emails and booking single view continue to use the new format via CalendarEvent. Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: strip assignmentReason from handlePaymentSuccess webhook payload Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: strip assignmentReason from triggerWebhooks and handleSeats webhook payloads Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: use zod safeParse instead of type assertion in sanitizeAssignmentReasonForWebhook Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 21d28c9 commit 3a7122d

11 files changed

Lines changed: 225 additions & 67 deletions

File tree

apps/web/lib/daily-webhook/triggerWebhooks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export const triggerRecordingReadyWebhook = async ({
5454
})
5555
);
5656

57+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
5758
const payload: EventPayloadType = {
58-
...evt,
59+
...evtWithoutAssignmentReason,
5960
downloadLink,
6061
};
6162

@@ -94,8 +95,9 @@ export const triggerTranscriptionGeneratedWebhook = async ({
9495
})
9596
);
9697

98+
const { assignmentReason: _emailAssignmentReason2, ...evtWithoutAssignmentReason2 } = evt;
9799
const payload: EventPayloadType = {
98-
...evt,
100+
...evtWithoutAssignmentReason2,
99101
downloadLinks,
100102
};
101103

packages/app-store/_utils/payments/handlePaymentSuccess.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ export async function handlePaymentSuccess(params: {
160160
length: booking.eventType?.length,
161161
};
162162

163+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
163164
const payload: EventPayloadType = {
164-
...evt,
165+
...evtWithoutAssignmentReason,
165166
...eventTypeInfo,
166167
bookingId,
167168
eventTypeId: booking.eventType?.id,

packages/features/bookings/lib/getWebhookPayloadForBooking.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export const getWebhookPayloadForBooking = ({
3030
length: booking.eventType?.length,
3131
};
3232

33+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
3334
const payload: EventPayloadType = {
34-
...evt,
35+
...evtWithoutAssignmentReason,
3536
...eventTypeInfo,
3637
bookingId: booking.id,
3738
};

packages/features/bookings/lib/handleCancelBooking.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import {
1313
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
1414
import { BookingReferenceRepository } from "@calcom/features/bookingReference/repositories/BookingReferenceRepository";
1515
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
16-
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
1716
import EventManager from "@calcom/features/bookings/lib/EventManager";
1817
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
1918
import { processNoShowFeeOnCancellation } from "@calcom/features/bookings/lib/payment/processNoShowFeeOnCancellation";
2019
import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund";
20+
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
2121
import { CreditService } from "@calcom/features/ee/billing/credit-service";
2222
import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
2323
import { getAllWorkflowsFromEventType } from "@calcom/features/ee/workflows/lib/getAllWorkflowsFromEventType";
@@ -429,9 +429,10 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
429429
isPlatformManagedUserBooking: bookingToDelete.user.isPlatformManaged,
430430
} satisfies HandleCancelBookingResponse;
431431

432+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
432433
const promises = webhooks.map((webhook) =>
433434
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, {
434-
...evt,
435+
...evtWithoutAssignmentReason,
435436
...eventTypeInfo,
436437
status: "CANCELLED",
437438
smsReminderNumber: bookingToDelete.smsReminderNumber || undefined,

packages/features/bookings/lib/handleConfirmation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { sendScheduledEmailsAndSMS } from "@calcom/emails/email-manager";
44
import type { Actor } from "@calcom/features/booking-audit/lib/dto/types";
55
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
66
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
7-
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
87
import type { EventManagerUser } from "@calcom/features/bookings/lib/EventManager";
98
import EventManager, { placeholderCreatedEvent } from "@calcom/features/bookings/lib/EventManager";
9+
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
10+
import type { ISimpleLogger } from "@calcom/features/di/shared/services/logger.service";
1011
import { CreditService } from "@calcom/features/ee/billing/credit-service";
1112
import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
1213
import {
@@ -34,10 +35,8 @@ import type { PlatformClientParams } from "@calcom/prisma/zod-utils";
3435
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
3536
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
3637
import { v4 as uuidv4 } from "uuid";
37-
3838
import { getCalEventResponses } from "./getCalEventResponses";
3939
import { scheduleNoShowTriggers } from "./handleNewBooking/scheduleNoShowTriggers";
40-
import type { ISimpleLogger } from "@calcom/features/di/shared/services/logger.service";
4140

4241
async function fireBookingAcceptedEvent({
4342
actor,
@@ -570,8 +569,9 @@ export async function handleConfirmation(args: {
570569
length: eventType?.length,
571570
};
572571

572+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
573573
const payload: EventPayloadType = {
574-
...evt,
574+
...evtWithoutAssignmentReason,
575575
...eventTypeInfo,
576576
bookingId,
577577
eventTypeId: eventType?.id,

packages/features/bookings/lib/handleSeats/cancel/cancelAttendeeSeat.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
2-
import { getAllDelegationCredentialsForUserIncludeServiceAccountKey } from "@calcom/app-store/delegationCredential";
3-
import { getDelegationCredentialOrFindRegularCredential } from "@calcom/app-store/delegationCredential";
2+
import {
3+
getAllDelegationCredentialsForUserIncludeServiceAccountKey,
4+
getDelegationCredentialOrFindRegularCredential,
5+
} from "@calcom/app-store/delegationCredential";
46
import { sendCancelledSeatEmailsAndSMS } from "@calcom/emails/email-manager";
57
import { updateMeeting } from "@calcom/features/conferencing/lib/videoClient";
68
import { WorkflowRepository } from "@calcom/features/ee/workflows/repositories/WorkflowRepository";
@@ -14,10 +16,9 @@ import { safeStringify } from "@calcom/lib/safeStringify";
1416
import { getTranslation } from "@calcom/lib/server/i18n";
1517
import prisma from "@calcom/prisma";
1618
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
17-
import { bookingCancelAttendeeSeatSchema } from "@calcom/prisma/zod-utils";
1819
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
20+
import { bookingCancelAttendeeSeatSchema } from "@calcom/prisma/zod-utils";
1921
import type { CalendarEvent } from "@calcom/types/Calendar";
20-
2122
import type { BookingToDelete } from "../../handleCancelBooking";
2223

2324
async function cancelAttendeeSeat(
@@ -159,8 +160,9 @@ async function cancelAttendeeSeat(
159160
]
160161
: [];
161162

163+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
162164
const payload: EventPayloadType = {
163-
...evt,
165+
...evtWithoutAssignmentReason,
164166
...eventTypeInfo,
165167
status: "CANCELLED",
166168
smsReminderNumber: bookingToDelete.smsReminderNumber || undefined,

packages/features/bookings/lib/handleSeats/handleSeats.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ const handleSeats = async (
284284
loggerWithEventDetails.error("Error while scheduling workflow reminders", JSON.stringify({ error }));
285285
}
286286

287+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
287288
const webhookData: EventPayloadType = {
288-
...evt,
289+
...evtWithoutAssignmentReason,
289290
...eventTypeInfo,
290291
uid: resultBooking?.uid || uid,
291292
bookingId: seatedBooking?.id,

packages/features/bookings/lib/service/RegularBookingService.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import short, { uuid } from "short-uuid";
2-
import { v5 as uuidv5 } from "uuid";
3-
import { getAuditActionSource } from "../handleNewBooking/getAuditActionSource";
4-
import {
5-
buildBookingCreatedAuditData,
6-
buildBookingRescheduledAuditData,
7-
} from "../handleNewBooking/buildBookingEventAuditData";
8-
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
1+
import process from "node:process";
92
import processExternalId from "@calcom/app-store/_utils/calendars/processExternalId";
103
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
114
import {
@@ -20,58 +13,59 @@ import {
2013
} from "@calcom/app-store/locations";
2114
import { getAppFromSlug } from "@calcom/app-store/utils";
2215
import {
23-
eventTypeMetaDataSchemaWithTypedApps,
2416
eventTypeAppMetadataOptionalSchema,
17+
eventTypeMetaDataSchemaWithTypedApps,
2518
} from "@calcom/app-store/zod-utils";
2619
import dayjs from "@calcom/dayjs";
2720
import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";
2821
import getICalUID from "@calcom/emails/lib/getICalUID";
29-
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
3022
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
31-
import { getAssignmentReasonCategory } from "@calcom/features/bookings/lib/getAssignmentReasonCategory";
32-
import EventManager, { placeholderCreatedEvent } from "@calcom/features/bookings/lib/EventManager";
33-
import type { BookingDataSchemaGetter } from "@calcom/features/bookings/lib/dto/types";
23+
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
3424
import type {
35-
CreateRegularBookingData,
36-
CreateBookingMeta,
25+
BookingDataSchemaGetter,
3726
BookingHandlerInput,
27+
CreateBookingMeta,
28+
CreateRegularBookingData,
3829
} from "@calcom/features/bookings/lib/dto/types";
30+
import EventManager, { placeholderCreatedEvent } from "@calcom/features/bookings/lib/EventManager";
31+
import { getAssignmentReasonCategory } from "@calcom/features/bookings/lib/getAssignmentReasonCategory";
3932
import type { CheckBookingAndDurationLimitsService } from "@calcom/features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits";
4033
import { handlePayment } from "@calcom/features/bookings/lib/handlePayment";
4134
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
4235
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
43-
import { BookingEventHandlerService } from "@calcom/features/bookings/lib/onBookingEvents/BookingEventHandlerService";
36+
import type { BookingEventHandlerService } from "@calcom/features/bookings/lib/onBookingEvents/BookingEventHandlerService";
4437
import type { BookingRescheduledPayload } from "@calcom/features/bookings/lib/onBookingEvents/types.d";
45-
import { BookingEmailAndSmsTasker } from "@calcom/features/bookings/lib/tasker/BookingEmailAndSmsTasker";
38+
import type { BookingEmailAndSmsTasker } from "@calcom/features/bookings/lib/tasker/BookingEmailAndSmsTasker";
39+
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
4640
import { getSpamCheckService } from "@calcom/features/di/watchlist/containers/SpamCheckService.container";
4741
import { CreditService } from "@calcom/features/ee/billing/credit-service";
4842
import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
49-
import { getRoutingTraceService } from "@calcom/features/routing-trace/di/RoutingTraceService.container";
5043
import AssignmentReasonRecorder from "@calcom/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder";
5144
import { BookingLocationService } from "@calcom/features/ee/round-robin/lib/bookingLocationService";
5245
import { getAllWorkflowsFromEventType } from "@calcom/features/ee/workflows/lib/getAllWorkflowsFromEventType";
5346
import { WorkflowService } from "@calcom/features/ee/workflows/lib/service/WorkflowService";
5447
import { WorkflowRepository } from "@calcom/features/ee/workflows/repositories/WorkflowRepository";
5548
import { getUsernameList } from "@calcom/features/eventtypes/lib/defaultEvents";
5649
import { getEventName, updateHostInEventName } from "@calcom/features/eventtypes/lib/eventNaming";
57-
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
50+
import type { FeaturesRepository } from "@calcom/features/flags/features.repository";
5851
import { getFullName } from "@calcom/features/form-builder/utils";
5952
import type { HashedLinkService } from "@calcom/features/hashedLink/lib/service/HashedLinkService";
6053
import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
54+
import { getRoutingTraceService } from "@calcom/features/routing-trace/di/RoutingTraceService.container";
6155
import { handleAnalyticsEvents } from "@calcom/features/tasker/tasks/analytics/handleAnalyticsEvents";
6256
import type { UserRepository } from "@calcom/features/users/repositories/UserRepository";
6357
import { UsersRepository } from "@calcom/features/users/users.repository";
6458
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
6559
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
6660
import {
67-
deleteWebhookScheduledTriggers,
6861
cancelNoShowTasksForBooking,
62+
deleteWebhookScheduledTriggers,
6963
scheduleTrigger,
7064
} from "@calcom/features/webhooks/lib/scheduleTrigger";
7165
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
72-
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
7366
import { groupHostsByGroupId } from "@calcom/lib/bookings/hostGroupUtils";
7467
import { shouldIgnoreContactOwner } from "@calcom/lib/bookings/routing/utils";
68+
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
7569
import { DEFAULT_GROUP_ID, ENABLE_ASYNC_TASKER } from "@calcom/lib/constants";
7670
import { ErrorCode } from "@calcom/lib/errorCodes";
7771
import { ErrorWithCode } from "@calcom/lib/errors";
@@ -87,36 +81,43 @@ import { getTranslation } from "@calcom/lib/server/i18n";
8781
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
8882
import { distributedTracing } from "@calcom/lib/tracing/factory";
8983
import type { PrismaClient } from "@calcom/prisma";
90-
import type { DestinationCalendar, Prisma, User, AssignmentReasonEnum } from "@calcom/prisma/client";
84+
import type { AssignmentReasonEnum, DestinationCalendar, Prisma, User } from "@calcom/prisma/client";
9185
import {
9286
BookingStatus,
87+
CreationSource,
9388
SchedulingType,
9489
WebhookTriggerEvents,
9590
WorkflowTriggerEvents,
96-
CreationSource,
9791
} from "@calcom/prisma/enums";
9892
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
9993
import type {
10094
AdditionalInformation,
10195
AppsStatus,
102-
CalendarEvent,
10396
CalEventResponses,
97+
CalendarEvent,
10498
} from "@calcom/types/Calendar";
10599
import type { CredentialForCalendarService } from "@calcom/types/Credential";
106100
import type { EventResult, PartialReference } from "@calcom/types/EventManager";
107-
101+
import short, { uuid } from "short-uuid";
102+
import { v5 as uuidv5 } from "uuid";
108103
import type { BookingRepository } from "../../repositories/BookingRepository";
109-
import { BookingActionMap, BookingEmailSmsHandler, type BookingActionType } from "../BookingEmailSmsHandler";
104+
import { BookingActionMap, type BookingActionType, BookingEmailSmsHandler } from "../BookingEmailSmsHandler";
110105
import { getAllCredentialsIncludeServiceAccountKey } from "../getAllCredentialsForUsersOnEvent/getAllCredentials";
111106
import { refreshCredentials } from "../getAllCredentialsForUsersOnEvent/refreshCredentials";
112107
import getBookingDataSchema from "../getBookingDataSchema";
113-
import { LuckyUserService } from "../getLuckyUser";
108+
import type { LuckyUserService } from "../getLuckyUser";
114109
import { addVideoCallDataToEvent } from "../handleNewBooking/addVideoCallDataToEvent";
110+
import {
111+
buildBookingCreatedAuditData,
112+
buildBookingRescheduledAuditData,
113+
} from "../handleNewBooking/buildBookingEventAuditData";
115114
import { checkActiveBookingsLimitForBooker } from "../handleNewBooking/checkActiveBookingsLimitForBooker";
116115
import { checkIfBookerEmailIsBlocked } from "../handleNewBooking/checkIfBookerEmailIsBlocked";
117-
import { createBooking } from "../handleNewBooking/createBooking";
118116
import type { Booking } from "../handleNewBooking/createBooking";
117+
import { createBooking } from "../handleNewBooking/createBooking";
119118
import { ensureAvailableUsers } from "../handleNewBooking/ensureAvailableUsers";
119+
import { getAuditActionSource } from "../handleNewBooking/getAuditActionSource";
120+
import { getBookingAuditActorForNewBooking } from "../handleNewBooking/getBookingAuditActorForNewBooking";
120121
import { getBookingData } from "../handleNewBooking/getBookingData";
121122
import { getCustomInputsResponses } from "../handleNewBooking/getCustomInputsResponses";
122123
import { getEventType } from "../handleNewBooking/getEventType";
@@ -127,15 +128,14 @@ import { getSeatedBooking } from "../handleNewBooking/getSeatedBooking";
127128
import { getVideoCallDetails } from "../handleNewBooking/getVideoCallDetails";
128129
import { handleAppsStatus } from "../handleNewBooking/handleAppsStatus";
129130
import { loadAndValidateUsers } from "../handleNewBooking/loadAndValidateUsers";
130-
import { getOriginalRescheduledBooking } from "../handleNewBooking/originalRescheduledBookingUtils";
131131
import type { BookingType } from "../handleNewBooking/originalRescheduledBookingUtils";
132+
import { getOriginalRescheduledBooking } from "../handleNewBooking/originalRescheduledBookingUtils";
132133
import { scheduleNoShowTriggers } from "../handleNewBooking/scheduleNoShowTriggers";
133134
import type { IEventTypePaymentCredentialType, Invitee, IsFixedAwareUser } from "../handleNewBooking/types";
134135
import { validateBookingTimeIsNotOutOfBounds } from "../handleNewBooking/validateBookingTimeIsNotOutOfBounds";
135136
import { validateEventLength } from "../handleNewBooking/validateEventLength";
136137
import handleSeats from "../handleSeats/handleSeats";
137138
import type { IBookingService } from "../interfaces/IBookingService";
138-
import { getBookingAuditActorForNewBooking } from "../handleNewBooking/getBookingAuditActorForNewBooking";
139139
import { isWithinMinimumRescheduleNotice } from "../reschedule/isWithinMinimumRescheduleNotice";
140140

141141
const translator = short();
@@ -1305,7 +1305,7 @@ async function handler(
13051305
const isManagedEventType = !!eventType.parentId;
13061306

13071307
// Track credential ID for per-host locations
1308-
let perHostCredentialId: number | undefined = undefined;
1308+
let perHostCredentialId: number | undefined;
13091309

13101310
// Handle per-host custom locations for round-robin events
13111311
if (
@@ -2498,8 +2498,9 @@ async function handler(
24982498

24992499
const webhookLocation = metadata?.videoCallUrl || evt.location;
25002500

2501+
const { assignmentReason: _emailAssignmentReason, ...evtWithoutAssignmentReason } = evt;
25012502
const webhookData: EventPayloadType = {
2502-
...evt,
2503+
...evtWithoutAssignmentReason,
25032504
...eventTypeInfo,
25042505
bookingId: booking?.id,
25052506
rescheduleId: originalRescheduledBooking?.id || undefined,

0 commit comments

Comments
 (0)