export default async function ServerRequest<T>(
  action: Promise<any> | any,
): Promise<ServerRequest<T>> {
  const response = await action;
  const json = response ? JSON.parse(response) : { operation: false };

  if (!json.operation && json.data && json.data.callback) {
    window.location.href = json.data.callback;
  }

  return json;
}
