Transform JavaScript Stage
The Transform JavaScript stage allows a message to be transformed using the JavaScript language.
Stage Overview
The Transform JavaScript stage allows a message to be transformed using the JavaScript language.
The format required for defining the JavaScript schema file changed in Integration Hub v5.0.0.
Stage Definition File Location
All Transform JavaScript stages are defined by creating an appropriately formatted JSON definition file in the following location:
Stage JSON Definition File Format
The JSON definition file for a Transform JavaScript stage is as follows:
{
"name": "stage-name",
"displayName": "Brief Stage Title",
"description": "Brief description of the stage.",
"enabled": "$env:STATUS_<INTEGRATION_NAME>",
"source": "source-event",
"concurrency": 10,
"discardEmptyPayloads": false,
"schemaFilename": "schemas/path/to/schema/schema-name.js",
"useBase64PayloadInput": false,
"templateVariables": {
"VARIABLE_1": "$env:VARIABLE_1",
"VARIABLE_2": "$env:VARIABLE_2"
},
"preLogTransformSchemaFileName": "schemas/path/to/schema/schema-name.liquid",
"preLogTransformSchemaType": "liquid|javascript",
"preLogTransformFormat": "json|xml|csv"
}
| Property | Description |
|---|---|
name | The name of the stage. |
displayName | Optional (but highly recommended). A short (3 or 4 word) "display name" for the stage, used as a "title" of the stage in the Integration Hub Portal service's self-documentation capability. |
description | Optional (but highly recommended). A brief (10 to 15 word) description of the stage, used as a brief description of the stage's purpose in the Integration Hub Portal service's self-documentation capability. For a more detailed explanation (when needed), use the stage markdown feature. |
enabled | Optional boolean flag (true or false). Default is true.Generally set via a DevOps variable. Controls if the stage is deployed enabled or not. |
source | The source event that the stage subscribes to. See Pub/Sub Model. Alternatively, sources may be supplied, and an array of one or more source events can be subscribed to. |
concurrency | Optional number of concurrent runs permitted for the stage. Default is 10. |
discardEmptyPayloads | Optional boolean flag (true or false). Default is false. When true, if the transformation results in producing a JSON payload that is an empty string, an empty JSON object (i.e. {}), or an empty JSON array (i.e. []), then the stage will "discard" the payload by not emitting an event to trigger further processing. |
schemaFilename | A filename that defines the JavaScript transformation schema. See below for more details on the file location and format. |
useBase64PayloadInput | Optional boolean flag (true or false). Default is false.Set to true when the preceding stage is supplying a Base64 encoded value, and the JavaScript transformation code is expecting and will handle the payload in that Base64 encoded format.If not set to true, the stage will decode the Base64 value prior to passing it into the JavaScript code for processing. |
templateVariables | An optional object of key/value pairs. Prior to deploying the stage, the JavaScript transformation schema will be updated to replace any instances of <<KEY_NAME>> in the schema with the corresponding value from this object.This allows a JavaScript transformation schema to be more easily used across different stages where only minor differences in the transformation are required. |
Pre-Logging Transformation
This stage supports the optional pre-logging transformation feature using the following fields:
preLogTransformSchemaFileNamepreLogTransformSchemaTypepreLogTransformFormat
See the Pre-Logging Transformation for details.
Transformation Schema File Location
The schemaFilename must be defined using a directory path which is based on the root of the Integration Hub service folder. It is recommended that this always starts with the directory schemas, and that all transform schemas be stored in a logical structure that allows for easy reuse of transform schema definitions as required.
Transformation Schema File Format
Integration Hub uses ClearScript for JavaScript stages.
As a result, JavaScript stage schema files must contain a process function, which is what will be executed. The output of this function is what will be used as the output from the transformation stage.
Typically, the process function will operate on the inbound payload data. For example:
globalThis.process = function (data) {
// Load the payload JSON
var inputJson = JSON.parse(data);
var payloadJson = inputJson.input;
var integrationMetadataJson = inputJson.cloudEvent;
// Prepare an output JSON object
var outputJson = {
"property": payloadJson.desiredElement;
};
// Return the output JSON object
return outputJson;
};
Notes:
- The incoming payload into the JavaScript code schema is in the
inputproperty after having parsed the originaldatavariable. - In addition to the
inputproperty which contains the incoming payload, thecloudEventproperty is also available, and contains metadata relating to the overall integration's execution to date. This includes file metadata from file-based inbound stages, and may be useful when an integration run's original source filename is required later in the integration process.
Unlike with Integration Hub v4.0.0, there is no need to escape double quotes in JavaScript schema files.
JavaScript Libraries
Additional JavaScript libraries are supported, and can be imported in the JavaScript schema files.
For example:
import { Rectangle } from 'modules/Geometry';
import FileTree from '/snippets/klevr-ih/file-tree.mdx';Last updated on