export type BackupDestination = {path?: string | undefined, server_list_id_prefix?: string | undefined, server_list_id_suffix?: string | undefined, type: string}; export type ListQL = {all_in_sets?: Array | undefined, lists?: Array | undefined, match_metadata?: {[key: string]: unknown} | undefined}; export type MultiListBackup = {destination: BackupDestination, lists: ListQL}; export type UpdateApiXlistBackupArgs = {body: MultiListBackup}; export type UpdateApiXlistBackupOptions = {baseUrl: string, jwt?: string | undefined, fetch?: typeof fetch | undefined}; /** * Backup lists * * PUT /xlist/backup */ export const updateApiXlistBackup = async (args: UpdateApiXlistBackupArgs, options: UpdateApiXlistBackupOptions) => { const {baseUrl, fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (jwt !== undefined) headers.set("Authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/xlist/backup${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };