export type GetApiRecordsSearchByCommentArgs = {q?: string | undefined, id?: string | undefined, userName?: string | undefined, userId?: string | undefined, naId?: string | undefined, page?: number | undefined, limit?: number | undefined, debug?: boolean | undefined, abbreviated?: boolean | undefined}; export type GetApiRecordsSearchByCommentOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get records related to comments by using url parameters to perform a catalog search. * * GET /records/search/by-comment */ export const getApiRecordsSearchByComment = async (args: GetApiRecordsSearchByCommentArgs, options?: GetApiRecordsSearchByCommentOptions) => { 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.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.debug != null) query.append("debug", String(args.debug)) if (args.abbreviated != null) query.append("abbreviated", String(args.abbreviated)) const url = `${baseUrl.replace(/\/+$/, '')}/records/search/by-comment${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 };