From fdc46fac7d73e2271441b99fc4382f8fad7382ef Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Thu, 19 May 2022 22:00:22 +0200 Subject: [PATCH] fix: build issues, extend event-type in types, use @calcom/types --- lib/helpers/verifyApiKey.ts | 8 ------- lib/types.ts | 35 ++++++++++++++++++++++++---- lib/validations/event-type.ts | 6 ++--- lib/validations/shared/jsonSchema.ts | 2 +- package.json | 7 +++--- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index cf5c4a8472..c467c6ce99 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -1,16 +1,8 @@ -import type { IncomingMessage } from "http"; import { NextMiddleware } from "next-api-middleware"; import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys"; import prisma from "@calcom/prisma"; -/** @todo figure how to use the one from `@calcom/types`fi */ -declare module "next" { - export interface NextApiRequest extends IncomingMessage { - userId: number; - } -} - // Used to check if the apiKey is not expired, could be extracted if reused. but not for now. export const dateNotInPast = function (date: Date) { const now = new Date(); diff --git a/lib/types.ts b/lib/types.ts index edd5b9f6c9..a5c7d8ad21 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,3 +1,4 @@ +import { AppStoreLocationType, DefaultLocationType } from "@calcom/app-store/locations"; import { User, Team, @@ -15,10 +16,9 @@ import { Payment, Schedule, ReminderMail, + EventType, } from "@calcom/prisma/client"; -import { schemaEventTypeReadPublic } from "@lib/validations/event-type"; - // Base response, used for all responses export type BaseResponse = { message?: string; @@ -124,13 +124,38 @@ export type EventTypeCustomInputResponse = BaseResponse & { export type EventTypeCustomInputsResponse = BaseResponse & { event_type_custom_inputs?: Partial[]; }; - +// From rrule https://jakubroztocil.github.io/rrule freq +enum Frequency { + "YEARLY", + "MONTHLY", + "WEEKLY", + "DAILY", + "HOURLY", + "MINUTELY", + "SECONDLY", +} +interface EventTypeExtended extends Omit { + recurringEvent: { + dtstart?: Date | undefined; + interval?: number | undefined; + count?: number | undefined; + freq?: Frequency | undefined; + until?: Date | undefined; + tzid?: string | undefined; + }; + locations: { + link?: string | undefined; + address?: string | undefined; + hostPhoneNumber?: string | undefined; + type: DefaultLocationType | AppStoreLocationType; + }[]; +} // 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 6b43a4474a..aee6002089 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -38,9 +38,9 @@ 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()), - recurringEvent: jsonSchema.optional().nullable().or(z.null()), + locations: jsonSchema.optional(), + metadata: z.any().optional(), + recurringEvent: jsonSchema.optional(), }) .strict(); diff --git a/lib/validations/shared/jsonSchema.ts b/lib/validations/shared/jsonSchema.ts index 826f0b6250..bfc7ae1f2b 100644 --- a/lib/validations/shared/jsonSchema.ts +++ b/lib/validations/shared/jsonSchema.ts @@ -5,5 +5,5 @@ type Literal = boolean | number | string; type Json = Literal | { [key: string]: Json } | Json[]; const literalSchema = z.union([z.string(), z.number(), z.boolean()]); export const jsonSchema: z.ZodSchema = z.lazy(() => - z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]).or(z.null()) + z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]) ); diff --git a/package.json b/package.json index 143065b933..8f025ebd54 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,12 @@ }, "devDependencies": { "@calcom/tsconfig": "*", - "@typescript-eslint/eslint-plugin": "^5.22.0", - "babel-jest": "^28.0.3", + "@calcom/types": "*", + "@typescript-eslint/eslint-plugin": "^5.25.0", + "babel-jest": "^28.1.0", "jest": "^28.0.3", "node-mocks-http": "^1.11.0" - }, + }, "dependencies": { "@calcom/prisma": "*", "@sentry/nextjs": "^6.19.7",