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

Commit 91aaac3

Browse files
committed
Merge v4.0.0-rc.2 into rc1 (using imerge)
2 parents bd0d242 + 6876656 commit 91aaac3

File tree

12 files changed

+82
-11
lines changed

12 files changed

+82
-11
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [4.0.0-rc.2] - April 24, 2020
11+
12+
### Bug fixes
13+
- Allow multiple instances to be created from the same datafile object ([#462](https://github.com/optimizely/javascript-sdk/pull/462))
14+
1015
## [4.0.0-rc.1] - April 17, 2020
1116

1217
### New Features

packages/optimizely-sdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This directory contains the source code for the JavaScript SDK, which is usable
1515
### Prerequisites
1616

1717
Ensure the SDK supports all of the platforms you're targeting. In particular, the SDK targets any ES5-compliant JavaScript environment. We officially support:
18-
- Node.js >= 4.0.0. By extension, environments like AWS Lambda, Google Cloud Functions, and Auth0 Webtasks are supported as well. Older Node.js releases likely work too (try `npm test` to validate for yourself), but are not formally supported.
18+
- Node.js >= 8.0.0. By extension, environments like AWS Lambda, Google Cloud Functions, and Auth0 Webtasks are supported as well. Older Node.js releases likely work too (try `npm test` to validate for yourself), but are not formally supported.
1919
- [Web browsers](https://caniuse.com/#feat=es5)
2020

2121
Other environments likely are compatible, too, but note that we don't officially support them:

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,41 @@ var EXPERIMENT_RUNNING_STATUS = 'Running';
2828
var RESERVED_ATTRIBUTE_PREFIX = '$opt_';
2929
var MODULE_NAME = 'PROJECT_CONFIG';
3030

31+
function createMutationSafeDatafileCopy(datafile) {
32+
var datafileCopy = fns.assign({}, datafile);
33+
datafileCopy.audiences = (datafile.audiences || []).map(function(audience) {
34+
return fns.assign({}, audience);
35+
});
36+
datafileCopy.experiments = (datafile.experiments || []).map(function(experiment) {
37+
return fns.assign({}, experiment);
38+
});
39+
datafileCopy.featureFlags = (datafile.featureFlags || []).map(function(featureFlag) {
40+
return fns.assign({}, featureFlag);
41+
});
42+
datafileCopy.groups = (datafile.groups || []).map(function(group) {
43+
var groupCopy = fns.assign({}, group);
44+
groupCopy.experiments = (group.experiments || []).map(function(experiment) {
45+
return fns.assign({}, experiment);
46+
});
47+
return groupCopy;
48+
});
49+
datafileCopy.rollouts = (datafile.rollouts || []).map(function(rollout) {
50+
var rolloutCopy = fns.assign({}, rollout);
51+
rolloutCopy.experiments = (rollout.experiments || []).map(function(experiment) {
52+
return fns.assign({}, experiment);
53+
});
54+
return rolloutCopy;
55+
});
56+
return datafileCopy;
57+
}
58+
3159
/**
3260
* Creates projectConfig object to be used for quick project property lookup
3361
* @param {Object} datafile JSON datafile representing the project
3462
* @return {Object} Object representing project configuration
3563
*/
3664
export var createProjectConfig = function(datafile) {
37-
var projectConfig = fns.assign({}, datafile);
65+
var projectConfig = createMutationSafeDatafileCopy(datafile);
3866

3967
/*
4068
* Conditions of audiences in projectConfig.typedAudiences are not

packages/optimizely-sdk/lib/core/project_config/index.tests.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,26 @@ import configValidator from '../../utils/config_validator';
3333
var logger = getLogger();
3434

3535
describe('lib/core/project_config', function() {
36-
var parsedAudiences = testDatafile.getParsedAudiences;
3736
describe('createProjectConfig method', function() {
3837
it('should set properties correctly when createProjectConfig is called', function() {
3938
var testData = testDatafile.getTestProjectConfig();
4039
var configObj = projectConfig.createProjectConfig(testData);
4140

4241
forEach(testData.audiences, function(audience) {
43-
audience.conditions = audience.conditions;
42+
audience.conditions = JSON.parse(audience.conditions);
4443
});
4544

4645
assert.strictEqual(configObj.accountId, testData.accountId);
4746
assert.strictEqual(configObj.projectId, testData.projectId);
4847
assert.strictEqual(configObj.revision, testData.revision);
4948
assert.deepEqual(configObj.events, testData.events);
5049
assert.deepEqual(configObj.audiences, testData.audiences);
50+
testData.groups.forEach(function(group) {
51+
group.experiments.forEach(function(experiment) {
52+
experiment.groupId = group.id;
53+
experiment.variationKeyMap = fns.keyBy(experiment.variations, 'key');
54+
});
55+
});
5156
assert.deepEqual(configObj.groups, testData.groups);
5257

5358
var expectedGroupIdMap = {
@@ -170,6 +175,13 @@ describe('lib/core/project_config', function() {
170175
assert.deepEqual(configObj.variationIdMap, expectedVariationIdMap);
171176
});
172177

178+
it('should not mutate the datafile', function() {
179+
var datafile = testDatafile.getTypedAudiencesConfig();
180+
var datafileClone = cloneDeep(datafile);
181+
projectConfig.createProjectConfig(datafile);
182+
assert.deepEqual(datafileClone, datafile);
183+
});
184+
173185
describe('feature management', function() {
174186
var configObj;
175187
beforeEach(function() {

packages/optimizely-sdk/lib/index.browser.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('javascript-sdk', function() {
145145
optlyInstance.onReady().catch(function() {});
146146

147147
assert.instanceOf(optlyInstance, Optimizely);
148-
assert.equal(optlyInstance.clientVersion, '4.0.0-rc.1');
148+
assert.equal(optlyInstance.clientVersion, '4.0.0-rc.2');
149149
});
150150

151151
it('should set the JavaScript client engine and version', function() {

packages/optimizely-sdk/lib/index.node.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('optimizelyFactory', function() {
9090
optlyInstance.onReady().catch(function() {});
9191

9292
assert.instanceOf(optlyInstance, Optimizely);
93-
assert.equal(optlyInstance.clientVersion, '4.0.0-rc.1');
93+
assert.equal(optlyInstance.clientVersion, '4.0.0-rc.2');
9494
});
9595

9696
describe('event processor configuration', function() {

packages/optimizely-sdk/lib/index.react_native.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('javascript-sdk/react-native', function() {
8989
optlyInstance.onReady().catch(function() {});
9090

9191
assert.instanceOf(optlyInstance, Optimizely);
92-
assert.equal(optlyInstance.clientVersion, '4.0.0-rc.1');
92+
assert.equal(optlyInstance.clientVersion, '4.0.0-rc.2');
9393
});
9494

9595
it('should set the React Native JS client engine and javascript SDK version', function() {

packages/optimizely-sdk/lib/optimizely/index.tests.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,28 @@ describe('lib/optimizely', function() {
245245
});
246246
});
247247
});
248+
249+
it('should support constructing two instances using the same datafile object', function() {
250+
var datafile = testData.getTypedAudiencesConfig();
251+
var optlyInstance = new Optimizely({
252+
clientEngine: 'node-sdk',
253+
datafile: datafile,
254+
errorHandler: stubErrorHandler,
255+
eventDispatcher: stubEventDispatcher,
256+
jsonSchemaValidator: jsonSchemaValidator,
257+
logger: createdLogger,
258+
});
259+
assert.instanceOf(optlyInstance, Optimizely);
260+
var optlyInstance2 = new Optimizely({
261+
clientEngine: 'node-sdk',
262+
datafile: datafile,
263+
errorHandler: stubErrorHandler,
264+
eventDispatcher: stubEventDispatcher,
265+
jsonSchemaValidator: jsonSchemaValidator,
266+
logger: createdLogger,
267+
});
268+
assert.instanceOf(optlyInstance2, Optimizely);
269+
});
248270
});
249271
});
250272

packages/optimizely-sdk/lib/utils/enums/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export var NODE_CLIENT_ENGINE = 'node-sdk';
175175
export var REACT_CLIENT_ENGINE = 'react-sdk';
176176
export var REACT_NATIVE_CLIENT_ENGINE = 'react-native-sdk';
177177
export var REACT_NATIVE_JS_CLIENT_ENGINE = 'react-native-js-sdk';
178-
export var NODE_CLIENT_VERSION = '4.0.0-rc.1';
178+
export var NODE_CLIENT_VERSION = '4.0.0-rc.2';
179179

180180
export var VALID_CLIENT_ENGINES = [
181181
NODE_CLIENT_ENGINE,

packages/optimizely-sdk/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)