export type UpdatePushPreferenceDto = {enabled: boolean}; export type PatchApiNotificationsPushPreferenceArgs = {body: UpdatePushPreferenceDto}; export type PatchApiNotificationsPushPreferenceOptions = {baseUrl?: string | undefined, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * Enable/disable push notifications for current user * * PATCH /notifications/push-preference */ export const patchApiNotificationsPushPreference = async (args: PatchApiNotificationsPushPreferenceArgs, options?: PatchApiNotificationsPushPreferenceOptions) => { const {baseUrl = "https://api.findmydocument.net", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/notifications/push-preference${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 };