@adobe/alloy 2.19.0-beta.11 → 2.19.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libEs5/components/DataCollector/index.js +3 -0
- package/libEs5/components/DataCollector/validateApplyResponse.js +2 -1
- package/libEs5/components/DataCollector/validateUserEventOptions.js +2 -1
- package/libEs5/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +32 -0
- package/libEs5/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +25 -0
- package/libEs5/components/DecisioningEngine/constants.js +31 -0
- package/libEs5/components/DecisioningEngine/createApplyResponse.js +34 -0
- package/libEs5/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
- package/libEs5/components/DecisioningEngine/createContextProvider.js +93 -0
- package/libEs5/components/DecisioningEngine/createDecisionHistory.js +28 -0
- package/libEs5/components/DecisioningEngine/createDecisionProvider.js +51 -0
- package/libEs5/components/DecisioningEngine/createEvaluableRulesetPayload.js +80 -0
- package/libEs5/components/DecisioningEngine/createEvaluateRulesetsCommand.js +49 -0
- package/libEs5/components/DecisioningEngine/createEventRegistry.js +123 -0
- package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +43 -0
- package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +87 -0
- package/libEs5/components/DecisioningEngine/index.js +114 -0
- package/libEs5/components/DecisioningEngine/utils.js +83 -0
- package/libEs5/components/Personalization/createActionsProvider.js +72 -0
- package/libEs5/components/Personalization/createApplyPropositions.js +2 -2
- package/libEs5/components/Personalization/createCollect.js +9 -4
- package/libEs5/components/Personalization/createComponent.js +5 -3
- package/libEs5/components/Personalization/createOnClickHandler.js +5 -3
- package/libEs5/components/Personalization/createOnDecisionHandler.js +45 -0
- package/libEs5/components/Personalization/createPersonalizationDetails.js +2 -2
- package/libEs5/components/Personalization/createPreprocessors.js +21 -0
- package/libEs5/components/Personalization/createViewCacheManager.js +1 -1
- package/libEs5/components/Personalization/event.js +25 -22
- package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +76 -0
- package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +288 -0
- package/libEs5/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +23 -0
- package/libEs5/components/Personalization/in-app-message-actions/utils.js +53 -0
- package/libEs5/components/Personalization/index.js +17 -5
- package/libEs5/constants/contentType.js +18 -0
- package/libEs5/constants/eventType.js +25 -0
- package/libEs5/{components/Personalization/constants/eventType.js → constants/handle.js} +4 -7
- package/libEs5/constants/libraryVersion.js +1 -1
- package/libEs5/constants/propositionEventType.js +33 -0
- package/libEs5/{components/Personalization/constants → constants}/schema.js +9 -1
- package/libEs5/core/componentCreators.js +2 -1
- package/libEs5/core/config/createCoreConfigs.js +1 -0
- package/libEs5/core/createEvent.js +26 -1
- package/libEs5/core/createEventManager.js +3 -0
- package/libEs5/core/createLifecycle.js +4 -1
- package/libEs5/utils/createSubscription.js +91 -0
- package/libEs5/utils/debounce.js +30 -0
- package/libEs5/utils/flattenArray.js +37 -0
- package/libEs5/utils/flattenObject.js +43 -0
- package/libEs5/utils/index.js +7 -0
- package/libEs5/utils/parseUrl.js +70 -0
- package/libEs6/components/DataCollector/index.js +2 -0
- package/libEs6/components/DataCollector/validateApplyResponse.js +2 -1
- package/libEs6/components/DataCollector/validateUserEventOptions.js +2 -1
- package/libEs6/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +30 -0
- package/{libEs5/components/Personalization/constants/propositionEventType.js → libEs6/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js} +13 -9
- package/libEs6/components/DecisioningEngine/constants.js +25 -0
- package/libEs6/components/DecisioningEngine/createApplyResponse.js +29 -0
- package/libEs6/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
- package/libEs6/components/DecisioningEngine/createContextProvider.js +95 -0
- package/libEs6/components/DecisioningEngine/createDecisionHistory.js +25 -0
- package/libEs6/components/DecisioningEngine/createDecisionProvider.js +41 -0
- package/libEs6/components/DecisioningEngine/createEvaluableRulesetPayload.js +79 -0
- package/libEs6/components/DecisioningEngine/createEvaluateRulesetsCommand.js +45 -0
- package/libEs6/components/DecisioningEngine/createEventRegistry.js +113 -0
- package/libEs6/components/DecisioningEngine/createOnResponseHandler.js +42 -0
- package/libEs6/components/DecisioningEngine/createSubscribeRulesetItems.js +79 -0
- package/libEs6/components/DecisioningEngine/index.js +119 -0
- package/libEs6/components/DecisioningEngine/utils.js +74 -0
- package/libEs6/components/Personalization/createActionsProvider.js +70 -0
- package/libEs6/components/Personalization/createApplyPropositions.js +2 -2
- package/libEs6/components/Personalization/createCollect.js +7 -4
- package/libEs6/components/Personalization/createComponent.js +5 -3
- package/libEs6/components/Personalization/createOnClickHandler.js +5 -3
- package/libEs6/components/Personalization/createOnDecisionHandler.js +43 -0
- package/libEs6/components/Personalization/createPersonalizationDetails.js +2 -2
- package/libEs6/components/Personalization/createPreprocessors.js +19 -0
- package/libEs6/components/Personalization/createViewCacheManager.js +1 -1
- package/libEs6/components/Personalization/event.js +14 -9
- package/libEs6/components/Personalization/handlers/createProcessInAppMessage.js +77 -0
- package/libEs6/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +291 -0
- package/libEs6/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +17 -0
- package/libEs6/components/Personalization/in-app-message-actions/utils.js +49 -0
- package/libEs6/components/Personalization/index.js +19 -6
- package/libEs6/{components/Personalization/constants/eventType.js → constants/contentType.js} +3 -4
- package/libEs6/constants/eventType.js +17 -0
- package/libEs6/{components/Personalization/constants/propositionEventType.js → constants/handle.js} +2 -6
- package/libEs6/constants/libraryVersion.js +1 -1
- package/libEs6/constants/propositionEventType.js +33 -0
- package/libEs6/{components/Personalization/constants → constants}/schema.js +4 -0
- package/libEs6/core/componentCreators.js +2 -1
- package/libEs6/core/config/createCoreConfigs.js +1 -0
- package/libEs6/core/createEvent.js +26 -1
- package/libEs6/core/createEventManager.js +2 -0
- package/libEs6/core/createLifecycle.js +4 -1
- package/libEs6/utils/createSubscription.js +70 -0
- package/libEs6/utils/debounce.js +22 -0
- package/libEs6/utils/flattenArray.js +26 -0
- package/libEs6/utils/flattenObject.js +28 -0
- package/libEs6/utils/index.js +1 -0
- package/libEs6/utils/parseUrl.js +62 -0
- package/package.json +6 -2
package/libEs6/components/Personalization/in-app-message-actions/actions/displayIframeContent.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { getNonce } from "../../dom-actions/dom";
|
|
14
|
+
import { parseAnchor, removeElementById } from "../utils";
|
|
15
|
+
import { TEXT_HTML } from "../../../../constants/contentType";
|
|
16
|
+
import { assign, includes, isNonEmptyString, values } from "../../../../utils";
|
|
17
|
+
import { createNode } from "../../../../utils/dom";
|
|
18
|
+
import { objectOf } from "../../../../utils/validation";
|
|
19
|
+
import { PropositionEventType } from "../../../../constants/propositionEventType";
|
|
20
|
+
import { EVENT_TYPE_TRUE, INTERACT } from "../../../../constants/eventType";
|
|
21
|
+
import createRedirect from "../../dom-actions/createRedirect";
|
|
22
|
+
const MESSAGING_CONTAINER_ID = "alloy-messaging-container";
|
|
23
|
+
const OVERLAY_CONTAINER_ID = "alloy-overlay-container";
|
|
24
|
+
const IFRAME_ID = "alloy-content-iframe";
|
|
25
|
+
const dismissMessage = () => [MESSAGING_CONTAINER_ID, OVERLAY_CONTAINER_ID].forEach(removeElementById);
|
|
26
|
+
export const createIframeClickHandler = (interact, navigateToUrl = createRedirect(window)) => {
|
|
27
|
+
return event => {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
event.stopImmediatePropagation();
|
|
30
|
+
const {
|
|
31
|
+
target
|
|
32
|
+
} = event;
|
|
33
|
+
const anchor = target.tagName.toLowerCase() === "a" ? target : target.closest("a");
|
|
34
|
+
if (!anchor) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
action,
|
|
39
|
+
interaction,
|
|
40
|
+
link,
|
|
41
|
+
label,
|
|
42
|
+
uuid
|
|
43
|
+
} = parseAnchor(anchor);
|
|
44
|
+
interact(action, {
|
|
45
|
+
label,
|
|
46
|
+
id: interaction,
|
|
47
|
+
uuid,
|
|
48
|
+
link
|
|
49
|
+
});
|
|
50
|
+
if (action === "dismiss") {
|
|
51
|
+
dismissMessage();
|
|
52
|
+
}
|
|
53
|
+
if (isNonEmptyString(link) && link.length > 0) {
|
|
54
|
+
navigateToUrl(link);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export const createIframe = (htmlContent, clickHandler) => {
|
|
59
|
+
const parser = new DOMParser();
|
|
60
|
+
const htmlDocument = parser.parseFromString(htmlContent, TEXT_HTML);
|
|
61
|
+
const scriptTag = htmlDocument.querySelector("script");
|
|
62
|
+
if (scriptTag) {
|
|
63
|
+
scriptTag.setAttribute("nonce", getNonce());
|
|
64
|
+
}
|
|
65
|
+
const element = createNode("iframe", {
|
|
66
|
+
src: URL.createObjectURL(new Blob([htmlDocument.documentElement.outerHTML], {
|
|
67
|
+
type: "text/html"
|
|
68
|
+
})),
|
|
69
|
+
id: IFRAME_ID
|
|
70
|
+
});
|
|
71
|
+
element.addEventListener("load", () => {
|
|
72
|
+
const {
|
|
73
|
+
addEventListener
|
|
74
|
+
} = element.contentDocument || element.contentWindow.document;
|
|
75
|
+
addEventListener("click", clickHandler);
|
|
76
|
+
});
|
|
77
|
+
return element;
|
|
78
|
+
};
|
|
79
|
+
const renderMessage = (iframe, webParameters, container, overlay) => {
|
|
80
|
+
[{
|
|
81
|
+
id: OVERLAY_CONTAINER_ID,
|
|
82
|
+
element: overlay
|
|
83
|
+
}, {
|
|
84
|
+
id: MESSAGING_CONTAINER_ID,
|
|
85
|
+
element: container
|
|
86
|
+
}, {
|
|
87
|
+
id: IFRAME_ID,
|
|
88
|
+
element: iframe
|
|
89
|
+
}].forEach(({
|
|
90
|
+
id,
|
|
91
|
+
element
|
|
92
|
+
}) => {
|
|
93
|
+
const {
|
|
94
|
+
style = {},
|
|
95
|
+
params = {}
|
|
96
|
+
} = webParameters[id];
|
|
97
|
+
assign(element.style, style);
|
|
98
|
+
const {
|
|
99
|
+
parentElement = "body",
|
|
100
|
+
insertionMethod = "appendChild",
|
|
101
|
+
enabled = true
|
|
102
|
+
} = params;
|
|
103
|
+
const parent = document.querySelector(parentElement);
|
|
104
|
+
if (enabled && parent && typeof parent[insertionMethod] === "function") {
|
|
105
|
+
parent[insertionMethod](element);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
export const buildStyleFromMobileParameters = mobileParameters => {
|
|
110
|
+
const {
|
|
111
|
+
verticalAlign,
|
|
112
|
+
width,
|
|
113
|
+
horizontalAlign,
|
|
114
|
+
backdropColor,
|
|
115
|
+
height,
|
|
116
|
+
cornerRadius,
|
|
117
|
+
horizontalInset,
|
|
118
|
+
verticalInset,
|
|
119
|
+
uiTakeover = false
|
|
120
|
+
} = mobileParameters;
|
|
121
|
+
const style = {
|
|
122
|
+
width: width ? `${width}%` : "100%",
|
|
123
|
+
backgroundColor: backdropColor || "rgba(0, 0, 0, 0.5)",
|
|
124
|
+
borderRadius: cornerRadius ? `${cornerRadius}px` : "0px",
|
|
125
|
+
border: "none",
|
|
126
|
+
position: uiTakeover ? "fixed" : "relative",
|
|
127
|
+
overflow: "hidden"
|
|
128
|
+
};
|
|
129
|
+
if (horizontalAlign === "left") {
|
|
130
|
+
style.left = horizontalInset ? `${horizontalInset}%` : "0";
|
|
131
|
+
} else if (horizontalAlign === "right") {
|
|
132
|
+
style.right = horizontalInset ? `${horizontalInset}%` : "0";
|
|
133
|
+
} else if (horizontalAlign === "center") {
|
|
134
|
+
style.left = "50%";
|
|
135
|
+
style.transform = "translateX(-50%)";
|
|
136
|
+
}
|
|
137
|
+
if (verticalAlign === "top") {
|
|
138
|
+
style.top = verticalInset ? `${verticalInset}%` : "0";
|
|
139
|
+
} else if (verticalAlign === "bottom") {
|
|
140
|
+
style.position = "fixed";
|
|
141
|
+
style.bottom = verticalInset ? `${verticalInset}%` : "0";
|
|
142
|
+
} else if (verticalAlign === "center") {
|
|
143
|
+
style.top = "50%";
|
|
144
|
+
style.transform = `${horizontalAlign === "center" ? `${style.transform} ` : ""}translateY(-50%)`;
|
|
145
|
+
style.display = "flex";
|
|
146
|
+
style.alignItems = "center";
|
|
147
|
+
style.justifyContent = "center";
|
|
148
|
+
}
|
|
149
|
+
if (height) {
|
|
150
|
+
style.height = `${height}vh`;
|
|
151
|
+
} else {
|
|
152
|
+
style.height = "100%";
|
|
153
|
+
}
|
|
154
|
+
return style;
|
|
155
|
+
};
|
|
156
|
+
export const mobileOverlay = mobileParameters => {
|
|
157
|
+
const {
|
|
158
|
+
backdropOpacity,
|
|
159
|
+
backdropColor
|
|
160
|
+
} = mobileParameters;
|
|
161
|
+
const opacity = backdropOpacity || 0.5;
|
|
162
|
+
const color = backdropColor || "#FFFFFF";
|
|
163
|
+
const style = {
|
|
164
|
+
position: "fixed",
|
|
165
|
+
top: "0",
|
|
166
|
+
left: "0",
|
|
167
|
+
width: "100%",
|
|
168
|
+
height: "100%",
|
|
169
|
+
background: "transparent",
|
|
170
|
+
opacity,
|
|
171
|
+
backgroundColor: color
|
|
172
|
+
};
|
|
173
|
+
return style;
|
|
174
|
+
};
|
|
175
|
+
const REQUIRED_PARAMS = ["enabled", "parentElement", "insertionMethod"];
|
|
176
|
+
const isValidWebParameters = webParameters => {
|
|
177
|
+
if (!webParameters) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
const ids = Object.keys(webParameters);
|
|
181
|
+
if (!includes(ids, MESSAGING_CONTAINER_ID)) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (!includes(ids, OVERLAY_CONTAINER_ID)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
const valuesArray = values(webParameters);
|
|
188
|
+
for (let i = 0; i < valuesArray.length; i += 1) {
|
|
189
|
+
if (!objectOf(valuesArray[i], "style")) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
if (!objectOf(valuesArray[i], "params")) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
for (let j = 0; j < REQUIRED_PARAMS.length; j += 1) {
|
|
196
|
+
if (!objectOf(valuesArray[i].params, REQUIRED_PARAMS[j])) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
};
|
|
203
|
+
const generateWebParameters = mobileParameters => {
|
|
204
|
+
if (!mobileParameters) {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
const {
|
|
208
|
+
uiTakeover = false
|
|
209
|
+
} = mobileParameters;
|
|
210
|
+
return {
|
|
211
|
+
[IFRAME_ID]: {
|
|
212
|
+
style: {
|
|
213
|
+
border: "none",
|
|
214
|
+
width: "100%",
|
|
215
|
+
height: "100%"
|
|
216
|
+
},
|
|
217
|
+
params: {
|
|
218
|
+
enabled: true,
|
|
219
|
+
parentElement: "#alloy-messaging-container",
|
|
220
|
+
insertionMethod: "appendChild"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
[MESSAGING_CONTAINER_ID]: {
|
|
224
|
+
style: buildStyleFromMobileParameters(mobileParameters),
|
|
225
|
+
params: {
|
|
226
|
+
enabled: true,
|
|
227
|
+
parentElement: "body",
|
|
228
|
+
insertionMethod: "appendChild"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
[OVERLAY_CONTAINER_ID]: {
|
|
232
|
+
style: mobileOverlay(mobileParameters),
|
|
233
|
+
params: {
|
|
234
|
+
enabled: uiTakeover === true,
|
|
235
|
+
parentElement: "body",
|
|
236
|
+
insertionMethod: "appendChild"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
export const displayHTMLContentInIframe = (settings = {}, interact) => {
|
|
242
|
+
dismissMessage();
|
|
243
|
+
const {
|
|
244
|
+
content,
|
|
245
|
+
contentType,
|
|
246
|
+
mobileParameters
|
|
247
|
+
} = settings;
|
|
248
|
+
let {
|
|
249
|
+
webParameters
|
|
250
|
+
} = settings;
|
|
251
|
+
if (contentType !== TEXT_HTML) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const container = createNode("div", {
|
|
255
|
+
id: MESSAGING_CONTAINER_ID
|
|
256
|
+
});
|
|
257
|
+
const iframe = createIframe(content, createIframeClickHandler(interact));
|
|
258
|
+
const overlay = createNode("div", {
|
|
259
|
+
id: OVERLAY_CONTAINER_ID
|
|
260
|
+
});
|
|
261
|
+
if (!isValidWebParameters(webParameters)) {
|
|
262
|
+
webParameters = generateWebParameters(mobileParameters);
|
|
263
|
+
}
|
|
264
|
+
if (!webParameters) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
renderMessage(iframe, webParameters, container, overlay);
|
|
268
|
+
};
|
|
269
|
+
export default ((settings, collect) => {
|
|
270
|
+
return new Promise(resolve => {
|
|
271
|
+
const {
|
|
272
|
+
meta
|
|
273
|
+
} = settings;
|
|
274
|
+
displayHTMLContentInIframe(settings, (action, propositionAction) => {
|
|
275
|
+
const propositionEventTypes = {};
|
|
276
|
+
propositionEventTypes[PropositionEventType.INTERACT] = EVENT_TYPE_TRUE;
|
|
277
|
+
if (Object.values(PropositionEventType).indexOf(action) !== -1) {
|
|
278
|
+
propositionEventTypes[action] = EVENT_TYPE_TRUE;
|
|
279
|
+
}
|
|
280
|
+
collect({
|
|
281
|
+
decisionsMeta: [meta],
|
|
282
|
+
propositionAction,
|
|
283
|
+
eventType: INTERACT,
|
|
284
|
+
propositionEventTypes: Object.keys(propositionEventTypes)
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
resolve({
|
|
288
|
+
meta
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|
package/libEs6/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import displayIframeContent from "./actions/displayIframeContent";
|
|
13
|
+
export default (collect => {
|
|
14
|
+
return {
|
|
15
|
+
defaultContent: settings => displayIframeContent(settings, collect)
|
|
16
|
+
};
|
|
17
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { isNonEmptyArray, queryString, startsWith } from "../../../utils";
|
|
13
|
+
import { removeNode, selectNodes } from "../../../utils/dom";
|
|
14
|
+
export const removeElementById = id => {
|
|
15
|
+
const element = selectNodes(`#${id}`, document);
|
|
16
|
+
if (element && element.length > 0) {
|
|
17
|
+
removeNode(element[0]);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const parseAnchor = anchor => {
|
|
21
|
+
const nothing = {};
|
|
22
|
+
if (!anchor || anchor.tagName.toLowerCase() !== "a") {
|
|
23
|
+
return nothing;
|
|
24
|
+
}
|
|
25
|
+
const {
|
|
26
|
+
href
|
|
27
|
+
} = anchor;
|
|
28
|
+
if (!href || !startsWith(href, "adbinapp://")) {
|
|
29
|
+
return nothing;
|
|
30
|
+
}
|
|
31
|
+
const hrefParts = href.split("?");
|
|
32
|
+
const action = hrefParts[0].split("://")[1];
|
|
33
|
+
const label = anchor.innerText;
|
|
34
|
+
const uuid = anchor.getAttribute("data-uuid") || "";
|
|
35
|
+
let interaction;
|
|
36
|
+
let link;
|
|
37
|
+
if (isNonEmptyArray(hrefParts)) {
|
|
38
|
+
const queryParams = queryString.parse(hrefParts[1]);
|
|
39
|
+
interaction = queryParams.interaction || "";
|
|
40
|
+
link = decodeURIComponent(queryParams.link || "");
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
action,
|
|
44
|
+
interaction,
|
|
45
|
+
link,
|
|
46
|
+
label,
|
|
47
|
+
uuid
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { boolean, objectOf, string } from "../../utils/validation";
|
|
14
14
|
import createComponent from "./createComponent";
|
|
15
15
|
import { initDomActionsModules } from "./dom-actions";
|
|
16
16
|
import createCollect from "./createCollect";
|
|
@@ -31,13 +31,16 @@ import remapHeadOffers from "./dom-actions/remapHeadOffers";
|
|
|
31
31
|
import createPreprocess from "./dom-actions/createPreprocess";
|
|
32
32
|
import injectCreateProposition from "./handlers/injectCreateProposition";
|
|
33
33
|
import createAsyncArray from "./utils/createAsyncArray";
|
|
34
|
-
import * as schema from "
|
|
34
|
+
import * as schema from "../../constants/schema";
|
|
35
35
|
import processDefaultContent from "./handlers/processDefaultContent";
|
|
36
36
|
import { isPageWideSurface } from "./utils/surfaceUtils";
|
|
37
37
|
import createProcessDomAction from "./handlers/createProcessDomAction";
|
|
38
38
|
import createProcessHtmlContent from "./handlers/createProcessHtmlContent";
|
|
39
39
|
import createProcessRedirect from "./handlers/createProcessRedirect";
|
|
40
40
|
import createProcessPropositions from "./handlers/createProcessPropositions";
|
|
41
|
+
import createOnDecisionHandler from "./createOnDecisionHandler";
|
|
42
|
+
import createProcessInAppMessage from "./handlers/createProcessInAppMessage";
|
|
43
|
+
import initInAppMessageActionsModules from "./in-app-message-actions/initInAppMessageActionsModules";
|
|
41
44
|
import createRedirect from "./dom-actions/createRedirect";
|
|
42
45
|
const createPersonalization = ({
|
|
43
46
|
config,
|
|
@@ -60,7 +63,7 @@ const createPersonalization = ({
|
|
|
60
63
|
const getPageLocation = createGetPageLocation({
|
|
61
64
|
window
|
|
62
65
|
});
|
|
63
|
-
const
|
|
66
|
+
const domActionsModules = initDomActionsModules();
|
|
64
67
|
const preprocess = createPreprocess([remapHeadOffers, remapCustomCodeOffers]);
|
|
65
68
|
const createProposition = injectCreateProposition({
|
|
66
69
|
preprocess,
|
|
@@ -73,18 +76,22 @@ const createPersonalization = ({
|
|
|
73
76
|
const schemaProcessors = {
|
|
74
77
|
[schema.DEFAULT_CONTENT_ITEM]: processDefaultContent,
|
|
75
78
|
[schema.DOM_ACTION]: createProcessDomAction({
|
|
76
|
-
modules,
|
|
79
|
+
modules: domActionsModules,
|
|
77
80
|
logger,
|
|
78
81
|
storeClickMetrics
|
|
79
82
|
}),
|
|
80
83
|
[schema.HTML_CONTENT_ITEM]: createProcessHtmlContent({
|
|
81
|
-
modules,
|
|
84
|
+
modules: domActionsModules,
|
|
82
85
|
logger
|
|
83
86
|
}),
|
|
84
87
|
[schema.REDIRECT_ITEM]: createProcessRedirect({
|
|
85
88
|
logger,
|
|
86
89
|
executeRedirect,
|
|
87
90
|
collect
|
|
91
|
+
}),
|
|
92
|
+
[schema.MESSAGE_IN_APP]: createProcessInAppMessage({
|
|
93
|
+
modules: initInAppMessageActionsModules(collect),
|
|
94
|
+
logger
|
|
88
95
|
})
|
|
89
96
|
};
|
|
90
97
|
const processPropositions = createProcessPropositions({
|
|
@@ -121,6 +128,11 @@ const createPersonalization = ({
|
|
|
121
128
|
const setTargetMigration = createSetTargetMigration({
|
|
122
129
|
targetMigrationEnabled
|
|
123
130
|
});
|
|
131
|
+
const onDecisionHandler = createOnDecisionHandler({
|
|
132
|
+
processPropositions,
|
|
133
|
+
createProposition,
|
|
134
|
+
collect
|
|
135
|
+
});
|
|
124
136
|
return createComponent({
|
|
125
137
|
getPageLocation,
|
|
126
138
|
logger,
|
|
@@ -134,7 +146,8 @@ const createPersonalization = ({
|
|
|
134
146
|
applyPropositions,
|
|
135
147
|
setTargetMigration,
|
|
136
148
|
mergeDecisionsMeta,
|
|
137
|
-
renderedPropositions
|
|
149
|
+
renderedPropositions,
|
|
150
|
+
onDecisionHandler
|
|
138
151
|
});
|
|
139
152
|
};
|
|
140
153
|
createPersonalization.namespace = "Personalization";
|
package/libEs6/{components/Personalization/constants/eventType.js → constants/contentType.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
3
|
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
5
|
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
@@ -9,6 +9,5 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
export const INTERACT = "decisioning.propositionInteract";
|
|
12
|
+
export const TEXT_HTML = "text/html";
|
|
13
|
+
export const APPLICATION_JSON = "application/json";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const DISPLAY = "decisioning.propositionDisplay";
|
|
14
|
+
export const INTERACT = "decisioning.propositionInteract";
|
|
15
|
+
export const TRIGGER = "decisioning.propositionTrigger";
|
|
16
|
+
export const DISMISS = "decisioning.propositionDismiss";
|
|
17
|
+
export const EVENT_TYPE_TRUE = 1;
|
package/libEs6/{components/Personalization/constants/propositionEventType.js → constants/handle.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
3
|
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
5
|
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
@@ -9,8 +9,4 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
export const PropositionEventType = {
|
|
14
|
-
DISPLAY: "display",
|
|
15
|
-
INTERACT: "interact"
|
|
16
|
-
};
|
|
12
|
+
export const PERSONALIZATION_DECISIONS_HANDLE = "personalization:decisions";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { DISPLAY, INTERACT, TRIGGER, DISMISS } from "./eventType";
|
|
14
|
+
export const PropositionEventType = {
|
|
15
|
+
DISPLAY: "display",
|
|
16
|
+
INTERACT: "interact",
|
|
17
|
+
TRIGGER: "trigger",
|
|
18
|
+
DISMISS: "dismiss"
|
|
19
|
+
};
|
|
20
|
+
const eventTypeToPropositionEventTypeMapping = {
|
|
21
|
+
[DISPLAY]: PropositionEventType.DISPLAY,
|
|
22
|
+
[INTERACT]: PropositionEventType.INTERACT,
|
|
23
|
+
[TRIGGER]: PropositionEventType.TRIGGER,
|
|
24
|
+
[DISMISS]: PropositionEventType.DISMISS
|
|
25
|
+
};
|
|
26
|
+
const propositionEventTypeToEventTypeMapping = {
|
|
27
|
+
[PropositionEventType.DISPLAY]: DISPLAY,
|
|
28
|
+
[PropositionEventType.INTERACT]: INTERACT,
|
|
29
|
+
[PropositionEventType.TRIGGER]: TRIGGER,
|
|
30
|
+
[PropositionEventType.DISMISS]: DISMISS
|
|
31
|
+
};
|
|
32
|
+
export const getPropositionEventType = eventType => eventTypeToPropositionEventTypeMapping[eventType];
|
|
33
|
+
export const getEventType = propositionEventType => propositionEventTypeToEventTypeMapping[propositionEventType];
|
|
@@ -14,5 +14,9 @@ export const DEFAULT_CONTENT_ITEM = "https://ns.adobe.com/personalization/defaul
|
|
|
14
14
|
export const DOM_ACTION = "https://ns.adobe.com/personalization/dom-action";
|
|
15
15
|
export const HTML_CONTENT_ITEM = "https://ns.adobe.com/personalization/html-content-item";
|
|
16
16
|
export const JSON_CONTENT_ITEM = "https://ns.adobe.com/personalization/json-content-item";
|
|
17
|
+
export const RULESET_ITEM = "https://ns.adobe.com/personalization/ruleset-item";
|
|
17
18
|
export const REDIRECT_ITEM = "https://ns.adobe.com/personalization/redirect-item";
|
|
19
|
+
export const MESSAGE_IN_APP = "https://ns.adobe.com/personalization/message/in-app";
|
|
20
|
+
export const MESSAGE_FEED_ITEM = "https://ns.adobe.com/personalization/message/feed-item";
|
|
21
|
+
export const MESSAGE_NATIVE_ALERT = "https://ns.adobe.com/personalization/message/native-alert";
|
|
18
22
|
export const MEASUREMENT_SCHEMA = "https://ns.adobe.com/personalization/measurement";
|
|
@@ -21,8 +21,9 @@ import createContext from "../components/Context";
|
|
|
21
21
|
import createPrivacy from "../components/Privacy";
|
|
22
22
|
import createEventMerge from "../components/EventMerge";
|
|
23
23
|
import createLibraryInfo from "../components/LibraryInfo";
|
|
24
|
+
import createDecisioningEngine from "../components/DecisioningEngine";
|
|
24
25
|
import createMachineLearning from "../components/MachineLearning";
|
|
25
26
|
|
|
26
27
|
// TODO: Register the Components here statically for now. They might be registered differently.
|
|
27
28
|
// TODO: Figure out how sub-components will be made available/registered
|
|
28
|
-
export default [createDataCollector, createActivityCollector, createIdentity, createAudiences, createPersonalization, createContext, createPrivacy, createEventMerge, createLibraryInfo, createMachineLearning];
|
|
29
|
+
export default [createDataCollector, createActivityCollector, createIdentity, createAudiences, createPersonalization, createContext, createPrivacy, createEventMerge, createLibraryInfo, createMachineLearning, createDecisioningEngine];
|
|
@@ -22,6 +22,7 @@ export default (() => objectOf({
|
|
|
22
22
|
edgeDomain: string().domain().default(EDGE_DOMAIN),
|
|
23
23
|
edgeBasePath: string().nonEmpty().default(EDGE_BASE_PATH),
|
|
24
24
|
orgId: string().unique().required(),
|
|
25
|
+
personalizationStorageEnabled: boolean().default(true),
|
|
25
26
|
onBeforeEventSend: callback().default(noop),
|
|
26
27
|
edgeConfigOverrides: validateConfigOverride
|
|
27
28
|
}).deprecated("edgeConfigId", string().unique(), "datastreamId"));
|
|
@@ -35,6 +35,23 @@ export default (() => {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
const event = {
|
|
38
|
+
hasQuery() {
|
|
39
|
+
return Object.prototype.hasOwnProperty.call(this.getContent(), "query");
|
|
40
|
+
},
|
|
41
|
+
getContent() {
|
|
42
|
+
const currentContent = JSON.parse(JSON.stringify(content));
|
|
43
|
+
if (userXdm) {
|
|
44
|
+
deepAssign(currentContent, {
|
|
45
|
+
xdm: userXdm
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (userData) {
|
|
49
|
+
deepAssign(currentContent, {
|
|
50
|
+
data: userData
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return currentContent;
|
|
54
|
+
},
|
|
38
55
|
setUserXdm(value) {
|
|
39
56
|
throwIfEventFinalized("setUserXdm");
|
|
40
57
|
userXdm = value;
|
|
@@ -51,6 +68,14 @@ export default (() => {
|
|
|
51
68
|
});
|
|
52
69
|
}
|
|
53
70
|
},
|
|
71
|
+
mergeData(data) {
|
|
72
|
+
throwIfEventFinalized("mergeData");
|
|
73
|
+
if (data) {
|
|
74
|
+
deepAssign(content, {
|
|
75
|
+
data
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
54
79
|
mergeMeta(meta) {
|
|
55
80
|
throwIfEventFinalized("mergeMeta");
|
|
56
81
|
if (meta) {
|
|
@@ -83,7 +108,7 @@ export default (() => {
|
|
|
83
108
|
content.xdm._experience.decisioning.propositions = newPropositions;
|
|
84
109
|
}
|
|
85
110
|
if (userData) {
|
|
86
|
-
|
|
111
|
+
event.mergeData(userData);
|
|
87
112
|
}
|
|
88
113
|
|
|
89
114
|
// the event should already be considered finalized in case onBeforeEventSend throws an error
|
|
@@ -101,6 +101,7 @@ export default (({
|
|
|
101
101
|
applyResponse(event, options = {}) {
|
|
102
102
|
const {
|
|
103
103
|
renderDecisions = false,
|
|
104
|
+
decisionContext = {},
|
|
104
105
|
responseHeaders = {},
|
|
105
106
|
responseBody = {
|
|
106
107
|
handle: []
|
|
@@ -115,6 +116,7 @@ export default (({
|
|
|
115
116
|
return lifecycle.onBeforeEvent({
|
|
116
117
|
event,
|
|
117
118
|
renderDecisions,
|
|
119
|
+
decisionContext,
|
|
118
120
|
decisionScopes: [PAGE_WIDE_SCOPE],
|
|
119
121
|
personalization,
|
|
120
122
|
onResponse: onResponseCallbackAggregator.add,
|
|
@@ -29,7 +29,10 @@ const hookNames = [
|
|
|
29
29
|
// { response } is passed as the parameter)
|
|
30
30
|
"onRequestFailure",
|
|
31
31
|
// A user clicked on an element.
|
|
32
|
-
"onClick"
|
|
32
|
+
"onClick",
|
|
33
|
+
// Called by DecisioningEngine when a ruleset is satisfied with a list of
|
|
34
|
+
// propositions
|
|
35
|
+
"onDecision"];
|
|
33
36
|
const createHook = (componentRegistry, hookName) => {
|
|
34
37
|
return (...args) => {
|
|
35
38
|
return Promise.all(componentRegistry.getLifecycleCallbacks(hookName).map(callback => {
|