* refactor: apply biome formatting to packages/features (batch 1 - small subdirs) Format small subdirectories in packages/features: di, flags, holidays, oauth, settings, users, assignment-reason, selectedCalendar, hashedLink, host, form, form-builder, availability, data-table, pbac, schedules, troubleshooter, eventtypes, calendar-subscription, and root-level files. Also includes straggler apps/web BookEventForm.tsx. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 2 - medium subdirs) Format medium subdirectories in packages/features: auth, credentials, calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone, tasker, and webhooks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 3 - bookings + insights) Format bookings and insights subdirectories in packages/features. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 4 - ee) Format packages/features/ee subdirectory covering billing, workflows, organizations, teams, managed-event-types, round-robin, dsync, integration-attribute-sync, and payments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1) Format booking-audit di, actions, common, dto, repository, and types subdirectories in packages/features/booking-audit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2) Format booking-audit service subdirectory in packages/features/booking-audit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
102 lines
3.2 KiB
TypeScript
102 lines
3.2 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import type { FORM_SUBMITTED_WEBHOOK_RESPONSES } from "@calcom/app-store/routing-forms/lib/formSubmissionUtils";
|
|
import incompleteBookingActionFunctions from "@calcom/app-store/routing-forms/lib/incompleteBooking/actionFunctions";
|
|
import {
|
|
DEFAULT_WEBHOOK_VERSION,
|
|
WebhookVersion,
|
|
} from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
|
|
import { sendGenericWebhookPayload } from "@calcom/features/webhooks/lib/sendPayload";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { getSubmitterEmail, shouldTriggerFormSubmittedNoEvent } from "./formSubmissionValidation";
|
|
|
|
export type ResponseData = {
|
|
responseId: number;
|
|
responses: FORM_SUBMITTED_WEBHOOK_RESPONSES;
|
|
form: { id: string; name: string; teamId: number | null };
|
|
redirect?: {
|
|
type: "customPageMessage" | "externalRedirectUrl" | "eventTypeRedirectUrl";
|
|
value: string;
|
|
};
|
|
};
|
|
|
|
export const ZTriggerFormSubmittedNoEventWebhookPayloadSchema = z.object({
|
|
webhook: z.object({
|
|
subscriberUrl: z.string().url(),
|
|
appId: z.string().nullable(),
|
|
payloadTemplate: z.string().nullable(),
|
|
secret: z.string().nullable(),
|
|
version: z.nativeEnum(WebhookVersion).optional(),
|
|
}),
|
|
responseId: z.number(),
|
|
responses: z.any(),
|
|
redirect: z
|
|
.object({
|
|
type: z.enum(["customPageMessage", "externalRedirectUrl", "eventTypeRedirectUrl"]),
|
|
value: z.string(),
|
|
})
|
|
.optional(),
|
|
form: z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
teamId: z.number().nullable(),
|
|
}),
|
|
});
|
|
|
|
export async function triggerFormSubmittedNoEventWebhook(payload: string): Promise<void> {
|
|
const { webhook, responseId, form, redirect, responses } =
|
|
ZTriggerFormSubmittedNoEventWebhookPayloadSchema.parse(JSON.parse(payload));
|
|
|
|
const shouldTrigger = await shouldTriggerFormSubmittedNoEvent({
|
|
formId: form.id,
|
|
responses: responses as FORM_SUBMITTED_WEBHOOK_RESPONSES,
|
|
responseId,
|
|
});
|
|
|
|
if (!shouldTrigger) return;
|
|
|
|
await sendGenericWebhookPayload({
|
|
secretKey: webhook.secret,
|
|
triggerEvent: "FORM_SUBMITTED_NO_EVENT",
|
|
createdAt: new Date().toISOString(),
|
|
webhook: {
|
|
subscriberUrl: webhook.subscriberUrl,
|
|
appId: webhook.appId,
|
|
payloadTemplate: webhook.payloadTemplate,
|
|
version: webhook.version ?? DEFAULT_WEBHOOK_VERSION,
|
|
},
|
|
data: {
|
|
formId: form.id,
|
|
formName: form.name,
|
|
teamId: form.teamId,
|
|
redirect,
|
|
responseId,
|
|
responses: responses as FORM_SUBMITTED_WEBHOOK_RESPONSES,
|
|
},
|
|
}).catch((e) => {
|
|
console.error(`Error executing FORM_SUBMITTED_NO_EVENT webhook`, webhook, e);
|
|
});
|
|
|
|
// See if there are other incomplete booking actions
|
|
const incompleteBookingActions = await prisma.app_RoutingForms_IncompleteBookingActions.findMany({
|
|
where: {
|
|
formId: form.id,
|
|
},
|
|
});
|
|
|
|
if (incompleteBookingActions) {
|
|
for (const incompleteBookingAction of incompleteBookingActions) {
|
|
const actionType = incompleteBookingAction.actionType;
|
|
|
|
// Get action function
|
|
const bookingActionFunction = incompleteBookingActionFunctions[actionType];
|
|
|
|
const emailValue = getSubmitterEmail(responses as FORM_SUBMITTED_WEBHOOK_RESPONSES);
|
|
if (emailValue) {
|
|
await bookingActionFunction(incompleteBookingAction, emailValue);
|
|
}
|
|
}
|
|
}
|
|
}
|