Files
ghatreh_user/src/config/app-config.ts
T
2026-06-29 15:27:35 +03:30

38 lines
804 B
TypeScript

import type { AppConfig } from './types'
type RawAppConfig = AppConfig & {
user?: Record<string, any>
}
let appConfig: RawAppConfig | null = null
export function setAppConfig(config: RawAppConfig) {
appConfig = config || {}
window.__APP_CONFIG__ = appConfig
}
export function getRawAppConfig() {
return appConfig ?? window.__APP_CONFIG__ ?? null
}
export function getTenantConfig() {
const rawConfig = getRawAppConfig()
if (rawConfig?.user && typeof rawConfig.user === 'object') {
return rawConfig.user
}
if (rawConfig && Object.keys(rawConfig).length > 0) {
return rawConfig
}
return {}
}
export function getConfig<T = any>(key: string, fallback?: T): T {
const config = getTenantConfig()
const value = config?.[key]
return (value ?? fallback ?? null) as T
}