import {z} from 'zod' export type GetApiApiV1InterviewsIdArgs = {id: string}; export type GetApiApiV1InterviewsIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1InterviewsIdResponse = 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(), candidate: z.object({id: z.string(), person: z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), name: z.string(), email: z.string().nullable()})}).nullable(), project: z.object({id: z.string(), role: z.string()}).nullable(), company: z.object({id: z.string(), name: z.string()}).nullable(), organizer: z.object({id: z.string().nullable(), name: z.string(), email: z.string().nullable(), type: z.enum(["user", "person"]), relationship: z.enum(["user", "candidate", "company_contact", "person"])}).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"])})), 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 }; /** * Get an interview by ID * * GET /api/v1/interviews/{id} */ export const getApiApiV1InterviewsId = async (args: GetApiApiV1InterviewsIdArgs, options: GetApiApiV1InterviewsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/interviews/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1InterviewsIdResponse, await res.json()) };