111 lines
2.9 KiB
TypeScript
111 lines
2.9 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { LocationType } from "@calcom/core/location";
|
|
import dayjs from "@calcom/dayjs";
|
|
import { slugify } from "@calcom/lib/slugify";
|
|
|
|
// Let's not import 118kb just to get an enum
|
|
export enum Frequency {
|
|
YEARLY = 0,
|
|
MONTHLY = 1,
|
|
WEEKLY = 2,
|
|
DAILY = 3,
|
|
HOURLY = 4,
|
|
MINUTELY = 5,
|
|
SECONDLY = 6,
|
|
}
|
|
|
|
export const eventTypeLocations = z.array(
|
|
z.object({
|
|
type: z.nativeEnum(LocationType),
|
|
address: z.string().optional(),
|
|
link: z.string().url().optional(),
|
|
displayLocationPublicly: z.boolean().optional(),
|
|
hostPhoneNumber: z.string().optional(),
|
|
})
|
|
);
|
|
|
|
// Matching RRule.Options: rrule/dist/esm/src/types.d.ts
|
|
export const recurringEventType = z
|
|
.object({
|
|
dtstart: z.date().optional(),
|
|
interval: z.number(),
|
|
count: z.number(),
|
|
freq: z.nativeEnum(Frequency),
|
|
until: z.date().optional(),
|
|
tzid: z.string().optional(),
|
|
})
|
|
.nullable();
|
|
|
|
export const eventTypeSlug = z.string().transform((val) => slugify(val.trim()));
|
|
|
|
export const stringToDate = z.string().transform((a) => new Date(a));
|
|
|
|
export const stringOrNumber = z.union([
|
|
z.string().transform((v, ctx) => {
|
|
const parsed = parseInt(v);
|
|
if (isNaN(parsed)) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: "Not a number",
|
|
});
|
|
}
|
|
return parsed;
|
|
}),
|
|
z.number().int(),
|
|
]);
|
|
|
|
export const stringToDayjs = z.string().transform((val) => dayjs(val));
|
|
|
|
export const bookingCreateBodySchema = z.object({
|
|
email: z.string(),
|
|
end: z.string(),
|
|
web3Details: z
|
|
.object({
|
|
userWallet: z.string(),
|
|
userSignature: z.string(),
|
|
})
|
|
.optional(),
|
|
eventTypeId: z.number(),
|
|
eventTypeSlug: z.string().optional(),
|
|
guests: z.array(z.string()).optional(),
|
|
location: z.string(),
|
|
name: z.string(),
|
|
notes: z.string().optional(),
|
|
rescheduleUid: z.string().optional(),
|
|
recurringEventId: z.string().optional(),
|
|
start: z.string(),
|
|
timeZone: z.string(),
|
|
user: z.union([z.string(), z.array(z.string())]).optional(),
|
|
language: z.string(),
|
|
bookingUid: z.string().optional(),
|
|
customInputs: z.array(z.object({ label: z.string(), value: z.union([z.string(), z.boolean()]) })),
|
|
metadata: z.record(z.string()),
|
|
hasHashedBookingLink: z.boolean().optional(),
|
|
hashedLink: z.string().nullish(),
|
|
});
|
|
|
|
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
|
|
|
export const extendedBookingCreateBody = bookingCreateBodySchema.merge(
|
|
z.object({
|
|
noEmail: z.boolean().optional(),
|
|
recurringCount: z.number().optional(),
|
|
rescheduleReason: z.string().optional(),
|
|
})
|
|
);
|
|
|
|
export const vitalSettingsUpdateSchema = z.object({
|
|
connected: z.boolean().optional(),
|
|
selectedParam: z.string().optional(),
|
|
sleepValue: z.number().optional(),
|
|
});
|
|
|
|
export const userMetadata = z
|
|
.object({
|
|
proPaidForByTeamId: z.number().optional(),
|
|
stripeCustomerId: z.string().optional(),
|
|
vitalSettings: vitalSettingsUpdateSchema.optional(),
|
|
})
|
|
.nullable();
|