export type GetApiTranscriptionsSearchArgs = {q?: string | undefined, id?: string | undefined, userName?: string | undefined, userId?: string | undefined, naId?: string | undefined, debug?: boolean | undefined}; export type GetApiTranscriptionsSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get search results for transcriptions data by sending a request with search parameters to the catalog. * * GET /transcriptions/search */ export const getApiTranscriptionsSearch = async (args: GetApiTranscriptionsSearchArgs, options?: GetApiTranscriptionsSearchOptions) => { 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(/\/+$/, '')}/transcriptions/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 };