export type UserPreferences = {categories?: (Array<{channels?: (Array<{enabled?: boolean | undefined, name?: string | undefined}>) | undefined, key?: string | undefined, label?: (string | null) | undefined}>) | undefined}; export type UpdateApiChannelsUserPreferencesArgs = {body: UserPreferences}; export type UpdateApiChannelsUserPreferencesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Save channel preferences * * PUT /channels/user_preferences */ export const updateApiChannelsUserPreferences = async (args: UpdateApiChannelsUserPreferencesArgs, options?: UpdateApiChannelsUserPreferencesOptions) => { const {baseUrl = "https://api.magicbell.com/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/channels/user_preferences${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 };