import {z} from 'zod' export type CreateApiApiV1MeetingsArgs = {body: {name: string, startAt: string, endAt: string, timeZone: string, communicationMethod: 'video_call' | 'phone_call' | 'in_person', attendees: Array<{id?: string | undefined, email: string, isUser: boolean, optional?: boolean | undefined, calendarOnly?: boolean | undefined}>, skipCalendarEvent: boolean, senderEmail?: string | undefined, description?: (string | null) | undefined, location?: (string | null) | undefined, projectId?: (string | null) | undefined, isPrivate?: boolean | undefined, hideAttendees?: boolean | undefined, inviteAINotetaker?: boolean | undefined, peopleNotes?: (string | null) | undefined, candidateEvent?: ({enabled: boolean, eventTitle?: (string | null) | undefined, description?: (string | null) | undefined, inviteeEmail?: string | undefined, inviteeName?: (string | null) | undefined} | null) | undefined}}; export type CreateApiApiV1MeetingsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1MeetingsResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), name: z.string().nullable(), description: z.string().nullable(), location: z.string().nullable(), meetingUrl: z.string().nullable(), method: z.enum(["video_call", "phone_call", "in_person", "null"]).nullable(), status: z.enum(["draft", "created", "scheduled", "coming", "waiting_to_join", "live", "completed", "transcribed", "failed", "canceled", "no_answer", "scheduling"]), direction: z.enum(["inbound", "outbound", "null"]).nullable(), startAt: z.string().nullable(), endAt: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), organizer: z.object({id: z.string().nullable(), name: z.string(), email: z.string().nullable(), type: z.enum(["user", "external"]), relationship: z.enum(["user", "external"])}).nullable(), participants: z.array(z.object({id: z.string(), name: z.string(), email: z.string().nullable(), type: z.enum(["user", "person"]), relationship: z.enum(["user", "candidate", "company_contact", "person"])})), project: z.object({id: z.string(), role: z.string(), companyName: z.string().nullable()}).nullable(), company: z.object({id: z.string(), name: z.string()}).nullable(), customAttributes: z.array(z.object({attributeId: z.string(), attributeName: z.string().nullable(), attributeType: z.enum(["options", "text_block", "text_line", "number_input", "integer", "date", "null"]).nullable(), values: z.array(z.union([z.string(), z.number(), z.object({optionId: z.string(), optionValue: z.string().nullable()})]))}))})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create a meeting * * POST /api/v1/meetings */ export const createApiApiV1Meetings = async (args: CreateApiApiV1MeetingsArgs, options: CreateApiApiV1MeetingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/meetings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1MeetingsResponse, await res.json()) };