"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.sendRequestWithFile = sendRequestWithFile;

var _store = _interopRequireDefault(require("../../stores/store"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// import { getRootUrl } from './getRootUrl'
async function sendRequestWithFile(path, opts = {}) {
  const headers = Object.assign({}, opts.headers || {}, {});
  const response = await fetch(`${_store.default.state.rootURL}/api/v1${path}`, Object.assign({
    method: 'POST',
    credentials: 'same-origin'
  }, opts, {
    headers
  }));
  const data = await response.json();

  if (data.error) {
    throw new Error(data.error);
  }

  return data;
}