Socket
Socket
Sign inDemoInstall

configcat-js-chromium-extension

Package Overview
Dependencies
3
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 1.0.0

CHANGELOG.md

11

lib/Cache.d.ts

@@ -1,9 +0,6 @@

import { ICache, ProjectConfig } from "configcat-common";
export declare class LocalStorageCache implements ICache {
cache: {
[key: string]: ProjectConfig;
};
set(key: string, config: ProjectConfig): Promise<void> | void;
get(key: string): Promise<ProjectConfig | null> | ProjectConfig | null;
import type { IConfigCatCache } from "configcat-common";
export declare class LocalStorageCache implements IConfigCatCache {
set(key: string, value: string): Promise<void>;
get(key: string): Promise<string | undefined>;
}
//# sourceMappingURL=Cache.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalStorageCache = void 0;
var tslib_1 = require("tslib");
var LocalStorageCache = /** @class */ (function () {
function LocalStorageCache() {
this.cache = {};
}
LocalStorageCache.prototype.set = function (key, config) {
this.cache[key] = config;
var obj = {};
obj[key] = btoa(JSON.stringify(config));
return new Promise(function (resolve) {
try {
chrome.storage.local.set(obj).then(function () {
resolve();
});
}
catch (ex) {
// chrome storage is unavailable
resolve();
}
LocalStorageCache.prototype.set = function (key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var ex_1;
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
return [4 /*yield*/, chrome.storage.local.set((_a = {}, _a[key] = btoa(value), _a))];
case 1:
_b.sent();
return [3 /*break*/, 3];
case 2:
ex_1 = _b.sent();
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});
};
LocalStorageCache.prototype.get = function (key) {
var _this = this;
var config = this.cache[key];
if (config) {
return config;
}
return new Promise(function (resolve) {
try {
chrome.storage.local.get(key, function (res) {
var configString = res[key];
if (configString) {
var config_1 = JSON.parse(atob(configString));
if (config_1) {
_this.cache[key] = config_1;
resolve(config_1);
return;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var cacheObj, configString, ex_2;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, chrome.storage.local.get(key)];
case 1:
cacheObj = _a.sent();
configString = cacheObj[key];
if (configString) {
return [2 /*return*/, atob(configString)];
}
}
resolve(null);
});
}
catch (ex) {
// chrome storage is unavailable or invalid cache value.
resolve(null);
}
return [3 /*break*/, 3];
case 2:
ex_2 = _a.sent();
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});

@@ -50,0 +50,0 @@ };

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

import { IConfigFetcher, OptionsBase, FetchResult } from "configcat-common";
import type { IConfigFetcher, IFetchResponse, OptionsBase } from "configcat-common";
export declare class HttpConfigFetcher implements IConfigFetcher {
fetchLogic(options: OptionsBase, lastEtag: string, callback: (result: FetchResult) => void): void;
fetchLogic(options: OptionsBase, lastEtag: string | null): Promise<IFetchResponse>;
}
//# sourceMappingURL=ConfigFetcher.d.ts.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpConfigFetcher = void 0;
var tslib_1 = require("tslib");
var configcat_common_1 = require("configcat-common");

@@ -44,40 +9,52 @@ var HttpConfigFetcher = /** @class */ (function () {

}
HttpConfigFetcher.prototype.fetchLogic = function (options, lastEtag, callback) {
var _this = this;
var controller = new AbortController();
var timeoutId = setTimeout(function () { return controller.abort(); }, options.requestTimeoutMs);
fetch(options.getUrl(), {
method: "GET",
signal: controller.signal
}).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
var text, etag;
return __generator(this, function (_a) {
switch (_a.label) {
HttpConfigFetcher.prototype.fetchLogic = function (options, lastEtag) {
var _a, _b, _c;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var requestInit, cleanup, controller_1, timeoutId_1, response, statusCode, reasonPhrase, body, eTag, err_1;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!(response.status === 200)) return [3 /*break*/, 2];
return [4 /*yield*/, response.text()];
requestInit = { method: "GET" };
// NOTE: Older Chromium versions (e.g. the one used in our tests) may not support AbortController.
if (typeof AbortController !== "undefined") {
controller_1 = new AbortController();
timeoutId_1 = setTimeout(function () { return controller_1.abort(); }, options.requestTimeoutMs);
requestInit.signal = controller_1.signal;
cleanup = function () { return clearTimeout(timeoutId_1); };
}
else {
cleanup = function () { };
}
_d.label = 1;
case 1:
text = _a.sent();
etag = response.headers && response.headers.get("Etag");
clearTimeout(timeoutId);
callback(configcat_common_1.FetchResult.success(text, etag !== null && etag !== void 0 ? etag : ""));
return [3 /*break*/, 3];
_d.trys.push([1, 6, 7, 8]);
return [4 /*yield*/, fetch(options.getUrl(), requestInit)];
case 2:
if (response.status === 304) {
clearTimeout(timeoutId);
callback(configcat_common_1.FetchResult.notModified());
response = _d.sent();
statusCode = response.status, reasonPhrase = response.statusText;
if (!(statusCode === 200)) return [3 /*break*/, 4];
return [4 /*yield*/, response.text()];
case 3:
body = _d.sent();
eTag = (_b = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("Etag")) !== null && _b !== void 0 ? _b : void 0;
return [2 /*return*/, { statusCode: statusCode, reasonPhrase: reasonPhrase, eTag: eTag, body: body }];
case 4: return [2 /*return*/, { statusCode: statusCode, reasonPhrase: reasonPhrase }];
case 5: return [3 /*break*/, 8];
case 6:
err_1 = _d.sent();
if (err_1 instanceof DOMException && err_1.name === "AbortError") {
if ((_c = requestInit.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
throw new configcat_common_1.FetchError("timeout", options.requestTimeoutMs);
}
else {
throw new configcat_common_1.FetchError("abort");
}
}
else {
options.logger.error("Failed to download feature flags & settings from ConfigCat. " + response.status + " - " + response.statusText);
clearTimeout(timeoutId);
callback(configcat_common_1.FetchResult.error());
}
_a.label = 3;
case 3: return [2 /*return*/];
throw new configcat_common_1.FetchError("failure", err_1);
case 7:
cleanup();
return [7 /*endfinally*/];
case 8: return [2 /*return*/];
}
});
}); }).catch(function (error) {
options.logger.error("Failed to download feature flags & settings from ConfigCat. Error: " + error);
clearTimeout(timeoutId);
callback(configcat_common_1.FetchResult.error());
});

@@ -84,0 +61,0 @@ };

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

import { __awaiter, __generator } from "tslib";
var LocalStorageCache = /** @class */ (function () {
function LocalStorageCache() {
this.cache = {};
}
LocalStorageCache.prototype.set = function (key, config) {
this.cache[key] = config;
var obj = {};
obj[key] = btoa(JSON.stringify(config));
return new Promise(function (resolve) {
try {
chrome.storage.local.set(obj).then(function () {
resolve();
});
}
catch (ex) {
// chrome storage is unavailable
resolve();
}
LocalStorageCache.prototype.set = function (key, value) {
return __awaiter(this, void 0, void 0, function () {
var ex_1;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 3]);
return [4 /*yield*/, chrome.storage.local.set((_a = {}, _a[key] = btoa(value), _a))];
case 1:
_b.sent();
return [3 /*break*/, 3];
case 2:
ex_1 = _b.sent();
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});
};
LocalStorageCache.prototype.get = function (key) {
var _this = this;
var config = this.cache[key];
if (config) {
return config;
}
return new Promise(function (resolve) {
try {
chrome.storage.local.get(key, function (res) {
var configString = res[key];
if (configString) {
var config_1 = JSON.parse(atob(configString));
if (config_1) {
_this.cache[key] = config_1;
resolve(config_1);
return;
return __awaiter(this, void 0, void 0, function () {
var cacheObj, configString, ex_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, chrome.storage.local.get(key)];
case 1:
cacheObj = _a.sent();
configString = cacheObj[key];
if (configString) {
return [2 /*return*/, atob(configString)];
}
}
resolve(null);
});
}
catch (ex) {
// chrome storage is unavailable or invalid cache value.
resolve(null);
}
return [3 /*break*/, 3];
case 2:
ex_2 = _a.sent();
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});

@@ -47,0 +47,0 @@ };

@@ -1,79 +0,56 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { FetchResult } from "configcat-common";
import { __awaiter, __generator } from "tslib";
import { FetchError } from "configcat-common";
var HttpConfigFetcher = /** @class */ (function () {
function HttpConfigFetcher() {
}
HttpConfigFetcher.prototype.fetchLogic = function (options, lastEtag, callback) {
var _this = this;
var controller = new AbortController();
var timeoutId = setTimeout(function () { return controller.abort(); }, options.requestTimeoutMs);
fetch(options.getUrl(), {
method: "GET",
signal: controller.signal
}).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
var text, etag;
return __generator(this, function (_a) {
switch (_a.label) {
HttpConfigFetcher.prototype.fetchLogic = function (options, lastEtag) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
var requestInit, cleanup, controller_1, timeoutId_1, response, statusCode, reasonPhrase, body, eTag, err_1;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!(response.status === 200)) return [3 /*break*/, 2];
return [4 /*yield*/, response.text()];
requestInit = { method: "GET" };
// NOTE: Older Chromium versions (e.g. the one used in our tests) may not support AbortController.
if (typeof AbortController !== "undefined") {
controller_1 = new AbortController();
timeoutId_1 = setTimeout(function () { return controller_1.abort(); }, options.requestTimeoutMs);
requestInit.signal = controller_1.signal;
cleanup = function () { return clearTimeout(timeoutId_1); };
}
else {
cleanup = function () { };
}
_d.label = 1;
case 1:
text = _a.sent();
etag = response.headers && response.headers.get("Etag");
clearTimeout(timeoutId);
callback(FetchResult.success(text, etag !== null && etag !== void 0 ? etag : ""));
return [3 /*break*/, 3];
_d.trys.push([1, 6, 7, 8]);
return [4 /*yield*/, fetch(options.getUrl(), requestInit)];
case 2:
if (response.status === 304) {
clearTimeout(timeoutId);
callback(FetchResult.notModified());
response = _d.sent();
statusCode = response.status, reasonPhrase = response.statusText;
if (!(statusCode === 200)) return [3 /*break*/, 4];
return [4 /*yield*/, response.text()];
case 3:
body = _d.sent();
eTag = (_b = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("Etag")) !== null && _b !== void 0 ? _b : void 0;
return [2 /*return*/, { statusCode: statusCode, reasonPhrase: reasonPhrase, eTag: eTag, body: body }];
case 4: return [2 /*return*/, { statusCode: statusCode, reasonPhrase: reasonPhrase }];
case 5: return [3 /*break*/, 8];
case 6:
err_1 = _d.sent();
if (err_1 instanceof DOMException && err_1.name === "AbortError") {
if ((_c = requestInit.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
throw new FetchError("timeout", options.requestTimeoutMs);
}
else {
throw new FetchError("abort");
}
}
else {
options.logger.error("Failed to download feature flags & settings from ConfigCat. " + response.status + " - " + response.statusText);
clearTimeout(timeoutId);
callback(FetchResult.error());
}
_a.label = 3;
case 3: return [2 /*return*/];
throw new FetchError("failure", err_1);
case 7:
cleanup();
return [7 /*endfinally*/];
case 8: return [2 /*return*/];
}
});
}); }).catch(function (error) {
options.logger.error("Failed to download feature flags & settings from ConfigCat. Error: " + error);
clearTimeout(timeoutId);
callback(FetchResult.error());
});

@@ -80,0 +57,0 @@ };

@@ -0,83 +1,62 @@

import { ExternalConfigCache, FlagOverrides, MapOverrideDataSource, PollingMode } from "configcat-common";
import * as configcatcommon from "configcat-common";
import { LocalStorageCache } from "./Cache";
import { HttpConfigFetcher } from "./ConfigFetcher";
import { LocalStorageCache } from "./Cache";
import CONFIGCAT_SDK_VERSION from "./Version";
/**
* Create an instance of ConfigCatClient and setup Auto polling with default options.
* @param {string} sdkkey - SDK Key to access your configuration.
* @param options - Options for Auto polling
* Returns an instance of `ConfigCatClient` for the specified SDK Key.
* @remarks This method returns a single, shared instance per each distinct SDK Key.
* That is, a new client object is created only when there is none available for the specified SDK Key.
* Otherwise, the already created instance is returned (in which case the `pollingMode` and `options` arguments are ignored).
* So, please keep in mind that when you make multiple calls to this method using the same SDK Key, you may end up with multiple references to the same client object.
* @param sdkKey SDK Key to access the ConfigCat config.
* @param pollingMode The polling mode to use.
* @param options Options for the specified polling mode.
*/
export function createClient(sdkkey, options) {
return createClientWithAutoPoll(sdkkey, options);
}
/**
* Create an instance of ConfigCatClient and setup Auto polling.
* @param {string} sdkkey - SDK Key to access your configuration.
* @param options - Options for Auto polling
*/
export function createClientWithAutoPoll(sdkKey, options) {
return configcatcommon.createClientWithAutoPoll(sdkKey, {
export function getClient(sdkKey, pollingMode, options) {
return configcatcommon.getClient(sdkKey, pollingMode !== null && pollingMode !== void 0 ? pollingMode : PollingMode.AutoPoll, options, {
configFetcher: new HttpConfigFetcher(),
cache: new LocalStorageCache(),
sdkType: "ConfigCat-JS-Chromium",
sdkVersion: CONFIGCAT_SDK_VERSION,
}, options);
defaultCacheFactory: function (options) { return new ExternalConfigCache(new LocalStorageCache(), options.logger); }
});
}
/**
* Create an instance of ConfigCatClient and setup Manual polling.
* @param {string} sdkKey - SDK Key to access your configuration.
* @param options - Options for Manual polling
* Disposes all existing `ConfigCatClient` instances.
*/
export function createClientWithManualPoll(sdkKey, options) {
return configcatcommon.createClientWithManualPoll(sdkKey, {
configFetcher: new HttpConfigFetcher(),
cache: new LocalStorageCache(),
sdkType: "ConfigCat-JS-Chromium",
sdkVersion: CONFIGCAT_SDK_VERSION,
}, options);
export function disposeAllClients() {
configcatcommon.disposeAllClients();
}
/**
* Create an instance of ConfigCatClient and setup Lazy loading.
* @param {string} sdkKey - SDK Key to access your configuration.
* @param options - Options for Lazy loading
* Creates an instance of `ConfigCatConsoleLogger`.
* @param logLevel Log level (the minimum level to use for filtering log events).
*/
export function createClientWithLazyLoad(sdkKey, options) {
return configcatcommon.createClientWithLazyLoad(sdkKey, {
configFetcher: new HttpConfigFetcher(),
cache: new LocalStorageCache(),
sdkType: "ConfigCat-JS-Chromium",
sdkVersion: CONFIGCAT_SDK_VERSION,
}, options);
}
export function createConsoleLogger(logLevel) {
return configcatcommon.createConsoleLogger(logLevel);
}
/**
* Creates an instance of `FlagOverrides` that uses a map data source.
* @param map The map that contains the overrides.
* @param behaviour The override behaviour.
* Specifies whether the local values should override the remote values
* or local values should only be used when a remote value doesn't exist
* or the local values should be used only.
*/
export function createFlagOverridesFromMap(map, behaviour) {
return new configcatcommon.FlagOverrides(new configcatcommon.MapOverrideDataSource(map), behaviour);
return new FlagOverrides(new MapOverrideDataSource(map), behaviour);
}
export var DataGovernance = {
/** Select this if your feature flags are published to all global CDN nodes. */
Global: configcatcommon.DataGovernance.Global,
/** Select this if your feature flags are published to CDN nodes only in the EU. */
EuOnly: configcatcommon.DataGovernance.EuOnly,
};
export var OverrideBehaviour = {
/**
* When evaluating values, the SDK will not use feature flags and settings from the ConfigCat CDN, but it will use
* all feature flags and settings that are loaded from local-override sources.
*/
LocalOnly: configcatcommon.OverrideBehaviour.LocalOnly,
/**
* When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN,
* plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is
* defined both in the fetched and the local-override source then the local-override version will take precedence.
*/
LocalOverRemote: configcatcommon.OverrideBehaviour.LocalOverRemote,
/**
* When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN,
* plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is
* defined both in the fetched and the local-override source then the fetched version will take precedence.
*/
RemoteOverLocal: configcatcommon.OverrideBehaviour.RemoteOverLocal,
};
export default createClient;
/* Public types re-export from common-js */
// These exports should be kept in sync with the exports listed in the section "Public types for end users" of common-js/src/index.ts!
export { PollingMode } from "configcat-common";
export { DataGovernance } from "configcat-common";
export { LogLevel } from "configcat-common";
export { FormattableLogMessage } from "configcat-common";
export { SettingType, Comparator } from "configcat-common";
export { SettingKeyValue } from "configcat-common";
export { User } from "configcat-common";
export { OverrideBehaviour } from "configcat-common";
export { RefreshResult } from "configcat-common";
/* Default export */
export default function (sdkKey, options) {
return getClient(sdkKey, PollingMode.AutoPoll, options);
}

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

export default "0.0.1";
export default "1.0.0";

@@ -1,60 +0,64 @@

import * as configcatcommon from "configcat-common";
import { IConfigCatClient, LogLevel } from "configcat-common";
import type { IAutoPollOptions, IConfigCatClient, IConfigCatLogger, ILazyLoadingOptions, IManualPollOptions, LogLevel, OverrideBehaviour, SettingValue } from "configcat-common";
import { FlagOverrides, PollingMode } from "configcat-common";
/**
* Create an instance of ConfigCatClient and setup Auto polling with default options.
* @param {string} sdkkey - SDK Key to access your configuration.
* @param options - Options for Auto polling
* Returns an instance of `ConfigCatClient` for the specified SDK Key.
* @remarks This method returns a single, shared instance per each distinct SDK Key.
* That is, a new client object is created only when there is none available for the specified SDK Key.
* Otherwise, the already created instance is returned (in which case the `pollingMode` and `options` arguments are ignored).
* So, please keep in mind that when you make multiple calls to this method using the same SDK Key, you may end up with multiple references to the same client object.
* @param sdkKey SDK Key to access the ConfigCat config.
* @param pollingMode The polling mode to use.
* @param options Options for the specified polling mode.
*/
export declare function createClient(sdkkey: string, options?: IJSAutoPollOptions): IConfigCatClient;
export declare function getClient<TMode extends PollingMode | undefined>(sdkKey: string, pollingMode?: TMode, options?: OptionsForPollingMode<TMode>): IConfigCatClient;
/**
* Create an instance of ConfigCatClient and setup Auto polling.
* @param {string} sdkkey - SDK Key to access your configuration.
* @param options - Options for Auto polling
* Disposes all existing `ConfigCatClient` instances.
*/
export declare function createClientWithAutoPoll(sdkKey: string, options?: IJSAutoPollOptions): IConfigCatClient;
export declare function disposeAllClients(): void;
/**
* Create an instance of ConfigCatClient and setup Manual polling.
* @param {string} sdkKey - SDK Key to access your configuration.
* @param options - Options for Manual polling
* Creates an instance of `ConfigCatConsoleLogger`.
* @param logLevel Log level (the minimum level to use for filtering log events).
*/
export declare function createClientWithManualPoll(sdkKey: string, options?: IJSManualPollOptions): IConfigCatClient;
export declare function createConsoleLogger(logLevel: LogLevel): IConfigCatLogger;
/**
* Create an instance of ConfigCatClient and setup Lazy loading.
* @param {string} sdkKey - SDK Key to access your configuration.
* @param options - Options for Lazy loading
* Creates an instance of `FlagOverrides` that uses a map data source.
* @param map The map that contains the overrides.
* @param behaviour The override behaviour.
* Specifies whether the local values should override the remote values
* or local values should only be used when a remote value doesn't exist
* or the local values should be used only.
*/
export declare function createClientWithLazyLoad(sdkKey: string, options?: IJSLazyLoadingOptions): IConfigCatClient;
export declare function createConsoleLogger(logLevel: LogLevel): configcatcommon.IConfigCatLogger;
export declare function createFlagOverridesFromMap(map: {
[name: string]: any;
}, behaviour: number): configcatcommon.FlagOverrides;
export declare type IJSAutoPollOptions = configcatcommon.IAutoPollOptions;
export declare type IJSLazyLoadingOptions = configcatcommon.ILazyLoadingOptions;
export declare type IJSManualPollOptions = configcatcommon.IManualPollOptions;
export declare const DataGovernance: {
/** Select this if your feature flags are published to all global CDN nodes. */
Global: configcatcommon.DataGovernance;
/** Select this if your feature flags are published to CDN nodes only in the EU. */
EuOnly: configcatcommon.DataGovernance;
};
export declare const OverrideBehaviour: {
/**
* When evaluating values, the SDK will not use feature flags and settings from the ConfigCat CDN, but it will use
* all feature flags and settings that are loaded from local-override sources.
*/
LocalOnly: configcatcommon.OverrideBehaviour;
/**
* When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN,
* plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is
* defined both in the fetched and the local-override source then the local-override version will take precedence.
*/
LocalOverRemote: configcatcommon.OverrideBehaviour;
/**
* When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN,
* plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is
* defined both in the fetched and the local-override source then the fetched version will take precedence.
*/
RemoteOverLocal: configcatcommon.OverrideBehaviour;
};
export default createClient;
[name: string]: NonNullable<SettingValue>;
}, behaviour: OverrideBehaviour): FlagOverrides;
/** Options used to configure the ConfigCat SDK in the case of Auto Polling mode. */
export interface IJSAutoPollOptions extends IAutoPollOptions {
}
/** Options used to configure the ConfigCat SDK in the case of Lazy Loading mode. */
export interface IJSLazyLoadingOptions extends ILazyLoadingOptions {
}
/** Options used to configure the ConfigCat SDK in the case of Manual Polling mode. */
export interface IJSManualPollOptions extends IManualPollOptions {
}
export type OptionsForPollingMode<TMode extends PollingMode | undefined> = TMode extends PollingMode.AutoPoll ? IJSAutoPollOptions : TMode extends PollingMode.ManualPoll ? IJSManualPollOptions : TMode extends PollingMode.LazyLoad ? IJSLazyLoadingOptions : TMode extends undefined ? IJSAutoPollOptions : never;
export { PollingMode } from "configcat-common";
export type { IOptions } from "configcat-common";
export type { IAutoPollOptions, IManualPollOptions, ILazyLoadingOptions } from "configcat-common";
export { DataGovernance } from "configcat-common";
export type { IConfigCatLogger } from "configcat-common";
export type { LogEventId, LogMessage } from "configcat-common";
export { LogLevel } from "configcat-common";
export { FormattableLogMessage } from "configcat-common";
export type { IConfigCatCache } from "configcat-common";
export type { IConfig, ISetting, ITargetingRule, IPercentageOption, SettingValue, VariationIdValue } from "configcat-common";
export { SettingType, Comparator } from "configcat-common";
export type { IConfigCatClient } from "configcat-common";
export { SettingKeyValue } from "configcat-common";
export type { IEvaluationDetails, SettingTypeOf } from "configcat-common";
export { User } from "configcat-common";
export type { FlagOverrides } from "configcat-common";
export { OverrideBehaviour } from "configcat-common";
export { RefreshResult } from "configcat-common";
export type { IProvidesHooks, HookEvents } from "configcat-common";
export default function (sdkKey: string, options?: IJSAutoPollOptions): IConfigCatClient;
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OverrideBehaviour = exports.DataGovernance = exports.createFlagOverridesFromMap = exports.createConsoleLogger = exports.createClientWithLazyLoad = exports.createClientWithManualPoll = exports.createClientWithAutoPoll = exports.createClient = void 0;
exports.RefreshResult = exports.OverrideBehaviour = exports.User = exports.SettingKeyValue = exports.Comparator = exports.SettingType = exports.FormattableLogMessage = exports.LogLevel = exports.DataGovernance = exports.PollingMode = exports.createFlagOverridesFromMap = exports.createConsoleLogger = exports.disposeAllClients = exports.getClient = void 0;
var configcat_common_1 = require("configcat-common");
var configcatcommon = require("configcat-common");
var Cache_1 = require("./Cache");
var ConfigFetcher_1 = require("./ConfigFetcher");
var Cache_1 = require("./Cache");
var Version_1 = require("./Version");
/**
* Create an instance of ConfigCatClient and setup Auto polling with default options.
* @param {string} sdkkey - SDK Key to access your configuration.
* @param options - Options for Auto polling
* Returns an instance of `ConfigCatClient` for the specified SDK Key.
* @remarks This method returns a single, shared instance per each distinct SDK Key.
* That is, a new client object is created only when there is none available for the specified SDK Key.
* Otherwise, the already created instance is returned (in which case the `pollingMode` and `options` arguments are ignored).
* So, please keep in mind that when you make multiple calls to this method using the same SDK Key, you may end up with multiple references to the same client object.
* @param sdkKey SDK Key to access the ConfigCat config.
* @param pollingMode The polling mode to use.
* @param options Options for the specified polling mode.
*/
function createClient(sdkkey, options) {
return createClientWithAutoPoll(sdkkey, options);
}
exports.createClient = createClient;
/**
* Create an instance of ConfigCatClient and setup Auto polling.
* @param {string} sdkkey - SDK Key to access your configuration.
* @param options - Options for Auto polling
*/
function createClientWithAutoPoll(sdkKey, options) {
return configcatcommon.createClientWithAutoPoll(sdkKey, {
function getClient(sdkKey, pollingMode, options) {
return configcatcommon.getClient(sdkKey, pollingMode !== null && pollingMode !== void 0 ? pollingMode : configcat_common_1.PollingMode.AutoPoll, options, {
configFetcher: new ConfigFetcher_1.HttpConfigFetcher(),
cache: new Cache_1.LocalStorageCache(),
sdkType: "ConfigCat-JS-Chromium",
sdkVersion: Version_1.default,
}, options);
defaultCacheFactory: function (options) { return new configcat_common_1.ExternalConfigCache(new Cache_1.LocalStorageCache(), options.logger); }
});
}
exports.createClientWithAutoPoll = createClientWithAutoPoll;
exports.getClient = getClient;
/**
* Create an instance of ConfigCatClient and setup Manual polling.
* @param {string} sdkKey - SDK Key to access your configuration.
* @param options - Options for Manual polling
* Disposes all existing `ConfigCatClient` instances.
*/
function createClientWithManualPoll(sdkKey, options) {
return configcatcommon.createClientWithManualPoll(sdkKey, {
configFetcher: new ConfigFetcher_1.HttpConfigFetcher(),
cache: new Cache_1.LocalStorageCache(),
sdkType: "ConfigCat-JS-Chromium",
sdkVersion: Version_1.default,
}, options);
function disposeAllClients() {
configcatcommon.disposeAllClients();
}
exports.createClientWithManualPoll = createClientWithManualPoll;
exports.disposeAllClients = disposeAllClients;
/**
* Create an instance of ConfigCatClient and setup Lazy loading.
* @param {string} sdkKey - SDK Key to access your configuration.
* @param options - Options for Lazy loading
* Creates an instance of `ConfigCatConsoleLogger`.
* @param logLevel Log level (the minimum level to use for filtering log events).
*/
function createClientWithLazyLoad(sdkKey, options) {
return configcatcommon.createClientWithLazyLoad(sdkKey, {
configFetcher: new ConfigFetcher_1.HttpConfigFetcher(),
cache: new Cache_1.LocalStorageCache(),
sdkType: "ConfigCat-JS-Chromium",
sdkVersion: Version_1.default,
}, options);
}
exports.createClientWithLazyLoad = createClientWithLazyLoad;
function createConsoleLogger(logLevel) {

@@ -63,31 +43,39 @@ return configcatcommon.createConsoleLogger(logLevel);

exports.createConsoleLogger = createConsoleLogger;
/**
* Creates an instance of `FlagOverrides` that uses a map data source.
* @param map The map that contains the overrides.
* @param behaviour The override behaviour.
* Specifies whether the local values should override the remote values
* or local values should only be used when a remote value doesn't exist
* or the local values should be used only.
*/
function createFlagOverridesFromMap(map, behaviour) {
return new configcatcommon.FlagOverrides(new configcatcommon.MapOverrideDataSource(map), behaviour);
return new configcat_common_1.FlagOverrides(new configcat_common_1.MapOverrideDataSource(map), behaviour);
}
exports.createFlagOverridesFromMap = createFlagOverridesFromMap;
exports.DataGovernance = {
/** Select this if your feature flags are published to all global CDN nodes. */
Global: configcatcommon.DataGovernance.Global,
/** Select this if your feature flags are published to CDN nodes only in the EU. */
EuOnly: configcatcommon.DataGovernance.EuOnly,
};
exports.OverrideBehaviour = {
/**
* When evaluating values, the SDK will not use feature flags and settings from the ConfigCat CDN, but it will use
* all feature flags and settings that are loaded from local-override sources.
*/
LocalOnly: configcatcommon.OverrideBehaviour.LocalOnly,
/**
* When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN,
* plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is
* defined both in the fetched and the local-override source then the local-override version will take precedence.
*/
LocalOverRemote: configcatcommon.OverrideBehaviour.LocalOverRemote,
/**
* When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN,
* plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is
* defined both in the fetched and the local-override source then the fetched version will take precedence.
*/
RemoteOverLocal: configcatcommon.OverrideBehaviour.RemoteOverLocal,
};
exports.default = createClient;
/* Public types re-export from common-js */
// These exports should be kept in sync with the exports listed in the section "Public types for end users" of common-js/src/index.ts!
var configcat_common_2 = require("configcat-common");
Object.defineProperty(exports, "PollingMode", { enumerable: true, get: function () { return configcat_common_2.PollingMode; } });
var configcat_common_3 = require("configcat-common");
Object.defineProperty(exports, "DataGovernance", { enumerable: true, get: function () { return configcat_common_3.DataGovernance; } });
var configcat_common_4 = require("configcat-common");
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return configcat_common_4.LogLevel; } });
var configcat_common_5 = require("configcat-common");
Object.defineProperty(exports, "FormattableLogMessage", { enumerable: true, get: function () { return configcat_common_5.FormattableLogMessage; } });
var configcat_common_6 = require("configcat-common");
Object.defineProperty(exports, "SettingType", { enumerable: true, get: function () { return configcat_common_6.SettingType; } });
Object.defineProperty(exports, "Comparator", { enumerable: true, get: function () { return configcat_common_6.Comparator; } });
var configcat_common_7 = require("configcat-common");
Object.defineProperty(exports, "SettingKeyValue", { enumerable: true, get: function () { return configcat_common_7.SettingKeyValue; } });
var configcat_common_8 = require("configcat-common");
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return configcat_common_8.User; } });
var configcat_common_9 = require("configcat-common");
Object.defineProperty(exports, "OverrideBehaviour", { enumerable: true, get: function () { return configcat_common_9.OverrideBehaviour; } });
var configcat_common_10 = require("configcat-common");
Object.defineProperty(exports, "RefreshResult", { enumerable: true, get: function () { return configcat_common_10.RefreshResult; } });
/* Default export */
function default_1(sdkKey, options) {
return getClient(sdkKey, configcat_common_1.PollingMode.AutoPoll, options);
}
exports.default = default_1;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "0.0.1";
exports.default = "1.0.0";
{
"name": "configcat-js-chromium-extension",
"version": "0.0.1",
"description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "lib/esm/index.js",
"scripts": {
"test": "karma start karma-chrome-coverage.conf.js",
"test-chrome": "karma start karma-chrome.conf.js",
"test-chromium": "karma start karma-chromium.conf.js",
"build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && gulp tsc",
"buildPure": "webpack && gulp webpack",
"prepare": "npm run build",
"lint": "eslint . --ext .ts",
"lint-fix": "eslint . --ext .ts --fix"
},
"keywords": [
"configcat",
"config",
"configuration",
"remote configuration",
"configcat client",
"feature flags",
"feature toggle",
"feature switch",
"canary release",
"soft launch",
"release strategy"
],
"author": "ConfigCat",
"license": "MIT",
"homepage": "https://configcat.com",
"dependencies": {
"@types/chrome": "0.0.193",
"configcat-common": "^6.0.1"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"@types/node": "^18.6.5",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"chai": "^4.3.6",
"core-js": "^3.24.1",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"gulp": "^4.0.2",
"gulp-replace": "^1.1.3",
"gulp-typescript": "^6.0.0-alpha.1",
"karma": "^6.4.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-cli": "^2.0.0",
"karma-coverage": "^2.2.0",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-safari-launcher": "^1.0.0",
"karma-typescript": "^5.5.3",
"karma-typescript-es6-transform": "^5.5.3",
"mocha": "^8.1.3",
"prettier": "^2.7.1",
"ts-loader": "^9.3.1",
"typescript": "^3.9.10",
"webpack": "^5.74.0",
"webpack-auto-inject-version": "^1.2.2",
"webpack-cli": "^4.10.0"
},
"repository": {
"type": "git",
"url": "https://github.com/configcat/js-chromium-extension-sdk"
},
"sideEffects": false
"name": "configcat-js-chromium-extension",
"version": "1.0.0",
"description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "lib/esm/index.js",
"scripts": {
"test": "karma start karma-chrome-coverage.conf.js",
"test-chrome": "karma start karma-chrome.conf.js",
"test-chromium": "karma start karma-chromium.conf.js",
"build": "tsc -p tsconfig.build.cjs.json && tsc -p tsconfig.build.esm.json && gulp tsc",
"buildPure": "webpack && gulp webpack",
"prepare": "npm run build",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix"
},
"keywords": [
"configcat",
"config",
"configuration",
"remote configuration",
"configcat client",
"feature flags",
"feature toggle",
"feature switch",
"canary release",
"soft launch",
"release strategy"
],
"author": "ConfigCat",
"license": "MIT",
"homepage": "https://configcat.com",
"dependencies": {
"@types/chrome": "0.0.193",
"configcat-common": "^8.0.0",
"tslib": "^2.4.1"
},
"devDependencies": {
"@ephesoft/webpack.istanbul.loader": "^2.2.0",
"@types/chai": "4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"chai": "^4.3.7",
"core-js": "^3.24.1",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"fetch-mock": "^9.11.0",
"gulp": "^4.0.2",
"gulp-replace": "^1.1.3",
"gulp-typescript": "^6.0.0-alpha.1",
"karma": "^6.4.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-cli": "^2.0.0",
"karma-coverage": "^2.2.0",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-safari-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.8",
"karma-webpack": "^5.0.0",
"mocha": "^10.2.0",
"ts-loader": "^9.3.1",
"typescript": "^4.9.4",
"webpack": "^5.77.0",
"webpack-auto-inject-version": "^1.2.2",
"webpack-cli": "^4.10.0"
},
"overrides": {
"chokidar": "3.5.3",
"glob-parent": "5.1.2",
"loader-utils": "1.4.2"
},
"repository": {
"type": "git",
"url": "https://github.com/configcat/js-chromium-extension-sdk"
},
"sideEffects": false
}

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

# ConfigCat SDK for Chrome Extensions [Beta]
# ConfigCat SDK for Chrome Extensions
https://configcat.com

@@ -35,4 +35,6 @@

```
> We strongly recommend using the *ConfigCat Client* as a Singleton object in your application.
> You can acquire singleton client instances for your SDK keys using the `getClient("<sdkKey>")` factory function.
(However, please keep in mind that subsequent calls to `getClient()` with the *same SDK Key* return a *shared* client instance, which was set up by the first call.)
### 4. Get your setting value:

@@ -39,0 +41,0 @@ The Promise (async/await) way:

Sorry, the diff of this file is too big to display

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc