2022-01-21 21:35:31 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
2022-04-05 18:03:22 +00:00
|
|
|
import { LocationType } from "@calcom/core/location";
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2022-02-21 18:45:35 +00:00
|
|
|
import { slugify } from "@calcom/lib/slugify";
|
2022-01-21 21:35:31 +00:00
|
|
|
|
2022-06-10 00:32:34 +00:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
|
2022-01-21 21:35:31 +00:00
|
|
|
export const eventTypeLocations = z.array(
|
2022-03-13 15:56:56 +00:00
|
|
|
z.object({
|
|
|
|
type: z.nativeEnum(LocationType),
|
|
|
|
address: z.string().optional(),
|
|
|
|
link: z.string().url().optional(),
|
2022-05-25 20:34:08 +00:00
|
|
|
displayLocationPublicly: z.boolean().optional(),
|
2022-05-16 15:50:12 +00:00
|
|
|
hostPhoneNumber: z.string().optional(),
|
2022-03-13 15:56:56 +00:00
|
|
|
})
|
2022-01-21 21:35:31 +00:00
|
|
|
);
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
// Matching RRule.Options: rrule/dist/esm/src/types.d.ts
|
2022-06-10 00:32:34 +00:00
|
|
|
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();
|
2022-05-05 21:16:25 +00:00
|
|
|
|
2022-02-21 16:53:16 +00:00
|
|
|
export const eventTypeSlug = z.string().transform((val) => slugify(val.trim()));
|
2022-06-10 00:32:34 +00:00
|
|
|
|
2022-01-21 21:35:31 +00:00
|
|
|
export const stringToDate = z.string().transform((a) => new Date(a));
|
2022-06-10 00:32:34 +00:00
|
|
|
|
|
|
|
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));
|
2022-06-10 18:38:46 +00:00
|
|
|
|
|
|
|
export const bookingCreateBodySchema = z.object({
|
|
|
|
email: z.string(),
|
|
|
|
end: z.string(),
|
|
|
|
web3Details: z
|
|
|
|
.object({
|
|
|
|
userWallet: z.string(),
|
|
|
|
userSignature: z.string(),
|
|
|
|
})
|
|
|
|
.optional(),
|
|
|
|
eventTypeId: z.number(),
|
2022-06-11 21:30:52 +00:00
|
|
|
eventTypeSlug: z.string().optional(),
|
2022-06-10 18:38:46 +00:00
|
|
|
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()),
|
2022-06-11 21:30:52 +00:00
|
|
|
hasHashedBookingLink: z.boolean().optional(),
|
2022-06-10 18:38:46 +00:00
|
|
|
hashedLink: z.string().nullish(),
|
|
|
|
});
|
|
|
|
|
2022-06-11 21:30:52 +00:00
|
|
|
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
|
|
|
|
2022-06-10 18:38:46 +00:00
|
|
|
export const extendedBookingCreateBody = bookingCreateBodySchema.merge(
|
|
|
|
z.object({
|
|
|
|
noEmail: z.boolean().optional(),
|
|
|
|
recurringCount: z.number().optional(),
|
|
|
|
rescheduleReason: z.string().optional(),
|
2022-07-14 00:10:45 +00:00
|
|
|
smsReminderNumber: z.string().optional(),
|
2022-06-10 18:38:46 +00:00
|
|
|
})
|
|
|
|
);
|
2022-06-14 20:07:54 +00:00
|
|
|
|
|
|
|
export const vitalSettingsUpdateSchema = z.object({
|
|
|
|
connected: z.boolean().optional(),
|
|
|
|
selectedParam: z.string().optional(),
|
|
|
|
sleepValue: z.number().optional(),
|
|
|
|
});
|
|
|
|
|
|
|
|
export const userMetadata = z
|
|
|
|
.object({
|
2022-06-16 19:33:23 +00:00
|
|
|
proPaidForByTeamId: z.number().optional(),
|
2022-06-14 20:07:54 +00:00
|
|
|
stripeCustomerId: z.string().optional(),
|
|
|
|
vitalSettings: vitalSettingsUpdateSchema.optional(),
|
2022-07-06 19:31:07 +00:00
|
|
|
isPremium: z.boolean().optional(),
|
|
|
|
intentUsername: z.string().optional(),
|
2022-06-14 20:07:54 +00:00
|
|
|
})
|
|
|
|
.nullable();
|