Skip to content

feat: Added support for sdkKey and environmentKey in OptimizelyConfig #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2021
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020, Optimizely
* Copyright 2019-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -137,5 +137,13 @@ describe('lib/core/optimizely_config', function() {
it('should return correct config revision', function() {
assert.equal(optimizelyConfigObject.revision, datafile.revision);
});

it('should return correct config sdkKey ', function() {
assert.equal(optimizelyConfigObject.sdkKey, datafile.sdkKey);
});

it('should return correct config environmentKey ', function() {
assert.equal(optimizelyConfigObject.environmentKey, datafile.environmentKey);
});
});
});
7 changes: 7 additions & 0 deletions packages/optimizely-sdk/lib/core/optimizely_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ export class OptimizelyConfig {
public experimentsMap: OptimizelyExperimentsMap;
public featuresMap: OptimizelyFeaturesMap;
public revision: string;
public sdkKey?: string;
public environmentKey?: string;
private datafile: string;

constructor(configObj: ProjectConfig, datafile: string) {
this.experimentsMap = OptimizelyConfig.getExperimentsMap(configObj);
this.featuresMap = OptimizelyConfig.getFeaturesMap(configObj, this.experimentsMap);
this.revision = configObj.revision;
this.datafile = datafile;

if (configObj.sdkKey && configObj.environmentKey) {
this.sdkKey = configObj.sdkKey;
this.environmentKey = configObj.environmentKey;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2020, Optimizely
* Copyright 2016-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/
import sinon from 'sinon';
import { assert, expect, config } from 'chai';
import { assert } from 'chai';
import { forEach, cloneDeep } from 'lodash';
import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '@optimizely/js-sdk-utils';
Expand Down
8 changes: 8 additions & 0 deletions packages/optimizely-sdk/lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ interface VariableUsageMap {
export interface ProjectConfig {
revision: string;
projectId: string;
sdkKey?: string;
environmentKey?: string;
sendFlagDecisions?: boolean;
experimentKeyMap: { [key: string]: Experiment };
featureKeyMap: {
Expand Down Expand Up @@ -116,6 +118,12 @@ function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
});
return rolloutCopy;
});

if (datafile.environmentKey && datafile.sdkKey) {
datafileCopy.environmentKey = datafile.environmentKey;
datafileCopy.sdkKey = datafile.sdkKey;
}

return datafileCopy;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/optimizely-sdk/lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ export interface OptimizelyConfig {
experimentsMap: OptimizelyExperimentsMap;
featuresMap: OptimizelyFeaturesMap;
revision: string;
sdkKey?: string;
environmentKey?: string;
getDatafile(): string;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/optimizely-sdk/lib/tests/test_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ var decideConfig = {
],
anonymizeIP: true,
botFiltering: true,
sdkKey: 'ValidProjectConfigV4',
environmentKey: 'production',
projectId: '10431130345',
variables: [],
featureFlags: [
Expand Down Expand Up @@ -1143,6 +1145,8 @@ var configWithFeatures = {
],
anonymizeIP: true,
botFiltering: true,
sdkKey: 'ValidProjectConfigV4',
environmentKey: 'development',
audiences: [
{
id: '594017',
Expand Down