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.- Source:
-
constants
-
Constants for shared use
Provides a constants object to access commonly needed
values that are shared across files.- Source:
-
<constant> crypto
-
Faye client extension implementation.
Implements extension for faye client to sign and send and
receive messages with IdealNet- Source:
-
<constant> crypto
-
Utility functions
Implements methods to support other functions
- Source:
-
<constant> Faye
-
Faye client implementation.
Implements faye client to communicate with IdealNet's pubsub
server.- 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 tokenstring the identifying token of the client
dbClientMongoClient 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 strstring 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 uristring 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 querystring 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 reqBodystring 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 prestring Value to prepend to the salt.
countnumber 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 tokenstring The token supplied in the request.
dbClientMongoClient 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 textstring the text being logged
objObject 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 pathstring the request path
reqObject the request body
Properties
Name Type Description tokenstring the token of the client being used to make the request
signaturestring the signature of req.payload + private key
payloadObject the actual api body to be used to make the pubsub request (structure varies)
payloadstring verbatim string from request body without any json parsing, only used for signature validation
dbClientMongoClient 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 jsonstring Json payload of the request
keystring The private key used to uniquely sign the request
saltstring 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 reqBodyObject 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 tokenstring the identifying token of the client
signaturestring the signature sent with the request
payloadObject the request payload (varies by request)
dbClientMongoClient 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