Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Optimizely(config) {
skipJSONValidation: config.skipJSONValidation,
});

this.__disposeOnUpdate = this.projectConfigManager.onUpdate(function(configObj) {
this.__disposeOnUpdate = this.projectConfigManager.onUpdate(function (configObj) {
this.logger.log(LOG_LEVEL.INFO, jsSdkUtils.sprintf(LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, MODULE_NAME, configObj.revision, configObj.projectId));
this.notificationCenter.sendNotifications(NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE);
}.bind(this));
Expand Down Expand Up @@ -124,7 +124,7 @@ function Optimizely(config) {
* constructor was also valid.
* @return {*}
*/
Optimizely.prototype.__isValidInstance = function() {
Optimizely.prototype.__isValidInstance = function () {
return this.__isOptimizelyConfigValid && this.projectConfigManager.getConfig();
};

Expand All @@ -135,7 +135,7 @@ Optimizely.prototype.__isValidInstance = function() {
* @param {Object} attributes
* @return {string|null} variation key
*/
Optimizely.prototype.activate = function(experimentKey, userId, attributes) {
Optimizely.prototype.activate = function (experimentKey, userId, attributes) {
try {
if (!this.__isValidInstance()) {
this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'activate'));
Expand Down Expand Up @@ -194,7 +194,7 @@ Optimizely.prototype.activate = function(experimentKey, userId, attributes) {
* @param {string} userId ID of user to whom the variation was shown
* @param {Object} attributes Optional user attributes
*/
Optimizely.prototype._sendImpressionEvent = function(experimentKey, variationKey, userId, attributes) {
Optimizely.prototype._sendImpressionEvent = function (experimentKey, variationKey, userId, attributes) {
var configObj = this.projectConfigManager.getConfig();
if (!configObj) {
return;
Expand All @@ -221,7 +221,7 @@ Optimizely.prototype._sendImpressionEvent = function(experimentKey, variationKey
* @param {string} userId ID of user to whom the variation was shown
* @param {Object} attributes Optional user attributes
*/
Optimizely.prototype.__emitNotificationCenterActivate = function(experimentKey, variationKey, userId, attributes) {
Optimizely.prototype.__emitNotificationCenterActivate = function (experimentKey, variationKey, userId, attributes) {
var configObj = this.projectConfigManager.getConfig();
if (!configObj) {
return;
Expand Down Expand Up @@ -268,7 +268,7 @@ Optimizely.prototype.__emitNotificationCenterActivate = function(experimentKey,
* @param {string} attributes
* @param {Object} eventTags Values associated with the event.
*/
Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) {
Optimizely.prototype.track = function (eventKey, userId, attributes, eventTags) {
try {
if (!this.__isValidInstance()) {
this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'track'));
Expand Down Expand Up @@ -318,7 +318,7 @@ Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) {
* @param {string} attributes
* @param {Object} eventTags Values associated with the event.
*/
Optimizely.prototype.__emitNotificationCenterTrack = function(eventKey, userId, attributes, eventTags) {
Optimizely.prototype.__emitNotificationCenterTrack = function (eventKey, userId, attributes, eventTags) {
try {
var configObj = this.projectConfigManager.getConfig();
if (!configObj) {
Expand Down Expand Up @@ -357,7 +357,7 @@ Optimizely.prototype.__emitNotificationCenterTrack = function(eventKey, userId,
* @param {Object} attributes
* @return {string|null} variation key
*/
Optimizely.prototype.getVariation = function(experimentKey, userId, attributes) {
Optimizely.prototype.getVariation = function (experimentKey, userId, attributes) {
try {
if (!this.__isValidInstance()) {
this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getVariation'));
Expand Down Expand Up @@ -417,7 +417,7 @@ Optimizely.prototype.getVariation = function(experimentKey, userId, attributes)
* @param {string|null} variationKey user will be forced into. If null, then clear the existing experiment-to-variation mapping.
* @return boolean A boolean value that indicates if the set completed successfully.
*/
Optimizely.prototype.setForcedVariation = function(experimentKey, userId, variationKey) {
Optimizely.prototype.setForcedVariation = function (experimentKey, userId, variationKey) {
if (!this.__validateInputs({ experiment_key: experimentKey, user_id: userId })) {
return false;
}
Expand All @@ -442,7 +442,7 @@ Optimizely.prototype.setForcedVariation = function(experimentKey, userId, variat
* @param {string} userId
* @return {string|null} The forced variation key.
*/
Optimizely.prototype.getForcedVariation = function(experimentKey, userId) {
Optimizely.prototype.getForcedVariation = function (experimentKey, userId) {
if (!this.__validateInputs({ experiment_key: experimentKey, user_id: userId })) {
return null;
}
Expand All @@ -469,7 +469,7 @@ Optimizely.prototype.getForcedVariation = function(experimentKey, userId) {
* @return {boolean} True if inputs are valid
*
*/
Optimizely.prototype.__validateInputs = function(stringInputs, userAttributes, eventTags) {
Optimizely.prototype.__validateInputs = function (stringInputs, userAttributes, eventTags) {
try {
// Null, undefined or non-string user Id is invalid.
if (stringInputs.hasOwnProperty('user_id')) {
Expand Down Expand Up @@ -508,7 +508,7 @@ Optimizely.prototype.__validateInputs = function(stringInputs, userAttributes, e
* @param userId
* @return {null}
*/
Optimizely.prototype.__notActivatingExperiment = function(experimentKey, userId) {
Optimizely.prototype.__notActivatingExperiment = function (experimentKey, userId) {
var failedActivationLogMessage = jsSdkUtils.sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, MODULE_NAME, userId, experimentKey);
this.logger.log(LOG_LEVEL.INFO, failedActivationLogMessage);
return null;
Expand All @@ -519,7 +519,7 @@ Optimizely.prototype.__notActivatingExperiment = function(experimentKey, userId)
* @param map
* @returns {Object} map
*/
Optimizely.prototype.__filterEmptyValues = function(map) {
Optimizely.prototype.__filterEmptyValues = function (map) {
for (var key in map) {
if (map.hasOwnProperty(key) && (map[key] === null || map[key] === undefined)) {
delete map[key];
Expand All @@ -535,7 +535,7 @@ Optimizely.prototype.__filterEmptyValues = function(map) {
* @param {Object} attributes Optional user attributes
* @return {boolean} True if the feature is enabled for the user, false otherwise
*/
Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes) {
Optimizely.prototype.isFeatureEnabled = function (featureKey, userId, attributes) {
try {
if (!this.__isValidInstance()) {
this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'isFeatureEnabled'));
Expand Down Expand Up @@ -612,7 +612,7 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes)
* @param {Object} attributes
* @return {Array} Array of feature keys (strings)
*/
Optimizely.prototype.getEnabledFeatures = function(userId, attributes) {
Optimizely.prototype.getEnabledFeatures = function (userId, attributes) {
try {
var enabledFeatures = [];
if (!this.__isValidInstance()) {
Expand Down Expand Up @@ -658,7 +658,7 @@ Optimizely.prototype.getEnabledFeatures = function(userId, attributes) {
* the variable key is invalid
*/

Optimizely.prototype.getFeatureVariable = function(featureKey, variableKey, userId, attributes) {
Optimizely.prototype.getFeatureVariable = function (featureKey, variableKey, userId, attributes) {
try {
return this._getFeatureVariableForType(featureKey, variableKey, null, userId, attributes);
} catch (e) {
Expand Down Expand Up @@ -690,7 +690,7 @@ Optimizely.prototype.getFeatureVariable = function(featureKey, variableKey, user
* variable key is invalid, or there is a mismatch
* with the type of the variable
*/
Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableKey, variableType, userId, attributes) {
Optimizely.prototype._getFeatureVariableForType = function (featureKey, variableKey, variableType, userId, attributes) {
if (!this.__isValidInstance()) {
var apiName = (variableType) ? 'getFeatureVariable' + variableType.charAt(0).toUpperCase() + variableType.slice(1) : 'getFeatureVariable';
this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, apiName));
Expand Down Expand Up @@ -792,7 +792,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK
* invalid, or there is a mismatch with the type
* of the variable
*/
Optimizely.prototype.getFeatureVariableBoolean = function(featureKey, variableKey, userId, attributes) {
Optimizely.prototype.getFeatureVariableBoolean = function (featureKey, variableKey, userId, attributes) {
try {
return this._getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.BOOLEAN, userId, attributes);
} catch (e) {
Expand All @@ -816,7 +816,7 @@ Optimizely.prototype.getFeatureVariableBoolean = function(featureKey, variableKe
* invalid, or there is a mismatch with the type
* of the variable
*/
Optimizely.prototype.getFeatureVariableDouble = function(featureKey, variableKey, userId, attributes) {
Optimizely.prototype.getFeatureVariableDouble = function (featureKey, variableKey, userId, attributes) {
try {
return this._getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.DOUBLE, userId, attributes);
} catch (e) {
Expand All @@ -840,7 +840,7 @@ Optimizely.prototype.getFeatureVariableDouble = function(featureKey, variableKey
* invalid, or there is a mismatch with the type
* of the variable
*/
Optimizely.prototype.getFeatureVariableInteger = function(featureKey, variableKey, userId, attributes) {
Optimizely.prototype.getFeatureVariableInteger = function (featureKey, variableKey, userId, attributes) {
try {
return this._getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.INTEGER, userId, attributes);
} catch (e) {
Expand All @@ -864,7 +864,7 @@ Optimizely.prototype.getFeatureVariableInteger = function(featureKey, variableKe
* invalid, or there is a mismatch with the type
* of the variable
*/
Optimizely.prototype.getFeatureVariableString = function(featureKey, variableKey, userId, attributes) {
Optimizely.prototype.getFeatureVariableString = function (featureKey, variableKey, userId, attributes) {
try {
return this._getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.STRING, userId, attributes);
} catch (e) {
Expand Down Expand Up @@ -910,7 +910,7 @@ Optimizely.prototype.getFeatureVariableString = function(featureKey, variableKey
* }
* }
*/
Optimizely.prototype.getOptimizelyConfig = function() {
Optimizely.prototype.getOptimizelyConfig = function () {
try {
var configObj = this.projectConfigManager.getConfig();
if (!configObj) {
Expand Down Expand Up @@ -955,7 +955,7 @@ Optimizely.prototype.getOptimizelyConfig = function() {
*
* @return {Promise}
*/
Optimizely.prototype.close = function() {
Optimizely.prototype.close = function () {
try {
var eventProcessorStoppedPromise = this.eventProcessor.stop();
if (this.__disposeOnUpdate) {
Expand All @@ -965,19 +965,19 @@ Optimizely.prototype.close = function() {
if (this.projectConfigManager) {
this.projectConfigManager.stop();
}
Object.keys(this.__readyTimeouts).forEach(function(readyTimeoutId) {
Object.keys(this.__readyTimeouts).forEach(function (readyTimeoutId) {
var readyTimeoutRecord = this.__readyTimeouts[readyTimeoutId];
clearTimeout(readyTimeoutRecord.readyTimeout);
readyTimeoutRecord.onClose();
}.bind(this));
this.__readyTimeouts = {};
return eventProcessorStoppedPromise.then(
function() {
function () {
return {
success: true,
};
},
function(err) {
function (err) {
return {
success: false,
reason: String(err),
Expand Down Expand Up @@ -1021,7 +1021,7 @@ Optimizely.prototype.close = function() {
* @param {number|undefined} options.timeout
* @return {Promise}
*/
Optimizely.prototype.onReady = function(options) {
Optimizely.prototype.onReady = function (options) {
var timeout;
if (typeof options === 'object' && options !== null) {
timeout = options.timeout;
Expand All @@ -1031,22 +1031,22 @@ Optimizely.prototype.onReady = function(options) {
}

var resolveTimeoutPromise;
var timeoutPromise = new Promise(function(resolve) {
var timeoutPromise = new Promise(function (resolve) {
resolveTimeoutPromise = resolve;
});

var timeoutId = this.__nextReadyTimeoutId;
this.__nextReadyTimeoutId++;

var onReadyTimeout = function() {
var onReadyTimeout = function () {
delete this.__readyTimeouts[timeoutId];
resolveTimeoutPromise({
success: false,
reason: jsSdkUtils.sprintf('onReady timeout expired after %s ms', timeout),
});
}.bind(this);
var readyTimeout = setTimeout(onReadyTimeout, timeout);
var onClose = function() {
var onClose = function () {
resolveTimeoutPromise({
success: false,
reason: 'Instance closed',
Expand All @@ -1058,7 +1058,7 @@ Optimizely.prototype.onReady = function(options) {
onClose: onClose,
};

this.__readyPromise.then(function() {
this.__readyPromise.then(function () {
clearTimeout(readyTimeout);
delete this.__readyTimeouts[timeoutId];
resolveTimeoutPromise({
Expand Down
Loading