Plugins

Plugins are places in Socotra where system behavior can be customized with user-created scripts written in Javascript.

Note

The first Socotra plugin is a replacement for our automated underwriting liquid scripts. Other plugins will follow on a regular basis with new functionality.

Note

See the Scripts API topic for information about deploying scripts and retrieving logs from scripts.

Script Format

Each plugin is implemented in a javascript file with a predefined name. A data object with a predefined format is passed to a function, again with a predefined name, and the response is sent back using the javascript return statement. For example, a simple implementation for the underwriting decision plugin can look like this:

// in underwriter.js
function getUnderwritingResult(data)
{
  console.log("Hello underwriting world!");

  return {
    "decision": "accept",
    "notes": [ "Everyone wins!" ]
  };
}
exports.getUnderwritingResult = getUnderwritingResult;

In this example, the file is underwriter.js, the function name is getUnderwritingResult, and the return object has a decision string property and a notes string array property. The exports statement at the end is required.

Script Deployment

Scripts may be uploaded in either of two ways:

  • Embedded in a configuration deployment. There will be top-level folder in the configuration zip file called /scripts which will contain branch folders and javascript files below.

  • Uploaded directly to the scripts deployment endpoint with a zip file in multipart form format. With this endpoint, include the structure below what would have gone in the configuration /scripts folder.

To use the simple underwriting decision plugin example above, the scripts zip file would have the following file:

/{branchName}/underwriter.js

Product Script Branch Selection

In the /products/{productName}/policy.json configuration file, the property scriptsBranch is used to tell Socotra to use the scripts in the given branch. For example, if scripts have been deployed with a file called /master/underwriter.js, then adding the property "scriptsBranch": "master" to policy.json will enable the underwriting decision plugin for that property.

Logging

In a javascript plugin script, the javascript method console.log can be used to log messages which can be retrieved later.

To retrieve logs, first call the scripts log query endpoint (with a QueryRequest object to filter based on desired values) to retrieve a list of top-level LogEvent objects (there will be one per plugin call).

Then, using the specific LogEvent of interest, retrieve individual log messages by calling the scripts logging endpoint again by setting the requestId property of the QueryRequest object.