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.

4.8 KB
Raw Blame
from typing import Optional, cast

from products.warehouse_sources.sources.eventee._config import EventeeSourceConfig
from products.warehouse_sources.sources.eventee.eventee import (
    eventee_source,
    validate_credentials as validate_eventee_credentials,
)
from products.warehouse_sources.sources.eventee.settings import ENDPOINTS, INCREMENTAL_FIELDS
from products.warehouse_sources.sources.sdk import (
    CanonicalDescriptions,
    DataWarehouseSourceCategory,
    ExternalDataSourceType,
    FieldType,
    ReleaseStatus,
    SimpleSource,
    SourceConfig,
    SourceFieldInputConfig,
    SourceFieldInputConfigType,
    SourceInputs,
    SourceRegistry,
    SourceResponse,
    SourceSchema,
    build_endpoint_schemas,
    detect,
)


@SourceRegistry.register
class EventeeSource(SimpleSource[EventeeSourceConfig]):
    codebase_detection = detect(env=("^EVENTEE_",))

    supported_versions = ("v1",)
    default_version = "v1"
    api_docs_url = "https://publiceventeeapi.docs.apiary.io/"

    lists_tables_without_credentials = True  # static endpoint catalog — safe for public docs

    @property
    def source_type(self) -> ExternalDataSourceType:
        return ExternalDataSourceType.EVENTEE

    @property
    def get_source_config(self) -> SourceConfig:
        return SourceConfig(
            name=ExternalDataSourceType.EVENTEE,
            category=DataWarehouseSourceCategory.PRODUCTIVITY,
            label="Eventee",
            releaseStatus=ReleaseStatus.BETA,
            caption="""Enter your Eventee API token to pull your event's content into the PostHog Data warehouse.

Generate a token in your Eventee admin dashboard under **Settings → Features**. The token is scoped to a single event, so connect one source per event you want to import.

All Eventee tables are full refresh only — the API exposes no incremental sync filter.""",
            iconPath="/static/services/eventee.png",
            docsUrl="https://posthog.com/docs/cdp/sources/eventee",
            fields=cast(
                list[FieldType],
                [
                    SourceFieldInputConfig(
                        name="api_key",
                        label="API token",
                        type=SourceFieldInputConfigType.PASSWORD,
                        required=True,
                        placeholder="",
                        secret=True,
                    ),
                ],
            ),
        )

    def get_canonical_descriptions(self) -> CanonicalDescriptions:
        from products.warehouse_sources.sources.eventee.canonical_descriptions import (
            CANONICAL_DESCRIPTIONS,  # noqa: PLC0415
        )

        return CANONICAL_DESCRIPTIONS

    def get_non_retryable_errors(self) -> dict[str, str | None]:
        return {
            # An invalid or expired token surfaces as a 401 (`token_invalid`) when `fetch` calls
            # `raise_for_status()`. Retrying can never fix a credential problem. Match the stable
            # status text and base host, not the per-request path.
            "401 Client Error: Unauthorized for url: https://api.eventee.com": "Your Eventee API token is invalid or has expired. Generate a new token in your Eventee admin dashboard (Settings → Features), then reconnect.",
            "403 Client Error: Forbidden for url: https://api.eventee.com": "Your Eventee API token does not have access to this event's data. Check the token in your Eventee admin dashboard, then reconnect.",
        }

    def get_schemas(
        self,
        config: EventeeSourceConfig,
        team_id: int,
        with_counts: bool = False,
        names: list[str] | None = None,
        force_refresh: bool = False,
        api_version: str | None = None,
    ) -> list[SourceSchema]:
        # Every endpoint is a snapshot with no server-side timestamp filter, so all are full refresh
        # only (no incremental/append) — INCREMENTAL_FIELDS is empty, so build_endpoint_schemas
        # produces supports_incremental=False/supports_append=False for every table.
        return build_endpoint_schemas(
            ENDPOINTS,
            INCREMENTAL_FIELDS,
            names,
            descriptions=dict.fromkeys(ENDPOINTS, "Full refresh only — Eventee exposes no incremental sync filter"),
        )

    def validate_credentials(
        self,
        config: EventeeSourceConfig,
        team_id: int,
        schema_name: Optional[str] = None,
        api_version: str | None = None,
    ) -> tuple[bool, str | None]:
        if validate_eventee_credentials(config.api_key):
            return True, None

        return False, "Invalid Eventee API token"

    def source_for_pipeline(self, config: EventeeSourceConfig, inputs: SourceInputs) -> SourceResponse:
        return eventee_source(
            api_key=config.api_key,
            endpoint=inputs.schema_name,
            team_id=inputs.team_id,
            job_id=inputs.job_id,
        )