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.

911 B
Raw Blame
import { IntegrationType } from '~/types'

export type DefaultEmailSenderReason = 'project_default' | 'only_verified_sender'

export interface DefaultEmailSender {
    integrationId: number
    reason: DefaultEmailSenderReason
}

export function resolveDefaultEmailSender(
    integrations: IntegrationType[] | null | undefined,
    defaultIntegrationId: number | null | undefined
): DefaultEmailSender | null {
    const verified = (integrations ?? []).filter(
        (integration) => integration.kind === 'email' && integration.config?.verified === true
    )
    const projectDefault = verified.find((integration) => integration.id === defaultIntegrationId)
    if (projectDefault) {
        return { integrationId: projectDefault.id, reason: 'project_default' }
    }
    if (verified.length === 1) {
        return { integrationId: verified[0].id, reason: 'only_verified_sender' }
    }
    return null
}