@adobe/alloy 2.9.0-alpha.3 → 2.9.0-alpha.4

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- exports.REDIRECT_ITEM = exports.JSON_CONTENT_ITEM = exports.HTML_CONTENT_ITEM = exports.DOM_ACTION = void 0;
3
+ exports.REDIRECT_ITEM = exports.JSON_CONTENT_ITEM = exports.HTML_CONTENT_ITEM = exports.DOM_ACTION = exports.DEFAULT_CONTENT_ITEM = void 0;
4
4
 
5
5
  /*
6
6
  Copyright 2019 Adobe. All rights reserved.
@@ -13,6 +13,8 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
13
13
  OF ANY KIND, either express or implied. See the License for the specific language
14
14
  governing permissions and limitations under the License.
15
15
  */
16
+ var DEFAULT_CONTENT_ITEM = "https://ns.adobe.com/personalization/default-content-item";
17
+ exports.DEFAULT_CONTENT_ITEM = DEFAULT_CONTENT_ITEM;
16
18
  var DOM_ACTION = "https://ns.adobe.com/personalization/dom-action";
17
19
  exports.DOM_ACTION = DOM_ACTION;
18
20
  var HTML_CONTENT_ITEM = "https://ns.adobe.com/personalization/html-content-item";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ exports.VIEW_SCOPE_TYPE = 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 VIEW_SCOPE_TYPE = "view";
17
+ exports.VIEW_SCOPE_TYPE = VIEW_SCOPE_TYPE;
@@ -15,6 +15,8 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
15
15
  OF ANY KIND, either express or implied. See the License for the specific language
16
16
  governing permissions and limitations under the License.
17
17
  */
18
+ var DEFAULT_ACTION_TYPE = "defaultContent";
19
+
18
20
  var identity = function identity(item) {
19
21
  return item;
20
22
  };
@@ -26,7 +28,9 @@ var buildActions = function buildActions(decision) {
26
28
  scopeDetails: decision.scopeDetails
27
29
  };
28
30
  return decision.items.map(function (item) {
29
- return (0, _utils.assign)({}, item.data, {
31
+ return (0, _utils.assign)({
32
+ type: DEFAULT_ACTION_TYPE
33
+ }, item.data, {
30
34
  meta: meta
31
35
  });
32
36
  });
@@ -48,7 +48,7 @@ var _default = function _default(_ref) {
48
48
  scopes.push(_scope.default);
49
49
  }
50
50
 
51
- var schemas = [_schema.HTML_CONTENT_ITEM, _schema.JSON_CONTENT_ITEM, _schema.REDIRECT_ITEM];
51
+ var schemas = [_schema.DEFAULT_CONTENT_ITEM, _schema.HTML_CONTENT_ITEM, _schema.JSON_CONTENT_ITEM, _schema.REDIRECT_ITEM];
52
52
 
53
53
  if ((0, _utils.includes)(scopes, _scope.default)) {
54
54
  schemas.push(_schema.DOM_ACTION);
@@ -36,6 +36,11 @@ var _default = function _default(store) {
36
36
  appendHtml: (0, _action.createAction)(_action.appendHtml),
37
37
  click: function click(settings) {
38
38
  return (0, _action.click)(settings, store);
39
+ },
40
+ defaultContent: function defaultContent(settings) {
41
+ return Promise.resolve({
42
+ meta: settings.meta
43
+ });
39
44
  }
40
45
  };
41
46
  };
@@ -6,6 +6,8 @@ var _utils = require("../../utils");
6
6
 
7
7
  var _schema = require("./constants/schema");
8
8
 
9
+ var _scopeType = require("./constants/scopeType");
10
+
9
11
  var _scope = require("./constants/scope");
10
12
 
11
13
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -20,11 +22,11 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
20
22
 
21
23
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
24
 
23
- var splitItems = function splitItems(items, schema) {
25
+ var splitItems = function splitItems(items, schemas) {
24
26
  var matched = [];
25
27
  var nonMatched = [];
26
28
  items.forEach(function (item) {
27
- if (item.schema === schema) {
29
+ if ((0, _utils.includes)(schemas, item.schema)) {
28
30
  matched.push(item);
29
31
  } else {
30
32
  nonMatched.push(item);
@@ -42,14 +44,18 @@ var createDecision = function createDecision(decision, items) {
42
44
  };
43
45
  };
44
46
 
45
- var splitDecisions = function splitDecisions(decisions, schema) {
47
+ var splitDecisions = function splitDecisions(decisions) {
48
+ for (var _len = arguments.length, schemas = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
49
+ schemas[_key - 1] = arguments[_key];
50
+ }
51
+
46
52
  var matchedDecisions = [];
47
53
  var unmatchedDecisions = [];
48
54
  decisions.forEach(function (decision) {
49
55
  var _decision$items = decision.items,
50
56
  items = _decision$items === void 0 ? [] : _decision$items;
51
57
 
52
- var _splitItems = splitItems(items, schema),
58
+ var _splitItems = splitItems(items, schemas),
53
59
  _splitItems2 = _slicedToArray(_splitItems, 2),
54
60
  matchedItems = _splitItems2[0],
55
61
  nonMatchedItems = _splitItems2[1];
@@ -68,43 +74,56 @@ var splitDecisions = function splitDecisions(decisions, schema) {
68
74
  };
69
75
  };
70
76
 
71
- var extractDecisionsByScope = function extractDecisionsByScope(decisions, scope) {
77
+ var appendScopeDecision = function appendScopeDecision(scopeDecisions, decision) {
78
+ if (!scopeDecisions[decision.scope]) {
79
+ scopeDecisions[decision.scope] = [];
80
+ }
81
+
82
+ scopeDecisions[decision.scope].push(decision);
83
+ };
84
+
85
+ var isViewScope = function isViewScope(scopeDetails) {
86
+ return scopeDetails.characteristics && scopeDetails.characteristics.scopeType && scopeDetails.characteristics.scopeType === _scopeType.VIEW_SCOPE_TYPE;
87
+ };
88
+
89
+ var extractDecisionsByScope = function extractDecisionsByScope(decisions) {
72
90
  var pageWideScopeDecisions = [];
73
- var nonPageWideScopeDecisions = {};
91
+ var nonPageWideScopeDecisions = [];
92
+ var viewScopeDecisions = {};
74
93
 
75
94
  if ((0, _utils.isNonEmptyArray)(decisions)) {
76
95
  decisions.forEach(function (decision) {
77
- if (decision.scope === scope) {
96
+ if (decision.scope === _scope.default) {
78
97
  pageWideScopeDecisions.push(decision);
98
+ } else if (isViewScope(decision.scopeDetails)) {
99
+ appendScopeDecision(viewScopeDecisions, decision);
79
100
  } else {
80
- if (!nonPageWideScopeDecisions[decision.scope]) {
81
- nonPageWideScopeDecisions[decision.scope] = [];
82
- }
83
-
84
- nonPageWideScopeDecisions[decision.scope].push(decision);
101
+ nonPageWideScopeDecisions.push(decision);
85
102
  }
86
103
  });
87
104
  }
88
105
 
89
106
  return {
90
107
  pageWideScopeDecisions: pageWideScopeDecisions,
91
- nonPageWideScopeDecisions: nonPageWideScopeDecisions
108
+ nonPageWideScopeDecisions: nonPageWideScopeDecisions,
109
+ viewScopeDecisions: viewScopeDecisions
92
110
  };
93
111
  };
94
112
 
95
113
  var groupDecisions = function groupDecisions(unprocessedDecisions) {
96
114
  var decisionsGroupedByRedirectItemSchema = splitDecisions(unprocessedDecisions, _schema.REDIRECT_ITEM);
97
- var decisionsGroupedByDomActionSchema = splitDecisions(decisionsGroupedByRedirectItemSchema.unmatchedDecisions, _schema.DOM_ACTION);
115
+ var decisionsGroupedByRenderableSchemas = splitDecisions(decisionsGroupedByRedirectItemSchema.unmatchedDecisions, _schema.DOM_ACTION, _schema.DEFAULT_CONTENT_ITEM);
98
116
 
99
- var _extractDecisionsBySc = extractDecisionsByScope(decisionsGroupedByDomActionSchema.matchedDecisions, _scope.default),
117
+ var _extractDecisionsBySc = extractDecisionsByScope(decisionsGroupedByRenderableSchemas.matchedDecisions),
100
118
  pageWideScopeDecisions = _extractDecisionsBySc.pageWideScopeDecisions,
101
- nonPageWideScopeDecisions = _extractDecisionsBySc.nonPageWideScopeDecisions;
119
+ nonPageWideScopeDecisions = _extractDecisionsBySc.nonPageWideScopeDecisions,
120
+ viewScopeDecisions = _extractDecisionsBySc.viewScopeDecisions;
102
121
 
103
122
  return {
104
123
  redirectDecisions: decisionsGroupedByRedirectItemSchema.matchedDecisions,
105
124
  pageWideScopeDecisions: pageWideScopeDecisions,
106
- viewDecisions: nonPageWideScopeDecisions,
107
- nonAutoRenderableDecisions: decisionsGroupedByDomActionSchema.unmatchedDecisions
125
+ viewDecisions: viewScopeDecisions,
126
+ nonAutoRenderableDecisions: decisionsGroupedByRenderableSchemas.unmatchedDecisions.concat(nonPageWideScopeDecisions)
108
127
  };
109
128
  };
110
129
 
@@ -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.9.0-alpha.3";
18
+ var _default = "2.9.0-alpha.4";
19
19
  exports.default = _default;
@@ -9,6 +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
+ export const DEFAULT_CONTENT_ITEM = "https://ns.adobe.com/personalization/default-content-item";
12
13
  export const DOM_ACTION = "https://ns.adobe.com/personalization/dom-action";
13
14
  export const HTML_CONTENT_ITEM = "https://ns.adobe.com/personalization/html-content-item";
14
15
  export const JSON_CONTENT_ITEM = "https://ns.adobe.com/personalization/json-content-item";
@@ -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 const VIEW_SCOPE_TYPE = "view";
@@ -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 { assign, flatMap, isNonEmptyArray } from "../../utils";
13
+ const DEFAULT_ACTION_TYPE = "defaultContent";
13
14
 
14
15
  const identity = item => item;
15
16
 
@@ -19,7 +20,9 @@ const buildActions = decision => {
19
20
  scope: decision.scope,
20
21
  scopeDetails: decision.scopeDetails
21
22
  };
22
- return decision.items.map(item => assign({}, item.data, {
23
+ return decision.items.map(item => assign({
24
+ type: DEFAULT_ACTION_TYPE
25
+ }, item.data, {
23
26
  meta
24
27
  }));
25
28
  };
@@ -11,7 +11,7 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  import { includes } from "../../utils";
13
13
  import PAGE_WIDE_SCOPE from "./constants/scope";
14
- import { DOM_ACTION, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM } from "./constants/schema";
14
+ import { DEFAULT_CONTENT_ITEM, DOM_ACTION, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM } from "./constants/schema";
15
15
  import isNonEmptyString from "../../utils/isNonEmptyString";
16
16
  export default (({
17
17
  renderDecisions,
@@ -44,7 +44,7 @@ export default (({
44
44
  scopes.push(PAGE_WIDE_SCOPE);
45
45
  }
46
46
 
47
- const schemas = [HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM];
47
+ const schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM];
48
48
 
49
49
  if (includes(scopes, PAGE_WIDE_SCOPE)) {
50
50
  schemas.push(DOM_ACTION);
@@ -28,6 +28,9 @@ export default (store => {
28
28
  replaceHtml: createAction(replaceHtml),
29
29
  prependHtml: createAction(prependHtml),
30
30
  appendHtml: createAction(appendHtml),
31
- click: settings => click(settings, store)
31
+ click: settings => click(settings, store),
32
+ defaultContent: settings => Promise.resolve({
33
+ meta: settings.meta
34
+ })
32
35
  };
33
36
  });
@@ -9,15 +9,16 @@ 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 { isNonEmptyArray } from "../../utils";
13
- import { DOM_ACTION, REDIRECT_ITEM } from "./constants/schema";
12
+ import { isNonEmptyArray, includes } from "../../utils";
13
+ import { DOM_ACTION, REDIRECT_ITEM, DEFAULT_CONTENT_ITEM } from "./constants/schema";
14
+ import { VIEW_SCOPE_TYPE } from "./constants/scopeType";
14
15
  import PAGE_WIDE_SCOPE from "./constants/scope";
15
16
 
16
- const splitItems = (items, schema) => {
17
+ const splitItems = (items, schemas) => {
17
18
  const matched = [];
18
19
  const nonMatched = [];
19
20
  items.forEach(item => {
20
- if (item.schema === schema) {
21
+ if (includes(schemas, item.schema)) {
21
22
  matched.push(item);
22
23
  } else {
23
24
  nonMatched.push(item);
@@ -35,14 +36,14 @@ const createDecision = (decision, items) => {
35
36
  };
36
37
  };
37
38
 
38
- const splitDecisions = (decisions, schema) => {
39
+ const splitDecisions = (decisions, ...schemas) => {
39
40
  const matchedDecisions = [];
40
41
  const unmatchedDecisions = [];
41
42
  decisions.forEach(decision => {
42
43
  const {
43
44
  items = []
44
45
  } = decision;
45
- const [matchedItems, nonMatchedItems] = splitItems(items, schema);
46
+ const [matchedItems, nonMatchedItems] = splitItems(items, schemas);
46
47
 
47
48
  if (isNonEmptyArray(matchedItems)) {
48
49
  matchedDecisions.push(createDecision(decision, matchedItems));
@@ -58,42 +59,53 @@ const splitDecisions = (decisions, schema) => {
58
59
  };
59
60
  };
60
61
 
61
- const extractDecisionsByScope = (decisions, scope) => {
62
+ const appendScopeDecision = (scopeDecisions, decision) => {
63
+ if (!scopeDecisions[decision.scope]) {
64
+ scopeDecisions[decision.scope] = [];
65
+ }
66
+
67
+ scopeDecisions[decision.scope].push(decision);
68
+ };
69
+
70
+ const isViewScope = scopeDetails => scopeDetails.characteristics && scopeDetails.characteristics.scopeType && scopeDetails.characteristics.scopeType === VIEW_SCOPE_TYPE;
71
+
72
+ const extractDecisionsByScope = decisions => {
62
73
  const pageWideScopeDecisions = [];
63
- const nonPageWideScopeDecisions = {};
74
+ const nonPageWideScopeDecisions = [];
75
+ const viewScopeDecisions = {};
64
76
 
65
77
  if (isNonEmptyArray(decisions)) {
66
78
  decisions.forEach(decision => {
67
- if (decision.scope === scope) {
79
+ if (decision.scope === PAGE_WIDE_SCOPE) {
68
80
  pageWideScopeDecisions.push(decision);
81
+ } else if (isViewScope(decision.scopeDetails)) {
82
+ appendScopeDecision(viewScopeDecisions, decision);
69
83
  } else {
70
- if (!nonPageWideScopeDecisions[decision.scope]) {
71
- nonPageWideScopeDecisions[decision.scope] = [];
72
- }
73
-
74
- nonPageWideScopeDecisions[decision.scope].push(decision);
84
+ nonPageWideScopeDecisions.push(decision);
75
85
  }
76
86
  });
77
87
  }
78
88
 
79
89
  return {
80
90
  pageWideScopeDecisions,
81
- nonPageWideScopeDecisions
91
+ nonPageWideScopeDecisions,
92
+ viewScopeDecisions
82
93
  };
83
94
  };
84
95
 
85
96
  const groupDecisions = unprocessedDecisions => {
86
97
  const decisionsGroupedByRedirectItemSchema = splitDecisions(unprocessedDecisions, REDIRECT_ITEM);
87
- const decisionsGroupedByDomActionSchema = splitDecisions(decisionsGroupedByRedirectItemSchema.unmatchedDecisions, DOM_ACTION);
98
+ const decisionsGroupedByRenderableSchemas = splitDecisions(decisionsGroupedByRedirectItemSchema.unmatchedDecisions, DOM_ACTION, DEFAULT_CONTENT_ITEM);
88
99
  const {
89
100
  pageWideScopeDecisions,
90
- nonPageWideScopeDecisions
91
- } = extractDecisionsByScope(decisionsGroupedByDomActionSchema.matchedDecisions, PAGE_WIDE_SCOPE);
101
+ nonPageWideScopeDecisions,
102
+ viewScopeDecisions
103
+ } = extractDecisionsByScope(decisionsGroupedByRenderableSchemas.matchedDecisions);
92
104
  return {
93
105
  redirectDecisions: decisionsGroupedByRedirectItemSchema.matchedDecisions,
94
106
  pageWideScopeDecisions,
95
- viewDecisions: nonPageWideScopeDecisions,
96
- nonAutoRenderableDecisions: decisionsGroupedByDomActionSchema.unmatchedDecisions
107
+ viewDecisions: viewScopeDecisions,
108
+ nonAutoRenderableDecisions: decisionsGroupedByRenderableSchemas.unmatchedDecisions.concat(nonPageWideScopeDecisions)
97
109
  };
98
110
  };
99
111
 
@@ -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.9.0-alpha.3";
14
+ export default "2.9.0-alpha.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.9.0-alpha.3",
3
+ "version": "2.9.0-alpha.4",
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.9.0-alpha.2",
67
+ "@adobe/alloy": "^2.9.0-alpha.3",
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",