/* eslint-disable @typescript-eslint/no-var-requires */ import { LocalStorage } from 'node-localstorage'; const os = require('os'); import SevenStorageName from '../enums/SevenStorageName'; import SevenNotification from '../enums/SevenNotification'; import { showNotification } from '../helpers/notificationHandler'; import SevenTenant from '../tenants/SevenTenant'; const localStorage = new LocalStorage(os.homedir() + '/seven-cli/storage/ls_tenant'); /** * Gets current tenant * @returns {SevenTenant | null} */ const getCurrentTenant = (): SevenTenant | null => { const tenant = localStorage.getItem(SevenStorageName.CURRENT_TENANT); return tenant ? JSON.parse(tenant) : null; }; /** * Removes current tenant from keytar */ const deleteCurrentTenant = (): void => { if (getCurrentTenant()) { localStorage.removeItem(SevenStorageName.CURRENT_TENANT); } }; /** * Saves current tenant * @param {SevenTenant} tenant */ const saveCurrentTenant = (tenant: SevenTenant | null): void => { localStorage.setItem(SevenStorageName.CURRENT_TENANT, JSON.stringify(tenant)); showNotification(SevenNotification.SUCCESS, `Selected tenant is ${tenant?.name}`); }; export { getCurrentTenant, saveCurrentTenant, deleteCurrentTenant };