You are reading the documentation for an outdated Corteza release. 2024.9 is the latest stable Corteza release.

Web Application

The last important bit of the automation system is the web application. The web application implements a small subset of Corteza server’s automation system features that allow script listing and their execution. The main purpose of this system is to provide the ability to interact with the user from inside automation scripts.

Since client scripts are executed in the browser, they are considered less secure. These scripts should not work with any sensitive data such as authentication tokens, API credentials, personal data filtering, …​

Main responsibilities

  1. Fetching and registration of automation scripts provided by Corredor server via Corteza server,

  2. registration of automation triggers on the system event bus,

  3. execution of automation scripts based on implicit/explicit events.

Event bus

In order to implement a powerful and flexible automation system, we have decided to base it around an event bus. With the help of an event bus, we are able to trivially handle any combination of automation scripts in a unified, robust manner.

Client side event bus and server side event bus are not the same, so both should receive equal attention when reading.

Client script trigger registration

Firstly we need to register client scripts on the event bus, so they can listen and respond to dispatched events. The flow is as follows:

  1. fetch the bundled automation scripts for the given service,

  2. for each trigger of every automation script:

    1. prepare a generic execution function,

    2. register the trigger with the execution function on the event bus.

Explicit server script trigger registration

Secondly we need to register explicit server scripts (manual server scripts). The flow is as follows:

  1. fetch available automation scripts, excluding non explicit and non server script entries,

  2. for each trigger of every automation script:

    1. prepare an execution function that invokes the Corteza server via API client libraries,

    2. register the trigger with the execution function on the event bus.

Event handling and script execution

Finally we discuss event dispatching, handling and script execution. Events are dispatched over the event bus and executed synchronously.

There is a slight difference between event validation when it comes to implicit and explicit scripts.

If the script name is provided

when the script name is provided, it is assumed, that we are invoking an explicit script. In this case, the event type must be defined as manual ('onManual'),

If the script name is not provided

when the script name is not provided, it is assumed, that we are invoking implicit script(s). In this case, the event type must not be defined as manual ('onManual').

Other than that, the flow is as follows:

  1. validate the event,

  2. filter triggers based on the provided event,

  3. for each available trigger:

    1. prepare context and payload,

    2. execute the automation with the above generated meta,

    3. handle possible errors.

When it comes to automation script execution, there is a small deviation between Corredor server and web application. When the automation script is executed inside the web application, it’s resources are provided by reference and therefore any changes made to the resource is reflected through the rest of the pipeline without the need of explicit return statements. For some resources, such as records, the changes are also reflected on the UI.

UI hooks

A UI hook represents a UI component (usually a button), that is able to invoke an explicit automation script, being a client or server script. UI hooks solely provide component definition (script name, element type, design, labels, …​) and it’s up to the user interface to render the component and dispatch the event when needed.