import {z} from 'zod' export type GetApiRecruitingCandidatesCandidateIdArgs = {candidateId: string}; export type GetApiRecruitingCandidatesCandidateIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiRecruitingCandidatesCandidateIdResponse = z.object({_id: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), origin: z.string().optional(), _createdById: z.string().optional(), _updatedById: z.string().optional(), _createdAt: z.string().optional(), _updatedAt: z.string().optional()}).and(z.record(z.string(), z.unknown())); 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 by ID. * * GET /recruiting/candidates/{candidateId} */ export const getApiRecruitingCandidatesCandidateId = async (args: GetApiRecruitingCandidatesCandidateIdArgs, options?: GetApiRecruitingCandidatesCandidateIdOptions) => { const {baseUrl = "https://sandbox-api.kenjo.io/api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/recruiting/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(getApiRecruitingCandidatesCandidateIdResponse, await res.json()) };