@@ -23,15 +23,16 @@ import {
23
23
} from '../../utils/enums' ;
24
24
import * as conditionTreeEvaluator from '../condition_tree_evaluator' ;
25
25
import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator' ;
26
- import { UserAttributes , Audience , Condition } from '../../shared_types' ;
26
+ import * as odpSegmentsConditionEvaluator from './odp_segment_condition_evaluator' ;
27
+ import { Audience , Condition , OptimizelyUserContext } from '../../shared_types' ;
27
28
28
29
const logger = getLogger ( ) ;
29
30
const MODULE_NAME = 'AUDIENCE_EVALUATOR' ;
30
31
31
32
export class AudienceEvaluator {
32
33
private typeToEvaluatorMap : {
33
34
[ key : string ] : {
34
- [ key : string ] : ( condition : Condition , userAttributes : UserAttributes ) => boolean | null
35
+ [ key : string ] : ( condition : Condition , user : OptimizelyUserContext ) => boolean | null
35
36
} ;
36
37
} ;
37
38
@@ -45,6 +46,7 @@ export class AudienceEvaluator {
45
46
constructor ( UNSTABLE_conditionEvaluators : unknown ) {
46
47
this . typeToEvaluatorMap = fns . assign ( { } , UNSTABLE_conditionEvaluators , {
47
48
custom_attribute : customAttributeConditionEvaluator ,
49
+ third_party_dimension : odpSegmentsConditionEvaluator ,
48
50
} ) ;
49
51
}
50
52
@@ -56,15 +58,15 @@ export class AudienceEvaluator {
56
58
* @param {[id: string]: Audience } audiencesById Object providing access to full audience objects for audience IDs
57
59
* contained in audienceConditions. Keys should be audience IDs, values
58
60
* should be full audience objects with conditions properties
59
- * @param {UserAttributes } userAttributes User attributes which will be used in determining if audience conditions
60
- * are met. If not provided, defaults to an empty object
61
+ * @param {OptimizelyUserContext } userAttributes User context which contains the attributes and segments which will be used in
62
+ * determining if audience conditions are met.
61
63
* @return {boolean } true if the user attributes match the given audience conditions, false
62
64
* otherwise
63
65
*/
64
66
evaluate (
65
67
audienceConditions : Array < string | string [ ] > ,
66
68
audiencesById : { [ id : string ] : Audience } ,
67
- userAttributes : UserAttributes = { }
69
+ user : OptimizelyUserContext ,
68
70
) : boolean {
69
71
// if there are no audiences, return true because that means ALL users are included in the experiment
70
72
if ( ! audienceConditions || audienceConditions . length === 0 ) {
@@ -80,7 +82,7 @@ export class AudienceEvaluator {
80
82
) ;
81
83
const result = conditionTreeEvaluator . evaluate (
82
84
audience . conditions as unknown [ ] ,
83
- this . evaluateConditionWithUserAttributes . bind ( this , userAttributes )
85
+ this . evaluateConditionWithUserAttributes . bind ( this , user )
84
86
) ;
85
87
const resultText = result === null ? 'UNKNOWN' : result . toString ( ) . toUpperCase ( ) ;
86
88
logger . log ( LOG_LEVEL . DEBUG , LOG_MESSAGES . AUDIENCE_EVALUATION_RESULT , MODULE_NAME , audienceId , resultText ) ;
@@ -95,18 +97,18 @@ export class AudienceEvaluator {
95
97
/**
96
98
* Wrapper around evaluator.evaluate that is passed to the conditionTreeEvaluator.
97
99
* Evaluates the condition provided given the user attributes if an evaluator has been defined for the condition type.
98
- * @param {UserAttributes } userAttributes A map of user attributes.
99
- * @param {Condition } condition A single condition object to evaluate.
100
+ * @param {OptimizelyUserContext } user Optimizely user context containing attributes and segments
101
+ * @param {Condition } condition A single condition object to evaluate.
100
102
* @return {boolean|null } true if the condition is satisfied, null if a matcher is not found.
101
103
*/
102
- evaluateConditionWithUserAttributes ( userAttributes : UserAttributes , condition : Condition ) : boolean | null {
104
+ evaluateConditionWithUserAttributes ( user : OptimizelyUserContext , condition : Condition ) : boolean | null {
103
105
const evaluator = this . typeToEvaluatorMap [ condition . type ] ;
104
106
if ( ! evaluator ) {
105
107
logger . log ( LOG_LEVEL . WARNING , LOG_MESSAGES . UNKNOWN_CONDITION_TYPE , MODULE_NAME , JSON . stringify ( condition ) ) ;
106
108
return null ;
107
109
}
108
110
try {
109
- return evaluator . evaluate ( condition , userAttributes ) ;
111
+ return evaluator . evaluate ( condition , user ) ;
110
112
} catch ( err : any ) {
111
113
logger . log (
112
114
LOG_LEVEL . ERROR ,
0 commit comments