"use strict";

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

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

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

async function sendRequest(path, opts = {}) {
  const headers = Object.assign({}, opts.headers || {}, {
    'Content-type': 'application/json; charset=UTF-8'
  });
  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 && data.error) {
    console.log(data.error);
  }

  return data;
}