feat: add webhook versioning (#23861)
* add webhook version schema * version the code * update version from numeric to date val * migration * update schema and build factory * update string * move version picker * tooltip instead of infobadge * -- * fix type * -- * fix type * fix type * -- * fix messed up merge * improvements to payloadfactory * extract version off of DB and instead keep it in IWebhookRepository * fix webhookform * fix type safety and routing ambiguity * scalable with easier factory extensions and base definition * fix types * -- * -- * clean up prisma/client type imports * fix * type fix * type fix * cleanup * add tests and registry changes * unintended file inclusion * type-fix * select in repo * -- * explicit return type * -- * fix type * fixes * feedback 1 * feedback 2 * use enum instead of string * fixes
This commit is contained in:
1 parent
42bd4b4057
commit
056922b6ee
71 files changed
+3319
-1002
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { WEBHOOK_TRIGGER_EVENTS } from "@calcom/features/webhooks/lib/constants";
|
||||
import { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
|
||||
import { WebhookSchema } from "@calcom/prisma/zod/modelSchema/WebhookSchema";
|
||||
|
||||
const schemaWebhookBaseBodyParams = WebhookSchema.pick({
|
||||
@@ -21,6 +22,7 @@ export const schemaWebhookCreateParams = z
|
||||
eventTypeId: z.number().optional(),
|
||||
userId: z.number().optional(),
|
||||
secret: z.string().optional().nullable(),
|
||||
version: z.nativeEnum(WebhookVersion).optional(),
|
||||
// API shouldn't mess with Apps webhooks yet (ie. Zapier)
|
||||
// appId: z.string().optional().nullable(),
|
||||
})
|
||||
@@ -33,6 +35,7 @@ export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams
|
||||
z.object({
|
||||
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(),
|
||||
secret: z.string().optional().nullable(),
|
||||
version: z.nativeEnum(WebhookVersion).optional(),
|
||||
})
|
||||
)
|
||||
.partial()
|
||||
@@ -44,6 +47,7 @@ export const schemaWebhookReadPublic = WebhookSchema.pick({
|
||||
eventTypeId: true,
|
||||
payloadTemplate: true,
|
||||
eventTriggers: true,
|
||||
version: true,
|
||||
// FIXME: We have some invalid urls saved in the DB
|
||||
// subscriberUrl: true,
|
||||
/** @todo: find out how to properly add back and validate those. */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ApiProperty, ApiPropertyOptional, PartialType } from "@nestjs/swagger";
|
||||
import { IsArray, IsBoolean, IsEnum, IsOptional, IsString } from "class-validator";
|
||||
|
||||
import { WebhookTriggerEvents } from "@calcom/platform-libraries";
|
||||
import { WebhookTriggerEvents, WebhookVersion } from "@calcom/platform-libraries";
|
||||
|
||||
export class CreateWebhookInputDto {
|
||||
@IsString()
|
||||
@@ -48,6 +48,15 @@ export class CreateWebhookInputDto {
|
||||
@IsOptional()
|
||||
@ApiPropertyOptional()
|
||||
secret?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(WebhookVersion)
|
||||
@ApiPropertyOptional({
|
||||
description: "The version of the webhook",
|
||||
example: WebhookVersion.V_2021_10_20,
|
||||
enum: WebhookVersion,
|
||||
})
|
||||
version?: WebhookVersion;
|
||||
}
|
||||
|
||||
export class UpdateWebhookInputDto extends PartialType(CreateWebhookInputDto) {}
|
||||
+2
-11
@@ -1,7 +1,6 @@
|
||||
import type { PageProps } from "app/_types";
|
||||
import { _generateMetadata, getTranslate } from "app/_utils";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
|
||||
import SettingsHeaderWithBackButton from "@calcom/features/settings/appDir/SettingsHeaderWithBackButton";
|
||||
import { WebhookRepository } from "@calcom/features/webhooks/lib/repository/WebhookRepository";
|
||||
import { EditWebhookView } from "@calcom/features/webhooks/pages/webhook-edit-view";
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
@@ -16,21 +15,13 @@ export const generateMetadata = async ({ params }: { params: Promise<{ id: strin
|
||||
);
|
||||
|
||||
const Page = async ({ params: _params }: PageProps) => {
|
||||
const t = await getTranslate();
|
||||
const params = await _params;
|
||||
const id = typeof params?.id === "string" ? params.id : undefined;
|
||||
|
||||
const webhookRepository = WebhookRepository.getInstance();
|
||||
const webhook = await webhookRepository.findByWebhookId(id);
|
||||
|
||||
return (
|
||||
<SettingsHeaderWithBackButton
|
||||
title={t("edit_webhook")}
|
||||
description={t("add_webhook_description", { appName: APP_NAME })}
|
||||
borderInShellHeader={true}>
|
||||
<EditWebhookView webhook={webhook} />
|
||||
</SettingsHeaderWithBackButton>
|
||||
);
|
||||
return <EditWebhookView webhook={webhook} />;
|
||||
};
|
||||
|
||||
export default Page;
|
||||
@@ -2,6 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
|
||||
import type { ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import type { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
|
||||
|
||||
type Input = {
|
||||
active: boolean;
|
||||
@@ -19,6 +20,7 @@ type Output = {
|
||||
triggers: WebhookTriggerEvents[];
|
||||
secret?: string;
|
||||
payloadTemplate: string | undefined | null;
|
||||
version?: WebhookVersion;
|
||||
};
|
||||
|
||||
export const useOAuthClientWebhooks = (clientId: string) => {
|
||||
|
||||
+9
-2
@@ -6,6 +6,7 @@ import { useRouter } from "next/navigation";
|
||||
import Shell from "@calcom/features/shell/Shell";
|
||||
import { WebhookForm } from "@calcom/features/webhooks/components";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { DEFAULT_WEBHOOK_VERSION } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
@@ -82,6 +83,7 @@ export default function EditOAuthClientWebhooks() {
|
||||
subscriberUrl: data.subscriberUrl,
|
||||
triggers: data.eventTriggers,
|
||||
secret: data.secret ?? undefined,
|
||||
version: data.version,
|
||||
};
|
||||
if (webhook) {
|
||||
await updateWebhook({
|
||||
@@ -95,7 +97,7 @@ export default function EditOAuthClientWebhooks() {
|
||||
}
|
||||
await refetchWebhooks();
|
||||
router.push("/settings/platform/");
|
||||
} catch (err) {
|
||||
} catch {
|
||||
showToast(t(webhookId ? "webhook_update_failed" : "webhook_create_failed"), "error");
|
||||
}
|
||||
}}
|
||||
@@ -105,7 +107,12 @@ export default function EditOAuthClientWebhooks() {
|
||||
noRoutingFormTriggers={true}
|
||||
webhook={
|
||||
webhook
|
||||
? { ...webhook, eventTriggers: webhook.triggers, secret: webhook.secret ?? null }
|
||||
? {
|
||||
...webhook,
|
||||
eventTriggers: webhook.triggers,
|
||||
secret: webhook.secret ?? null,
|
||||
version: webhook.version ?? DEFAULT_WEBHOOK_VERSION,
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -3835,6 +3835,7 @@
|
||||
"webhook_attendee_email": "Email of the first attendee",
|
||||
"webhook_attendee_timezone": "Timezone of the first attendee",
|
||||
"webhook_attendee_locale": "Locale of the first attendee",
|
||||
"webhook_version": "Webhook Version",
|
||||
"webhook_team_name": "Name of the team booked",
|
||||
"webhook_team_members": "Members of the team booked",
|
||||
"webhook_video_call_url": "Video call URL for the meeting",
|
||||
|
||||
Reference in new issue
Block a user