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