@l.x/gating 1.0.3 → 1.0.4

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.
@@ -0,0 +1,47 @@
1
+ import { StatsigClient } from '@statsig/react-bindings'
2
+ import { getConfig } from '@l.x/config'
3
+ import { LocalOverrideAdapterWrapper } from '@l.x/gating/src/LocalOverrideAdapterWrapper'
4
+ import { isTestEnv } from 'utilities/src/environment/env'
5
+
6
+ export {
7
+ StatsigClient,
8
+ StatsigContext,
9
+ type StatsigOptions,
10
+ StatsigProvider,
11
+ type StatsigUser,
12
+ Storage,
13
+ type StorageProvider,
14
+ type TypedReturn,
15
+ useClientAsyncInit,
16
+ useDynamicConfig,
17
+ useExperiment,
18
+ useFeatureGate,
19
+ useGateValue,
20
+ useLayer,
21
+ useStatsigClient,
22
+ useStatsigUser,
23
+ } from '@statsig/react-bindings'
24
+
25
+ let localOverrideAdapter: LocalOverrideAdapterWrapper | undefined
26
+
27
+ function getStatsigApiKeyOrThrow(): string {
28
+ // A dummy key is used in test env b/c the wallet/mobile tests use this file instead of the statsig.native file
29
+ const statsigApiKey = isTestEnv() ? 'dummy-test-key' : getConfig().statsigApiKey
30
+
31
+ if (!statsigApiKey) {
32
+ throw new Error('STATSIG_API_KEY is not set')
33
+ }
34
+
35
+ return statsigApiKey
36
+ }
37
+
38
+ export function getOverrideAdapter(): LocalOverrideAdapterWrapper {
39
+ if (!localOverrideAdapter) {
40
+ localOverrideAdapter = new LocalOverrideAdapterWrapper(getStatsigApiKeyOrThrow())
41
+ }
42
+ return localOverrideAdapter
43
+ }
44
+
45
+ export function getStatsigClient(): StatsigClient {
46
+ return StatsigClient.instance(getStatsigApiKeyOrThrow())
47
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { PrecomputedEvaluationsInterface } from '@statsig/js-client'
2
+ import { getOverrideAdapter } from '@l.x/gating/src/sdk/statsig'
3
+
4
+ export function isStatsigReady(client: PrecomputedEvaluationsInterface): boolean {
5
+ return client.loadingStatus === 'Ready'
6
+ }
7
+
8
+ type GateOverride = [string, boolean]
9
+ type ConfigOverride = [string, Record<string, unknown>]
10
+
11
+ export function getOverrides(client: PrecomputedEvaluationsInterface): {
12
+ configOverrides: ConfigOverride[]
13
+ gateOverrides: GateOverride[]
14
+ } {
15
+ const statsigOverrides = isStatsigReady(client)
16
+ ? getOverrideAdapter().getAllOverrides()
17
+ : { gate: {}, dynamicConfig: {}, layer: {} }
18
+
19
+ const filterNumbers = (value: [string, unknown]): boolean => isNaN(parseInt(value[0], 10))
20
+ const gateOverrides = Object.entries(statsigOverrides.gate).filter(filterNumbers)
21
+ const configOverrides = Object.entries(statsigOverrides.dynamicConfig).filter(filterNumbers)
22
+
23
+ return { configOverrides, gateOverrides }
24
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "extends": "../../config/tsconfig/app.json",
3
+ "include": [
4
+ "src/**/*.ts",
5
+ "src/**/*.tsx",
6
+ "src/**/*.json",
7
+ "src/global.d.ts"
8
+ ],
9
+ "exclude": [
10
+ "src/**/*.spec.ts",
11
+ "src/**/*.spec.tsx",
12
+ "src/**/*.test.ts",
13
+ "src/**/*.test.tsx"
14
+ ],
15
+ "compilerOptions": {
16
+ "emitDeclarationOnly": true,
17
+ "noEmit": false,
18
+ "types": ["node"],
19
+ "paths": {}
20
+ },
21
+ "references": [
22
+ {
23
+ "path": "../utilities"
24
+ },
25
+ {
26
+ "path": "../config"
27
+ },
28
+ {
29
+ "path": "../api"
30
+ },
31
+ {
32
+ "path": "../eslint-config"
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "preserveSymlinks": true
5
+ },
6
+ "include": ["**/*.ts", "**/*.tsx", "**/*.json"],
7
+ "exclude": ["node_modules"]
8
+ }
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@luxexchange/gating';
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('@luxexchange/gating');