import {z} from 'zod' export type GetApiAssessFetchAssessmentsArgs = {pids?: string | undefined, puuid?: string | undefined, docid?: string | undefined, status?: ('COMPLETED' | 'IN_REVIEW') | undefined, sd?: string | undefined, ed?: string | undefined, wflowid?: string | undefined, is_abha_linkable?: boolean | undefined, limit?: number | undefined, offset?: number | undefined, sort?: ('asc' | 'desc') | undefined}; export type GetApiAssessFetchAssessmentsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAssessFetchAssessmentsResponse = z.object({conversations: z.record(z.string(), z.array(z.object({conversationid: z.string().optional(), created_at: z.string().optional(), created_epoch: z.number().int().optional(), wfid: z.number().int().optional(), share_to_abha: z.boolean().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 }; /** * Fetch assessments (Deprecated) * * GET /assess/fetch_assessments/ * * Also accepts auth: auth */ export const getApiAssessFetchAssessments = async (args: GetApiAssessFetchAssessmentsArgs, options?: GetApiAssessFetchAssessmentsOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pids != null) query.append("pids", String(args.pids)) if (args.puuid != null) query.append("puuid", String(args.puuid)) if (args.docid != null) query.append("docid", String(args.docid)) if (args.status != null) query.append("status", String(args.status)) if (args.sd != null) query.append("sd", String(args.sd)) if (args.ed != null) query.append("ed", String(args.ed)) if (args.wflowid != null) query.append("wflowid", String(args.wflowid)) if (args.is_abha_linkable != null) query.append("is_abha_linkable", String(args.is_abha_linkable)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.sort != null) query.append("sort", String(args.sort)) if (apiKeyAuth !== undefined) headers.set('authorization', `Bearer ${apiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/assess/fetch_assessments/${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(getApiAssessFetchAssessmentsResponse, await res.json()) };