import {z} from 'zod' export type GetApiFeedbackResponsesExternalReviewsArgs = {user?: string | undefined, deleted?: number | undefined, page?: number | undefined, limit?: number | undefined, _select?: string | undefined, platform?: ('google' | 'yelp') | undefined, replyEligible?: boolean | undefined}; export type GetApiFeedbackResponsesExternalReviewsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiFeedbackResponsesExternalReviewsResponse = z.object({response: z.array(z.object({_id: z.string().optional(), platform: z.enum(["google", "yelp"]).optional(), externalId: z.object({source: z.enum(["google", "yelp"]), value: z.string(), location: z.string(), vendorSecret: z.string()}).optional(), externalAuthorName: z.string().optional(), rating: z.number().gte(1).lte(5).optional(), reviewText: z.string().optional(), reviewedAt: z.string().optional(), sentiment: z.enum(["positive", "neutral", "negative"]).optional(), themes: z.array(z.string()).optional(), replyEligible: z.boolean().optional(), platformRepliedAt: z.string().optional(), facility: z.string().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 external reviews * * GET /feedbackResponsesExternalReviews */ export const getApiFeedbackResponsesExternalReviews = async (args: GetApiFeedbackResponsesExternalReviewsArgs, options?: GetApiFeedbackResponsesExternalReviewsOptions) => { 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.user != null) query.append("user", String(args.user)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args._select != null) query.append("_select", String(args._select)) if (args.platform != null) query.append("platform", String(args.platform)) if (args.replyEligible != null) query.append("replyEligible", String(args.replyEligible)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/feedbackResponsesExternalReviews${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(getApiFeedbackResponsesExternalReviewsResponse, await res.json()) };