This library provides a bootstrapping mechanism to free the developer from boring, repetitive tasks like retrieving the values from the action object provided by Kaholo platform, parsing the parameters and settings.
The bootstrapping allows the plugin method to take the form of:
function pluginMethod(parameters)
instead of the typical
function pluginMethod(action, settings)
When using the bootstrapping, the developer can always be sure that the parameters the plugin method receives are parsed and validated based on their config.json
definition. Moreover they are already combined with the settings, so no need to handle those separately. The parameters only consists of the values that are defined in config.json
for the given method. They are also validated and no empty values are present in the parameters
object.
function bootstrap(pluginMethods, autocompleteFunctions)
Allows to use more developer friendly version of plugin methods, removing the necessity of performing such repetitive tasks like manually parsing action arguments and settings.
pluginMethods
(object) – an object containing all of the plugin methods to be bootstrapped within Kaholo Plugin Library. The following parameters will be passed to each and every method provided in this object:
parameters
(object) – the object containing all of the parameters passed to an action combined with plugin settings. All of the values in this object are already parsed based on eithertype
orparserType
provided inconfig.json
.originalParameters
(object) – the original Kaholo plugin method parameters. The object contains two fields:actions
andsettings
.
autocompleteFuncs
(object) – an object containing all of the autocomplete functions to be bootstrapped with Kaholo Plugin Library. The following parameters will be passed to each and every function provided in this object:
query
(string) - a query to be used for result filteringparams
(object) - the object containing all of the parameters passed to an action combined with plugin settings. All of the values in this object are already parsed on eithertype
orparserType
provided inconfig.json
.originalParameters
– the original Kaholo plugin method parameters. The object contains two fields:actions
andsettings
.
ℹ️ Note:
UsingoriginalParameters
in either plugin methods or autocomplete function is generally discouraged in favor of already parsedparams
object.originalParameters
should only be used in case when access to the raw object is absolutely necessary – if you wonder if you need to use it, you probably don't.
This function returns an objects of bootstrapped functions, ready to be exported form your main plugin script (most likely app.js
).
- config.json
{
// ...
"methods": [
"name": "somePluginMethod",
"params": [
// ...
{
"name": "someArray",
"type": "text",
"parserType": "array",
"required": true,
}
// ...
]
]
}
- app.js
const kaholo = require("kaholo-plugin-library");
function somePluginMethod(parameters) {
// ...
}
module.exports = kaholo.bootstrap({ describeInstances }, {});
bootstrap
function and benefit from automatically parsed parameters, then you shouldn't use it!
function readActionArguments(action, settings)
Retrieves and parses the action parameters based on config.json
definitions.
action
(object) – raw action object
settings
(object) – raw settings object
An object containing all of the action parameters with parsed values.
function resolveParser(type)
returns the appropriate parser function based on string type.
type
(string) – type name. Supported values are: object, int, float, number, boolean, vault, options, text, string, autocomplete, array
A parsing function appropriate for given type
function string(value)
Parses single or multiline string
value
(any) – value to parse
String representing parsed value
function autocomplete(value)
Parses autocomplete item, returns it's value as a string
value
(object) – Autocomplete item to parse
String representing a value from autocomplete
function boolean(value)
Parses a boolean value
value
(any) – value to parse
Boolean representation of the provided value
function number(value)
Parses a numeric value. Supports both integer and floating point numbers.
value
(any) – value to parse
Numeric value parsed from provided argument
function object(value)
Parses object from JSON value.
value
(JSON string) – value to parse
Object parsed from JSON string
function array(value)
Parses array from new line separated string
value
(string) – value to parse
Parsed array of strings
bootstrap
function and benefit from automatically parsed parameters, then you shouldn't use those
function mapAutocompleteFuncParamsToObject(params)
This function is used to create an object containing parsed values of the raw parameters or settings passed to autocomplete functions from Kaholo platform.
params
(object) – raw params or settings object received from Kaholo platform
An object with all the parameters with parsed values.