<commit_before>const { toFlat } = require('../format');
const { encrypt, decrypt } = require('../crypto');

module.exports = (client, ui) => {
    const list = function* (project, env, config, all = false) {
        let url = config ?
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/${config}/history` :
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/history`;

        if (all) {
            url += '?all';
        }

        try {
            return yield client.get(url);
        } catch (error) {
            ui.printRequestError(error);
            ui.exit(1);
        }
    };

    const add = function* (project, env, content, { configName, tag, defaultFormat }) {
        // TODO: Send the default format to the API
        const body = toFlat(content);

        Object.keys(body).forEach((key) => {
            body[key] = encrypt(body[key].toString(), project.passphrase);
        });

        const url = `${project.origin}/projects/${project.id}/environments/${env}/configurations/${configName}/${tag}`;

        try {
            yield client.post(url, body);
        } catch (error) {
            ui.printRequestError(error);
            ui.exit(1);
        }
    };

    const get = function* (project, env, { configName, tag }) {
        const url = tag ?
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/${configName}/${tag}` :
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/${configName}`;

        let response;
        try {
            response = yield client.get(url);
        } catch (error) {
            ui.printRequestError(error);
            ui.exit(1);
        }

        const { body } = response;

        Object.keys(body).forEach((key) => {
            body[key] = decrypt(body[key].toString(), project.passphrase);
        });

        return { body };
    };

    return { list, add, get };
};<commit_msg>Use authorization on the client<commit_after>const { toFlat } = require('../format');
const { encrypt, decrypt } = require('../crypto');

module.exports = (client, ui) => {
    const list = function* (project, env, config, all = false) {
        let url = config ?
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/${config}/history` :
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/history`;

        if (all) {
            url += '?all';
        }

        try {
            return yield client.get(url, client.buildAuthorization(project));
        } catch (error) {
            ui.printRequestError(error);
            ui.exit(1);
        }
    };

    const add = function* (project, env, content, { configName, tag, defaultFormat }) {
        // TODO: Send the default format to the API
        const body = toFlat(content);

        Object.keys(body).forEach((key) => {
            body[key] = encrypt(body[key].toString(), project.passphrase);
        });

        const url = `${project.origin}/projects/${project.id}/environments/${env}/configurations/${configName}/${tag}`;

        try {
            yield client.post(url, body, client.buildAuthorization(project));
        } catch (error) {
            ui.printRequestError(error);
            ui.exit(1);
        }
    };

    const get = function* (project, env, { configName, tag }) {
        const url = tag ?
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/${configName}/${tag}` :
            `${project.origin}/projects/${project.id}/environments/${env}/configurations/${configName}`;

        let response;
        try {
            response = yield client.get(url, client.buildAuthorization(project));
        } catch (error) {
            ui.printRequestError(error);
            ui.exit(1);
        }

        const { body } = response;

        Object.keys(body).forEach((key) => {
            body[key] = decrypt(body[key].toString(), project.passphrase);
        });

        return { body };
    };

    return { list, add, get };
};
{'fraction_non_alphanumeric': 0.1658607350096712, 'fraction_numerical': 0.0014506769825918763, 'mean_word_length': 2.136467020470053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1969156', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1162, 'n_words': 217}