@adobe/alloy 2.29.0-beta.4 → 2.29.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 (141) 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/getPushSubscriptionDetails.js +116 -0
  12. package/libEs5/components/PushNotifications/index.js +96 -0
  13. package/libEs5/components/PushNotifications/request/createSendPushSubscriptionPayload.js +62 -0
  14. package/libEs5/components/PushNotifications/request/createSendPushSubscriptionRequest.js +35 -0
  15. package/libEs5/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +88 -0
  16. package/libEs5/components/PushNotifications/types.js +14 -0
  17. package/libEs5/constants/libraryVersion.js +1 -1
  18. package/libEs5/core/componentCreators.js +8 -1
  19. package/libEs5/core/consent/createConsent.js +10 -0
  20. package/libEs5/core/consent/createConsentStateMachine.js +36 -0
  21. package/libEs5/core/consent/types.js +24 -0
  22. package/libEs5/core/edgeNetwork/injectSendEdgeNetworkRequest.js +20 -0
  23. package/libEs5/core/edgeNetwork/types.js +10 -0
  24. package/libEs5/core/identity/createIdentity.js +36 -0
  25. package/libEs5/core/identity/types.js +15 -0
  26. package/libEs5/core/injectCreateResponse.js +9 -7
  27. package/libEs5/core/types.js +101 -11
  28. package/libEs5/utils/bytes.js +12 -1
  29. package/libEs5/utils/createLoggingCookieJar.js +14 -1
  30. package/libEs5/utils/createMerger.js +5 -4
  31. package/libEs5/utils/injectStorage.js +19 -0
  32. package/libEs5/utils/request/createDataCollectionRequestPayload.js +16 -8
  33. package/libEs5/utils/request/createRequest.js +28 -1
  34. package/libEs5/utils/request/createRequestPayload.js +68 -4
  35. package/libEs5/utils/request/types.js +52 -0
  36. package/libEs5/utils/types.js +39 -0
  37. package/libEs6/components/ActivityCollector/utils/dom/findClickableElement.js +4 -0
  38. package/libEs6/components/Advertising/handlers/clickThroughHandler.js +2 -1
  39. package/libEs6/components/Advertising/handlers/onBeforeSendEventHandler.js +8 -3
  40. package/libEs6/components/Advertising/handlers/viewThroughHandler.js +2 -1
  41. package/libEs6/components/Advertising/identities/collectID5Id.js +1 -1
  42. package/libEs6/components/Advertising/identities/collectRampId.js +1 -1
  43. package/libEs6/components/Consent/createConsentRequestPayload.js +16 -3
  44. package/libEs6/components/Consent/types.js +15 -0
  45. package/libEs6/components/Personalization/dom-actions/action.js +7 -4
  46. package/libEs6/components/Personalization/dom-actions/initDomActionsModules.js +10 -10
  47. package/libEs6/components/PushNotifications/helpers/getPushSubscriptionDetails.js +114 -0
  48. package/libEs6/components/PushNotifications/index.js +93 -0
  49. package/libEs6/components/PushNotifications/request/createSendPushSubscriptionPayload.js +61 -0
  50. package/libEs6/components/PushNotifications/request/createSendPushSubscriptionRequest.js +34 -0
  51. package/libEs6/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +84 -0
  52. package/libEs6/components/PushNotifications/types.js +11 -0
  53. package/libEs6/constants/libraryVersion.js +1 -1
  54. package/libEs6/core/componentCreators.js +2 -1
  55. package/libEs6/core/consent/createConsent.js +12 -0
  56. package/libEs6/core/consent/createConsentStateMachine.js +36 -0
  57. package/libEs6/core/consent/types.js +21 -0
  58. package/libEs6/core/edgeNetwork/injectSendEdgeNetworkRequest.js +20 -0
  59. package/libEs6/core/edgeNetwork/types.js +7 -0
  60. package/libEs6/core/identity/createIdentity.js +38 -0
  61. package/libEs6/core/identity/types.js +12 -0
  62. package/libEs6/core/injectCreateResponse.js +11 -7
  63. package/libEs6/core/types.js +101 -11
  64. package/libEs6/utils/bytes.js +12 -1
  65. package/libEs6/utils/createLoggingCookieJar.js +15 -1
  66. package/libEs6/utils/createMerger.js +5 -4
  67. package/libEs6/utils/injectStorage.js +20 -0
  68. package/libEs6/utils/request/createDataCollectionRequestPayload.js +19 -8
  69. package/libEs6/utils/request/createRequest.js +29 -1
  70. package/libEs6/utils/request/createRequestPayload.js +67 -4
  71. package/libEs6/utils/request/types.js +49 -0
  72. package/libEs6/utils/types.js +36 -0
  73. package/package.json +30 -30
  74. package/types/components/ActivityCollector/utils/dom/findClickableElement.d.ts.map +1 -1
  75. package/types/components/Advertising/handlers/onBeforeSendEventHandler.d.ts.map +1 -1
  76. package/types/components/Advertising/handlers/viewThroughHandler.d.ts.map +1 -1
  77. package/types/components/Consent/createConsentRequest.d.ts +1 -11
  78. package/types/components/Consent/createConsentRequest.d.ts.map +1 -1
  79. package/types/components/Consent/createConsentRequestPayload.d.ts +2 -9
  80. package/types/components/Consent/createConsentRequestPayload.d.ts.map +1 -1
  81. package/types/components/Consent/types.d.ts +28 -0
  82. package/types/components/Consent/types.d.ts.map +1 -0
  83. package/types/components/Identity/getIdentity/createIdentityRequest.d.ts +1 -11
  84. package/types/components/Identity/getIdentity/createIdentityRequest.d.ts.map +1 -1
  85. package/types/components/Identity/getIdentity/createIdentityRequestPayload.d.ts +1 -9
  86. package/types/components/Identity/getIdentity/createIdentityRequestPayload.d.ts.map +1 -1
  87. package/types/components/Personalization/dom-actions/action.d.ts +1 -1
  88. package/types/components/Personalization/dom-actions/action.d.ts.map +1 -1
  89. package/types/components/PushNotifications/helpers/getPushSubscriptionDetails.d.ts +30 -0
  90. package/types/components/PushNotifications/helpers/getPushSubscriptionDetails.d.ts.map +1 -0
  91. package/types/components/PushNotifications/index.d.ts +43 -0
  92. package/types/components/PushNotifications/index.d.ts.map +1 -0
  93. package/types/components/PushNotifications/request/createSendPushSubscriptionPayload.d.ts +10 -0
  94. package/types/components/PushNotifications/request/createSendPushSubscriptionPayload.d.ts.map +1 -0
  95. package/types/components/PushNotifications/request/createSendPushSubscriptionRequest.d.ts +7 -0
  96. package/types/components/PushNotifications/request/createSendPushSubscriptionRequest.d.ts.map +1 -0
  97. package/types/components/PushNotifications/request/makeSendPushSubscriptionRequest.d.ts +20 -0
  98. package/types/components/PushNotifications/request/makeSendPushSubscriptionRequest.d.ts.map +1 -0
  99. package/types/components/PushNotifications/types.d.ts +23 -0
  100. package/types/components/PushNotifications/types.d.ts.map +1 -0
  101. package/types/components/StreamingMedia/createMediaRequest.d.ts +1 -11
  102. package/types/components/StreamingMedia/createMediaRequest.d.ts.map +1 -1
  103. package/types/core/componentCreators.d.ts +1 -0
  104. package/types/core/consent/createConsent.d.ts +4 -10
  105. package/types/core/consent/createConsent.d.ts.map +1 -1
  106. package/types/core/consent/createConsentStateMachine.d.ts +4 -12
  107. package/types/core/consent/createConsentStateMachine.d.ts.map +1 -1
  108. package/types/core/consent/types.d.ts +42 -0
  109. package/types/core/consent/types.d.ts.map +1 -0
  110. package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts +15 -13
  111. package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts.map +1 -1
  112. package/types/core/edgeNetwork/types.d.ts +12 -0
  113. package/types/core/edgeNetwork/types.d.ts.map +1 -0
  114. package/types/core/identity/createIdentity.d.ts +9 -9
  115. package/types/core/identity/createIdentity.d.ts.map +1 -1
  116. package/types/core/identity/types.d.ts +23 -0
  117. package/types/core/identity/types.d.ts.map +1 -0
  118. package/types/core/injectCreateResponse.d.ts +3 -27
  119. package/types/core/injectCreateResponse.d.ts.map +1 -1
  120. package/types/core/types.d.ts +209 -22
  121. package/types/core/types.d.ts.map +1 -1
  122. package/types/utils/bytes.d.ts +3 -1
  123. package/types/utils/bytes.d.ts.map +1 -1
  124. package/types/utils/createLoggingCookieJar.d.ts +5 -3
  125. package/types/utils/createLoggingCookieJar.d.ts.map +1 -1
  126. package/types/utils/createMerger.d.ts +1 -1
  127. package/types/utils/createMerger.d.ts.map +1 -1
  128. package/types/utils/injectStorage.d.ts +2 -40
  129. package/types/utils/injectStorage.d.ts.map +1 -1
  130. package/types/utils/request/createDataCollectionRequest.d.ts +1 -11
  131. package/types/utils/request/createDataCollectionRequest.d.ts.map +1 -1
  132. package/types/utils/request/createDataCollectionRequestPayload.d.ts +2 -9
  133. package/types/utils/request/createDataCollectionRequestPayload.d.ts.map +1 -1
  134. package/types/utils/request/createRequest.d.ts +13 -11
  135. package/types/utils/request/createRequest.d.ts.map +1 -1
  136. package/types/utils/request/createRequestPayload.d.ts +7 -9
  137. package/types/utils/request/createRequestPayload.d.ts.map +1 -1
  138. package/types/utils/request/types.d.ts +91 -0
  139. package/types/utils/request/types.d.ts.map +1 -0
  140. package/types/utils/types.d.ts +91 -0
  141. 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,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,96 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _index = require("../../utils/validation/index.js");
5
+ var _index2 = require("../../utils/index.js");
6
+ var _makeSendPushSubscriptionRequest = require("./request/makeSendPushSubscriptionRequest.js");
7
+ /*
8
+ Copyright 2025 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
+ /** @import { StorageCreator } from '../../utils/types.js' */
20
+ /** @import { EventManager, Logger } from '../../core/types.js' */
21
+ /** @import { IdentityManager } from '../../core/identity/types.js' */
22
+ /** @import { ConsentManager } from '../../core/consent/types.js' */
23
+ /** @import { EdgeRequestExecutor } from '../../core/edgeNetwork/types.js' */
24
+
25
+ const isComponentConfigured = ({
26
+ orgId,
27
+ pushNotifications: {
28
+ vapidPublicKey
29
+ } = {
30
+ vapidPublicKey: undefined
31
+ }
32
+ }) => orgId && vapidPublicKey;
33
+
34
+ /**
35
+ * @function
36
+ *
37
+ * @param {Object} options
38
+ * @param {{ orgId: string, pushNotifications: { vapidPublicKey: string }}} options.config
39
+ * @param {StorageCreator} options.createNamespacedStorage
40
+ * @param {EventManager} options.eventManager
41
+ * @param {Logger} options.logger
42
+ * @param {ConsentManager} options.consent
43
+ * @param {IdentityManager} options.identity
44
+ * @param {EdgeRequestExecutor} options.sendEdgeNetworkRequest
45
+ * @returns {{ commands: { sendPushSubscription: object } }}
46
+ */
47
+ const createPushNotifications = ({
48
+ createNamespacedStorage,
49
+ eventManager,
50
+ config,
51
+ logger,
52
+ consent,
53
+ identity,
54
+ sendEdgeNetworkRequest
55
+ }) => {
56
+ return {
57
+ commands: {
58
+ sendPushSubscription: {
59
+ run: async () => {
60
+ if (!isComponentConfigured(config)) {
61
+ throw new Error("Push notifications module is not configured. No VAPID public key was provided.");
62
+ }
63
+ const {
64
+ orgId,
65
+ pushNotifications: {
66
+ vapidPublicKey
67
+ } = {
68
+ vapidPublicKey: undefined
69
+ }
70
+ } = config || {};
71
+ const storage = createNamespacedStorage((0, _index2.sanitizeOrgIdForCookieName)(orgId) + ".pushNotifications.");
72
+ return (0, _makeSendPushSubscriptionRequest.default)({
73
+ config: {
74
+ vapidPublicKey
75
+ },
76
+ storage: storage.persistent,
77
+ logger,
78
+ sendEdgeNetworkRequest,
79
+ consent,
80
+ eventManager,
81
+ identity,
82
+ window
83
+ });
84
+ },
85
+ optionsValidator: (0, _index.objectOf)({}).noUnknownFields()
86
+ }
87
+ }
88
+ };
89
+ };
90
+ createPushNotifications.namespace = "Push Notifications";
91
+ createPushNotifications.configValidators = (0, _index.objectOf)({
92
+ pushNotifications: (0, _index.objectOf)({
93
+ vapidPublicKey: (0, _index.string)().required()
94
+ }).noUnknownFields()
95
+ });
96
+ var _default = exports.default = createPushNotifications;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _createDataCollectionRequestPayload = require("../../../utils/request/createDataCollectionRequestPayload.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
+ /** @import { EventManager } from "../../../core/types.js" */
17
+ /** @import { DataCollectionRequestPayload } from "../../../utils/request/types.js" */
18
+ /**
19
+ * Creates a data collection request payload for sending push subscription details to Adobe Experience Platform.
20
+ *
21
+ * This function constructs an event containing push notification subscription information,
22
+ * including the subscription details, platform information, and identity data. The event
23
+ * is then packaged into a data collection request payload for transmission to the edge network.
24
+ *
25
+ * @async
26
+ * @function
27
+ *
28
+ * @param {Object} options
29
+ * @param {string} options.ecid
30
+ * @param {EventManager} options.eventManager
31
+ * @param {string} options.serializedPushSubscriptionDetails
32
+ * @param {Window} options.window
33
+ *
34
+ * @returns {Promise<DataCollectionRequestPayload>}
35
+ */
36
+ var _default = async ({
37
+ ecid,
38
+ eventManager,
39
+ serializedPushSubscriptionDetails,
40
+ window
41
+ }) => {
42
+ const event = eventManager.createEvent();
43
+ event.setUserData({
44
+ pushNotificationDetails: [{
45
+ appID: window.location.host,
46
+ token: serializedPushSubscriptionDetails,
47
+ platform: "web",
48
+ denylisted: false,
49
+ identity: {
50
+ namespace: {
51
+ code: "ECID"
52
+ },
53
+ id: ecid
54
+ }
55
+ }]
56
+ });
57
+ event.finalize();
58
+ const payload = (0, _createDataCollectionRequestPayload.default)();
59
+ payload.addEvent(event);
60
+ return payload;
61
+ };
62
+ exports.default = _default;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _index = require("../../../utils/request/index.js");
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
+ /** @import { DataCollectionRequestPayload, Request } from '../../../utils/request/types.js' */
17
+ /**
18
+ * @function
19
+ *
20
+ * @param {{ payload: DataCollectionRequestPayload }} options
21
+ *
22
+ * @returns {Request}
23
+ */
24
+ var _default = ({
25
+ payload
26
+ }) => (0, _index.createRequest)({
27
+ payload,
28
+ getAction() {
29
+ return "interact";
30
+ },
31
+ getUseSendBeacon() {
32
+ return false;
33
+ }
34
+ });
35
+ exports.default = _default;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _index = require("../../../utils/index.js");
5
+ var _getPushSubscriptionDetails = require("../helpers/getPushSubscriptionDetails.js");
6
+ var _createSendPushSubscriptionRequest = require("./createSendPushSubscriptionRequest.js");
7
+ var _createSendPushSubscriptionPayload = require("./createSendPushSubscriptionPayload.js");
8
+ /*
9
+ Copyright 2025 Adobe. All rights reserved.
10
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License. You may obtain a copy
12
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software distributed under
15
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ OF ANY KIND, either express or implied. See the License for the specific language
17
+ governing permissions and limitations under the License.
18
+ */
19
+
20
+ /** @import { Storage } from '../../../utils/types.js' */
21
+ /** @import { EventManager, Logger } from '../../../core/types.js' */
22
+ /** @import { IdentityManager } from '../../../core/identity/types.js' */
23
+ /** @import { ConsentManager } from '../../../core/consent/types.js' */
24
+ /** @import { EdgeRequestExecutor } from '../../../core/edgeNetwork/types.js' */
25
+
26
+ const SUBSCRIPTION_DETAILS = "subscriptionDetails";
27
+
28
+ /**
29
+ * Retrieves and returns push subscription details with sorted object keys.
30
+ *
31
+ * This function gets the push subscription details using the provided VAPID public key
32
+ * and returns the details with all object keys sorted recursively for consistent output.
33
+ *
34
+ * @async
35
+ * @function
36
+ *
37
+ * @param {Object} options
38
+ * @param {{vapidPublicKey: string}} options.config
39
+ * @param {Storage} options.storage
40
+ * @param {Logger} options.logger
41
+ * @param {EventManager} options.eventManager
42
+ * @param {IdentityManager} options.identity
43
+ * @param {EdgeRequestExecutor} options.sendEdgeNetworkRequest
44
+ * @param {ConsentManager} options.consent
45
+ * @param {Window} options.window
46
+ *
47
+ * @returns {Promise<void>}
48
+ */
49
+ var _default = async ({
50
+ config: {
51
+ vapidPublicKey
52
+ },
53
+ storage,
54
+ logger,
55
+ sendEdgeNetworkRequest,
56
+ consent,
57
+ eventManager,
58
+ identity,
59
+ window
60
+ }) => {
61
+ await identity.awaitIdentity();
62
+ const ecid = identity.getEcidFromCookie();
63
+ const pushSubscriptionDetails = await (0, _getPushSubscriptionDetails.default)({
64
+ vapidPublicKey,
65
+ window
66
+ });
67
+ const serializedPushSubscriptionDetails = JSON.stringify((0, _index.sortObjectKeysRecursively)(pushSubscriptionDetails));
68
+ const cacheValue = "" + ecid + serializedPushSubscriptionDetails;
69
+ if (cacheValue === storage.getItem(SUBSCRIPTION_DETAILS)) {
70
+ logger.info("Subscription details have not changed. Not sending to the server.");
71
+ return;
72
+ }
73
+ storage.setItem(SUBSCRIPTION_DETAILS, cacheValue);
74
+ const payload = await (0, _createSendPushSubscriptionPayload.default)({
75
+ eventManager,
76
+ ecid,
77
+ serializedPushSubscriptionDetails,
78
+ window
79
+ });
80
+ const request = (0, _createSendPushSubscriptionRequest.default)({
81
+ payload
82
+ });
83
+ await consent.awaitConsent();
84
+ await sendEdgeNetworkRequest({
85
+ request
86
+ });
87
+ };
88
+ exports.default = _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ exports.Types = void 0;
4
+ /** @import { Identity } from '../../utils/request/types.js' */
5
+
6
+ /**
7
+ * @typedef {Object} PushSubscription
8
+ * @property {string} endpoint - The push service endpoint URL
9
+ * @property {Object} keys - The subscription keys object
10
+ * @property {string|null} keys.p256dh - The P-256 ECDH public key as an ArrayBuffer, or null if not available
11
+ * @property {string|null} keys.auth - The authentication secret as an ArrayBuffer, or null if not available
12
+ */
13
+
14
+ const Types = exports.Types = {};
@@ -14,4 +14,4 @@ governing permissions and limitations under the License.
14
14
  */
15
15
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
16
16
  // see babel-plugin-version
17
- var _default = exports.default = "2.29.0-beta.4";
17
+ var _default = exports.default = "2.29.0";
@@ -42,6 +42,12 @@ Object.defineProperty(exports, "personalization", {
42
42
  return _index6.default;
43
43
  }
44
44
  });
45
+ Object.defineProperty(exports, "pushNotifications", {
46
+ enumerable: true,
47
+ get: function () {
48
+ return _index0.default;
49
+ }
50
+ });
45
51
  Object.defineProperty(exports, "rulesEngine", {
46
52
  enumerable: true,
47
53
  get: function () {
@@ -62,4 +68,5 @@ var _index5 = require("../components/MediaAnalyticsBridge/index.js");
62
68
  var _index6 = require("../components/Personalization/index.js");
63
69
  var _index7 = require("../components/RulesEngine/index.js");
64
70
  var _index8 = require("../components/StreamingMedia/index.js");
65
- var _index9 = require("../components/Advertising/index.js");
71
+ var _index9 = require("../components/Advertising/index.js");
72
+ var _index0 = require("../components/PushNotifications/index.js");
@@ -15,6 +15,16 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
15
15
  OF ANY KIND, either express or implied. See the License for the specific language
16
16
  governing permissions and limitations under the License.
17
17
  */
18
+ /** @import { ConsentManager } from './types.js' */
19
+ /**
20
+ * @function
21
+ *
22
+ * @param {Object} options
23
+ * @param {ConsentStateMachine} options.generalConsentState
24
+ * @param {Logger} options.logger
25
+ *
26
+ * @returns {ConsentManager}
27
+ */
18
28
  var _default = ({
19
29
  generalConsentState,
20
30
  logger