lib/pxapi.js
function callServer(ctx, config, callback) {
    const ip = ctx.ip;
    const fullUrl = ctx.fullUrl;
    const vid = ctx.vid || '';
    const pxhd = ctx.pxhd || '';
    const vidSource = ctx.vidSource || '';
    const uuid = ctx.uuid || '';
    const uri = ctx.uri || '/';
    const headers = pxUtil.formatHeaders(ctx.headers, config.SENSITIVE_HEADERS);
    const httpVersion = ctx.httpVersion;
    const riskMode = config.MODULE_MODE === config.MONITOR_MODE.MONITOR ? 'monitor' : 'active_blocking';

    const data = {
        request: {
            ip: ip,
            headers: headers,
            url: fullUrl,
            uri: uri,
            firstParty: config.FIRST_PARTY_ENABLED
        },
        additional: {
            s2s_call_reason: ctx.s2sCallReason,
            http_version: httpVersion,
            http_method: ctx.httpMethod,
            risk_mode: riskMode,
            module_version: config.MODULE_VERSION,
            cookie_origin: ctx.cookieOrigin,
            request_cookie_names: ctx.requestCookieNames
        }
    };

    if (ctx.s2sCallReason === 'cookie_decryption_failed') {
        data.additional.px_orig_cookie = ctx.getCookie(); //No need strigify, already a string
    }

    if (ctx.s2sCallReason === 'cookie_expired' || ctx.s2sCallReason === 'cookie_validation_failed') {
        data.additional.px_cookie = JSON.stringify(ctx.decodedCookie);
    }

    pxUtil.prepareCustomParams(config, data.additional);

    const reqHeaders = {
        Authorization: 'Bearer ' + config.AUTH_TOKEN,
        'Content-Type': 'application/json'
    };

    if (vid) {
        data.vid = vid;
    }
    if (uuid) {
        data.uuid = uuid;
    }
    if (pxhd) {
        data.pxhd = pxhd;
    }
    if (vidSource) {
        data.vid_source = vidSource;
    }
    if (pxhd && data.additional.s2s_call_reason === 'no_cookie') {
        data.additional.s2s_call_reason = 'no_cookie_w_vid';
    }
    if (ctx.originalUuid) {
        data.additional['original_uuid'] = ctx.originalUuid;
    }

    if (ctx.originalTokenError) {
        data.additional['original_token_error'] = ctx.originalTokenError;
    }

    if (ctx.originalToken) {
        data.additional['original_token'] = ctx.originalToken;
    }

    if (ctx.decodedOriginalToken) {
        data.additional['px_decoded_original_token'] = ctx.decodedOriginalToken;
    }

    if(ctx.hmac) {
        data.additional['px_cookie_hmac'] = ctx.hmac;
    }

    ctx.hasMadeServerCall = true;
    return pxHttpc.callServer(data, reqHeaders, config.SERVER_TO_SERVER_API_URI, 'query', config, callback);
}
function callServer(ctx, config, callback) {
    const ip = ctx.ip;
    const fullUrl = ctx.fullUrl;
    const vid = ctx.vid || '';
    const pxhd = ctx.pxhd || '';
    const vidSource = ctx.vidSource || '';
    const uuid = ctx.uuid || '';
    const uri = ctx.uri || '/';
    const headers = pxUtil.formatHeaders(ctx.headers, config.SENSITIVE_HEADERS);
    const httpVersion = ctx.httpVersion;
    const riskMode = config.MODULE_MODE === config.MONITOR_MODE.MONITOR ? 'monitor' : 'active_blocking';

    const data = {
        request: {
            ip: ip,
            headers: headers,
            url: fullUrl,
            uri: uri,
            firstParty: config.FIRST_PARTY_ENABLED
        },
        additional: {
            s2s_call_reason: ctx.s2sCallReason,
            http_version: httpVersion,
            http_method: ctx.httpMethod,
            risk_mode: riskMode,
            module_version: config.MODULE_VERSION,
            cookie_origin: ctx.cookieOrigin,
            request_cookie_names: ctx.requestCookieNames
        }
    };

    if (ctx.s2sCallReason === 'cookie_decryption_failed') {
        data.additional.px_orig_cookie = ctx.getCookie(); //No need strigify, already a string
    }

    if (ctx.s2sCallReason === 'cookie_expired' || ctx.s2sCallReason === 'cookie_validation_failed') {
        data.additional.px_cookie = JSON.stringify(ctx.decodedCookie);
    }

    pxUtil.prepareCustomParams(config, data.additional);

    const reqHeaders = {
        Authorization: 'Bearer ' + config.AUTH_TOKEN,
        'Content-Type': 'application/json'
    };

    if (vid) {
        data.vid = vid;
    }
    if (uuid) {
        data.uuid = uuid;
    }
    if (pxhd) {
        data.pxhd = pxhd;
    }
    if (vidSource) {
        data.vid_source = vidSource;
    }
    if (pxhd && data.additional.s2s_call_reason === 'no_cookie') {
        data.additional.s2s_call_reason = 'no_cookie_w_vid';
    }
    if (ctx.originalUuid) {
        data.additional['original_uuid'] = ctx.originalUuid;
    }

    if (ctx.originalTokenError) {
        data.additional['original_token_error'] = ctx.originalTokenError;
    }

    if (ctx.originalToken) {
        data.additional['original_token'] = ctx.originalToken;
    }

    if (ctx.decodedOriginalToken) {
        data.additional['px_decoded_original_token'] = ctx.decodedOriginalToken;
    }

    if(ctx.hmac) {
        data.additional['px_cookie_hmac'] = ctx.hmac;
    }

    ctx.hasMadeServerCall = true;
    return pxHttpc.callServer(data, reqHeaders, config.SERVER_TO_SERVER_API_URI, 'query', config, callback);
}
function callServer ( ctx , config , callback ) { const ip = ctx . ip ; const fullUrl = ctx . fullUrl ; const vid = ctx . vid || '' ; const pxhd = ctx . pxhd || '' ; const vidSource = ctx . vidSource || '' ; const uuid = ctx . uuid || '' ; const uri = ctx . uri || '/' ; const headers = pxUtil . formatHeaders ( ctx . headers , config . SENSITIVE_HEADERS ) ; const httpVersion = ctx . httpVersion ; const riskMode = config . MODULE_MODE === config . MONITOR_MODE . MONITOR ? 'monitor' : 'active_blocking' ; const data = { request : { ip : ip , headers : headers , url : fullUrl , uri : uri , firstParty : config . FIRST_PARTY_ENABLED } , additional : { s2s_call_reason : ctx . s2sCallReason , http_version : httpVersion , http_method : ctx . httpMethod , risk_mode : riskMode , module_version : config . MODULE_VERSION , cookie_origin : ctx . cookieOrigin , request_cookie_names : ctx . requestCookieNames } } ; if ( ctx . s2sCallReason === 'cookie_decryption_failed' ) { data . additional . px_orig_cookie = ctx . getCookie ( ) ; //No need strigify, already a string } if ( ctx . s2sCallReason === 'cookie_expired' || ctx . s2sCallReason === 'cookie_validation_failed' ) { data . additional . px_cookie = JSON . stringify ( ctx . decodedCookie ) ; } pxUtil . prepareCustomParams ( config , data . additional ) ; const reqHeaders = { Authorization : 'Bearer ' + config . AUTH_TOKEN , 'Content-Type' : 'application/json' } ; if ( vid ) { data . vid = vid ; } if ( uuid ) { data . uuid = uuid ; } if ( pxhd ) { data . pxhd = pxhd ; } if ( vidSource ) { data . vid_source = vidSource ; } if ( pxhd && data . additional . s2s_call_reason === 'no_cookie' ) { data . additional . s2s_call_reason = 'no_cookie_w_vid' ; } if ( ctx . originalUuid ) { data . additional [ 'original_uuid' ] = ctx . originalUuid ; } if ( ctx . originalTokenError ) { data . additional [ 'original_token_error' ] = ctx . originalTokenError ; } if ( ctx . originalToken ) { data . additional [ 'original_token' ] = ctx . originalToken ; } if ( ctx . decodedOriginalToken ) { data . additional [ 'px_decoded_original_token' ] = ctx . decodedOriginalToken ; } if ( ctx . hmac ) { data . additional [ 'px_cookie_hmac' ] = ctx . hmac ; } ctx . hasMadeServerCall = true ; return pxHttpc . callServer ( data , reqHeaders , config . SERVER_TO_SERVER_API_URI , 'query' , config , callback ) ; }
callServer - call the perimeterx api server to receive a score for a given user.

@param {Object} ctx - current request context
@param {Function} callback - callback function.
callServer - call the perimeterx api server to receive a score for a given user .