import {z} from 'zod' export type GetApiAbdmNhprV1HfrSearchHfrIdArgs = {'X-Pt-Id'?: string | undefined, 'X-Partner-Pt-Id'?: string | undefined, 'X-Hip-Id'?: string | undefined, hfrId: string}; export type GetApiAbdmNhprV1HfrSearchHfrIdOptions = {baseUrl?: string | undefined, authApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const modelsFacility = z.object({address: z.string().optional(), districtLGDCode: z.string().optional(), districtName: z.string().optional(), facilityId: z.string().optional(), facilityName: z.string().optional(), facilityStatus: z.string().optional(), facilityType: z.string().optional(), facilityTypeCode: z.string().optional(), latitude: z.string().optional(), longitude: z.string().optional(), ownership: z.string().optional(), ownershipCode: z.string().optional(), pincode: z.string().optional(), stateLGDCode: z.string().optional(), stateName: z.string().optional(), subDistrictLGDCode: z.string().optional(), subDistrictName: z.string().optional(), systemOfMedicine: z.string().optional(), systemOfMedicineCode: z.string().optional(), villageCityTownLGDCode: z.unknown(), villageCityTownName: z.unknown()}); export const handlerTypedAPIResponseGithubComEkaCareNdhmInternalNhprRepoModelsFacility = z.object({data: modelsFacility.optional(), error: z.unknown(), success: z.boolean().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 }; /** * Search Facility * * GET /abdm/nhpr/v1/hfr/search/{hfrId} */ export const getApiAbdmNhprV1HfrSearchHfrId = async (args: GetApiAbdmNhprV1HfrSearchHfrIdArgs, options?: GetApiAbdmNhprV1HfrSearchHfrIdOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch, authApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Pt-Id'] != null) headers.set("X-Pt-Id", String(args['X-Pt-Id'])) if (args['X-Partner-Pt-Id'] != null) headers.set("X-Partner-Pt-Id", String(args['X-Partner-Pt-Id'])) if (args['X-Hip-Id'] != null) headers.set("X-Hip-Id", String(args['X-Hip-Id'])) if (authApiKey !== undefined) headers.set('authorization', `Bearer ${authApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/abdm/nhpr/v1/hfr/search/${encodeURIComponent(String(args.hfrId))}${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(handlerTypedAPIResponseGithubComEkaCareNdhmInternalNhprRepoModelsFacility, await res.json()) };