From 93b2e961443f9f0c417efdd055a369a90026001a Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 18:51:19 +0200 Subject: [PATCH 01/11] fix: dont overdo validation on read event-type --- lib/validations/event-type.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 3357c53794..53fbcb620f 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -86,11 +86,4 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}) - .merge( - z.object({ - recurringEvent: jsonSchema.nullable(), - metadata: jsonSchema.nullable(), - }) - ) - .strict(); +}); From b95c0648286c46ba8c242aefe4bd30026a7c9352 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 18:58:37 +0200 Subject: [PATCH 02/11] fix: metadata zany --- lib/validations/event-type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 53fbcb620f..92f7c42f56 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -86,4 +86,4 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}); +}).merge(z.object({ metadata: z.any() })); From b7f9791439bad77c31fe9855127f8fe3adde6d00 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:00:27 +0200 Subject: [PATCH 03/11] fix: add locations any too --- lib/validations/event-type.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 92f7c42f56..f436757ef2 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -61,7 +61,6 @@ export const schemaEventTypeReadPublic = EventType.pick({ title: true, slug: true, length: true, - locations: true, hidden: true, position: true, userId: true, @@ -86,4 +85,4 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}).merge(z.object({ metadata: z.any() })); +}).merge(z.object({ metadata: z.any(), locations: z.any() })); From 957d6d2375c092878be05a96fb0f8866bc916871 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:10:16 +0200 Subject: [PATCH 04/11] fix: locations or z null --- lib/validations/event-type.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index f436757ef2..53947aad5b 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -38,8 +38,8 @@ const schemaEventTypeCreateParams = z slug: z.string(), description: z.string().optional().nullable(), length: z.number().int(), - locations: jsonSchema.optional().nullable().or(z.null()), - metadata: z.any().optional().nullable().nullish(), + // locations: jsonSchema.optional().nullable().or(z.null()), + // metadata: z.any().optional().nullable().nullish(), recurringEvent: jsonSchema.optional().nullable().or(z.null()), }) .strict(); @@ -85,4 +85,4 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}).merge(z.object({ metadata: z.any(), locations: z.any() })); +}).merge(z.object({ metadata: z.any(), locations: jsonSchema.or(z.null()) })); From 35ebf53f19352e69cb25c2053cc9d8f14496e2c5 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:21:48 +0200 Subject: [PATCH 05/11] fix: json validation --- lib/validations/event-type.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 53947aad5b..770d570cfd 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -38,8 +38,8 @@ const schemaEventTypeCreateParams = z slug: z.string(), description: z.string().optional().nullable(), length: z.number().int(), - // locations: jsonSchema.optional().nullable().or(z.null()), - // metadata: z.any().optional().nullable().nullish(), + locations: jsonSchema.optional().nullable().or(z.null()), + metadata: z.any().optional().nullable().or(z.null()), recurringEvent: jsonSchema.optional().nullable().or(z.null()), }) .strict(); @@ -85,4 +85,10 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}).merge(z.object({ metadata: z.any(), locations: jsonSchema.or(z.null()) })); +}).merge( + z.object({ + locations: jsonSchema.optional().nullable().or(z.null()), + metadata: z.any().optional().nullable().or(z.null()), + recurringEvent: jsonSchema.optional().nullable().or(z.null()), + }) +); From eb03188d78fefdc42ac9be7ce17073d072be2754 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:25:50 +0200 Subject: [PATCH 06/11] fix: dont validate read event-type --- pages/api/event-types/[id].ts | 2 +- pages/api/event-types/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts index 6319b48b9e..19ca5e0cbb 100644 --- a/pages/api/event-types/[id].ts +++ b/pages/api/event-types/[id].ts @@ -55,7 +55,7 @@ export async function eventTypeById( case "GET": await prisma.eventType .findUnique({ where: { id: safeQuery.data.id } }) - .then((data) => schemaEventTypeReadPublic.parse(data)) + // .then((data) => schemaEventTypeReadPublic.parse(data)) .then((event_type) => res.status(200).json({ event_type })) .catch((error: Error) => res.status(404).json({ diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 163fa501fb..4570934b17 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -30,8 +30,8 @@ async function createOrlistAllEventTypes( * description: No event types were found */ const data = await prisma.eventType.findMany({ where: { userId } }); - const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); - if (event_types) res.status(200).json({ event_types }); + // const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); + if (data) res.status(200).json({ event_types: data }); else (error: Error) => res.status(404).json({ From 5c97283aa188a050c20e12b37c52e4d6fa9f689a Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:39:31 +0200 Subject: [PATCH 07/11] fix: dont add locations/metadata on create event type --- lib/validations/event-type.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 770d570cfd..2eb3d88774 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -38,8 +38,8 @@ const schemaEventTypeCreateParams = z slug: z.string(), description: z.string().optional().nullable(), length: z.number().int(), - locations: jsonSchema.optional().nullable().or(z.null()), - metadata: z.any().optional().nullable().or(z.null()), + // locations: jsonSchema.optional().nullable().or(z.null()), + // metadata: z.any().optional().nullable().or(z.null()), recurringEvent: jsonSchema.optional().nullable().or(z.null()), }) .strict(); @@ -85,10 +85,4 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}).merge( - z.object({ - locations: jsonSchema.optional().nullable().or(z.null()), - metadata: z.any().optional().nullable().or(z.null()), - recurringEvent: jsonSchema.optional().nullable().or(z.null()), - }) -); +}); From 7b90ccb3bffb18161ea98ce27538b4ac0b0724c9 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:49:42 +0200 Subject: [PATCH 08/11] fix: add locations to event type in response types --- lib/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/types.ts b/lib/types.ts index cc3f95d7e8..526950d121 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -127,7 +127,7 @@ export type EventTypeCustomInputsResponse = BaseResponse & { // EventType export type EventTypeResponse = BaseResponse & { - event_type?: Partial; + event_type?: Partial; }; export type EventTypesResponse = BaseResponse & { event_types?: Partial[]; From e7a7c89071089878c6a43b693fa6272d593d5612 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 19:51:40 +0200 Subject: [PATCH 09/11] fix add locations metadata and recurring events to eventtype response --- lib/types.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/types.ts b/lib/types.ts index 526950d121..58d4b17a9c 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -124,13 +124,17 @@ export type EventTypeCustomInputResponse = BaseResponse & { export type EventTypeCustomInputsResponse = BaseResponse & { event_type_custom_inputs?: Partial[]; }; - +export type EventTypeWithMetadataLocations = EventType & { + locations?: object; + metadata?: object; + recurringEvent?: object; +}; // EventType export type EventTypeResponse = BaseResponse & { - event_type?: Partial; + event_type?: Partial; }; export type EventTypesResponse = BaseResponse & { - event_types?: Partial[]; + event_types?: Partial[]; }; // Payment From 37069e2d7b4d00046a351ad2a1cda999c03ec8df Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 20:22:43 +0200 Subject: [PATCH 10/11] fix: omit metadata/locations and rewrite as json --- lib/types.ts | 14 +++++++------- lib/validations/event-type.ts | 6 ++++-- pages/api/event-types/[id].ts | 2 +- pages/api/event-types/index.ts | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/types.ts b/lib/types.ts index 58d4b17a9c..574e164e29 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -124,17 +124,17 @@ export type EventTypeCustomInputResponse = BaseResponse & { export type EventTypeCustomInputsResponse = BaseResponse & { event_type_custom_inputs?: Partial[]; }; -export type EventTypeWithMetadataLocations = EventType & { - locations?: object; - metadata?: object; - recurringEvent?: object; -}; +export interface EventTypeMeta extends Omit { + locations?: JSON; + metadata?: JSON; + recurringEvent: JSON; +} // EventType export type EventTypeResponse = BaseResponse & { - event_type?: Partial; + event_type?: Partial; }; export type EventTypesResponse = BaseResponse & { - event_types?: Partial[]; + event_types?: Partial[]; }; // Payment diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 2eb3d88774..6b43a4474a 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -38,8 +38,8 @@ const schemaEventTypeCreateParams = z slug: z.string(), description: z.string().optional().nullable(), length: z.number().int(), - // locations: jsonSchema.optional().nullable().or(z.null()), - // metadata: z.any().optional().nullable().or(z.null()), + locations: jsonSchema.optional().nullable().or(z.null()), + metadata: z.any().optional().nullable().or(z.null()), recurringEvent: jsonSchema.optional().nullable().or(z.null()), }) .strict(); @@ -85,4 +85,6 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, + locations: true, + metadata: true, }); diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts index 19ca5e0cbb..6319b48b9e 100644 --- a/pages/api/event-types/[id].ts +++ b/pages/api/event-types/[id].ts @@ -55,7 +55,7 @@ export async function eventTypeById( case "GET": await prisma.eventType .findUnique({ where: { id: safeQuery.data.id } }) - // .then((data) => schemaEventTypeReadPublic.parse(data)) + .then((data) => schemaEventTypeReadPublic.parse(data)) .then((event_type) => res.status(200).json({ event_type })) .catch((error: Error) => res.status(404).json({ diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 4570934b17..163fa501fb 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -30,8 +30,8 @@ async function createOrlistAllEventTypes( * description: No event types were found */ const data = await prisma.eventType.findMany({ where: { userId } }); - // const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); - if (data) res.status(200).json({ event_types: data }); + const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); + if (event_types) res.status(200).json({ event_types }); else (error: Error) => res.status(404).json({ From 5bb2c54648860bd8864ae1398e4f51e9c19c6ffc Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 20:29:35 +0200 Subject: [PATCH 11/11] fix: add fallback for keys generated with cal_ instead of cal_live_ prefix --- lib/helpers/verifyApiKey.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index cf5c4a8472..6026106231 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -23,7 +23,10 @@ export const dateNotInPast = function (date: Date) { export const verifyApiKey: NextMiddleware = async (req, res, next) => { if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" }); // We remove the prefix from the user provided api_key. If no env set default to "cal_" - const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", ""); + let strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX, ""); + strippedApiKey = strippedApiKey.includes("cal_") + ? strippedApiKey.replace("cal_", "") + : strippedApiKey; // Hash the key again before matching against the database records. const hashedKey = hashAPIKey(strippedApiKey); // Check if the hashed api key exists in database.