2023-03-28 12:01:18 +02:00
|
|
|
import { writable } from "svelte/store"
|
|
|
|
import { API } from "api"
|
|
|
|
import { licensing } from "./licensing"
|
2023-05-24 10:50:51 +02:00
|
|
|
import { ConfigType } from "@budibase/types"
|
2023-03-28 12:01:18 +02:00
|
|
|
|
|
|
|
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,
|
2023-03-29 10:31:07 +02:00
|
|
|
isConfigFlagEnabled: scimConfig?.config?.enabled,
|
2023-03-28 12:01:18 +02:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
|
|
|
...actions,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const features = createFeatureStore()
|