export type GetApiSearchIndexOperationArgs = {index: string, operation: string, q?: string | undefined}; export type GetApiSearchIndexOperationOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Perform simple search queries over Auckland Museum Collections and Cenotaph data * * GET /search/{index}/{operation} */ export const getApiSearchIndexOperation = async (args: GetApiSearchIndexOperationArgs, options: GetApiSearchIndexOperationOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.q != null) query.append("q", String(args.q)) const url = `${baseUrl.replace(/\/+$/, '')}/search/${encodeURIComponent(String(args.index))}/${encodeURIComponent(String(args.operation))}${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 };