export type GetApiCommentsSearchArgs = {q?: string | undefined, id?: string | undefined, userName?: string | undefined, userId?: string | undefined, naId?: string | undefined, debug?: boolean | undefined}; export type GetApiCommentsSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get search results for comment data by sending a request with search parameters to the catalog. * * GET /comments/search */ export const getApiCommentsSearch = async (args: GetApiCommentsSearchArgs, options?: GetApiCommentsSearchOptions) => { const {baseUrl = "https://catalog.archives.gov/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.q != null) query.append("q", String(args.q)) if (args.id != null) query.append("id", String(args.id)) if (args.userName != null) query.append("userName", String(args.userName)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.naId != null) query.append("naId", String(args.naId)) if (args.debug != null) query.append("debug", String(args.debug)) const url = `${baseUrl.replace(/\/+$/, '')}/comments/search${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 undefined };