@@ -80,7 +80,7 @@ export class FeatureManager implements IFeatureManager {
8080 return { variant : undefined , reason : VariantAssignmentReason . None } ;
8181 }
8282
83- async #isEnabled( featureFlag : FeatureFlag , context ?: unknown ) : Promise < boolean > {
83+ async #isEnabled( featureFlag : FeatureFlag , appContext ?: unknown ) : Promise < boolean > {
8484 if ( featureFlag . enabled !== true ) {
8585 // If the feature is not explicitly enabled, then it is disabled by default.
8686 return false ;
@@ -110,11 +110,11 @@ export class FeatureManager implements IFeatureManager {
110110 clientFilterEvaluationResult = false ;
111111 }
112112 else {
113- let appContext = context ;
114- if ( clientFilter . name === "Microsoft.Targeting" && this . #targetingContextAccessor !== undefined ) {
115- appContext = this . #targetingContextAccessor( ) ;
113+ if ( clientFilter . name === "Microsoft.Targeting" ) {
114+ clientFilterEvaluationResult = await matchedFeatureFilter . evaluate ( contextWithFeatureName , this . #getTargetingContext( appContext ) ) ;
115+ } else {
116+ clientFilterEvaluationResult = await matchedFeatureFilter . evaluate ( contextWithFeatureName , appContext ) ;
116117 }
117- clientFilterEvaluationResult = await matchedFeatureFilter . evaluate ( contextWithFeatureName , appContext ) ;
118118 }
119119 if ( clientFilterEvaluationResult === shortCircuitEvaluationResult ) {
120120 return shortCircuitEvaluationResult ;
@@ -125,7 +125,7 @@ export class FeatureManager implements IFeatureManager {
125125 return ! shortCircuitEvaluationResult ;
126126 }
127127
128- async #evaluateFeature( featureName : string , context : unknown ) : Promise < EvaluationResult > {
128+ async #evaluateFeature( featureName : string , appContext : unknown ) : Promise < EvaluationResult > {
129129 const featureFlag = await this . #provider. getFeatureFlag ( featureName ) ;
130130 const result = new EvaluationResult ( featureFlag ) ;
131131
@@ -138,12 +138,10 @@ export class FeatureManager implements IFeatureManager {
138138 validateFeatureFlagFormat ( featureFlag ) ;
139139
140140 // Evaluate if the feature is enabled.
141- result . enabled = await this . #isEnabled( featureFlag , context ) ;
141+ result . enabled = await this . #isEnabled( featureFlag , appContext ) ;
142142
143- let targetingContext = context as ITargetingContext ;
144- if ( this . #targetingContextAccessor !== undefined ) {
145- targetingContext = this . #targetingContextAccessor( ) ;
146- }
143+ // Get targeting context from the app context or the targeting context accessor
144+ const targetingContext = this . #getTargetingContext( appContext ) ;
147145 result . targetingId = targetingContext ?. userId ;
148146
149147 // Determine Variant
@@ -202,6 +200,14 @@ export class FeatureManager implements IFeatureManager {
202200
203201 return result ;
204202 }
203+
204+ #getTargetingContext( context : unknown ) : ITargetingContext | undefined {
205+ let targetingContext = context as ITargetingContext ;
206+ if ( targetingContext === undefined && this . #targetingContextAccessor !== undefined ) {
207+ targetingContext = this . #targetingContextAccessor( ) ;
208+ }
209+ return targetingContext ;
210+ }
205211}
206212
207213export interface FeatureManagerOptions {
0 commit comments