@statsig/js-client 3.12.0 → 3.12.2

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.
@@ -32,6 +32,7 @@ class EvaluationStore {
32
32
  : null;
33
33
  }
34
34
  setValues(result, user) {
35
+ var _a;
35
36
  if (!result) {
36
37
  return false;
37
38
  }
@@ -51,12 +52,7 @@ class EvaluationStore {
51
52
  if (result.source && values.user) {
52
53
  this._setWarningState(user, values);
53
54
  }
54
- if (values.sdk_flags) {
55
- client_core_1.SDKFlags.setFlags(this._sdkKey, values.sdk_flags);
56
- }
57
- else {
58
- client_core_1.SDKFlags.setFlags(this._sdkKey, {});
59
- }
55
+ client_core_1.SDKFlags.setFlags(this._sdkKey, (_a = values.sdk_flags) !== null && _a !== void 0 ? _a : {});
60
56
  return true;
61
57
  }
62
58
  getWarnings() {
@@ -84,6 +80,10 @@ class EvaluationStore {
84
80
  getSource() {
85
81
  return this._source;
86
82
  }
83
+ getExposureMapping() {
84
+ var _a;
85
+ return (_a = this._values) === null || _a === void 0 ? void 0 : _a.exposures;
86
+ }
87
87
  _extractBootstrapMetadata(source, values) {
88
88
  if (source !== 'Bootstrap') {
89
89
  return null;
package/src/Network.d.ts CHANGED
@@ -3,6 +3,6 @@ import { StatsigOptions } from './StatsigOptions';
3
3
  export default class StatsigNetwork extends NetworkCore {
4
4
  private _initializeUrlConfig;
5
5
  constructor(options: StatsigOptions | null, emitter?: StatsigClientEmitEventFunc);
6
- fetchEvaluations(sdkKey: string, current: string | null, priority?: NetworkPriority, user?: StatsigUser): Promise<string | null>;
6
+ fetchEvaluations(sdkKey: string, current: string | null, priority?: NetworkPriority, user?: StatsigUser, isCacheValidFor204?: boolean): Promise<string | null>;
7
7
  private _fetchEvaluations;
8
8
  }
package/src/Network.js CHANGED
@@ -17,7 +17,7 @@ class StatsigNetwork extends client_core_1.NetworkCore {
17
17
  const config = options === null || options === void 0 ? void 0 : options.networkConfig;
18
18
  this._initializeUrlConfig = new client_core_1.UrlConfiguration(client_core_1.Endpoint._initialize, config === null || config === void 0 ? void 0 : config.initializeUrl, config === null || config === void 0 ? void 0 : config.api, config === null || config === void 0 ? void 0 : config.initializeFallbackUrls);
19
19
  }
20
- fetchEvaluations(sdkKey, current, priority, user) {
20
+ fetchEvaluations(sdkKey, current, priority, user, isCacheValidFor204) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  const cache = current
23
23
  ? (0, client_core_1._typedJsonParse)(current, 'has_updates', 'InitializeResponse')
@@ -29,7 +29,9 @@ class StatsigNetwork extends client_core_1.NetworkCore {
29
29
  full_checksum: null,
30
30
  };
31
31
  if (cache === null || cache === void 0 ? void 0 : cache.has_updates) {
32
- data = Object.assign(Object.assign({}, data), { sinceTime: cache.time, previousDerivedFields: 'derived_fields' in cache ? cache.derived_fields : {}, deltasResponseRequested: true, full_checksum: cache.full_checksum });
32
+ data = Object.assign(Object.assign({}, data), { sinceTime: isCacheValidFor204 ? cache.time : 0, previousDerivedFields: 'derived_fields' in cache && isCacheValidFor204
33
+ ? cache.derived_fields
34
+ : {}, deltasResponseRequested: true, full_checksum: cache.full_checksum });
33
35
  }
34
36
  return this._fetchEvaluations(sdkKey, cache, data, priority);
35
37
  });
@@ -107,7 +107,7 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
107
107
  id_type: string;
108
108
  name: string;
109
109
  rule_id: string;
110
- secondary_exposures: import("@statsig/client-core").SecondaryExposure[];
110
+ secondary_exposures: string[] | import("@statsig/client-core").SecondaryExposure[];
111
111
  value: Record<string, unknown>;
112
112
  version?: string | undefined;
113
113
  group_name?: string | undefined;
@@ -136,7 +136,7 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
136
136
  id_type: string;
137
137
  name: string;
138
138
  rule_id: string;
139
- secondary_exposures: import("@statsig/client-core").SecondaryExposure[];
139
+ secondary_exposures: string[] | import("@statsig/client-core").SecondaryExposure[];
140
140
  value: Record<string, unknown>;
141
141
  version?: string | undefined;
142
142
  group_name?: string | undefined;
@@ -164,7 +164,7 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
164
164
  readonly __evaluation: {
165
165
  name: string;
166
166
  rule_id: string;
167
- secondary_exposures: import("@statsig/client-core").SecondaryExposure[];
167
+ secondary_exposures: string[] | import("@statsig/client-core").SecondaryExposure[];
168
168
  value: Record<string, unknown>;
169
169
  version?: string | undefined;
170
170
  group_name?: string | undefined;
@@ -175,7 +175,7 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
175
175
  passed?: boolean | undefined;
176
176
  allocated_experiment_name: string;
177
177
  explicit_parameters: string[];
178
- undelegated_secondary_exposures?: import("@statsig/client-core").SecondaryExposure[] | undefined;
178
+ undelegated_secondary_exposures?: string[] | import("@statsig/client-core").SecondaryExposure[] | undefined;
179
179
  } | null;
180
180
  readonly get: import("@statsig/client-core").TypedGet;
181
181
  };
@@ -286,7 +286,7 @@ class StatsigClient extends client_core_1.StatsigClientBase {
286
286
  const gate = (0, client_core_1._makeFeatureGate)(name, details, evaluation);
287
287
  const overridden = (_b = (_a = this.overrideAdapter) === null || _a === void 0 ? void 0 : _a.getGateOverride) === null || _b === void 0 ? void 0 : _b.call(_a, gate, this._user, options);
288
288
  const result = overridden !== null && overridden !== void 0 ? overridden : gate;
289
- this._enqueueExposure(name, (0, client_core_1._createGateExposure)(this._user, result), options);
289
+ this._enqueueExposure(name, (0, client_core_1._createGateExposure)(this._user, result, this._store.getExposureMapping()), options);
290
290
  this.$emt({ name: 'gate_evaluation', gate: result });
291
291
  return result;
292
292
  }
@@ -296,17 +296,20 @@ class StatsigClient extends client_core_1.StatsigClientBase {
296
296
  const config = (0, client_core_1._makeDynamicConfig)(name, details, evaluation);
297
297
  const overridden = (_b = (_a = this.overrideAdapter) === null || _a === void 0 ? void 0 : _a.getDynamicConfigOverride) === null || _b === void 0 ? void 0 : _b.call(_a, config, this._user, options);
298
298
  const result = overridden !== null && overridden !== void 0 ? overridden : config;
299
- this._enqueueExposure(name, (0, client_core_1._createConfigExposure)(this._user, result), options);
299
+ this._enqueueExposure(name, (0, client_core_1._createConfigExposure)(this._user, result, this._store.getExposureMapping()), options);
300
300
  this.$emt({ name: 'dynamic_config_evaluation', dynamicConfig: result });
301
301
  return result;
302
302
  }
303
303
  _getExperimentImpl(name, options) {
304
- var _a, _b;
304
+ var _a, _b, _c, _d;
305
305
  const { result: evaluation, details } = this._store.getConfig(name);
306
306
  const experiment = (0, client_core_1._makeExperiment)(name, details, evaluation);
307
- const overridden = (_b = (_a = this.overrideAdapter) === null || _a === void 0 ? void 0 : _a.getExperimentOverride) === null || _b === void 0 ? void 0 : _b.call(_a, experiment, this._user, options);
307
+ if (experiment.__evaluation != null) {
308
+ experiment.__evaluation.secondary_exposures = (0, client_core_1._mapExposures)((_b = (_a = experiment.__evaluation) === null || _a === void 0 ? void 0 : _a.secondary_exposures) !== null && _b !== void 0 ? _b : [], this._store.getExposureMapping());
309
+ }
310
+ const overridden = (_d = (_c = this.overrideAdapter) === null || _c === void 0 ? void 0 : _c.getExperimentOverride) === null || _d === void 0 ? void 0 : _d.call(_c, experiment, this._user, options);
308
311
  const result = overridden !== null && overridden !== void 0 ? overridden : experiment;
309
- this._enqueueExposure(name, (0, client_core_1._createConfigExposure)(this._user, result), options);
312
+ this._enqueueExposure(name, (0, client_core_1._createConfigExposure)(this._user, result, this._store.getExposureMapping()), options);
310
313
  this.$emt({ name: 'experiment_evaluation', experiment: result });
311
314
  return result;
312
315
  }
@@ -322,20 +325,28 @@ class StatsigClient extends client_core_1.StatsigClientBase {
322
325
  if (options === null || options === void 0 ? void 0 : options.disableExposureLog) {
323
326
  return;
324
327
  }
325
- this._enqueueExposure(name, (0, client_core_1._createLayerParameterExposure)(this._user, result, param), options);
328
+ this._enqueueExposure(name, (0, client_core_1._createLayerParameterExposure)(this._user, result, param, this._store.getExposureMapping()), options);
326
329
  });
327
330
  this.$emt({ name: 'layer_evaluation', layer: result });
328
331
  return result;
329
332
  }
330
333
  _getParameterStoreImpl(name, options) {
334
+ var _a, _b;
331
335
  const { result: configuration, details } = this._store.getParamStore(name);
332
336
  this._logger.incrementNonExposureCount(name);
333
- return {
337
+ const paramStore = {
334
338
  name,
335
- details,
339
+ details: details,
336
340
  __configuration: configuration,
337
341
  get: (0, ParamStoreGetterFactory_1._makeParamStoreGetter)(this, configuration, options),
338
342
  };
343
+ const overridden = (_b = (_a = this.overrideAdapter) === null || _a === void 0 ? void 0 : _a.getParamStoreOverride) === null || _b === void 0 ? void 0 : _b.call(_a, paramStore, options);
344
+ if (overridden != null) {
345
+ paramStore.__configuration = overridden.config;
346
+ paramStore.details = overridden.details;
347
+ paramStore.get = (0, ParamStoreGetterFactory_1._makeParamStoreGetter)(this, overridden.config, options);
348
+ }
349
+ return paramStore;
339
350
  }
340
351
  }
341
352
  exports.default = StatsigClient;
@@ -9,7 +9,7 @@ export declare class StatsigEvaluationsDataAdapter extends DataAdapterCore imple
9
9
  prefetchData(user: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
10
10
  setData(data: string): void;
11
11
  setDataLegacy(data: string, user: StatsigUser): void;
12
- protected _fetchFromNetwork(current: string | null, user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<string | null>;
12
+ protected _fetchFromNetwork(current: string | null, user?: StatsigUser, options?: DataAdapterAsyncOptions, isCacheValidFor204?: boolean): Promise<string | null>;
13
13
  protected _getCacheKey(user?: StatsigUserInternal): string;
14
14
  protected _isCachedResultValidFor204(result: DataAdapterResult, user: StatsigUser | undefined): boolean;
15
15
  }
@@ -40,10 +40,10 @@ class StatsigEvaluationsDataAdapter extends client_core_1.DataAdapterCore {
40
40
  setDataLegacy(data, user) {
41
41
  super.setData(data, user);
42
42
  }
43
- _fetchFromNetwork(current, user, options) {
43
+ _fetchFromNetwork(current, user, options, isCacheValidFor204) {
44
44
  var _a;
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- const result = yield ((_a = this._network) === null || _a === void 0 ? void 0 : _a.fetchEvaluations(this._getSdkKey(), current, options === null || options === void 0 ? void 0 : options.priority, user));
46
+ const result = yield ((_a = this._network) === null || _a === void 0 ? void 0 : _a.fetchEvaluations(this._getSdkKey(), current, options === null || options === void 0 ? void 0 : options.priority, user, isCacheValidFor204));
47
47
  return result !== null && result !== void 0 ? result : null;
48
48
  });
49
49
  }