<commit_before>/**
 * Module dependencies.
 */

var regex = require('../regex');
var utils = require('../utils');
var i18n = require('../i18n');
var _ = require('underscore');
var xtend = _.extend;
var okeys = _.keys;

var supportedParams = [
  'state',
  'access_token',
  'scope',
  'protocol',
  'device',
  'request_id',
  'connection_scopes',
  'nonce'
];

/**
 * Expose `OptionsManager`
 */

module.exports = OptionsManager;

/**
 * Create an `OptionsManager` from
 * instanceOptions and displayOptions
 *
 * @param {Auth0Widget} widget
 * @param {Object} displayOptions
 * @constructor
 */

function OptionsManager(widget, options) {
  if (!(this instanceof OptionsManager)) {
    return new OptionsManager(widget, options);
  };

  this.$widget = widget;

  // Set `i18n` dictionary for templates
  this.i18n = i18n.getDict(this.dict);

  // save widget instance options with `$` prepended
  _.each(okeys(widget.$options), function(key) {
    this["$" + key] = widget.$options[key];
  }, this);

  // save widget's $client object reference
  this.$client = widget.$client;

  this.$strategies = widget.$strategies;

  // copies all provided options to instance
  _.each(okeys(options), function(key) {
    this[key] = options[key];
  }, this);

  // Copies the supportedParams from displayOptions
  // to this.extraParameters
  var extra = utils.extract(options, supportedParams);
  this.extraParameters = _.extend({}, extra, options.extraParameters);

  // labels text
  // XXX: ?????????? @siacomuzzi
  this.showEmail = null != options.showEmail
    ? options.showEmail
    : true;
  this.showPassword = null != options.showPassword
    ? options.showPassword
    : true;
  this.rememberLastLogin = null != options.rememberLastLogin
    ? options.rememberLastLogin
    : true;
  this.enableADRealmDiscovery = null != options.enableADRealmDiscovery
    ? options.enableADRealmDiscovery
    : true;

  if (!_.isEmpty(this.$client)) {
    this._onclientloaded(this.$client);
  } else {
    var setClient = global.window.Auth0.setClient;
    var self = this;
    global.window.Auth0.setClient = function(client) {
      setClient.apply(window.Auth0, arguments);
      self.$client = _.extend(self.$client, client);
      self._onclientloaded.call(self);
    }
  }
}

OptionsManager.prototype._onclientloaded = function() {

  // Enrich $client.strategies
  // then, continue setting up the mode
  if (this.connections) {
    this.$client.strategies = _.chain(this.$client.strategies)
      .map(strategiesConnectionsMapper(options.connections))<commit_msg>Fix .strategies setup by options-manager<commit_after>/**
 * Module dependencies.
 */

var regex = require('../regex');
var utils = require('../utils');
var i18n = require('../i18n');
var _ = require('underscore');
var xtend = _.extend;
var okeys = _.keys;

var supportedParams = [
  'state',
  'access_token',
  'scope',
  'protocol',
  'device',
  'request_id',
  'connection_scopes',
  'nonce'
];

/**
 * Expose `OptionsManager`
 */

module.exports = OptionsManager;

/**
 * Create an `OptionsManager` from
 * instanceOptions and displayOptions
 *
 * @param {Auth0Widget} widget
 * @param {Object} displayOptions
 * @constructor
 */

function OptionsManager(widget, options) {
  if (!(this instanceof OptionsManager)) {
    return new OptionsManager(widget, options);
  };

  this.$widget = widget;

  // Set `i18n` dictionary for templates
  this.i18n = i18n.getDict(this.dict);

  // save widget instance options with `$` prepended
  _.each(okeys(widget.$options), function(key) {
    this["$" + key] = widget.$options[key];
  }, this);

  // save widget's $client object reference
  this.$client = widget.$client;

  this.$strategies = widget.$strategies;

  // copies all provided options to instance
  _.each(okeys(options), function(key) {
    this[key] = options[key];
  }, this);

  // Copies the supportedParams from displayOptions
  // to this.extraParameters
  var extra = utils.extract(options, supportedParams);
  this.extraParameters = _.extend({}, extra, options.extraParameters);

  // labels text
  // XXX: ?????????? @siacomuzzi
  this.showEmail = null != options.showEmail
    ? options.showEmail
    : true;
  this.showPassword = null != options.showPassword
    ? options.showPassword
    : true;
  this.rememberLastLogin = null != options.rememberLastLogin
    ? options.rememberLastLogin
    : true;
  this.enableADRealmDiscovery = null != options.enableADRealmDiscovery
    ? options.enableADRealmDiscovery
    : true;

  if (!_.isEmpty(this.$client)) {
    this._onclientloaded(this.$client);
  } else {
    var setClient = global.window.Auth0.setClient;
    var self = this;
    global.window.Auth0.setClient = function(client) {
      setClient.apply(window.Auth0, arguments);
      self.$client = _.extend(self.$client, client);
      self._onclientloaded.call(self);
    }
  }
}

OptionsManager.prototype._onclientloaded = function() {

  // Enrich $client.strategies
  // then, continue setting up the mode
  if (this.connections) {
    this.$client.strategies = _.chain(this.$client.strategies)
      .map(strategiesConnectionsMapper(this.connections))
{'fraction_non_alphanumeric': 0.14296814296814297, 'fraction_numerical': 0.005439005439005439, 'mean_word_length': 3.6851683348498634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '897874', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1579, 'n_words': 347}