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 4.6.2 to 5.0.0

lib/cjs/FlagOverrides.d.ts

1

lib/AutoPollConfigService.d.ts

@@ -17,2 +17,3 @@ import { AutoPollOptions } from "./ConfigCatClientOptions";

private startRefreshWorker;
private refreshWorkerLogic;
private tryReadFromCache;

@@ -19,0 +20,0 @@ private sleep;

14

lib/AutoPollConfigService.js

@@ -121,8 +121,14 @@ "use strict";

var _this = this;
this.refreshLogic(true).then(function (_) {
setTimeout(function () { return _this.refreshWorkerLogic(delay); }, delay);
});
};
AutoPollConfigService.prototype.refreshWorkerLogic = function (delay) {
var _this = this;
if (this.disposed) {
return;
}
this.refreshLogic(false).then(function (_) {
if (_this.disposed) {
return;
}
_this.timerId = setTimeout(function () {
_this.startRefreshWorker(delay);
_this.refreshWorkerLogic(delay);
}, delay);

@@ -129,0 +135,0 @@ });

@@ -17,2 +17,3 @@ import { AutoPollOptions } from "./ConfigCatClientOptions";

private startRefreshWorker;
private refreshWorkerLogic;
private tryReadFromCache;

@@ -19,0 +20,0 @@ private sleep;

@@ -121,8 +121,14 @@ "use strict";

var _this = this;
this.refreshLogic(true).then(function (_) {
setTimeout(function () { return _this.refreshWorkerLogic(delay); }, delay);
});
};
AutoPollConfigService.prototype.refreshWorkerLogic = function (delay) {
var _this = this;
if (this.disposed) {
return;
}
this.refreshLogic(false).then(function (_) {
if (_this.disposed) {
return;
}
_this.timerId = setTimeout(function () {
_this.startRefreshWorker(delay);
_this.refreshWorkerLogic(delay);
}, delay);

@@ -129,0 +135,0 @@ });

@@ -37,3 +37,3 @@ import { IConfigCatKernel } from "./index";

export declare class ConfigCatClient implements IConfigCatClient {
private configService;
private configService?;
private evaluator;

@@ -57,2 +57,3 @@ private options;

getAllValuesAsync(user?: User): Promise<SettingKeyValue[]>;
private getSettings;
}

@@ -59,0 +60,0 @@ export declare class SettingKeyValue {

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -46,4 +57,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var ProjectConfig_1 = require("./ProjectConfig");
var FlagOverrides_1 = require("./FlagOverrides");
var ConfigCatClient = /** @class */ (function () {
function ConfigCatClient(options, configCatKernel) {
var _a;
if (!options) {

@@ -60,14 +73,16 @@ throw new Error("Invalid 'options' value");

this.evaluator = new RolloutEvaluator_1.RolloutEvaluator(options.logger);
if (options && options instanceof ConfigCatClientOptions_1.LazyLoadOptions) {
this.configService = new LazyLoadConfigService_1.LazyLoadConfigService(configCatKernel.configFetcher, options);
if (((_a = options === null || options === void 0 ? void 0 : options.flagOverrides) === null || _a === void 0 ? void 0 : _a.behaviour) != FlagOverrides_1.OverrideBehaviour.LocalOnly) {
if (options && options instanceof ConfigCatClientOptions_1.LazyLoadOptions) {
this.configService = new LazyLoadConfigService_1.LazyLoadConfigService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ConfigCatClientOptions_1.ManualPollOptions) {
this.configService = new ManualPollService_1.ManualPollService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ConfigCatClientOptions_1.AutoPollOptions) {
this.configService = new AutoPollConfigService_1.AutoPollConfigService(configCatKernel.configFetcher, options);
}
else {
throw new Error("Invalid 'options' value");
}
}
else if (options && options instanceof ConfigCatClientOptions_1.ManualPollOptions) {
this.configService = new ManualPollService_1.ManualPollService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ConfigCatClientOptions_1.AutoPollOptions) {
this.configService = new AutoPollConfigService_1.AutoPollConfigService(configCatKernel.configFetcher, options);
}
else {
throw new Error("Invalid 'options' value");
}
}

@@ -87,9 +102,14 @@ ConfigCatClient.prototype.dispose = function () {

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, result;
var settings, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
result = this.evaluator.Evaluate(config, key, defaultValue, user).Value;
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present. Returning default value: '" + defaultValue + "'.");
resolve(defaultValue);
return [2 /*return*/];
}
result = this.evaluator.Evaluate(settings, key, defaultValue, user).Value;
resolve(result);

@@ -109,7 +129,8 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.refreshConfigAsync()];
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, ((_a = this.configService) === null || _a === void 0 ? void 0 : _a.refreshConfigAsync())];
case 1:
_a.sent();
_b.sent();
resolve();

@@ -129,9 +150,9 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config;
var settings;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -141,3 +162,3 @@ resolve([]);

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

@@ -156,9 +177,14 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, result;
var settings, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
result = this.evaluator.Evaluate(config, key, null, user, defaultVariationId).VariationId;
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present. Returning default variationId: '" + defaultVariationId + "'.");
resolve(defaultVariationId);
return [2 /*return*/];
}
result = this.evaluator.Evaluate(settings, key, null, user, defaultVariationId).VariationId;
resolve(result);

@@ -207,9 +233,9 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, featureFlags, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
var settings, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -219,14 +245,13 @@ resolve(null);

}
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] });
for (settingKey in settings) {
if (variationId === settings[settingKey].variationId) {
resolve({ settingKey: settingKey, settingValue: settings[settingKey].value });
return [2 /*return*/];
}
rolloutRules = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutRules];
rolloutRules = settings[settingKey].rolloutRules;
if (rolloutRules && rolloutRules.length > 0) {
for (i = 0; i < rolloutRules.length; i++) {
rolloutRule = rolloutRules[i];
if (variationId === rolloutRule[ProjectConfig_1.RolloutRules.VariationId]) {
resolve({ settingKey: settingKey, settingValue: rolloutRule[ProjectConfig_1.RolloutRules.Value] });
if (variationId === rolloutRule.variationId) {
resolve({ settingKey: settingKey, settingValue: rolloutRule.value });
return [2 /*return*/];

@@ -236,8 +261,8 @@ }

}
percentageItems = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutPercentageItems];
percentageItems = settings[settingKey].rolloutPercentageItems;
if (percentageItems && percentageItems.length > 0) {
for (i = 0; i < percentageItems.length; i++) {
percentageItem = percentageItems[i];
if (variationId === percentageItem[ProjectConfig_1.RolloutPercentageItems.VariationId]) {
resolve({ settingKey: settingKey, settingValue: percentageItem[ProjectConfig_1.RolloutPercentageItems.Value] });
if (variationId === percentageItem.variationId) {
resolve({ settingKey: settingKey, settingValue: percentageItem.value });
return [2 /*return*/];

@@ -263,10 +288,10 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, keys, result;
var settings, keys, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -276,3 +301,3 @@ resolve([]);

}
keys = Object.keys(config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]);
keys = Object.keys(settings);
result = [];

@@ -282,3 +307,3 @@ keys.forEach(function (key) {

settingKey: key,
settingValue: _this.evaluator.Evaluate(config, key, undefined, user).Value
settingValue: _this.evaluator.Evaluate(settings, key, undefined, user).Value
});

@@ -292,2 +317,44 @@ });

};
ConfigCatClient.prototype.getSettings = function () {
var _this = this;
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var localSettings, config_1, remoteSettings, config;
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.flagOverrides)) return [3 /*break*/, 3];
return [4 /*yield*/, this.options.flagOverrides.dataSource.getOverrides()];
case 1:
localSettings = _e.sent();
if (this.options.flagOverrides.behaviour == FlagOverrides_1.OverrideBehaviour.LocalOnly) {
resolve(localSettings);
return [2 /*return*/];
}
return [4 /*yield*/, ((_b = this.configService) === null || _b === void 0 ? void 0 : _b.getConfig())];
case 2:
config_1 = _e.sent();
remoteSettings = (_c = config_1 === null || config_1 === void 0 ? void 0 : config_1.getSettings()) !== null && _c !== void 0 ? _c : {};
if (this.options.flagOverrides.behaviour == FlagOverrides_1.OverrideBehaviour.LocalOverRemote) {
resolve(__assign(__assign({}, remoteSettings), localSettings));
return [2 /*return*/];
}
else if (this.options.flagOverrides.behaviour == FlagOverrides_1.OverrideBehaviour.RemoteOverLocal) {
resolve(__assign(__assign({}, localSettings), remoteSettings));
return [2 /*return*/];
}
_e.label = 3;
case 3: return [4 /*yield*/, ((_d = this.configService) === null || _d === void 0 ? void 0 : _d.getConfig())];
case 4:
config = _e.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
resolve(null);
return [2 /*return*/];
}
resolve(config.getSettings());
return [2 /*return*/];
}
});
}); });
};
return ConfigCatClient;

@@ -294,0 +361,0 @@ }());

import { IConfigCatLogger, IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions, ICache } from "./index";
import { FlagOverrides } from "./FlagOverrides";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */

@@ -22,2 +23,3 @@ export declare enum DataGovernance {

cache?: ICache | null;
flagOverrides?: FlagOverrides | null;
}

@@ -35,2 +37,3 @@ export declare abstract class OptionsBase implements IOptions {

cache: ICache;
flagOverrides?: FlagOverrides;
constructor(apiKey: string, clientVersion: string, options?: IOptions | null, defaultCache?: ICache | null);

@@ -37,0 +40,0 @@ getUrl(): string;

@@ -77,2 +77,5 @@ "use strict";

}
if (options.flagOverrides) {
this.flagOverrides = options.flagOverrides;
}
}

@@ -79,0 +82,0 @@ }

@@ -9,3 +9,7 @@ import { IConfigCatLogger, LogLevel } from "./index";

constructor(logLevel: LogLevel);
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
log(message: string): void;
debug(message: string): void;
info(message: string): void;

@@ -12,0 +16,0 @@ warn(message: string): void;

@@ -16,5 +16,13 @@ "use strict";

}
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
ConfigCatConsoleLogger.prototype.log = function (message) {
this.info(message);
};
ConfigCatConsoleLogger.prototype.debug = function (message) {
if (this.isLogLevelEnabled(index_1.LogLevel.Debug)) {
console.info(this.SOURCE + " - DEBUG - " + message);
}
};
ConfigCatConsoleLogger.prototype.info = function (message) {

@@ -21,0 +29,0 @@ if (this.isLogLevelEnabled(index_1.LogLevel.Info)) {

@@ -11,3 +11,2 @@ import { IConfigFetcher } from "./index";

protected baseConfig: OptionsBase;
private fetchLogicLock;
private fetchLogicCallbacks;

@@ -14,0 +13,0 @@ constructor(configFetcher: IConfigFetcher, baseConfig: OptionsBase);

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

exports.ConfigServiceBase = void 0;
var index_1 = require("./index");
var ProjectConfig_1 = require("./ProjectConfig");
var ConfigServiceBase = /** @class */ (function () {
function ConfigServiceBase(configFetcher, baseConfig) {
this.fetchLogicLock = false;
this.fetchLogicCallbacks = [];

@@ -53,19 +53,24 @@ this.configFetcher = configFetcher;

return new Promise(function (resolve) {
_this.fetchLogic(_this.baseConfig, lastProjectConfig, 0, function (newConfig) { return __awaiter(_this, void 0, void 0, function () {
var _a;
_this.fetchLogic(_this.baseConfig, (_a = lastProjectConfig === null || lastProjectConfig === void 0 ? void 0 : lastProjectConfig.HttpETag) !== null && _a !== void 0 ? _a : null, 0, function (newConfig) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(newConfig && newConfig.ConfigJSON)) return [3 /*break*/, 3];
if (!(forceUpdateCache || !ProjectConfig_1.ProjectConfig.equals(newConfig, lastProjectConfig))) return [3 /*break*/, 2];
if (!(newConfig && newConfig.ConfigJSON)) return [3 /*break*/, 2];
return [4 /*yield*/, this.baseConfig.cache.set(this.baseConfig.getCacheKey(), newConfig)];
case 1:
_a.sent();
_a.label = 2;
resolve(newConfig);
return [3 /*break*/, 5];
case 2:
resolve(newConfig);
return [3 /*break*/, 4];
if (!(forceUpdateCache && lastProjectConfig && lastProjectConfig.ConfigJSON)) return [3 /*break*/, 4];
return [4 /*yield*/, this.baseConfig.cache.set(this.baseConfig.getCacheKey(), lastProjectConfig)];
case 3:
_a.sent();
resolve(lastProjectConfig);
_a.label = 4;
case 4: return [2 /*return*/];
return [3 /*break*/, 5];
case 4:
resolve(lastProjectConfig);
_a.label = 5;
case 5: return [2 /*return*/];
}

@@ -76,6 +81,11 @@ });

};
ConfigServiceBase.prototype.fetchLogic = function (options, lastProjectConfig, retries, callback) {
ConfigServiceBase.prototype.fetchLogic = function (options, lastEtag, retries, callback) {
var _this = this;
var calledBaseUrl = this.baseConfig.baseUrl;
this.fetchLogicInternal(this.baseConfig, lastProjectConfig, retries, function (newConfig) {
this.fetchLogicInternal(this.baseConfig, lastEtag, retries, function (result) {
if (result.status != index_1.FetchStatus.Fetched || ProjectConfig_1.ProjectConfig.compareEtags(lastEtag !== null && lastEtag !== void 0 ? lastEtag : '', result.eTag)) {
callback(null);
return;
}
var newConfig = new ProjectConfig_1.ProjectConfig(new Date().getTime(), result.responseBody, result.eTag);
if (!newConfig || !newConfig.ConfigJSON) {

@@ -119,10 +129,9 @@ callback(null);

}
_this.fetchLogic(options, lastProjectConfig, ++retries, callback);
_this.fetchLogic(options, lastEtag, ++retries, callback);
return;
});
};
ConfigServiceBase.prototype.fetchLogicInternal = function (options, lastProjectConfig, retries, callback) {
ConfigServiceBase.prototype.fetchLogicInternal = function (options, lastEtag, retries, callback) {
var _this = this;
if (retries === 0) {
// Only lock on the top-level calls, not on the recursive calls (config.json redirections).
if (retries === 0) { // Only lock on the top-level calls, not on the recursive calls (config.json redirections).
this.fetchLogicCallbacks.push(callback);

@@ -133,3 +142,3 @@ if (this.fetchLogicCallbacks.length > 1) {

}
this.configFetcher.fetchLogic(options, lastProjectConfig, function (newProjectConfig) {
this.configFetcher.fetchLogic(options, lastEtag, function (newProjectConfig) {
while (_this.fetchLogicCallbacks.length) {

@@ -145,3 +154,3 @@ var thisCallback = _this.fetchLogicCallbacks.pop();

// Recursive calls should call the fetchLogic as is.
this.configFetcher.fetchLogic(options, lastProjectConfig, callback);
this.configFetcher.fetchLogic(options, lastEtag, callback);
}

@@ -148,0 +157,0 @@ };

@@ -38,2 +38,6 @@ import { IConfigCatClient } from "./ConfigCatClient";

export interface IConfigCatLogger {
debug(message: string): void;
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
log(message: string): void;

@@ -45,2 +49,3 @@ info(message: string): void;

export declare enum LogLevel {
Debug = 4,
Info = 3,

@@ -58,4 +63,18 @@ Warn = 2,

}
export declare enum FetchStatus {
Fetched = 0,
NotModified = 1,
Errored = 2
}
export declare class FetchResult {
status: FetchStatus;
responseBody: string;
eTag?: string;
constructor(status: FetchStatus, responseBody: string, eTag?: string);
static success(responseBody: string, eTag: string): FetchResult;
static notModified(): FetchResult;
static error(): FetchResult;
}
export interface IConfigFetcher {
fetchLogic(options: OptionsBase, lastProjectConfig: ProjectConfig | null, callback: (newProjectConfig: ProjectConfig | null) => void): void;
fetchLogic(options: OptionsBase, lastEtag: string | null, callback: (result: FetchResult) => void): void;
}

@@ -70,2 +89,3 @@ export interface ICache {

export { User } from "./RolloutEvaluator";
export { IOverrideDataSource, FlagOverrides } from "./FlagOverrides";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.User = exports.DataGovernance = exports.OptionsBase = exports.ProjectConfig = exports.LogLevel = exports.createConsoleLogger = exports.createClientWithLazyLoad = exports.createClientWithManualPoll = exports.createClientWithAutoPoll = void 0;
exports.FlagOverrides = exports.User = exports.DataGovernance = exports.OptionsBase = exports.ProjectConfig = exports.FetchResult = exports.FetchStatus = exports.LogLevel = exports.createConsoleLogger = exports.createClientWithLazyLoad = exports.createClientWithManualPoll = exports.createClientWithAutoPoll = void 0;
var ConfigCatClient_1 = require("./ConfigCatClient");

@@ -44,2 +44,3 @@ var ConfigCatClientOptions_1 = require("./ConfigCatClientOptions");

(function (LogLevel) {
LogLevel[LogLevel["Debug"] = 4] = "Debug";
LogLevel[LogLevel["Info"] = 3] = "Info";

@@ -50,2 +51,26 @@ LogLevel[LogLevel["Warn"] = 2] = "Warn";

})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
var FetchStatus;
(function (FetchStatus) {
FetchStatus[FetchStatus["Fetched"] = 0] = "Fetched";
FetchStatus[FetchStatus["NotModified"] = 1] = "NotModified";
FetchStatus[FetchStatus["Errored"] = 2] = "Errored";
})(FetchStatus = exports.FetchStatus || (exports.FetchStatus = {}));
var FetchResult = /** @class */ (function () {
function FetchResult(status, responseBody, eTag) {
this.status = status;
this.responseBody = responseBody;
this.eTag = eTag;
}
FetchResult.success = function (responseBody, eTag) {
return new FetchResult(FetchStatus.Fetched, responseBody, eTag);
};
FetchResult.notModified = function () {
return new FetchResult(FetchStatus.NotModified, "");
};
FetchResult.error = function () {
return new FetchResult(FetchStatus.Errored, "");
};
return FetchResult;
}());
exports.FetchResult = FetchResult;
var ProjectConfig_1 = require("./ProjectConfig");

@@ -58,1 +83,3 @@ Object.defineProperty(exports, "ProjectConfig", { enumerable: true, get: function () { return ProjectConfig_1.ProjectConfig; } });

Object.defineProperty(exports, "User", { enumerable: true, get: function () { return RolloutEvaluator_1.User; } });
var FlagOverrides_1 = require("./FlagOverrides");
Object.defineProperty(exports, "FlagOverrides", { enumerable: true, get: function () { return FlagOverrides_1.FlagOverrides; } });

@@ -13,3 +13,7 @@ export declare class ProjectConfig {

static equals(projectConfig1: ProjectConfig | null, projectConfig2: ProjectConfig | null): boolean;
static compareEtags(etag1?: string, etag2?: string): boolean;
private static ensureStrictEtag;
getSettings(): {
[name: string]: Setting;
};
}

@@ -30,4 +34,10 @@ export declare class ConfigFile {

static VariationId: string;
value: any;
rolloutPercentageItems: RolloutPercentageItem[];
rolloutRules: RolloutRule[];
variationId: string;
constructor(value: any, rolloutPercentageItems: RolloutPercentageItem[], rolloutRules: RolloutRule[], variationId: string);
static fromJson(json: any): Setting;
}
export declare class RolloutRules {
export declare class RolloutRule {
static Order: string;

@@ -39,4 +49,11 @@ static ComparisonAttribute: string;

static VariationId: string;
comparisonAttribute: string;
comparator: number;
comparisonValue: string;
value: any;
variationId: string;
constructor(comparisonAttribute: string, comparator: number, comparisonValue: string, value: any, variationId: string);
static fromJson(json: any): RolloutRule;
}
export declare class RolloutPercentageItems {
export declare class RolloutPercentageItem {
static Order: string;

@@ -46,3 +63,8 @@ static Value: string;

static VariationId: string;
percentage: number;
value: any;
variationId: string;
constructor(percentage: number, value: any, variationId: string);
static fromJson(json: any): RolloutPercentageItem;
}
//# sourceMappingURL=ProjectConfig.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloutPercentageItems = exports.RolloutRules = exports.Setting = exports.Preferences = exports.ConfigFile = exports.ProjectConfig = void 0;
exports.RolloutPercentageItem = exports.RolloutRule = exports.Setting = exports.Preferences = exports.ConfigFile = exports.ProjectConfig = void 0;
var ProjectConfig = /** @class */ (function () {

@@ -16,4 +16,7 @@ function ProjectConfig(timeStamp, jsonConfig, httpETag) {

return false;
return (this.ensureStrictEtag(projectConfig1.HttpETag) === this.ensureStrictEtag(projectConfig2.HttpETag));
return this.compareEtags(projectConfig1.HttpETag, projectConfig2.HttpETag);
};
ProjectConfig.compareEtags = function (etag1, etag2) {
return this.ensureStrictEtag(etag1) === this.ensureStrictEtag(etag2);
};
ProjectConfig.ensureStrictEtag = function (etag) {

@@ -28,2 +31,8 @@ if (!etag) {

};
ProjectConfig.prototype.getSettings = function () {
return Object.fromEntries(Object.entries(this.ConfigJSON[ConfigFile.FeatureFlags]).map(function (_a) {
var key = _a[0], value = _a[1];
return [key, Setting.fromJson(value)];
}));
};
return ProjectConfig;

@@ -49,4 +58,12 @@ }());

var Setting = /** @class */ (function () {
function Setting() {
function Setting(value, rolloutPercentageItems, rolloutRules, variationId) {
this.value = value;
this.rolloutPercentageItems = rolloutPercentageItems;
this.rolloutRules = rolloutRules;
this.variationId = variationId;
}
Setting.fromJson = function (json) {
var _a, _b, _c, _d;
return new Setting(json[this.Value], (_b = (_a = json[this.RolloutPercentageItems]) === null || _a === void 0 ? void 0 : _a.map(function (item) { return RolloutPercentageItem.fromJson(item); })) !== null && _b !== void 0 ? _b : [], (_d = (_c = json[this.RolloutRules]) === null || _c === void 0 ? void 0 : _c.map(function (item) { return RolloutRule.fromJson(item); })) !== null && _d !== void 0 ? _d : [], json[this.VariationId]);
};
Setting.Value = "v";

@@ -60,23 +77,37 @@ Setting.SettingType = "t";

exports.Setting = Setting;
var RolloutRules = /** @class */ (function () {
function RolloutRules() {
var RolloutRule = /** @class */ (function () {
function RolloutRule(comparisonAttribute, comparator, comparisonValue, value, variationId) {
this.comparisonAttribute = comparisonAttribute;
this.comparator = comparator;
this.comparisonValue = comparisonValue;
this.value = value;
this.variationId = variationId;
}
RolloutRules.Order = "o";
RolloutRules.ComparisonAttribute = "a";
RolloutRules.Comparator = "t";
RolloutRules.ComparisonValue = "c";
RolloutRules.Value = "v";
RolloutRules.VariationId = "i";
return RolloutRules;
RolloutRule.fromJson = function (json) {
return new RolloutRule(json[this.ComparisonAttribute], json[this.Comparator], json[this.ComparisonValue], json[this.Value], json[this.VariationId]);
};
RolloutRule.Order = "o";
RolloutRule.ComparisonAttribute = "a";
RolloutRule.Comparator = "t";
RolloutRule.ComparisonValue = "c";
RolloutRule.Value = "v";
RolloutRule.VariationId = "i";
return RolloutRule;
}());
exports.RolloutRules = RolloutRules;
var RolloutPercentageItems = /** @class */ (function () {
function RolloutPercentageItems() {
exports.RolloutRule = RolloutRule;
var RolloutPercentageItem = /** @class */ (function () {
function RolloutPercentageItem(percentage, value, variationId) {
this.percentage = percentage;
this.value = value;
this.variationId = variationId;
}
RolloutPercentageItems.Order = "o";
RolloutPercentageItems.Value = "v";
RolloutPercentageItems.Percentage = "p";
RolloutPercentageItems.VariationId = "i";
return RolloutPercentageItems;
RolloutPercentageItem.fromJson = function (json) {
return new RolloutPercentageItem(json[this.Percentage], json[this.Value], json[this.VariationId]);
};
RolloutPercentageItem.Order = "o";
RolloutPercentageItem.Value = "v";
RolloutPercentageItem.Percentage = "p";
RolloutPercentageItem.VariationId = "i";
return RolloutPercentageItem;
}());
exports.RolloutPercentageItems = RolloutPercentageItems;
exports.RolloutPercentageItem = RolloutPercentageItem;
import { IConfigCatLogger } from "./index";
import { ProjectConfig } from "./ProjectConfig";
import { Setting } from "./ProjectConfig";
export interface IRolloutEvaluator {
Evaluate(config: ProjectConfig | null, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
Evaluate(settings: {
[name: string]: Setting;
}, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
}

@@ -25,3 +27,5 @@ /** Object for variation evaluation */

constructor(logger: IConfigCatLogger);
Evaluate(config: ProjectConfig | null, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
Evaluate(settings: {
[name: string]: Setting;
}, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
private EvaluateRules;

@@ -28,0 +32,0 @@ private EvaluateVariations;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloutEvaluator = exports.User = void 0;
var ProjectConfig_1 = require("./ProjectConfig");
var Sha1_1 = require("./Sha1");

@@ -25,15 +24,10 @@ var semver = require("./Semver");

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

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

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

@@ -59,4 +53,4 @@ }

else {
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)) {
if ((featureFlag.rolloutRules && featureFlag.rolloutRules.length > 0) ||
(featureFlag.rolloutPercentageItems && featureFlag.rolloutPercentageItems.length > 0)) {
var s = "Evaluating getValue('" + key + "'). ";

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

result.ValueAndVariationId = {
Value: featureFlag[ProjectConfig_1.Setting.Value],
VariationId: featureFlag[ProjectConfig_1.Setting.VariationId],
Value: featureFlag.value,
VariationId: featureFlag.variationId,
};

@@ -85,8 +79,8 @@ result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;

var rule = rolloutRules[i];
var comparisonAttribute = this_1.GetUserAttribute(user, rule[ProjectConfig_1.RolloutRules.ComparisonAttribute]);
var comparisonAttribute = this_1.GetUserAttribute(user, rule.comparisonAttribute);
if (!comparisonAttribute) {
return "continue";
}
var comparator = rule[ProjectConfig_1.RolloutRules.Comparator];
var comparisonValue = rule[ProjectConfig_1.RolloutRules.ComparisonValue];
var comparator = rule.comparator;
var comparisonValue = rule.comparisonValue;
var log = "Evaluating rule: '" + comparisonAttribute + "' " + this_1.RuleToString(comparator) + " '" + comparisonValue + "' => ";

@@ -101,4 +95,4 @@ switch (comparator) {

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -122,4 +116,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -133,8 +127,8 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

case 2: // contains
if (comparisonAttribute.search(comparisonValue) !== -1) {
if (comparisonAttribute.indexOf(comparisonValue) !== -1) {
log += "MATCH";
eLog.OpAppendLine(log);
result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -148,8 +142,8 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

case 3: // not contains
if (comparisonAttribute.search(comparisonValue) === -1) {
if (comparisonAttribute.indexOf(comparisonValue) === -1) {
log += "MATCH";
eLog.OpAppendLine(log);
result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -172,4 +166,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -192,4 +186,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -209,4 +203,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -230,4 +224,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -263,7 +257,7 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

var variation = rolloutPercentageItems[i];
bucket += +variation[ProjectConfig_1.RolloutPercentageItems.Percentage];
bucket += +variation.percentage;
if (hashScale < bucket) {
return {
Value: variation[ProjectConfig_1.RolloutPercentageItems.Value],
VariationId: variation[ProjectConfig_1.RolloutPercentageItems.VariationId]
Value: variation.value,
VariationId: variation.variationId
};

@@ -270,0 +264,0 @@ }

@@ -38,18 +38,18 @@ "use strict";

createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
createToken('MAINVERSION', "(" + src[t['NUMERICIDENTIFIER']] + ")\\." +
("(" + src[t['NUMERICIDENTIFIER']] + ")\\.") +
("(" + src[t['NUMERICIDENTIFIER']] + ")"));
createToken('MAINVERSIONLOOSE', "(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")\\." +
("(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")\\.") +
("(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")"));
createToken('PRERELEASEIDENTIFIER', "(?:" + src[t['NUMERICIDENTIFIER']] + "|" + src[t['NONNUMERICIDENTIFIER']] + ")");
createToken('PRERELEASEIDENTIFIERLOOSE', "(?:" + src[t['NUMERICIDENTIFIERLOOSE']] + "|" + src[t['NONNUMERICIDENTIFIER']] + ")");
createToken('PRERELEASE', "(?:-(" + src[t['PRERELEASEIDENTIFIER']] + "(?:\\." + src[t['PRERELEASEIDENTIFIER']] + ")*))");
createToken('PRERELEASELOOSE', "(?:-?(" + src[t['PRERELEASEIDENTIFIERLOOSE']] + "(?:\\." + src[t['PRERELEASEIDENTIFIERLOOSE']] + ")*))");
createToken('MAINVERSION', "(".concat(src[t['NUMERICIDENTIFIER']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIER']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIER']], ")"));
createToken('MAINVERSIONLOOSE', "(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")"));
createToken('PRERELEASEIDENTIFIER', "(?:".concat(src[t['NUMERICIDENTIFIER']], "|").concat(src[t['NONNUMERICIDENTIFIER']], ")"));
createToken('PRERELEASEIDENTIFIERLOOSE', "(?:".concat(src[t['NUMERICIDENTIFIERLOOSE']], "|").concat(src[t['NONNUMERICIDENTIFIER']], ")"));
createToken('PRERELEASE', "(?:-(".concat(src[t['PRERELEASEIDENTIFIER']], "(?:\\.").concat(src[t['PRERELEASEIDENTIFIER']], ")*))"));
createToken('PRERELEASELOOSE', "(?:-?(".concat(src[t['PRERELEASEIDENTIFIERLOOSE']], "(?:\\.").concat(src[t['PRERELEASEIDENTIFIERLOOSE']], ")*))"));
createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
createToken('BUILD', "(?:\\+(" + src[t['BUILDIDENTIFIER']] + "(?:\\." + src[t['BUILDIDENTIFIER']] + ")*))");
createToken('FULLPLAIN', "v?" + src[t['MAINVERSION']] + src[t['PRERELEASE']] + "?" + src[t['BUILD']] + "?");
createToken('FULL', "^" + src[t['FULLPLAIN']] + "$");
createToken('LOOSEPLAIN', "[v=\\s]*" + src[t['MAINVERSIONLOOSE']] + src[t['PRERELEASELOOSE']] + "?" + src[t['BUILD']] + "?");
createToken('LOOSE', "^" + src[t['LOOSEPLAIN']] + "$");
createToken('BUILD', "(?:\\+(".concat(src[t['BUILDIDENTIFIER']], "(?:\\.").concat(src[t['BUILDIDENTIFIER']], ")*))"));
createToken('FULLPLAIN', "v?".concat(src[t['MAINVERSION']]).concat(src[t['PRERELEASE']], "?").concat(src[t['BUILD']], "?"));
createToken('FULL', "^".concat(src[t['FULLPLAIN']], "$"));
createToken('LOOSEPLAIN', "[v=\\s]*".concat(src[t['MAINVERSIONLOOSE']]).concat(src[t['PRERELEASELOOSE']], "?").concat(src[t['BUILD']], "?"));
createToken('LOOSE', "^".concat(src[t['LOOSEPLAIN']], "$"));
var SemVer = /** @class */ (function () {

@@ -73,6 +73,6 @@ function SemVer(version, options) {

else if (typeof version !== 'string') {
throw new TypeError("Invalid Version: " + version);
throw new TypeError("Invalid Version: ".concat(version));
}
if (version.length > MAX_LENGTH) {
throw new TypeError("version is longer than " + MAX_LENGTH + " characters");
throw new TypeError("version is longer than ".concat(MAX_LENGTH, " characters"));
}

@@ -86,3 +86,3 @@ this.options = options;

if (!m) {
throw new TypeError("Invalid Version: " + version);
throw new TypeError("Invalid Version: ".concat(version));
}

@@ -122,5 +122,5 @@ this.raw = version;

SemVer.prototype.format = function () {
this.version = this.major + "." + this.minor + "." + this.patch;
this.version = "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
if (this.prerelease.length) {
this.version += "-" + this.prerelease.join('.');
this.version += "-".concat(this.prerelease.join('.'));
}

@@ -313,3 +313,3 @@ return this.version;

default:
throw new Error("invalid increment argument: " + release);
throw new Error("invalid increment argument: ".concat(release));
}

@@ -316,0 +316,0 @@ this.format();

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

@@ -37,3 +37,3 @@ import { IConfigCatKernel } from "./index";

export declare class ConfigCatClient implements IConfigCatClient {
private configService;
private configService?;
private evaluator;

@@ -57,2 +57,3 @@ private options;

getAllValuesAsync(user?: User): Promise<SettingKeyValue[]>;
private getSettings;
}

@@ -59,0 +60,0 @@ export declare class SettingKeyValue {

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -46,4 +57,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var ProjectConfig_1 = require("./ProjectConfig");
var FlagOverrides_1 = require("./FlagOverrides");
var ConfigCatClient = /** @class */ (function () {
function ConfigCatClient(options, configCatKernel) {
var _a;
if (!options) {

@@ -60,14 +73,16 @@ throw new Error("Invalid 'options' value");

this.evaluator = new RolloutEvaluator_1.RolloutEvaluator(options.logger);
if (options && options instanceof ConfigCatClientOptions_1.LazyLoadOptions) {
this.configService = new LazyLoadConfigService_1.LazyLoadConfigService(configCatKernel.configFetcher, options);
if (((_a = options === null || options === void 0 ? void 0 : options.flagOverrides) === null || _a === void 0 ? void 0 : _a.behaviour) != FlagOverrides_1.OverrideBehaviour.LocalOnly) {
if (options && options instanceof ConfigCatClientOptions_1.LazyLoadOptions) {
this.configService = new LazyLoadConfigService_1.LazyLoadConfigService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ConfigCatClientOptions_1.ManualPollOptions) {
this.configService = new ManualPollService_1.ManualPollService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ConfigCatClientOptions_1.AutoPollOptions) {
this.configService = new AutoPollConfigService_1.AutoPollConfigService(configCatKernel.configFetcher, options);
}
else {
throw new Error("Invalid 'options' value");
}
}
else if (options && options instanceof ConfigCatClientOptions_1.ManualPollOptions) {
this.configService = new ManualPollService_1.ManualPollService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ConfigCatClientOptions_1.AutoPollOptions) {
this.configService = new AutoPollConfigService_1.AutoPollConfigService(configCatKernel.configFetcher, options);
}
else {
throw new Error("Invalid 'options' value");
}
}

@@ -87,9 +102,14 @@ ConfigCatClient.prototype.dispose = function () {

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, result;
var settings, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
result = this.evaluator.Evaluate(config, key, defaultValue, user).Value;
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present. Returning default value: '" + defaultValue + "'.");
resolve(defaultValue);
return [2 /*return*/];
}
result = this.evaluator.Evaluate(settings, key, defaultValue, user).Value;
resolve(result);

@@ -109,7 +129,8 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.refreshConfigAsync()];
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, ((_a = this.configService) === null || _a === void 0 ? void 0 : _a.refreshConfigAsync())];
case 1:
_a.sent();
_b.sent();
resolve();

@@ -129,9 +150,9 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config;
var settings;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -141,3 +162,3 @@ resolve([]);

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

@@ -156,9 +177,14 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, result;
var settings, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
result = this.evaluator.Evaluate(config, key, null, user, defaultVariationId).VariationId;
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present. Returning default variationId: '" + defaultVariationId + "'.");
resolve(defaultVariationId);
return [2 /*return*/];
}
result = this.evaluator.Evaluate(settings, key, null, user, defaultVariationId).VariationId;
resolve(result);

@@ -207,9 +233,9 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, featureFlags, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
var settings, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -219,14 +245,13 @@ resolve(null);

}
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] });
for (settingKey in settings) {
if (variationId === settings[settingKey].variationId) {
resolve({ settingKey: settingKey, settingValue: settings[settingKey].value });
return [2 /*return*/];
}
rolloutRules = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutRules];
rolloutRules = settings[settingKey].rolloutRules;
if (rolloutRules && rolloutRules.length > 0) {
for (i = 0; i < rolloutRules.length; i++) {
rolloutRule = rolloutRules[i];
if (variationId === rolloutRule[ProjectConfig_1.RolloutRules.VariationId]) {
resolve({ settingKey: settingKey, settingValue: rolloutRule[ProjectConfig_1.RolloutRules.Value] });
if (variationId === rolloutRule.variationId) {
resolve({ settingKey: settingKey, settingValue: rolloutRule.value });
return [2 /*return*/];

@@ -236,8 +261,8 @@ }

}
percentageItems = featureFlags[settingKey][ProjectConfig_1.Setting.RolloutPercentageItems];
percentageItems = settings[settingKey].rolloutPercentageItems;
if (percentageItems && percentageItems.length > 0) {
for (i = 0; i < percentageItems.length; i++) {
percentageItem = percentageItems[i];
if (variationId === percentageItem[ProjectConfig_1.RolloutPercentageItems.VariationId]) {
resolve({ settingKey: settingKey, settingValue: percentageItem[ProjectConfig_1.RolloutPercentageItems.Value] });
if (variationId === percentageItem.variationId) {
resolve({ settingKey: settingKey, settingValue: percentageItem.value });
return [2 /*return*/];

@@ -263,10 +288,10 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, keys, result;
var settings, keys, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -276,3 +301,3 @@ resolve([]);

}
keys = Object.keys(config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]);
keys = Object.keys(settings);
result = [];

@@ -282,3 +307,3 @@ keys.forEach(function (key) {

settingKey: key,
settingValue: _this.evaluator.Evaluate(config, key, undefined, user).Value
settingValue: _this.evaluator.Evaluate(settings, key, undefined, user).Value
});

@@ -292,2 +317,44 @@ });

};
ConfigCatClient.prototype.getSettings = function () {
var _this = this;
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var localSettings, config_1, remoteSettings, config;
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.flagOverrides)) return [3 /*break*/, 3];
return [4 /*yield*/, this.options.flagOverrides.dataSource.getOverrides()];
case 1:
localSettings = _e.sent();
if (this.options.flagOverrides.behaviour == FlagOverrides_1.OverrideBehaviour.LocalOnly) {
resolve(localSettings);
return [2 /*return*/];
}
return [4 /*yield*/, ((_b = this.configService) === null || _b === void 0 ? void 0 : _b.getConfig())];
case 2:
config_1 = _e.sent();
remoteSettings = (_c = config_1 === null || config_1 === void 0 ? void 0 : config_1.getSettings()) !== null && _c !== void 0 ? _c : {};
if (this.options.flagOverrides.behaviour == FlagOverrides_1.OverrideBehaviour.LocalOverRemote) {
resolve(__assign(__assign({}, remoteSettings), localSettings));
return [2 /*return*/];
}
else if (this.options.flagOverrides.behaviour == FlagOverrides_1.OverrideBehaviour.RemoteOverLocal) {
resolve(__assign(__assign({}, localSettings), remoteSettings));
return [2 /*return*/];
}
_e.label = 3;
case 3: return [4 /*yield*/, ((_d = this.configService) === null || _d === void 0 ? void 0 : _d.getConfig())];
case 4:
config = _e.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ProjectConfig_1.ConfigFile.FeatureFlags]) {
resolve(null);
return [2 /*return*/];
}
resolve(config.getSettings());
return [2 /*return*/];
}
});
}); });
};
return ConfigCatClient;

@@ -294,0 +361,0 @@ }());

import { IConfigCatLogger, IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions, ICache } from "./index";
import { FlagOverrides } from "./FlagOverrides";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */

@@ -22,2 +23,3 @@ export declare enum DataGovernance {

cache?: ICache | null;
flagOverrides?: FlagOverrides | null;
}

@@ -35,2 +37,3 @@ export declare abstract class OptionsBase implements IOptions {

cache: ICache;
flagOverrides?: FlagOverrides;
constructor(apiKey: string, clientVersion: string, options?: IOptions | null, defaultCache?: ICache | null);

@@ -37,0 +40,0 @@ getUrl(): string;

@@ -77,2 +77,5 @@ "use strict";

}
if (options.flagOverrides) {
this.flagOverrides = options.flagOverrides;
}
}

@@ -79,0 +82,0 @@ }

@@ -9,3 +9,7 @@ import { IConfigCatLogger, LogLevel } from "./index";

constructor(logLevel: LogLevel);
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
log(message: string): void;
debug(message: string): void;
info(message: string): void;

@@ -12,0 +16,0 @@ warn(message: string): void;

@@ -16,5 +16,13 @@ "use strict";

}
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
ConfigCatConsoleLogger.prototype.log = function (message) {
this.info(message);
};
ConfigCatConsoleLogger.prototype.debug = function (message) {
if (this.isLogLevelEnabled(index_1.LogLevel.Debug)) {
console.info(this.SOURCE + " - DEBUG - " + message);
}
};
ConfigCatConsoleLogger.prototype.info = function (message) {

@@ -21,0 +29,0 @@ if (this.isLogLevelEnabled(index_1.LogLevel.Info)) {

@@ -11,3 +11,2 @@ import { IConfigFetcher } from "./index";

protected baseConfig: OptionsBase;
private fetchLogicLock;
private fetchLogicCallbacks;

@@ -14,0 +13,0 @@ constructor(configFetcher: IConfigFetcher, baseConfig: OptionsBase);

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

exports.ConfigServiceBase = void 0;
var index_1 = require("./index");
var ProjectConfig_1 = require("./ProjectConfig");
var ConfigServiceBase = /** @class */ (function () {
function ConfigServiceBase(configFetcher, baseConfig) {
this.fetchLogicLock = false;
this.fetchLogicCallbacks = [];

@@ -53,19 +53,24 @@ this.configFetcher = configFetcher;

return new Promise(function (resolve) {
_this.fetchLogic(_this.baseConfig, lastProjectConfig, 0, function (newConfig) { return __awaiter(_this, void 0, void 0, function () {
var _a;
_this.fetchLogic(_this.baseConfig, (_a = lastProjectConfig === null || lastProjectConfig === void 0 ? void 0 : lastProjectConfig.HttpETag) !== null && _a !== void 0 ? _a : null, 0, function (newConfig) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(newConfig && newConfig.ConfigJSON)) return [3 /*break*/, 3];
if (!(forceUpdateCache || !ProjectConfig_1.ProjectConfig.equals(newConfig, lastProjectConfig))) return [3 /*break*/, 2];
if (!(newConfig && newConfig.ConfigJSON)) return [3 /*break*/, 2];
return [4 /*yield*/, this.baseConfig.cache.set(this.baseConfig.getCacheKey(), newConfig)];
case 1:
_a.sent();
_a.label = 2;
resolve(newConfig);
return [3 /*break*/, 5];
case 2:
resolve(newConfig);
return [3 /*break*/, 4];
if (!(forceUpdateCache && lastProjectConfig && lastProjectConfig.ConfigJSON)) return [3 /*break*/, 4];
return [4 /*yield*/, this.baseConfig.cache.set(this.baseConfig.getCacheKey(), lastProjectConfig)];
case 3:
_a.sent();
resolve(lastProjectConfig);
_a.label = 4;
case 4: return [2 /*return*/];
return [3 /*break*/, 5];
case 4:
resolve(lastProjectConfig);
_a.label = 5;
case 5: return [2 /*return*/];
}

@@ -76,6 +81,11 @@ });

};
ConfigServiceBase.prototype.fetchLogic = function (options, lastProjectConfig, retries, callback) {
ConfigServiceBase.prototype.fetchLogic = function (options, lastEtag, retries, callback) {
var _this = this;
var calledBaseUrl = this.baseConfig.baseUrl;
this.fetchLogicInternal(this.baseConfig, lastProjectConfig, retries, function (newConfig) {
this.fetchLogicInternal(this.baseConfig, lastEtag, retries, function (result) {
if (result.status != index_1.FetchStatus.Fetched || ProjectConfig_1.ProjectConfig.compareEtags(lastEtag !== null && lastEtag !== void 0 ? lastEtag : '', result.eTag)) {
callback(null);
return;
}
var newConfig = new ProjectConfig_1.ProjectConfig(new Date().getTime(), result.responseBody, result.eTag);
if (!newConfig || !newConfig.ConfigJSON) {

@@ -119,10 +129,9 @@ callback(null);

}
_this.fetchLogic(options, lastProjectConfig, ++retries, callback);
_this.fetchLogic(options, lastEtag, ++retries, callback);
return;
});
};
ConfigServiceBase.prototype.fetchLogicInternal = function (options, lastProjectConfig, retries, callback) {
ConfigServiceBase.prototype.fetchLogicInternal = function (options, lastEtag, retries, callback) {
var _this = this;
if (retries === 0) {
// Only lock on the top-level calls, not on the recursive calls (config.json redirections).
if (retries === 0) { // Only lock on the top-level calls, not on the recursive calls (config.json redirections).
this.fetchLogicCallbacks.push(callback);

@@ -133,3 +142,3 @@ if (this.fetchLogicCallbacks.length > 1) {

}
this.configFetcher.fetchLogic(options, lastProjectConfig, function (newProjectConfig) {
this.configFetcher.fetchLogic(options, lastEtag, function (newProjectConfig) {
while (_this.fetchLogicCallbacks.length) {

@@ -145,3 +154,3 @@ var thisCallback = _this.fetchLogicCallbacks.pop();

// Recursive calls should call the fetchLogic as is.
this.configFetcher.fetchLogic(options, lastProjectConfig, callback);
this.configFetcher.fetchLogic(options, lastEtag, callback);
}

@@ -148,0 +157,0 @@ };

@@ -17,2 +17,3 @@ import { AutoPollOptions } from "./ConfigCatClientOptions";

private startRefreshWorker;
private refreshWorkerLogic;
private tryReadFromCache;

@@ -19,0 +20,0 @@ private sleep;

@@ -118,8 +118,14 @@ var __extends = (this && this.__extends) || (function () {

var _this = this;
this.refreshLogic(true).then(function (_) {
setTimeout(function () { return _this.refreshWorkerLogic(delay); }, delay);
});
};
AutoPollConfigService.prototype.refreshWorkerLogic = function (delay) {
var _this = this;
if (this.disposed) {
return;
}
this.refreshLogic(false).then(function (_) {
if (_this.disposed) {
return;
}
_this.timerId = setTimeout(function () {
_this.startRefreshWorker(delay);
_this.refreshWorkerLogic(delay);
}, delay);

@@ -126,0 +132,0 @@ });

@@ -37,3 +37,3 @@ import { IConfigCatKernel } from "./index";

export declare class ConfigCatClient implements IConfigCatClient {
private configService;
private configService?;
private evaluator;

@@ -57,2 +57,3 @@ private options;

getAllValuesAsync(user?: User): Promise<SettingKeyValue[]>;
private getSettings;
}

@@ -59,0 +60,0 @@ export declare class SettingKeyValue {

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

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -42,5 +53,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

import { RolloutEvaluator } from "./RolloutEvaluator";
import { Setting, RolloutRules, RolloutPercentageItems, ConfigFile } from "./ProjectConfig";
import { ConfigFile } from "./ProjectConfig";
import { OverrideBehaviour } from "./FlagOverrides";
var ConfigCatClient = /** @class */ (function () {
function ConfigCatClient(options, configCatKernel) {
var _a;
if (!options) {

@@ -57,14 +70,16 @@ throw new Error("Invalid 'options' value");

this.evaluator = new RolloutEvaluator(options.logger);
if (options && options instanceof LazyLoadOptions) {
this.configService = new LazyLoadConfigService(configCatKernel.configFetcher, options);
if (((_a = options === null || options === void 0 ? void 0 : options.flagOverrides) === null || _a === void 0 ? void 0 : _a.behaviour) != OverrideBehaviour.LocalOnly) {
if (options && options instanceof LazyLoadOptions) {
this.configService = new LazyLoadConfigService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof ManualPollOptions) {
this.configService = new ManualPollService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof AutoPollOptions) {
this.configService = new AutoPollConfigService(configCatKernel.configFetcher, options);
}
else {
throw new Error("Invalid 'options' value");
}
}
else if (options && options instanceof ManualPollOptions) {
this.configService = new ManualPollService(configCatKernel.configFetcher, options);
}
else if (options && options instanceof AutoPollOptions) {
this.configService = new AutoPollConfigService(configCatKernel.configFetcher, options);
}
else {
throw new Error("Invalid 'options' value");
}
}

@@ -84,9 +99,14 @@ ConfigCatClient.prototype.dispose = function () {

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, result;
var settings, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
result = this.evaluator.Evaluate(config, key, defaultValue, user).Value;
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present. Returning default value: '" + defaultValue + "'.");
resolve(defaultValue);
return [2 /*return*/];
}
result = this.evaluator.Evaluate(settings, key, defaultValue, user).Value;
resolve(result);

@@ -106,7 +126,8 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.refreshConfigAsync()];
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, ((_a = this.configService) === null || _a === void 0 ? void 0 : _a.refreshConfigAsync())];
case 1:
_a.sent();
_b.sent();
resolve();

@@ -126,9 +147,9 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config;
var settings;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -138,3 +159,3 @@ resolve([]);

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

@@ -153,9 +174,14 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, result;
var settings, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
result = this.evaluator.Evaluate(config, key, null, user, defaultVariationId).VariationId;
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present. Returning default variationId: '" + defaultVariationId + "'.");
resolve(defaultVariationId);
return [2 /*return*/];
}
result = this.evaluator.Evaluate(settings, key, null, user, defaultVariationId).VariationId;
resolve(result);

@@ -204,9 +230,9 @@ return [2 /*return*/];

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, featureFlags, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
var settings, settingKey, rolloutRules, i, rolloutRule, percentageItems, i, percentageItem;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -216,14 +242,13 @@ resolve(null);

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

@@ -233,8 +258,8 @@ }

}
percentageItems = featureFlags[settingKey][Setting.RolloutPercentageItems];
percentageItems = settings[settingKey].rolloutPercentageItems;
if (percentageItems && percentageItems.length > 0) {
for (i = 0; i < percentageItems.length; i++) {
percentageItem = percentageItems[i];
if (variationId === percentageItem[RolloutPercentageItems.VariationId]) {
resolve({ settingKey: settingKey, settingValue: percentageItem[RolloutPercentageItems.Value] });
if (variationId === percentageItem.variationId) {
resolve({ settingKey: settingKey, settingValue: percentageItem.value });
return [2 /*return*/];

@@ -260,10 +285,10 @@ }

return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var config, keys, result;
var settings, keys, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.configService.getConfig()];
case 0: return [4 /*yield*/, this.getSettings()];
case 1:
config = _a.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
settings = _a.sent();
if (!settings) {
this.options.logger.error("config.json is not present, returning empty array");

@@ -273,3 +298,3 @@ resolve([]);

}
keys = Object.keys(config.ConfigJSON[ConfigFile.FeatureFlags]);
keys = Object.keys(settings);
result = [];

@@ -279,3 +304,3 @@ keys.forEach(function (key) {

settingKey: key,
settingValue: _this.evaluator.Evaluate(config, key, undefined, user).Value
settingValue: _this.evaluator.Evaluate(settings, key, undefined, user).Value
});

@@ -289,2 +314,44 @@ });

};
ConfigCatClient.prototype.getSettings = function () {
var _this = this;
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var localSettings, config_1, remoteSettings, config;
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.flagOverrides)) return [3 /*break*/, 3];
return [4 /*yield*/, this.options.flagOverrides.dataSource.getOverrides()];
case 1:
localSettings = _e.sent();
if (this.options.flagOverrides.behaviour == OverrideBehaviour.LocalOnly) {
resolve(localSettings);
return [2 /*return*/];
}
return [4 /*yield*/, ((_b = this.configService) === null || _b === void 0 ? void 0 : _b.getConfig())];
case 2:
config_1 = _e.sent();
remoteSettings = (_c = config_1 === null || config_1 === void 0 ? void 0 : config_1.getSettings()) !== null && _c !== void 0 ? _c : {};
if (this.options.flagOverrides.behaviour == OverrideBehaviour.LocalOverRemote) {
resolve(__assign(__assign({}, remoteSettings), localSettings));
return [2 /*return*/];
}
else if (this.options.flagOverrides.behaviour == OverrideBehaviour.RemoteOverLocal) {
resolve(__assign(__assign({}, localSettings), remoteSettings));
return [2 /*return*/];
}
_e.label = 3;
case 3: return [4 /*yield*/, ((_d = this.configService) === null || _d === void 0 ? void 0 : _d.getConfig())];
case 4:
config = _e.sent();
if (!config || !config.ConfigJSON || !config.ConfigJSON[ConfigFile.FeatureFlags]) {
resolve(null);
return [2 /*return*/];
}
resolve(config.getSettings());
return [2 /*return*/];
}
});
}); });
};
return ConfigCatClient;

@@ -291,0 +358,0 @@ }());

import { IConfigCatLogger, IAutoPollOptions, ILazyLoadingOptions, IManualPollOptions, ICache } from "./index";
import { FlagOverrides } from "./FlagOverrides";
/** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */

@@ -22,2 +23,3 @@ export declare enum DataGovernance {

cache?: ICache | null;
flagOverrides?: FlagOverrides | null;
}

@@ -35,2 +37,3 @@ export declare abstract class OptionsBase implements IOptions {

cache: ICache;
flagOverrides?: FlagOverrides;
constructor(apiKey: string, clientVersion: string, options?: IOptions | null, defaultCache?: ICache | null);

@@ -37,0 +40,0 @@ getUrl(): string;

@@ -74,2 +74,5 @@ var __extends = (this && this.__extends) || (function () {

}
if (options.flagOverrides) {
this.flagOverrides = options.flagOverrides;
}
}

@@ -76,0 +79,0 @@ }

@@ -9,3 +9,7 @@ import { IConfigCatLogger, LogLevel } from "./index";

constructor(logLevel: LogLevel);
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
log(message: string): void;
debug(message: string): void;
info(message: string): void;

@@ -12,0 +16,0 @@ warn(message: string): void;

@@ -13,5 +13,13 @@ import { LogLevel } from "./index";

}
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
ConfigCatConsoleLogger.prototype.log = function (message) {
this.info(message);
};
ConfigCatConsoleLogger.prototype.debug = function (message) {
if (this.isLogLevelEnabled(LogLevel.Debug)) {
console.info(this.SOURCE + " - DEBUG - " + message);
}
};
ConfigCatConsoleLogger.prototype.info = function (message) {

@@ -18,0 +26,0 @@ if (this.isLogLevelEnabled(LogLevel.Info)) {

@@ -11,3 +11,2 @@ import { IConfigFetcher } from "./index";

protected baseConfig: OptionsBase;
private fetchLogicLock;
private fetchLogicCallbacks;

@@ -14,0 +13,0 @@ constructor(configFetcher: IConfigFetcher, baseConfig: OptionsBase);

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

};
import { FetchStatus } from "./index";
import { ConfigFile, Preferences, ProjectConfig } from "./ProjectConfig";
var ConfigServiceBase = /** @class */ (function () {
function ConfigServiceBase(configFetcher, baseConfig) {
this.fetchLogicLock = false;
this.fetchLogicCallbacks = [];

@@ -50,19 +50,24 @@ this.configFetcher = configFetcher;

return new Promise(function (resolve) {
_this.fetchLogic(_this.baseConfig, lastProjectConfig, 0, function (newConfig) { return __awaiter(_this, void 0, void 0, function () {
var _a;
_this.fetchLogic(_this.baseConfig, (_a = lastProjectConfig === null || lastProjectConfig === void 0 ? void 0 : lastProjectConfig.HttpETag) !== null && _a !== void 0 ? _a : null, 0, function (newConfig) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(newConfig && newConfig.ConfigJSON)) return [3 /*break*/, 3];
if (!(forceUpdateCache || !ProjectConfig.equals(newConfig, lastProjectConfig))) return [3 /*break*/, 2];
if (!(newConfig && newConfig.ConfigJSON)) return [3 /*break*/, 2];
return [4 /*yield*/, this.baseConfig.cache.set(this.baseConfig.getCacheKey(), newConfig)];
case 1:
_a.sent();
_a.label = 2;
resolve(newConfig);
return [3 /*break*/, 5];
case 2:
resolve(newConfig);
return [3 /*break*/, 4];
if (!(forceUpdateCache && lastProjectConfig && lastProjectConfig.ConfigJSON)) return [3 /*break*/, 4];
return [4 /*yield*/, this.baseConfig.cache.set(this.baseConfig.getCacheKey(), lastProjectConfig)];
case 3:
_a.sent();
resolve(lastProjectConfig);
_a.label = 4;
case 4: return [2 /*return*/];
return [3 /*break*/, 5];
case 4:
resolve(lastProjectConfig);
_a.label = 5;
case 5: return [2 /*return*/];
}

@@ -73,6 +78,11 @@ });

};
ConfigServiceBase.prototype.fetchLogic = function (options, lastProjectConfig, retries, callback) {
ConfigServiceBase.prototype.fetchLogic = function (options, lastEtag, retries, callback) {
var _this = this;
var calledBaseUrl = this.baseConfig.baseUrl;
this.fetchLogicInternal(this.baseConfig, lastProjectConfig, retries, function (newConfig) {
this.fetchLogicInternal(this.baseConfig, lastEtag, retries, function (result) {
if (result.status != FetchStatus.Fetched || ProjectConfig.compareEtags(lastEtag !== null && lastEtag !== void 0 ? lastEtag : '', result.eTag)) {
callback(null);
return;
}
var newConfig = new ProjectConfig(new Date().getTime(), result.responseBody, result.eTag);
if (!newConfig || !newConfig.ConfigJSON) {

@@ -116,10 +126,9 @@ callback(null);

}
_this.fetchLogic(options, lastProjectConfig, ++retries, callback);
_this.fetchLogic(options, lastEtag, ++retries, callback);
return;
});
};
ConfigServiceBase.prototype.fetchLogicInternal = function (options, lastProjectConfig, retries, callback) {
ConfigServiceBase.prototype.fetchLogicInternal = function (options, lastEtag, retries, callback) {
var _this = this;
if (retries === 0) {
// Only lock on the top-level calls, not on the recursive calls (config.json redirections).
if (retries === 0) { // Only lock on the top-level calls, not on the recursive calls (config.json redirections).
this.fetchLogicCallbacks.push(callback);

@@ -130,3 +139,3 @@ if (this.fetchLogicCallbacks.length > 1) {

}
this.configFetcher.fetchLogic(options, lastProjectConfig, function (newProjectConfig) {
this.configFetcher.fetchLogic(options, lastEtag, function (newProjectConfig) {
while (_this.fetchLogicCallbacks.length) {

@@ -142,3 +151,3 @@ var thisCallback = _this.fetchLogicCallbacks.pop();

// Recursive calls should call the fetchLogic as is.
this.configFetcher.fetchLogic(options, lastProjectConfig, callback);
this.configFetcher.fetchLogic(options, lastEtag, callback);
}

@@ -145,0 +154,0 @@ };

@@ -38,2 +38,6 @@ import { IConfigCatClient } from "./ConfigCatClient";

export interface IConfigCatLogger {
debug(message: string): void;
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
log(message: string): void;

@@ -45,2 +49,3 @@ info(message: string): void;

export declare enum LogLevel {
Debug = 4,
Info = 3,

@@ -58,4 +63,18 @@ Warn = 2,

}
export declare enum FetchStatus {
Fetched = 0,
NotModified = 1,
Errored = 2
}
export declare class FetchResult {
status: FetchStatus;
responseBody: string;
eTag?: string;
constructor(status: FetchStatus, responseBody: string, eTag?: string);
static success(responseBody: string, eTag: string): FetchResult;
static notModified(): FetchResult;
static error(): FetchResult;
}
export interface IConfigFetcher {
fetchLogic(options: OptionsBase, lastProjectConfig: ProjectConfig | null, callback: (newProjectConfig: ProjectConfig | null) => void): void;
fetchLogic(options: OptionsBase, lastEtag: string | null, callback: (result: FetchResult) => void): void;
}

@@ -70,2 +89,3 @@ export interface ICache {

export { User } from "./RolloutEvaluator";
export { IOverrideDataSource, FlagOverrides } from "./FlagOverrides";
//# sourceMappingURL=index.d.ts.map

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

(function (LogLevel) {
LogLevel[LogLevel["Debug"] = 4] = "Debug";
LogLevel[LogLevel["Info"] = 3] = "Info";

@@ -43,4 +44,29 @@ LogLevel[LogLevel["Warn"] = 2] = "Warn";

})(LogLevel || (LogLevel = {}));
export var FetchStatus;
(function (FetchStatus) {
FetchStatus[FetchStatus["Fetched"] = 0] = "Fetched";
FetchStatus[FetchStatus["NotModified"] = 1] = "NotModified";
FetchStatus[FetchStatus["Errored"] = 2] = "Errored";
})(FetchStatus || (FetchStatus = {}));
var FetchResult = /** @class */ (function () {
function FetchResult(status, responseBody, eTag) {
this.status = status;
this.responseBody = responseBody;
this.eTag = eTag;
}
FetchResult.success = function (responseBody, eTag) {
return new FetchResult(FetchStatus.Fetched, responseBody, eTag);
};
FetchResult.notModified = function () {
return new FetchResult(FetchStatus.NotModified, "");
};
FetchResult.error = function () {
return new FetchResult(FetchStatus.Errored, "");
};
return FetchResult;
}());
export { FetchResult };
export { ProjectConfig } from "./ProjectConfig";
export { OptionsBase, DataGovernance } from "./ConfigCatClientOptions";
export { User } from "./RolloutEvaluator";
export { FlagOverrides } from "./FlagOverrides";

@@ -13,3 +13,7 @@ export declare class ProjectConfig {

static equals(projectConfig1: ProjectConfig | null, projectConfig2: ProjectConfig | null): boolean;
static compareEtags(etag1?: string, etag2?: string): boolean;
private static ensureStrictEtag;
getSettings(): {
[name: string]: Setting;
};
}

@@ -30,4 +34,10 @@ export declare class ConfigFile {

static VariationId: string;
value: any;
rolloutPercentageItems: RolloutPercentageItem[];
rolloutRules: RolloutRule[];
variationId: string;
constructor(value: any, rolloutPercentageItems: RolloutPercentageItem[], rolloutRules: RolloutRule[], variationId: string);
static fromJson(json: any): Setting;
}
export declare class RolloutRules {
export declare class RolloutRule {
static Order: string;

@@ -39,4 +49,11 @@ static ComparisonAttribute: string;

static VariationId: string;
comparisonAttribute: string;
comparator: number;
comparisonValue: string;
value: any;
variationId: string;
constructor(comparisonAttribute: string, comparator: number, comparisonValue: string, value: any, variationId: string);
static fromJson(json: any): RolloutRule;
}
export declare class RolloutPercentageItems {
export declare class RolloutPercentageItem {
static Order: string;

@@ -46,3 +63,8 @@ static Value: string;

static VariationId: string;
percentage: number;
value: any;
variationId: string;
constructor(percentage: number, value: any, variationId: string);
static fromJson(json: any): RolloutPercentageItem;
}
//# sourceMappingURL=ProjectConfig.d.ts.map

@@ -13,4 +13,7 @@ var ProjectConfig = /** @class */ (function () {

return false;
return (this.ensureStrictEtag(projectConfig1.HttpETag) === this.ensureStrictEtag(projectConfig2.HttpETag));
return this.compareEtags(projectConfig1.HttpETag, projectConfig2.HttpETag);
};
ProjectConfig.compareEtags = function (etag1, etag2) {
return this.ensureStrictEtag(etag1) === this.ensureStrictEtag(etag2);
};
ProjectConfig.ensureStrictEtag = function (etag) {

@@ -25,2 +28,8 @@ if (!etag) {

};
ProjectConfig.prototype.getSettings = function () {
return Object.fromEntries(Object.entries(this.ConfigJSON[ConfigFile.FeatureFlags]).map(function (_a) {
var key = _a[0], value = _a[1];
return [key, Setting.fromJson(value)];
}));
};
return ProjectConfig;

@@ -46,4 +55,12 @@ }());

var Setting = /** @class */ (function () {
function Setting() {
function Setting(value, rolloutPercentageItems, rolloutRules, variationId) {
this.value = value;
this.rolloutPercentageItems = rolloutPercentageItems;
this.rolloutRules = rolloutRules;
this.variationId = variationId;
}
Setting.fromJson = function (json) {
var _a, _b, _c, _d;
return new Setting(json[this.Value], (_b = (_a = json[this.RolloutPercentageItems]) === null || _a === void 0 ? void 0 : _a.map(function (item) { return RolloutPercentageItem.fromJson(item); })) !== null && _b !== void 0 ? _b : [], (_d = (_c = json[this.RolloutRules]) === null || _c === void 0 ? void 0 : _c.map(function (item) { return RolloutRule.fromJson(item); })) !== null && _d !== void 0 ? _d : [], json[this.VariationId]);
};
Setting.Value = "v";

@@ -57,23 +74,37 @@ Setting.SettingType = "t";

export { Setting };
var RolloutRules = /** @class */ (function () {
function RolloutRules() {
var RolloutRule = /** @class */ (function () {
function RolloutRule(comparisonAttribute, comparator, comparisonValue, value, variationId) {
this.comparisonAttribute = comparisonAttribute;
this.comparator = comparator;
this.comparisonValue = comparisonValue;
this.value = value;
this.variationId = variationId;
}
RolloutRules.Order = "o";
RolloutRules.ComparisonAttribute = "a";
RolloutRules.Comparator = "t";
RolloutRules.ComparisonValue = "c";
RolloutRules.Value = "v";
RolloutRules.VariationId = "i";
return RolloutRules;
RolloutRule.fromJson = function (json) {
return new RolloutRule(json[this.ComparisonAttribute], json[this.Comparator], json[this.ComparisonValue], json[this.Value], json[this.VariationId]);
};
RolloutRule.Order = "o";
RolloutRule.ComparisonAttribute = "a";
RolloutRule.Comparator = "t";
RolloutRule.ComparisonValue = "c";
RolloutRule.Value = "v";
RolloutRule.VariationId = "i";
return RolloutRule;
}());
export { RolloutRules };
var RolloutPercentageItems = /** @class */ (function () {
function RolloutPercentageItems() {
export { RolloutRule };
var RolloutPercentageItem = /** @class */ (function () {
function RolloutPercentageItem(percentage, value, variationId) {
this.percentage = percentage;
this.value = value;
this.variationId = variationId;
}
RolloutPercentageItems.Order = "o";
RolloutPercentageItems.Value = "v";
RolloutPercentageItems.Percentage = "p";
RolloutPercentageItems.VariationId = "i";
return RolloutPercentageItems;
RolloutPercentageItem.fromJson = function (json) {
return new RolloutPercentageItem(json[this.Percentage], json[this.Value], json[this.VariationId]);
};
RolloutPercentageItem.Order = "o";
RolloutPercentageItem.Value = "v";
RolloutPercentageItem.Percentage = "p";
RolloutPercentageItem.VariationId = "i";
return RolloutPercentageItem;
}());
export { RolloutPercentageItems };
export { RolloutPercentageItem };
import { IConfigCatLogger } from "./index";
import { ProjectConfig } from "./ProjectConfig";
import { Setting } from "./ProjectConfig";
export interface IRolloutEvaluator {
Evaluate(config: ProjectConfig | null, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
Evaluate(settings: {
[name: string]: Setting;
}, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
}

@@ -25,3 +27,5 @@ /** Object for variation evaluation */

constructor(logger: IConfigCatLogger);
Evaluate(config: ProjectConfig | null, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
Evaluate(settings: {
[name: string]: Setting;
}, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
private EvaluateRules;

@@ -28,0 +32,0 @@ private EvaluateVariations;

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

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

@@ -22,15 +21,10 @@ import * as semver from "./Semver";

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

@@ -43,9 +37,9 @@ eLog.User = user;

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

@@ -56,4 +50,4 @@ }

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

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

result.ValueAndVariationId = {
Value: featureFlag[Setting.Value],
VariationId: featureFlag[Setting.VariationId],
Value: featureFlag.value,
VariationId: featureFlag.variationId,
};

@@ -82,8 +76,8 @@ result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;

var rule = rolloutRules[i];
var comparisonAttribute = this_1.GetUserAttribute(user, rule[RolloutRules.ComparisonAttribute]);
var comparisonAttribute = this_1.GetUserAttribute(user, rule.comparisonAttribute);
if (!comparisonAttribute) {
return "continue";
}
var comparator = rule[RolloutRules.Comparator];
var comparisonValue = rule[RolloutRules.ComparisonValue];
var comparator = rule.comparator;
var comparisonValue = rule.comparisonValue;
var log = "Evaluating rule: '" + comparisonAttribute + "' " + this_1.RuleToString(comparator) + " '" + comparisonValue + "' => ";

@@ -98,4 +92,4 @@ switch (comparator) {

result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -119,4 +113,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -130,8 +124,8 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

case 2: // contains
if (comparisonAttribute.search(comparisonValue) !== -1) {
if (comparisonAttribute.indexOf(comparisonValue) !== -1) {
log += "MATCH";
eLog.OpAppendLine(log);
result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -145,8 +139,8 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

case 3: // not contains
if (comparisonAttribute.search(comparisonValue) === -1) {
if (comparisonAttribute.indexOf(comparisonValue) === -1) {
log += "MATCH";
eLog.OpAppendLine(log);
result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -169,4 +163,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -189,4 +183,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -206,4 +200,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -227,4 +221,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[RolloutRules.Value],
VariationId: rule[RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -260,7 +254,7 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

var variation = rolloutPercentageItems[i];
bucket += +variation[RolloutPercentageItems.Percentage];
bucket += +variation.percentage;
if (hashScale < bucket) {
return {
Value: variation[RolloutPercentageItems.Value],
VariationId: variation[RolloutPercentageItems.VariationId]
Value: variation.value,
VariationId: variation.variationId
};

@@ -267,0 +261,0 @@ }

@@ -35,18 +35,18 @@ var numeric = /^[0-9]+$/;

createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
createToken('MAINVERSION', "(" + src[t['NUMERICIDENTIFIER']] + ")\\." +
("(" + src[t['NUMERICIDENTIFIER']] + ")\\.") +
("(" + src[t['NUMERICIDENTIFIER']] + ")"));
createToken('MAINVERSIONLOOSE', "(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")\\." +
("(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")\\.") +
("(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")"));
createToken('PRERELEASEIDENTIFIER', "(?:" + src[t['NUMERICIDENTIFIER']] + "|" + src[t['NONNUMERICIDENTIFIER']] + ")");
createToken('PRERELEASEIDENTIFIERLOOSE', "(?:" + src[t['NUMERICIDENTIFIERLOOSE']] + "|" + src[t['NONNUMERICIDENTIFIER']] + ")");
createToken('PRERELEASE', "(?:-(" + src[t['PRERELEASEIDENTIFIER']] + "(?:\\." + src[t['PRERELEASEIDENTIFIER']] + ")*))");
createToken('PRERELEASELOOSE', "(?:-?(" + src[t['PRERELEASEIDENTIFIERLOOSE']] + "(?:\\." + src[t['PRERELEASEIDENTIFIERLOOSE']] + ")*))");
createToken('MAINVERSION', "(".concat(src[t['NUMERICIDENTIFIER']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIER']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIER']], ")"));
createToken('MAINVERSIONLOOSE', "(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")"));
createToken('PRERELEASEIDENTIFIER', "(?:".concat(src[t['NUMERICIDENTIFIER']], "|").concat(src[t['NONNUMERICIDENTIFIER']], ")"));
createToken('PRERELEASEIDENTIFIERLOOSE', "(?:".concat(src[t['NUMERICIDENTIFIERLOOSE']], "|").concat(src[t['NONNUMERICIDENTIFIER']], ")"));
createToken('PRERELEASE', "(?:-(".concat(src[t['PRERELEASEIDENTIFIER']], "(?:\\.").concat(src[t['PRERELEASEIDENTIFIER']], ")*))"));
createToken('PRERELEASELOOSE', "(?:-?(".concat(src[t['PRERELEASEIDENTIFIERLOOSE']], "(?:\\.").concat(src[t['PRERELEASEIDENTIFIERLOOSE']], ")*))"));
createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
createToken('BUILD', "(?:\\+(" + src[t['BUILDIDENTIFIER']] + "(?:\\." + src[t['BUILDIDENTIFIER']] + ")*))");
createToken('FULLPLAIN', "v?" + src[t['MAINVERSION']] + src[t['PRERELEASE']] + "?" + src[t['BUILD']] + "?");
createToken('FULL', "^" + src[t['FULLPLAIN']] + "$");
createToken('LOOSEPLAIN', "[v=\\s]*" + src[t['MAINVERSIONLOOSE']] + src[t['PRERELEASELOOSE']] + "?" + src[t['BUILD']] + "?");
createToken('LOOSE', "^" + src[t['LOOSEPLAIN']] + "$");
createToken('BUILD', "(?:\\+(".concat(src[t['BUILDIDENTIFIER']], "(?:\\.").concat(src[t['BUILDIDENTIFIER']], ")*))"));
createToken('FULLPLAIN', "v?".concat(src[t['MAINVERSION']]).concat(src[t['PRERELEASE']], "?").concat(src[t['BUILD']], "?"));
createToken('FULL', "^".concat(src[t['FULLPLAIN']], "$"));
createToken('LOOSEPLAIN', "[v=\\s]*".concat(src[t['MAINVERSIONLOOSE']]).concat(src[t['PRERELEASELOOSE']], "?").concat(src[t['BUILD']], "?"));
createToken('LOOSE', "^".concat(src[t['LOOSEPLAIN']], "$"));
var SemVer = /** @class */ (function () {

@@ -70,6 +70,6 @@ function SemVer(version, options) {

else if (typeof version !== 'string') {
throw new TypeError("Invalid Version: " + version);
throw new TypeError("Invalid Version: ".concat(version));
}
if (version.length > MAX_LENGTH) {
throw new TypeError("version is longer than " + MAX_LENGTH + " characters");
throw new TypeError("version is longer than ".concat(MAX_LENGTH, " characters"));
}

@@ -83,3 +83,3 @@ this.options = options;

if (!m) {
throw new TypeError("Invalid Version: " + version);
throw new TypeError("Invalid Version: ".concat(version));
}

@@ -119,5 +119,5 @@ this.raw = version;

SemVer.prototype.format = function () {
this.version = this.major + "." + this.minor + "." + this.patch;
this.version = "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
if (this.prerelease.length) {
this.version += "-" + this.prerelease.join('.');
this.version += "-".concat(this.prerelease.join('.'));
}

@@ -310,3 +310,3 @@ return this.version;

default:
throw new Error("invalid increment argument: " + release);
throw new Error("invalid increment argument: ".concat(release));
}

@@ -313,0 +313,0 @@ this.format();

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

export default "4.6.2";
export default "5.0.0";

@@ -38,2 +38,6 @@ import { IConfigCatClient } from "./ConfigCatClient";

export interface IConfigCatLogger {
debug(message: string): void;
/**
* @deprecated Use `debug(message: string)` method instead of this
*/
log(message: string): void;

@@ -45,2 +49,3 @@ info(message: string): void;

export declare enum LogLevel {
Debug = 4,
Info = 3,

@@ -58,4 +63,18 @@ Warn = 2,

}
export declare enum FetchStatus {
Fetched = 0,
NotModified = 1,
Errored = 2
}
export declare class FetchResult {
status: FetchStatus;
responseBody: string;
eTag?: string;
constructor(status: FetchStatus, responseBody: string, eTag?: string);
static success(responseBody: string, eTag: string): FetchResult;
static notModified(): FetchResult;
static error(): FetchResult;
}
export interface IConfigFetcher {
fetchLogic(options: OptionsBase, lastProjectConfig: ProjectConfig | null, callback: (newProjectConfig: ProjectConfig | null) => void): void;
fetchLogic(options: OptionsBase, lastEtag: string | null, callback: (result: FetchResult) => void): void;
}

@@ -70,2 +89,3 @@ export interface ICache {

export { User } from "./RolloutEvaluator";
export { IOverrideDataSource, FlagOverrides } from "./FlagOverrides";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.User = exports.DataGovernance = exports.OptionsBase = exports.ProjectConfig = exports.LogLevel = exports.createConsoleLogger = exports.createClientWithLazyLoad = exports.createClientWithManualPoll = exports.createClientWithAutoPoll = void 0;
exports.FlagOverrides = exports.User = exports.DataGovernance = exports.OptionsBase = exports.ProjectConfig = exports.FetchResult = exports.FetchStatus = exports.LogLevel = exports.createConsoleLogger = exports.createClientWithLazyLoad = exports.createClientWithManualPoll = exports.createClientWithAutoPoll = void 0;
var ConfigCatClient_1 = require("./ConfigCatClient");

@@ -44,2 +44,3 @@ var ConfigCatClientOptions_1 = require("./ConfigCatClientOptions");

(function (LogLevel) {
LogLevel[LogLevel["Debug"] = 4] = "Debug";
LogLevel[LogLevel["Info"] = 3] = "Info";

@@ -50,2 +51,26 @@ LogLevel[LogLevel["Warn"] = 2] = "Warn";

})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
var FetchStatus;
(function (FetchStatus) {
FetchStatus[FetchStatus["Fetched"] = 0] = "Fetched";
FetchStatus[FetchStatus["NotModified"] = 1] = "NotModified";
FetchStatus[FetchStatus["Errored"] = 2] = "Errored";
})(FetchStatus = exports.FetchStatus || (exports.FetchStatus = {}));
var FetchResult = /** @class */ (function () {
function FetchResult(status, responseBody, eTag) {
this.status = status;
this.responseBody = responseBody;
this.eTag = eTag;
}
FetchResult.success = function (responseBody, eTag) {
return new FetchResult(FetchStatus.Fetched, responseBody, eTag);
};
FetchResult.notModified = function () {
return new FetchResult(FetchStatus.NotModified, "");
};
FetchResult.error = function () {
return new FetchResult(FetchStatus.Errored, "");
};
return FetchResult;
}());
exports.FetchResult = FetchResult;
var ProjectConfig_1 = require("./ProjectConfig");

@@ -58,1 +83,3 @@ Object.defineProperty(exports, "ProjectConfig", { enumerable: true, get: function () { return ProjectConfig_1.ProjectConfig; } });

Object.defineProperty(exports, "User", { enumerable: true, get: function () { return RolloutEvaluator_1.User; } });
var FlagOverrides_1 = require("./FlagOverrides");
Object.defineProperty(exports, "FlagOverrides", { enumerable: true, get: function () { return FlagOverrides_1.FlagOverrides; } });

@@ -13,3 +13,7 @@ export declare class ProjectConfig {

static equals(projectConfig1: ProjectConfig | null, projectConfig2: ProjectConfig | null): boolean;
static compareEtags(etag1?: string, etag2?: string): boolean;
private static ensureStrictEtag;
getSettings(): {
[name: string]: Setting;
};
}

@@ -30,4 +34,10 @@ export declare class ConfigFile {

static VariationId: string;
value: any;
rolloutPercentageItems: RolloutPercentageItem[];
rolloutRules: RolloutRule[];
variationId: string;
constructor(value: any, rolloutPercentageItems: RolloutPercentageItem[], rolloutRules: RolloutRule[], variationId: string);
static fromJson(json: any): Setting;
}
export declare class RolloutRules {
export declare class RolloutRule {
static Order: string;

@@ -39,4 +49,11 @@ static ComparisonAttribute: string;

static VariationId: string;
comparisonAttribute: string;
comparator: number;
comparisonValue: string;
value: any;
variationId: string;
constructor(comparisonAttribute: string, comparator: number, comparisonValue: string, value: any, variationId: string);
static fromJson(json: any): RolloutRule;
}
export declare class RolloutPercentageItems {
export declare class RolloutPercentageItem {
static Order: string;

@@ -46,3 +63,8 @@ static Value: string;

static VariationId: string;
percentage: number;
value: any;
variationId: string;
constructor(percentage: number, value: any, variationId: string);
static fromJson(json: any): RolloutPercentageItem;
}
//# sourceMappingURL=ProjectConfig.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloutPercentageItems = exports.RolloutRules = exports.Setting = exports.Preferences = exports.ConfigFile = exports.ProjectConfig = void 0;
exports.RolloutPercentageItem = exports.RolloutRule = exports.Setting = exports.Preferences = exports.ConfigFile = exports.ProjectConfig = void 0;
var ProjectConfig = /** @class */ (function () {

@@ -16,4 +16,7 @@ function ProjectConfig(timeStamp, jsonConfig, httpETag) {

return false;
return (this.ensureStrictEtag(projectConfig1.HttpETag) === this.ensureStrictEtag(projectConfig2.HttpETag));
return this.compareEtags(projectConfig1.HttpETag, projectConfig2.HttpETag);
};
ProjectConfig.compareEtags = function (etag1, etag2) {
return this.ensureStrictEtag(etag1) === this.ensureStrictEtag(etag2);
};
ProjectConfig.ensureStrictEtag = function (etag) {

@@ -28,2 +31,8 @@ if (!etag) {

};
ProjectConfig.prototype.getSettings = function () {
return Object.fromEntries(Object.entries(this.ConfigJSON[ConfigFile.FeatureFlags]).map(function (_a) {
var key = _a[0], value = _a[1];
return [key, Setting.fromJson(value)];
}));
};
return ProjectConfig;

@@ -49,4 +58,12 @@ }());

var Setting = /** @class */ (function () {
function Setting() {
function Setting(value, rolloutPercentageItems, rolloutRules, variationId) {
this.value = value;
this.rolloutPercentageItems = rolloutPercentageItems;
this.rolloutRules = rolloutRules;
this.variationId = variationId;
}
Setting.fromJson = function (json) {
var _a, _b, _c, _d;
return new Setting(json[this.Value], (_b = (_a = json[this.RolloutPercentageItems]) === null || _a === void 0 ? void 0 : _a.map(function (item) { return RolloutPercentageItem.fromJson(item); })) !== null && _b !== void 0 ? _b : [], (_d = (_c = json[this.RolloutRules]) === null || _c === void 0 ? void 0 : _c.map(function (item) { return RolloutRule.fromJson(item); })) !== null && _d !== void 0 ? _d : [], json[this.VariationId]);
};
Setting.Value = "v";

@@ -60,23 +77,37 @@ Setting.SettingType = "t";

exports.Setting = Setting;
var RolloutRules = /** @class */ (function () {
function RolloutRules() {
var RolloutRule = /** @class */ (function () {
function RolloutRule(comparisonAttribute, comparator, comparisonValue, value, variationId) {
this.comparisonAttribute = comparisonAttribute;
this.comparator = comparator;
this.comparisonValue = comparisonValue;
this.value = value;
this.variationId = variationId;
}
RolloutRules.Order = "o";
RolloutRules.ComparisonAttribute = "a";
RolloutRules.Comparator = "t";
RolloutRules.ComparisonValue = "c";
RolloutRules.Value = "v";
RolloutRules.VariationId = "i";
return RolloutRules;
RolloutRule.fromJson = function (json) {
return new RolloutRule(json[this.ComparisonAttribute], json[this.Comparator], json[this.ComparisonValue], json[this.Value], json[this.VariationId]);
};
RolloutRule.Order = "o";
RolloutRule.ComparisonAttribute = "a";
RolloutRule.Comparator = "t";
RolloutRule.ComparisonValue = "c";
RolloutRule.Value = "v";
RolloutRule.VariationId = "i";
return RolloutRule;
}());
exports.RolloutRules = RolloutRules;
var RolloutPercentageItems = /** @class */ (function () {
function RolloutPercentageItems() {
exports.RolloutRule = RolloutRule;
var RolloutPercentageItem = /** @class */ (function () {
function RolloutPercentageItem(percentage, value, variationId) {
this.percentage = percentage;
this.value = value;
this.variationId = variationId;
}
RolloutPercentageItems.Order = "o";
RolloutPercentageItems.Value = "v";
RolloutPercentageItems.Percentage = "p";
RolloutPercentageItems.VariationId = "i";
return RolloutPercentageItems;
RolloutPercentageItem.fromJson = function (json) {
return new RolloutPercentageItem(json[this.Percentage], json[this.Value], json[this.VariationId]);
};
RolloutPercentageItem.Order = "o";
RolloutPercentageItem.Value = "v";
RolloutPercentageItem.Percentage = "p";
RolloutPercentageItem.VariationId = "i";
return RolloutPercentageItem;
}());
exports.RolloutPercentageItems = RolloutPercentageItems;
exports.RolloutPercentageItem = RolloutPercentageItem;
import { IConfigCatLogger } from "./index";
import { ProjectConfig } from "./ProjectConfig";
import { Setting } from "./ProjectConfig";
export interface IRolloutEvaluator {
Evaluate(config: ProjectConfig | null, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
Evaluate(settings: {
[name: string]: Setting;
}, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
}

@@ -25,3 +27,5 @@ /** Object for variation evaluation */

constructor(logger: IConfigCatLogger);
Evaluate(config: ProjectConfig | null, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
Evaluate(settings: {
[name: string]: Setting;
}, key: string, defaultValue: any, user?: User, defaultVariationId?: any): ValueAndVariationId;
private EvaluateRules;

@@ -28,0 +32,0 @@ private EvaluateVariations;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloutEvaluator = exports.User = void 0;
var ProjectConfig_1 = require("./ProjectConfig");
var Sha1_1 = require("./Sha1");

@@ -25,15 +24,10 @@ var semver = require("./Semver");

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

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

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

@@ -59,4 +53,4 @@ }

else {
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)) {
if ((featureFlag.rolloutRules && featureFlag.rolloutRules.length > 0) ||
(featureFlag.rolloutPercentageItems && featureFlag.rolloutPercentageItems.length > 0)) {
var s = "Evaluating getValue('" + key + "'). ";

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

result.ValueAndVariationId = {
Value: featureFlag[ProjectConfig_1.Setting.Value],
VariationId: featureFlag[ProjectConfig_1.Setting.VariationId],
Value: featureFlag.value,
VariationId: featureFlag.variationId,
};

@@ -85,8 +79,8 @@ result.EvaluateLog.ReturnValue = result.ValueAndVariationId.Value;

var rule = rolloutRules[i];
var comparisonAttribute = this_1.GetUserAttribute(user, rule[ProjectConfig_1.RolloutRules.ComparisonAttribute]);
var comparisonAttribute = this_1.GetUserAttribute(user, rule.comparisonAttribute);
if (!comparisonAttribute) {
return "continue";
}
var comparator = rule[ProjectConfig_1.RolloutRules.Comparator];
var comparisonValue = rule[ProjectConfig_1.RolloutRules.ComparisonValue];
var comparator = rule.comparator;
var comparisonValue = rule.comparisonValue;
var log = "Evaluating rule: '" + comparisonAttribute + "' " + this_1.RuleToString(comparator) + " '" + comparisonValue + "' => ";

@@ -101,4 +95,4 @@ switch (comparator) {

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -122,4 +116,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -133,8 +127,8 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

case 2: // contains
if (comparisonAttribute.search(comparisonValue) !== -1) {
if (comparisonAttribute.indexOf(comparisonValue) !== -1) {
log += "MATCH";
eLog.OpAppendLine(log);
result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -148,8 +142,8 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

case 3: // not contains
if (comparisonAttribute.search(comparisonValue) === -1) {
if (comparisonAttribute.indexOf(comparisonValue) === -1) {
log += "MATCH";
eLog.OpAppendLine(log);
result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -172,4 +166,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -192,4 +186,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -209,4 +203,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -230,4 +224,4 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

result.ValueAndVariationId = {
Value: rule[ProjectConfig_1.RolloutRules.Value],
VariationId: rule[ProjectConfig_1.RolloutRules.VariationId]
Value: rule.value,
VariationId: rule.variationId
};

@@ -263,7 +257,7 @@ eLog.ReturnValue = result.ValueAndVariationId.Value;

var variation = rolloutPercentageItems[i];
bucket += +variation[ProjectConfig_1.RolloutPercentageItems.Percentage];
bucket += +variation.percentage;
if (hashScale < bucket) {
return {
Value: variation[ProjectConfig_1.RolloutPercentageItems.Value],
VariationId: variation[ProjectConfig_1.RolloutPercentageItems.VariationId]
Value: variation.value,
VariationId: variation.variationId
};

@@ -270,0 +264,0 @@ }

@@ -38,18 +38,18 @@ "use strict";

createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
createToken('MAINVERSION', "(" + src[t['NUMERICIDENTIFIER']] + ")\\." +
("(" + src[t['NUMERICIDENTIFIER']] + ")\\.") +
("(" + src[t['NUMERICIDENTIFIER']] + ")"));
createToken('MAINVERSIONLOOSE', "(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")\\." +
("(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")\\.") +
("(" + src[t['NUMERICIDENTIFIERLOOSE']] + ")"));
createToken('PRERELEASEIDENTIFIER', "(?:" + src[t['NUMERICIDENTIFIER']] + "|" + src[t['NONNUMERICIDENTIFIER']] + ")");
createToken('PRERELEASEIDENTIFIERLOOSE', "(?:" + src[t['NUMERICIDENTIFIERLOOSE']] + "|" + src[t['NONNUMERICIDENTIFIER']] + ")");
createToken('PRERELEASE', "(?:-(" + src[t['PRERELEASEIDENTIFIER']] + "(?:\\." + src[t['PRERELEASEIDENTIFIER']] + ")*))");
createToken('PRERELEASELOOSE', "(?:-?(" + src[t['PRERELEASEIDENTIFIERLOOSE']] + "(?:\\." + src[t['PRERELEASEIDENTIFIERLOOSE']] + ")*))");
createToken('MAINVERSION', "(".concat(src[t['NUMERICIDENTIFIER']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIER']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIER']], ")"));
createToken('MAINVERSIONLOOSE', "(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")\\.") +
"(".concat(src[t['NUMERICIDENTIFIERLOOSE']], ")"));
createToken('PRERELEASEIDENTIFIER', "(?:".concat(src[t['NUMERICIDENTIFIER']], "|").concat(src[t['NONNUMERICIDENTIFIER']], ")"));
createToken('PRERELEASEIDENTIFIERLOOSE', "(?:".concat(src[t['NUMERICIDENTIFIERLOOSE']], "|").concat(src[t['NONNUMERICIDENTIFIER']], ")"));
createToken('PRERELEASE', "(?:-(".concat(src[t['PRERELEASEIDENTIFIER']], "(?:\\.").concat(src[t['PRERELEASEIDENTIFIER']], ")*))"));
createToken('PRERELEASELOOSE', "(?:-?(".concat(src[t['PRERELEASEIDENTIFIERLOOSE']], "(?:\\.").concat(src[t['PRERELEASEIDENTIFIERLOOSE']], ")*))"));
createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
createToken('BUILD', "(?:\\+(" + src[t['BUILDIDENTIFIER']] + "(?:\\." + src[t['BUILDIDENTIFIER']] + ")*))");
createToken('FULLPLAIN', "v?" + src[t['MAINVERSION']] + src[t['PRERELEASE']] + "?" + src[t['BUILD']] + "?");
createToken('FULL', "^" + src[t['FULLPLAIN']] + "$");
createToken('LOOSEPLAIN', "[v=\\s]*" + src[t['MAINVERSIONLOOSE']] + src[t['PRERELEASELOOSE']] + "?" + src[t['BUILD']] + "?");
createToken('LOOSE', "^" + src[t['LOOSEPLAIN']] + "$");
createToken('BUILD', "(?:\\+(".concat(src[t['BUILDIDENTIFIER']], "(?:\\.").concat(src[t['BUILDIDENTIFIER']], ")*))"));
createToken('FULLPLAIN', "v?".concat(src[t['MAINVERSION']]).concat(src[t['PRERELEASE']], "?").concat(src[t['BUILD']], "?"));
createToken('FULL', "^".concat(src[t['FULLPLAIN']], "$"));
createToken('LOOSEPLAIN', "[v=\\s]*".concat(src[t['MAINVERSIONLOOSE']]).concat(src[t['PRERELEASELOOSE']], "?").concat(src[t['BUILD']], "?"));
createToken('LOOSE', "^".concat(src[t['LOOSEPLAIN']], "$"));
var SemVer = /** @class */ (function () {

@@ -73,6 +73,6 @@ function SemVer(version, options) {

else if (typeof version !== 'string') {
throw new TypeError("Invalid Version: " + version);
throw new TypeError("Invalid Version: ".concat(version));
}
if (version.length > MAX_LENGTH) {
throw new TypeError("version is longer than " + MAX_LENGTH + " characters");
throw new TypeError("version is longer than ".concat(MAX_LENGTH, " characters"));
}

@@ -86,3 +86,3 @@ this.options = options;

if (!m) {
throw new TypeError("Invalid Version: " + version);
throw new TypeError("Invalid Version: ".concat(version));
}

@@ -122,5 +122,5 @@ this.raw = version;

SemVer.prototype.format = function () {
this.version = this.major + "." + this.minor + "." + this.patch;
this.version = "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
if (this.prerelease.length) {
this.version += "-" + this.prerelease.join('.');
this.version += "-".concat(this.prerelease.join('.'));
}

@@ -313,3 +313,3 @@ return this.version;

default:
throw new Error("invalid increment argument: " + release);
throw new Error("invalid increment argument: ".concat(release));
}

@@ -316,0 +316,0 @@ this.format();

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

@@ -33,15 +33,15 @@ "main": "lib/index.js",

"devDependencies": {
"@types/chai": "4.2.22",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.6",
"chai": "^4.3.4",
"@types/chai": "4.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.17",
"chai": "^4.3.6",
"gulp": "^4.0.2",
"gulp-replace": "^1.1.3",
"gulp-typescript": "^6.0.0-alpha.1",
"mocha": "^9.1.3",
"mocha": "^9.2.0",
"moq.ts": "^7.4.1",
"nyc": "^15.1.0",
"source-map-support": "^0.5.20",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
"source-map-support": "^0.5.21",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
},

@@ -48,0 +48,0 @@ "repository": {

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

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