import {z} from 'zod' export type GetApiApiV0ProfessionalsIdArgs = {Authorization?: string | undefined, id: number, process_id?: number | undefined}; export type GetApiApiV0ProfessionalsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV0ProfessionalsIdResponse = z.object({data: z.object({id: z.string(), type: z.string(), attributes: z.object({slug: z.string(), email: z.string().optional(), name: z.string(), location: z.unknown(), description: z.string().optional(), image: z.object({url: z.unknown(), thumb: z.object({url: z.unknown()})}).optional(), github: z.string().optional(), twitter: z.unknown(), linkedin: z.unknown(), portfolio: z.unknown(), min_salary: z.unknown(), professional_background: z.string().optional(), academic_background: z.string().optional(), uploaded_cv: z.object({url: z.string().nullable()}).optional(), country: z.string(), stackoverflow: z.unknown(), youtube: z.unknown(), gitlab: z.unknown(), phone: z.unknown(), created_at: z.number().int(), updated_at: z.number().int(), country_name: z.string().optional()})})}); 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 }; /** * Retrieve a professional * * GET /api/v0/professionals/{id} */ export const getApiApiV0ProfessionalsId = async (args: GetApiApiV0ProfessionalsIdArgs, options?: GetApiApiV0ProfessionalsIdOptions) => { const {baseUrl = "https://www.getonbrd.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.process_id != null) query.append("process_id", String(args.process_id)) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v0/professionals/${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(getApiApiV0ProfessionalsIdResponse, await res.json()) };