@adobe/alloy 2.29.0-beta.5 → 2.30.0-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 (177) hide show
  1. package/libEs5/components/ActivityCollector/utils/dom/findClickableElement.js +4 -0
  2. package/libEs5/components/Advertising/handlers/clickThroughHandler.js +2 -1
  3. package/libEs5/components/Advertising/handlers/onBeforeSendEventHandler.js +8 -3
  4. package/libEs5/components/Advertising/handlers/viewThroughHandler.js +2 -1
  5. package/libEs5/components/Advertising/identities/collectID5Id.js +1 -1
  6. package/libEs5/components/Advertising/identities/collectRampId.js +1 -1
  7. package/libEs5/components/Consent/createConsentRequestPayload.js +14 -3
  8. package/libEs5/components/Consent/types.js +18 -0
  9. package/libEs5/components/Personalization/dom-actions/action.js +7 -4
  10. package/libEs5/components/Personalization/dom-actions/initDomActionsModules.js +10 -10
  11. package/libEs5/components/PushNotifications/helpers/constants.js +19 -0
  12. package/libEs5/components/PushNotifications/helpers/getPushSubscriptionDetails.js +116 -0
  13. package/libEs5/components/PushNotifications/helpers/readFromIndexedDb.js +41 -0
  14. package/libEs5/components/PushNotifications/helpers/saveToIndexedDb.js +50 -0
  15. package/libEs5/components/PushNotifications/helpers/serviceWorkerNotificationClickListener.js +85 -0
  16. package/libEs5/components/PushNotifications/helpers/serviceWorkerPushListener.js +70 -0
  17. package/libEs5/components/PushNotifications/index.js +129 -0
  18. package/libEs5/components/PushNotifications/request/createSendPushSubscriptionPayload.js +62 -0
  19. package/libEs5/components/PushNotifications/request/createSendPushSubscriptionRequest.js +35 -0
  20. package/libEs5/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +93 -0
  21. package/libEs5/components/PushNotifications/request/makeSendServiceWorkerTrackingData.js +146 -0
  22. package/libEs5/components/PushNotifications/serviceWorker.js +91 -0
  23. package/libEs5/components/PushNotifications/types.js +95 -0
  24. package/libEs5/constants/libraryVersion.js +1 -1
  25. package/libEs5/core/componentCreators.js +8 -1
  26. package/libEs5/core/consent/createConsent.js +10 -0
  27. package/libEs5/core/consent/createConsentStateMachine.js +36 -0
  28. package/libEs5/core/consent/types.js +24 -0
  29. package/libEs5/core/edgeNetwork/injectSendEdgeNetworkRequest.js +20 -0
  30. package/libEs5/core/edgeNetwork/types.js +10 -0
  31. package/libEs5/core/identity/createIdentity.js +36 -0
  32. package/libEs5/core/identity/types.js +15 -0
  33. package/libEs5/core/injectCreateResponse.js +9 -7
  34. package/libEs5/core/types.js +101 -11
  35. package/libEs5/utils/bytes.js +12 -1
  36. package/libEs5/utils/createLoggingCookieJar.js +14 -1
  37. package/libEs5/utils/createMerger.js +5 -4
  38. package/libEs5/utils/index.js +19 -0
  39. package/libEs5/utils/indexedDb.js +73 -0
  40. package/libEs5/utils/injectStorage.js +19 -0
  41. package/libEs5/utils/request/createDataCollectionRequestPayload.js +16 -8
  42. package/libEs5/utils/request/createRequest.js +28 -1
  43. package/libEs5/utils/request/createRequestPayload.js +15 -2
  44. package/libEs5/utils/request/types.js +52 -0
  45. package/libEs5/utils/types.js +39 -0
  46. package/libEs6/components/ActivityCollector/utils/dom/findClickableElement.js +4 -0
  47. package/libEs6/components/Advertising/handlers/clickThroughHandler.js +2 -1
  48. package/libEs6/components/Advertising/handlers/onBeforeSendEventHandler.js +8 -3
  49. package/libEs6/components/Advertising/handlers/viewThroughHandler.js +2 -1
  50. package/libEs6/components/Advertising/identities/collectID5Id.js +1 -1
  51. package/libEs6/components/Advertising/identities/collectRampId.js +1 -1
  52. package/libEs6/components/Consent/createConsentRequestPayload.js +16 -3
  53. package/libEs6/components/Consent/types.js +15 -0
  54. package/libEs6/components/Personalization/dom-actions/action.js +7 -4
  55. package/libEs6/components/Personalization/dom-actions/initDomActionsModules.js +10 -10
  56. package/libEs6/components/PushNotifications/helpers/constants.js +16 -0
  57. package/libEs6/components/PushNotifications/helpers/getPushSubscriptionDetails.js +114 -0
  58. package/libEs6/components/PushNotifications/helpers/readFromIndexedDb.js +40 -0
  59. package/libEs6/components/PushNotifications/helpers/saveToIndexedDb.js +48 -0
  60. package/libEs6/components/PushNotifications/helpers/serviceWorkerNotificationClickListener.js +82 -0
  61. package/libEs6/components/PushNotifications/helpers/serviceWorkerPushListener.js +69 -0
  62. package/libEs6/components/PushNotifications/index.js +126 -0
  63. package/libEs6/components/PushNotifications/request/createSendPushSubscriptionPayload.js +61 -0
  64. package/libEs6/components/PushNotifications/request/createSendPushSubscriptionRequest.js +34 -0
  65. package/libEs6/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +89 -0
  66. package/libEs6/components/PushNotifications/request/makeSendServiceWorkerTrackingData.js +146 -0
  67. package/libEs6/components/PushNotifications/serviceWorker.js +90 -0
  68. package/libEs6/components/PushNotifications/types.js +92 -0
  69. package/libEs6/constants/libraryVersion.js +1 -1
  70. package/libEs6/core/componentCreators.js +2 -1
  71. package/libEs6/core/consent/createConsent.js +12 -0
  72. package/libEs6/core/consent/createConsentStateMachine.js +36 -0
  73. package/libEs6/core/consent/types.js +21 -0
  74. package/libEs6/core/edgeNetwork/injectSendEdgeNetworkRequest.js +20 -0
  75. package/libEs6/core/edgeNetwork/types.js +7 -0
  76. package/libEs6/core/identity/createIdentity.js +38 -0
  77. package/libEs6/core/identity/types.js +12 -0
  78. package/libEs6/core/injectCreateResponse.js +11 -7
  79. package/libEs6/core/types.js +101 -11
  80. package/libEs6/utils/bytes.js +12 -1
  81. package/libEs6/utils/createLoggingCookieJar.js +15 -1
  82. package/libEs6/utils/createMerger.js +5 -4
  83. package/libEs6/utils/index.js +1 -0
  84. package/libEs6/utils/indexedDb.js +67 -0
  85. package/libEs6/utils/injectStorage.js +20 -0
  86. package/libEs6/utils/request/createDataCollectionRequestPayload.js +19 -8
  87. package/libEs6/utils/request/createRequest.js +29 -1
  88. package/libEs6/utils/request/createRequestPayload.js +15 -2
  89. package/libEs6/utils/request/types.js +49 -0
  90. package/libEs6/utils/types.js +36 -0
  91. package/package.json +45 -52
  92. package/scripts/alloyBuilder.js +130 -4
  93. package/types/components/ActivityCollector/utils/dom/findClickableElement.d.ts.map +1 -1
  94. package/types/components/Advertising/handlers/onBeforeSendEventHandler.d.ts.map +1 -1
  95. package/types/components/Advertising/handlers/viewThroughHandler.d.ts.map +1 -1
  96. package/types/components/Consent/createConsentRequest.d.ts +1 -11
  97. package/types/components/Consent/createConsentRequest.d.ts.map +1 -1
  98. package/types/components/Consent/createConsentRequestPayload.d.ts +2 -9
  99. package/types/components/Consent/createConsentRequestPayload.d.ts.map +1 -1
  100. package/types/components/Consent/types.d.ts +28 -0
  101. package/types/components/Consent/types.d.ts.map +1 -0
  102. package/types/components/Identity/getIdentity/createIdentityRequest.d.ts +1 -11
  103. package/types/components/Identity/getIdentity/createIdentityRequest.d.ts.map +1 -1
  104. package/types/components/Identity/getIdentity/createIdentityRequestPayload.d.ts +1 -9
  105. package/types/components/Identity/getIdentity/createIdentityRequestPayload.d.ts.map +1 -1
  106. package/types/components/Personalization/dom-actions/action.d.ts +1 -1
  107. package/types/components/Personalization/dom-actions/action.d.ts.map +1 -1
  108. package/types/components/PushNotifications/helpers/constants.d.ts +5 -0
  109. package/types/components/PushNotifications/helpers/constants.d.ts.map +1 -0
  110. package/types/components/PushNotifications/helpers/getPushSubscriptionDetails.d.ts +30 -0
  111. package/types/components/PushNotifications/helpers/getPushSubscriptionDetails.d.ts.map +1 -0
  112. package/types/components/PushNotifications/helpers/readFromIndexedDb.d.ts +4 -0
  113. package/types/components/PushNotifications/helpers/readFromIndexedDb.d.ts.map +1 -0
  114. package/types/components/PushNotifications/helpers/saveToIndexedDb.d.ts +9 -0
  115. package/types/components/PushNotifications/helpers/saveToIndexedDb.d.ts.map +1 -0
  116. package/types/components/PushNotifications/helpers/serviceWorkerNotificationClickListener.d.ts +9 -0
  117. package/types/components/PushNotifications/helpers/serviceWorkerNotificationClickListener.d.ts.map +1 -0
  118. package/types/components/PushNotifications/helpers/serviceWorkerPushListener.d.ts +8 -0
  119. package/types/components/PushNotifications/helpers/serviceWorkerPushListener.d.ts.map +1 -0
  120. package/types/components/PushNotifications/index.d.ts +51 -0
  121. package/types/components/PushNotifications/index.d.ts.map +1 -0
  122. package/types/components/PushNotifications/request/createSendPushSubscriptionPayload.d.ts +10 -0
  123. package/types/components/PushNotifications/request/createSendPushSubscriptionPayload.d.ts.map +1 -0
  124. package/types/components/PushNotifications/request/createSendPushSubscriptionRequest.d.ts +7 -0
  125. package/types/components/PushNotifications/request/createSendPushSubscriptionRequest.d.ts.map +1 -0
  126. package/types/components/PushNotifications/request/makeSendPushSubscriptionRequest.d.ts +21 -0
  127. package/types/components/PushNotifications/request/makeSendPushSubscriptionRequest.d.ts.map +1 -0
  128. package/types/components/PushNotifications/request/makeSendServiceWorkerTrackingData.d.ts +11 -0
  129. package/types/components/PushNotifications/request/makeSendServiceWorkerTrackingData.d.ts.map +1 -0
  130. package/types/components/PushNotifications/serviceWorker.d.ts +2 -0
  131. package/types/components/PushNotifications/serviceWorker.d.ts.map +1 -0
  132. package/types/components/PushNotifications/types.d.ts +190 -0
  133. package/types/components/PushNotifications/types.d.ts.map +1 -0
  134. package/types/components/StreamingMedia/createMediaRequest.d.ts +1 -11
  135. package/types/components/StreamingMedia/createMediaRequest.d.ts.map +1 -1
  136. package/types/core/componentCreators.d.ts +1 -0
  137. package/types/core/consent/createConsent.d.ts +4 -10
  138. package/types/core/consent/createConsent.d.ts.map +1 -1
  139. package/types/core/consent/createConsentStateMachine.d.ts +4 -12
  140. package/types/core/consent/createConsentStateMachine.d.ts.map +1 -1
  141. package/types/core/consent/types.d.ts +42 -0
  142. package/types/core/consent/types.d.ts.map +1 -0
  143. package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts +15 -13
  144. package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts.map +1 -1
  145. package/types/core/edgeNetwork/types.d.ts +12 -0
  146. package/types/core/edgeNetwork/types.d.ts.map +1 -0
  147. package/types/core/identity/createIdentity.d.ts +9 -9
  148. package/types/core/identity/createIdentity.d.ts.map +1 -1
  149. package/types/core/identity/types.d.ts +23 -0
  150. package/types/core/identity/types.d.ts.map +1 -0
  151. package/types/core/injectCreateResponse.d.ts +3 -27
  152. package/types/core/injectCreateResponse.d.ts.map +1 -1
  153. package/types/core/types.d.ts +209 -22
  154. package/types/core/types.d.ts.map +1 -1
  155. package/types/utils/bytes.d.ts +3 -1
  156. package/types/utils/bytes.d.ts.map +1 -1
  157. package/types/utils/createLoggingCookieJar.d.ts +5 -3
  158. package/types/utils/createLoggingCookieJar.d.ts.map +1 -1
  159. package/types/utils/createMerger.d.ts +1 -1
  160. package/types/utils/createMerger.d.ts.map +1 -1
  161. package/types/utils/index.d.ts +1 -0
  162. package/types/utils/indexedDb.d.ts +4 -0
  163. package/types/utils/indexedDb.d.ts.map +1 -0
  164. package/types/utils/injectStorage.d.ts +2 -40
  165. package/types/utils/injectStorage.d.ts.map +1 -1
  166. package/types/utils/request/createDataCollectionRequest.d.ts +1 -11
  167. package/types/utils/request/createDataCollectionRequest.d.ts.map +1 -1
  168. package/types/utils/request/createDataCollectionRequestPayload.d.ts +2 -9
  169. package/types/utils/request/createDataCollectionRequestPayload.d.ts.map +1 -1
  170. package/types/utils/request/createRequest.d.ts +13 -11
  171. package/types/utils/request/createRequest.d.ts.map +1 -1
  172. package/types/utils/request/createRequestPayload.d.ts +7 -9
  173. package/types/utils/request/createRequestPayload.d.ts.map +1 -1
  174. package/types/utils/request/types.d.ts +91 -0
  175. package/types/utils/request/types.d.ts.map +1 -0
  176. package/types/utils/types.d.ts +91 -0
  177. package/types/utils/types.d.ts.map +1 -0
@@ -19,6 +19,10 @@ governing permissions and limitations under the License.
19
19
  var _default = element => {
20
20
  let node = element;
21
21
  while (node) {
22
+ // Stop looking when BODY is reached
23
+ if (node.nodeName && node.nodeName === "BODY") {
24
+ break;
25
+ }
22
26
  if ((0, _isSupportedAnchorElement.default)(node) || (0, _elementHasClickHandler.default)(node) || (0, _isInputSubmitElement.default)(node) || (0, _isButtonSubmitElement.default)(node)) {
23
27
  return node;
24
28
  }
@@ -64,7 +64,8 @@ async function handleClickThrough({
64
64
  }
65
65
  }
66
66
  },
67
- eventType: _index.AD_CONVERSION_CLICK_EVENT_TYPE
67
+ eventType: _index.AD_CONVERSION_CLICK_EVENT_TYPE,
68
+ timestamp: new Date().toISOString()
68
69
  };
69
70
  event.setUserXdm(xdm);
70
71
  cookieManager.setValue(_index.LAST_CONVERSION_TIME_KEY);
@@ -7,6 +7,7 @@ var _collectRampId = require("../identities/collectRampId.js");
7
7
  var _helpers = require("../utils/helpers.js");
8
8
  var _index = require("../constants/index.js");
9
9
  var _consentStatus = require("../../../constants/consentStatus.js");
10
+ var _browser = require("../../../constants/browser.js");
10
11
  /*
11
12
  Copyright 2023 Adobe. All rights reserved.
12
13
  Licensed under the Apache License, Version 2.0.
@@ -14,10 +15,10 @@ http://www.apache.org/licenses/LICENSE-2.0
14
15
  */
15
16
 
16
17
  const isAdvertisingDisabled = advertising => {
17
- return ![_consentStatus.AUTO, _consentStatus.WAIT].includes(advertising?.handleAdvertisingData);
18
+ return ![_consentStatus.AUTO, _consentStatus.WAIT].includes(advertising?.handleAdvertisingData?.toLowerCase());
18
19
  };
19
20
  const waitForAdvertisingId = advertising => {
20
- return advertising?.handleAdvertisingData === _consentStatus.WAIT;
21
+ return advertising?.handleAdvertisingData?.toLowerCase() === _consentStatus.WAIT;
21
22
  };
22
23
 
23
24
  /**
@@ -47,7 +48,11 @@ async function handleOnBeforeSendEvent({
47
48
  if (isAdvertisingDisabled(advertising) || isClickThru || (0, _helpers.isThrottled)(_index.SURFER_ID, cookieManager) && (0, _helpers.isThrottled)(_index.ID5_ID, cookieManager) && (0, _helpers.isThrottled)(_index.RAMP_ID, cookieManager)) return;
48
49
  try {
49
50
  const useShortTimeout = waitForAdvertisingId(advertising);
50
- const [surferIdResult, id5IdResult, rampIdResult] = await Promise.allSettled([(0, _collectSurferId.default)(cookieManager, getBrowser, useShortTimeout), (0, _collectID5Id.getID5Id)(logger, componentConfig.id5PartnerId, useShortTimeout, useShortTimeout), (0, _collectRampId.getRampId)(logger, componentConfig.rampIdJSPath, cookieManager, useShortTimeout, useShortTimeout)]);
51
+ let rampIdPromise = null;
52
+ if (!getBrowser || getBrowser() !== _browser.CHROME) {
53
+ rampIdPromise = (0, _collectRampId.getRampId)(logger, componentConfig.rampIdJSPath, cookieManager, useShortTimeout, useShortTimeout);
54
+ }
55
+ const [surferIdResult, id5IdResult, rampIdResult] = await Promise.allSettled([(0, _collectSurferId.default)(cookieManager, getBrowser, useShortTimeout), (0, _collectID5Id.getID5Id)(logger, componentConfig.id5PartnerId, useShortTimeout, useShortTimeout), rampIdPromise]);
51
56
  const availableIds = {};
52
57
  if (surferIdResult.status === "fulfilled" && surferIdResult.value && !(0, _helpers.isThrottled)(_index.SURFER_ID, cookieManager)) {
53
58
  availableIds.surferId = surferIdResult.value;
@@ -26,7 +26,8 @@ async function handleViewThrough({
26
26
  try {
27
27
  const event = (0, _helpers.appendAdvertisingIdQueryToEvent)(resolvedIds, eventManager.createEvent(), cookieManager, componentConfig, true);
28
28
  const xdm = {
29
- eventType: _index.AD_CONVERSION_VIEW_EVENT_TYPE
29
+ eventType: _index.AD_CONVERSION_VIEW_EVENT_TYPE,
30
+ timestamp: new Date().toISOString()
30
31
  };
31
32
  event.setUserXdm(xdm);
32
33
  const result = await adConversionHandler.trackAdConversion({
@@ -17,7 +17,7 @@ governing permissions and limitations under the License.
17
17
 
18
18
  let id5Id = "";
19
19
  let inProgressId5Promise = null;
20
- const SHORT_TIMEOUT_MS = 5000;
20
+ const SHORT_TIMEOUT_MS = 2000;
21
21
  const DEFAULT_TIMEOUT_MS = 30000;
22
22
  const initiateID5Call = (partnerId, useShortTimeout, logger) => {
23
23
  partnerId = Math.floor(Number(partnerId));
@@ -20,7 +20,7 @@ const RETRY_CONFIG = {
20
20
  MAX_TIME_MS: 30000,
21
21
  DELAY_BASE_MS: 500,
22
22
  MAX_DELAY_MS: 5000,
23
- SHORT_TIMEOUT_MS: 5000
23
+ SHORT_TIMEOUT_MS: 2000
24
24
  };
25
25
  const state = {
26
26
  rampIdEnv: undefined,
@@ -13,9 +13,15 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
13
13
  OF ANY KIND, either express or implied. See the License for the specific language
14
14
  governing permissions and limitations under the License.
15
15
  */
16
+ /** @import { ConsentRequestPayload } from './types.js' */
17
+ /**
18
+ * @function
19
+ *
20
+ * @returns {ConsentRequestPayload}
21
+ */
16
22
  var _default = () => {
17
23
  const content = {};
18
- const payload = (0, _index.createRequestPayload)({
24
+ const requestPayload = (0, _index.createRequestPayload)({
19
25
  content,
20
26
  addIdentity: (namespaceCode, identity) => {
21
27
  content.identityMap = content.identityMap || {};
@@ -26,8 +32,13 @@ var _default = () => {
26
32
  return (content.identityMap && content.identityMap[namespaceCode]) !== undefined;
27
33
  }
28
34
  });
29
- payload.setConsent = consent => {
30
- content.consent = consent;
35
+
36
+ /** @type {ConsentRequestPayload} */
37
+ const payload = {
38
+ ...requestPayload,
39
+ setConsent: consent => {
40
+ content.consent = consent;
41
+ }
31
42
  };
32
43
  return payload;
33
44
  };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ exports.Types = void 0;
4
+ /**
5
+ * Request payload object with methods for merging different types of data.
6
+ *
7
+ * @typedef {Object} ConsentRequestPayload
8
+ * @property {Function} mergeMeta
9
+ * @property {Function} mergeState
10
+ * @property {Function} mergeQuery
11
+ * @property {Function} mergeConfigOverride
12
+ * @property {Function} addIdentity
13
+ * @property {Function} hasIdentity
14
+ * @property {Function} toJSON
15
+ * @property {Function} setConsent
16
+ */
17
+
18
+ const Types = exports.Types = {};
@@ -108,9 +108,10 @@ const renderContent = ({
108
108
  content,
109
109
  decorateProposition,
110
110
  renderFunc,
111
- renderStatusHandler
111
+ renderStatusHandler,
112
+ alwaysRender
112
113
  }) => {
113
- const executions = containers.filter(renderStatusHandler.shouldRender).map(async container => {
114
+ const executions = containers.filter(element => alwaysRender || renderStatusHandler.shouldRender(element)).map(async container => {
114
115
  await renderFunc(container, content, decorateProposition);
115
116
  renderStatusHandler.markAsRendered(container);
116
117
  });
@@ -121,8 +122,9 @@ const renderContent = ({
121
122
  * Creates an action function that renders content into a container element.
122
123
  *
123
124
  * @param {Function} renderFunc - The function that performs the rendering.
125
+ * @param {boolean} alwaysRender - Whether to always render the content, even if it has already been rendered.
124
126
  */
125
- const createAction = renderFunc => {
127
+ const createAction = (renderFunc, alwaysRender = false) => {
126
128
  /**
127
129
  * Renders content into a container element.
128
130
  *
@@ -144,7 +146,8 @@ const createAction = renderFunc => {
144
146
  content,
145
147
  decorateProposition,
146
148
  renderFunc,
147
- renderStatusHandler
149
+ renderStatusHandler,
150
+ alwaysRender
148
151
  });
149
152
  } finally {
150
153
  (0, _index2.showElements)(prehidingSelector);
@@ -48,22 +48,22 @@ const DOM_ACTION_CLICK = exports.DOM_ACTION_CLICK = "click";
48
48
  const DOM_ACTION_COLLECT_INTERACTIONS = exports.DOM_ACTION_COLLECT_INTERACTIONS = "collectInteractions";
49
49
  var _default = () => {
50
50
  return {
51
- [DOM_ACTION_SET_HTML]: (0, _action.createAction)(_setHtml.default),
51
+ [DOM_ACTION_SET_HTML]: (0, _action.createAction)(_setHtml.default, true),
52
52
  [DOM_ACTION_CUSTOM_CODE]: (0, _action.createAction)(_prependHtml.default),
53
- [DOM_ACTION_SET_TEXT]: (0, _action.createAction)(_setText.default),
54
- [DOM_ACTION_SET_ATTRIBUTE]: (0, _action.createAction)(_setAttributes.default),
55
- [DOM_ACTION_SET_IMAGE_SOURCE]: (0, _action.createAction)(_swapImage.default),
56
- [DOM_ACTION_SET_STYLE]: (0, _action.createAction)(_setStyles.default),
57
- [DOM_ACTION_MOVE]: (0, _action.createAction)(_move.default),
58
- [DOM_ACTION_RESIZE]: (0, _action.createAction)(_resize.default),
53
+ [DOM_ACTION_SET_TEXT]: (0, _action.createAction)(_setText.default, true),
54
+ [DOM_ACTION_SET_ATTRIBUTE]: (0, _action.createAction)(_setAttributes.default, true),
55
+ [DOM_ACTION_SET_IMAGE_SOURCE]: (0, _action.createAction)(_swapImage.default, true),
56
+ [DOM_ACTION_SET_STYLE]: (0, _action.createAction)(_setStyles.default, true),
57
+ [DOM_ACTION_MOVE]: (0, _action.createAction)(_move.default, true),
58
+ [DOM_ACTION_RESIZE]: (0, _action.createAction)(_resize.default, true),
59
59
  [DOM_ACTION_REARRANGE]: (0, _action.createAction)(_rearrangeChildren.default),
60
- [DOM_ACTION_REMOVE]: (0, _action.createAction)(_index.removeNode),
60
+ [DOM_ACTION_REMOVE]: (0, _action.createAction)(_index.removeNode, true),
61
61
  [DOM_ACTION_INSERT_AFTER]: (0, _action.createAction)(_insertHtmlAfter.default),
62
62
  [DOM_ACTION_INSERT_BEFORE]: (0, _action.createAction)(_insertHtmlBefore.default),
63
- [DOM_ACTION_REPLACE_HTML]: (0, _action.createAction)(_replaceHtml.default),
63
+ [DOM_ACTION_REPLACE_HTML]: (0, _action.createAction)(_replaceHtml.default, true),
64
64
  [DOM_ACTION_PREPEND_HTML]: (0, _action.createAction)(_prependHtml.default),
65
65
  [DOM_ACTION_APPEND_HTML]: (0, _action.createAction)(_appendHtml.default),
66
- [DOM_ACTION_COLLECT_INTERACTIONS]: (0, _action.createAction)(_collectInteractions.default)
66
+ [DOM_ACTION_COLLECT_INTERACTIONS]: (0, _action.createAction)(_collectInteractions.default, true)
67
67
  };
68
68
  };
69
69
  exports.default = _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ exports.STORE_NAME = exports.INDEX_KEY = exports.DB_VERSION = exports.DB_NAME = void 0;
4
+ /*
5
+ Copyright 2025 Adobe. All rights reserved.
6
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License. You may obtain a copy
8
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software distributed under
11
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ OF ANY KIND, either express or implied. See the License for the specific language
13
+ governing permissions and limitations under the License.
14
+ */
15
+
16
+ const DB_NAME = exports.DB_NAME = "alloyPushNotifications";
17
+ const DB_VERSION = exports.DB_VERSION = 1;
18
+ const STORE_NAME = exports.STORE_NAME = "config";
19
+ const INDEX_KEY = exports.INDEX_KEY = "alloyConfig";
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _index = require("../../../utils/index.js");
5
+ /*
6
+ Copyright 2025 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
+
17
+ /** @import { PushSubscription } from '../types.js' */
18
+
19
+ /**
20
+ * Gets push subscription details for the current browser.
21
+ *
22
+ * @async
23
+ * @function
24
+ *
25
+ * @param {object} options
26
+ * @param {string} options.vapidPublicKey - The VAPID public key in base64 format used for push notification authentication.
27
+ * @param {Window} options.window
28
+ *
29
+ * @returns {Promise<PushSubscription>} A promise that resolves to an object containing the push subscription details.
30
+
31
+ * @throws {Error} Throws an error if service workers are not supported in the browser.
32
+ * @throws {Error} Throws an error if user didn't approve push notifications for the domain.
33
+ * @throws {Error} Throws an error if push notifications are not supported in the browser.
34
+ * @throws {Error} Throws an error if no VAPID public key was provided.
35
+ *
36
+ * @example
37
+ * // Get subscription details with VAPID key
38
+ * const vapidKey = "BEl62iUYgUivxIkv69yViEuiBIa40HI5hmjHbKPlXO...";
39
+ * const subscription = await getPushSubscriptionDetails(vapidKey);
40
+ * console.log(subscription.endpoint); // "https://fcm.googleapis.com/fcm/send/..."
41
+ */
42
+ const getPushSubscriptionDetails = async ({
43
+ vapidPublicKey,
44
+ window
45
+ }) => {
46
+ if (!("serviceWorker" in window.navigator)) {
47
+ throw new Error("Service workers are not supported in this browser.");
48
+ }
49
+ if (!("PushManager" in window) || !("Notification" in window)) {
50
+ throw new Error("Push notifications are not supported in this browser.");
51
+ }
52
+
53
+ /** @type {object} */
54
+ const notification = window.Notification;
55
+ if (notification.permission !== "granted") {
56
+ throw new Error("The user has not given permission to send push notifications.");
57
+ }
58
+ const serviceWorkerRegistration =
59
+ // eslint-disable-next-line compat/compat
60
+ await window.navigator.serviceWorker.getRegistration();
61
+ if (!serviceWorkerRegistration) {
62
+ throw new Error("No service worker registration was found.");
63
+ }
64
+
65
+ // Even `applicationServerKey` is not required in the spec, some browsers like Chrome are requiring it.
66
+ if (!vapidPublicKey) {
67
+ throw new Error("No VAPID public key was provided.");
68
+ }
69
+ const subscriptionOptions = {
70
+ userVisibleOnly: true,
71
+ applicationServerKey: (0, _index.base64ToBytes)(vapidPublicKey)
72
+ };
73
+
74
+ // Push subscription handling strategy:
75
+ //
76
+ // 1. We always call subscribe() to either get the current subscription or create a new one.
77
+ // - If called with the same VAPID key as an existing subscription, it returns that subscription
78
+ // - If called with a different VAPID key when a subscription exists, it throws an error
79
+ //
80
+ // 2. Error handling approach:
81
+ // - Browser error messages vary and don't clearly indicate VAPID key conflicts
82
+ // - When subscribe() fails, we assume it's likely due to a VAPID key mismatch
83
+ // - We attempt recovery by unsubscribing the existing subscription and retrying
84
+ // - If the retry also fails, we re-throw the original error
85
+ //
86
+ // This strategy ensures we can handle both new subscriptions and VAPID key changes
87
+ // while gracefully falling back to error reporting when recovery isn't possible.
88
+ try {
89
+ const subscription = await serviceWorkerRegistration.pushManager.subscribe(subscriptionOptions);
90
+ return {
91
+ endpoint: subscription.endpoint,
92
+ keys: {
93
+ p256dh: (0, _index.bytesToBase64)(new Uint8Array(subscription.getKey("p256dh")), {
94
+ urlSafe: true
95
+ }),
96
+ auth: (0, _index.bytesToBase64)(new Uint8Array(subscription.getKey("auth")), {
97
+ urlSafe: true
98
+ })
99
+ }
100
+ };
101
+ } catch (e) {
102
+ const subscription = await serviceWorkerRegistration.pushManager.getSubscription();
103
+ if (!subscription) {
104
+ throw e;
105
+ }
106
+ const unsubscribeResult = await subscription.unsubscribe();
107
+ if (!unsubscribeResult) {
108
+ throw e;
109
+ }
110
+ return getPushSubscriptionDetails({
111
+ vapidPublicKey,
112
+ window
113
+ });
114
+ }
115
+ };
116
+ var _default = exports.default = getPushSubscriptionDetails;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _indexedDb = require("../../../utils/indexedDb.js");
5
+ var _constants = require("./constants.js");
6
+ /*
7
+ Copyright 2025 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
+ /** @import { ServiceWorkerLogger } from '../types.js' */
18
+ /**
19
+ * @param {ServiceWorkerLogger} logger
20
+ * @returns {Promise<Object|undefined>}
21
+ * @throws {Error}
22
+ */
23
+ var _default = async logger => {
24
+ try {
25
+ const db = await (0, _indexedDb.openIndexedDb)(_constants.DB_NAME, _constants.DB_VERSION, (/** @type {IDBDatabase} */db) => {
26
+ if (!db.objectStoreNames.contains(_constants.STORE_NAME)) {
27
+ db.createObjectStore(_constants.STORE_NAME, {
28
+ keyPath: "id"
29
+ });
30
+ }
31
+ });
32
+ const existingConfigData = await (0, _indexedDb.getFromIndexedDbStore)(db, _constants.STORE_NAME, _constants.INDEX_KEY);
33
+ db.close();
34
+ return existingConfigData;
35
+ } catch (error) {
36
+ logger.error("Failed to read data from IndexedDB", {
37
+ error
38
+ });
39
+ }
40
+ };
41
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ exports.default = saveToIndexedDB;
4
+ var _index = require("../../../utils/index.js");
5
+ var _constants = require("./constants.js");
6
+ /*
7
+ Copyright 2025 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
+ /** @import { Logger } from '../../../core/types.js' */
19
+
20
+ /**
21
+ * @param {Object} data
22
+ * @param {Logger} logger
23
+ *
24
+ * @returns {Promise<void>}
25
+ */
26
+ async function saveToIndexedDB(data, logger) {
27
+ try {
28
+ const db = await (0, _index.openIndexedDb)(_constants.DB_NAME, _constants.DB_VERSION, (/** @type {IDBDatabase} */db) => {
29
+ if (!db.objectStoreNames.contains(_constants.STORE_NAME)) {
30
+ db.createObjectStore(_constants.STORE_NAME, {
31
+ keyPath: "id"
32
+ });
33
+ }
34
+ });
35
+ const existingConfigData = await (0, _index.getFromIndexedDbStore)(db, _constants.STORE_NAME, _constants.INDEX_KEY);
36
+ const updatedConfigData = {
37
+ ...(existingConfigData || {}),
38
+ ...data,
39
+ id: _constants.INDEX_KEY,
40
+ timestamp: Date.now()
41
+ };
42
+ await (0, _index.putToIndexedDbStore)(db, _constants.STORE_NAME, updatedConfigData);
43
+ db.close();
44
+ logger.info("Successfully saved web SDK config to IndexedDB", updatedConfigData);
45
+ } catch (error) {
46
+ logger.error("Failed to save config to IndexedDB", {
47
+ error
48
+ });
49
+ }
50
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _makeSendServiceWorkerTrackingData = require("../request/makeSendServiceWorkerTrackingData.js");
5
+ /*
6
+ Copyright 2025 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
+
17
+ // @ts-check
18
+ /// <reference lib="webworker" />
19
+
20
+ /** @import { ServiceWorkerLogger } from '../types.js' */
21
+
22
+ /**
23
+ * @param {string} type
24
+ * @returns {boolean}
25
+ */
26
+ const canHandleUrl = type => ["DEEPLINK", "WEBURL"].includes(type);
27
+
28
+ /**
29
+ * @function
30
+ *
31
+ * @param {Object} options
32
+ * @param {ServiceWorkerGlobalScope} options.sw
33
+ * @param {NotificationEvent} options.event
34
+ * @param {(url: string, options: object) => Promise<Response>} options.fetch
35
+ * @param {ServiceWorkerLogger} options.logger
36
+ */
37
+ var _default = ({
38
+ event,
39
+ sw,
40
+ logger,
41
+ fetch
42
+ }) => {
43
+ event.notification.close();
44
+ const data = event.notification.data;
45
+ let targetUrl = null;
46
+ let actionLabel = null;
47
+ if (event.action) {
48
+ const actionIndex = parseInt(event.action.replace("action_", ""), 10);
49
+ if (data?.actions?.buttons[actionIndex]) {
50
+ const button = data.actions.buttons[actionIndex];
51
+ actionLabel = button.label;
52
+ if (canHandleUrl(button.type) && button.uri) {
53
+ targetUrl = button.uri;
54
+ }
55
+ }
56
+ } else if (canHandleUrl(data?.interaction?.type) && data?.interaction?.uri) {
57
+ targetUrl = data.interaction.uri;
58
+ }
59
+ (0, _makeSendServiceWorkerTrackingData.default)({
60
+ // eslint-disable-next-line no-underscore-dangle
61
+ xdm: data._xdm.mixins,
62
+ actionLabel,
63
+ applicationLaunches: 1
64
+ }, {
65
+ logger,
66
+ fetch
67
+ }).catch(error => {
68
+ logger.error("Failed to send tracking call:", error);
69
+ });
70
+ if (targetUrl) {
71
+ event.waitUntil(sw.clients.matchAll({
72
+ type: "window"
73
+ }).then(clientList => {
74
+ for (const client of clientList) {
75
+ if (client.url === targetUrl && "focus" in client) {
76
+ return client.focus();
77
+ }
78
+ }
79
+ if (sw.clients.openWindow) {
80
+ return sw.clients.openWindow(targetUrl);
81
+ }
82
+ }));
83
+ }
84
+ };
85
+ exports.default = _default;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ /*
5
+ Copyright 2025 Adobe. All rights reserved.
6
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License. You may obtain a copy
8
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software distributed under
11
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ OF ANY KIND, either express or implied. See the License for the specific language
13
+ governing permissions and limitations under the License.
14
+ */
15
+ // @ts-check
16
+ /// <reference lib="webworker" />
17
+ /** @import { PushNotificationData } from '../types.js' */
18
+ /** @import { ServiceWorkerLogger } from '../types.js' */
19
+ /**
20
+ * @async
21
+ * @function
22
+ *
23
+ * @param {Object} options
24
+ * @param {ServiceWorkerGlobalScope} options.sw
25
+ * @param {PushEvent} options.event
26
+ * @param {ServiceWorkerLogger} options.logger
27
+ * @returns {Promise<void>}
28
+ */
29
+ var _default = async ({
30
+ sw,
31
+ event,
32
+ logger
33
+ }) => {
34
+ if (!event.data) {
35
+ return;
36
+ }
37
+
38
+ /** @type {PushNotificationData} */
39
+ let notificationData;
40
+ try {
41
+ notificationData = event.data.json();
42
+ } catch (error) {
43
+ logger.error("Error decoding notification JSON data:", error);
44
+ return;
45
+ }
46
+ const webData = notificationData.web;
47
+ if (!webData?.title) {
48
+ return;
49
+ }
50
+ const notificationOptions = {
51
+ body: webData.body,
52
+ icon: webData.media,
53
+ image: webData.media,
54
+ data: webData,
55
+ actions: []
56
+ };
57
+ Object.keys(notificationOptions).forEach(k => {
58
+ if (notificationOptions[k] == null) {
59
+ delete notificationOptions[k];
60
+ }
61
+ });
62
+ if (webData.actions && webData.actions.buttons) {
63
+ notificationOptions.actions = webData.actions.buttons.map((button, index) => ({
64
+ action: "action_" + index,
65
+ title: button.label
66
+ }));
67
+ }
68
+ return sw.registration.showNotification(webData.title, notificationOptions);
69
+ };
70
+ exports.default = _default;