@statsig/client-core
Advanced tools
Comparing version 0.0.1-beta.30 to 0.0.1-beta.31
{ | ||
"name": "@statsig/client-core", | ||
"version": "0.0.1-beta.30", | ||
"version": "0.0.1-beta.31", | ||
"dependencies": {}, | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
@@ -8,3 +8,3 @@ import { StatsigClientInterface } from './ClientInterfaces'; | ||
srInstances?: Record<string, unknown>; | ||
instance?: (sdkKey: string) => StatsigClientInterface | undefined; | ||
instance: (sdkKey?: string) => StatsigClientInterface | undefined; | ||
}; | ||
@@ -18,1 +18,2 @@ declare global { | ||
export declare const _getStatsigGlobal: () => StatsigGlobal; | ||
export declare const _getInstance: (sdkKey: string) => StatsigClientInterface | undefined; |
@@ -5,3 +5,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._getStatsigGlobal = void 0; | ||
exports._getInstance = exports._getStatsigGlobal = void 0; | ||
const _getStatsigGlobal = () => { | ||
return __STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : statsigGlobal; | ||
}; | ||
exports._getStatsigGlobal = _getStatsigGlobal; | ||
const _getInstance = (sdkKey) => { | ||
var _a; | ||
return sdkKey ? (_a = __STATSIG__ === null || __STATSIG__ === void 0 ? void 0 : __STATSIG__.instances) === null || _a === void 0 ? void 0 : _a[sdkKey] : __STATSIG__ === null || __STATSIG__ === void 0 ? void 0 : __STATSIG__.lastInstance; | ||
}; | ||
exports._getInstance = _getInstance; | ||
const GLOBAL_KEY = '__STATSIG__'; | ||
@@ -11,9 +20,7 @@ const _window = typeof window !== 'undefined' ? window : {}; | ||
const _globalThis = typeof globalThis !== 'undefined' ? globalThis : {}; | ||
const statsigGlobal = (_c = (_b = (_a = _window[GLOBAL_KEY]) !== null && _a !== void 0 ? _a : _global[GLOBAL_KEY]) !== null && _b !== void 0 ? _b : _globalThis[GLOBAL_KEY]) !== null && _c !== void 0 ? _c : {}; | ||
const statsigGlobal = (_c = (_b = (_a = _window[GLOBAL_KEY]) !== null && _a !== void 0 ? _a : _global[GLOBAL_KEY]) !== null && _b !== void 0 ? _b : _globalThis[GLOBAL_KEY]) !== null && _c !== void 0 ? _c : { | ||
instance: exports._getInstance, | ||
}; | ||
_window[GLOBAL_KEY] = statsigGlobal; | ||
_global[GLOBAL_KEY] = statsigGlobal; | ||
_globalThis[GLOBAL_KEY] = statsigGlobal; | ||
const _getStatsigGlobal = () => { | ||
return __STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : statsigGlobal; | ||
}; | ||
exports._getStatsigGlobal = _getStatsigGlobal; |
@@ -45,2 +45,5 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!_ensureValidSdkKey(args)) { | ||
return false; | ||
} | ||
const url = yield this._getPopulatedURL(args); | ||
@@ -54,2 +57,5 @@ const body = yield this._getPopulatedBody(args); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!_ensureValidSdkKey(args)) { | ||
return null; | ||
} | ||
const { method, body, retries } = args; | ||
@@ -136,2 +142,9 @@ const controller = new AbortController(); | ||
exports.NetworkCore = NetworkCore; | ||
const _ensureValidSdkKey = (args) => { | ||
if (!args.sdkKey) { | ||
Log_1.Log.warn('Unable to make request without an SDK key'); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
function _getErrorMessage(controller, error) { | ||
@@ -138,0 +151,0 @@ if (controller.signal.aborted && |
@@ -7,7 +7,7 @@ import './$_StatsigGlobal'; | ||
import { OverrideAdapter } from './OverrideAdapter'; | ||
import { StatsigClientEvent, StatsigClientEventCallback, StatsigClientEventEmitterInterface, StatsigClientEventName, StatsigLoadingStatus } from './StatsigClientEventEmitter'; | ||
import { AnyStatsigClientEvent, StatsigClientEventCallback, StatsigClientEventEmitterInterface, StatsigClientEventName, StatsigLoadingStatus } from './StatsigClientEventEmitter'; | ||
import { DataAdapterResult, EvaluationsDataAdapter, SpecsDataAdapter } from './StatsigDataAdapter'; | ||
import { StatsigEventInternal } from './StatsigEvent'; | ||
import { AnyStatsigOptions, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon'; | ||
export type StatsigClientEmitEventFunc = (event: StatsigClientEvent) => void; | ||
export type StatsigClientEmitEventFunc = (event: AnyStatsigClientEvent) => void; | ||
export type StatsigContext = { | ||
@@ -64,5 +64,5 @@ sdkKey: string; | ||
__on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void; | ||
protected _emit(event: StatsigClientEvent): void; | ||
protected _emit(event: AnyStatsigClientEvent): void; | ||
protected _setStatus(newStatus: StatsigLoadingStatus, values: DataAdapterResult | null): void; | ||
protected _enqueueExposure(name: string, exposure: StatsigEventInternal, options?: EvaluationOptionsCommon): void; | ||
} |
@@ -14,2 +14,3 @@ "use strict"; | ||
require("./$_StatsigGlobal"); | ||
const __StatsigGlobal_1 = require("./$_StatsigGlobal"); | ||
const ErrorBoundary_1 = require("./ErrorBoundary"); | ||
@@ -38,4 +39,7 @@ const EventLogger_1 = require("./EventLogger"); | ||
this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey); | ||
const statsigGlobal = __STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {}; | ||
const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)(); | ||
const instances = (_c = statsigGlobal.instances) !== null && _c !== void 0 ? _c : {}; | ||
if (instances[sdkKey] != null) { | ||
Log_1.Log.warn('Creating multiple Statsig clients with the same SDK key can lead to unexpected behavior. Multi-instance support requires different SDK keys.'); | ||
} | ||
const inst = this; | ||
@@ -42,0 +46,0 @@ instances[sdkKey] = inst; |
@@ -50,3 +50,3 @@ import { DataAdapterResult } from './StatsigDataAdapter'; | ||
*/ | ||
export type StatsigClientEvent = Flatten<{ | ||
export type AnyStatsigClientEvent = Flatten<{ | ||
[K in keyof EventNameToEventDataMap]: { | ||
@@ -56,7 +56,8 @@ name: K; | ||
}[keyof EventNameToEventDataMap]>; | ||
export type StatsigClientEvent<T> = Extract<AnyStatsigClientEvent, { | ||
name: T; | ||
}>; | ||
export type AnyStatsigClientEventListener = StatsigClientEventCallback<StatsigClientEventName>; | ||
export type StatsigClientEventName = StatsigClientEvent['name'] | '*'; | ||
export type StatsigClientEventCallback<T extends StatsigClientEventName> = (event: T extends '*' ? StatsigClientEvent : Extract<StatsigClientEvent, { | ||
name: T; | ||
}>) => void; | ||
export type StatsigClientEventName = AnyStatsigClientEvent['name'] | '*'; | ||
export type StatsigClientEventCallback<T extends StatsigClientEventName> = (event: T extends '*' ? AnyStatsigClientEvent : StatsigClientEvent<T>) => void; | ||
export interface StatsigClientEventEmitterInterface { | ||
@@ -63,0 +64,0 @@ readonly loadingStatus: StatsigLoadingStatus; |
@@ -1,2 +0,2 @@ | ||
export declare const SDK_VERSION = "0.0.1-beta.30"; | ||
export declare const SDK_VERSION = "0.0.1-beta.31"; | ||
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.30'; | ||
exports.SDK_VERSION = '0.0.1-beta.31'; | ||
let metadata = { | ||
@@ -6,0 +6,0 @@ sdkVersion: exports.SDK_VERSION, |
@@ -6,4 +6,3 @@ import { LogLevel } from './Log'; | ||
/** | ||
* Prevents writing anything to storage. | ||
* Note: caching will not work if storage is disabled | ||
* Prevents sending any events over the network. | ||
*/ | ||
@@ -13,2 +12,3 @@ disableLogging?: boolean; | ||
* Prevents writing anything to storage. | ||
* | ||
* Note: caching will not work if storage is disabled | ||
@@ -15,0 +15,0 @@ */ |
111880
2597