@statsig/client-core 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/DataAdapterCore.d.ts +3 -3
- package/src/DataAdapterCore.js +8 -7
- package/src/EventLogger.js +1 -1
- package/src/StatsigEvent.d.ts +5 -5
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
- package/src/StatsigUser.d.ts +3 -3
- package/src/StatsigUser.js +4 -4
package/package.json
CHANGED
package/src/DataAdapterCore.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataAdapterAsyncOptions, DataAdapterResult } from './StatsigDataAdapter';
|
|
2
2
|
import { AnyStatsigOptions } from './StatsigOptionsCommon';
|
|
3
|
-
import { StatsigUser } from './StatsigUser';
|
|
3
|
+
import { StatsigUser, StatsigUserInternal } from './StatsigUser';
|
|
4
4
|
export declare abstract class DataAdapterCore {
|
|
5
5
|
private _adapterName;
|
|
6
6
|
protected _cacheSuffix: string;
|
|
@@ -18,10 +18,10 @@ export declare abstract class DataAdapterCore {
|
|
|
18
18
|
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
19
19
|
*/
|
|
20
20
|
__primeInMemoryCache(cache: Record<string, DataAdapterResult>): void;
|
|
21
|
-
protected _getDataAsyncImpl(current: DataAdapterResult | null, user?:
|
|
21
|
+
protected _getDataAsyncImpl(current: DataAdapterResult | null, user?: StatsigUserInternal, options?: DataAdapterAsyncOptions): Promise<DataAdapterResult | null>;
|
|
22
22
|
protected _prefetchDataImpl(user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
|
|
23
23
|
protected abstract _fetchFromNetwork(current: string | null, user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<string | null>;
|
|
24
|
-
protected abstract _getCacheKey(user?:
|
|
24
|
+
protected abstract _getCacheKey(user?: StatsigUserInternal): string;
|
|
25
25
|
protected abstract _isCachedResultValidFor204(result: DataAdapterResult, user: StatsigUser | undefined): boolean;
|
|
26
26
|
private _fetchAndPrepFromNetwork;
|
|
27
27
|
protected _getSdkKey(): string;
|
package/src/DataAdapterCore.js
CHANGED
|
@@ -30,21 +30,21 @@ class DataAdapterCore {
|
|
|
30
30
|
this._options = options;
|
|
31
31
|
}
|
|
32
32
|
getDataSync(user) {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
33
|
+
const normalized = user && (0, StatsigUser_1._normalizeUser)(user, this._options);
|
|
34
|
+
const cacheKey = this._getCacheKey(normalized);
|
|
35
|
+
const inMem = this._inMemoryCache.get(cacheKey, normalized);
|
|
35
36
|
if (inMem) {
|
|
36
37
|
return inMem;
|
|
37
38
|
}
|
|
38
39
|
const cache = this._loadFromCache(cacheKey);
|
|
39
40
|
if (cache) {
|
|
40
41
|
this._inMemoryCache.add(cacheKey, cache);
|
|
41
|
-
return this._inMemoryCache.get(cacheKey,
|
|
42
|
+
return this._inMemoryCache.get(cacheKey, normalized);
|
|
42
43
|
}
|
|
43
44
|
return null;
|
|
44
45
|
}
|
|
45
46
|
setData(data, user) {
|
|
46
|
-
|
|
47
|
-
const normalized = user && (0, StatsigUser_1._normalizeUser)(user, (_a = this._options) === null || _a === void 0 ? void 0 : _a.environment);
|
|
47
|
+
const normalized = user && (0, StatsigUser_1._normalizeUser)(user, this._options);
|
|
48
48
|
const cacheKey = this._getCacheKey(normalized);
|
|
49
49
|
this._inMemoryCache.add(cacheKey, _makeDataAdapterResult('Bootstrap', data, null, normalized));
|
|
50
50
|
}
|
|
@@ -71,8 +71,9 @@ class DataAdapterCore {
|
|
|
71
71
|
}
|
|
72
72
|
_prefetchDataImpl(user, options) {
|
|
73
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const
|
|
75
|
-
const
|
|
74
|
+
const normalized = user && (0, StatsigUser_1._normalizeUser)(user, this._options);
|
|
75
|
+
const cacheKey = this._getCacheKey(normalized);
|
|
76
|
+
const result = yield this._getDataAsyncImpl(null, normalized, options);
|
|
76
77
|
if (result) {
|
|
77
78
|
this._inMemoryCache.add(cacheKey, Object.assign(Object.assign({}, result), { source: 'Prefetch' }));
|
|
78
79
|
}
|
package/src/EventLogger.js
CHANGED
|
@@ -115,7 +115,7 @@ class EventLogger {
|
|
|
115
115
|
if (!(0, StatsigEvent_1._isExposureEvent)(event)) {
|
|
116
116
|
return true;
|
|
117
117
|
}
|
|
118
|
-
const user = event.user ? event.user : {};
|
|
118
|
+
const user = event.user ? event.user : { statsigEnvironment: undefined };
|
|
119
119
|
const metadata = event.metadata ? event.metadata : {};
|
|
120
120
|
const key = [
|
|
121
121
|
event.eventName,
|
package/src/StatsigEvent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SecondaryExposure } from './EvaluationTypes';
|
|
2
2
|
import { DynamicConfig, FeatureGate, Layer } from './StatsigTypes';
|
|
3
|
-
import {
|
|
3
|
+
import { StatsigUserInternal } from './StatsigUser';
|
|
4
4
|
export type StatsigEvent = {
|
|
5
5
|
eventName: string;
|
|
6
6
|
value?: string | number | null;
|
|
@@ -9,7 +9,7 @@ export type StatsigEvent = {
|
|
|
9
9
|
} | null;
|
|
10
10
|
};
|
|
11
11
|
export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
|
|
12
|
-
user:
|
|
12
|
+
user: StatsigUserInternal | null;
|
|
13
13
|
time: number;
|
|
14
14
|
metadata?: {
|
|
15
15
|
[key: string]: unknown;
|
|
@@ -17,6 +17,6 @@ export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
|
|
|
17
17
|
secondaryExposures?: SecondaryExposure[];
|
|
18
18
|
};
|
|
19
19
|
export declare const _isExposureEvent: ({ eventName, }: StatsigEventInternal) => boolean;
|
|
20
|
-
export declare const _createGateExposure: (user:
|
|
21
|
-
export declare const _createConfigExposure: (user:
|
|
22
|
-
export declare const _createLayerParameterExposure: (user:
|
|
20
|
+
export declare const _createGateExposure: (user: StatsigUserInternal, gate: FeatureGate) => StatsigEventInternal;
|
|
21
|
+
export declare const _createConfigExposure: (user: StatsigUserInternal, config: DynamicConfig) => StatsigEventInternal;
|
|
22
|
+
export declare const _createLayerParameterExposure: (user: StatsigUserInternal, layer: Layer, parameterName: string) => StatsigEventInternal;
|
package/src/StatsigMetadata.d.ts
CHANGED
package/src/StatsigMetadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
|
|
4
|
-
exports.SDK_VERSION = '1.
|
|
4
|
+
exports.SDK_VERSION = '1.5.0';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|
package/src/StatsigUser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StatsigEnvironment } from './StatsigOptionsCommon';
|
|
1
|
+
import type { AnyStatsigOptions, StatsigEnvironment } from './StatsigOptionsCommon';
|
|
2
2
|
type StatsigUserPrimitives = string | number | boolean | Array<string> | undefined;
|
|
3
3
|
export type StatsigUser = {
|
|
4
4
|
userID?: string;
|
|
@@ -16,8 +16,8 @@ export type StatsigUser = {
|
|
|
16
16
|
privateAttributes?: Record<string, StatsigUserPrimitives> | null;
|
|
17
17
|
};
|
|
18
18
|
export type StatsigUserInternal = StatsigUser & {
|
|
19
|
-
statsigEnvironment
|
|
19
|
+
statsigEnvironment: StatsigEnvironment | undefined;
|
|
20
20
|
};
|
|
21
|
-
export declare function _normalizeUser(original: StatsigUser,
|
|
21
|
+
export declare function _normalizeUser(original: StatsigUser, options?: AnyStatsigOptions | null): StatsigUserInternal;
|
|
22
22
|
export declare function _getFullUserHash(user: StatsigUser | undefined): string | null;
|
|
23
23
|
export {};
|
package/src/StatsigUser.js
CHANGED
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._getFullUserHash = exports._normalizeUser = void 0;
|
|
4
4
|
const Hashing_1 = require("./Hashing");
|
|
5
5
|
const Log_1 = require("./Log");
|
|
6
|
-
function _normalizeUser(original,
|
|
6
|
+
function _normalizeUser(original, options) {
|
|
7
7
|
try {
|
|
8
8
|
const copy = JSON.parse(JSON.stringify(original));
|
|
9
|
-
if (environment != null) {
|
|
10
|
-
copy.statsigEnvironment = environment;
|
|
9
|
+
if (options != null && options.environment != null) {
|
|
10
|
+
copy.statsigEnvironment = options.environment;
|
|
11
11
|
}
|
|
12
12
|
return copy;
|
|
13
13
|
}
|
|
14
14
|
catch (error) {
|
|
15
15
|
Log_1.Log.error('Failed to JSON.stringify user');
|
|
16
|
-
return {};
|
|
16
|
+
return { statsigEnvironment: undefined };
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports._normalizeUser = _normalizeUser;
|