import {z} from 'zod' export type GetApiPredictionsPeopleArgs = {first_name?: string | undefined, last_name?: string | undefined, born_at?: string | undefined}; export type GetApiPredictionsPeopleOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPredictionsPeopleResponse = z.object({people: z.array(z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), links: z.object({consultations: z.string().optional(), consultation_lab_test_results: z.string().optional(), consultation_schedules: z.string().optional(), vital_signs_sets: z.string().optional(), medical_history: z.string().optional(), deffers: z.string().optional(), medical_notes: z.string().optional(), insurance_coverage: z.string().optional()}).optional(), full_name: z.string().optional(), telephone: z.unknown(), email: z.unknown(), born_at: z.string().optional(), gender: z.string().optional(), avatar_url_small: z.string().optional(), avatar_url_medium: z.string().optional(), telephone2: z.string().optional(), address_state_id: z.number().int().optional(), address_city: z.unknown(), address_street: z.unknown(), address_zipcode: z.unknown(), identity_number: z.unknown(), account_id: z.number().int().optional(), avatar_url_large: z.string().optional(), notes: z.unknown(), person_attributes: z.object({}).optional(), phone_country_id: z.number().int().optional(), is_migrated: z.boolean().optional(), without_cellphone: z.boolean().optional(), nimbochat_invitation_sent: z.boolean().optional(), medical_record: z.unknown()})).optional(), meta: z.object({total_pages: z.number().int().optional()}).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 }; /** * GET /predictions/people * * GET /predictions/people */ export const getApiPredictionsPeople = async (args: GetApiPredictionsPeopleArgs, options?: GetApiPredictionsPeopleOptions) => { const {baseUrl = "https://api.example.test", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.first_name != null) query.append("first_name", String(args.first_name)) if (args.last_name != null) query.append("last_name", String(args.last_name)) if (args.born_at != null) query.append("born_at", String(args.born_at)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/predictions/people${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(getApiPredictionsPeopleResponse, await res.json()) };