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

configcat-common

Package Overview
Dependencies
Maintainers
4
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 8.1.1 to 8.2.0

9

lib/AutoPollConfigService.d.ts
import type { AutoPollOptions } from "./ConfigCatClientOptions";
import type { IConfigFetcher } from "./ConfigFetcher";
import type { IConfigService, RefreshResult } from "./ConfigServiceBase";
import { ConfigServiceBase } from "./ConfigServiceBase";
import { ClientReadyState } from "./Hooks";
import { ClientCacheState, ConfigServiceBase } from "./ConfigServiceBase";
import type { ProjectConfig } from "./ProjectConfig";

@@ -11,5 +10,7 @@ export declare class AutoPollConfigService extends ConfigServiceBase<AutoPollOptions> implements IConfigService {

private signalInitialization;
private timerId?;
private workerTimerId?;
private readonly initTimerId?;
private readonly pollIntervalMs;
constructor(configFetcher: IConfigFetcher, options: AutoPollOptions);
protected onCacheSynced(): void;
private waitForInitializationAsync;

@@ -25,4 +26,4 @@ getConfig(): Promise<ProjectConfig>;

private refreshWorkerLogic;
protected getReadyState(cachedConfig: ProjectConfig): ClientReadyState;
getCacheState(cachedConfig: ProjectConfig): ClientCacheState;
}
//# sourceMappingURL=AutoPollConfigService.d.ts.map

@@ -6,3 +6,2 @@ "use strict";

var ConfigServiceBase_1 = require("./ConfigServiceBase");
var Hooks_1 = require("./Hooks");
var Utils_1 = require("./Utils");

@@ -15,2 +14,3 @@ var AutoPollConfigService = /** @class */ (function (_super) {

_this.pollIntervalMs = options.pollIntervalSeconds * 1000;
var initialCacheSync = _super.prototype.syncUpWithCache.call(_this);
if (options.maxInitWaitTimeSeconds !== 0) {

@@ -24,7 +24,8 @@ _this.initialized = false;

_this.initialized = true;
clearTimeout(_this.initTimerId);
resolve();
}; });
_this.initialization.then(function () { return options.hooks.emit("clientReady", _this.getReadyState(options.cache.getInMemory())); });
_this.initialization.then(function () { return _super.prototype.onCacheSynced.call(_this, options.cache.getInMemory()); });
if (options.maxInitWaitTimeSeconds > 0) {
setTimeout(function () { return _this.signalInitialization(); }, options.maxInitWaitTimeSeconds * 1000);
_this.initTimerId = setTimeout(function () { return _this.signalInitialization(); }, options.maxInitWaitTimeSeconds * 1000);
}

@@ -35,13 +36,16 @@ }

_this.initialization = Promise.resolve();
options.hooks.emit("clientReady", _this.getReadyState(options.cache.getInMemory()));
initialCacheSync.then(function (cachedConfig) { return _super.prototype.onCacheSynced.call(_this, cachedConfig); });
}
if (!options.offline) {
_this.startRefreshWorker();
_this.startRefreshWorker(initialCacheSync);
}
return _this;
}
AutoPollConfigService.prototype.onCacheSynced = function () {
// We override this method with a no-op to prevent the default behavior because
// we want to defer emitting clientReady until maxInitWaitTimeSeconds has passed. */
};
AutoPollConfigService.prototype.waitForInitializationAsync = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var cancelDelay, result;
var _this = this;
var delayCleanup, success;
return tslib_1.__generator(this, function (_a) {

@@ -55,17 +59,12 @@ switch (_a.label) {

return [2 /*return*/, true];
case 2: return [4 /*yield*/, Promise.race([
(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.initialization];
case 1:
_a.sent();
return [2 /*return*/, true];
}
}); }); })(),
Utils_1.delay(this.options.maxInitWaitTimeSeconds * 1000, function (cancel) { return cancelDelay = cancel; })
])];
case 2:
delayCleanup = {};
return [4 /*yield*/, Promise.race([
this.initialization.then(function () { return true; }),
Utils_1.delay(this.options.maxInitWaitTimeSeconds * 1000, delayCleanup).then(function () { return false; })
])];
case 3:
result = _a.sent();
cancelDelay();
return [2 /*return*/, !!result];
success = _a.sent();
delayCleanup.clearTimer();
return [2 /*return*/, success];
}

@@ -119,3 +118,3 @@ });

_super.prototype.dispose.call(this);
if (this.timerId) {
if (this.workerTimerId) {
this.stopRefreshWorker();

@@ -134,3 +133,3 @@ }

};
AutoPollConfigService.prototype.startRefreshWorker = function () {
AutoPollConfigService.prototype.startRefreshWorker = function (initialCacheSync) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -144,3 +143,3 @@ var delayMs, latestConfig;

delayMs = this.pollIntervalMs;
return [4 /*yield*/, this.options.cache.get(this.cacheKey)];
return [4 /*yield*/, (initialCacheSync !== null && initialCacheSync !== void 0 ? initialCacheSync : this.options.cache.get(this.cacheKey))];
case 1:

@@ -160,3 +159,3 @@ latestConfig = _a.sent();

this.options.logger.debug("AutoPollConfigService.startRefreshWorker() - calling refreshWorkerLogic()'s setTimeout.");
this.timerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
this.workerTimerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
return [2 /*return*/];

@@ -169,3 +168,3 @@ }

this.options.logger.debug("AutoPollConfigService.stopRefreshWorker() - clearing setTimeout.");
clearTimeout(this.timerId);
clearTimeout(this.workerTimerId);
};

@@ -194,3 +193,3 @@ AutoPollConfigService.prototype.refreshWorkerLogic = function (delayMs) {

this.options.logger.debug("AutoPollConfigService.refreshWorkerLogic() - calling refreshWorkerLogic()'s setTimeout.");
this.timerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
this.workerTimerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
return [2 /*return*/];

@@ -201,10 +200,10 @@ }

};
AutoPollConfigService.prototype.getReadyState = function (cachedConfig) {
AutoPollConfigService.prototype.getCacheState = function (cachedConfig) {
if (cachedConfig.isEmpty) {
return Hooks_1.ClientReadyState.NoFlagData;
return ConfigServiceBase_1.ClientCacheState.NoFlagData;
}
if (cachedConfig.isExpired(this.pollIntervalMs)) {
return Hooks_1.ClientReadyState.HasCachedFlagDataOnly;
return ConfigServiceBase_1.ClientCacheState.HasCachedFlagDataOnly;
}
return Hooks_1.ClientReadyState.HasUpToDateFlagData;
return ConfigServiceBase_1.ClientCacheState.HasUpToDateFlagData;
};

@@ -211,0 +210,0 @@ return AutoPollConfigService;

@@ -36,2 +36,3 @@ import type { LoggerWrapper } from "./ConfigCatLogger";

set(key: string, config: ProjectConfig): Promise<void>;
private updateCachedConfig;
get(key: string): Promise<ProjectConfig>;

@@ -38,0 +39,0 @@ getInMemory(): ProjectConfig;

@@ -6,2 +6,3 @@ "use strict";

var ProjectConfig_1 = require("./ProjectConfig");
var Utils_1 = require("./Utils");
var InMemoryConfigCache = /** @class */ (function () {

@@ -60,26 +61,43 @@ function InMemoryConfigCache() {

};
ExternalConfigCache.prototype.updateCachedConfig = function (externalSerializedConfig) {
if (externalSerializedConfig === null || externalSerializedConfig === void 0 || externalSerializedConfig === this.cachedSerializedConfig) {
return;
}
this.cachedConfig = ProjectConfig_1.ProjectConfig.deserialize(externalSerializedConfig);
this.cachedSerializedConfig = externalSerializedConfig;
};
ExternalConfigCache.prototype.get = function (key) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var externalSerializedConfig, err_2;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.cache.get(key)];
case 1:
externalSerializedConfig = _a.sent();
if (externalSerializedConfig === null || externalSerializedConfig === void 0 || externalSerializedConfig === this.cachedSerializedConfig) {
return [2 /*return*/, this.cachedConfig];
var _this = this;
try {
var cacheGetResult = this.cache.get(key);
// Take the async path only when the IConfigCatCache.get operation is asynchronous.
if (Utils_1.isPromiseLike(cacheGetResult)) {
return (function (cacheGetPromise) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, err_2;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
_a = this.updateCachedConfig;
return [4 /*yield*/, cacheGetPromise];
case 1:
_a.apply(this, [_b.sent()]);
return [3 /*break*/, 3];
case 2:
err_2 = _b.sent();
this.logger.configServiceCacheReadError(err_2);
return [3 /*break*/, 3];
case 3: return [2 /*return*/, this.cachedConfig];
}
this.cachedConfig = ProjectConfig_1.ProjectConfig.deserialize(externalSerializedConfig);
this.cachedSerializedConfig = externalSerializedConfig;
return [3 /*break*/, 3];
case 2:
err_2 = _a.sent();
this.logger.configServiceCacheReadError(err_2);
return [3 /*break*/, 3];
case 3: return [2 /*return*/, this.cachedConfig];
}
});
});
});
}); })(cacheGetResult);
}
// Otherwise, keep the code flow synchronous so the config services can sync up
// with the cache in their ctors synchronously (see ConfigServiceBase.syncUpWithCache).
this.updateCachedConfig(cacheGetResult);
}
catch (err) {
this.logger.configServiceCacheReadError(err);
}
return Promise.resolve(this.cachedConfig);
};

@@ -86,0 +104,0 @@ ExternalConfigCache.prototype.getInMemory = function () {

@@ -6,6 +6,5 @@ import type { IConfigCache } from "./ConfigCatCache";

import type { IConfigService } from "./ConfigServiceBase";
import { RefreshResult } from "./ConfigServiceBase";
import { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
import type { IEventEmitter } from "./EventEmitter";
import type { HookEvents, IProvidesHooks } from "./Hooks";
import { ClientReadyState } from "./Hooks";
import type { IConfig, SettingValue } from "./ProjectConfig";

@@ -74,3 +73,3 @@ import type { IEvaluationDetails, IRolloutEvaluator, SettingTypeOf, User } from "./RolloutEvaluator";

*/
waitForReady(): Promise<ClientReadyState>;
waitForReady(): Promise<ClientCacheState>;
/**

@@ -109,2 +108,3 @@ * Captures the current state of the client.

export interface IConfigCatClientSnapshot {
readonly cacheState: ClientCacheState;
/** The latest config which has been fetched from the remote server. */

@@ -183,3 +183,3 @@ readonly fetchedConfig: IConfig | null;

setOffline(): void;
waitForReady(): Promise<ClientReadyState>;
waitForReady(): Promise<ClientCacheState>;
snapshot(): IConfigCatClientSnapshot;

@@ -186,0 +186,0 @@ private getSettingsAsync;

@@ -9,3 +9,2 @@ "use strict";

var FlagOverrides_1 = require("./FlagOverrides");
var Hooks_1 = require("./Hooks");
var LazyLoadConfigService_1 = require("./LazyLoadConfigService");

@@ -95,3 +94,3 @@ var ManualPollConfigService_1 = require("./ManualPollConfigService");

else {
this.options.hooks.emit("clientReady", Hooks_1.ClientReadyState.HasLocalOverrideFlagDataOnly);
this.options.hooks.emit("clientReady", ConfigServiceBase_1.ClientCacheState.HasLocalOverrideFlagDataOnly);
}

@@ -555,2 +554,5 @@ this.suppressFinalize = registerForFinalization(this, { sdkKey: options.apiKey, cacheToken: cacheToken, configService: this.configService, logger: options.logger });

this.options = client["options"];
this.cacheState = remoteConfig
? client["configService"].getCacheState(remoteConfig)
: ConfigServiceBase_1.ClientCacheState.HasLocalOverrideFlagDataOnly;
}

@@ -557,0 +559,0 @@ Object.defineProperty(Snapshot.prototype, "fetchedConfig", {

import type { IConfigCache, IConfigCatCache } from "./ConfigCatCache";
import type { IConfigCatLogger } from "./ConfigCatLogger";
import { LoggerWrapper } from "./ConfigCatLogger";
import type { ClientCacheState } from "./ConfigServiceBase";
import type { IEventEmitter } from "./EventEmitter";
import type { FlagOverrides } from "./FlagOverrides";
import type { ClientReadyState, IProvidesHooks } from "./Hooks";
import type { IProvidesHooks } from "./Hooks";
import { Hooks } from "./Hooks";

@@ -116,3 +117,3 @@ import type { User } from "./RolloutEvaluator";

hooks: Hooks;
readyPromise: Promise<ClientReadyState>;
readyPromise: Promise<ClientCacheState>;
constructor(apiKey: string, clientVersion: string, options?: IOptions | null, defaultCacheFactory?: ((options: OptionsBase) => IConfigCache) | null, eventEmitterFactory?: (() => IEventEmitter) | null);

@@ -119,0 +120,0 @@ getUrl(): string;

@@ -19,3 +19,3 @@ import type { Hooks } from "./Hooks";

export declare type LogEventId = number;
/** Represents a log message format with names arguments. */
/** Represents a log message format with named arguments. */
export declare class FormattableLogMessage {

@@ -22,0 +22,0 @@ readonly strings: ReadonlyArray<string>;

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

})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
/** Represents a log message format with names arguments. */
/** Represents a log message format with named arguments. */
var FormattableLogMessage = /** @class */ (function () {

@@ -26,0 +26,0 @@ function FormattableLogMessage(strings, argNames, argValues) {

import type { OptionsBase } from "./ConfigCatClientOptions";
import type { IConfigFetcher } from "./ConfigFetcher";
import { FetchResult } from "./ConfigFetcher";
import type { ClientReadyState } from "./Hooks";
import { ProjectConfig } from "./ProjectConfig";

@@ -25,2 +24,9 @@ /** Contains the result of an `IConfigCatClient.forceRefresh` or `IConfigCatClient.forceRefreshAsync` operation. */

}
/** Specifies the possible states of the local cache. */
export declare enum ClientCacheState {
NoFlagData = 0,
HasLocalOverrideFlagDataOnly = 1,
HasCachedFlagDataOnly = 2,
HasUpToDateFlagData = 3
}
export interface IConfigService {

@@ -32,2 +38,3 @@ getConfig(): Promise<ProjectConfig>;

setOffline(): void;
getCacheState(cachedConfig: ProjectConfig): ClientCacheState;
dispose(): void;

@@ -58,5 +65,6 @@ }

setOffline(): void;
protected abstract getReadyState(cachedConfig: ProjectConfig): ClientReadyState;
protected syncUpWithCache(): Promise<void>;
abstract getCacheState(cachedConfig: ProjectConfig): ClientCacheState;
protected onCacheSynced(cachedConfig: ProjectConfig): void;
protected syncUpWithCache(): Promise<ProjectConfig>;
}
//# sourceMappingURL=ConfigServiceBase.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigServiceBase = exports.RefreshResult = void 0;
exports.ConfigServiceBase = exports.ClientCacheState = exports.RefreshResult = void 0;
var tslib_1 = require("tslib");

@@ -39,2 +39,10 @@ var ConfigFetcher_1 = require("./ConfigFetcher");

exports.RefreshResult = RefreshResult;
/** Specifies the possible states of the local cache. */
var ClientCacheState;
(function (ClientCacheState) {
ClientCacheState[ClientCacheState["NoFlagData"] = 0] = "NoFlagData";
ClientCacheState[ClientCacheState["HasLocalOverrideFlagDataOnly"] = 1] = "HasLocalOverrideFlagDataOnly";
ClientCacheState[ClientCacheState["HasCachedFlagDataOnly"] = 2] = "HasCachedFlagDataOnly";
ClientCacheState[ClientCacheState["HasUpToDateFlagData"] = 3] = "HasUpToDateFlagData";
})(ClientCacheState = exports.ClientCacheState || (exports.ClientCacheState = {}));
var ConfigServiceStatus;

@@ -295,2 +303,5 @@ (function (ConfigServiceStatus) {

};
ConfigServiceBase.prototype.onCacheSynced = function (cachedConfig) {
this.options.hooks.emit("clientReady", this.getCacheState(cachedConfig));
};
ConfigServiceBase.prototype.syncUpWithCache = function () {

@@ -304,4 +315,4 @@ return tslib_1.__awaiter(this, void 0, void 0, function () {

cachedConfig = _a.sent();
this.options.hooks.emit("clientReady", this.getReadyState(cachedConfig));
return [2 /*return*/];
this.onCacheSynced(cachedConfig);
return [2 /*return*/, cachedConfig];
}

@@ -308,0 +319,0 @@ });

import { __awaiter, __extends, __generator } from "tslib";
import { ConfigServiceBase } from "./ConfigServiceBase";
import { ClientReadyState } from "./Hooks";
import { ClientCacheState, ConfigServiceBase } from "./ConfigServiceBase";
import { delay } from "./Utils";

@@ -11,2 +10,3 @@ var AutoPollConfigService = /** @class */ (function (_super) {

_this.pollIntervalMs = options.pollIntervalSeconds * 1000;
var initialCacheSync = _super.prototype.syncUpWithCache.call(_this);
if (options.maxInitWaitTimeSeconds !== 0) {

@@ -20,7 +20,8 @@ _this.initialized = false;

_this.initialized = true;
clearTimeout(_this.initTimerId);
resolve();
}; });
_this.initialization.then(function () { return options.hooks.emit("clientReady", _this.getReadyState(options.cache.getInMemory())); });
_this.initialization.then(function () { return _super.prototype.onCacheSynced.call(_this, options.cache.getInMemory()); });
if (options.maxInitWaitTimeSeconds > 0) {
setTimeout(function () { return _this.signalInitialization(); }, options.maxInitWaitTimeSeconds * 1000);
_this.initTimerId = setTimeout(function () { return _this.signalInitialization(); }, options.maxInitWaitTimeSeconds * 1000);
}

@@ -31,13 +32,16 @@ }

_this.initialization = Promise.resolve();
options.hooks.emit("clientReady", _this.getReadyState(options.cache.getInMemory()));
initialCacheSync.then(function (cachedConfig) { return _super.prototype.onCacheSynced.call(_this, cachedConfig); });
}
if (!options.offline) {
_this.startRefreshWorker();
_this.startRefreshWorker(initialCacheSync);
}
return _this;
}
AutoPollConfigService.prototype.onCacheSynced = function () {
// We override this method with a no-op to prevent the default behavior because
// we want to defer emitting clientReady until maxInitWaitTimeSeconds has passed. */
};
AutoPollConfigService.prototype.waitForInitializationAsync = function () {
return __awaiter(this, void 0, void 0, function () {
var cancelDelay, result;
var _this = this;
var delayCleanup, success;
return __generator(this, function (_a) {

@@ -51,17 +55,12 @@ switch (_a.label) {

return [2 /*return*/, true];
case 2: return [4 /*yield*/, Promise.race([
(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.initialization];
case 1:
_a.sent();
return [2 /*return*/, true];
}
}); }); })(),
delay(this.options.maxInitWaitTimeSeconds * 1000, function (cancel) { return cancelDelay = cancel; })
])];
case 2:
delayCleanup = {};
return [4 /*yield*/, Promise.race([
this.initialization.then(function () { return true; }),
delay(this.options.maxInitWaitTimeSeconds * 1000, delayCleanup).then(function () { return false; })
])];
case 3:
result = _a.sent();
cancelDelay();
return [2 /*return*/, !!result];
success = _a.sent();
delayCleanup.clearTimer();
return [2 /*return*/, success];
}

@@ -115,3 +114,3 @@ });

_super.prototype.dispose.call(this);
if (this.timerId) {
if (this.workerTimerId) {
this.stopRefreshWorker();

@@ -130,3 +129,3 @@ }

};
AutoPollConfigService.prototype.startRefreshWorker = function () {
AutoPollConfigService.prototype.startRefreshWorker = function (initialCacheSync) {
return __awaiter(this, void 0, void 0, function () {

@@ -140,3 +139,3 @@ var delayMs, latestConfig;

delayMs = this.pollIntervalMs;
return [4 /*yield*/, this.options.cache.get(this.cacheKey)];
return [4 /*yield*/, (initialCacheSync !== null && initialCacheSync !== void 0 ? initialCacheSync : this.options.cache.get(this.cacheKey))];
case 1:

@@ -156,3 +155,3 @@ latestConfig = _a.sent();

this.options.logger.debug("AutoPollConfigService.startRefreshWorker() - calling refreshWorkerLogic()'s setTimeout.");
this.timerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
this.workerTimerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
return [2 /*return*/];

@@ -165,3 +164,3 @@ }

this.options.logger.debug("AutoPollConfigService.stopRefreshWorker() - clearing setTimeout.");
clearTimeout(this.timerId);
clearTimeout(this.workerTimerId);
};

@@ -190,3 +189,3 @@ AutoPollConfigService.prototype.refreshWorkerLogic = function (delayMs) {

this.options.logger.debug("AutoPollConfigService.refreshWorkerLogic() - calling refreshWorkerLogic()'s setTimeout.");
this.timerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
this.workerTimerId = setTimeout(function (d) { return _this.refreshWorkerLogic(d); }, delayMs, delayMs);
return [2 /*return*/];

@@ -197,10 +196,10 @@ }

};
AutoPollConfigService.prototype.getReadyState = function (cachedConfig) {
AutoPollConfigService.prototype.getCacheState = function (cachedConfig) {
if (cachedConfig.isEmpty) {
return ClientReadyState.NoFlagData;
return ClientCacheState.NoFlagData;
}
if (cachedConfig.isExpired(this.pollIntervalMs)) {
return ClientReadyState.HasCachedFlagDataOnly;
return ClientCacheState.HasCachedFlagDataOnly;
}
return ClientReadyState.HasUpToDateFlagData;
return ClientCacheState.HasUpToDateFlagData;
};

@@ -207,0 +206,0 @@ return AutoPollConfigService;

import { __awaiter, __generator } from "tslib";
import { ProjectConfig } from "./ProjectConfig";
import { isPromiseLike } from "./Utils";
var InMemoryConfigCache = /** @class */ (function () {

@@ -56,26 +57,43 @@ function InMemoryConfigCache() {

};
ExternalConfigCache.prototype.updateCachedConfig = function (externalSerializedConfig) {
if (externalSerializedConfig === null || externalSerializedConfig === void 0 || externalSerializedConfig === this.cachedSerializedConfig) {
return;
}
this.cachedConfig = ProjectConfig.deserialize(externalSerializedConfig);
this.cachedSerializedConfig = externalSerializedConfig;
};
ExternalConfigCache.prototype.get = function (key) {
return __awaiter(this, void 0, void 0, function () {
var externalSerializedConfig, err_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.cache.get(key)];
case 1:
externalSerializedConfig = _a.sent();
if (externalSerializedConfig === null || externalSerializedConfig === void 0 || externalSerializedConfig === this.cachedSerializedConfig) {
return [2 /*return*/, this.cachedConfig];
var _this = this;
try {
var cacheGetResult = this.cache.get(key);
// Take the async path only when the IConfigCatCache.get operation is asynchronous.
if (isPromiseLike(cacheGetResult)) {
return (function (cacheGetPromise) { return __awaiter(_this, void 0, void 0, function () {
var _a, err_2;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
_a = this.updateCachedConfig;
return [4 /*yield*/, cacheGetPromise];
case 1:
_a.apply(this, [_b.sent()]);
return [3 /*break*/, 3];
case 2:
err_2 = _b.sent();
this.logger.configServiceCacheReadError(err_2);
return [3 /*break*/, 3];
case 3: return [2 /*return*/, this.cachedConfig];
}
this.cachedConfig = ProjectConfig.deserialize(externalSerializedConfig);
this.cachedSerializedConfig = externalSerializedConfig;
return [3 /*break*/, 3];
case 2:
err_2 = _a.sent();
this.logger.configServiceCacheReadError(err_2);
return [3 /*break*/, 3];
case 3: return [2 /*return*/, this.cachedConfig];
}
});
});
});
}); })(cacheGetResult);
}
// Otherwise, keep the code flow synchronous so the config services can sync up
// with the cache in their ctors synchronously (see ConfigServiceBase.syncUpWithCache).
this.updateCachedConfig(cacheGetResult);
}
catch (err) {
this.logger.configServiceCacheReadError(err);
}
return Promise.resolve(this.cachedConfig);
};

@@ -82,0 +100,0 @@ ExternalConfigCache.prototype.getInMemory = function () {

import { __assign, __awaiter, __generator } from "tslib";
import { AutoPollConfigService } from "./AutoPollConfigService";
import { AutoPollOptions, LazyLoadOptions, ManualPollOptions, PollingMode } from "./ConfigCatClientOptions";
import { RefreshResult } from "./ConfigServiceBase";
import { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
import { OverrideBehaviour } from "./FlagOverrides";
import { ClientReadyState } from "./Hooks";
import { LazyLoadConfigService } from "./LazyLoadConfigService";

@@ -91,3 +90,3 @@ import { ManualPollConfigService } from "./ManualPollConfigService";

else {
this.options.hooks.emit("clientReady", ClientReadyState.HasLocalOverrideFlagDataOnly);
this.options.hooks.emit("clientReady", ClientCacheState.HasLocalOverrideFlagDataOnly);
}

@@ -551,2 +550,5 @@ this.suppressFinalize = registerForFinalization(this, { sdkKey: options.apiKey, cacheToken: cacheToken, configService: this.configService, logger: options.logger });

this.options = client["options"];
this.cacheState = remoteConfig
? client["configService"].getCacheState(remoteConfig)
: ClientCacheState.HasLocalOverrideFlagDataOnly;
}

@@ -553,0 +555,0 @@ Object.defineProperty(Snapshot.prototype, "fetchedConfig", {

@@ -20,3 +20,3 @@ import { __makeTemplateObject } from "tslib";

})(LogLevel || (LogLevel = {}));
/** Represents a log message format with names arguments. */
/** Represents a log message format with named arguments. */
var FormattableLogMessage = /** @class */ (function () {

@@ -23,0 +23,0 @@ function FormattableLogMessage(strings, argNames, argValues) {

@@ -36,2 +36,10 @@ import { __awaiter, __generator } from "tslib";

export { RefreshResult };
/** Specifies the possible states of the local cache. */
export var ClientCacheState;
(function (ClientCacheState) {
ClientCacheState[ClientCacheState["NoFlagData"] = 0] = "NoFlagData";
ClientCacheState[ClientCacheState["HasLocalOverrideFlagDataOnly"] = 1] = "HasLocalOverrideFlagDataOnly";
ClientCacheState[ClientCacheState["HasCachedFlagDataOnly"] = 2] = "HasCachedFlagDataOnly";
ClientCacheState[ClientCacheState["HasUpToDateFlagData"] = 3] = "HasUpToDateFlagData";
})(ClientCacheState || (ClientCacheState = {}));
var ConfigServiceStatus;

@@ -292,2 +300,5 @@ (function (ConfigServiceStatus) {

};
ConfigServiceBase.prototype.onCacheSynced = function (cachedConfig) {
this.options.hooks.emit("clientReady", this.getCacheState(cachedConfig));
};
ConfigServiceBase.prototype.syncUpWithCache = function () {

@@ -301,4 +312,4 @@ return __awaiter(this, void 0, void 0, function () {

cachedConfig = _a.sent();
this.options.hooks.emit("clientReady", this.getReadyState(cachedConfig));
return [2 /*return*/];
this.onCacheSynced(cachedConfig);
return [2 /*return*/, cachedConfig];
}

@@ -305,0 +316,0 @@ });

import { __spreadArrays } from "tslib";
import { ClientCacheState } from "./ConfigServiceBase";
import { NullEventEmitter } from "./EventEmitter";
/** Contains the initialization state of `ConfigCatClient`. */
export var ClientReadyState;
(function (ClientReadyState) {
ClientReadyState[ClientReadyState["NoFlagData"] = 0] = "NoFlagData";
ClientReadyState[ClientReadyState["HasLocalOverrideFlagDataOnly"] = 1] = "HasLocalOverrideFlagDataOnly";
ClientReadyState[ClientReadyState["HasCachedFlagDataOnly"] = 2] = "HasCachedFlagDataOnly";
ClientReadyState[ClientReadyState["HasUpToDateFlagData"] = 3] = "HasUpToDateFlagData";
})(ClientReadyState || (ClientReadyState = {}));
/**
* @deprecated This type is obsolete and will be removed from the public API in a future major version. Please use `ClientCacheState` instead.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export var ClientReadyState = ClientCacheState;
var disconnectedEventEmitter = new NullEventEmitter();

@@ -12,0 +10,0 @@ var Hooks = /** @class */ (function () {

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

export { OverrideBehaviour } from "./FlagOverrides";
export { RefreshResult } from "./ConfigServiceBase";
export { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
export { ClientReadyState } from "./Hooks";
import { __awaiter, __extends, __generator } from "tslib";
import { ConfigServiceBase } from "./ConfigServiceBase";
import { ClientReadyState } from "./Hooks";
import { ClientCacheState, ConfigServiceBase } from "./ConfigServiceBase";
var LazyLoadConfigService = /** @class */ (function (_super) {

@@ -49,10 +48,10 @@ __extends(LazyLoadConfigService, _super);

};
LazyLoadConfigService.prototype.getReadyState = function (cachedConfig) {
LazyLoadConfigService.prototype.getCacheState = function (cachedConfig) {
if (cachedConfig.isEmpty) {
return ClientReadyState.NoFlagData;
return ClientCacheState.NoFlagData;
}
if (cachedConfig.isExpired(this.cacheTimeToLiveMs)) {
return ClientReadyState.HasCachedFlagDataOnly;
return ClientCacheState.HasCachedFlagDataOnly;
}
return ClientReadyState.HasUpToDateFlagData;
return ClientCacheState.HasUpToDateFlagData;
};

@@ -59,0 +58,0 @@ return LazyLoadConfigService;

import { __awaiter, __extends, __generator } from "tslib";
import { ConfigServiceBase } from "./ConfigServiceBase";
import { ClientReadyState } from "./Hooks";
import { ClientCacheState, ConfigServiceBase } from "./ConfigServiceBase";
var ManualPollConfigService = /** @class */ (function (_super) {

@@ -11,7 +10,7 @@ __extends(ManualPollConfigService, _super);

}
ManualPollConfigService.prototype.getReadyState = function (cachedConfig) {
ManualPollConfigService.prototype.getCacheState = function (cachedConfig) {
if (cachedConfig.isEmpty) {
return ClientReadyState.NoFlagData;
return ClientCacheState.NoFlagData;
}
return ClientReadyState.HasCachedFlagDataOnly;
return ClientCacheState.HasCachedFlagDataOnly;
};

@@ -18,0 +17,0 @@ ManualPollConfigService.prototype.getConfig = function () {

@@ -1,5 +0,7 @@

export function delay(delayMs, obtainCancel) {
export function delay(delayMs, delayCleanup) {
var timerId;
var promise = new Promise(function (resolve) { return timerId = setTimeout(resolve, delayMs); });
obtainCancel === null || obtainCancel === void 0 ? void 0 : obtainCancel(function () { return clearTimeout(timerId); });
if (delayCleanup) {
delayCleanup.clearTimer = function () { return clearTimeout(timerId); };
}
return promise;

@@ -13,1 +15,6 @@ }

}
export function isPromiseLike(obj) {
var _a;
// See also: https://stackoverflow.com/a/27746324/8656352
return typeof ((_a = obj) === null || _a === void 0 ? void 0 : _a.then) === "function";
}

@@ -0,15 +1,18 @@

import { ClientCacheState } from "./ConfigServiceBase";
import type { IEventEmitter, IEventProvider } from "./EventEmitter";
import type { IConfig } from "./ProjectConfig";
import type { IEvaluationDetails } from "./RolloutEvaluator";
/** Contains the initialization state of `ConfigCatClient`. */
export declare enum ClientReadyState {
NoFlagData = 0,
HasLocalOverrideFlagDataOnly = 1,
HasCachedFlagDataOnly = 2,
HasUpToDateFlagData = 3
}
/**
* Contains the initialization state of `ConfigCatClient`.
* @deprecated This type is obsolete and will be removed from the public API in a future major version. Please use `ClientCacheState` instead.
*/
export declare type ClientReadyState = ClientCacheState;
/**
* @deprecated This type is obsolete and will be removed from the public API in a future major version. Please use `ClientCacheState` instead.
*/
export declare const ClientReadyState: typeof ClientCacheState;
/** Hooks (events) that can be emitted by `ConfigCatClient`. */
export declare type HookEvents = {
/** Occurs when the client is ready to provide the actual value of feature flags or settings. */
clientReady: [state: ClientReadyState];
clientReady: [cacheState: ClientCacheState];
/** Occurs after the value of a feature flag of setting has been evaluated. */

@@ -16,0 +19,0 @@ flagEvaluated: [evaluationDetails: IEvaluationDetails];

@@ -5,11 +5,9 @@ "use strict";

var tslib_1 = require("tslib");
var ConfigServiceBase_1 = require("./ConfigServiceBase");
var EventEmitter_1 = require("./EventEmitter");
/** Contains the initialization state of `ConfigCatClient`. */
var ClientReadyState;
(function (ClientReadyState) {
ClientReadyState[ClientReadyState["NoFlagData"] = 0] = "NoFlagData";
ClientReadyState[ClientReadyState["HasLocalOverrideFlagDataOnly"] = 1] = "HasLocalOverrideFlagDataOnly";
ClientReadyState[ClientReadyState["HasCachedFlagDataOnly"] = 2] = "HasCachedFlagDataOnly";
ClientReadyState[ClientReadyState["HasUpToDateFlagData"] = 3] = "HasUpToDateFlagData";
})(ClientReadyState = exports.ClientReadyState || (exports.ClientReadyState = {}));
/**
* @deprecated This type is obsolete and will be removed from the public API in a future major version. Please use `ClientCacheState` instead.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
exports.ClientReadyState = ConfigServiceBase_1.ClientCacheState;
var disconnectedEventEmitter = new EventEmitter_1.NullEventEmitter();

@@ -16,0 +14,0 @@ var Hooks = /** @class */ (function () {

@@ -52,5 +52,5 @@ import type { IConfigCatClient, IConfigCatKernel } from "./ConfigCatClient";

export { OverrideBehaviour } from "./FlagOverrides";
export { RefreshResult } from "./ConfigServiceBase";
export { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
export type { IProvidesHooks, HookEvents } from "./Hooks";
export { ClientReadyState } from "./Hooks";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientReadyState = exports.RefreshResult = exports.OverrideBehaviour = exports.User = exports.SettingKeyValue = exports.Comparator = exports.SettingType = exports.FormattableLogMessage = exports.LogLevel = exports.DataGovernance = exports.PollingMode = exports.MapOverrideDataSource = exports.FlagOverrides = exports.ExternalConfigCache = exports.FetchError = exports.FetchResult = exports.FetchStatus = exports.createConsoleLogger = exports.disposeAllClients = exports.getClient = void 0;
exports.ClientReadyState = exports.RefreshResult = exports.ClientCacheState = exports.OverrideBehaviour = exports.User = exports.SettingKeyValue = exports.Comparator = exports.SettingType = exports.FormattableLogMessage = exports.LogLevel = exports.DataGovernance = exports.PollingMode = exports.MapOverrideDataSource = exports.FlagOverrides = exports.ExternalConfigCache = exports.FetchError = exports.FetchResult = exports.FetchStatus = exports.createConsoleLogger = exports.disposeAllClients = exports.getClient = void 0;
var ConfigCatClient_1 = require("./ConfigCatClient");

@@ -63,4 +63,5 @@ var ConfigCatClientOptions_1 = require("./ConfigCatClientOptions");

var ConfigServiceBase_1 = require("./ConfigServiceBase");
Object.defineProperty(exports, "ClientCacheState", { enumerable: true, get: function () { return ConfigServiceBase_1.ClientCacheState; } });
Object.defineProperty(exports, "RefreshResult", { enumerable: true, get: function () { return ConfigServiceBase_1.RefreshResult; } });
var Hooks_1 = require("./Hooks");
Object.defineProperty(exports, "ClientReadyState", { enumerable: true, get: function () { return Hooks_1.ClientReadyState; } });
import type { LazyLoadOptions } from "./ConfigCatClientOptions";
import type { IConfigFetcher } from "./ConfigFetcher";
import type { IConfigService, RefreshResult } from "./ConfigServiceBase";
import { ConfigServiceBase } from "./ConfigServiceBase";
import { ClientReadyState } from "./Hooks";
import { ClientCacheState, ConfigServiceBase } from "./ConfigServiceBase";
import type { ProjectConfig } from "./ProjectConfig";

@@ -12,4 +11,4 @@ export declare class LazyLoadConfigService extends ConfigServiceBase<LazyLoadOptions> implements IConfigService {

refreshConfigAsync(): Promise<[RefreshResult, ProjectConfig]>;
protected getReadyState(cachedConfig: ProjectConfig): ClientReadyState;
getCacheState(cachedConfig: ProjectConfig): ClientCacheState;
}
//# sourceMappingURL=LazyLoadConfigService.d.ts.map

@@ -6,3 +6,2 @@ "use strict";

var ConfigServiceBase_1 = require("./ConfigServiceBase");
var Hooks_1 = require("./Hooks");
var LazyLoadConfigService = /** @class */ (function (_super) {

@@ -53,10 +52,10 @@ tslib_1.__extends(LazyLoadConfigService, _super);

};
LazyLoadConfigService.prototype.getReadyState = function (cachedConfig) {
LazyLoadConfigService.prototype.getCacheState = function (cachedConfig) {
if (cachedConfig.isEmpty) {
return Hooks_1.ClientReadyState.NoFlagData;
return ConfigServiceBase_1.ClientCacheState.NoFlagData;
}
if (cachedConfig.isExpired(this.cacheTimeToLiveMs)) {
return Hooks_1.ClientReadyState.HasCachedFlagDataOnly;
return ConfigServiceBase_1.ClientCacheState.HasCachedFlagDataOnly;
}
return Hooks_1.ClientReadyState.HasUpToDateFlagData;
return ConfigServiceBase_1.ClientCacheState.HasUpToDateFlagData;
};

@@ -63,0 +62,0 @@ return LazyLoadConfigService;

import type { ManualPollOptions } from "./ConfigCatClientOptions";
import type { IConfigFetcher } from "./ConfigFetcher";
import type { IConfigService, RefreshResult } from "./ConfigServiceBase";
import { ConfigServiceBase } from "./ConfigServiceBase";
import { ClientReadyState } from "./Hooks";
import { ClientCacheState, ConfigServiceBase } from "./ConfigServiceBase";
import type { ProjectConfig } from "./ProjectConfig";
export declare class ManualPollConfigService extends ConfigServiceBase<ManualPollOptions> implements IConfigService {
constructor(configFetcher: IConfigFetcher, options: ManualPollOptions);
protected getReadyState(cachedConfig: ProjectConfig): ClientReadyState;
getCacheState(cachedConfig: ProjectConfig): ClientCacheState;
getConfig(): Promise<ProjectConfig>;

@@ -11,0 +10,0 @@ refreshConfigAsync(): Promise<[RefreshResult, ProjectConfig]>;

@@ -6,3 +6,2 @@ "use strict";

var ConfigServiceBase_1 = require("./ConfigServiceBase");
var Hooks_1 = require("./Hooks");
var ManualPollConfigService = /** @class */ (function (_super) {

@@ -15,7 +14,7 @@ tslib_1.__extends(ManualPollConfigService, _super);

}
ManualPollConfigService.prototype.getReadyState = function (cachedConfig) {
ManualPollConfigService.prototype.getCacheState = function (cachedConfig) {
if (cachedConfig.isEmpty) {
return Hooks_1.ClientReadyState.NoFlagData;
return ConfigServiceBase_1.ClientCacheState.NoFlagData;
}
return Hooks_1.ClientReadyState.HasCachedFlagDataOnly;
return ConfigServiceBase_1.ClientCacheState.HasCachedFlagDataOnly;
};

@@ -22,0 +21,0 @@ ManualPollConfigService.prototype.getConfig = function () {

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

export declare function delay(delayMs: number, obtainCancel?: (cancel: () => void) => void): Promise<void>;
export declare function delay(delayMs: number, delayCleanup?: {
clearTimer?: () => void;
} | null): Promise<void>;
export declare function errorToString(err: any, includeStackTrace?: boolean): string;
export declare function isPromiseLike<T>(obj: unknown): obj is PromiseLike<T>;
//# sourceMappingURL=Utils.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorToString = exports.delay = void 0;
function delay(delayMs, obtainCancel) {
exports.isPromiseLike = exports.errorToString = exports.delay = void 0;
function delay(delayMs, delayCleanup) {
var timerId;
var promise = new Promise(function (resolve) { return timerId = setTimeout(resolve, delayMs); });
obtainCancel === null || obtainCancel === void 0 ? void 0 : obtainCancel(function () { return clearTimeout(timerId); });
if (delayCleanup) {
delayCleanup.clearTimer = function () { return clearTimeout(timerId); };
}
return promise;

@@ -18,1 +20,7 @@ }

exports.errorToString = errorToString;
function isPromiseLike(obj) {
var _a;
// See also: https://stackoverflow.com/a/27746324/8656352
return typeof ((_a = obj) === null || _a === void 0 ? void 0 : _a.then) === "function";
}
exports.isPromiseLike = isPromiseLike;
{
"name": "configcat-common",
"version": "8.1.1",
"version": "8.2.0",
"description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.",

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

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