@oai-statsig/statsig-node-core 0.33.0-rc.1 → 0.34.0-beta.20261001.1828
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/error_boundary.js +12 -0
- package/index.d.ts +9 -2
- package/index.js +27 -3
- package/package.json +13 -10
- package/statsig-generated.d.ts +8 -0
- package/statsig-generated.js +53 -52
- package/statsig_types.d.ts +8 -0
- package/statsig_types.js +15 -1
- package/typed_config.d.ts +31 -0
- package/typed_config.js +236 -0
- package/typed_config_schema.d.ts +15 -0
- package/typed_config_schema_esm.d.mts +10 -0
package/error_boundary.js
CHANGED
|
@@ -6,6 +6,10 @@ class ErrorBoundary {
|
|
|
6
6
|
try {
|
|
7
7
|
const obj = instance;
|
|
8
8
|
_getAllInstanceMethodNames(obj).forEach((name) => {
|
|
9
|
+
// Typed APIs deliberately expose their argument/unavailable/conversion
|
|
10
|
+
// errors. Logging the caught exception could disclose protobuf payloads.
|
|
11
|
+
if (TYPED_METHODS.has(name))
|
|
12
|
+
return;
|
|
9
13
|
const original = obj[name];
|
|
10
14
|
if ('$EB' in original) {
|
|
11
15
|
return;
|
|
@@ -40,6 +44,14 @@ class ErrorBoundary {
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
exports.ErrorBoundary = ErrorBoundary;
|
|
47
|
+
const TYPED_METHODS = new Set([
|
|
48
|
+
'getTypedConfig',
|
|
49
|
+
'registerTypedConfigCallback',
|
|
50
|
+
'__INTERNAL_getTypedConfig',
|
|
51
|
+
'__INTERNAL_typedConfigContext',
|
|
52
|
+
'__INTERNAL_startTypedConfigUpdates',
|
|
53
|
+
'__INTERNAL_closeTypedConfigUpdates',
|
|
54
|
+
]);
|
|
43
55
|
function _getAllInstanceMethodNames(instance) {
|
|
44
56
|
const names = new Set();
|
|
45
57
|
let proto = Object.getPrototypeOf(instance);
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { Message } from '@bufbuild/protobuf';
|
|
2
|
+
import type { TypedConfigSchema } from './typed_config_schema';
|
|
1
3
|
import { DynamicConfigEvaluationOptions, ExperimentEvaluationOptions, FeatureGateEvaluationOptions, LayerEvaluationOptions, SdkEvent, StatsigNapiInternal, StatsigOptions, StatsigResult, StatsigUser } from './statsig-generated';
|
|
2
|
-
import { DynamicConfig, Experiment, FeatureGate, Layer } from './statsig_types';
|
|
4
|
+
import { DynamicConfig, Experiment, FeatureGate, Layer, TypedDynamicConfig } from './statsig_types';
|
|
3
5
|
export * from './statsig-generated';
|
|
4
6
|
export * from './statsig_types';
|
|
5
|
-
export
|
|
7
|
+
export { TypedConfigUnavailableError, TypedConfigConversionError } from './typed_config';
|
|
8
|
+
export declare const SDK_VERSION = "0.34.0-beta.20261001.1828";
|
|
6
9
|
export declare class Statsig extends StatsigNapiInternal {
|
|
7
10
|
private static _sharedInstance;
|
|
11
|
+
private _typedConfigs?;
|
|
12
|
+
private _typedClosed;
|
|
8
13
|
static shared(): Statsig;
|
|
9
14
|
static hasShared(): boolean;
|
|
10
15
|
static newShared(sdkKey: string, options?: StatsigOptions): Statsig;
|
|
@@ -15,6 +20,8 @@ export declare class Statsig extends StatsigNapiInternal {
|
|
|
15
20
|
subscribe(eventName: SdkEvent, callback: (event: any) => void): string;
|
|
16
21
|
getFeatureGate(user: StatsigUser, gateName: string, options?: FeatureGateEvaluationOptions): FeatureGate;
|
|
17
22
|
getDynamicConfig(user: StatsigUser, configName: string, options?: DynamicConfigEvaluationOptions): DynamicConfig;
|
|
23
|
+
getTypedConfig<T extends Message>(user: StatsigUser, configName: string, schema: TypedConfigSchema<T>, options?: DynamicConfigEvaluationOptions): TypedDynamicConfig<T>;
|
|
24
|
+
registerTypedConfigCallback<T extends Message>(user: StatsigUser, configName: string, schema: TypedConfigSchema<T>, callback: (result: TypedDynamicConfig<T>) => void | Promise<void>): void;
|
|
18
25
|
getExperiment(user: StatsigUser, experimentName: string, options?: ExperimentEvaluationOptions): Experiment;
|
|
19
26
|
getExperimentByGroupName(experimentName: string, groupName: string): Experiment;
|
|
20
27
|
getLayer(user: StatsigUser, layerName: string, options?: LayerEvaluationOptions): Layer;
|
package/index.js
CHANGED
|
@@ -23,15 +23,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Statsig = exports.SDK_VERSION = void 0;
|
|
26
|
+
exports.Statsig = exports.SDK_VERSION = exports.TypedConfigConversionError = exports.TypedConfigUnavailableError = void 0;
|
|
27
27
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
28
28
|
const console_capture_1 = require("./console_capture");
|
|
29
29
|
const error_boundary_1 = require("./error_boundary");
|
|
30
30
|
const statsig_generated_1 = require("./statsig-generated");
|
|
31
31
|
const statsig_types_1 = require("./statsig_types");
|
|
32
|
+
const typed_config_1 = require("./typed_config");
|
|
32
33
|
__exportStar(require("./statsig-generated"), exports);
|
|
33
34
|
__exportStar(require("./statsig_types"), exports);
|
|
34
|
-
|
|
35
|
+
var typed_config_2 = require("./typed_config");
|
|
36
|
+
Object.defineProperty(exports, "TypedConfigUnavailableError", { enumerable: true, get: function () { return typed_config_2.TypedConfigUnavailableError; } });
|
|
37
|
+
Object.defineProperty(exports, "TypedConfigConversionError", { enumerable: true, get: function () { return typed_config_2.TypedConfigConversionError; } });
|
|
38
|
+
exports.SDK_VERSION = '0.34.0-beta.20261001.1828';
|
|
35
39
|
const inspectSym = Symbol.for('nodejs.util.inspect.custom');
|
|
36
40
|
// @ts-expect-error - prototype assignment
|
|
37
41
|
statsig_generated_1.StatsigUser.prototype[inspectSym] = function () {
|
|
@@ -81,6 +85,7 @@ class Statsig extends statsig_generated_1.StatsigNapiInternal {
|
|
|
81
85
|
constructor(sdkKey, options) {
|
|
82
86
|
var _a;
|
|
83
87
|
super(sdkKey, options);
|
|
88
|
+
this._typedClosed = false;
|
|
84
89
|
error_boundary_1.ErrorBoundary.wrap(this);
|
|
85
90
|
if ((_a = options === null || options === void 0 ? void 0 : options.consoleCaptureOptions) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
86
91
|
(0, console_capture_1.startStatsigConsoleCapture)(sdkKey, options.consoleCaptureOptions);
|
|
@@ -94,8 +99,13 @@ class Statsig extends statsig_generated_1.StatsigNapiInternal {
|
|
|
94
99
|
shutdown: { get: () => super.shutdown }
|
|
95
100
|
});
|
|
96
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a;
|
|
103
|
+
this._typedClosed = true;
|
|
104
|
+
const typedFinished = (_a = this._typedConfigs) === null || _a === void 0 ? void 0 : _a.close();
|
|
97
105
|
(0, console_capture_1.stopStatsigConsoleCapture)();
|
|
98
|
-
|
|
106
|
+
const nativeFinished = _super.shutdown.call(this, timeout_ms);
|
|
107
|
+
yield typedFinished;
|
|
108
|
+
return nativeFinished;
|
|
99
109
|
});
|
|
100
110
|
}
|
|
101
111
|
subscribe(eventName, callback) {
|
|
@@ -116,6 +126,20 @@ class Statsig extends statsig_generated_1.StatsigNapiInternal {
|
|
|
116
126
|
const raw = this.__INTERNAL_getDynamicConfig(user, configName, options);
|
|
117
127
|
return new statsig_types_1.DynamicConfig(configName, raw);
|
|
118
128
|
}
|
|
129
|
+
getTypedConfig(user, configName, schema, options) {
|
|
130
|
+
var _a;
|
|
131
|
+
if (this._typedClosed)
|
|
132
|
+
throw new typed_config_1.TypedConfigUnavailableError();
|
|
133
|
+
(_a = this._typedConfigs) !== null && _a !== void 0 ? _a : (this._typedConfigs = new typed_config_1.TypedConfigs(this));
|
|
134
|
+
return this._typedConfigs.get(user, configName, schema, options);
|
|
135
|
+
}
|
|
136
|
+
registerTypedConfigCallback(user, configName, schema, callback) {
|
|
137
|
+
var _a;
|
|
138
|
+
if (this._typedClosed)
|
|
139
|
+
throw new typed_config_1.TypedConfigUnavailableError();
|
|
140
|
+
(_a = this._typedConfigs) !== null && _a !== void 0 ? _a : (this._typedConfigs = new typed_config_1.TypedConfigs(this));
|
|
141
|
+
this._typedConfigs.register(user, configName, schema, callback);
|
|
142
|
+
}
|
|
119
143
|
getExperiment(user, experimentName, options) {
|
|
120
144
|
const raw = this.__INTERNAL_getExperiment(user, experimentName, options);
|
|
121
145
|
return new statsig_types_1.Experiment(experimentName, raw);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oai-statsig/statsig-node-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0-beta.20261001.1828",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "jest --colors"
|
|
6
|
+
"test": "jest --colors",
|
|
7
|
+
"generate:typed-fixture": "protoc -I src/__tests__/fixtures --es_out=src/__tests__/fixtures --es_opt=target=ts,import_extension=js src/__tests__/fixtures/typed_config.proto"
|
|
7
8
|
},
|
|
8
9
|
"keywords": [],
|
|
9
10
|
"author": "",
|
|
@@ -11,12 +12,14 @@
|
|
|
11
12
|
"description": "",
|
|
12
13
|
"repository": "https://github.com/openai/statsig-priv-server-core.git",
|
|
13
14
|
"dependencies": {
|
|
15
|
+
"@bufbuild/protobuf": "2.6.1",
|
|
14
16
|
"@octokit/core": "^6.1.6",
|
|
15
17
|
"https-proxy-agent": "^7.0.6",
|
|
16
18
|
"node-fetch": "2.7.0"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
21
|
"@babel/helpers": "7.29.7",
|
|
22
|
+
"@bufbuild/protoc-gen-es": "2.6.1",
|
|
20
23
|
"@napi-rs/cli": "3.4.1",
|
|
21
24
|
"@octokit/endpoint": "10.1.4",
|
|
22
25
|
"@octokit/plugin-paginate-rest": "11.6.0",
|
|
@@ -60,13 +63,13 @@
|
|
|
60
63
|
}
|
|
61
64
|
},
|
|
62
65
|
"optionalDependencies": {
|
|
63
|
-
"@oai-statsig/statsig-node-core-darwin-arm64": "0.
|
|
64
|
-
"@oai-statsig/statsig-node-core-darwin-x64": "0.
|
|
65
|
-
"@oai-statsig/statsig-node-core-linux-arm64-gnu": "0.
|
|
66
|
-
"@oai-statsig/statsig-node-core-linux-arm64-musl": "0.
|
|
67
|
-
"@oai-statsig/statsig-node-core-linux-x64-gnu": "0.
|
|
68
|
-
"@oai-statsig/statsig-node-core-linux-x64-musl": "0.
|
|
69
|
-
"@oai-statsig/statsig-node-core-win32-ia32-msvc": "0.
|
|
70
|
-
"@oai-statsig/statsig-node-core-win32-x64-msvc": "0.
|
|
66
|
+
"@oai-statsig/statsig-node-core-darwin-arm64": "0.34.0-beta.20261001.1828",
|
|
67
|
+
"@oai-statsig/statsig-node-core-darwin-x64": "0.34.0-beta.20261001.1828",
|
|
68
|
+
"@oai-statsig/statsig-node-core-linux-arm64-gnu": "0.34.0-beta.20261001.1828",
|
|
69
|
+
"@oai-statsig/statsig-node-core-linux-arm64-musl": "0.34.0-beta.20261001.1828",
|
|
70
|
+
"@oai-statsig/statsig-node-core-linux-x64-gnu": "0.34.0-beta.20261001.1828",
|
|
71
|
+
"@oai-statsig/statsig-node-core-linux-x64-musl": "0.34.0-beta.20261001.1828",
|
|
72
|
+
"@oai-statsig/statsig-node-core-win32-ia32-msvc": "0.34.0-beta.20261001.1828",
|
|
73
|
+
"@oai-statsig/statsig-node-core-win32-x64-msvc": "0.34.0-beta.20261001.1828"
|
|
71
74
|
}
|
|
72
75
|
}
|
package/statsig-generated.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ export declare class StatsigNapiInternal {
|
|
|
65
65
|
getExperimentList(): Array<string>
|
|
66
66
|
getParameterStoreList(): Array<string>
|
|
67
67
|
getParsedUserAgentValueForUser(user: StatsigUser): Record<string, string | undefined | null> | null
|
|
68
|
+
__INTERNAL_getTypedConfig(user: StatsigUser, name: string, options?: DynamicConfigEvaluationOptions | undefined | null): Record<string, unknown>
|
|
69
|
+
__INTERNAL_typedConfigContext(user: StatsigUser, name: string): TypedConfigContext
|
|
70
|
+
__INTERNAL_startTypedConfigUpdates(callback: () => void): void
|
|
71
|
+
__INTERNAL_closeTypedConfigUpdates(): void
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
export declare class StatsigUser {
|
|
@@ -96,6 +100,10 @@ export declare class StatsigUser {
|
|
|
96
100
|
toJSON(): any
|
|
97
101
|
}
|
|
98
102
|
|
|
103
|
+
export declare class TypedConfigContext {
|
|
104
|
+
getEvaluation(): Record<string, unknown>
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
export declare function __internal__testDataStore(store: DataStore, path: string, value: string): Promise<[DataStoreResponse | undefined | null, boolean]>
|
|
100
108
|
|
|
101
109
|
export declare function __internal__testObservabilityClient(client: ObservabilityClient, action: string, metricName: string, value: number, tags?: Record<string, string> | undefined | null): Promise<void>
|
package/statsig-generated.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('@oai-statsig/statsig-node-core-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '0.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
80
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('@oai-statsig/statsig-node-core-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '0.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
96
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('@oai-statsig/statsig-node-core-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '0.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
117
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('@oai-statsig/statsig-node-core-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '0.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
133
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('@oai-statsig/statsig-node-core-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
150
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('@oai-statsig/statsig-node-core-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '0.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
166
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('@oai-statsig/statsig-node-core-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '0.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
185
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('@oai-statsig/statsig-node-core-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '0.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
201
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('@oai-statsig/statsig-node-core-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '0.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
217
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('@oai-statsig/statsig-node-core-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
237
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('@oai-statsig/statsig-node-core-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '0.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
253
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('@oai-statsig/statsig-node-core-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '0.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
274
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('@oai-statsig/statsig-node-core-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '0.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
290
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('@oai-statsig/statsig-node-core-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '0.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
308
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('@oai-statsig/statsig-node-core-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '0.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
324
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('@oai-statsig/statsig-node-core-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '0.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
342
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('@oai-statsig/statsig-node-core-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '0.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
358
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('@oai-statsig/statsig-node-core-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '0.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
376
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('@oai-statsig/statsig-node-core-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '0.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
392
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('@oai-statsig/statsig-node-core-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
410
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('@oai-statsig/statsig-node-core-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '0.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
426
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('@oai-statsig/statsig-node-core-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
443
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('@oai-statsig/statsig-node-core-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
459
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('@oai-statsig/statsig-node-core-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
479
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('@oai-statsig/statsig-node-core-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
495
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('@oai-statsig/statsig-node-core-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('@oai-statsig/statsig-node-core-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '0.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
511
|
+
if (bindingPackageVersion !== '0.34.0-beta.20261001.1828' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.34.0-beta.20261001.1828 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -577,6 +577,7 @@ module.exports.LayerParamExposureData = nativeBinding.LayerParamExposureData
|
|
|
577
577
|
module.exports.ParameterStore = nativeBinding.ParameterStore
|
|
578
578
|
module.exports.StatsigNapiInternal = nativeBinding.StatsigNapiInternal
|
|
579
579
|
module.exports.StatsigUser = nativeBinding.StatsigUser
|
|
580
|
+
module.exports.TypedConfigContext = nativeBinding.TypedConfigContext
|
|
580
581
|
module.exports.__internal__testDataStore = nativeBinding.__internal__testDataStore
|
|
581
582
|
module.exports.__internal__testObservabilityClient = nativeBinding.__internal__testObservabilityClient
|
|
582
583
|
module.exports.__internal__testOutputLogger = nativeBinding.__internal__testOutputLogger
|
package/statsig_types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EvaluationDetails, SecondaryExposure } from './statsig-generated';
|
|
2
|
+
import type { Message } from '@bufbuild/protobuf';
|
|
2
3
|
export type TypedGet = <T = unknown>(key: string, defaultValue: T, typeGuard?: ((value: unknown) => value is T | null) | null) => T;
|
|
3
4
|
export type UnknownGet = (key: string, fallback?: boolean | number | string | object | Array<any> | null) => unknown | null;
|
|
4
5
|
type RawEvaluation = Record<string, unknown> | string | null;
|
|
@@ -24,6 +25,13 @@ export declare class DynamicConfig extends BaseEvaluation {
|
|
|
24
25
|
readonly getValue: UnknownGet;
|
|
25
26
|
constructor(name: string, raw: RawEvaluation);
|
|
26
27
|
}
|
|
28
|
+
/** A fresh protobuf message and metadata from the same native evaluation. */
|
|
29
|
+
export declare class TypedDynamicConfig<T extends Message> extends BaseEvaluation {
|
|
30
|
+
readonly value: T;
|
|
31
|
+
constructor(name: string, raw: Record<string, unknown>, value: T);
|
|
32
|
+
getName(): string;
|
|
33
|
+
getValue(): T;
|
|
34
|
+
}
|
|
27
35
|
export declare class Experiment extends BaseEvaluation {
|
|
28
36
|
readonly groupName: string | null;
|
|
29
37
|
readonly value: Record<string, unknown>;
|
package/statsig_types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Layer = exports.Experiment = exports.DynamicConfig = exports.FeatureGate = void 0;
|
|
3
|
+
exports.Layer = exports.Experiment = exports.TypedDynamicConfig = exports.DynamicConfig = exports.FeatureGate = void 0;
|
|
4
4
|
function _getTypeOf(x) {
|
|
5
5
|
return Array.isArray(x) ? 'array' : x === null ? 'null' : typeof x;
|
|
6
6
|
}
|
|
@@ -48,6 +48,20 @@ class DynamicConfig extends BaseEvaluation {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
exports.DynamicConfig = DynamicConfig;
|
|
51
|
+
/** A fresh protobuf message and metadata from the same native evaluation. */
|
|
52
|
+
class TypedDynamicConfig extends BaseEvaluation {
|
|
53
|
+
constructor(name, raw, value) {
|
|
54
|
+
super(name, raw);
|
|
55
|
+
this.value = value;
|
|
56
|
+
}
|
|
57
|
+
getName() {
|
|
58
|
+
return this.name;
|
|
59
|
+
}
|
|
60
|
+
getValue() {
|
|
61
|
+
return this.value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.TypedDynamicConfig = TypedDynamicConfig;
|
|
51
65
|
class Experiment extends BaseEvaluation {
|
|
52
66
|
constructor(name, raw) {
|
|
53
67
|
var _a, _b;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Message } from '@bufbuild/protobuf';
|
|
2
|
+
import type { TypedConfigSchema } from './typed_config_schema';
|
|
3
|
+
import { DynamicConfigEvaluationOptions, StatsigNapiInternal, StatsigUser } from './statsig-generated';
|
|
4
|
+
import { TypedDynamicConfig } from './statsig_types';
|
|
5
|
+
export declare class TypedConfigUnavailableError extends Error {
|
|
6
|
+
constructor(message?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class TypedConfigConversionError extends Error {
|
|
9
|
+
readonly cause: unknown;
|
|
10
|
+
constructor(cause: unknown);
|
|
11
|
+
}
|
|
12
|
+
/** Internal coordinator; ordinary reads retain no context, observer, or result. */
|
|
13
|
+
export declare class TypedConfigs {
|
|
14
|
+
private readonly sdk;
|
|
15
|
+
private closed;
|
|
16
|
+
private started;
|
|
17
|
+
private baselines;
|
|
18
|
+
private pending;
|
|
19
|
+
private worker?;
|
|
20
|
+
private observers;
|
|
21
|
+
constructor(sdk: StatsigNapiInternal);
|
|
22
|
+
get<T extends Message>(user: StatsigUser, name: string, schema: TypedConfigSchema<T>, options?: DynamicConfigEvaluationOptions): TypedDynamicConfig<T>;
|
|
23
|
+
register<T extends Message>(user: StatsigUser, name: string, schema: TypedConfigSchema<T>, callback: (result: TypedDynamicConfig<T>) => void | Promise<void>): void;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
private ensureOpen;
|
|
26
|
+
private ensureUsable;
|
|
27
|
+
private convert;
|
|
28
|
+
private notify;
|
|
29
|
+
private drain;
|
|
30
|
+
private run;
|
|
31
|
+
}
|
package/typed_config.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TypedConfigs = exports.TypedConfigConversionError = exports.TypedConfigUnavailableError = void 0;
|
|
13
|
+
const statsig_generated_1 = require("./statsig-generated");
|
|
14
|
+
const statsig_types_1 = require("./statsig_types");
|
|
15
|
+
class TypedConfigUnavailableError extends Error {
|
|
16
|
+
constructor(message = 'Typed config has no usable native value or the SDK is closed') {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'TypedConfigUnavailableError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TypedConfigUnavailableError = TypedConfigUnavailableError;
|
|
22
|
+
class TypedConfigConversionError extends Error {
|
|
23
|
+
constructor(cause) {
|
|
24
|
+
super('Failed to convert typed config to the requested protobuf message');
|
|
25
|
+
this.name = 'TypedConfigConversionError';
|
|
26
|
+
this.cause = cause;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.TypedConfigConversionError = TypedConfigConversionError;
|
|
30
|
+
let protobuf;
|
|
31
|
+
let callbackScope;
|
|
32
|
+
function runtime() {
|
|
33
|
+
return protobuf !== null && protobuf !== void 0 ? protobuf : (protobuf = require('@bufbuild/protobuf'));
|
|
34
|
+
}
|
|
35
|
+
function validateArguments(user, name, options) {
|
|
36
|
+
if (!(user instanceof statsig_generated_1.StatsigUser) || typeof name !== 'string' ||
|
|
37
|
+
name.length === 0 || name.includes('\0')) {
|
|
38
|
+
throw new TypeError('Typed configs require a StatsigUser and a nonempty config name without NUL characters');
|
|
39
|
+
}
|
|
40
|
+
if (options !== undefined && (options === null || typeof options !== 'object' || Array.isArray(options) ||
|
|
41
|
+
(options.disableExposureLogging !== undefined &&
|
|
42
|
+
typeof options.disableExposureLogging !== 'boolean'))) {
|
|
43
|
+
throw new TypeError('options must be DynamicConfigEvaluationOptions');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function errorKind(error) {
|
|
47
|
+
if (error instanceof TypedConfigUnavailableError)
|
|
48
|
+
return 'TypedConfigUnavailableError';
|
|
49
|
+
if (error instanceof TypedConfigConversionError)
|
|
50
|
+
return 'TypedConfigConversionError';
|
|
51
|
+
if (error instanceof TypeError)
|
|
52
|
+
return 'TypeError';
|
|
53
|
+
if (error instanceof RangeError)
|
|
54
|
+
return 'RangeError';
|
|
55
|
+
return error instanceof Error ? 'Error' : 'NonError';
|
|
56
|
+
}
|
|
57
|
+
function warn(operation, kind) {
|
|
58
|
+
try {
|
|
59
|
+
// Exception messages and causes can contain config payloads. Only fixed
|
|
60
|
+
// error categories are logged, including for non-Error callback throws.
|
|
61
|
+
console.warn(`[Statsig] Typed config ${operation} failed (${kind})`);
|
|
62
|
+
}
|
|
63
|
+
catch (_a) {
|
|
64
|
+
// Application-provided console hooks must not stop other observers.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Internal coordinator; ordinary reads retain no context, observer, or result. */
|
|
68
|
+
class TypedConfigs {
|
|
69
|
+
constructor(sdk) {
|
|
70
|
+
this.sdk = sdk;
|
|
71
|
+
this.closed = false;
|
|
72
|
+
this.started = false;
|
|
73
|
+
this.baselines = 0;
|
|
74
|
+
this.pending = false;
|
|
75
|
+
this.observers = [];
|
|
76
|
+
}
|
|
77
|
+
get(user, name, schema, options) {
|
|
78
|
+
validateArguments(user, name, options);
|
|
79
|
+
this.ensureOpen();
|
|
80
|
+
const raw = this.sdk.__INTERNAL_getTypedConfig(user, name, options);
|
|
81
|
+
this.ensureUsable(raw);
|
|
82
|
+
const result = this.convert(name, raw, schema);
|
|
83
|
+
this.ensureOpen();
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
register(user, name, schema, callback) {
|
|
87
|
+
validateArguments(user, name);
|
|
88
|
+
if (typeof callback !== 'function') {
|
|
89
|
+
throw new TypeError('callback must be a function');
|
|
90
|
+
}
|
|
91
|
+
this.ensureOpen();
|
|
92
|
+
if (!callbackScope) {
|
|
93
|
+
const { AsyncLocalStorage } = require('node:async_hooks');
|
|
94
|
+
callbackScope = new AsyncLocalStorage();
|
|
95
|
+
}
|
|
96
|
+
if (!this.started) {
|
|
97
|
+
// TSFN Weak only unrefs the event loop. A weak state reference also avoids
|
|
98
|
+
// rooting the SDK through the native worker's retained JS callback.
|
|
99
|
+
const state = new WeakRef(this);
|
|
100
|
+
try {
|
|
101
|
+
this.sdk.__INTERNAL_startTypedConfigUpdates(() => { var _a; return (_a = state.deref()) === null || _a === void 0 ? void 0 : _a.notify(); });
|
|
102
|
+
}
|
|
103
|
+
catch (_a) {
|
|
104
|
+
throw new TypedConfigUnavailableError('Initialize Statsig before registering callbacks');
|
|
105
|
+
}
|
|
106
|
+
this.started = true;
|
|
107
|
+
}
|
|
108
|
+
this.baselines++;
|
|
109
|
+
try {
|
|
110
|
+
const observer = {
|
|
111
|
+
name,
|
|
112
|
+
context: this.sdk.__INTERNAL_typedConfigContext(user, name),
|
|
113
|
+
schema,
|
|
114
|
+
callback: callback,
|
|
115
|
+
};
|
|
116
|
+
try {
|
|
117
|
+
const raw = observer.context.getEvaluation();
|
|
118
|
+
this.ensureUsable(raw);
|
|
119
|
+
this.convert(name, raw, schema);
|
|
120
|
+
observer.revision = raw.__typedRevision;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
observer.error = errorKind(error);
|
|
124
|
+
warn('observation', observer.error);
|
|
125
|
+
}
|
|
126
|
+
this.ensureOpen();
|
|
127
|
+
this.observers.push(observer);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
this.baselines--;
|
|
131
|
+
this.drain();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
close() {
|
|
135
|
+
var _a;
|
|
136
|
+
this.closed = true;
|
|
137
|
+
this.pending = false;
|
|
138
|
+
this.observers = [];
|
|
139
|
+
this.sdk.__INTERNAL_closeTypedConfigUpdates();
|
|
140
|
+
const admission = callbackScope === null || callbackScope === void 0 ? void 0 : callbackScope.getStore();
|
|
141
|
+
// This is intentionally decided on each call. Reusing an external join
|
|
142
|
+
// promise inside its still-running callback would make shutdown self-join.
|
|
143
|
+
if ((admission === null || admission === void 0 ? void 0 : admission.owner) === this && admission.active)
|
|
144
|
+
return Promise.resolve();
|
|
145
|
+
return (_a = this.worker) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
146
|
+
}
|
|
147
|
+
ensureOpen() {
|
|
148
|
+
if (this.closed)
|
|
149
|
+
throw new TypedConfigUnavailableError();
|
|
150
|
+
}
|
|
151
|
+
ensureUsable(raw) {
|
|
152
|
+
if (!raw.__typedUsable || typeof raw.__typedRevision !== 'string' ||
|
|
153
|
+
raw.value === null || typeof raw.value !== 'object' || Array.isArray(raw.value)) {
|
|
154
|
+
throw new TypedConfigUnavailableError();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
convert(name, raw, schema) {
|
|
158
|
+
let value;
|
|
159
|
+
try {
|
|
160
|
+
// Both module formats use equivalent descriptors at runtime. Normalize the
|
|
161
|
+
// declaration brand only at the lazily loaded CommonJS parser boundary.
|
|
162
|
+
value = runtime().fromJson(schema, raw.value, { ignoreUnknownFields: false });
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new TypedConfigConversionError(error);
|
|
166
|
+
}
|
|
167
|
+
return new statsig_types_1.TypedDynamicConfig(name, raw, value);
|
|
168
|
+
}
|
|
169
|
+
notify() {
|
|
170
|
+
if (this.closed)
|
|
171
|
+
return;
|
|
172
|
+
this.pending = true;
|
|
173
|
+
this.drain();
|
|
174
|
+
}
|
|
175
|
+
drain() {
|
|
176
|
+
if (this.closed || this.baselines || !this.pending || this.worker)
|
|
177
|
+
return;
|
|
178
|
+
// Install the join promise before invoking any callback, including a
|
|
179
|
+
// synchronous callback that reenters registration or shutdown.
|
|
180
|
+
this.worker = Promise.resolve().then(() => this.run()).finally(() => {
|
|
181
|
+
this.worker = undefined;
|
|
182
|
+
this.drain();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
run() {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
while (this.pending && !this.closed && !this.baselines) {
|
|
188
|
+
this.pending = false;
|
|
189
|
+
for (const observer of this.observers.slice()) {
|
|
190
|
+
if (this.closed)
|
|
191
|
+
return;
|
|
192
|
+
let raw;
|
|
193
|
+
let result;
|
|
194
|
+
try {
|
|
195
|
+
raw = observer.context.getEvaluation();
|
|
196
|
+
this.ensureUsable(raw);
|
|
197
|
+
if (this.closed)
|
|
198
|
+
return;
|
|
199
|
+
// Baselines and successful deliveries acknowledge revisions. Skip
|
|
200
|
+
// protobuf allocation/parsing only for an already acknowledged value.
|
|
201
|
+
if (observer.revision === raw.__typedRevision) {
|
|
202
|
+
observer.error = undefined;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
result = this.convert(observer.name, raw, observer.schema);
|
|
206
|
+
observer.error = undefined;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
const kind = errorKind(error);
|
|
210
|
+
if (!this.closed && observer.error !== kind)
|
|
211
|
+
warn('observation', kind);
|
|
212
|
+
observer.error = kind;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (this.closed)
|
|
216
|
+
return;
|
|
217
|
+
const revision = raw.__typedRevision;
|
|
218
|
+
const admission = { owner: this, active: true };
|
|
219
|
+
try {
|
|
220
|
+
yield callbackScope.run(admission, () => observer.callback(result));
|
|
221
|
+
if (!this.closed)
|
|
222
|
+
observer.revision = revision;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
warn('callback', errorKind(error));
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
admission.active = false;
|
|
229
|
+
admission.owner = undefined;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.TypedConfigs = TypedConfigs;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference path="./typed_config_schema_esm.d.mts" />
|
|
2
|
+
import type { Message } from '@bufbuild/protobuf';
|
|
3
|
+
import type { GenMessage } from '@bufbuild/protobuf/codegenv2';
|
|
4
|
+
|
|
5
|
+
// Protobuf-ES gives its CommonJS and ESM declarations distinct generated-message
|
|
6
|
+
// brands. Keep both genuine brands so schema inference works in either format.
|
|
7
|
+
// This authored declaration is copied unchanged, preserving the ESM reference.
|
|
8
|
+
export type SchemaMessage = Message;
|
|
9
|
+
|
|
10
|
+
export interface SchemaVariants<T extends SchemaMessage> {
|
|
11
|
+
commonjs: GenMessage<T>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type TypedConfigSchema<T extends SchemaMessage> =
|
|
15
|
+
SchemaVariants<T>[keyof SchemaVariants<T>];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SchemaMessage } from './typed_config_schema.js';
|
|
2
|
+
import type { GenMessage } from '@bufbuild/protobuf/codegenv2';
|
|
3
|
+
|
|
4
|
+
// The .d.mts extension resolves Protobuf-ES's ESM declarations. Augment only our
|
|
5
|
+
// relative module, not a global interface or the application's protobuf types.
|
|
6
|
+
declare module './typed_config_schema.js' {
|
|
7
|
+
interface SchemaVariants<T extends SchemaMessage> {
|
|
8
|
+
esm: GenMessage<T>;
|
|
9
|
+
}
|
|
10
|
+
}
|