<commit_before>const rp = require('request-promise-native');

module.exports = async ({ baseUrl = "https://flow.manywho.com", username, password, tenantId, flowId, flowVersionId }) => {

    const token = await rp({
        method: "POST",
        uri: baseUrl + "/api/draw/1/authentication",
        body: {
            "loginUrl": baseUrl + "/plugins/manywho/api/draw/1/authentication",
            "username": username,
            "password": password
        },
        headers: {
            'ManyWhoTenant': 'da497693-4d02-45db-bc08-8ea16d2ccbdf'
        },
        json: true
    });

    const authToken = await rp({
        method: "GET",
        uri: baseUrl + "/api/draw/1/authentication/" + tenantId,
        headers: {
            'authorization': token,
        }
    });

    const authTokenClean = authToken.replace(/\"/g, '');

    const snapshot = await rp({
        method: "GET",
        uri: baseUrl + "/api/draw/1/flow/snap/" + flowId + "/" + flowVersionId,
        headers: {
            'authorization': authTokenClean,
            'ManyWhoTenant': tenantId
        }
    });

    return snapshot;
};<commit_msg>CORE-4432 - Added task in metadata generation that gets the latest default version if no version id is specified<commit_after>const rp = require('request-promise-native');

module.exports = async ({ baseUrl = "https://flow.manywho.com", username, password, tenantId, flowId, flowVersionId }) => {

    const token = await rp({
        method: "POST",
        uri: baseUrl + "/api/draw/1/authentication",
        body: {
            "loginUrl": baseUrl + "/plugins/manywho/api/draw/1/authentication",
            "username": username,
            "password": password
        },
        headers: {
            'ManyWhoTenant': 'da497693-4d02-45db-bc08-8ea16d2ccbdf'
        },
        json: true
    });

    const authToken = await rp({
        method: "GET",
        uri: baseUrl + "/api/draw/1/authentication/" + tenantId,
        headers: {
            'authorization': token,
        }
    });

    const authTokenClean = authToken.replace(/\"/g, '');

    if (!flowVersionId) {
        const snapshots = await rp({
            method: "GET",
            uri: baseUrl + "/api/draw/1/flow/snap/" + flowId,
            headers: {
                'authorization': authTokenClean,
                'ManyWhoTenant': tenantId
            },
            json: true
        });

        if (snapshots && snapshots.length > 0) {
            let snapshot = snapshots.find(item => item.isDefault);
            if (snapshot)
                flowVersionId = snapshot.id.versionId;
            else {
                console.error(`The flow ${flowId} has not been published, publish the flow then re-run this build`)
                return;
            }
        }
        else {
            console.error(`The flow ${flowId} has not been published, publish the flow then re-run this build`)
            return;
        }
    }

    const snapshot = await rp({
        method: "GET",
        uri: baseUrl + "/api/draw/1/flow/snap/" + flowId + "/" + flowVersionId,
        headers: {
            'authorization': authTokenClean,
            'ManyWhoTenant': tenantId
        }
    });

    return snapshot;
};
{'fraction_non_alphanumeric': 0.1326530612244898, 'fraction_numerical': 0.014842300556586271, 'mean_word_length': 1.8228621291448517, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '6144893', 'n_tokens_mistral': 960, 'n_tokens_neox': 923, 'n_words': 216}