import {z} from 'zod' export type GetApiApiV1ProjectsProjectIdCandidatesCandidateIdArgs = {projectId: string, candidateId: string}; export type GetApiApiV1ProjectsProjectIdCandidatesCandidateIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1ProjectsProjectIdCandidatesCandidateIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), 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()}), owner: z.object({id: z.string(), name: z.string(), email: 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()}), project: z.object({id: z.string(), jobRole: z.string(), state: z.enum(["active", "closed", "on_hold", "talent_pool", "lead", "pitch", "opportunity"])}).nullable(), 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()})}); 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 a candidate in a project * * GET /api/v1/projects/{projectId}/candidates/{candidateId} */ export const getApiApiV1ProjectsProjectIdCandidatesCandidateId = async (args: GetApiApiV1ProjectsProjectIdCandidatesCandidateIdArgs, options: GetApiApiV1ProjectsProjectIdCandidatesCandidateIdOptions) => { 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/projects/${encodeURIComponent(String(args.projectId))}/candidates/${encodeURIComponent(String(args.candidateId))}${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(getApiApiV1ProjectsProjectIdCandidatesCandidateIdResponse, await res.json()) };