@adobe/alloy 2.12.0-beta.0 → 2.13.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 (73) hide show
  1. package/libEs5/components/ActivityCollector/attachClickActivityCollector.js +4 -9
  2. package/libEs5/components/ActivityCollector/createLinkClick.js +7 -1
  3. package/libEs5/components/Context/createComponent.js +7 -6
  4. package/libEs5/components/Context/index.js +17 -13
  5. package/libEs5/components/Context/injectHighEntropyUserAgentHints.js +55 -0
  6. package/libEs5/components/DataCollector/index.js +26 -0
  7. package/libEs5/components/DataCollector/validateApplyResponse.js +22 -0
  8. package/libEs5/components/DataCollector/validateUserEventOptions.js +5 -3
  9. package/libEs5/components/Identity/getIdentity/getIdentityOptionsValidator.js +1 -1
  10. package/libEs5/components/Personalization/constants/propositionEventType.js +20 -0
  11. package/libEs5/components/Personalization/createCollect.js +3 -1
  12. package/libEs5/components/Personalization/createComponent.js +19 -13
  13. package/libEs5/components/Personalization/createFetchDataHandler.js +1 -2
  14. package/libEs5/components/Personalization/createOnClickHandler.js +3 -1
  15. package/libEs5/components/Personalization/createSetTargetMigration.js +34 -0
  16. package/libEs5/components/Personalization/createViewChangeHandler.js +3 -1
  17. package/libEs5/components/Personalization/event.js +5 -2
  18. package/libEs5/components/Personalization/index.js +12 -3
  19. package/libEs5/constants/cookieNameKey.js +4 -2
  20. package/libEs5/constants/highEntropyUserAgentClientHints.js +17 -0
  21. package/libEs5/constants/legacyCookies.js +21 -0
  22. package/libEs5/constants/libraryVersion.js +1 -1
  23. package/libEs5/core/createCookieTransfer.js +2 -9
  24. package/libEs5/core/createEventManager.js +32 -1
  25. package/libEs5/core/edgeNetwork/handleRequestFailure.js +20 -0
  26. package/libEs5/core/edgeNetwork/injectApplyResponse.js +62 -0
  27. package/libEs5/core/edgeNetwork/injectGetLocationHint.js +18 -1
  28. package/libEs5/core/edgeNetwork/injectSendEdgeNetworkRequest.js +14 -29
  29. package/libEs5/core/edgeNetwork/mergeLifecycleResponses.js +28 -0
  30. package/libEs5/core/index.js +19 -3
  31. package/libEs5/core/injectShouldTransferCookie.js +33 -0
  32. package/libEs5/utils/isUnique.js +38 -0
  33. package/libEs5/utils/request/createRequestPayload.js +1 -0
  34. package/libEs5/utils/validateIdentityMap.js +1 -1
  35. package/libEs5/utils/validation/createUniqueItemsValidator.js +26 -0
  36. package/libEs5/utils/validation/index.js +8 -1
  37. package/libEs6/components/ActivityCollector/attachClickActivityCollector.js +3 -8
  38. package/libEs6/components/ActivityCollector/createLinkClick.js +7 -1
  39. package/libEs6/components/Context/createComponent.js +4 -5
  40. package/libEs6/components/Context/index.js +10 -2
  41. package/libEs6/components/Context/injectHighEntropyUserAgentHints.js +46 -0
  42. package/libEs6/components/DataCollector/index.js +24 -0
  43. package/libEs6/components/DataCollector/validateApplyResponse.js +16 -0
  44. package/libEs6/components/DataCollector/validateUserEventOptions.js +5 -3
  45. package/libEs6/components/Identity/getIdentity/getIdentityOptionsValidator.js +1 -1
  46. package/libEs6/components/Personalization/constants/propositionEventType.js +15 -0
  47. package/libEs6/components/Personalization/createCollect.js +2 -1
  48. package/libEs6/components/Personalization/createComponent.js +9 -1
  49. package/libEs6/components/Personalization/createFetchDataHandler.js +1 -5
  50. package/libEs6/components/Personalization/createOnClickHandler.js +2 -1
  51. package/libEs6/components/Personalization/createSetTargetMigration.js +27 -0
  52. package/libEs6/components/Personalization/createViewChangeHandler.js +2 -1
  53. package/libEs6/components/Personalization/event.js +6 -2
  54. package/libEs6/components/Personalization/index.js +14 -4
  55. package/libEs6/constants/cookieNameKey.js +2 -1
  56. package/libEs6/constants/highEntropyUserAgentClientHints.js +12 -0
  57. package/libEs6/constants/legacyCookies.js +14 -0
  58. package/libEs6/constants/libraryVersion.js +1 -1
  59. package/libEs6/core/createCookieTransfer.js +3 -10
  60. package/libEs6/core/createEventManager.js +32 -2
  61. package/libEs6/core/edgeNetwork/handleRequestFailure.js +14 -0
  62. package/libEs6/core/edgeNetwork/injectApplyResponse.js +48 -0
  63. package/libEs6/core/edgeNetwork/injectGetLocationHint.js +17 -1
  64. package/libEs6/core/edgeNetwork/injectSendEdgeNetworkRequest.js +5 -21
  65. package/libEs6/core/edgeNetwork/mergeLifecycleResponses.js +9 -0
  66. package/libEs6/core/index.js +17 -3
  67. package/libEs6/core/injectShouldTransferCookie.js +24 -0
  68. package/libEs6/utils/isUnique.js +32 -0
  69. package/libEs6/utils/request/createRequestPayload.js +1 -0
  70. package/libEs6/utils/validateIdentityMap.js +1 -1
  71. package/libEs6/utils/validation/createUniqueItemsValidator.js +18 -0
  72. package/libEs6/utils/validation/index.js +7 -1
  73. package/package.json +4 -3
@@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
  import validateUserEventOptions from "./validateUserEventOptions";
13
+ import validateApplyResponse from "./validateApplyResponse";
13
14
 
14
15
  const createDataCollector = ({
15
16
  eventManager
@@ -68,6 +69,29 @@ const createDataCollector = ({
68
69
  decisionScopes
69
70
  });
70
71
  }
72
+ },
73
+ applyResponse: {
74
+ documentationUri: "",
75
+ optionsValidator: options => {
76
+ return validateApplyResponse({
77
+ options
78
+ });
79
+ },
80
+ run: options => {
81
+ const {
82
+ renderDecisions = false,
83
+ responseHeaders = {},
84
+ responseBody = {
85
+ handle: []
86
+ }
87
+ } = options;
88
+ const event = eventManager.createEvent();
89
+ return eventManager.applyResponse(event, {
90
+ renderDecisions,
91
+ responseHeaders,
92
+ responseBody
93
+ });
94
+ }
71
95
  }
72
96
  }
73
97
  };
@@ -0,0 +1,16 @@
1
+ import { anything, arrayOf, boolean, mapOfValues, objectOf, string } from "../../utils/validation";
2
+ export default (({
3
+ options
4
+ }) => {
5
+ const validator = objectOf({
6
+ renderDecisions: boolean(),
7
+ responseHeaders: mapOfValues(string().required()),
8
+ responseBody: objectOf({
9
+ handle: arrayOf(objectOf({
10
+ type: string().required(),
11
+ payload: anything().required()
12
+ })).required()
13
+ }).required()
14
+ }).noUnknownFields();
15
+ return validator(options);
16
+ });
@@ -27,9 +27,11 @@ export default (({
27
27
  identityMap: validateIdentityMap
28
28
  }),
29
29
  data: objectOf({}),
30
+ documentUnloading: boolean(),
30
31
  renderDecisions: boolean(),
31
- decisionScopes: arrayOf(string()),
32
- datasetId: string()
33
- }).required();
32
+ decisionScopes: arrayOf(string()).uniqueItems(),
33
+ datasetId: string(),
34
+ mergeId: string()
35
+ }).required().noUnknownFields();
34
36
  return eventOptionsValidator(options);
35
37
  });
@@ -18,7 +18,7 @@ import { objectOf, literal, arrayOf } from "../../../utils/validation";
18
18
 
19
19
  export default (options => {
20
20
  const getIdentityOptionsValidator = objectOf({
21
- namespaces: arrayOf(literal("ECID")).nonEmpty()
21
+ namespaces: arrayOf(literal("ECID")).nonEmpty().uniqueItems()
22
22
  }).noUnknownFields();
23
23
  getIdentityOptionsValidator(options); // Return default options for now
24
24
  // To-Do: Accept namespace from given options
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export const PropositionEventType = {
13
+ DISPLAY: "display",
14
+ INTERACT: "interact"
15
+ };
@@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
  import { DISPLAY } from "./constants/eventType";
13
+ import { PropositionEventType } from "./constants/propositionEventType";
13
14
  import { isNonEmptyArray } from "../../utils";
14
15
  export default (({
15
16
  eventManager,
@@ -35,7 +36,7 @@ export default (({
35
36
  }
36
37
 
37
38
  if (isNonEmptyArray(decisionsMeta)) {
38
- mergeDecisionsMeta(event, decisionsMeta);
39
+ mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
39
40
  }
40
41
 
41
42
  event.mergeXdm(data);
@@ -22,10 +22,18 @@ export default (({
22
22
  mergeQuery,
23
23
  viewCache,
24
24
  showContainers,
25
- applyPropositions
25
+ applyPropositions,
26
+ setTargetMigration
26
27
  }) => {
27
28
  return {
28
29
  lifecycle: {
30
+ onBeforeRequest({
31
+ request
32
+ }) {
33
+ setTargetMigration(request);
34
+ return Promise.resolve();
35
+ },
36
+
29
37
  onBeforeEvent({
30
38
  event,
31
39
  renderDecisions,
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
  export default (({
13
- config,
13
+ prehidingStyle,
14
14
  responseHandler,
15
15
  hideContainers,
16
16
  mergeQuery
@@ -21,10 +21,6 @@ export default (({
21
21
  event,
22
22
  onResponse
23
23
  }) => {
24
- const {
25
- prehidingStyle
26
- } = config;
27
-
28
24
  if (personalizationDetails.isRenderDecisions()) {
29
25
  hideContainers(prehidingStyle);
30
26
  }
@@ -11,6 +11,7 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  import { isNonEmptyArray } from "../../utils";
13
13
  import { INTERACT } from "./constants/eventType";
14
+ import { PropositionEventType } from "./constants/propositionEventType";
14
15
  import PAGE_WIDE_SCOPE from "./constants/scope";
15
16
  export default (({
16
17
  mergeDecisionsMeta,
@@ -43,7 +44,7 @@ export default (({
43
44
  }
44
45
 
45
46
  event.mergeXdm(xdm);
46
- mergeDecisionsMeta(event, decisionsMeta);
47
+ mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.INTERACT);
47
48
  }
48
49
  }
49
50
  };
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { noop } from "../../utils";
13
+ export default (({
14
+ targetMigrationEnabled
15
+ }) => {
16
+ if (targetMigrationEnabled) {
17
+ return request => {
18
+ request.getPayload().mergeMeta({
19
+ target: {
20
+ migration: true
21
+ }
22
+ });
23
+ };
24
+ }
25
+
26
+ return noop;
27
+ });
@@ -11,6 +11,7 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  import composePersonalizationResultingObject from "./utils/composePersonalizationResultingObject";
13
13
  import { isNonEmptyArray } from "../../utils";
14
+ import { PropositionEventType } from "./constants/propositionEventType";
14
15
  export default (({
15
16
  mergeDecisionsMeta,
16
17
  collect,
@@ -28,7 +29,7 @@ export default (({
28
29
  return executeDecisions(viewDecisions).then(decisionsMeta => {
29
30
  // if there are decisions to be rendered we render them and attach the result in experience.decisions.propositions
30
31
  if (isNonEmptyArray(decisionsMeta)) {
31
- mergeDecisionsMeta(event, decisionsMeta);
32
+ mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
32
33
  onResponse(() => {
33
34
  return composePersonalizationResultingObject(viewDecisions, true);
34
35
  });
@@ -9,11 +9,15 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- export const mergeDecisionsMeta = (event, decisionsMeta) => {
12
+ const EVENT_TYPE_TRUE = 1;
13
+ export const mergeDecisionsMeta = (event, decisionsMeta, eventType) => {
13
14
  event.mergeXdm({
14
15
  _experience: {
15
16
  decisioning: {
16
- propositions: decisionsMeta
17
+ propositions: decisionsMeta,
18
+ propositionEventType: {
19
+ [eventType]: EVENT_TYPE_TRUE
20
+ }
17
21
  }
18
22
  }
19
23
  });
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { string } from "../../utils/validation";
12
+ import { string, boolean } from "../../utils/validation";
13
13
  import createComponent from "./createComponent";
14
14
  import { initDomActionsModules, executeActions } from "./dom-actions";
15
15
  import createCollect from "./createCollect";
@@ -29,12 +29,17 @@ import createRedirectHandler from "./createRedirectHandler";
29
29
  import createAutorenderingHandler from "./createAutoRenderingHandler";
30
30
  import createNonRenderingHandler from "./createNonRenderingHandler";
31
31
  import createApplyPropositions from "./createApplyPropositions";
32
+ import createSetTargetMigration from "./createSetTargetMigration";
32
33
 
33
34
  const createPersonalization = ({
34
35
  config,
35
36
  logger,
36
37
  eventManager
37
38
  }) => {
39
+ const {
40
+ targetMigrationEnabled,
41
+ prehidingStyle
42
+ } = config;
38
43
  const collect = createCollect({
39
44
  eventManager,
40
45
  mergeDecisionsMeta
@@ -77,7 +82,7 @@ const createPersonalization = ({
77
82
  showContainers
78
83
  });
79
84
  const fetchDataHandler = createFetchDataHandler({
80
- config,
85
+ prehidingStyle,
81
86
  responseHandler,
82
87
  hideContainers,
83
88
  mergeQuery
@@ -94,6 +99,9 @@ const createPersonalization = ({
94
99
  executeDecisions,
95
100
  viewCache
96
101
  });
102
+ const setTargetMigration = createSetTargetMigration({
103
+ targetMigrationEnabled
104
+ });
97
105
  return createComponent({
98
106
  logger,
99
107
  fetchDataHandler,
@@ -103,12 +111,14 @@ const createPersonalization = ({
103
111
  mergeQuery,
104
112
  viewCache,
105
113
  showContainers,
106
- applyPropositions
114
+ applyPropositions,
115
+ setTargetMigration
107
116
  });
108
117
  };
109
118
 
110
119
  createPersonalization.namespace = "Personalization";
111
120
  createPersonalization.configValidators = {
112
- prehidingStyle: string().nonEmpty()
121
+ prehidingStyle: string().nonEmpty(),
122
+ targetMigrationEnabled: boolean().default(false)
113
123
  };
114
124
  export default createPersonalization;
@@ -11,4 +11,5 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  export const IDENTITY = "identity";
13
13
  export const CONSENT = "consent";
14
- export const CLUSTER = "cluster";
14
+ export const CLUSTER = "cluster";
15
+ export const MBOX = "mbox";
@@ -0,0 +1,12 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export default ["architecture", "bitness", "model", "platformVersion", "wow64"];
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export const MBOX_EDGE_CLUSTER = "mboxEdgeCluster";
13
+ export const AT_QA_MODE = "at_qa_mode";
14
+ export const MBOX = "mbox";
@@ -11,4 +11,4 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
13
13
  // see babel-plugin-version
14
- export default "2.12.0-beta.0";
14
+ export default "2.13.0-beta.0";
@@ -9,11 +9,11 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { endsWith, isNamespacedCookieName } from "../utils";
12
+ import { endsWith } from "../utils";
13
13
  const STATE_STORE_HANDLE_TYPE = "state:store";
14
14
  export default (({
15
15
  cookieJar,
16
- orgId,
16
+ shouldTransferCookie,
17
17
  apexDomain,
18
18
  dateProvider
19
19
  }) => {
@@ -34,14 +34,7 @@ export default (({
34
34
 
35
35
  if (!isEndpointFirstParty) {
36
36
  const cookies = cookieJar.get();
37
- const entries = Object.keys(cookies).filter(name => {
38
- // We have a contract with the server that we will pass
39
- // all cookies whose names are namespaced according to the
40
- // logic in isNamespacedCookieName as well as any legacy
41
- // cookie names (so that the server can handle migrating
42
- // identities on websites previously using Visitor.js)
43
- return isNamespacedCookieName(orgId, name);
44
- }).map(qualifyingCookieName => {
37
+ const entries = Object.keys(cookies).filter(shouldTransferCookie).map(qualifyingCookieName => {
45
38
  return {
46
39
  key: qualifyingCookieName,
47
40
  value: cookies[qualifyingCookieName]
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { createCallbackAggregator } from "../utils";
12
+ import { createCallbackAggregator, noop } from "../utils";
13
13
  const EVENT_CANCELLATION_MESSAGE = "Event was canceled because the onBeforeEventSend callback returned false.";
14
14
  export default (({
15
15
  config,
@@ -19,7 +19,8 @@ export default (({
19
19
  createEvent,
20
20
  createDataCollectionRequestPayload,
21
21
  createDataCollectionRequest,
22
- sendEdgeNetworkRequest
22
+ sendEdgeNetworkRequest,
23
+ applyResponse
23
24
  }) => {
24
25
  const {
25
26
  onBeforeEventSend
@@ -36,6 +37,7 @@ export default (({
36
37
  * @param {Object} [options]
37
38
  * @param {boolean} [options.renderDecisions=false]
38
39
  * @param {Array} [options.decisionScopes]
40
+ * @param {Object} [options.serverState]
39
41
  * This will be passed to components
40
42
  * so they can take appropriate action.
41
43
  * @returns {*}
@@ -91,6 +93,34 @@ export default (({
91
93
  runOnRequestFailureCallbacks: onRequestFailureCallbackAggregator.call
92
94
  });
93
95
  });
96
+ },
97
+
98
+ applyResponse(event, options = {}) {
99
+ const {
100
+ renderDecisions = false,
101
+ responseHeaders = {},
102
+ responseBody = {
103
+ handle: []
104
+ }
105
+ } = options;
106
+ const payload = createDataCollectionRequestPayload();
107
+ const request = createDataCollectionRequest(payload);
108
+ const onResponseCallbackAggregator = createCallbackAggregator();
109
+ return lifecycle.onBeforeEvent({
110
+ event,
111
+ renderDecisions,
112
+ decisionScopes: [],
113
+ onResponse: onResponseCallbackAggregator.add,
114
+ onRequestFailure: noop
115
+ }).then(() => {
116
+ payload.addEvent(event);
117
+ return applyResponse({
118
+ request,
119
+ responseHeaders,
120
+ responseBody,
121
+ runOnResponseCallbacks: onResponseCallbackAggregator.call
122
+ });
123
+ });
94
124
  }
95
125
 
96
126
  };
@@ -0,0 +1,14 @@
1
+ export default (onRequestFailureCallbackAggregator => {
2
+ return error => {
3
+ // Regardless of whether the network call failed, an unexpected status
4
+ // code was returned, or the response body was malformed, we want to call
5
+ // the onRequestFailure callbacks, but still throw the exception.
6
+ const throwError = () => {
7
+ throw error;
8
+ };
9
+
10
+ return onRequestFailureCallbackAggregator.call({
11
+ error
12
+ }).then(throwError, throwError);
13
+ };
14
+ });
@@ -0,0 +1,48 @@
1
+ import { createCallbackAggregator, noop } from "../../utils";
2
+ import mergeLifecycleResponses from "./mergeLifecycleResponses";
3
+ import handleRequestFailure from "./handleRequestFailure";
4
+ const HTTP_STATUS_OK = 200;
5
+ export default (({
6
+ cookieTransfer,
7
+ lifecycle,
8
+ createResponse,
9
+ processWarningsAndErrors
10
+ }) => {
11
+ return ({
12
+ request,
13
+ responseHeaders,
14
+ responseBody,
15
+ runOnResponseCallbacks = noop,
16
+ runOnRequestFailureCallbacks = noop
17
+ }) => {
18
+ const onResponseCallbackAggregator = createCallbackAggregator();
19
+ onResponseCallbackAggregator.add(lifecycle.onResponse);
20
+ onResponseCallbackAggregator.add(runOnResponseCallbacks);
21
+ const onRequestFailureCallbackAggregator = createCallbackAggregator();
22
+ onRequestFailureCallbackAggregator.add(lifecycle.onRequestFailure);
23
+ onRequestFailureCallbackAggregator.add(runOnRequestFailureCallbacks);
24
+
25
+ const getHeader = key => responseHeaders[key];
26
+
27
+ return lifecycle.onBeforeRequest({
28
+ request,
29
+ onResponse: onResponseCallbackAggregator.add,
30
+ onRequestFailure: onRequestFailureCallbackAggregator.add
31
+ }).then(() => processWarningsAndErrors({
32
+ statusCode: HTTP_STATUS_OK,
33
+ getHeader,
34
+ body: JSON.stringify(responseBody),
35
+ parsedBody: responseBody
36
+ })).catch(handleRequestFailure(onRequestFailureCallbackAggregator)).then(() => {
37
+ const response = createResponse({
38
+ content: responseBody,
39
+ getHeader
40
+ }); // This will clobber any cookies set via HTTP from the server. So care should be given to remove any state:store handles if that is not desirable
41
+
42
+ cookieTransfer.responseToCookies(response);
43
+ return onResponseCallbackAggregator.call({
44
+ response
45
+ }).then(mergeLifecycleResponses);
46
+ });
47
+ };
48
+ });
@@ -11,10 +11,26 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  import { getNamespacedCookieName } from "../../utils";
13
13
  import { CLUSTER } from "../../constants/cookieNameKey";
14
+ import { MBOX_EDGE_CLUSTER } from "../../constants/legacyCookies";
14
15
  export default (({
15
16
  orgId,
16
17
  cookieJar
17
18
  }) => {
18
19
  const clusterCookieName = getNamespacedCookieName(orgId, CLUSTER);
19
- return () => cookieJar.get(clusterCookieName);
20
+
21
+ const fromClusterCookie = () => cookieJar.get(clusterCookieName);
22
+
23
+ const fromTarget = () => {
24
+ const mboxEdgeCluster = cookieJar.get(MBOX_EDGE_CLUSTER);
25
+
26
+ if (mboxEdgeCluster) {
27
+ return `t${mboxEdgeCluster}`;
28
+ }
29
+
30
+ return undefined;
31
+ };
32
+
33
+ return () => {
34
+ return fromClusterCookie() || fromTarget();
35
+ };
20
36
  });
@@ -11,7 +11,9 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  import { ID_THIRD_PARTY as ID_THIRD_PARTY_DOMAIN } from "../../constants/domain";
13
13
  import apiVersion from "../../constants/apiVersion";
14
- import { createCallbackAggregator, noop, assign } from "../../utils";
14
+ import { createCallbackAggregator, noop } from "../../utils";
15
+ import mergeLifecycleResponses from "./mergeLifecycleResponses";
16
+ import handleRequestFailure from "./handleRequestFailure";
15
17
  export default (({
16
18
  config,
17
19
  lifecycle,
@@ -61,18 +63,7 @@ export default (({
61
63
  }).then(networkResponse => {
62
64
  processWarningsAndErrors(networkResponse);
63
65
  return networkResponse;
64
- }).catch(error => {
65
- // Regardless of whether the network call failed, an unexpected status
66
- // code was returned, or the response body was malformed, we want to call
67
- // the onRequestFailure callbacks, but still throw the exception.
68
- const throwError = () => {
69
- throw error;
70
- };
71
-
72
- return onRequestFailureCallbackAggregator.call({
73
- error
74
- }).then(throwError, throwError);
75
- }).then(({
66
+ }).catch(handleRequestFailure(onRequestFailureCallbackAggregator)).then(({
76
67
  parsedBody,
77
68
  getHeader
78
69
  }) => {
@@ -89,14 +80,7 @@ export default (({
89
80
 
90
81
  return onResponseCallbackAggregator.call({
91
82
  response
92
- }).then(returnValues => {
93
- // Merges all returned objects from all `onResponse` callbacks into
94
- // a single object that can later be returned to the customer.
95
- const lifecycleOnResponseReturnValues = returnValues.shift() || [];
96
- const consumerOnResponseReturnValues = returnValues.shift() || [];
97
- const lifecycleOnBeforeRequestReturnValues = returnValues;
98
- return assign({}, ...lifecycleOnResponseReturnValues, ...consumerOnResponseReturnValues, ...lifecycleOnBeforeRequestReturnValues);
99
- });
83
+ }).then(mergeLifecycleResponses);
100
84
  });
101
85
  };
102
86
  });
@@ -0,0 +1,9 @@
1
+ import { assign } from "../../utils";
2
+ export default (returnValues => {
3
+ // Merges all returned objects from all `onResponse` callbacks into
4
+ // a single object that can later be returned to the customer.
5
+ const lifecycleOnResponseReturnValues = returnValues.shift() || [];
6
+ const consumerOnResponseReturnValues = returnValues.shift() || [];
7
+ const lifecycleOnBeforeRequestReturnValues = returnValues;
8
+ return assign({}, ...lifecycleOnResponseReturnValues, ...consumerOnResponseReturnValues, ...lifecycleOnBeforeRequestReturnValues);
9
+ });
@@ -34,12 +34,14 @@ import injectSendBeaconRequest from "./network/requestMethods/injectSendBeaconRe
34
34
  import createLogger from "./createLogger";
35
35
  import createEventManager from "./createEventManager";
36
36
  import createCookieTransfer from "./createCookieTransfer";
37
+ import injectShouldTransferCookie from "./injectShouldTransferCookie";
37
38
  import { createDataCollectionRequest, createDataCollectionRequestPayload } from "../utils/request";
38
39
  import injectSendEdgeNetworkRequest from "./edgeNetwork/injectSendEdgeNetworkRequest";
39
40
  import injectProcessWarningsAndErrors from "./edgeNetwork/injectProcessWarningsAndErrors";
40
41
  import injectGetLocationHint from "./edgeNetwork/injectGetLocationHint";
41
42
  import isRequestRetryable from "./network/isRequestRetryable";
42
43
  import getRequestRetryDelay from "./network/getRequestRetryDelay";
44
+ import injectApplyResponse from "./edgeNetwork/injectApplyResponse";
43
45
  const createNamespacedStorage = injectStorage(window);
44
46
  const {
45
47
  console,
@@ -91,11 +93,16 @@ export const createExecuteCommand = ({
91
93
  setDebugEnabled
92
94
  });
93
95
  const {
94
- orgId
96
+ orgId,
97
+ targetMigrationEnabled
95
98
  } = config;
99
+ const shouldTransferCookie = injectShouldTransferCookie({
100
+ orgId,
101
+ targetMigrationEnabled
102
+ });
96
103
  const cookieTransfer = createCookieTransfer({
97
104
  cookieJar: loggingCookieJar,
98
- orgId,
105
+ shouldTransferCookie,
99
106
  apexDomain,
100
107
  dateProvider: () => new Date()
101
108
  });
@@ -135,6 +142,12 @@ export const createExecuteCommand = ({
135
142
  processWarningsAndErrors,
136
143
  getLocationHint
137
144
  });
145
+ const applyResponse = injectApplyResponse({
146
+ lifecycle,
147
+ cookieTransfer,
148
+ createResponse,
149
+ processWarningsAndErrors
150
+ });
138
151
  const generalConsentState = createConsentStateMachine({
139
152
  logger
140
153
  });
@@ -150,7 +163,8 @@ export const createExecuteCommand = ({
150
163
  createEvent,
151
164
  createDataCollectionRequestPayload,
152
165
  createDataCollectionRequest,
153
- sendEdgeNetworkRequest
166
+ sendEdgeNetworkRequest,
167
+ applyResponse
154
168
  });
155
169
  return initializeComponents({
156
170
  componentCreators,