api/utils/requestProcessor

Module for processing data passed to Countly

Source:

Methods

(static) processRequest(params) → {void}

Source:

Default request processing handler, which requires request context to operate. Check tcp_example.js

Example
//creating request context
var params = {
    //providing data in request object
    'req':{"url":"/i", "body":{"device_id":"test","app_key":"APP_KEY","begin_session":1,"metrics":{}}},
    //adding custom processing for API responses
    'APICallback': function(err, data, headers, returnCode, params){
         //handling api response, like sending to client or verifying
         if(err){
             //there was problem processing request
             console.log(data, returnCode);
         }
         else{
             //request was processed, let's handle response data
             handle(data);
         }
    }
};

//processing request
processRequest(params);
Parameters:
Name Type Description
params params

for request context. Minimum needed properties listed

Properties
Name Type Description
req object

Request object, should not be empty and should contain listed params

Properties
Name Type Description
url string

Endpoint URL that you are calling. May contain query string.

body object

Parsed JSON object with data (same name params will overwrite query string if anything provided there)

APICallback APICallback

API output handler. Which should handle API response

Returns:

void

Type
void

(inner) checksumSaltVerification(params, type, done) → {function}

Source:
Parameters:
Name Type Description
params object

params object

type String

source type

done function

done callback

Returns:
  • done or boolean value
Type
function

(inner) fetchAppUser(params) → {promise}

Source:

Function to fetch app user from db

Parameters:
Name Type Description
params object

params object

Returns:
  • user
Type
promise

(inner) ignorePossibleDevices(params, done) → {function}

Source:

Add devices to ignore them

Parameters:
Name Type Description
params params

params object

done function

callback when processing done

Returns:

done

Type
function

(inner) loadDbVersionMarks(callback) → {void}

Source:

Fetches version mark history (database)

Parameters:
Name Type Description
callback function

callback when response is ready

Returns:

void

Type
void

(inner) loadFsVersionMarks(callback) → {void}

Source:

Fetches version mark history (filesystem)

Parameters:
Name Type Description
callback function

callback when response is ready

Returns:

void

Type
void

(inner) processBulkRequest(i, requests, params) → {void}

Source:

Process Bulk Request

Parameters:
Name Type Description
i number

request number in bulk

requests array

array of requests to process

params params

params object

Returns:

void

Type
void

(inner) processFetchRequest(params, app, done)

Source:

Process fetch request from sdk

Parameters:
Name Type Description
params object

params object

app object

app document

done function

callback when processing done

(inner) processRequestData(params, app, done)

Source:

Process Request Data

Parameters:
Name Type Description
params params

params object

app object

app document

done function

callbck when processing done

(inner) processUser(params, initiator, done, try_times) → {Promise}

Source:
Parameters:
Name Type Description
params object

params object

initiator function

function which initiated request

done function

callback when processing done

try_times number

how many times request was retried

Returns:
  • resolved
Type
Promise

(inner) restartRequest(params, initiator, done, try_times, fail) → {void}

Source:

Restart Request

Parameters:
Name Type Description
params params

params object

initiator function

function which initiated request

done function

callback when processing done

try_times number

how many times request was retried

fail function

callback when restart limit reached

Returns:

void

Type
void

(inner) validateAppForFetchAPI(params, done, try_times) → {function}

Source:

Validate app for fetch API from sdk

Parameters:
Name Type Description
params object

params object

done function

callback when processing done

try_times number

how many times request was retried

Returns:

done - done callback

Type
function

(inner) validateAppForWriteAPI(params, done, try_times) → {void}

Source:

Validate App for Write API Checks app_key from the http request against "apps" collection. This is the first step of every write request to API.

Parameters:
Name Type Description
params params

params object

done function

callback when processing done

try_times number

how many times request was retried

Returns:

void

Type
void