refactor: v2 OAuth webhooks & workflows (#17959)
* refactor: handleMarkNoShow OAuth webhook handling * refactor: confirm / decline booking OAuth webhook handling * refactor: pass oauth client to calendar event * refactor: pass oauth params * fix import * fix tests * chore: bump libraries * chore: bump libraries * chore: republish platform libraries * chore: republish platform libraries * fix: use replexica key in v2 and unit test CI * lock file * fixup! Merge branch 'main' into lauris/cal-4807-platform-refactor-oauth-webhooks * Revert "fix: use replexica key in v2 and unit test CI" This reverts commit 0bd6c364535f9e11a4d1497a6bd8909885562080. --------- Co-authored-by: Morgan <[email protected]> Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
13 files changed
+5834
-107
No files matched your search
@@ -29,7 +29,7 @@
|
|||||||
"@axiomhq/winston": "^1.2.0",
|
"@axiomhq/winston": "^1.2.0",
|
||||||
"@calcom/platform-constants": "*",
|
"@calcom/platform-constants": "*",
|
||||||
"@calcom/platform-enums": "*",
|
"@calcom/platform-enums": "*",
|
||||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]3",
|
"@calcom/platform-libraries": "npm:@calcom/[email protected]7",
|
||||||
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
||||||
"@calcom/platform-types": "*",
|
"@calcom/platform-types": "*",
|
||||||
"@calcom/platform-utils": "*",
|
"@calcom/platform-utils": "*",
|
||||||
|
|||||||
+8
-1
@@ -34,6 +34,7 @@ import {
|
|||||||
OrganizerCancelledEmail,
|
OrganizerCancelledEmail,
|
||||||
AttendeeCancelledEmail,
|
AttendeeCancelledEmail,
|
||||||
OrganizerReassignedEmail,
|
OrganizerReassignedEmail,
|
||||||
|
AttendeeUpdatedEmail,
|
||||||
} from "@calcom/platform-libraries";
|
} from "@calcom/platform-libraries";
|
||||||
import {
|
import {
|
||||||
CreateBookingInput_2024_08_13,
|
CreateBookingInput_2024_08_13,
|
||||||
@@ -61,10 +62,12 @@ jest
|
|||||||
jest
|
jest
|
||||||
.spyOn(OrganizerCancelledEmail.prototype, "getHtml")
|
.spyOn(OrganizerCancelledEmail.prototype, "getHtml")
|
||||||
.mockImplementation(() => Promise.resolve("<p>email</p>"));
|
.mockImplementation(() => Promise.resolve("<p>email</p>"));
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.spyOn(OrganizerReassignedEmail.prototype, "getHtml")
|
.spyOn(OrganizerReassignedEmail.prototype, "getHtml")
|
||||||
.mockImplementation(() => Promise.resolve("<p>email</p>"));
|
.mockImplementation(() => Promise.resolve("<p>email</p>"));
|
||||||
|
jest
|
||||||
|
.spyOn(AttendeeUpdatedEmail.prototype, "getHtml")
|
||||||
|
.mockImplementation(() => Promise.resolve("<p>email</p>"));
|
||||||
|
|
||||||
type EmailSetup = {
|
type EmailSetup = {
|
||||||
team: Team;
|
team: Team;
|
||||||
@@ -681,6 +684,7 @@ describe("Bookings Endpoints 2024-08-13 team emails", () => {
|
|||||||
expect(responseBody.data).toBeDefined();
|
expect(responseBody.data).toBeDefined();
|
||||||
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
expect(OrganizerScheduledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(OrganizerScheduledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
|
expect(AttendeeUpdatedEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
emailsDisabledSetup.roundRobinEventType.currentHostId = reassignToId;
|
emailsDisabledSetup.roundRobinEventType.currentHostId = reassignToId;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -697,6 +701,7 @@ describe("Bookings Endpoints 2024-08-13 team emails", () => {
|
|||||||
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
expect(OrganizerScheduledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(OrganizerScheduledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
expect(OrganizerReassignedEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(OrganizerReassignedEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
|
expect(AttendeeUpdatedEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -898,6 +903,7 @@ describe("Bookings Endpoints 2024-08-13 team emails", () => {
|
|||||||
expect(responseBody.data).toBeDefined();
|
expect(responseBody.data).toBeDefined();
|
||||||
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
expect(OrganizerScheduledEmail.prototype.getHtml).toHaveBeenCalled();
|
expect(OrganizerScheduledEmail.prototype.getHtml).toHaveBeenCalled();
|
||||||
|
expect(AttendeeUpdatedEmail.prototype.getHtml).toHaveBeenCalled();
|
||||||
emailsDisabledSetup.roundRobinEventType.currentHostId = reassignToId;
|
emailsDisabledSetup.roundRobinEventType.currentHostId = reassignToId;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -914,6 +920,7 @@ describe("Bookings Endpoints 2024-08-13 team emails", () => {
|
|||||||
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
expect(AttendeeCancelledEmail.prototype.getHtml).not.toHaveBeenCalled();
|
||||||
expect(OrganizerScheduledEmail.prototype.getHtml).toHaveBeenCalled();
|
expect(OrganizerScheduledEmail.prototype.getHtml).toHaveBeenCalled();
|
||||||
expect(OrganizerReassignedEmail.prototype.getHtml).toHaveBeenCalled();
|
expect(OrganizerReassignedEmail.prototype.getHtml).toHaveBeenCalled();
|
||||||
|
expect(AttendeeUpdatedEmail.prototype.getHtml).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -363,12 +363,17 @@ export class BookingsService_2024_08_13 {
|
|||||||
|
|
||||||
async markAbsent(bookingUid: string, bookingOwnerId: number, body: MarkAbsentBookingInput_2024_08_13) {
|
async markAbsent(bookingUid: string, bookingOwnerId: number, body: MarkAbsentBookingInput_2024_08_13) {
|
||||||
const bodyTransformed = this.inputService.transformInputMarkAbsentBooking(body);
|
const bodyTransformed = this.inputService.transformInputMarkAbsentBooking(body);
|
||||||
|
const bookingBefore = await this.bookingsRepository.getByUid(bookingUid);
|
||||||
|
const platformClientParams = bookingBefore?.eventTypeId
|
||||||
|
? await this.inputService.getOAuthClientParams(bookingBefore.eventTypeId)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
await handleMarkNoShow({
|
await handleMarkNoShow({
|
||||||
bookingUid,
|
bookingUid,
|
||||||
attendees: bodyTransformed.attendees,
|
attendees: bodyTransformed.attendees,
|
||||||
noShowHost: bodyTransformed.noShowHost,
|
noShowHost: bodyTransformed.noShowHost,
|
||||||
userId: bookingOwnerId,
|
userId: bookingOwnerId,
|
||||||
|
platformClientParams,
|
||||||
});
|
});
|
||||||
|
|
||||||
const booking = await this.bookingsRepository.getByUidWithAttendeesAndUserAndEvent(bookingUid);
|
const booking = await this.bookingsRepository.getByUidWithAttendeesAndUserAndEvent(bookingUid);
|
||||||
@@ -423,7 +428,11 @@ export class BookingsService_2024_08_13 {
|
|||||||
throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);
|
throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailsEnabled = booking.eventTypeId ? await this.getEmailsEnabled(booking.eventTypeId) : true;
|
const platformClientParams = booking.eventTypeId
|
||||||
|
? await this.inputService.getOAuthClientParams(booking.eventTypeId)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const emailsEnabled = platformClientParams ? platformClientParams.arePlatformEmailsEnabled : true;
|
||||||
|
|
||||||
const profile = this.usersService.getUserMainProfile(requestUser);
|
const profile = this.usersService.getUserMainProfile(requestUser);
|
||||||
|
|
||||||
@@ -431,6 +440,7 @@ export class BookingsService_2024_08_13 {
|
|||||||
bookingId: booking.id,
|
bookingId: booking.id,
|
||||||
orgId: profile?.organizationId || null,
|
orgId: profile?.organizationId || null,
|
||||||
emailsEnabled,
|
emailsEnabled,
|
||||||
|
platformClientParams,
|
||||||
});
|
});
|
||||||
|
|
||||||
const reassigned = await this.bookingsRepository.getByUidWithUser(bookingUid);
|
const reassigned = await this.bookingsRepository.getByUidWithUser(bookingUid);
|
||||||
@@ -441,12 +451,6 @@ export class BookingsService_2024_08_13 {
|
|||||||
return this.outputService.getOutputReassignedBooking(reassigned);
|
return this.outputService.getOutputReassignedBooking(reassigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEmailsEnabled(eventTypeId: number) {
|
|
||||||
const oAuthParams = await this.inputService.getOAuthClientParams(eventTypeId);
|
|
||||||
const emailsEnabled = oAuthParams ? oAuthParams.arePlatformEmailsEnabled : true;
|
|
||||||
return emailsEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
async reassignBookingToUser(
|
async reassignBookingToUser(
|
||||||
bookingUid: string,
|
bookingUid: string,
|
||||||
newUserId: number,
|
newUserId: number,
|
||||||
@@ -463,7 +467,11 @@ export class BookingsService_2024_08_13 {
|
|||||||
throw new NotFoundException(`User with id=${newUserId} was not found in the database`);
|
throw new NotFoundException(`User with id=${newUserId} was not found in the database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailsEnabled = booking.eventTypeId ? await this.getEmailsEnabled(booking.eventTypeId) : true;
|
const platformClientParams = booking.eventTypeId
|
||||||
|
? await this.inputService.getOAuthClientParams(booking.eventTypeId)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const emailsEnabled = platformClientParams ? platformClientParams.arePlatformEmailsEnabled : true;
|
||||||
|
|
||||||
const profile = this.usersService.getUserMainProfile(user);
|
const profile = this.usersService.getUserMainProfile(user);
|
||||||
|
|
||||||
@@ -474,6 +482,7 @@ export class BookingsService_2024_08_13 {
|
|||||||
reassignReason: body.reason,
|
reassignReason: body.reason,
|
||||||
reassignedById,
|
reassignedById,
|
||||||
emailsEnabled,
|
emailsEnabled,
|
||||||
|
platformClientParams,
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.outputService.getOutputReassignedBooking(reassigned);
|
return this.outputService.getOutputReassignedBooking(reassigned);
|
||||||
@@ -485,7 +494,11 @@ export class BookingsService_2024_08_13 {
|
|||||||
throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);
|
throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailsEnabled = booking.eventTypeId ? await this.getEmailsEnabled(booking.eventTypeId) : true;
|
const platformClientParams = booking.eventTypeId
|
||||||
|
? await this.inputService.getOAuthClientParams(booking.eventTypeId)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const emailsEnabled = platformClientParams ? platformClientParams.arePlatformEmailsEnabled : true;
|
||||||
|
|
||||||
await confirmBookingHandler({
|
await confirmBookingHandler({
|
||||||
ctx: {
|
ctx: {
|
||||||
@@ -496,6 +509,7 @@ export class BookingsService_2024_08_13 {
|
|||||||
confirmed: true,
|
confirmed: true,
|
||||||
recurringEventId: booking.recurringEventId,
|
recurringEventId: booking.recurringEventId,
|
||||||
emailsEnabled,
|
emailsEnabled,
|
||||||
|
platformClientParams,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -508,7 +522,11 @@ export class BookingsService_2024_08_13 {
|
|||||||
throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);
|
throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailsEnabled = booking.eventTypeId ? await this.getEmailsEnabled(booking.eventTypeId) : true;
|
const platformClientParams = booking.eventTypeId
|
||||||
|
? await this.inputService.getOAuthClientParams(booking.eventTypeId)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const emailsEnabled = platformClientParams ? platformClientParams.arePlatformEmailsEnabled : true;
|
||||||
|
|
||||||
await confirmBookingHandler({
|
await confirmBookingHandler({
|
||||||
ctx: {
|
ctx: {
|
||||||
@@ -520,6 +538,7 @@ export class BookingsService_2024_08_13 {
|
|||||||
recurringEventId: booking.recurringEventId,
|
recurringEventId: booking.recurringEventId,
|
||||||
reason,
|
reason,
|
||||||
emailsEnabled,
|
emailsEnabled,
|
||||||
|
platformClientParams,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -24,10 +24,10 @@ import { withNextAuth } from "test/utils/withNextAuth";
|
|||||||
|
|
||||||
import { PlatformOAuthClient, Team, Webhook } from "@calcom/prisma/client";
|
import { PlatformOAuthClient, Team, Webhook } from "@calcom/prisma/client";
|
||||||
|
|
||||||
describe("EventTypes WebhooksController (e2e)", () => {
|
describe("OAuth client WebhooksController (e2e)", () => {
|
||||||
let app: INestApplication;
|
let app: INestApplication;
|
||||||
const userEmail = "event-types[email protected]";
|
const userEmail = "oauth-client[email protected]";
|
||||||
const otherUserEmail = "other-event-types[email protected]";
|
const otherUserEmail = "other-oauth-client[email protected]";
|
||||||
let user: UserWithProfile;
|
let user: UserWithProfile;
|
||||||
let otherUser: UserWithProfile;
|
let otherUser: UserWithProfile;
|
||||||
let oAuthClient: PlatformOAuthClient;
|
let oAuthClient: PlatformOAuthClient;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { safeStringify } from "@calcom/lib/safeStringify";
|
|||||||
import type { PrismaClient } from "@calcom/prisma";
|
import type { PrismaClient } from "@calcom/prisma";
|
||||||
import type { SchedulingType } from "@calcom/prisma/enums";
|
import type { SchedulingType } from "@calcom/prisma/enums";
|
||||||
import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||||
|
import type { PlatformClientParams } from "@calcom/prisma/zod-utils";
|
||||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
||||||
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
|
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
|
||||||
@@ -68,8 +69,19 @@ export async function handleConfirmation(args: {
|
|||||||
};
|
};
|
||||||
paid?: boolean;
|
paid?: boolean;
|
||||||
emailsEnabled?: boolean;
|
emailsEnabled?: boolean;
|
||||||
|
platformClientParams?: PlatformClientParams;
|
||||||
}) {
|
}) {
|
||||||
const { user, evt, recurringEventId, prisma, bookingId, booking, paid, emailsEnabled = true } = args;
|
const {
|
||||||
|
user,
|
||||||
|
evt,
|
||||||
|
recurringEventId,
|
||||||
|
prisma,
|
||||||
|
bookingId,
|
||||||
|
booking,
|
||||||
|
paid,
|
||||||
|
emailsEnabled = true,
|
||||||
|
platformClientParams,
|
||||||
|
} = args;
|
||||||
const eventType = booking.eventType;
|
const eventType = booking.eventType;
|
||||||
const eventTypeMetadata = EventTypeMetaDataSchema.parse(eventType?.metadata || {});
|
const eventTypeMetadata = EventTypeMetaDataSchema.parse(eventType?.metadata || {});
|
||||||
const eventManager = new EventManager(user, eventTypeMetadata?.apps);
|
const eventManager = new EventManager(user, eventTypeMetadata?.apps);
|
||||||
@@ -355,6 +367,7 @@ export async function handleConfirmation(args: {
|
|||||||
triggerEvent: WebhookTriggerEvents.BOOKING_CREATED,
|
triggerEvent: WebhookTriggerEvents.BOOKING_CREATED,
|
||||||
teamId,
|
teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId: platformClientParams?.platformClientId,
|
||||||
});
|
});
|
||||||
const subscribersMeetingStarted = await getWebhooks({
|
const subscribersMeetingStarted = await getWebhooks({
|
||||||
userId,
|
userId,
|
||||||
@@ -362,6 +375,7 @@ export async function handleConfirmation(args: {
|
|||||||
triggerEvent: WebhookTriggerEvents.MEETING_STARTED,
|
triggerEvent: WebhookTriggerEvents.MEETING_STARTED,
|
||||||
teamId: eventType?.teamId,
|
teamId: eventType?.teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId: platformClientParams?.platformClientId,
|
||||||
});
|
});
|
||||||
const subscribersMeetingEnded = await getWebhooks({
|
const subscribersMeetingEnded = await getWebhooks({
|
||||||
userId,
|
userId,
|
||||||
@@ -369,6 +383,7 @@ export async function handleConfirmation(args: {
|
|||||||
triggerEvent: WebhookTriggerEvents.MEETING_ENDED,
|
triggerEvent: WebhookTriggerEvents.MEETING_ENDED,
|
||||||
teamId: eventType?.teamId,
|
teamId: eventType?.teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId: platformClientParams?.platformClientId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const scheduleTriggerPromises: Promise<unknown>[] = [];
|
const scheduleTriggerPromises: Promise<unknown>[] = [];
|
||||||
@@ -410,6 +425,7 @@ export async function handleConfirmation(args: {
|
|||||||
eventTypeId: booking.eventTypeId,
|
eventTypeId: booking.eventTypeId,
|
||||||
teamId,
|
teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId: platformClientParams?.platformClientId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const eventTypeInfo: EventTypeInfo = {
|
const eventTypeInfo: EventTypeInfo = {
|
||||||
@@ -429,6 +445,7 @@ export async function handleConfirmation(args: {
|
|||||||
status: "ACCEPTED",
|
status: "ACCEPTED",
|
||||||
smsReminderNumber: booking.smsReminderNumber || undefined,
|
smsReminderNumber: booking.smsReminderNumber || undefined,
|
||||||
metadata: meetingUrl ? { videoCallUrl: meetingUrl } : undefined,
|
metadata: meetingUrl ? { videoCallUrl: meetingUrl } : undefined,
|
||||||
|
...(platformClientParams ? platformClientParams : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const promises = subscribersBookingCreated.map((sub) =>
|
const promises = subscribersBookingCreated.map((sub) =>
|
||||||
@@ -440,7 +457,7 @@ export async function handleConfirmation(args: {
|
|||||||
payload
|
payload
|
||||||
).catch((e) => {
|
).catch((e) => {
|
||||||
log.error(
|
log.error(
|
||||||
`Error executing webhook for event: ${WebhookTriggerEvents.BOOKING_CREATED}, URL: ${sub.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
|
`Error executing webhook for event: ${WebhookTriggerEvents.BOOKING_CREATED}, URL: ${sub.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}, platformClientId: ${platformClientParams?.platformClientId}`,
|
||||||
safeStringify(e)
|
safeStringify(e)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -456,6 +473,7 @@ export async function handleConfirmation(args: {
|
|||||||
triggerEvent: WebhookTriggerEvents.BOOKING_PAID,
|
triggerEvent: WebhookTriggerEvents.BOOKING_PAID,
|
||||||
teamId: eventType?.teamId,
|
teamId: eventType?.teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId: platformClientParams?.platformClientId,
|
||||||
});
|
});
|
||||||
const bookingWithPayment = await prisma.booking.findFirst({
|
const bookingWithPayment = await prisma.booking.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
|||||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
import { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||||
|
import type { PlatformClientParams } from "@calcom/prisma/zod-utils";
|
||||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
||||||
import type { AdditionalInformation, AppsStatus, CalendarEvent, Person } from "@calcom/types/Calendar";
|
import type { AdditionalInformation, AppsStatus, CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||||
@@ -339,14 +340,10 @@ function buildTroubleshooterData({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handler(
|
async function handler(
|
||||||
req: NextApiRequest & {
|
req: NextApiRequest &
|
||||||
userId?: number | undefined;
|
PlatformClientParams & {
|
||||||
platformClientId?: string;
|
userId?: number | undefined;
|
||||||
platformRescheduleUrl?: string;
|
},
|
||||||
platformCancelUrl?: string;
|
|
||||||
platformBookingUrl?: string;
|
|
||||||
platformBookingLocation?: string;
|
|
||||||
},
|
|
||||||
bookingDataSchemaGetter: BookingDataSchemaGetter = getBookingDataSchema
|
bookingDataSchemaGetter: BookingDataSchemaGetter = getBookingDataSchema
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ type ScheduleNoShowTriggersArgs = {
|
|||||||
eventTypeId: number | null;
|
eventTypeId: number | null;
|
||||||
teamId?: number | null;
|
teamId?: number | null;
|
||||||
orgId?: number | null;
|
orgId?: number | null;
|
||||||
|
oAuthClientId?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => {
|
export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => {
|
||||||
const { booking, triggerForUser, organizerUser, eventTypeId, teamId, orgId } = args;
|
const { booking, triggerForUser, organizerUser, eventTypeId, teamId, orgId, oAuthClientId } = args;
|
||||||
|
|
||||||
// Add task for automatic no show in cal video
|
// Add task for automatic no show in cal video
|
||||||
const noShowPromises: Promise<any>[] = [];
|
const noShowPromises: Promise<any>[] = [];
|
||||||
@@ -27,6 +28,7 @@ export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) =
|
|||||||
triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW,
|
triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW,
|
||||||
teamId,
|
teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId,
|
||||||
});
|
});
|
||||||
|
|
||||||
noShowPromises.push(
|
noShowPromises.push(
|
||||||
@@ -56,6 +58,7 @@ export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) =
|
|||||||
triggerEvent: WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW,
|
triggerEvent: WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW,
|
||||||
teamId,
|
teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId,
|
||||||
});
|
});
|
||||||
|
|
||||||
noShowPromises.push(
|
noShowPromises.push(
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
|||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
import { WorkflowActions, WorkflowMethods, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
import { WorkflowActions, WorkflowMethods, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
import type { EventTypeMetadata, PlatformClientParams } from "@calcom/prisma/zod-utils";
|
||||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||||
|
|
||||||
import { handleRescheduleEventManager } from "./handleRescheduleEventManager";
|
import { handleRescheduleEventManager } from "./handleRescheduleEventManager";
|
||||||
@@ -49,6 +49,7 @@ export const roundRobinManualReassignment = async ({
|
|||||||
reassignReason,
|
reassignReason,
|
||||||
reassignedById,
|
reassignedById,
|
||||||
emailsEnabled = true,
|
emailsEnabled = true,
|
||||||
|
platformClientParams,
|
||||||
}: {
|
}: {
|
||||||
bookingId: number;
|
bookingId: number;
|
||||||
newUserId: number;
|
newUserId: number;
|
||||||
@@ -56,6 +57,7 @@ export const roundRobinManualReassignment = async ({
|
|||||||
reassignReason?: string;
|
reassignReason?: string;
|
||||||
reassignedById: number;
|
reassignedById: number;
|
||||||
emailsEnabled?: boolean;
|
emailsEnabled?: boolean;
|
||||||
|
platformClientParams?: PlatformClientParams;
|
||||||
}) => {
|
}) => {
|
||||||
const roundRobinReassignLogger = logger.getSubLogger({
|
const roundRobinReassignLogger = logger.getSubLogger({
|
||||||
prefix: ["roundRobinManualReassign", `${bookingId}`],
|
prefix: ["roundRobinManualReassign", `${bookingId}`],
|
||||||
@@ -264,6 +266,7 @@ export const roundRobinManualReassignment = async ({
|
|||||||
booking,
|
booking,
|
||||||
}),
|
}),
|
||||||
location: bookingLocation,
|
location: bookingLocation,
|
||||||
|
...(platformClientParams ? platformClientParams : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const credentials = await prisma.credential.findMany({
|
const credentials = await prisma.credential.findMany({
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
|||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
import { WorkflowActions, WorkflowMethods, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
import { WorkflowActions, WorkflowMethods, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
import type { EventTypeMetadata, PlatformClientParams } from "@calcom/prisma/zod-utils";
|
||||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||||
|
|
||||||
import { handleRescheduleEventManager } from "./handleRescheduleEventManager";
|
import { handleRescheduleEventManager } from "./handleRescheduleEventManager";
|
||||||
@@ -42,10 +42,12 @@ export const roundRobinReassignment = async ({
|
|||||||
bookingId,
|
bookingId,
|
||||||
orgId,
|
orgId,
|
||||||
emailsEnabled = true,
|
emailsEnabled = true,
|
||||||
|
platformClientParams,
|
||||||
}: {
|
}: {
|
||||||
bookingId: number;
|
bookingId: number;
|
||||||
orgId: number | null;
|
orgId: number | null;
|
||||||
emailsEnabled?: boolean;
|
emailsEnabled?: boolean;
|
||||||
|
platformClientParams?: PlatformClientParams;
|
||||||
}) => {
|
}) => {
|
||||||
const roundRobinReassignLogger = logger.getSubLogger({
|
const roundRobinReassignLogger = logger.getSubLogger({
|
||||||
prefix: ["roundRobinReassign", `${bookingId}`],
|
prefix: ["roundRobinReassign", `${bookingId}`],
|
||||||
@@ -294,6 +296,7 @@ export const roundRobinReassignment = async ({
|
|||||||
booking,
|
booking,
|
||||||
}),
|
}),
|
||||||
location: bookingLocation,
|
location: bookingLocation,
|
||||||
|
...(platformClientParams ? platformClientParams : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const credentials = await prisma.credential.findMany({
|
const credentials = await prisma.credential.findMany({
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { getTranslation } from "@calcom/lib/server/i18n";
|
|||||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
import { WebhookTriggerEvents } from "@calcom/prisma/client";
|
import { WebhookTriggerEvents } from "@calcom/prisma/client";
|
||||||
|
import type { PlatformClientParams } from "@calcom/prisma/zod-utils";
|
||||||
import type { TNoShowInputSchema } from "@calcom/trpc/server/routers/loggedInViewer/markNoShow.schema";
|
import type { TNoShowInputSchema } from "@calcom/trpc/server/routers/loggedInViewer/markNoShow.schema";
|
||||||
|
|
||||||
import handleSendingAttendeeNoShowDataToApps from "./noShow/handleSendingAttendeeNoShowDataToApps";
|
import handleSendingAttendeeNoShowDataToApps from "./noShow/handleSendingAttendeeNoShowDataToApps";
|
||||||
@@ -82,7 +83,12 @@ const handleMarkNoShow = async ({
|
|||||||
noShowHost,
|
noShowHost,
|
||||||
userId,
|
userId,
|
||||||
locale,
|
locale,
|
||||||
}: TNoShowInputSchema & { userId?: number; locale?: string }) => {
|
platformClientParams,
|
||||||
|
}: TNoShowInputSchema & {
|
||||||
|
userId?: number;
|
||||||
|
locale?: string;
|
||||||
|
platformClientParams?: PlatformClientParams;
|
||||||
|
}) => {
|
||||||
const responsePayload = new ResponsePayload();
|
const responsePayload = new ResponsePayload();
|
||||||
const t = await getTranslation(locale ?? "en", "common");
|
const t = await getTranslation(locale ?? "en", "common");
|
||||||
|
|
||||||
@@ -94,13 +100,17 @@ const handleMarkNoShow = async ({
|
|||||||
|
|
||||||
const payload = await buildResultPayload(bookingUid, attendeeEmails, attendees, t);
|
const payload = await buildResultPayload(bookingUid, attendeeEmails, attendees, t);
|
||||||
|
|
||||||
const { webhooks, bookingId } = await getWebhooksService(bookingUid);
|
const { webhooks, bookingId } = await getWebhooksService(
|
||||||
|
bookingUid,
|
||||||
|
platformClientParams?.platformClientId
|
||||||
|
);
|
||||||
|
|
||||||
await webhooks.sendPayload({
|
await webhooks.sendPayload({
|
||||||
...payload,
|
...payload,
|
||||||
/** We send webhook message pre-translated, on client we already handle this */
|
/** We send webhook message pre-translated, on client we already handle this */
|
||||||
bookingUid,
|
bookingUid,
|
||||||
bookingId,
|
bookingId,
|
||||||
|
...(platformClientParams ? platformClientParams : {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
responsePayload.setAttendees(payload.attendees);
|
responsePayload.setAttendees(payload.attendees);
|
||||||
@@ -179,7 +189,7 @@ const updateAttendees = async (
|
|||||||
.map((x) => ({ email: x.email, noShow: x.noShow }));
|
.map((x) => ({ email: x.email, noShow: x.noShow }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getWebhooksService = async (bookingUid: string) => {
|
const getWebhooksService = async (bookingUid: string, platformClientId?: string) => {
|
||||||
const booking = await prisma.booking.findUnique({
|
const booking = await prisma.booking.findUnique({
|
||||||
where: { uid: bookingUid },
|
where: { uid: bookingUid },
|
||||||
select: {
|
select: {
|
||||||
@@ -204,6 +214,7 @@ const getWebhooksService = async (bookingUid: string) => {
|
|||||||
eventTypeId: booking?.eventType?.id,
|
eventTypeId: booking?.eventType?.id,
|
||||||
orgId,
|
orgId,
|
||||||
triggerEvent: WebhookTriggerEvents.BOOKING_NO_SHOW_UPDATED,
|
triggerEvent: WebhookTriggerEvents.BOOKING_NO_SHOW_UPDATED,
|
||||||
|
oAuthClientId: platformClientId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { webhooks, bookingId: booking?.id };
|
return { webhooks, bookingId: booking?.id };
|
||||||
|
|||||||
@@ -276,12 +276,23 @@ export const requiredCustomInputSchema = z.union([
|
|||||||
|
|
||||||
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
||||||
|
|
||||||
|
const PlatformClientParamsSchema = z.object({
|
||||||
|
platformClientId: z.string().optional(),
|
||||||
|
platformRescheduleUrl: z.string().nullable().optional(),
|
||||||
|
platformCancelUrl: z.string().nullable().optional(),
|
||||||
|
platformBookingUrl: z.string().nullable().optional(),
|
||||||
|
platformBookingLocation: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type PlatformClientParams = z.infer<typeof PlatformClientParamsSchema>;
|
||||||
|
|
||||||
export const bookingConfirmPatchBodySchema = z.object({
|
export const bookingConfirmPatchBodySchema = z.object({
|
||||||
bookingId: z.number(),
|
bookingId: z.number(),
|
||||||
confirmed: z.boolean(),
|
confirmed: z.boolean(),
|
||||||
recurringEventId: z.string().optional(),
|
recurringEventId: z.string().optional(),
|
||||||
reason: z.string().optional(),
|
reason: z.string().optional(),
|
||||||
emailsEnabled: z.boolean().default(true),
|
emailsEnabled: z.boolean().default(true),
|
||||||
|
platformClientParams: PlatformClientParamsSchema.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// `responses` is merged with it during handleNewBooking call because `responses` schema is dynamic and depends on eventType
|
// `responses` is merged with it during handleNewBooking call because `responses` schema is dynamic and depends on eventType
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventR
|
|||||||
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
|
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
|
||||||
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
||||||
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
|
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
|
||||||
|
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||||
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||||
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
|
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
|
||||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||||
@@ -41,7 +42,14 @@ type ConfirmOptions = {
|
|||||||
|
|
||||||
export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||||
const { user } = ctx;
|
const { user } = ctx;
|
||||||
const { bookingId, recurringEventId, reason: rejectionReason, confirmed, emailsEnabled } = input;
|
const {
|
||||||
|
bookingId,
|
||||||
|
recurringEventId,
|
||||||
|
reason: rejectionReason,
|
||||||
|
confirmed,
|
||||||
|
emailsEnabled,
|
||||||
|
platformClientParams,
|
||||||
|
} = input;
|
||||||
|
|
||||||
const tOrganizer = await getTranslation(user.locale ?? "en", "common");
|
const tOrganizer = await getTranslation(user.locale ?? "en", "common");
|
||||||
|
|
||||||
@@ -214,6 +222,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
|||||||
members: [],
|
members: [],
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
...(platformClientParams ? platformClientParams : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const recurringEvent = parseRecurringEvent(booking.eventType?.recurringEvent);
|
const recurringEvent = parseRecurringEvent(booking.eventType?.recurringEvent);
|
||||||
@@ -270,6 +279,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
|||||||
bookingId,
|
bookingId,
|
||||||
booking,
|
booking,
|
||||||
emailsEnabled,
|
emailsEnabled,
|
||||||
|
platformClientParams,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
evt.rejectionReason = rejectionReason;
|
evt.rejectionReason = rejectionReason;
|
||||||
@@ -383,12 +393,13 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
|||||||
const orgId = await getOrgIdFromMemberOrTeamId({ memberId: booking.userId, teamId });
|
const orgId = await getOrgIdFromMemberOrTeamId({ memberId: booking.userId, teamId });
|
||||||
|
|
||||||
// send BOOKING_REJECTED webhooks
|
// send BOOKING_REJECTED webhooks
|
||||||
const subscriberOptions = {
|
const subscriberOptions: GetSubscriberOptions = {
|
||||||
userId: booking.userId,
|
userId: booking.userId,
|
||||||
eventTypeId: booking.eventTypeId,
|
eventTypeId: booking.eventTypeId,
|
||||||
triggerEvent: WebhookTriggerEvents.BOOKING_REJECTED,
|
triggerEvent: WebhookTriggerEvents.BOOKING_REJECTED,
|
||||||
teamId,
|
teamId,
|
||||||
orgId,
|
orgId,
|
||||||
|
oAuthClientId: platformClientParams?.platformClientId,
|
||||||
};
|
};
|
||||||
const eventTrigger: WebhookTriggerEvents = WebhookTriggerEvents.BOOKING_REJECTED;
|
const eventTrigger: WebhookTriggerEvents = WebhookTriggerEvents.BOOKING_REJECTED;
|
||||||
const eventTypeInfo: EventTypeInfo = {
|
const eventTypeInfo: EventTypeInfo = {
|
||||||
|
|||||||
Reference in new issue
Block a user