@mimik/public-helper v3.0.0
public-helper
Example
const publicHlelper = require('@mimik/public-helper');public-helper~PROPERTIES
Property associated with the location.
The following environment variables are set:
| Env variable name | Description | Default | Comments | 
|---|---|---|---|
| queryURL_ENV | query to fill the different local properties from AWS | SERVER_LOCAL_IPV4, INSTANCE_ID, LOCAL_HOSTNAME | |
| publicQueryURL_ENV | publicQuery to fill the public property from AWS | SERVER_PUBLIC_IPV4 | 
The following environment variables are used:
| Env variable name | Description | Default | Comments | 
|---|---|---|---|
| AWS_LOCAL_PROPERTIES | IP address to access instance properties on AWS | 169.254.169.254 | 
Kind: inner constant of public-helper
public-helper~getLocation(}, ip, correlationId, options) ⇒ Promise
The location object has the follwoing structure:
 {
   "type": "Point",
   "coordinates": [ lon, lat],
   .....
 }The result object has the following structure:
 {
   "status": (describing where the data come from),
   "ip": (the public IP address of the server),
   "location": (the location object)
 }When ip is not present, the following environement variables will be updated:
| Env variable name | Description | Default | Comments | 
|---|---|---|---|
| SERVER_LOCATION_LON | longitude of the IP address | location.coordinates0 | |
| SERVER_LOCATION_LAT | latitude of the IP address | location.coordinates1 | |
| SERVER_PUBLIC_IPV4 | public IP address | result.ip | 
Kind: inner method of public-helper
Returns: Promise - .
Category: async
Fulfil: object The location object encapsulated in the result.  
| Param | Type | Description | 
|---|---|---|
| } | object | locationProvider - location provider information to use for getting the location { url, key } (key is optional). | 
| ip | IP.<string> | Optional IP address to locate. | 
| correlationId | string | Correlation Id to add the the request. | 
| options | object | Options associated with the call. Use to pass metrics to rpRetry. | 
public-helper~getPublic(locationProvider, cloudProvider, correlationId, options) ⇒ Promise
The location data has the following structure:
 {
   "status": (describing where the data come from),
   "ip": (the public IP address of the server),
   "localIp": (`in case of AWS` local adddress),
   "instanceId": (`in case of AWS` id of the instance running the service),
   "location": (the location object)
 }When provided, the locationProvider information has the following stucture:
 {
   "url": (URL of the provider),
   "key": (security key to associated with the request)
 }The following environment variables will used:
| Env variable name | Description | Default | Comments | 
|---|---|---|---|
| SERVER_LOCAL_IPV4 | AWS local IP address | ||
| INSTANCE_ID | id of the instance | ||
| SERVER_PUBLIC_IPV4 | public IP address | ||
| SERVER_ID | id of the server | ||
| SERVER_LOCATION_LON | longitude of the server | ||
| SERVER_LOCATION_LAT | latitude of the server | 
and in order to set these properties process.env.AWS_LOCAL_PROPERTIES is used and is default 169.254.169.254 is used.
Kind: inner method of public-helper
Returns: Promise - .
Category: async
Fulfil: object The location data.  
| Param | Type | Description | 
|---|---|---|
| locationProvider | URL.<string> | The location provider or noPublic when no locationProvider is used or environment when the environment variables have the information. | 
| cloudProvider | string | Cloud Provider used to run the service (currently limited to AWS). | 
| correlationId | string | Correlation Id to add the the request. | 
| options | object | Options associated with the call. Use to pass metrics to rpRetry. | 
public-helper~setSettings(settings, newConfig) ⇒ object
Set config.serverSettings with location data.
Kind: inner method of public-helper
Returns: object - The updated config.serverSettings.
Category: sync  
| Param | Type | Description | 
|---|---|---|
| settings | object | The config.serverSettings to update. | 
| newConfig | object | The location configuration to use to update the config.serverSettings. |