@adobe/alloy 2.19.0-beta.9 → 2.19.1-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.
- package/README.md +4 -1
- package/libEs5/components/DataCollector/index.js +3 -0
- package/libEs5/components/DataCollector/validateApplyResponse.js +2 -1
- package/libEs5/components/DataCollector/validateUserEventOptions.js +2 -1
- package/libEs5/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +32 -0
- package/libEs5/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +25 -0
- package/libEs5/components/DecisioningEngine/constants.js +31 -0
- package/libEs5/components/DecisioningEngine/createApplyResponse.js +36 -0
- package/libEs5/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
- package/libEs5/components/DecisioningEngine/createContextProvider.js +93 -0
- package/libEs5/components/DecisioningEngine/createDecisionHistory.js +28 -0
- package/libEs5/components/DecisioningEngine/createDecisionProvider.js +51 -0
- package/libEs5/components/DecisioningEngine/createEvaluableRulesetPayload.js +80 -0
- package/libEs5/components/DecisioningEngine/createEvaluateRulesetsCommand.js +49 -0
- package/libEs5/components/DecisioningEngine/createEventRegistry.js +130 -0
- package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +46 -0
- package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +87 -0
- package/libEs5/components/DecisioningEngine/index.js +119 -0
- package/libEs5/components/DecisioningEngine/utils.js +90 -0
- package/libEs5/components/Personalization/createActionsProvider.js +72 -0
- package/libEs5/components/Personalization/createApplyPropositions.js +2 -2
- package/libEs5/components/Personalization/createCollect.js +9 -4
- package/libEs5/components/Personalization/createComponent.js +5 -3
- package/libEs5/components/Personalization/createFetchDataHandler.js +2 -17
- package/libEs5/components/Personalization/createNotificationHandler.js +33 -0
- package/libEs5/components/Personalization/createOnClickHandler.js +5 -3
- package/libEs5/components/Personalization/createOnDecisionHandler.js +44 -0
- package/libEs5/components/Personalization/createPersonalizationDetails.js +8 -5
- package/libEs5/components/Personalization/createPreprocessors.js +21 -0
- package/libEs5/components/Personalization/createViewCacheManager.js +9 -2
- package/libEs5/components/Personalization/dom-actions/createRedirect.js +11 -1
- package/libEs5/components/Personalization/event.js +25 -22
- package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +76 -0
- package/libEs5/components/Personalization/handlers/createProcessRedirect.js +5 -2
- package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +288 -0
- package/libEs5/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +23 -0
- package/libEs5/components/Personalization/in-app-message-actions/utils.js +53 -0
- package/libEs5/components/Personalization/index.js +20 -7
- package/libEs5/constants/contentType.js +18 -0
- package/libEs5/{components/Personalization/constants/propositionEventType.js → constants/decisionProvider.js} +4 -8
- package/libEs5/constants/eventType.js +25 -0
- package/libEs5/{components/Personalization/constants/eventType.js → constants/handle.js} +4 -7
- package/libEs5/constants/libraryVersion.js +1 -1
- package/libEs5/constants/propositionEventType.js +33 -0
- package/libEs5/{components/Personalization/constants → constants}/schema.js +9 -1
- package/libEs5/core/componentCreators.js +2 -1
- package/libEs5/core/createEvent.js +26 -1
- package/libEs5/core/createEventManager.js +3 -0
- package/libEs5/core/createLifecycle.js +4 -1
- package/libEs5/core/edgeNetwork/mergeLifecycleResponses.js +1 -1
- package/libEs5/utils/assignConcatArrayValues.js +49 -0
- package/libEs5/utils/createSubscription.js +91 -0
- package/libEs5/utils/debounce.js +30 -0
- package/libEs5/utils/dom/selectNodesWithShadow.js +10 -3
- package/libEs5/utils/flattenArray.js +37 -0
- package/libEs5/utils/flattenObject.js +43 -0
- package/libEs5/utils/index.js +14 -0
- package/libEs5/utils/parseUrl.js +70 -0
- package/libEs6/components/DataCollector/index.js +2 -0
- package/libEs6/components/DataCollector/validateApplyResponse.js +2 -1
- package/libEs6/components/DataCollector/validateUserEventOptions.js +2 -1
- package/libEs6/components/DecisioningEngine/consequenceAdapters/inAppMessageConsequenceAdapter.js +30 -0
- package/libEs6/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js +24 -0
- package/libEs6/components/DecisioningEngine/constants.js +25 -0
- package/libEs6/components/DecisioningEngine/createApplyResponse.js +31 -0
- package/libEs6/components/DecisioningEngine/createConsequenceAdapter.js +29 -0
- package/libEs6/components/DecisioningEngine/createContextProvider.js +95 -0
- package/libEs6/components/DecisioningEngine/createDecisionHistory.js +25 -0
- package/libEs6/components/DecisioningEngine/createDecisionProvider.js +41 -0
- package/libEs6/components/DecisioningEngine/createEvaluableRulesetPayload.js +79 -0
- package/libEs6/components/DecisioningEngine/createEvaluateRulesetsCommand.js +45 -0
- package/libEs6/components/DecisioningEngine/createEventRegistry.js +120 -0
- package/libEs6/components/DecisioningEngine/createOnResponseHandler.js +45 -0
- package/libEs6/components/DecisioningEngine/createSubscribeRulesetItems.js +79 -0
- package/libEs6/components/DecisioningEngine/index.js +124 -0
- package/libEs6/components/DecisioningEngine/utils.js +83 -0
- package/libEs6/components/Personalization/createActionsProvider.js +70 -0
- package/libEs6/components/Personalization/createApplyPropositions.js +2 -2
- package/libEs6/components/Personalization/createCollect.js +7 -4
- package/libEs6/components/Personalization/createComponent.js +5 -3
- package/libEs6/components/Personalization/createFetchDataHandler.js +3 -18
- package/libEs6/components/Personalization/createNotificationHandler.js +29 -0
- package/libEs6/components/Personalization/createOnClickHandler.js +5 -3
- package/libEs6/components/Personalization/createOnDecisionHandler.js +42 -0
- package/libEs6/components/Personalization/createPersonalizationDetails.js +8 -5
- package/libEs6/components/Personalization/createPreprocessors.js +19 -0
- package/libEs6/components/Personalization/createViewCacheManager.js +12 -3
- package/libEs6/components/Personalization/dom-actions/createRedirect.js +10 -1
- package/libEs6/components/Personalization/event.js +14 -9
- package/libEs6/components/Personalization/handlers/createProcessInAppMessage.js +77 -0
- package/libEs6/components/Personalization/handlers/createProcessRedirect.js +5 -2
- package/libEs6/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +291 -0
- package/libEs6/components/Personalization/in-app-message-actions/initInAppMessageActionsModules.js +17 -0
- package/libEs6/components/Personalization/in-app-message-actions/utils.js +49 -0
- package/libEs6/components/Personalization/index.js +22 -8
- package/libEs6/{components/Personalization/constants/eventType.js → constants/contentType.js} +3 -4
- package/libEs6/{components/Personalization/constants/propositionEventType.js → constants/decisionProvider.js} +2 -6
- package/libEs6/constants/eventType.js +17 -0
- package/libEs6/constants/handle.js +12 -0
- package/libEs6/constants/libraryVersion.js +1 -1
- package/libEs6/constants/propositionEventType.js +33 -0
- package/libEs6/{components/Personalization/constants → constants}/schema.js +4 -0
- package/libEs6/core/componentCreators.js +2 -1
- package/libEs6/core/createEvent.js +26 -1
- package/libEs6/core/createEventManager.js +2 -0
- package/libEs6/core/createLifecycle.js +4 -1
- package/libEs6/core/edgeNetwork/mergeLifecycleResponses.js +3 -2
- package/libEs6/utils/assignConcatArrayValues.js +36 -0
- package/libEs6/utils/createSubscription.js +70 -0
- package/libEs6/utils/debounce.js +22 -0
- package/libEs6/utils/dom/selectNodesWithShadow.js +10 -3
- package/libEs6/utils/flattenArray.js +26 -0
- package/libEs6/utils/flattenObject.js +28 -0
- package/libEs6/utils/index.js +2 -0
- package/libEs6/utils/parseUrl.js +62 -0
- package/package.json +6 -2
|
@@ -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
|
+
});
|
|
@@ -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 { PERSONALIZATION_DECISIONS_HANDLE } from "../../constants/handle";
|
|
13
|
+
import flattenObject from "../../utils/flattenObject";
|
|
14
|
+
export default (({
|
|
15
|
+
renderDecisions,
|
|
16
|
+
decisionProvider,
|
|
17
|
+
applyResponse,
|
|
18
|
+
event,
|
|
19
|
+
personalization,
|
|
20
|
+
decisionContext
|
|
21
|
+
}) => {
|
|
22
|
+
const context = {
|
|
23
|
+
...flattenObject(event.getContent()),
|
|
24
|
+
...decisionContext
|
|
25
|
+
};
|
|
26
|
+
return ({
|
|
27
|
+
response
|
|
28
|
+
}) => {
|
|
29
|
+
decisionProvider.addPayloads(response.getPayloadsByType(PERSONALIZATION_DECISIONS_HANDLE));
|
|
30
|
+
|
|
31
|
+
// only evaluate events that include a personalization query
|
|
32
|
+
if (!event.hasQuery()) {
|
|
33
|
+
return {
|
|
34
|
+
propositions: []
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const propositions = decisionProvider.evaluate(context);
|
|
38
|
+
return applyResponse({
|
|
39
|
+
renderDecisions,
|
|
40
|
+
propositions,
|
|
41
|
+
event,
|
|
42
|
+
personalization
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
});
|
|
@@ -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 { arrayOf, callback as callbackType, objectOf, string } from "../../utils/validation";
|
|
13
|
+
import createSubscription from "../../utils/createSubscription";
|
|
14
|
+
import { includes } from "../../utils";
|
|
15
|
+
const validateOptions = ({
|
|
16
|
+
options
|
|
17
|
+
}) => {
|
|
18
|
+
const validator = objectOf({
|
|
19
|
+
surfaces: arrayOf(string()).uniqueItems(),
|
|
20
|
+
schemas: arrayOf(string()).uniqueItems(),
|
|
21
|
+
callback: callbackType().required()
|
|
22
|
+
}).noUnknownFields();
|
|
23
|
+
return validator(options);
|
|
24
|
+
};
|
|
25
|
+
const emissionPreprocessor = (params, propositions) => {
|
|
26
|
+
const {
|
|
27
|
+
surfacesFilter,
|
|
28
|
+
schemasFilter
|
|
29
|
+
} = params;
|
|
30
|
+
const result = {
|
|
31
|
+
propositions: propositions.filter(payload => surfacesFilter ? includes(surfacesFilter, payload.scope) : true).map(payload => {
|
|
32
|
+
const {
|
|
33
|
+
items = []
|
|
34
|
+
} = payload;
|
|
35
|
+
return {
|
|
36
|
+
...payload,
|
|
37
|
+
items: items.filter(item => schemasFilter ? includes(schemasFilter, item.schema) : true)
|
|
38
|
+
};
|
|
39
|
+
}).filter(payload => payload.items.length > 0)
|
|
40
|
+
};
|
|
41
|
+
return [result];
|
|
42
|
+
};
|
|
43
|
+
const emissionCondition = (params, result) => {
|
|
44
|
+
return result.propositions.length > 0;
|
|
45
|
+
};
|
|
46
|
+
export default (() => {
|
|
47
|
+
const subscription = createSubscription();
|
|
48
|
+
subscription.setEmissionPreprocessor(emissionPreprocessor);
|
|
49
|
+
subscription.setEmissionCondition(emissionCondition);
|
|
50
|
+
const run = ({
|
|
51
|
+
surfaces,
|
|
52
|
+
schemas,
|
|
53
|
+
callback
|
|
54
|
+
}) => {
|
|
55
|
+
const unsubscribe = subscription.add(callback, {
|
|
56
|
+
surfacesFilter: surfaces instanceof Array ? surfaces : undefined,
|
|
57
|
+
schemasFilter: schemas instanceof Array ? schemas : undefined
|
|
58
|
+
});
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
unsubscribe
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const optionsValidator = options => validateOptions({
|
|
64
|
+
options
|
|
65
|
+
});
|
|
66
|
+
const refresh = propositions => {
|
|
67
|
+
if (!subscription.hasSubscriptions()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
subscription.emit(propositions);
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
refresh,
|
|
74
|
+
command: {
|
|
75
|
+
optionsValidator,
|
|
76
|
+
run
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { noop, sanitizeOrgIdForCookieName } from "../../utils";
|
|
13
|
+
import createOnResponseHandler from "./createOnResponseHandler";
|
|
14
|
+
import createDecisionProvider from "./createDecisionProvider";
|
|
15
|
+
import createApplyResponse from "./createApplyResponse";
|
|
16
|
+
import createEventRegistry from "./createEventRegistry";
|
|
17
|
+
import createContextProvider from "./createContextProvider";
|
|
18
|
+
import createSubscribeRulesetItems from "./createSubscribeRulesetItems";
|
|
19
|
+
import { CONTEXT_KEY, CONTEXT_EVENT_SOURCE, CONTEXT_EVENT_TYPE } from "./constants";
|
|
20
|
+
import createEvaluateRulesetsCommand from "./createEvaluateRulesetsCommand";
|
|
21
|
+
import { clearLocalStorage, createInMemoryStorage } from "./utils";
|
|
22
|
+
import { objectOf, boolean } from "../../utils/validation";
|
|
23
|
+
const createDecisioningEngine = ({
|
|
24
|
+
config,
|
|
25
|
+
createNamespacedStorage,
|
|
26
|
+
consent
|
|
27
|
+
}) => {
|
|
28
|
+
const {
|
|
29
|
+
orgId,
|
|
30
|
+
personalizationStorageEnabled
|
|
31
|
+
} = config;
|
|
32
|
+
const storage = createNamespacedStorage(`${sanitizeOrgIdForCookieName(orgId)}.decisioning.`);
|
|
33
|
+
if (!personalizationStorageEnabled) {
|
|
34
|
+
clearLocalStorage(storage.persistent);
|
|
35
|
+
}
|
|
36
|
+
const eventRegistry = createEventRegistry({
|
|
37
|
+
storage: createInMemoryStorage()
|
|
38
|
+
});
|
|
39
|
+
const decisionProvider = createDecisionProvider({
|
|
40
|
+
eventRegistry
|
|
41
|
+
});
|
|
42
|
+
const contextProvider = createContextProvider({
|
|
43
|
+
eventRegistry,
|
|
44
|
+
window
|
|
45
|
+
});
|
|
46
|
+
const evaluateRulesetsCommand = createEvaluateRulesetsCommand({
|
|
47
|
+
contextProvider,
|
|
48
|
+
decisionProvider
|
|
49
|
+
});
|
|
50
|
+
const subscribeRulesetItems = createSubscribeRulesetItems();
|
|
51
|
+
let applyResponse;
|
|
52
|
+
return {
|
|
53
|
+
lifecycle: {
|
|
54
|
+
onDecision({
|
|
55
|
+
propositions
|
|
56
|
+
}) {
|
|
57
|
+
subscribeRulesetItems.refresh(propositions);
|
|
58
|
+
},
|
|
59
|
+
onComponentsRegistered(tools) {
|
|
60
|
+
applyResponse = createApplyResponse(tools.lifecycle);
|
|
61
|
+
if (personalizationStorageEnabled) {
|
|
62
|
+
consent.awaitConsent().then(() => {
|
|
63
|
+
eventRegistry.setStorage(storage.persistent);
|
|
64
|
+
}).catch(() => {
|
|
65
|
+
if (storage) {
|
|
66
|
+
clearLocalStorage(storage.persistent);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
onBeforeEvent({
|
|
72
|
+
event,
|
|
73
|
+
renderDecisions,
|
|
74
|
+
personalization = {},
|
|
75
|
+
onResponse = noop
|
|
76
|
+
}) {
|
|
77
|
+
const {
|
|
78
|
+
decisionContext = {}
|
|
79
|
+
} = personalization;
|
|
80
|
+
onResponse(createOnResponseHandler({
|
|
81
|
+
renderDecisions,
|
|
82
|
+
decisionProvider,
|
|
83
|
+
applyResponse,
|
|
84
|
+
event,
|
|
85
|
+
personalization,
|
|
86
|
+
decisionContext: contextProvider.getContext({
|
|
87
|
+
[CONTEXT_KEY.TYPE]: CONTEXT_EVENT_TYPE.EDGE,
|
|
88
|
+
[CONTEXT_KEY.SOURCE]: CONTEXT_EVENT_SOURCE.REQUEST,
|
|
89
|
+
...decisionContext
|
|
90
|
+
})
|
|
91
|
+
}));
|
|
92
|
+
eventRegistry.addExperienceEdgeEvent(event);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
commands: {
|
|
96
|
+
evaluateRulesets: {
|
|
97
|
+
run: ({
|
|
98
|
+
renderDecisions,
|
|
99
|
+
personalization = {}
|
|
100
|
+
}) => {
|
|
101
|
+
const {
|
|
102
|
+
decisionContext = {}
|
|
103
|
+
} = personalization;
|
|
104
|
+
return evaluateRulesetsCommand.run({
|
|
105
|
+
renderDecisions,
|
|
106
|
+
decisionContext: {
|
|
107
|
+
[CONTEXT_KEY.TYPE]: CONTEXT_EVENT_TYPE.RULES_ENGINE,
|
|
108
|
+
[CONTEXT_KEY.SOURCE]: CONTEXT_EVENT_SOURCE.REQUEST,
|
|
109
|
+
...decisionContext
|
|
110
|
+
},
|
|
111
|
+
applyResponse
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
optionsValidator: evaluateRulesetsCommand.optionsValidator
|
|
115
|
+
},
|
|
116
|
+
subscribeRulesetItems: subscribeRulesetItems.command
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
createDecisioningEngine.namespace = "DecisioningEngine";
|
|
121
|
+
createDecisioningEngine.configValidators = objectOf({
|
|
122
|
+
personalizationStorageEnabled: boolean().default(false)
|
|
123
|
+
});
|
|
124
|
+
export default createDecisioningEngine;
|
|
@@ -0,0 +1,83 @@
|
|
|
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 const createRestoreStorage = (storage, storageKey) => {
|
|
14
|
+
return defaultValue => {
|
|
15
|
+
const stored = storage.getItem(storageKey);
|
|
16
|
+
if (!stored) {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(stored);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return defaultValue;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const createSaveStorage = (storage, storageKey, prepareFn = value => value) => {
|
|
27
|
+
return value => {
|
|
28
|
+
storage.setItem(storageKey, JSON.stringify(prepareFn(value)));
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const getExpirationDate = retentionPeriod => {
|
|
32
|
+
const expirationDate = new Date();
|
|
33
|
+
expirationDate.setDate(expirationDate.getDate() - retentionPeriod);
|
|
34
|
+
return expirationDate;
|
|
35
|
+
};
|
|
36
|
+
export const getActivityId = proposition => {
|
|
37
|
+
const {
|
|
38
|
+
scopeDetails = {}
|
|
39
|
+
} = proposition;
|
|
40
|
+
const {
|
|
41
|
+
activity = {}
|
|
42
|
+
} = scopeDetails;
|
|
43
|
+
const {
|
|
44
|
+
id
|
|
45
|
+
} = activity;
|
|
46
|
+
return id;
|
|
47
|
+
};
|
|
48
|
+
export const createInMemoryStorage = () => {
|
|
49
|
+
const inMemoryStorage = {};
|
|
50
|
+
return {
|
|
51
|
+
getItem: key => {
|
|
52
|
+
return key in inMemoryStorage ? inMemoryStorage[key] : null;
|
|
53
|
+
},
|
|
54
|
+
setItem: (key, value) => {
|
|
55
|
+
inMemoryStorage[key] = value;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export const clearLocalStorage = storage => {
|
|
60
|
+
storage.clear();
|
|
61
|
+
};
|
|
62
|
+
export const hasExperienceData = xdm => {
|
|
63
|
+
const {
|
|
64
|
+
eventType = "",
|
|
65
|
+
_experience
|
|
66
|
+
} = xdm;
|
|
67
|
+
if (!eventType || eventType === "") {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (!_experience || typeof _experience !== "object") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
75
|
+
export const getDecisionProvider = proposition => {
|
|
76
|
+
const {
|
|
77
|
+
scopeDetails = {}
|
|
78
|
+
} = proposition;
|
|
79
|
+
const {
|
|
80
|
+
decisionProvider
|
|
81
|
+
} = scopeDetails;
|
|
82
|
+
return decisionProvider;
|
|
83
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
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 createPreprocessors from "./createPreprocessors";
|
|
13
|
+
import { assign } from "../../utils";
|
|
14
|
+
export default (({
|
|
15
|
+
modules,
|
|
16
|
+
preprocessors = createPreprocessors(),
|
|
17
|
+
logger
|
|
18
|
+
}) => {
|
|
19
|
+
const logActionError = (action, error) => {
|
|
20
|
+
if (logger.enabled) {
|
|
21
|
+
const details = JSON.stringify(action);
|
|
22
|
+
const {
|
|
23
|
+
message,
|
|
24
|
+
stack
|
|
25
|
+
} = error;
|
|
26
|
+
const errorMessage = `Failed to execute action ${details}. ${message} ${stack ? `\n ${stack}` : ""}`;
|
|
27
|
+
logger.warn(errorMessage);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const logActionCompleted = action => {
|
|
31
|
+
if (logger.enabled) {
|
|
32
|
+
const details = JSON.stringify(action);
|
|
33
|
+
logger.info(`Action ${details} executed.`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const getExecuteAction = (schema, type) => {
|
|
37
|
+
if (!modules[schema] || !modules[schema][type]) {
|
|
38
|
+
return () => Promise.reject(new Error(`Action "${type}" not found for schema "${schema}"`));
|
|
39
|
+
}
|
|
40
|
+
return modules[schema][type];
|
|
41
|
+
};
|
|
42
|
+
const applyPreprocessors = action => {
|
|
43
|
+
const {
|
|
44
|
+
schema
|
|
45
|
+
} = action;
|
|
46
|
+
const preprocessorsList = preprocessors[schema];
|
|
47
|
+
if (!schema || !(preprocessorsList instanceof Array) || preprocessorsList.length === 0) {
|
|
48
|
+
return action;
|
|
49
|
+
}
|
|
50
|
+
return preprocessorsList.reduce((processed, fn) => assign(processed, fn(processed)), action);
|
|
51
|
+
};
|
|
52
|
+
const executeAction = action => {
|
|
53
|
+
const processedAction = applyPreprocessors(action);
|
|
54
|
+
const {
|
|
55
|
+
type,
|
|
56
|
+
schema
|
|
57
|
+
} = processedAction;
|
|
58
|
+
const execute = getExecuteAction(schema, type);
|
|
59
|
+
return execute(processedAction).then(result => {
|
|
60
|
+
logActionCompleted(processedAction);
|
|
61
|
+
return result;
|
|
62
|
+
}).catch(error => {
|
|
63
|
+
logActionError(processedAction, error);
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
executeAction
|
|
69
|
+
};
|
|
70
|
+
});
|
|
@@ -11,9 +11,9 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { isNonEmptyArray, isObject, defer } from "../../utils";
|
|
14
|
-
import { DOM_ACTION, HTML_CONTENT_ITEM } from "
|
|
14
|
+
import { DOM_ACTION, HTML_CONTENT_ITEM, MESSAGE_IN_APP } from "../../constants/schema";
|
|
15
15
|
import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
|
|
16
|
-
const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];
|
|
16
|
+
const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM, MESSAGE_IN_APP];
|
|
17
17
|
export default (({
|
|
18
18
|
processPropositions,
|
|
19
19
|
createProposition,
|
|
@@ -9,8 +9,8 @@ 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 { DISPLAY } from "
|
|
13
|
-
import {
|
|
12
|
+
import { DISPLAY } from "../../constants/eventType";
|
|
13
|
+
import { getPropositionEventType } from "../../constants/propositionEventType";
|
|
14
14
|
import { isNonEmptyArray } from "../../utils";
|
|
15
15
|
export default (({
|
|
16
16
|
eventManager,
|
|
@@ -19,12 +19,15 @@ export default (({
|
|
|
19
19
|
// Called when a decision is auto-rendered for the __view__ scope or a SPA view(display and empty display notification)
|
|
20
20
|
return ({
|
|
21
21
|
decisionsMeta = [],
|
|
22
|
+
propositionAction,
|
|
22
23
|
documentMayUnload = false,
|
|
24
|
+
eventType = DISPLAY,
|
|
25
|
+
propositionEventTypes = [getPropositionEventType(eventType)],
|
|
23
26
|
viewName
|
|
24
27
|
}) => {
|
|
25
28
|
const event = eventManager.createEvent();
|
|
26
29
|
const data = {
|
|
27
|
-
eventType
|
|
30
|
+
eventType
|
|
28
31
|
};
|
|
29
32
|
if (viewName) {
|
|
30
33
|
data.web = {
|
|
@@ -34,7 +37,7 @@ export default (({
|
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
if (isNonEmptyArray(decisionsMeta)) {
|
|
37
|
-
mergeDecisionsMeta(event, decisionsMeta,
|
|
40
|
+
mergeDecisionsMeta(event, decisionsMeta, propositionEventTypes, propositionAction);
|
|
38
41
|
}
|
|
39
42
|
event.mergeXdm(data);
|
|
40
43
|
if (documentMayUnload) {
|
|
@@ -13,8 +13,8 @@ governing permissions and limitations under the License.
|
|
|
13
13
|
import { noop, flatMap, isNonEmptyArray } from "../../utils";
|
|
14
14
|
import createPersonalizationDetails from "./createPersonalizationDetails";
|
|
15
15
|
import { AUTHORING_ENABLED } from "./constants/loggerMessage";
|
|
16
|
+
import { PropositionEventType } from "../../constants/propositionEventType";
|
|
16
17
|
import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
|
|
17
|
-
import { PropositionEventType } from "./constants/propositionEventType";
|
|
18
18
|
export default (({
|
|
19
19
|
getPageLocation,
|
|
20
20
|
logger,
|
|
@@ -28,10 +28,12 @@ export default (({
|
|
|
28
28
|
applyPropositions,
|
|
29
29
|
setTargetMigration,
|
|
30
30
|
mergeDecisionsMeta,
|
|
31
|
-
renderedPropositions
|
|
31
|
+
renderedPropositions,
|
|
32
|
+
onDecisionHandler
|
|
32
33
|
}) => {
|
|
33
34
|
return {
|
|
34
35
|
lifecycle: {
|
|
36
|
+
onDecision: onDecisionHandler,
|
|
35
37
|
onBeforeRequest({
|
|
36
38
|
request
|
|
37
39
|
}) {
|
|
@@ -100,7 +102,7 @@ export default (({
|
|
|
100
102
|
// from two places: the pending display notifications and the view change handler.
|
|
101
103
|
const decisionsMeta = flatMap(decisionsMetas, dms => dms);
|
|
102
104
|
if (isNonEmptyArray(decisionsMeta)) {
|
|
103
|
-
mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
|
|
105
|
+
mergeDecisionsMeta(event, decisionsMeta, [PropositionEventType.DISPLAY]);
|
|
104
106
|
}
|
|
105
107
|
});
|
|
106
108
|
},
|
|
@@ -9,17 +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 {
|
|
12
|
+
import { groupBy } from "../../utils";
|
|
13
13
|
const DECISIONS_HANDLE = "personalization:decisions";
|
|
14
14
|
export default (({
|
|
15
15
|
prehidingStyle,
|
|
16
16
|
showContainers,
|
|
17
17
|
hideContainers,
|
|
18
18
|
mergeQuery,
|
|
19
|
-
collect,
|
|
20
19
|
processPropositions,
|
|
21
20
|
createProposition,
|
|
22
|
-
|
|
21
|
+
notificationHandler
|
|
23
22
|
}) => {
|
|
24
23
|
return ({
|
|
25
24
|
cacheUpdate,
|
|
@@ -33,21 +32,7 @@ export default (({
|
|
|
33
32
|
showContainers();
|
|
34
33
|
}
|
|
35
34
|
mergeQuery(event, personalizationDetails.createQueryDetails());
|
|
36
|
-
|
|
37
|
-
if (personalizationDetails.isSendDisplayEvent()) {
|
|
38
|
-
handleNotifications = decisionsMeta => {
|
|
39
|
-
if (decisionsMeta.length > 0) {
|
|
40
|
-
collect({
|
|
41
|
-
decisionsMeta,
|
|
42
|
-
viewName: personalizationDetails.getViewName()
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
} else {
|
|
47
|
-
const renderedPropositionsDeferred = defer();
|
|
48
|
-
renderedPropositions.concat(renderedPropositionsDeferred.promise);
|
|
49
|
-
handleNotifications = renderedPropositionsDeferred.resolve;
|
|
50
|
-
}
|
|
35
|
+
const handleNotifications = notificationHandler(personalizationDetails.isSendDisplayEvent(), personalizationDetails.getViewName());
|
|
51
36
|
onResponse(({
|
|
52
37
|
response
|
|
53
38
|
}) => {
|
|
@@ -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 { defer } from "../../utils";
|
|
13
|
+
export default ((collect, renderedPropositions) => {
|
|
14
|
+
return (sendDisplayEvent, viewName) => {
|
|
15
|
+
if (!sendDisplayEvent) {
|
|
16
|
+
const renderedPropositionsDeferred = defer();
|
|
17
|
+
renderedPropositions.concat(renderedPropositionsDeferred.promise);
|
|
18
|
+
return renderedPropositionsDeferred.resolve;
|
|
19
|
+
}
|
|
20
|
+
return decisionsMeta => {
|
|
21
|
+
if (decisionsMeta.length > 0) {
|
|
22
|
+
collect({
|
|
23
|
+
decisionsMeta,
|
|
24
|
+
viewName
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
});
|