# Module: ruleBroker

Contains all the functions necessary to manage the business rules system.

Author:
  - Seth Hollingsead
Copyright:
  - Copyright © 2022-… by Seth Hollingsead. All rights reserved
Source:
  - brokers/ruleBroker.js, line 1

### Requires

- module:ruleParsing
- module:rulesLibrary
- module:data
- @haystacks/constants
- path

### Methods

#### (inner) addClientRules(clientRules) → {void}

Merges client defined business rules with the system defined business rules.

##### Parameters:

Name | Type | Description
--- | --- | ---
`clientRules` | array.<object> | The client rules that should be merged with the system rules.

Author:
  - Seth Hollingsead
Source:
  - brokers/ruleBroker.js, line 50

##### Returns:

Type
  void

#### (inner) addPluginRules(pluginName, pluginRules) → {boolean}

Merges plugin defined business rules with the system defined business rules.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the current plugin these rules belong to.
`pluginRules` | array.<object> | The plugin rules that should be merged with the system rules.

Author:
  - Seth Hollingsead
Source:
  - brokers/ruleBroker.js, line 66

##### Returns:

True or False to indicate if the merge was successful or not.

Type
  boolean

#### (inner) bootStrapBusinessRules() → {void}

Captures all of the business rule string-to-function call map data in the rulesLibrary and migrates that data to the D-data structure. This is important now because we are going to allow the client to define their own business rules separate from the system defined business rules. So we need a way to merge all client defined and system defined business rules into one location. Then the rule broker will execute business rules from the D-data structure and not the rules library per-say. This will allow the system to expand much more dynamically and even be user-defined & flexible to client needs.

Author:
  - Seth Hollingsead
Source:
  - brokers/ruleBroker.js, line 29

##### Returns:

Type
  void

#### (inner) processRules(inputs, rulesToExecute) → {string|integer|boolean|object|function}

Parse the given input Object/String/Integer/Data/Function through a set of business rules, (Some rules do not support chaining); where the rules are defined in the input rules array.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputs` | array.<(string|integer|boolean|object|function()), (string|integer|boolean|object|function())> | An array of inputs, inputData & inputMetaData. inputs[0] = inputData - The primary input data that should be processed by the business rule. inputs[1] = inputMetaData - Additional meta-data that should be used when processing the business rule.
`rulesToExecute` | array.<string> | The name(s) of the rule(s) that should be executed for modding the input data.

Author:
  - Seth Hollingsead
Source:
  - brokers/ruleBroker.js, line 107

##### Returns:

A modified data Object/String/Integer/Boolean/Function where the data has been modified based on the input data, input meta-data, and business rule that was executed.

Type
  string | integer | boolean | object | function