@statsig/client-core
Advanced tools
Comparing version 3.3.0 to 3.4.0-beta.1
{ | ||
"name": "@statsig/client-core", | ||
"version": "3.3.0", | ||
"version": "3.4.0-beta.1", | ||
"dependencies": {}, | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
@@ -19,4 +19,4 @@ /** Statsig Global should go first */ | ||
export * from './Log'; | ||
export * from './NetworkConfig'; | ||
export * from './NetworkCore'; | ||
export * from './NetworkConfig'; | ||
export * from './OverrideAdapter'; | ||
@@ -34,6 +34,6 @@ export * from './ParamStoreTypes'; | ||
export * from './StatsigOptionsCommon'; | ||
export * from './StatsigPlugin'; | ||
export * from './StatsigTypeFactories'; | ||
export * from './StatsigTypes'; | ||
export * from './StatsigUser'; | ||
export * from './StatsigPlugin'; | ||
export * from './StorageProvider'; | ||
@@ -40,0 +40,0 @@ export * from './TypedJsonParse'; |
@@ -41,4 +41,4 @@ "use strict"; | ||
__exportStar(require("./Log"), exports); | ||
__exportStar(require("./NetworkConfig"), exports); | ||
__exportStar(require("./NetworkCore"), exports); | ||
__exportStar(require("./NetworkConfig"), exports); | ||
__exportStar(require("./OverrideAdapter"), exports); | ||
@@ -56,6 +56,6 @@ __exportStar(require("./ParamStoreTypes"), exports); | ||
__exportStar(require("./StatsigOptionsCommon"), exports); | ||
__exportStar(require("./StatsigPlugin"), exports); | ||
__exportStar(require("./StatsigTypeFactories"), exports); | ||
__exportStar(require("./StatsigTypes"), exports); | ||
__exportStar(require("./StatsigUser"), exports); | ||
__exportStar(require("./StatsigPlugin"), exports); | ||
__exportStar(require("./StorageProvider"), exports); | ||
@@ -62,0 +62,0 @@ __exportStar(require("./TypedJsonParse"), exports); |
import './$_StatsigGlobal'; | ||
import { ErrorBoundary } from './ErrorBoundary'; | ||
import { NetworkPriority } from './NetworkConfig'; | ||
@@ -31,7 +32,10 @@ import { StatsigClientEmitEventFunc } from './StatsigClientBase'; | ||
private readonly _options; | ||
private readonly _fallbackResolver; | ||
private _errorBoundary; | ||
constructor(options: AnyStatsigOptions | null, _emitter?: StatsigClientEmitEventFunc | undefined); | ||
setErrorBoundary(errorBoundary: ErrorBoundary): void; | ||
isBeaconSupported(): boolean; | ||
beacon(args: BeaconRequestArgs): Promise<boolean>; | ||
post(args: RequestArgsWithData): Promise<NetworkResponse | null>; | ||
get(args: RequestArgs): Promise<NetworkResponse | null>; | ||
isBeaconSupported(): boolean; | ||
beacon(args: BeaconRequestArgs): Promise<boolean>; | ||
private _sendRequest; | ||
@@ -41,3 +45,4 @@ private _getPopulatedURL; | ||
private _attemptToEncodeString; | ||
private _getInternalRequestArgs; | ||
} | ||
export {}; |
@@ -18,2 +18,3 @@ "use strict"; | ||
const NetworkConfig_1 = require("./NetworkConfig"); | ||
const NetworkFallbackResolver_1 = require("./NetworkFallbackResolver"); | ||
const SDKType_1 = require("./SDKType"); | ||
@@ -34,2 +35,3 @@ const SafeJs_1 = require("./SafeJs"); | ||
this._options = {}; | ||
this._errorBoundary = null; | ||
if (options) { | ||
@@ -44,15 +46,10 @@ this._options = options; | ||
} | ||
this._fallbackResolver = new NetworkFallbackResolver_1.NetworkFallbackResolver(this._options); | ||
} | ||
post(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let body = yield this._getPopulatedBody(args); | ||
if (args.isStatsigEncodable) { | ||
body = this._attemptToEncodeString(args, body); | ||
} | ||
return this._sendRequest(Object.assign({ method: 'POST', body }, args)); | ||
}); | ||
setErrorBoundary(errorBoundary) { | ||
this._errorBoundary = errorBoundary; | ||
this._errorBoundary.wrap(this); | ||
this._errorBoundary.wrap(this._fallbackResolver); | ||
this._fallbackResolver.setErrorBoundary(errorBoundary); | ||
} | ||
get(args) { | ||
return this._sendRequest(Object.assign({ method: 'GET' }, args)); | ||
} | ||
isBeaconSupported() { | ||
@@ -67,4 +64,5 @@ return (typeof navigator !== 'undefined' && | ||
} | ||
const body = yield this._getPopulatedBody(args); | ||
const url = yield this._getPopulatedURL(args); | ||
const argsInternal = this._getInternalRequestArgs('POST', args); | ||
const body = yield this._getPopulatedBody(argsInternal, args.data); | ||
const url = yield this._getPopulatedURL(argsInternal); | ||
const nav = navigator; | ||
@@ -74,2 +72,16 @@ return nav.sendBeacon.bind(nav)(url, body); | ||
} | ||
post(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const argsInternal = this._getInternalRequestArgs('POST', args); | ||
argsInternal.body = yield this._getPopulatedBody(argsInternal, args.data); | ||
if (args.isStatsigEncodable) { | ||
argsInternal.body = this._attemptToEncodeString(argsInternal, argsInternal.body); | ||
} | ||
return this._sendRequest(argsInternal); | ||
}); | ||
} | ||
get(args) { | ||
const argsInternal = this._getInternalRequestArgs('GET', args); | ||
return this._sendRequest(argsInternal); | ||
} | ||
_sendRequest(args) { | ||
@@ -86,5 +98,7 @@ var _a, _b, _c; | ||
const currentAttempt = attempt !== null && attempt !== void 0 ? attempt : 1; | ||
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null; | ||
const handle = setTimeout(() => controller === null || controller === void 0 ? void 0 : controller.abort(`Timeout of ${this._timeout}ms expired.`), this._timeout); | ||
const url = yield this._getPopulatedURL(args); | ||
const abortController = typeof AbortController !== 'undefined' ? new AbortController() : null; | ||
const timeoutHandle = setTimeout(() => { | ||
abortController === null || abortController === void 0 ? void 0 : abortController.abort(`Timeout of ${this._timeout}ms expired.`); | ||
}, this._timeout); | ||
const populatedUrl = yield this._getPopulatedURL(args); | ||
let response = null; | ||
@@ -97,17 +111,13 @@ const keepalive = (0, VisibilityObserving_1._isUnloading)(); | ||
headers: Object.assign({}, args.headers), | ||
signal: controller === null || controller === void 0 ? void 0 : controller.signal, | ||
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, | ||
priority: args.priority, | ||
keepalive, | ||
}; | ||
if (args.isInitialize) { | ||
Diagnostics_1.Diagnostics._markInitNetworkReqStart(args.sdkKey, { | ||
attempt: currentAttempt, | ||
}); | ||
} | ||
_tryMarkInitStart(args, currentAttempt); | ||
const func = (_a = this._netConfig.networkOverrideFunc) !== null && _a !== void 0 ? _a : fetch; | ||
response = yield func(url, config); | ||
clearTimeout(handle); | ||
response = yield func(populatedUrl, config); | ||
clearTimeout(timeoutHandle); | ||
if (!response.ok) { | ||
const text = yield response.text().catch(() => 'No Text'); | ||
const err = new Error(`NetworkError: ${url} ${text}`); | ||
const err = new Error(`NetworkError: ${populatedUrl} ${text}`); | ||
err.name = 'NetworkError'; | ||
@@ -117,5 +127,4 @@ throw err; | ||
const text = yield response.text(); | ||
if (args.isInitialize) { | ||
Diagnostics_1.Diagnostics._markInitNetworkReqEnd(args.sdkKey, Diagnostics_1.Diagnostics._getDiagnosticsData(response, currentAttempt, text)); | ||
} | ||
_tryMarkInitEnd(args, response, currentAttempt, text); | ||
this._fallbackResolver.tryBumpExpiryTime(args.sdkKey, populatedUrl); | ||
return { | ||
@@ -127,5 +136,8 @@ body: text, | ||
catch (error) { | ||
const errorMessage = _getErrorMessage(controller, error); | ||
if (args.isInitialize) { | ||
Diagnostics_1.Diagnostics._markInitNetworkReqEnd(args.sdkKey, Diagnostics_1.Diagnostics._getDiagnosticsData(response, currentAttempt, '', error)); | ||
const errorMessage = _getErrorMessage(abortController, error); | ||
const timedOut = _didTimeout(abortController); | ||
_tryMarkInitEnd(args, response, currentAttempt, '', error); | ||
const fallbackUpdated = yield this._fallbackResolver.tryFetchUpdatedFallbackInfo(args.sdkKey, populatedUrl, errorMessage, timedOut); | ||
if (fallbackUpdated) { | ||
args.fallbackUrl = this._fallbackResolver.getFallbackUrl(args.sdkKey, args.url); | ||
} | ||
@@ -141,6 +153,6 @@ if (!retries || | ||
}); | ||
Log_1.Log.error(`A networking error occured during ${method} request to ${url}.`, errorMessage, error); | ||
Log_1.Log.error(`A networking error occured during ${method} request to ${populatedUrl}.`, errorMessage, error); | ||
return null; | ||
} | ||
return this._sendRequest(Object.assign(Object.assign({}, args), { retries: retries, attempt: currentAttempt + 1 })); | ||
return this._sendRequest(Object.assign(Object.assign({}, args), { retries, attempt: currentAttempt + 1 })); | ||
} | ||
@@ -150,3 +162,5 @@ }); | ||
_getPopulatedURL(args) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = (_a = args.fallbackUrl) !== null && _a !== void 0 ? _a : args.url; | ||
const params = Object.assign({ [NetworkConfig_1.NetworkParam.SdkKey]: args.sdkKey, [NetworkConfig_1.NetworkParam.SdkType]: SDKType_1.SDKType._get(args.sdkKey), [NetworkConfig_1.NetworkParam.SdkVersion]: StatsigMetadata_1.SDK_VERSION, [NetworkConfig_1.NetworkParam.Time]: String(Date.now()), [NetworkConfig_1.NetworkParam.SessionID]: SessionID_1.SessionID.get(args.sdkKey) }, args.params); | ||
@@ -158,8 +172,8 @@ const query = Object.keys(params) | ||
.join('&'); | ||
return `${args.url}${query ? `?${query}` : ''}`; | ||
return `${url}${query ? `?${query}` : ''}`; | ||
}); | ||
} | ||
_getPopulatedBody(args) { | ||
_getPopulatedBody(args, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data, sdkKey } = args; | ||
const { sdkKey, fallbackUrl } = args; | ||
const stableID = StableID_1.StableID.get(sdkKey); | ||
@@ -170,3 +184,4 @@ const sessionID = SessionID_1.SessionID.get(sdkKey); | ||
sessionID, | ||
sdkType }) })); | ||
sdkType, | ||
fallbackUrl }) })); | ||
}); | ||
@@ -177,4 +192,3 @@ } | ||
const win = (0, SafeJs_1._getWindowSafe)(); | ||
if (!args.isStatsigEncodable || | ||
this._options.disableStatsigEncoding || | ||
if (this._options.disableStatsigEncoding || | ||
(0, __StatsigGlobal_1._getStatsigGlobalFlag)('no-encode') != null || | ||
@@ -194,2 +208,7 @@ !(win === null || win === void 0 ? void 0 : win.btoa)) { | ||
} | ||
_getInternalRequestArgs(method, args) { | ||
const fallbackUrl = this._fallbackResolver.getFallbackUrl(args.sdkKey, args.url); | ||
return Object.assign(Object.assign({}, args), { method, | ||
fallbackUrl }); | ||
} | ||
} | ||
@@ -217,1 +236,21 @@ exports.NetworkCore = NetworkCore; | ||
} | ||
function _didTimeout(controller) { | ||
const timeout = (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) && | ||
typeof controller.signal.reason === 'string' && | ||
controller.signal.reason.includes('Timeout'); | ||
return timeout || false; | ||
} | ||
function _tryMarkInitStart(args, attempt) { | ||
if (!args.isInitialize) { | ||
return; | ||
} | ||
Diagnostics_1.Diagnostics._markInitNetworkReqStart(args.sdkKey, { | ||
attempt, | ||
}); | ||
} | ||
function _tryMarkInitEnd(args, response, attempt, body, err) { | ||
if (!args.isInitialize) { | ||
return; | ||
} | ||
Diagnostics_1.Diagnostics._markInitNetworkReqEnd(args.sdkKey, Diagnostics_1.Diagnostics._getDiagnosticsData(response, attempt, body, err)); | ||
} |
@@ -39,5 +39,5 @@ "use strict"; | ||
this._errorBoundary.wrap(this); | ||
this._errorBoundary.wrap(network); | ||
this._errorBoundary.wrap(adapter); | ||
this._errorBoundary.wrap(this._logger); | ||
network.setErrorBoundary(this._errorBoundary); | ||
this.dataAdapter = adapter; | ||
@@ -44,0 +44,0 @@ this.dataAdapter.attach(sdkKey, options); |
@@ -1,2 +0,2 @@ | ||
export declare const SDK_VERSION = "3.3.0"; | ||
export declare const SDK_VERSION = "3.4.0-beta.1"; | ||
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 = '3.3.0'; | ||
exports.SDK_VERSION = '3.4.0-beta.1'; | ||
let metadata = { | ||
@@ -6,0 +6,0 @@ sdkVersion: exports.SDK_VERSION, |
@@ -8,2 +8,2 @@ import { DynamicConfigEvaluation, EvaluationDetails, GateEvaluation, LayerEvaluation } from './EvaluationTypes'; | ||
export declare function _mergeOverride<T extends AnyConfigBasedStatsigType>(original: T, overridden: T | null | undefined, value: Record<string, unknown>, exposeFunc?: (param: string) => void): T; | ||
export declare function _makeTypedGet(value: Record<string, unknown> | undefined, exposeFunc?: (param: string) => void): TypedGet; | ||
export declare function _makeTypedGet(name: string, value: Record<string, unknown> | undefined, exposeFunc?: (param: string) => void): TypedGet; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._makeTypedGet = exports._mergeOverride = exports._makeLayer = exports._makeExperiment = exports._makeDynamicConfig = exports._makeFeatureGate = void 0; | ||
const Log_1 = require("./Log"); | ||
const TypingUtils_1 = require("./TypingUtils"); | ||
@@ -23,3 +24,3 @@ const DEFAULT_RULE = 'default'; | ||
const value = (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _a !== void 0 ? _a : {}; | ||
return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, value)), { get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) }); | ||
return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, value)), { get: _makeTypedGet(name, evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) }); | ||
} | ||
@@ -35,10 +36,10 @@ exports._makeDynamicConfig = _makeDynamicConfig; | ||
var _a, _b; | ||
return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, undefined)), { get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value, exposeFunc), groupName: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.group_name) !== null && _a !== void 0 ? _a : null, __value: (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _b !== void 0 ? _b : {} }); | ||
return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, undefined)), { get: _makeTypedGet(name, evaluation === null || evaluation === void 0 ? void 0 : evaluation.value, exposeFunc), groupName: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.group_name) !== null && _a !== void 0 ? _a : null, __value: (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _b !== void 0 ? _b : {} }); | ||
} | ||
exports._makeLayer = _makeLayer; | ||
function _mergeOverride(original, overridden, value, exposeFunc) { | ||
return Object.assign(Object.assign(Object.assign({}, original), overridden), { get: _makeTypedGet(value, exposeFunc) }); | ||
return Object.assign(Object.assign(Object.assign({}, original), overridden), { get: _makeTypedGet(original.name, value, exposeFunc) }); | ||
} | ||
exports._mergeOverride = _mergeOverride; | ||
function _makeTypedGet(value, exposeFunc) { | ||
function _makeTypedGet(name, value, exposeFunc) { | ||
return (param, fallback) => { | ||
@@ -51,2 +52,3 @@ var _a; | ||
if (fallback != null && !(0, TypingUtils_1._isTypeMatch)(found, fallback)) { | ||
Log_1.Log.warn(`Parameter type mismatch. '${name}.${param}' was found to be type '${typeof found}' but fallback/return type is '${typeof fallback}'. See https://docs.statsig.com/client/javascript-sdk/#typed-getters`); | ||
return (fallback !== null && fallback !== void 0 ? fallback : null); | ||
@@ -53,0 +55,0 @@ } |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
143159
81
3447
2
3