export type MoveFolderAction = {srcPath: string, dstPath: string}; export type CreateApiMoveArgs = {'X-Resource-Version'?: string | undefined, body: MoveFolderAction}; export type CreateApiMoveOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Move/Rename a folder * * POST /move */ export const createApiMove = async (args: CreateApiMoveArgs, options?: CreateApiMoveOptions) => { const {baseUrl = "https://developers.bloomreach.io/delivery/site/v2/documents", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Resource-Version'] != null) headers.set("X-Resource-Version", String(args['X-Resource-Version'])) const url = `${baseUrl.replace(/\/+$/, '')}/move${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 };