Skip to content

Commit

Permalink
Merge pull request #351 from adobe/inBrowserMessages
Browse files Browse the repository at this point in the history
Add evaluateRulesets action, subscribeRulesetItems event for "in browser messages" beta
  • Loading branch information
jonsnyder authored Oct 27, 2023
2 parents 981e496 + 258f0ef commit 2224429
Show file tree
Hide file tree
Showing 15 changed files with 835 additions and 33 deletions.
96 changes: 96 additions & 0 deletions scripts/helpers/createExtensionManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,20 @@ const createExtensionManifest = ({ version }) => {
},
includeRenderedPropositions: {
type: "boolean"
},
decisionContext: {
anyOf: [
{
type: "string",
pattern: "^%[^%]+%$"
},
{
type: "object",
additionalProperties: {
type: "string"
}
}
]
}
},
additionalProperties: false
Expand Down Expand Up @@ -760,6 +774,42 @@ const createExtensionManifest = ({ version }) => {
],
libPath: "dist/lib/actions/updateVariable/index.js",
viewPath: "actions/updateVariable.html"
},
{
displayName: "Evaluate rulesets",
name: "evaluate-rulesets",
schema: {
$schema: "http://json-schema.org/draft-04/schema#",
type: "object",
instanceName: {
type: "string",
minLength: 1
},
renderDecisions: {
type: "boolean"
},
personalization: {
type: "object",
properties: {
decisionContext: {
anyOf: [
{
type: "string",
pattern: "^%[^%]+%$"
},
{
type: "object",
additionalProperties: {
type: "string"
}
}
]
}
}
}
},
libPath: "dist/lib/actions/evaluateRulesets/index.js",
viewPath: "actions/evaluateRulesets.html"
}
],
events: [
Expand All @@ -774,6 +824,52 @@ const createExtensionManifest = ({ version }) => {
displayName: "Send event complete",
libPath: "dist/lib/events/sendEventComplete/index.js",
schema: {}
},
{
name: "subscribe-ruleset-items",
displayName: "Subscribe ruleset items",
libPath: "dist/lib/events/subscribeRulesetItems/index.js",
viewPath: "events/subscribeRulesetItems.html",
schema: {
$schema: "http://json-schema.org/draft-04/schema#",
type: "object",
instanceName: {
type: "string",
minLength: 1
},
surfaces: {
anyOf: [
{
type: "array",
minItems: 1,
items: {
type: "string",
minLength: 1
}
},
{
type: "string",
pattern: "^%[^%]+%$"
}
]
},
schemas: {
anyOf: [
{
type: "array",
minItems: 1,
items: {
type: "string",
minLength: 1
}
},
{
type: "string",
pattern: "^%[^%]+%$"
}
]
}
}
}
],
dataElements: [
Expand Down
24 changes: 24 additions & 0 deletions src/lib/actions/evaluateRulesets/createEvaluateRulesets.js
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);
};
18 changes: 18 additions & 0 deletions src/lib/actions/evaluateRulesets/index.js
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
});
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
});
};
16 changes: 16 additions & 0 deletions src/lib/events/subscribeRulesetItems/index.js
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 });
13 changes: 13 additions & 0 deletions src/view/actions/evaluateRulesets.html
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>
75 changes: 75 additions & 0 deletions src/view/actions/evaluateRulesets.jsx
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);
36 changes: 30 additions & 6 deletions src/view/actions/sendEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import form from "../forms/form";
import radioGroup from "../forms/radioGroup";
import section from "../forms/section";
import dataElement from "../forms/dataElement";
import stringArray from "../forms/stringArray";
import fieldArray from "../forms/fieldArray";
import disabledTextField from "../forms/disabledTextField";
import conditional from "../forms/conditional";
import disabledCheckbox from "../forms/disabledCheckbox";
import configOverrides from "../forms/configOverrides";
import simpleMap from "../forms/simpleMap";

import eventTypes from "./constants/eventTypes";

Expand Down Expand Up @@ -79,13 +80,15 @@ const wrapGetSettings = getSettings => ({ values }) => {
surfaces,
sendDisplayEvent,
includeRenderedPropositions,
decisionContext,
...settings
} = getSettings({ values });
if (
decisionScopes ||
surfaces ||
sendDisplayEvent === false ||
includeRenderedPropositions
includeRenderedPropositions ||
decisionContext
) {
settings.personalization = {};
}
Expand All @@ -101,6 +104,9 @@ const wrapGetSettings = getSettings => ({ values }) => {
if (includeRenderedPropositions) {
settings.personalization.includeRenderedPropositions = includeRenderedPropositions;
}
if (decisionContext) {
settings.personalization.decisionContext = decisionContext;
}
return settings;
};

Expand Down Expand Up @@ -171,7 +177,7 @@ const mergeIdField = dataElement({
"Provide an identifier used to merge multiple events. This will populate the `eventMergeId` XDM field. This field has been deprecated because it is not supported by Adobe Experience Platform."
});

const decisionScopesField = stringArray({
const decisionScopesField = fieldArray({
name: "decisionScopes",
label: "Scopes",
singularLabel: "Scope",
Expand All @@ -180,7 +186,7 @@ const decisionScopesField = stringArray({
"This data element should resolve to an array of scopes."
});

const surfacesField = stringArray({
const surfacesField = fieldArray({
name: "surfaces",
label: "Surfaces",
singularLabel: "Surface",
Expand Down Expand Up @@ -233,6 +239,22 @@ const sendDisplayEventUnchecked = disabledCheckbox({
beta: true
});

const decisionContext = 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.",
beta: true
});

const configOverrideFields = configOverrides();
const datasetIdField = textField({
name: "datasetId",
Expand Down Expand Up @@ -274,7 +296,8 @@ const sendEventForm = form(
decisionScopesField,
surfacesField,
renderDecisionsField,
sendDisplayEventField
sendDisplayEventField,
decisionContext
]),
configOverrideFields,
datasetIdField
Expand Down Expand Up @@ -320,7 +343,8 @@ const sendEventForm = form(
decisionScopesField,
surfacesField,
renderDecisionsField,
sendDisplayEventUnchecked
sendDisplayEventUnchecked,
decisionContext
]),
configOverrideFields
]
Expand Down
Loading

0 comments on commit 2224429

Please sign in to comment.