text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var _uuid = _interopRequireDefault(require("./uuid"));
  
  var _flow_interfaces = require("../flow_interfaces");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  var PRESENCE_TIMEOUT_MINIMUM = 20;
  var PRESENCE_TIMEOUT_DEFAULT = 300;
  
  var _default = function () {
    function _default(_ref) {
      var setup = _ref.setup,
          db = _ref.db;
  
      _classCallCheck(this, _default);
  
      _defineProperty(this, "_db", void 0);
  
      _defineProperty(this, "subscribeKey", void 0);
  
      _defineProperty(this, "publishKey", void 0);
  
      _defineProperty(this, "secretKey", void 0);
  
      _defineProperty(this, "cipherKey", void 0);
  
      _defineProperty(this, "authKey", void 0);
  
      _defineProperty(this, "UUID", void 0);
  
      _defineProperty(this, "proxy", void 0);
  
      _defineProperty(this, "instanceId", void 0);
  
      _defineProperty(this, "sdkName", void 0);
  
      _defineProperty(this, "sdkFamily", void 0);
  
      _defineProperty(this, "partnerId", void 0);
  
      _defineProperty(this, "filterExpression", void 0);
  
      _defineProperty(this, "suppressLeaveEvents", void 0);
  
      _defineProperty(this, "secure", void 0);
  
      _defineProperty(this, "origin", void 0);
  
      _defineProperty(this, "logVerbosity", void 0);
  
      _defineProperty(this, "useInstanceId", void 0);
  
      _defineProperty(this, "useRequestId", void 0);
  
      _defineProperty(this, "keepAlive", void 0);
  
      _defineProperty(this, "keepAliveSettings", void 0);
  
      _defineProperty(this, "autoNetworkDetection", void 0);
  
      _defineProperty(this, "announceSuccessfulHeartbeats", void 0);
  
      _defineProperty(this, "announceFailedHeartbeats", void 0);
  
      _defineProperty(this, "_presenceTimeout", void 0);
  
      _defineProperty(this, "_heartbeatInterval", void 0);
  
      _defineProperty(this, "_subscribeRequestTimeout", void 0);
  
      _defineProperty(this, "_transactionalRequestTimeout", void 0);
  
      _defineProperty(this, "_useSendBeacon", void 0);
  
      _defineProperty(this, "_PNSDKSuffix", void 0);
  
      _defineProperty(this, "requestMessageCountThreshold", void 0);
  
      _defineProperty(this, "restore", void 0);
  
      _defineProperty(this, "dedupeOnSubscribe", void 0);
  
      _defineProperty(this, "maximumCacheSize", void 0);
  
      _defineProperty(this, "customEncrypt", void 0);
  
      _defineProperty(this, "customDecrypt", void 0);
  
      this._PNSDKSuffix = {};
      this._db = db;
      this.instanceId = "pn-".concat(_uuid["default"].createUUID());
      this.secretKey = setup.secretKey || setup.secret_key;
      this.subscribeKey = setup.subscribeKey || setup.subscribe_key;
      this.publishKey = setup.publishKey || setup.publish_key;
      this.sdkName = setup.sdkName;
      this.sdkFamily = setup.sdkFamily;
      this.partnerId = setup.partnerId;
      this.setAuthKey(setup.authKey);
      this.setCipherKey(setup.cipherKey);
      this.setFilterExpression(setup.filterExpression);
      this.origin = setup.origin || 'ps.pndsn.com';
      this.secure = setup.ssl || false;
      this.restore = setup.restore || false;
      this.proxy = setup.proxy;
      this.keepAlive = setup.keepAlive;
      this.keepAliveSettings = setup.keepAliveSettings;
      this.autoNetworkDetection = setup.autoNetworkDetection || false;
      this.dedupeOnSubscribe = setup.dedupeOnSubscribe || false;
      this.maximumCacheSize = setup.maximumCacheSize || 100;
      this.customEncrypt = setup.customEncrypt;
      this.customDecrypt = setup.customDecrypt;
  
      if (typeof location !== 'undefined' && location.protocol === 'https:') {
        this.secure = true;
      }
  
      this.logVerbosity = setup.logVerbosity || false;
      this.suppressLeaveEvents = setup.suppressLeaveEvents || false;
      this.announceFailedHeartbeats = setup.announceFailedHeartbeats || true;
      this.announceSuccessfulHeartbeats = setup.announceSuccessfulHeartbeats || false;
      this.useInstanceId = setup.useInstanceId || false;
      this.useRequestId = setup.useRequestId || false;
      this.requestMessageCountThreshold = setup.requestMessageCountThreshold;
      this.setTransactionTimeout(setup.transactionalRequestTimeout || 15 * 1000);
      this.setSubscribeTimeout(setup.subscribeRequestTimeout || 310 * 1000);
      this.setSendBeaconConfig(setup.useSendBeacon || true);
  
      if (setup.presenceTimeout) {
        this.setPresenceTimeout(setup.presenceTimeout);
      } else {
        this._presenceTimeout = PRESENCE_TIMEOUT_DEFAULT;
      }
  
      if (setup.heartbeatInterval != null) {
        this.setHeartbeatInterval(setup.heartbeatInterval);
      }
  
      this.setUUID(this._decideUUID(setup.uuid));
    }
  
    _createClass(_default, [{
      key: "getAuthKey",
      value: function getAuthKey() {
        return this.authKey;
      }
    }, {
      key: "setAuthKey",
      value: function setAuthKey(val) {
        this.authKey = val;
        return this;
      }
    }, {
      key: "setCipherKey",
      value: function setCipherKey(val) {
        this.cipherKey = val;
        return this;
      }
    }, {
      key: "getUUID",
      value: function getUUID() {
        return this.UUID;
      }
    }, {
      key: "setUUID",
      value: function setUUID(val) {
        if (this._db && this._db.set) this._db.set("".concat(this.subscribeKey, "uuid"), val);
        this.UUID = val;
        return this;
      }
    }, {
      key: "getFilterExpression",
      value: function getFilterExpression() {
        return this.filterExpression;
      }
    }, {
      key: "setFilterExpression",
      value: function setFilterExpression(val) {
        this.filterExpression = val;
        return this;
      }
    }, {
      key: "getPresenceTimeout",
      value: function getPresenceTimeout() {
        return this._presenceTimeout;
      }
    }, {
      key: "setPresenceTimeout",
      value: function setPresenceTimeout(val) {
        if (val >= PRESENCE_TIMEOUT_MINIMUM) {
          this._presenceTimeout = val;
        } else {
          this._presenceTimeout = PRESENCE_TIMEOUT_MINIMUM;
          console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', this._presenceTimeout);
        }
  
        this.setHeartbeatInterval(this._presenceTimeout / 2 - 1);
        return this;
      }
    }, {
      key: "setProxy",
      value: function setProxy(proxy) {
        this.proxy = proxy;
      }
    }, {
      key: "getHeartbeatInterval",
      value: function getHeartbeatInterval() {
        return this._heartbeatInterval;
      }
    }, {
      key: "setHeartbeatInterval",
      value: function setHeartbeatInterval(val) {
        this._heartbeatInterval = val;
        return this;
      }
    }, {
      key: "getSubscribeTimeout",
      value: function getSubscribeTimeout() {
        return this._subscribeRequestTimeout;
      }
    }, {
      key: "setSubscribeTimeout",
      value: function setSubscribeTimeout(val) {
        this._subscribeRequestTimeout = val;
        return this;
      }
    }, {
      key: "getTransactionTimeout",
      value: function getTransactionTimeout() {
        return this._transactionalRequestTimeout;
      }
    }, {
      key: "setTransactionTimeout",
      value: function setTransactionTimeout(val) {
        this._transactionalRequestTimeout = val;
        return this;
      }
    }, {
      key: "isSendBeaconEnabled",
      value: function isSendBeaconEnabled() {
        return this._useSendBeacon;
      }
    }, {
      key: "setSendBeaconConfig",
      value: function setSendBeaconConfig(val) {
        this._useSendBeacon = val;
        return this;
      }
    }, {
      key: "getVersion",
      value: function getVersion() {
        return '4.27.3';
      }
    }, {
      key: "_addPnsdkSuffix",
      value: function _addPnsdkSuffix(name, suffix) {
        this._PNSDKSuffix[name] = suffix;
      }
    }, {
      key: "_getPnsdkSuffix",
      value: function _getPnsdkSuffix(separator) {
        var _this = this;
  
        return Object.keys(this._PNSDKSuffix).reduce(function (result, key) {
          return result + separator + _this._PNSDKSuffix[key];
        }, '');
      }
    }, {
      key: "_decideUUID",
      value: function _decideUUID(providedUUID) {
        if (providedUUID) {
          return providedUUID;
        }
  
        if (this._db && this._db.get && this._db.get("".concat(this.subscribeKey, "uuid"))) {
          return this._db.get("".concat(this.subscribeKey, "uuid"));
        }
  
        return "pn-".concat(_uuid["default"].createUUID());
      }
    }]);
  
    return _default;
  }();
  
  exports["default"] = _default;
  module.exports = exports.default;
  //# sourceMappingURL=config.js.map
  