Socket
Socket
Sign inDemoInstall

configcat-common

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configcat-common - npm Package Compare versions

Comparing version 3.0.2 to 4.0.0

4

lib/AutoPollConfigService.js

@@ -68,3 +68,3 @@ "use strict";

AutoPollConfigService.prototype.getConfig = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
if (!p) {

@@ -87,3 +87,3 @@ return this.refreshLogic();

case 0:
p = this.cache.Get(this.baseConfig.apiKey);
p = this.cache.get(this.baseConfig.getCacheKey());
return [4 /*yield*/, this.refreshLogicBaseAsync(p)];

@@ -90,0 +90,0 @@ case 1:

@@ -7,5 +7,5 @@ import { ProjectConfig } from "./ProjectConfig";

};
Set(apiKey: string, config: ProjectConfig): void;
Get(apiKey: string): ProjectConfig;
set(key: string, config: ProjectConfig): void;
get(key: string): ProjectConfig;
}
//# sourceMappingURL=Cache.d.ts.map

@@ -8,7 +8,7 @@ "use strict";

}
InMemoryCache.prototype.Set = function (apiKey, config) {
this.cache[apiKey] = config;
InMemoryCache.prototype.set = function (key, config) {
this.cache[key] = config;
};
InMemoryCache.prototype.Get = function (apiKey) {
return this.cache[apiKey];
InMemoryCache.prototype.get = function (key) {
return this.cache[key];
};

@@ -15,0 +15,0 @@ return InMemoryCache;

@@ -68,3 +68,3 @@ "use strict";

AutoPollConfigService.prototype.getConfig = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
if (!p) {

@@ -87,3 +87,3 @@ return this.refreshLogic();

case 0:
p = this.cache.Get(this.baseConfig.apiKey);
p = this.cache.get(this.baseConfig.getCacheKey());
return [4 /*yield*/, this.refreshLogicBaseAsync(p)];

@@ -90,0 +90,0 @@ case 1:

@@ -7,5 +7,5 @@ import { ProjectConfig } from "./ProjectConfig";

};
Set(apiKey: string, config: ProjectConfig): void;
Get(apiKey: string): ProjectConfig;
set(key: string, config: ProjectConfig): void;
get(key: string): ProjectConfig;
}
//# sourceMappingURL=Cache.d.ts.map

@@ -8,7 +8,7 @@ "use strict";

}
InMemoryCache.prototype.Set = function (apiKey, config) {
this.cache[apiKey] = config;
InMemoryCache.prototype.set = function (key, config) {
this.cache[key] = config;
};
InMemoryCache.prototype.Get = function (apiKey) {
return this.cache[apiKey];
InMemoryCache.prototype.get = function (key) {
return this.cache[key];
};

@@ -15,0 +15,0 @@ return InMemoryCache;

@@ -131,3 +131,3 @@ "use strict";

config = _a.sent();
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
this.options.logger.error("JSONConfig is not present, returning empty array");

@@ -137,3 +137,3 @@ resolve([]);

}
resolve(Object.keys(config.ConfigJSON));
resolve(Object.keys(config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]));
return [2 /*return*/];

@@ -203,3 +203,3 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
var config, featureFlags, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
return __generator(this, function (_a) {

@@ -210,3 +210,3 @@ switch (_a.label) {

config = _a.sent();
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
this.options.logger.error("JSONConfig is not present, returning null");

@@ -216,8 +216,9 @@ resolve(null);

}
for (settingKey in config.ConfigJSON) {
if (variationId === config.ConfigJSON[settingKey][ProjectConfig_1.Setting.VariationId]) {
resolve({ settingKey: settingKey, settingValue: config.ConfigJSON[settingKey][ProjectConfig_1.Setting.Value] });
featureFlags = config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags];
for (settingKey in featureFlags) {
if (variationId === featureFlags[settingKey][ProjectConfig_1.Setting.VariationId]) {
resolve({ settingKey: settingKey, settingValue: featureFlags[settingKey][ProjectConfig_1.Setting.Value] });
return [2 /*return*/];
}
rolloutRules = config.ConfigJSON[settingKey][ProjectConfig_1.Setting.RolloutRules];
rolloutRules = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutRules];
if (rolloutRules && rolloutRules.length > 0) {

@@ -232,3 +233,3 @@ for (i = 0; i < rolloutRules.length; i++) {

}
percentageItems = config.ConfigJSON[settingKey][ProjectConfig_1.Setting.RolloutPercentageItems];
percentageItems = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutPercentageItems];
if (percentageItems && percentageItems.length > 0) {

@@ -235,0 +236,0 @@ for (i = 0; i < percentageItems.length; i++) {

import { IConfigCatLogger, IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions } from "./index";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
export declare enum DataGovernance {
/** Select this if your feature flags are published to all global CDN nodes. */
Global = 0,
/** Select this if your feature flags are published to CDN nodes only in the EU. */
EuOnly = 1
}
export interface IOptions {

@@ -6,5 +13,10 @@ logger?: IConfigCatLogger;

baseUrl?: string;
/** You can set a base_url if you want to use a proxy server between your application and ConfigCat */
proxy?: string;
/** Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
* https://app.configcat.com/organization/data-governance (Only Organization Admins have access) */
dataGovernance?: DataGovernance;
}
export declare abstract class OptionsBase implements IOptions {
private configFileName;
logger: IConfigCatLogger;

@@ -15,8 +27,13 @@ apiKey: string;

baseUrl: string;
baseUrlOverriden: boolean;
proxy: string;
dataGovernance: DataGovernance;
constructor(apiKey: string, clientVersion: string, options: IOptions);
getUrl(): string;
getCacheKey(): string;
}
export declare class AutoPollOptions extends OptionsBase implements IAutoPollOptions {
/** The client's poll interval in seconds. Default: 60 seconds. */
pollIntervalSeconds: number;
/** You can subscribe to configuration changes with this callback */
configChanged: () => void;

@@ -29,2 +46,3 @@ constructor(apiKey: string, options: IAutoPollOptions);

export declare class LazyLoadOptions extends OptionsBase implements ILazyLoadingOptions {
/** The cache TTL. */
cacheTimeToLiveSeconds: number;

@@ -31,0 +49,0 @@ constructor(apiKey: string, options: ILazyLoadingOptions);

@@ -16,11 +16,21 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyLoadOptions = exports.ManualPollOptions = exports.AutoPollOptions = exports.OptionsBase = void 0;
exports.LazyLoadOptions = exports.ManualPollOptions = exports.AutoPollOptions = exports.OptionsBase = exports.DataGovernance = void 0;
var ConfigCatLogger_1 = require("./ConfigCatLogger");
var index_1 = require("./index");
var Version_1 = require("./Version");
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
var DataGovernance;
(function (DataGovernance) {
/** Select this if your feature flags are published to all global CDN nodes. */
DataGovernance[DataGovernance["Global"] = 0] = "Global";
/** Select this if your feature flags are published to CDN nodes only in the EU. */
DataGovernance[DataGovernance["EuOnly"] = 1] = "EuOnly";
})(DataGovernance = exports.DataGovernance || (exports.DataGovernance = {}));
var OptionsBase = /** @class */ (function () {
function OptionsBase(apiKey, clientVersion, options) {
var _a;
this.configFileName = "config_v5";
this.logger = new ConfigCatLogger_1.ConfigCatConsoleLogger(index_1.LogLevel.Warn);
this.requestTimeoutMs = 30000;
this.baseUrl = "https://cdn.configcat.com";
this.baseUrlOverriden = false;
this.proxy = "";

@@ -32,2 +42,11 @@ if (!apiKey) {

this.clientVersion = clientVersion;
this.dataGovernance = (_a = options === null || options === void 0 ? void 0 : options.dataGovernance) !== null && _a !== void 0 ? _a : DataGovernance.Global;
switch (this.dataGovernance) {
case DataGovernance.EuOnly:
this.baseUrl = "https://cdn-eu.configcat.com";
break;
default:
this.baseUrl = "https://cdn-global.configcat.com";
break;
}
if (options) {

@@ -45,2 +64,3 @@ if (options.logger) {

this.baseUrl = options.baseUrl;
this.baseUrlOverriden = true;
}

@@ -53,4 +73,7 @@ if (options.proxy) {

OptionsBase.prototype.getUrl = function () {
return this.baseUrl + "/configuration-files/" + this.apiKey + "/config_v4.json";
return this.baseUrl + "/configuration-files/" + this.apiKey + "/" + this.configFileName + ".json";
};
OptionsBase.prototype.getCacheKey = function () {
return "js_" + this.configFileName + "_" + this.apiKey;
};
return OptionsBase;

@@ -63,3 +86,5 @@ }());

var _this = _super.call(this, apiKey, "a-" + Version_1.default, options) || this;
/** The client's poll interval in seconds. Default: 60 seconds. */
_this.pollIntervalSeconds = 60;
/** You can subscribe to configuration changes with this callback */
_this.configChanged = function () { };

@@ -94,2 +119,3 @@ if (options) {

var _this = _super.call(this, apiKey, "l-" + Version_1.default, options) || this;
/** The cache TTL. */
_this.cacheTimeToLiveSeconds = 60;

@@ -96,0 +122,0 @@ if (options) {

@@ -14,3 +14,4 @@ import { IConfigFetcher, ICache } from "./index";

protected refreshLogicBaseAsync(lastProjectConfig: ProjectConfig): Promise<ProjectConfig>;
private fetchLogic;
}
//# sourceMappingURL=ConfigServiceBase.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigServiceBase = void 0;
var ProjectConfig_1 = require("./ProjectConfig");
var ConfigServiceBase = /** @class */ (function () {

@@ -13,5 +14,5 @@ function ConfigServiceBase(configFetcher, cache, baseConfig) {

return new Promise(function (resolve) {
_this.configFetcher.fetchLogic(_this.baseConfig, lastProjectConfig, function (newConfig) {
if (newConfig) {
_this.cache.Set(_this.baseConfig.apiKey, newConfig);
_this.fetchLogic(_this.baseConfig, lastProjectConfig, 0, function (newConfig) {
if (newConfig && newConfig.ConfigJSON) {
_this.cache.set(_this.baseConfig.getCacheKey(), newConfig);
resolve(newConfig);

@@ -25,4 +26,49 @@ }

};
ConfigServiceBase.prototype.fetchLogic = function (options, lastProjectConfig, retries, callback) {
var _this = this;
this.configFetcher.fetchLogic(this.baseConfig, lastProjectConfig, function (newConfig) {
if (!newConfig || !newConfig.ConfigJSON) {
callback(null);
return;
}
var preferences = newConfig.ConfigJSON[ProjectConfig_1.ConfigFile.Preferences];
if (!preferences) {
callback(newConfig);
return;
}
var baseUrl = preferences[ProjectConfig_1.Preferences.BaseUrl];
// If the base_url is the same as the last called one, just return the response.
if (!baseUrl || baseUrl == options.baseUrl) {
callback(newConfig);
return;
}
var redirect = preferences[ProjectConfig_1.Preferences.Redirect];
// If the base_url is overridden, and the redirect parameter is not 2 (force),
// the SDK should not redirect the calls and it just have to return the response.
if (options.baseUrlOverriden && redirect !== 2) {
callback(newConfig);
return;
}
options.baseUrl = baseUrl;
if (redirect === 0) {
callback(newConfig);
return;
}
if (redirect === 1) {
options.logger.warn("Your dataGovernance parameter at ConfigCatClient initialization is not in sync " +
"with your preferences on the ConfigCat Dashboard: " +
"https://app.configcat.com/organization/data-governance. " +
"Only Organization Admins can access this preference.");
}
if (retries >= 2) {
options.logger.error("Redirect loop during config.json fetch. Please contact support@configcat.com.");
callback(newConfig);
return;
}
_this.fetchLogic(options, lastProjectConfig, ++retries, callback);
return;
});
};
return ConfigServiceBase;
}());
exports.ConfigServiceBase = ConfigServiceBase;

@@ -56,9 +56,9 @@ import { IConfigCatClient } from "./ConfigCatClient";

export interface ICache {
Set(apiKey: string, config: ProjectConfig): void;
Get(apiKey: string): ProjectConfig;
set(key: string, config: ProjectConfig): void;
get(key: string): ProjectConfig;
}
export { ProjectConfig } from "./ProjectConfig";
export { IConfigCatClient } from "./ConfigCatClient";
export { OptionsBase } from "./ConfigCatClientOptions";
export { OptionsBase, DataGovernance } from "./ConfigCatClientOptions";
export { User } from "./RolloutEvaluator";
//# sourceMappingURL=index.d.ts.map

@@ -53,3 +53,4 @@ "use strict";

Object.defineProperty(exports, "OptionsBase", { enumerable: true, get: function () { return ConfigCatClientOptions_2.OptionsBase; } });
Object.defineProperty(exports, "DataGovernance", { enumerable: true, get: function () { return ConfigCatClientOptions_2.DataGovernance; } });
var RolloutEvaluator_1 = require("./RolloutEvaluator");
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return RolloutEvaluator_1.User; } });

@@ -26,3 +26,3 @@ "use strict";

LazyLoadConfigService.prototype.getConfig = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
if (p && p.Timestamp + (this.cacheTimeToLiveSeconds * 1000) > new Date().getTime()) {

@@ -36,3 +36,3 @@ return new Promise(function (resolve) { return resolve(p); });

LazyLoadConfigService.prototype.refreshConfigAsync = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
return this.refreshLogicBaseAsync(p);

@@ -39,0 +39,0 @@ };

@@ -25,6 +25,6 @@ "use strict";

var _this = this;
return new Promise(function (resolve) { return resolve(_this.cache.Get(_this.baseConfig.apiKey)); });
return new Promise(function (resolve) { return resolve(_this.cache.get(_this.baseConfig.getCacheKey())); });
};
ManualPollService.prototype.refreshConfigAsync = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
return this.refreshLogicBaseAsync(p);

@@ -31,0 +31,0 @@ };

@@ -10,2 +10,10 @@ export declare class ProjectConfig {

}
export declare class ConfigFile {
static Preferences: string;
static FeatureFlags: string;
}
export declare class Preferences {
static BaseUrl: string;
static Redirect: string;
}
export declare class Setting {

@@ -12,0 +20,0 @@ static Value: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloutPercentageItems = exports.RolloutRules = exports.Setting = exports.ProjectConfig = void 0;
exports.RolloutPercentageItems = exports.RolloutRules = exports.Setting = exports.Preferences = exports.ConfigFile = exports.ProjectConfig = void 0;
var ProjectConfig = /** @class */ (function () {

@@ -13,2 +13,18 @@ function ProjectConfig(timeStamp, jsonConfig, httpETag) {

exports.ProjectConfig = ProjectConfig;
var ConfigFile = /** @class */ (function () {
function ConfigFile() {
}
ConfigFile.Preferences = "p";
ConfigFile.FeatureFlags = "f";
return ConfigFile;
}());
exports.ConfigFile = ConfigFile;
var Preferences = /** @class */ (function () {
function Preferences() {
}
Preferences.BaseUrl = "u";
Preferences.Redirect = "r";
return Preferences;
}());
exports.Preferences = Preferences;
var Setting = /** @class */ (function () {

@@ -15,0 +31,0 @@ function Setting() {

@@ -29,12 +29,14 @@ "use strict";

RolloutEvaluator.prototype.Evaluate = function (config, key, defaultValue, user, defaultVariationId) {
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
this.logger.error("JSONConfig is not present. Returning default value: '" + defaultValue + "'.");
return { Value: defaultValue, VariationId: defaultVariationId };
}
if (!config.ConfigJSON[key]) {
var featureFlags = config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags];
if (!featureFlags[key]) {
var s = "Evaluating getValue('" + key + "') failed. Returning default value: '" + defaultValue + "'.";
s += " Here are the available keys: {" + Object.keys(config.ConfigJSON).join() + "}.";
s += " Here are the available keys: {" + Object.keys(featureFlags).join() + "}.";
this.logger.error(s);
return { Value: defaultValue, VariationId: defaultVariationId };
}
var featureFlag = featureFlags[key];
var eLog = new EvaluateLogger();

@@ -47,9 +49,9 @@ eLog.User = user;

if (user) {
result = this.EvaluateRules(config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutRules], user, eLog);
result = this.EvaluateRules(featureFlag[ProjectConfig_1.Setting.RolloutRules], user, eLog);
if (result.ValueAndVariationId == null) {
result.ValueAndVariationId = this.EvaluateVariations(config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems], key, user);
result.ValueAndVariationId = this.EvaluateVariations(featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems], key, user);
if (result.ValueAndVariationId) {
result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;
}
if (config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems].length > 0) {
if (featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems].length > 0) {
result.EvaluateLog.OpAppendLine("Evaluating % options => " + (result.ValueAndVariationId == null ? "user not targeted" : "user targeted"));

@@ -60,4 +62,4 @@ }

else {
if ((config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutRules] && config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutRules].length > 0) ||
(config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems] && config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems].length > 0)) {
if ((featureFlag[ProjectConfig_1.Setting.RolloutRules] && featureFlag[ProjectConfig_1.Setting.RolloutRules].length > 0) ||
(featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems] && featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems].length > 0)) {
var s = "Evaluating getValue('" + key + "'). ";

@@ -71,4 +73,4 @@ s += "UserObject missing! You should pass a UserObject to getValue(), in order to make targeting work properly. ";

result.ValueAndVariationId = {
Value: config.ConfigJSON[key][ProjectConfig_1.Setting.Value],
VariationId: config.ConfigJSON[key][ProjectConfig_1.Setting.VariationId],
Value: featureFlag[ProjectConfig_1.Setting.Value],
VariationId: featureFlag[ProjectConfig_1.Setting.VariationId],
};

@@ -75,0 +77,0 @@ result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "3.0.2";
exports.default = "4.0.0";

@@ -131,3 +131,3 @@ "use strict";

config = _a.sent();
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
this.options.logger.error("JSONConfig is not present, returning empty array");

@@ -137,3 +137,3 @@ resolve([]);

}
resolve(Object.keys(config.ConfigJSON));
resolve(Object.keys(config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]));
return [2 /*return*/];

@@ -203,3 +203,3 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
var config, featureFlags, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
return __generator(this, function (_a) {

@@ -210,3 +210,3 @@ switch (_a.label) {

config = _a.sent();
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
this.options.logger.error("JSONConfig is not present, returning null");

@@ -216,8 +216,9 @@ resolve(null);

}
for (settingKey in config.ConfigJSON) {
if (variationId === config.ConfigJSON[settingKey][ProjectConfig_1.Setting.VariationId]) {
resolve({ settingKey: settingKey, settingValue: config.ConfigJSON[settingKey][ProjectConfig_1.Setting.Value] });
featureFlags = config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags];
for (settingKey in featureFlags) {
if (variationId === featureFlags[settingKey][ProjectConfig_1.Setting.VariationId]) {
resolve({ settingKey: settingKey, settingValue: featureFlags[settingKey][ProjectConfig_1.Setting.Value] });
return [2 /*return*/];
}
rolloutRules = config.ConfigJSON[settingKey][ProjectConfig_1.Setting.RolloutRules];
rolloutRules = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutRules];
if (rolloutRules && rolloutRules.length > 0) {

@@ -232,3 +233,3 @@ for (i = 0; i < rolloutRules.length; i++) {

}
percentageItems = config.ConfigJSON[settingKey][ProjectConfig_1.Setting.RolloutPercentageItems];
percentageItems = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutPercentageItems];
if (percentageItems && percentageItems.length > 0) {

@@ -235,0 +236,0 @@ for (i = 0; i < percentageItems.length; i++) {

import { IConfigCatLogger, IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions } from "./index";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
export declare enum DataGovernance {
/** Select this if your feature flags are published to all global CDN nodes. */
Global = 0,
/** Select this if your feature flags are published to CDN nodes only in the EU. */
EuOnly = 1
}
export interface IOptions {

@@ -6,5 +13,10 @@ logger?: IConfigCatLogger;

baseUrl?: string;
/** You can set a base_url if you want to use a proxy server between your application and ConfigCat */
proxy?: string;
/** Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
* https://app.configcat.com/organization/data-governance (Only Organization Admins have access) */
dataGovernance?: DataGovernance;
}
export declare abstract class OptionsBase implements IOptions {
private configFileName;
logger: IConfigCatLogger;

@@ -15,8 +27,13 @@ apiKey: string;

baseUrl: string;
baseUrlOverriden: boolean;
proxy: string;
dataGovernance: DataGovernance;
constructor(apiKey: string, clientVersion: string, options: IOptions);
getUrl(): string;
getCacheKey(): string;
}
export declare class AutoPollOptions extends OptionsBase implements IAutoPollOptions {
/** The client's poll interval in seconds. Default: 60 seconds. */
pollIntervalSeconds: number;
/** You can subscribe to configuration changes with this callback */
configChanged: () => void;

@@ -29,2 +46,3 @@ constructor(apiKey: string, options: IAutoPollOptions);

export declare class LazyLoadOptions extends OptionsBase implements ILazyLoadingOptions {
/** The cache TTL. */
cacheTimeToLiveSeconds: number;

@@ -31,0 +49,0 @@ constructor(apiKey: string, options: ILazyLoadingOptions);

@@ -16,11 +16,21 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyLoadOptions = exports.ManualPollOptions = exports.AutoPollOptions = exports.OptionsBase = void 0;
exports.LazyLoadOptions = exports.ManualPollOptions = exports.AutoPollOptions = exports.OptionsBase = exports.DataGovernance = void 0;
var ConfigCatLogger_1 = require("./ConfigCatLogger");
var index_1 = require("./index");
var Version_1 = require("./Version");
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
var DataGovernance;
(function (DataGovernance) {
/** Select this if your feature flags are published to all global CDN nodes. */
DataGovernance[DataGovernance["Global"] = 0] = "Global";
/** Select this if your feature flags are published to CDN nodes only in the EU. */
DataGovernance[DataGovernance["EuOnly"] = 1] = "EuOnly";
})(DataGovernance = exports.DataGovernance || (exports.DataGovernance = {}));
var OptionsBase = /** @class */ (function () {
function OptionsBase(apiKey, clientVersion, options) {
var _a;
this.configFileName = "config_v5";
this.logger = new ConfigCatLogger_1.ConfigCatConsoleLogger(index_1.LogLevel.Warn);
this.requestTimeoutMs = 30000;
this.baseUrl = "https://cdn.configcat.com";
this.baseUrlOverriden = false;
this.proxy = "";

@@ -32,2 +42,11 @@ if (!apiKey) {

this.clientVersion = clientVersion;
this.dataGovernance = (_a = options === null || options === void 0 ? void 0 : options.dataGovernance) !== null && _a !== void 0 ? _a : DataGovernance.Global;
switch (this.dataGovernance) {
case DataGovernance.EuOnly:
this.baseUrl = "https://cdn-eu.configcat.com";
break;
default:
this.baseUrl = "https://cdn-global.configcat.com";
break;
}
if (options) {

@@ -45,2 +64,3 @@ if (options.logger) {

this.baseUrl = options.baseUrl;
this.baseUrlOverriden = true;
}

@@ -53,4 +73,7 @@ if (options.proxy) {

OptionsBase.prototype.getUrl = function () {
return this.baseUrl + "/configuration-files/" + this.apiKey + "/config_v4.json";
return this.baseUrl + "/configuration-files/" + this.apiKey + "/" + this.configFileName + ".json";
};
OptionsBase.prototype.getCacheKey = function () {
return "js_" + this.configFileName + "_" + this.apiKey;
};
return OptionsBase;

@@ -63,3 +86,5 @@ }());

var _this = _super.call(this, apiKey, "a-" + Version_1.default, options) || this;
/** The client's poll interval in seconds. Default: 60 seconds. */
_this.pollIntervalSeconds = 60;
/** You can subscribe to configuration changes with this callback */
_this.configChanged = function () { };

@@ -94,2 +119,3 @@ if (options) {

var _this = _super.call(this, apiKey, "l-" + Version_1.default, options) || this;
/** The cache TTL. */
_this.cacheTimeToLiveSeconds = 60;

@@ -96,0 +122,0 @@ if (options) {

@@ -14,3 +14,4 @@ import { IConfigFetcher, ICache } from "./index";

protected refreshLogicBaseAsync(lastProjectConfig: ProjectConfig): Promise<ProjectConfig>;
private fetchLogic;
}
//# sourceMappingURL=ConfigServiceBase.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigServiceBase = void 0;
var ProjectConfig_1 = require("./ProjectConfig");
var ConfigServiceBase = /** @class */ (function () {

@@ -13,5 +14,5 @@ function ConfigServiceBase(configFetcher, cache, baseConfig) {

return new Promise(function (resolve) {
_this.configFetcher.fetchLogic(_this.baseConfig, lastProjectConfig, function (newConfig) {
if (newConfig) {
_this.cache.Set(_this.baseConfig.apiKey, newConfig);
_this.fetchLogic(_this.baseConfig, lastProjectConfig, 0, function (newConfig) {
if (newConfig && newConfig.ConfigJSON) {
_this.cache.set(_this.baseConfig.getCacheKey(), newConfig);
resolve(newConfig);

@@ -25,4 +26,49 @@ }

};
ConfigServiceBase.prototype.fetchLogic = function (options, lastProjectConfig, retries, callback) {
var _this = this;
this.configFetcher.fetchLogic(this.baseConfig, lastProjectConfig, function (newConfig) {
if (!newConfig || !newConfig.ConfigJSON) {
callback(null);
return;
}
var preferences = newConfig.ConfigJSON[ProjectConfig_1.ConfigFile.Preferences];
if (!preferences) {
callback(newConfig);
return;
}
var baseUrl = preferences[ProjectConfig_1.Preferences.BaseUrl];
// If the base_url is the same as the last called one, just return the response.
if (!baseUrl || baseUrl == options.baseUrl) {
callback(newConfig);
return;
}
var redirect = preferences[ProjectConfig_1.Preferences.Redirect];
// If the base_url is overridden, and the redirect parameter is not 2 (force),
// the SDK should not redirect the calls and it just have to return the response.
if (options.baseUrlOverriden && redirect !== 2) {
callback(newConfig);
return;
}
options.baseUrl = baseUrl;
if (redirect === 0) {
callback(newConfig);
return;
}
if (redirect === 1) {
options.logger.warn("Your dataGovernance parameter at ConfigCatClient initialization is not in sync " +
"with your preferences on the ConfigCat Dashboard: " +
"https://app.configcat.com/organization/data-governance. " +
"Only Organization Admins can access this preference.");
}
if (retries >= 2) {
options.logger.error("Redirect loop during config.json fetch. Please contact support@configcat.com.");
callback(newConfig);
return;
}
_this.fetchLogic(options, lastProjectConfig, ++retries, callback);
return;
});
};
return ConfigServiceBase;
}());
exports.ConfigServiceBase = ConfigServiceBase;

@@ -65,3 +65,3 @@ var __extends = (this && this.__extends) || (function () {

AutoPollConfigService.prototype.getConfig = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
if (!p) {

@@ -84,3 +84,3 @@ return this.refreshLogic();

case 0:
p = this.cache.Get(this.baseConfig.apiKey);
p = this.cache.get(this.baseConfig.getCacheKey());
return [4 /*yield*/, this.refreshLogicBaseAsync(p)];

@@ -87,0 +87,0 @@ case 1:

@@ -7,5 +7,5 @@ import { ProjectConfig } from "./ProjectConfig";

};
Set(apiKey: string, config: ProjectConfig): void;
Get(apiKey: string): ProjectConfig;
set(key: string, config: ProjectConfig): void;
get(key: string): ProjectConfig;
}
//# sourceMappingURL=Cache.d.ts.map

@@ -5,7 +5,7 @@ var InMemoryCache = /** @class */ (function () {

}
InMemoryCache.prototype.Set = function (apiKey, config) {
this.cache[apiKey] = config;
InMemoryCache.prototype.set = function (key, config) {
this.cache[key] = config;
};
InMemoryCache.prototype.Get = function (apiKey) {
return this.cache[apiKey];
InMemoryCache.prototype.get = function (key) {
return this.cache[key];
};

@@ -12,0 +12,0 @@ return InMemoryCache;

@@ -42,3 +42,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { RolloutEvaluator } from "./RolloutEvaluator";
import { Setting, RolloutRules, RolloutPercentageItems } from "./ProjectConfig";
import { Setting, RolloutRules, RolloutPercentageItems, ConfigFile } from "./ProjectConfig";
export var CONFIG_CHANGE_EVENT_NAME = "changed";

@@ -129,3 +129,3 @@ var ConfigCatClient = /** @class */ (function () {

config = _a.sent();
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
this.options.logger.error("JSONConfig is not present, returning empty array");

@@ -135,3 +135,3 @@ resolve([]);

}
resolve(Object.keys(config.ConfigJSON));
resolve(Object.keys(config.ConfigJSON[ConfigFile.FeatureFlags]));
return [2 /*return*/];

@@ -201,3 +201,3 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
var config, featureFlags, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
return __generator(this, function (_a) {

@@ -208,3 +208,3 @@ switch (_a.label) {

config = _a.sent();
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
this.options.logger.error("JSONConfig is not present, returning null");

@@ -214,8 +214,9 @@ resolve(null);

}
for (settingKey in config.ConfigJSON) {
if (variationId === config.ConfigJSON[settingKey][Setting.VariationId]) {
resolve({ settingKey: settingKey, settingValue: config.ConfigJSON[settingKey][Setting.Value] });
featureFlags = config.ConfigJSON[ConfigFile.FeatureFlags];
for (settingKey in featureFlags) {
if (variationId === featureFlags[settingKey][Setting.VariationId]) {
resolve({ settingKey: settingKey, settingValue: featureFlags[settingKey][Setting.Value] });
return [2 /*return*/];
}
rolloutRules = config.ConfigJSON[settingKey][Setting.RolloutRules];
rolloutRules = featureFlags[settingKey][Setting.RolloutRules];
if (rolloutRules && rolloutRules.length > 0) {

@@ -230,3 +231,3 @@ for (i = 0; i < rolloutRules.length; i++) {

}
percentageItems = config.ConfigJSON[settingKey][Setting.RolloutPercentageItems];
percentageItems = featureFlags[settingKey][Setting.RolloutPercentageItems];
if (percentageItems && percentageItems.length > 0) {

@@ -233,0 +234,0 @@ for (i = 0; i < percentageItems.length; i++) {

import { IConfigCatLogger, IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions } from "./index";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
export declare enum DataGovernance {
/** Select this if your feature flags are published to all global CDN nodes. */
Global = 0,
/** Select this if your feature flags are published to CDN nodes only in the EU. */
EuOnly = 1
}
export interface IOptions {

@@ -6,5 +13,10 @@ logger?: IConfigCatLogger;

baseUrl?: string;
/** You can set a base_url if you want to use a proxy server between your application and ConfigCat */
proxy?: string;
/** Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
* https://app.configcat.com/organization/data-governance (Only Organization Admins have access) */
dataGovernance?: DataGovernance;
}
export declare abstract class OptionsBase implements IOptions {
private configFileName;
logger: IConfigCatLogger;

@@ -15,8 +27,13 @@ apiKey: string;

baseUrl: string;
baseUrlOverriden: boolean;
proxy: string;
dataGovernance: DataGovernance;
constructor(apiKey: string, clientVersion: string, options: IOptions);
getUrl(): string;
getCacheKey(): string;
}
export declare class AutoPollOptions extends OptionsBase implements IAutoPollOptions {
/** The client's poll interval in seconds. Default: 60 seconds. */
pollIntervalSeconds: number;
/** You can subscribe to configuration changes with this callback */
configChanged: () => void;

@@ -29,2 +46,3 @@ constructor(apiKey: string, options: IAutoPollOptions);

export declare class LazyLoadOptions extends OptionsBase implements ILazyLoadingOptions {
/** The cache TTL. */
cacheTimeToLiveSeconds: number;

@@ -31,0 +49,0 @@ constructor(apiKey: string, options: ILazyLoadingOptions);

@@ -17,7 +17,17 @@ var __extends = (this && this.__extends) || (function () {

import COMMON_VERSION from "./Version";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
export var DataGovernance;
(function (DataGovernance) {
/** Select this if your feature flags are published to all global CDN nodes. */
DataGovernance[DataGovernance["Global"] = 0] = "Global";
/** Select this if your feature flags are published to CDN nodes only in the EU. */
DataGovernance[DataGovernance["EuOnly"] = 1] = "EuOnly";
})(DataGovernance || (DataGovernance = {}));
var OptionsBase = /** @class */ (function () {
function OptionsBase(apiKey, clientVersion, options) {
var _a;
this.configFileName = "config_v5";
this.logger = new ConfigCatConsoleLogger(LogLevel.Warn);
this.requestTimeoutMs = 30000;
this.baseUrl = "https://cdn.configcat.com";
this.baseUrlOverriden = false;
this.proxy = "";

@@ -29,2 +39,11 @@ if (!apiKey) {

this.clientVersion = clientVersion;
this.dataGovernance = (_a = options === null || options === void 0 ? void 0 : options.dataGovernance) !== null && _a !== void 0 ? _a : DataGovernance.Global;
switch (this.dataGovernance) {
case DataGovernance.EuOnly:
this.baseUrl = "https://cdn-eu.configcat.com";
break;
default:
this.baseUrl = "https://cdn-global.configcat.com";
break;
}
if (options) {

@@ -42,2 +61,3 @@ if (options.logger) {

this.baseUrl = options.baseUrl;
this.baseUrlOverriden = true;
}

@@ -50,4 +70,7 @@ if (options.proxy) {

OptionsBase.prototype.getUrl = function () {
return this.baseUrl + "/configuration-files/" + this.apiKey + "/config_v4.json";
return this.baseUrl + "/configuration-files/" + this.apiKey + "/" + this.configFileName + ".json";
};
OptionsBase.prototype.getCacheKey = function () {
return "js_" + this.configFileName + "_" + this.apiKey;
};
return OptionsBase;

@@ -60,3 +83,5 @@ }());

var _this = _super.call(this, apiKey, "a-" + COMMON_VERSION, options) || this;
/** The client's poll interval in seconds. Default: 60 seconds. */
_this.pollIntervalSeconds = 60;
/** You can subscribe to configuration changes with this callback */
_this.configChanged = function () { };

@@ -91,2 +116,3 @@ if (options) {

var _this = _super.call(this, apiKey, "l-" + COMMON_VERSION, options) || this;
/** The cache TTL. */
_this.cacheTimeToLiveSeconds = 60;

@@ -93,0 +119,0 @@ if (options) {

@@ -14,3 +14,4 @@ import { IConfigFetcher, ICache } from "./index";

protected refreshLogicBaseAsync(lastProjectConfig: ProjectConfig): Promise<ProjectConfig>;
private fetchLogic;
}
//# sourceMappingURL=ConfigServiceBase.d.ts.map

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

import { ConfigFile, Preferences } from "./ProjectConfig";
var ConfigServiceBase = /** @class */ (function () {

@@ -10,5 +11,5 @@ function ConfigServiceBase(configFetcher, cache, baseConfig) {

return new Promise(function (resolve) {
_this.configFetcher.fetchLogic(_this.baseConfig, lastProjectConfig, function (newConfig) {
if (newConfig) {
_this.cache.Set(_this.baseConfig.apiKey, newConfig);
_this.fetchLogic(_this.baseConfig, lastProjectConfig, 0, function (newConfig) {
if (newConfig && newConfig.ConfigJSON) {
_this.cache.set(_this.baseConfig.getCacheKey(), newConfig);
resolve(newConfig);

@@ -22,4 +23,49 @@ }

};
ConfigServiceBase.prototype.fetchLogic = function (options, lastProjectConfig, retries, callback) {
var _this = this;
this.configFetcher.fetchLogic(this.baseConfig, lastProjectConfig, function (newConfig) {
if (!newConfig || !newConfig.ConfigJSON) {
callback(null);
return;
}
var preferences = newConfig.ConfigJSON[ConfigFile.Preferences];
if (!preferences) {
callback(newConfig);
return;
}
var baseUrl = preferences[Preferences.BaseUrl];
// If the base_url is the same as the last called one, just return the response.
if (!baseUrl || baseUrl == options.baseUrl) {
callback(newConfig);
return;
}
var redirect = preferences[Preferences.Redirect];
// If the base_url is overridden, and the redirect parameter is not 2 (force),
// the SDK should not redirect the calls and it just have to return the response.
if (options.baseUrlOverriden && redirect !== 2) {
callback(newConfig);
return;
}
options.baseUrl = baseUrl;
if (redirect === 0) {
callback(newConfig);
return;
}
if (redirect === 1) {
options.logger.warn("Your dataGovernance parameter at ConfigCatClient initialization is not in sync " +
"with your preferences on the ConfigCat Dashboard: " +
"https://app.configcat.com/organization/data-governance. " +
"Only Organization Admins can access this preference.");
}
if (retries >= 2) {
options.logger.error("Redirect loop during config.json fetch. Please contact support@configcat.com.");
callback(newConfig);
return;
}
_this.fetchLogic(options, lastProjectConfig, ++retries, callback);
return;
});
};
return ConfigServiceBase;
}());
export { ConfigServiceBase };

@@ -56,9 +56,9 @@ import { IConfigCatClient } from "./ConfigCatClient";

export interface ICache {
Set(apiKey: string, config: ProjectConfig): void;
Get(apiKey: string): ProjectConfig;
set(key: string, config: ProjectConfig): void;
get(key: string): ProjectConfig;
}
export { ProjectConfig } from "./ProjectConfig";
export { IConfigCatClient } from "./ConfigCatClient";
export { OptionsBase } from "./ConfigCatClientOptions";
export { OptionsBase, DataGovernance } from "./ConfigCatClientOptions";
export { User } from "./RolloutEvaluator";
//# sourceMappingURL=index.d.ts.map

@@ -43,3 +43,3 @@ import { ConfigCatClient } from "./ConfigCatClient";

export { ProjectConfig } from "./ProjectConfig";
export { OptionsBase } from "./ConfigCatClientOptions";
export { OptionsBase, DataGovernance } from "./ConfigCatClientOptions";
export { User } from "./RolloutEvaluator";

@@ -23,3 +23,3 @@ var __extends = (this && this.__extends) || (function () {

LazyLoadConfigService.prototype.getConfig = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
if (p && p.Timestamp + (this.cacheTimeToLiveSeconds * 1000) > new Date().getTime()) {

@@ -33,3 +33,3 @@ return new Promise(function (resolve) { return resolve(p); });

LazyLoadConfigService.prototype.refreshConfigAsync = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
return this.refreshLogicBaseAsync(p);

@@ -36,0 +36,0 @@ };

@@ -22,6 +22,6 @@ var __extends = (this && this.__extends) || (function () {

var _this = this;
return new Promise(function (resolve) { return resolve(_this.cache.Get(_this.baseConfig.apiKey)); });
return new Promise(function (resolve) { return resolve(_this.cache.get(_this.baseConfig.getCacheKey())); });
};
ManualPollService.prototype.refreshConfigAsync = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
return this.refreshLogicBaseAsync(p);

@@ -28,0 +28,0 @@ };

@@ -10,2 +10,10 @@ export declare class ProjectConfig {

}
export declare class ConfigFile {
static Preferences: string;
static FeatureFlags: string;
}
export declare class Preferences {
static BaseUrl: string;
static Redirect: string;
}
export declare class Setting {

@@ -12,0 +20,0 @@ static Value: string;

@@ -10,2 +10,18 @@ var ProjectConfig = /** @class */ (function () {

export { ProjectConfig };
var ConfigFile = /** @class */ (function () {
function ConfigFile() {
}
ConfigFile.Preferences = "p";
ConfigFile.FeatureFlags = "f";
return ConfigFile;
}());
export { ConfigFile };
var Preferences = /** @class */ (function () {
function Preferences() {
}
Preferences.BaseUrl = "u";
Preferences.Redirect = "r";
return Preferences;
}());
export { Preferences };
var Setting = /** @class */ (function () {

@@ -12,0 +28,0 @@ function Setting() {

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

import { Setting, RolloutRules, RolloutPercentageItems } from "./ProjectConfig";
import { Setting, RolloutRules, RolloutPercentageItems, ConfigFile } from "./ProjectConfig";
import { sha1 } from "./Sha1";

@@ -26,12 +26,14 @@ import * as semver from "./Semver";

RolloutEvaluator.prototype.Evaluate = function (config, key, defaultValue, user, defaultVariationId) {
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
this.logger.error("JSONConfig is not present. Returning default value: '" + defaultValue + "'.");
return { Value: defaultValue, VariationId: defaultVariationId };
}
if (!config.ConfigJSON[key]) {
var featureFlags = config.ConfigJSON[ConfigFile.FeatureFlags];
if (!featureFlags[key]) {
var s = "Evaluating getValue('" + key + "') failed. Returning default value: '" + defaultValue + "'.";
s += " Here are the available keys: {" + Object.keys(config.ConfigJSON).join() + "}.";
s += " Here are the available keys: {" + Object.keys(featureFlags).join() + "}.";
this.logger.error(s);
return { Value: defaultValue, VariationId: defaultVariationId };
}
var featureFlag = featureFlags[key];
var eLog = new EvaluateLogger();

@@ -44,9 +46,9 @@ eLog.User = user;

if (user) {
result = this.EvaluateRules(config.ConfigJSON[key][Setting.RolloutRules], user, eLog);
result = this.EvaluateRules(featureFlag[Setting.RolloutRules], user, eLog);
if (result.ValueAndVariationId == null) {
result.ValueAndVariationId = this.EvaluateVariations(config.ConfigJSON[key][Setting.RolloutPercentageItems], key, user);
result.ValueAndVariationId = this.EvaluateVariations(featureFlag[Setting.RolloutPercentageItems], key, user);
if (result.ValueAndVariationId) {
result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;
}
if (config.ConfigJSON[key][Setting.RolloutPercentageItems].length > 0) {
if (featureFlag[Setting.RolloutPercentageItems].length > 0) {
result.EvaluateLog.OpAppendLine("Evaluating % options => " + (result.ValueAndVariationId == null ? "user not targeted" : "user targeted"));

@@ -57,4 +59,4 @@ }

else {
if ((config.ConfigJSON[key][Setting.RolloutRules] && config.ConfigJSON[key][Setting.RolloutRules].length > 0) ||
(config.ConfigJSON[key][Setting.RolloutPercentageItems] && config.ConfigJSON[key][Setting.RolloutPercentageItems].length > 0)) {
if ((featureFlag[Setting.RolloutRules] && featureFlag[Setting.RolloutRules].length > 0) ||
(featureFlag[Setting.RolloutPercentageItems] && featureFlag[Setting.RolloutPercentageItems].length > 0)) {
var s = "Evaluating getValue('" + key + "'). ";

@@ -68,4 +70,4 @@ s += "UserObject missing! You should pass a UserObject to getValue(), in order to make targeting work properly. ";

result.ValueAndVariationId = {
Value: config.ConfigJSON[key][Setting.Value],
VariationId: config.ConfigJSON[key][Setting.VariationId],
Value: featureFlag[Setting.Value],
VariationId: featureFlag[Setting.VariationId],
};

@@ -72,0 +74,0 @@ result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;

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

export default "3.0.2";
export default "4.0.0";

@@ -56,9 +56,9 @@ import { IConfigCatClient } from "./ConfigCatClient";

export interface ICache {
Set(apiKey: string, config: ProjectConfig): void;
Get(apiKey: string): ProjectConfig;
set(key: string, config: ProjectConfig): void;
get(key: string): ProjectConfig;
}
export { ProjectConfig } from "./ProjectConfig";
export { IConfigCatClient } from "./ConfigCatClient";
export { OptionsBase } from "./ConfigCatClientOptions";
export { OptionsBase, DataGovernance } from "./ConfigCatClientOptions";
export { User } from "./RolloutEvaluator";
//# sourceMappingURL=index.d.ts.map

@@ -53,3 +53,4 @@ "use strict";

Object.defineProperty(exports, "OptionsBase", { enumerable: true, get: function () { return ConfigCatClientOptions_2.OptionsBase; } });
Object.defineProperty(exports, "DataGovernance", { enumerable: true, get: function () { return ConfigCatClientOptions_2.DataGovernance; } });
var RolloutEvaluator_1 = require("./RolloutEvaluator");
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return RolloutEvaluator_1.User; } });

@@ -26,3 +26,3 @@ "use strict";

LazyLoadConfigService.prototype.getConfig = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
if (p && p.Timestamp + (this.cacheTimeToLiveSeconds * 1000) > new Date().getTime()) {

@@ -36,3 +36,3 @@ return new Promise(function (resolve) { return resolve(p); });

LazyLoadConfigService.prototype.refreshConfigAsync = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
return this.refreshLogicBaseAsync(p);

@@ -39,0 +39,0 @@ };

@@ -25,6 +25,6 @@ "use strict";

var _this = this;
return new Promise(function (resolve) { return resolve(_this.cache.Get(_this.baseConfig.apiKey)); });
return new Promise(function (resolve) { return resolve(_this.cache.get(_this.baseConfig.getCacheKey())); });
};
ManualPollService.prototype.refreshConfigAsync = function () {
var p = this.cache.Get(this.baseConfig.apiKey);
var p = this.cache.get(this.baseConfig.getCacheKey());
return this.refreshLogicBaseAsync(p);

@@ -31,0 +31,0 @@ };

@@ -10,2 +10,10 @@ export declare class ProjectConfig {

}
export declare class ConfigFile {
static Preferences: string;
static FeatureFlags: string;
}
export declare class Preferences {
static BaseUrl: string;
static Redirect: string;
}
export declare class Setting {

@@ -12,0 +20,0 @@ static Value: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloutPercentageItems = exports.RolloutRules = exports.Setting = exports.ProjectConfig = void 0;
exports.RolloutPercentageItems = exports.RolloutRules = exports.Setting = exports.Preferences = exports.ConfigFile = exports.ProjectConfig = void 0;
var ProjectConfig = /** @class */ (function () {

@@ -13,2 +13,18 @@ function ProjectConfig(timeStamp, jsonConfig, httpETag) {

exports.ProjectConfig = ProjectConfig;
var ConfigFile = /** @class */ (function () {
function ConfigFile() {
}
ConfigFile.Preferences = "p";
ConfigFile.FeatureFlags = "f";
return ConfigFile;
}());
exports.ConfigFile = ConfigFile;
var Preferences = /** @class */ (function () {
function Preferences() {
}
Preferences.BaseUrl = "u";
Preferences.Redirect = "r";
return Preferences;
}());
exports.Preferences = Preferences;
var Setting = /** @class */ (function () {

@@ -15,0 +31,0 @@ function Setting() {

@@ -29,12 +29,14 @@ "use strict";

RolloutEvaluator.prototype.Evaluate = function (config, key, defaultValue, user, defaultVariationId) {
if (!config || !config.ConfigJSON) {
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
this.logger.error("JSONConfig is not present. Returning default value: '" + defaultValue + "'.");
return { Value: defaultValue, VariationId: defaultVariationId };
}
if (!config.ConfigJSON[key]) {
var featureFlags = config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags];
if (!featureFlags[key]) {
var s = "Evaluating getValue('" + key + "') failed. Returning default value: '" + defaultValue + "'.";
s += " Here are the available keys: {" + Object.keys(config.ConfigJSON).join() + "}.";
s += " Here are the available keys: {" + Object.keys(featureFlags).join() + "}.";
this.logger.error(s);
return { Value: defaultValue, VariationId: defaultVariationId };
}
var featureFlag = featureFlags[key];
var eLog = new EvaluateLogger();

@@ -47,9 +49,9 @@ eLog.User = user;

if (user) {
result = this.EvaluateRules(config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutRules], user, eLog);
result = this.EvaluateRules(featureFlag[ProjectConfig_1.Setting.RolloutRules], user, eLog);
if (result.ValueAndVariationId == null) {
result.ValueAndVariationId = this.EvaluateVariations(config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems], key, user);
result.ValueAndVariationId = this.EvaluateVariations(featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems], key, user);
if (result.ValueAndVariationId) {
result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;
}
if (config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems].length > 0) {
if (featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems].length > 0) {
result.EvaluateLog.OpAppendLine("Evaluating % options => " + (result.ValueAndVariationId == null ? "user not targeted" : "user targeted"));

@@ -60,4 +62,4 @@ }

else {
if ((config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutRules] && config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutRules].length > 0) ||
(config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems] && config.ConfigJSON[key][ProjectConfig_1.Setting.RolloutPercentageItems].length > 0)) {
if ((featureFlag[ProjectConfig_1.Setting.RolloutRules] && featureFlag[ProjectConfig_1.Setting.RolloutRules].length > 0) ||
(featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems] && featureFlag[ProjectConfig_1.Setting.RolloutPercentageItems].length > 0)) {
var s = "Evaluating getValue('" + key + "'). ";

@@ -71,4 +73,4 @@ s += "UserObject missing! You should pass a UserObject to getValue(), in order to make targeting work properly. ";

result.ValueAndVariationId = {
Value: config.ConfigJSON[key][ProjectConfig_1.Setting.Value],
VariationId: config.ConfigJSON[key][ProjectConfig_1.Setting.VariationId],
Value: featureFlag[ProjectConfig_1.Setting.Value],
VariationId: featureFlag[ProjectConfig_1.Setting.VariationId],
};

@@ -75,0 +77,0 @@ result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "3.0.2";
exports.default = "4.0.0";
{
"name": "configcat-common",
"version": "3.0.2",
"version": "4.0.0",
"description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.",

@@ -39,3 +39,3 @@ "main": "lib/index.js",

"gulp-typescript": "^6.0.0-alpha.1",
"mocha": "^8.0.1",
"mocha": "^8.1.3",
"nyc": "^15.1.0",

@@ -42,0 +42,0 @@ "source-map-support": "^0.5.19",

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

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

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

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

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

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