import {z} from 'zod' export type GetApiApiV0ProfessionalsArgs = {Authorization: string, page?: number | undefined, per_page?: number | undefined, process_id?: number | undefined}; export type GetApiApiV0ProfessionalsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV0ProfessionalsResponse = z.object({data: z.array(z.object({id: z.string(), type: z.string(), attributes: z.object({slug: z.string(), country: z.string(), name: z.string(), country_name: z.string().optional(), created_at: z.number().int(), updated_at: z.number().int(), email: z.string().optional(), 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(), stackoverflow: z.unknown(), youtube: z.unknown(), gitlab: z.unknown(), phone: z.unknown()})})), meta: z.object({page: z.number().int(), per_page: z.number().int(), total_pages: z.number().int()})}); 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 professionals * * GET /api/v0/professionals */ export const getApiApiV0Professionals = async (args: GetApiApiV0ProfessionalsArgs, options?: GetApiApiV0ProfessionalsOptions) => { 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.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) 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${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(getApiApiV0ProfessionalsResponse, await res.json()) };