From 1829b46e4366ab970e1e5fd93ef37733c6aa9a61 Mon Sep 17 00:00:00 2001 From: Jason Waters Date: Thu, 26 Oct 2023 11:53:22 -0600 Subject: [PATCH] Move decisionContext within personalization (#1068) --- .../components/InAppMessagesDemo/InAppMessages.js | 7 ++++--- .../DataCollector/validateApplyResponse.js | 4 ++-- .../DataCollector/validateUserEventOptions.js | 4 ++-- .../createEvaluateRulesetsCommand.js | 4 +++- src/components/DecisioningEngine/index.js | 12 ++++++++---- test/functional/specs/DecisioningEngine/C13348429.js | 10 ++++++---- test/functional/specs/DecisioningEngine/C13405889.js | 10 ++++++---- test/functional/specs/DecisioningEngine/C13419240.js | 10 ++++++---- .../specs/components/DecisioningEngine/index.spec.js | 8 ++++---- 9 files changed, 41 insertions(+), 28 deletions(-) diff --git a/sandbox/src/components/InAppMessagesDemo/InAppMessages.js b/sandbox/src/components/InAppMessagesDemo/InAppMessages.js index 061b8d92e..474701f0e 100644 --- a/sandbox/src/components/InAppMessagesDemo/InAppMessages.js +++ b/sandbox/src/components/InAppMessagesDemo/InAppMessages.js @@ -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)); }; diff --git a/src/components/DataCollector/validateApplyResponse.js b/src/components/DataCollector/validateApplyResponse.js index 25a5fffc2..75d2ddba5 100644 --- a/src/components/DataCollector/validateApplyResponse.js +++ b/src/components/DataCollector/validateApplyResponse.js @@ -21,7 +21,6 @@ import { export default ({ options }) => { const validator = objectOf({ renderDecisions: boolean(), - decisionContext: objectOf({}), responseHeaders: mapOfValues(string().required()), responseBody: objectOf({ handle: arrayOf( @@ -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(); diff --git a/src/components/DataCollector/validateUserEventOptions.js b/src/components/DataCollector/validateUserEventOptions.js index 8383476c6..e9e1a4969 100644 --- a/src/components/DataCollector/validateUserEventOptions.js +++ b/src/components/DataCollector/validateUserEventOptions.js @@ -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(), diff --git a/src/components/DecisioningEngine/createEvaluateRulesetsCommand.js b/src/components/DecisioningEngine/createEvaluateRulesetsCommand.js index ae5bfb73f..095e032e5 100644 --- a/src/components/DecisioningEngine/createEvaluateRulesetsCommand.js +++ b/src/components/DecisioningEngine/createEvaluateRulesetsCommand.js @@ -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); diff --git a/src/components/DecisioningEngine/index.js b/src/components/DecisioningEngine/index.js index b53a4bd84..2c945f8d6 100644 --- a/src/components/DecisioningEngine/index.js +++ b/src/components/DecisioningEngine/index.js @@ -73,9 +73,11 @@ const createDecisioningEngine = ({ onBeforeEvent({ event, renderDecisions, - decisionContext = {}, + personalization = {}, onResponse = noop }) { + const { decisionContext = {} } = personalization; + onResponse( createOnResponseHandler({ renderDecisions, @@ -95,8 +97,9 @@ 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, @@ -104,7 +107,8 @@ const createDecisioningEngine = ({ ...decisionContext }, applyResponse - }), + }); + }, optionsValidator: evaluateRulesetsCommand.optionsValidator }, subscribeRulesetItems: subscribeRulesetItems.command diff --git a/test/functional/specs/DecisioningEngine/C13348429.js b/test/functional/specs/DecisioningEngine/C13348429.js index d54c5b3d3..042d45fdd 100644 --- a/test/functional/specs/DecisioningEngine/C13348429.js +++ b/test/functional/specs/DecisioningEngine/C13348429.js @@ -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 }); diff --git a/test/functional/specs/DecisioningEngine/C13405889.js b/test/functional/specs/DecisioningEngine/C13405889.js index 1d10b13ff..d04c41efb 100644 --- a/test/functional/specs/DecisioningEngine/C13405889.js +++ b/test/functional/specs/DecisioningEngine/C13405889.js @@ -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(); diff --git a/test/functional/specs/DecisioningEngine/C13419240.js b/test/functional/specs/DecisioningEngine/C13419240.js index 09619111b..4020fcdd0 100644 --- a/test/functional/specs/DecisioningEngine/C13419240.js +++ b/test/functional/specs/DecisioningEngine/C13419240.js @@ -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 + } } }); diff --git a/test/unit/specs/components/DecisioningEngine/index.spec.js b/test/unit/specs/components/DecisioningEngine/index.spec.js index 105d5e677..0d031b660 100644 --- a/test/unit/specs/components/DecisioningEngine/index.spec.js +++ b/test/unit/specs/components/DecisioningEngine/index.spec.js @@ -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({}); @@ -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({}); @@ -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({}); @@ -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({});