@adobe/alloy 2.19.0-beta.9 → 2.19.1-beta.0

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.
Files changed (116) hide show
  1. package/README.md +4 -1
  2. package/libEs5/components/DataCollector/index.js +3 -0
  3. package/libEs5/components/DataCollector/validateApplyResponse.js +2 -1
  4. package/libEs5/components/DataCollector/validateUserEventOptions.js +2 -1
  5. package/libEs5/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +32 -0
  6. package/libEs5/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +25 -0
  7. package/libEs5/components/DecisioningEngine/constants.js +31 -0
  8. package/libEs5/components/DecisioningEngine/createApplyResponse.js +36 -0
  9. package/libEs5/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
  10. package/libEs5/components/DecisioningEngine/createContextProvider.js +93 -0
  11. package/libEs5/components/DecisioningEngine/createDecisionHistory.js +28 -0
  12. package/libEs5/components/DecisioningEngine/createDecisionProvider.js +51 -0
  13. package/libEs5/components/DecisioningEngine/createEvaluableRulesetPayload.js +80 -0
  14. package/libEs5/components/DecisioningEngine/createEvaluateRulesetsCommand.js +49 -0
  15. package/libEs5/components/DecisioningEngine/createEventRegistry.js +130 -0
  16. package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +46 -0
  17. package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +87 -0
  18. package/libEs5/components/DecisioningEngine/index.js +119 -0
  19. package/libEs5/components/DecisioningEngine/utils.js +90 -0
  20. package/libEs5/components/Personalization/createActionsProvider.js +72 -0
  21. package/libEs5/components/Personalization/createApplyPropositions.js +2 -2
  22. package/libEs5/components/Personalization/createCollect.js +9 -4
  23. package/libEs5/components/Personalization/createComponent.js +5 -3
  24. package/libEs5/components/Personalization/createFetchDataHandler.js +2 -17
  25. package/libEs5/components/Personalization/createNotificationHandler.js +33 -0
  26. package/libEs5/components/Personalization/createOnClickHandler.js +5 -3
  27. package/libEs5/components/Personalization/createOnDecisionHandler.js +44 -0
  28. package/libEs5/components/Personalization/createPersonalizationDetails.js +8 -5
  29. package/libEs5/components/Personalization/createPreprocessors.js +21 -0
  30. package/libEs5/components/Personalization/createViewCacheManager.js +9 -2
  31. package/libEs5/components/Personalization/dom-actions/createRedirect.js +11 -1
  32. package/libEs5/components/Personalization/event.js +25 -22
  33. package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +76 -0
  34. package/libEs5/components/Personalization/handlers/createProcessRedirect.js +5 -2
  35. package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +288 -0
  36. package/libEs5/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +23 -0
  37. package/libEs5/components/Personalization/in-app-message-actions/utils.js +53 -0
  38. package/libEs5/components/Personalization/index.js +20 -7
  39. package/libEs5/constants/contentType.js +18 -0
  40. package/libEs5/{components/Personalization/constants/propositionEventType.js → constants/decisionProvider.js} +4 -8
  41. package/libEs5/constants/eventType.js +25 -0
  42. package/libEs5/{components/Personalization/constants/eventType.js → constants/handle.js} +4 -7
  43. package/libEs5/constants/libraryVersion.js +1 -1
  44. package/libEs5/constants/propositionEventType.js +33 -0
  45. package/libEs5/{components/Personalization/constants → constants}/schema.js +9 -1
  46. package/libEs5/core/componentCreators.js +2 -1
  47. package/libEs5/core/createEvent.js +26 -1
  48. package/libEs5/core/createEventManager.js +3 -0
  49. package/libEs5/core/createLifecycle.js +4 -1
  50. package/libEs5/core/edgeNetwork/mergeLifecycleResponses.js +1 -1
  51. package/libEs5/utils/assignConcatArrayValues.js +49 -0
  52. package/libEs5/utils/createSubscription.js +91 -0
  53. package/libEs5/utils/debounce.js +30 -0
  54. package/libEs5/utils/dom/selectNodesWithShadow.js +10 -3
  55. package/libEs5/utils/flattenArray.js +37 -0
  56. package/libEs5/utils/flattenObject.js +43 -0
  57. package/libEs5/utils/index.js +14 -0
  58. package/libEs5/utils/parseUrl.js +70 -0
  59. package/libEs6/components/DataCollector/index.js +2 -0
  60. package/libEs6/components/DataCollector/validateApplyResponse.js +2 -1
  61. package/libEs6/components/DataCollector/validateUserEventOptions.js +2 -1
  62. package/libEs6/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +30 -0
  63. package/libEs6/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +24 -0
  64. package/libEs6/components/DecisioningEngine/constants.js +25 -0
  65. package/libEs6/components/DecisioningEngine/createApplyResponse.js +31 -0
  66. package/libEs6/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
  67. package/libEs6/components/DecisioningEngine/createContextProvider.js +95 -0
  68. package/libEs6/components/DecisioningEngine/createDecisionHistory.js +25 -0
  69. package/libEs6/components/DecisioningEngine/createDecisionProvider.js +41 -0
  70. package/libEs6/components/DecisioningEngine/createEvaluableRulesetPayload.js +79 -0
  71. package/libEs6/components/DecisioningEngine/createEvaluateRulesetsCommand.js +45 -0
  72. package/libEs6/components/DecisioningEngine/createEventRegistry.js +120 -0
  73. package/libEs6/components/DecisioningEngine/createOnResponseHandler.js +45 -0
  74. package/libEs6/components/DecisioningEngine/createSubscribeRulesetItems.js +79 -0
  75. package/libEs6/components/DecisioningEngine/index.js +124 -0
  76. package/libEs6/components/DecisioningEngine/utils.js +83 -0
  77. package/libEs6/components/Personalization/createActionsProvider.js +70 -0
  78. package/libEs6/components/Personalization/createApplyPropositions.js +2 -2
  79. package/libEs6/components/Personalization/createCollect.js +7 -4
  80. package/libEs6/components/Personalization/createComponent.js +5 -3
  81. package/libEs6/components/Personalization/createFetchDataHandler.js +3 -18
  82. package/libEs6/components/Personalization/createNotificationHandler.js +29 -0
  83. package/libEs6/components/Personalization/createOnClickHandler.js +5 -3
  84. package/libEs6/components/Personalization/createOnDecisionHandler.js +42 -0
  85. package/libEs6/components/Personalization/createPersonalizationDetails.js +8 -5
  86. package/libEs6/components/Personalization/createPreprocessors.js +19 -0
  87. package/libEs6/components/Personalization/createViewCacheManager.js +12 -3
  88. package/libEs6/components/Personalization/dom-actions/createRedirect.js +10 -1
  89. package/libEs6/components/Personalization/event.js +14 -9
  90. package/libEs6/components/Personalization/handlers/createProcessInAppMessage.js +77 -0
  91. package/libEs6/components/Personalization/handlers/createProcessRedirect.js +5 -2
  92. package/libEs6/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +291 -0
  93. package/libEs6/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +17 -0
  94. package/libEs6/components/Personalization/in-app-message-actions/utils.js +49 -0
  95. package/libEs6/components/Personalization/index.js +22 -8
  96. package/libEs6/{components/Personalization/constants/eventType.js → constants/contentType.js} +3 -4
  97. package/libEs6/{components/Personalization/constants/propositionEventType.js → constants/decisionProvider.js} +2 -6
  98. package/libEs6/constants/eventType.js +17 -0
  99. package/libEs6/constants/handle.js +12 -0
  100. package/libEs6/constants/libraryVersion.js +1 -1
  101. package/libEs6/constants/propositionEventType.js +33 -0
  102. package/libEs6/{components/Personalization/constants → constants}/schema.js +4 -0
  103. package/libEs6/core/componentCreators.js +2 -1
  104. package/libEs6/core/createEvent.js +26 -1
  105. package/libEs6/core/createEventManager.js +2 -0
  106. package/libEs6/core/createLifecycle.js +4 -1
  107. package/libEs6/core/edgeNetwork/mergeLifecycleResponses.js +3 -2
  108. package/libEs6/utils/assignConcatArrayValues.js +36 -0
  109. package/libEs6/utils/createSubscription.js +70 -0
  110. package/libEs6/utils/debounce.js +22 -0
  111. package/libEs6/utils/dom/selectNodesWithShadow.js +10 -3
  112. package/libEs6/utils/flattenArray.js +26 -0
  113. package/libEs6/utils/flattenObject.js +28 -0
  114. package/libEs6/utils/index.js +2 -0
  115. package/libEs6/utils/parseUrl.js +62 -0
  116. package/package.json +6 -2
@@ -11,8 +11,8 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  import { isNonEmptyArray } from "../../utils";
14
- import { INTERACT } from "./constants/eventType";
15
- import { PropositionEventType } from "./constants/propositionEventType";
14
+ import { INTERACT } from "../../constants/eventType";
15
+ import { PropositionEventType } from "../../constants/propositionEventType";
16
16
  export default (({
17
17
  mergeDecisionsMeta,
18
18
  collectClicks,
@@ -43,7 +43,9 @@ export default (({
43
43
  };
44
44
  }
45
45
  event.mergeXdm(xdm);
46
- mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.INTERACT, eventLabel);
46
+ mergeDecisionsMeta(event, decisionsMeta, [PropositionEventType.INTERACT], eventLabel ? {
47
+ label: eventLabel
48
+ } : undefined);
47
49
  }
48
50
  }
49
51
  };
@@ -0,0 +1,42 @@
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
+ export default (({
14
+ processPropositions,
15
+ createProposition,
16
+ notificationHandler
17
+ }) => {
18
+ return ({
19
+ renderDecisions,
20
+ propositions,
21
+ event,
22
+ personalization = {}
23
+ }) => {
24
+ if (!renderDecisions) {
25
+ return Promise.resolve();
26
+ }
27
+ const {
28
+ sendDisplayEvent = true
29
+ } = personalization;
30
+ const viewName = event ? event.getViewName() : undefined;
31
+ const propositionsToExecute = propositions.map(proposition => createProposition(proposition, true));
32
+ const {
33
+ render,
34
+ returnedPropositions
35
+ } = processPropositions(propositionsToExecute);
36
+ const handleNotifications = notificationHandler(sendDisplayEvent, viewName);
37
+ render().then(handleNotifications);
38
+ return Promise.resolve({
39
+ propositions: returnedPropositions
40
+ });
41
+ };
42
+ });
@@ -13,7 +13,7 @@ governing permissions and limitations under the License.
13
13
  import { includes, isNonEmptyString, isNonEmptyArray } from "../../utils";
14
14
  import { buildPageSurface, normalizeSurfaces } from "./utils/surfaceUtils";
15
15
  import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
16
- import { DEFAULT_CONTENT_ITEM, DOM_ACTION, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM } from "./constants/schema";
16
+ import { DEFAULT_CONTENT_ITEM, DOM_ACTION, HTML_CONTENT_ITEM, MESSAGE_IN_APP, JSON_CONTENT_ITEM, REDIRECT_ITEM, RULESET_ITEM, MESSAGE_FEED_ITEM } from "../../constants/schema";
17
17
  const addPageWideScope = scopes => {
18
18
  if (!includes(scopes, PAGE_WIDE_SCOPE)) {
19
19
  scopes.push(PAGE_WIDE_SCOPE);
@@ -64,11 +64,11 @@ export default (({
64
64
  scopes.push(...personalization.decisionScopes);
65
65
  }
66
66
  const eventSurfaces = normalizeSurfaces(personalization.surfaces, getPageLocation, logger);
67
- if (!this.isCacheInitialized() || personalization.requestPersonalization) {
67
+ if (this.shouldRequestDefaultPersonalization()) {
68
68
  addPageWideScope(scopes);
69
69
  addPageSurface(eventSurfaces, getPageLocation);
70
70
  }
71
- const schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM];
71
+ const schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM, RULESET_ITEM, MESSAGE_IN_APP, MESSAGE_FEED_ITEM];
72
72
  if (includes(scopes, PAGE_WIDE_SCOPE)) {
73
73
  schemas.push(DOM_ACTION);
74
74
  }
@@ -82,10 +82,13 @@ export default (({
82
82
  return isCacheInitialized;
83
83
  },
84
84
  shouldFetchData() {
85
- return this.hasScopes() || this.hasSurfaces() || personalization.requestPersonalization || !this.isCacheInitialized() && personalization.requestPersonalization !== false;
85
+ return this.hasScopes() || this.hasSurfaces() || this.shouldRequestDefaultPersonalization();
86
86
  },
87
87
  shouldUseCachedData() {
88
- return this.hasViewName() && this.isCacheInitialized();
88
+ return this.hasViewName() && !this.shouldFetchData();
89
+ },
90
+ shouldRequestDefaultPersonalization() {
91
+ return personalization.defaultPersonalizationEnabled || !this.isCacheInitialized() && personalization.defaultPersonalizationEnabled !== false;
89
92
  }
90
93
  };
91
94
  });
@@ -0,0 +1,19 @@
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 { DOM_ACTION } from "../../constants/schema";
13
+ import remapHeadOffers from "./dom-actions/remapHeadOffers";
14
+ import remapCustomCodeOffers from "./dom-actions/remapCustomCodeOffers";
15
+ export default (() => {
16
+ return {
17
+ [DOM_ACTION]: [remapHeadOffers, remapCustomCodeOffers]
18
+ };
19
+ });
@@ -10,9 +10,9 @@ 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 { groupBy } from "../../utils";
13
+ import { assign, groupBy } from "../../utils";
14
14
  import defer from "../../utils/defer";
15
- import { DEFAULT_CONTENT_ITEM } from "./constants/schema";
15
+ import { DEFAULT_CONTENT_ITEM } from "../../constants/schema";
16
16
  import { VIEW_SCOPE_TYPE } from "./constants/scopeType";
17
17
  export default (({
18
18
  createProposition
@@ -42,7 +42,16 @@ export default (({
42
42
  const createCacheUpdate = viewName => {
43
43
  const updateCacheDeferred = defer();
44
44
  cacheUpdateCreatedAtLeastOnce = true;
45
- viewStoragePromise = viewStoragePromise.then(oldViewStorage => updateCacheDeferred.promise.catch(() => oldViewStorage));
45
+
46
+ // Additional updates will merge the new view propositions with the old.
47
+ // i.e. if there are new "cart" view propositions they will overwrite the
48
+ // old "cart" view propositions, but if there are no new "cart" view
49
+ // propositions the old "cart" view propositions will remain.
50
+ viewStoragePromise = viewStoragePromise.then(oldViewStorage => {
51
+ return updateCacheDeferred.promise.then(newViewStorage => {
52
+ return assign({}, oldViewStorage, newViewStorage);
53
+ }).catch(() => oldViewStorage);
54
+ });
46
55
  return {
47
56
  update(viewPropositions) {
48
57
  const viewPropositionsWithScope = viewPropositions.filter(proposition => proposition.getScope());
@@ -10,4 +10,13 @@ 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
- export default (window => url => window.location.replace(url));
13
+ export default (window => (url, preserveHistory = false) => {
14
+ if (preserveHistory) {
15
+ window.location.href = url;
16
+ } else {
17
+ window.location.replace(url);
18
+ }
19
+ // Return a promise that never resolves because redirects never complete
20
+ // within the current page.
21
+ return new Promise(() => undefined);
22
+ });
@@ -10,24 +10,29 @@ 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
- const EVENT_TYPE_TRUE = 1;
13
+ import { EVENT_TYPE_TRUE } from "../../constants/eventType";
14
14
 
15
15
  /* eslint-disable no-underscore-dangle */
16
- export const mergeDecisionsMeta = (event, decisionsMeta, eventType, eventLabel = "") => {
16
+ export const mergeDecisionsMeta = (event, decisionsMeta, propositionEventTypes, propositionAction) => {
17
+ // Do not send a display notification with no decisions. Even empty view changes
18
+ // should include a proposition.
19
+ if (decisionsMeta.length === 0) {
20
+ return;
21
+ }
22
+ const propositionEventType = {};
23
+ propositionEventTypes.forEach(type => {
24
+ propositionEventType[type] = EVENT_TYPE_TRUE;
25
+ });
17
26
  const xdm = {
18
27
  _experience: {
19
28
  decisioning: {
20
29
  propositions: decisionsMeta,
21
- propositionEventType: {
22
- [eventType]: EVENT_TYPE_TRUE
23
- }
30
+ propositionEventType
24
31
  }
25
32
  }
26
33
  };
27
- if (eventLabel) {
28
- xdm._experience.decisioning.propositionAction = {
29
- label: eventLabel
30
- };
34
+ if (propositionAction) {
35
+ xdm._experience.decisioning.propositionAction = propositionAction;
31
36
  }
32
37
  event.mergeXdm(xdm);
33
38
  };
@@ -0,0 +1,77 @@
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 { APPLICATION_JSON } from "../../../constants/contentType";
13
+ const DEFAULT_CONTENT = "defaultContent";
14
+ const expectedProps = ["content", "contentType"];
15
+ const expectedContentProps = ["mobileParameters", "webParameters", "html"];
16
+ const isValidInAppMessage = (data, logger) => {
17
+ for (let i = 0; i < expectedProps.length; i += 1) {
18
+ const prop = expectedProps[i];
19
+ if (!Object.prototype.hasOwnProperty.call(data, prop)) {
20
+ logger.warn(`Invalid in-app message data: missing property '${prop}'.`, data);
21
+ return false;
22
+ }
23
+ }
24
+ const {
25
+ content,
26
+ contentType
27
+ } = data;
28
+ if (contentType === APPLICATION_JSON) {
29
+ for (let i = 0; i < expectedContentProps.length; i += 1) {
30
+ const prop = expectedContentProps[i];
31
+ if (!Object.prototype.hasOwnProperty.call(content, prop)) {
32
+ logger.warn(`Invalid in-app message data.content: missing property '${prop}'.`, data);
33
+ return false;
34
+ }
35
+ }
36
+ }
37
+ return true;
38
+ };
39
+ export default (({
40
+ modules,
41
+ logger
42
+ }) => {
43
+ return item => {
44
+ const data = item.getData();
45
+ const meta = {
46
+ ...item.getProposition().getNotification()
47
+ };
48
+ if (!data) {
49
+ logger.warn("Invalid in-app message data: undefined.", data);
50
+ return {};
51
+ }
52
+ const {
53
+ type = DEFAULT_CONTENT
54
+ } = data;
55
+ if (!modules[type]) {
56
+ logger.warn("Invalid in-app message data: unknown type.", data);
57
+ return {};
58
+ }
59
+ if (!isValidInAppMessage(data, logger)) {
60
+ return {};
61
+ }
62
+ if (!meta) {
63
+ logger.warn("Invalid in-app message meta: undefined.", meta);
64
+ return {};
65
+ }
66
+ return {
67
+ render: () => {
68
+ return modules[type]({
69
+ ...data,
70
+ meta
71
+ });
72
+ },
73
+ setRenderAttempted: true,
74
+ includeInNotification: true
75
+ };
76
+ };
77
+ });
@@ -26,8 +26,11 @@ export default (({
26
26
  decisionsMeta: [item.getProposition().getNotification()],
27
27
  documentMayUnload: true
28
28
  }).then(() => {
29
- executeRedirect(content);
30
- // We've already sent the display notification, so don't return anything
29
+ return executeRedirect(content);
30
+ // Execute redirect will never resolve. If there are bottom of page events that are waiting
31
+ // for display notifications from this request, they will never run because this promise will
32
+ // not resolve. This is intentional because we don't want to run bottom of page events if
33
+ // there is a redirect.
31
34
  });
32
35
  };
33
36
 
@@ -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, true);
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
+ });
@@ -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
+ };