Transform Extension Development
Transforms enable arbitrary transformation (such as Base64 or URL encoding, compression, encryption) of Fields or Field groups within a Message Template.
Frontend Implementation
The frontend component of a transform consists of two files: properties.json
and skeleton.json
.
skeleton.json
The skeleton.json
file describes the transform in a format that is expected by the transform’s backend and frontend components. The core structure can be seen below.
{
name: "example",
parameters: {}
}
The below table describes the above properties.
Property | Description |
---|---|
name | The actual name of the transform. The SDK generates it based on the name provided on the command line when generating the extension. This is the name that is being used by GURDARA to refer to the transform when running tests. |
parameters | Key value pairs representing the parameters of the transform. |
An example skeleton operating with two parameters each having an empty string as default value can be seen below.
{
name: "example",
“parameters”: {
“firstParameter”: “”,
“secondParameter”: “”
}
}
properties.json
The properties.json
file is a user interface specific extension of the transform skeleton. It is mainly responsible for controlling the rendering and processing of transform parameters.
An example is shown below.
{
"name": Example Transform",
"description": "Description of example transform.",
"properties": {
"firstParameter": {
"title": "Test String",
"description": "This is to accept a property of string type.",
"type": "string",
"format": "^.*$"
}
}
}
The name
property should be set to the user-friendly name of the transform. The description should be a short, but descriptive sentence on what the purpose of the transform is.
The properties
object works similarly to as of the field’s properties. Each parameter within the transform’s skeleton must be described with an entry under the properties. Each parameter can have attributes.
The below table summarizes the mandatory attributes.
Attribute | Description |
---|---|
title | The human-friendly name of the transform. |
description | The brief description of the transform. |
type | The type of the parameter value. The value of this field determines what kind of form control element is going to be rendered by the user interface to accept the value of the parameter. Valid values are: string , integer , boolean , select . |
The additional attributes supported are listed in the table below.
Attribute | Description |
---|---|
format | Validates the attribute’s value against the provided regular expression. |
values | In case the parameter’s type is set to select , the expected value for the value attribute is a list of objects representing the name and value of each of the selectable options. An example of such list is: [{text: "Option 1", value: "Value 1"}, {text: "Option 2", value: "Value 2"}] |
Backend Implementation
Transforms are very simple. All transform sub-class TransformInterface
.
Transforms should only define a static method called transform
, which accepts a value
and a params
parameter. This method is the entry point of the Transform and will be called by the Engine. The value of the field the transform to be applied to will be passed in via the value
argument as Python bytes
. Any parameters configured for the transform is accessible via the params
argument (Python dict
).
The transform method is expected to return the processed value as Python bytes
.