sinch-rtc
Version:
RTC JavaScript/Web SDK
61 lines • 2.29 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureStorage = void 0;
const KeyValueStorage_1 = require("./KeyValueStorage");
const constants_1 = require("../constants");
class FeatureStorage extends KeyValueStorage_1.KeyValueStorage {
constructor(storage) {
super(storage, _a.FEATURE_PREFIX);
}
setApplicationConfig(userId, applicationKey) {
this.userId = userId;
this.applicationKey = applicationKey;
}
getFeatureFlag(featureFlag) {
const prefixedFeatureFlagKey = this.getPrefixedFeatureFlagKey(featureFlag);
return this.get(prefixedFeatureFlagKey);
}
setFeatureFlag(featureFlag, value) {
if (!this.isApplicationConfigSet()) {
console.error("Attempting to persist feature flags without user instance");
return;
}
this.set(this.getPrefixedFeatureFlagKey(featureFlag), value);
}
isEmpty() {
return Object.keys(constants_1.FeatureFlag).every((featureFlagKey) => {
const featureFlag = constants_1.FeatureFlag[featureFlagKey];
const featureFlagValue = this.getFeatureFlag(featureFlag);
return typeof featureFlagValue === "undefined";
});
}
removeAll() {
_a.STORAGE_KEYS.forEach((storageKey) => {
this.remove(this.getPrefixedFeatureFlagKey(storageKey));
});
}
get lastRefreshedAt() {
const lastRefreshedAt = this.get(_a.LAST_REFRESHED_AT);
return lastRefreshedAt ? lastRefreshedAt : 0;
}
set lastRefreshedAt(dateInMilliseconds) {
this.set(_a.LAST_REFRESHED_AT, dateInMilliseconds);
}
isApplicationConfigSet() {
return this.userId && this.applicationKey;
}
getPrefixedFeatureFlagKey(featureFlag) {
return `${this.applicationKey}:${this.userId}:${featureFlag}`;
}
}
exports.FeatureStorage = FeatureStorage;
_a = FeatureStorage;
FeatureStorage.FEATURE_PREFIX = "sinch:features:";
FeatureStorage.LAST_REFRESHED_AT = "LastRefreshedAt";
FeatureStorage.REFRESH_INTERVAL_MS = 3600 * 1000 * 48;
FeatureStorage.STORAGE_KEYS = [
...Object.entries(constants_1.FeatureFlag).map((entry) => entry[1]),
_a.LAST_REFRESHED_AT,
];
//# sourceMappingURL=FeatureStorage.js.map