import {z} from 'zod' export type GetApiCdrV1HipusersHipUserIdArgs = {auth: string, hip_user_id: string}; export type GetApiCdrV1HipusersHipUserIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCdrV1HipusersHipUserIdResponse = z.object({status: z.string().optional(), user: z.object({id: z.string().optional(), firstname: z.string().optional(), lastname: z.string().optional(), mobile: z.string().optional(), email: z.string().optional(), is_admin: z.boolean().optional(), seat_type: z.string().optional(), doctors: z.array(z.object({id: z.string().optional(), firstname: z.string().optional(), lastname: z.string().optional()})).optional(), clinics: z.array(z.object({id: z.string().optional(), name: z.string().optional()})).optional(), partner_id: z.string().nullable().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 HIP User Details by ID * * GET /cdr/v1/hipusers/{hip_user_id} */ export const getApiCdrV1HipusersHipUserId = async (args: GetApiCdrV1HipusersHipUserIdArgs, options?: GetApiCdrV1HipusersHipUserIdOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.auth != null) headers.set("auth", String(args.auth)) const url = `${baseUrl.replace(/\/+$/, '')}/cdr/v1/hipusers/${encodeURIComponent(String(args.hip_user_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(getApiCdrV1HipusersHipUserIdResponse, await res.json()) };