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.42 to 1.0.0

2

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

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

@@ -17,2 +17,3 @@ import { StatsigClientInterface } from './ClientInterfaces';

export declare const _getStatsigGlobal: () => StatsigGlobal;
export declare const _getStatsigGlobalFlag: (flag: string) => unknown;
export declare const _getInstance: (sdkKey: string) => StatsigClientInterface | undefined;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports._getInstance = exports._getStatsigGlobal = void 0;
exports._getInstance = exports._getStatsigGlobalFlag = exports._getStatsigGlobal = void 0;
const _getStatsigGlobal = () => {

@@ -11,2 +11,6 @@ return __STATSIG__ ? __STATSIG__ : statsigGlobal;

exports._getStatsigGlobal = _getStatsigGlobal;
const _getStatsigGlobalFlag = (flag) => {
return (0, exports._getStatsigGlobal)()[flag];
};
exports._getStatsigGlobalFlag = _getStatsigGlobalFlag;
const _getInstance = (sdkKey) => {

@@ -13,0 +17,0 @@ const gbl = (0, exports._getStatsigGlobal)();

@@ -25,2 +25,3 @@ import { DataAdapterAsyncOptions, DataAdapterResult } from './StatsigDataAdapter';

protected abstract _getCacheKey(user?: StatsigUser): string;
protected abstract _isCachedResultValidFor204(result: DataAdapterResult, user: StatsigUser | undefined): boolean;
private _fetchAndPrepFromNetwork;

@@ -27,0 +28,0 @@ protected _getSdkKey(): string;

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

const cacheKey = this._getCacheKey(normalized);
this._inMemoryCache.add(cacheKey, _makeDataAdapterResult('Bootstrap', data, null));
this._inMemoryCache.add(cacheKey, _makeDataAdapterResult('Bootstrap', data, null, normalized));
}

@@ -61,8 +61,5 @@ /**

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

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

}
_fetchAndPrepFromNetwork(current, user, options) {
_fetchAndPrepFromNetwork(cachedResult, user, options) {
return __awaiter(this, void 0, void 0, function* () {
const latest = yield this._fetchFromNetwork(current, user, options);
let cachedData = null;
if (cachedResult && this._isCachedResultValidFor204(cachedResult, user)) {
cachedData = cachedResult.data;
}
const latest = yield this._fetchFromNetwork(cachedData, user, options);
if (!latest) {

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

}
const response = (0, TypedJsonParse_1._typedJsonParse)(latest, 'has_updates', 'Initialize Response');
const response = (0, TypedJsonParse_1._typedJsonParse)(latest, 'has_updates', 'Response');
const sdkKey = this._getSdkKey();

@@ -100,6 +101,6 @@ const stableID = yield StableID_1.StableID.get(sdkKey);

if ((response === null || response === void 0 ? void 0 : response.has_updates) === true) {
result = _makeDataAdapterResult('Network', latest, stableID);
result = _makeDataAdapterResult('Network', latest, stableID, user);
}
else if (current && (response === null || response === void 0 ? void 0 : response.has_updates) === false) {
result = _makeDataAdapterResult('NetworkNotModified', current, stableID);
else if (cachedData && (response === null || response === void 0 ? void 0 : response.has_updates) === false) {
result = _makeDataAdapterResult('NetworkNotModified', cachedData, stableID, user);
}

@@ -157,3 +158,3 @@ else {

exports.DataAdapterCore = DataAdapterCore;
function _makeDataAdapterResult(source, data, stableID) {
function _makeDataAdapterResult(source, data, stableID, user) {
return {

@@ -164,2 +165,3 @@ source,

stableID,
fullUserHash: (0, StatsigUser_1._getFullUserHash)(user),
};

@@ -166,0 +168,0 @@ }

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

let value = object[key];
if (value instanceof Object) {
if (!Array.isArray(value) && value instanceof Object) {
value = _getSortedObject(value);

@@ -29,0 +29,0 @@ }

import { DynamicConfigEvaluation, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
import { StatsigUser } from './StatsigUser';
type SessionReplayFields = {

@@ -14,2 +15,3 @@ can_record_session?: boolean;

derived_fields?: Record<string, unknown>;
user?: StatsigUser;
};

@@ -16,0 +18,0 @@ export type InitializeResponse = InitializeResponseWithUpdates | {

@@ -25,7 +25,7 @@ import './$_StatsigGlobal';

export declare class NetworkCore {
private _options;
private _emitter?;
private readonly _timeout;
private readonly _netConfig;
constructor(_options: AnyStatsigOptions | null, _emitter?: StatsigClientEmitEventFunc | undefined);
private readonly _options;
constructor(options: AnyStatsigOptions | null, _emitter?: StatsigClientEmitEventFunc | undefined);
post(args: RequestArgsWithData): Promise<NetworkResponse | null>;

@@ -39,3 +39,4 @@ get(args: RequestArgs): Promise<NetworkResponse | null>;

private _attemptToEncodeString;
private _attemptToCompressBody;
}
export {};

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

require("./$_StatsigGlobal");
const __StatsigGlobal_1 = require("./$_StatsigGlobal");
const Diagnostics_1 = require("./Diagnostics");

@@ -26,8 +27,16 @@ const Log_1 = require("./Log");

class NetworkCore {
constructor(_options, _emitter) {
var _a, _b, _c;
this._options = _options;
constructor(options, _emitter) {
this._emitter = _emitter;
this._netConfig = (_a = _options === null || _options === void 0 ? void 0 : _options.networkConfig) !== null && _a !== void 0 ? _a : null;
this._timeout = (_c = (_b = this._netConfig) === null || _b === void 0 ? void 0 : _b.networkTimeoutMs) !== null && _c !== void 0 ? _c : DEFAULT_TIMEOUT_MS;
this._timeout = DEFAULT_TIMEOUT_MS;
this._netConfig = {};
this._options = {};
if (options) {
this._options = options;
}
if (this._options.networkConfig) {
this._netConfig = this._options.networkConfig;
}
if (this._netConfig.networkTimeoutMs) {
this._timeout = this._netConfig.networkTimeoutMs;
}
}

@@ -41,3 +50,3 @@ post(args) {

else if (args.isCompressable) {
body = yield _attemptToCompressBody(args, body);
body = yield this._attemptToCompressBody(args, body);
}

@@ -60,9 +69,10 @@ return this._sendRequest(Object.assign({ method: 'POST', body }, args));

let body = yield this._getPopulatedBody(args);
body = yield _attemptToCompressBody(args, body);
body = yield this._attemptToCompressBody(args, body);
const url = yield this._getPopulatedURL(args);
return navigator.sendBeacon(url, body);
const nav = navigator;
return nav.sendBeacon.bind(nav)(url, body);
});
}
_sendRequest(args) {
var _a, _b, _c, _d;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {

@@ -72,3 +82,3 @@ if (!_ensureValidSdkKey(args)) {

}
if ((_a = this._netConfig) === null || _a === void 0 ? void 0 : _a.preventAllNetworkTraffic) {
if (this._netConfig.preventAllNetworkTraffic) {
return null;

@@ -91,3 +101,3 @@ }

};
const func = (_c = (_b = this._netConfig) === null || _b === void 0 ? void 0 : _b.networkOverrideFunc) !== null && _c !== void 0 ? _c : fetch;
const func = (_a = this._netConfig.networkOverrideFunc) !== null && _a !== void 0 ? _a : fetch;
response = yield func(url, config);

@@ -112,3 +122,3 @@ clearTimeout(handle);

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

@@ -144,16 +154,16 @@ return null;

_attemptToEncodeString(args, input) {
var _a, _b, _c;
var _a, _b;
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) {
if (!args.isStatsigEncodable ||
this._options.disableStatsigEncoding ||
(0, __StatsigGlobal_1._getStatsigGlobalFlag)('no-encode') != null ||
!(win === null || win === void 0 ? void 0 : win.btoa)) {
return 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' });
const result = (_a = win.btoa(input).split('').reverse().join('')) !== null && _a !== void 0 ? _a : input;
args.params = Object.assign(Object.assign({}, ((_b = args.params) !== null && _b !== void 0 ? _b : {})), { [NetworkConfig_1.NetworkParam.StatsigEncoded]: '1' });
return result;
}
catch (_d) {
catch (_c) {
Log_1.Log.warn('/initialize request encoding failed');

@@ -163,2 +173,21 @@ return input;

}
_attemptToCompressBody(args, body) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!args.isCompressable ||
this._options.disableCompression ||
(0, __StatsigGlobal_1._getStatsigGlobalFlag)('no-compress') != null ||
typeof CompressionStream === 'undefined' ||
typeof TextEncoder === 'undefined') {
return body;
}
const bytes = new TextEncoder().encode(body);
const stream = new CompressionStream('gzip');
const writer = stream.writable.getWriter();
writer.write(bytes).catch(Log_1.Log.error);
writer.close().catch(Log_1.Log.error);
args.params = Object.assign(Object.assign({}, ((_a = args.params) !== null && _a !== void 0 ? _a : {})), { [NetworkConfig_1.NetworkParam.IsGzipped]: '1' });
return yield new Response(stream.readable).arrayBuffer();
});
}
}

@@ -186,19 +215,1 @@ exports.NetworkCore = NetworkCore;

}
function _attemptToCompressBody(args, body) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!args.isCompressable ||
typeof CompressionStream === 'undefined' ||
typeof TextEncoder === 'undefined' ||
(__STATSIG__ === null || __STATSIG__ === void 0 ? void 0 : __STATSIG__['no-compress']) != null) {
return body;
}
const bytes = new TextEncoder().encode(body);
const stream = new CompressionStream('gzip');
const writer = stream.writable.getWriter();
writer.write(bytes).catch(Log_1.Log.error);
writer.close().catch(Log_1.Log.error);
args.params = Object.assign(Object.assign({}, ((_a = args.params) !== null && _a !== void 0 ? _a : {})), { [NetworkConfig_1.NetworkParam.IsGzipped]: '1' });
return yield new Response(stream.readable).arrayBuffer();
});
}
type ClientType = 'javascript-client' | 'js-on-device-eval-client';
type BindingType = 'expo' | 'rn' | 'react';
type BindingType = 'expo' | 'rn' | 'react' | 'angular';
export declare const SDKType: {

@@ -4,0 +4,0 @@ _get: (sdkKey: string) => string;

@@ -10,2 +10,3 @@ import { NetworkPriority } from './NetworkConfig';

readonly stableID: string | null;
readonly fullUserHash: string | null;
};

@@ -80,7 +81,24 @@ export type DataAdapterAsyncOptions = {

/**
* Manually set the evaluations data from a JSON string.
*
* Statsig Server SDKs supported:
* - node-js-server-sdk\@5.20.0
* - java-server-sdk\@1.18.0
* - python-sdk\@0.32.0
* - ruby-sdk\@1.34.0
* - dotnet-sdk\@1.25.0
* - php-sdk\@3.2.0
*
* Note: You can use {@link EvaluationsDataAdapter.setDataLegacy} if your server is running an older Statsig Server SDK.
*/
readonly setData: (data: string) => void;
/**
* Manually set evaluations data for the given user.
*
* @param {StatsigUser} user The StatsigUser this data is for.
*
* @deprecated This method is provided only to support older versions of Statsig server SDKs.
* Newer SDKs include the StatsigUser as part of the data string, and can be used with the {@link EvaluationsDataAdapter.setData} method instead.
*/
readonly setData: (data: string, user: StatsigUser) => void;
readonly setDataLegacy: (data: string, user: StatsigUser) => void;
};

@@ -87,0 +105,0 @@ export type SpecsDataAdapter = DataAdapterCommon & {

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

export declare const SDK_VERSION = "0.0.1-beta.42";
export declare const SDK_VERSION = "1.0.0";
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.42';
exports.SDK_VERSION = '1.0.0';
let metadata = {

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

@@ -101,2 +101,8 @@ import { LogLevel } from './Log';

disableStatsigEncoding?: boolean;
/**
* Whether or not Statsig should compress JSON bodies for network requests where possible.
*
* default: `false`
*/
disableCompression?: boolean;
};

@@ -103,0 +109,0 @@ export type AnyStatsigOptions = StatsigOptionsCommon<NetworkConfigCommon>;

@@ -22,3 +22,3 @@ import type { StatsigEnvironment } from './StatsigOptionsCommon';

export declare function _normalizeUser(original: StatsigUser, environment?: StatsigEnvironment): StatsigUser;
export declare function getUnitIDFromUser(user: StatsigUser, idType: string): string | undefined;
export declare function _getFullUserHash(user: StatsigUser | undefined): string | null;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUnitIDFromUser = exports._normalizeUser = void 0;
exports._getFullUserHash = exports._normalizeUser = void 0;
const Hashing_1 = require("./Hashing");
const Log_1 = require("./Log");
function _normalizeUser(original, environment) {

@@ -13,13 +15,10 @@ try {

catch (error) {
throw new Error('User object must be convertable to JSON string.');
Log_1.Log.error('Failed to JSON.stringify user');
return {};
}
}
exports._normalizeUser = _normalizeUser;
function getUnitIDFromUser(user, idType) {
var _a, _b, _c;
if (typeof idType === 'string' && idType.toLowerCase() !== 'userid') {
return (_b = (_a = user.customIDs) === null || _a === void 0 ? void 0 : _a[idType]) !== null && _b !== void 0 ? _b : (_c = user === null || user === void 0 ? void 0 : user.customIDs) === null || _c === void 0 ? void 0 : _c[idType.toLowerCase()];
}
return user.userID;
function _getFullUserHash(user) {
return user ? (0, Hashing_1._DJB2Object)(user) : null;
}
exports.getUnitIDFromUser = getUnitIDFromUser;
exports._getFullUserHash = _getFullUserHash;
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