UNPKG

@sky-mavis/tanto-connect

Version:
42 lines (39 loc) 1.39 kB
'use strict'; const STORAGE_PREFIX = 'tanto'; const LocalStorage = { isAccessible: () => typeof localStorage !== 'undefined', set: (key, data) => { if (!LocalStorage.isAccessible()) { return false; } localStorage.setItem(key, JSON.stringify(data)); return true; }, get: (key) => { if (!LocalStorage.isAccessible()) { return undefined; } const data = localStorage.getItem(key); if (data) { return JSON.parse(data); } return undefined; }, remove: (key) => { if (!LocalStorage.isAccessible()) { return false; } localStorage.removeItem(key); return true; }, }; const ReconnectStorage = { get: (connectorId) => LocalStorage.get(`${STORAGE_PREFIX}.RECONNECT.${connectorId}`) ?? false, add: (connectorId) => LocalStorage.set(`${STORAGE_PREFIX}.RECONNECT.${connectorId}`, true), remove: (connectorId) => LocalStorage.remove(`${STORAGE_PREFIX}.RECONNECT.${connectorId}`), }; const WAYPOINT_ACCESS_TOKEN_STORAGE_KEY = `${STORAGE_PREFIX}.WAYPOINT.ACCESS_TOKEN`; exports.LocalStorage = LocalStorage; exports.ReconnectStorage = ReconnectStorage; exports.STORAGE_PREFIX = STORAGE_PREFIX; exports.WAYPOINT_ACCESS_TOKEN_STORAGE_KEY = WAYPOINT_ACCESS_TOKEN_STORAGE_KEY;