# Module: main

Contains all customer facing functions to are used to interface with the rest of the application framework.

Author:
  - Seth Hollingsead
Copyright:
  - Copyright © 2022-… by Seth Hollingsead. All rights reserved
Source:
  - main.js, line 3

### Requires

- module:warden
- module:loggers
- module:prompt
- module:stack
- module:data
- haystacks
- @haystacks/constants
- url
- dotenv
- path

### Methods

#### (inner) accouterFramework(data) → {boolean}

Equip and outfit this instance of the haystacks framework with an existing data structure. This function essentially allows plugins to inject a clone of the D-data structure from another instance of Haystacks into this instance of Haystacks, essentially creating a clone of the original instance of Haystacks. The purpose being to be able to call back to Haystacks and have it perform loading and parsing operations on files.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | object | A JSON data structure, that is a clone of the D-data structure from another instance of Haystacks.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 132

##### Returns:

A True or False value to indicate if the operation was completed successfully or not.

Type
  boolean

#### (inner) clearAllPluginRegistry() → {boolean}

This is a wrapper function for warden.clearAllPluginRegistry. Which is in-turn a wrapper function for chiefPlugin.clearPluginRegistry. Which is in-turn a wrapper function for pluginBroker.unregisterAllPlugins.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 458

##### Returns:

True or False to indicate if the plugin registry data hive was cleared successfully or not.

Type
  boolean

#### (inner) clearData(dataName) → {boolean}

Wipes out the data using the unique specified data name, if any is found in the D-0data structure data storage data hive.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataName` | string | The unique name of the data that should be cleared.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 731

##### Returns:

True or False to indicate if the data was cleared successfully or not.

Type
  boolean

#### (inner) consoleLog(theNamespacePrefix, theFunctionName, message) → {void}

A wrapper function to expose the loggers.consoleLog function to the client application.

##### Parameters:

Name | Type | Description
--- | --- | ---
`theNamespacePrefix` | string | The namespace of the log that is being sent. Ex: folder.filename
`theFunctionName` | string | The name of the function that log is being called from.
`message` | string | object | The message that should be logged.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 891

##### Returns:

Type
  void

#### (inner) enqueueCommand(command) → {void}

Adds a command to the command queue. It is worth noting that a command could actually load a whole workflow of commands. So one command can spawn into many commands that cause the command queue to be very full with a very complicated workflow. This also acts as a wrapper for the warden.enqueueCommand function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`command` | string | The command to add to the command queue for executing.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 776

##### Returns:

Type
  void

#### (inner) executeBusinessRules(inputs, businessRules) → {string}

A wrapper call to a business rule from the warden.executeBusinessRules.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputs` | array.<(string|integer|boolean|object|function()), (string|integer|boolean|object|function())> | The array of inputs: inputs[0] = inputData - The input to the rule that is being called. inputs[1] = inputMetaData - Additional data the input to the rule.
`businessRules` | array.<string> | The array of rule name(s) that should be executed.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 752

##### Returns:

The value that is returned from the rule is also returned.

Type
  string

#### (inner) getConfigurationSetting(configurationNamespace, configurationName) → {string|integer|boolean|double|object}

This is just a wrapper for the warden.getConfigurationSetting function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`configurationNamespace` | string | The path in the configuration JSON object where the configuration setting should be found.
`configurationName` | string | The key of the configuration setting.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 866

##### Returns:

The value of whatever was stored in the D[configuration][configurationName].

Type
  string | integer | boolean | double | object

#### (inner) getData(dataName) → {object|string|boolean|number|array}

Gets data from the D-Data structure data storage data hive.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataName` | string | The unique name the data should be stored under.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 711

##### Returns:

The data element or object that was stored if any was found.

Type
  object | string | boolean | number | array

#### (inner) getFrameworkData() → {object}

Returns all the contents of the framework data. Can be used to pull the data contents of a Haystacks instance to swap it out with mock data, then swap back afterward.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 168

##### Returns:

A JSON object that contains the entire contents of the Haystacks D-data structure.

Type
  object

#### (inner) getPluginsRegistryPath() → {string}

A wrapper call to the warden.getPluginsRegistryPath function. Which is in-turn a wrapper function for the chiefPlugin.getPluginsRegistryPath. Which is in-turn a wrapper function for pluginBroker.getPluginsRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 622

##### Returns:

The path to the plugins listed in the plugin registry as meta-data.

Type
  string

#### (inner) initFramework(clientConfiguration) → {void}

Initializes the framework systems.

##### Parameters:

Name | Type | Description
--- | --- | ---
`clientConfiguration` | object | A configuration data object that contains all the data needed to bootstrap the framework for a client application.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 41

##### Returns:

Type
  void

#### (inner) isCommandQueueEmpty() → {boolean}

Determines if the command queue is empty or not empty. This is a wrapper function for the warden.isCommandQueueEmpty function.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 800

##### Returns:

True or False to indicate if the command execution queue is empty or not. Useful to determine if the command queue should continue executing or not.

Type
  boolean

#### (inner) listAllPluginsInRegistry() → {array.<string>}

This is a wrapper function for warden.listAllPluginsInRegistry. Which is in-turn a wrapper function for chiefPlugin.getAllPluginsInRegistry. Which is in-turn a wrapper function for pluginBroker.listPluginsInRegistry.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 280

##### Returns:

A list array of the names of the plugins in the plugin registry.

Type
  array.<string>

#### (inner) listAllPluginsInRegistryPath() → {array.<string>}

This is a wrapper function for warden.listAllPluginsInRegistryPath. Which is in-turn a wrapper function for chiefPlugin.getAllPluginsInRegistryPath. Which is in-turn a wrapper function for pluginBroker.listPluginsInRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 299

##### Returns:

A list array of the names of the plugins in the plugin registry.

Type
  array.<string>

#### (inner) listLoadedPlugins() → {array.<string>}

This is a wrapper function for warden.listLoadedPlugins. Which is in-turn a wrapper function for chiefPlugin.listLoadedPlugins. Which is in-turn a wrapper function for pluginBroker.listAllLoadedPlugins.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 261

##### Returns:

A list array of the names of the plugins that are currently loaded.

Type
  array.<string>

#### (inner) loadAllJsonData(dataPath, contextName)

Loads all of the JSON data at the specified path. Can be used to load account data, transaction history logs, activity logs, or any other kind of JSON data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataPath` | string | The path to the JSON files that should be loaded.
`contextName` | string | The type of data that should be loaded.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 664

##### Returns:

A JSON object that contains all of the data that was loaded and merged together.

#### (inner) loadCommandAliases(commandAliasesPath, contextName) → {void}

Loads and merges a set of client command aliases with the framework command aliases. This function acts as a wrapper for calling the warden.loadCommandAliases function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`commandAliasesPath` | string | The path to where the commands aliases XML file is stored, that should be loaded.
`contextName` | string | A name for the set of command aliases that should be used to store the path in the configuration system so it can be loaded by the framework.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 215

##### Returns:

Type
  void

#### (inner) loadCommandWorkflows(workflowPath, contextName) → {void}

Loads and merges a set of client workflows with the framework workflows. This function acts as a wrapper for calling the warden.loadCommandWorkflows function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`workflowPath` | string | The path to where the workflows file is stored, that should be loaded.
`contextName` | string | A name for the workflows that should be used to store the path in the configuration system so it can be loaded by the framework.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 238

##### Returns:

Type
  void

#### (inner) loadPlugin(pluginPath) → {boolean}

A wrapper call to the warden.loadPlugin function. Calls various functions in the chiefPlugn and pluginBroker to load plugin metaData and data: Business rules, Commands, Workflows, Constants, Configurations, dependencies ist(dependant plugins), etc...

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginPath` | string | The fully qualified path where to load the plugin from.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 496

##### Returns:

True or False to indicate if the plugin was loaded or not.

Type
  boolean

#### (inner) loadPluginResourceData(contextName, pluginConfigPath) → {object}

A wrapper call to the warden.loadPluginResourceData function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`contextName` | string | The type of resource that is being loaded, eg: configuration, commandAliases, workflows, ect...
`pluginConfigPath` | string | The fully qualified path to where the plugin data is located and should be loaded from.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 641

##### Returns:

The JSON data that is loaded and parsed from the plugin path.

Type
  object

#### (inner) loadPlugins(pluginsPaths) → {boolean}

A wrapper call to the warden.loadPlugins function. Calls various functions in the chiefPlugin and pluginBroker to load plugin metaData and data: Business rules, Commands, Workflows, Constants, Configurations, dependencies list (dependant plugins), etc...

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginsPaths` | array.<string> | The fully qualified paths where to load the plugins from.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 518

##### Returns:

True or False to indicate if all the plugins were loaded or not.

Type
  boolean

#### (inner) loadPluginsFromRegistry() → {boolean}

A wrapper call to warden.loadPluginsFromRegistry function. Calls various functions in the chief Plugin and pluginBroker to oad plugin metaData and data: Business rules, Commands, Workflows, Constants, Configurations, dependencies ist (dependant plugns), etc...

Author:
  - Seth Hollingsead
Source:
  - main.js, line 540

##### Returns:

True or False to indicate if all the plugins were loaded or not.

Type
  boolean

#### (inner) mergeClientBusinessRules(clientBusinessRules) → {void}

A wrapper function to expose the warden.mergeClientBusinessRules functionality.

##### Parameters:

Name | Type | Description
--- | --- | ---
`clientBusinessRules` | object | A map of client defined business rule names and client defined business rule function calls.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 185

##### Returns:

Type
  void

#### (inner) mergeClientCommands(clientCommands) → {void}

A wrapper function to expose the warden.mergeClientCommands functionality.

##### Parameters:

Name | Type | Description
--- | --- | ---
`clientCommands` | object | A map of client defined command names and client defined command function calls.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 200

##### Returns:

Type
  void

#### (inner) numberOfPluginsInRegistry() → {integer}

This is a wrapper function for warden.numberOfPluginsInRegistry. Which is in-turn a wrapper function for chiefPlugin.countAllPluginsInRegistry. Which is in-turn a wrapper function for pluginBroker.countPluginsInRegistry.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 318

##### Returns:

The count of the number of plugins listed in the plugin registry data hive.

Type
  integer

#### (inner) numberOfPluginsInRegistryPath() → {integer}

This is a wrapper function for warden.numberOfPluginsInRegistryPath. Which is in-turn a wrapper function for chiefPlugin.countAllPluginsInRegistryPath. Which is in-turn a wrapper function for pluginBroker.countPluginsInRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 337

##### Returns:

Teh count of the number of plugin sub-folders in the plugins path listed in the plugn registry data hive.

Type
  integer

#### (inner) processCommandQueue() → {array.<boolean, (string|integer|boolean|object|array)>}

This is a wrapper function for the warden.processCommandQueue. This leads to a call to the chiefCommander.processCommand to process an individual command. This is because a command could actually invoke a command workflow that might enqueue a bunch of commands to the command queue. All of them must be executed in sequence as part of the main application loop.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 819

##### Returns:

An array with a boolean True or False value to indicate if the application should exit or not exit, followed by the command output.

Type
  array.<boolean, (string|integer|boolean|object|array)>

#### (inner) registerPluginByNameAndPath(pluginName, pluginPath) → {boolean}

This is a wrapper function for warden.registerPluginByNameAndPath. Which is in-turn a wrapper function for chiefPlugin.registerNamedPlugin. Which is in-turn a wrapper function for pluginBroker.registerPlugin.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should be registered.
`pluginPath` | string | The path to the plugin, to be added to the plugin registry. This should be the path to the plugin/package.json file, but not including the package.json as part of the path URI.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 356

##### Returns:

True or False to indicate if the plugin was added to the plugin registry successfully or not.

Type
  boolean

#### (inner) setConfigurationSetting(configurationNamespace, configurationName, configurationValue) → {void}

This is just a wrapper for the warden.setConfigurationSetting function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`configurationNamespace` | string | The path in the configuration JSON object where the configuration setting should be set. Ex: businessRules.rules.stringParsing.countCamelCaseWords
`configurationName` | string | The key of the configuration setting.
`configurationValue` | string | integer | boolean | double | object | The value of the configuration setting.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 840

##### Returns:

Type
  void

#### (inner) storeData(dataName, data) → {boolean}

Persist some data to the data storage in the D-data structure.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataName` | string | The name of the data, unique name used to store the data in the data structure.
`data` | object | string | boolean | number | array | The data that should be stored.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 688

##### Returns:

True or False to indicate if the data was stored successfully or not.

Type
  boolean

#### (inner) syncPluginRegistryWithPath() → {boolean}

This is a wrapper function for warden.syncPluginRegistryWithPath. Which is in-turn a wrapper function for chiefPlugin.synchronizePluginRegistryWithPath. Which is in-turn a wrapper function for pluginBroker.synchPluginRegistryWithPluginRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 435

##### Returns:

True or False to indicate if the synchronization was performed successfully or not.

Type
  boolean

#### (inner) unloadAllPlugins() → {boolean}

A wrapper call to the warden.unloadAllPlugins function. Calls various functions in the chiefPlugin and pluginBroker to unload and remove all plugin metaData and data: Business rules, Commands, Workflows, Constants, Configurations, dependencies list (dependant plugins), etc...

Author:
  - Seth Hollingsead
Source:
  - main.js, line 603

##### Returns:

True or False to indicate if all the plugins were unloaded successfully or not.

Type
  boolean

#### (inner) unloadPlugin(pluginName) → {boolean}

A wrapper call to the warden.unloadPlugin function. Calls various functions in the chiefPlugin and pluginBroker to unload and remove metaData and data: Business rules, Commands, Workflows, Constants, Configurations, dependencies list (dependant plugins), etc...

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should be unloaded.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 559

##### Returns:

True or False to indicate if the plugin was unloaded successfully or not.

Type
  boolean

#### (inner) unloadPlugins(pluginNames) → {boolean}

A wrapper call to the warden.unloadPlugins function. Calls various functions in the chiefPlugin and pluginBroker to unload and remove all the metaData and data for a list of plugins: Business rules, Commands, Workflows, Constants, Configurations, dependencies list (dependant plugins), etc...

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginNames` | array.<string> | An array list of names of plugins that should be unloaded.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 581

##### Returns:

True or False to indicate if all the plugins were unloaded successfully or not.

Type
  boolean

#### (inner) unregisterPluginByName(pluginName) → {boolean}

This is a wrapper function for warden.unregisterPluginByName. Which is in-turn a wrapper function for chiefPlugin.unregisterNamedPlugin. Which is in-turn a wrapper function for pluginBroker.unregisterPlugin.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should be removed from the plugin registry.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 382

##### Returns:

True or False to indicate if the plugin was removed from the plugin registry successfully or not.

Type
  boolean

#### (inner) unregisterPlugins(pluginsListArray) → {boolean}

This is a wrapper function for warden.unregisterPlugins. Which is in-turn a wrapper function for chiefPlugin.unregisterPlugins. Which is in-turn a wrapper function for pluginBroker.unregisterPlugins.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginsListArray` | string | array.<string> | A string or list array of plugin names that should be removed from the plugin registry.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 404

##### Returns:

True or False to indicate if all the plugins were successfully removed from the plugin registry or not.

Type
  boolean

#### (inner) writePluginRegistryToDisk() → {boolean}

This is a wrapper function for warden.writePluginRegistryToDisk. Which is in-turn a wrapper function for chiefPlugin.savePluginRegistryDisk. Which is in-turn a wrapper function for pluginBroker.savePluginRegistry.

Author:
  - Seth Hollingsead
Source:
  - main.js, line 477

##### Returns:

True or False to indicate if the plugin registry was successfully saved to the disk or not.

Type
  boolean