@statsig/client-core 2.2.0-beta.5 → 2.2.0-beta.6
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
CHANGED
|
@@ -9,6 +9,7 @@ import { StatsigEvent } from './StatsigEvent';
|
|
|
9
9
|
import { AnyStatsigOptions, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon';
|
|
10
10
|
import { DynamicConfig, Experiment, FeatureGate, Layer, ParameterStore } from './StatsigTypes';
|
|
11
11
|
import { StatsigUser } from './StatsigUser';
|
|
12
|
+
import { StorageProvider } from './StorageProvider';
|
|
12
13
|
import { Flatten } from './TypingUtils';
|
|
13
14
|
export interface StatsigClientCommonInterface extends StatsigClientEventEmitterInterface {
|
|
14
15
|
initializeSync(): void;
|
|
@@ -23,6 +24,7 @@ export type CommonContext = {
|
|
|
23
24
|
errorBoundary: ErrorBoundary;
|
|
24
25
|
session: StatsigSession;
|
|
25
26
|
stableID: string;
|
|
27
|
+
storageProvider: StorageProvider;
|
|
26
28
|
};
|
|
27
29
|
export type OnDeviceEvaluationsContext = CommonContext & {
|
|
28
30
|
values: DownloadConfigSpecsResponse | null;
|
package/src/DataAdapterCore.d.ts
CHANGED
|
@@ -12,12 +12,6 @@ export declare abstract class DataAdapterCore {
|
|
|
12
12
|
attach(sdkKey: string, options: AnyStatsigOptions | null): void;
|
|
13
13
|
getDataSync(user?: StatsigUser | undefined): DataAdapterResult | null;
|
|
14
14
|
setData(data: string, user?: StatsigUser): void;
|
|
15
|
-
/**
|
|
16
|
-
* (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
|
|
17
|
-
*
|
|
18
|
-
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
19
|
-
*/
|
|
20
|
-
__primeInMemoryCache(cache: Record<string, DataAdapterResult>): void;
|
|
21
15
|
protected _getDataAsyncImpl(current: DataAdapterResult | null, user?: StatsigUserInternal, options?: DataAdapterAsyncOptions): Promise<DataAdapterResult | null>;
|
|
22
16
|
protected _prefetchDataImpl(user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
|
|
23
17
|
protected abstract _fetchFromNetwork(current: string | null, user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<string | null>;
|
package/src/DataAdapterCore.js
CHANGED
|
@@ -48,16 +48,9 @@ class DataAdapterCore {
|
|
|
48
48
|
const cacheKey = this._getCacheKey(normalized);
|
|
49
49
|
this._inMemoryCache.add(cacheKey, _makeDataAdapterResult('Bootstrap', data, null, normalized));
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
|
|
53
|
-
*
|
|
54
|
-
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
55
|
-
*/
|
|
56
|
-
__primeInMemoryCache(cache) {
|
|
57
|
-
this._inMemoryCache.merge(cache);
|
|
58
|
-
}
|
|
59
51
|
_getDataAsyncImpl(current, user, options) {
|
|
60
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
StorageProvider_1.Storage._isProviderReady() && (yield StorageProvider_1.Storage._isProviderReady());
|
|
61
54
|
const cache = current !== null && current !== void 0 ? current : this.getDataSync(user);
|
|
62
55
|
const ops = [this._fetchAndPrepFromNetwork(cache, user, options)];
|
|
63
56
|
if (options === null || options === void 0 ? void 0 : options.timeoutMs) {
|
|
@@ -92,7 +85,7 @@ class DataAdapterCore {
|
|
|
92
85
|
}
|
|
93
86
|
const response = (0, TypedJsonParse_1._typedJsonParse)(latest, 'has_updates', 'Response');
|
|
94
87
|
const sdkKey = this._getSdkKey();
|
|
95
|
-
const stableID =
|
|
88
|
+
const stableID = StableID_1.StableID.get(sdkKey);
|
|
96
89
|
let result = null;
|
|
97
90
|
if ((response === null || response === void 0 ? void 0 : response.has_updates) === true) {
|
|
98
91
|
result = _makeDataAdapterResult('Network', latest, stableID, user);
|
|
@@ -105,7 +98,7 @@ class DataAdapterCore {
|
|
|
105
98
|
}
|
|
106
99
|
const cacheKey = this._getCacheKey(user);
|
|
107
100
|
this._inMemoryCache.add(cacheKey, result);
|
|
108
|
-
|
|
101
|
+
this._writeToCache(cacheKey, result);
|
|
109
102
|
return result;
|
|
110
103
|
});
|
|
111
104
|
}
|
|
@@ -126,23 +119,19 @@ class DataAdapterCore {
|
|
|
126
119
|
return result ? Object.assign(Object.assign({}, result), { source: 'Cache' }) : null;
|
|
127
120
|
}
|
|
128
121
|
_writeToCache(cacheKey, result) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
yield this._runLocalStorageCacheEviction(cacheKey);
|
|
132
|
-
});
|
|
122
|
+
StorageProvider_1.Storage._setItem(cacheKey, JSON.stringify(result));
|
|
123
|
+
this._runLocalStorageCacheEviction(cacheKey);
|
|
133
124
|
}
|
|
134
125
|
_runLocalStorageCacheEviction(cacheKey) {
|
|
135
126
|
var _a;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
yield (0, StorageProvider_1._setObjectInStorage)(this._lastModifiedStoreKey, lastModifiedTimeMap);
|
|
145
|
-
});
|
|
127
|
+
const lastModifiedTimeMap = (_a = (0, StorageProvider_1._getObjectFromStorage)(this._lastModifiedStoreKey)) !== null && _a !== void 0 ? _a : {};
|
|
128
|
+
lastModifiedTimeMap[cacheKey] = Date.now();
|
|
129
|
+
const evictable = _getEvictableKey(lastModifiedTimeMap, CACHE_LIMIT);
|
|
130
|
+
if (evictable) {
|
|
131
|
+
delete lastModifiedTimeMap[evictable];
|
|
132
|
+
StorageProvider_1.Storage._removeItem(evictable);
|
|
133
|
+
}
|
|
134
|
+
(0, StorageProvider_1._setObjectInStorage)(this._lastModifiedStoreKey, lastModifiedTimeMap);
|
|
146
135
|
}
|
|
147
136
|
}
|
|
148
137
|
exports.DataAdapterCore = DataAdapterCore;
|
package/src/NetworkCore.js
CHANGED
|
@@ -144,8 +144,8 @@ class NetworkCore {
|
|
|
144
144
|
_getPopulatedBody(args) {
|
|
145
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
146
|
const { data, sdkKey } = args;
|
|
147
|
-
const stableID =
|
|
148
|
-
const sessionID =
|
|
147
|
+
const stableID = StableID_1.StableID.get(sdkKey);
|
|
148
|
+
const sessionID = SessionID_1.SessionID.get(sdkKey);
|
|
149
149
|
const sdkType = SDKType_1.SDKType._get(sdkKey);
|
|
150
150
|
return JSON.stringify(Object.assign(Object.assign({}, data), { statsigMetadata: Object.assign(Object.assign({}, StatsigMetadata_1.StatsigMetadataProvider.get()), { stableID,
|
|
151
151
|
sessionID,
|
|
@@ -55,12 +55,6 @@ type DataAdapterCommon = {
|
|
|
55
55
|
* @param {StatsigOptionsCommon | null} options The StatsigOptions being used by the Statsig client.
|
|
56
56
|
*/
|
|
57
57
|
readonly attach: (sdkKey: string, options: AnyStatsigOptions | null) => void;
|
|
58
|
-
/**
|
|
59
|
-
* (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
|
|
60
|
-
*
|
|
61
|
-
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
62
|
-
*/
|
|
63
|
-
readonly __primeInMemoryCache: (cache: Record<string, DataAdapterResult>) => void;
|
|
64
58
|
};
|
|
65
59
|
export type EvaluationsDataAdapter = DataAdapterCommon & {
|
|
66
60
|
/**
|
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 = '2.2.0-beta.
|
|
4
|
+
exports.SDK_VERSION = '2.2.0-beta.6';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|