Skip to content

Commit 1d814a2

Browse files
authored
[FSSDK-10619] Refactor project config manager to be injectable (optimizely#945)
1 parent e7cc602 commit 1d814a2

File tree

102 files changed

+4365
-4816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+4365
-4816
lines changed

lib/common_exports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Optimizely
2+
* Copyright 2023-2024 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.
@@ -17,3 +17,5 @@
1717
export { LogLevel, LogHandler, getLogger, setLogHandler } from './modules/logging';
1818
export { LOG_LEVEL } from './utils/enums';
1919
export { createLogger } from './plugins/logger';
20+
export { createStaticProjectConfigManager } from './project_config/config_manager_factory';
21+
export { PollingConfigManagerConfig } from './project_config/config_manager_factory';

lib/core/bucketer/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-2017, 2019-2022, Optimizely
2+
* Copyright 2016-2017, 2019-2022, 2024, 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.
@@ -25,7 +25,7 @@ import {
2525
LOG_LEVEL,
2626
} from '../../utils/enums';
2727
import { createLogger } from '../../plugins/logger';
28-
import projectConfig from '../project_config';
28+
import projectConfig from '../../project_config/project_config';
2929
import { getTestProjectConfig } from '../../tests/test_data';
3030

3131
var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));

lib/core/decision_service/index.tests.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/****************************************************************************
2-
* Copyright 2017-2022 Optimizely, Inc. and contributors *
3-
* *
4-
* Licensed under the Apache License, Version 2.0 (the "License"); *
5-
* you may not use this file except in compliance with the License. *
6-
* You may obtain a copy of the License at *
7-
* *
8-
* http://www.apache.org/licenses/LICENSE-2.0 *
9-
* *
10-
* Unless required by applicable law or agreed to in writing, software *
11-
* distributed under the License is distributed on an "AS IS" BASIS, *
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13-
* See the License for the specific language governing permissions and *
14-
* limitations under the License. *
15-
***************************************************************************/
1+
/**
2+
* Copyright 2017-2022, 2024, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616
import sinon from 'sinon';
1717
import { assert } from 'chai';
1818
import cloneDeep from 'lodash/cloneDeep';
@@ -29,11 +29,13 @@ import { createForwardingEventProcessor } from '../../plugins/event_processor/fo
2929
import { createNotificationCenter } from '../notification_center';
3030
import Optimizely from '../../optimizely';
3131
import OptimizelyUserContext from '../../optimizely_user_context';
32-
import projectConfig from '../project_config';
32+
import projectConfig, { createProjectConfig } from '../../project_config/project_config';
3333
import AudienceEvaluator from '../audience_evaluator';
3434
import errorHandler from '../../plugins/error_handler';
3535
import eventDispatcher from '../../plugins/event_dispatcher/index.node';
3636
import * as jsonSchemaValidator from '../../utils/json_schema_validator';
37+
import { getMockProjectConfigManager } from '../../tests/mock/mock_project_config_manager';
38+
3739
import {
3840
getTestProjectConfig,
3941
getTestProjectConfigWithFeatures,
@@ -1067,7 +1069,9 @@ describe('lib/core/decision_service', function() {
10671069
beforeEach(function() {
10681070
optlyInstance = new Optimizely({
10691071
clientEngine: 'node-sdk',
1070-
datafile: cloneDeep(testData),
1072+
projectConfigManager: getMockProjectConfigManager({
1073+
initConfig: createProjectConfig(cloneDeep(testData))
1074+
}),
10711075
jsonSchemaValidator: jsonSchemaValidator,
10721076
isValidInstance: true,
10731077
logger: createdLogger,

lib/core/decision_service/index.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/****************************************************************************
2-
* Copyright 2017-2022 Optimizely, Inc. and contributors *
3-
* *
4-
* Licensed under the Apache License, Version 2.0 (the "License"); *
5-
* you may not use this file except in compliance with the License. *
6-
* You may obtain a copy of the License at *
7-
* *
8-
* http://www.apache.org/licenses/LICENSE-2.0 *
9-
* *
10-
* Unless required by applicable law or agreed to in writing, software *
11-
* distributed under the License is distributed on an "AS IS" BASIS, *
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13-
* See the License for the specific language governing permissions and *
14-
* limitations under the License. *
15-
***************************************************************************/
1+
/**
2+
* Copyright 2017-2022, 2024, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616
import { LogHandler } from '../../modules/logging';
1717
import { sprintf } from '../../utils/fns';
1818

@@ -38,7 +38,7 @@ import {
3838
getVariationKeyFromId,
3939
isActive,
4040
ProjectConfig,
41-
} from '../project_config';
41+
} from '../../project_config/project_config';
4242
import { AudienceEvaluator, createAudienceEvaluator } from '../audience_evaluator';
4343
import * as stringValidator from '../../utils/string_value_validator';
4444
import {

lib/core/event_builder/event_helpers.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2020, 2024, 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.
@@ -17,7 +17,7 @@ import sinon from 'sinon';
1717
import { assert } from 'chai';
1818

1919
import fns from '../../utils/fns';
20-
import * as projectConfig from '../project_config';
20+
import * as projectConfig from '../../project_config/project_config';
2121
import * as decision from '../decision';
2222
import { buildImpressionEvent, buildConversionEvent } from './event_helpers';
2323

lib/core/event_builder/event_helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019-2022, Optimizely
2+
* Copyright 2019-2022, 2024, 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.
@@ -27,7 +27,7 @@ import {
2727
getEventId,
2828
getLayerId,
2929
ProjectConfig,
30-
} from '../project_config';
30+
} from '../../project_config/project_config';
3131

3232
const logger = getLogger('EVENT_BUILDER');
3333

lib/core/event_builder/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-2021, Optimizely
2+
* Copyright 2016-2021, 2024, 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.
@@ -18,7 +18,7 @@ import { assert } from 'chai';
1818

1919
import fns from '../../utils/fns';
2020
import testData from '../../tests/test_data';
21-
import projectConfig from '../project_config';
21+
import projectConfig from '../../project_config/project_config';
2222
import packageJSON from '../../../package.json';
2323
import { getConversionEvent, getImpressionEvent } from './';
2424

lib/core/event_builder/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2022, Optimizely
2+
* Copyright 2016-2022, 2024, 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.
@@ -24,7 +24,7 @@ import {
2424
getLayerId,
2525
getVariationKeyFromId,
2626
ProjectConfig,
27-
} from '../project_config';
27+
} from '../../project_config/project_config';
2828
import * as eventTagUtils from '../../utils/event_tag_utils';
2929
import { isAttributeValid } from '../../utils/attributes_validator';
3030
import { EventTags, UserAttributes, Event as EventLoggingEndpoint } from '../../shared_types';

lib/core/notification_center/notification_registry.tests.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

lib/core/notification_center/notification_registry.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

lib/core/odp/odp_event_api_manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { LogHandler, LogLevel } from '../../modules/logging';
1818
import { OdpEvent } from './odp_event';
19-
import { RequestHandler } from '../../utils/http_request_handler/http';
19+
import { HttpMethod, RequestHandler } from '../../utils/http_request_handler/http';
2020
import { OdpConfig } from './odp_config';
2121
import { ERROR_MESSAGES } from '../../utils/enums';
2222

@@ -109,7 +109,7 @@ export abstract class OdpEventApiManager implements IOdpEventApiManager {
109109
odpConfig: OdpConfig,
110110
events: OdpEvent[]
111111
): {
112-
method: string;
112+
method: HttpMethod;
113113
endpoint: string;
114114
headers: { [key: string]: string };
115115
data: string;

lib/core/odp/odp_event_manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { OdpConfig } from './odp_config';
2424
import { IOdpEventApiManager } from './odp_event_api_manager';
2525
import { invalidOdpDataFound } from './odp_utils';
2626
import { IUserAgentParser } from './user_agent_parser';
27-
import { scheduleMicrotaskOrTimeout } from '../../utils/microtask';
27+
import { scheduleMicrotask } from '../../utils/microtask';
2828

2929
const MAX_RETRIES = 3;
3030

@@ -394,7 +394,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
394394

395395
if (batch.length > 0) {
396396
// put sending the event on another event loop
397-
scheduleMicrotaskOrTimeout(async () => {
397+
scheduleMicrotask(async () => {
398398
let shouldRetry: boolean;
399399
let attemptNumber = 0;
400400
do {

lib/core/optimizely_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 2019-2021, Optimizely
2+
* Copyright 2019-2021, 2024, 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.
@@ -18,7 +18,7 @@ import { cloneDeep } from 'lodash';
1818
import sinon from 'sinon';
1919

2020
import { createOptimizelyConfig, OptimizelyConfig } from './';
21-
import { createProjectConfig } from '../project_config';
21+
import { createProjectConfig } from '../../project_config/project_config';
2222
import {
2323
getTestProjectConfigWithFeatures,
2424
getTypedAudiencesConfig,

lib/core/optimizely_config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2020-2023, Optimizely
2+
* Copyright 2020-2024, 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 { LoggerFacade, getLogger } from '../../modules/logging';
17-
import { ProjectConfig } from '../project_config';
17+
import { ProjectConfig } from '../../project_config/project_config';
1818
import { DEFAULT_OPERATOR_TYPES } from '../condition_tree_evaluator';
1919
import {
2020
Audience,

0 commit comments

Comments
 (0)