@adobe/alloy 2.19.0-beta.10 → 2.19.0-beta.12
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/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 +34 -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 +123 -0
- package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +43 -0
- package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +87 -0
- package/libEs5/components/DecisioningEngine/index.js +114 -0
- package/libEs5/components/DecisioningEngine/utils.js +83 -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/createOnClickHandler.js +5 -3
- package/libEs5/components/Personalization/createOnDecisionHandler.js +45 -0
- package/libEs5/components/Personalization/createPersonalizationDetails.js +2 -2
- package/libEs5/components/Personalization/createPreprocessors.js +21 -0
- package/libEs5/components/Personalization/createViewCacheManager.js +1 -1
- package/libEs5/components/Personalization/event.js +25 -22
- package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +76 -0
- 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 +17 -5
- package/libEs5/constants/contentType.js +18 -0
- 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/config/createCoreConfigs.js +1 -0
- package/libEs5/core/createEvent.js +26 -1
- package/libEs5/core/createEventManager.js +3 -0
- package/libEs5/core/createLifecycle.js +4 -1
- 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 +7 -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/{libEs5/components/Personalization/constants/propositionEventType.js → libEs6/components/DecisioningEngine/consequenceAdapters/schemaTypeConsequenceAdapter.js} +13 -9
- package/libEs6/components/DecisioningEngine/constants.js +25 -0
- package/libEs6/components/DecisioningEngine/createApplyResponse.js +29 -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 +113 -0
- package/libEs6/components/DecisioningEngine/createOnResponseHandler.js +42 -0
- package/libEs6/components/DecisioningEngine/createSubscribeRulesetItems.js +79 -0
- package/libEs6/components/DecisioningEngine/index.js +119 -0
- package/libEs6/components/DecisioningEngine/utils.js +74 -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/createOnClickHandler.js +5 -3
- package/libEs6/components/Personalization/createOnDecisionHandler.js +43 -0
- package/libEs6/components/Personalization/createPersonalizationDetails.js +2 -2
- package/libEs6/components/Personalization/createPreprocessors.js +19 -0
- package/libEs6/components/Personalization/createViewCacheManager.js +1 -1
- package/libEs6/components/Personalization/event.js +14 -9
- package/libEs6/components/Personalization/handlers/createProcessInAppMessage.js +77 -0
- 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 +19 -6
- package/libEs6/{components/Personalization/constants/eventType.js → constants/contentType.js} +3 -4
- package/libEs6/constants/eventType.js +17 -0
- package/libEs6/{components/Personalization/constants/propositionEventType.js → constants/handle.js} +2 -6
- 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/config/createCoreConfigs.js +1 -0
- package/libEs6/core/createEvent.js +26 -1
- package/libEs6/core/createEventManager.js +2 -0
- package/libEs6/core/createLifecycle.js +4 -1
- 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 +1 -0
- package/libEs6/utils/parseUrl.js +62 -0
- package/package.json +6 -2
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
const createDecisioningEngine = ({
|
|
23
|
+
config,
|
|
24
|
+
createNamespacedStorage,
|
|
25
|
+
consent
|
|
26
|
+
}) => {
|
|
27
|
+
const {
|
|
28
|
+
orgId,
|
|
29
|
+
personalizationStorageEnabled
|
|
30
|
+
} = config;
|
|
31
|
+
const storage = createNamespacedStorage(`${sanitizeOrgIdForCookieName(orgId)}.decisioning.`);
|
|
32
|
+
if (!personalizationStorageEnabled) {
|
|
33
|
+
clearLocalStorage(storage.persistent);
|
|
34
|
+
}
|
|
35
|
+
const eventRegistry = createEventRegistry({
|
|
36
|
+
storage: createInMemoryStorage()
|
|
37
|
+
});
|
|
38
|
+
const decisionProvider = createDecisionProvider({
|
|
39
|
+
eventRegistry
|
|
40
|
+
});
|
|
41
|
+
const contextProvider = createContextProvider({
|
|
42
|
+
eventRegistry,
|
|
43
|
+
window
|
|
44
|
+
});
|
|
45
|
+
const evaluateRulesetsCommand = createEvaluateRulesetsCommand({
|
|
46
|
+
contextProvider,
|
|
47
|
+
decisionProvider
|
|
48
|
+
});
|
|
49
|
+
const subscribeRulesetItems = createSubscribeRulesetItems();
|
|
50
|
+
let applyResponse;
|
|
51
|
+
return {
|
|
52
|
+
lifecycle: {
|
|
53
|
+
onDecision({
|
|
54
|
+
propositions
|
|
55
|
+
}) {
|
|
56
|
+
subscribeRulesetItems.refresh(propositions);
|
|
57
|
+
},
|
|
58
|
+
onComponentsRegistered(tools) {
|
|
59
|
+
applyResponse = createApplyResponse(tools.lifecycle);
|
|
60
|
+
if (personalizationStorageEnabled) {
|
|
61
|
+
consent.awaitConsent().then(() => {
|
|
62
|
+
eventRegistry.setStorage(storage.persistent);
|
|
63
|
+
}).catch(() => {
|
|
64
|
+
if (storage) {
|
|
65
|
+
clearLocalStorage(storage.persistent);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
onBeforeEvent({
|
|
71
|
+
event,
|
|
72
|
+
renderDecisions,
|
|
73
|
+
personalization = {},
|
|
74
|
+
onResponse = noop
|
|
75
|
+
}) {
|
|
76
|
+
const {
|
|
77
|
+
decisionContext = {}
|
|
78
|
+
} = personalization;
|
|
79
|
+
onResponse(createOnResponseHandler({
|
|
80
|
+
renderDecisions,
|
|
81
|
+
decisionProvider,
|
|
82
|
+
applyResponse,
|
|
83
|
+
event,
|
|
84
|
+
decisionContext: contextProvider.getContext({
|
|
85
|
+
[CONTEXT_KEY.TYPE]: CONTEXT_EVENT_TYPE.EDGE,
|
|
86
|
+
[CONTEXT_KEY.SOURCE]: CONTEXT_EVENT_SOURCE.REQUEST,
|
|
87
|
+
...decisionContext
|
|
88
|
+
})
|
|
89
|
+
}));
|
|
90
|
+
eventRegistry.addExperienceEdgeEvent(event);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
commands: {
|
|
94
|
+
evaluateRulesets: {
|
|
95
|
+
run: ({
|
|
96
|
+
renderDecisions,
|
|
97
|
+
personalization = {}
|
|
98
|
+
}) => {
|
|
99
|
+
const {
|
|
100
|
+
decisionContext = {}
|
|
101
|
+
} = personalization;
|
|
102
|
+
return evaluateRulesetsCommand.run({
|
|
103
|
+
renderDecisions,
|
|
104
|
+
decisionContext: {
|
|
105
|
+
[CONTEXT_KEY.TYPE]: CONTEXT_EVENT_TYPE.RULES_ENGINE,
|
|
106
|
+
[CONTEXT_KEY.SOURCE]: CONTEXT_EVENT_SOURCE.REQUEST,
|
|
107
|
+
...decisionContext
|
|
108
|
+
},
|
|
109
|
+
applyResponse
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
optionsValidator: evaluateRulesetsCommand.optionsValidator
|
|
113
|
+
},
|
|
114
|
+
subscribeRulesetItems: subscribeRulesetItems.command
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
createDecisioningEngine.namespace = "DecisioningEngine";
|
|
119
|
+
export default createDecisioningEngine;
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
};
|
|
@@ -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
|
},
|
|
@@ -11,8 +11,8 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { isNonEmptyArray } from "../../utils";
|
|
14
|
-
import { INTERACT } from "
|
|
15
|
-
import { PropositionEventType } from "
|
|
14
|
+
import { INTERACT } from "../../constants/eventType";
|
|
15
|
+
import { PropositionEventType } from "../../constants/propositionEventType";
|
|
16
16
|
export default (({
|
|
17
17
|
mergeDecisionsMeta,
|
|
18
18
|
collectClicks,
|
|
@@ -43,7 +43,9 @@ export default (({
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
event.mergeXdm(xdm);
|
|
46
|
-
mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.INTERACT, eventLabel
|
|
46
|
+
mergeDecisionsMeta(event, decisionsMeta, [PropositionEventType.INTERACT], eventLabel ? {
|
|
47
|
+
label: eventLabel
|
|
48
|
+
} : undefined);
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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 (({
|
|
14
|
+
processPropositions,
|
|
15
|
+
createProposition,
|
|
16
|
+
collect
|
|
17
|
+
}) => {
|
|
18
|
+
return ({
|
|
19
|
+
viewName,
|
|
20
|
+
renderDecisions,
|
|
21
|
+
propositions
|
|
22
|
+
}) => {
|
|
23
|
+
if (!renderDecisions) {
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
}
|
|
26
|
+
const propositionsToExecute = propositions.map(proposition => createProposition(proposition, true));
|
|
27
|
+
const {
|
|
28
|
+
render,
|
|
29
|
+
returnedPropositions
|
|
30
|
+
} = processPropositions(propositionsToExecute);
|
|
31
|
+
render().then(decisionsMeta => {
|
|
32
|
+
if (decisionsMeta.length > 0) {
|
|
33
|
+
collect({
|
|
34
|
+
decisionsMeta,
|
|
35
|
+
viewName
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return Promise.resolve({
|
|
40
|
+
propositions: returnedPropositions
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
});
|
|
@@ -13,7 +13,7 @@ governing permissions and limitations under the License.
|
|
|
13
13
|
import { includes, isNonEmptyString, isNonEmptyArray } from "../../utils";
|
|
14
14
|
import { buildPageSurface, normalizeSurfaces } from "./utils/surfaceUtils";
|
|
15
15
|
import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
|
|
16
|
-
import { DEFAULT_CONTENT_ITEM, DOM_ACTION, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM } from "
|
|
16
|
+
import { DEFAULT_CONTENT_ITEM, DOM_ACTION, HTML_CONTENT_ITEM, MESSAGE_IN_APP, JSON_CONTENT_ITEM, REDIRECT_ITEM, RULESET_ITEM, MESSAGE_FEED_ITEM } from "../../constants/schema";
|
|
17
17
|
const addPageWideScope = scopes => {
|
|
18
18
|
if (!includes(scopes, PAGE_WIDE_SCOPE)) {
|
|
19
19
|
scopes.push(PAGE_WIDE_SCOPE);
|
|
@@ -68,7 +68,7 @@ export default (({
|
|
|
68
68
|
addPageWideScope(scopes);
|
|
69
69
|
addPageSurface(eventSurfaces, getPageLocation);
|
|
70
70
|
}
|
|
71
|
-
const schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM];
|
|
71
|
+
const schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM, RULESET_ITEM, MESSAGE_IN_APP, MESSAGE_FEED_ITEM];
|
|
72
72
|
if (includes(scopes, PAGE_WIDE_SCOPE)) {
|
|
73
73
|
schemas.push(DOM_ACTION);
|
|
74
74
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { DOM_ACTION } from "../../constants/schema";
|
|
13
|
+
import remapHeadOffers from "./dom-actions/remapHeadOffers";
|
|
14
|
+
import remapCustomCodeOffers from "./dom-actions/remapCustomCodeOffers";
|
|
15
|
+
export default (() => {
|
|
16
|
+
return {
|
|
17
|
+
[DOM_ACTION]: [remapHeadOffers, remapCustomCodeOffers]
|
|
18
|
+
};
|
|
19
|
+
});
|
|
@@ -12,7 +12,7 @@ governing permissions and limitations under the License.
|
|
|
12
12
|
|
|
13
13
|
import { groupBy } from "../../utils";
|
|
14
14
|
import defer from "../../utils/defer";
|
|
15
|
-
import { DEFAULT_CONTENT_ITEM } from "
|
|
15
|
+
import { DEFAULT_CONTENT_ITEM } from "../../constants/schema";
|
|
16
16
|
import { VIEW_SCOPE_TYPE } from "./constants/scopeType";
|
|
17
17
|
export default (({
|
|
18
18
|
createProposition
|
|
@@ -10,24 +10,29 @@ 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
|
|
|
13
|
-
|
|
13
|
+
import { EVENT_TYPE_TRUE } from "../../constants/eventType";
|
|
14
14
|
|
|
15
15
|
/* eslint-disable no-underscore-dangle */
|
|
16
|
-
export const mergeDecisionsMeta = (event, decisionsMeta,
|
|
16
|
+
export const mergeDecisionsMeta = (event, decisionsMeta, propositionEventTypes, propositionAction) => {
|
|
17
|
+
// Do not send a display notification with no decisions. Even empty view changes
|
|
18
|
+
// should include a proposition.
|
|
19
|
+
if (decisionsMeta.length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const propositionEventType = {};
|
|
23
|
+
propositionEventTypes.forEach(type => {
|
|
24
|
+
propositionEventType[type] = EVENT_TYPE_TRUE;
|
|
25
|
+
});
|
|
17
26
|
const xdm = {
|
|
18
27
|
_experience: {
|
|
19
28
|
decisioning: {
|
|
20
29
|
propositions: decisionsMeta,
|
|
21
|
-
propositionEventType
|
|
22
|
-
[eventType]: EVENT_TYPE_TRUE
|
|
23
|
-
}
|
|
30
|
+
propositionEventType
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
33
|
};
|
|
27
|
-
if (
|
|
28
|
-
xdm._experience.decisioning.propositionAction =
|
|
29
|
-
label: eventLabel
|
|
30
|
-
};
|
|
34
|
+
if (propositionAction) {
|
|
35
|
+
xdm._experience.decisioning.propositionAction = propositionAction;
|
|
31
36
|
}
|
|
32
37
|
event.mergeXdm(xdm);
|
|
33
38
|
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { APPLICATION_JSON } from "../../../constants/contentType";
|
|
13
|
+
const DEFAULT_CONTENT = "defaultContent";
|
|
14
|
+
const expectedProps = ["content", "contentType"];
|
|
15
|
+
const expectedContentProps = ["mobileParameters", "webParameters", "html"];
|
|
16
|
+
const isValidInAppMessage = (data, logger) => {
|
|
17
|
+
for (let i = 0; i < expectedProps.length; i += 1) {
|
|
18
|
+
const prop = expectedProps[i];
|
|
19
|
+
if (!Object.prototype.hasOwnProperty.call(data, prop)) {
|
|
20
|
+
logger.warn(`Invalid in-app message data: missing property '${prop}'.`, data);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const {
|
|
25
|
+
content,
|
|
26
|
+
contentType
|
|
27
|
+
} = data;
|
|
28
|
+
if (contentType === APPLICATION_JSON) {
|
|
29
|
+
for (let i = 0; i < expectedContentProps.length; i += 1) {
|
|
30
|
+
const prop = expectedContentProps[i];
|
|
31
|
+
if (!Object.prototype.hasOwnProperty.call(content, prop)) {
|
|
32
|
+
logger.warn(`Invalid in-app message data.content: missing property '${prop}'.`, data);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
export default (({
|
|
40
|
+
modules,
|
|
41
|
+
logger
|
|
42
|
+
}) => {
|
|
43
|
+
return item => {
|
|
44
|
+
const data = item.getData();
|
|
45
|
+
const meta = {
|
|
46
|
+
...item.getProposition().getNotification()
|
|
47
|
+
};
|
|
48
|
+
if (!data) {
|
|
49
|
+
logger.warn("Invalid in-app message data: undefined.", data);
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
const {
|
|
53
|
+
type = DEFAULT_CONTENT
|
|
54
|
+
} = data;
|
|
55
|
+
if (!modules[type]) {
|
|
56
|
+
logger.warn("Invalid in-app message data: unknown type.", data);
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
if (!isValidInAppMessage(data, logger)) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
if (!meta) {
|
|
63
|
+
logger.warn("Invalid in-app message meta: undefined.", meta);
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
render: () => {
|
|
68
|
+
return modules[type]({
|
|
69
|
+
...data,
|
|
70
|
+
meta
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
setRenderAttempted: true,
|
|
74
|
+
includeInNotification: true
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
});
|