@adobe/alloy 2.19.0-beta.2 → 2.19.0-beta.3

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.
@@ -84,6 +84,10 @@ var _default = function _default(_ref) {
84
84
  _ref4$metadata = _ref4.metadata,
85
85
  metadata = _ref4$metadata === void 0 ? {} : _ref4$metadata,
86
86
  viewName = _ref4.viewName;
87
+ // We need to immediately call concat so that subsequent sendEvent
88
+ // calls will wait for applyPropositions to complete before executing.
89
+ var displayNotificationsDeferred = (0, _utils.defer)();
90
+ pendingDisplayNotifications.concat(displayNotificationsDeferred.promise);
87
91
  var propositionsToExecute = preparePropositions({
88
92
  propositions: propositions,
89
93
  metadata: metadata
@@ -99,7 +103,7 @@ var _default = function _default(_ref) {
99
103
  var _processPropositions = processPropositions([].concat(_toConsumableArray(propositionsToExecute), _toConsumableArray(additionalPropositions))),
100
104
  render = _processPropositions.render,
101
105
  returnedPropositions = _processPropositions.returnedPropositions;
102
- pendingDisplayNotifications.concat(render());
106
+ render().then(displayNotificationsDeferred.resolve);
103
107
  return {
104
108
  propositions: returnedPropositions
105
109
  };
@@ -5,6 +5,7 @@ var _utils = require("../../utils");
5
5
  var _createPersonalizationDetails = require("./createPersonalizationDetails");
6
6
  var _loggerMessage = require("./constants/loggerMessage");
7
7
  var _validateApplyPropositionsOptions = require("./validateApplyPropositionsOptions");
8
+ var _propositionEventType = require("./constants/propositionEventType");
8
9
  /*
9
10
  Copyright 2020 Adobe. All rights reserved.
10
11
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -28,7 +29,8 @@ var _default = function _default(_ref) {
28
29
  showContainers = _ref.showContainers,
29
30
  applyPropositions = _ref.applyPropositions,
30
31
  setTargetMigration = _ref.setTargetMigration,
31
- pendingNotificationsHandler = _ref.pendingNotificationsHandler;
32
+ mergeDecisionsMeta = _ref.mergeDecisionsMeta,
33
+ pendingDisplayNotifications = _ref.pendingDisplayNotifications;
32
34
  return {
33
35
  lifecycle: {
34
36
  onBeforeRequest: function onBeforeRequest(_ref2) {
@@ -74,11 +76,9 @@ var _default = function _default(_ref) {
74
76
  isCacheInitialized: viewCache.isInitialized(),
75
77
  logger: logger
76
78
  });
77
- var handlerPromises = [];
79
+ var decisionsMetaPromises = [];
78
80
  if (personalizationDetails.shouldAddPendingDisplayNotifications()) {
79
- handlerPromises.push(pendingNotificationsHandler({
80
- event: event
81
- }));
81
+ decisionsMetaPromises.push(pendingDisplayNotifications.clear());
82
82
  }
83
83
  if (personalizationDetails.shouldFetchData()) {
84
84
  var cacheUpdate = viewCache.createCacheUpdate(personalizationDetails.getViewName());
@@ -93,16 +93,24 @@ var _default = function _default(_ref) {
93
93
  });
94
94
  } else if (personalizationDetails.shouldUseCachedData()) {
95
95
  // eslint-disable-next-line consistent-return
96
- handlerPromises.push(viewChangeHandler({
96
+ decisionsMetaPromises.push(viewChangeHandler({
97
97
  personalizationDetails: personalizationDetails,
98
98
  event: event,
99
99
  onResponse: onResponse,
100
100
  onRequestFailure: onRequestFailure
101
101
  }));
102
102
  }
103
- // We can wait for personalization to be applied and for
104
- // the fetch data request to complete in parallel.
105
- return Promise.all(handlerPromises);
103
+
104
+ // This promise.all waits for both the pending display notifications to be resolved
105
+ // (i.e. the top of page call to finish rendering) and the view change handler to
106
+ // finish rendering anything for this view.
107
+ return Promise.all(decisionsMetaPromises).then(function (decisionsMetas) {
108
+ // We only want to call mergeDecisionsMeta once, but we can get the propositions
109
+ // from two places: the pending display notifications and the view change handler.
110
+ mergeDecisionsMeta(event, (0, _utils.flatMap)(decisionsMetas, function (dms) {
111
+ return dms;
112
+ }), _propositionEventType.PropositionEventType.DISPLAY);
113
+ });
106
114
  },
107
115
  onClick: function onClick(_ref4) {
108
116
  var event = _ref4.event,
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  exports.default = void 0;
4
- var _propositionEventType = require("./constants/propositionEventType");
5
4
  /*
6
5
  Copyright 2020 Adobe. All rights reserved.
7
6
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -14,12 +13,10 @@ OF ANY KIND, either express or implied. See the License for the specific languag
14
13
  governing permissions and limitations under the License.
15
14
  */
16
15
  var _default = function _default(_ref) {
17
- var mergeDecisionsMeta = _ref.mergeDecisionsMeta,
18
- processPropositions = _ref.processPropositions,
16
+ var processPropositions = _ref.processPropositions,
19
17
  viewCache = _ref.viewCache;
20
18
  return function (_ref2) {
21
19
  var personalizationDetails = _ref2.personalizationDetails,
22
- event = _ref2.event,
23
20
  onResponse = _ref2.onResponse;
24
21
  var returnedPropositions;
25
22
  var returnedDecisions;
@@ -43,8 +40,6 @@ var _default = function _default(_ref) {
43
40
  returnedPropositions = _processPropositions2.returnedPropositions;
44
41
  returnedDecisions = _processPropositions2.returnedDecisions;
45
42
  return [];
46
- }).then(function (decisionsMeta) {
47
- mergeDecisionsMeta(event, decisionsMeta, _propositionEventType.PropositionEventType.DISPLAY);
48
43
  });
49
44
  };
50
45
  };
@@ -21,6 +21,11 @@ var EVENT_TYPE_TRUE = 1;
21
21
  /* eslint-disable no-underscore-dangle */
22
22
  var mergeDecisionsMeta = function mergeDecisionsMeta(event, decisionsMeta, eventType) {
23
23
  var eventLabel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
24
+ // Do not send a display notification with no decisions. Even empty view changes
25
+ // should include a proposition.
26
+ if (decisionsMeta.length === 0) {
27
+ return;
28
+ }
24
29
  var xdm = {
25
30
  _experience: {
26
31
  decisioning: {
@@ -22,7 +22,6 @@ var _remapHeadOffers = require("./dom-actions/remapHeadOffers");
22
22
  var _createPreprocess = require("./dom-actions/createPreprocess");
23
23
  var _injectCreateProposition = require("./handlers/injectCreateProposition");
24
24
  var _createAsyncArray = require("./utils/createAsyncArray");
25
- var _createPendingNotificationsHandler = require("./createPendingNotificationsHandler");
26
25
  var schema = require("./constants/schema");
27
26
  var _processDefaultContent = require("./handlers/processDefaultContent");
28
27
  var _surfaceUtils = require("./utils/surfaceUtils");
@@ -87,10 +86,6 @@ var createPersonalization = function createPersonalization(_ref) {
87
86
  logger: logger
88
87
  });
89
88
  var pendingDisplayNotifications = (0, _createAsyncArray.default)();
90
- var pendingNotificationsHandler = (0, _createPendingNotificationsHandler.default)({
91
- pendingDisplayNotifications: pendingDisplayNotifications,
92
- mergeDecisionsMeta: _event.mergeDecisionsMeta
93
- });
94
89
  var fetchDataHandler = (0, _createFetchDataHandler.default)({
95
90
  prehidingStyle: prehidingStyle,
96
91
  showContainers: _flicker.showContainers,
@@ -108,7 +103,6 @@ var createPersonalization = function createPersonalization(_ref) {
108
103
  getClickMetasBySelector: getClickMetasBySelector
109
104
  });
110
105
  var viewChangeHandler = (0, _createViewChangeHandler.default)({
111
- mergeDecisionsMeta: _event.mergeDecisionsMeta,
112
106
  processPropositions: processPropositions,
113
107
  viewCache: viewCache
114
108
  });
@@ -133,7 +127,8 @@ var createPersonalization = function createPersonalization(_ref) {
133
127
  showContainers: _flicker.showContainers,
134
128
  applyPropositions: applyPropositions,
135
129
  setTargetMigration: setTargetMigration,
136
- pendingNotificationsHandler: pendingNotificationsHandler
130
+ mergeDecisionsMeta: _event.mergeDecisionsMeta,
131
+ pendingDisplayNotifications: pendingDisplayNotifications
137
132
  });
138
133
  };
139
134
  createPersonalization.namespace = "Personalization";
@@ -14,5 +14,5 @@ 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 = "2.19.0-beta.2";
17
+ var _default = "2.19.0-beta.3";
18
18
  exports.default = _default;
@@ -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
 
13
- import { isNonEmptyArray, isObject } from "../../utils";
13
+ import { isNonEmptyArray, isObject, defer } from "../../utils";
14
14
  import { DOM_ACTION, HTML_CONTENT_ITEM } from "./constants/schema";
15
15
  import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
16
16
  const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];
@@ -76,6 +76,10 @@ export default (({
76
76
  metadata = {},
77
77
  viewName
78
78
  }) => {
79
+ // We need to immediately call concat so that subsequent sendEvent
80
+ // calls will wait for applyPropositions to complete before executing.
81
+ const displayNotificationsDeferred = defer();
82
+ pendingDisplayNotifications.concat(displayNotificationsDeferred.promise);
79
83
  const propositionsToExecute = preparePropositions({
80
84
  propositions,
81
85
  metadata
@@ -90,7 +94,7 @@ export default (({
90
94
  render,
91
95
  returnedPropositions
92
96
  } = processPropositions([...propositionsToExecute, ...additionalPropositions]);
93
- pendingDisplayNotifications.concat(render());
97
+ render().then(displayNotificationsDeferred.resolve);
94
98
  return {
95
99
  propositions: returnedPropositions
96
100
  };
@@ -10,10 +10,11 @@ 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
 
13
- import { noop } from "../../utils";
13
+ import { noop, flatMap } from "../../utils";
14
14
  import createPersonalizationDetails from "./createPersonalizationDetails";
15
15
  import { AUTHORING_ENABLED } from "./constants/loggerMessage";
16
16
  import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
17
+ import { PropositionEventType } from "./constants/propositionEventType";
17
18
  export default (({
18
19
  getPageLocation,
19
20
  logger,
@@ -26,7 +27,8 @@ export default (({
26
27
  showContainers,
27
28
  applyPropositions,
28
29
  setTargetMigration,
29
- pendingNotificationsHandler
30
+ mergeDecisionsMeta,
31
+ pendingDisplayNotifications
30
32
  }) => {
31
33
  return {
32
34
  lifecycle: {
@@ -67,11 +69,9 @@ export default (({
67
69
  isCacheInitialized: viewCache.isInitialized(),
68
70
  logger
69
71
  });
70
- const handlerPromises = [];
72
+ const decisionsMetaPromises = [];
71
73
  if (personalizationDetails.shouldAddPendingDisplayNotifications()) {
72
- handlerPromises.push(pendingNotificationsHandler({
73
- event
74
- }));
74
+ decisionsMetaPromises.push(pendingDisplayNotifications.clear());
75
75
  }
76
76
  if (personalizationDetails.shouldFetchData()) {
77
77
  const cacheUpdate = viewCache.createCacheUpdate(personalizationDetails.getViewName());
@@ -84,16 +84,22 @@ export default (({
84
84
  });
85
85
  } else if (personalizationDetails.shouldUseCachedData()) {
86
86
  // eslint-disable-next-line consistent-return
87
- handlerPromises.push(viewChangeHandler({
87
+ decisionsMetaPromises.push(viewChangeHandler({
88
88
  personalizationDetails,
89
89
  event,
90
90
  onResponse,
91
91
  onRequestFailure
92
92
  }));
93
93
  }
94
- // We can wait for personalization to be applied and for
95
- // the fetch data request to complete in parallel.
96
- return Promise.all(handlerPromises);
94
+
95
+ // This promise.all waits for both the pending display notifications to be resolved
96
+ // (i.e. the top of page call to finish rendering) and the view change handler to
97
+ // finish rendering anything for this view.
98
+ return Promise.all(decisionsMetaPromises).then(decisionsMetas => {
99
+ // We only want to call mergeDecisionsMeta once, but we can get the propositions
100
+ // from two places: the pending display notifications and the view change handler.
101
+ mergeDecisionsMeta(event, flatMap(decisionsMetas, dms => dms), PropositionEventType.DISPLAY);
102
+ });
97
103
  },
98
104
  onClick({
99
105
  event,
@@ -10,15 +10,12 @@ 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
 
13
- import { PropositionEventType } from "./constants/propositionEventType";
14
13
  export default (({
15
- mergeDecisionsMeta,
16
14
  processPropositions,
17
15
  viewCache
18
16
  }) => {
19
17
  return ({
20
18
  personalizationDetails,
21
- event,
22
19
  onResponse
23
20
  }) => {
24
21
  let returnedPropositions;
@@ -45,8 +42,6 @@ export default (({
45
42
  returnedDecisions
46
43
  } = processPropositions([], propositions));
47
44
  return [];
48
- }).then(decisionsMeta => {
49
- mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
50
45
  });
51
46
  };
52
47
  });
@@ -14,6 +14,11 @@ const EVENT_TYPE_TRUE = 1;
14
14
 
15
15
  /* eslint-disable no-underscore-dangle */
16
16
  export const mergeDecisionsMeta = (event, decisionsMeta, eventType, eventLabel = "") => {
17
+ // Do not send a display notification with no decisions. Even empty view changes
18
+ // should include a proposition.
19
+ if (decisionsMeta.length === 0) {
20
+ return;
21
+ }
17
22
  const xdm = {
18
23
  _experience: {
19
24
  decisioning: {
@@ -31,7 +31,6 @@ import remapHeadOffers from "./dom-actions/remapHeadOffers";
31
31
  import createPreprocess from "./dom-actions/createPreprocess";
32
32
  import injectCreateProposition from "./handlers/injectCreateProposition";
33
33
  import createAsyncArray from "./utils/createAsyncArray";
34
- import createPendingNotificationsHandler from "./createPendingNotificationsHandler";
35
34
  import * as schema from "./constants/schema";
36
35
  import processDefaultContent from "./handlers/processDefaultContent";
37
36
  import { isPageWideSurface } from "./utils/surfaceUtils";
@@ -91,10 +90,6 @@ const createPersonalization = ({
91
90
  logger
92
91
  });
93
92
  const pendingDisplayNotifications = createAsyncArray();
94
- const pendingNotificationsHandler = createPendingNotificationsHandler({
95
- pendingDisplayNotifications,
96
- mergeDecisionsMeta
97
- });
98
93
  const fetchDataHandler = createFetchDataHandler({
99
94
  prehidingStyle,
100
95
  showContainers,
@@ -112,7 +107,6 @@ const createPersonalization = ({
112
107
  getClickMetasBySelector
113
108
  });
114
109
  const viewChangeHandler = createViewChangeHandler({
115
- mergeDecisionsMeta,
116
110
  processPropositions,
117
111
  viewCache
118
112
  });
@@ -137,7 +131,8 @@ const createPersonalization = ({
137
131
  showContainers,
138
132
  applyPropositions,
139
133
  setTargetMigration,
140
- pendingNotificationsHandler
134
+ mergeDecisionsMeta,
135
+ pendingDisplayNotifications
141
136
  });
142
137
  };
143
138
  createPersonalization.namespace = "Personalization";
@@ -13,4 +13,4 @@ governing permissions and limitations under the License.
13
13
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
14
14
  // see babel-plugin-version
15
15
 
16
- export default "2.19.0-beta.2";
16
+ export default "2.19.0-beta.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.19.0-beta.2",
3
+ "version": "2.19.0-beta.3",
4
4
  "description": "Adobe Experience Platform Web SDK",
5
5
  "main": "libEs5/index.js",
6
6
  "module": "libEs6/index.js",
@@ -66,7 +66,7 @@
66
66
  "uuid": "^3.3.2"
67
67
  },
68
68
  "devDependencies": {
69
- "@adobe/alloy": "^2.19.0-beta.1",
69
+ "@adobe/alloy": "^2.19.0-beta.2",
70
70
  "@babel/cli": "^7.12.8",
71
71
  "@babel/core": "^7.2.2",
72
72
  "@babel/plugin-proposal-object-rest-spread": "^7.3.2",
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- exports.default = void 0;
4
- var _propositionEventType = require("./constants/propositionEventType");
5
- /*
6
- Copyright 2023 Adobe. All rights reserved.
7
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
- you may not use this file except in compliance with the License. You may obtain a copy
9
- of the License at http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software distributed under
12
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
- OF ANY KIND, either express or implied. See the License for the specific language
14
- governing permissions and limitations under the License.
15
- */
16
- var _default = function _default(_ref) {
17
- var pendingDisplayNotifications = _ref.pendingDisplayNotifications,
18
- mergeDecisionsMeta = _ref.mergeDecisionsMeta;
19
- return function (_ref2) {
20
- var event = _ref2.event;
21
- return pendingDisplayNotifications.clear().then(function (decisionsMeta) {
22
- mergeDecisionsMeta(event, decisionsMeta, _propositionEventType.PropositionEventType.DISPLAY);
23
- });
24
- };
25
- };
26
- exports.default = _default;
@@ -1,22 +0,0 @@
1
- /*
2
- Copyright 2023 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 { PropositionEventType } from "./constants/propositionEventType";
13
- export default (({
14
- pendingDisplayNotifications,
15
- mergeDecisionsMeta
16
- }) => ({
17
- event
18
- }) => {
19
- return pendingDisplayNotifications.clear().then(decisionsMeta => {
20
- mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
21
- });
22
- });