Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 91e28c6

Browse files
author
Michael Ng
authored
Merge branch 'master' into mng/testbuildevents
2 parents ef303fd + fb7b674 commit 91e28c6

File tree

25 files changed

+242
-179
lines changed

25 files changed

+242
-179
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
9+
## [3.5.0] - February 20th, 2020
10+
811
### Bug fixes
912
- Fixed default event dispatcher not used in React Native entry point ([#383](https://github.com/optimizely/javascript-sdk/pull/383))
13+
- Fixed errors in `getOptimizelyConfig` TypeScript type definitions ([#406](https://github.com/optimizely/javascript-sdk/pull/406))
14+
15+
### New Features
16+
- Promise returned from `close` tracks the state of in-flight event dispatcher requests ([#404](https://github.com/optimizely/javascript-sdk/pull/404))
1017

1118
## [3.4.1] - January 28th, 2020
1219

packages/optimizely-sdk/lib/core/audience_evaluator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var MODULE_NAME = 'AUDIENCE_EVALUATOR';
3535
* @constructor
3636
*/
3737
function AudienceEvaluator(UNSTABLE_conditionEvaluators) {
38-
this.typeToEvaluatorMap = fns.assignIn({}, UNSTABLE_conditionEvaluators, {
38+
this.typeToEvaluatorMap = fns.assign({}, UNSTABLE_conditionEvaluators, {
3939
'custom_attribute': customAttributeConditionEvaluator
4040
});
4141
}

packages/optimizely-sdk/lib/core/custom_attribute_condition_evaluator/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function exactEvaluator(condition, userAttributes, logger) {
9999
var userValue = userAttributes[conditionName];
100100
var userValueType = typeof userValue;
101101

102-
if (!isValueTypeValidForExactConditions(conditionValue) || (fns.isNumber(conditionValue) && !fns.isFinite(conditionValue))) {
102+
if (!isValueTypeValidForExactConditions(conditionValue) || (fns.isNumber(conditionValue) && !fns.isSafeInteger(conditionValue))) {
103103
logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNEXPECTED_CONDITION_VALUE, MODULE_NAME, JSON.stringify(condition)));
104104
return null;
105105
}
@@ -114,7 +114,7 @@ function exactEvaluator(condition, userAttributes, logger) {
114114
return null;
115115
}
116116

117-
if (fns.isNumber(userValue) && !fns.isFinite(userValue)) {
117+
if (fns.isNumber(userValue) && !fns.isSafeInteger(userValue)) {
118118
logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.OUT_OF_BOUNDS, MODULE_NAME, JSON.stringify(condition), conditionName));
119119
return null;
120120
}
@@ -152,7 +152,7 @@ function greaterThanEvaluator(condition, userAttributes, logger) {
152152
var userValueType = typeof userValue;
153153
var conditionValue = condition.value;
154154

155-
if (!fns.isFinite(conditionValue)) {
155+
if (!fns.isSafeInteger(conditionValue)) {
156156
logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNEXPECTED_CONDITION_VALUE, MODULE_NAME, JSON.stringify(condition)));
157157
return null;
158158
}
@@ -167,7 +167,7 @@ function greaterThanEvaluator(condition, userAttributes, logger) {
167167
return null;
168168
}
169169

170-
if (!fns.isFinite(userValue)) {
170+
if (!fns.isSafeInteger(userValue)) {
171171
logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.OUT_OF_BOUNDS, MODULE_NAME, JSON.stringify(condition), conditionName));
172172
return null;
173173
}
@@ -191,7 +191,7 @@ function lessThanEvaluator(condition, userAttributes, logger) {
191191
var userValueType = typeof userValue;
192192
var conditionValue = condition.value;
193193

194-
if (!fns.isFinite(conditionValue)) {
194+
if (!fns.isSafeInteger(conditionValue)) {
195195
logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNEXPECTED_CONDITION_VALUE, MODULE_NAME, JSON.stringify(condition)));
196196
return null;
197197
}
@@ -206,7 +206,7 @@ function lessThanEvaluator(condition, userAttributes, logger) {
206206
return null;
207207
}
208208

209-
if (!fns.isFinite(userValue)) {
209+
if (!fns.isSafeInteger(userValue)) {
210210
logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.OUT_OF_BOUNDS, MODULE_NAME, JSON.stringify(condition), conditionName));
211211
return null;
212212
}

packages/optimizely-sdk/lib/core/decision_service/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ DecisionService.prototype.__resolveExperimentBucketMap = function(userId, attrib
116116
attributes = attributes || {}
117117
var userProfile = this.__getUserProfile(userId) || {};
118118
var attributeExperimentBucketMap = attributes[enums.CONTROL_ATTRIBUTES.STICKY_BUCKETING_KEY];
119-
return fns.assignIn({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
119+
return fns.assign({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
120120
};
121121

122122

@@ -144,7 +144,7 @@ DecisionService.prototype.__checkIfExperimentIsActive = function(configObj, expe
144144
* @return {string|null} Forced variation if it exists for user ID, otherwise null
145145
*/
146146
DecisionService.prototype.__getWhitelistedVariation = function(experiment, userId) {
147-
if (!fns.isEmpty(experiment.forcedVariations) && experiment.forcedVariations.hasOwnProperty(userId)) {
147+
if (experiment.forcedVariations && experiment.forcedVariations.hasOwnProperty(userId)) {
148148
var forcedVariationKey = experiment.forcedVariations[userId];
149149
if (experiment.variationKeyMap.hasOwnProperty(forcedVariationKey)) {
150150
var forcedBucketingSucceededMessageLog = sprintf(LOG_MESSAGES.USER_FORCED_IN_VARIATION, MODULE_NAME, userId, forcedVariationKey);

packages/optimizely-sdk/lib/core/event_builder/event_helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ exports.buildConversionEvent = function buildConversionEvent(config) {
140140
function buildVisitorAttributes(configObj, attributes) {
141141
var builtAttributes = [];
142142
// Omit attribute values that are not supported by the log endpoint.
143-
fns.forOwn(attributes, function(attributeValue, attributeKey) {
143+
Object.keys(attributes || {}).forEach(function(attributeKey) {
144+
var attributeValue = attributes[attributeKey];
144145
if (attributesValidator.isAttributeValid(attributeKey, attributeValue)) {
145146
var attributeId = projectConfig.getAttributeId(configObj, attributeKey, logger);
146147
if (attributeId) {

packages/optimizely-sdk/lib/core/event_builder/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function getCommonEventParams(options) {
6161
};
6262

6363
// Omit attribute values that are not supported by the log endpoint.
64-
fns.forOwn(attributes, function(attributeValue, attributeKey) {
64+
Object.keys(attributes || {}).forEach(function(attributeKey) {
65+
var attributeValue = attributes[attributeKey];
6566
if (attributeValidator.isAttributeValid(attributeKey, attributeValue)) {
6667
var attributeId = projectConfig.getAttributeId(options.configObj, attributeKey, options.logger);
6768
if (attributeId) {

packages/optimizely-sdk/lib/core/notification_center/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
var enums = require('../../utils/enums');
18-
var fns = require('../../utils/fns');
19-
var sprintf = require('@optimizely/js-sdk-utils').sprintf;
18+
var jsSdkUtils = require('@optimizely/js-sdk-utils');
2019

2120
var LOG_LEVEL = enums.LOG_LEVEL;
2221
var LOG_MESSAGES = enums.LOG_MESSAGES;
@@ -37,7 +36,8 @@ function NotificationCenter(options) {
3736
this.logger = options.logger;
3837
this.errorHandler = options.errorHandler;
3938
this.__notificationListeners = {};
40-
fns.forOwn(enums.NOTIFICATION_TYPES, function(notificationTypeEnum) {
39+
40+
jsSdkUtils.objectValues(enums.NOTIFICATION_TYPES).forEach(function(notificationTypeEnum) {
4141
this.__notificationListeners[notificationTypeEnum] = [];
4242
}.bind(this));
4343
this.__listenerId = 1;
@@ -55,7 +55,7 @@ function NotificationCenter(options) {
5555
*/
5656
NotificationCenter.prototype.addNotificationListener = function (notificationType, callback) {
5757
try {
58-
var isNotificationTypeValid = fns.values(enums.NOTIFICATION_TYPES)
58+
var isNotificationTypeValid = jsSdkUtils.objectValues(enums.NOTIFICATION_TYPES)
5959
.indexOf(notificationType) > -1;
6060
if (!isNotificationTypeValid) {
6161
return -1;
@@ -66,7 +66,7 @@ NotificationCenter.prototype.addNotificationListener = function (notificationTyp
6666
}
6767

6868
var callbackAlreadyAdded = false;
69-
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
69+
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
7070
if (listenerEntry.callback === callback) {
7171
callbackAlreadyAdded = true;
7272
return false;
@@ -101,19 +101,22 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
101101
try {
102102
var indexToRemove;
103103
var typeToRemove;
104-
fns.forOwn(this.__notificationListeners, function (listenersForType, notificationType) {
105-
fns.forEach(listenersForType, function (listenerEntry, i) {
104+
105+
Object.keys(this.__notificationListeners).some(function(notificationType) {
106+
var listenersForType = this.__notificationListeners[notificationType];
107+
(listenersForType || []).every(function(listenerEntry, i) {
106108
if (listenerEntry.id === listenerId) {
107109
indexToRemove = i;
108110
typeToRemove = notificationType;
109111
return false;
110112
}
113+
return true
111114
});
112115
if (indexToRemove !== undefined && typeToRemove !== undefined) {
113-
return false;
116+
return true;
114117
}
115-
});
116-
118+
}.bind(this));
119+
117120
if (indexToRemove !== undefined && typeToRemove !== undefined) {
118121
this.__notificationListeners[typeToRemove].splice(indexToRemove, 1);
119122
return true;
@@ -130,7 +133,7 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
130133
*/
131134
NotificationCenter.prototype.clearAllNotificationListeners = function () {
132135
try{
133-
fns.forOwn(enums.NOTIFICATION_TYPES, function (notificationTypeEnum) {
136+
jsSdkUtils.objectValues(enums.NOTIFICATION_TYPES).forEach(function (notificationTypeEnum) {
134137
this.__notificationListeners[notificationTypeEnum] = [];
135138
}.bind(this));
136139
} catch (e) {
@@ -160,12 +163,12 @@ NotificationCenter.prototype.clearNotificationListeners = function (notification
160163
*/
161164
NotificationCenter.prototype.sendNotifications = function (notificationType, notificationData) {
162165
try {
163-
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
166+
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
164167
var callback = listenerEntry.callback;
165168
try {
166169
callback(notificationData);
167170
} catch (ex) {
168-
this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.NOTIFICATION_LISTENER_EXCEPTION, MODULE_NAME, notificationType, ex.message));
171+
this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.NOTIFICATION_LISTENER_EXCEPTION, MODULE_NAME, notificationType, ex.message));
169172
}
170173
}.bind(this));
171174
} catch (e) {

0 commit comments

Comments
 (0)