From 899ec90f12ec162acc02af53df0d798574e1b648 Mon Sep 17 00:00:00 2001 From: Jason Waters Date: Fri, 27 Oct 2023 10:11:11 -0600 Subject: [PATCH] some fixes (#1071) --- .../DecisioningEngine/createEventRegistry.js | 26 +++++++++---------- src/components/DecisioningEngine/utils.js | 14 ++++++++++ .../actions/displayIframeContent.js | 18 +++++-------- .../in-app-message-actions/utils.js | 8 +++--- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/components/DecisioningEngine/createEventRegistry.js b/src/components/DecisioningEngine/createEventRegistry.js index 21893860d..87a840ac6 100644 --- a/src/components/DecisioningEngine/createEventRegistry.js +++ b/src/components/DecisioningEngine/createEventRegistry.js @@ -13,7 +13,8 @@ import { createRestoreStorage, createSaveStorage, getExpirationDate, - getActivityId + getActivityId, + hasExperienceData } from "./utils"; import { EVENT_TYPE_TRUE } from "../../constants/eventType"; @@ -95,16 +96,12 @@ export default ({ storage }) => { const addExperienceEdgeEvent = event => { const { xdm = {} } = event.getContent(); - const { eventType = "", _experience } = xdm; - - if ( - !eventType || - !_experience || - typeof _experience !== "object" || - eventType === "" - ) { + const { _experience } = xdm; + + if (!hasExperienceData(xdm)) { return; } + const { decisioning = {} } = _experience; const { propositionEventType: propositionEventTypeObj = {}, @@ -119,10 +116,14 @@ export default ({ storage }) => { return; } + const validPropositionEventType = propositionEventType => + propositionEventTypeObj[propositionEventType] === EVENT_TYPE_TRUE; + const { id: action } = propositionAction; - propositionEventTypesList.forEach(propositionEventType => { - if (propositionEventTypeObj[propositionEventType] === EVENT_TYPE_TRUE) { + propositionEventTypesList + .filter(validPropositionEventType) + .forEach(propositionEventType => { propositions.forEach(proposition => { addEvent( {}, @@ -131,8 +132,7 @@ export default ({ storage }) => { action ); }); - } - }); + }); }; const getEvent = (eventType, eventId) => { if (!events[eventType]) { diff --git a/src/components/DecisioningEngine/utils.js b/src/components/DecisioningEngine/utils.js index bf3eac582..97b1315f3 100644 --- a/src/components/DecisioningEngine/utils.js +++ b/src/components/DecisioningEngine/utils.js @@ -61,3 +61,17 @@ export const createInMemoryStorage = () => { export const clearLocalStorage = storage => { storage.clear(); }; + +export const hasExperienceData = xdm => { + const { eventType = "", _experience } = xdm; + + if (!eventType || eventType === "") { + return false; + } + + if (!_experience || typeof _experience !== "object") { + return false; + } + + return true; +}; diff --git a/src/components/Personalization/in-app-message-actions/actions/displayIframeContent.js b/src/components/Personalization/in-app-message-actions/actions/displayIframeContent.js index 36557d375..fc79f22eb 100644 --- a/src/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +++ b/src/components/Personalization/in-app-message-actions/actions/displayIframeContent.js @@ -13,17 +13,11 @@ governing permissions and limitations under the License. import { getNonce } from "../../dom-actions/dom"; import { parseAnchor, removeElementById } from "../utils"; import { TEXT_HTML } from "../../../../constants/contentType"; -import { - assign, - includes, - isNonEmptyString, - toArray, - values -} from "../../../../utils"; +import { assign, includes, isNonEmptyString, values } from "../../../../utils"; import { createNode } from "../../../../utils/dom"; import { objectOf } from "../../../../utils/validation"; import { PropositionEventType } from "../../../../constants/propositionEventType"; -import { INTERACT } from "../../../../constants/eventType"; +import { EVENT_TYPE_TRUE, INTERACT } from "../../../../constants/eventType"; import createRedirect from "../../dom-actions/createRedirect"; const ALLOY_MESSAGING_CONTAINER_ID = "alloy-messaging-container"; @@ -292,18 +286,18 @@ export default (settings, collect) => { return new Promise(resolve => { const { meta } = settings; displayHTMLContentInIframe(settings, (action, propositionAction) => { - const propositionEventTypes = new Set(); - propositionEventTypes.add(PropositionEventType.INTERACT); + const propositionEventTypes = {}; + propositionEventTypes[PropositionEventType.INTERACT] = EVENT_TYPE_TRUE; if (Object.values(PropositionEventType).indexOf(action) !== -1) { - propositionEventTypes.add(action); + propositionEventTypes[action] = EVENT_TYPE_TRUE; } collect({ decisionsMeta: [meta], propositionAction, eventType: INTERACT, - propositionEventTypes: toArray(propositionEventTypes) + propositionEventTypes: Object.keys(propositionEventTypes) }); }); diff --git a/src/components/Personalization/in-app-message-actions/utils.js b/src/components/Personalization/in-app-message-actions/utils.js index 43fac75cc..1a85978e5 100644 --- a/src/components/Personalization/in-app-message-actions/utils.js +++ b/src/components/Personalization/in-app-message-actions/utils.js @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import { isNonEmptyArray, startsWith } from "../../../utils"; +import { isNonEmptyArray, queryString, startsWith } from "../../../utils"; import { removeNode, selectNodes } from "../../../utils/dom"; export const removeElementById = id => { @@ -40,9 +40,9 @@ export const parseAnchor = anchor => { let link; if (isNonEmptyArray(hrefParts)) { - const queryParams = new URLSearchParams(hrefParts[1]); - interaction = queryParams.get("interaction") || ""; - link = decodeURIComponent(queryParams.get("link") || ""); + const queryParams = queryString.parse(hrefParts[1]); + interaction = queryParams.interaction || ""; + link = decodeURIComponent(queryParams.link || ""); } return { action,