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.

6.5 KB
Raw Blame
from typing import Optional, cast

from products.warehouse_sources.sources.boldsign._config import BoldSignSourceConfig
from products.warehouse_sources.sources.boldsign.boldsign import (
    BoldSignResumeConfig,
    boldsign_source,
    validate_credentials as validate_boldsign_credentials,
)
from products.warehouse_sources.sources.boldsign.settings import BOLDSIGN_ENDPOINTS, ENDPOINTS
from products.warehouse_sources.sources.sdk import (
    CanonicalDescriptions,
    DataWarehouseSourceCategory,
    ExternalDataSourceType,
    FieldType,
    ReleaseStatus,
    ResumableSource,
    ResumableSourceManager,
    SourceConfig,
    SourceFieldInputConfig,
    SourceFieldInputConfigType,
    SourceFieldSelectConfig,
    SourceFieldSelectConfigOption,
    SourceInputs,
    SourceRegistry,
    SourceResponse,
    SourceSchema,
    detect,
)


@SourceRegistry.register
class BoldSignSource(ResumableSource[BoldSignSourceConfig, BoldSignResumeConfig]):
    codebase_detection = detect(
        env=("^(BOLD_SIGN|BOLDSIGN)_",),
        npm=("boldsign",),
        pypi=("boldsign",),
        composer=("boldsign/boldsign-php",),
        maven=("com.boldsign:boldsign-java", "com.boldsign:boldsign-java-sdk"),
    )

    lists_tables_without_credentials = True  # static endpoint catalog — safe for public docs
    supported_versions = ("v1",)
    default_version = "v1"
    api_docs_url = "https://developers.boldsign.com"

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

    @property
    def get_source_config(self) -> SourceConfig:
        return SourceConfig(
            name=ExternalDataSourceType.BOLDSIGN,
            category=DataWarehouseSourceCategory.SALES,
            label="BoldSign",
            releaseStatus=ReleaseStatus.GA,
            caption="""Enter your BoldSign API key to pull your eSignature documents, templates, and contacts into the PostHog Data warehouse.

Create an API key in your [BoldSign account settings](https://app.boldsign.com/settings) under **API** → **API Key**. API keys carry all scopes by default.

Pick the region your BoldSign account lives in — accounts are hosted on either the US (`api.boldsign.com`) or EU (`api-eu.boldsign.com`) host.""",
            iconPath="/static/services/boldsign.png",
            docsUrl="https://posthog.com/docs/cdp/sources/boldsign",
            fields=cast(
                list[FieldType],
                [
                    SourceFieldInputConfig(
                        name="api_key",
                        label="API key",
                        type=SourceFieldInputConfigType.PASSWORD,
                        required=True,
                        placeholder="",
                        secret=True,
                    ),
                    SourceFieldSelectConfig(
                        name="region",
                        label="Region",
                        required=True,
                        defaultValue="us",
                        options=[
                            SourceFieldSelectConfigOption(label="US", value="us"),
                            SourceFieldSelectConfigOption(label="EU", value="eu"),
                        ],
                    ),
                ],
            ),
        )

    def get_canonical_descriptions(self) -> CanonicalDescriptions:
        from products.warehouse_sources.sources.boldsign.canonical_descriptions import CANONICAL_DESCRIPTIONS

        return CANONICAL_DESCRIPTIONS

    def get_non_retryable_errors(self) -> dict[str, str | None]:
        return {
            # 401/403 surface as a requests HTTPError when the REST client calls `raise_for_status()`.
            # Retrying can never satisfy a credential problem, so stop the sync. Match the stable
            # status text and base host, not the per-request path/query.
            "401 Client Error: Unauthorized for url: https://api.boldsign.com": "Your BoldSign API key is invalid or has been revoked. Create a new key in your BoldSign account settings, then reconnect.",
            "401 Client Error: Unauthorized for url: https://api-eu.boldsign.com": "Your BoldSign API key is invalid or has been revoked. Create a new key in your BoldSign account settings, then reconnect.",
            "403 Client Error: Forbidden for url: https://api.boldsign.com": "Your BoldSign API key does not have permission to access this data. Check the key's permissions, then reconnect.",
            "403 Client Error: Forbidden for url: https://api-eu.boldsign.com": "Your BoldSign API key does not have permission to access this data. Check the key's permissions, then reconnect.",
        }

    def get_schemas(
        self,
        config: BoldSignSourceConfig,
        team_id: int,
        with_counts: bool = False,
        names: list[str] | None = None,
        force_refresh: bool = False,
        api_version: str | None = None,
    ) -> list[SourceSchema]:
        schemas = [
            SourceSchema(
                # BoldSign has no reliable server-side updated-since filter, so every table is
                # full refresh (no incremental / append).
                name=endpoint,
                supports_incremental=False,
                supports_append=False,
                incremental_fields=[],
                should_sync_default=BOLDSIGN_ENDPOINTS[endpoint].should_sync_default,
                detected_primary_keys=BOLDSIGN_ENDPOINTS[endpoint].primary_keys,
            )
            for endpoint in ENDPOINTS
        ]
        if names is not None:
            names_set = set(names)
            schemas = [s for s in schemas if s.name in names_set]
        return schemas

    def validate_credentials(
        self,
        config: BoldSignSourceConfig,
        team_id: int,
        schema_name: Optional[str] = None,
        api_version: str | None = None,
    ) -> tuple[bool, str | None]:
        return validate_boldsign_credentials(config.region, config.api_key)

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

    def source_for_pipeline(
        self,
        config: BoldSignSourceConfig,
        resumable_source_manager: ResumableSourceManager[BoldSignResumeConfig],
        inputs: SourceInputs,
    ) -> SourceResponse:
        return boldsign_source(
            region=config.region,
            api_key=config.api_key,
            endpoint=inputs.schema_name,
            team_id=inputs.team_id,
            job_id=inputs.job_id,
            resumable_source_manager=resumable_source_manager,
        )