@statsig/js-client 3.12.2 → 3.14.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/README.md +1 -1
- package/build/statsig-js-client+session-replay+web-analytics.min.js +1 -1
- package/build/statsig-js-client+session-replay.min.js +1 -1
- package/build/statsig-js-client+web-analytics.min.js +1 -1
- package/build/statsig-js-client.min.js +1 -1
- package/package.json +2 -2
- package/src/Network.d.ts +1 -0
- package/src/Network.js +6 -2
- package/src/StatsigEvaluationsDataAdapter.d.ts +2 -2
- package/src/StatsigEvaluationsDataAdapter.js +8 -3
- package/src/StatsigOptions.d.ts +6 -0
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
|
-
|
|
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
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DataAdapterAsyncOptions, DataAdapterCore, DataAdapterResult, EvaluationsDataAdapter, StatsigUser, StatsigUserInternal } from '@statsig/client-core';
|
|
1
|
+
import { DataAdapterAsyncOptions, DataAdapterCore, DataAdapterResult, EvaluationsDataAdapter, NetworkCore, StatsigUser, StatsigUserInternal } from '@statsig/client-core';
|
|
2
2
|
import { StatsigOptions } from './StatsigOptions';
|
|
3
3
|
export declare class StatsigEvaluationsDataAdapter extends DataAdapterCore implements EvaluationsDataAdapter {
|
|
4
4
|
private _network;
|
|
5
5
|
protected _options: StatsigOptions | null;
|
|
6
6
|
constructor();
|
|
7
|
-
attach(sdkKey: string, options: StatsigOptions | null): void;
|
|
7
|
+
attach(sdkKey: string, options: StatsigOptions | null, network: NetworkCore | null): void;
|
|
8
8
|
getDataAsync(current: DataAdapterResult | null, user: StatsigUser, options?: DataAdapterAsyncOptions): Promise<DataAdapterResult | null>;
|
|
9
9
|
prefetchData(user: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
|
|
10
10
|
setData(data: string): void;
|
|
@@ -18,9 +18,14 @@ class StatsigEvaluationsDataAdapter extends client_core_1.DataAdapterCore {
|
|
|
18
18
|
this._network = null;
|
|
19
19
|
this._options = null;
|
|
20
20
|
}
|
|
21
|
-
attach(sdkKey, options) {
|
|
22
|
-
super.attach(sdkKey, options);
|
|
23
|
-
|
|
21
|
+
attach(sdkKey, options, network) {
|
|
22
|
+
super.attach(sdkKey, options, network);
|
|
23
|
+
if (network !== null && network instanceof Network_1.default) {
|
|
24
|
+
this._network = network;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this._network = new Network_1.default(options !== null && options !== void 0 ? options : {});
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
getDataAsync(current, user, options) {
|
|
26
31
|
return this._getDataAsyncImpl(current, (0, client_core_1._normalizeUser)(user, this._options), options);
|
package/src/StatsigOptions.d.ts
CHANGED
|
@@ -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
|
/**
|