Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/statsig/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function initStatsigClient(
*/
export function getStatsigClientSync(): StatsigClient {
if (!client) {
throw new Error('[@lovart-open/statsig] Not initialized. Call initStatsigClient() first.');
throw new Error('[@lovart-open/flags/statsig] Not initialized. Call initStatsigClient() first.');
}
return client;
}
Expand Down
14 changes: 9 additions & 5 deletions src/statsig/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ export class FlagStore<TDefinitions extends Record<string, FlagDefinition>> {
}

// 4. Remote value from Statsig
const currentGate = gate ?? getStatsigClientSync().getFeatureGate(keyStr, evaluationOptions);
return {
flag: currentGate.value,
source: currentGate.idType ? 'remote' : 'fallback',
};
try {
const currentGate = gate ?? getStatsigClientSync().getFeatureGate(keyStr, evaluationOptions);
return {
flag: currentGate.value,
source: currentGate.idType ? 'remote' : 'fallback',
};
} catch {
return { flag: false, source: 'fallback' };
}
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/statsig/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,17 @@ export class ParamStore<TStores extends Record<string, ParamStoreDefinition<any>
}
// 4. Remote value from Statsig
else {
const clientStore = statsigStore ?? getStatsigClientSync().getParameterStore(storeKey as string, evaluationOptions);
const config = (clientStore as any)?.__configuration?.[paramKey as string];
if (config !== undefined) {
value = clientStore.get(paramKey as string, def.fallback);
source = 'remote';
} else {
try {
const clientStore = statsigStore ?? getStatsigClientSync().getParameterStore(storeKey as string, evaluationOptions);
const config = (clientStore as any)?.__configuration?.[paramKey as string];
if (config !== undefined) {
value = clientStore.get(paramKey as string, def.fallback);
source = 'remote';
} else {
value = def.fallback;
source = 'fallback';
}
} catch {
value = def.fallback;
source = 'fallback';
}
Expand Down