dex-connector-superdurable-webhook 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_superdurable_webhook-0.1.0/.gitignore +16 -0
- dex_connector_superdurable_webhook-0.1.0/PKG-INFO +37 -0
- dex_connector_superdurable_webhook-0.1.0/README.md +26 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/README.md +53 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/__init__.py +3 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/flow.py +59 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/integration_test.py +113 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/sample-input.json +6 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/start.py +60 -0
- dex_connector_superdurable_webhook-0.1.0/examples/send_event/worker.py +53 -0
- dex_connector_superdurable_webhook-0.1.0/pyproject.toml +37 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/__init__.py +23 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/__init__.py +2 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/config.py +33 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/connection.py +179 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/definitions.py +36 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/mock.py +68 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/models.py +29 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/_generated/steps.py +75 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/client.py +73 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/connection.py +12 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/dex-connector.json +39 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/models.py +7 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/operations.py +138 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/py.typed +0 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/steps.py +7 -0
- dex_connector_superdurable_webhook-0.1.0/src/dex_connectors/superdurable_webhook/webhookmock/__init__.py +6 -0
- dex_connector_superdurable_webhook-0.1.0/tests/test_client.py +144 -0
- dex_connector_superdurable_webhook-0.1.0/tests/test_conformance.py +58 -0
- dex_connector_superdurable_webhook-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,37 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-superdurable-webhook
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Super Durable Webhook 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
|
+
# Super Durable Webhook Python connector
|
|
13
|
+
|
|
14
|
+
The `dex-connector-superdurable-webhook` package implements `sendEvent` for
|
|
15
|
+
Python Dex Flows. It sends one JSON value to the connection's HTTPS
|
|
16
|
+
`deliveryUrl` with Standard Webhooks `webhook-id`, `webhook-timestamp`, and
|
|
17
|
+
`webhook-signature` headers. The same Dex call retains its webhook ID across
|
|
18
|
+
retries. The receiver must deduplicate that ID as described in the
|
|
19
|
+
[connector contract](../README.md#the-sendevent-mutation).
|
|
20
|
+
|
|
21
|
+
The Python package does not implement the Go `requestReceived` Trigger.
|
|
22
|
+
Configure `signing_secret` and `deliveryUrl` in Dex Web **Connections**, using
|
|
23
|
+
the [provider setup guide](../README.md#sender-setup). The secret never enters
|
|
24
|
+
Flow input or Results. An invalid destination or payload selects
|
|
25
|
+
`defect`; a definite receiver rejection selects `rejected`. Both are optional
|
|
26
|
+
branches, so the [runnable Flow](examples/send_event/flow.py) leaves them
|
|
27
|
+
unwired and fails when selected.
|
|
28
|
+
|
|
29
|
+
`SendEventInput.payload` accepts any JSON value, including `None` for JSON
|
|
30
|
+
`null`. Pass UTF-8 JSON `bytes` to send and sign the exact bytes supplied;
|
|
31
|
+
otherwise the connector encodes the Python value as JSON before checking
|
|
32
|
+
`maxBodyBytes`.
|
|
33
|
+
|
|
34
|
+
Run the [send event example](examples/send_event/README.md) to exercise the
|
|
35
|
+
package through a Dex Worker and Client. Its static connection name is
|
|
36
|
+
`webhook-forwarding`. The example's `SendSignedWebhookEvent` Step exposes no
|
|
37
|
+
operation-specific configuration fields in Dex Web.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Super Durable Webhook Python connector
|
|
2
|
+
|
|
3
|
+
The `dex-connector-superdurable-webhook` package implements `sendEvent` for
|
|
4
|
+
Python Dex Flows. It sends one JSON value to the connection's HTTPS
|
|
5
|
+
`deliveryUrl` with Standard Webhooks `webhook-id`, `webhook-timestamp`, and
|
|
6
|
+
`webhook-signature` headers. The same Dex call retains its webhook ID across
|
|
7
|
+
retries. The receiver must deduplicate that ID as described in the
|
|
8
|
+
[connector contract](../README.md#the-sendevent-mutation).
|
|
9
|
+
|
|
10
|
+
The Python package does not implement the Go `requestReceived` Trigger.
|
|
11
|
+
Configure `signing_secret` and `deliveryUrl` in Dex Web **Connections**, using
|
|
12
|
+
the [provider setup guide](../README.md#sender-setup). The secret never enters
|
|
13
|
+
Flow input or Results. An invalid destination or payload selects
|
|
14
|
+
`defect`; a definite receiver rejection selects `rejected`. Both are optional
|
|
15
|
+
branches, so the [runnable Flow](examples/send_event/flow.py) leaves them
|
|
16
|
+
unwired and fails when selected.
|
|
17
|
+
|
|
18
|
+
`SendEventInput.payload` accepts any JSON value, including `None` for JSON
|
|
19
|
+
`null`. Pass UTF-8 JSON `bytes` to send and sign the exact bytes supplied;
|
|
20
|
+
otherwise the connector encodes the Python value as JSON before checking
|
|
21
|
+
`maxBodyBytes`.
|
|
22
|
+
|
|
23
|
+
Run the [send event example](examples/send_event/README.md) to exercise the
|
|
24
|
+
package through a Dex Worker and Client. Its static connection name is
|
|
25
|
+
`webhook-forwarding`. The example's `SendSignedWebhookEvent` Step exposes no
|
|
26
|
+
operation-specific configuration fields in Dex Web.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Signed event delivery Flow for Python
|
|
2
|
+
|
|
3
|
+
This Flow POSTs the JSON value in [`sample-input.json`](sample-input.json) to
|
|
4
|
+
one HTTPS receiver and completes with its status and stable webhook ID. Its
|
|
5
|
+
static Dex connection is `webhook / webhook-forwarding`. The `rejected` and
|
|
6
|
+
`defect` branches fail the Flow. The receiver should record each `webhook-id`
|
|
7
|
+
with the event it applies and answer 2xx when the same ID arrives again.
|
|
8
|
+
|
|
9
|
+
From `connectors/superdurable/webhook/python`, install and generate strict FDG
|
|
10
|
+
2.0 with the latest stable Dex CLI:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
uv sync --locked
|
|
14
|
+
mkdir -p build
|
|
15
|
+
dexcli visualize examples/send_event/flow.py --language python \
|
|
16
|
+
--python .venv/bin/python --schema-version 2.0 --json \
|
|
17
|
+
--out build/send-event
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The graph must report `valid: true`. Start `dexcli dev
|
|
21
|
+
--flow-rendering-dir ./build`, then open Dex Web **Connections** and configure
|
|
22
|
+
`webhook / webhook-forwarding`. Set `deliveryUrl` to the receiver's HTTPS URL
|
|
23
|
+
from its endpoint or webhook settings; the URL must contain no embedded
|
|
24
|
+
secret. Enter `signing_secret` as the whole `whsec_` secret issued by a
|
|
25
|
+
Standard Webhooks receiver or another shared secret it expects. The
|
|
26
|
+
[connector setup guide](../../../README.md#sender-setup) explains the other
|
|
27
|
+
authorization and incoming request fields. They are unnecessary for this
|
|
28
|
+
outgoing-only Flow. The Step has no additional configuration units.
|
|
29
|
+
|
|
30
|
+
Point `DEX_CONNECTOR_CONFIG_FILE` at the owner-only `connections.json` written
|
|
31
|
+
by the Dex Web project. Run the Worker and then start with a unique Flow ID:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
|
|
35
|
+
DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json \
|
|
36
|
+
uv run python -m examples.send_event.worker
|
|
37
|
+
|
|
38
|
+
DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
|
|
39
|
+
DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json \
|
|
40
|
+
uv run python -m examples.send_event.start \
|
|
41
|
+
webhook-send-001 examples/send_event/sample-input.json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
With `dexcli dev` running, the checked-in integration test uses its real
|
|
45
|
+
Worker and Client while a credential-safe fake receiver verifies the
|
|
46
|
+
signature, returns 503 once, and then acknowledges the repeated webhook ID:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
|
|
50
|
+
uv run pytest examples/send_event/integration_test.py
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This test does not verify a live receiver or real Dex Web authorization.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Deliver one signed JSON event through a named webhook connection."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import MutationResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.superdurable_webhook import (
|
|
9
|
+
Connection,
|
|
10
|
+
SendEventInput,
|
|
11
|
+
SendEventOutput,
|
|
12
|
+
new_send_event_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
CONNECTION_NAME = "webhook-forwarding"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# dex:group group-id:send-event group-label:"Send event"
|
|
19
|
+
# dex:explanation text:"Complete after the receiver acknowledges the signed event."
|
|
20
|
+
class CompleteDelivery(dex.Step[MutationResult[SendEventOutput]]):
|
|
21
|
+
"""Return the receiver status and stable webhook ID."""
|
|
22
|
+
|
|
23
|
+
def execute(self, context: dex.Context, input: MutationResult[SendEventOutput]) -> dex.StepDecision:
|
|
24
|
+
"""Complete with the non-secret delivery outcome."""
|
|
25
|
+
return dex.graceful_complete(input.value)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SendEventFlow(dex.Flow[SendEventInput]):
|
|
29
|
+
"""Send a JSON event using the static webhook-forwarding connection."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, connection: Connection) -> None:
|
|
32
|
+
if connection is None or connection.reference.name != CONNECTION_NAME:
|
|
33
|
+
raise ValueError("send event requires the static webhook connection")
|
|
34
|
+
self.complete = CompleteDelivery()
|
|
35
|
+
self.send = new_send_event_step(
|
|
36
|
+
step_type="SendSignedWebhookEvent",
|
|
37
|
+
step_input_type=SendEventInput,
|
|
38
|
+
annotations={
|
|
39
|
+
"groupId": "send-event",
|
|
40
|
+
"groupLabel": "Send event",
|
|
41
|
+
"explanation": "Sign and POST the event with a stable webhook ID.",
|
|
42
|
+
},
|
|
43
|
+
connection=connection,
|
|
44
|
+
connection_name=CONNECTION_NAME,
|
|
45
|
+
map_to_operation_input=lambda input: input,
|
|
46
|
+
delivered=self.complete,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def get_flow_type(self) -> str:
|
|
50
|
+
"""Return the durable delivery Flow identity."""
|
|
51
|
+
return "WebhookSendEventPython"
|
|
52
|
+
|
|
53
|
+
def get_steps(self) -> dex.StepList[SendEventInput]:
|
|
54
|
+
"""Register the provider Mutation and completion Step."""
|
|
55
|
+
return dex.StepList.start_step(self.send).other_steps(self.complete)
|
|
56
|
+
|
|
57
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
58
|
+
"""Store no Attributes or Streams for this operation-only Flow."""
|
|
59
|
+
return dex.PersistenceSchema.of()
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Exercise signed delivery, retry, and result routing in real Dex."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import base64
|
|
7
|
+
import hashlib
|
|
8
|
+
import hmac
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import tempfile
|
|
12
|
+
from datetime import timedelta
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from uuid import uuid4
|
|
15
|
+
|
|
16
|
+
import dex
|
|
17
|
+
import httpx
|
|
18
|
+
import pytest
|
|
19
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
20
|
+
|
|
21
|
+
from dex_connectors.superdurable_webhook import SendEventOutput, new_project_connection
|
|
22
|
+
|
|
23
|
+
from .flow import CONNECTION_NAME, SendEventFlow
|
|
24
|
+
from .start import start_send_event
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.asyncio
|
|
28
|
+
async def test_signed_event_retries_with_one_id_through_dex(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
29
|
+
"""Verify a real Worker retries 503 and completes on receiver acknowledgment."""
|
|
30
|
+
server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
31
|
+
secret = "inert-webhook-signing-key"
|
|
32
|
+
requests: list[httpx.Request] = []
|
|
33
|
+
|
|
34
|
+
def answer(request: httpx.Request) -> httpx.Response:
|
|
35
|
+
requests.append(request)
|
|
36
|
+
assert request.method == "POST"
|
|
37
|
+
assert str(request.url) == "https://receiver.example.test/hooks?tenant=forms"
|
|
38
|
+
assert request.headers["Content-Type"] == "application/json"
|
|
39
|
+
assert json.loads(request.content) == {
|
|
40
|
+
"type": "form.submitted",
|
|
41
|
+
"data": {"submissionId": "evt_123"},
|
|
42
|
+
}
|
|
43
|
+
signed = (
|
|
44
|
+
request.headers["webhook-id"].encode()
|
|
45
|
+
+ b"."
|
|
46
|
+
+ request.headers["webhook-timestamp"].encode()
|
|
47
|
+
+ b"."
|
|
48
|
+
+ request.content
|
|
49
|
+
)
|
|
50
|
+
expected_signature = (
|
|
51
|
+
"v1," + base64.b64encode(hmac.new(secret.encode(), signed, hashlib.sha256).digest()).decode()
|
|
52
|
+
)
|
|
53
|
+
assert request.headers["webhook-signature"] == expected_signature
|
|
54
|
+
return httpx.Response(503 if len(requests) == 1 else 202)
|
|
55
|
+
|
|
56
|
+
async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as provider_client:
|
|
57
|
+
with tempfile.TemporaryDirectory(prefix="webhook-python-dex-") as cache_directory:
|
|
58
|
+
connections_path = Path(cache_directory) / "connections.json"
|
|
59
|
+
connections_path.write_text(
|
|
60
|
+
json.dumps(
|
|
61
|
+
{
|
|
62
|
+
"schemaVersion": "connectors.dex.dev/local-connections/v1alpha1",
|
|
63
|
+
"connections": [
|
|
64
|
+
{
|
|
65
|
+
"connectorId": "webhook",
|
|
66
|
+
"connectionName": CONNECTION_NAME,
|
|
67
|
+
"modulePath": (
|
|
68
|
+
"github.com/superdurable/dex-connectors-library/connectors/superdurable/webhook"
|
|
69
|
+
),
|
|
70
|
+
"provider": "webhook",
|
|
71
|
+
"authMethodId": "api-key-only",
|
|
72
|
+
"configuration": {
|
|
73
|
+
"deliveryUrl": "https://receiver.example.test/hooks?tenant=forms"
|
|
74
|
+
},
|
|
75
|
+
"credentials": {"signing_secret": secret},
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"triggerBindings": [],
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
connections_path.chmod(0o600)
|
|
83
|
+
monkeypatch.setenv("DEX_CONNECTOR_CONFIG_FILE", str(connections_path))
|
|
84
|
+
project = await load_from_environment({"DEX_CONNECTOR_CONFIG_FILE": str(connections_path)})
|
|
85
|
+
connection = new_project_connection(project, CONNECTION_NAME, provider_client)
|
|
86
|
+
registry = dex.Registry([SendEventFlow(connection)], allow_async_handlers=True)
|
|
87
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(Path(cache_directory) / "blobs"), 1 << 24))
|
|
88
|
+
try:
|
|
89
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
|
|
90
|
+
worker_task = asyncio.create_task(worker.start())
|
|
91
|
+
try:
|
|
92
|
+
await worker.wait_pull_registered(timeout=15)
|
|
93
|
+
async with dex.AsyncClient(
|
|
94
|
+
registry, cache, dex.ClientOptions(server_address=server_address)
|
|
95
|
+
) as dex_client:
|
|
96
|
+
flow_id = f"webhook-python-send-{uuid4().hex}"
|
|
97
|
+
assert await start_send_event(flow_id, Path(__file__).with_name("sample-input.json"))
|
|
98
|
+
result = await asyncio.wait_for(
|
|
99
|
+
dex_client.wait_for_flow(flow_id, timedelta(seconds=30)), 40
|
|
100
|
+
)
|
|
101
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
102
|
+
output = result.single_output(SendEventOutput)
|
|
103
|
+
assert output.status_code == 202
|
|
104
|
+
assert output.webhook_id.startswith("msg_")
|
|
105
|
+
assert len(requests) == 2
|
|
106
|
+
assert requests[0].headers["webhook-id"] == requests[1].headers["webhook-id"]
|
|
107
|
+
finally:
|
|
108
|
+
await worker.stop()
|
|
109
|
+
await worker_task
|
|
110
|
+
finally:
|
|
111
|
+
cache.close()
|
|
112
|
+
await connection.aclose()
|
|
113
|
+
await project.close()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Start a signed webhook delivery Flow with one JSON file."""
|
|
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.superdurable_webhook import SendEventInput, new_project_connection
|
|
15
|
+
|
|
16
|
+
from .flow import CONNECTION_NAME, SendEventFlow
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def start_send_event(flow_id: str, input_file: Path) -> str:
|
|
20
|
+
"""Decode a bounded event and start the registered Dex 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("webhook event input exceeds 65536 bytes")
|
|
25
|
+
input_value = (
|
|
26
|
+
dex.CodecRegistry()
|
|
27
|
+
.resolve(SendEventInput)
|
|
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 = SendEventFlow(connection)
|
|
34
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
35
|
+
with tempfile.TemporaryDirectory(prefix="webhook-python-start-blobs-") as cache_directory:
|
|
36
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 24))
|
|
37
|
+
try:
|
|
38
|
+
address = os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")
|
|
39
|
+
async with dex.AsyncClient(
|
|
40
|
+
registry, cache, dex.ClientOptions(server_address=address)
|
|
41
|
+
) as client:
|
|
42
|
+
return await client.start_flow(flow, flow_id, input_value)
|
|
43
|
+
finally:
|
|
44
|
+
cache.close()
|
|
45
|
+
finally:
|
|
46
|
+
await connection.aclose()
|
|
47
|
+
await project.close()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def main() -> None:
|
|
51
|
+
"""Accept a unique Flow ID and JSON input path."""
|
|
52
|
+
parser = argparse.ArgumentParser(description="Start a signed webhook delivery 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_send_event(arguments.flow_id, arguments.input_file)))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
main()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Serve the signed event Flow on a Dex pull Worker."""
|
|
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.superdurable_webhook import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, SendEventFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Open the Dex Web connection and serve delivery requests."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
try:
|
|
23
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
24
|
+
registry = dex.Registry([SendEventFlow(connection)], allow_async_handlers=True)
|
|
25
|
+
directory = os.environ.get(
|
|
26
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-webhook-python-blobs")
|
|
27
|
+
)
|
|
28
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(directory, 1 << 30))
|
|
29
|
+
try:
|
|
30
|
+
worker = dex.AsyncWorker(
|
|
31
|
+
registry,
|
|
32
|
+
cache,
|
|
33
|
+
dex.WorkerOptions(
|
|
34
|
+
server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
async with worker:
|
|
38
|
+
await worker.start()
|
|
39
|
+
finally:
|
|
40
|
+
cache.close()
|
|
41
|
+
finally:
|
|
42
|
+
if connection is not None:
|
|
43
|
+
await connection.aclose()
|
|
44
|
+
await project.close()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main() -> None:
|
|
48
|
+
"""Run the Worker until interrupted."""
|
|
49
|
+
asyncio.run(run_worker())
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
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-superdurable-webhook"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Super Durable Webhook 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,23 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Signed Standard Webhooks event delivery for Dex 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 SendEventInput, SendEventOutput
|
|
8
|
+
from .operations import SendEventOperation
|
|
9
|
+
from .steps import new_send_event_step
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"Client",
|
|
13
|
+
"Config",
|
|
14
|
+
"Credentials",
|
|
15
|
+
"Connection",
|
|
16
|
+
"SendEventInput",
|
|
17
|
+
"SendEventOutput",
|
|
18
|
+
"SendEventOperation",
|
|
19
|
+
"new_connection",
|
|
20
|
+
"new_connection_with_operations",
|
|
21
|
+
"new_project_connection",
|
|
22
|
+
"new_send_event_step",
|
|
23
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
signature_prefix: str
|
|
14
|
+
event_id_header: str
|
|
15
|
+
event_id_pointer: str
|
|
16
|
+
forwarded_headers: tuple[str, ...]
|
|
17
|
+
delivery_url: str
|
|
18
|
+
verification: str = "hmacSha256"
|
|
19
|
+
signature_header: str = "X-Signature-256"
|
|
20
|
+
signature_encoding: str = "hex"
|
|
21
|
+
timestamp_tolerance_seconds: int = 300
|
|
22
|
+
token_header: str = "X-Webhook-Token"
|
|
23
|
+
max_body_bytes: int = 1048576
|
|
24
|
+
|
|
25
|
+
setattr(Config, '__module__', 'dex_connectors.superdurable_webhook.client')
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class Credentials:
|
|
30
|
+
|
|
31
|
+
signing_secret: SecretString
|
|
32
|
+
|
|
33
|
+
setattr(Credentials, '__module__', 'dex_connectors.superdurable_webhook.client')
|