export type StateChangeActionDto = {action: Record}; export type PatchApiApiV1IndexStateArgs = {body: StateChangeActionDto}; export type PatchApiApiV1IndexStateOptions = {baseUrl: string, LocalUserJWT?: string | undefined, fetch?: typeof fetch | undefined}; /** * 🛡️ Control the current indexing run. * * PATCH /api/v1/index/state */ export const patchApiApiV1IndexState = async (args: PatchApiApiV1IndexStateArgs, options: PatchApiApiV1IndexStateOptions) => { const {baseUrl, fetch: fetchFn = fetch, LocalUserJWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (LocalUserJWT !== undefined) headers.set('authorization', `Bearer ${LocalUserJWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/index/state${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };