"use strict";

var _insecure = _interopRequireDefault(require("./keychain/insecure"));

var _browser = _interopRequireDefault(require("./keychain/browser"));

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

/**
 * External dependencies
 */
const debug = require('debug')('@automattic/vip:keychain');
/**
 * Internal dependencies
 */


let e = {};

if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
  // node
  try {
    // Try using Secure keychain ("keytar") first
    const Secure = require("./keychain/secure");

    e = new Secure();
  } catch (error) {
    debug('Cannot use Secure keychain; falling back to Insecure keychain (Details: %o)', error); // Fallback to Insecure keychain if we can't

    e = new _insecure.default('vip-go-cli');
  }
} else {
  e = new _browser.default();
}

module.exports = e;