Skip to content

Commit a4dcc3e

Browse files
authored
feat: Added support for sdkKey and environmentKey in OptimizelyConfig (#683)
* WIP * Add environmentKey and sdkKey to datafile, OptimizelyConfig, and ProjectConfig * Change environmentKey and sdkKey to optional params to fix FSC * Clean up * Incorporate comments
1 parent 88fded0 commit a4dcc3e

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -137,5 +137,13 @@ describe('lib/core/optimizely_config', function() {
137137
it('should return correct config revision', function() {
138138
assert.equal(optimizelyConfigObject.revision, datafile.revision);
139139
});
140+
141+
it('should return correct config sdkKey ', function() {
142+
assert.equal(optimizelyConfigObject.sdkKey, datafile.sdkKey);
143+
});
144+
145+
it('should return correct config environmentKey ', function() {
146+
assert.equal(optimizelyConfigObject.environmentKey, datafile.environmentKey);
147+
});
140148
});
141149
});

packages/optimizely-sdk/lib/core/optimizely_config/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ export class OptimizelyConfig {
3737
public experimentsMap: OptimizelyExperimentsMap;
3838
public featuresMap: OptimizelyFeaturesMap;
3939
public revision: string;
40+
public sdkKey?: string;
41+
public environmentKey?: string;
4042
private datafile: string;
4143

4244
constructor(configObj: ProjectConfig, datafile: string) {
4345
this.experimentsMap = OptimizelyConfig.getExperimentsMap(configObj);
4446
this.featuresMap = OptimizelyConfig.getFeaturesMap(configObj, this.experimentsMap);
4547
this.revision = configObj.revision;
4648
this.datafile = datafile;
49+
50+
if (configObj.sdkKey && configObj.environmentKey) {
51+
this.sdkKey = configObj.sdkKey;
52+
this.environmentKey = configObj.environmentKey;
53+
}
4754
}
4855

4956
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2020, Optimizely
2+
* Copyright 2016-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import sinon from 'sinon';
17-
import { assert, expect, config } from 'chai';
17+
import { assert } from 'chai';
1818
import { forEach, cloneDeep } from 'lodash';
1919
import { getLogger } from '@optimizely/js-sdk-logging';
2020
import { sprintf } from '@optimizely/js-sdk-utils';

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ interface VariableUsageMap {
5858
export interface ProjectConfig {
5959
revision: string;
6060
projectId: string;
61+
sdkKey?: string;
62+
environmentKey?: string;
6163
sendFlagDecisions?: boolean;
6264
experimentKeyMap: { [key: string]: Experiment };
6365
featureKeyMap: {
@@ -116,6 +118,12 @@ function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
116118
});
117119
return rolloutCopy;
118120
});
121+
122+
if (datafile.environmentKey && datafile.sdkKey) {
123+
datafileCopy.environmentKey = datafile.environmentKey;
124+
datafileCopy.sdkKey = datafile.sdkKey;
125+
}
126+
119127
return datafileCopy;
120128
}
121129

packages/optimizely-sdk/lib/shared_types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ export interface OptimizelyConfig {
304304
experimentsMap: OptimizelyExperimentsMap;
305305
featuresMap: OptimizelyFeaturesMap;
306306
revision: string;
307+
sdkKey?: string;
308+
environmentKey?: string;
307309
getDatafile(): string;
308310
}
309311

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ var decideConfig = {
418418
],
419419
anonymizeIP: true,
420420
botFiltering: true,
421+
sdkKey: 'ValidProjectConfigV4',
422+
environmentKey: 'production',
421423
projectId: '10431130345',
422424
variables: [],
423425
featureFlags: [
@@ -1143,6 +1145,8 @@ var configWithFeatures = {
11431145
],
11441146
anonymizeIP: true,
11451147
botFiltering: true,
1148+
sdkKey: 'ValidProjectConfigV4',
1149+
environmentKey: 'development',
11461150
audiences: [
11471151
{
11481152
id: '594017',

0 commit comments

Comments
 (0)