<commit_before>import os from 'os';
import path from 'path';
import tar from 'tar';
import fs from 'fs-extra';
import { remote } from 'electron';
import localStorage from 'mobx-localstorage';

import ServiceModel from '../../models/Service';
import RecipePreviewModel from '../../models/RecipePreview';
import RecipeModel from '../../models/Recipe';
import PlanModel from '../../models/Plan';
import NewsModel from '../../models/News';
import UserModel from '../../models/User';
import OrderModel from '../../models/Order';

import { sleep } from '../../helpers/async-helpers';

import { API } from '../../environment';

import {
  getRecipeDirectory,
  getDevRecipeDirectory,
  loadRecipeConfig,
} from '../../helpers/recipe-helpers';

import {
  removeServicePartitionDirectory,
} from '../../helpers/service-helpers.js';

const debug = require('debug')('ServerApi');

module.paths.unshift(
  getDevRecipeDirectory(),
  getRecipeDirectory(),
);

const { app } = remote;
const fetch = remote.require('electron-fetch');

const SERVER_URL = API;
const API_VERSION = 'v1';

export default class ServerApi {
  recipePreviews = [];
  recipes = [];

  // User
  async login(email, passwordHash) {
    const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/auth/login`, this._prepareAuthRequest({
      method: 'POST',
      headers: {
        Authorization: `Basic ${window.btoa(`${email}:${passwordHash}`)}`,
      },
    }, false));
    if (!request.ok) {
      throw request;
    }
    const u = await request.json();

    debug('ServerApi::login resolves', u);
    return u.token;
  }

  async signup(data) {
    const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/auth/signup`, this._prepareAuthRequest({
      method: 'POST',
      body: JSON.stringify(data),<commit_msg>Revert "Fix fetch is undefined"<commit_after>import os from 'os';
import path from 'path';
import tar from 'tar';
import fs from 'fs-extra';
import { remote } from 'electron';
import localStorage from 'mobx-localstorage';

import ServiceModel from '../../models/Service';
import RecipePreviewModel from '../../models/RecipePreview';
import RecipeModel from '../../models/Recipe';
import PlanModel from '../../models/Plan';
import NewsModel from '../../models/News';
import UserModel from '../../models/User';
import OrderModel from '../../models/Order';

import { sleep } from '../../helpers/async-helpers';

import { API } from '../../environment';

import {
  getRecipeDirectory,
  getDevRecipeDirectory,
  loadRecipeConfig,
} from '../../helpers/recipe-helpers';

import {
  removeServicePartitionDirectory,
} from '../../helpers/service-helpers.js';

const debug = require('debug')('ServerApi');

module.paths.unshift(
  getDevRecipeDirectory(),
  getRecipeDirectory(),
);

const { app } = remote;
const { default: fetch } = remote.require('electron-fetch');

const SERVER_URL = API;
const API_VERSION = 'v1';

export default class ServerApi {
  recipePreviews = [];
  recipes = [];

  // User
  async login(email, passwordHash) {
    const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/auth/login`, this._prepareAuthRequest({
      method: 'POST',
      headers: {
        Authorization: `Basic ${window.btoa(`${email}:${passwordHash}`)}`,
      },
    }, false));
    if (!request.ok) {
      throw request;
    }
    const u = await request.json();

    debug('ServerApi::login resolves', u);
    return u.token;
  }

  async signup(data) {
    const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/auth/signup`, this._prepareAuthRequest({
      method: 'POST',
      body: JSON.stringify(data),
{'fraction_non_alphanumeric': 0.17094725214029274, 'fraction_numerical': 0.0005523336095001381, 'mean_word_length': 3.667525773195876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '93453', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1080, 'n_words': 272}