: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(warehouse_sources): support framer API version 5.1.0 (#113213)
Tom Owersa9767872b8f8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.pyindex 7fe670eed5b9..e95c6f46b20a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py@@ -14,7 +14,7 @@ import timeimport socketimport http.clientfrom collections.abc import Callable, Iterator-from typing import Any, Optional, Protocol+from typing import Any, Optional, Protocol, TypedDictfrom urllib.parse import unquote, urlencode, urljoin, urlsplitfrom structlog.types import FilteringBoundLogger@@ -35,6 +35,22 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.framer.setFRAMER_HEADLESS_WS_URL = "wss://api.framer.com/channel/headless-plugin"+FRAMER_SDK_VERSION_0_1_29 = "0.1.29"+FRAMER_SDK_VERSION_5_1_0 = "5.1.0"+++class CollectionMethods(TypedDict):+ fields: str+ items: str+++# framer-api 5.x reads CMS collections through the `3` RPCs, whose array fields can nest+# any scalar field type, not just images.+COLLECTION_METHODS_BY_VERSION: dict[str, CollectionMethods] = {+ FRAMER_SDK_VERSION_0_1_29: {"fields": "getCollectionFields2", "items": "getCollectionItems2"},+ FRAMER_SDK_VERSION_5_1_0: {"fields": "getCollectionFields3", "items": "getCollectionItems3"},+}+# The server boots a headless instance of the project on connect, which can take a while# for large projects — the official SDK allows 90s, so we do too.CONNECT_TIMEOUT_SECONDS = 90@@ -150,6 +166,10 @@ class FramerClient:self._next_invocation_id = 0self._chunk_buffers: dict[str, list[str]] = {}+ @property+ def protocol_version(self) -> str:+ return self._protocol_version+def __enter__(self) -> "FramerClient":self.connect()return self@@ -333,6 +353,13 @@ def validate_credentials(project: str, api_key: str, protocol_version: str) -> treturn False, "Couldn't connect to Framer. Check the project URL and API key, then try again."+def _collection_methods(protocol_version: str) -> CollectionMethods:+ methods = COLLECTION_METHODS_BY_VERSION.get(protocol_version)+ if methods is None:+ raise ValueError(f"Unsupported Framer SDK version: {protocol_version}")+ return methods++def _without_class_marker(node: dict[str, Any]) -> dict[str, Any]:return {key: value for key, value in node.items() if key != "__class"}@@ -364,9 +391,10 @@ def _pages_rows(client: FramerClient) -> Iterator[list[dict[str, Any]]]:def _collections_rows(client: FramerClient) -> Iterator[list[dict[str, Any]]]:+ methods = _collection_methods(client.protocol_version)rows = []for collection in _as_dict_rows(client.call("getCollections")):- fields = _as_dict_rows(client.call("getCollectionFields2", collection["id"], True))+ fields = _as_dict_rows(client.call(methods["fields"], collection["id"], True))rows.append({**collection, "fields": fields})if rows:yield rows@@ -414,11 +442,12 @@ def _collection_item_row(def _collection_items_rows(client: FramerClient) -> Iterator[list[dict[str, Any]]]:+ methods = _collection_methods(client.protocol_version)for collection in _as_dict_rows(client.call("getCollections")):collection_id = collection["id"]- fields = _as_dict_rows(client.call("getCollectionFields2", collection_id, True))+ fields = _as_dict_rows(client.call(methods["fields"], collection_id, True))field_names = {field.get("id"): str(field.get("name")) for field in fields if field.get("name")}- items = _as_dict_rows(client.call("getCollectionItems2", collection_id))+ items = _as_dict_rows(client.call(methods["items"], collection_id))rows = [_collection_item_row(item, collection, field_names) for item in items]if rows:yield rowsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/source.pyindex 872524588318..86e9c1d5e53e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/source.py@@ -18,6 +18,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sch)from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs, SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer.framer import (+ FRAMER_SDK_VERSION_0_1_29,+ FRAMER_SDK_VERSION_5_1_0,framer_source,validate_credentials as validate_framer_credentials,)@@ -35,8 +37,8 @@ class FramerSource(SimpleSource[FramerSourceConfig]):# Framer has no REST API; the official surface is the `framer-api` SDK's WebSocket# protocol, and the pinned version is the SDK release whose message contract we speak# (sent as the `sdkVersion` connection parameter).- supported_versions = ("0.1.29",)- default_version = "0.1.29"+ supported_versions = (FRAMER_SDK_VERSION_0_1_29, FRAMER_SDK_VERSION_5_1_0)+ default_version = FRAMER_SDK_VERSION_5_1_0api_docs_url = "https://www.framer.com/developers/server-api-introduction"@propertydiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.pyindex 4ff57ca5d56a..a4266dab15ab 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py@@ -15,6 +15,7 @@ from websockets.exceptions import InvalidMessagefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer import devaluefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer.framer import (+ COLLECTION_METHODS_BY_VERSION,FramerAPIError,FramerClient,framer_source,@@ -29,6 +30,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.framer.setPROJECT_ID = "a" * 20+COLLECTION_METHOD_CASES = [+ (version, methods["fields"], methods["items"]) for version, methods in COLLECTION_METHODS_BY_VERSION.items()+]+class FakeFramerServer:"""Scripted in-memory stand-in for the Framer headless WebSocket channel."""@@ -123,8 +128,8 @@ def no_ambient_proxy(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.delenv(name)-def make_client(server: FakeFramerServer) -> FramerClient:- client = FramerClient(PROJECT_ID, "test-key", protocol_version="0.1.29", connect_fn=server)+def make_client(server: FakeFramerServer, protocol_version: str = "0.1.29") -> FramerClient:+ client = FramerClient(PROJECT_ID, "test-key", protocol_version=protocol_version, connect_fn=server)client.connect()return client@@ -232,14 +237,15 @@ class TestFramer:def test_parse_project_id_rejects_invalid(self, value: str) -> None:assert parse_project_id(value) is None- def test_client_handshake_and_call(self) -> None:+ @parameterized.expand([(version,) for version in COLLECTION_METHODS_BY_VERSION])+ def test_client_handshake_and_call(self, protocol_version: str) -> None:server = FakeFramerServer(methods={"getProjectInfo2": {"id": PROJECT_ID, "name": "Site"}})- client = make_client(server)+ client = make_client(server, protocol_version)assert client.call("getProjectInfo2") == {"id": PROJECT_ID, "name": "Site"}assert server.sent[0] == {"type": "pluginReadySignal"}assert "Authorization" in server.connect_kwargs["additional_headers"]assert f"projectId={PROJECT_ID}" in server.url- assert "sdkVersion=0.1.29" in server.url+ assert f"sdkVersion={protocol_version}" in server.urldef test_client_close_sends_graceful_disconnect(self) -> None:server = FakeFramerServer(graceful_disconnect=True)@@ -396,9 +402,11 @@ class TestFramer:assert "Framer API error" not in errorassert "try again" in error- def _run_endpoint(self, endpoint: str, methods: dict[str, Any]) -> list[dict[str, Any]]:+ def _run_endpoint(+ self, endpoint: str, methods: dict[str, Any], protocol_version: str = "0.1.29"+ ) -> list[dict[str, Any]]:server = FakeFramerServer(methods=methods)- response = framer_source(PROJECT_ID, "key", endpoint, protocol_version="0.1.29")+ response = framer_source(PROJECT_ID, "key", endpoint, protocol_version=protocol_version)assert response.name == endpointassert response.primary_keys == PRIMARY_KEYS[endpoint]with pytest.MonkeyPatch.context() as patcher:@@ -446,13 +454,17 @@ class TestFramer:)assert rows == [{"id": "page-1", "path": "/about", "collectionId": None, "draft": False}]- def test_collections_rows_include_fields(self) -> None:+ @parameterized.expand(COLLECTION_METHOD_CASES)+ def test_collections_rows_include_fields(+ self, protocol_version: str, fields_method: str, _items_method: str+ ) -> None:rows = self._run_endpoint("Collections",{"getCollections": [{"id": "c1", "name": "Blog", "readonly": False, "managedBy": "user"}],- "getCollectionFields2": [{"id": "f1", "name": "Title", "type": "string"}],+ fields_method: [{"id": "f1", "name": "Title", "type": "string"}],},+ protocol_version,)assert rows == [{@@ -464,16 +476,17 @@ class TestFramer:}]- def test_collection_items_rows(self) -> None:+ @parameterized.expand(COLLECTION_METHOD_CASES)+ def test_collection_items_rows(self, protocol_version: str, fields_method: str, items_method: str) -> None:rows = self._run_endpoint("CollectionItems",{"getCollections": [{"id": "c1", "name": "Blog"}],- "getCollectionFields2": [+ fields_method: [{"id": "f1", "name": "Title", "type": "string"},{"id": "f2", "name": "Title", "type": "string"},],- "getCollectionItems2": [+ items_method: [{"nodeId": "n1","externalId": None,@@ -490,6 +503,7 @@ class TestFramer:}],},+ protocol_version,)assert rows == [{diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer_source.pyindex 736248b707f6..044ac9e5c099 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer_source.py@@ -4,6 +4,7 @@ from unittest import mockfrom parameterized import parameterized+from products.warehouse_sources.backend.temporal.data_imports.sources.framer.framer import COLLECTION_METHODS_BY_VERSIONfrom products.warehouse_sources.backend.temporal.data_imports.sources.framer.source import FramerSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.framer import FramerSourceConfig@@ -22,7 +23,8 @@ def _inputs(schema_name: str, api_version: str | None = None) -> Any:class TestFramerSource:@parameterized.expand([- (None, "0.1.29"), # no pin falls back to default_version+ (None, "5.1.0"), # no pin falls back to default_version+ ("0.1.29", "0.1.29"),("9.9.9", "9.9.9"), # a stored pin is honored verbatim])@@ -43,6 +45,9 @@ class TestFramerSource:logger=inputs.logger,)+ def test_every_supported_version_has_collection_methods(self) -> None:+ assert set(COLLECTION_METHODS_BY_VERSION) == set(FramerSource.supported_versions)+def test_broken_code_component_is_non_retryable(self) -> None:# Framer's headless loader raises this identically on every retry when a project's# code component references a module the headless runtime can't resolve — a project