Skip to content

Using Third Party Libraries in Rulesets (client side)

NOTE -- This article is under initial construction and review. Content may change while this notice is present.

Overview

Third party NodeJS libraries can now be utilised from within server side rulesets.

It is necessary to copy the node js files of the library to a specific folder within the Formbird application folder structure. In this way, only fully sanctioned libraries can be used from within a ruleset.

This usage is for scripting within server side rulesets only.

Requirements

  • Formbird app version 2.0.11 or later
  • Ruleset Include "JS Library Loader"

Method

  • Install the ruleset include "JS Library Loader".
  • Include the ruleset include
  • Create an array of strings called jsLibraries containing the url of the libraries to load.
  • Create a rule to load the libraries

Example

{
...
#include "JS Library Loader",

    jsLibraries : [
        'https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js'   ,
        'https://npmcdn.com/@turf/turf/turf.min.js'
    ],
...

    ruleset : {

        ...

        ruleLoadJSLibs : {
            ruleCondition : ...

            ruleAction : function(ntf, callback) {
                ft3.JSLibraryLoader.loadJSLibraries(ntf, function() {
                    callback();
                });
            }

        },
  • Once this is in place, subsequent rules can then use the globally available javascript objects/functions provided by those libraries.

Caveat

It is advisable to check that those global javascript objects meant to be provided are defined before using. The above loader does not fail if the provided url is incorrect or unreachable.

#include "JS Library Loader",

    jsLibraries : [
        'https://npmcdn.com/@turf/turf/turf.min.js'     // Provides global object "turf"
    ],

    ...

    ruleXXX : {
        ...

        ruleAction : ...
            if (typeof turf === 'undefined') {
                ...
            }
    }