Socket
Socket
Sign inDemoInstall

configcat-js-ssr

Package Overview
Dependencies
Maintainers
4
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configcat-js-ssr - npm Package Compare versions

Comparing version 8.1.0 to 8.2.0

10

lib/Cache.d.ts

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

import type { IConfigCatCache } from "configcat-common";
import type { IConfigCatCache, IConfigCatKernel } from "configcat-common";
export declare class LocalStorageCache implements IConfigCatCache {
private readonly storage;
static setup(kernel: IConfigCatKernel, localStorageGetter?: () => Storage | null): IConfigCatKernel;
constructor(storage: Storage);
set(key: string, value: string): void;
get(key: string): string | undefined;
private b64EncodeUnicode;
private b64DecodeUnicode;
}
export declare function getLocalStorage(): Storage | null;
export declare function toUtf8Base64(str: string): string;
export declare function fromUtf8Base64(str: string): string;
//# sourceMappingURL=Cache.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalStorageCache = void 0;
exports.fromUtf8Base64 = exports.toUtf8Base64 = exports.getLocalStorage = exports.LocalStorageCache = void 0;
var configcat_common_1 = require("configcat-common");
var LocalStorageCache = /** @class */ (function () {
function LocalStorageCache() {
function LocalStorageCache(storage) {
this.storage = storage;
}
LocalStorageCache.prototype.set = function (key, value) {
try {
localStorage.setItem(key, this.b64EncodeUnicode(value));
LocalStorageCache.setup = function (kernel, localStorageGetter) {
var localStorage = (localStorageGetter !== null && localStorageGetter !== void 0 ? localStorageGetter : getLocalStorage)();
if (localStorage) {
kernel.defaultCacheFactory = function (options) { return new configcat_common_1.ExternalConfigCache(new LocalStorageCache(localStorage), options.logger); };
}
catch (ex) {
// local storage is unavailable
}
return kernel;
};
LocalStorageCache.prototype.set = function (key, value) {
this.storage.setItem(key, toUtf8Base64(value));
};
LocalStorageCache.prototype.get = function (key) {
try {
var configString = localStorage.getItem(key);
if (configString) {
return this.b64DecodeUnicode(configString);
}
var configString = this.storage.getItem(key);
if (configString) {
return fromUtf8Base64(configString);
}
catch (ex) {
// local storage is unavailable or invalid cache value in localstorage
}
return void 0;
};
LocalStorageCache.prototype.b64EncodeUnicode = function (str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (_, p1) {
return String.fromCharCode(parseInt(p1, 16));
}));
};
LocalStorageCache.prototype.b64DecodeUnicode = function (str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
};
return LocalStorageCache;
}());
exports.LocalStorageCache = LocalStorageCache;
function getLocalStorage() {
var testKey = "__configcat_localStorage_test";
try {
var storage = window.localStorage;
storage.setItem(testKey, testKey);
var retrievedItem = void 0;
try {
retrievedItem = storage.getItem(testKey);
}
finally {
storage.removeItem(testKey);
}
if (retrievedItem === testKey) {
return storage;
}
}
catch (err) { /* intentional no-op */ }
return null;
}
exports.getLocalStorage = getLocalStorage;
function toUtf8Base64(str) {
str = encodeURIComponent(str);
str = str.replace(/%([0-9A-F]{2})/g, function (_, p1) { return String.fromCharCode(parseInt(p1, 16)); });
return btoa(str);
}
exports.toUtf8Base64 = toUtf8Base64;
function fromUtf8Base64(str) {
str = atob(str);
str = str.replace(/[%\x80-\xFF]/g, function (m) { return "%" + m.charCodeAt(0).toString(16); });
return decodeURIComponent(str);
}
exports.fromUtf8Base64 = fromUtf8Base64;

@@ -12,15 +12,22 @@ "use strict";

return tslib_1.__awaiter(this, void 0, void 0, function () {
var headers, axiosConfig, response, err_1, statusCode_1, reasonPhrase_1, _a, code, message, _b, statusCode, reasonPhrase, eTag;
var url, headers, axiosConfig, response, err_1, statusCode_1, reasonPhrase_1, _a, code, message, _b, statusCode, reasonPhrase, eTag;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
headers = typeof window !== "undefined" || !lastEtag
// NOTE: It's intentional that we don't specify the If-None-Match header.
// The browser automatically handles it, adding it manually would cause an unnecessary CORS OPTIONS request.
? {}
: { "If-None-Match": lastEtag };
url = options.getUrl();
if (lastEtag) {
if (typeof window !== "undefined") {
// NOTE: If we are running in browser, it's intentional that we don't specify the If-None-Match header.
// The browser automatically handles it, adding it manually would cause an unnecessary CORS OPTIONS request.
// In case the browser doesn't handle it, we are transforming the ccetag query parameter to the If-None-Match header in our CDN provider.
url += "&ccetag=" + lastEtag;
}
else {
headers = { "If-None-Match": lastEtag };
}
}
axiosConfig = {
method: "get",
timeout: options.requestTimeoutMs,
url: options.getUrl(),
url: url,
headers: headers,

@@ -27,0 +34,0 @@ responseType: "text",

@@ -0,36 +1,53 @@

import { ExternalConfigCache } from "configcat-common";
var LocalStorageCache = /** @class */ (function () {
function LocalStorageCache() {
function LocalStorageCache(storage) {
this.storage = storage;
}
LocalStorageCache.prototype.set = function (key, value) {
try {
localStorage.setItem(key, this.b64EncodeUnicode(value));
LocalStorageCache.setup = function (kernel, localStorageGetter) {
var localStorage = (localStorageGetter !== null && localStorageGetter !== void 0 ? localStorageGetter : getLocalStorage)();
if (localStorage) {
kernel.defaultCacheFactory = function (options) { return new ExternalConfigCache(new LocalStorageCache(localStorage), options.logger); };
}
catch (ex) {
// local storage is unavailable
}
return kernel;
};
LocalStorageCache.prototype.set = function (key, value) {
this.storage.setItem(key, toUtf8Base64(value));
};
LocalStorageCache.prototype.get = function (key) {
try {
var configString = localStorage.getItem(key);
if (configString) {
return this.b64DecodeUnicode(configString);
}
var configString = this.storage.getItem(key);
if (configString) {
return fromUtf8Base64(configString);
}
catch (ex) {
// local storage is unavailable or invalid cache value in localstorage
}
return void 0;
};
LocalStorageCache.prototype.b64EncodeUnicode = function (str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (_, p1) {
return String.fromCharCode(parseInt(p1, 16));
}));
};
LocalStorageCache.prototype.b64DecodeUnicode = function (str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
};
return LocalStorageCache;
}());
export { LocalStorageCache };
export function getLocalStorage() {
var testKey = "__configcat_localStorage_test";
try {
var storage = window.localStorage;
storage.setItem(testKey, testKey);
var retrievedItem = void 0;
try {
retrievedItem = storage.getItem(testKey);
}
finally {
storage.removeItem(testKey);
}
if (retrievedItem === testKey) {
return storage;
}
}
catch (err) { /* intentional no-op */ }
return null;
}
export function toUtf8Base64(str) {
str = encodeURIComponent(str);
str = str.replace(/%([0-9A-F]{2})/g, function (_, p1) { return String.fromCharCode(parseInt(p1, 16)); });
return btoa(str);
}
export function fromUtf8Base64(str) {
str = atob(str);
str = str.replace(/[%\x80-\xFF]/g, function (m) { return "%" + m.charCodeAt(0).toString(16); });
return decodeURIComponent(str);
}

@@ -9,15 +9,22 @@ import { __awaiter, __generator } from "tslib";

return __awaiter(this, void 0, void 0, function () {
var headers, axiosConfig, response, err_1, statusCode_1, reasonPhrase_1, _a, code, message, _b, statusCode, reasonPhrase, eTag;
var url, headers, axiosConfig, response, err_1, statusCode_1, reasonPhrase_1, _a, code, message, _b, statusCode, reasonPhrase, eTag;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
headers = typeof window !== "undefined" || !lastEtag
// NOTE: It's intentional that we don't specify the If-None-Match header.
// The browser automatically handles it, adding it manually would cause an unnecessary CORS OPTIONS request.
? {}
: { "If-None-Match": lastEtag };
url = options.getUrl();
if (lastEtag) {
if (typeof window !== "undefined") {
// NOTE: If we are running in browser, it's intentional that we don't specify the If-None-Match header.
// The browser automatically handles it, adding it manually would cause an unnecessary CORS OPTIONS request.
// In case the browser doesn't handle it, we are transforming the ccetag query parameter to the If-None-Match header in our CDN provider.
url += "&ccetag=" + lastEtag;
}
else {
headers = { "If-None-Match": lastEtag };
}
}
axiosConfig = {
method: "get",
timeout: options.requestTimeoutMs,
url: options.getUrl(),
url: url,
headers: headers,

@@ -24,0 +31,0 @@ responseType: "text",

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

import { ExternalConfigCache, FlagOverrides, MapOverrideDataSource, PollingMode } from "configcat-common";
import { FlagOverrides, MapOverrideDataSource, PollingMode } from "configcat-common";
import * as configcatcommon from "configcat-common";

@@ -17,8 +17,7 @@ import { LocalStorageCache } from "./Cache";

export function getClient(sdkKey, pollingMode, options) {
return configcatcommon.getClient(sdkKey, pollingMode !== null && pollingMode !== void 0 ? pollingMode : PollingMode.AutoPoll, options, {
return configcatcommon.getClient(sdkKey, pollingMode !== null && pollingMode !== void 0 ? pollingMode : PollingMode.AutoPoll, options, LocalStorageCache.setup({
configFetcher: new HttpConfigFetcher(),
sdkType: "ConfigCat-JS-SSR",
sdkVersion: CONFIGCAT_SDK_VERSION,
defaultCacheFactory: function (options) { return new ExternalConfigCache(new LocalStorageCache(), options.logger); }
});
}));
}

@@ -25,0 +24,0 @@ /**

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

export default "8.1.0";
export default "8.2.0";

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

function getClient(sdkKey, pollingMode, options) {
return configcatcommon.getClient(sdkKey, pollingMode !== null && pollingMode !== void 0 ? pollingMode : configcat_common_1.PollingMode.AutoPoll, options, {
return configcatcommon.getClient(sdkKey, pollingMode !== null && pollingMode !== void 0 ? pollingMode : configcat_common_1.PollingMode.AutoPoll, options, Cache_1.LocalStorageCache.setup({
configFetcher: new ConfigFetcher_1.HttpConfigFetcher(),
sdkType: "ConfigCat-JS-SSR",
sdkVersion: Version_1.default,
defaultCacheFactory: function (options) { return new configcat_common_1.ExternalConfigCache(new Cache_1.LocalStorageCache(), options.logger); }
});
}));
}

@@ -28,0 +27,0 @@ exports.getClient = getClient;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "8.1.0";
exports.default = "8.2.0";
{
"name": "configcat-js-ssr",
"version": "8.1.0",
"version": "8.2.0",
"description": "ConfigCat Feature Flags for Server Side Rendered apps like NuxtJS. Official ConfigCat SDK for Server Side Rendered to easily access feature flags.",

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

"test-chromium": "karma start karma-chromium.conf.js",
"test-node": "cross-env NODE_EXTRA_CA_CERTS=./test/cert/testCA.pem TS_NODE_PROJECT=./tsconfig.mocha.json mocha --require ts-node/register 'test/**/*.ts' --ignore test/index.ts --exit --timeout 30000",
"build": "tsc -p tsconfig.build.cjs.json && tsc -p tsconfig.build.esm.json && gulp tsc",

@@ -50,3 +51,3 @@ "buildPure": "webpack && gulp webpack",

"axios": "^1.6.2",
"configcat-common": "^9.0.0",
"configcat-common": "^9.1.0",
"tslib": "^2.4.1"

@@ -64,2 +65,3 @@ },

"core-js": "^3.24.1",
"cross-env": "^7.0.3",
"eslint": "^8.34.0",

@@ -81,2 +83,3 @@ "eslint-plugin-import": "^2.27.5",

"ts-loader": "^9.3.1",
"ts-node": "^10.9.2",
"typescript": "^4.8.4",

@@ -83,0 +86,0 @@ "webpack": "^5.77.0",

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc