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.9 KB
Raw Blame
from typing import Optional, cast

from products.warehouse_sources.sources.huntr._config import HuntrSourceConfig
from products.warehouse_sources.sources.huntr.huntr import HuntrResumeConfig, huntr_source, validate_credentials
from products.warehouse_sources.sources.huntr.settings import ENDPOINTS, HUNTR_ENDPOINTS, INCREMENTAL_FIELDS
from products.warehouse_sources.sources.sdk import (
    CanonicalDescriptions,
    DataWarehouseSourceCategory,
    ExternalDataSourceType,
    FieldType,
    ReleaseStatus,
    ResumableSource,
    ResumableSourceManager,
    SourceConfig,
    SourceFieldInputConfig,
    SourceFieldInputConfigType,
    SourceInputs,
    SourceRegistry,
    SourceResponse,
    SourceSchema,
    build_endpoint_schemas,
    detect,
)


@SourceRegistry.register
class HuntrSource(ResumableSource[HuntrSourceConfig, HuntrResumeConfig]):
    codebase_detection = detect(env=("^HUNTR_",))

    api_docs_url = "https://docs.huntr.co"

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

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

    @property
    def get_source_config(self) -> SourceConfig:
        return SourceConfig(
            name=ExternalDataSourceType.HUNTR,
            category=DataWarehouseSourceCategory.HR___RECRUITING,
            label="Huntr",
            releaseStatus=ReleaseStatus.BETA,
            caption="""Enter your Huntr organization access token to pull your Organization API data into the PostHog Data warehouse.

You can generate an access token in your Huntr organization admin dashboard. The token grants read access to your members, advisors, candidates, jobs, job posts, employers, activities, actions, activity categories, tags, and candidate action metrics.
""",
            iconPath="/static/services/huntr.png",
            docsUrl="https://posthog.com/docs/cdp/sources/huntr",
            fields=cast(
                list[FieldType],
                [
                    SourceFieldInputConfig(
                        name="access_token",
                        label="Organization access token",
                        type=SourceFieldInputConfigType.PASSWORD,
                        required=True,
                        placeholder="",
                        secret=True,
                    ),
                ],
            ),
        )

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

        return CANONICAL_DESCRIPTIONS

    def get_non_retryable_errors(self) -> dict[str, str | None]:
        return {
            "401 Client Error: Unauthorized for url: https://api.huntr.co/org": "Your Huntr access token is invalid or has been revoked. Generate a new token in your Huntr organization admin dashboard, then reconnect.",
            "403 Client Error: Forbidden for url: https://api.huntr.co/org": "Your Huntr access token does not have access to this data. Check the token's permissions in your organization admin dashboard, then reconnect.",
        }

    def get_schemas(
        self,
        config: HuntrSourceConfig,
        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 full refresh only — no resource exposes a reliable updated_after cursor, so
        # there is no incremental cursor to advance across every stream (INCREMENTAL_FIELDS is empty).
        return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)

    def validate_credentials(
        self, config: HuntrSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = None
    ) -> tuple[bool, str | None]:
        # The access token is organization-wide, so a single probe validates access to every schema.
        return validate_credentials(config.access_token)

    def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[HuntrResumeConfig]:
        return ResumableSourceManager[HuntrResumeConfig](inputs, HuntrResumeConfig)

    def source_for_pipeline(
        self,
        config: HuntrSourceConfig,
        resumable_source_manager: ResumableSourceManager[HuntrResumeConfig],
        inputs: SourceInputs,
    ) -> SourceResponse:
        if inputs.schema_name not in HUNTR_ENDPOINTS:
            raise ValueError(f"Unknown Huntr schema '{inputs.schema_name}'")

        return huntr_source(
            access_token=config.access_token,
            endpoint=inputs.schema_name,
            team_id=inputs.team_id,
            job_id=inputs.job_id,
            resumable_source_manager=resumable_source_manager,
            db_incremental_field_last_value=None,  # every Huntr endpoint is full refresh
        )