@mimik/validation-helper
v2.1.1
Published
Validation helper for mimik microservices
Readme
validation-helper
Example
// default import
import validationHelper from '@mimik/validation-helper';
// named imports
import { validateCompositeId, validateOauthId, validateLocalLinkNetworkId, validateLocation, validateGeoLocation, validateUniqueAttributes } from '@mimik/validation-helper';- validation-helper
- ~validateCompositeId(id) ⇒ object
- ~validateOauthId(id, userId, onBehalfId) ⇒ string
- ~validateLocalLinkNetworkId(localLinkNetworkId, networkAddress, publicAddress) ⇒ string
- ~validateLocation(lon, lat, [elevation], type) ⇒ object | null
- ~validateGeoLocation(location) ⇒ object | null
- ~validateUniqueAttributes(attributes) ⇒ boolean
validation-helper~validateCompositeId(id) ⇒ object
A composite id is a base64 encoded object with the following structure:
{
"nodeId": (string),
"localLinkNetworkId": (string)
}Kind: inner method of validation-helper
Returns: object - The decoded composite id object.
Category: sync
Throws:
- Error If the id is not a valid base64 composite.
| Param | Type | Description | | --- | --- | --- | | id | string | Id to validate as a composite id. |
validation-helper~validateOauthId(id, userId, onBehalfId) ⇒ string
Resolves a request id against JWT-derived identifiers:
"me": returnsuserId; throws ifuserIdis empty or ifonBehalfIdis present."onBehalf": returnsonBehalfId; throws ifonBehalfIdis empty.- Any other value: must match
userIdoronBehalfId(if present), otherwise throws a mismatch error.
Kind: inner method of validation-helper
Returns: string - The validated id.
Category: sync
Throws:
- Error If validation fails.
| Param | Type | Description |
| --- | --- | --- |
| id | string | The id to validate. Use "me" to resolve to userId, or "onBehalf" to resolve to onBehalfId. |
| userId | string | The userId to validate against (from JWT.sub). |
| onBehalfId | string | The onBehalfId to validate against (from JWT.onBehalfId). |
validation-helper~validateLocalLinkNetworkId(localLinkNetworkId, networkAddress, publicAddress) ⇒ string
The localLinkNetworkId is a base64 encoded object:
{
"networkAddress": (string),
"publicAddress": (string)
}Kind: inner method of validation-helper
Returns: string - The localLinkNetworkId.
Category: sync
Throws:
- Error If validation fails.
| Param | Type | Description | | --- | --- | --- | | localLinkNetworkId | string | The id to validate. | | networkAddress | string | A network address. | | publicAddress | string | A public address. |
validation-helper~validateLocation(lon, lat, [elevation], type) ⇒ object | null
Validate location.
Kind: inner method of validation-helper
Returns: object | null - The validated location object, or null if all values are missing.
Category: sync
Throws:
- Error If validation fails.
| Param | Type | Description | | --- | --- | --- | | lon | number | Longitude [-180, 180] in degrees. | | lat | number | Latitude [-90, 90] in degrees. | | [elevation] | number | Elevation [-5000, 50000] in meters. | | type | string | Type of coordinates ("Point"). |
validation-helper~validateGeoLocation(location) ⇒ object | null
Validate GeoLocation.
Kind: inner method of validation-helper
Returns: object | null - The validated location, or null if not present.
Category: sync
Throws:
- Error If validation fails.
| Param | Type | Description |
| --- | --- | --- |
| location | object | null | A GeoJSON location object with a coordinates array of [longitude, latitude], a type of "Point", and an optional elevation number. |
validation-helper~validateUniqueAttributes(attributes) ⇒ boolean
Validate unique attributes.
Kind: inner method of validation-helper
Returns: boolean - True if attributes are unique by name.
Category: sync
| Param | Type | Description |
| --- | --- | --- |
| attributes | Array.<object> | A non-null array of attribute objects, each with a name property. |
