<commit_before>// chrome.gorgias.io API plugin
var _GORGIAS_API_PLUGIN = function () {
    var apiBaseURL = Config.apiBaseURL;
    var baseURL = Config.baseURL;

    var TemplateStorage = {
        set: function(data, callback) {
            chrome.storage.local.set(data, callback);
        },
        get: function(k, callback) {
            chrome.storage.local.get(k, callback);
        },
        remove: function(k, callback) {
            chrome.storage.local.remove(k, callback);
        },
        clear: function(callback) {
            chrome.storage.local.clear(callback);
        }
    };

    // Settings
    var _localStorageSettings = {
        get: function(key, def, callback) {<commit_msg>Hotfix for #311: Return only templates from chrome storage. The legacy TemplateStorage helper returns all keys from chrome storage, not just templates. This caused the quick action dropdown in gmail to display undefined items. Previously we only stored templates in chrome storage. We now store more items. Filter and return only templates from TemplateStorage.get.<commit_after>// chrome.gorgias.io API plugin
var _GORGIAS_API_PLUGIN = function () {
    var apiBaseURL = Config.apiBaseURL;
    var baseURL = Config.baseURL;

    function isLegacyTemplate (key = '', template = {}) {
        return (
            // key is uuid
            key.length === 36 && key.split('-').length === 5 &&
            // template has body
            template.body &&
            // template has id
            template.id
        );
    }

    var TemplateStorage = {
        set: function(data, callback) {
            chrome.storage.local.set(data, callback);
        },
        get: function(k, callback) {
            chrome.storage.local.get(k, (data) => {
                // return only templates from storage
                var filteredData = {};
                Object.keys(data).forEach((key) => {
                    if (isLegacyTemplate(key, data[key])) {
                        filteredData[key] = data[key];
                    }
                });
                callback(filteredData);
            });
        },
        remove: function(k, callback) {
            chrome.storage.local.remove(k, callback);
        },
        clear: function(callback) {
            chrome.storage.local.clear(callback);
        }
    };

    // Settings
    var _localStorageSettings = {
        get: function(key, def, callback) {
{'fraction_non_alphanumeric': 0.10827501029230135, 'fraction_numerical': 0.002470152326060107, 'mean_word_length': 1.8859857482185274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1324195', 'n_tokens_mistral': 656, 'n_tokens_neox': 623, 'n_words': 167}