export type ReindexBulkActionSchema = {include_assets?: boolean | undefined, include_collections?: boolean | undefined, object_ids: Array, object_type: 'assets' | 'collections' | 'saved_searches', realms?: (Array | null) | undefined, sync_to_another_dc?: boolean | undefined}; export type CreateApiV1ReindexBulkArgs = {'Auth-Token': string, 'App-ID': string, body: ReindexBulkActionSchema}; export type CreateApiV1ReindexBulkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Create a job for bulk reindexing of assets * * POST /v1/reindex/bulk/ */ export const createApiV1ReindexBulk = async (args: CreateApiV1ReindexBulkArgs, options: CreateApiV1ReindexBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/reindex/bulk/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 };