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
feat: Add ODP Datafile Parsing and Audience Evaluation #765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qualified-type support looks good! I'd like to see UserContext passed down to audience evaluators. See my comments and let's chat about it.
userAttributes: UserAttributes = {}, | ||
segments: string[] = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this (unpacking and passing separate) better than passing down UserContext all the way? I see that we may need to use other fields (existing one like userId, or new ones to be added later) in evaluation later.
@@ -64,7 +66,8 @@ export class AudienceEvaluator { | |||
evaluate( | |||
audienceConditions: Array<string | string[]>, | |||
audiencesById: { [id: string]: Audience }, | |||
userAttributes: UserAttributes = {} | |||
userAttributes: UserAttributes = {}, | |||
segments: string[] = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add 'segments' in doc comments
@@ -99,14 +102,14 @@ export class AudienceEvaluator { | |||
* @param {Condition} condition A single condition object to evaluate. | |||
* @return {boolean|null} true if the condition is satisfied, null if a matcher is not found. | |||
*/ | |||
evaluateConditionWithUserAttributes(userAttributes: UserAttributes, condition: Condition): boolean | null { | |||
evaluateConditionWithUserAttributes(userAttributes: UserAttributes, segments: string[], condition: Condition): boolean | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update doc comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A couple of small changes suggested.
@@ -29,6 +29,7 @@ export default class OptimizelyUserContext { | |||
private userId: string; | |||
private attributes: UserAttributes; | |||
private forcedDecisionsMap: { [key: string]: { [key: string]: OptimizelyForcedDecision } }; | |||
private qualifiedSegments: string[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we open {get, set} for this prop to public? They can override it with own segments for debugging or other purposes?
} | ||
|
||
function qualifiedEvaluator(condition: Condition, user: OptimizelyUserContext): boolean { | ||
//return user.getQualifiedSegments().indexOf(condition.value as string) > -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
} | ||
const audience = new AudienceEvaluator(); | ||
|
||
it('shoud evaluate to true if segment is found', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('shoud evaluate to true if segment is found', () => { | |
it('should evaluate to true if segment is found', () => { |
fix same for others below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@zashraf1985 - I believe I fixed the import issues, however although the Git Actions shows all tests passing there seems to be 2 failing / 2 pending checks still. What am I missing? |
Summary
A new field
integrations
and new audience typeodp.audiences
will be added to the datafile schema for ODP integration.Parses new datafile odp values (“publicKey” and “host”) from the “integrations” section. These values are used to send requests to the ODP server.
Parses datafile with and without the “integrations” section or empty section as well.
support a new audience with the
odp.audiences
andqualified
match.support any (allowed) combination of audiences, including ODP and other existing audiences.
Test plan
Issues