dex-connector-airtable 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 (31) hide show
  1. dex_connector_airtable-0.1.0/.gitignore +8 -0
  2. dex_connector_airtable-0.1.0/LICENSE +21 -0
  3. dex_connector_airtable-0.1.0/PKG-INFO +68 -0
  4. dex_connector_airtable-0.1.0/README.md +56 -0
  5. dex_connector_airtable-0.1.0/examples/policy_lookup/README.md +36 -0
  6. dex_connector_airtable-0.1.0/examples/policy_lookup/__init__.py +3 -0
  7. dex_connector_airtable-0.1.0/examples/policy_lookup/flow.py +121 -0
  8. dex_connector_airtable-0.1.0/examples/policy_lookup/integration_test.py +125 -0
  9. dex_connector_airtable-0.1.0/examples/policy_lookup/sample-input.json +1 -0
  10. dex_connector_airtable-0.1.0/examples/policy_lookup/start.py +60 -0
  11. dex_connector_airtable-0.1.0/examples/policy_lookup/worker.py +51 -0
  12. dex_connector_airtable-0.1.0/pyproject.toml +37 -0
  13. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/__init__.py +120 -0
  14. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/__init__.py +2 -0
  15. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/config.py +24 -0
  16. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/connection.py +142 -0
  17. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/definitions.py +94 -0
  18. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/mock.py +245 -0
  19. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/models.py +270 -0
  20. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/_generated/steps.py +240 -0
  21. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/airtablemock/__init__.py +147 -0
  22. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/client.py +1005 -0
  23. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/connection.py +16 -0
  24. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/dex-connector.json +158 -0
  25. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/models.py +40 -0
  26. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/py.typed +0 -0
  27. dex_connector_airtable-0.1.0/src/dex_connectors/airtable/steps.py +16 -0
  28. dex_connector_airtable-0.1.0/tests/test_conformance.py +36 -0
  29. dex_connector_airtable-0.1.0/tests/test_manifest_contract.py +158 -0
  30. dex_connector_airtable-0.1.0/tests/test_operations.py +365 -0
  31. dex_connector_airtable-0.1.0/uv.lock +932 -0
@@ -0,0 +1,8 @@
1
+ /.dex-local/dexcli
2
+ /.dex-local/dex-server-zd
3
+ /.dex-local/data/
4
+ /.dex-local/cli.log
5
+ /.dex-local/visualize.json
6
+ /.dex-local/visualize.err
7
+ /dist/dex_connector_airtable-0.1.0-py3-none-any.whl
8
+ /dist/dex_connector_airtable-0.1.0.tar.gz
@@ -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,68 @@
1
+ Metadata-Version: 2.5
2
+ Name: dex-connector-airtable
3
+ Version: 0.1.0
4
+ Summary: Airtable 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
+ # Airtable connector for Python
14
+
15
+ Install with `pip install dex-connector-airtable==0.1.0`. The package requires
16
+ `dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
17
+ manifest Queries `listRecords` and `getRecord` and Mutations `upsertRecords` and
18
+ `updateRecords` with the same branches, defaults, and failure classification as
19
+ the Go module.
20
+
21
+ ## Operations
22
+
23
+ | Operation | Factory | Happy branch | Optional branches |
24
+ | --- | --- | --- | --- |
25
+ | `listRecords` | `new_list_records_step` | `listed` | `offsetExpired`, `providerRejected`, `invalidResponse`, `defect` |
26
+ | `getRecord` | `new_get_record_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
27
+ | `upsertRecords` | `new_upsert_records_step` | `upserted` | `providerRejected`, `invalidResponse`, `defect` |
28
+ | `updateRecords` | `new_update_records_step` | `updated` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
29
+
30
+ `listRecords` uses Airtable's POST listRecords form. Typed `FieldEqualityFilter`
31
+ values are escaped and ANDed with an optional raw formula (see
32
+ `build_filter_formula`); the formula sent is returned in `filter_formula`.
33
+ `upsertRecords` writes 1 to 10 records matched by 1 to 3 merge fields, so a
34
+ retried write updates the records the first attempt created; it uses sync
35
+ durability so two attempts never overlap. `updateRecords` sets absolute values
36
+ by record ID. Cell values keep Airtable's JSON form, and `None` clears a field.
37
+
38
+ Requests to one base are spaced 200 ms apart within one process; a queue longer
39
+ than two seconds, or a 429, which holds the base for 30 seconds, retries. 408
40
+ and 5xx other than 501 retry; an expired list offset selects `offsetExpired`;
41
+ 401, 403, 400, 413, 422, and redirects select `providerRejected` with the Go
42
+ failure kinds and Airtable's error type, never its message text.
43
+
44
+ The Python example passes its base and table as Flow input. The manifest's
45
+ `basePicker` and `tablePicker` units remain available in Dex Web Connections
46
+ for applications that use the generated setup UI.
47
+
48
+ ## Authorization
49
+
50
+ Create a Dex Web connection as described in the
51
+ [connector README](../README.md#authentication). The personal access token
52
+ travels only in the `Authorization: Bearer` header and is resolved for every
53
+ attempt.
54
+
55
+ ## Example
56
+
57
+ [`examples/policy_lookup`](examples/policy_lookup/README.md) is the policy lookup
58
+ Step of the Go refund-decision example, with the base and table passed as start
59
+ input. It includes Worker and Client entrypoints and strict FDG 2.0 generation
60
+ instructions. Its static connection name is `airtable-refund-policies`.
61
+
62
+ ## Tests
63
+
64
+ `airtablemock.Mock` scripts every operation and defaults to the manifest
65
+ answers, including the three-page policy listing. Run `uv run pytest tests`
66
+ for unit and Go-recorded conformance checks. The example integration test runs
67
+ against a real local Dex Worker and Client with an inert provider fake. Live
68
+ Airtable authorization and provider behavior have not been verified.
@@ -0,0 +1,56 @@
1
+ # Airtable connector for Python
2
+
3
+ Install with `pip install dex-connector-airtable==0.1.0`. The package requires
4
+ `dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
5
+ manifest Queries `listRecords` and `getRecord` and Mutations `upsertRecords` and
6
+ `updateRecords` with the same branches, defaults, and failure classification as
7
+ the Go module.
8
+
9
+ ## Operations
10
+
11
+ | Operation | Factory | Happy branch | Optional branches |
12
+ | --- | --- | --- | --- |
13
+ | `listRecords` | `new_list_records_step` | `listed` | `offsetExpired`, `providerRejected`, `invalidResponse`, `defect` |
14
+ | `getRecord` | `new_get_record_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
15
+ | `upsertRecords` | `new_upsert_records_step` | `upserted` | `providerRejected`, `invalidResponse`, `defect` |
16
+ | `updateRecords` | `new_update_records_step` | `updated` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
17
+
18
+ `listRecords` uses Airtable's POST listRecords form. Typed `FieldEqualityFilter`
19
+ values are escaped and ANDed with an optional raw formula (see
20
+ `build_filter_formula`); the formula sent is returned in `filter_formula`.
21
+ `upsertRecords` writes 1 to 10 records matched by 1 to 3 merge fields, so a
22
+ retried write updates the records the first attempt created; it uses sync
23
+ durability so two attempts never overlap. `updateRecords` sets absolute values
24
+ by record ID. Cell values keep Airtable's JSON form, and `None` clears a field.
25
+
26
+ Requests to one base are spaced 200 ms apart within one process; a queue longer
27
+ than two seconds, or a 429, which holds the base for 30 seconds, retries. 408
28
+ and 5xx other than 501 retry; an expired list offset selects `offsetExpired`;
29
+ 401, 403, 400, 413, 422, and redirects select `providerRejected` with the Go
30
+ failure kinds and Airtable's error type, never its message text.
31
+
32
+ The Python example passes its base and table as Flow input. The manifest's
33
+ `basePicker` and `tablePicker` units remain available in Dex Web Connections
34
+ for applications that use the generated setup UI.
35
+
36
+ ## Authorization
37
+
38
+ Create a Dex Web connection as described in the
39
+ [connector README](../README.md#authentication). The personal access token
40
+ travels only in the `Authorization: Bearer` header and is resolved for every
41
+ attempt.
42
+
43
+ ## Example
44
+
45
+ [`examples/policy_lookup`](examples/policy_lookup/README.md) is the policy lookup
46
+ Step of the Go refund-decision example, with the base and table passed as start
47
+ input. It includes Worker and Client entrypoints and strict FDG 2.0 generation
48
+ instructions. Its static connection name is `airtable-refund-policies`.
49
+
50
+ ## Tests
51
+
52
+ `airtablemock.Mock` scripts every operation and defaults to the manifest
53
+ answers, including the three-page policy listing. Run `uv run pytest tests`
54
+ for unit and Go-recorded conformance checks. The example integration test runs
55
+ against a real local Dex Worker and Client with an inert provider fake. Live
56
+ Airtable authorization and provider behavior have not been verified.
@@ -0,0 +1,36 @@
1
+ # Policy lookup example
2
+
3
+ This Flow lists up to two policy records by `Policy Key` and returns the one
4
+ matching record. Zero or multiple matches return `isAmbiguous: true`.
5
+
6
+ With Dex CLI 1.33.0 or later, generate strict FDG 2.0 from
7
+ `connectors/airtable/python` after `uv sync --locked`:
8
+
9
+ ```sh
10
+ mkdir -p build
11
+ dexcli visualize ./examples/policy_lookup/flow.py --language python \
12
+ --python .venv/bin/python --schema-version 2.0 --json \
13
+ --out ./build/airtable-policy-lookup
14
+ ```
15
+
16
+ Start `dexcli dev -flow-rendering-dir ./build`, then configure the static
17
+ `airtable / airtable-refund-policies` connection in Dex Web with a personal
18
+ access token from <https://airtable.com/create/tokens>. Grant
19
+ `data.records:read` and access to the chosen base. Export the owner-only
20
+ `DEX_CONNECTOR_CONFIG_FILE` path and `DEX_FLOW_SERVICE_ADDRESS` from that
21
+ project, then run the Worker:
22
+
23
+ ```sh
24
+ uv run python -m examples.policy_lookup.worker
25
+ ```
26
+
27
+ In another terminal with the same environment, start a Flow with a unique ID
28
+ and input containing a base ID, table ID or name, and policy key:
29
+
30
+ ```sh
31
+ uv run python -m examples.policy_lookup.start airtable-policy-001 examples/policy_lookup/sample-input.json
32
+ ```
33
+
34
+ The real Dex integration test uses a local provider fake so no token is needed:
35
+ `uv run pytest examples/policy_lookup/integration_test.py` while `dexcli dev` is
36
+ running and `DEX_FLOW_SERVICE_ADDRESS` points to it.
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Airtable policy lookup example Flow."""
@@ -0,0 +1,121 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Runnable Flow that finds the one refund policy row whose Policy Key equals a requested key.
4
+
5
+ It is the policy lookup Step of the Go refund-decision example, with the base and table passed
6
+ as start input instead of Studio pickers.
7
+ """
8
+
9
+ from dataclasses import dataclass, field, replace
10
+
11
+ import dex
12
+ from dex_connectors.sdk import QueryResult
13
+
14
+ from dex_connectors.airtable import (
15
+ Connection,
16
+ FieldEqualityFilter,
17
+ ListRecordsInput,
18
+ Record,
19
+ RecordPage,
20
+ new_list_records_step,
21
+ )
22
+
23
+ FLOW_TYPE = "AirtablePolicyLookup"
24
+ CONNECTION_NAME = "airtable-refund-policies"
25
+ _FIND_POLICY_STEP_TYPE = "FindAirtableRefundPolicy"
26
+ _POLICY_KEY_FIELD = "Policy Key"
27
+
28
+
29
+ @dataclass(frozen=True, slots=True)
30
+ class PolicyLookupRequest:
31
+ """Base ID such as appXXXXXXXXXXXXXX, table ID or name, and the Policy Key text to match."""
32
+
33
+ base_id: str = field(default="", metadata={"dex_json_name": "baseId"})
34
+ table_id_or_name: str = field(default="", metadata={"dex_json_name": "tableIdOrName"})
35
+ policy_key: str = field(default="", metadata={"dex_json_name": "policyKey"})
36
+
37
+
38
+ @dataclass(frozen=True, slots=True)
39
+ class PolicyLookupOutcome:
40
+ """The single matching policy record, or isAmbiguous when zero or several rows matched."""
41
+
42
+ policy: Record | None = field(default=None, metadata={"dex_json_omit_default": True})
43
+ is_ambiguous: bool = field(default=False, metadata={"dex_json_name": "isAmbiguous"})
44
+
45
+
46
+ _REQUEST = dex.Attribute("airtable-policy-lookup-request", PolicyLookupRequest)
47
+ _OUTCOME = dex.Attribute("airtable-policy-lookup-outcome", PolicyLookupOutcome)
48
+
49
+
50
+ def map_to_list_records_input(request: PolicyLookupRequest) -> ListRecordsInput:
51
+ """List at most two rows whose Policy Key equals the key, so a duplicate key is detected."""
52
+ return ListRecordsInput(
53
+ base_id=request.base_id,
54
+ table_id_or_name=request.table_id_or_name,
55
+ filters=(FieldEqualityFilter(field=_POLICY_KEY_FIELD, text=request.policy_key),),
56
+ page_size=2,
57
+ )
58
+
59
+
60
+ # dex:group group-id:airtable group-label:"Airtable"
61
+ # dex:explanation text:"Validate and record the policy lookup before calling Airtable."
62
+ class _RecordPolicyLookupRequest(dex.Step[PolicyLookupRequest]):
63
+ def get_step_type(self) -> str:
64
+ return "RecordAirtablePolicyLookupRequest"
65
+
66
+ def execute(self, context: dex.Context, input: PolicyLookupRequest) -> dex.StepDecision:
67
+ request = replace(input, policy_key=input.policy_key.strip())
68
+ if not request.base_id or not request.table_id_or_name or not request.policy_key:
69
+ return dex.force_fail("baseId, tableIdOrName, and policyKey are required")
70
+ _REQUEST.set(context, request)
71
+ return dex.go_to(dex.StepRef("FindAirtableRefundPolicy"), request)
72
+
73
+
74
+ # dex:group group-id:airtable group-label:"Airtable"
75
+ # dex:explanation text:"Complete with the one matching policy, or mark the lookup ambiguous."
76
+ class _CompletePolicyLookup(dex.Step[QueryResult[RecordPage]]):
77
+ def get_step_type(self) -> str:
78
+ return "CompleteAirtablePolicyLookup"
79
+
80
+ def execute(self, context: dex.Context, input: QueryResult[RecordPage]) -> dex.StepDecision:
81
+ records = input.value.records
82
+ outcome = (
83
+ PolicyLookupOutcome(records[0]) if len(records) == 1 else PolicyLookupOutcome(is_ambiguous=True)
84
+ )
85
+ _OUTCOME.set(context, outcome)
86
+ return dex.graceful_complete(outcome)
87
+
88
+
89
+ class PolicyLookupFlow(dex.Flow[PolicyLookupRequest]):
90
+ """Find one refund policy row through the static airtable-refund-policies connection."""
91
+
92
+ def __init__(self, connection: Connection) -> None:
93
+ if connection.reference.name != CONNECTION_NAME:
94
+ raise ValueError("policy lookup requires the static airtable-refund-policies connection")
95
+ self._record_request = _RecordPolicyLookupRequest()
96
+ self._complete = _CompletePolicyLookup()
97
+ self._find = new_list_records_step(
98
+ step_type=_FIND_POLICY_STEP_TYPE,
99
+ step_input_type=PolicyLookupRequest,
100
+ annotations={
101
+ "groupId": "airtable",
102
+ "groupLabel": "Airtable",
103
+ "explanation": "Find the refund policy whose Policy Key equals the requested key.",
104
+ },
105
+ connection=connection,
106
+ connection_name=CONNECTION_NAME,
107
+ map_to_operation_input=map_to_list_records_input,
108
+ listed=self._complete,
109
+ )
110
+
111
+ def get_flow_type(self) -> str:
112
+ """Return the stable Flow identity used in Dex Web."""
113
+ return "AirtablePolicyLookup"
114
+
115
+ def get_steps(self) -> dex.StepList[PolicyLookupRequest]:
116
+ """Register the request, policy lookup, and completion Steps."""
117
+ return dex.StepList.start_step(self._record_request).other_steps(self._find, self._complete)
118
+
119
+ def get_persistence_schema(self) -> dex.PersistenceSchema:
120
+ """Persist the request and outcome."""
121
+ return dex.PersistenceSchema.of(_REQUEST, _OUTCOME)
@@ -0,0 +1,125 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Exercise the policy lookup Flow through a real Dex Worker and Client."""
4
+
5
+ import asyncio
6
+ import json
7
+ import os
8
+ from datetime import timedelta
9
+ from pathlib import Path
10
+ from uuid import uuid4
11
+
12
+ import dex
13
+ import httpx
14
+ import pytest
15
+ from dex_connectors.sdk.projectconfig import load_from_environment
16
+
17
+ from dex_connectors.airtable import new_project_connection
18
+
19
+ from .flow import CONNECTION_NAME, PolicyLookupFlow, PolicyLookupOutcome
20
+ from .start import start_policy_lookup
21
+
22
+
23
+ @pytest.mark.asyncio
24
+ async def test_policy_lookup_retries_and_fails_unwired_rejection_in_real_dex(
25
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
26
+ ) -> None:
27
+ """Verify retry, completion, and optional branch failure across the Dex boundary."""
28
+ server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
29
+ requests: list[httpx.Request] = []
30
+
31
+ def answer(request: httpx.Request) -> httpx.Response:
32
+ requests.append(request)
33
+ body = json.loads(request.content)
34
+ formula = body["filterByFormula"]
35
+ if "rejected" in formula:
36
+ return httpx.Response(403, json={"error": {"type": "INVALID_PERMISSIONS"}})
37
+ if len(requests) == 1:
38
+ return httpx.Response(503, json={"error": {"type": "SERVICE_UNAVAILABLE"}})
39
+ return httpx.Response(
40
+ 200,
41
+ json={
42
+ "records": [
43
+ {
44
+ "id": "recPolicyStandard",
45
+ "createdTime": "2026-09-01T09:00:00Z",
46
+ "fields": {"Policy Key": "refund-standard", "Approval Limit USD": 250},
47
+ }
48
+ ]
49
+ },
50
+ )
51
+
52
+ connections_path = tmp_path / "connections.json"
53
+ connections_path.write_text(
54
+ json.dumps(
55
+ {
56
+ "schemaVersion": "connectors.dex.dev/local-connections/v1alpha1",
57
+ "connections": [
58
+ {
59
+ "connectorId": "airtable",
60
+ "connectionName": CONNECTION_NAME,
61
+ "modulePath": "github.com/superdurable/dex-connectors-library/connectors/airtable",
62
+ "provider": "airtable",
63
+ "authMethodId": "api-key-only",
64
+ "configuration": {"endpoint": "http://127.0.0.1:22080"},
65
+ "credentials": {"personal_access_token": "patTEST.token"},
66
+ }
67
+ ],
68
+ "triggerBindings": [],
69
+ }
70
+ )
71
+ )
72
+ connections_path.chmod(0o600)
73
+ monkeypatch.setenv("DEX_CONNECTOR_CONFIG_FILE", str(connections_path))
74
+
75
+ async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as provider_http_client:
76
+ project = await load_from_environment()
77
+ connection = new_project_connection(project, CONNECTION_NAME, provider_http_client)
78
+ flow = PolicyLookupFlow(connection)
79
+ registry = dex.Registry([flow], allow_async_handlers=True)
80
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 24))
81
+ worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
82
+ worker_task = asyncio.create_task(worker.start())
83
+ try:
84
+ await worker.wait_pull_registered(timeout=20)
85
+ async with dex.AsyncClient(
86
+ registry, cache, dex.ClientOptions(server_address=server_address)
87
+ ) as client:
88
+ successful_id = f"airtable-python-policy-{uuid4().hex}"
89
+ await start_policy_lookup(successful_id, Path(__file__).with_name("sample-input.json"))
90
+ successful = await asyncio.wait_for(
91
+ client.wait_for_flow(successful_id, timedelta(seconds=20)), 30
92
+ )
93
+ assert successful.status == dex.FlowStatus.COMPLETED, successful.error_message
94
+ outcome = successful.single_output(PolicyLookupOutcome)
95
+ assert outcome.policy is not None
96
+ assert outcome.policy.id == "recPolicyStandard"
97
+ assert not outcome.is_ambiguous
98
+ assert len(requests) == 2
99
+ assert all(request.method == "POST" for request in requests)
100
+
101
+ rejected_id = f"airtable-python-policy-{uuid4().hex}"
102
+ rejected_input = tmp_path / "rejected-input.json"
103
+ rejected_input.write_text(
104
+ json.dumps(
105
+ {
106
+ "baseId": "appRefundBase0001",
107
+ "tableIdOrName": "tblPolicies000001",
108
+ "policyKey": "rejected",
109
+ }
110
+ )
111
+ )
112
+ await start_policy_lookup(rejected_id, rejected_input)
113
+ rejected = await asyncio.wait_for(
114
+ client.wait_for_flow(rejected_id, timedelta(seconds=20)), 30
115
+ )
116
+ assert rejected.status == dex.FlowStatus.FAILED
117
+ assert rejected.error_message is not None
118
+ assert "providerRejected" in rejected.error_message
119
+ assert len(requests) == 3
120
+ finally:
121
+ await worker.stop()
122
+ await worker_task
123
+ cache.close()
124
+ await connection.aclose()
125
+ await project.close()
@@ -0,0 +1 @@
1
+ {"baseId":"appRefundBase0001","tableIdOrName":"tblPolicies000001","policyKey":"refund-standard"}
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Start a policy lookup using the static Airtable project connection."""
4
+
5
+ import argparse
6
+ import asyncio
7
+ import os
8
+ import tempfile
9
+ from pathlib import Path
10
+
11
+ import dex
12
+ from dex_connectors.sdk.projectconfig import load_from_environment
13
+
14
+ from dex_connectors.airtable import new_project_connection
15
+
16
+ from .flow import CONNECTION_NAME, PolicyLookupFlow, PolicyLookupRequest
17
+
18
+
19
+ async def start_policy_lookup(flow_id: str, input_file: Path) -> str:
20
+ """Decode one bounded JSON input and start a policy lookup Flow."""
21
+ with input_file.open("rb") as source:
22
+ encoded_input = source.read(65_537)
23
+ if len(encoded_input) > 65_536:
24
+ raise ValueError("policy lookup input exceeds 65536 bytes")
25
+ request = (
26
+ dex.CodecRegistry()
27
+ .resolve(PolicyLookupRequest)
28
+ .decode(dex.Value(dex.WireKind.JSON, encoded_input.decode("utf-8")))
29
+ )
30
+ project = await load_from_environment()
31
+ connection = new_project_connection(project, CONNECTION_NAME)
32
+ try:
33
+ flow = PolicyLookupFlow(connection)
34
+ registry = dex.Registry([flow], allow_async_handlers=True)
35
+ with tempfile.TemporaryDirectory(prefix="airtable-python-start-blobs-") as cache_directory:
36
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 24))
37
+ try:
38
+ server_address = os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")
39
+ async with dex.AsyncClient(
40
+ registry, cache, dex.ClientOptions(server_address=server_address)
41
+ ) as client:
42
+ return await client.start_flow(flow, flow_id, request)
43
+ finally:
44
+ cache.close()
45
+ finally:
46
+ await connection.aclose()
47
+ await project.close()
48
+
49
+
50
+ def main() -> None:
51
+ """Read the unique Flow ID and JSON input path from the command line."""
52
+ parser = argparse.ArgumentParser(description="Start an Airtable policy lookup Flow")
53
+ parser.add_argument("flow_id")
54
+ parser.add_argument("input_file", type=Path)
55
+ arguments = parser.parse_args()
56
+ print(asyncio.run(start_policy_lookup(arguments.flow_id, arguments.input_file)))
57
+
58
+
59
+ if __name__ == "__main__":
60
+ main()
@@ -0,0 +1,51 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Worker entrypoint for the Airtable policy lookup 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.airtable import new_project_connection
14
+
15
+ from .flow import CONNECTION_NAME, PolicyLookupFlow
16
+
17
+
18
+ async def run_worker() -> None:
19
+ """Load the named Dex Web connection and find refund policies."""
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([PolicyLookupFlow(connection)], allow_async_handlers=True)
26
+ cache_directory = os.environ.get(
27
+ "DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-airtable-policy-lookup-blobs")
28
+ )
29
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
30
+ worker = dex.AsyncWorker(
31
+ registry,
32
+ cache,
33
+ dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
34
+ )
35
+ async with worker:
36
+ await worker.start()
37
+ finally:
38
+ if connection is not None:
39
+ await connection.aclose()
40
+ if cache is not None:
41
+ cache.close()
42
+ await project.close()
43
+
44
+
45
+ def main() -> None:
46
+ """Run until the Worker stops or the process receives an interrupt."""
47
+ asyncio.run(run_worker())
48
+
49
+
50
+ if __name__ == "__main__":
51
+ 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-airtable"
7
+ version = "0.1.0"
8
+ description = "Airtable 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"]