import {z} from 'zod' export type GetApiApiV1ProjectsIdCandidatesArgs = {id: string, phase?: string | undefined, stageId?: string | undefined, statusId?: string | undefined, excludeRejected?: ('true' | 'false') | undefined, sortDirection?: ('asc' | 'desc') | undefined, page?: number | undefined, pageSize?: number | undefined}; export type GetApiApiV1ProjectsIdCandidatesOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1ProjectsIdCandidatesResponse = z.object({status: z.literal("ok"), data: z.array(z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), headlineRole: z.string().nullable(), headlineCompanyName: z.string().nullable(), person: z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), headlineRole: z.string().nullable(), headlineCompanyName: z.string().nullable(), avatarUrl: z.string().nullable()}), stage: z.object({id: z.string(), name: z.string(), phase: z.enum(["internal_selection", "presentation", "first_round", "late_stage"])}), status: z.object({id: z.string(), name: z.string()}), rejectedAt: z.string().nullable(), rejectionType: z.enum(["by_us", "by_client", "self", "null"]).nullable(), rejectionReason: z.string().nullable(), customRejectionReasonId: z.string().nullable(), rejectionDetails: z.string().nullable(), rejectedBy: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), comment: z.string().nullable(), commentFormatted: z.string().nullable(), createdAt: z.string(), updatedAt: z.string()})), 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 candidates in a project * * GET /api/v1/projects/{id}/candidates */ export const getApiApiV1ProjectsIdCandidates = async (args: GetApiApiV1ProjectsIdCandidatesArgs, options: GetApiApiV1ProjectsIdCandidatesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.phase != null) query.append("phase", String(args.phase)) if (args.stageId != null) query.append("stageId", String(args.stageId)) if (args.statusId != null) query.append("statusId", String(args.statusId)) if (args.excludeRejected != null) query.append("excludeRejected", String(args.excludeRejected)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.id))}/candidates${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(getApiApiV1ProjectsIdCandidatesResponse, await res.json()) };