npm package: @mimik/validation-helper
Description: Validation helper for mimik microservices
Author: mimik technology inc
Latest version: 2.1.1

<a name="module_validation-helper"></a>

## validation-helper
**Example**  
```js
// default import
import validationHelper from '@mimik/validation-helper';

// named imports
import { validateCompositeId, validateOauthId, validateLocalLinkNetworkId, validateLocation, validateGeoLocation, validateUniqueAttributes } from '@mimik/validation-helper';
```

* [validation-helper](#module_validation-helper)
    * [~validateCompositeId(id)](#module_validation-helper..validateCompositeId) ⇒ <code>object</code>
    * [~validateOauthId(id, userId, onBehalfId)](#module_validation-helper..validateOauthId) ⇒ <code>string</code>
    * [~validateLocalLinkNetworkId(localLinkNetworkId, networkAddress, publicAddress)](#module_validation-helper..validateLocalLinkNetworkId) ⇒ <code>string</code>
    * [~validateLocation(lon, lat, [elevation], type)](#module_validation-helper..validateLocation) ⇒ <code>object</code> \| <code>null</code>
    * [~validateGeoLocation(location)](#module_validation-helper..validateGeoLocation) ⇒ <code>object</code> \| <code>null</code>
    * [~validateUniqueAttributes(attributes)](#module_validation-helper..validateUniqueAttributes) ⇒ <code>boolean</code>

<a name="module_validation-helper..validateCompositeId"></a>

### validation-helper~validateCompositeId(id) ⇒ <code>object</code>
A composite id is a base64 encoded object with the following structure:
```javascript
 {
   "nodeId": (string),
   "localLinkNetworkId": (string)
 }
```

**Kind**: inner method of [<code>validation-helper</code>](#module_validation-helper)  
**Returns**: <code>object</code> - The decoded composite id object.  
**Category**: sync  
**Throws**:

- <code>Error</code> If the id is not a valid base64 composite.


| Param | Type | Description |
| --- | --- | --- |
| id | <code>string</code> | Id to validate as a composite id. |

<a name="module_validation-helper..validateOauthId"></a>

### validation-helper~validateOauthId(id, userId, onBehalfId) ⇒ <code>string</code>
Resolves a request id against JWT-derived identifiers:
- `"me"`: returns `userId`; throws if `userId` is empty or if `onBehalfId` is present.
- `"onBehalf"`: returns `onBehalfId`; throws if `onBehalfId` is empty.
- Any other value: must match `userId` or `onBehalfId` (if present), otherwise throws a mismatch error.

**Kind**: inner method of [<code>validation-helper</code>](#module_validation-helper)  
**Returns**: <code>string</code> - The validated id.  
**Category**: sync  
**Throws**:

- <code>Error</code> If validation fails.


| Param | Type | Description |
| --- | --- | --- |
| id | <code>string</code> | The id to validate. Use `"me"` to resolve to `userId`, or `"onBehalf"` to resolve to `onBehalfId`. |
| userId | <code>string</code> | The userId to validate against (from JWT.sub). |
| onBehalfId | <code>string</code> | The onBehalfId to validate against (from JWT.onBehalfId). |

<a name="module_validation-helper..validateLocalLinkNetworkId"></a>

### validation-helper~validateLocalLinkNetworkId(localLinkNetworkId, networkAddress, publicAddress) ⇒ <code>string</code>
The localLinkNetworkId is a base64 encoded object:
```javascript
{
  "networkAddress": (string),
  "publicAddress": (string)
}
```

**Kind**: inner method of [<code>validation-helper</code>](#module_validation-helper)  
**Returns**: <code>string</code> - The localLinkNetworkId.  
**Category**: sync  
**Throws**:

- <code>Error</code> If validation fails.


| Param | Type | Description |
| --- | --- | --- |
| localLinkNetworkId | <code>string</code> | The id to validate. |
| networkAddress | <code>string</code> | A network address. |
| publicAddress | <code>string</code> | A public address. |

<a name="module_validation-helper..validateLocation"></a>

### validation-helper~validateLocation(lon, lat, [elevation], type) ⇒ <code>object</code> \| <code>null</code>
Validate location.

**Kind**: inner method of [<code>validation-helper</code>](#module_validation-helper)  
**Returns**: <code>object</code> \| <code>null</code> - The validated location object, or null if all values are missing.  
**Category**: sync  
**Throws**:

- <code>Error</code> If validation fails.


| Param | Type | Description |
| --- | --- | --- |
| lon | <code>number</code> | Longitude [-180, 180] in degrees. |
| lat | <code>number</code> | Latitude [-90, 90] in degrees. |
| [elevation] | <code>number</code> | Elevation [-5000, 50000] in meters. |
| type | <code>string</code> | Type of coordinates ("Point"). |

<a name="module_validation-helper..validateGeoLocation"></a>

### validation-helper~validateGeoLocation(location) ⇒ <code>object</code> \| <code>null</code>
Validate GeoLocation.

**Kind**: inner method of [<code>validation-helper</code>](#module_validation-helper)  
**Returns**: <code>object</code> \| <code>null</code> - The validated location, or null if not present.  
**Category**: sync  
**Throws**:

- <code>Error</code> If validation fails.


| Param | Type | Description |
| --- | --- | --- |
| location | <code>object</code> \| <code>null</code> | A GeoJSON location object with a `coordinates` array of `[longitude, latitude]`, a `type` of `"Point"`, and an optional `elevation` number. |

<a name="module_validation-helper..validateUniqueAttributes"></a>

### validation-helper~validateUniqueAttributes(attributes) ⇒ <code>boolean</code>
Validate unique attributes.

**Kind**: inner method of [<code>validation-helper</code>](#module_validation-helper)  
**Returns**: <code>boolean</code> - True if attributes are unique by name.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| attributes | <code>Array.&lt;object&gt;</code> | A non-null array of attribute objects, each with a `name` property. |