Skip to content

Commit

Permalink
some fixes (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwaters authored Oct 27, 2023
1 parent d740196 commit 899ec90
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
26 changes: 13 additions & 13 deletions src/components/DecisioningEngine/createEventRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
createRestoreStorage,
createSaveStorage,
getExpirationDate,
getActivityId
getActivityId,
hasExperienceData
} from "./utils";
import { EVENT_TYPE_TRUE } from "../../constants/eventType";

Expand Down Expand Up @@ -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 = {},
Expand All @@ -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(
{},
Expand All @@ -131,8 +132,7 @@ export default ({ storage }) => {
action
);
});
}
});
});
};
const getEvent = (eventType, eventId) => {
if (!events[eventType]) {
Expand Down
14 changes: 14 additions & 0 deletions src/components/DecisioningEngine/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 899ec90

Please sign in to comment.