Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ironsource/core-ui-services

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ironsource/core-ui-services - npm Package Compare versions

Comparing version 0.0.2-rc.4 to 0.0.2-rc.6

2

index.d.ts

@@ -1,3 +0,3 @@

export { CacheType, CacheService } from './services/cache';
export { CacheType, CoreCacheService } from './services/cache';
export { CoreConfigurationsService } from './services/configuration';
export { CoreFeatureFlagService } from './services/feature-flag';

@@ -1,4 +0,4 @@

export { CacheType, CacheService } from './services/cache';
export { CacheType, CoreCacheService } from './services/cache';
export { CoreConfigurationsService } from './services/configuration';
export { CoreFeatureFlagService } from './services/feature-flag';
//# sourceMappingURL=index.js.map
{
"name": "@ironsource/core-ui-services",
"version": "0.0.2-rc.4",
"version": "0.0.2-rc.6",
"description": "Plain TypeScript services for using in multi-framed core-platform front-end apps",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,3 +0,3 @@

# core-platform-ui-services
# core-ui-services
Plain TypeScript services for using in multi-framed core-platform front-end apps.
import { CacheType } from './cache-entities';
export declare class CacheService {
export declare class CoreCacheService {
#private;
private static instance;
static getInstance(): CoreCacheService;
cacheObject: any;
private persistentKeyPrefix;
get(cacheType: CacheType, keyName: string): string;

@@ -16,5 +18,2 @@ set(cacheType: CacheType, keyName: string, data: any): void;

clearCacheForPartialKey(cacheType: CacheType, partialKey: string): void;
private clearLocalStorage;
private b64EncodeUnicode;
private b64DecodeUnicode;
}

@@ -0,4 +1,12 @@

var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _CoreCacheService_instances, _CoreCacheService_persistentKeyPrefix, _CoreCacheService_clearLocalStorage, _CoreCacheService_b64EncodeUnicode, _CoreCacheService_b64DecodeUnicode;
import { CacheType } from './cache-entities';
export class CacheService {
export class CoreCacheService {
constructor() {
_CoreCacheService_instances.add(this);
// endregion
Object.defineProperty(this, "cacheObject", {

@@ -10,9 +18,10 @@ enumerable: true,

});
Object.defineProperty(this, "persistentKeyPrefix", {
enumerable: true,
configurable: true,
writable: true,
value: 'persistent_'
});
_CoreCacheService_persistentKeyPrefix.set(this, 'persistent_');
}
static getInstance() {
if (!CoreCacheService.instance) {
CoreCacheService.instance = new CoreCacheService();
}
return CoreCacheService.instance;
}
get(cacheType, keyName) {

@@ -29,3 +38,3 @@ let data = null;

if (rawLSData) {
data = JSON.parse(this.b64DecodeUnicode(rawLSData));
data = JSON.parse(__classPrivateFieldGet(this, _CoreCacheService_instances, "m", _CoreCacheService_b64DecodeUnicode).call(this, rawLSData));
}

@@ -36,3 +45,3 @@ break;

if (rawSSData) {
data = JSON.parse(this.b64DecodeUnicode(rawSSData));
data = JSON.parse(__classPrivateFieldGet(this, _CoreCacheService_instances, "m", _CoreCacheService_b64DecodeUnicode).call(this, rawSSData));
}

@@ -49,6 +58,6 @@ break;

case CacheType.LocalStorage:
window.localStorage.setItem(keyName, this.b64EncodeUnicode(JSON.stringify(data)));
window.localStorage.setItem(keyName, __classPrivateFieldGet(this, _CoreCacheService_instances, "m", _CoreCacheService_b64EncodeUnicode).call(this, JSON.stringify(data)));
break;
case CacheType.SessionStorage:
window.sessionStorage.setItem(keyName, this.b64EncodeUnicode(JSON.stringify(data)));
window.sessionStorage.setItem(keyName, __classPrivateFieldGet(this, _CoreCacheService_instances, "m", _CoreCacheService_b64EncodeUnicode).call(this, JSON.stringify(data)));
break;

@@ -78,3 +87,3 @@ }

this.cacheObject = {};
this.clearLocalStorage();
__classPrivateFieldGet(this, _CoreCacheService_instances, "m", _CoreCacheService_clearLocalStorage).call(this);
sessionStorage.clear();

@@ -104,28 +113,26 @@ }

}
clearLocalStorage() {
const keys = Object.keys(localStorage);
const persistentItems = [];
// save persistent values
keys.forEach((key) => {
if (key.startsWith(this.persistentKeyPrefix)) {
persistentItems.push({ key, value: localStorage.getItem(key) });
}
});
// clear cache
localStorage.clear();
// restore persistent values
persistentItems.forEach((item) => {
localStorage.setItem(item.key, item.value);
});
}
b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(Number('0x' + p1))));
}
b64DecodeUnicode(str) {
return decodeURIComponent(atob(str)
.split('')
.map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
.join(''));
}
}
_CoreCacheService_persistentKeyPrefix = new WeakMap(), _CoreCacheService_instances = new WeakSet(), _CoreCacheService_clearLocalStorage = function _CoreCacheService_clearLocalStorage() {
const keys = Object.keys(localStorage);
const persistentItems = [];
// save persistent values
keys.forEach((key) => {
if (key.startsWith(__classPrivateFieldGet(this, _CoreCacheService_persistentKeyPrefix, "f"))) {
persistentItems.push({ key, value: localStorage.getItem(key) });
}
});
// clear cache
localStorage.clear();
// restore persistent values
persistentItems.forEach((item) => {
localStorage.setItem(item.key, item.value);
});
}, _CoreCacheService_b64EncodeUnicode = function _CoreCacheService_b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(Number('0x' + p1))));
}, _CoreCacheService_b64DecodeUnicode = function _CoreCacheService_b64DecodeUnicode(str) {
return decodeURIComponent(atob(str)
.split('')
.map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
.join(''));
};
//# sourceMappingURL=cache.service.js.map
export declare class CoreConfigurationsService {
#private;
private static instance;
static getInstance(): CoreConfigurationsService;
config: {
[key: string]: any;
};
private cached;
private storageConfigurationKey;
private configurationApiCallBack;
private configurationVersion;
private cacheService;
private static instance;
static getInstance(): CoreConfigurationsService;
private featureFlagService;
initConfiguration(configurationApiCallBack: any): Promise<boolean>;
private shouldRefreshCache;
private getConfigurationFromCache;
private setConfigurations;
private getConfigFromAPI;
private handleConfigResponse;
}

@@ -1,2 +0,14 @@

import { CacheService, CacheType } from '../cache';
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _CoreConfigurationsService_instances, _CoreConfigurationsService_cached, _CoreConfigurationsService_storageConfigurationKey, _CoreConfigurationsService_configurationApiCallBack, _CoreConfigurationsService_configurationVersion, _CoreConfigurationsService_featureFlagService, _CoreConfigurationsService_cacheService, _CoreConfigurationsService_shouldRefreshCache, _CoreConfigurationsService_getConfigurationFromCache, _CoreConfigurationsService_setConfigurations, _CoreConfigurationsService_getConfigFromAPI, _CoreConfigurationsService_handleConfigResponse;
import { CoreCacheService, CacheType } from '../cache';
import { CoreFeatureFlagService } from '../feature-flag';

@@ -7,2 +19,4 @@ const STORAGE_DEFAULT_KEY = 'persistent_core_configurations';

constructor() {
_CoreConfigurationsService_instances.add(this);
// endregion
Object.defineProperty(this, "config", {

@@ -14,39 +28,8 @@ enumerable: true,

});
Object.defineProperty(this, "cached", {
enumerable: true,
configurable: true,
writable: true,
value: {}
});
Object.defineProperty(this, "storageConfigurationKey", {
enumerable: true,
configurable: true,
writable: true,
value: STORAGE_DEFAULT_KEY
});
Object.defineProperty(this, "configurationApiCallBack", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "configurationVersion", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
Object.defineProperty(this, "cacheService", {
enumerable: true,
configurable: true,
writable: true,
value: new CacheService()
});
// endregion
Object.defineProperty(this, "featureFlagService", {
enumerable: true,
configurable: true,
writable: true,
value: CoreFeatureFlagService.getInstance()
});
_CoreConfigurationsService_cached.set(this, {});
_CoreConfigurationsService_storageConfigurationKey.set(this, STORAGE_DEFAULT_KEY);
_CoreConfigurationsService_configurationApiCallBack.set(this, void 0);
_CoreConfigurationsService_configurationVersion.set(this, 0);
_CoreConfigurationsService_featureFlagService.set(this, CoreFeatureFlagService.getInstance());
_CoreConfigurationsService_cacheService.set(this, CoreCacheService.getInstance());
}

@@ -60,39 +43,34 @@ static getInstance() {

initConfiguration(configurationApiCallBack) {
this.configurationApiCallBack = configurationApiCallBack;
this.configurationVersion = this.featureFlagService.getFlag(FLAG_DEFAULT_KEY, 0);
// this.configurationVersion++;
if (!this.configurationApiCallBack) {
__classPrivateFieldSet(this, _CoreConfigurationsService_configurationApiCallBack, configurationApiCallBack, "f");
__classPrivateFieldSet(this, _CoreConfigurationsService_configurationVersion, __classPrivateFieldGet(this, _CoreConfigurationsService_featureFlagService, "f").getFlag(FLAG_DEFAULT_KEY, 0), "f");
if (!__classPrivateFieldGet(this, _CoreConfigurationsService_configurationApiCallBack, "f")) {
return Promise.reject(new Error('Configuration API callback method is required'));
}
const shouldRefreshCache = this.shouldRefreshCache(this.configurationVersion);
return this.setConfigurations(shouldRefreshCache);
const shouldRefreshCache = __classPrivateFieldGet(this, _CoreConfigurationsService_instances, "m", _CoreConfigurationsService_shouldRefreshCache).call(this, __classPrivateFieldGet(this, _CoreConfigurationsService_configurationVersion, "f"));
return __classPrivateFieldGet(this, _CoreConfigurationsService_instances, "m", _CoreConfigurationsService_setConfigurations).call(this, shouldRefreshCache);
}
shouldRefreshCache(version) {
const cachedConfiguration = this.getConfigurationFromCache();
if (!cachedConfiguration || !version) {
return true;
}
return !(cachedConfiguration['version'] && cachedConfiguration['version'] >= version);
}
_CoreConfigurationsService_cached = new WeakMap(), _CoreConfigurationsService_storageConfigurationKey = new WeakMap(), _CoreConfigurationsService_configurationApiCallBack = new WeakMap(), _CoreConfigurationsService_configurationVersion = new WeakMap(), _CoreConfigurationsService_featureFlagService = new WeakMap(), _CoreConfigurationsService_cacheService = new WeakMap(), _CoreConfigurationsService_instances = new WeakSet(), _CoreConfigurationsService_shouldRefreshCache = function _CoreConfigurationsService_shouldRefreshCache(version) {
const cachedConfiguration = __classPrivateFieldGet(this, _CoreConfigurationsService_instances, "m", _CoreConfigurationsService_getConfigurationFromCache).call(this);
if (!cachedConfiguration || !version) {
return true;
}
getConfigurationFromCache() {
const key = this.storageConfigurationKey;
if (!this.cached[key]) {
this.cached[key] = this.cacheService.get(CacheType.LocalStorage, key);
}
return this.cached[key];
return !(cachedConfiguration['version'] && cachedConfiguration['version'] >= version);
}, _CoreConfigurationsService_getConfigurationFromCache = function _CoreConfigurationsService_getConfigurationFromCache() {
const key = __classPrivateFieldGet(this, _CoreConfigurationsService_storageConfigurationKey, "f");
if (!__classPrivateFieldGet(this, _CoreConfigurationsService_cached, "f")[key]) {
__classPrivateFieldGet(this, _CoreConfigurationsService_cached, "f")[key] = __classPrivateFieldGet(this, _CoreConfigurationsService_cacheService, "f").get(CacheType.LocalStorage, key);
}
setConfigurations(shouldRefreshCache) {
return (shouldRefreshCache ? this.getConfigFromAPI() : Promise.resolve(this.getConfigurationFromCache()))
.then(this.handleConfigResponse.bind(this))
.then(() => true);
}
getConfigFromAPI() {
return this.configurationApiCallBack();
}
handleConfigResponse(config) {
this.config = { ...config };
this.cacheService.set(CacheType.LocalStorage, this.storageConfigurationKey, config);
delete this.cached[this.storageConfigurationKey];
}
}
return __classPrivateFieldGet(this, _CoreConfigurationsService_cached, "f")[key];
}, _CoreConfigurationsService_setConfigurations = function _CoreConfigurationsService_setConfigurations(shouldRefreshCache) {
return (shouldRefreshCache ? __classPrivateFieldGet(this, _CoreConfigurationsService_instances, "m", _CoreConfigurationsService_getConfigFromAPI).call(this) : Promise.resolve(__classPrivateFieldGet(this, _CoreConfigurationsService_instances, "m", _CoreConfigurationsService_getConfigurationFromCache).call(this)))
.then(__classPrivateFieldGet(this, _CoreConfigurationsService_instances, "m", _CoreConfigurationsService_handleConfigResponse).bind(this))
.then(() => true);
}, _CoreConfigurationsService_getConfigFromAPI = function _CoreConfigurationsService_getConfigFromAPI() {
return __classPrivateFieldGet(this, _CoreConfigurationsService_configurationApiCallBack, "f").call(this);
}, _CoreConfigurationsService_handleConfigResponse = function _CoreConfigurationsService_handleConfigResponse(config) {
this.config = { ...config };
__classPrivateFieldGet(this, _CoreConfigurationsService_cacheService, "f").set(CacheType.LocalStorage, __classPrivateFieldGet(this, _CoreConfigurationsService_storageConfigurationKey, "f"), config);
delete __classPrivateFieldGet(this, _CoreConfigurationsService_cached, "f")[__classPrivateFieldGet(this, _CoreConfigurationsService_storageConfigurationKey, "f")];
};
//# sourceMappingURL=configuration.service.js.map
export declare class CoreFeatureFlagService {
#private;
private static instance;
static getInstance(): CoreFeatureFlagService;
private flags;
setFlags(flags: {
[key: string]: any;
[key: string]: {
value: boolean | string | number;
};
}): void;
getFlag(key: string, defaultValue?: boolean | string | number): boolean | string | number;
}

@@ -0,9 +1,17 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _CoreFeatureFlagService_flags;
export class CoreFeatureFlagService {
constructor() {
Object.defineProperty(this, "flags", {
enumerable: true,
configurable: true,
writable: true,
value: {}
});
// endregion
_CoreFeatureFlagService_flags.set(this, {});
}

@@ -18,12 +26,13 @@ static getInstance() {

if (flags && Object.keys(flags).length) {
this.flags = Object.keys(flags).reduce((acc, curr) => {
__classPrivateFieldSet(this, _CoreFeatureFlagService_flags, Object.keys(flags).reduce((acc, curr) => {
acc[curr] = flags[curr].value;
return acc;
}, {});
}, {}), "f");
}
}
getFlag(key, defaultValue = false) {
return this.flags[key] || defaultValue;
return __classPrivateFieldGet(this, _CoreFeatureFlagService_flags, "f")[key] || defaultValue;
}
}
_CoreFeatureFlagService_flags = new WeakMap();
//# sourceMappingURL=feature-flag.service.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc