Global

Members


<constant> axios

IdealNet REST Request.

Implements functions and logic to parse the REST request
coming into IdealNet REST and translate that to a pubsub
request.

Author:
Source:

constants

Constants for shared use

Provides a constants object to access commonly needed
values that are shared across files.

Author:
Source:

<constant> crypto

Faye client extension implementation.

Implements extension for faye client to sign and send and
receive messages with IdealNet

Author:
Source:

<constant> crypto

Utility functions

Implements methods to support other functions

Author:
Source:

<constant> Faye

Faye client implementation.

Implements faye client to communicate with IdealNet's pubsub
server.

Author:
Source:

Methods


<async> authDoc(token, dbClient)

Lookup the auth doc tied to a token

Lookup and return the auth doc tied to a provided token.

Parameters:
Name Type Description
token string

the identifying token of the client

dbClient MongoClient

Client connection to use for auth doc access

Source:
Returns:

the auth doc for the token

Type
Object

base64Encode(str)

Encode a string as Base64.

Parameters:
Name Type Description
str string

The string we are encoding.

Source:
Returns:

Base64 encoded string.

Type
string

<async> createClient(uri)

Create a MongoClient.

Create a mongo client connection in order to interact with mongo

Parameters:
Name Type Description
uri string

the connection uri

Source:
Returns:

client connection

Type
MongoClient

dbName()

Get the database name

Return the correct database to use based the env var set

Source:
Returns:

the database name

Type
string

extractApiFromQuery(query)

Return PubSub api from a given query string.

Parameters:
Name Type Description
query string

the query string to extract the api from

Source:
Returns:

the PubSub api

Type
string

extractPayload(reqBody)

Take the request body and extract the payload as a string, without parsing to JSON.
First get a substring starting at '"payload"' and ending at the end of the string.
Next get the index of the first '{', this will be our starting point. Then loop through each character of the substring with a counter
for the number of '{' that appear in the string. Add 1 to the counter for each '{' and subtract 1 for each '}'.
When the counter reaches 0, we have found the index of the last '}'.
Then our result will be a substring of that starting at the starting point and ending at the last '}'.

Parameters:
Name Type Description
reqBody string

string representation of the request body before being parsed

Source:

generateSalt(pre, count)

Generate a salt to be used in signing.

Parameters:
Name Type Description
pre string

Value to prepend to the salt.

count number

Current iterations count.

Source:
Returns:

The salt to be used for signing.

Type
string

<async> getPrivateKey(token, dbClient)

Retrieve the private key associated with a token.

Connect to the database and retrieve the auth doc in order to get the private
key that we will need for the client connection.

Parameters:
Name Type Description
token string

The token supplied in the request.

dbClient MongoClient

The db client used to retrieve the private key.

Source:
Returns:

The private key associated with the token.

Type
string

log(text, obj)

Log to console in a standard way for readability.

Parameters:
Name Type Description
text string

the text being logged

obj Object

an optional object to logg with the text

Source:
Returns:

no return value

Type
undefined

route(path, req, payload, dbClient)

Process incoming route requests.

Validate requests are going to an existing route,
route them to the correct endpoint, and return an
appropriate result.

Parameters:
Name Type Description
path string

the request path

req Object

the request body

Properties
Name Type Description
token string

the token of the client being used to make the request

signature string

the signature of req.payload + private key

payload Object

the actual api body to be used to make the pubsub request (structure varies)

payload string

verbatim string from request body without any json parsing, only used for signature validation

dbClient MongoClient

the db client used for this request

Source:
Returns:

Response returned from pubsub api call

Type
Object

signRequest(json, key, salt)

Generate and return a signature for a request body.

Signature generated from the SHA256 hashing of the json
payload, the private key and a unique salt.

Parameters:
Name Type Description
json string

Json payload of the request

key string

The private key used to uniquely sign the request

salt string

salt used to sign the request - must be passed in
since we need to send it down

Source:
Returns:

The signature

Type
string

validateRequest(reqBody)

Validate request structure

Validate that the request has all the necessary components of a request

Parameters:
Name Type Description
reqBody Object

The request body to validate

Source:
Returns:

Object represents whether
the request is structurally valid and a string of why it's not if it's not

Type
Object

<async> validateSignature(token, signature, payload, dbClient)

Validate signature of request

Validate that the signature was in fact created from
the right credentials to ensure integrity.

Parameters:
Name Type Description
token string

the identifying token of the client

signature string

the signature sent with the request

payload Object

the request payload (varies by request)

dbClient MongoClient

the db client used to retrieve the private key

Source:
Returns:

Promise object represents whether
the rebuilt signature matches the signature sent in the request

Type
Promise