@adobe/alloy 2.29.0-beta.1 → 2.29.0-beta.13

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 (161) hide show
  1. package/libEs5/components/ActivityCollector/utils/dom/findClickableElement.js +4 -0
  2. package/libEs5/components/Advertising/createComponent.js +1 -5
  3. package/libEs5/components/Advertising/handlers/clickThroughHandler.js +2 -1
  4. package/libEs5/components/Advertising/handlers/sendAdConversion.js +6 -8
  5. package/libEs5/components/Advertising/handlers/viewThroughHandler.js +4 -3
  6. package/libEs5/components/Consent/createConsentRequestPayload.js +14 -3
  7. package/libEs5/components/Consent/types.js +18 -0
  8. package/libEs5/components/Identity/createComponent.js +5 -4
  9. package/libEs5/components/Identity/index.js +4 -9
  10. package/libEs5/components/Personalization/dom-actions/action.js +7 -4
  11. package/libEs5/components/Personalization/dom-actions/initDomActionsModules.js +10 -10
  12. package/libEs5/components/PushNotifications/helpers/getPushSubscriptionDetails.js +112 -0
  13. package/libEs5/components/PushNotifications/index.js +96 -0
  14. package/libEs5/components/PushNotifications/request/createSendPushSubscriptionPayload.js +62 -0
  15. package/libEs5/components/PushNotifications/request/createSendPushSubscriptionRequest.js +35 -0
  16. package/libEs5/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +88 -0
  17. package/libEs5/components/PushNotifications/types.js +14 -0
  18. package/libEs5/constants/libraryVersion.js +1 -1
  19. package/libEs5/core/componentCreators.js +8 -1
  20. package/libEs5/core/consent/createConsent.js +10 -0
  21. package/libEs5/core/consent/createConsentStateMachine.js +36 -0
  22. package/libEs5/core/consent/types.js +24 -0
  23. package/libEs5/core/edgeNetwork/injectSendEdgeNetworkRequest.js +20 -0
  24. package/libEs5/core/edgeNetwork/types.js +10 -0
  25. package/libEs5/core/identity/createIdentity.js +82 -0
  26. package/libEs5/core/identity/types.js +15 -0
  27. package/libEs5/core/index.js +8 -0
  28. package/libEs5/core/injectCreateResponse.js +9 -7
  29. package/libEs5/core/types.js +101 -11
  30. package/libEs5/utils/bytes.js +38 -0
  31. package/libEs5/{components/Identity → utils}/createDecodeKndctrCookie.js +12 -20
  32. package/libEs5/utils/createLoggingCookieJar.js +14 -1
  33. package/libEs5/utils/createMerger.js +5 -4
  34. package/libEs5/utils/index.js +13 -0
  35. package/libEs5/utils/injectStorage.js +19 -0
  36. package/libEs5/utils/request/createDataCollectionRequestPayload.js +16 -8
  37. package/libEs5/utils/request/createRequest.js +28 -1
  38. package/libEs5/utils/request/createRequestPayload.js +68 -4
  39. package/libEs5/utils/request/types.js +52 -0
  40. package/libEs5/utils/types.js +39 -0
  41. package/libEs6/components/ActivityCollector/utils/dom/findClickableElement.js +4 -0
  42. package/libEs6/components/Advertising/createComponent.js +1 -5
  43. package/libEs6/components/Advertising/handlers/clickThroughHandler.js +2 -1
  44. package/libEs6/components/Advertising/handlers/sendAdConversion.js +6 -8
  45. package/libEs6/components/Advertising/handlers/viewThroughHandler.js +4 -3
  46. package/libEs6/components/Consent/createConsentRequestPayload.js +16 -3
  47. package/libEs6/components/Consent/types.js +15 -0
  48. package/libEs6/components/Identity/createComponent.js +5 -4
  49. package/libEs6/components/Identity/index.js +4 -9
  50. package/libEs6/components/Personalization/dom-actions/action.js +7 -4
  51. package/libEs6/components/Personalization/dom-actions/initDomActionsModules.js +10 -10
  52. package/libEs6/components/PushNotifications/helpers/getPushSubscriptionDetails.js +110 -0
  53. package/libEs6/components/PushNotifications/index.js +93 -0
  54. package/libEs6/components/PushNotifications/request/createSendPushSubscriptionPayload.js +61 -0
  55. package/libEs6/components/PushNotifications/request/createSendPushSubscriptionRequest.js +34 -0
  56. package/libEs6/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +84 -0
  57. package/libEs6/components/PushNotifications/types.js +11 -0
  58. package/libEs6/constants/libraryVersion.js +1 -1
  59. package/libEs6/core/componentCreators.js +2 -1
  60. package/libEs6/core/consent/createConsent.js +12 -0
  61. package/libEs6/core/consent/createConsentStateMachine.js +36 -0
  62. package/libEs6/core/consent/types.js +21 -0
  63. package/libEs6/core/edgeNetwork/injectSendEdgeNetworkRequest.js +20 -0
  64. package/libEs6/core/edgeNetwork/types.js +7 -0
  65. package/libEs6/core/identity/createIdentity.js +81 -0
  66. package/libEs6/core/identity/types.js +12 -0
  67. package/libEs6/core/index.js +8 -0
  68. package/libEs6/core/injectCreateResponse.js +11 -7
  69. package/libEs6/core/types.js +101 -11
  70. package/libEs6/utils/bytes.js +33 -0
  71. package/libEs6/{components/Identity → utils}/createDecodeKndctrCookie.js +11 -19
  72. package/libEs6/utils/createLoggingCookieJar.js +15 -1
  73. package/libEs6/utils/createMerger.js +5 -4
  74. package/libEs6/utils/index.js +1 -0
  75. package/libEs6/utils/injectStorage.js +20 -0
  76. package/libEs6/utils/request/createDataCollectionRequestPayload.js +19 -8
  77. package/libEs6/utils/request/createRequest.js +29 -1
  78. package/libEs6/utils/request/createRequestPayload.js +67 -4
  79. package/libEs6/utils/request/types.js +49 -0
  80. package/libEs6/utils/types.js +36 -0
  81. package/package.json +30 -30
  82. package/types/components/ActivityCollector/utils/dom/findClickableElement.d.ts.map +1 -1
  83. package/types/components/Advertising/createComponent.d.ts +1 -1
  84. package/types/components/Advertising/createComponent.d.ts.map +1 -1
  85. package/types/components/Advertising/handlers/sendAdConversion.d.ts.map +1 -1
  86. package/types/components/Advertising/handlers/viewThroughHandler.d.ts.map +1 -1
  87. package/types/components/Advertising/index.d.ts +1 -1
  88. package/types/components/Consent/createConsentRequest.d.ts +1 -11
  89. package/types/components/Consent/createConsentRequest.d.ts.map +1 -1
  90. package/types/components/Consent/createConsentRequestPayload.d.ts +2 -9
  91. package/types/components/Consent/createConsentRequestPayload.d.ts.map +1 -1
  92. package/types/components/Consent/types.d.ts +28 -0
  93. package/types/components/Consent/types.d.ts.map +1 -0
  94. package/types/components/Identity/createComponent.d.ts +2 -2
  95. package/types/components/Identity/createComponent.d.ts.map +1 -1
  96. package/types/components/Identity/getIdentity/createIdentityRequest.d.ts +1 -11
  97. package/types/components/Identity/getIdentity/createIdentityRequest.d.ts.map +1 -1
  98. package/types/components/Identity/getIdentity/createIdentityRequestPayload.d.ts +1 -9
  99. package/types/components/Identity/getIdentity/createIdentityRequestPayload.d.ts.map +1 -1
  100. package/types/components/Identity/index.d.ts +2 -1
  101. package/types/components/Identity/index.d.ts.map +1 -1
  102. package/types/components/Personalization/dom-actions/action.d.ts +1 -1
  103. package/types/components/Personalization/dom-actions/action.d.ts.map +1 -1
  104. package/types/components/PushNotifications/helpers/getPushSubscriptionDetails.d.ts +30 -0
  105. package/types/components/PushNotifications/helpers/getPushSubscriptionDetails.d.ts.map +1 -0
  106. package/types/components/PushNotifications/index.d.ts +43 -0
  107. package/types/components/PushNotifications/index.d.ts.map +1 -0
  108. package/types/components/PushNotifications/request/createSendPushSubscriptionPayload.d.ts +10 -0
  109. package/types/components/PushNotifications/request/createSendPushSubscriptionPayload.d.ts.map +1 -0
  110. package/types/components/PushNotifications/request/createSendPushSubscriptionRequest.d.ts +7 -0
  111. package/types/components/PushNotifications/request/createSendPushSubscriptionRequest.d.ts.map +1 -0
  112. package/types/components/PushNotifications/request/makeSendPushSubscriptionRequest.d.ts +20 -0
  113. package/types/components/PushNotifications/request/makeSendPushSubscriptionRequest.d.ts.map +1 -0
  114. package/types/components/PushNotifications/types.d.ts +23 -0
  115. package/types/components/PushNotifications/types.d.ts.map +1 -0
  116. package/types/components/StreamingMedia/createMediaRequest.d.ts +1 -11
  117. package/types/components/StreamingMedia/createMediaRequest.d.ts.map +1 -1
  118. package/types/core/componentCreators.d.ts +1 -0
  119. package/types/core/consent/createConsent.d.ts +4 -10
  120. package/types/core/consent/createConsent.d.ts.map +1 -1
  121. package/types/core/consent/createConsentStateMachine.d.ts +4 -12
  122. package/types/core/consent/createConsentStateMachine.d.ts.map +1 -1
  123. package/types/core/consent/types.d.ts +42 -0
  124. package/types/core/consent/types.d.ts.map +1 -0
  125. package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts +15 -13
  126. package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts.map +1 -1
  127. package/types/core/edgeNetwork/types.d.ts +12 -0
  128. package/types/core/edgeNetwork/types.d.ts.map +1 -0
  129. package/types/core/identity/createIdentity.d.ts +12 -0
  130. package/types/core/identity/createIdentity.d.ts.map +1 -0
  131. package/types/core/identity/types.d.ts +23 -0
  132. package/types/core/identity/types.d.ts.map +1 -0
  133. package/types/core/index.d.ts.map +1 -1
  134. package/types/core/injectCreateResponse.d.ts +3 -27
  135. package/types/core/injectCreateResponse.d.ts.map +1 -1
  136. package/types/core/types.d.ts +209 -22
  137. package/types/core/types.d.ts.map +1 -1
  138. package/types/utils/bytes.d.ts +3 -0
  139. package/types/utils/bytes.d.ts.map +1 -0
  140. package/types/utils/createDecodeKndctrCookie.d.ts.map +1 -0
  141. package/types/utils/createLoggingCookieJar.d.ts +5 -3
  142. package/types/utils/createLoggingCookieJar.d.ts.map +1 -1
  143. package/types/utils/createMerger.d.ts +1 -1
  144. package/types/utils/createMerger.d.ts.map +1 -1
  145. package/types/utils/index.d.ts +1 -0
  146. package/types/utils/injectStorage.d.ts +2 -40
  147. package/types/utils/injectStorage.d.ts.map +1 -1
  148. package/types/utils/request/createDataCollectionRequest.d.ts +1 -11
  149. package/types/utils/request/createDataCollectionRequest.d.ts.map +1 -1
  150. package/types/utils/request/createDataCollectionRequestPayload.d.ts +2 -9
  151. package/types/utils/request/createDataCollectionRequestPayload.d.ts.map +1 -1
  152. package/types/utils/request/createRequest.d.ts +13 -11
  153. package/types/utils/request/createRequest.d.ts.map +1 -1
  154. package/types/utils/request/createRequestPayload.d.ts +7 -9
  155. package/types/utils/request/createRequestPayload.d.ts.map +1 -1
  156. package/types/utils/request/types.d.ts +91 -0
  157. package/types/utils/request/types.d.ts.map +1 -0
  158. package/types/utils/types.d.ts +91 -0
  159. package/types/utils/types.d.ts.map +1 -0
  160. package/types/components/Identity/createDecodeKndctrCookie.d.ts.map +0 -1
  161. /package/types/{components/Identity → utils}/createDecodeKndctrCookie.d.ts +0 -0
@@ -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.1";
17
+ var _default = exports.default = "2.29.0-beta.13";
@@ -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
@@ -14,17 +14,53 @@ OF ANY KIND, either express or implied. See the License for the specific languag
14
14
  governing permissions and limitations under the License.
15
15
  */
16
16
 
17
+ /** @import { Logger } from '../../core/types.js' */
18
+ /** @import { ConsentStateMachineUtils, ConsentStateMachine } from './types.js' */
19
+
17
20
  const DECLINED_CONSENT = exports.DECLINED_CONSENT = "The user declined consent.";
18
21
  const DECLINED_CONSENT_ERROR_CODE = exports.DECLINED_CONSENT_ERROR_CODE = "declinedConsent";
19
22
  const CONSENT_SOURCE_DEFAULT = exports.CONSENT_SOURCE_DEFAULT = "default";
20
23
  const CONSENT_SOURCE_INITIAL = exports.CONSENT_SOURCE_INITIAL = "initial";
21
24
  const CONSENT_SOURCE_NEW = exports.CONSENT_SOURCE_NEW = "new";
25
+
26
+ /**
27
+ * @private
28
+ * @param {string} errorMessage
29
+ * @returns {Error}
30
+ */
22
31
  const createDeclinedConsentError = errorMessage => {
23
32
  const error = new Error(errorMessage);
24
33
  error.code = DECLINED_CONSENT_ERROR_CODE;
25
34
  error.message = errorMessage;
26
35
  return error;
27
36
  };
37
+
38
+ /**
39
+ * Creates a consent state machine that manages user consent preferences and
40
+ * coordinates deferred operations that require consent.
41
+ *
42
+ * The state machine supports the following states:
43
+ * - "in": User has provided consent (with default or explicit consent)
44
+ * - "out": User has declined consent (with default or explicit decline)
45
+ * - "pending": Consent decision is awaiting user input
46
+ *
47
+ * @param {object} options
48
+ * @param {Logger} options.logger
49
+ *
50
+ * @returns {ConsentStateMachine}
51
+ *
52
+ * @example
53
+ * const consentStateMachine = createConsentStateMachine({ logger });
54
+ *
55
+ * // Set consent state
56
+ * consentStateMachine.in('new');
57
+ *
58
+ * // Wait for consent
59
+ * await consentStateMachine.awaitConsent();
60
+ *
61
+ * // Check current state
62
+ * const { state, wasSet } = consentStateMachine.current();
63
+ */
28
64
  var _default = ({
29
65
  logger
30
66
  }) => {
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ exports.Types = void 0;
4
+ /**
5
+ * @typedef {Object} ConsentStateMachine
6
+ * @property {function(string): void} in
7
+ * @property {function(string): void} out
8
+ * @property {function(string): void} pending
9
+ * @property {function(boolean=): Promise<void>} awaitConsent
10
+ * @property {function(): Promise<void>} withConsent
11
+ * @property {function(): {state: string, wasSet: boolean}} current
12
+ */
13
+
14
+ /**
15
+ * @typedef {Object} ConsentManager
16
+ * @property {function(Object, Object): void} initializeConsent
17
+ * @property {function(Object): void} setConsent
18
+ * @property {function(): void} suspend
19
+ * @property {function(): Promise<void>} awaitConsent
20
+ * @property {function(): Promise<void>} withConsent
21
+ * @property {function(): {state: string, wasSet: boolean}} current
22
+ */
23
+
24
+ const Types = exports.Types = {};
@@ -19,9 +19,29 @@ OF ANY KIND, either express or implied. See the License for the specific languag
19
19
  governing permissions and limitations under the License.
20
20
  */
21
21
 
22
+ /** @import { EdgeRequestExecutor } from './types.js' */
23
+ /** @import { ResponseCreator } from '../types.js' */
24
+
22
25
  const isDemdexBlockedError = (error, request) => {
23
26
  return request.getUseIdThirdPartyDomain() && (0, _networkErrors.isNetworkError)(error);
24
27
  };
28
+
29
+ /**
30
+ * @function
31
+ *
32
+ * @param {object} options
33
+ * @param {{edgeDomain: string, edgeBasePath: string, datastreamId: string}} options.config
34
+ * @param {object} options.lifecycle
35
+ * @param {object} options.cookieTransfer
36
+ * @param {function(object): Promise<Object>} options.sendNetworkRequest
37
+ * @param {ResponseCreator} options.createResponse
38
+ * @param {function(object): void} options.processWarningsAndErrors
39
+ * @param {function(): string|undefined} options.getLocationHint
40
+ * @param {function(): string} options.getAssuranceValidationTokenParams
41
+
42
+ *
43
+ * @returns {EdgeRequestExecutor} A function that sends edge network requests with lifecycle management
44
+ */
25
45
  var _default = ({
26
46
  config,
27
47
  lifecycle,
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ exports.Types = void 0;
4
+ /** @import { Request } from '../../utils/request/types.js' */
5
+
6
+ /**
7
+ * @typedef {function({request: Request, runOnResponseCallbacks?: function(): void, runOnRequestFailureCallbacks?: function(): void}): Promise<Object>} EdgeRequestExecutor
8
+ */
9
+
10
+ const Types = exports.Types = {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _createDecodeKndctrCookie = require("../../utils/createDecodeKndctrCookie.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 { IdentityManager } from './types.js' */
17
+ /** @import { Logger } from '../types.js' */
18
+ /** @import { CookieJar } from '../../utils/types.js' */
19
+ /**
20
+ * Creates an identity management service for handling ECID (Experience Cloud ID) resolution and tracking.
21
+ *
22
+ * This factory function creates an identity manager service that manages the state of identity resolution,
23
+ * provides methods to check for existing identity cookies, and handles the asynchronous nature
24
+ * of identity acquisition in Adobe Experience Platform Web SDK.
25
+ *
26
+ * @function
27
+ *
28
+ * @param {Object} options
29
+ * @param {Logger} options.logger
30
+ * @param {CookieJar} options.loggingCookieJar
31
+ * @param {{orgId: string}} options.config
32
+ *
33
+ * @returns {IdentityManager}
34
+ *
35
+ * @example
36
+ * // Create an identity service
37
+ * const identityManager = createIdentity({
38
+ * logger: myLogger,
39
+ * loggingCookieJar: myCookieJar,
40
+ * config: { orgId: 'myOrgId@AdobeOrg' }
41
+ * });
42
+ *
43
+ * // Initialize and check for existing identity
44
+ * identityManager.initialize();
45
+ *
46
+ * // Wait for identity to be available
47
+ * await identityManager.awaitIdentity();
48
+ *
49
+ * // Get ECID from cookie
50
+ * const ecid = identityManager.getEcidFromCookie();
51
+ */
52
+ var _default = ({
53
+ logger,
54
+ loggingCookieJar,
55
+ config
56
+ }) => {
57
+ let awaitIdentityResolve = null;
58
+ const awaitIdentityPromise = new Promise(resolve => {
59
+ awaitIdentityResolve = resolve;
60
+ });
61
+ const decodeKndctrCookie = (0, _createDecodeKndctrCookie.default)({
62
+ orgId: config.orgId,
63
+ cookieJar: loggingCookieJar,
64
+ logger
65
+ });
66
+ return {
67
+ initialize() {
68
+ const ecidFromCookie = decodeKndctrCookie();
69
+ if (ecidFromCookie) {
70
+ this.setIdentityAcquired();
71
+ }
72
+ },
73
+ setIdentityAcquired() {
74
+ awaitIdentityResolve();
75
+ },
76
+ awaitIdentity() {
77
+ return awaitIdentityPromise;
78
+ },
79
+ getEcidFromCookie: () => decodeKndctrCookie()
80
+ };
81
+ };
82
+ exports.default = _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ exports.Types = void 0;
4
+ /** @import { Logger } from '../../core/types.js' */
5
+ /** @import { CookieJar } from '../../utils/types.js' */
6
+
7
+ /**
8
+ * @typedef {Object} IdentityManager
9
+ * @property {Function} initialize
10
+ * @property {Function} setIdentityAcquired - Marks identity as acquired and resolves any pending identity promises
11
+ * @property {Function} awaitIdentity - Returns a promise that resolves when identity is acquired
12
+ * @property {Function} getEcidFromCookie
13
+ */
14
+
15
+ const Types = exports.Types = {};
@@ -8,6 +8,7 @@ var _createLifecycle = require("./createLifecycle.js");
8
8
  var _createComponentRegistry = require("./createComponentRegistry.js");
9
9
  var _injectSendNetworkRequest = require("./network/injectSendNetworkRequest.js");
10
10
  var _injectExtractEdgeInfo = require("./edgeNetwork/injectExtractEdgeInfo.js");
11
+ var _createIdentity = require("./identity/createIdentity.js");
11
12
  var _createConsent = require("./consent/createConsent.js");
12
13
  var _createConsentStateMachine = require("./consent/createConsentStateMachine.js");
13
14
  var _createEvent = require("./createEvent.js");
@@ -159,6 +160,12 @@ const createExecuteCommand = ({
159
160
  generalConsentState,
160
161
  logger
161
162
  });
163
+ const identity = (0, _createIdentity.default)({
164
+ config,
165
+ logger,
166
+ loggingCookieJar
167
+ });
168
+ identity.initialize();
162
169
  const eventManager = (0, _createEventManager.default)({
163
170
  config,
164
171
  logger,
@@ -180,6 +187,7 @@ const createExecuteCommand = ({
180
187
  config,
181
188
  componentRegistry,
182
189
  consent,
190
+ identity,
183
191
  eventManager,
184
192
  fireReferrerHideableImage,
185
193
  logger: componentLogger,
@@ -13,10 +13,17 @@ 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 { ResponseCreator } from './types.js' */
16
17
  /**
17
18
  * Creates a representation of a gateway response with the addition of
18
19
  * helper methods.
19
- * @returns Response
20
+ *
21
+ * @function
22
+ *
23
+ * @param {object} options
24
+ * @param {function(string): Object} options.extractEdgeInfo
25
+ *
26
+ * @returns {ResponseCreator}
20
27
  */
21
28
  var _default = ({
22
29
  extractEdgeInfo
@@ -29,15 +36,10 @@ var _default = ({
29
36
  errors = [],
30
37
  warnings = []
31
38
  } = content;
32
-
33
- /**
34
- * Response object.
35
- * @typedef {Object} Response
36
- */
37
39
  return {
38
40
  /**
39
41
  * Returns matching fragments of the response by type.
40
- * @param {String} type A string with the current format: <namespace:action>
42
+ * @param {string} type A string with the current format: <namespace:action>
41
43
  *
42
44
  * @example
43
45
  * getPayloadsByType("identity:persist")
@@ -3,17 +3,107 @@
3
3
  exports.Types = void 0;
4
4
  /**
5
5
  * @typedef {object} AlloyMonitor
6
- * @property {function(data): void} [onBeforeLog]
7
- * @property {function(data): void} [onInstanceCreated]
8
- * @property {function(data): void} [onInstanceConfigured]
9
- * @property {function(data): void} [onBeforeCommand]
10
- * @property {function(data): void} [onCommandResolved]
11
- * @property {function(data): void} [onCommandRejected]
12
- * @property {function(data): void} [onBeforeNetworkRequest]
13
- * @property {function(data): void} [onNetworkResponse]
14
- * @property {function(data): void} [onNetworkError]
15
- * @property {function(data): void} [onContentHiding]
16
- * @property {function(data): void} [onContentRendering]
6
+ * @property {function(any): void} [onBeforeLog]
7
+ * @property {function(any): void} [onInstanceCreated]
8
+ * @property {function(any): void} [onInstanceConfigured]
9
+ * @property {function(any): void} [onBeforeCommand]
10
+ * @property {function(any): void} [onCommandResolved]
11
+ * @property {function(any): void} [onCommandRejected]
12
+ * @property {function(any): void} [onBeforeNetworkRequest]
13
+ * @property {function(any): void} [onNetworkResponse]
14
+ * @property {function(any): void} [onNetworkError]
15
+ * @property {function(any): void} [onContentHiding]
16
+ * @property {function(any): void} [onContentRendering]
17
+ */
18
+
19
+ /**
20
+ * @typedef {object} Logger
21
+ * @property {boolean} enabled
22
+ * @property {function(any): void} logOnInstanceCreated
23
+ * @property {function(any): void} logOnInstanceConfigured
24
+ * @property {function(any): void} logOnBeforeCommand
25
+ * @property {function(any): void} logOnCommandResolved
26
+ * @property {function(any): void} logOnCommandRejected
27
+ * @property {function(any): void} logOnBeforeNetworkRequest
28
+ * @property {function(any): void} logOnNetworkResponse
29
+ * @property {function(any): void} logOnNetworkError
30
+ * @property {function(any): void} logOnContentHiding
31
+ * @property {function(any): void} logOnContentRendering
32
+ * @property {function(...any): void} info
33
+ * @property {function(...any): void} warn
34
+ * @property {function(...any): void} error
35
+ */
36
+
37
+ /**
38
+ * @typedef {object} Event
39
+ * @property {function(): boolean} hasQuery
40
+ * @property {function(): object} getContent
41
+ * @property {function(object): void} setUserXdm
42
+ * @property {function(object): void} setUserData
43
+ * @property {function(object): void} mergeXdm
44
+ * @property {function(object): void} mergeData
45
+ * @property {function(object): void} mergeMeta
46
+ * @property {function(object): void} mergeQuery
47
+ * @property {function(): void} documentMayUnload
48
+ * @property {function(function=): void} finalize
49
+ * @property {function(): boolean} getDocumentMayUnload
50
+ * @property {function(): boolean} isEmpty
51
+ * @property {function(): boolean} shouldSend
52
+ * @property {function(): string|undefined} getViewName
53
+ * @property {function(): object} toJSON
54
+ */
55
+
56
+ /**
57
+ * @typedef {object} SendEventOptions
58
+ * @property {object} [edgeConfigOverrides]
59
+ configuration
60
+ * @property {boolean} [renderDecisions]
61
+ * @property {string[]} [decisionScopes]
62
+ * @property {object} [decisionContext]
63
+ * @property {object} [personalization]
64
+ * @property {object} [mediaOptions]
65
+ */
66
+
67
+ /**
68
+ * @typedef {object} ApplyResponseOptions
69
+ * @property {boolean} [renderDecisions=false]
70
+ * @property {object} [decisionContext={}]
71
+ * @property {object} [responseHeaders={}]
72
+ * @property {object} [responseBody={handle:[]}]
73
+ * @property {object} [personalization]
74
+ */
75
+
76
+ /**
77
+ * @typedef {object} EventManager
78
+ * @property {function(): Event} createEvent
79
+ * @property {function(Event, SendEventOptions=): Promise<any>} sendEvent
80
+ * @property {function(Event, ApplyResponseOptions=): Promise<any>} applyResponse
81
+ */
82
+
83
+ /**
84
+ * @typedef {Object} ResponseContent
85
+ * @property {Array<{type: string, payload: Array<Object>}>} [handle] - Array of response fragments with type and payload
86
+ * @property {Array<object>} [errors] - Array of error objects
87
+ * @property {Array<object>} [warnings] - Array of warning objects
88
+ */
89
+
90
+ /**
91
+ * @typedef {Object} ResponseFragment
92
+ * @property {string} type - Fragment type in format "<namespace:action>"
93
+ * @property {any} payload - Fragment payload data
94
+ */
95
+
96
+ /**
97
+ * @typedef {Object} Response
98
+ * @property {function(string): Array<any>} getPayloadsByType - Returns matching fragments by type (e.g., "identity:persist")
99
+ * @property {function(): Array<object>} getErrors - Returns all error objects from the response
100
+ * @property {function(): Array<object>} getWarnings - Returns all warning objects from the response
101
+ * @property {function(): object} getEdge - Returns object containing regionId from x-adobe-edge header
102
+ * @property {function(): ResponseContent} toJSON
103
+ */
104
+
105
+ /**
106
+ * @typedef {function({content?: ResponseContent, getHeader: function(string): string|undefined}): Response} ResponseCreator
17
107
  */
18
108
 
19
109
  const Types = exports.Types = {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ exports.bytesToBase64 = exports.base64ToBytes = 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
+ /**
17
+ * Takes a base64 string of bytes and returns a Uint8Array.
18
+ * @param {string} base64String
19
+ * @returns {Uint8Array}
20
+ */
21
+ const base64ToBytes = base64String => {
22
+ // Add padding if needed
23
+ const padding = "=".repeat((4 - base64String.length % 4) % 4);
24
+
25
+ // Convert URL-safe base64 to regular base64
26
+ const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
27
+ const binString = atob(base64);
28
+ return Uint8Array.from(binString, m => m.codePointAt(0));
29
+ };
30
+
31
+ /**
32
+ * Takes a Uint8Array and returns a base64 string.
33
+ * @param {Uint8Array} bytes
34
+ * @returns {string}
35
+ */
36
+ exports.base64ToBytes = base64ToBytes;
37
+ const bytesToBase64 = bytes => btoa(String.fromCharCode(...bytes));
38
+ exports.bytesToBase64 = bytesToBase64;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  exports.default = exports.decodeVarint = void 0;
4
- var _index = require("../../utils/index.js");
4
+ var _index = require("./index.js");
5
+ var _bytes = require("./bytes.js");
5
6
  /*
6
7
  Copyright 2024 Adobe. All rights reserved.
7
8
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -29,39 +30,39 @@ governing permissions and limitations under the License.
29
30
  * and https://git.corp.adobe.com/experience-edge/konductor/blob/master/feature-identity/src/main/kotlin/com/adobe/edge/features/identity/data/StoredIdentity.kt#L16
30
31
 
31
32
  * syntax = "proto3";
32
- *
33
+ *
33
34
  * // Device-level identity for Experience Edge
34
35
  * message Identity {
35
36
  * // The Experience Cloud ID value
36
37
  * string ecid = 1;
37
- *
38
+ *
38
39
  * IdentityMetadata metadata = 10;
39
- *
40
+ *
40
41
  * // Used only in the 3rd party domain context.
41
42
  * // It stores the UNIX timestamp and some metadata about the last identity sync triggered by Experience Edge.
42
43
  * int64 last_sync = 20;
43
44
  * int64 sync_hash = 21;
44
45
  * int32 id_sync_container_id = 22;
45
- *
46
+ *
46
47
  * // UNIX timestamp when the Identity was last returned in a `state:store` instruction.
47
48
  * // The Identity is written at most once every 24h with a large TTL, to ensure it does not expire.
48
49
  * int64 write_time = 30;
49
50
  * }
50
- *
51
+ *
51
52
  * message IdentityMetadata {
52
53
  * // UNIX timestamp when this identity was minted.
53
54
  * int64 created_at = 1;
54
- *
55
+ *
55
56
  * // Whether or not the identity is random (new) or based on an existing seed.
56
57
  * bool is_new = 2;
57
- *
58
+ *
58
59
  * // Type of device for which the identity was generated.
59
60
  * // 0 = UNKNOWN, 1 = BROWSER, 2 = MOBILE
60
61
  * int32 device_type = 3;
61
- *
62
+ *
62
63
  * // The Experience Edge region in which the identity was minted.
63
64
  * string region = 5;
64
- *
65
+ *
65
66
  * // More details on the source of the ECID identity.
66
67
  * // Invariant: when `is_new` = true, the source must be set to `RANDOM`.
67
68
  * // 0 = RANDOM, 1 = THIRD_PARTY_ID, 2 = FIRST_PARTY_ID, 3 = RECEIVED_IN_REQUEST
@@ -224,15 +225,6 @@ const decodeKndctrProtobuf = buffer => {
224
225
  throw new Error("No ECID found in cookie.");
225
226
  };
226
227
 
227
- /**
228
- * takes a base64 string of bytes and returns a Uint8Array
229
- * @param {string} base64
230
- * @returns {Uint8Array}
231
- */
232
- const base64ToBytes = base64 => {
233
- const binString = atob(base64);
234
- return Uint8Array.from(binString, m => m.codePointAt(0));
235
- };
236
228
  // #endregion
237
229
 
238
230
  // #region decode cookie
@@ -256,7 +248,7 @@ var _default = ({
256
248
  // cookie is a base64 encoded byte representation of a Identity protobuf message
257
249
  // and we need to get it to a Uint8Array in order to decode it
258
250
 
259
- const cookieBytes = base64ToBytes(decodedCookie);
251
+ const cookieBytes = (0, _bytes.base64ToBytes)(decodedCookie);
260
252
  return decodeKndctrProtobuf(cookieBytes);
261
253
  } catch (error) {
262
254
  logger.warn("Unable to decode ECID from " + kndctrCookieName + " cookie", error);