'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.configureCSpace = exports.createSession = exports.CSPACE_CONFIGURED = undefined;

var _cspaceClient = require('cspace-client');

var _cspaceClient2 = _interopRequireDefault(_cspaceClient);

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

var CSPACE_CONFIGURED = exports.CSPACE_CONFIGURED = 'CSPACE_CONFIGURED';

var client = void 0;
var session = void 0;

var createSession = exports.createSession = function createSession(username, password) {
  if (typeof username === 'undefined' && typeof password === 'undefined') {
    session = client.session();
  } else {
    session = client.session({
      username: username,
      password: password
    });
  }

  return {
    type: CSPACE_CONFIGURED,
    payload: session.config()
  };
};

var configureCSpace = exports.configureCSpace = function configureCSpace(config) {
  client = (0, _cspaceClient2.default)(config);

  return createSession();
};

exports.default = function () {
  return session;
};