import localStorage from 'mobx-localstorage'; import { ferdiLocale, ferdiVersion } from '../../environment-remote'; export const prepareAuthRequest = ( // eslint-disable-next-line unicorn/no-object-as-default-parameter options = { method: 'GET' }, auth = true, ) => { const request = Object.assign(options, { mode: 'cors', headers: { 'Content-Type': 'application/json', 'X-Franz-Source': 'desktop', 'X-Franz-Version': ferdiVersion, 'X-Franz-platform': process.platform, 'X-Franz-Timezone-Offset': new Date().getTimezoneOffset(), 'X-Franz-System-Locale': ferdiLocale, // @ts-expect-error Property 'headers' does not exist on type '{ method: string; }'. ...options.headers, }, }); if (auth) { request.headers.Authorization = `Bearer ${localStorage.getItem( 'authToken', )}`; } return request; }; export const sendAuthRequest = ( url: RequestInfo, options: { method: string } | undefined, auth?: boolean, ) => // @ts-expect-error Argument of type '{ method: string; } & { mode: string; headers: any; }' is not assignable to parameter of type 'RequestInit | undefined'. window.fetch(url, prepareAuthRequest(options, auth));