Create a transformer
Introduction
Transformers are re-usable functions that manipulate data in UserClouds. Transformers control how a token is generated and what it looks like. Transformers allow you to retain select structure and information from the raw data for different use cases, like sorting alphabetically, common domain analysis or simply flowing through your systems without triggering validation errors.
Transformers can be managed in the User Store page of the UserClouds Console, or via the UserClouds API.
How Transformers Work
When data is passed to a transformer, three steps happen in sequence:
- Validation: First, we make sure the data matches the expected type for the transformer. For example, if the transformer is supposed to work with dates, we check to see if the data has type date.
- Normalization: After confirming the data type, we convert the data into a string. This makes it easier to work with because strings are universal and aren't specific to any one programming language.
- Transformation: The transformer then receives the string and carries out its task. Since it gets the data as a string, this function can be written in JavaScript or (coming soon!) any other programming language.
Expected String Formats
For the transformers that work with specific data types, you should expect to receive and work with the following string formats:
- Date Types: For Birthdate and Date types, expect a
YYYY-MM-DD
format. - Time Types: Timestamps come in a
YYYY-MM-DDTHH:mm:ss.sssZ
format. - UUID Types: UUIDs follow the standard format of
00000000-0000-0000-0000-000000000000
.
Remember to convert these strings into the JavaScript objects or primitives that you need before working with them in your transformer.
Creating a transformer in UserClouds Console
To create a transformer in UserClouds, go to the Policies page, accessible from the sidebar in Console, and click Create Transformer.
1 Name and Describe the Transformer
Specify a name and description for the transformer, to help your team find and use it later.
2 Define how the transformer will change the data
Define how the transformer will work by stating:
- An input data type for the transformer (string, timestamp etc)
- An output data type for the transformer (string, timestamp etc)
- A transform type - for more info on these, see
- A transform function, which will receive raw data as a string and return the transformed data
- (Optional) A set of parameters for that function, which allows you to rapidly create transformers with parallel logic
3 Test and save your transformer
Finally, test your transformer by adding raw data to the "Data" field and clicking "Run Test". Once you are happy with the test results, click "Save Transformer" to finish.
Creating a transformer via the API
To learn how to create a transformer via the UserClouds API, see our API Reference.
Updated 12 months ago