diff --git a/lib/core/optimizely_config/index.ts b/lib/core/optimizely_config/index.ts index 4b435b830..8fd66246e 100644 --- a/lib/core/optimizely_config/index.ts +++ b/lib/core/optimizely_config/index.ts @@ -62,7 +62,6 @@ export class OptimizelyConfig { public events: OptimizelyEvent[]; private datafile: string; - constructor(configObj: ProjectConfig, datafile: string, logger?: LoggerFacade) { this.sdkKey = configObj.sdkKey ?? ''; this.environmentKey = configObj.environmentKey ?? ''; diff --git a/lib/core/project_config/index.tests.js b/lib/core/project_config/index.tests.js index 24134e3cd..d920ed7a3 100644 --- a/lib/core/project_config/index.tests.js +++ b/lib/core/project_config/index.tests.js @@ -31,6 +31,15 @@ var logger = getLogger(); describe('lib/core/project_config', function() { describe('createProjectConfig method', function() { + // Copy experimentIds to experimentsIds in each event to fix typo in property name + // https://github.com/optimizely/javascript-sdk/issues/991 + const copyEventExperimentIds = (event) => { + return { + ...event, + experimentsIds: event.experimentIds, + } + }; + it('should set properties correctly when createProjectConfig is called', function() { var testData = testDatafile.getTestProjectConfig(); var configObj = projectConfig.createProjectConfig(testData); @@ -42,7 +51,7 @@ describe('lib/core/project_config', function() { assert.strictEqual(configObj.accountId, testData.accountId); assert.strictEqual(configObj.projectId, testData.projectId); assert.strictEqual(configObj.revision, testData.revision); - assert.deepEqual(configObj.events, testData.events); + assert.deepEqual(configObj.events, testData.events.map((e) => copyEventExperimentIds(e))); assert.deepEqual(configObj.audiences, testData.audiences); testData.groups.forEach(function(group) { group.experiments.forEach(function(experiment) { @@ -99,13 +108,13 @@ describe('lib/core/project_config', function() { assert.deepEqual(configObj.experimentKeyMap, expectedExperimentKeyMap); var expectedEventKeyMap = { - testEvent: testData.events[0], - 'Total Revenue': testData.events[1], - testEventWithAudiences: testData.events[2], - testEventWithoutExperiments: testData.events[3], - testEventWithExperimentNotRunning: testData.events[4], - testEventWithMultipleExperiments: testData.events[5], - testEventLaunched: testData.events[6], + testEvent: copyEventExperimentIds(testData.events[0]), + 'Total Revenue': copyEventExperimentIds(testData.events[1]), + testEventWithAudiences: copyEventExperimentIds(testData.events[2]), + testEventWithoutExperiments: copyEventExperimentIds(testData.events[3]), + testEventWithExperimentNotRunning: copyEventExperimentIds(testData.events[4]), + testEventWithMultipleExperiments: copyEventExperimentIds(testData.events[5]), + testEventLaunched: copyEventExperimentIds(testData.events[6]), }; assert.deepEqual(configObj.eventKeyMap, expectedEventKeyMap); diff --git a/lib/core/project_config/index.ts b/lib/core/project_config/index.ts index a52b46efa..9f0258fac 100644 --- a/lib/core/project_config/index.ts +++ b/lib/core/project_config/index.ts @@ -1,5 +1,5 @@ /** - * Copyright 2016-2024, Optimizely + * Copyright 2016-2025, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,10 @@ interface Event { key: string; id: string; experimentsIds: string[]; + + // the field is named experimentIds in the datafile, but this type previously defined it as experimentsIds. + // keeping both to avoid breaking changes, removed experimentsIds in v6. + experimentIds: string[]; // fix typo in property name (https://github.com/optimizely/javascript-sdk/issues/991) } interface VariableUsageMap { @@ -101,6 +105,16 @@ const MODULE_NAME = 'PROJECT_CONFIG'; // eslint-disable-next-line @typescript-eslint/no-explicit-any function createMutationSafeDatafileCopy(datafile: any): ProjectConfig { const datafileCopy = assign({}, datafile); + + datafileCopy.events = (datafile.events || []).map((event: Event) => { + const eventCopy: Event = assign({}, event); + + // Copy experimentIds to experimentsIds in each event to fix typo in property name + // https://github.com/optimizely/javascript-sdk/issues/991 + eventCopy.experimentsIds = event.experimentIds; + return eventCopy; + }); + datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => { return assign({}, audience); }); diff --git a/lib/shared_types.ts b/lib/shared_types.ts index 75885b83e..9e52c8a69 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -1,5 +1,5 @@ /** - * Copyright 2020-2024, Optimizely + * Copyright 2020-2025, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -469,6 +469,10 @@ export type OptimizelyEvent = { id: string; key: string; experimentsIds: string[]; + + // the field is named experimentIds in the datafile, but this type previously defined it as experimentsIds. + // keeping both to avoid breaking changes, removed experimentsIds in v6. + experimentIds: string[]; // fix typo in property name (https://github.com/optimizely/javascript-sdk/issues/991) }; export interface OptimizelyFeature {