@adobe/alloy 2.14.0-alpha.0 → 2.14.0-alpha.2

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 (27) hide show
  1. package/libEs5/components/DataCollector/index.js +4 -1
  2. package/libEs5/components/DataCollector/validateUserEventOptions.js +4 -0
  3. package/libEs5/components/Personalization/constants/surface.js +23 -0
  4. package/libEs5/components/Personalization/createComponent.js +8 -2
  5. package/libEs5/components/Personalization/createGetPageLocation.js +23 -0
  6. package/libEs5/components/Personalization/createPersonalizationDetails.js +44 -10
  7. package/libEs5/components/Personalization/groupDecisions.js +3 -3
  8. package/libEs5/components/Personalization/index.js +6 -0
  9. package/libEs5/components/Personalization/utils/isPageWideScope.js +24 -0
  10. package/libEs5/components/Personalization/utils/surfaceUtils.js +128 -0
  11. package/libEs5/constants/libraryVersion.js +1 -1
  12. package/libEs5/core/createEventManager.js +7 -2
  13. package/libEs5/utils/isNil.js +1 -1
  14. package/libEs6/components/DataCollector/index.js +4 -1
  15. package/libEs6/components/DataCollector/validateUserEventOptions.js +4 -0
  16. package/libEs6/components/Personalization/constants/surface.js +15 -0
  17. package/libEs6/components/Personalization/createComponent.js +6 -1
  18. package/libEs6/components/Personalization/createGetPageLocation.js +16 -0
  19. package/libEs6/components/Personalization/createPersonalizationDetails.js +40 -8
  20. package/libEs6/components/Personalization/groupDecisions.js +2 -2
  21. package/libEs6/components/Personalization/index.js +5 -0
  22. package/libEs6/components/Personalization/utils/isPageWideScope.js +14 -0
  23. package/libEs6/components/Personalization/utils/surfaceUtils.js +93 -0
  24. package/libEs6/constants/libraryVersion.js +1 -1
  25. package/libEs6/core/createEventManager.js +7 -2
  26. package/libEs6/utils/isNil.js +1 -1
  27. package/package.json +2 -2
@@ -39,6 +39,8 @@ var createDataCollector = function createDataCollector(_ref) {
39
39
  renderDecisions = _options$renderDecisi === void 0 ? false : _options$renderDecisi,
40
40
  _options$decisionScop = options.decisionScopes,
41
41
  decisionScopes = _options$decisionScop === void 0 ? [] : _options$decisionScop,
42
+ _options$personalizat = options.personalization,
43
+ personalization = _options$personalizat === void 0 ? {} : _options$personalizat,
42
44
  datasetId = options.datasetId;
43
45
  var event = eventManager.createEvent();
44
46
 
@@ -71,7 +73,8 @@ var createDataCollector = function createDataCollector(_ref) {
71
73
 
72
74
  return eventManager.sendEvent(event, {
73
75
  renderDecisions: renderDecisions,
74
- decisionScopes: decisionScopes
76
+ decisionScopes: decisionScopes,
77
+ personalization: personalization
75
78
  });
76
79
  }
77
80
  },
@@ -35,6 +35,10 @@ var _default = function _default(_ref) {
35
35
  documentUnloading: (0, _validation.boolean)(),
36
36
  renderDecisions: (0, _validation.boolean)(),
37
37
  decisionScopes: (0, _validation.arrayOf)((0, _validation.string)()).uniqueItems(),
38
+ personalization: (0, _validation.objectOf)({
39
+ decisionScopes: (0, _validation.arrayOf)((0, _validation.string)()).uniqueItems(),
40
+ surfaces: (0, _validation.arrayOf)((0, _validation.string)()).uniqueItems()
41
+ }),
38
42
  datasetId: (0, _validation.string)(),
39
43
  mergeId: (0, _validation.string)()
40
44
  }).required().noUnknownFields();
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ exports.WEBAPP = exports.WEB = exports.SURFACE_TYPE_DELIMITER = exports.FRAGMENT_DELIMITER = void 0;
4
+
5
+ /*
6
+ Copyright 2022 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 WEB = "web";
17
+ exports.WEB = WEB;
18
+ var WEBAPP = "webapp";
19
+ exports.WEBAPP = WEBAPP;
20
+ var SURFACE_TYPE_DELIMITER = "://";
21
+ exports.SURFACE_TYPE_DELIMITER = SURFACE_TYPE_DELIMITER;
22
+ var FRAGMENT_DELIMITER = "#";
23
+ exports.FRAGMENT_DELIMITER = FRAGMENT_DELIMITER;
@@ -22,7 +22,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
22
22
  governing permissions and limitations under the License.
23
23
  */
24
24
  var _default = function _default(_ref) {
25
- var logger = _ref.logger,
25
+ var getPageLocation = _ref.getPageLocation,
26
+ logger = _ref.logger,
26
27
  fetchDataHandler = _ref.fetchDataHandler,
27
28
  viewChangeHandler = _ref.viewChangeHandler,
28
29
  onClickHandler = _ref.onClickHandler,
@@ -44,6 +45,8 @@ var _default = function _default(_ref) {
44
45
  renderDecisions = _ref3.renderDecisions,
45
46
  _ref3$decisionScopes = _ref3.decisionScopes,
46
47
  decisionScopes = _ref3$decisionScopes === void 0 ? [] : _ref3$decisionScopes,
48
+ _ref3$personalization = _ref3.personalization,
49
+ personalization = _ref3$personalization === void 0 ? {} : _ref3$personalization,
47
50
  _ref3$onResponse = _ref3.onResponse,
48
51
  onResponse = _ref3$onResponse === void 0 ? _utils.noop : _ref3$onResponse,
49
52
  _ref3$onRequestFailur = _ref3.onRequestFailure,
@@ -68,10 +71,13 @@ var _default = function _default(_ref) {
68
71
  }
69
72
 
70
73
  var personalizationDetails = (0, _createPersonalizationDetails.default)({
74
+ getPageLocation: getPageLocation,
71
75
  renderDecisions: renderDecisions,
72
76
  decisionScopes: decisionScopes,
77
+ personalization: personalization,
73
78
  event: event,
74
- viewCache: viewCache
79
+ viewCache: viewCache,
80
+ logger: logger
75
81
  });
76
82
 
77
83
  if (personalizationDetails.shouldFetchData()) {
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+
5
+ /*
6
+ Copyright 2022 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 window = _ref.window;
18
+ return function () {
19
+ return window.location;
20
+ };
21
+ };
22
+
23
+ exports.default = _default;
@@ -4,12 +4,12 @@ exports.default = void 0;
4
4
 
5
5
  var _utils = require("../../utils");
6
6
 
7
+ var _surfaceUtils = require("./utils/surfaceUtils");
8
+
7
9
  var _pageWideScope = require("../../constants/pageWideScope");
8
10
 
9
11
  var _schema = require("./constants/schema");
10
12
 
11
- var _isNonEmptyString = require("../../utils/isNonEmptyString");
12
-
13
13
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
14
14
 
15
15
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -22,11 +22,34 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
22
22
 
23
23
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
24
24
 
25
+ var addPageWideScope = function addPageWideScope(scopes) {
26
+ if (!(0, _utils.includes)(scopes, _pageWideScope.default)) {
27
+ scopes.push(_pageWideScope.default);
28
+ }
29
+ };
30
+
31
+ var addPageSurface = function addPageSurface(surfaces, getPageLocation) {
32
+ var pageSurface = (0, _surfaceUtils.buildPageSurface)(getPageLocation);
33
+
34
+ if (!(0, _utils.includes)(surfaces, pageSurface)) {
35
+ surfaces.push(pageSurface);
36
+ }
37
+ };
38
+
39
+ var dedupe = function dedupe(array) {
40
+ return array.filter(function (item, pos) {
41
+ return array.indexOf(item) === pos;
42
+ });
43
+ };
44
+
25
45
  var _default = function _default(_ref) {
26
- var renderDecisions = _ref.renderDecisions,
46
+ var getPageLocation = _ref.getPageLocation,
47
+ renderDecisions = _ref.renderDecisions,
27
48
  decisionScopes = _ref.decisionScopes,
49
+ personalization = _ref.personalization,
28
50
  event = _ref.event,
29
- viewCache = _ref.viewCache;
51
+ viewCache = _ref.viewCache,
52
+ logger = _ref.logger;
30
53
  var viewName = event.getViewName();
31
54
  return {
32
55
  isRenderDecisions: function isRenderDecisions() {
@@ -36,16 +59,26 @@ var _default = function _default(_ref) {
36
59
  return viewName;
37
60
  },
38
61
  hasScopes: function hasScopes() {
39
- return decisionScopes.length > 0;
62
+ return decisionScopes.length > 0 || (0, _utils.isNonEmptyArray)(personalization.decisionScopes);
63
+ },
64
+ hasSurfaces: function hasSurfaces() {
65
+ return (0, _utils.isNonEmptyArray)(personalization.surfaces);
40
66
  },
41
67
  hasViewName: function hasViewName() {
42
- return (0, _isNonEmptyString.default)(viewName);
68
+ return (0, _utils.isNonEmptyString)(viewName);
43
69
  },
44
70
  createQueryDetails: function createQueryDetails() {
45
71
  var scopes = _toConsumableArray(decisionScopes);
46
72
 
47
- if (!this.isCacheInitialized() && !(0, _utils.includes)(scopes, _pageWideScope.default)) {
48
- scopes.push(_pageWideScope.default);
73
+ if ((0, _utils.isNonEmptyArray)(personalization.decisionScopes)) {
74
+ scopes.push.apply(scopes, _toConsumableArray(personalization.decisionScopes));
75
+ }
76
+
77
+ var eventSurfaces = (0, _surfaceUtils.normalizeSurfaces)(personalization.surfaces, getPageLocation, logger);
78
+
79
+ if (!this.isCacheInitialized()) {
80
+ addPageWideScope(scopes);
81
+ addPageSurface(eventSurfaces, getPageLocation);
49
82
  }
50
83
 
51
84
  var schemas = [_schema.DEFAULT_CONTENT_ITEM, _schema.HTML_CONTENT_ITEM, _schema.JSON_CONTENT_ITEM, _schema.REDIRECT_ITEM];
@@ -56,14 +89,15 @@ var _default = function _default(_ref) {
56
89
 
57
90
  return {
58
91
  schemas: schemas,
59
- decisionScopes: scopes
92
+ decisionScopes: dedupe(scopes),
93
+ surfaces: dedupe(eventSurfaces)
60
94
  };
61
95
  },
62
96
  isCacheInitialized: function isCacheInitialized() {
63
97
  return viewCache.isInitialized();
64
98
  },
65
99
  shouldFetchData: function shouldFetchData() {
66
- return this.hasScopes() || !this.isCacheInitialized();
100
+ return this.hasScopes() || this.hasSurfaces() || !this.isCacheInitialized();
67
101
  },
68
102
  shouldUseCachedData: function shouldUseCachedData() {
69
103
  return this.hasViewName() && this.isCacheInitialized();
@@ -4,12 +4,12 @@ exports.default = void 0;
4
4
 
5
5
  var _utils = require("../../utils");
6
6
 
7
+ var _isPageWideScope = require("./utils/isPageWideScope");
8
+
7
9
  var _schema = require("./constants/schema");
8
10
 
9
11
  var _scopeType = require("./constants/scopeType");
10
12
 
11
- var _pageWideScope = require("../../constants/pageWideScope");
12
-
13
13
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
14
14
 
15
15
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -118,7 +118,7 @@ var extractDecisionsByScope = function extractDecisionsByScope(decisions) {
118
118
 
119
119
  if ((0, _utils.isNonEmptyArray)(decisions)) {
120
120
  decisions.forEach(function (decision) {
121
- if (decision.scope === _pageWideScope.default) {
121
+ if ((0, _isPageWideScope.default)(decision.scope)) {
122
122
  pageWideScopeDecisions.push(decision);
123
123
  } else if (isViewScope(decision.scopeDetails)) {
124
124
  appendScopeDecision(viewScopeDecisions, decision);
@@ -42,6 +42,8 @@ var _createNonRenderingHandler = require("./createNonRenderingHandler");
42
42
 
43
43
  var _createApplyPropositions = require("./createApplyPropositions");
44
44
 
45
+ var _createGetPageLocation = require("./createGetPageLocation");
46
+
45
47
  var _createSetTargetMigration = require("./createSetTargetMigration");
46
48
 
47
49
  /*
@@ -71,6 +73,9 @@ var createPersonalization = function createPersonalization(_ref) {
71
73
  getClickSelectors = _createClickStorage.getClickSelectors,
72
74
  storeClickMetrics = _createClickStorage.storeClickMetrics;
73
75
 
76
+ var getPageLocation = (0, _createGetPageLocation.default)({
77
+ window: window
78
+ });
74
79
  var viewCache = (0, _createViewCacheManager.default)();
75
80
  var modules = (0, _domActions.initDomActionsModules)(storeClickMetrics);
76
81
  var executeDecisions = (0, _createExecuteDecisions.default)({
@@ -125,6 +130,7 @@ var createPersonalization = function createPersonalization(_ref) {
125
130
  targetMigrationEnabled: targetMigrationEnabled
126
131
  });
127
132
  return (0, _createComponent.default)({
133
+ getPageLocation: getPageLocation,
128
134
  logger: logger,
129
135
  fetchDataHandler: fetchDataHandler,
130
136
  viewChangeHandler: viewChangeHandler,
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+
5
+ var _surfaceUtils = require("./surfaceUtils");
6
+
7
+ var _pageWideScope = require("../../../constants/pageWideScope");
8
+
9
+ /*
10
+ Copyright 2022 Adobe. All rights reserved.
11
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ you may not use this file except in compliance with the License. You may obtain a copy
13
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software distributed under
16
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ OF ANY KIND, either express or implied. See the License for the specific language
18
+ governing permissions and limitations under the License.
19
+ */
20
+ var _default = function _default(scope) {
21
+ return scope === _pageWideScope.default || (0, _surfaceUtils.isPageWideSurface)(scope);
22
+ };
23
+
24
+ exports.default = _default;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ exports.normalizeSurfaces = exports.isPageWideSurface = exports.buildPageSurface = void 0;
4
+
5
+ var _surface = require("../constants/surface");
6
+
7
+ var _utils = require("../../../utils");
8
+
9
+ /*
10
+ Copyright 2022 Adobe. All rights reserved.
11
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ you may not use this file except in compliance with the License. You may obtain a copy
13
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software distributed under
16
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ OF ANY KIND, either express or implied. See the License for the specific language
18
+ governing permissions and limitations under the License.
19
+ */
20
+ var SURFACE_REGEX = /^(\w+):\/\/([^/#]+)(\/[^#]*)?(#.*)?$/;
21
+ var AUTHORITY_REGEX = /^(?:.*@)?(?:[a-z\d\u00a1-\uffff.-]+|\[[a-f\d:]+])(?::\d+)?$/;
22
+ var PATH_REGEX = /^\/(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})*$/;
23
+ var FRAGMENT_REGEX = /^#(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})+$/;
24
+
25
+ var normalizePath = function normalizePath() {
26
+ var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "/";
27
+ var end = path.length;
28
+
29
+ while (end > 0 && "/".indexOf(path.charAt(end - 1)) !== -1) {
30
+ end -= 1;
31
+ }
32
+
33
+ return path.substring(0, end) || "/";
34
+ };
35
+
36
+ var getSurfaceType = function getSurfaceType(surfaceTypeMatch) {
37
+ return (0, _utils.isNonEmptyString)(surfaceTypeMatch) ? surfaceTypeMatch.toLowerCase() : "";
38
+ };
39
+
40
+ var getAuthority = function getAuthority(authorityMatch) {
41
+ return (0, _utils.isNonEmptyString)(authorityMatch) ? authorityMatch.toLowerCase() : "";
42
+ };
43
+
44
+ var getPath = function getPath(pathMatch) {
45
+ return (0, _utils.isNonEmptyString)(pathMatch) ? normalizePath(pathMatch) : "/";
46
+ };
47
+
48
+ var parseSurface = function parseSurface(surfaceString) {
49
+ var matched = surfaceString.match(SURFACE_REGEX);
50
+ return matched ? {
51
+ surfaceType: getSurfaceType(matched[1]),
52
+ authority: getAuthority(matched[2]),
53
+ path: getPath(matched[3]),
54
+ fragment: matched[4]
55
+ } : null;
56
+ };
57
+
58
+ var stringifySurface = function stringifySurface(surface) {
59
+ return "" + surface.surfaceType + _surface.SURFACE_TYPE_DELIMITER + surface.authority + (surface.path || "") + (surface.fragment || "");
60
+ };
61
+
62
+ var buildPageSurface = function buildPageSurface(getPageLocation) {
63
+ var location = getPageLocation();
64
+ var host = location.host.toLowerCase();
65
+ var path = location.pathname;
66
+ return _surface.WEB + _surface.SURFACE_TYPE_DELIMITER + host + normalizePath(path);
67
+ };
68
+
69
+ exports.buildPageSurface = buildPageSurface;
70
+
71
+ var expandFragmentSurface = function expandFragmentSurface(surface, getPageLocation) {
72
+ return (0, _utils.startsWith)(surface, _surface.FRAGMENT_DELIMITER) ? buildPageSurface(getPageLocation) + surface : surface;
73
+ };
74
+
75
+ var validateSurface = function validateSurface(surface, getPageLocation, logger) {
76
+ var invalidateSurface = function invalidateSurface(validationError) {
77
+ logger.warn(validationError);
78
+ return null;
79
+ };
80
+
81
+ if (!(0, _utils.isNonEmptyString)(surface)) {
82
+ return invalidateSurface("Invalid surface: " + surface);
83
+ }
84
+
85
+ var expanded = expandFragmentSurface(surface, getPageLocation);
86
+ var parsed = parseSurface(expanded);
87
+
88
+ if (parsed === null) {
89
+ return invalidateSurface("Invalid surface: " + surface);
90
+ }
91
+
92
+ if (!(0, _utils.includes)([_surface.WEB, _surface.WEBAPP], parsed.surfaceType)) {
93
+ return invalidateSurface("Unsupported surface type " + parsed.surfaceType + " in surface: " + surface);
94
+ }
95
+
96
+ if (!parsed.authority || !AUTHORITY_REGEX.test(parsed.authority)) {
97
+ return invalidateSurface("Invalid authority " + parsed.authority + " in surface: " + surface);
98
+ }
99
+
100
+ if (parsed.path && !PATH_REGEX.test(parsed.path)) {
101
+ return invalidateSurface("Invalid path " + parsed.path + " in surface: " + surface);
102
+ }
103
+
104
+ if (parsed.fragment && !FRAGMENT_REGEX.test(parsed.fragment)) {
105
+ return invalidateSurface("Invalid fragment " + parsed.fragment + " in surface: " + surface);
106
+ }
107
+
108
+ return parsed;
109
+ };
110
+
111
+ var isPageWideSurface = function isPageWideSurface(scope) {
112
+ return !!scope && scope.indexOf(_surface.WEB + _surface.SURFACE_TYPE_DELIMITER) === 0 && scope.indexOf(_surface.FRAGMENT_DELIMITER) === -1;
113
+ };
114
+
115
+ exports.isPageWideSurface = isPageWideSurface;
116
+
117
+ var normalizeSurfaces = function normalizeSurfaces() {
118
+ var surfaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
119
+ var getPageLocation = arguments.length > 1 ? arguments[1] : undefined;
120
+ var logger = arguments.length > 2 ? arguments[2] : undefined;
121
+ return surfaces.map(function (surface) {
122
+ return validateSurface(surface, getPageLocation, logger);
123
+ }).filter(function (surface) {
124
+ return !(0, _utils.isNil)(surface);
125
+ }).map(stringifySurface);
126
+ };
127
+
128
+ exports.normalizeSurfaces = normalizeSurfaces;
@@ -15,5 +15,5 @@ governing permissions and limitations under the License.
15
15
  */
16
16
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
17
17
  // see babel-plugin-version
18
- var _default = "2.14.0-alpha.0";
18
+ var _default = "2.14.0-alpha.2";
19
19
  exports.default = _default;
@@ -41,7 +41,9 @@ var _default = function _default(_ref) {
41
41
  * the request payload.
42
42
  * @param {Object} [options]
43
43
  * @param {boolean} [options.renderDecisions=false]
44
- * @param {Array} [options.decisionScopes]
44
+ * @param {Array} [options.decisionScopes] Note: this option will soon
45
+ * be deprecated, please use *personalization.decisionScopes* instead
46
+ * @param {Object} [options.personalization]
45
47
  * @param {Object} [options.serverState]
46
48
  * This will be passed to components
47
49
  * so they can take appropriate action.
@@ -51,7 +53,8 @@ var _default = function _default(_ref) {
51
53
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
52
54
  var _options$renderDecisi = options.renderDecisions,
53
55
  renderDecisions = _options$renderDecisi === void 0 ? false : _options$renderDecisi,
54
- decisionScopes = options.decisionScopes;
56
+ decisionScopes = options.decisionScopes,
57
+ personalization = options.personalization;
55
58
  var payload = createDataCollectionRequestPayload();
56
59
  var request = createDataCollectionRequest(payload);
57
60
  var onResponseCallbackAggregator = (0, _utils.createCallbackAggregator)();
@@ -60,6 +63,7 @@ var _default = function _default(_ref) {
60
63
  event: event,
61
64
  renderDecisions: renderDecisions,
62
65
  decisionScopes: decisionScopes,
66
+ personalization: personalization,
63
67
  onResponse: onResponseCallbackAggregator.add,
64
68
  onRequestFailure: onRequestFailureCallbackAggregator.add
65
69
  }).then(function () {
@@ -116,6 +120,7 @@ var _default = function _default(_ref) {
116
120
  event: event,
117
121
  renderDecisions: renderDecisions,
118
122
  decisionScopes: [_pageWideScope.default],
123
+ personalization: {},
119
124
  onResponse: onResponseCallbackAggregator.add,
120
125
  onRequestFailure: _utils.noop
121
126
  }).then(function () {
@@ -15,7 +15,7 @@ governing permissions and limitations under the License.
15
15
  */
16
16
 
17
17
  /**
18
- * Returns true whether the value is null or undefined.
18
+ * Returns true when the value is null.
19
19
  * @param {*} value
20
20
  * @returns {boolean}
21
21
  */
@@ -33,6 +33,8 @@ const createDataCollector = ({
33
33
  mergeId,
34
34
  renderDecisions = false,
35
35
  decisionScopes = [],
36
+ // Note: this option will soon be deprecated, please use personalization.decisionScopes instead
37
+ personalization = {},
36
38
  datasetId
37
39
  } = options;
38
40
  const event = eventManager.createEvent();
@@ -66,7 +68,8 @@ const createDataCollector = ({
66
68
 
67
69
  return eventManager.sendEvent(event, {
68
70
  renderDecisions,
69
- decisionScopes
71
+ decisionScopes,
72
+ personalization
70
73
  });
71
74
  }
72
75
  },
@@ -30,6 +30,10 @@ export default (({
30
30
  documentUnloading: boolean(),
31
31
  renderDecisions: boolean(),
32
32
  decisionScopes: arrayOf(string()).uniqueItems(),
33
+ personalization: objectOf({
34
+ decisionScopes: arrayOf(string()).uniqueItems(),
35
+ surfaces: arrayOf(string()).uniqueItems()
36
+ }),
33
37
  datasetId: string(),
34
38
  mergeId: string()
35
39
  }).required().noUnknownFields();
@@ -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 WEB = "web";
13
+ export const WEBAPP = "webapp";
14
+ export const SURFACE_TYPE_DELIMITER = "://";
15
+ export const FRAGMENT_DELIMITER = "#";
@@ -14,6 +14,7 @@ import createPersonalizationDetails from "./createPersonalizationDetails";
14
14
  import { AUTHORING_ENABLED } from "./constants/loggerMessage";
15
15
  import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
16
16
  export default (({
17
+ getPageLocation,
17
18
  logger,
18
19
  fetchDataHandler,
19
20
  viewChangeHandler,
@@ -38,6 +39,7 @@ export default (({
38
39
  event,
39
40
  renderDecisions,
40
41
  decisionScopes = [],
42
+ personalization = {},
41
43
  onResponse = noop,
42
44
  onRequestFailure = noop
43
45
  }) {
@@ -57,10 +59,13 @@ export default (({
57
59
  }
58
60
 
59
61
  const personalizationDetails = createPersonalizationDetails({
62
+ getPageLocation,
60
63
  renderDecisions,
61
64
  decisionScopes,
65
+ personalization,
62
66
  event,
63
- viewCache
67
+ viewCache,
68
+ logger
64
69
  });
65
70
 
66
71
  if (personalizationDetails.shouldFetchData()) {
@@ -0,0 +1,16 @@
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 (({
13
+ window
14
+ }) => () => {
15
+ return window.location;
16
+ });
@@ -9,15 +9,35 @@ 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 { includes } from "../../utils";
12
+ import { includes, isNonEmptyString, isNonEmptyArray } from "../../utils";
13
+ import { buildPageSurface, normalizeSurfaces } from "./utils/surfaceUtils";
13
14
  import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
14
15
  import { DEFAULT_CONTENT_ITEM, DOM_ACTION, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM } from "./constants/schema";
15
- import isNonEmptyString from "../../utils/isNonEmptyString";
16
+
17
+ const addPageWideScope = scopes => {
18
+ if (!includes(scopes, PAGE_WIDE_SCOPE)) {
19
+ scopes.push(PAGE_WIDE_SCOPE);
20
+ }
21
+ };
22
+
23
+ const addPageSurface = (surfaces, getPageLocation) => {
24
+ const pageSurface = buildPageSurface(getPageLocation);
25
+
26
+ if (!includes(surfaces, pageSurface)) {
27
+ surfaces.push(pageSurface);
28
+ }
29
+ };
30
+
31
+ const dedupe = array => array.filter((item, pos) => array.indexOf(item) === pos);
32
+
16
33
  export default (({
34
+ getPageLocation,
17
35
  renderDecisions,
18
36
  decisionScopes,
37
+ personalization,
19
38
  event,
20
- viewCache
39
+ viewCache,
40
+ logger
21
41
  }) => {
22
42
  const viewName = event.getViewName();
23
43
  return {
@@ -30,7 +50,11 @@ export default (({
30
50
  },
31
51
 
32
52
  hasScopes() {
33
- return decisionScopes.length > 0;
53
+ return decisionScopes.length > 0 || isNonEmptyArray(personalization.decisionScopes);
54
+ },
55
+
56
+ hasSurfaces() {
57
+ return isNonEmptyArray(personalization.surfaces);
34
58
  },
35
59
 
36
60
  hasViewName() {
@@ -40,8 +64,15 @@ export default (({
40
64
  createQueryDetails() {
41
65
  const scopes = [...decisionScopes];
42
66
 
43
- if (!this.isCacheInitialized() && !includes(scopes, PAGE_WIDE_SCOPE)) {
44
- scopes.push(PAGE_WIDE_SCOPE);
67
+ if (isNonEmptyArray(personalization.decisionScopes)) {
68
+ scopes.push(...personalization.decisionScopes);
69
+ }
70
+
71
+ const eventSurfaces = normalizeSurfaces(personalization.surfaces, getPageLocation, logger);
72
+
73
+ if (!this.isCacheInitialized()) {
74
+ addPageWideScope(scopes);
75
+ addPageSurface(eventSurfaces, getPageLocation);
45
76
  }
46
77
 
47
78
  const schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM];
@@ -52,7 +83,8 @@ export default (({
52
83
 
53
84
  return {
54
85
  schemas,
55
- decisionScopes: scopes
86
+ decisionScopes: dedupe(scopes),
87
+ surfaces: dedupe(eventSurfaces)
56
88
  };
57
89
  },
58
90
 
@@ -61,7 +93,7 @@ export default (({
61
93
  },
62
94
 
63
95
  shouldFetchData() {
64
- return this.hasScopes() || !this.isCacheInitialized();
96
+ return this.hasScopes() || this.hasSurfaces() || !this.isCacheInitialized();
65
97
  },
66
98
 
67
99
  shouldUseCachedData() {
@@ -10,9 +10,9 @@ 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 { isNonEmptyArray, includes } from "../../utils";
13
+ import isPageWideScope from "./utils/isPageWideScope";
13
14
  import { DOM_ACTION, REDIRECT_ITEM, DEFAULT_CONTENT_ITEM, MEASUREMENT_SCHEMA } from "./constants/schema";
14
15
  import { VIEW_SCOPE_TYPE } from "./constants/scopeType";
15
- import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
16
16
 
17
17
  const splitItems = (items, schemas) => {
18
18
  const matched = [];
@@ -90,7 +90,7 @@ const extractDecisionsByScope = decisions => {
90
90
 
91
91
  if (isNonEmptyArray(decisions)) {
92
92
  decisions.forEach(decision => {
93
- if (decision.scope === PAGE_WIDE_SCOPE) {
93
+ if (isPageWideScope(decision.scope)) {
94
94
  pageWideScopeDecisions.push(decision);
95
95
  } else if (isViewScope(decision.scopeDetails)) {
96
96
  appendScopeDecision(viewScopeDecisions, decision);
@@ -29,6 +29,7 @@ import createRedirectHandler from "./createRedirectHandler";
29
29
  import createAutorenderingHandler from "./createAutoRenderingHandler";
30
30
  import createNonRenderingHandler from "./createNonRenderingHandler";
31
31
  import createApplyPropositions from "./createApplyPropositions";
32
+ import createGetPageLocation from "./createGetPageLocation";
32
33
  import createSetTargetMigration from "./createSetTargetMigration";
33
34
 
34
35
  const createPersonalization = ({
@@ -49,6 +50,9 @@ const createPersonalization = ({
49
50
  getClickSelectors,
50
51
  storeClickMetrics
51
52
  } = createClickStorage();
53
+ const getPageLocation = createGetPageLocation({
54
+ window
55
+ });
52
56
  const viewCache = createViewCacheManager();
53
57
  const modules = initDomActionsModules(storeClickMetrics);
54
58
  const executeDecisions = createExecuteDecisions({
@@ -103,6 +107,7 @@ const createPersonalization = ({
103
107
  targetMigrationEnabled
104
108
  });
105
109
  return createComponent({
110
+ getPageLocation,
106
111
  logger,
107
112
  fetchDataHandler,
108
113
  viewChangeHandler,
@@ -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
+ import { isPageWideSurface } from "./surfaceUtils";
13
+ import PAGE_WIDE_SCOPE from "../../../constants/pageWideScope";
14
+ export default (scope => scope === PAGE_WIDE_SCOPE || isPageWideSurface(scope));
@@ -0,0 +1,93 @@
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 { WEB, WEBAPP, SURFACE_TYPE_DELIMITER, FRAGMENT_DELIMITER } from "../constants/surface";
13
+ import { startsWith, isNil, isNonEmptyString, includes } from "../../../utils";
14
+ const SURFACE_REGEX = /^(\w+):\/\/([^/#]+)(\/[^#]*)?(#.*)?$/;
15
+ const AUTHORITY_REGEX = /^(?:.*@)?(?:[a-z\d\u00a1-\uffff.-]+|\[[a-f\d:]+])(?::\d+)?$/;
16
+ const PATH_REGEX = /^\/(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})*$/;
17
+ const FRAGMENT_REGEX = /^#(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})+$/;
18
+
19
+ const normalizePath = (path = "/") => {
20
+ let end = path.length;
21
+
22
+ while (end > 0 && "/".indexOf(path.charAt(end - 1)) !== -1) {
23
+ end -= 1;
24
+ }
25
+
26
+ return path.substring(0, end) || "/";
27
+ };
28
+
29
+ const getSurfaceType = surfaceTypeMatch => isNonEmptyString(surfaceTypeMatch) ? surfaceTypeMatch.toLowerCase() : "";
30
+
31
+ const getAuthority = authorityMatch => isNonEmptyString(authorityMatch) ? authorityMatch.toLowerCase() : "";
32
+
33
+ const getPath = pathMatch => isNonEmptyString(pathMatch) ? normalizePath(pathMatch) : "/";
34
+
35
+ const parseSurface = surfaceString => {
36
+ const matched = surfaceString.match(SURFACE_REGEX);
37
+ return matched ? {
38
+ surfaceType: getSurfaceType(matched[1]),
39
+ authority: getAuthority(matched[2]),
40
+ path: getPath(matched[3]),
41
+ fragment: matched[4]
42
+ } : null;
43
+ };
44
+
45
+ const stringifySurface = surface => `${surface.surfaceType}${SURFACE_TYPE_DELIMITER}${surface.authority}${surface.path || ""}${surface.fragment || ""}`;
46
+
47
+ export const buildPageSurface = getPageLocation => {
48
+ const location = getPageLocation();
49
+ const host = location.host.toLowerCase();
50
+ const path = location.pathname;
51
+ return WEB + SURFACE_TYPE_DELIMITER + host + normalizePath(path);
52
+ };
53
+
54
+ const expandFragmentSurface = (surface, getPageLocation) => startsWith(surface, FRAGMENT_DELIMITER) ? buildPageSurface(getPageLocation) + surface : surface;
55
+
56
+ const validateSurface = (surface, getPageLocation, logger) => {
57
+ const invalidateSurface = validationError => {
58
+ logger.warn(validationError);
59
+ return null;
60
+ };
61
+
62
+ if (!isNonEmptyString(surface)) {
63
+ return invalidateSurface(`Invalid surface: ${surface}`);
64
+ }
65
+
66
+ const expanded = expandFragmentSurface(surface, getPageLocation);
67
+ const parsed = parseSurface(expanded);
68
+
69
+ if (parsed === null) {
70
+ return invalidateSurface(`Invalid surface: ${surface}`);
71
+ }
72
+
73
+ if (!includes([WEB, WEBAPP], parsed.surfaceType)) {
74
+ return invalidateSurface(`Unsupported surface type ${parsed.surfaceType} in surface: ${surface}`);
75
+ }
76
+
77
+ if (!parsed.authority || !AUTHORITY_REGEX.test(parsed.authority)) {
78
+ return invalidateSurface(`Invalid authority ${parsed.authority} in surface: ${surface}`);
79
+ }
80
+
81
+ if (parsed.path && !PATH_REGEX.test(parsed.path)) {
82
+ return invalidateSurface(`Invalid path ${parsed.path} in surface: ${surface}`);
83
+ }
84
+
85
+ if (parsed.fragment && !FRAGMENT_REGEX.test(parsed.fragment)) {
86
+ return invalidateSurface(`Invalid fragment ${parsed.fragment} in surface: ${surface}`);
87
+ }
88
+
89
+ return parsed;
90
+ };
91
+
92
+ export const isPageWideSurface = scope => !!scope && scope.indexOf(WEB + SURFACE_TYPE_DELIMITER) === 0 && scope.indexOf(FRAGMENT_DELIMITER) === -1;
93
+ export const normalizeSurfaces = (surfaces = [], getPageLocation, logger) => surfaces.map(surface => validateSurface(surface, getPageLocation, logger)).filter(surface => !isNil(surface)).map(stringifySurface);
@@ -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.14.0-alpha.0";
14
+ export default "2.14.0-alpha.2";
@@ -37,7 +37,9 @@ export default (({
37
37
  * the request payload.
38
38
  * @param {Object} [options]
39
39
  * @param {boolean} [options.renderDecisions=false]
40
- * @param {Array} [options.decisionScopes]
40
+ * @param {Array} [options.decisionScopes] Note: this option will soon
41
+ * be deprecated, please use *personalization.decisionScopes* instead
42
+ * @param {Object} [options.personalization]
41
43
  * @param {Object} [options.serverState]
42
44
  * This will be passed to components
43
45
  * so they can take appropriate action.
@@ -46,7 +48,8 @@ export default (({
46
48
  sendEvent(event, options = {}) {
47
49
  const {
48
50
  renderDecisions = false,
49
- decisionScopes
51
+ decisionScopes,
52
+ personalization
50
53
  } = options;
51
54
  const payload = createDataCollectionRequestPayload();
52
55
  const request = createDataCollectionRequest(payload);
@@ -56,6 +59,7 @@ export default (({
56
59
  event,
57
60
  renderDecisions,
58
61
  decisionScopes,
62
+ personalization,
59
63
  onResponse: onResponseCallbackAggregator.add,
60
64
  onRequestFailure: onRequestFailureCallbackAggregator.add
61
65
  }).then(() => {
@@ -111,6 +115,7 @@ export default (({
111
115
  event,
112
116
  renderDecisions,
113
117
  decisionScopes: [PAGE_WIDE_SCOPE],
118
+ personalization: {},
114
119
  onResponse: onResponseCallbackAggregator.add,
115
120
  onRequestFailure: noop
116
121
  }).then(() => {
@@ -11,7 +11,7 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  /**
14
- * Returns true whether the value is null or undefined.
14
+ * Returns true when the value is null.
15
15
  * @param {*} value
16
16
  * @returns {boolean}
17
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.14.0-alpha.0",
3
+ "version": "2.14.0-alpha.2",
4
4
  "description": "Adobe Experience Platform Web SDK",
5
5
  "main": "libEs5/index.js",
6
6
  "module": "libEs6/index.js",
@@ -64,7 +64,7 @@
64
64
  "uuid": "^3.3.2"
65
65
  },
66
66
  "devDependencies": {
67
- "@adobe/alloy": "^2.13.0",
67
+ "@adobe/alloy": "^2.14.0-alpha.1",
68
68
  "@babel/cli": "^7.12.8",
69
69
  "@babel/core": "^7.2.2",
70
70
  "@babel/plugin-proposal-object-rest-spread": "^7.3.2",