@adobe/alloy 2.11.0-alpha.6 → 2.11.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.
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ exports.default = exports.SUPPORTED_SCHEMAS = void 0;
4
+
5
+ var _composePersonalizationResultingObject = require("./utils/composePersonalizationResultingObject");
6
+
7
+ var _utils = require("../../utils");
8
+
9
+ var _schema = require("./constants/schema");
10
+
11
+ var _scope = require("./constants/scope");
12
+
13
+ var _validateApplyPropositionsOptions = require("./validateApplyPropositionsOptions");
14
+
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
+
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+
19
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
+
21
+ var SUPPORTED_SCHEMAS = [_schema.DOM_ACTION, _schema.HTML_CONTENT_ITEM];
22
+ exports.SUPPORTED_SCHEMAS = SUPPORTED_SCHEMAS;
23
+
24
+ var _default = function _default(_ref) {
25
+ var executeDecisions = _ref.executeDecisions;
26
+
27
+ var filterItemsPredicate = function filterItemsPredicate(item) {
28
+ return SUPPORTED_SCHEMAS.includes(item.schema);
29
+ };
30
+
31
+ var updatePropositionItems = function updatePropositionItems(_ref2) {
32
+ var items = _ref2.items,
33
+ metadataForScope = _ref2.metadataForScope;
34
+ return items.filter(filterItemsPredicate).map(function (item) {
35
+ if (item.schema !== _schema.HTML_CONTENT_ITEM) {
36
+ return _objectSpread({}, item);
37
+ }
38
+
39
+ if ((0, _utils.isObject)(metadataForScope)) {
40
+ return _objectSpread(_objectSpread({}, item), {}, {
41
+ data: _objectSpread(_objectSpread({}, item.data), {}, {
42
+ selector: metadataForScope.selector,
43
+ type: metadataForScope.actionType
44
+ })
45
+ });
46
+ }
47
+
48
+ return undefined;
49
+ }).filter(function (item) {
50
+ return item;
51
+ });
52
+ };
53
+
54
+ var filterPropositionsPredicate = function filterPropositionsPredicate(proposition) {
55
+ return !(proposition.scope === _scope.default && proposition.renderAttempted);
56
+ };
57
+
58
+ var preparePropositions = function preparePropositions(_ref3) {
59
+ var propositions = _ref3.propositions,
60
+ metadata = _ref3.metadata;
61
+ return propositions.filter(filterPropositionsPredicate).map(function (proposition) {
62
+ if ((0, _utils.isNonEmptyArray)(proposition.items)) {
63
+ var id = proposition.id,
64
+ scope = proposition.scope,
65
+ scopeDetails = proposition.scopeDetails;
66
+ return {
67
+ id: id,
68
+ scope: scope,
69
+ scopeDetails: scopeDetails,
70
+ items: updatePropositionItems({
71
+ items: proposition.items,
72
+ metadataForScope: metadata[proposition.scope]
73
+ })
74
+ };
75
+ }
76
+
77
+ return proposition;
78
+ }).filter(function (proposition) {
79
+ return (0, _utils.isNonEmptyArray)(proposition.items);
80
+ });
81
+ };
82
+
83
+ var applyPropositions = function applyPropositions(_ref4) {
84
+ var propositions = _ref4.propositions,
85
+ metadata = _ref4.metadata;
86
+ var propositionsToExecute = preparePropositions({
87
+ propositions: propositions,
88
+ metadata: metadata
89
+ });
90
+ return executeDecisions(propositionsToExecute).then(function () {
91
+ return (0, _composePersonalizationResultingObject.default)(propositionsToExecute, true);
92
+ });
93
+ };
94
+
95
+ return function (_ref5) {
96
+ var propositions = _ref5.propositions,
97
+ _ref5$metadata = _ref5.metadata,
98
+ metadata = _ref5$metadata === void 0 ? {} : _ref5$metadata;
99
+
100
+ if ((0, _utils.isNonEmptyArray)(propositions)) {
101
+ return applyPropositions({
102
+ propositions: propositions,
103
+ metadata: metadata
104
+ });
105
+ }
106
+
107
+ return Promise.resolve(_validateApplyPropositionsOptions.EMPTY_PROPOSITIONS);
108
+ };
109
+ };
110
+
111
+ exports.default = _default;
@@ -8,6 +8,8 @@ var _createPersonalizationDetails = require("./createPersonalizationDetails");
8
8
 
9
9
  var _loggerMessage = require("./constants/loggerMessage");
10
10
 
11
+ var _validateApplyPropositionsOptions = require("./validateApplyPropositionsOptions");
12
+
11
13
  /*
12
14
  Copyright 2020 Adobe. All rights reserved.
13
15
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -27,7 +29,8 @@ var _default = function _default(_ref) {
27
29
  isAuthoringModeEnabled = _ref.isAuthoringModeEnabled,
28
30
  mergeQuery = _ref.mergeQuery,
29
31
  viewCache = _ref.viewCache,
30
- showContainers = _ref.showContainers;
32
+ showContainers = _ref.showContainers,
33
+ applyPropositions = _ref.applyPropositions;
31
34
  return {
32
35
  lifecycle: {
33
36
  onBeforeEvent: function onBeforeEvent(_ref2) {
@@ -98,6 +101,17 @@ var _default = function _default(_ref) {
98
101
  clickedElement: clickedElement
99
102
  });
100
103
  }
104
+ },
105
+ commands: {
106
+ applyPropositions: {
107
+ optionsValidator: function optionsValidator(options) {
108
+ return (0, _validateApplyPropositionsOptions.default)({
109
+ logger: logger,
110
+ options: options
111
+ });
112
+ },
113
+ run: applyPropositions
114
+ }
101
115
  }
102
116
  };
103
117
  };
@@ -40,6 +40,8 @@ var _createAutoRenderingHandler = require("./createAutoRenderingHandler");
40
40
 
41
41
  var _createNonRenderingHandler = require("./createNonRenderingHandler");
42
42
 
43
+ var _createApplyPropositions = require("./createApplyPropositions");
44
+
43
45
  /*
44
46
  Copyright 2019 Adobe. All rights reserved.
45
47
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -84,6 +86,9 @@ var createPersonalization = function createPersonalization(_ref) {
84
86
  showContainers: _flicker.showContainers,
85
87
  collect: collect
86
88
  });
89
+ var applyPropositions = (0, _createApplyPropositions.default)({
90
+ executeDecisions: executeDecisions
91
+ });
87
92
  var nonRenderingHandler = (0, _createNonRenderingHandler.default)({
88
93
  viewCache: viewCache
89
94
  });
@@ -120,7 +125,8 @@ var createPersonalization = function createPersonalization(_ref) {
120
125
  isAuthoringModeEnabled: _isAuthoringModeEnabled.default,
121
126
  mergeQuery: _event.mergeQuery,
122
127
  viewCache: viewCache,
123
- showContainers: _flicker.showContainers
128
+ showContainers: _flicker.showContainers,
129
+ applyPropositions: applyPropositions
124
130
  });
125
131
  };
126
132
 
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ exports.default = exports.EMPTY_PROPOSITIONS = void 0;
4
+
5
+ var _validation = require("../../utils/validation");
6
+
7
+ var EMPTY_PROPOSITIONS = {
8
+ propositions: []
9
+ };
10
+ exports.EMPTY_PROPOSITIONS = EMPTY_PROPOSITIONS;
11
+
12
+ var _default = function _default(_ref) {
13
+ var logger = _ref.logger,
14
+ options = _ref.options;
15
+ var applyPropositionsOptionsValidator = (0, _validation.objectOf)({
16
+ propositions: (0, _validation.arrayOf)((0, _validation.objectOf)((0, _validation.anything)())).nonEmpty(),
17
+ metadata: (0, _validation.objectOf)((0, _validation.anything)())
18
+ }).required();
19
+
20
+ try {
21
+ return applyPropositionsOptionsValidator(options);
22
+ } catch (e) {
23
+ logger.warn("Invalid options for applyPropositions. No propositions will be applied.", e);
24
+ return EMPTY_PROPOSITIONS;
25
+ }
26
+ };
27
+
28
+ exports.default = _default;
@@ -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.11.0-alpha.6";
18
+ var _default = "2.11.0-beta.0";
19
19
  exports.default = _default;
@@ -0,0 +1,102 @@
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 composePersonalizationResultingObject from "./utils/composePersonalizationResultingObject";
13
+ import { isNonEmptyArray, isObject } from "../../utils";
14
+ import { DOM_ACTION, HTML_CONTENT_ITEM } from "./constants/schema";
15
+ import PAGE_WIDE_SCOPE from "./constants/scope";
16
+ import { EMPTY_PROPOSITIONS } from "./validateApplyPropositionsOptions";
17
+ export const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];
18
+ export default (({
19
+ executeDecisions
20
+ }) => {
21
+ const filterItemsPredicate = item => SUPPORTED_SCHEMAS.includes(item.schema);
22
+
23
+ const updatePropositionItems = ({
24
+ items,
25
+ metadataForScope
26
+ }) => {
27
+ return items.filter(filterItemsPredicate).map(item => {
28
+ if (item.schema !== HTML_CONTENT_ITEM) {
29
+ return { ...item
30
+ };
31
+ }
32
+
33
+ if (isObject(metadataForScope)) {
34
+ return { ...item,
35
+ data: { ...item.data,
36
+ selector: metadataForScope.selector,
37
+ type: metadataForScope.actionType
38
+ }
39
+ };
40
+ }
41
+
42
+ return undefined;
43
+ }).filter(item => item);
44
+ };
45
+
46
+ const filterPropositionsPredicate = proposition => {
47
+ return !(proposition.scope === PAGE_WIDE_SCOPE && proposition.renderAttempted);
48
+ };
49
+
50
+ const preparePropositions = ({
51
+ propositions,
52
+ metadata
53
+ }) => {
54
+ return propositions.filter(filterPropositionsPredicate).map(proposition => {
55
+ if (isNonEmptyArray(proposition.items)) {
56
+ const {
57
+ id,
58
+ scope,
59
+ scopeDetails
60
+ } = proposition;
61
+ return {
62
+ id,
63
+ scope,
64
+ scopeDetails,
65
+ items: updatePropositionItems({
66
+ items: proposition.items,
67
+ metadataForScope: metadata[proposition.scope]
68
+ })
69
+ };
70
+ }
71
+
72
+ return proposition;
73
+ }).filter(proposition => isNonEmptyArray(proposition.items));
74
+ };
75
+
76
+ const applyPropositions = ({
77
+ propositions,
78
+ metadata
79
+ }) => {
80
+ const propositionsToExecute = preparePropositions({
81
+ propositions,
82
+ metadata
83
+ });
84
+ return executeDecisions(propositionsToExecute).then(() => {
85
+ return composePersonalizationResultingObject(propositionsToExecute, true);
86
+ });
87
+ };
88
+
89
+ return ({
90
+ propositions,
91
+ metadata = {}
92
+ }) => {
93
+ if (isNonEmptyArray(propositions)) {
94
+ return applyPropositions({
95
+ propositions,
96
+ metadata
97
+ });
98
+ }
99
+
100
+ return Promise.resolve(EMPTY_PROPOSITIONS);
101
+ };
102
+ });
@@ -12,6 +12,7 @@ governing permissions and limitations under the License.
12
12
  import { noop, defer } from "../../utils";
13
13
  import createPersonalizationDetails from "./createPersonalizationDetails";
14
14
  import { AUTHORING_ENABLED } from "./constants/loggerMessage";
15
+ import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
15
16
  export default (({
16
17
  logger,
17
18
  fetchDataHandler,
@@ -20,7 +21,8 @@ export default (({
20
21
  isAuthoringModeEnabled,
21
22
  mergeQuery,
22
23
  viewCache,
23
- showContainers
24
+ showContainers,
25
+ applyPropositions
24
26
  }) => {
25
27
  return {
26
28
  lifecycle: {
@@ -87,6 +89,15 @@ export default (({
87
89
  });
88
90
  }
89
91
 
92
+ },
93
+ commands: {
94
+ applyPropositions: {
95
+ optionsValidator: options => validateApplyPropositionsOptions({
96
+ logger,
97
+ options
98
+ }),
99
+ run: applyPropositions
100
+ }
90
101
  }
91
102
  };
92
103
  });
@@ -28,6 +28,7 @@ import createClickStorage from "./createClickStorage";
28
28
  import createRedirectHandler from "./createRedirectHandler";
29
29
  import createAutorenderingHandler from "./createAutoRenderingHandler";
30
30
  import createNonRenderingHandler from "./createNonRenderingHandler";
31
+ import createApplyPropositions from "./createApplyPropositions";
31
32
 
32
33
  const createPersonalization = ({
33
34
  config,
@@ -62,6 +63,9 @@ const createPersonalization = ({
62
63
  showContainers,
63
64
  collect
64
65
  });
66
+ const applyPropositions = createApplyPropositions({
67
+ executeDecisions
68
+ });
65
69
  const nonRenderingHandler = createNonRenderingHandler({
66
70
  viewCache
67
71
  });
@@ -98,7 +102,8 @@ const createPersonalization = ({
98
102
  isAuthoringModeEnabled,
99
103
  mergeQuery,
100
104
  viewCache,
101
- showContainers
105
+ showContainers,
106
+ applyPropositions
102
107
  });
103
108
  };
104
109
 
@@ -0,0 +1,20 @@
1
+ import { anything, objectOf, arrayOf } from "../../utils/validation";
2
+ export const EMPTY_PROPOSITIONS = {
3
+ propositions: []
4
+ };
5
+ export default (({
6
+ logger,
7
+ options
8
+ }) => {
9
+ const applyPropositionsOptionsValidator = objectOf({
10
+ propositions: arrayOf(objectOf(anything())).nonEmpty(),
11
+ metadata: objectOf(anything())
12
+ }).required();
13
+
14
+ try {
15
+ return applyPropositionsOptionsValidator(options);
16
+ } catch (e) {
17
+ logger.warn("Invalid options for applyPropositions. No propositions will be applied.", e);
18
+ return EMPTY_PROPOSITIONS;
19
+ }
20
+ });
@@ -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.11.0-alpha.6";
14
+ export default "2.11.0-beta.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.11.0-alpha.6",
3
+ "version": "2.11.0-beta.0",
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.11.0-alpha.5",
67
+ "@adobe/alloy": "^2.11.0-alpha.8",
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",