@statsig/client-core 0.0.1-beta.13 → 0.0.1-beta.15
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 +1 -1
- package/src/ErrorBoundary.js +1 -1
- package/src/EventLogger.js +1 -1
- package/src/NetworkCore.js +1 -1
- package/src/StatsigClientBase.d.ts +5 -5
- package/src/StatsigClientBase.js +13 -5
- package/src/StatsigClientEventEmitter.d.ts +38 -33
- package/src/StatsigDataAdapter.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
package/package.json
CHANGED
package/src/ErrorBoundary.js
CHANGED
package/src/EventLogger.js
CHANGED
package/src/NetworkCore.js
CHANGED
|
@@ -85,7 +85,7 @@ class NetworkCore {
|
|
|
85
85
|
contentLength: response === null || response === void 0 ? void 0 : response.headers.get('content-length'),
|
|
86
86
|
});
|
|
87
87
|
if (!retries || retries <= 0) {
|
|
88
|
-
(_a = this._emitter) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
88
|
+
(_a = this._emitter) === null || _a === void 0 ? void 0 : _a.call(this, { name: 'error', error });
|
|
89
89
|
Log_1.Log.error(`A networking error occured during ${method} request to ${url}.`, errorMessage, error);
|
|
90
90
|
return null;
|
|
91
91
|
}
|
|
@@ -4,11 +4,11 @@ import { EvaluationOptionsCommon } from './EvaluationOptions';
|
|
|
4
4
|
import { EventLogger } from './EventLogger';
|
|
5
5
|
import { NetworkCore } from './NetworkCore';
|
|
6
6
|
import { OverrideAdapter } from './OverrideAdapter';
|
|
7
|
-
import { StatsigClientEvent, StatsigClientEventCallback,
|
|
7
|
+
import { StatsigClientEvent, StatsigClientEventCallback, StatsigClientEventEmitterInterface, StatsigClientEventName, StatsigLoadingStatus } from './StatsigClientEventEmitter';
|
|
8
8
|
import { DataAdapterResult, EvaluationsDataAdapter, SpecsDataAdapter } from './StatsigDataAdapter';
|
|
9
9
|
import { StatsigEventInternal } from './StatsigEvent';
|
|
10
10
|
import { StatsigOptionsCommon, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon';
|
|
11
|
-
export type StatsigClientEmitEventFunc = (
|
|
11
|
+
export type StatsigClientEmitEventFunc = (event: StatsigClientEvent) => void;
|
|
12
12
|
export declare abstract class StatsigClientBase<TAdapter extends EvaluationsDataAdapter | SpecsDataAdapter> implements StatsigClientEventEmitterInterface {
|
|
13
13
|
protected readonly _sdkKey: string;
|
|
14
14
|
loadingStatus: StatsigLoadingStatus;
|
|
@@ -20,9 +20,9 @@ export declare abstract class StatsigClientBase<TAdapter extends EvaluationsData
|
|
|
20
20
|
constructor(_sdkKey: string, adapter: TAdapter, network: NetworkCore, options: StatsigOptionsCommon | null);
|
|
21
21
|
updateRuntimeOptions(options: StatsigRuntimeMutableOptions): void;
|
|
22
22
|
flush(): Promise<void>;
|
|
23
|
-
on(event:
|
|
24
|
-
off(event:
|
|
25
|
-
protected _emit(
|
|
23
|
+
on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
24
|
+
off<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
25
|
+
protected _emit(event: StatsigClientEvent): void;
|
|
26
26
|
protected _setStatus(newStatus: StatsigLoadingStatus, values: DataAdapterResult | null): void;
|
|
27
27
|
protected _enqueueExposure(name: string, exposure: StatsigEventInternal, options?: EvaluationOptionsCommon): void;
|
|
28
28
|
}
|
package/src/StatsigClientBase.js
CHANGED
|
@@ -52,16 +52,24 @@ class StatsigClientBase {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
_emit(
|
|
55
|
+
_emit(event) {
|
|
56
56
|
var _a;
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const barrier = (listener) => {
|
|
58
|
+
try {
|
|
59
|
+
listener(event);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
Log_1.Log.error(`An error occurred in a StatsigClientEvent listener. This is not an issue with Statsig.`, event);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (this._listeners[event.name]) {
|
|
66
|
+
this._listeners[event.name].forEach((l) => barrier(l));
|
|
59
67
|
}
|
|
60
|
-
(_a = this._listeners['*']) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
68
|
+
(_a = this._listeners['*']) === null || _a === void 0 ? void 0 : _a.forEach(barrier);
|
|
61
69
|
}
|
|
62
70
|
_setStatus(newStatus, values) {
|
|
63
71
|
this.loadingStatus = newStatus;
|
|
64
|
-
this._emit({
|
|
72
|
+
this._emit({ name: 'values_updated', status: newStatus, values });
|
|
65
73
|
}
|
|
66
74
|
_enqueueExposure(name, exposure, options) {
|
|
67
75
|
if ((options === null || options === void 0 ? void 0 : options.disableExposureLog) === true) {
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import { DataAdapterResult } from './StatsigDataAdapter';
|
|
2
2
|
import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
|
|
3
|
+
import { Flatten } from './UtitlityTypes';
|
|
3
4
|
export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
|
|
5
|
+
type EventNameToEventDataMap = {
|
|
6
|
+
values_updated: {
|
|
7
|
+
status: StatsigLoadingStatus;
|
|
8
|
+
values: DataAdapterResult | null;
|
|
9
|
+
};
|
|
10
|
+
error: {
|
|
11
|
+
error: unknown;
|
|
12
|
+
};
|
|
13
|
+
logs_flushed: {
|
|
14
|
+
events: Record<string, unknown>[];
|
|
15
|
+
};
|
|
16
|
+
gate_evaluation: {
|
|
17
|
+
gate: FeatureGate;
|
|
18
|
+
};
|
|
19
|
+
dynamic_config_evaluation: {
|
|
20
|
+
dynamicConfig: DynamicConfig;
|
|
21
|
+
};
|
|
22
|
+
experiment_evaluation: {
|
|
23
|
+
experiment: Experiment;
|
|
24
|
+
};
|
|
25
|
+
layer_evaluation: {
|
|
26
|
+
layer: Layer;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
4
29
|
/**
|
|
5
|
-
*
|
|
30
|
+
* Type representing various events emitted by a Statsig client.
|
|
6
31
|
*
|
|
7
32
|
* `values_updated` - When the Statsig clients internal values change as the result of an initialize/update operation.
|
|
8
33
|
*
|
|
@@ -18,38 +43,18 @@ export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
|
|
|
18
43
|
*
|
|
19
44
|
* `layer_evaluation` - Fired when any layer is checked from the Statsig client.
|
|
20
45
|
*/
|
|
21
|
-
export type StatsigClientEvent =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
values: DataAdapterResult | null;
|
|
31
|
-
} | {
|
|
32
|
-
event: 'error';
|
|
33
|
-
error: unknown;
|
|
34
|
-
} | {
|
|
35
|
-
event: 'logs_flushed';
|
|
36
|
-
events: Record<string, unknown>[];
|
|
37
|
-
} | {
|
|
38
|
-
event: 'gate_evaluation';
|
|
39
|
-
gate: FeatureGate;
|
|
40
|
-
} | {
|
|
41
|
-
event: 'dynamic_config_evaluation';
|
|
42
|
-
dynamicConfig: DynamicConfig;
|
|
43
|
-
} | {
|
|
44
|
-
event: 'experiment_evaluation';
|
|
45
|
-
experiment: Experiment;
|
|
46
|
-
} | {
|
|
47
|
-
event: 'layer_evaluation';
|
|
48
|
-
layer: Layer;
|
|
49
|
-
});
|
|
50
|
-
export type StatsigClientEventCallback = (data: StatsigClientEventData) => void;
|
|
46
|
+
export type StatsigClientEvent = Flatten<{
|
|
47
|
+
[K in keyof EventNameToEventDataMap]: {
|
|
48
|
+
name: K;
|
|
49
|
+
} & EventNameToEventDataMap[K];
|
|
50
|
+
}[keyof EventNameToEventDataMap]>;
|
|
51
|
+
export type StatsigClientEventName = StatsigClientEvent['name'] | '*';
|
|
52
|
+
export type StatsigClientEventCallback<T extends StatsigClientEventName> = (event: T extends '*' ? StatsigClientEvent : Extract<StatsigClientEvent, {
|
|
53
|
+
name: T;
|
|
54
|
+
}>) => void;
|
|
51
55
|
export interface StatsigClientEventEmitterInterface {
|
|
52
56
|
readonly loadingStatus: StatsigLoadingStatus;
|
|
53
|
-
on(event:
|
|
54
|
-
off(event:
|
|
57
|
+
on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
58
|
+
off<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
55
59
|
}
|
|
60
|
+
export {};
|
|
@@ -35,7 +35,7 @@ type DataAdapterCommon = {
|
|
|
35
35
|
};
|
|
36
36
|
export type EvaluationsDataAdapter = DataAdapterCommon & {
|
|
37
37
|
/**
|
|
38
|
-
* Synchronously
|
|
38
|
+
* Synchronously get evaluation data for the given user. Called during initializeSync and/or updateUserSync.
|
|
39
39
|
*
|
|
40
40
|
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
41
41
|
* @param {StatsigUser} user The StatsigUser to get data for.
|
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 = void 0;
|
|
4
|
-
const SDK_VERSION = '0.0.1-beta.
|
|
4
|
+
const SDK_VERSION = '0.0.1-beta.15';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|