UNPKG

@swrve/smarttv-sdk

Version:

Swrve marketing engagement platform SDK for SmartTV OTT devices

38 lines (37 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RealTimeUserPropertiesManager = void 0; const StorageManager_1 = require("../Storage/StorageManager"); const SwrveConstants_1 = require("../utils/SwrveConstants"); class RealTimeUserPropertiesManager { constructor(profileManager) { this._realTimeUserProperties = {}; this._profileManager = profileManager; this.loadStoredUserProperties(); } get UserProperties() { return this._realTimeUserProperties; } storeUserProperties(response, userId = this._profileManager.currentUser.userId) { if (response && response.real_time_user_properties) { this._realTimeUserProperties = response.real_time_user_properties; StorageManager_1.StorageManager.saveData(`${SwrveConstants_1.REAL_TIME_USER_PROPERTIES}${userId}`, JSON.stringify(this._realTimeUserProperties)); } } loadStoredUserProperties(userId = this._profileManager.currentUser.userId) { this._realTimeUserProperties = {}; const storedUserProperties = StorageManager_1.StorageManager.getData(`${SwrveConstants_1.REAL_TIME_USER_PROPERTIES}${userId}`); if (storedUserProperties) { this._realTimeUserProperties = JSON.parse(storedUserProperties); } } static processForPersonalization(rtups) { const result = {}; const keysList = Object.keys(rtups); for (const entry of keysList) { result["user." + entry] = rtups[entry]; } return result; } } exports.RealTimeUserPropertiesManager = RealTimeUserPropertiesManager;