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. diff --git a/lib/types.ts b/lib/types.ts index cc3f95d7e8..574e164e29 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 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 3357c53794..6b43a4474a 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -39,7 +39,7 @@ const schemaEventTypeCreateParams = z description: z.string().optional().nullable(), length: z.number().int(), locations: jsonSchema.optional().nullable().or(z.null()), - metadata: z.any().optional().nullable().nullish(), + metadata: z.any().optional().nullable().or(z.null()), recurringEvent: jsonSchema.optional().nullable().or(z.null()), }) .strict(); @@ -61,7 +61,6 @@ export const schemaEventTypeReadPublic = EventType.pick({ title: true, slug: true, length: true, - locations: true, hidden: true, position: true, userId: true, @@ -86,11 +85,6 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, -}) - .merge( - z.object({ - recurringEvent: jsonSchema.nullable(), - metadata: jsonSchema.nullable(), - }) - ) - .strict(); + locations: true, + metadata: true, +});