Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

statsig-node-lite

Package Overview
Dependencies
Maintainers
8
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statsig-node-lite - npm Package Compare versions

Comparing version
0.4.4
to
0.5.0
+1
-1
dist/Evaluator.d.ts

@@ -49,3 +49,3 @@ import { ConfigCondition, ConfigRule, ConfigSpec } from './ConfigSpec';

private store;
constructor(fetcher: StatsigFetcher, options: ExplicitStatsigOptions, diagnostics: Diagnostics);
constructor(sdkKey: string, fetcher: StatsigFetcher, options: ExplicitStatsigOptions, diagnostics: Diagnostics);
init(): Promise<void>;

@@ -52,0 +52,0 @@ overrideGate(gateName: string, value: boolean, userID?: string | null): void;

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

var Evaluator = /** @class */ (function () {
function Evaluator(fetcher, options, diagnostics) {
function Evaluator(sdkKey, fetcher, options, diagnostics) {
this.initialized = false;
this.store = new SpecStore_1["default"](fetcher, options, diagnostics);
this.store = new SpecStore_1["default"](sdkKey, fetcher, options, diagnostics);
this.gateOverrides = {};

@@ -77,0 +77,0 @@ this.configOverrides = {};

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

var Errors_1 = require("./Errors");
var SpecStore_1 = require("./SpecStore");
var CONFIG_EXPOSURE_EVENT = 'config_exposure';

@@ -109,2 +110,3 @@ var LAYER_EXPOSURE_EVENT = 'layer_exposure';

LogEventProcessor.prototype.flush = function (fireAndForget) {
var _a;
if (fireAndForget === void 0) { fireAndForget = false; }

@@ -114,3 +116,3 @@ return __awaiter(this, void 0, void 0, function () {

var _this = this;
return __generator(this, function (_a) {
return __generator(this, function (_b) {
this._appendAndResetNonExposedChecks();

@@ -127,3 +129,3 @@ if (this.queue.length === 0) {

return [2 /*return*/, this.fetcher
.post(this.options.api + '/log_event', body, fireAndForget ? 0 : this.options.postLogsRetryLimit, this.options.postLogsRetryBackoff)
.post(((_a = this.options.api) !== null && _a !== void 0 ? _a : SpecStore_1.DEFAULT_API) + '/log_event', body, fireAndForget ? 0 : this.options.postLogsRetryLimit, this.options.postLogsRetryBackoff)
.then(function () {

@@ -130,0 +132,0 @@ return Promise.resolve();

@@ -20,2 +20,3 @@ import { ConfigSpec } from './ConfigSpec';

};
export declare const DEFAULT_API = "https://statsigapi.net/v1";
export type SDKConstants = DiagnosticsSamplingRate;

@@ -47,3 +48,4 @@ export default class SpecStore {

private outputLogger;
constructor(fetcher: StatsigFetcher, options: ExplicitStatsigOptions, diagnostics: Diagnostics);
private sdkKey;
constructor(sdkKey: string, fetcher: StatsigFetcher, options: ExplicitStatsigOptions, diagnostics: Diagnostics);
getInitReason(): EvaluationReason;

@@ -50,0 +52,0 @@ getInitialUpdateTime(): number;

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

exports.__esModule = true;
exports.DEFAULT_API = void 0;
var ConfigSpec_1 = require("./ConfigSpec");

@@ -53,4 +54,6 @@ var Diagnostics_1 = require("./Diagnostics");

var SYNC_OUTDATED_MAX = 120 * 1000;
exports.DEFAULT_API = 'https://statsigapi.net/v1';
var DEFAULT_API_FOR_DOWNLOAD_CONFIG_SPECS = 'https://api.statsigcdn.com/v1';
var SpecStore = /** @class */ (function () {
function SpecStore(fetcher, options, diagnostics) {
function SpecStore(sdkKey, fetcher, options, diagnostics) {
var _a;

@@ -92,2 +95,3 @@ this.syncFailureCount = 0;

this.initStrategyForIDLists = options.initStrategyForIDLists;
this.sdkKey = sdkKey;
}

@@ -277,7 +281,7 @@ SpecStore.prototype.getInitReason = function () {

SpecStore.prototype._fetchConfigSpecsFromServer = function () {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var response, error, url, e_1, status_1, specsString, processResult;
return __generator(this, function (_b) {
switch (_b.label) {
var response, error, path, url, e_1, status_1, specsString, processResult;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:

@@ -289,15 +293,15 @@ this.addDiagnosticsMarker('download_config_specs', 'start', {

error = undefined;
_b.label = 1;
_c.label = 1;
case 1:
_b.trys.push([1, 3, 4, 5]);
url = ((_a = this.apiForDownloadConfigSpecs) !== null && _a !== void 0 ? _a : this.api) + '/download_config_specs';
return [4 /*yield*/, this.fetcher.post(url, {
statsigMetadata: getStatsigMetadata(),
sinceTime: this.lastUpdateTime
})];
_c.trys.push([1, 3, 4, 5]);
path = '/download_config_specs' +
"/".concat(this.sdkKey, ".json") +
"?sinceTime=".concat(this.lastUpdateTime);
url = ((_b = (_a = this.apiForDownloadConfigSpecs) !== null && _a !== void 0 ? _a : this.api) !== null && _b !== void 0 ? _b : DEFAULT_API_FOR_DOWNLOAD_CONFIG_SPECS) + path;
return [4 /*yield*/, this.fetcher.get(url)];
case 2:
response = _b.sent();
response = _c.sent();
return [3 /*break*/, 5];
case 3:
e_1 = _b.sent();
e_1 = _c.sent();
error = e_1;

@@ -326,3 +330,3 @@ return [3 /*break*/, 5];

case 6:
specsString = _b.sent();
specsString = _c.sent();
processResult = this._process(JSON.parse(specsString));

@@ -689,7 +693,7 @@ if (!processResult) {

SpecStore.prototype.syncIdListsFromNetwork = function () {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function () {
var response, e_3, status_2, json, lookup, promises, _i, _f, _g, name_2, item, url, fileID, newCreationTime, oldCreationTime, newFile, fileSize, readSize, e_4;
return __generator(this, function (_h) {
switch (_h.label) {
var response, e_3, status_2, json, lookup, promises, _i, _g, _h, name_2, item, url, fileID, newCreationTime, oldCreationTime, newFile, fileSize, readSize, e_4;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:

@@ -700,10 +704,10 @@ this.addDiagnosticsMarker('get_id_list_sources', 'start', {

response = null;
_h.label = 1;
_j.label = 1;
case 1:
_h.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.fetcher.post(this.api + '/get_id_lists', {
_j.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.fetcher.post(((_a = this.api) !== null && _a !== void 0 ? _a : exports.DEFAULT_API) + '/get_id_lists', {
statsigMetadata: getStatsigMetadata()
})];
case 2:
response = _h.sent();
response = _j.sent();
this.addDiagnosticsMarker('get_id_list_sources', 'end', {

@@ -715,3 +719,3 @@ step: 'network_request',

case 3:
e_3 = _h.sent();
e_3 = _j.sent();
status_2 = this.getResponseCodeFromError(e_3);

@@ -725,3 +729,3 @@ this.addDiagnosticsMarker('get_id_list_sources', 'end', {

case 4:
_h.trys.push([4, 9, , 10]);
_j.trys.push([4, 9, , 10]);
this.addDiagnosticsMarker('get_id_list_sources', 'start', {

@@ -732,3 +736,3 @@ step: 'process'

case 5:
json = _h.sent();
json = _j.sent();
lookup = IDListUtil_1["default"].parseLookupResponse(json);

@@ -742,8 +746,8 @@ this.addDiagnosticsMarker('get_id_list_sources', 'end', {

promises = [];
for (_i = 0, _f = Object.entries(lookup); _i < _f.length; _i++) {
_g = _f[_i], name_2 = _g[0], item = _g[1];
for (_i = 0, _g = Object.entries(lookup); _i < _g.length; _i++) {
_h = _g[_i], name_2 = _h[0], item = _h[1];
url = item.url;
fileID = item.fileID;
newCreationTime = item.creationTime;
oldCreationTime = (_b = (_a = this.store.idLists[name_2]) === null || _a === void 0 ? void 0 : _a.creationTime) !== null && _b !== void 0 ? _b : 0;
oldCreationTime = (_c = (_b = this.store.idLists[name_2]) === null || _b === void 0 ? void 0 : _b.creationTime) !== null && _c !== void 0 ? _c : 0;
if (typeof url !== 'string' ||

@@ -754,3 +758,3 @@ newCreationTime < oldCreationTime ||

}
newFile = fileID !== ((_c = this.store.idLists[name_2]) === null || _c === void 0 ? void 0 : _c.fileID) &&
newFile = fileID !== ((_d = this.store.idLists[name_2]) === null || _d === void 0 ? void 0 : _d.fileID) &&
newCreationTime >= oldCreationTime;

@@ -769,4 +773,4 @@ if ((lookup.hasOwnProperty(name_2) &&

}
fileSize = (_d = item.size) !== null && _d !== void 0 ? _d : 0;
readSize = (_e = this.store.idLists[name_2].readBytes) !== null && _e !== void 0 ? _e : 0;
fileSize = (_e = item.size) !== null && _e !== void 0 ? _e : 0;
readSize = (_f = this.store.idLists[name_2].readBytes) !== null && _f !== void 0 ? _f : 0;
if (fileSize <= readSize) {

@@ -780,11 +784,11 @@ continue;

case 6:
_h.sent();
_j.sent();
if (!this.dataAdapter) return [3 /*break*/, 8];
return [4 /*yield*/, IDListUtil_1["default"].saveToDataAdapter(this.dataAdapter, this.store.idLists)];
case 7:
_h.sent();
_h.label = 8;
_j.sent();
_j.label = 8;
case 8: return [3 /*break*/, 10];
case 9:
e_4 = _h.sent();
e_4 = _j.sent();
return [3 /*break*/, 10];

@@ -791,0 +795,0 @@ case 10: return [2 /*return*/];

@@ -14,3 +14,3 @@ import { IDataAdapter } from './interfaces/IDataAdapter';

export type ExplicitStatsigOptions = {
api: string;
api: string | null;
apiForDownloadConfigSpecs: string | null;

@@ -17,0 +17,0 @@ bootstrapValues: string | null;

"use strict";
exports.__esModule = true;
exports.OptionsWithDefaults = void 0;
var DEFAULT_API = 'https://statsigapi.net/v1';
var DEFAULT_RULESETS_SYNC_INTERVAL = 10 * 1000;

@@ -15,5 +14,5 @@ var MIN_RULESETS_SYNC_INTERVAL = 5 * 1000;

function OptionsWithDefaults(opts) {
var _a, _b, _c, _d, _e, _f, _g;
var _a, _b, _c, _d, _e, _f;
return {
api: normalizeUrl((_a = getString(opts, 'api', DEFAULT_API)) !== null && _a !== void 0 ? _a : DEFAULT_API),
api: normalizeUrl(getString(opts, 'api', null)),
apiForDownloadConfigSpecs: normalizeUrl(getString(opts, 'apiForDownloadConfigSpecs', null)),

@@ -29,4 +28,4 @@ bootstrapValues: getString(opts, 'bootstrapValues', null),

initTimeoutMs: getNumber(opts, 'initTimeoutMs', 0),
logger: (_b = opts.logger) !== null && _b !== void 0 ? _b : console,
dataAdapter: (_c = opts.dataAdapter) !== null && _c !== void 0 ? _c : null,
logger: (_a = opts.logger) !== null && _a !== void 0 ? _a : console,
dataAdapter: (_b = opts.dataAdapter) !== null && _b !== void 0 ? _b : null,
rulesetsSyncIntervalMs: Math.max(getNumber(opts, 'rulesetsSyncIntervalMs', DEFAULT_RULESETS_SYNC_INTERVAL), MIN_RULESETS_SYNC_INTERVAL),

@@ -37,8 +36,8 @@ idListsSyncIntervalMs: Math.max(getNumber(opts, 'idListsSyncIntervalMs', DEFAULT_ID_LISTS_SYNC_INTERVAL), MIN_ID_LISTS_SYNC_INTERVAL),

disableDiagnostics: getBoolean(opts, 'disableDiagnostics', DEFAULT_LOG_DIAGNOSTICS),
initStrategyForIDLists: (_d = getString(opts, 'initStrategyForIDLists', 'await')) !== null && _d !== void 0 ? _d : 'await',
initStrategyForIDLists: (_c = getString(opts, 'initStrategyForIDLists', 'await')) !== null && _c !== void 0 ? _c : 'await',
allowReInitialize: getBoolean(opts, 'allowReInitialize', false),
postLogsRetryLimit: getNumber(opts, 'postLogsRetryLimit', DEFAULT_POST_LOGS_RETRY_LIMIT),
postLogsRetryBackoff: (_e = opts.postLogsRetryBackoff) !== null && _e !== void 0 ? _e : DEFAULT_POST_LOGS_RETRY_BACKOFF,
disableRulesetsSync: (_f = opts.disableRulesetsSync) !== null && _f !== void 0 ? _f : false,
disableIdListsSync: (_g = opts.disableIdListsSync) !== null && _g !== void 0 ? _g : false
postLogsRetryBackoff: (_d = opts.postLogsRetryBackoff) !== null && _d !== void 0 ? _d : DEFAULT_POST_LOGS_RETRY_BACKOFF,
disableRulesetsSync: (_e = opts.disableRulesetsSync) !== null && _e !== void 0 ? _e : false,
disableIdListsSync: (_f = opts.disableIdListsSync) !== null && _f !== void 0 ? _f : false
};

@@ -45,0 +44,0 @@ }

@@ -153,4 +153,3 @@ import DynamicConfig from './DynamicConfig';

private _validateInputs;
private _fetchConfig;
private _makeOnDefaultValueFallbackFunction;
}

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

});
this._evaluator = new Evaluator_1["default"](this._fetcher, this._options, this._diagnostics);
this._evaluator = new Evaluator_1["default"](this._secretKey, this._fetcher, this._options, this._diagnostics);
this._errorBoundary = new ErrorBoundary_1["default"](secretKey);

@@ -594,22 +594,2 @@ }

};
StatsigServer.prototype._fetchConfig = function (user, name, exposureLogging) {
var _this = this;
return this._fetcher
.dispatch(this._options.api + '/get_config', {
user: user,
configName: name,
statsigMetadata: (0, core_1.getStatsigMetadata)({
exposureLoggingDisabled: exposureLogging === ExposureLogging.Disabled
})
}, 5000)
.then(function (res) {
// @ts-ignore
return res.json();
})
.then(function (resJSON) {
return Promise.resolve(new DynamicConfig_1["default"](name, resJSON.value, resJSON.rule_id, resJSON.groupName, [], _this._makeOnDefaultValueFallbackFunction(user)));
})["catch"](function () {
return Promise.resolve(new DynamicConfig_1["default"](name));
});
};
StatsigServer.prototype._makeOnDefaultValueFallbackFunction = function (user) {

@@ -616,0 +596,0 @@ var _this = this;

@@ -12,4 +12,6 @@ import { ExplicitStatsigOptions, RetryBackoffFunc } from '../StatsigOptions';

post(url: string, body: Record<string, unknown>, retries?: number, backoff?: number | RetryBackoffFunc, isRetrying?: boolean): Promise<Response>;
get(url: string, retries?: number, backoff?: number | RetryBackoffFunc, isRetrying?: boolean): Promise<Response>;
request(method: 'GET' | 'POST', url: string, body?: Record<string, unknown>, retries?: number, backoff?: number | RetryBackoffFunc, isRetrying?: boolean): Promise<Response>;
shutdown(): void;
private _retry;
}

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

StatsigFetcher.prototype.post = function (url, body, retries, backoff, isRetrying) {
if (retries === void 0) { retries = 0; }
if (backoff === void 0) { backoff = 1000; }
if (isRetrying === void 0) { isRetrying = false; }
return this.request('POST', url, body, retries, backoff, isRetrying);
};
StatsigFetcher.prototype.get = function (url, retries, backoff, isRetrying) {
if (retries === void 0) { retries = 0; }
if (backoff === void 0) { backoff = 1000; }
if (isRetrying === void 0) { isRetrying = false; }
return this.request('GET', url, undefined, retries, backoff, isRetrying);
};
StatsigFetcher.prototype.request = function (method, url, body, retries, backoff, isRetrying) {
var _this = this;

@@ -50,4 +62,3 @@ if (retries === void 0) { retries = 0; }

var params = {
method: 'POST',
body: JSON.stringify(body),
method: method,
headers: {

@@ -62,6 +73,9 @@ 'Content-type': 'application/json; charset=UTF-8',

};
if (body != null) {
params['body'] = JSON.stringify(body);
}
return (0, safeFetch_1["default"])(url, params)
.then(function (res) {
if ((!res.ok || retryStatusCodes.includes(res.status)) && retries > 0) {
return _this._retry(url, body, retries - 1, backoffAdjusted);
return _this._retry(method, url, body, retries - 1, backoffAdjusted);
}

@@ -74,3 +88,3 @@ else if (!res.ok) {

if (retries > 0) {
return _this._retry(url, body, retries - 1, backoffAdjusted);
return _this._retry(method, url, body, retries - 1, backoffAdjusted);
}

@@ -94,3 +108,3 @@ return Promise.reject(e);

};
StatsigFetcher.prototype._retry = function (url, body, retries, backoff) {
StatsigFetcher.prototype._retry = function (method, url, body, retries, backoff) {
var _this = this;

@@ -100,3 +114,3 @@ return new Promise(function (resolve, reject) {

_this.leakyBucket[url] = Math.max(_this.leakyBucket[url] - 1, 0);
_this.post(url, body, retries, backoff, true)
_this.request(method, url, body, retries, backoff, true)
.then(resolve)["catch"](reject);

@@ -103,0 +117,0 @@ }, backoff).unref());

{
"name": "statsig-node-lite",
"version": "0.4.4",
"version": "0.5.0",
"description": "A slimmed version of the Statsig Node.js SDK.",

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