@statsig/js-client 3.13.0 → 3.14.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/src/Network.js CHANGED
@@ -15,21 +15,25 @@ class StatsigNetwork extends client_core_1.NetworkCore {
15
15
  constructor(options, emitter) {
16
16
  super(options, emitter);
17
17
  const config = options === null || options === void 0 ? void 0 : options.networkConfig;
18
+ this._option = options;
18
19
  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
20
  }
20
21
  fetchEvaluations(sdkKey, current, priority, user, isCacheValidFor204) {
22
+ var _a, _b, _c, _d, _e, _f;
21
23
  return __awaiter(this, void 0, void 0, function* () {
22
24
  const cache = current
23
25
  ? (0, client_core_1._typedJsonParse)(current, 'has_updates', 'InitializeResponse')
24
26
  : null;
25
27
  let data = {
26
28
  user,
27
- hash: 'djb2',
29
+ hash: (_c = (_b = (_a = this._option) === null || _a === void 0 ? void 0 : _a.networkConfig) === null || _b === void 0 ? void 0 : _b.initializeHashAlgorithm) !== null && _c !== void 0 ? _c : 'djb2',
28
30
  deltasResponseRequested: false,
29
31
  full_checksum: null,
30
32
  };
31
33
  if (cache === null || cache === void 0 ? void 0 : cache.has_updates) {
32
- data = Object.assign(Object.assign({}, data), { sinceTime: isCacheValidFor204 ? cache.time : 0, previousDerivedFields: 'derived_fields' in cache && isCacheValidFor204
34
+ const hasHashChanged = (cache === null || cache === void 0 ? void 0 : cache.hash_used) !==
35
+ ((_f = (_e = (_d = this._option) === null || _d === void 0 ? void 0 : _d.networkConfig) === null || _e === void 0 ? void 0 : _e.initializeHashAlgorithm) !== null && _f !== void 0 ? _f : 'djb2');
36
+ data = Object.assign(Object.assign({}, data), { sinceTime: isCacheValidFor204 && !hasHashChanged ? cache.time : 0, previousDerivedFields: 'derived_fields' in cache && isCacheValidFor204
33
37
  ? cache.derived_fields
34
38
  : {}, deltasResponseRequested: true, full_checksum: cache.full_checksum });
35
39
  }
@@ -11,6 +11,12 @@ type UrlOverrideOptions = Flatten<NetworkConfigCommon & {
11
11
  * A list of URLs to try if the primary initializeUrl fails.
12
12
  */
13
13
  initializeFallbackUrls?: string[];
14
+ /**
15
+ * The hashing algorithm applied to the initialization response.
16
+ *
17
+ * default: `djb2`
18
+ */
19
+ initializeHashAlgorithm?: 'djb2' | 'sha256' | 'none';
14
20
  }>;
15
21
  export type StatsigOptions = Flatten<StatsigOptionsCommon<UrlOverrideOptions> & {
16
22
  /**