Skip to content

Commit 6561a4f

Browse files
committed
yarn fix: simplify isObfuscated messaging (#253)
* fix: warn when setting isObfuscated not when checking config, also change level to info * v4.14.3
1 parent ac8655e commit 6561a4f

File tree

2 files changed

+40
-51
lines changed

2 files changed

+40
-51
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.14.2",
3+
"version": "4.14.3",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/client/eppo-client.ts

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export type EppoClientParameters = {
108108
flagConfigurationStore: IConfigurationStore<Flag | ObfuscatedFlag>;
109109
banditVariationConfigurationStore?: IConfigurationStore<BanditVariation[]>;
110110
banditModelConfigurationStore?: IConfigurationStore<BanditParameters>;
111+
overrideStore?: ISyncStore<Variation>;
111112
configurationRequestParameters?: FlagConfigurationRequestParameters;
112113
/**
113114
* Setting this value will have no side effects other than triggering a warning when the actual
@@ -136,9 +137,6 @@ export default class EppoClient {
136137
private assignmentCache?: AssignmentCache;
137138
// whether to suppress any errors and return default values instead
138139
private isGracefulFailureMode = true;
139-
private expectObfuscated: boolean;
140-
private obfuscationMismatchWarningIssued = false;
141-
private configObfuscatedCache?: boolean;
142140
private requestPoller?: IPoller;
143141
private readonly evaluator = new Evaluator();
144142
private configurationRequestor?: ConfigurationRequestor;
@@ -147,30 +145,27 @@ export default class EppoClient {
147145

148146
constructor({
149147
eventDispatcher = new NoOpEventDispatcher(),
150-
isObfuscated = false,
148+
isObfuscated,
151149
flagConfigurationStore,
152150
banditVariationConfigurationStore,
153151
banditModelConfigurationStore,
154152
overrideStore,
155153
configurationRequestParameters,
156-
}: {
157-
// Dispatcher for arbitrary, application-level events (not to be confused with Eppo specific assignment
158-
// or bandit events). These events are application-specific and captures by EppoClient#track API.
159-
eventDispatcher?: EventDispatcher;
160-
flagConfigurationStore: IConfigurationStore<Flag | ObfuscatedFlag>;
161-
banditVariationConfigurationStore?: IConfigurationStore<BanditVariation[]>;
162-
banditModelConfigurationStore?: IConfigurationStore<BanditParameters>;
163-
overrideStore?: ISyncStore<Variation>;
164-
configurationRequestParameters?: FlagConfigurationRequestParameters;
165-
isObfuscated?: boolean;
166-
}) {
154+
}: EppoClientParameters) {
167155
this.eventDispatcher = eventDispatcher;
168156
this.flagConfigurationStore = flagConfigurationStore;
169157
this.banditVariationConfigurationStore = banditVariationConfigurationStore;
170158
this.banditModelConfigurationStore = banditModelConfigurationStore;
171159
this.overrideStore = overrideStore;
172160
this.configurationRequestParameters = configurationRequestParameters;
173-
this.expectObfuscated = isObfuscated;
161+
162+
if (isObfuscated !== undefined) {
163+
logger.warn(
164+
'[Eppo SDK] specifying isObfuscated no longer has an effect and will be removed in the next major release; obfuscation ' +
165+
'is now inferred from the configuration, so you can safely remove the option.',
166+
);
167+
}
168+
174169

175170
// Initialize the configuration manager
176171
this.configurationManager = new ConfigurationManager(
@@ -184,32 +179,6 @@ export default class EppoClient {
184179
return this.configurationManager.getConfiguration();
185180
}
186181

187-
private maybeWarnAboutObfuscationMismatch(configObfuscated: boolean) {
188-
// Don't warn again if we did on the last check.
189-
if (configObfuscated !== this.expectObfuscated && !this.obfuscationMismatchWarningIssued) {
190-
this.obfuscationMismatchWarningIssued = true;
191-
logger.warn(
192-
`[Eppo SDK] configuration obfuscation [${configObfuscated}] does not match expected [${this.expectObfuscated}]`,
193-
);
194-
} else if (configObfuscated === this.expectObfuscated) {
195-
// Reset the warning to false in case the client configuration (re-)enters a mismatched state.
196-
this.obfuscationMismatchWarningIssued = false;
197-
}
198-
}
199-
200-
/**
201-
* This method delegates to the configuration to determine whether it is obfuscated, then caches the actual
202-
* obfuscation state and issues a warning if it hasn't already.
203-
* This method can be removed with the next major update when the @deprecated setIsObfuscated is removed
204-
*/
205-
private isObfuscated(config: IConfiguration) {
206-
if (this.configObfuscatedCache === undefined) {
207-
this.configObfuscatedCache = config.isObfuscated();
208-
}
209-
this.maybeWarnAboutObfuscationMismatch(this.configObfuscatedCache);
210-
return this.configObfuscatedCache;
211-
}
212-
213182
/**
214183
* Validates and parses x-eppo-overrides header sent by Eppo's Chrome extension
215184
*/
@@ -248,8 +217,6 @@ export default class EppoClient {
248217
// noinspection JSUnusedGlobalSymbols
249218
setFlagConfigurationStore(flagConfigurationStore: IConfigurationStore<Flag | ObfuscatedFlag>) {
250219
this.flagConfigurationStore = flagConfigurationStore;
251-
this.configObfuscatedCache = undefined;
252-
253220
// Update the configuration manager
254221
this.innerSetConfigurationStores();
255222
}
@@ -303,6 +270,29 @@ export default class EppoClient {
303270
this.eventDispatcher?.attachContext(key, value);
304271
}
305272

273+
// noinspection JSUnusedGlobalSymbols
274+
setBanditModelConfigurationStore(
275+
banditModelConfigurationStore: IConfigurationStore<BanditParameters>,
276+
) {
277+
this.banditModelConfigurationStore = banditModelConfigurationStore;
278+
}
279+
280+
// noinspection JSUnusedGlobalSymbols
281+
/**
282+
* Setting this value will have no side effects other than triggering a warning when the actual
283+
* configuration's obfuscated does not match the value set here.
284+
*
285+
* @deprecated The client determines whether the configuration is obfuscated by inspection
286+
* @param isObfuscated
287+
*/
288+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
289+
setIsObfuscated(isObfuscated: boolean) {
290+
logger.warn(
291+
'[Eppo SDK] setIsObfuscated no longer has an effect and will be removed in the next major release; obfuscation ' +
292+
'is now inferred from the configuration, so you can safely remove the call to this method.',
293+
);
294+
}
295+
306296
setOverrideStore(store: ISyncStore<Variation>): void {
307297
this.overrideStore = store;
308298
}
@@ -360,7 +350,7 @@ export default class EppoClient {
360350
apiKey,
361351
sdkName,
362352
sdkVersion,
363-
baseUrl,
353+
baseUrl, // Default is set in ApiEndpoints constructor if undefined
364354
requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS,
365355
numInitialRequestRetries = DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES,
366356
numPollRequestRetries = DEFAULT_POLL_CONFIG_REQUEST_RETRIES,
@@ -392,7 +382,6 @@ export default class EppoClient {
392382

393383
const pollingCallback = async () => {
394384
if (await this.flagConfigurationStore.isExpired()) {
395-
this.configObfuscatedCache = undefined;
396385
return configurationRequestor.fetchAndStoreConfigurations();
397386
}
398387
};
@@ -1015,7 +1004,7 @@ export default class EppoClient {
10151004
configDetails,
10161005
subjectKey,
10171006
subjectAttributes,
1018-
this.isObfuscated(config),
1007+
config.isObfuscated(),
10191008
);
10201009

10211010
// allocationKey is set along with variation when there is a result. this check appeases typescript below
@@ -1168,7 +1157,7 @@ export default class EppoClient {
11681157
);
11691158
}
11701159

1171-
const isObfuscated = this.isObfuscated(config);
1160+
const isObfuscated = config.isObfuscated();
11721161
const result = this.evaluator.evaluateFlag(
11731162
flag,
11741163
configDetails,
@@ -1220,7 +1209,7 @@ export default class EppoClient {
12201209
}
12211210

12221211
private getNormalizedFlag(config: IConfiguration, flagKey: string): Flag | null {
1223-
return this.isObfuscated(config)
1212+
return config.isObfuscated()
12241213
? this.getObfuscatedFlag(config, flagKey)
12251214
: config.getFlag(flagKey);
12261215
}
@@ -1387,7 +1376,7 @@ export default class EppoClient {
13871376

13881377
private buildLoggerMetadata(): Record<string, unknown> {
13891378
return {
1390-
obfuscated: this.isObfuscated(this.getConfiguration()),
1379+
obfuscated: this.getConfiguration().isObfuscated(),
13911380
sdkLanguage: 'javascript',
13921381
sdkLibVersion: LIB_VERSION,
13931382
};

0 commit comments

Comments
 (0)