New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@statsig/client-core

Package Overview
Dependencies
Maintainers
4
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@statsig/client-core - npm Package Compare versions

Comparing version 0.0.1-beta.38 to 0.0.1-beta.39

2

package.json
{
"name": "@statsig/client-core",
"version": "0.0.1-beta.38",
"version": "0.0.1-beta.39",
"dependencies": {},

@@ -5,0 +5,0 @@ "type": "commonjs",

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

import { ErrorBoundary } from './ErrorBoundary';
import { DataAdapterAsyncOptions, DataAdapterResult } from './StatsigDataAdapter';

@@ -8,3 +7,2 @@ import { AnyStatsigOptions } from './StatsigOptionsCommon';

private _cacheSuffix;
protected _errorBoundary: ErrorBoundary | null;
private _sdkKey;

@@ -25,4 +23,4 @@ private _inMemoryCache;

protected _prefetchDataImpl(user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
protected abstract _fetchFromNetwork(current: string | null, user?: StatsigUser): Promise<string | null>;
private _fetchLatest;
protected abstract _fetchFromNetwork(current: string | null, user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<string | null>;
private _fetchAndPrepFromNetwork;
protected _getSdkKey(): string;

@@ -29,0 +27,0 @@ protected _getCacheKey(user?: StatsigUser): string;

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

exports.DataAdapterCore = void 0;
const ErrorBoundary_1 = require("./ErrorBoundary");
const Log_1 = require("./Log");

@@ -25,3 +24,2 @@ const StatsigDataAdapter_1 = require("./StatsigDataAdapter");

this._cacheSuffix = _cacheSuffix;
this._errorBoundary = null;
this._sdkKey = null;

@@ -33,3 +31,2 @@ this._inMemoryCache = {};

this._sdkKey = sdkKey;
this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey);
}

@@ -69,3 +66,5 @@ getDataSync(user) {

const cache = current !== null && current !== void 0 ? current : this.getDataSync(user);
const ops = [this._fetchLatest((_a = cache === null || cache === void 0 ? void 0 : cache.data) !== null && _a !== void 0 ? _a : null, user)];
const ops = [
this._fetchAndPrepFromNetwork((_a = cache === null || cache === void 0 ? void 0 : cache.data) !== null && _a !== void 0 ? _a : null, user, options),
];
if (options === null || options === void 0 ? void 0 : options.timeoutMs) {

@@ -89,5 +88,5 @@ ops.push(new Promise((r) => setTimeout(r, options.timeoutMs)).then(() => {

}
_fetchLatest(current, user) {
_fetchAndPrepFromNetwork(current, user, options) {
return __awaiter(this, void 0, void 0, function* () {
const latest = yield this._fetchFromNetwork(current, user);
const latest = yield this._fetchFromNetwork(current, user, options);
if (!latest) {

@@ -94,0 +93,0 @@ Log_1.Log.debug('No response returned for latest value');

import { StatsigClientEmitEventFunc } from './StatsigClientBase';
import { AnyStatsigOptions } from './StatsigOptionsCommon';
export declare const EXCEPTION_ENDPOINT = "https://statsigapi.net/v1/sdk_exception";
export declare class ErrorBoundary {
private _sdkKey;
private _options;
private _emitter?;
private _seen;
constructor(_sdkKey: string, _emitter?: StatsigClientEmitEventFunc | undefined);
constructor(_sdkKey: string, _options: AnyStatsigOptions | null, _emitter?: StatsigClientEmitEventFunc | undefined);
wrap(instance: unknown): void;

@@ -9,0 +11,0 @@ capture(tag: string, task: () => unknown): unknown;

@@ -18,4 +18,5 @@ "use strict";

class ErrorBoundary {
constructor(_sdkKey, _emitter) {
constructor(_sdkKey, _options, _emitter) {
this._sdkKey = _sdkKey;
this._options = _options;
this._emitter = _emitter;

@@ -62,3 +63,3 @@ this._seen = new Set();

const impl = () => __awaiter(this, void 0, void 0, function* () {
var _a;
var _a, _b, _c, _d;
const unwrapped = (error !== null && error !== void 0 ? error : Error('[Statsig] Error was empty'));

@@ -71,2 +72,6 @@ const isError = unwrapped instanceof Error;

this._seen.add(name);
if ((_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.networkConfig) === null || _b === void 0 ? void 0 : _b.preventAllNetworkTraffic) {
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error });
return;
}
const sdkType = SDKType_1.SDKType._get(this._sdkKey);

@@ -86,3 +91,3 @@ const statsigMetadata = StatsigMetadata_1.StatsigMetadataProvider.get();

});
(_a = this._emitter) === null || _a === void 0 ? void 0 : _a.call(this, { name: 'error', error });
(_d = this._emitter) === null || _d === void 0 ? void 0 : _d.call(this, { name: 'error', error });
});

@@ -89,0 +94,0 @@ impl()

@@ -6,2 +6,3 @@ export declare const NetworkDefault: {

};
export type NetworkPriority = 'high' | 'low' | 'auto';
export declare enum NetworkParam {

@@ -8,0 +9,0 @@ EventCount = "ec",

import './$_StatsigGlobal';
import { NetworkPriority } from './NetworkConfig';
import { StatsigClientEmitEventFunc } from './StatsigClientBase';

@@ -7,2 +8,3 @@ import { AnyStatsigOptions } from './StatsigOptionsCommon';

url: string;
priority?: NetworkPriority;
retries?: number;

@@ -9,0 +11,0 @@ params?: Record<string, string>;

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

const SDKType_1 = require("./SDKType");
const SafeJs_1 = require("./SafeJs");
const SessionID_1 = require("./SessionID");

@@ -55,3 +56,3 @@ const StableID_1 = require("./StableID");

_sendRequest(args) {
var _a;
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () {

@@ -61,2 +62,5 @@ if (!_ensureValidSdkKey(args)) {

}
if ((_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.networkConfig) === null || _b === void 0 ? void 0 : _b.preventAllNetworkTraffic) {
return null;
}
const { method, body, retries } = args;

@@ -68,3 +72,3 @@ const controller = new AbortController();

try {
response = yield fetch(url, {
const config = {
method,

@@ -74,3 +78,5 @@ body,

signal: controller.signal,
});
priority: args.priority,
};
response = yield fetch(url, config);
clearTimeout(handle);

@@ -94,3 +100,3 @@ if (!response.ok) {

if (!retries || retries <= 0) {
(_a = this._emitter) === null || _a === void 0 ? void 0 : _a.call(this, { name: 'error', error });
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error });
Log_1.Log.error(`A networking error occured during ${method} request to ${url}.`, errorMessage, error);

@@ -127,11 +133,18 @@ return null;

var _a, _b, _c;
if ((__STATSIG__ === null || __STATSIG__ === void 0 ? void 0 : __STATSIG__['no-encode']) != null ||
const win = (0, SafeJs_1._getWindowSafe)();
if (!(win === null || win === void 0 ? void 0 : win.btoa) ||
(__STATSIG__ === null || __STATSIG__ === void 0 ? void 0 : __STATSIG__['no-encode']) != null ||
((_a = this._options) === null || _a === void 0 ? void 0 : _a.disableStatsigEncoding) ||
!args.isStatsigEncodable ||
typeof window === 'undefined' ||
!window.btoa) {
!args.isStatsigEncodable) {
return input;
}
args.params = Object.assign(Object.assign({}, ((_b = args.params) !== null && _b !== void 0 ? _b : {})), { [NetworkConfig_1.NetworkParam.StatsigEncoded]: '1' });
return (_c = window.btoa(input).split('').reverse().join('')) !== null && _c !== void 0 ? _c : input;
try {
const result = (_b = win.btoa(input).split('').reverse().join('')) !== null && _b !== void 0 ? _b : input;
args.params = Object.assign(Object.assign({}, ((_c = args.params) !== null && _c !== void 0 ? _c : {})), { [NetworkConfig_1.NetworkParam.StatsigEncoded]: '1' });
return result;
}
catch (_d) {
Log_1.Log.warn('/initialize request encoding failed');
return input;
}
}

@@ -138,0 +151,0 @@ }

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

StableID_1.StableID.setOverride(options.overrideStableID, sdkKey);
this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey, emitter);
this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey, options, emitter);
this._errorBoundary.wrap(this);

@@ -37,0 +37,0 @@ this._errorBoundary.wrap(network);

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

import { NetworkPriority } from './NetworkConfig';
import type { AnyStatsigOptions, NetworkConfigCommon } from './StatsigOptionsCommon';

@@ -17,2 +18,10 @@ import { StatsigUser } from './StatsigUser';

readonly timeoutMs?: NetworkConfigCommon['networkTimeoutMs'];
/**
* The priority that should be applied to the Http request that is fired.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch#priority
*
* default: 'auto'
*/
readonly priority?: NetworkPriority;
};

@@ -24,5 +33,5 @@ export declare const DataAdapterCachePrefix = "statsig.cached";

* See below to find the default adapters, but know that it is possible to create your
* own StatsigDataAdapter and provide it via {@link AnyStatsigOptions.dataAdapter}.
* own StatsigDataAdapter and provide it via `StatsigOptions.dataAdapter`.
*
* Defaults:
* defaults:
*

@@ -29,0 +38,0 @@ * - {@link StatsigClient} uses {@link EvaluationsDataAdapter}

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

export declare const SDK_VERSION = "0.0.1-beta.38";
export declare const SDK_VERSION = "0.0.1-beta.39";
export type StatsigMetadata = {

@@ -3,0 +3,0 @@ readonly [key: string]: string | undefined;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
exports.SDK_VERSION = '0.0.1-beta.38';
exports.SDK_VERSION = '0.0.1-beta.39';
let metadata = {

@@ -6,0 +6,0 @@ sdkVersion: exports.SDK_VERSION,

@@ -41,2 +41,6 @@ import { LogLevel } from './Log';

networkTimeoutMs?: number;
/**
* Intended for testing purposes. Prevents any network requests being made.
*/
preventAllNetworkTraffic?: boolean;
};

@@ -43,0 +47,0 @@ /** Options for configuring a Statsig client. */

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

const inMemoryStore = {};
const _resolve = (input) => Promise.resolve(input);
const _inMemoryProvider = {

@@ -24,14 +25,14 @@ _getProviderName: () => 'InMemory',

var _a;
return Promise.resolve((_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null);
return _resolve((_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null);
},
_setItem(key, value) {
inMemoryStore[key] = value;
return Promise.resolve();
return _resolve();
},
_removeItem(key) {
delete inMemoryStore[key];
return Promise.resolve();
return _resolve();
},
_getAllKeys() {
return Promise.resolve(Object.keys(inMemoryStore));
return _resolve(Object.keys(inMemoryStore));
},

@@ -48,15 +49,15 @@ };

_getItem(key) {
return Promise.resolve(localStorage.getItem(key));
return _resolve(localStorage.getItem(key));
},
_setItem(key, value) {
localStorage.setItem(key, value);
return Promise.resolve();
return _resolve();
},
_removeItem(key) {
localStorage.removeItem(key);
return Promise.resolve();
return _resolve();
},
_getAllKeys() {
const keys = Object.keys(localStorage);
return Promise.resolve(keys);
return _resolve(keys);
},

@@ -63,0 +64,0 @@ };

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