export type GetApiContributionsSearchArgs = {q?: string | undefined, id?: string | undefined, userName?: string | undefined, userId?: string | undefined, naId?: string | undefined, debug?: boolean | undefined, searchAfter?: string | undefined}; export type GetApiContributionsSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get search results for contributions data by sending a request with search parameters to the catalog. * * GET /contributions/search */ export const getApiContributionsSearch = async (args: GetApiContributionsSearchArgs, options?: GetApiContributionsSearchOptions) => { 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)) if (args.searchAfter != null) query.append("searchAfter", String(args.searchAfter)) const url = `${baseUrl.replace(/\/+$/, '')}/contributions/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 };