After testing I can confirm that you can use the following in your extension.json file
"transforms": [
{
"type": "function",
"propertyPath": "source",
"parameters": ["event"]
}
]You need to place it at the same level as schema
"configuration": {
"viewPath": "configuration/configuration.html",
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": { }
},
"transforms": [
{
"type": "function",
"propertyPath": "source",
"parameters": ["event"]
}
]
},In my extension the on edit button I call this function:
function editConfig() {
window.extensionBridge.openCodeEditor({
code: window.customCode.source,
language: 'javascript'
}).then(function (code) {
window.customCode.source = code;
});
}This is configuration in extension bridge
window.extensionBridge.register({
init: function (info) {
if (info.settings) {
if (info.settings.source) {
window.customCode.source = info.settings.source;
}
}
},
getSettings: function () {
return {
source: window.customCode.source
}
},
validate: function () {
return true;
}
});When I enter this code and I save in my configuration view:
var x = 123;
return x;
When the build is successfully completed I can see the following in the library:
"settings": {
"source": function(event) {
var x = 123;
return x;
}
}This is documented here: https://experienceleague.adobe.com/docs/experience-platform/tags/extension-dev/manifest.html?lang=en
Function transform
The function transform allows code written by Platform users to be executed by a library module within the emitted tag runtime library.
Let’s assume we would like to provide a “custom script” action type. The “custom script” action view might provide a textarea wherein the user can enter some code. Let’s assume a user entered the following code into the textarea:
console.log('Welcome, ' + username +'. This is ZomboCom.');
When the user saves the rule, the settings object saved by the view may look like this:
{
foo: {
bar: "console.log('Welcome, ' + username +'. This is ZomboCom.');"
}
}
When a rule using our action fires within the tag runtime library, we would like to execute the user’s code and pass it a username.
At the point that the settings object is saved from the action type’s view, the user’s code is simply a string. This is good because it can be properly serialized to and from JSON; however, it’s also bad because it would typically be emitted in the tag runtime library as a string as well instead of an executable function. Although you could attempt to execute the code within your action type’s library module using eval or a Function constructor, it is highly discouraged due to content security policies potentially blocking execution.
As a workaround for this situation, using the function transform tells Platform to wrap the user’s code in a executable function when it is emitted in the tag runtime library. To solve our example problem, we would define the transform on the type definition in extension.json as follows:
{
"transforms": [
{
"type": "function",
"propertyPath": "foo.bar",
"parameters": ["username"]
}
]
}
- type defines the type of transform that should be applied to the settings object.
- propertyPath is a period-delimited string that tells Platform where to find the property that needs to be modified within the settings object.
- parameters is an array of parameter names that should be included in the wrapping function’s signature.
When the settings object is emitted in the tag runtime library, it will be transformed to the following:
{
foo: {
bar: function(username) {
console.log('Welcome, ' + username +'. This is ZomboCom.');
}
}
}Your library module can then call the function containing the user’s code and pass in the username argument.