import {z} from 'zod' export type GetApiPeoplePersonIdArgs = {person_id: string}; export type GetApiPeoplePersonIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPeoplePersonIdResponse = z.object({person: 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.unknown(), address_city: z.unknown(), address_street: z.unknown(), address_zipcode: z.unknown(), identity_number: z.string().optional(), account_id: z.number().int().optional(), avatar_url_large: z.string().optional(), notes: z.unknown(), person_attributes: z.object({tax_rfc: z.string().optional(), identity_number: z.string().optional()}).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.string().optional(), cirrus_patient_id: z.unknown()}).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 /people/{person_id} * * GET /people/{person_id} */ export const getApiPeoplePersonId = async (args: GetApiPeoplePersonIdArgs, options?: GetApiPeoplePersonIdOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/people/${encodeURIComponent(String(args.person_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(getApiPeoplePersonIdResponse, await res.json()) };