:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { MakeLogicType, actions, kea, path } from 'kea'
import { loaders } from 'kea-loaders'
import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface settingsSnapshotLogicValues {
settingsSnapshot: Record<string, any> | null
settingsSnapshotLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface settingsSnapshotLogicActions {
loadSettingsAsOf: (
at: string,
scope?: string | string[]
) => {
at: string
scope: string | string[] | undefined
}
loadSettingsAsOfFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadSettingsAsOfSuccess: (
settingsSnapshot: Record<string, any>,
payload?: {
at: string
scope: string | string[] | undefined
}
) => {
settingsSnapshot: Record<string, any>
payload?: {
at: string
scope: string | string[] | undefined
}
}
}
export type settingsSnapshotLogicType = MakeLogicType<settingsSnapshotLogicValues, settingsSnapshotLogicActions>
export const settingsSnapshotLogic = kea<settingsSnapshotLogicType>([
path(['lib', 'components', 'settingsSnapshotLogic']),
actions({
loadSettingsAsOf: (at: string, scope?: string | string[]) => ({ at, scope }),
}),
loaders(() => ({
settingsSnapshot: [
null as Record<string, any> | null,
{
loadSettingsAsOf: async ({ at, scope }: { at: string; scope?: string | string[] }) => {
const scopeArray = Array.isArray(scope)
? scope.filter((s): s is string => !!s)
: scope
? [scope]
: undefined
if (!at) {
lemonToast.warning('A timestamp is required to load settings at a point in time')
return {}
}
return await api.teamSettings.asOf(at, scopeArray)
},
},
],
})),
])