packages/optimizely-sdk/lib/optimizely/index.js
function Optimizely(config) {
  var clientEngine = config.clientEngine;
  if (clientEngine !== enums.NODE_CLIENT_ENGINE && clientEngine !== enums.JAVASCRIPT_CLIENT_ENGINE) {
    config.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, MODULE_NAME, clientEngine));
    clientEngine = enums.NODE_CLIENT_ENGINE;
  }

  this.clientEngine = clientEngine;
  this.clientVersion = config.clientVersion || enums.NODE_CLIENT_VERSION;
  this.errorHandler = config.errorHandler;
  this.eventDispatcher = config.eventDispatcher;
  this.__isOptimizelyConfigValid = config.isValidInstance;
  this.logger = config.logger;

  this.projectConfigManager = new projectConfigManager.ProjectConfigManager({
    datafile: config.datafile,
    datafileOptions: config.datafileOptions,
    jsonSchemaValidator: config.jsonSchemaValidator,
    sdkKey: config.sdkKey,
    skipJSONValidation: config.skipJSONValidation,
  });

  this.__disposeOnUpdate = this.projectConfigManager.onUpdate(function(configObj) {
    this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, MODULE_NAME, configObj.revision, configObj.projectId));
    this.notificationCenter.sendNotifications(NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE);
  }.bind(this));

  this.__readyPromise = this.projectConfigManager.onReady();

  var userProfileService = null;
  if (config.userProfileService) {
    try {
      if (userProfileServiceValidator.validate(config.userProfileService)) {
        userProfileService = config.userProfileService;
        this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.VALID_USER_PROFILE_SERVICE, MODULE_NAME));
      }
    } catch (ex) {
      this.logger.log(LOG_LEVEL.WARNING, ex.message);
    }
  }

  this.decisionService = decisionService.createDecisionService({
    userProfileService: userProfileService,
    logger: this.logger,
  });

  this.notificationCenter = notificationCenter.createNotificationCenter({
    logger: this.logger,
    errorHandler: this.errorHandler,
  });

  this.eventProcessor = new eventProcessor.LogTierV1EventProcessor({
    dispatcher: this.eventDispatcher,
    flushInterval: config.eventFlushInterval || DEFAULT_EVENT_FLUSH_INTERVAL,
    maxQueueSize: config.eventBatchSize || DEFAULT_EVENT_MAX_QUEUE_SIZE,
  });
  this.eventProcessor.start();

  this.__readyTimeouts = {};
  this.__nextReadyTimeoutId = 0;
}
function Optimizely(config) {
  var clientEngine = config.clientEngine;
  if (clientEngine !== enums.NODE_CLIENT_ENGINE && clientEngine !== enums.JAVASCRIPT_CLIENT_ENGINE) {
    config.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, MODULE_NAME, clientEngine));
    clientEngine = enums.NODE_CLIENT_ENGINE;
  }

  this.clientEngine = clientEngine;
  this.clientVersion = config.clientVersion || enums.NODE_CLIENT_VERSION;
  this.errorHandler = config.errorHandler;
  this.eventDispatcher = config.eventDispatcher;
  this.__isOptimizelyConfigValid = config.isValidInstance;
  this.logger = config.logger;

  this.projectConfigManager = new projectConfigManager.ProjectConfigManager({
    datafile: config.datafile,
    datafileOptions: config.datafileOptions,
    jsonSchemaValidator: config.jsonSchemaValidator,
    sdkKey: config.sdkKey,
    skipJSONValidation: config.skipJSONValidation,
  });

  this.__disposeOnUpdate = this.projectConfigManager.onUpdate(function(configObj) {
    this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, MODULE_NAME, configObj.revision, configObj.projectId));
    this.notificationCenter.sendNotifications(NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE);
  }.bind(this));

  this.__readyPromise = this.projectConfigManager.onReady();

  var userProfileService = null;
  if (config.userProfileService) {
    try {
      if (userProfileServiceValidator.validate(config.userProfileService)) {
        userProfileService = config.userProfileService;
        this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.VALID_USER_PROFILE_SERVICE, MODULE_NAME));
      }
    } catch (ex) {
      this.logger.log(LOG_LEVEL.WARNING, ex.message);
    }
  }

  this.decisionService = decisionService.createDecisionService({
    userProfileService: userProfileService,
    logger: this.logger,
  });

  this.notificationCenter = notificationCenter.createNotificationCenter({
    logger: this.logger,
    errorHandler: this.errorHandler,
  });

  this.eventProcessor = new eventProcessor.LogTierV1EventProcessor({
    dispatcher: this.eventDispatcher,
    flushInterval: config.eventFlushInterval || DEFAULT_EVENT_FLUSH_INTERVAL,
    maxQueueSize: config.eventBatchSize || DEFAULT_EVENT_MAX_QUEUE_SIZE,
  });
  this.eventProcessor.start();

  this.__readyTimeouts = {};
  this.__nextReadyTimeoutId = 0;
}
function Optimizely ( config ) { var clientEngine = config . clientEngine ; if ( clientEngine !== enums . NODE_CLIENT_ENGINE && clientEngine !== enums . JAVASCRIPT_CLIENT_ENGINE ) { config . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . INVALID_CLIENT_ENGINE , MODULE_NAME , clientEngine ) ) ; clientEngine = enums . NODE_CLIENT_ENGINE ; } this . clientEngine = clientEngine ; this . clientVersion = config . clientVersion || enums . NODE_CLIENT_VERSION ; this . errorHandler = config . errorHandler ; this . eventDispatcher = config . eventDispatcher ; this . __isOptimizelyConfigValid = config . isValidInstance ; this . logger = config . logger ; this . projectConfigManager = new projectConfigManager . ProjectConfigManager ( { datafile : config . datafile , datafileOptions : config . datafileOptions , jsonSchemaValidator : config . jsonSchemaValidator , sdkKey : config . sdkKey , skipJSONValidation : config . skipJSONValidation , } ) ; this . __disposeOnUpdate = this . projectConfigManager . onUpdate ( function ( configObj ) { this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . UPDATED_OPTIMIZELY_CONFIG , MODULE_NAME , configObj . revision , configObj . projectId ) ) ; this . notificationCenter . sendNotifications ( NOTIFICATION_TYPES . OPTIMIZELY_CONFIG_UPDATE ) ; } . bind ( this ) ) ; this . __readyPromise = this . projectConfigManager . onReady ( ) ; var userProfileService = null ; if ( config . userProfileService ) { try { if ( userProfileServiceValidator . validate ( config . userProfileService ) ) { userProfileService = config . userProfileService ; this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . VALID_USER_PROFILE_SERVICE , MODULE_NAME ) ) ; } } catch ( ex ) { this . logger . log ( LOG_LEVEL . WARNING , ex . message ) ; } } this . decisionService = decisionService . createDecisionService ( { userProfileService : userProfileService , logger : this . logger , } ) ; this . notificationCenter = notificationCenter . createNotificationCenter ( { logger : this . logger , errorHandler : this . errorHandler , } ) ; this . eventProcessor = new eventProcessor . LogTierV1EventProcessor ( { dispatcher : this . eventDispatcher , flushInterval : config . eventFlushInterval || DEFAULT_EVENT_FLUSH_INTERVAL , maxQueueSize : config . eventBatchSize || DEFAULT_EVENT_MAX_QUEUE_SIZE , } ) ; this . eventProcessor . start ( ) ; this . __readyTimeouts = { } ; this . __nextReadyTimeoutId = 0 ; }
The Optimizely class
@param {Object} config
@param {string} config.clientEngine
@param {string} config.clientVersion
@param {Object} config.datafile
@param {Object} config.errorHandler
@param {Object} config.eventDispatcher
@param {Object} config.logger
@param {Object} config.skipJSONValidation
@param {Object} config.userProfileService
@param {Object} config.eventBatchSize
@param {Object} config.eventFlushInterval
The Optimizely class