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.

feat(boldsign): sync contact groups, custom fields and team documents (#99806)

Tom Owers47da471afb8b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 42a5baa6958d..ebebef3d742f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -889,14 +889,14 @@ Note: Coverage is otherwise complete — every list-\* endpoint in the reference
## BoldSign — gaps
-Today (7): `brands`, `contacts`, `documents`, `sender_identities`, `teams`, `templates`, `users`
+Today (11): `behalf_documents`, `brands`, `contact_groups`, `contacts`, `custom_fields`, `documents`, `sender_identities`, `team_documents`, `teams`, `templates`, `users`
Diffed against: <https://api.boldsign.com/swagger/v1/swagger.json>
-- [ ] `GET /v1/contactGroups/list` — lookup resolving the contact group IDs carried on the contacts we already sync (high)
-- [ ] `GET /v1/customField/list` — brand-scoped custom field definitions that resolve field IDs appearing on documents and templates (medium)
-- [ ] `GET /v1/document/teamlist` — documents across the whole team, broader than the API user's own document list (medium)
-- [ ] `GET /v1/document/behalfList` — documents sent on behalf of others, otherwise invisible in the documents table (low)
+- [x] `GET /v1/contactGroups/list` — lookup resolving the contact group IDs carried on the contacts we already sync (high)
+- [x] `GET /v1/customField/list` — brand-scoped custom field definitions that resolve field IDs appearing on documents and templates (medium)
+- [x] `GET /v1/document/teamlist` — documents across the whole team, broader than the API user's own document list (medium)
+- [x] `GET /v1/document/behalfList` — documents sent on behalf of others, otherwise invisible in the documents table (low)
Note: Remaining GETs are file downloads (document/template/audit-log PDFs), single-object detail lookups, or billing credit counts — none are queryable collections. /v1/plan/apiCreditsCount was excluded as billing config.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/boldsign.py b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/boldsign.py
index 745adb8dda34..4fe786e40c6c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/boldsign.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/boldsign.py
@@ -4,8 +4,10 @@ from typing import Any, Optional
import structlog
from requests import Request, Response
+from products.warehouse_sources.backend.temporal.data_imports.sources.boldsign.fanout import boldsign_fanout_source
from products.warehouse_sources.backend.temporal.data_imports.sources.boldsign.settings import (
BOLDSIGN_ENDPOINTS,
+ PAGE_SIZE,
BoldSignEndpointConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
@@ -28,8 +30,8 @@ BOLDSIGN_HOSTS = {
"us": "https://api.boldsign.com",
"eu": "https://api-eu.boldsign.com",
}
-PAGE_SIZE = 100
-# Page-number access is capped at 10,000 records; document/list pages past it via NextCursor.
+# Page-number access is capped at 10,000 records; the document list endpoints page past it via
+# NextCursor.
RECORD_CURSOR_THRESHOLD = 10_000
@@ -62,9 +64,9 @@ class BoldSignPaginator(BasePaginator):
"""Page-number pagination with BoldSign's 10,000-record page-number cap.
Standard pages advance ``Page``; once the running record count crosses the cap, endpoints that
- support it (document/list) switch to cursor paging via ``NextCursor`` (taken from the last
- row's ``cursor`` field, with ``Page`` reset to 1). Endpoints without cursor support stop at
- the cap rather than loop.
+ support it (the document list endpoints) switch to cursor paging via ``NextCursor`` (taken
+ from the last row's ``cursor`` field, with ``Page`` reset to 1). Endpoints without cursor
+ support stop at the cap rather than loop.
"""
def __init__(self, endpoint: str, supports_cursor: bool) -> None:
@@ -171,6 +173,9 @@ def boldsign_source(
) -> SourceResponse:
config: BoldSignEndpointConfig = BOLDSIGN_ENDPOINTS[endpoint]
+ if config.fanout is not None:
+ return boldsign_fanout_source(_base_url(region), api_key, endpoint, team_id, job_id)
+
paginator: BasePaginator
if config.paginated:
paginator = BoldSignPaginator(endpoint=endpoint, supports_cursor=config.supports_cursor)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/canonical_descriptions.py
index f09597fd2493..011b48802e16 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/canonical_descriptions.py
@@ -2,29 +2,44 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.can
CanonicalDescriptions,
)
+# `document/list`, `document/teamlist` and `document/behalfList` all return the same row shape.
+_DOCUMENT_COLUMNS: dict[str, str] = {
+ "documentId": "Unique identifier of the document.",
+ "messageTitle": "Title of the document shown to recipients.",
+ "status": "Current status of the document (e.g. InProgress, Completed, Declined, Revoked, Expired, Draft).",
+ "displayStatus": "Human-readable status label for display.",
+ "senderDetail": "Details of the user who sent the document.",
+ "ccDetails": "Recipients copied on the document.",
+ "signerDetails": "Recipients required to act on the document, with their roles and status.",
+ "createdDate": "Unix epoch timestamp for when the document was created.",
+ "activityDate": "Unix epoch timestamp of the most recent activity on the document.",
+ "activityBy": "Email of the user responsible for the most recent activity.",
+ "expiryDate": "Unix epoch timestamp for when the document expires.",
+ "scheduledSendTime": "Unix epoch timestamp for a scheduled send, if configured.",
+ "enableSigningOrder": "Whether recipients must sign in a defined order.",
+ "isDeleted": "Whether the document has been deleted.",
+ "inEditingMode": "Whether the document is currently being edited.",
+ "labels": "Labels applied to the document.",
+ "brandId": "Identifier of the brand applied to the document.",
+ "cursor": "Opaque pagination cursor used to page past the 10,000-record limit.",
+}
+
CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"documents": {
"description": "Signature documents sent from the account, including their status, signers, and lifecycle dates.",
"docs_url": "https://developers.boldsign.com/documents/list-documents/",
+ "columns": _DOCUMENT_COLUMNS,
+ },
+ "team_documents": {
+ "description": "Signature documents across every team the account can see, a wider set than the API user's own documents.",
+ "docs_url": "https://developers.boldsign.com/documents/list-team-documents/",
+ "columns": _DOCUMENT_COLUMNS,
+ },
+ "behalf_documents": {
+ "description": "Signature documents the API user sent on behalf of another sender identity.",
"columns": {
- "documentId": "Unique identifier of the document.",
- "messageTitle": "Title of the document shown to recipients.",
- "status": "Current status of the document (e.g. InProgress, Completed, Declined, Revoked, Expired, Draft).",
- "displayStatus": "Human-readable status label for display.",
- "senderDetail": "Details of the user who sent the document.",
- "ccDetails": "Recipients copied on the document.",
- "signerDetails": "Recipients required to act on the document, with their roles and status.",
- "createdDate": "Unix epoch timestamp for when the document was created.",
- "activityDate": "Unix epoch timestamp of the most recent activity on the document.",
- "activityBy": "Email of the user responsible for the most recent activity.",
- "expiryDate": "Unix epoch timestamp for when the document expires.",
- "scheduledSendTime": "Unix epoch timestamp for a scheduled send, if configured.",
- "enableSigningOrder": "Whether recipients must sign in a defined order.",
- "isDeleted": "Whether the document has been deleted.",
- "inEditingMode": "Whether the document is currently being edited.",
- "labels": "Labels applied to the document.",
- "brandId": "Identifier of the brand applied to the document.",
- "cursor": "Opaque pagination cursor used to page past the 10,000-record limit.",
+ "behalfOf": "Name and email of the sender the document was sent on behalf of.",
+ **_DOCUMENT_COLUMNS,
},
},
"templates": {
@@ -86,6 +101,15 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"phoneNumber": "Phone number of the contact.",
},
},
+ "contact_groups": {
+ "description": "Named groups of address-book contacts that can be added to a document together.",
+ "columns": {
+ "groupId": "Unique identifier of the contact group.",
+ "groupName": "Name of the contact group.",
+ "contacts": "Members of the group, each with a name and email address.",
+ "directories": "Directories the group is sourced from.",
+ },
+ },
"sender_identities": {
"description": "Verified sender identities that documents can be sent on behalf of.",
"docs_url": "https://developers.boldsign.com/sender-identities/list-sender-identities/",
@@ -117,4 +141,16 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"documentTimeZone": "Time zone applied to documents using this brand.",
},
},
+ "custom_fields": {
+ "description": "Reusable custom field definitions belonging to a brand, resolving the field identifiers that appear on documents and templates.",
+ "columns": {
+ "customFieldId": "Unique identifier of the custom field within its brand.",
+ "brandId": "Identifier of the brand the custom field belongs to.",
+ "fieldName": "Name of the custom field.",
+ "fieldDescription": "Description of the custom field.",
+ "fieldOrder": "Position of the custom field in the brand's field list.",
+ "sharedField": "Whether the custom field is shared across the account.",
+ "formField": "Form field definition (type, size, validation and styling) applied when the field is placed on a document.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/fanout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/fanout.py
new file mode 100644
index 000000000000..242a8e91537e
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/fanout.py
@@ -0,0 +1,70 @@
+from collections.abc import Iterable
+from typing import Any, cast
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.boldsign.settings import BOLDSIGN_ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ build_dependent_resource,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
+ SinglePagePaginator,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
+
+
+def _client_config(base_url: str, api_key: str) -> ClientConfig:
+ return {
+ "base_url": base_url,
+ # The API key rides the framework auth config so its value is redacted from logs; only
+ # the non-secret Accept header is set here.
+ "headers": {"Accept": "application/json"},
+ "auth": {"type": "api_key", "api_key": api_key, "name": "X-API-KEY", "location": "header"},
+ "paginator": SinglePagePaginator(),
+ }
+
+
+def boldsign_fanout_source(
+ base_url: str,
+ api_key: str,
+ endpoint: str,
+ team_id: int,
+ job_id: str,
+) -> SourceResponse:
+ """Build an endpoint that BoldSign only exposes per parent row, e.g. custom fields per brand."""
+ config = BOLDSIGN_ENDPOINTS[endpoint]
+ fanout = config.fanout
+ if fanout is None:
+ raise ValueError(f"BoldSign endpoint {endpoint} has no fan-out configured")
+ parent_config = BOLDSIGN_ENDPOINTS[fanout.parent_name]
+
+ # Neither side of this fan-out paginates, and the shared fan-out helper has no resume support:
+ # the brand list is small and the children are replaced wholesale each run.
+ resource = cast(
+ Iterable[Any],
+ build_dependent_resource(
+ endpoint_configs=BOLDSIGN_ENDPOINTS,
+ child_endpoint=endpoint,
+ fanout=fanout,
+ client_config=_client_config(base_url, api_key),
+ path_format_values={},
+ team_id=team_id,
+ job_id=job_id,
+ db_incremental_field_last_value=None,
+ # Neither endpoint takes a page-size param.
+ page_size_param=None,
+ parent_endpoint_extra={
+ "data_selector": parent_config.data_key,
+ "paginator": SinglePagePaginator(),
+ },
+ child_endpoint_extra={
+ "data_selector": config.data_key,
+ "paginator": SinglePagePaginator(),
+ },
+ ),
+ )
+ return SourceResponse(
+ name=endpoint,
+ items=lambda: resource,
+ primary_keys=config.primary_keys,
+ partition_mode=None,
+ )
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/settings.py
index 9e433612f4e2..363227fa288a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/settings.py
@@ -1,7 +1,16 @@
-from dataclasses import dataclass, field
+from dataclasses import field
+from posthog.dataclasses import frozen
-@dataclass
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
+from products.warehouse_sources.backend.types import IncrementalField
+
+PAGE_SIZE = 100
+
+
+@frozen
class BoldSignEndpointConfig:
name: str
path: str
@@ -10,19 +19,27 @@ class BoldSignEndpointConfig:
primary_keys: list[str] = field(default_factory=lambda: ["documentId"])
# `brand/list` returns the full set in one response with no pagination params.
paginated: bool = True
- # Only `document/list` exposes a `cursor` field + `NextCursor` param to page past the
- # 10,000-record cap that page-number access is limited to. Other endpoints stay page-only.
+ # Only the document list endpoints expose a `cursor` field + `NextCursor` param to page past
+ # the 10,000-record cap that page-number access is limited to. Others stay page-only.
supports_cursor: bool = False
# Static query params always sent for the endpoint (e.g. widening filters to "all").
extra_params: dict[str, str] = field(default_factory=dict)
should_sync_default: bool = True
+ # Set when the endpoint is only reachable per parent row (e.g. custom fields per brand).
+ fanout: DependentEndpointConfig | None = None
+ # Every BoldSign endpoint is full refresh; these stay empty but satisfy the fan-out helper's
+ # endpoint protocol.
+ incremental_fields: list[IncrementalField] = field(default_factory=list)
+ default_incremental_field: str | None = None
+ page_size: int = PAGE_SIZE
# Curated catalog of the BoldSign list endpoints a user is likely to sync. Cross-referenced
# against the public Swagger (https://api.boldsign.com/swagger/v1/swagger.json). Every endpoint
-# is full refresh: the only server-side date filter BoldSign documents (document/list's
-# StartDate/EndDate with DateFilterType=SentBetween) filters on the document *transmit* date and
-# has no matching stable cursor field in the response, so there is no reliable incremental field.
+# is full refresh: the only server-side date filter BoldSign documents (the document list
+# endpoints' StartDate/EndDate with DateFilterType=SentBetween) filters on the document
+# *transmit* date and has no matching stable cursor field in the response, so there is no
+# reliable incremental field.
BOLDSIGN_ENDPOINTS: dict[str, BoldSignEndpointConfig] = {
"documents": BoldSignEndpointConfig(
name="documents",
@@ -30,6 +47,26 @@ BOLDSIGN_ENDPOINTS: dict[str, BoldSignEndpointConfig] = {
primary_keys=["documentId"],
supports_cursor=True,
),
+ "team_documents": BoldSignEndpointConfig(
+ name="team_documents",
+ path="/v1/document/teamlist",
+ primary_keys=["documentId"],
+ supports_cursor=True,
+ # Off by default: on a team account this is a superset of `documents`, so syncing both
+ # by default would bill most rows twice.
+ should_sync_default=False,
+ ),
+ "behalf_documents": BoldSignEndpointConfig(
+ name="behalf_documents",
+ path="/v1/document/behalfList",
+ primary_keys=["documentId"],
+ supports_cursor=True,
+ # PageType has no documented server-side default, so pick one rather than depend on it.
+ # BehalfOfOthers is the sense the endpoint exists for — documents the API user sent for
+ # someone else. Documents others sent for the API user (BehalfOfMe) are not synced.
+ extra_params={"PageType": "BehalfOfOthers"},
+ should_sync_default=False,
+ ),
"templates": BoldSignEndpointConfig(
name="templates",
path="/v1/template/list",
@@ -55,6 +92,12 @@ BOLDSIGN_ENDPOINTS: dict[str, BoldSignEndpointConfig] = {
primary_keys=["id"],
extra_params={"ContactType": "AllContacts"},
),
+ "contact_groups": BoldSignEndpointConfig(
+ name="contact_groups",
+ path="/v1/contactGroups/list",
+ primary_keys=["groupId"],
+ extra_params={"ContactType": "AllContacts"},
+ ),
"sender_identities": BoldSignEndpointConfig(
name="sender_identities",
path="/v1/senderIdentities/list",
@@ -66,6 +109,22 @@ BOLDSIGN_ENDPOINTS: dict[str, BoldSignEndpointConfig] = {
primary_keys=["brandId"],
paginated=False,
),
+ "custom_fields": BoldSignEndpointConfig(
+ name="custom_fields",
+ # brandId is a required query param, so it is bound into the path by the fan-out.
+ path="/v1/customField/list?brandId={brandId}",
+ primary_keys=["brandId", "customFieldId"],
+ paginated=False,
+ fanout=DependentEndpointConfig(
+ parent_name="brands",
+ resolve_param="brandId",
+ resolve_field="brandId",
+ # The response's own brandId is nullable, so take the parent's value — it is half of
+ # the primary key.
+ include_from_parent=["brandId"],
+ parent_field_renames={"brandId": "brandId"},
+ ),
+ ),
}
ENDPOINTS = tuple(BOLDSIGN_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/tests/test_boldsign.py b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/tests/test_boldsign.py
index f88afaf2e6c7..bd5f73a63be8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/tests/test_boldsign.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/boldsign/tests/test_boldsign.py
@@ -161,12 +161,36 @@ class TestPagination:
assert rows == [{"teamId": "T1"}]
+ @pytest.mark.parametrize(
+ "endpoint, param, expected",
+ [
+ ("templates", "TemplateType", "all"),
+ ("contacts", "ContactType", "AllContacts"),
+ ("contact_groups", "ContactType", "AllContacts"),
+ # PageType has no documented server-side default, so it must be sent explicitly.
+ ("behalf_documents", "PageType", "BehalfOfOthers"),
+ ],
+ )
@mock.patch(CLIENT_SESSION_PATCH)
- def test_templates_send_template_type_param(self, MockSession) -> None:
+ def test_endpoints_send_their_widening_params(self, MockSession, endpoint, param, expected) -> None:
session = MockSession.return_value
- _, params, _ = _run("templates", [_response([{"documentId": "T1"}])], session)
+ _, params, _ = _run(endpoint, [_response([{"documentId": "X1"}])], session)
- assert params[0]["TemplateType"] == "all"
+ assert params[0][param] == expected
+
+ @pytest.mark.parametrize("endpoint", ["team_documents", "behalf_documents"])
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_document_variants_switch_to_cursor_past_record_threshold(self, MockSession, endpoint) -> None:
+ session = MockSession.return_value
+ threshold_pages = boldsign.RECORD_CURSOR_THRESHOLD // PAGE_SIZE
+ full_pages = [
+ _response([{"documentId": f"D{p}-{i}", "cursor": p * PAGE_SIZE + i} for i in range(PAGE_SIZE)])
+ for p in range(threshold_pages)
+ ]
+ _, params, _ = _run(endpoint, [*full_pages, _response([{"documentId": "after-cursor"}])], session)
+
+ assert params[-1]["NextCursor"] == boldsign.RECORD_CURSOR_THRESHOLD - 1
+ assert params[-1]["Page"] == 1
@mock.patch(CLIENT_SESSION_PATCH)
def test_api_key_supplied_via_framework_auth(self, MockSession) -> None:
@@ -276,8 +300,12 @@ class TestSourceResponse:
("users", ["userId"]),
("teams", ["teamId"]),
("contacts", ["id"]),
+ ("contact_groups", ["groupId"]),
("sender_identities", ["id"]),
("brands", ["brandId"]),
+ ("team_documents", ["documentId"]),
+ ("behalf_documents", ["documentId"]),
+ ("custom_fields", ["brandId", "customFieldId"]),
],
)
def test_primary_keys_per_endpoint(self, endpoint: str, expected_pk: list[str]) -> None:
@@ -296,6 +324,75 @@ class TestSourceResponse:
assert response.primary_keys == BOLDSIGN_ENDPOINTS[endpoint].primary_keys
+class TestCustomFieldsFanout:
+ """`customField/list` needs a brandId, so it fans out over the brands endpoint."""
+
+ @staticmethod
+ def _wire_urls(session: mock.MagicMock, responses: list[Response]) -> list[str]:
+ session.headers = {}
+ urls: list[str] = []
+
+ def _prepare(request: Any) -> mock.MagicMock:
+ urls.append(request.url)
+ return mock.MagicMock()
+
+ session.prepare_request.side_effect = _prepare
+ session.send.side_effect = responses
+ return urls
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_fans_out_over_every_brand(self, MockSession) -> None:
+ session = MockSession.return_value
+ urls = self._wire_urls(
+ session,
+ [
+ _response([{"brandId": "B1"}, {"brandId": "B2"}]),
+ _response([{"customFieldId": "F1", "brandId": "B1"}]),
+ # The response's own brandId is nullable, so the parent's value must fill it in.
+ _response([{"customFieldId": "F2", "brandId": None}]),
+ ],
+ )
+
+ rows = _rows(
+ boldsign_source(
+ region="us",
+ api_key="key",
+ endpoint="custom_fields",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ )
+ )
+
+ assert [url for url in urls if "customField" in url] == [
+ "https://api.boldsign.com/v1/customField/list?brandId=B1",
+ "https://api.boldsign.com/v1/customField/list?brandId=B2",
+ ]
+ assert rows == [
+ {"customFieldId": "F1", "brandId": "B1"},
+ {"customFieldId": "F2", "brandId": "B2"},
+ ]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_no_brands_makes_no_child_requests(self, MockSession) -> None:
+ session = MockSession.return_value
+ self._wire_urls(session, [_response([])])
+
+ rows = _rows(
+ boldsign_source(
+ region="us",
+ api_key="key",
+ endpoint="custom_fields",
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ )
+ )
+
+ assert rows == []
+ assert session.send.call_count == 1
+
+
class TestValidateCredentials:
@pytest.mark.parametrize(
"status_code, expected_valid, expected_message",