55 lines
1.1 KiB
JavaScript
55 lines
1.1 KiB
JavaScript
import { writable } from "svelte/store"
|
|
import { API } from "api"
|
|
import { licensing } from "./licensing"
|
|
import { ConfigType } from "@budibase/types"
|
|
|
|
export const createFeatureStore = () => {
|
|
const internalStore = writable({
|
|
scim: {
|
|
isFeatureFlagEnabled: false,
|
|
isConfigFlagEnabled: false,
|
|
},
|
|
})
|
|
|
|
const store = writable({
|
|
isScimEnabled: false,
|
|
})
|
|
|
|
internalStore.subscribe(s => {
|
|
store.update(state => ({
|
|
...state,
|
|
isScimEnabled: s.scim.isFeatureFlagEnabled && s.scim.isConfigFlagEnabled,
|
|
}))
|
|
})
|
|
|
|
licensing.subscribe(v => {
|
|
internalStore.update(state => ({
|
|
...state,
|
|
scim: {
|
|
...state.scim,
|
|
isFeatureFlagEnabled: v.scimEnabled,
|
|
},
|
|
}))
|
|
})
|
|
|
|
const actions = {
|
|
init: async () => {
|
|
const scimConfig = await API.getConfig(ConfigType.SCIM)
|
|
internalStore.update(state => ({
|
|
...state,
|
|
scim: {
|
|
...state.scim,
|
|
isConfigFlagEnabled: scimConfig?.config?.enabled,
|
|
},
|
|
}))
|
|
},
|
|
}
|
|
|
|
return {
|
|
subscribe: store.subscribe,
|
|
...actions,
|
|
}
|
|
}
|
|
|
|
export const features = createFeatureStore()
|