tududi/frontend/utils/featureFlags.ts
Chris bf281b740d
Feat backups (#686)
* Scaffold backups

* Add FFlags

* fixup! Add FFlags

* fixup! fixup! Add FFlags

* fixup! fixup! fixup! Add FFlags
2025-12-09 08:00:46 +02:00

42 lines
1 KiB
TypeScript

import { getApiPath } from '../config/paths';
export interface FeatureFlags {
backups: boolean;
calendar: boolean;
}
let cachedFeatureFlags: FeatureFlags | null = null;
export const getFeatureFlags = async (): Promise<FeatureFlags> => {
if (cachedFeatureFlags) {
return cachedFeatureFlags;
}
try {
const response = await fetch(getApiPath('feature-flags'), {
credentials: 'include',
});
if (!response.ok) {
console.error('Failed to fetch feature flags');
return {
backups: false,
calendar: false,
};
}
const data = await response.json();
cachedFeatureFlags = data.featureFlags;
return cachedFeatureFlags;
} catch (error) {
console.error('Error fetching feature flags:', error);
return {
backups: false,
calendar: false,
};
}
};
export const clearFeatureFlagsCache = () => {
cachedFeatureFlags = null;
};