Corticon.js enables you to deploy rules on any JavaScript platform:
  • Rules deployed as serverless functions on AWS Lambda, or Microsoft Azure Functions
  • Rules integrated into a cloud work flow such as AWS Step Functions or Microsoft Flow
  • Rules run on your own back end as part of your Node.js platform
  • Rules bundled in a mobile app created with Xamarin, React, Vue.js, or other toolkits
  • Rules executed in a browser as part of a web application

After you have created and tested your rules in the Corticon.js Studio Ruletests, you are ready to package them for deployment. When you package your rules, Corticon generates a self-contained JavaScript bundle:

  • Self-contained means that it has no dependencies on other Corticon components at runtime.
  • JavaScript means that it will be compatible with any JavaScript platform.
  • Bundle means that the complete set of rules are produced in the scope of the Ruleflow to include all its Rulesheets and enclosed Ruleflows in a single JavaScript file.

Each bundle sets the top-level Ruleflow as the entry point to your Decision Service, tailored for the selected platform, with a wrapper that you can customize, and the rules in an obfuscated JavaScript file.

How to package rules for JavaScript deployment

When you package rules for deployment, you select the target platform.

Note: See the Corticon.js Supported Platforms Matrix to review the supported JavaScript and web platforms, and mobile apps. You are not limited to these JavaScript platforms. The API for integrating rules in your JavaScript application allows you to develop your own wrapper or integration code that calls rules.
Corticon will generate a JavaScript bundle with your rules and a wrapper specific to the target platform. The available target platforms are:

Selecting AWS Lambda, Azure Functions, or Google Cloud Functions as the target platform generates the rules and a wrapper ready for deployment as a serverless function. After the rules are deployed, you can use them on your cloud platform—for example, to expose the decision service through a REST endpoint, to respond to a database update, or to integrate into a cloud vendor workflow system such as AWS step functions.

The Node.js target can be used for running decision services in Node server and as well to run them in Mobile applications created with NativeScript and ReactNative.

Selecting Browser generates the decision service and simple example code that demonstrates how to integrate the rules into your application.

Installing the sample project

After installing Corticon.js, setup the sample project as follows:
  1. Launch Corticon.js Studio.
  2. Choose Help > Samples, and then click Open.
  3. Click OK.
The tutorial sample is installed with both its Vocabulary that is the starting point for the Corticon.js Studio Tutorial: Basic Rule Modeling as well as the completed tutorial files.
To create a Corticon JavaScript package:
  1. In Corticon.js Studio, select a project, and then select Project > Package Rules for Deployment. The Package Rules for Deployment dialog box opens:


  2. Select the Ruleflow for your application.
  3. Choose the Target Platform:

  4. Enter a preferred Bundle name so that you produce your package in a distinctly named folder. Each Ruleflow selected generates a separate package.
  5. Enter a preferred to Directory where your package will be placed.
  6. Click Next. The second panel of the dialog opens:


  7. Choose the top-level entities for this package. In our example, only the Cargo entity is referenced so just that entity is selected.
  8. Click Finish to generate the packaged JavaScript as a Decision Service plus everything you need to deploy it. The packaging process generates a single JavaScript bundle that is the entry point for the rules, which contain all the decision logic in its enclosed components for the selected Ruleflow. The generated bundle is compressed and obfuscated. It is valid, executable JavaScript, but it is not readable and cannot be edited.

How to use the JavaScript rules API

All five platform wrappers have a lot in common. Their fundamental difference is the flow of the operations on each platform. Each of the sample.js wrappers is self-documented.

The integration of the bundle with your JavaScript application is a simple API, not much more than a call to execute against the bundle. The following sample code is taken from the node.sample.js file:
  1. Include the generated rule bundle:
    const decisionService = require('./decisionServiceBundle');
  2. Get the JSON payload from your application:
    const payload = readPayload(payloadFileName);
  3. Set the configuration:
    const configuration = { logLevel: 0 };
  4. Execute the rules on the payload:
    const result = await decisionService.execute(payload, configuration);

Customizing the wrapper

The wrappers generated by Corticon.js are sample code with extensive comments. You are free to modify them to meet your needs, or use them as reference for integrating Corticon.js rules with other code.

At their core, the wrappers all do the same things:
  • Get the JSON payload to be processed.
  • Execute rules on the payload.
  • Do something with the result JSON payload.
In your custom code you could:
  • Transform the payload, for example to make it suitable to pass to Corticon.
  • Enrich the payload, for example with data you read from a database
  • Store the result payload, saving the output of rule processing
  • Process the result payload, for example passing it to REST service or another step in a workflow
What you do is up to you.
Each of the wrapper samples provides the same logging and error handling template. You can also define a preferred logger, and set logging to debug mode. See How to use logging and diagnostics for details.

Service contracts

A service contract for a decision service shows the inputs you need to pass to the decision service as part of the input payload, and the output you can expect to receive as part of the result JSON payload.