import {z} from 'zod' export type GetApiApiV1InterviewsArgs = {personId?: string | undefined, projectId?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, createdAfter?: (string | string) | undefined, createdBefore?: (string | string) | undefined, updatedAfter?: (string | string) | undefined, updatedBefore?: (string | string) | undefined, includeDeleted?: ('true' | 'false') | undefined, status?: ('scheduled' | 'finished') | undefined, type?: ('general' | 'interview') | undefined, order?: ('asc' | 'desc') | undefined, includeCustomAttributes?: ('true' | 'false') | undefined, customAttributeIds?: string | undefined, page?: number | undefined, pageSize?: number | undefined, perPage?: number | undefined}; export type GetApiApiV1InterviewsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1InterviewsResponse = z.object({status: z.literal("ok"), data: z.array(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.string(), startAt: z.string().nullable(), endAt: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), deletedAt: z.string().nullable(), organizer: z.object({id: z.string().nullable(), name: z.string(), email: z.string().nullable(), type: 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"])})), candidate: z.object({id: z.string(), person: z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), headlineRole: z.string().nullable(), headlineCompany: z.string().nullable()})}).nullable(), projectId: z.string().nullable(), companyId: z.string().nullable(), hasTranscript: z.boolean(), hasManualNote: z.boolean(), hasAiNotes: z.boolean(), 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()})]))})).optional()})), pagination: z.object({page: z.number().int(), pageSize: z.number().int(), total: z.number().int(), hasMore: z.boolean()})}); 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 }; /** * List interviews * * GET /api/v1/interviews */ export const getApiApiV1Interviews = async (args: GetApiApiV1InterviewsArgs, options: GetApiApiV1InterviewsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.personId != null) query.append("personId", String(args.personId)) if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.updatedAfter != null) query.append("updatedAfter", String(args.updatedAfter)) if (args.updatedBefore != null) query.append("updatedBefore", String(args.updatedBefore)) if (args.includeDeleted != null) query.append("includeDeleted", String(args.includeDeleted)) if (args.status != null) query.append("status", String(args.status)) if (args.type != null) query.append("type", String(args.type)) if (args.order != null) query.append("order", String(args.order)) if (args.includeCustomAttributes != null) query.append("includeCustomAttributes", String(args.includeCustomAttributes)) if (args.customAttributeIds != null) query.append("customAttributeIds", String(args.customAttributeIds)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/interviews${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(getApiApiV1InterviewsResponse, await res.json()) };