dex-connector-activecampaign 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.
- dex_connector_activecampaign-0.1.0/.gitignore +16 -0
- dex_connector_activecampaign-0.1.0/LICENSE +21 -0
- dex_connector_activecampaign-0.1.0/PKG-INFO +15 -0
- dex_connector_activecampaign-0.1.0/README.md +3 -0
- dex_connector_activecampaign-0.1.0/examples/contact_inspection/README.md +11 -0
- dex_connector_activecampaign-0.1.0/examples/contact_inspection/__init__.py +3 -0
- dex_connector_activecampaign-0.1.0/examples/contact_inspection/flow.py +79 -0
- dex_connector_activecampaign-0.1.0/examples/contact_inspection/integration_test.py +75 -0
- dex_connector_activecampaign-0.1.0/examples/contact_inspection/worker.py +52 -0
- dex_connector_activecampaign-0.1.0/pyproject.toml +37 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/__init__.py +26 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/__init__.py +2 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/config.py +25 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/connection.py +139 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/definitions.py +57 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/mock.py +113 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/models.py +72 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/steps.py +131 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/activecampaignmock/__init__.py +6 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/client.py +303 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/connection.py +8 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/dex-connector.json +118 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/models.py +8 -0
- dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/steps.py +6 -0
- dex_connector_activecampaign-0.1.0/tests/test_conformance.py +36 -0
- dex_connector_activecampaign-0.1.0/tests/test_manifest_contract.py +15 -0
- dex_connector_activecampaign-0.1.0/uv.lock +932 -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,15 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-activecampaign
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ActiveCampaign connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# ActiveCampaign Python connector
|
|
14
|
+
|
|
15
|
+
The Python package implements `listContacts` and `getContact` with provider requests and branch decisions replayed against the Go reference. It returns contact ID, email address, and names without embedded relationships. Sign in to [ActiveCampaign](https://www.activecampaign.com/login), open Settings > Developer, and copy the account-specific API URL into `baseUrl` and your API Key into the Dex connection secret. See [the connector README](../README.md) and [the runnable example](examples/contact_inspection/README.md).
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# ActiveCampaign Python connector
|
|
2
|
+
|
|
3
|
+
The Python package implements `listContacts` and `getContact` with provider requests and branch decisions replayed against the Go reference. It returns contact ID, email address, and names without embedded relationships. Sign in to [ActiveCampaign](https://www.activecampaign.com/login), open Settings > Developer, and copy the account-specific API URL into `baseUrl` and your API Key into the Dex connection secret. See [the connector README](../README.md) and [the runnable example](examples/contact_inspection/README.md).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# ActiveCampaign Python contact inspection
|
|
2
|
+
|
|
3
|
+
This runnable Flow calls `listContacts` using the static `activecampaign` connection, stores the page in an Attribute, and completes with the typed result. Sign in at https://www.activecampaign.com/login, open Settings > Developer, copy the account API URL ending in `/api/3` into `baseUrl`, and save the user-specific API Key in the secret field. Blank `baseUrl` is invalid; blank timeout and response-size fields use their displayed defaults.
|
|
4
|
+
|
|
5
|
+
With `DEX_PROJECT_*` and `DEX_FLOW_SERVICE_ADDRESS` set for a running Dex development environment, run from `connectors/activecampaign/python`:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv run python -m examples.contact_inspection.worker
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Start Flow type `ActiveCampaignContactInspection` with a unique Flow ID and input `{"offset":0,"limit":20}`. The Worker has no inbound listener. Optional outcome branches are unwired and fail the Flow when selected.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable ActiveCampaign contact inspection Flow using the listContacts Query."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.activecampaign import (
|
|
9
|
+
Connection,
|
|
10
|
+
ContactsPage,
|
|
11
|
+
ListContactsInput,
|
|
12
|
+
new_list_contacts_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
FLOW_TYPE = "ActiveCampaignContactInspection"
|
|
16
|
+
CONNECTION_NAME = "activecampaign"
|
|
17
|
+
_CALL_STEP_TYPE = "CallActiveCampaign"
|
|
18
|
+
_RESULT = dex.Attribute("activecampaign-contacts-page", ContactsPage)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def map_to_operation_input(request: ListContactsInput) -> ListContactsInput:
|
|
22
|
+
"""Send the request unchanged."""
|
|
23
|
+
return request
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# dex:group group-id:activecampaign group-label:"ActiveCampaign"
|
|
27
|
+
# dex:explanation text:"Start the ActiveCampaign request."
|
|
28
|
+
class _StartRequest(dex.Step[ListContactsInput]):
|
|
29
|
+
def get_step_type(self) -> str:
|
|
30
|
+
return "StartActiveCampaignRequest"
|
|
31
|
+
|
|
32
|
+
def execute(self, context: dex.Context, input: ListContactsInput) -> dex.StepDecision:
|
|
33
|
+
return dex.go_to(dex.StepRef("CallActiveCampaign"), input)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# dex:group group-id:activecampaign group-label:"ActiveCampaign"
|
|
37
|
+
# dex:explanation text:"Record the provider result and complete the Flow."
|
|
38
|
+
class _CompleteRequest(dex.Step[QueryResult[ContactsPage]]):
|
|
39
|
+
def get_step_type(self) -> str:
|
|
40
|
+
return "CompleteActiveCampaignRequest"
|
|
41
|
+
|
|
42
|
+
def execute(self, context: dex.Context, input: QueryResult[ContactsPage]) -> dex.StepDecision:
|
|
43
|
+
_RESULT.set(context, input.value)
|
|
44
|
+
return dex.graceful_complete(input.value)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ContactInspectionFlow(dex.Flow[ListContactsInput]):
|
|
48
|
+
"""Run one listContacts read through the static activecampaign connection."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, connection: Connection) -> None:
|
|
51
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
52
|
+
raise ValueError("the contact inspection requires the static activecampaign connection")
|
|
53
|
+
self._start = _StartRequest()
|
|
54
|
+
self._complete = _CompleteRequest()
|
|
55
|
+
self._call = new_list_contacts_step(
|
|
56
|
+
step_type=_CALL_STEP_TYPE,
|
|
57
|
+
step_input_type=ListContactsInput,
|
|
58
|
+
annotations={
|
|
59
|
+
"groupId": "activecampaign",
|
|
60
|
+
"groupLabel": "ActiveCampaign",
|
|
61
|
+
"explanation": "List contacts accessible to the connected ActiveCampaign account.",
|
|
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 "ActiveCampaignContactInspection"
|
|
72
|
+
|
|
73
|
+
def get_steps(self) -> dex.StepList[ListContactsInput]:
|
|
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,75 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Real Dex Worker and Client verification for the ActiveCampaign 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.activecampaign import (
|
|
17
|
+
Client,
|
|
18
|
+
Config,
|
|
19
|
+
ContactsPage,
|
|
20
|
+
Credentials,
|
|
21
|
+
ListContactsInput,
|
|
22
|
+
new_connection,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from .flow import CONNECTION_NAME, ContactInspectionFlow
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.asyncio
|
|
29
|
+
async def test_contact_inspection_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
|
+
requests.append(request)
|
|
36
|
+
if len(requests) == 1:
|
|
37
|
+
return httpx.Response(503)
|
|
38
|
+
return httpx.Response(
|
|
39
|
+
200,
|
|
40
|
+
json={
|
|
41
|
+
"contacts": [
|
|
42
|
+
{"id": "68", "email": "ada@example.com", "firstName": "Ada", "lastName": "Lovelace"}
|
|
43
|
+
],
|
|
44
|
+
"meta": {"total": "1"},
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
reference = ConnectionRef("activecampaign", CONNECTION_NAME)
|
|
49
|
+
credentials = Credentials(SecretString("synthetic-api-key"))
|
|
50
|
+
async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as http_client:
|
|
51
|
+
provider = Client(
|
|
52
|
+
Config(base_url="http://127.0.0.1:12345/api/3"),
|
|
53
|
+
StaticCredentialProvider({reference: credentials}),
|
|
54
|
+
http_client,
|
|
55
|
+
)
|
|
56
|
+
connection = new_connection(provider, reference)
|
|
57
|
+
flow = ContactInspectionFlow(connection)
|
|
58
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
59
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 24))
|
|
60
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=address))
|
|
61
|
+
worker_task = asyncio.create_task(worker.start())
|
|
62
|
+
try:
|
|
63
|
+
await worker.wait_pull_registered(timeout=15)
|
|
64
|
+
async with dex.AsyncClient(registry, cache, dex.ClientOptions(server_address=address)) as client:
|
|
65
|
+
flow_id = f"activecampaign-python-{uuid4().hex}"
|
|
66
|
+
await client.start_flow(flow, flow_id, ListContactsInput(offset=0, limit=20))
|
|
67
|
+
result = await asyncio.wait_for(client.wait_for_flow(flow_id, timedelta(seconds=25)), 30)
|
|
68
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
69
|
+
assert result.single_output(ContactsPage).contacts[0].id == "68"
|
|
70
|
+
assert len(requests) == 2
|
|
71
|
+
finally:
|
|
72
|
+
await worker.stop()
|
|
73
|
+
await worker_task
|
|
74
|
+
cache.close()
|
|
75
|
+
await connection.aclose()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the ActiveCampaign contact inspection 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.activecampaign import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, ContactInspectionFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the named Dex Web connection and serve ActiveCampaign 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([ContactInspectionFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR",
|
|
28
|
+
str(Path(tempfile.gettempdir()) / "dex-activecampaign-contact-inspection-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-activecampaign"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "ActiveCampaign connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["dex-connectors-sdk==0.1.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,26 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""ActiveCampaign Queries for Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials, GetContactOperation, ListContactsOperation
|
|
6
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
7
|
+
from .models import ContactMetadata, ContactsPage, GetContactInput, ListContactsInput
|
|
8
|
+
from .steps import new_get_contact_step, new_list_contacts_step
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Client",
|
|
12
|
+
"Config",
|
|
13
|
+
"Connection",
|
|
14
|
+
"Credentials",
|
|
15
|
+
"ContactMetadata",
|
|
16
|
+
"ContactsPage",
|
|
17
|
+
"GetContactInput",
|
|
18
|
+
"GetContactOperation",
|
|
19
|
+
"ListContactsInput",
|
|
20
|
+
"ListContactsOperation",
|
|
21
|
+
"new_connection",
|
|
22
|
+
"new_connection_with_operations",
|
|
23
|
+
"new_get_contact_step",
|
|
24
|
+
"new_list_contacts_step",
|
|
25
|
+
"new_project_connection",
|
|
26
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 1048576
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.activecampaign.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
api_key: SecretString
|
|
24
|
+
|
|
25
|
+
setattr(Credentials, '__module__', 'dex_connectors.activecampaign.client')
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, GET_CONTACT_DEFINITION, LIST_CONTACTS_DEFINITION
|
|
13
|
+
from ..models import ContactMetadata, ContactsPage, GetContactInput, ListContactsInput
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_list_contacts', '_get_contact', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
list_contacts: Query[ListContactsInput, ContactsPage],
|
|
22
|
+
get_contact: Query[GetContactInput, ContactMetadata],
|
|
23
|
+
client: Client | None = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
reference.validate()
|
|
26
|
+
if reference.provider != CONNECTOR_ID or list_contacts is None or get_contact is None:
|
|
27
|
+
raise ValueError("ActiveCampaign connection provider and operations are required")
|
|
28
|
+
if list_contacts.definition().operation != LIST_CONTACTS_DEFINITION.operation:
|
|
29
|
+
raise ValueError("ActiveCampaign connection operation identity differs")
|
|
30
|
+
if get_contact.definition().operation != GET_CONTACT_DEFINITION.operation:
|
|
31
|
+
raise ValueError("ActiveCampaign connection operation identity differs")
|
|
32
|
+
self.reference = reference
|
|
33
|
+
self._list_contacts = list_contacts
|
|
34
|
+
self._get_contact = get_contact
|
|
35
|
+
self._client = client
|
|
36
|
+
|
|
37
|
+
def list_contacts(self) -> Query[ListContactsInput, ContactsPage]:
|
|
38
|
+
return self._list_contacts
|
|
39
|
+
|
|
40
|
+
def get_contact(self) -> Query[GetContactInput, ContactMetadata]:
|
|
41
|
+
return self._get_contact
|
|
42
|
+
|
|
43
|
+
async def aclose(self) -> None:
|
|
44
|
+
if self._client is not None:
|
|
45
|
+
await self._client.aclose()
|
|
46
|
+
|
|
47
|
+
def __repr__(self) -> str:
|
|
48
|
+
return "activecampaign.Connection([REDACTED])"
|
|
49
|
+
|
|
50
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
51
|
+
raise TypeError("ActiveCampaign connections cannot be serialized")
|
|
52
|
+
|
|
53
|
+
setattr(Connection, '__module__', 'dex_connectors.activecampaign.connection')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
57
|
+
if client is None:
|
|
58
|
+
raise ValueError("ActiveCampaign client is required")
|
|
59
|
+
return Connection(reference, client.list_contacts(), client.get_contact(), client)
|
|
60
|
+
|
|
61
|
+
setattr(new_connection, '__module__', 'dex_connectors.activecampaign.connection')
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def new_connection_with_operations(
|
|
65
|
+
list_contacts: Query[ListContactsInput, ContactsPage],
|
|
66
|
+
get_contact: Query[GetContactInput, ContactMetadata],
|
|
67
|
+
reference: ConnectionRef,
|
|
68
|
+
) -> Connection:
|
|
69
|
+
return Connection(reference, list_contacts, get_contact)
|
|
70
|
+
|
|
71
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.activecampaign.connection')
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _ProjectCredentialSource:
|
|
75
|
+
|
|
76
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
77
|
+
self.project = project
|
|
78
|
+
self.key = key
|
|
79
|
+
|
|
80
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
81
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
82
|
+
if not isinstance(material, dict):
|
|
83
|
+
raise ValueError("ActiveCampaign stored credential does not match the connector credential fields")
|
|
84
|
+
if set(material) - set(('api_key',)):
|
|
85
|
+
raise ValueError("ActiveCampaign stored credential does not match the connector credential fields")
|
|
86
|
+
api_key = material.get("api_key")
|
|
87
|
+
if api_key is not None and not (isinstance(api_key, str)):
|
|
88
|
+
raise ValueError("ActiveCampaign credential api_key has an invalid type")
|
|
89
|
+
if not api_key:
|
|
90
|
+
raise ValueError("ActiveCampaign credential api_key is required")
|
|
91
|
+
return Credentials(SecretString(api_key))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def new_project_connection(
|
|
95
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
96
|
+
) -> Connection:
|
|
97
|
+
if project is None:
|
|
98
|
+
raise ValueError("ActiveCampaign connection requires loaded project configuration")
|
|
99
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
100
|
+
reference.validate()
|
|
101
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
102
|
+
matching = [
|
|
103
|
+
entry
|
|
104
|
+
for entry in project.configuration.connections
|
|
105
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
106
|
+
]
|
|
107
|
+
if len(matching) != 1:
|
|
108
|
+
raise ValueError("ActiveCampaign project connection is missing or duplicated")
|
|
109
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
110
|
+
raise ValueError("ActiveCampaign project connection provider differs")
|
|
111
|
+
config = _decode_config(matching[0].configuration)
|
|
112
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
113
|
+
return new_connection(client, reference)
|
|
114
|
+
|
|
115
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.activecampaign.connection')
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
119
|
+
if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
|
|
120
|
+
raise ValueError("ActiveCampaign configuration has unknown fields")
|
|
121
|
+
config_arguments: dict[str, Any] = {}
|
|
122
|
+
if "baseUrl" in value:
|
|
123
|
+
base_url = value["baseUrl"]
|
|
124
|
+
if not (isinstance(base_url, str)):
|
|
125
|
+
raise ValueError("ActiveCampaign configuration baseUrl has an invalid type")
|
|
126
|
+
config_arguments['base_url'] = base_url
|
|
127
|
+
else:
|
|
128
|
+
raise ValueError("ActiveCampaign configuration baseUrl is required")
|
|
129
|
+
if "timeout" in value:
|
|
130
|
+
timeout = value["timeout"]
|
|
131
|
+
if not (type(timeout) is int):
|
|
132
|
+
raise ValueError("ActiveCampaign configuration timeout has an invalid type")
|
|
133
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
134
|
+
if "maxResponseBytes" in value:
|
|
135
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
136
|
+
if not (type(max_response_bytes) is int):
|
|
137
|
+
raise ValueError("ActiveCampaign configuration maxResponseBytes has an invalid type")
|
|
138
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
139
|
+
return Config(**config_arguments)
|
dex_connector_activecampaign-0.1.0/src/dex_connectors/activecampaign/_generated/definitions.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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 = "activecampaign"
|
|
18
|
+
PROVIDER = "activecampaign"
|
|
19
|
+
LIST_CONTACTS_OPERATION_ID = "listContacts"
|
|
20
|
+
GET_CONTACT_OPERATION_ID = "getContact"
|
|
21
|
+
DEFECT = "defect"
|
|
22
|
+
FOUND = "found"
|
|
23
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
24
|
+
LISTED = "listed"
|
|
25
|
+
NOT_FOUND = "notFound"
|
|
26
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
27
|
+
|
|
28
|
+
LIST_CONTACTS_DEFINITION = QueryDefinition(
|
|
29
|
+
OperationRef(CONNECTOR_ID, LIST_CONTACTS_OPERATION_ID),
|
|
30
|
+
(
|
|
31
|
+
BranchDefinition(LISTED, "ActiveCampaign returned the selected contact page.", False),
|
|
32
|
+
BranchDefinition(PROVIDER_REJECTED, "ActiveCampaign conclusively rejected the request.", True),
|
|
33
|
+
BranchDefinition(INVALID_RESPONSE, "ActiveCampaign returned malformed or oversized JSON.", True),
|
|
34
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
35
|
+
),
|
|
36
|
+
StepDefaults(
|
|
37
|
+
timedelta(seconds=30),
|
|
38
|
+
2,
|
|
39
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
GET_CONTACT_DEFINITION = QueryDefinition(
|
|
44
|
+
OperationRef(CONNECTOR_ID, GET_CONTACT_OPERATION_ID),
|
|
45
|
+
(
|
|
46
|
+
BranchDefinition(FOUND, "ActiveCampaign returned contact metadata.", False),
|
|
47
|
+
BranchDefinition(NOT_FOUND, "No contact with this ID is visible to the API user.", True),
|
|
48
|
+
BranchDefinition(PROVIDER_REJECTED, "ActiveCampaign conclusively rejected the request.", True),
|
|
49
|
+
BranchDefinition(INVALID_RESPONSE, "ActiveCampaign returned malformed or oversized JSON.", True),
|
|
50
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
51
|
+
),
|
|
52
|
+
StepDefaults(
|
|
53
|
+
timedelta(seconds=30),
|
|
54
|
+
2,
|
|
55
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
56
|
+
),
|
|
57
|
+
)
|