Skip to content

: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.

1.9 KB
Raw Blame
import { MakeLogicType, connect, kea, path, selectors } from 'kea'

import { sdkHealthLogic } from '~/scenes/onboarding/shared/sdkHealth/sdkHealthLogic'

import type { AugmentedTeamSdkVersionsInfo } from '../onboarding/shared/sdkHealth/sdkHealthLogic'
import { TeamSdkVersions } from './surveyVersionRequirements'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface surveysSdkLogicValues {
    sdkHealthData: AugmentedTeamSdkVersionsInfo // sdkHealthLogic
    teamSdkVersions: TeamSdkVersions
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface surveysSdkLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        teamSdkVersions: (sdkHealthData: AugmentedTeamSdkVersionsInfo) => TeamSdkVersions
    }
}

export type surveysSdkLogicType = MakeLogicType<surveysSdkLogicValues, {}, Record<string, any>, surveysSdkLogicMeta>

export const surveysSdkLogic = kea<surveysSdkLogicType>([
    path(['scenes', 'surveys', 'surveysSdkLogic']),
    connect(() => ({
        values: [sdkHealthLogic, ['augmentedData as sdkHealthData']],
    })),
    selectors({
        teamSdkVersions: [
            (s) => [s.sdkHealthData],
            (
                sdkHealthData: import('~/scenes/onboarding/shared/sdkHealth/sdkHealthLogic').AugmentedTeamSdkVersionsInfo
            ): TeamSdkVersions => {
                const versions: TeamSdkVersions = {}

                for (const [sdkType, sdkInfo] of Object.entries(sdkHealthData ?? {})) {
                    if (sdkInfo?.allReleases?.length) {
                        // sdk health uses 'web' but we use 'posthog-js' in SURVEY_SDK_REQUIREMENTS
                        const key = sdkType === 'web' ? 'posthog-js' : sdkType
                        versions[key as keyof TeamSdkVersions] = sdkInfo.allReleases[0]?.version ?? null
                    }
                }

                return versions
            },
        ],
    }),
])