dex-connector-vercel 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_vercel-0.1.0/.gitignore +6 -0
- dex_connector_vercel-0.1.0/PKG-INFO +49 -0
- dex_connector_vercel-0.1.0/README.md +38 -0
- dex_connector_vercel-0.1.0/examples/vercel_lookup/__init__.py +3 -0
- dex_connector_vercel-0.1.0/examples/vercel_lookup/flow.py +76 -0
- dex_connector_vercel-0.1.0/examples/vercel_lookup/worker.py +51 -0
- dex_connector_vercel-0.1.0/pyproject.toml +37 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/__init__.py +51 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/__init__.py +2 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/config.py +25 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/connection.py +137 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/definitions.py +57 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/mock.py +113 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/models.py +82 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/_generated/steps.py +131 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/client.py +326 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/connection.py +46 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/dex-connector.json +82 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/models.py +33 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/py.typed +0 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/steps.py +37 -0
- dex_connector_vercel-0.1.0/src/dex_connectors/vercel/vercelmock/__init__.py +45 -0
- dex_connector_vercel-0.1.0/tests/test_conformance.py +42 -0
- dex_connector_vercel-0.1.0/tests/test_manifest_contract.py +15 -0
- dex_connector_vercel-0.1.0/tests/test_operations.py +144 -0
- dex_connector_vercel-0.1.0/uv.lock +932 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-vercel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Vercel connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
8
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Vercel connector for Python
|
|
13
|
+
|
|
14
|
+
Install with `pip install dex-connector-vercel==0.1.0`. The package requires
|
|
15
|
+
`dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
|
|
16
|
+
manifest Queries `listDeployments` and `getDeployment` with the same branches,
|
|
17
|
+
defaults, and failure classification as the Go module.
|
|
18
|
+
|
|
19
|
+
## Operations
|
|
20
|
+
|
|
21
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| `listDeployments` | `new_list_deployments_step` | `listed` | `providerRejected`, `invalidResponse`, `defect` |
|
|
24
|
+
| `getDeployment` | `new_get_deployment_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
25
|
+
|
|
26
|
+
Both accept an optional `team_id`; blank uses the personal account.
|
|
27
|
+
`getDeployment` takes a deployment ID or hostname and needs a `uid` or `id` in
|
|
28
|
+
the response. 408, 409, 429, 5xx, and transport failures retry. On
|
|
29
|
+
`getDeployment`, HTTP 404 selects `notFound`; other non-200 responses select
|
|
30
|
+
`providerRejected` with authentication, authorization, not-found, or
|
|
31
|
+
validation failure kinds.
|
|
32
|
+
|
|
33
|
+
## Authorization
|
|
34
|
+
|
|
35
|
+
Create a Dex Web connection named `vercel` as described in the
|
|
36
|
+
[connector README](../README.md#authorization). The access token travels only
|
|
37
|
+
in the `Authorization: Bearer` header and is resolved for every attempt.
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
[`examples/vercel_lookup`](examples/vercel_lookup/flow.py) lists deployments
|
|
42
|
+
and records them. Run the Worker with
|
|
43
|
+
`uv run python -m examples.vercel_lookup.worker` after `dexcli dev` has loaded
|
|
44
|
+
a project containing the `vercel` connection.
|
|
45
|
+
|
|
46
|
+
## Tests
|
|
47
|
+
|
|
48
|
+
`vercelmock.Mock` scripts both Queries and defaults to the manifest answers.
|
|
49
|
+
Run `uv run pytest tests` for provider parity and manifest contract checks.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Vercel connector for Python
|
|
2
|
+
|
|
3
|
+
Install with `pip install dex-connector-vercel==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 `listDeployments` and `getDeployment` with the same branches,
|
|
6
|
+
defaults, and failure classification as the Go module.
|
|
7
|
+
|
|
8
|
+
## Operations
|
|
9
|
+
|
|
10
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| `listDeployments` | `new_list_deployments_step` | `listed` | `providerRejected`, `invalidResponse`, `defect` |
|
|
13
|
+
| `getDeployment` | `new_get_deployment_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
14
|
+
|
|
15
|
+
Both accept an optional `team_id`; blank uses the personal account.
|
|
16
|
+
`getDeployment` takes a deployment ID or hostname and needs a `uid` or `id` in
|
|
17
|
+
the response. 408, 409, 429, 5xx, and transport failures retry. On
|
|
18
|
+
`getDeployment`, HTTP 404 selects `notFound`; other non-200 responses select
|
|
19
|
+
`providerRejected` with authentication, authorization, not-found, or
|
|
20
|
+
validation failure kinds.
|
|
21
|
+
|
|
22
|
+
## Authorization
|
|
23
|
+
|
|
24
|
+
Create a Dex Web connection named `vercel` as described in the
|
|
25
|
+
[connector README](../README.md#authorization). The access token travels only
|
|
26
|
+
in the `Authorization: Bearer` header and is resolved for every attempt.
|
|
27
|
+
|
|
28
|
+
## Example
|
|
29
|
+
|
|
30
|
+
[`examples/vercel_lookup`](examples/vercel_lookup/flow.py) lists deployments
|
|
31
|
+
and records them. Run the Worker with
|
|
32
|
+
`uv run python -m examples.vercel_lookup.worker` after `dexcli dev` has loaded
|
|
33
|
+
a project containing the `vercel` connection.
|
|
34
|
+
|
|
35
|
+
## Tests
|
|
36
|
+
|
|
37
|
+
`vercelmock.Mock` scripts both Queries and defaults to the manifest answers.
|
|
38
|
+
Run `uv run pytest tests` for provider parity and manifest contract checks.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable Vercel lookup Flow using the listDeployments Query."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.vercel import Connection, DeploymentsPage, ListDeploymentsInput, new_list_deployments_step
|
|
9
|
+
|
|
10
|
+
FLOW_TYPE = "VercelLookup"
|
|
11
|
+
CONNECTION_NAME = "vercel"
|
|
12
|
+
_OPERATION_STEP_TYPE = "ListDeploymentsVercel"
|
|
13
|
+
_REQUEST = dex.Attribute("vercel-lookup-request", ListDeploymentsInput)
|
|
14
|
+
_OUTPUT = dex.Attribute("vercel-lookup-output", DeploymentsPage)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def map_to_operation_input(request: ListDeploymentsInput) -> ListDeploymentsInput:
|
|
18
|
+
"""List deployments for the requested team, or the personal account when blank."""
|
|
19
|
+
return request
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# dex:group group-id:vercel-lookup group-label:"Vercel lookup"
|
|
23
|
+
# dex:explanation text:"Record the lookup request before listing Vercel deployments."
|
|
24
|
+
class _StartLookup(dex.Step[ListDeploymentsInput]):
|
|
25
|
+
def get_step_type(self) -> str:
|
|
26
|
+
return "StartVercelLookup"
|
|
27
|
+
|
|
28
|
+
def execute(self, context: dex.Context, input: ListDeploymentsInput) -> dex.StepDecision:
|
|
29
|
+
_REQUEST.set(context, input)
|
|
30
|
+
return dex.go_to(dex.StepRef(_OPERATION_STEP_TYPE), input)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# dex:group group-id:vercel-lookup group-label:"Vercel lookup"
|
|
34
|
+
# dex:explanation text:"Record the deployments and complete the Flow."
|
|
35
|
+
class _CompleteLookup(dex.Step[QueryResult[DeploymentsPage]]):
|
|
36
|
+
def get_step_type(self) -> str:
|
|
37
|
+
return "CompleteVercelLookup"
|
|
38
|
+
|
|
39
|
+
def execute(self, context: dex.Context, input: QueryResult[DeploymentsPage]) -> dex.StepDecision:
|
|
40
|
+
_OUTPUT.set(context, input.value)
|
|
41
|
+
return dex.graceful_complete(input.value)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class VercelLookupFlow(dex.Flow[ListDeploymentsInput]):
|
|
45
|
+
"""List Vercel deployments through the static vercel connection."""
|
|
46
|
+
|
|
47
|
+
def __init__(self, connection: Connection) -> None:
|
|
48
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
49
|
+
raise ValueError("Vercel lookup requires the static vercel connection")
|
|
50
|
+
self._start = _StartLookup()
|
|
51
|
+
self._complete = _CompleteLookup()
|
|
52
|
+
self._list = new_list_deployments_step(
|
|
53
|
+
step_type=_OPERATION_STEP_TYPE,
|
|
54
|
+
step_input_type=ListDeploymentsInput,
|
|
55
|
+
annotations={
|
|
56
|
+
"groupId": "vercel",
|
|
57
|
+
"groupLabel": "Vercel",
|
|
58
|
+
"explanation": "List deployments visible to a personal account or team.",
|
|
59
|
+
},
|
|
60
|
+
connection=connection,
|
|
61
|
+
connection_name=CONNECTION_NAME,
|
|
62
|
+
map_to_operation_input=map_to_operation_input,
|
|
63
|
+
listed=self._complete,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def get_flow_type(self) -> str:
|
|
67
|
+
"""Return the stable Flow identity used in Dex Web."""
|
|
68
|
+
return FLOW_TYPE
|
|
69
|
+
|
|
70
|
+
def get_steps(self) -> dex.StepList[ListDeploymentsInput]:
|
|
71
|
+
"""Register the start, provider list, and completion Steps."""
|
|
72
|
+
return dex.StepList.start_step(self._start).other_steps(self._list, self._complete)
|
|
73
|
+
|
|
74
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
75
|
+
"""Persist the request and deployment page."""
|
|
76
|
+
return dex.PersistenceSchema.of(_REQUEST, _OUTPUT)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Vercel 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.vercel import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, VercelLookupFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the named Dex Web connection and serve Vercel lookups."""
|
|
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([VercelLookupFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-vercel-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-vercel"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Vercel 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,51 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Vercel deployment Queries for Dex connector Steps."""
|
|
4
|
+
|
|
5
|
+
from .client import (
|
|
6
|
+
CONNECTOR_ID,
|
|
7
|
+
DEFECT,
|
|
8
|
+
FOUND,
|
|
9
|
+
GET_DEPLOYMENT_DEFINITION,
|
|
10
|
+
INVALID_RESPONSE,
|
|
11
|
+
LIST_DEPLOYMENTS_DEFINITION,
|
|
12
|
+
LISTED,
|
|
13
|
+
NOT_FOUND,
|
|
14
|
+
PROVIDER_REJECTED,
|
|
15
|
+
Client,
|
|
16
|
+
Config,
|
|
17
|
+
Credentials,
|
|
18
|
+
GetDeploymentOperation,
|
|
19
|
+
ListDeploymentsOperation,
|
|
20
|
+
)
|
|
21
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
22
|
+
from .models import Deployment, DeploymentsPage, GetDeploymentInput, ListDeploymentsInput, Pagination
|
|
23
|
+
from .steps import new_get_deployment_step, new_list_deployments_step
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Client",
|
|
27
|
+
"Config",
|
|
28
|
+
"Connection",
|
|
29
|
+
"Credentials",
|
|
30
|
+
"Deployment",
|
|
31
|
+
"DeploymentsPage",
|
|
32
|
+
"GetDeploymentInput",
|
|
33
|
+
"GetDeploymentOperation",
|
|
34
|
+
"ListDeploymentsInput",
|
|
35
|
+
"ListDeploymentsOperation",
|
|
36
|
+
"Pagination",
|
|
37
|
+
"new_connection",
|
|
38
|
+
"new_connection_with_operations",
|
|
39
|
+
"new_get_deployment_step",
|
|
40
|
+
"new_list_deployments_step",
|
|
41
|
+
"new_project_connection",
|
|
42
|
+
"CONNECTOR_ID",
|
|
43
|
+
"DEFECT",
|
|
44
|
+
"FOUND",
|
|
45
|
+
"GET_DEPLOYMENT_DEFINITION",
|
|
46
|
+
"INVALID_RESPONSE",
|
|
47
|
+
"LIST_DEPLOYMENTS_DEFINITION",
|
|
48
|
+
"LISTED",
|
|
49
|
+
"NOT_FOUND",
|
|
50
|
+
"PROVIDER_REJECTED",
|
|
51
|
+
]
|
|
@@ -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 = "https://api.vercel.com"
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 2097152
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.vercel.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
access_token: SecretString
|
|
24
|
+
|
|
25
|
+
setattr(Credentials, '__module__', 'dex_connectors.vercel.client')
|
|
@@ -0,0 +1,137 @@
|
|
|
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_DEPLOYMENT_DEFINITION, LIST_DEPLOYMENTS_DEFINITION
|
|
13
|
+
from ..models import Deployment, DeploymentsPage, GetDeploymentInput, ListDeploymentsInput
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_list_deployments', '_get_deployment', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
list_deployments: Query[ListDeploymentsInput, DeploymentsPage],
|
|
22
|
+
get_deployment: Query[GetDeploymentInput, Deployment],
|
|
23
|
+
client: Client | None = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
reference.validate()
|
|
26
|
+
if reference.provider != CONNECTOR_ID or list_deployments is None or get_deployment is None:
|
|
27
|
+
raise ValueError("Vercel connection provider and operations are required")
|
|
28
|
+
if list_deployments.definition().operation != LIST_DEPLOYMENTS_DEFINITION.operation:
|
|
29
|
+
raise ValueError("Vercel connection operation identity differs")
|
|
30
|
+
if get_deployment.definition().operation != GET_DEPLOYMENT_DEFINITION.operation:
|
|
31
|
+
raise ValueError("Vercel connection operation identity differs")
|
|
32
|
+
self.reference = reference
|
|
33
|
+
self._list_deployments = list_deployments
|
|
34
|
+
self._get_deployment = get_deployment
|
|
35
|
+
self._client = client
|
|
36
|
+
|
|
37
|
+
def list_deployments(self) -> Query[ListDeploymentsInput, DeploymentsPage]:
|
|
38
|
+
return self._list_deployments
|
|
39
|
+
|
|
40
|
+
def get_deployment(self) -> Query[GetDeploymentInput, Deployment]:
|
|
41
|
+
return self._get_deployment
|
|
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 "vercel.Connection([REDACTED])"
|
|
49
|
+
|
|
50
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
51
|
+
raise TypeError("Vercel connections cannot be serialized")
|
|
52
|
+
|
|
53
|
+
setattr(Connection, '__module__', 'dex_connectors.vercel.connection')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
57
|
+
if client is None:
|
|
58
|
+
raise ValueError("Vercel client is required")
|
|
59
|
+
return Connection(reference, client.list_deployments(), client.get_deployment(), client)
|
|
60
|
+
|
|
61
|
+
setattr(new_connection, '__module__', 'dex_connectors.vercel.connection')
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def new_connection_with_operations(
|
|
65
|
+
list_deployments: Query[ListDeploymentsInput, DeploymentsPage],
|
|
66
|
+
get_deployment: Query[GetDeploymentInput, Deployment],
|
|
67
|
+
reference: ConnectionRef,
|
|
68
|
+
) -> Connection:
|
|
69
|
+
return Connection(reference, list_deployments, get_deployment)
|
|
70
|
+
|
|
71
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.vercel.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("Vercel stored credential does not match the connector credential fields")
|
|
84
|
+
if set(material) - set(('access_token',)):
|
|
85
|
+
raise ValueError("Vercel stored credential does not match the connector credential fields")
|
|
86
|
+
access_token = material.get("access_token")
|
|
87
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
88
|
+
raise ValueError("Vercel credential access_token has an invalid type")
|
|
89
|
+
if not access_token:
|
|
90
|
+
raise ValueError("Vercel credential access_token is required")
|
|
91
|
+
return Credentials(SecretString(access_token))
|
|
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("Vercel 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("Vercel project connection is missing or duplicated")
|
|
109
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
110
|
+
raise ValueError("Vercel 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.vercel.connection')
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
119
|
+
if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
|
|
120
|
+
raise ValueError("Vercel 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("Vercel configuration baseUrl has an invalid type")
|
|
126
|
+
config_arguments['base_url'] = base_url
|
|
127
|
+
if "timeout" in value:
|
|
128
|
+
timeout = value["timeout"]
|
|
129
|
+
if not (type(timeout) is int):
|
|
130
|
+
raise ValueError("Vercel configuration timeout has an invalid type")
|
|
131
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
132
|
+
if "maxResponseBytes" in value:
|
|
133
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
134
|
+
if not (type(max_response_bytes) is int):
|
|
135
|
+
raise ValueError("Vercel configuration maxResponseBytes has an invalid type")
|
|
136
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
137
|
+
return Config(**config_arguments)
|
|
@@ -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 = "vercel"
|
|
18
|
+
PROVIDER = "vercel"
|
|
19
|
+
LIST_DEPLOYMENTS_OPERATION_ID = "listDeployments"
|
|
20
|
+
GET_DEPLOYMENT_OPERATION_ID = "getDeployment"
|
|
21
|
+
DEFECT = "defect"
|
|
22
|
+
FOUND = "found"
|
|
23
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
24
|
+
LISTED = "listed"
|
|
25
|
+
NOT_FOUND = "notFound"
|
|
26
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
27
|
+
|
|
28
|
+
LIST_DEPLOYMENTS_DEFINITION = QueryDefinition(
|
|
29
|
+
OperationRef(CONNECTOR_ID, LIST_DEPLOYMENTS_OPERATION_ID),
|
|
30
|
+
(
|
|
31
|
+
BranchDefinition(LISTED, "List deployments visible to a personal account or team.", False),
|
|
32
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
33
|
+
BranchDefinition(INVALID_RESPONSE, "The provider 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_DEPLOYMENT_DEFINITION = QueryDefinition(
|
|
44
|
+
OperationRef(CONNECTOR_ID, GET_DEPLOYMENT_OPERATION_ID),
|
|
45
|
+
(
|
|
46
|
+
BranchDefinition(FOUND, "Read a deployment by Vercel deployment ID or hostname.", False),
|
|
47
|
+
BranchDefinition(NOT_FOUND, "The requested resource does not exist or is inaccessible.", True),
|
|
48
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
49
|
+
BranchDefinition(INVALID_RESPONSE, "The provider 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
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
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 Deployment, DeploymentsPage, GetDeploymentInput, ListDeploymentsInput, Pagination
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, FOUND, GET_DEPLOYMENT_DEFINITION, INVALID_RESPONSE, LISTED, LIST_DEPLOYMENTS_DEFINITION, NOT_FOUND, PROVIDER_REJECTED
|
|
13
|
+
|
|
14
|
+
def list_deployments_listed(value: DeploymentsPage, failure: Failure | None = None) -> Case[DeploymentsPage]:
|
|
15
|
+
return Case.branch_result(LISTED, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(list_deployments_listed, '__module__', "dex_connectors.vercel.vercelmock")
|
|
18
|
+
|
|
19
|
+
def list_deployments_provider_rejected(value: DeploymentsPage, failure: Failure | None = None) -> Case[DeploymentsPage]:
|
|
20
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(list_deployments_provider_rejected, '__module__', "dex_connectors.vercel.vercelmock")
|
|
23
|
+
|
|
24
|
+
def list_deployments_invalid_response(value: DeploymentsPage, failure: Failure | None = None) -> Case[DeploymentsPage]:
|
|
25
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(list_deployments_invalid_response, '__module__', "dex_connectors.vercel.vercelmock")
|
|
28
|
+
|
|
29
|
+
def list_deployments_defect(value: DeploymentsPage, failure: Failure | None = None) -> Case[DeploymentsPage]:
|
|
30
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(list_deployments_defect, '__module__', "dex_connectors.vercel.vercelmock")
|
|
33
|
+
|
|
34
|
+
def list_deployments_retry(failure: Failure, after_seconds: float = 0) -> Case[DeploymentsPage]:
|
|
35
|
+
return Case.retry(failure, after_seconds)
|
|
36
|
+
|
|
37
|
+
setattr(list_deployments_retry, '__module__', "dex_connectors.vercel.vercelmock")
|
|
38
|
+
|
|
39
|
+
def list_deployments_listed_default() -> Case[DeploymentsPage]:
|
|
40
|
+
return Case.branch_result(LISTED, DeploymentsPage(deployments=(Deployment(uid='dpl_meridian1', name='meridian-web', url='meridian-web.vercel.app', state='READY', created=1761436800000),), pagination=Pagination(next=None)))
|
|
41
|
+
|
|
42
|
+
setattr(list_deployments_listed_default, '__module__', "dex_connectors.vercel.vercelmock")
|
|
43
|
+
|
|
44
|
+
def get_deployment_found(value: Deployment, failure: Failure | None = None) -> Case[Deployment]:
|
|
45
|
+
return Case.branch_result(FOUND, value, failure)
|
|
46
|
+
|
|
47
|
+
setattr(get_deployment_found, '__module__', "dex_connectors.vercel.vercelmock")
|
|
48
|
+
|
|
49
|
+
def get_deployment_not_found(value: Deployment, failure: Failure | None = None) -> Case[Deployment]:
|
|
50
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
51
|
+
|
|
52
|
+
setattr(get_deployment_not_found, '__module__', "dex_connectors.vercel.vercelmock")
|
|
53
|
+
|
|
54
|
+
def get_deployment_provider_rejected(value: Deployment, failure: Failure | None = None) -> Case[Deployment]:
|
|
55
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
56
|
+
|
|
57
|
+
setattr(get_deployment_provider_rejected, '__module__', "dex_connectors.vercel.vercelmock")
|
|
58
|
+
|
|
59
|
+
def get_deployment_invalid_response(value: Deployment, failure: Failure | None = None) -> Case[Deployment]:
|
|
60
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
61
|
+
|
|
62
|
+
setattr(get_deployment_invalid_response, '__module__', "dex_connectors.vercel.vercelmock")
|
|
63
|
+
|
|
64
|
+
def get_deployment_defect(value: Deployment, failure: Failure | None = None) -> Case[Deployment]:
|
|
65
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
66
|
+
|
|
67
|
+
setattr(get_deployment_defect, '__module__', "dex_connectors.vercel.vercelmock")
|
|
68
|
+
|
|
69
|
+
def get_deployment_retry(failure: Failure, after_seconds: float = 0) -> Case[Deployment]:
|
|
70
|
+
return Case.retry(failure, after_seconds)
|
|
71
|
+
|
|
72
|
+
setattr(get_deployment_retry, '__module__', "dex_connectors.vercel.vercelmock")
|
|
73
|
+
|
|
74
|
+
def get_deployment_found_default() -> Case[Deployment]:
|
|
75
|
+
return Case.branch_result(FOUND, Deployment(uid='dpl_meridian1', name='meridian-web', url='meridian-web.vercel.app', state='READY', created=1761436800000))
|
|
76
|
+
|
|
77
|
+
setattr(get_deployment_found_default, '__module__', "dex_connectors.vercel.vercelmock")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Mock:
|
|
81
|
+
|
|
82
|
+
def __init__(self, connection_name: str = "vercel") -> None:
|
|
83
|
+
self.list_deployments_script: Query[ListDeploymentsInput, DeploymentsPage] = Query(LIST_DEPLOYMENTS_DEFINITION)
|
|
84
|
+
self.list_deployments_script.default(list_deployments_listed_default())
|
|
85
|
+
self.get_deployment_script: Query[GetDeploymentInput, Deployment] = Query(GET_DEPLOYMENT_DEFINITION)
|
|
86
|
+
self.get_deployment_script.default(get_deployment_found_default())
|
|
87
|
+
self._connection = new_connection_with_operations(
|
|
88
|
+
list_deployments=self.list_deployments_script,
|
|
89
|
+
get_deployment=self.get_deployment_script,
|
|
90
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def connection(self) -> Connection:
|
|
94
|
+
return self._connection
|
|
95
|
+
|
|
96
|
+
setattr(Mock, '__module__', "dex_connectors.vercel.vercelmock")
|
|
97
|
+
|
|
98
|
+
__all__ = [
|
|
99
|
+
"Mock",
|
|
100
|
+
"list_deployments_listed",
|
|
101
|
+
"list_deployments_provider_rejected",
|
|
102
|
+
"list_deployments_invalid_response",
|
|
103
|
+
"list_deployments_defect",
|
|
104
|
+
"list_deployments_retry",
|
|
105
|
+
"list_deployments_listed_default",
|
|
106
|
+
"get_deployment_found",
|
|
107
|
+
"get_deployment_not_found",
|
|
108
|
+
"get_deployment_provider_rejected",
|
|
109
|
+
"get_deployment_invalid_response",
|
|
110
|
+
"get_deployment_defect",
|
|
111
|
+
"get_deployment_retry",
|
|
112
|
+
"get_deployment_found_default",
|
|
113
|
+
]
|