export function syncFetch(
   url: string,
   init?: RequestInit & { body?: XMLHttpRequestBodyInit | Document },
) {
   // Running under node.js
   if (typeof window === 'undefined') {
      return require('sync-fetch')(url, init);
   }

   const request = new XMLHttpRequest();
   if (init?.headers) {
      for (const [key, value] of Object.entries(init.headers)) {
         request.setRequestHeader(key, value);
      }
   }

   request.open(init?.method ?? 'GET', url, false);
   request.send(init?.body ?? null);

   return {
      ...request,
      json: () => JSON.parse(request.responseText),
   };
}
