@adobe/alloy 2.19.0-beta.9 → 2.19.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 (111) hide show
  1. package/libEs5/components/DataCollector/index.js +3 -0
  2. package/libEs5/components/DataCollector/validateApplyResponse.js +2 -1
  3. package/libEs5/components/DataCollector/validateUserEventOptions.js +2 -1
  4. package/libEs5/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +32 -0
  5. package/libEs5/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +25 -0
  6. package/libEs5/components/DecisioningEngine/constants.js +31 -0
  7. package/libEs5/components/DecisioningEngine/createApplyResponse.js +36 -0
  8. package/libEs5/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
  9. package/libEs5/components/DecisioningEngine/createContextProvider.js +93 -0
  10. package/libEs5/components/DecisioningEngine/createDecisionHistory.js +28 -0
  11. package/libEs5/components/DecisioningEngine/createDecisionProvider.js +51 -0
  12. package/libEs5/components/DecisioningEngine/createEvaluableRulesetPayload.js +80 -0
  13. package/libEs5/components/DecisioningEngine/createEvaluateRulesetsCommand.js +49 -0
  14. package/libEs5/components/DecisioningEngine/createEventRegistry.js +130 -0
  15. package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +46 -0
  16. package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +87 -0
  17. package/libEs5/components/DecisioningEngine/index.js +119 -0
  18. package/libEs5/components/DecisioningEngine/utils.js +90 -0
  19. package/libEs5/components/Personalization/createActionsProvider.js +72 -0
  20. package/libEs5/components/Personalization/createApplyPropositions.js +2 -2
  21. package/libEs5/components/Personalization/createCollect.js +9 -4
  22. package/libEs5/components/Personalization/createComponent.js +5 -3
  23. package/libEs5/components/Personalization/createFetchDataHandler.js +2 -17
  24. package/libEs5/components/Personalization/createNotificationHandler.js +33 -0
  25. package/libEs5/components/Personalization/createOnClickHandler.js +5 -3
  26. package/libEs5/components/Personalization/createOnDecisionHandler.js +44 -0
  27. package/libEs5/components/Personalization/createPersonalizationDetails.js +8 -5
  28. package/libEs5/components/Personalization/createPreprocessors.js +21 -0
  29. package/libEs5/components/Personalization/createViewCacheManager.js +9 -2
  30. package/libEs5/components/Personalization/dom-actions/createRedirect.js +11 -1
  31. package/libEs5/components/Personalization/event.js +25 -22
  32. package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +76 -0
  33. package/libEs5/components/Personalization/handlers/createProcessRedirect.js +5 -2
  34. package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +288 -0
  35. package/libEs5/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +23 -0
  36. package/libEs5/components/Personalization/in-app-message-actions/utils.js +53 -0
  37. package/libEs5/components/Personalization/index.js +20 -7
  38. package/libEs5/constants/contentType.js +18 -0
  39. package/libEs5/{components/Personalization/constants/propositionEventType.js → constants/decisionProvider.js} +4 -8
  40. package/libEs5/constants/eventType.js +25 -0
  41. package/libEs5/{components/Personalization/constants/eventType.js → constants/handle.js} +4 -7
  42. package/libEs5/constants/libraryVersion.js +1 -1
  43. package/libEs5/constants/propositionEventType.js +33 -0
  44. package/libEs5/{components/Personalization/constants → constants}/schema.js +9 -1
  45. package/libEs5/core/componentCreators.js +2 -1
  46. package/libEs5/core/createEvent.js +26 -1
  47. package/libEs5/core/createEventManager.js +3 -0
  48. package/libEs5/core/createLifecycle.js +4 -1
  49. package/libEs5/utils/createSubscription.js +91 -0
  50. package/libEs5/utils/debounce.js +30 -0
  51. package/libEs5/utils/dom/selectNodesWithShadow.js +10 -3
  52. package/libEs5/utils/flattenArray.js +37 -0
  53. package/libEs5/utils/flattenObject.js +43 -0
  54. package/libEs5/utils/index.js +7 -0
  55. package/libEs5/utils/parseUrl.js +70 -0
  56. package/libEs6/components/DataCollector/index.js +2 -0
  57. package/libEs6/components/DataCollector/validateApplyResponse.js +2 -1
  58. package/libEs6/components/DataCollector/validateUserEventOptions.js +2 -1
  59. package/libEs6/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +30 -0
  60. package/libEs6/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +24 -0
  61. package/libEs6/components/DecisioningEngine/constants.js +25 -0
  62. package/libEs6/components/DecisioningEngine/createApplyResponse.js +31 -0
  63. package/libEs6/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
  64. package/libEs6/components/DecisioningEngine/createContextProvider.js +95 -0
  65. package/libEs6/components/DecisioningEngine/createDecisionHistory.js +25 -0
  66. package/libEs6/components/DecisioningEngine/createDecisionProvider.js +41 -0
  67. package/libEs6/components/DecisioningEngine/createEvaluableRulesetPayload.js +79 -0
  68. package/libEs6/components/DecisioningEngine/createEvaluateRulesetsCommand.js +45 -0
  69. package/libEs6/components/DecisioningEngine/createEventRegistry.js +120 -0
  70. package/libEs6/components/DecisioningEngine/createOnResponseHandler.js +45 -0
  71. package/libEs6/components/DecisioningEngine/createSubscribeRulesetItems.js +79 -0
  72. package/libEs6/components/DecisioningEngine/index.js +124 -0
  73. package/libEs6/components/DecisioningEngine/utils.js +83 -0
  74. package/libEs6/components/Personalization/createActionsProvider.js +70 -0
  75. package/libEs6/components/Personalization/createApplyPropositions.js +2 -2
  76. package/libEs6/components/Personalization/createCollect.js +7 -4
  77. package/libEs6/components/Personalization/createComponent.js +5 -3
  78. package/libEs6/components/Personalization/createFetchDataHandler.js +3 -18
  79. package/libEs6/components/Personalization/createNotificationHandler.js +29 -0
  80. package/libEs6/components/Personalization/createOnClickHandler.js +5 -3
  81. package/libEs6/components/Personalization/createOnDecisionHandler.js +42 -0
  82. package/libEs6/components/Personalization/createPersonalizationDetails.js +8 -5
  83. package/libEs6/components/Personalization/createPreprocessors.js +19 -0
  84. package/libEs6/components/Personalization/createViewCacheManager.js +12 -3
  85. package/libEs6/components/Personalization/dom-actions/createRedirect.js +10 -1
  86. package/libEs6/components/Personalization/event.js +14 -9
  87. package/libEs6/components/Personalization/handlers/createProcessInAppMessage.js +77 -0
  88. package/libEs6/components/Personalization/handlers/createProcessRedirect.js +5 -2
  89. package/libEs6/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +291 -0
  90. package/libEs6/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +17 -0
  91. package/libEs6/components/Personalization/in-app-message-actions/utils.js +49 -0
  92. package/libEs6/components/Personalization/index.js +22 -8
  93. package/libEs6/{components/Personalization/constants/eventType.js → constants/contentType.js} +3 -4
  94. package/libEs6/{components/Personalization/constants/propositionEventType.js → constants/decisionProvider.js} +2 -6
  95. package/libEs6/constants/eventType.js +17 -0
  96. package/libEs6/constants/handle.js +12 -0
  97. package/libEs6/constants/libraryVersion.js +1 -1
  98. package/libEs6/constants/propositionEventType.js +33 -0
  99. package/libEs6/{components/Personalization/constants → constants}/schema.js +4 -0
  100. package/libEs6/core/componentCreators.js +2 -1
  101. package/libEs6/core/createEvent.js +26 -1
  102. package/libEs6/core/createEventManager.js +2 -0
  103. package/libEs6/core/createLifecycle.js +4 -1
  104. package/libEs6/utils/createSubscription.js +70 -0
  105. package/libEs6/utils/debounce.js +22 -0
  106. package/libEs6/utils/dom/selectNodesWithShadow.js +10 -3
  107. package/libEs6/utils/flattenArray.js +26 -0
  108. package/libEs6/utils/flattenObject.js +28 -0
  109. package/libEs6/utils/index.js +1 -0
  110. package/libEs6/utils/parseUrl.js +62 -0
  111. package/package.json +6 -2
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ exports.default = void 0;
4
+ var _parseUri = require("parse-uri");
5
+ var _isString = require("./isString");
6
+ 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; }
7
+ 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; }
8
+ 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; } /*
9
+ Copyright 2023 Adobe. All rights reserved.
10
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License. You may obtain a copy
12
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software distributed under
15
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ OF ANY KIND, either express or implied. See the License for the specific language
17
+ governing permissions and limitations under the License.
18
+ */
19
+ var parseDomainBasic = function parseDomainBasic(host) {
20
+ var result = {};
21
+ var domainParts = host.split(".");
22
+ switch (domainParts.length) {
23
+ case 1:
24
+ result.subdomain = "";
25
+ result.domain = host;
26
+ result.topLevelDomain = "";
27
+ break;
28
+ case 2:
29
+ result.subdomain = "";
30
+ result.domain = host;
31
+ result.topLevelDomain = domainParts[1];
32
+ break;
33
+ case 3:
34
+ result.subdomain = domainParts[0] === "www" ? "" : domainParts[0];
35
+ result.domain = host;
36
+ result.topLevelDomain = domainParts[2];
37
+ break;
38
+ case 4:
39
+ result.subdomain = domainParts[0] === "www" ? "" : domainParts[0];
40
+ result.domain = host;
41
+ result.topLevelDomain = domainParts[2] + "." + domainParts[3];
42
+ break;
43
+ default:
44
+ break;
45
+ }
46
+ return result;
47
+ };
48
+ var parseUrl = function parseUrl(url) {
49
+ var parseDomain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : parseDomainBasic;
50
+ if (!(0, _isString.default)(url)) {
51
+ // eslint-disable-next-line no-param-reassign
52
+ url = "";
53
+ }
54
+ var parsed = (0, _parseUri.default)(url) || {};
55
+ var _parsed$host = parsed.host,
56
+ host = _parsed$host === void 0 ? "" : _parsed$host,
57
+ _parsed$path = parsed.path,
58
+ path = _parsed$path === void 0 ? "" : _parsed$path,
59
+ _parsed$query = parsed.query,
60
+ query = _parsed$query === void 0 ? "" : _parsed$query,
61
+ _parsed$anchor = parsed.anchor,
62
+ anchor = _parsed$anchor === void 0 ? "" : _parsed$anchor;
63
+ return _objectSpread({
64
+ path: path,
65
+ query: query,
66
+ fragment: anchor
67
+ }, parseDomain(host));
68
+ };
69
+ var _default = parseUrl;
70
+ exports.default = _default;
@@ -82,6 +82,7 @@ const createDataCollector = ({
82
82
  run: options => {
83
83
  const {
84
84
  renderDecisions = false,
85
+ decisionContext = {},
85
86
  responseHeaders = {},
86
87
  responseBody = {
87
88
  handle: []
@@ -91,6 +92,7 @@ const createDataCollector = ({
91
92
  const event = eventManager.createEvent();
92
93
  return eventManager.applyResponse(event, {
93
94
  renderDecisions,
95
+ decisionContext,
94
96
  responseHeaders,
95
97
  responseBody,
96
98
  personalization
@@ -23,7 +23,8 @@ export default (({
23
23
  })).required()
24
24
  }).required(),
25
25
  personalization: objectOf({
26
- sendDisplayEvent: boolean().default(true)
26
+ sendDisplayEvent: boolean().default(true),
27
+ decisionContext: objectOf({})
27
28
  }).default({
28
29
  sendDisplayEvent: true
29
30
  })
@@ -35,7 +35,8 @@ export default (({
35
35
  surfaces: arrayOf(string()).uniqueItems(),
36
36
  sendDisplayEvent: boolean().default(true),
37
37
  includeRenderedPropositions: boolean().default(false),
38
- requestPersonalization: boolean()
38
+ defaultPersonalizationEnabled: boolean(),
39
+ decisionContext: objectOf({})
39
40
  }).default({
40
41
  sendDisplayEvent: true
41
42
  }),
@@ -0,0 +1,30 @@
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 { MESSAGE_IN_APP } from "../../../constants/schema";
13
+ import { TEXT_HTML } from "../../../constants/contentType";
14
+ export default ((id, type, detail) => {
15
+ const {
16
+ html,
17
+ mobileParameters
18
+ } = detail;
19
+ const webParameters = {};
20
+ return {
21
+ schema: MESSAGE_IN_APP,
22
+ data: {
23
+ mobileParameters,
24
+ webParameters,
25
+ content: html,
26
+ contentType: TEXT_HTML
27
+ },
28
+ id
29
+ };
30
+ });
@@ -0,0 +1,24 @@
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
+
13
+ export default ((id, type, detail) => {
14
+ const {
15
+ schema,
16
+ data,
17
+ id: detailId
18
+ } = detail;
19
+ return {
20
+ schema,
21
+ data,
22
+ id: detailId || id
23
+ };
24
+ });
@@ -0,0 +1,25 @@
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
+ export const CONTEXT_KEY = {
13
+ TYPE: "~type",
14
+ SOURCE: "~source"
15
+ };
16
+ export const CONTEXT_EVENT_TYPE = {
17
+ LIFECYCLE: "com.adobe.eventType.lifecycle",
18
+ TRACK: "com.adobe.eventType.generic.track",
19
+ EDGE: "com.adobe.eventType.edge",
20
+ RULES_ENGINE: "com.adobe.eventType.rulesEngine"
21
+ };
22
+ export const CONTEXT_EVENT_SOURCE = {
23
+ LAUNCH: "com.adobe.eventSource.applicationLaunch",
24
+ REQUEST: "com.adobe.eventSource.requestContent"
25
+ };
@@ -0,0 +1,31 @@
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
+ export default (lifecycle => {
13
+ return ({
14
+ renderDecisions = false,
15
+ propositions = [],
16
+ event,
17
+ personalization
18
+ }) => {
19
+ if (propositions.length > 0 && lifecycle) {
20
+ lifecycle.onDecision({
21
+ renderDecisions,
22
+ propositions,
23
+ event,
24
+ personalization
25
+ });
26
+ }
27
+ return {
28
+ propositions
29
+ };
30
+ };
31
+ });
@@ -0,0 +1,29 @@
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 inAppMessageConsequenceAdapter from "./consequenceAdapters/inAppMessageConsequenceAdapter";
13
+ import schemaTypeConsequenceAdapter from "./consequenceAdapters/schemaTypeConsequenceAdapter";
14
+ const CJM_IN_APP_MESSAGE_TYPE = "cjmiam";
15
+ const SCHEMA = "schema";
16
+ const adapters = {
17
+ [CJM_IN_APP_MESSAGE_TYPE]: inAppMessageConsequenceAdapter,
18
+ [SCHEMA]: schemaTypeConsequenceAdapter
19
+ };
20
+ export default (() => {
21
+ return consequence => {
22
+ const {
23
+ id,
24
+ type,
25
+ detail
26
+ } = consequence;
27
+ return typeof adapters[type] === "function" ? adapters[type](id, type, detail) : detail;
28
+ };
29
+ });
@@ -0,0 +1,95 @@
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 getBrowser from "../../utils/getBrowser";
13
+ import parseUrl from "../../utils/parseUrl";
14
+ import flattenObject from "../../utils/flattenObject";
15
+ import libraryVersion from "../../constants/libraryVersion";
16
+ export default (({
17
+ eventRegistry,
18
+ window
19
+ }) => {
20
+ const pageLoadTimestamp = new Date().getTime();
21
+ const getBrowserContext = () => {
22
+ return {
23
+ name: getBrowser(window)
24
+ };
25
+ };
26
+ const getPageContext = () => {
27
+ return {
28
+ title: window.title,
29
+ url: window.url,
30
+ ...parseUrl(window.url)
31
+ };
32
+ };
33
+ const getReferrerContext = () => {
34
+ return {
35
+ url: window.referrer,
36
+ ...parseUrl(window.referrer)
37
+ };
38
+ };
39
+ const getTimeContext = () => {
40
+ const now = new Date();
41
+ const currentTimestamp = now.getTime();
42
+ return {
43
+ pageLoadTimestamp,
44
+ currentTimestamp,
45
+ currentDate: now.getDate(),
46
+ // Day of the week starts on Monday as is practiced in ISO 8601, but we want it to start on Sunday to match the authoring UI rule
47
+ "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": now.getDay() + 1,
48
+ "~state.com.adobe.module.lifecycle/lifecyclecontextdata.hourofday": now.getHours(),
49
+ currentMinute: now.getMinutes(),
50
+ currentMonth: now.getMonth(),
51
+ currentYear: now.getFullYear(),
52
+ pageVisitDuration: currentTimestamp - pageLoadTimestamp,
53
+ "~timestampu": currentTimestamp / 1000,
54
+ "~timestampz": now.toISOString()
55
+ };
56
+ };
57
+ const getWindowContext = () => {
58
+ const height = window.height;
59
+ const width = window.width;
60
+ const scrollY = window.scrollY;
61
+ const scrollX = window.scrollX;
62
+ return {
63
+ height,
64
+ width,
65
+ scrollY,
66
+ scrollX
67
+ };
68
+ };
69
+ const coreGlobalContext = {
70
+ browser: getBrowserContext(),
71
+ page: getPageContext(),
72
+ referringPage: getReferrerContext()
73
+ };
74
+ const getGlobalContext = () => {
75
+ return {
76
+ ...coreGlobalContext,
77
+ ...getTimeContext(),
78
+ window: getWindowContext(),
79
+ "~sdkver": libraryVersion
80
+ };
81
+ };
82
+ const getContext = (addedContext = {}) => {
83
+ const context = {
84
+ ...getGlobalContext(),
85
+ ...addedContext
86
+ };
87
+ return {
88
+ ...flattenObject(context),
89
+ events: eventRegistry.toJSON()
90
+ };
91
+ };
92
+ return {
93
+ getContext
94
+ };
95
+ });
@@ -0,0 +1,25 @@
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
+ eventRegistry
15
+ }) => {
16
+ const recordQualified = id => {
17
+ if (!id) {
18
+ return undefined;
19
+ }
20
+ return eventRegistry.addEvent({}, PropositionEventType.TRIGGER, id);
21
+ };
22
+ return {
23
+ recordQualified
24
+ };
25
+ });
@@ -0,0 +1,41 @@
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 createEvaluableRulesetPayload from "./createEvaluableRulesetPayload";
13
+ import createDecisionHistory from "./createDecisionHistory";
14
+ import { getActivityId } from "./utils";
15
+ export default (({
16
+ eventRegistry
17
+ }) => {
18
+ const payloadsBasedOnActivityId = {};
19
+ const decisionHistory = createDecisionHistory({
20
+ eventRegistry
21
+ });
22
+ const addPayload = payload => {
23
+ const activityId = getActivityId(payload);
24
+ if (!activityId) {
25
+ return;
26
+ }
27
+ const evaluableRulesetPayload = createEvaluableRulesetPayload(payload, eventRegistry, decisionHistory);
28
+ if (evaluableRulesetPayload.isEvaluable) {
29
+ payloadsBasedOnActivityId[activityId] = evaluableRulesetPayload;
30
+ }
31
+ };
32
+ const evaluate = (context = {}) => Object.values(payloadsBasedOnActivityId).map(payload => payload.evaluate(context)).filter(payload => payload.items.length > 0);
33
+ const addPayloads = personalizationPayloads => {
34
+ personalizationPayloads.forEach(addPayload);
35
+ };
36
+ return {
37
+ addPayload,
38
+ addPayloads,
39
+ evaluate
40
+ };
41
+ });
@@ -0,0 +1,79 @@
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 RulesEngine from "@adobe/aep-rules-engine";
13
+ import { JSON_CONTENT_ITEM, RULESET_ITEM } from "../../constants/schema";
14
+ import { DISPLAY } from "../../constants/eventType";
15
+ import { getActivityId } from "./utils";
16
+ import flattenArray from "../../utils/flattenArray";
17
+ import createConsequenceAdapter from "./createConsequenceAdapter";
18
+ const isRulesetItem = item => {
19
+ const {
20
+ schema,
21
+ data
22
+ } = item;
23
+ if (schema === RULESET_ITEM) {
24
+ return true;
25
+ }
26
+ if (schema !== JSON_CONTENT_ITEM) {
27
+ return false;
28
+ }
29
+ try {
30
+ const content = typeof data.content === "string" ? JSON.parse(data.content) : data.content;
31
+ return content && Object.prototype.hasOwnProperty.call(content, "version") && Object.prototype.hasOwnProperty.call(content, "rules");
32
+ } catch (error) {
33
+ return false;
34
+ }
35
+ };
36
+ export default ((payload, eventRegistry, decisionHistory) => {
37
+ const consequenceAdapter = createConsequenceAdapter();
38
+ const activityId = getActivityId(payload);
39
+ const items = [];
40
+ const addItem = item => {
41
+ const {
42
+ data = {},
43
+ schema
44
+ } = item;
45
+ const content = schema === RULESET_ITEM ? data : data.content;
46
+ if (!content) {
47
+ return;
48
+ }
49
+ items.push(RulesEngine(typeof content === "string" ? JSON.parse(content) : content));
50
+ };
51
+ const evaluate = context => {
52
+ const displayEvent = eventRegistry.getEvent(DISPLAY, activityId);
53
+ const displayedDate = displayEvent ? displayEvent.firstTimestamp : undefined;
54
+ const qualifyingItems = flattenArray(items.map(item => item.execute(context))).map(consequenceAdapter).map(item => {
55
+ const {
56
+ firstTimestamp: qualifiedDate
57
+ } = decisionHistory.recordQualified(activityId) || {};
58
+ return {
59
+ ...item,
60
+ data: {
61
+ ...item.data,
62
+ qualifiedDate,
63
+ displayedDate
64
+ }
65
+ };
66
+ });
67
+ return {
68
+ ...payload,
69
+ items: qualifyingItems
70
+ };
71
+ };
72
+ if (Array.isArray(payload.items)) {
73
+ payload.items.filter(isRulesetItem).forEach(addItem);
74
+ }
75
+ return {
76
+ evaluate,
77
+ isEvaluable: items.length > 0
78
+ };
79
+ });
@@ -0,0 +1,45 @@
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 { boolean, objectOf } from "../../utils/validation";
13
+ const validateOptions = ({
14
+ options
15
+ }) => {
16
+ const validator = objectOf({
17
+ renderDecisions: boolean(),
18
+ personalization: objectOf({
19
+ decisionContext: objectOf({})
20
+ })
21
+ }).noUnknownFields();
22
+ return validator(options);
23
+ };
24
+ export default (({
25
+ contextProvider,
26
+ decisionProvider
27
+ }) => {
28
+ const run = ({
29
+ renderDecisions,
30
+ decisionContext,
31
+ applyResponse
32
+ }) => {
33
+ return applyResponse({
34
+ renderDecisions,
35
+ propositions: decisionProvider.evaluate(contextProvider.getContext(decisionContext))
36
+ });
37
+ };
38
+ const optionsValidator = options => validateOptions({
39
+ options
40
+ });
41
+ return {
42
+ optionsValidator,
43
+ run
44
+ };
45
+ });
@@ -0,0 +1,120 @@
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 { createRestoreStorage, createSaveStorage, getExpirationDate, getActivityId, hasExperienceData, getDecisionProvider } from "./utils";
13
+ import { EVENT_TYPE_TRUE } from "../../constants/eventType";
14
+ import { ADOBE_JOURNEY_OPTIMIZER } from "../../constants/decisionProvider";
15
+ const STORAGE_KEY = "events";
16
+ const MAX_EVENT_RECORDS = 1000;
17
+ const RETENTION_PERIOD = 30;
18
+ const prefixed = key => `iam.${key}`;
19
+ export const createEventPruner = (limit = MAX_EVENT_RECORDS, retentionPeriod = RETENTION_PERIOD) => {
20
+ return events => {
21
+ const pruned = {};
22
+ Object.keys(events).forEach(eventType => {
23
+ pruned[eventType] = {};
24
+ Object.values(events[eventType]).filter(entry => new Date(entry.firstTimestamp) >= getExpirationDate(retentionPeriod)).sort((a, b) => a.firstTimestamp - b.firstTimestamp).slice(-1 * limit).forEach(entry => {
25
+ pruned[eventType][entry.event[prefixed("id")]] = entry;
26
+ });
27
+ });
28
+ return pruned;
29
+ };
30
+ };
31
+ export default (({
32
+ storage
33
+ }) => {
34
+ let currentStorage = storage;
35
+ let restore;
36
+ let save;
37
+ let events;
38
+ const setStorage = newStorage => {
39
+ currentStorage = newStorage;
40
+ restore = createRestoreStorage(currentStorage, STORAGE_KEY);
41
+ save = createSaveStorage(currentStorage, STORAGE_KEY, createEventPruner(MAX_EVENT_RECORDS, RETENTION_PERIOD));
42
+ events = restore({});
43
+ };
44
+ setStorage(storage);
45
+ const addEvent = (event, eventType, eventId, action) => {
46
+ if (!eventType || !eventId) {
47
+ return undefined;
48
+ }
49
+ if (!events[eventType]) {
50
+ events[eventType] = {};
51
+ }
52
+ const existingEvent = events[eventType][eventId];
53
+ const count = existingEvent ? existingEvent.count : 0;
54
+ const timestamp = new Date().getTime();
55
+ const firstTimestamp = existingEvent ? existingEvent.firstTimestamp || existingEvent.timestamp : timestamp;
56
+ events[eventType][eventId] = {
57
+ event: {
58
+ ...event,
59
+ [prefixed("id")]: eventId,
60
+ [prefixed("eventType")]: eventType,
61
+ [prefixed("action")]: action
62
+ },
63
+ firstTimestamp,
64
+ timestamp,
65
+ count: count + 1
66
+ };
67
+ save(events);
68
+ return events[eventType][eventId];
69
+ };
70
+ const addExperienceEdgeEvent = event => {
71
+ const {
72
+ xdm = {}
73
+ } = event.getContent();
74
+ const {
75
+ _experience
76
+ } = xdm;
77
+ if (!hasExperienceData(xdm)) {
78
+ return;
79
+ }
80
+ const {
81
+ decisioning = {}
82
+ } = _experience;
83
+ const {
84
+ propositionEventType: propositionEventTypeObj = {},
85
+ propositionAction = {},
86
+ propositions = []
87
+ } = decisioning;
88
+ const propositionEventTypesList = Object.keys(propositionEventTypeObj);
89
+
90
+ // https://wiki.corp.adobe.com/pages/viewpage.action?spaceKey=CJM&title=Proposition+Event+Types
91
+ if (propositionEventTypesList.length === 0) {
92
+ return;
93
+ }
94
+ const validPropositionEventType = propositionEventType => propositionEventTypeObj[propositionEventType] === EVENT_TYPE_TRUE;
95
+ const {
96
+ id: action
97
+ } = propositionAction;
98
+ propositionEventTypesList.filter(validPropositionEventType).forEach(propositionEventType => {
99
+ propositions.forEach(proposition => {
100
+ if (getDecisionProvider(proposition) !== ADOBE_JOURNEY_OPTIMIZER) {
101
+ return;
102
+ }
103
+ addEvent({}, propositionEventType, getActivityId(proposition), action);
104
+ });
105
+ });
106
+ };
107
+ const getEvent = (eventType, eventId) => {
108
+ if (!events[eventType]) {
109
+ return undefined;
110
+ }
111
+ return events[eventType][eventId];
112
+ };
113
+ return {
114
+ addExperienceEdgeEvent,
115
+ addEvent,
116
+ getEvent,
117
+ toJSON: () => events,
118
+ setStorage
119
+ };
120
+ });