2024-08-27 16:49:43 +02:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
export const useFeatureFlagsStore = defineStore('feature_flags', () => {
|
|
|
|
|
const flags = ref({})
|
|
|
|
|
|
|
|
|
|
async function fetchFlags() {
|
|
|
|
|
try {
|
2024-08-28 15:20:39 +02:00
|
|
|
const { data } = await useOpnApi('content/feature-flags')
|
2024-08-27 16:49:43 +02:00
|
|
|
flags.value = data.value
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Failed to fetch feature flags:', error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFlag(path, defaultValue = false) {
|
|
|
|
|
return path.split('.').reduce((acc, part) => {
|
|
|
|
|
if (acc === undefined) return defaultValue
|
|
|
|
|
return acc && acc[part] !== undefined ? acc[part] : defaultValue
|
|
|
|
|
}, flags.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { flags, fetchFlags, getFlag }
|
|
|
|
|
})
|