-
Notifications
You must be signed in to change notification settings - Fork 1
fix: simplify isObfuscated
messaging
#253
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ export type EppoClientParameters = { | |
flagConfigurationStore: IConfigurationStore<Flag | ObfuscatedFlag>; | ||
banditVariationConfigurationStore?: IConfigurationStore<BanditVariation[]>; | ||
banditModelConfigurationStore?: IConfigurationStore<BanditParameters>; | ||
overrideStore?: ISyncStore<Variation>; | ||
configurationRequestParameters?: FlagConfigurationRequestParameters; | ||
/** | ||
* Setting this value will have no side effects other than triggering a warning when the actual | ||
|
@@ -131,40 +132,32 @@ export default class EppoClient { | |
private assignmentCache?: AssignmentCache; | ||
// whether to suppress any errors and return default values instead | ||
private isGracefulFailureMode = true; | ||
private expectObfuscated: boolean; | ||
private obfuscationMismatchWarningIssued = false; | ||
private configObfuscatedCache?: boolean; | ||
private requestPoller?: IPoller; | ||
private readonly evaluator = new Evaluator(); | ||
private configurationRequestor?: ConfigurationRequestor; | ||
private readonly overrideValidator = new OverrideValidator(); | ||
|
||
constructor({ | ||
eventDispatcher = new NoOpEventDispatcher(), | ||
isObfuscated = false, | ||
isObfuscated, | ||
typotter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flagConfigurationStore, | ||
banditVariationConfigurationStore, | ||
banditModelConfigurationStore, | ||
overrideStore, | ||
configurationRequestParameters, | ||
}: { | ||
// Dispatcher for arbitrary, application-level events (not to be confused with Eppo specific assignment | ||
// or bandit events). These events are application-specific and captures by EppoClient#track API. | ||
eventDispatcher?: EventDispatcher; | ||
flagConfigurationStore: IConfigurationStore<Flag | ObfuscatedFlag>; | ||
banditVariationConfigurationStore?: IConfigurationStore<BanditVariation[]>; | ||
banditModelConfigurationStore?: IConfigurationStore<BanditParameters>; | ||
overrideStore?: ISyncStore<Variation>; | ||
configurationRequestParameters?: FlagConfigurationRequestParameters; | ||
isObfuscated?: boolean; | ||
}) { | ||
}: EppoClientParameters) { | ||
this.eventDispatcher = eventDispatcher; | ||
this.flagConfigurationStore = flagConfigurationStore; | ||
this.banditVariationConfigurationStore = banditVariationConfigurationStore; | ||
this.banditModelConfigurationStore = banditModelConfigurationStore; | ||
this.overrideStore = overrideStore; | ||
this.configurationRequestParameters = configurationRequestParameters; | ||
this.expectObfuscated = isObfuscated; | ||
|
||
if (isObfuscated !== undefined) { | ||
logger.info( | ||
|
||
`[Eppo SDK] specifying isObfuscated no longer has an effect; obfuscation is inferred from the configuration.`, | ||
typotter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
); | ||
} | ||
} | ||
|
||
private getConfiguration(): IConfiguration { | ||
|
@@ -177,32 +170,6 @@ export default class EppoClient { | |
); | ||
} | ||
|
||
private maybeWarnAboutObfuscationMismatch(configObfuscated: boolean) { | ||
// Don't warn again if we did on the last check. | ||
if (configObfuscated !== this.expectObfuscated && !this.obfuscationMismatchWarningIssued) { | ||
this.obfuscationMismatchWarningIssued = true; | ||
logger.warn( | ||
`[Eppo SDK] configuration obfuscation [${configObfuscated}] does not match expected [${this.expectObfuscated}]`, | ||
); | ||
} else if (configObfuscated === this.expectObfuscated) { | ||
// Reset the warning to false in case the client configuration (re-)enters a mismatched state. | ||
this.obfuscationMismatchWarningIssued = false; | ||
} | ||
} | ||
|
||
/** | ||
* This method delegates to the configuration to determine whether it is obfuscated, then caches the actual | ||
* obfuscation state and issues a warning if it hasn't already. | ||
* This method can be removed with the next major update when the @deprecated setIsObfuscated is removed | ||
*/ | ||
private isObfuscated(config: IConfiguration) { | ||
if (this.configObfuscatedCache === undefined) { | ||
this.configObfuscatedCache = config.isObfuscated(); | ||
} | ||
this.maybeWarnAboutObfuscationMismatch(this.configObfuscatedCache); | ||
return this.configObfuscatedCache; | ||
} | ||
|
||
/** | ||
* Validates and parses x-eppo-overrides header sent by Eppo's Chrome extension | ||
*/ | ||
|
@@ -241,7 +208,6 @@ export default class EppoClient { | |
// noinspection JSUnusedGlobalSymbols | ||
setFlagConfigurationStore(flagConfigurationStore: IConfigurationStore<Flag | ObfuscatedFlag>) { | ||
this.flagConfigurationStore = flagConfigurationStore; | ||
this.configObfuscatedCache = undefined; | ||
} | ||
|
||
// noinspection JSUnusedGlobalSymbols | ||
|
@@ -287,8 +253,11 @@ export default class EppoClient { | |
* @deprecated The client determines whether the configuration is obfuscated by inspection | ||
* @param isObfuscated | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
setIsObfuscated(isObfuscated: boolean) { | ||
this.expectObfuscated = isObfuscated; | ||
logger.info( | ||
'[Eppo SDK] setIsObfuscated no longer has an effect; obfuscation is inferred from the configuration.', | ||
); | ||
} | ||
|
||
setOverrideStore(store: ISyncStore<Variation>): void { | ||
|
@@ -354,7 +323,6 @@ export default class EppoClient { | |
|
||
const pollingCallback = async () => { | ||
if (await configurationRequestor.isFlagConfigExpired()) { | ||
this.configObfuscatedCache = undefined; | ||
return configurationRequestor.fetchAndStoreConfigurations(); | ||
} | ||
}; | ||
|
@@ -977,7 +945,7 @@ export default class EppoClient { | |
configDetails, | ||
subjectKey, | ||
subjectAttributes, | ||
this.isObfuscated(config), | ||
config.isObfuscated(), | ||
); | ||
|
||
// allocationKey is set along with variation when there is a result. this check appeases typescript below | ||
|
@@ -1130,7 +1098,7 @@ export default class EppoClient { | |
); | ||
} | ||
|
||
const isObfuscated = this.isObfuscated(config); | ||
const isObfuscated = config.isObfuscated(); | ||
const result = this.evaluator.evaluateFlag( | ||
flag, | ||
configDetails, | ||
|
@@ -1182,7 +1150,7 @@ export default class EppoClient { | |
} | ||
|
||
private getNormalizedFlag(config: IConfiguration, flagKey: string): Flag | null { | ||
return this.isObfuscated(config) | ||
return config.isObfuscated() | ||
? this.getObfuscatedFlag(config, flagKey) | ||
: config.getFlag(flagKey); | ||
} | ||
|
@@ -1349,7 +1317,7 @@ export default class EppoClient { | |
|
||
private buildLoggerMetadata(): Record<string, unknown> { | ||
return { | ||
obfuscated: this.isObfuscated(this.getConfiguration()), | ||
obfuscated: this.getConfiguration().isObfuscated(), | ||
sdkLanguage: 'javascript', | ||
sdkLibVersion: LIB_VERSION, | ||
}; | ||
|
Uh oh!
There was an error while loading. Please reload this page.