<commit_before>"use strict";

const request = require("request-promise-native");
const authApiUrl = "http://localhost:60323/api/";

module.exports = exports = {
    validateEmail
};

// cross-checks a user email against the auth database
function validateEmail(email) {
    let username, urlStub, options;

    try {
        username = extractUsername(email);
    }
    catch (error) {
        return handleFailure(error);
    }

    urlStub = `HCM?userId=${username}`;
    options = _getRequestOptions(urlStub);

    return request.post(options).then((response) => {
        response = JSON.parse(response);

        return {
            username: response.username,
            instances: response.jira.map((instance) => {
                return instance.name;
            })
        };
    }).catch(handleFailure);

    function extractUsername(email) {
        let indexEnd = email.indexOf("@");

        if (indexEnd < 0) {
            throw new Error("Not a proper email address");
        }

        return email.substring(0, indexEnd);
    }

    function handleFailure(error) {
        let { statusCode } = error, message;

        if (!statusCode) {
            message = error.message;
        }
        else {
            message = "User not found";
        }

        return Promise.reject(message);
    }
}

// generates the options object for HTTP requests
function _getRequestOptions(urlStub, payload) {
    let url = `${authApiUrl}${urlStub}`;

    return {
        url,
        headers: {
            'Content-Type': 'application/json'
        },
        json: payload
    };
}<commit_msg>refactor auth module for consistency<commit_after>"use strict";

const request = require("request-promise-native");
const authApiUrl = "http://localhost:60323/api/";

module.exports = exports = {
    validateEmail
};

// cross-checks a user email against the auth database
function validateEmail(email) {
    let username, urlStub, options;

    try {
        username = extractUsername(email);
    }
    catch (error) {
        return _handleFailure(error);
    }

    urlStub = `HCM?userId=${username}`;
    options = _getRequestOptions(urlStub);

    return request.post(options).then((response) => {
        response = JSON.parse(response);

        return {
            username: response.username,
            instances: response.jira.map((instance) => {
                return instance.name;
            })
        };
    }).catch(_handleFailure);

    function extractUsername(email) {
        let indexEnd = email.indexOf("@");

        if (indexEnd < 0) {
            throw new Error("Not a proper email address");
        }

        return email.substring(0, indexEnd);
    }
}

// generates the options object for HTTP requests
function _getRequestOptions(urlStub, payload) {
    let url = `${authApiUrl}${urlStub}`;

    return {
        url,
        headers: {
            'Content-Type': 'application/json'
        },
        json: payload
    };
}

// handles failure of HTTP requests
function _handleFailure(error) {
    let { statusCode } = error, message;

    if (!statusCode) {
        message = error.message;
    }
    else {
        message = `Failed with ${statusCode}`;
    }

    return Promise.reject(message);
}
{'fraction_non_alphanumeric': 0.12041884816753927, 'fraction_numerical': 0.004311672312904219, 'mean_word_length': 2.2577733199598797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7437830', 'n_tokens_mistral': 906, 'n_tokens_neox': 892, 'n_words': 215}