import {z} from 'zod' export type GetApiFeedbackResponsesArgs = {patient?: string | undefined, provider?: string | undefined, facility?: string | undefined, appointment?: string | undefined, 'response.type'?: ('npsscore' | 'positive-click' | 'negative-click') | undefined, user?: string | undefined, deleted?: number | undefined, createdBy?: string | undefined, updatedBy?: string | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, page?: number | undefined, limit?: number | undefined, _populate?: string | undefined, _select?: string | undefined}; export type GetApiFeedbackResponsesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiFeedbackResponsesResponse = z.object({response: z.array(z.object({_id: z.string().optional(), patient: z.string().optional(), provider: z.string().optional(), facility: z.string().optional(), appointment: z.string().optional(), npsscore: z.number().optional(), response: z.object({type: z.enum(["npsscore", "positive-click", "negative-click"]).optional(), value: z.unknown()}).optional(), scoreSource: z.enum(["patient", "sentiment"]).optional()})).optional(), page: z.number().int().optional(), size: z.number().int().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 }; /** * List feedback responses * * GET /feedbackResponses */ export const getApiFeedbackResponses = async (args: GetApiFeedbackResponsesArgs, options?: GetApiFeedbackResponsesOptions) => { const {baseUrl = "https://api.lumahealth.io/api/v2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.patient != null) query.append("patient", String(args.patient)) if (args.provider != null) query.append("provider", String(args.provider)) if (args.facility != null) query.append("facility", String(args.facility)) if (args.appointment != null) query.append("appointment", String(args.appointment)) if (args['response.type'] != null) query.append("response.type", String(args['response.type'])) if (args.user != null) query.append("user", String(args.user)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.createdBy != null) query.append("createdBy", String(args.createdBy)) if (args.updatedBy != null) query.append("updatedBy", String(args.updatedBy)) if (args.createdAt != null) query.append("createdAt", String(args.createdAt)) if (args.updatedAt != null) query.append("updatedAt", String(args.updatedAt)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args._populate != null) query.append("_populate", String(args._populate)) if (args._select != null) query.append("_select", String(args._select)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/feedbackResponses${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(getApiFeedbackResponsesResponse, await res.json()) };