Skip to content
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

Move decisionContext within personalization #1068

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading