@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
@@ -4,7 +4,7 @@ exports.default = void 0;
4
4
  var _utils = require("../../utils");
5
5
  var _surfaceUtils = require("./utils/surfaceUtils");
6
6
  var _pageWideScope = require("../../constants/pageWideScope");
7
- var _schema = require("./constants/schema");
7
+ var _schema = require("../../constants/schema");
8
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
9
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
10
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -74,11 +74,11 @@ var _default = function _default(_ref) {
74
74
  scopes.push.apply(scopes, _toConsumableArray(personalization.decisionScopes));
75
75
  }
76
76
  var eventSurfaces = (0, _surfaceUtils.normalizeSurfaces)(personalization.surfaces, getPageLocation, logger);
77
- if (!this.isCacheInitialized() || personalization.requestPersonalization) {
77
+ if (this.shouldRequestDefaultPersonalization()) {
78
78
  addPageWideScope(scopes);
79
79
  addPageSurface(eventSurfaces, getPageLocation);
80
80
  }
81
- var schemas = [_schema.DEFAULT_CONTENT_ITEM, _schema.HTML_CONTENT_ITEM, _schema.JSON_CONTENT_ITEM, _schema.REDIRECT_ITEM];
81
+ var schemas = [_schema.DEFAULT_CONTENT_ITEM, _schema.HTML_CONTENT_ITEM, _schema.JSON_CONTENT_ITEM, _schema.REDIRECT_ITEM, _schema.RULESET_ITEM, _schema.MESSAGE_IN_APP, _schema.MESSAGE_FEED_ITEM];
82
82
  if ((0, _utils.includes)(scopes, _pageWideScope.default)) {
83
83
  schemas.push(_schema.DOM_ACTION);
84
84
  }
@@ -92,10 +92,13 @@ var _default = function _default(_ref) {
92
92
  return _isCacheInitialized;
93
93
  },
94
94
  shouldFetchData: function shouldFetchData() {
95
- return this.hasScopes() || this.hasSurfaces() || personalization.requestPersonalization || !this.isCacheInitialized() && personalization.requestPersonalization !== false;
95
+ return this.hasScopes() || this.hasSurfaces() || this.shouldRequestDefaultPersonalization();
96
96
  },
97
97
  shouldUseCachedData: function shouldUseCachedData() {
98
- return this.hasViewName() && this.isCacheInitialized();
98
+ return this.hasViewName() && !this.shouldFetchData();
99
+ },
100
+ shouldRequestDefaultPersonalization: function shouldRequestDefaultPersonalization() {
101
+ return personalization.defaultPersonalizationEnabled || !this.isCacheInitialized() && personalization.defaultPersonalizationEnabled !== false;
99
102
  }
100
103
  };
101
104
  };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _schema = require("../../constants/schema");
5
+ var _remapHeadOffers = require("./dom-actions/remapHeadOffers");
6
+ var _remapCustomCodeOffers = require("./dom-actions/remapCustomCodeOffers");
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /*
8
+ Copyright 2023 Adobe. All rights reserved.
9
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License. You may obtain a copy
11
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software distributed under
14
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ OF ANY KIND, either express or implied. See the License for the specific language
16
+ governing permissions and limitations under the License.
17
+ */
18
+ var _default = function _default() {
19
+ return _defineProperty({}, _schema.DOM_ACTION, [_remapHeadOffers.default, _remapCustomCodeOffers.default]);
20
+ };
21
+ exports.default = _default;
@@ -3,7 +3,7 @@
3
3
  exports.default = void 0;
4
4
  var _utils = require("../../utils");
5
5
  var _defer = require("../../utils/defer");
6
- var _schema = require("./constants/schema");
6
+ var _schema = require("../../constants/schema");
7
7
  var _scopeType = require("./constants/scopeType");
8
8
  /*
9
9
  Copyright 2020 Adobe. All rights reserved.
@@ -43,8 +43,15 @@ var _default = function _default(_ref) {
43
43
  var createCacheUpdate = function createCacheUpdate(viewName) {
44
44
  var updateCacheDeferred = (0, _defer.default)();
45
45
  cacheUpdateCreatedAtLeastOnce = true;
46
+
47
+ // Additional updates will merge the new view propositions with the old.
48
+ // i.e. if there are new "cart" view propositions they will overwrite the
49
+ // old "cart" view propositions, but if there are no new "cart" view
50
+ // propositions the old "cart" view propositions will remain.
46
51
  viewStoragePromise = viewStoragePromise.then(function (oldViewStorage) {
47
- return updateCacheDeferred.promise.catch(function () {
52
+ return updateCacheDeferred.promise.then(function (newViewStorage) {
53
+ return (0, _utils.assign)({}, oldViewStorage, newViewStorage);
54
+ }).catch(function () {
48
55
  return oldViewStorage;
49
56
  });
50
57
  });
@@ -14,7 +14,17 @@ governing permissions and limitations under the License.
14
14
  */
15
15
  var _default = function _default(window) {
16
16
  return function (url) {
17
- return window.location.replace(url);
17
+ var preserveHistory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
18
+ if (preserveHistory) {
19
+ window.location.href = url;
20
+ } else {
21
+ window.location.replace(url);
22
+ }
23
+ // Return a promise that never resolves because redirects never complete
24
+ // within the current page.
25
+ return new Promise(function () {
26
+ return undefined;
27
+ });
18
28
  };
19
29
  };
20
30
  exports.default = _default;
@@ -1,38 +1,41 @@
1
1
  "use strict";
2
2
 
3
3
  exports.mergeQuery = exports.mergeDecisionsMeta = void 0;
4
+ var _eventType = require("../../constants/eventType");
4
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
- /*
8
- Copyright 2019 Adobe. All rights reserved.
9
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- you may not use this file except in compliance with the License. You may obtain a copy
11
- of the License at http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- Unless required by applicable law or agreed to in writing, software distributed under
14
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- OF ANY KIND, either express or implied. See the License for the specific language
16
- governing permissions and limitations under the License.
17
- */
18
-
19
- var EVENT_TYPE_TRUE = 1;
20
-
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /*
8
+ Copyright 2019 Adobe. All rights reserved.
9
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License. You may obtain a copy
11
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software distributed under
14
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ OF ANY KIND, either express or implied. See the License for the specific language
16
+ governing permissions and limitations under the License.
17
+ */
21
18
  /* eslint-disable no-underscore-dangle */
22
- var mergeDecisionsMeta = function mergeDecisionsMeta(event, decisionsMeta, eventType) {
23
- var eventLabel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
19
+ var mergeDecisionsMeta = function mergeDecisionsMeta(event, decisionsMeta, propositionEventTypes, propositionAction) {
20
+ // Do not send a display notification with no decisions. Even empty view changes
21
+ // should include a proposition.
22
+ if (decisionsMeta.length === 0) {
23
+ return;
24
+ }
25
+ var propositionEventType = {};
26
+ propositionEventTypes.forEach(function (type) {
27
+ propositionEventType[type] = _eventType.EVENT_TYPE_TRUE;
28
+ });
24
29
  var xdm = {
25
30
  _experience: {
26
31
  decisioning: {
27
32
  propositions: decisionsMeta,
28
- propositionEventType: _defineProperty({}, eventType, EVENT_TYPE_TRUE)
33
+ propositionEventType: propositionEventType
29
34
  }
30
35
  }
31
36
  };
32
- if (eventLabel) {
33
- xdm._experience.decisioning.propositionAction = {
34
- label: eventLabel
35
- };
37
+ if (propositionAction) {
38
+ xdm._experience.decisioning.propositionAction = propositionAction;
36
39
  }
37
40
  event.mergeXdm(xdm);
38
41
  };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _contentType = require("../../../constants/contentType");
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /*
8
+ Copyright 2023 Adobe. All rights reserved.
9
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License. You may obtain a copy
11
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software distributed under
14
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ OF ANY KIND, either express or implied. See the License for the specific language
16
+ governing permissions and limitations under the License.
17
+ */
18
+ var DEFAULT_CONTENT = "defaultContent";
19
+ var expectedProps = ["content", "contentType"];
20
+ var expectedContentProps = ["mobileParameters", "webParameters", "html"];
21
+ var isValidInAppMessage = function isValidInAppMessage(data, logger) {
22
+ for (var i = 0; i < expectedProps.length; i += 1) {
23
+ var prop = expectedProps[i];
24
+ if (!Object.prototype.hasOwnProperty.call(data, prop)) {
25
+ logger.warn("Invalid in-app message data: missing property '" + prop + "'.", data);
26
+ return false;
27
+ }
28
+ }
29
+ var content = data.content,
30
+ contentType = data.contentType;
31
+ if (contentType === _contentType.APPLICATION_JSON) {
32
+ for (var _i = 0; _i < expectedContentProps.length; _i += 1) {
33
+ var _prop = expectedContentProps[_i];
34
+ if (!Object.prototype.hasOwnProperty.call(content, _prop)) {
35
+ logger.warn("Invalid in-app message data.content: missing property '" + _prop + "'.", data);
36
+ return false;
37
+ }
38
+ }
39
+ }
40
+ return true;
41
+ };
42
+ var _default = function _default(_ref) {
43
+ var modules = _ref.modules,
44
+ logger = _ref.logger;
45
+ return function (item) {
46
+ var data = item.getData();
47
+ var meta = _objectSpread({}, item.getProposition().getNotification());
48
+ if (!data) {
49
+ logger.warn("Invalid in-app message data: undefined.", data);
50
+ return {};
51
+ }
52
+ var _data$type = data.type,
53
+ type = _data$type === void 0 ? DEFAULT_CONTENT : _data$type;
54
+ if (!modules[type]) {
55
+ logger.warn("Invalid in-app message data: unknown type.", data);
56
+ return {};
57
+ }
58
+ if (!isValidInAppMessage(data, logger)) {
59
+ return {};
60
+ }
61
+ if (!meta) {
62
+ logger.warn("Invalid in-app message meta: undefined.", meta);
63
+ return {};
64
+ }
65
+ return {
66
+ render: function render() {
67
+ return modules[type](_objectSpread(_objectSpread({}, data), {}, {
68
+ meta: meta
69
+ }));
70
+ },
71
+ setRenderAttempted: true,
72
+ includeInNotification: true
73
+ };
74
+ };
75
+ };
76
+ exports.default = _default;
@@ -28,8 +28,11 @@ var _default = function _default(_ref) {
28
28
  decisionsMeta: [item.getProposition().getNotification()],
29
29
  documentMayUnload: true
30
30
  }).then(function () {
31
- executeRedirect(content);
32
- // We've already sent the display notification, so don't return anything
31
+ return executeRedirect(content);
32
+ // Execute redirect will never resolve. If there are bottom of page events that are waiting
33
+ // for display notifications from this request, they will never run because this promise will
34
+ // not resolve. This is intentional because we don't want to run bottom of page events if
35
+ // there is a redirect.
33
36
  });
34
37
  };
35
38
 
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+
3
+ exports.mobileOverlay = exports.displayHTMLContentInIframe = exports.default = exports.createIframeClickHandler = exports.createIframe = exports.buildStyleFromMobileParameters = void 0;
4
+ var _dom = require("../../dom-actions/dom");
5
+ var _utils = require("../utils");
6
+ var _contentType = require("../../../../constants/contentType");
7
+ var _utils2 = require("../../../../utils");
8
+ var _dom2 = require("../../../../utils/dom");
9
+ var _validation = require("../../../../utils/validation");
10
+ var _propositionEventType = require("../../../../constants/propositionEventType");
11
+ var _eventType = require("../../../../constants/eventType");
12
+ var _createRedirect = require("../../dom-actions/createRedirect");
13
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /*
14
+ Copyright 2023 Adobe. All rights reserved.
15
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ you may not use this file except in compliance with the License. You may obtain a copy
17
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+
19
+ Unless required by applicable law or agreed to in writing, software distributed under
20
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ OF ANY KIND, either express or implied. See the License for the specific language
22
+ governing permissions and limitations under the License.
23
+ */
24
+ var MESSAGING_CONTAINER_ID = "alloy-messaging-container";
25
+ var OVERLAY_CONTAINER_ID = "alloy-overlay-container";
26
+ var IFRAME_ID = "alloy-content-iframe";
27
+ var dismissMessage = function dismissMessage() {
28
+ return [MESSAGING_CONTAINER_ID, OVERLAY_CONTAINER_ID].forEach(_utils.removeElementById);
29
+ };
30
+ var createIframeClickHandler = function createIframeClickHandler(interact) {
31
+ var navigateToUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _createRedirect.default)(window);
32
+ return function (event) {
33
+ event.preventDefault();
34
+ event.stopImmediatePropagation();
35
+ var target = event.target;
36
+ var anchor = target.tagName.toLowerCase() === "a" ? target : target.closest("a");
37
+ if (!anchor) {
38
+ return;
39
+ }
40
+ var _parseAnchor = (0, _utils.parseAnchor)(anchor),
41
+ action = _parseAnchor.action,
42
+ interaction = _parseAnchor.interaction,
43
+ link = _parseAnchor.link,
44
+ label = _parseAnchor.label,
45
+ uuid = _parseAnchor.uuid;
46
+ interact(action, {
47
+ label: label,
48
+ id: interaction,
49
+ uuid: uuid,
50
+ link: link
51
+ });
52
+ if (action === "dismiss") {
53
+ dismissMessage();
54
+ }
55
+ if ((0, _utils2.isNonEmptyString)(link) && link.length > 0) {
56
+ navigateToUrl(link, true);
57
+ }
58
+ };
59
+ };
60
+ exports.createIframeClickHandler = createIframeClickHandler;
61
+ var createIframe = function createIframe(htmlContent, clickHandler) {
62
+ var parser = new DOMParser();
63
+ var htmlDocument = parser.parseFromString(htmlContent, _contentType.TEXT_HTML);
64
+ var scriptTag = htmlDocument.querySelector("script");
65
+ if (scriptTag) {
66
+ scriptTag.setAttribute("nonce", (0, _dom.getNonce)());
67
+ }
68
+ var element = (0, _dom2.createNode)("iframe", {
69
+ src: URL.createObjectURL(new Blob([htmlDocument.documentElement.outerHTML], {
70
+ type: "text/html"
71
+ })),
72
+ id: IFRAME_ID
73
+ });
74
+ element.addEventListener("load", function () {
75
+ var _ref = element.contentDocument || element.contentWindow.document,
76
+ addEventListener = _ref.addEventListener;
77
+ addEventListener("click", clickHandler);
78
+ });
79
+ return element;
80
+ };
81
+ exports.createIframe = createIframe;
82
+ var renderMessage = function renderMessage(iframe, webParameters, container, overlay) {
83
+ [{
84
+ id: OVERLAY_CONTAINER_ID,
85
+ element: overlay
86
+ }, {
87
+ id: MESSAGING_CONTAINER_ID,
88
+ element: container
89
+ }, {
90
+ id: IFRAME_ID,
91
+ element: iframe
92
+ }].forEach(function (_ref2) {
93
+ var id = _ref2.id,
94
+ element = _ref2.element;
95
+ var _webParameters$id = webParameters[id],
96
+ _webParameters$id$sty = _webParameters$id.style,
97
+ style = _webParameters$id$sty === void 0 ? {} : _webParameters$id$sty,
98
+ _webParameters$id$par = _webParameters$id.params,
99
+ params = _webParameters$id$par === void 0 ? {} : _webParameters$id$par;
100
+ (0, _utils2.assign)(element.style, style);
101
+ var _params$parentElement = params.parentElement,
102
+ parentElement = _params$parentElement === void 0 ? "body" : _params$parentElement,
103
+ _params$insertionMeth = params.insertionMethod,
104
+ insertionMethod = _params$insertionMeth === void 0 ? "appendChild" : _params$insertionMeth,
105
+ _params$enabled = params.enabled,
106
+ enabled = _params$enabled === void 0 ? true : _params$enabled;
107
+ var parent = document.querySelector(parentElement);
108
+ if (enabled && parent && typeof parent[insertionMethod] === "function") {
109
+ parent[insertionMethod](element);
110
+ }
111
+ });
112
+ };
113
+ var buildStyleFromMobileParameters = function buildStyleFromMobileParameters(mobileParameters) {
114
+ var verticalAlign = mobileParameters.verticalAlign,
115
+ width = mobileParameters.width,
116
+ horizontalAlign = mobileParameters.horizontalAlign,
117
+ backdropColor = mobileParameters.backdropColor,
118
+ height = mobileParameters.height,
119
+ cornerRadius = mobileParameters.cornerRadius,
120
+ horizontalInset = mobileParameters.horizontalInset,
121
+ verticalInset = mobileParameters.verticalInset,
122
+ _mobileParameters$uiT = mobileParameters.uiTakeover,
123
+ uiTakeover = _mobileParameters$uiT === void 0 ? false : _mobileParameters$uiT;
124
+ var style = {
125
+ width: width ? width + "%" : "100%",
126
+ backgroundColor: backdropColor || "rgba(0, 0, 0, 0.5)",
127
+ borderRadius: cornerRadius ? cornerRadius + "px" : "0px",
128
+ border: "none",
129
+ position: uiTakeover ? "fixed" : "relative",
130
+ overflow: "hidden"
131
+ };
132
+ if (horizontalAlign === "left") {
133
+ style.left = horizontalInset ? horizontalInset + "%" : "0";
134
+ } else if (horizontalAlign === "right") {
135
+ style.right = horizontalInset ? horizontalInset + "%" : "0";
136
+ } else if (horizontalAlign === "center") {
137
+ style.left = "50%";
138
+ style.transform = "translateX(-50%)";
139
+ }
140
+ if (verticalAlign === "top") {
141
+ style.top = verticalInset ? verticalInset + "%" : "0";
142
+ } else if (verticalAlign === "bottom") {
143
+ style.position = "fixed";
144
+ style.bottom = verticalInset ? verticalInset + "%" : "0";
145
+ } else if (verticalAlign === "center") {
146
+ style.top = "50%";
147
+ style.transform = (horizontalAlign === "center" ? style.transform + " " : "") + "translateY(-50%)";
148
+ style.display = "flex";
149
+ style.alignItems = "center";
150
+ style.justifyContent = "center";
151
+ }
152
+ if (height) {
153
+ style.height = height + "vh";
154
+ } else {
155
+ style.height = "100%";
156
+ }
157
+ return style;
158
+ };
159
+ exports.buildStyleFromMobileParameters = buildStyleFromMobileParameters;
160
+ var mobileOverlay = function mobileOverlay(mobileParameters) {
161
+ var backdropOpacity = mobileParameters.backdropOpacity,
162
+ backdropColor = mobileParameters.backdropColor;
163
+ var opacity = backdropOpacity || 0.5;
164
+ var color = backdropColor || "#FFFFFF";
165
+ var style = {
166
+ position: "fixed",
167
+ top: "0",
168
+ left: "0",
169
+ width: "100%",
170
+ height: "100%",
171
+ background: "transparent",
172
+ opacity: opacity,
173
+ backgroundColor: color
174
+ };
175
+ return style;
176
+ };
177
+ exports.mobileOverlay = mobileOverlay;
178
+ var REQUIRED_PARAMS = ["enabled", "parentElement", "insertionMethod"];
179
+ var isValidWebParameters = function isValidWebParameters(webParameters) {
180
+ if (!webParameters) {
181
+ return false;
182
+ }
183
+ var ids = Object.keys(webParameters);
184
+ if (!(0, _utils2.includes)(ids, MESSAGING_CONTAINER_ID)) {
185
+ return false;
186
+ }
187
+ if (!(0, _utils2.includes)(ids, OVERLAY_CONTAINER_ID)) {
188
+ return false;
189
+ }
190
+ var valuesArray = (0, _utils2.values)(webParameters);
191
+ for (var i = 0; i < valuesArray.length; i += 1) {
192
+ if (!(0, _validation.objectOf)(valuesArray[i], "style")) {
193
+ return false;
194
+ }
195
+ if (!(0, _validation.objectOf)(valuesArray[i], "params")) {
196
+ return false;
197
+ }
198
+ for (var j = 0; j < REQUIRED_PARAMS.length; j += 1) {
199
+ if (!(0, _validation.objectOf)(valuesArray[i].params, REQUIRED_PARAMS[j])) {
200
+ return false;
201
+ }
202
+ }
203
+ }
204
+ return true;
205
+ };
206
+ var generateWebParameters = function generateWebParameters(mobileParameters) {
207
+ var _ref3;
208
+ if (!mobileParameters) {
209
+ return undefined;
210
+ }
211
+ var _mobileParameters$uiT2 = mobileParameters.uiTakeover,
212
+ uiTakeover = _mobileParameters$uiT2 === void 0 ? false : _mobileParameters$uiT2;
213
+ return _ref3 = {}, _defineProperty(_ref3, IFRAME_ID, {
214
+ style: {
215
+ border: "none",
216
+ width: "100%",
217
+ height: "100%"
218
+ },
219
+ params: {
220
+ enabled: true,
221
+ parentElement: "#alloy-messaging-container",
222
+ insertionMethod: "appendChild"
223
+ }
224
+ }), _defineProperty(_ref3, MESSAGING_CONTAINER_ID, {
225
+ style: buildStyleFromMobileParameters(mobileParameters),
226
+ params: {
227
+ enabled: true,
228
+ parentElement: "body",
229
+ insertionMethod: "appendChild"
230
+ }
231
+ }), _defineProperty(_ref3, OVERLAY_CONTAINER_ID, {
232
+ style: mobileOverlay(mobileParameters),
233
+ params: {
234
+ enabled: uiTakeover === true,
235
+ parentElement: "body",
236
+ insertionMethod: "appendChild"
237
+ }
238
+ }), _ref3;
239
+ };
240
+ var displayHTMLContentInIframe = function displayHTMLContentInIframe() {
241
+ var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
242
+ var interact = arguments.length > 1 ? arguments[1] : undefined;
243
+ dismissMessage();
244
+ var content = settings.content,
245
+ contentType = settings.contentType,
246
+ mobileParameters = settings.mobileParameters;
247
+ var webParameters = settings.webParameters;
248
+ if (contentType !== _contentType.TEXT_HTML) {
249
+ return;
250
+ }
251
+ var container = (0, _dom2.createNode)("div", {
252
+ id: MESSAGING_CONTAINER_ID
253
+ });
254
+ var iframe = createIframe(content, createIframeClickHandler(interact));
255
+ var overlay = (0, _dom2.createNode)("div", {
256
+ id: OVERLAY_CONTAINER_ID
257
+ });
258
+ if (!isValidWebParameters(webParameters)) {
259
+ webParameters = generateWebParameters(mobileParameters);
260
+ }
261
+ if (!webParameters) {
262
+ return;
263
+ }
264
+ renderMessage(iframe, webParameters, container, overlay);
265
+ };
266
+ exports.displayHTMLContentInIframe = displayHTMLContentInIframe;
267
+ var _default = function _default(settings, collect) {
268
+ return new Promise(function (resolve) {
269
+ var meta = settings.meta;
270
+ displayHTMLContentInIframe(settings, function (action, propositionAction) {
271
+ var propositionEventTypes = {};
272
+ propositionEventTypes[_propositionEventType.PropositionEventType.INTERACT] = _eventType.EVENT_TYPE_TRUE;
273
+ if (Object.values(_propositionEventType.PropositionEventType).indexOf(action) !== -1) {
274
+ propositionEventTypes[action] = _eventType.EVENT_TYPE_TRUE;
275
+ }
276
+ collect({
277
+ decisionsMeta: [meta],
278
+ propositionAction: propositionAction,
279
+ eventType: _eventType.INTERACT,
280
+ propositionEventTypes: Object.keys(propositionEventTypes)
281
+ });
282
+ });
283
+ resolve({
284
+ meta: meta
285
+ });
286
+ });
287
+ };
288
+ exports.default = _default;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _displayIframeContent = require("./actions/displayIframeContent");
5
+ /*
6
+ Copyright 2023 Adobe. All rights reserved.
7
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License. You may obtain a copy
9
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software distributed under
12
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ OF ANY KIND, either express or implied. See the License for the specific language
14
+ governing permissions and limitations under the License.
15
+ */
16
+ var _default = function _default(collect) {
17
+ return {
18
+ defaultContent: function defaultContent(settings) {
19
+ return (0, _displayIframeContent.default)(settings, collect);
20
+ }
21
+ };
22
+ };
23
+ exports.default = _default;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ exports.removeElementById = exports.parseAnchor = void 0;
4
+ var _utils = require("../../../utils");
5
+ var _dom = require("../../../utils/dom");
6
+ /*
7
+ Copyright 2023 Adobe. All rights reserved.
8
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License. You may obtain a copy
10
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software distributed under
13
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ OF ANY KIND, either express or implied. See the License for the specific language
15
+ governing permissions and limitations under the License.
16
+ */
17
+
18
+ var removeElementById = function removeElementById(id) {
19
+ var element = (0, _dom.selectNodes)("#" + id, document);
20
+ if (element && element.length > 0) {
21
+ (0, _dom.removeNode)(element[0]);
22
+ }
23
+ };
24
+ exports.removeElementById = removeElementById;
25
+ var parseAnchor = function parseAnchor(anchor) {
26
+ var nothing = {};
27
+ if (!anchor || anchor.tagName.toLowerCase() !== "a") {
28
+ return nothing;
29
+ }
30
+ var href = anchor.href;
31
+ if (!href || !(0, _utils.startsWith)(href, "adbinapp://")) {
32
+ return nothing;
33
+ }
34
+ var hrefParts = href.split("?");
35
+ var action = hrefParts[0].split("://")[1];
36
+ var label = anchor.innerText;
37
+ var uuid = anchor.getAttribute("data-uuid") || "";
38
+ var interaction;
39
+ var link;
40
+ if ((0, _utils.isNonEmptyArray)(hrefParts)) {
41
+ var queryParams = _utils.queryString.parse(hrefParts[1]);
42
+ interaction = queryParams.interaction || "";
43
+ link = decodeURIComponent(queryParams.link || "");
44
+ }
45
+ return {
46
+ action: action,
47
+ interaction: interaction,
48
+ link: link,
49
+ label: label,
50
+ uuid: uuid
51
+ };
52
+ };
53
+ exports.parseAnchor = parseAnchor;