UNPKG

@shift-code/cli

Version:

Redeem Gearbox SHiFT codes automatically

70 lines 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.accountCacheExists = accountCacheExists; exports.loadAccountCache = loadAccountCache; exports.saveAccountCache = saveAccountCache; exports.saveAccountSession = saveAccountSession; exports.saveAccount = saveAccount; exports.clearAccountSession = clearAccountSession; exports.saveCodeCache = saveCodeCache; exports.appendCodeCache = appendCodeCache; exports.clearCodeCache = clearCodeCache; exports.removeCodeCache = removeCodeCache; const store_1 = require("../store"); async function accountCacheExists(accountID) { const exists = await (0, store_1.storeExists)(store_1.ACCOUNT_CACHE, accountID); return exists; } async function loadAccountCache(accountID) { const cache = await (0, store_1.loadContents)(store_1.ACCOUNT_CACHE, accountID, {}); return cache; } async function saveAccountCache(accountID, data) { await (0, store_1.storeContents)(store_1.ACCOUNT_CACHE, accountID, data); } async function saveAccountSession(accountID, session) { const cache = await loadAccountCache(accountID); await saveAccountCache(accountID, { ...cache, session }); } async function saveAccount(accountID, account) { const cache = await loadAccountCache(accountID); await saveAccountCache(accountID, { ...cache, account }); } async function clearAccountSession(accountID) { const cache = await loadAccountCache(accountID); delete cache?.session; await saveAccountCache(accountID, cache); } async function saveCodeCache(accountID, codes) { const cache = await loadAccountCache(accountID); await saveAccountCache(accountID, { ...cache, codes }); } async function appendCodeCache(accountID, code) { const cache = await loadAccountCache(accountID); if (!cache.codes) cache.codes = []; cache.codes.push(code); await saveAccountCache(accountID, cache); } async function clearCodeCache(accountID) { const cache = await loadAccountCache(accountID); delete cache?.codes; await saveAccountCache(accountID, cache); } async function removeCodeCache(accountID, code) { const cache = await loadAccountCache(accountID); if (!cache.codes) cache.codes = []; cache.codes = cache.codes.filter((c) => c !== code); await saveAccountCache(accountID, cache); } //# sourceMappingURL=account.js.map