feat(webhooks): pass webhook secret to `testTrigger` (#12187)

This commit is contained in:
JA 2023-11-22 14:17:50 -05:00 committed by GitHub
parent 1de05ebf3d
commit 7ee035c3a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -6,7 +6,7 @@ import { Badge, Button, showToast } from "@calcom/ui";
import { Activity } from "@calcom/ui/components/icon";
export default function WebhookTestDisclosure() {
const subscriberUrl: string = useWatch({ name: "subscriberUrl" });
const [subscriberUrl, webhookSecret]: [string, string] = useWatch({ name: ["subscriberUrl", "secret"] });
const payloadTemplate = useWatch({ name: "payloadTemplate" }) || null;
const { t } = useLocale();
const mutation = trpc.viewer.webhook.testTrigger.useMutation({
@ -27,7 +27,9 @@ export default function WebhookTestDisclosure() {
color="secondary"
disabled={mutation.isLoading || !subscriberUrl}
StartIcon={Activity}
onClick={() => mutation.mutate({ url: subscriberUrl, type: "PING", payloadTemplate })}>
onClick={() =>
mutation.mutate({ url: subscriberUrl, secret: webhookSecret, type: "PING", payloadTemplate })
}>
{t("ping_test")}
</Button>
</div>

View File

@ -10,7 +10,7 @@ type TestTriggerOptions = {
};
export const testTriggerHandler = async ({ ctx: _ctx, input }: TestTriggerOptions) => {
const { url, type, payloadTemplate = null } = input;
const { url, type, payloadTemplate = null, secret = null } = input;
const translation = await getTranslation("en", "common");
const language = {
locale: "en",
@ -40,8 +40,8 @@ export const testTriggerHandler = async ({ ctx: _ctx, input }: TestTriggerOption
};
try {
const webhook = { subscriberUrl: url, payloadTemplate, appId: null, secret: null };
return await sendPayload(null, type, new Date().toISOString(), webhook, data);
const webhook = { subscriberUrl: url, appId: null, payloadTemplate };
return await sendPayload(secret, type, new Date().toISOString(), webhook, data);
} catch (_err) {
const error = getErrorFromUnknown(_err);
return {

View File

@ -4,6 +4,7 @@ import { webhookIdAndEventTypeIdSchema } from "./types";
export const ZTestTriggerInputSchema = webhookIdAndEventTypeIdSchema.extend({
url: z.string().url(),
secret: z.string().optional(),
type: z.string(),
payloadTemplate: z.string().optional().nullable(),
});