0e3696f20c
* chore: dedupe yarn.lock to remove duplicate package versions - Consolidated 762 duplicate package versions - Reduced yarn.lock from 51,211 lines (1.7MB) to 44,471 lines (1.5MB) - Removed 7,071 lines (~200KB) of redundant dependency entries - Major packages deduplicated include: resolve, semver, type-fest, commander, glob, lru-cache, dotenv, @babel/* packages, typescript, tslib, postcss, and many more Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: resolve type errors in managed event types and react-select components - Add Zod-compatible versions of allManagedEventTypeProps and unlockedManagedEventTypeProps that only include scalar fields (excludes Prisma relation fields) - Update handleChildrenEventTypes.ts and queries.ts to use the new Zod-compatible props - Fix react-select CSS type errors in Select.tsx files by using Object.assign instead of spread operator to avoid TypeScript type inference issues - Fix lint warning in updateNewTeamMemberEventTypes by using if statement Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: derive eventType parameter type from actual query result Use Awaited<ReturnType<typeof getEventTypesToAddNewMembers>>[number] to ensure type safety at call sites, avoiding Prisma type namespace mismatches. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: disable turbo cache for @calcom/trpc#build to prevent stale type errors Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: correct field names in API v1 validation schemas - Remove timeZone from booking schema (field doesn't exist on Booking model) - Remove bookingId from destination-calendar schema (field doesn't exist, only booking relation) - Change avatar to avatarUrl in user schema (correct field name) Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: use Object.assign for react-select styles to fix TypeScript spread type errors The spread operator causes TypeScript to compute an incompatible type with CSSObjectWithLabel due to the accentColor property. Using Object.assign preserves the correct type inference. Fixed files: - FormEdit.tsx - DestinationCalendarSelector.tsx (features and platform) - TimezoneSelect.tsx - ApiKeyDialogForm.tsx - Select.tsx (features/form) - WebhookForm.tsx Also fixed pre-existing lint warnings: - Constant truthiness in label assignment - Unused variant parameter Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: remove extra fields from allManagedEventTypePropsForZod to match original behavior The Zod-compatible version should only include scalar fields that were in the original allManagedEventTypeProps. Removed instantMeetingScheduleId, profileId, rrSegmentQueryValue, and assignRRMembersUsingSegment which were incorrectly added and caused test failures by including extra fields in Prisma update payloads. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: remove access to fields not in Zod schema - Remove unnecessary destructuring of profileId and instantMeetingScheduleId from managedEventTypeValues in handleChildrenEventTypes.ts (these fields are already sourced from other variables) - Set rrSegmentQueryValue to undefined directly in queries.ts instead of accessing it from managedEventTypeValues (not applicable for managed children) Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: add name property to mock credentials and revert turbo cache change - Add name property to MockCredential type and factory function in InstallAppButtonChild.test.tsx to match expected credentials type - Revert turbo cache disable for @calcom/trpc#build (per review comment) Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: revert API v1 validation changes and restore eslint comment - Revert API v1 validation changes (booking.ts, destination-calendar.ts, user.ts) since API v1 is deprecated and these could be breaking changes - Restore eslint-disable comment for @typescript-eslint/no-empty-function in Select.tsx that was accidentally removed Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: add inputs to @calcom/trpc#build to properly invalidate cache Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: properly fix API v1 validation schemas for stricter zod 3.25.76 The yarn dedupe upgraded zod from 3.22.4 to 3.25.76, which has stricter .pick() typing that now properly rejects picking non-existent fields. Changes: - user.ts: Pick avatarUrl (actual Prisma field) and extend with avatar for API v1 backward compatibility - booking.ts: Remove timeZone from pick (not a field on Booking model, only exists in nested attendees/user objects) - destination-calendar.ts: Remove bookingId from pick (not a field on DestinationCalendar model) Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: remove turbo.json inputs for @calcom/trpc#build to use cached artifacts Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: use robust selector for react-select option in routing forms E2E test The previous selector used .nth(1) which assumed the email text appeared exactly twice in the DOM in a specific order. This broke when react-select was upgraded from 5.7.2 to 5.8.0 via yarn dedupe. The new approach waits for the react-select listbox to appear and clicks the option within it, which is more robust against DOM structure changes. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
186 lines
5.5 KiB
TypeScript
186 lines
5.5 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { checkUsername } from "@calcom/features/profile/lib/checkUsername";
|
|
import { emailSchema } from "@calcom/lib/emailSchema";
|
|
import { iso8601 } from "@calcom/prisma/zod-utils";
|
|
import { UserSchema } from "@calcom/prisma/zod/modelSchema/UserSchema";
|
|
|
|
import { isValidBase64Image } from "~/lib/utils/isValidBase64Image";
|
|
import { timeZone } from "~/lib/validations/shared/timeZone";
|
|
|
|
// @note: These are the ONLY values allowed as weekStart. So user don't introduce bad data.
|
|
enum weekdays {
|
|
MONDAY = "Monday",
|
|
TUESDAY = "Tuesday",
|
|
WEDNESDAY = "Wednesday",
|
|
THURSDAY = "Thursday",
|
|
FRIDAY = "Friday",
|
|
SATURDAY = "Saturday",
|
|
SUNDAY = "Sunday",
|
|
}
|
|
|
|
// @note: extracted from apps/web/next-i18next.config.js, update if new locales.
|
|
enum locales {
|
|
EN = "en",
|
|
FR = "fr",
|
|
IT = "it",
|
|
RU = "ru",
|
|
ES = "es",
|
|
DE = "de",
|
|
PT = "pt",
|
|
RO = "ro",
|
|
NL = "nl",
|
|
PT_BR = "pt-BR",
|
|
ES_419 = "es-419",
|
|
KO = "ko",
|
|
JA = "ja",
|
|
PL = "pl",
|
|
AR = "ar",
|
|
IW = "iw",
|
|
ZH_CN = "zh-CN",
|
|
ZH_TW = "zh-TW",
|
|
CS = "cs",
|
|
SR = "sr",
|
|
SV = "sv",
|
|
VI = "vi",
|
|
BN = "bn",
|
|
}
|
|
enum theme {
|
|
DARK = "dark",
|
|
LIGHT = "light",
|
|
}
|
|
|
|
enum timeFormat {
|
|
TWELVE = 12,
|
|
TWENTY_FOUR = 24,
|
|
}
|
|
|
|
const usernameSchema = z
|
|
.string()
|
|
.transform((v) => v.toLowerCase())
|
|
// .refine(() => {})
|
|
.superRefine(async (val, ctx) => {
|
|
if (val) {
|
|
const result = await checkUsername(val);
|
|
if (!result.available) ctx.addIssue({ code: z.ZodIssueCode.custom, message: "already_in_use_error" });
|
|
if (result.premium) ctx.addIssue({ code: z.ZodIssueCode.custom, message: "premium_username" });
|
|
}
|
|
});
|
|
|
|
// @note: These are the values that are editable via PATCH method on the user Model
|
|
export const schemaUserBaseBodyParams = UserSchema.pick({
|
|
name: true,
|
|
email: true,
|
|
username: true,
|
|
bio: true,
|
|
timeZone: true,
|
|
weekStart: true,
|
|
theme: true,
|
|
appTheme: true,
|
|
defaultScheduleId: true,
|
|
locale: true,
|
|
hideBranding: true,
|
|
timeFormat: true,
|
|
brandColor: true,
|
|
darkBrandColor: true,
|
|
allowDynamicBooking: true,
|
|
role: true,
|
|
// @note: disallowing avatar changes via API for now. We can add it later if needed. User should upload image via UI.
|
|
// avatar: true,
|
|
}).partial();
|
|
// @note: partial() is used to allow for the user to edit only the fields they want to edit making all optional,
|
|
// if want to make any required do it in the schemaRequiredParams
|
|
|
|
// Here we can both require or not (adding optional or nullish) and also rewrite validations for any value
|
|
// for example making weekStart only accept weekdays as input
|
|
const schemaUserEditParams = z.object({
|
|
email: emailSchema.toLowerCase(),
|
|
username: usernameSchema,
|
|
weekStart: z.nativeEnum(weekdays).optional(),
|
|
brandColor: z.string().min(4).max(9).regex(/^#/).optional(),
|
|
darkBrandColor: z.string().min(4).max(9).regex(/^#/).optional(),
|
|
hideBranding: z.boolean().optional(),
|
|
timeZone: timeZone.optional(),
|
|
theme: z.nativeEnum(theme).optional().nullable(),
|
|
appTheme: z.nativeEnum(theme).optional().nullable(),
|
|
timeFormat: z.nativeEnum(timeFormat).optional(),
|
|
defaultScheduleId: z
|
|
.number()
|
|
.refine((id: number) => id > 0)
|
|
.optional()
|
|
.nullable(),
|
|
locale: z.nativeEnum(locales).optional().nullable(),
|
|
avatar: z.string().refine(isValidBase64Image).optional(),
|
|
});
|
|
|
|
// @note: These are the values that are editable via PATCH method on the user Model,
|
|
// merging both BaseBodyParams with RequiredParams, and omitting whatever we want at the end.
|
|
|
|
const schemaUserCreateParams = z.object({
|
|
email: emailSchema.toLowerCase(),
|
|
username: usernameSchema,
|
|
weekStart: z.nativeEnum(weekdays).optional(),
|
|
brandColor: z.string().min(4).max(9).regex(/^#/).optional(),
|
|
darkBrandColor: z.string().min(4).max(9).regex(/^#/).optional(),
|
|
hideBranding: z.boolean().optional(),
|
|
timeZone: timeZone.optional(),
|
|
theme: z.nativeEnum(theme).optional().nullable(),
|
|
appTheme: z.nativeEnum(theme).optional().nullable(),
|
|
timeFormat: z.nativeEnum(timeFormat).optional(),
|
|
defaultScheduleId: z
|
|
.number()
|
|
.refine((id: number) => id > 0)
|
|
.optional()
|
|
.nullable(),
|
|
locale: z.nativeEnum(locales).optional(),
|
|
createdDate: iso8601.optional(),
|
|
avatar: z.string().refine(isValidBase64Image).optional(),
|
|
});
|
|
|
|
// @note: These are the values that are editable via PATCH method on the user Model,
|
|
// merging both BaseBodyParams with RequiredParams, and omitting whatever we want at the end.
|
|
export const schemaUserEditBodyParams = schemaUserBaseBodyParams
|
|
.merge(schemaUserEditParams)
|
|
.omit({})
|
|
.partial()
|
|
.strict();
|
|
|
|
export const schemaUserCreateBodyParams = schemaUserBaseBodyParams
|
|
.merge(schemaUserCreateParams)
|
|
.omit({})
|
|
.strict();
|
|
|
|
// @note: These are the values that are always returned when reading a user
|
|
// Note: We pick avatarUrl from the Prisma schema and extend with avatar for API v1 backward compatibility
|
|
export const schemaUserReadPublic = UserSchema.pick({
|
|
id: true,
|
|
username: true,
|
|
name: true,
|
|
email: true,
|
|
emailVerified: true,
|
|
bio: true,
|
|
avatarUrl: true,
|
|
timeZone: true,
|
|
weekStart: true,
|
|
endTime: true,
|
|
bufferTime: true,
|
|
appTheme: true,
|
|
theme: true,
|
|
defaultScheduleId: true,
|
|
locale: true,
|
|
timeFormat: true,
|
|
hideBranding: true,
|
|
brandColor: true,
|
|
darkBrandColor: true,
|
|
allowDynamicBooking: true,
|
|
createdDate: true,
|
|
verified: true,
|
|
invitedTo: true,
|
|
role: true,
|
|
}).extend({
|
|
// API v1 backward compatibility: expose avatarUrl as avatar
|
|
avatar: UserSchema.shape.avatarUrl,
|
|
});
|
|
|
|
export const schemaUsersReadPublic = z.array(schemaUserReadPublic);
|