<commit_before>import {Actions} from 'flummox';
import request from 'common/src/superagent';

class TokeninfoActions extends Actions {
    fetchTokenInfo(token) {
        return request
                    .get('/tokeninfo')
                    .query({
                        access_token: token
                    })
                    .accept('json')
                    .exec()
                    .then(res => [token, res.body]);
    }
}

export default TokeninfoActions;<commit_msg>#81 update token actions<commit_after>/* globals Date, Promise */
import {Actions} from 'flummox';
import request from 'common/src/superagent';
import {Provider} from 'common/src/oauth-provider';

class TokeninfoActions extends Actions {
    fetchTokenInfo() {
        let token = Provider.getAccessToken();
        if (!token) {
            return Promise.reject();
        }
        return request
                    .get('/tokeninfo')
                    .query({
                        access_token: token
                    })
                    .accept('json')
                    .exec()
                    .then(res => [token, res.body]);
                    .then(res => {
                        let body = res.body;
                        body.valid_until = Date.now() + parseInt(res.body.expires_in, 10) * 1000;
                        return body;
                    })
                    .catch(err => {
                        if (err.status === 400) {
                            // access token is no longer valid
                            this.deleteTokenInfo();
                            throw err;
                        }
                    });
    }

    deleteTokenInfo() {
        Provider.deleteTokens();
        return true;
    }
}

export default TokeninfoActions;
{'fraction_non_alphanumeric': 0.10239287701725097, 'fraction_numerical': 0.006121313299944352, 'mean_word_length': 1.1481481481481481, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6717332', 'n_tokens_mistral': 447, 'n_tokens_neox': 409, 'n_words': 99}