export type UpdateApiConfigurationFieldArgs = {field: string, reindex?: boolean | undefined, body: BodyInit}; export type UpdateApiConfigurationFieldOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Set a specific configuration field * * PUT /configuration/{field} */ export const updateApiConfigurationField = async (args: UpdateApiConfigurationFieldArgs, options: UpdateApiConfigurationFieldOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") if (args.reindex != null) query.append("reindex", String(args.reindex)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/configuration/${encodeURIComponent(String(args.field))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };