From b9c5590a4795ab8632a41a341fefcaae723d8750 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 11:20:49 +0530 Subject: [PATCH 01/11] Updated webhook validations --- lib/validations/webhook.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 40aec5c288..86b811739c 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,9 +1,15 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; +import { WebhookTriggerEvents } from "@calcom/prisma/client"; + +export const WEBHOOK_TRIGGER_EVENTS = [ + WebhookTriggerEvents.BOOKING_CANCELLED, + WebhookTriggerEvents.BOOKING_CREATED, + WebhookTriggerEvents.BOOKING_RESCHEDULED, +] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; const schemaWebhookBaseBodyParams = Webhook.pick({ - id: true, userId: true, eventTypeId: true, eventTriggers: true, @@ -14,12 +20,12 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ - userId: z.number().or(z.string()).optional(), - eventTypeId: z.number().or(z.string()).optional(), - eventTriggers: z.any().optional(), - active: z.boolean().optional(), - subscriberUrl: z.string(), - payloadTemplate: z.string().optional(), + subscriberUrl: z.string().url(), + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), + active: z.boolean(), + payloadTemplate: z.string().nullable(), + eventTypeId: z.number().optional(), + appId: z.string().optional().nullable(), }) .strict(); @@ -30,8 +36,8 @@ export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ payloadTemplate: z.string().optional(), - /** @todo: don't use any here and validate eventTriggers proper */ - eventTriggers: z.any(), + /** @todo: don't use 'any' here and validate eventTriggers proper */ + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(), subscriberUrl: z.string().optional(), }) ); From 4737778dc1e3b360df0aa2797a40c7e6fc36a72e Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 11:41:36 +0530 Subject: [PATCH 02/11] Debug create err --- lib/validations/webhook.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 86b811739c..b228f47e42 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,13 +1,13 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; -import { WebhookTriggerEvents } from "@calcom/prisma/client"; +// import { WebhookTriggerEvents } from "@calcom/prisma/client"; -export const WEBHOOK_TRIGGER_EVENTS = [ - WebhookTriggerEvents.BOOKING_CANCELLED, - WebhookTriggerEvents.BOOKING_CREATED, - WebhookTriggerEvents.BOOKING_RESCHEDULED, -] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; +// export const WEBHOOK_TRIGGER_EVENTS = [ +// WebhookTriggerEvents.BOOKING_CANCELLED, +// WebhookTriggerEvents.BOOKING_CREATED, +// WebhookTriggerEvents.BOOKING_RESCHEDULED, +// ] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; const schemaWebhookBaseBodyParams = Webhook.pick({ userId: true, @@ -21,7 +21,7 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ subscriberUrl: z.string().url(), - eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), + eventTriggers: z.any(), active: z.boolean(), payloadTemplate: z.string().nullable(), eventTypeId: z.number().optional(), @@ -37,7 +37,7 @@ export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ payloadTemplate: z.string().optional(), /** @todo: don't use 'any' here and validate eventTriggers proper */ - eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(), + eventTriggers: z.any().optional(), subscriberUrl: z.string().optional(), }) ); From d372c4c526f9a537ae90df45161a9b8292f54e4b Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:03:14 +0530 Subject: [PATCH 03/11] more debug --- lib/validations/webhook.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index b228f47e42..48665c61d1 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -21,9 +21,9 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ subscriberUrl: z.string().url(), - eventTriggers: z.any(), + eventTriggers: z.string().array(), active: z.boolean(), - payloadTemplate: z.string().nullable(), + payloadTemplate: z.string().optional().nullable(), eventTypeId: z.number().optional(), appId: z.string().optional().nullable(), }) From 92b011214cbd8eb29932ab2dfd50bda1d0b8f5a8 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:06:15 +0530 Subject: [PATCH 04/11] More debug --- lib/validations/webhook.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 48665c61d1..44f433b3c1 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -21,11 +21,11 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ subscriberUrl: z.string().url(), - eventTriggers: z.string().array(), + eventTriggers: z.any(), active: z.boolean(), - payloadTemplate: z.string().optional().nullable(), - eventTypeId: z.number().optional(), - appId: z.string().optional().nullable(), +// payloadTemplate: z.string().optional().nullable(), +// eventTypeId: z.number().optional(), +// appId: z.string().optional().nullable(), }) .strict(); From 5e3b51c6217c2c301c7b1c5393219f0ee70a36ed Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:12:13 +0530 Subject: [PATCH 05/11] added ID --- lib/validations/webhook.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 44f433b3c1..f523c4c71e 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,15 +1,16 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; -// import { WebhookTriggerEvents } from "@calcom/prisma/client"; +import { WebhookTriggerEvents } from "@calcom/prisma/client"; -// export const WEBHOOK_TRIGGER_EVENTS = [ -// WebhookTriggerEvents.BOOKING_CANCELLED, -// WebhookTriggerEvents.BOOKING_CREATED, -// WebhookTriggerEvents.BOOKING_RESCHEDULED, -// ] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; +export const WEBHOOK_TRIGGER_EVENTS = [ + WebhookTriggerEvents.BOOKING_CANCELLED, + WebhookTriggerEvents.BOOKING_CREATED, + WebhookTriggerEvents.BOOKING_RESCHEDULED, +] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; const schemaWebhookBaseBodyParams = Webhook.pick({ + id: true, userId: true, eventTypeId: true, eventTriggers: true, @@ -20,12 +21,13 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ + id: z.string(), subscriberUrl: z.string().url(), - eventTriggers: z.any(), + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), active: z.boolean(), -// payloadTemplate: z.string().optional().nullable(), -// eventTypeId: z.number().optional(), -// appId: z.string().optional().nullable(), + payloadTemplate: z.string().optional().nullable(), + eventTypeId: z.number().optional(), + appId: z.string().optional().nullable(), }) .strict(); @@ -36,8 +38,7 @@ export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ payloadTemplate: z.string().optional(), - /** @todo: don't use 'any' here and validate eventTriggers proper */ - eventTriggers: z.any().optional(), + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(), subscriberUrl: z.string().optional(), }) ); From 316c5a1266672b653fccb9d5affdbd4e01da9f1d Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:16:51 +0530 Subject: [PATCH 06/11] Fixing prettier --- lib/validations/webhook.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index f523c4c71e..1997bdbb3e 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,8 +1,9 @@ import { z } from "zod"; -import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; import { WebhookTriggerEvents } from "@calcom/prisma/client"; +import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; + export const WEBHOOK_TRIGGER_EVENTS = [ WebhookTriggerEvents.BOOKING_CANCELLED, WebhookTriggerEvents.BOOKING_CREATED, @@ -31,9 +32,7 @@ export const schemaWebhookCreateParams = z }) .strict(); -export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( - schemaWebhookCreateParams -); +export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookCreateParams); export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ From 09acaef90466729979e572962376d5078a6f4143 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:20:32 +0530 Subject: [PATCH 07/11] Further prettier changes --- lib/validations/webhook.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 1997bdbb3e..d7109e5912 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,7 +1,6 @@ import { z } from "zod"; import { WebhookTriggerEvents } from "@calcom/prisma/client"; - import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; export const WEBHOOK_TRIGGER_EVENTS = [ From b408015df4c10ff52f4f02ce248a2e8a1f45ac63 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:25:13 +0530 Subject: [PATCH 08/11] Fixed enum --- lib/validations/webhook.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index d7109e5912..b2d6485275 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,8 +1,13 @@ import { z } from "zod"; -import { WebhookTriggerEvents } from "@calcom/prisma/client"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; +export const WebhookTriggerEvents: { + BOOKING_CREATED: 'BOOKING_CREATED', + BOOKING_RESCHEDULED: 'BOOKING_RESCHEDULED', + BOOKING_CANCELLED: 'BOOKING_CANCELLED' +}; + export const WEBHOOK_TRIGGER_EVENTS = [ WebhookTriggerEvents.BOOKING_CANCELLED, WebhookTriggerEvents.BOOKING_CREATED, From 7b936073a4b65410981788c7785ed33b154b1031 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:28:38 +0530 Subject: [PATCH 09/11] More fix --- lib/validations/webhook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index b2d6485275..6c35fb9743 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -2,7 +2,7 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; -export const WebhookTriggerEvents: { +export const WebhookTriggerEvents = { BOOKING_CREATED: 'BOOKING_CREATED', BOOKING_RESCHEDULED: 'BOOKING_RESCHEDULED', BOOKING_CANCELLED: 'BOOKING_CANCELLED' From e8e36abc75d0fe7d804b318c3caeb2f606ceab45 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:32:04 +0530 Subject: [PATCH 10/11] prettier fix --- lib/validations/webhook.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 6c35fb9743..59da7bb71a 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -3,9 +3,9 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; export const WebhookTriggerEvents = { - BOOKING_CREATED: 'BOOKING_CREATED', - BOOKING_RESCHEDULED: 'BOOKING_RESCHEDULED', - BOOKING_CANCELLED: 'BOOKING_CANCELLED' + BOOKING_CREATED: "BOOKING_CREATED", + BOOKING_RESCHEDULED: "BOOKING_RESCHEDULED", + BOOKING_CANCELLED: "BOOKING_CANCELLED" }; export const WEBHOOK_TRIGGER_EVENTS = [ From 8721a04d445a33f7c3a3e56c2de21b12f80a4385 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:35:28 +0530 Subject: [PATCH 11/11] prettier fix again --- lib/validations/webhook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 59da7bb71a..ee42052204 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -5,7 +5,7 @@ import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; export const WebhookTriggerEvents = { BOOKING_CREATED: "BOOKING_CREATED", BOOKING_RESCHEDULED: "BOOKING_RESCHEDULED", - BOOKING_CANCELLED: "BOOKING_CANCELLED" + BOOKING_CANCELLED: "BOOKING_CANCELLED", }; export const WEBHOOK_TRIGGER_EVENTS = [