dex-connector-basecamp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. dex_connector_basecamp-0.1.0/.gitignore +16 -0
  2. dex_connector_basecamp-0.1.0/LICENSE +21 -0
  3. dex_connector_basecamp-0.1.0/PKG-INFO +17 -0
  4. dex_connector_basecamp-0.1.0/README.md +5 -0
  5. dex_connector_basecamp-0.1.0/examples/__init__.py +2 -0
  6. dex_connector_basecamp-0.1.0/examples/accounts/README.md +5 -0
  7. dex_connector_basecamp-0.1.0/examples/accounts/__init__.py +2 -0
  8. dex_connector_basecamp-0.1.0/examples/accounts/flow.py +79 -0
  9. dex_connector_basecamp-0.1.0/examples/accounts/integration_test.py +76 -0
  10. dex_connector_basecamp-0.1.0/examples/accounts/worker.py +52 -0
  11. dex_connector_basecamp-0.1.0/pyproject.toml +37 -0
  12. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/__init__.py +24 -0
  13. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/__init__.py +2 -0
  14. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/config.py +28 -0
  15. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/connection.py +177 -0
  16. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/definitions.py +38 -0
  17. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/mock.py +68 -0
  18. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/models.py +58 -0
  19. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/refresh.py +9 -0
  20. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/_generated/steps.py +78 -0
  21. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/basecampmock/__init__.py +6 -0
  22. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/client.py +106 -0
  23. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/connection.py +8 -0
  24. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/dex-connector.json +64 -0
  25. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/models.py +9 -0
  26. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/operations.py +116 -0
  27. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/py.typed +0 -0
  28. dex_connector_basecamp-0.1.0/src/dex_connectors/basecamp/steps.py +5 -0
  29. dex_connector_basecamp-0.1.0/tests/refresh_agreement_cases.json +531 -0
  30. dex_connector_basecamp-0.1.0/tests/test_conformance.py +47 -0
  31. dex_connector_basecamp-0.1.0/tests/test_manifest_contract.py +15 -0
  32. dex_connector_basecamp-0.1.0/tests/test_refresh_agreement.py +278 -0
  33. dex_connector_basecamp-0.1.0/uv.lock +934 -0
@@ -0,0 +1,16 @@
1
+ .DS_Store
2
+ __pycache__/
3
+ *.py[cod]
4
+ node_modules/
5
+ dist/
6
+ sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
7
+ /.bin/dexcli
8
+ /.bin/dex-server-zd
9
+ /sdkpython/.dexcli-data/
10
+ site/.catalog.yaml
11
+ coverage/
12
+ *.out
13
+ *.test
14
+ go.work
15
+ go.work.sum
16
+ .idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Super Durable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.5
2
+ Name: dex-connector-basecamp
3
+ Version: 0.1.0
4
+ Summary: Basecamp connector for Dex Flows
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: dex-connectors-sdk==0.7.0
9
+ Requires-Dist: dex-python-sdk>=1.28.0
10
+ Requires-Dist: httpx>=0.27
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Basecamp connector for Python
14
+
15
+ This package implements `listAccounts` with the shared [manifest](../connector.yaml) and Go-recorded provider scenarios. See the [connector guide](../README.md) for OAuth setup and local pagination behavior. The [runnable account Flow](examples/accounts/README.md) uses the static `basecamp` Dex Web connection.
16
+
17
+ Run `uv sync --locked`, `uv run ruff check .`, `uv run mypy --strict src`, and `uv run pytest tests` from this directory. Live Basecamp authorization and Dex Web field rendering have not been verified.
@@ -0,0 +1,5 @@
1
+ # Basecamp connector for Python
2
+
3
+ This package implements `listAccounts` with the shared [manifest](../connector.yaml) and Go-recorded provider scenarios. See the [connector guide](../README.md) for OAuth setup and local pagination behavior. The [runnable account Flow](examples/accounts/README.md) uses the static `basecamp` Dex Web connection.
4
+
5
+ Run `uv sync --locked`, `uv run ruff check .`, `uv run mypy --strict src`, and `uv run pytest tests` from this directory. Live Basecamp authorization and Dex Web field rendering have not been verified.
@@ -0,0 +1,2 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,5 @@
1
+ # Account discovery Flow (Python)
2
+
3
+ This runnable Flow calls `listAccounts` through the static `basecamp` Dex Web connection. Configure OAuth in the [connector guide](../../../README.md), then run `uv run python -m examples.accounts.worker` from the Python package directory. The result is stored in a declared Attribute.
4
+
5
+ Run `dexcli visualize python/examples/accounts/flow.py --schema-version 2.0 --lint app --json --python python/.venv/bin/python --out /tmp/basecamp-python-fdg --open=false` from the connector directory. With `dexcli dev` running, set `DEX_FLOW_SERVICE_ADDRESS` and run `uv run pytest examples/accounts/integration_test.py` from the Python package directory to verify the real Worker and Client path against a local provider fixture. Live Basecamp authorization has not been verified.
@@ -0,0 +1,2 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,79 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Runnable Basecamp page Flow using the listAccounts Query."""
4
+
5
+ import dex
6
+ from dex_connectors.sdk import QueryResult
7
+
8
+ from dex_connectors.basecamp import (
9
+ AccountsPage,
10
+ Connection,
11
+ ListAccountsInput,
12
+ new_list_accounts_step,
13
+ )
14
+
15
+ FLOW_TYPE = "BasecampAccountsListPython"
16
+ CONNECTION_NAME = "basecamp"
17
+ _CALL_STEP_TYPE = "CallListAccounts"
18
+ _RESULT = dex.Attribute("basecamp-python-page", AccountsPage)
19
+
20
+
21
+ def map_to_operation_input(request: ListAccountsInput) -> ListAccountsInput:
22
+ """Send the request unchanged."""
23
+ return request
24
+
25
+
26
+ # dex:group group-id:basecamp group-label:"Basecamp"
27
+ # dex:explanation text:"Start the Basecamp request."
28
+ class _StartRequest(dex.Step[ListAccountsInput]):
29
+ def get_step_type(self) -> str:
30
+ return "StartListAccounts"
31
+
32
+ def execute(self, context: dex.Context, input: ListAccountsInput) -> dex.StepDecision:
33
+ return dex.go_to(dex.StepRef("CallListAccounts"), input)
34
+
35
+
36
+ # dex:group group-id:basecamp group-label:"Basecamp"
37
+ # dex:explanation text:"Record the provider result and complete the Flow."
38
+ class _CompleteRequest(dex.Step[QueryResult[AccountsPage]]):
39
+ def get_step_type(self) -> str:
40
+ return "CompleteListAccounts"
41
+
42
+ def execute(self, context: dex.Context, input: QueryResult[AccountsPage]) -> dex.StepDecision:
43
+ _RESULT.set(context, input.value)
44
+ return dex.graceful_complete(input.value)
45
+
46
+
47
+ class AccountsFlow(dex.Flow[ListAccountsInput]):
48
+ """Run one listAccounts read through the static basecamp connection."""
49
+
50
+ def __init__(self, connection: Connection) -> None:
51
+ if connection.reference.name != CONNECTION_NAME:
52
+ raise ValueError("the accounts lookup Flow requires the static basecamp connection")
53
+ self._start = _StartRequest()
54
+ self._complete = _CompleteRequest()
55
+ self._call = new_list_accounts_step(
56
+ step_type=_CALL_STEP_TYPE,
57
+ step_input_type=ListAccountsInput,
58
+ annotations={
59
+ "groupId": "basecamp",
60
+ "groupLabel": "Basecamp",
61
+ "explanation": "Read one Basecamp page.",
62
+ },
63
+ connection=connection,
64
+ connection_name=CONNECTION_NAME,
65
+ map_to_operation_input=map_to_operation_input,
66
+ listed=self._complete,
67
+ )
68
+
69
+ def get_flow_type(self) -> str:
70
+ """Return the stable Flow identity used in Dex Web."""
71
+ return "BasecampAccountsListPython"
72
+
73
+ def get_steps(self) -> dex.StepList[ListAccountsInput]:
74
+ """Register the start, provider read, and completion Steps."""
75
+ return dex.StepList.start_step(self._start).other_steps(self._call, self._complete)
76
+
77
+ def get_persistence_schema(self) -> dex.PersistenceSchema:
78
+ """Persist the provider result."""
79
+ return dex.PersistenceSchema.of(_RESULT)
@@ -0,0 +1,76 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Real Dex Worker and Client verification for the Basecamp Python Flow."""
4
+
5
+ import asyncio
6
+ import os
7
+ from datetime import timedelta
8
+ from pathlib import Path
9
+ from uuid import uuid4
10
+
11
+ import dex
12
+ import httpx
13
+ import pytest
14
+ from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
15
+
16
+ from dex_connectors.basecamp import (
17
+ AccountsPage,
18
+ Client,
19
+ Config,
20
+ Credentials,
21
+ ListAccountsInput,
22
+ new_connection,
23
+ )
24
+
25
+ from .flow import CONNECTION_NAME, AccountsFlow
26
+
27
+
28
+ @pytest.mark.asyncio
29
+ async def test_accounts_retries_503(tmp_path: Path) -> None:
30
+ """Run the checked-in Flow across real Dex retry and persistence boundaries."""
31
+ address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
32
+ requests: list[httpx.Request] = []
33
+
34
+ def answer(request: httpx.Request) -> httpx.Response:
35
+ assert request.headers["Authorization"] == "Bearer synthetic-basecamp-token"
36
+ assert request.url.path == "/authorization.json"
37
+ requests.append(request)
38
+ if len(requests) == 1:
39
+ return httpx.Response(503)
40
+ return httpx.Response(
41
+ 200, json={"accounts": [{"product": "bc3", "id": 123, "name": "Example Company"}]}
42
+ )
43
+
44
+ reference = ConnectionRef("basecamp", CONNECTION_NAME)
45
+ credentials = Credentials(
46
+ "synthetic-client",
47
+ SecretString("synthetic-secret"),
48
+ SecretString("synthetic-basecamp-token"),
49
+ SecretString("synthetic-refresh"),
50
+ )
51
+ async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as http_client:
52
+ provider = Client(
53
+ Config(base_url="http://127.0.0.1:12345"),
54
+ StaticCredentialProvider({reference: credentials}),
55
+ http_client,
56
+ )
57
+ connection = new_connection(provider, reference)
58
+ flow = AccountsFlow(connection)
59
+ registry = dex.Registry([flow], allow_async_handlers=True)
60
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 24))
61
+ worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=address))
62
+ worker_task = asyncio.create_task(worker.start())
63
+ try:
64
+ await worker.wait_pull_registered(timeout=15)
65
+ async with dex.AsyncClient(registry, cache, dex.ClientOptions(server_address=address)) as client:
66
+ flow_id = f"basecamp-python-{uuid4().hex}"
67
+ await client.start_flow(flow, flow_id, ListAccountsInput())
68
+ result = await asyncio.wait_for(client.wait_for_flow(flow_id, timedelta(seconds=25)), 30)
69
+ assert result.status == dex.FlowStatus.COMPLETED, result.error_message
70
+ assert result.single_output(AccountsPage).accounts[0].id == "123"
71
+ assert len(requests) == 2
72
+ finally:
73
+ await worker.stop()
74
+ await worker_task
75
+ cache.close()
76
+ await connection.aclose()
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Worker entrypoint for the Basecamp page Flow."""
4
+
5
+ import asyncio
6
+ import os
7
+ import tempfile
8
+ from pathlib import Path
9
+
10
+ import dex
11
+ from dex_connectors.sdk.projectconfig import load_from_environment
12
+
13
+ from dex_connectors.basecamp import new_project_connection
14
+
15
+ from .flow import CONNECTION_NAME, AccountsFlow
16
+
17
+
18
+ async def run_worker() -> None:
19
+ """Load the named Dex Web connection and serve Basecamp reads."""
20
+ project = await load_from_environment()
21
+ connection = None
22
+ cache = None
23
+ try:
24
+ connection = new_project_connection(project, CONNECTION_NAME)
25
+ registry = dex.Registry([AccountsFlow(connection)], allow_async_handlers=True)
26
+ cache_directory = os.environ.get(
27
+ "DEX_BLOB_CACHE_DIR",
28
+ str(Path(tempfile.gettempdir()) / "dex-basecamp-python-page-blobs"),
29
+ )
30
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
31
+ worker = dex.AsyncWorker(
32
+ registry,
33
+ cache,
34
+ dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
35
+ )
36
+ async with worker:
37
+ await worker.start()
38
+ finally:
39
+ if connection is not None:
40
+ await connection.aclose()
41
+ if cache is not None:
42
+ cache.close()
43
+ await project.close()
44
+
45
+
46
+ def main() -> None:
47
+ """Run until the Worker stops or the process receives an interrupt."""
48
+ asyncio.run(run_worker())
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "dex-connector-basecamp"
7
+ version = "0.1.0"
8
+ description = "Basecamp connector for Dex Flows"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ dependencies = ["dex-connectors-sdk==0.7.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
13
+
14
+ [dependency-groups]
15
+ dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6", "types-PyYAML>=6"]
16
+
17
+ [tool.hatch.build.targets.wheel]
18
+ packages = ["src/dex_connectors"]
19
+
20
+ [tool.pytest.ini_options]
21
+ testpaths = ["tests"]
22
+ pythonpath = [".", "src"]
23
+ asyncio_mode = "auto"
24
+ asyncio_default_fixture_loop_scope = "function"
25
+
26
+ [tool.mypy]
27
+ python_version = "3.11"
28
+ strict = true
29
+ mypy_path = "src"
30
+ explicit_package_bases = true
31
+
32
+ [tool.ruff]
33
+ target-version = "py311"
34
+ line-length = 110
35
+
36
+ [tool.ruff.lint]
37
+ select = ["E", "F", "I", "UP", "B"]
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Basecamp operations for Dex Python Flows."""
4
+
5
+ from .client import Client, Config, Credentials
6
+ from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
7
+ from .models import Account, AccountsPage, ListAccountsInput
8
+ from .operations import ListAccountsOperation
9
+ from .steps import new_list_accounts_step
10
+
11
+ __all__ = [
12
+ "Account",
13
+ "AccountsPage",
14
+ "Client",
15
+ "Config",
16
+ "Connection",
17
+ "Credentials",
18
+ "ListAccountsInput",
19
+ "ListAccountsOperation",
20
+ "new_connection",
21
+ "new_connection_with_operations",
22
+ "new_list_accounts_step",
23
+ "new_project_connection",
24
+ ]
@@ -0,0 +1,2 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ # ruff: noqa
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from dex_connectors.sdk import SecretString
8
+
9
+
10
+ @dataclass(frozen=True, slots=True)
11
+ class Config:
12
+
13
+ base_url: str = "https://launchpad.37signals.com"
14
+ timeout_seconds: float = 15
15
+ max_response_bytes: int = 1048576
16
+
17
+ setattr(Config, '__module__', 'dex_connectors.basecamp.client')
18
+
19
+
20
+ @dataclass(frozen=True, slots=True)
21
+ class Credentials:
22
+
23
+ oauth_client_id: str
24
+ oauth_client_secret: SecretString
25
+ access_token: SecretString
26
+ refresh_token: SecretString
27
+
28
+ setattr(Credentials, '__module__', 'dex_connectors.basecamp.client')
@@ -0,0 +1,177 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ # ruff: noqa
4
+
5
+ from typing import Any
6
+
7
+ import httpx
8
+ from dex_connectors.sdk import ConnectionRef, Query, Call, SecretString, CredentialRefreshDriver
9
+ from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
10
+ from dex_connectors.sdk.projectconfig.provider import RefreshingCredentialProvider
11
+ from dex_connectors.sdk.oauthtoken import ManifestCredentialRefreshDriver
12
+
13
+ from ..client import Client, Config, Credentials
14
+ from .definitions import CONNECTOR_ID, LIST_ACCOUNTS_DEFINITION
15
+ from .refresh import AUTHORIZATION, CREDENTIAL_FIELDS
16
+ from ..models import AccountsPage, ListAccountsInput
17
+
18
+ class Connection:
19
+
20
+ __slots__ = ('_list_accounts', '_client', 'reference')
21
+
22
+ def __init__(self,
23
+ reference: ConnectionRef,
24
+ list_accounts: Query[ListAccountsInput, AccountsPage],
25
+ client: Client | None = None,
26
+ ) -> None:
27
+ reference.validate()
28
+ if reference.provider != CONNECTOR_ID or list_accounts is None:
29
+ raise ValueError("Basecamp connection provider and operations are required")
30
+ if list_accounts.definition().operation != LIST_ACCOUNTS_DEFINITION.operation:
31
+ raise ValueError("Basecamp connection operation identity differs")
32
+ self.reference = reference
33
+ self._list_accounts = list_accounts
34
+ self._client = client
35
+
36
+ def list_accounts(self) -> Query[ListAccountsInput, AccountsPage]:
37
+ return self._list_accounts
38
+
39
+ async def aclose(self) -> None:
40
+ if self._client is not None:
41
+ await self._client.aclose()
42
+
43
+ def __repr__(self) -> str:
44
+ return "basecamp.Connection([REDACTED])"
45
+
46
+ def __reduce__(self) -> tuple[object, ...]:
47
+ raise TypeError("Basecamp connections cannot be serialized")
48
+
49
+ setattr(Connection, '__module__', 'dex_connectors.basecamp.connection')
50
+
51
+
52
+ def new_connection(client: Client, reference: ConnectionRef) -> Connection:
53
+ if client is None:
54
+ raise ValueError("Basecamp client is required")
55
+ return Connection(reference, client.list_accounts(), client)
56
+
57
+ setattr(new_connection, '__module__', 'dex_connectors.basecamp.connection')
58
+
59
+
60
+ def new_connection_with_operations(
61
+ list_accounts: Query[ListAccountsInput, AccountsPage],
62
+ reference: ConnectionRef,
63
+ ) -> Connection:
64
+ return Connection(reference, list_accounts)
65
+
66
+ setattr(new_connection_with_operations, '__module__', 'dex_connectors.basecamp.connection')
67
+
68
+
69
+ def decode_credentials(material: dict[str, Any], *, shared: bool = False) -> Credentials:
70
+ if not isinstance(material, dict):
71
+ raise ValueError("Basecamp stored credential does not match the connector credential fields")
72
+ if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token')):
73
+ raise ValueError("Basecamp stored credential does not match the connector credential fields")
74
+ is_shared = shared
75
+ oauth_client_id = material.get("oauth_client_id")
76
+ if oauth_client_id is not None and not (isinstance(oauth_client_id, str)):
77
+ raise ValueError("Basecamp credential oauth_client_id has an invalid type")
78
+ oauth_client_secret = material.get("oauth_client_secret")
79
+ if oauth_client_secret is not None and not (isinstance(oauth_client_secret, str)):
80
+ raise ValueError("Basecamp credential oauth_client_secret has an invalid type")
81
+ access_token = material.get("access_token")
82
+ if access_token is not None and not (isinstance(access_token, str)):
83
+ raise ValueError("Basecamp credential access_token has an invalid type")
84
+ refresh_token = material.get("refresh_token")
85
+ if refresh_token is not None and not (isinstance(refresh_token, str)):
86
+ raise ValueError("Basecamp credential refresh_token has an invalid type")
87
+ if not oauth_client_id:
88
+ raise ValueError("Basecamp credential oauth_client_id is required")
89
+ if not oauth_client_secret and not is_shared:
90
+ raise ValueError("Basecamp credential oauth_client_secret is required")
91
+ if not access_token:
92
+ raise ValueError("Basecamp credential access_token is required")
93
+ if not refresh_token and not is_shared:
94
+ raise ValueError("Basecamp credential refresh_token is required")
95
+ return Credentials(oauth_client_id, SecretString(oauth_client_secret or ''), SecretString(access_token), SecretString(refresh_token or ''))
96
+
97
+
98
+ def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
99
+ return decode_credentials(material, shared=True)
100
+
101
+
102
+ def encode_credentials(credentials: Credentials) -> dict[str, Any]:
103
+ material: dict[str, Any] = {}
104
+ if credentials.oauth_client_id:
105
+ material["oauth_client_id"] = credentials.oauth_client_id
106
+ if credentials.oauth_client_secret.reveal():
107
+ material["oauth_client_secret"] = credentials.oauth_client_secret.reveal()
108
+ if credentials.access_token.reveal():
109
+ material["access_token"] = credentials.access_token.reveal()
110
+ if credentials.refresh_token.reveal():
111
+ material["refresh_token"] = credentials.refresh_token.reveal()
112
+ decode_credentials(material)
113
+ return material
114
+
115
+
116
+ class _ProjectCredentialSource:
117
+ def __init__(self, project: LoadedProject, key: ConnectionKey, http_client: httpx.AsyncClient, settings: dict[str, Any]) -> None:
118
+ self.provider = RefreshingCredentialProvider(
119
+ project.connections, key, decode_credentials, encode_credentials, decode_shared_credentials
120
+ )
121
+ self.driver = ManifestCredentialRefreshDriver[Credentials]("Basecamp", AUTHORIZATION, CREDENTIAL_FIELDS, http_client, settings=settings)
122
+
123
+ async def resolve(self, call: Call) -> Credentials:
124
+ return await self.provider.resolve_with_refresh(call, self.driver)
125
+
126
+ async def resolve_with_refresh(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
127
+ return await self.provider.resolve_with_refresh(call, driver or self.driver)
128
+
129
+ async def resolve_after_rejection(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
130
+ return await self.provider.resolve_after_rejection(call, driver or self.driver)
131
+
132
+
133
+ def new_project_connection(
134
+ project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
135
+ ) -> Connection:
136
+ if project is None:
137
+ raise ValueError("Basecamp connection requires loaded project configuration")
138
+ reference = ConnectionRef(CONNECTOR_ID, connection_name)
139
+ reference.validate()
140
+ key = ConnectionKey(CONNECTOR_ID, connection_name)
141
+ matching = [
142
+ entry
143
+ for entry in project.configuration.connections
144
+ if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
145
+ ]
146
+ if len(matching) != 1:
147
+ raise ValueError("Basecamp project connection is missing or duplicated")
148
+ if matching[0].provider != CONNECTOR_ID:
149
+ raise ValueError("Basecamp project connection provider differs")
150
+ config = _decode_config(matching[0].configuration)
151
+ http_client = http_client or httpx.AsyncClient()
152
+ client = Client(config, _ProjectCredentialSource(project, key, http_client, matching[0].configuration), http_client)
153
+ return new_connection(client, reference)
154
+
155
+ setattr(new_project_connection, '__module__', 'dex_connectors.basecamp.connection')
156
+
157
+
158
+ def _decode_config(value: dict[str, Any]) -> Config:
159
+ if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
160
+ raise ValueError("Basecamp configuration has unknown fields")
161
+ config_arguments: dict[str, Any] = {}
162
+ if "baseUrl" in value:
163
+ base_url = value["baseUrl"]
164
+ if not (isinstance(base_url, str)):
165
+ raise ValueError("Basecamp configuration baseUrl has an invalid type")
166
+ config_arguments['base_url'] = base_url
167
+ if "timeout" in value:
168
+ timeout = value["timeout"]
169
+ if not (type(timeout) is int):
170
+ raise ValueError("Basecamp configuration timeout has an invalid type")
171
+ config_arguments['timeout_seconds'] = timeout / 1_000_000_000
172
+ if "maxResponseBytes" in value:
173
+ max_response_bytes = value["maxResponseBytes"]
174
+ if not (type(max_response_bytes) is int):
175
+ raise ValueError("Basecamp configuration maxResponseBytes has an invalid type")
176
+ config_arguments['max_response_bytes'] = max_response_bytes
177
+ return Config(**config_arguments)
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ # ruff: noqa
4
+
5
+ from datetime import timedelta
6
+
7
+ from dex_connectors.sdk import (
8
+ BranchDefinition,
9
+ MutationDefinition,
10
+ OperationRef,
11
+ QueryDefinition,
12
+ RetryPolicy,
13
+ StepDefaults,
14
+ default_connector_step_execute_retry_policy,
15
+ )
16
+
17
+ CONNECTOR_ID = "basecamp"
18
+ PROVIDER = "basecamp"
19
+ LIST_ACCOUNTS_OPERATION_ID = "listAccounts"
20
+ DEFECT = "defect"
21
+ INVALID_RESPONSE = "invalidResponse"
22
+ LISTED = "listed"
23
+ PROVIDER_REJECTED = "providerRejected"
24
+
25
+ LIST_ACCOUNTS_DEFINITION = QueryDefinition(
26
+ OperationRef(CONNECTOR_ID, LIST_ACCOUNTS_OPERATION_ID),
27
+ (
28
+ BranchDefinition(LISTED, "Basecamp returned accessible account identities.", False),
29
+ BranchDefinition(PROVIDER_REJECTED, "Basecamp conclusively rejected the read.", True),
30
+ BranchDefinition(INVALID_RESPONSE, "Basecamp returned malformed or oversized account JSON.", True),
31
+ BranchDefinition(DEFECT, "Local page input or connection credentials are invalid.", True),
32
+ ),
33
+ StepDefaults(
34
+ timedelta(seconds=30),
35
+ 2,
36
+ execute_retry=default_connector_step_execute_retry_policy(),
37
+ ),
38
+ )
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ # ruff: noqa
4
+
5
+ from datetime import datetime
6
+
7
+ from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
8
+ from dex_connectors.sdk.connectormock import Case, Query
9
+
10
+ from ..connection import Connection, new_connection_with_operations
11
+ from ..models import Account, AccountsPage, ListAccountsInput
12
+ from .definitions import CONNECTOR_ID, DEFECT, INVALID_RESPONSE, LISTED, LIST_ACCOUNTS_DEFINITION, PROVIDER_REJECTED
13
+
14
+ def list_accounts_listed(value: AccountsPage, failure: Failure | None = None) -> Case[AccountsPage]:
15
+ return Case.branch_result(LISTED, value, failure)
16
+
17
+ setattr(list_accounts_listed, '__module__', "dex_connectors.basecamp.basecampmock")
18
+
19
+ def list_accounts_provider_rejected(value: AccountsPage, failure: Failure | None = None) -> Case[AccountsPage]:
20
+ return Case.branch_result(PROVIDER_REJECTED, value, failure)
21
+
22
+ setattr(list_accounts_provider_rejected, '__module__', "dex_connectors.basecamp.basecampmock")
23
+
24
+ def list_accounts_invalid_response(value: AccountsPage, failure: Failure | None = None) -> Case[AccountsPage]:
25
+ return Case.branch_result(INVALID_RESPONSE, value, failure)
26
+
27
+ setattr(list_accounts_invalid_response, '__module__', "dex_connectors.basecamp.basecampmock")
28
+
29
+ def list_accounts_defect(value: AccountsPage, failure: Failure | None = None) -> Case[AccountsPage]:
30
+ return Case.branch_result(DEFECT, value, failure)
31
+
32
+ setattr(list_accounts_defect, '__module__', "dex_connectors.basecamp.basecampmock")
33
+
34
+ def list_accounts_retry(failure: Failure, after_seconds: float = 0) -> Case[AccountsPage]:
35
+ return Case.retry(failure, after_seconds)
36
+
37
+ setattr(list_accounts_retry, '__module__', "dex_connectors.basecamp.basecampmock")
38
+
39
+ def list_accounts_listed_default() -> Case[AccountsPage]:
40
+ return Case.branch_result(LISTED, AccountsPage(accounts=(Account(id='99999999', company='Example Company'),), offset=0, limit=100, total=1))
41
+
42
+ setattr(list_accounts_listed_default, '__module__', "dex_connectors.basecamp.basecampmock")
43
+
44
+
45
+ class Mock:
46
+
47
+ def __init__(self, connection_name: str = "basecamp") -> None:
48
+ self.list_accounts_script: Query[ListAccountsInput, AccountsPage] = Query(LIST_ACCOUNTS_DEFINITION)
49
+ self.list_accounts_script.default(list_accounts_listed_default())
50
+ self._connection = new_connection_with_operations(
51
+ list_accounts=self.list_accounts_script,
52
+ reference=ConnectionRef(CONNECTOR_ID, connection_name),
53
+ )
54
+
55
+ def connection(self) -> Connection:
56
+ return self._connection
57
+
58
+ setattr(Mock, '__module__', "dex_connectors.basecamp.basecampmock")
59
+
60
+ __all__ = [
61
+ "Mock",
62
+ "list_accounts_listed",
63
+ "list_accounts_provider_rejected",
64
+ "list_accounts_invalid_response",
65
+ "list_accounts_defect",
66
+ "list_accounts_retry",
67
+ "list_accounts_listed_default",
68
+ ]