lib/pxapi.js
function evalByServerCall(ctx, config, callback) {
    if (!ctx.ip || !ctx.headers) {
        config.logger.error('perimeterx score evaluation failed. bad parameters.');
        return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
    }
    config.logger.debug(`Evaluating Risk API request, call reason: ${ctx.s2sCallReason}`);
    callServer(ctx, config, (err, res) => {
        if (err) {
            if (err === 'timeout') {
                ctx.passReason = config.PASS_REASON.S2S_TIMEOUT;
                return callback(config.SCORE_EVALUATE_ACTION.S2S_TIMEOUT_PASS);
            }
            config.logger.error(`Unexpected exception while evaluating Risk API. ${err}`);
            ctx.passReason = config.PASS_REASON.REQUEST_FAILED;
            return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
        }
        ctx.pxhd = res.pxhd;
        const action = isBadRiskScore(res, ctx, config);
        /* score response invalid - pass traffic */
        if (action === -1) {
            config.logger.error('perimeterx server query response is invalid');
            return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
        }

        /* score did not cross threshold - pass traffic */
        if (action === 1) {
            return callback(config.SCORE_EVALUATE_ACTION.GOOD_SCORE);
        }

        /* score crossed threshold - block traffic */
        if (action === 0) {
            ctx.uuid = res.uuid || '';
            return callback(config.SCORE_EVALUATE_ACTION.BAD_SCORE);
        }

        /* This shouldn't be called - if it did - we pass the traffic */
        return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
    });
}
function evalByServerCall(ctx, config, callback) {
    if (!ctx.ip || !ctx.headers) {
        config.logger.error('perimeterx score evaluation failed. bad parameters.');
        return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
    }
    config.logger.debug(`Evaluating Risk API request, call reason: ${ctx.s2sCallReason}`);
    callServer(ctx, config, (err, res) => {
        if (err) {
            if (err === 'timeout') {
                ctx.passReason = config.PASS_REASON.S2S_TIMEOUT;
                return callback(config.SCORE_EVALUATE_ACTION.S2S_TIMEOUT_PASS);
            }
            config.logger.error(`Unexpected exception while evaluating Risk API. ${err}`);
            ctx.passReason = config.PASS_REASON.REQUEST_FAILED;
            return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
        }
        ctx.pxhd = res.pxhd;
        const action = isBadRiskScore(res, ctx, config);
        /* score response invalid - pass traffic */
        if (action === -1) {
            config.logger.error('perimeterx server query response is invalid');
            return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
        }

        /* score did not cross threshold - pass traffic */
        if (action === 1) {
            return callback(config.SCORE_EVALUATE_ACTION.GOOD_SCORE);
        }

        /* score crossed threshold - block traffic */
        if (action === 0) {
            ctx.uuid = res.uuid || '';
            return callback(config.SCORE_EVALUATE_ACTION.BAD_SCORE);
        }

        /* This shouldn't be called - if it did - we pass the traffic */
        return callback(config.SCORE_EVALUATE_ACTION.UNEXPECTED_RESULT);
    });
}
function evalByServerCall ( ctx , config , callback ) { if ( ! ctx . ip || ! ctx . headers ) { config . logger . error ( 'perimeterx score evaluation failed. bad parameters.' ) ; return callback ( config . SCORE_EVALUATE_ACTION . UNEXPECTED_RESULT ) ; } config . logger . debug ( ` ${ ctx . s2sCallReason } ` ) ; callServer ( ctx , config , ( err , res ) => { if ( err ) { if ( err === 'timeout' ) { ctx . passReason = config . PASS_REASON . S2S_TIMEOUT ; return callback ( config . SCORE_EVALUATE_ACTION . S2S_TIMEOUT_PASS ) ; } config . logger . error ( ` ${ err } ` ) ; ctx . passReason = config . PASS_REASON . REQUEST_FAILED ; return callback ( config . SCORE_EVALUATE_ACTION . UNEXPECTED_RESULT ) ; } ctx . pxhd = res . pxhd ; const action = isBadRiskScore ( res , ctx , config ) ; /* score response invalid - pass traffic */ if ( action === - 1 ) { config . logger . error ( 'perimeterx server query response is invalid' ) ; return callback ( config . SCORE_EVALUATE_ACTION . UNEXPECTED_RESULT ) ; } /* score did not cross threshold - pass traffic */ if ( action === 1 ) { return callback ( config . SCORE_EVALUATE_ACTION . GOOD_SCORE ) ; } /* score crossed threshold - block traffic */ if ( action === 0 ) { ctx . uuid = res . uuid || '' ; return callback ( config . SCORE_EVALUATE_ACTION . BAD_SCORE ) ; } /* This shouldn't be called - if it did - we pass the traffic */ return callback ( config . SCORE_EVALUATE_ACTION . UNEXPECTED_RESULT ) ; } ) ; }
evalByServerCall - main server to server function, execute a server call for score and process its value to make blocking decisions.
'
@param {Object} ctx - current request context.
@param {Function} callback - callback function.
evalByServerCall - main server to server function execute a server call for score and process its value to make blocking decisions .