Skip to content

Scheduling infrastructure for absolutely everyone.

fix: importing from @calcom/emails exposed daily-video api route to client code (#19994)

Benny Joo495ac74255cc
diff --git a/apps/web/app/api/recorded-daily-video/route.ts b/apps/web/app/api/recorded-daily-video/route.ts
index ee9b6b2884f..fd583fd1856 100644
--- a/apps/web/app/api/recorded-daily-video/route.ts
+++ b/apps/web/app/api/recorded-daily-video/route.ts
@@ -5,8 +5,10 @@ import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { getRoomNameFromRecordingId, getBatchProcessorJobAccessLink } from "@calcom/app-store/dailyvideo/lib";
-import { sendDailyVideoRecordingEmails } from "@calcom/emails";
-import { sendDailyVideoTranscriptEmails } from "@calcom/emails";
+import {
+ sendDailyVideoRecordingEmails,
+ sendDailyVideoTranscriptEmails,
+} from "@calcom/emails/daily-video-emails";
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
import { HttpError } from "@calcom/lib/http-error";
import logger from "@calcom/lib/logger";
diff --git a/packages/emails/daily-video-emails.ts b/packages/emails/daily-video-emails.ts
new file mode 100644
index 00000000000..84287f71920
--- /dev/null
+++ b/packages/emails/daily-video-emails.ts
@@ -0,0 +1,49 @@
+// It's ensured that this file does not import any client-side code
+import type BaseEmail from "@calcom/emails/templates/_base-email";
+import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
+import type { CalendarEvent } from "@calcom/types/Calendar";
+
+import AttendeeDailyVideoDownloadRecordingEmail from "./templates/attendee-daily-video-download-recording-email";
+import AttendeeDailyVideoDownloadTranscriptEmail from "./templates/attendee-daily-video-download-transcript-email";
+import OrganizerDailyVideoDownloadRecordingEmail from "./templates/organizer-daily-video-download-recording-email";
+import OrganizerDailyVideoDownloadTranscriptEmail from "./templates/organizer-daily-video-download-transcript-email";
+
+const sendEmail = (prepare: () => BaseEmail) => {
+ return new Promise((resolve, reject) => {
+ try {
+ const email = prepare();
+ resolve(email.sendEmail());
+ } catch (e) {
+ reject(console.error(`${prepare.constructor.name}.sendEmail failed`, e));
+ }
+ });
+};
+
+export const sendDailyVideoTranscriptEmails = async (calEvent: CalendarEvent, transcripts: string[]) => {
+ const emailsToSend: Promise<unknown>[] = [];
+
+ emailsToSend.push(sendEmail(() => new OrganizerDailyVideoDownloadTranscriptEmail(calEvent, transcripts)));
+
+ for (const attendee of calEvent.attendees) {
+ emailsToSend.push(
+ sendEmail(() => new AttendeeDailyVideoDownloadTranscriptEmail(calEvent, attendee, transcripts))
+ );
+ }
+ await Promise.all(emailsToSend);
+};
+
+export const sendDailyVideoRecordingEmails = async (calEvent: CalendarEvent, downloadLink: string) => {
+ const calendarEvent = formatCalEvent(calEvent);
+ const emailsToSend: Promise<unknown>[] = [];
+
+ emailsToSend.push(
+ sendEmail(() => new OrganizerDailyVideoDownloadRecordingEmail(calendarEvent, downloadLink))
+ );
+
+ for (const attendee of calendarEvent.attendees) {
+ emailsToSend.push(
+ sendEmail(() => new AttendeeDailyVideoDownloadRecordingEmail(calendarEvent, attendee, downloadLink))
+ );
+ }
+ await Promise.all(emailsToSend);
+};