@statsig/statsig-node-core 0.0.6-beta.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.
Files changed (3) hide show
  1. package/index.d.ts +166 -0
  2. package/index.js +373 -0
  3. package/package.json +52 -0
package/index.d.ts ADDED
@@ -0,0 +1,166 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare class DynamicConfig {
4
+ name: string
5
+ value: Record<string, any>
6
+ ruleID: string
7
+ idType: string
8
+ get(paramName: string, fallback: any): any
9
+ }
10
+
11
+ export declare class Experiment {
12
+ name: string
13
+ value: Record<string, any>
14
+ ruleID: string
15
+ idType: string
16
+ groupName?: string
17
+ get(paramName: string, fallback: any): any
18
+ }
19
+
20
+ export declare class Layer {
21
+ name: string
22
+ ruleID: string
23
+ groupName?: string
24
+ get(paramName: string, fallback: any): any
25
+ }
26
+
27
+ export declare class Statsig {
28
+ constructor(sdkKey: string, options?: StatsigOptions | undefined | null)
29
+ initialize(): Promise<StatsigResult>
30
+ shutdown(): Promise<StatsigResult>
31
+ flushEvents(): Promise<StatsigResult>
32
+ logEvent(user: StatsigUser, eventName: string, value?: string | number | null, metadata?: Record<string, string> | undefined | null): void
33
+ checkGate(user: StatsigUser, gateName: string, options?: FeatureGateEvaluationOptions | undefined | null): boolean
34
+ getFeatureGate(user: StatsigUser, featureName: string, options?: FeatureGateEvaluationOptions | undefined | null): FeatureGate
35
+ getDynamicConfig(user: StatsigUser, configName: string, options?: DynamicConfigEvaluationOptions | undefined | null): DynamicConfig
36
+ getExperiment(user: StatsigUser, experimentName: string, options?: ExperimentEvaluationOptions | undefined | null): Experiment
37
+ getLayer(user: StatsigUser, layerName: string, options?: LayerEvaluationOptions | undefined | null): Layer
38
+ getClientInitializeResponse(user: StatsigUser, options?: ClientInitResponseOptions | undefined | null): string
39
+ manuallyLogFeatureGateExposure(user: StatsigUser, gateName: string): void
40
+ manuallyLogDynamicConfigExposure(user: StatsigUser, configName: string): void
41
+ manuallyLogExperimentExposure(user: StatsigUser, experimentName: string): void
42
+ manuallyLogLayerParamExposure(user: StatsigUser, layerName: string, paramName: string): void
43
+ }
44
+
45
+ export declare class StatsigUser {
46
+ constructor(args: StatsigUserArgs)
47
+ static withUserID(userId: string): StatsigUser
48
+ static withCustomIDs(customIds: Record<string, any>): StatsigUser
49
+ get customIDs(): Record<string, string> | null
50
+ set customIDs(value: Record<string, string> | null)
51
+ get custom(): Record<string, string> | null
52
+ set custom(value: Record<string, string | number | boolean | Array<string | number | boolean>> | null)
53
+ get privateAttributes(): Record<string, string> | null
54
+ set privateAttributes(value: Record<string, string | number | boolean | Array<string | number | boolean>> | null)
55
+ get userID(): string | null
56
+ set userID(value: any)
57
+ get email(): string | null
58
+ set email(value: any)
59
+ get ip(): string | null
60
+ set ip(value: any)
61
+ get userAgent(): string | null
62
+ set userAgent(value: any)
63
+ get country(): string | null
64
+ set country(value: any)
65
+ get locale(): string | null
66
+ set locale(value: any)
67
+ get appVersion(): string | null
68
+ set appVersion(value: any)
69
+ }
70
+
71
+ export declare function __internal__testDataStore(store: DataStore, path: string, value: string): Promise<[DataStoreResponse | undefined | null, boolean]>
72
+
73
+ export declare function __internal__testObservabilityClient(client: ObservabilityClient, action: string, metricName: string, value: number, tags?: Record<string, string> | undefined | null): Promise<void>
74
+
75
+ export interface ClientInitResponseOptions {
76
+ hashAlgorithm?: string
77
+ clientSdkKey?: string
78
+ includeLocalOverrides?: boolean
79
+ }
80
+
81
+ export interface DataStore {
82
+ initialize?: () => Promise<void>
83
+ shutdown?: () => Promise<void>
84
+ get?: (key: string) => Promise<DataStoreResponse>
85
+ set?: (key: string, value: string, time?: number) => Promise<void>
86
+ supportPollingUpdatesFor?: (key: string) => Promise<boolean>
87
+ }
88
+
89
+ export interface DataStoreResponse {
90
+ result?: string
91
+ time?: number
92
+ }
93
+
94
+ export interface DynamicConfigEvaluationOptions {
95
+ disableExposureLogging?: boolean
96
+ }
97
+
98
+ export interface ExperimentEvaluationOptions {
99
+ disableExposureLogging?: boolean
100
+ }
101
+
102
+ export interface FeatureGate {
103
+ name: string
104
+ value: boolean
105
+ ruleID: string
106
+ idType: string
107
+ }
108
+
109
+ export interface FeatureGateEvaluationOptions {
110
+ disableExposureLogging?: boolean
111
+ }
112
+
113
+ export interface LayerEvaluationOptions {
114
+ disableExposureLogging?: boolean
115
+ }
116
+
117
+ export interface ObservabilityClient {
118
+ initialize?: () => void
119
+ increment?: (metricName: string, value: number, tags: Record<string, string>) => void
120
+ gauge?: (metricName: string, value: number, tags: Record<string, string>) => void
121
+ dist?: (metricName: string, value: number, tags: Record<string, string>) => void
122
+ }
123
+
124
+ export interface SpecAdapterConfig {
125
+ adapterType: 'data_store' | 'network_grpc_websocket' | 'network_http'
126
+ specsUrl?: string
127
+ initTimeoutMs: number
128
+ }
129
+
130
+ export interface StatsigOptions {
131
+ dataStore?: DataStore
132
+ disableAllLogging?: boolean
133
+ enableIdLists?: boolean
134
+ environment?: string
135
+ eventLoggingFlushIntervalMs?: number
136
+ eventLoggingMaxQueueSize?: number
137
+ fallbackToStatsigApi?: boolean
138
+ idListsSyncIntervalMs?: number
139
+ idListsUrl?: string
140
+ initTimeoutMs?: number
141
+ logEventUrl?: string
142
+ observabilityClient?: ObservabilityClient
143
+ outputLogLevel?: 'none' | 'debug' | 'info' | 'warn' | 'error'
144
+ specAdaptersConfig?: Array<SpecAdapterConfig>
145
+ specsUrl?: string
146
+ specsSyncIntervalMs?: number
147
+ serviceName?: string
148
+ }
149
+
150
+ export interface StatsigResult {
151
+ isSuccess: boolean
152
+ error?: string
153
+ }
154
+
155
+ export interface StatsigUserArgs {
156
+ userID: string
157
+ customIDs: Record<string, string | number | number>
158
+ email?: string
159
+ ip?: string
160
+ userAgent?: string
161
+ country?: string
162
+ locale?: string
163
+ appVersion?: string
164
+ custom?: Record<string, string | number | boolean | Array<string | number | boolean>>
165
+ privateAttributes?: Record<string, string | number | boolean | Array<string | number | boolean>>
166
+ }
package/index.js ADDED
@@ -0,0 +1,373 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const { createRequire } = require('node:module')
7
+ require = createRequire(__filename)
8
+
9
+ const { readFileSync } = require('node:fs')
10
+ let nativeBinding = null
11
+ const loadErrors = []
12
+
13
+ const isMusl = () => {
14
+ let musl = false
15
+ if (process.platform === 'linux') {
16
+ musl = isMuslFromFilesystem()
17
+ if (musl === null) {
18
+ musl = isMuslFromReport()
19
+ }
20
+ if (musl === null) {
21
+ musl = isMuslFromChildProcess()
22
+ }
23
+ }
24
+ return musl
25
+ }
26
+
27
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
28
+
29
+ const isMuslFromFilesystem = () => {
30
+ try {
31
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
32
+ } catch {
33
+ return null
34
+ }
35
+ }
36
+
37
+ const isMuslFromReport = () => {
38
+ const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
39
+ if (!report) {
40
+ return null
41
+ }
42
+ if (report.header && report.header.glibcVersionRuntime) {
43
+ return false
44
+ }
45
+ if (Array.isArray(report.sharedObjects)) {
46
+ if (report.sharedObjects.some(isFileMusl)) {
47
+ return true
48
+ }
49
+ }
50
+ return false
51
+ }
52
+
53
+ const isMuslFromChildProcess = () => {
54
+ try {
55
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
56
+ } catch (e) {
57
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
58
+ return false
59
+ }
60
+ }
61
+
62
+ function requireNative() {
63
+ if (process.platform === 'android') {
64
+ if (process.arch === 'arm64') {
65
+ try {
66
+ return require('./statsig-node-core.android-arm64.node')
67
+ } catch (e) {
68
+ loadErrors.push(e)
69
+ }
70
+ try {
71
+ return require('@statsig/statsig-node-core-android-arm64')
72
+ } catch (e) {
73
+ loadErrors.push(e)
74
+ }
75
+
76
+ } else if (process.arch === 'arm') {
77
+ try {
78
+ return require('./statsig-node-core.android-arm-eabi.node')
79
+ } catch (e) {
80
+ loadErrors.push(e)
81
+ }
82
+ try {
83
+ return require('@statsig/statsig-node-core-android-arm-eabi')
84
+ } catch (e) {
85
+ loadErrors.push(e)
86
+ }
87
+
88
+ } else {
89
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
90
+ }
91
+ } else if (process.platform === 'win32') {
92
+ if (process.arch === 'x64') {
93
+ try {
94
+ return require('./statsig-node-core.win32-x64-msvc.node')
95
+ } catch (e) {
96
+ loadErrors.push(e)
97
+ }
98
+ try {
99
+ return require('@statsig/statsig-node-core-win32-x64-msvc')
100
+ } catch (e) {
101
+ loadErrors.push(e)
102
+ }
103
+
104
+ } else if (process.arch === 'ia32') {
105
+ try {
106
+ return require('./statsig-node-core.win32-ia32-msvc.node')
107
+ } catch (e) {
108
+ loadErrors.push(e)
109
+ }
110
+ try {
111
+ return require('@statsig/statsig-node-core-win32-ia32-msvc')
112
+ } catch (e) {
113
+ loadErrors.push(e)
114
+ }
115
+
116
+ } else if (process.arch === 'arm64') {
117
+ try {
118
+ return require('./statsig-node-core.win32-arm64-msvc.node')
119
+ } catch (e) {
120
+ loadErrors.push(e)
121
+ }
122
+ try {
123
+ return require('@statsig/statsig-node-core-win32-arm64-msvc')
124
+ } catch (e) {
125
+ loadErrors.push(e)
126
+ }
127
+
128
+ } else {
129
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
130
+ }
131
+ } else if (process.platform === 'darwin') {
132
+ try {
133
+ return require('./statsig-node-core.darwin-universal.node')
134
+ } catch (e) {
135
+ loadErrors.push(e)
136
+ }
137
+ try {
138
+ return require('@statsig/statsig-node-core-darwin-universal')
139
+ } catch (e) {
140
+ loadErrors.push(e)
141
+ }
142
+
143
+ if (process.arch === 'x64') {
144
+ try {
145
+ return require('./statsig-node-core.darwin-x64.node')
146
+ } catch (e) {
147
+ loadErrors.push(e)
148
+ }
149
+ try {
150
+ return require('@statsig/statsig-node-core-darwin-x64')
151
+ } catch (e) {
152
+ loadErrors.push(e)
153
+ }
154
+
155
+ } else if (process.arch === 'arm64') {
156
+ try {
157
+ return require('./statsig-node-core.darwin-arm64.node')
158
+ } catch (e) {
159
+ loadErrors.push(e)
160
+ }
161
+ try {
162
+ return require('@statsig/statsig-node-core-darwin-arm64')
163
+ } catch (e) {
164
+ loadErrors.push(e)
165
+ }
166
+
167
+ } else {
168
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
169
+ }
170
+ } else if (process.platform === 'freebsd') {
171
+ if (process.arch === 'x64') {
172
+ try {
173
+ return require('./statsig-node-core.freebsd-x64.node')
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ try {
178
+ return require('@statsig/statsig-node-core-freebsd-x64')
179
+ } catch (e) {
180
+ loadErrors.push(e)
181
+ }
182
+
183
+ } else if (process.arch === 'arm64') {
184
+ try {
185
+ return require('./statsig-node-core.freebsd-arm64.node')
186
+ } catch (e) {
187
+ loadErrors.push(e)
188
+ }
189
+ try {
190
+ return require('@statsig/statsig-node-core-freebsd-arm64')
191
+ } catch (e) {
192
+ loadErrors.push(e)
193
+ }
194
+
195
+ } else {
196
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
197
+ }
198
+ } else if (process.platform === 'linux') {
199
+ if (process.arch === 'x64') {
200
+ if (isMusl()) {
201
+ try {
202
+ return require('./statsig-node-core.linux-x64-musl.node')
203
+ } catch (e) {
204
+ loadErrors.push(e)
205
+ }
206
+ try {
207
+ return require('@statsig/statsig-node-core-linux-x64-musl')
208
+ } catch (e) {
209
+ loadErrors.push(e)
210
+ }
211
+
212
+ } else {
213
+ try {
214
+ return require('./statsig-node-core.linux-x64-gnu.node')
215
+ } catch (e) {
216
+ loadErrors.push(e)
217
+ }
218
+ try {
219
+ return require('@statsig/statsig-node-core-linux-x64-gnu')
220
+ } catch (e) {
221
+ loadErrors.push(e)
222
+ }
223
+
224
+ }
225
+ } else if (process.arch === 'arm64') {
226
+ if (isMusl()) {
227
+ try {
228
+ return require('./statsig-node-core.linux-arm64-musl.node')
229
+ } catch (e) {
230
+ loadErrors.push(e)
231
+ }
232
+ try {
233
+ return require('@statsig/statsig-node-core-linux-arm64-musl')
234
+ } catch (e) {
235
+ loadErrors.push(e)
236
+ }
237
+
238
+ } else {
239
+ try {
240
+ return require('./statsig-node-core.linux-arm64-gnu.node')
241
+ } catch (e) {
242
+ loadErrors.push(e)
243
+ }
244
+ try {
245
+ return require('@statsig/statsig-node-core-linux-arm64-gnu')
246
+ } catch (e) {
247
+ loadErrors.push(e)
248
+ }
249
+
250
+ }
251
+ } else if (process.arch === 'arm') {
252
+ if (isMusl()) {
253
+ try {
254
+ return require('./statsig-node-core.linux-arm-musleabihf.node')
255
+ } catch (e) {
256
+ loadErrors.push(e)
257
+ }
258
+ try {
259
+ return require('@statsig/statsig-node-core-linux-arm-musleabihf')
260
+ } catch (e) {
261
+ loadErrors.push(e)
262
+ }
263
+
264
+ } else {
265
+ try {
266
+ return require('./statsig-node-core.linux-arm-gnueabihf.node')
267
+ } catch (e) {
268
+ loadErrors.push(e)
269
+ }
270
+ try {
271
+ return require('@statsig/statsig-node-core-linux-arm-gnueabihf')
272
+ } catch (e) {
273
+ loadErrors.push(e)
274
+ }
275
+
276
+ }
277
+ } else if (process.arch === 'riscv64') {
278
+ if (isMusl()) {
279
+ try {
280
+ return require('./statsig-node-core.linux-riscv64-musl.node')
281
+ } catch (e) {
282
+ loadErrors.push(e)
283
+ }
284
+ try {
285
+ return require('@statsig/statsig-node-core-linux-riscv64-musl')
286
+ } catch (e) {
287
+ loadErrors.push(e)
288
+ }
289
+
290
+ } else {
291
+ try {
292
+ return require('./statsig-node-core.linux-riscv64-gnu.node')
293
+ } catch (e) {
294
+ loadErrors.push(e)
295
+ }
296
+ try {
297
+ return require('@statsig/statsig-node-core-linux-riscv64-gnu')
298
+ } catch (e) {
299
+ loadErrors.push(e)
300
+ }
301
+
302
+ }
303
+ } else if (process.arch === 'ppc64') {
304
+ try {
305
+ return require('./statsig-node-core.linux-ppc64-gnu.node')
306
+ } catch (e) {
307
+ loadErrors.push(e)
308
+ }
309
+ try {
310
+ return require('@statsig/statsig-node-core-linux-ppc64-gnu')
311
+ } catch (e) {
312
+ loadErrors.push(e)
313
+ }
314
+
315
+ } else if (process.arch === 's390x') {
316
+ try {
317
+ return require('./statsig-node-core.linux-s390x-gnu.node')
318
+ } catch (e) {
319
+ loadErrors.push(e)
320
+ }
321
+ try {
322
+ return require('@statsig/statsig-node-core-linux-s390x-gnu')
323
+ } catch (e) {
324
+ loadErrors.push(e)
325
+ }
326
+
327
+ } else {
328
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
329
+ }
330
+ } else {
331
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
332
+ }
333
+ }
334
+
335
+ nativeBinding = requireNative()
336
+
337
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
338
+ try {
339
+ nativeBinding = require('./statsig-node-core.wasi.cjs')
340
+ } catch (err) {
341
+ if (process.env.NAPI_RS_FORCE_WASI) {
342
+ loadErrors.push(err)
343
+ }
344
+ }
345
+ if (!nativeBinding) {
346
+ try {
347
+ nativeBinding = require('@statsig/statsig-node-core-wasm32-wasi')
348
+ } catch (err) {
349
+ if (process.env.NAPI_RS_FORCE_WASI) {
350
+ loadErrors.push(err)
351
+ }
352
+ }
353
+ }
354
+ }
355
+
356
+ if (!nativeBinding) {
357
+ if (loadErrors.length > 0) {
358
+ // TODO Link to documentation with potential fixes
359
+ // - The package owner could build/publish bindings for this arch
360
+ // - The user may need to bundle the correct files
361
+ // - The user may need to re-install node_modules to get new packages
362
+ throw new Error('Failed to load native binding', { cause: loadErrors })
363
+ }
364
+ throw new Error(`Failed to load native binding`)
365
+ }
366
+
367
+ module.exports.DynamicConfig = nativeBinding.DynamicConfig
368
+ module.exports.Experiment = nativeBinding.Experiment
369
+ module.exports.Layer = nativeBinding.Layer
370
+ module.exports.Statsig = nativeBinding.Statsig
371
+ module.exports.StatsigUser = nativeBinding.StatsigUser
372
+ module.exports.__internal__testDataStore = nativeBinding.__internal__testDataStore
373
+ module.exports.__internal__testObservabilityClient = nativeBinding.__internal__testObservabilityClient
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@statsig/statsig-node-core",
3
+ "version": "0.0.6-beta.2",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "jest --colors",
7
+ "build": "napi build --platform --js index.js --dts index.d.ts --output-dir ./build --strip"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "devDependencies": {
14
+ "@mongodb-js/zstd": "^2.0.0",
15
+ "@napi-rs/cli": "^3.0.0-alpha.62",
16
+ "@types/compression": "^1.7.5",
17
+ "@types/express": "^5.0.0",
18
+ "@types/jest": "^29.5.14",
19
+ "@types/node": "^22.10.10",
20
+ "compression": "^1.7.4",
21
+ "express": "^4.21.2",
22
+ "jest": "^29.7.0",
23
+ "ts-jest": "^29.2.5",
24
+ "typescript": "^5.7.3"
25
+ },
26
+ "engines": {
27
+ "node": ">= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0 < 10 || >= 10.0.0"
28
+ },
29
+ "napi": {
30
+ "binaryName": "statsig-node-core",
31
+ "targets": [
32
+ "aarch64-apple-darwin",
33
+ "aarch64-unknown-linux-gnu",
34
+ "aarch64-unknown-linux-musl",
35
+ "i686-pc-windows-msvc",
36
+ "x86_64-apple-darwin",
37
+ "x86_64-pc-windows-msvc",
38
+ "x86_64-unknown-linux-gnu",
39
+ "x86_64-unknown-linux-musl"
40
+ ]
41
+ },
42
+ "optionalDependencies": {
43
+ "@statsig/statsig-node-core-win32-x64-msvc": "0.0.6-beta.2",
44
+ "@statsig/statsig-node-core-win32-ia32-msvc": "0.0.6-beta.2",
45
+ "@statsig/statsig-node-core-linux-x64-musl": "0.0.6-beta.2",
46
+ "@statsig/statsig-node-core-linux-x64-gnu": "0.0.6-beta.2",
47
+ "@statsig/statsig-node-core-linux-arm64-musl": "0.0.6-beta.2",
48
+ "@statsig/statsig-node-core-linux-arm64-gnu": "0.0.6-beta.2",
49
+ "@statsig/statsig-node-core-darwin-x64": "0.0.6-beta.2",
50
+ "@statsig/statsig-node-core-darwin-arm64": "0.0.6-beta.2"
51
+ }
52
+ }