Skip to content

Commit

Permalink
Move decisionContext within personalization (#1068)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwaters authored Oct 26, 2023
1 parent b5a39e0 commit 1829b46
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 28 deletions.
7 changes: 4 additions & 3 deletions sandbox/src/components/InAppMessagesDemo/InAppMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ export default function InAppMessages() {
if (useEvaluateRulesetsCommand) {
alloyInstance("evaluateRulesets", {
renderDecisions: true,
decisionContext: context
personalization: {
decisionContext: context
}
});
return;
}

alloyInstance("sendEvent", {
renderDecisions: true,
decisionContext: context,
personalization: { surfaces: ["#hello"] }
personalization: { surfaces: ["#hello"], decisionContext: context }
}).then(() => setSentEvent(true));
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/DataCollector/validateApplyResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
export default ({ options }) => {
const validator = objectOf({
renderDecisions: boolean(),
decisionContext: objectOf({}),
responseHeaders: mapOfValues(string().required()),
responseBody: objectOf({
handle: arrayOf(
Expand All @@ -32,7 +31,8 @@ export default ({ options }) => {
).required()
}).required(),
personalization: objectOf({
sendDisplayEvent: boolean().default(true)
sendDisplayEvent: boolean().default(true),
decisionContext: objectOf({})
}).default({ sendDisplayEvent: true })
}).noUnknownFields();

Expand Down
4 changes: 2 additions & 2 deletions src/components/DataCollector/validateUserEventOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export default ({ options }) => {
data: objectOf({}),
documentUnloading: boolean(),
renderDecisions: boolean(),
decisionContext: objectOf({}),
decisionScopes: arrayOf(string()).uniqueItems(),
personalization: objectOf({
decisionScopes: arrayOf(string()).uniqueItems(),
surfaces: arrayOf(string()).uniqueItems(),
sendDisplayEvent: boolean().default(true),
includeRenderedPropositions: boolean().default(false),
requestPersonalization: boolean()
requestPersonalization: boolean(),
decisionContext: objectOf({})
}).default({ sendDisplayEvent: true }),
datasetId: string(),
mergeId: string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { boolean, objectOf } from "../../utils/validation";
const validateOptions = ({ options }) => {
const validator = objectOf({
renderDecisions: boolean(),
decisionContext: objectOf({})
personalization: objectOf({
decisionContext: objectOf({})
})
}).noUnknownFields();

return validator(options);
Expand Down
12 changes: 8 additions & 4 deletions src/components/DecisioningEngine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ const createDecisioningEngine = ({
onBeforeEvent({
event,
renderDecisions,
decisionContext = {},
personalization = {},
onResponse = noop
}) {
const { decisionContext = {} } = personalization;

onResponse(
createOnResponseHandler({
renderDecisions,
Expand All @@ -95,16 +97,18 @@ const createDecisioningEngine = ({
},
commands: {
evaluateRulesets: {
run: ({ renderDecisions, decisionContext = {} }) =>
evaluateRulesetsCommand.run({
run: ({ renderDecisions, personalization = {} }) => {
const { decisionContext = {} } = personalization;
return evaluateRulesetsCommand.run({
renderDecisions,
decisionContext: {
[CONTEXT_KEY.TYPE]: CONTEXT_EVENT_TYPE.RULES_ENGINE,
[CONTEXT_KEY.SOURCE]: CONTEXT_EVENT_SOURCE.REQUEST,
...decisionContext
},
applyResponse
}),
});
},
optionsValidator: evaluateRulesetsCommand.optionsValidator
},
subscribeRulesetItems: subscribeRulesetItems.command
Expand Down
10 changes: 6 additions & 4 deletions test/functional/specs/DecisioningEngine/C13348429.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ test("Test C13348429: Verify DOM action using the applyResponse command.", async

await alloy.applyResponse({
renderDecisions: true,
decisionContext: {
"~type": "com.adobe.eventType.generic.track",
"~source": "com.adobe.eventSource.requestContent",
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2
personalization: {
decisionContext: {
"~type": "com.adobe.eventType.generic.track",
"~source": "com.adobe.eventSource.requestContent",
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2
}
},
responseBody: mockResponse
});
Expand Down
10 changes: 6 additions & 4 deletions test/functional/specs/DecisioningEngine/C13405889.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ test("Test C13405889: Verify DOM action using the evaluateRulesets command", asy
});
await alloy.evaluateRulesets({
renderDecisions: true,
decisionContext: {
"~type": "com.adobe.eventType.generic.track",
"~source": "com.adobe.eventSource.requestContent",
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2
personalization: {
decisionContext: {
"~type": "com.adobe.eventType.generic.track",
"~source": "com.adobe.eventSource.requestContent",
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2
}
}
});
const containerElement = await getIframeContainer();
Expand Down
10 changes: 6 additions & 4 deletions test/functional/specs/DecisioningEngine/C13419240.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ test("Test C13419240: Verify DOM action using the sendEvent command", async () =

await alloy.sendEvent({
renderDecisions: true,
decisionContext: {
"~type": "com.adobe.eventType.generic.track",
"~source": "com.adobe.eventSource.requestContent",
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2
personalization: {
decisionContext: {
"~type": "com.adobe.eventType.generic.track",
"~source": "com.adobe.eventSource.requestContent",
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2
}
}
});

Expand Down
8 changes: 4 additions & 4 deletions test/unit/specs/components/DecisioningEngine/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => {
decisioningEngine.lifecycle.onBeforeEvent({
event: mockEvent,
renderDecisions: true,
decisionContext: {},
personalization: { decisionContext: {} },
onResponse: onResponseHandler
});
const result = decisioningEngine.commands.evaluateRulesets.run({});
Expand All @@ -93,7 +93,7 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => {
decisioningEngine.lifecycle.onBeforeEvent({
event: mockEvent,
renderDecisions: true,
decisionContext: {},
personalization: { decisionContext: {} },
onResponse: onResponseHandler
});
const result = decisioningEngine.commands.evaluateRulesets.run({});
Expand All @@ -118,7 +118,7 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => {
decisioningEngine.lifecycle.onBeforeEvent({
event: mockEvent,
renderDecisions: true,
decisionContext: {},
personalization: { decisionContext: {} },
onResponse: onResponseHandler
});
const result = decisioningEngine.commands.evaluateRulesets.run({});
Expand All @@ -143,7 +143,7 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => {
decisioningEngine.lifecycle.onBeforeEvent({
event: mockEvent,
renderDecisions: false,
decisionContext: {},
personalization: { decisionContext: {} },
onResponse: onResponseHandler
});
const result = decisioningEngine.commands.evaluateRulesets.run({});
Expand Down

0 comments on commit 1829b46

Please sign in to comment.