@statsig/client-core 3.18.0 → 3.18.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/client-core",
3
- "version": "3.18.0",
3
+ "version": "3.18.1",
4
4
  "license": "ISC",
5
5
  "homepage": "https://github.com/statsig-io/js-client-monorepo",
6
6
  "repository": {
@@ -13,6 +13,7 @@ export declare abstract class DataAdapterCore {
13
13
  attach(sdkKey: string, options: AnyStatsigOptions | null, _network: NetworkCore | null): void;
14
14
  getDataSync(user?: StatsigUser | undefined): DataAdapterResult | null;
15
15
  setData(data: string, user?: StatsigUser): void;
16
+ protected _getIsCacheValueValid(current: DataAdapterResult): boolean;
16
17
  protected _getDataAsyncImpl(current: DataAdapterResult | null, user?: StatsigUserInternal, options?: DataAdapterAsyncOptions): Promise<DataAdapterResult | null>;
17
18
  protected _prefetchDataImpl(user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
18
19
  protected abstract _fetchFromNetwork(current: string | null, user?: StatsigUser, options?: DataAdapterAsyncOptions, isCacheValidFor204?: boolean): Promise<string | null>;
@@ -33,11 +33,11 @@ class DataAdapterCore {
33
33
  const normalized = user && (0, StatsigUser_1._normalizeUser)(user, this._options);
34
34
  const cacheKey = this._getCacheKey(normalized);
35
35
  const inMem = this._inMemoryCache.get(cacheKey, normalized);
36
- if (inMem) {
36
+ if (inMem && this._getIsCacheValueValid(inMem)) {
37
37
  return inMem;
38
38
  }
39
39
  const cache = this._loadFromCache(cacheKey);
40
- if (cache) {
40
+ if (cache && this._getIsCacheValueValid(cache)) {
41
41
  this._inMemoryCache.add(cacheKey, cache);
42
42
  return this._inMemoryCache.get(cacheKey, normalized);
43
43
  }
@@ -48,6 +48,10 @@ class DataAdapterCore {
48
48
  const cacheKey = this._getCacheKey(normalized);
49
49
  this._inMemoryCache.add(cacheKey, _makeDataAdapterResult('Bootstrap', data, null, normalized));
50
50
  }
51
+ _getIsCacheValueValid(current) {
52
+ return (current.stableID == null ||
53
+ current.stableID === StableID_1.StableID.get(this._getSdkKey()));
54
+ }
51
55
  _getDataAsyncImpl(current, user, options) {
52
56
  return __awaiter(this, void 0, void 0, function* () {
53
57
  if (!StorageProvider_1.Storage.isReady()) {
@@ -75,8 +79,8 @@ class DataAdapterCore {
75
79
  });
76
80
  }
77
81
  _fetchAndPrepFromNetwork(cachedResult, user, options) {
78
- var _a;
79
82
  return __awaiter(this, void 0, void 0, function* () {
83
+ var _a;
80
84
  const cachedData = (_a = cachedResult === null || cachedResult === void 0 ? void 0 : cachedResult.data) !== null && _a !== void 0 ? _a : null;
81
85
  const isCacheValidFor204 = cachedResult != null &&
82
86
  this._isCachedResultValidFor204(cachedResult, user);
@@ -36,11 +36,11 @@ export declare const Diagnostics: {
36
36
  _formatError(e: unknown): Record<string, unknown> | undefined;
37
37
  _getDiagnosticsData(res: Response | null, attempt: number, body: string, e?: unknown): {
38
38
  success: boolean;
39
- isDelta?: boolean | undefined;
40
- sdkRegion?: string | null | undefined;
41
- statusCode?: number | undefined;
39
+ isDelta?: boolean;
40
+ sdkRegion?: string | null;
41
+ statusCode?: number;
42
42
  attempt: number;
43
- error?: Record<string, unknown> | undefined;
43
+ error?: Record<string, unknown>;
44
44
  };
45
45
  _enqueueDiagnosticsEvent(user: StatsigUserInternal | null, logger: EventLogger, sdk: string, options: StatsigOptionsCommon<NetworkConfigCommon> | null): number;
46
46
  };
@@ -17,6 +17,14 @@ export type ExperimentEvaluationOptions = EvaluationOptionsCommon & {
17
17
  */
18
18
  userPersistedValues?: unknown;
19
19
  };
20
- export type LayerEvaluationOptions = EvaluationOptionsCommon & {};
20
+ export type LayerEvaluationOptions = EvaluationOptionsCommon & {
21
+ /**
22
+ * Provide a map of values to be used across checks
23
+ *
24
+ * @requires {@link @statsig/js-user-persisted-storage}
25
+ * @see {@link https://docs.statsig.com/client/concepts/persistent_assignment#example-usage}
26
+ */
27
+ userPersistedValues?: unknown;
28
+ };
21
29
  export type ParameterStoreEvaluationOptions = EvaluationOptionsCommon & {};
22
30
  export type AnyEvaluationOptions = FeatureGateEvaluationOptions | DynamicConfigEvaluationOptions | ExperimentEvaluationOptions | LayerEvaluationOptions | ParameterStoreEvaluationOptions;
@@ -86,6 +86,10 @@ class EventLogger {
86
86
  this._nonExposedChecks[name] = current + 1;
87
87
  }
88
88
  reset() {
89
+ // attempt to flush any remaining events
90
+ this.flush().catch(() => {
91
+ // noop
92
+ });
89
93
  this._lastExposureTimeMap = {};
90
94
  }
91
95
  start() {
@@ -177,8 +181,8 @@ class EventLogger {
177
181
  return true;
178
182
  }
179
183
  _sendEvents(events) {
180
- var _a, _b;
181
184
  return __awaiter(this, void 0, void 0, function* () {
185
+ var _a, _b;
182
186
  if (this._loggingEnabled === 'disabled') {
183
187
  this._saveFailedLogsToStorage(events);
184
188
  return false;
@@ -215,8 +219,8 @@ class EventLogger {
215
219
  });
216
220
  }
217
221
  _sendEventsViaPost(events) {
218
- var _a;
219
222
  return __awaiter(this, void 0, void 0, function* () {
223
+ var _a;
220
224
  const result = yield this._network.post(this._getRequestData(events));
221
225
  const code = (_a = result === null || result === void 0 ? void 0 : result.code) !== null && _a !== void 0 ? _a : -1;
222
226
  return { success: code >= 200 && code < 300 };
@@ -93,8 +93,8 @@ class NetworkCore {
93
93
  return this._sendRequest(argsInternal);
94
94
  }
95
95
  _sendRequest(args) {
96
- var _a, _b, _c, _d;
97
96
  return __awaiter(this, void 0, void 0, function* () {
97
+ var _a, _b, _c, _d;
98
98
  if (!_ensureValidSdkKey(args)) {
99
99
  return null;
100
100
  }
@@ -239,8 +239,8 @@ class NetworkCore {
239
239
  }
240
240
  }
241
241
  _tryToCompressBody(args) {
242
- var _a;
243
242
  return __awaiter(this, void 0, void 0, function* () {
243
+ var _a;
244
244
  const body = args.body;
245
245
  if (typeof body !== 'string' || !_allowCompression(args, this._options)) {
246
246
  return;
@@ -61,8 +61,8 @@ class NetworkFallbackResolver {
61
61
  return null;
62
62
  }
63
63
  tryFetchUpdatedFallbackInfo(sdkKey, urlConfig, errorMessage, timedOut) {
64
- var _a, _b;
65
64
  return __awaiter(this, void 0, void 0, function* () {
65
+ var _a, _b;
66
66
  try {
67
67
  if (!_isDomainFailure(errorMessage, timedOut)) {
68
68
  return false;
@@ -108,8 +108,8 @@ class NetworkFallbackResolver {
108
108
  _tryWriteFallbackInfoToCache(sdkKey, this._fallbackInfo);
109
109
  }
110
110
  _tryFetchFallbackUrlsFromNetwork(urlConfig) {
111
- var _a;
112
111
  return __awaiter(this, void 0, void 0, function* () {
112
+ var _a;
113
113
  const cooldown = this._dnsQueryCooldowns[urlConfig.endpoint];
114
114
  if (cooldown && Date.now() < cooldown) {
115
115
  return null;
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "3.18.0";
1
+ export declare const SDK_VERSION = "3.18.1";
2
2
  export type StatsigMetadata = {
3
3
  readonly [key: string]: string | undefined | null;
4
4
  readonly appVersion?: string;
@@ -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 = '3.18.0';
4
+ exports.SDK_VERSION = '3.18.1';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients