@swrve/smarttv-sdk
Version:
Swrve marketing engagement platform SDK for SmartTV OTT devices
50 lines (49 loc) • 1.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageManager = void 0;
const PAL_1 = __importDefault(require("../utils/PAL"));
const md5_1 = require("../utils/md5");
const SwrveConstants_1 = require("../utils/SwrveConstants");
class StorageManager {
static saveData(key, data) {
this.getStorage().setItem(this.getKey(key), data);
}
static getData(key) {
return this.getStorage().getItem(this.getKey(key));
}
static clearData(key) {
this.getStorage().removeItem(this.getKey(key));
}
static saveDataWithMD5Hash(key, data) {
const store = this.getStorage();
return md5_1.md5Async(key + data)
.then(md5 => {
store.setItem(this.getKey(key), data);
store.setItem(this.getHashKey(key), md5);
});
}
static getDataWithMD5Hash(key) {
const store = this.getStorage();
const data = store.getItem(this.getKey(key));
const hash = store.getItem(this.getHashKey(key));
return md5_1.md5Async(key + data)
.then(rehash => hash === rehash ? data : null);
}
static getKey(key) {
return "swrve." + key;
}
static getHashKey(key) {
return "swrve." + key + ".hash";
}
static getStorage() {
const store = PAL_1.default.getPlatform().synchronousStorage;
if (!store) {
throw new Error(SwrveConstants_1.NO_SYNCHRONOUS_STORAGE);
}
return store;
}
}
exports.StorageManager = StorageManager;