-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from adobe/inBrowserMessages
Add evaluateRulesets action, subscribeRulesetItems event for "in browser messages" beta
- Loading branch information
Showing
15 changed files
with
835 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/lib/actions/evaluateRulesets/createEvaluateRulesets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
module.exports = ({ instanceManager }) => settings => { | ||
const { instanceName, ...options } = settings; | ||
|
||
const instance = instanceManager.getInstance(instanceName); | ||
if (!instance) { | ||
throw new Error( | ||
`Failed to evaluate rulesets for instance "${instanceName}". No instance was found with this name.` | ||
); | ||
} | ||
|
||
return instance("evaluateRulesets", options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const createEvaluateRulesets = require("./createEvaluateRulesets"); | ||
const instanceManager = require("../../instanceManager/index"); | ||
|
||
module.exports = createEvaluateRulesets({ | ||
instanceManager | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/lib/events/subscribeRulesetItems/createSubscribeRulesetItems.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2021 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
module.exports = ({ instanceManager }) => (settings, trigger) => { | ||
const { instanceName, ...options } = settings; | ||
|
||
const instance = instanceManager.getInstance(instanceName); | ||
if (!instance) { | ||
throw new Error( | ||
`Failed to subscribe ruleset items for instance "${instanceName}". No instance was found with this name.` | ||
); | ||
} | ||
|
||
return instance("subscribeRulesetItems", { | ||
...options, | ||
callback: trigger | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Copyright 2021 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const createSubscribeRulesetItems = require("./createSubscribeRulesetItems"); | ||
const instanceManager = require("../../instanceManager/index"); | ||
|
||
module.exports = createSubscribeRulesetItems({ instanceManager }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Extension View</title> | ||
<link rel="stylesheet" href="https://use.typekit.net/ruf7eed.css" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script src="https://assets.adobedtm.com/activation/reactor/extensionbridge/extensionbridge.min.js"></script> | ||
<script type="module" src="./evaluateRulesets.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import renderForm from "../forms/renderForm"; | ||
import form from "../forms/form"; | ||
import instancePicker from "../forms/instancePicker"; | ||
import checkbox from "../forms/checkbox"; | ||
import simpleMap from "../forms/simpleMap"; | ||
import notice from "../forms/notice"; | ||
|
||
const wrapGetInitialValues = getInitialValues => ({ initInfo }) => { | ||
const { personalization = {}, ...otherSettings } = initInfo.settings || {}; | ||
return getInitialValues({ | ||
initInfo: { | ||
...initInfo, | ||
settings: { ...personalization, ...otherSettings } | ||
} | ||
}); | ||
}; | ||
|
||
const wrapGetSettings = getSettings => ({ values }) => { | ||
const { decisionContext, ...settings } = getSettings({ values }); | ||
if (decisionContext) { | ||
settings.personalization = {}; | ||
settings.personalization.decisionContext = decisionContext; | ||
} | ||
return settings; | ||
}; | ||
|
||
const evaluateRulesetsForm = form( | ||
{ | ||
wrapGetInitialValues, | ||
wrapGetSettings | ||
}, | ||
[ | ||
notice({ | ||
title: "Evaluate rulesets action", | ||
description: | ||
"This action manually triggers ruleset evaluation. Rulesets are returned from Adobe Journey Optimizer in-browser-messages.", | ||
beta: true | ||
}), | ||
instancePicker({ name: "instanceName" }), | ||
checkbox({ | ||
name: "renderDecisions", | ||
label: "Render visual personalization decisions", | ||
description: | ||
"Check this to render visual personalization decisions for the ruleset items that match.", | ||
defaultValue: false | ||
}), | ||
simpleMap({ | ||
name: "decisionContext", | ||
label: "Decision context", | ||
singularLabel: "Context item", | ||
description: | ||
"Provide the keys and values that the rulesets will use to determine which experience to deliver.", | ||
dataElementDescription: | ||
"Provide a data element that resolves to a map of key/value pairs.", | ||
keyLabel: "Key", | ||
keyLabelPlural: "Keys", | ||
keyDescription: "Enter the context key.", | ||
valueLabel: "Value", | ||
valueDescription: "Enter the context value." | ||
}) | ||
] | ||
); | ||
|
||
renderForm(evaluateRulesetsForm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.