Skip to content

Commit 4f6431f

Browse files
authored
[FSSDK-12242] support UNSTABLE_conditionEvaluators option (#1133)
1 parent c1af6da commit 4f6431f

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

lib/client_factory.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2025, Optimizely
2+
* Copyright 2025-2026, 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.
@@ -22,7 +22,7 @@ import { extractOdpManager } from "./odp/odp_manager_factory";
2222
import { extractVuidManager } from "./vuid/vuid_manager_factory";
2323
import { RequestHandler } from "./utils/http_request_handler/http";
2424
import { CLIENT_VERSION, DEFAULT_CMAB_BACKOFF_MS, DEFAULT_CMAB_CACHE_SIZE, DEFAULT_CMAB_CACHE_TIMEOUT_MS, DEFAULT_CMAB_RETRIES, JAVASCRIPT_CLIENT_ENGINE } from "./utils/enums";
25-
import Optimizely from "./optimizely";
25+
import Optimizely, { OptimizelyOptions } from "./optimizely";
2626
import { DefaultCmabClient } from "./core/decision_service/cmab/cmab_client";
2727
import { CmabCacheValue, DefaultCmabService } from "./core/decision_service/cmab/cmab_service";
2828
import { InMemoryLruCache } from "./utils/cache/in_memory_lru_cache";
@@ -76,7 +76,7 @@ export const getOptimizelyInstance = (config: OptimizelyFactoryConfig): Optimize
7676
logger: logger?.child()
7777
});
7878

79-
const optimizelyOptions = {
79+
const optimizelyOptions: OptimizelyOptions = {
8080
cmabService,
8181
clientEngine: clientEngine || JAVASCRIPT_CLIENT_ENGINE,
8282
clientVersion: clientVersion || CLIENT_VERSION,
@@ -91,6 +91,9 @@ export const getOptimizelyInstance = (config: OptimizelyFactoryConfig): Optimize
9191
eventProcessor,
9292
odpManager,
9393
vuidManager,
94+
// UNSTABLE_conditionEvaluators is not exposed in the public types, but we want to pass it through
95+
// for internal use cases.
96+
UNSTABLE_conditionEvaluators: (config as any).UNSTABLE_conditionEvaluators,
9497
};
9598

9699
return new Optimizely(optimizelyOptions);

lib/core/decision_service/index.tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var createLogger = () => ({
7777
warn: () => {},
7878
error: () => {},
7979
child: () => createLogger(),
80+
setName: () => {},
8081
})
8182

8283
describe('lib/core/decision_service', function() {

lib/core/decision_service/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017-2022, 2024-2025, Optimizely
2+
* Copyright 2017-2022, 2024-2026, 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.
@@ -158,6 +158,8 @@ export type DecideOptionsMap = Partial<Record<OptimizelyDecideOption, boolean>>;
158158

159159
export const CMAB_DUMMY_ENTITY_ID= '$'
160160

161+
export const LOGGER_NAME = 'DecisionService';
162+
161163
/**
162164
* Optimizely's decision service that determines which variation of an experiment the user will be allocated to.
163165
*
@@ -183,6 +185,7 @@ export class DecisionService {
183185

184186
constructor(options: DecisionServiceOptions) {
185187
this.logger = options.logger;
188+
this.logger?.setName(LOGGER_NAME);
186189
this.audienceEvaluator = createAudienceEvaluator(options.UNSTABLE_conditionEvaluators, this.logger);
187190
this.forcedVariationMap = {};
188191
this.userProfileService = options.userProfileService;

lib/optimizely/index.tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ var createLogger = () => ({
9898
warn: () => {},
9999
error: () => {},
100100
child: () => createLogger(),
101+
setName: () => {},
101102
})
102103

103104
const getOptlyInstance = ({ datafileObj, defaultDecideOptions }) => {
@@ -240,7 +241,7 @@ describe('lib/optimizely', function() {
240241
sinon.assert.calledWith(decisionService.createDecisionService, {
241242
userProfileService: userProfileServiceInstance,
242243
userProfileServiceAsync: undefined,
243-
logger: createdLogger,
244+
logger: sinon.match.any,
244245
cmabService,
245246
UNSTABLE_conditionEvaluators: undefined,
246247
});
@@ -272,7 +273,7 @@ describe('lib/optimizely', function() {
272273
sinon.assert.calledWith(decisionService.createDecisionService, {
273274
userProfileService: undefined,
274275
userProfileServiceAsync: undefined,
275-
logger: createdLogger,
276+
logger: sinon.match.any,
276277
UNSTABLE_conditionEvaluators: undefined,
277278
cmabService,
278279
});

lib/optimizely/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2020-2025, Optimizely
2+
* Copyright 2020-2026, 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.
@@ -242,7 +242,7 @@ export default class Optimizely extends BaseService implements Client {
242242
userProfileService: userProfileService,
243243
userProfileServiceAsync: config.userProfileServiceAsync || undefined,
244244
cmabService: config.cmabService,
245-
logger: this.logger,
245+
logger: this.logger?.child(),
246246
UNSTABLE_conditionEvaluators: config.UNSTABLE_conditionEvaluators,
247247
});
248248

lib/optimizely_user_context/index.tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var createLogger = () => ({
4848
warn: () => {},
4949
error: () => {},
5050
child: () => createLogger(),
51+
setName: () => {},
5152
});
5253

5354
const getOptlyInstance = ({ datafileObj, defaultDecideOptions }) => {

0 commit comments

Comments
 (0)