hookbase 4.2.0__tar.gz → 4.3.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.
- {hookbase-4.2.0 → hookbase-4.3.0}/PKG-INFO +39 -1
- {hookbase-4.2.0 → hookbase-4.3.0}/README.md +38 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/_client.py +24 -3
- hookbase-4.3.0/src/hookbase/_version.py +1 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/__init__.py +37 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/events.py +6 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/sources.py +248 -1
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/_base.py +6 -2
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/sources.py +171 -0
- hookbase-4.3.0/tests/resources/test_source_connections.py +539 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_sync_async_parity.py +36 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_models_exports.py +11 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_retry.py +2 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_secret_redaction.py +7 -0
- hookbase-4.2.0/src/hookbase/_version.py +0 -1
- {hookbase-4.2.0 → hookbase-4.3.0}/.github/workflows/python-publish.yml +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/.gitignore +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/LICENSE +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/examples/async_usage.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/examples/basic_inbound.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/examples/error_handling.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/examples/send_webhooks.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/examples/verify_webhooks.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/pyproject.toml +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/__init__.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/_constants.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/_pagination.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/client.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/errors.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/_base.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/_wire.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/analytics.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/api_keys.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/applications.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/catalog.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/common.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/cron_jobs.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/deliveries.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/destinations.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/dlq.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/endpoints.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/event_types.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/filters.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/messages.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/organizations.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/portal_tokens.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/routes.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/schemas.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/subscriptions.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/transforms.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/models/tunnels.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/py.typed +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/__init__.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/analytics.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/api_keys.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/applications.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/cron_jobs.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/deliveries.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/destinations.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/dlq.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/endpoints.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/event_types.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/events.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/filters.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/message_log.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/messages.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/organizations.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/portal_tokens.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/providers.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/routes.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/schemas.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/subscriptions.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/transforms.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/resources/tunnels.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/src/hookbase/webhook.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/__init__.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/conftest.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/__init__.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_applications.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_cron_jobs.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_destinations.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_dlq.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_endpoints.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_inbound_contract.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_messages.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_open_types.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_outbound_contract.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_resource_contracts.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_source_contract.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_source_fields.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/resources/test_sources.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_client.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_errors.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_http_client.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_pagination.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_slug_contract.py +0 -0
- {hookbase-4.2.0 → hookbase-4.3.0}/tests/test_webhook.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: hookbase
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.3.0
|
|
4
4
|
Summary: Official Python SDK for the Hookbase webhook management platform
|
|
5
5
|
Project-URL: Homepage, https://hookbase.app
|
|
6
6
|
Project-URL: Documentation, https://www.hookbase.app/docs/send/sdk
|
|
@@ -140,6 +140,23 @@ client.sources.rotate_verify_token(wa.id)
|
|
|
140
140
|
pending = client.sources.get_pending_verification("notion")
|
|
141
141
|
client.sources.adopt_pending_verification("notion")
|
|
142
142
|
|
|
143
|
+
# Connected sources: give Hookbase a least-privilege provider key (Stripe, GitHub or Paddle) and
|
|
144
|
+
# it registers the webhook, holds its signing secret, and recovers events the provider failed to
|
|
145
|
+
# deliver (Pro and Business). The key is never returned or logged, and ConnectSourceParams
|
|
146
|
+
# leaves it out of repr().
|
|
147
|
+
result = client.sources.connect("src_id", {"provider": "stripe", "credential": "rk_live_..."})
|
|
148
|
+
result.connection.status, result.connection.credential_hint, result.warnings
|
|
149
|
+
client.sources.connect("src_gh", {"provider": "github", "credential": "github_pat_...",
|
|
150
|
+
"githubRepository": "acme/api", "events": ["push"]})
|
|
151
|
+
client.sources.get_connection("src_id") # None when not connected; .last_run, .recovered_total
|
|
152
|
+
client.sources.update_connection("src_id", {"credential": "rk_live_..."}) # replace the key
|
|
153
|
+
client.sources.update_connection("src_id", {"reconcileEnabled": False})
|
|
154
|
+
client.sources.run_recovery("src_id") # True; ConflictError with details["reason"] if refused
|
|
155
|
+
client.sources.list_recovery_items("src_id", status="gave_up", limit=20)
|
|
156
|
+
client.sources.disconnect("src_id") # .remote_removed, .retrying, .message
|
|
157
|
+
client.sources.get("src_id").connection # summary on list() and get(); None if not connected
|
|
158
|
+
client.events.get("evt_id").recovery # .method, .recovered_at when recovery delivered it
|
|
159
|
+
|
|
143
160
|
# Provider catalog: which secret each provider needs (public, no auth needed)
|
|
144
161
|
for p in client.providers.list(category="payments").providers:
|
|
145
162
|
print(p.hookbase_provider, p.signature_verification and p.signature_verification.secret_source)
|
|
@@ -418,6 +435,10 @@ Up to `max_retries` retries (default 3):
|
|
|
418
435
|
is retried only when it carries an idempotency key (`outbound.messages.send` always does).
|
|
419
436
|
- **A connection that was never made** is always retried.
|
|
420
437
|
- **Other 4xx** responses are never retried.
|
|
438
|
+
- `sources.connect()`, and `sources.update_connection()` with a `credential`, are not retried
|
|
439
|
+
after a 5xx, a read timeout or a dropped connection, since a second attempt could register the
|
|
440
|
+
provider webhook twice. A 429 is still retried. After such a failure (or a 503 with code
|
|
441
|
+
`CONNECT_OUTCOME_UNKNOWN`), call `sources.get_connection()` before connecting again.
|
|
421
442
|
|
|
422
443
|
### Pydantic Models
|
|
423
444
|
|
|
@@ -437,6 +458,23 @@ source = client.sources.create({"name": "GitHub", "slug": "github", "provider":
|
|
|
437
458
|
# source with a provider newer than this package still parses.
|
|
438
459
|
```
|
|
439
460
|
|
|
461
|
+
## Upgrading to 4.3
|
|
462
|
+
|
|
463
|
+
- Connected sources: `sources.connect()`, `get_connection()`, `update_connection()`,
|
|
464
|
+
`disconnect()`, `run_recovery()` and `list_recovery_items()`, with the models
|
|
465
|
+
`ConnectSourceParams`, `UpdateSourceConnectionParams`, `SourceConnection`,
|
|
466
|
+
`ConnectSourceResult`, `DisconnectSourceResult`, `RecoveryRun` and `RecoveryItem`.
|
|
467
|
+
`credential` is left out of `repr()`, `str()` and validation errors, and is never logged.
|
|
468
|
+
`connect()` (and `update_connection()` with a `credential`) is not retried after a 5xx, a
|
|
469
|
+
timeout or a dropped connection; see [Retries](#retries).
|
|
470
|
+
- `Source.connection` (`SourceConnectionSummary`: provider, status, environment,
|
|
471
|
+
reconcile_enabled) on `list()` and `get()`, None when the source isn't connected.
|
|
472
|
+
- `EventDetail.recovery` and `events.debug().event.recovery` (`EventRecovery`: method,
|
|
473
|
+
recovered_at), set when recovery got the event to its source.
|
|
474
|
+
- The connection error codes (`INVALID_CREDENTIAL`, `PROVIDER_CREDENTIAL_INVALID`,
|
|
475
|
+
`CONNECTION_CONFLICT`, `CONNECT_OUTCOME_UNKNOWN`, ...) arrive in `APIError.code`; a refused
|
|
476
|
+
`run_recovery()` carries its `reason` in `details`, and a 429 its `retryAfter` there too.
|
|
477
|
+
|
|
440
478
|
## Upgrading to 4.2
|
|
441
479
|
|
|
442
480
|
- **Fix:** `destinations.list()` and `get()` raised a `ValidationError` when the organization had
|
|
@@ -102,6 +102,23 @@ client.sources.rotate_verify_token(wa.id)
|
|
|
102
102
|
pending = client.sources.get_pending_verification("notion")
|
|
103
103
|
client.sources.adopt_pending_verification("notion")
|
|
104
104
|
|
|
105
|
+
# Connected sources: give Hookbase a least-privilege provider key (Stripe, GitHub or Paddle) and
|
|
106
|
+
# it registers the webhook, holds its signing secret, and recovers events the provider failed to
|
|
107
|
+
# deliver (Pro and Business). The key is never returned or logged, and ConnectSourceParams
|
|
108
|
+
# leaves it out of repr().
|
|
109
|
+
result = client.sources.connect("src_id", {"provider": "stripe", "credential": "rk_live_..."})
|
|
110
|
+
result.connection.status, result.connection.credential_hint, result.warnings
|
|
111
|
+
client.sources.connect("src_gh", {"provider": "github", "credential": "github_pat_...",
|
|
112
|
+
"githubRepository": "acme/api", "events": ["push"]})
|
|
113
|
+
client.sources.get_connection("src_id") # None when not connected; .last_run, .recovered_total
|
|
114
|
+
client.sources.update_connection("src_id", {"credential": "rk_live_..."}) # replace the key
|
|
115
|
+
client.sources.update_connection("src_id", {"reconcileEnabled": False})
|
|
116
|
+
client.sources.run_recovery("src_id") # True; ConflictError with details["reason"] if refused
|
|
117
|
+
client.sources.list_recovery_items("src_id", status="gave_up", limit=20)
|
|
118
|
+
client.sources.disconnect("src_id") # .remote_removed, .retrying, .message
|
|
119
|
+
client.sources.get("src_id").connection # summary on list() and get(); None if not connected
|
|
120
|
+
client.events.get("evt_id").recovery # .method, .recovered_at when recovery delivered it
|
|
121
|
+
|
|
105
122
|
# Provider catalog: which secret each provider needs (public, no auth needed)
|
|
106
123
|
for p in client.providers.list(category="payments").providers:
|
|
107
124
|
print(p.hookbase_provider, p.signature_verification and p.signature_verification.secret_source)
|
|
@@ -380,6 +397,10 @@ Up to `max_retries` retries (default 3):
|
|
|
380
397
|
is retried only when it carries an idempotency key (`outbound.messages.send` always does).
|
|
381
398
|
- **A connection that was never made** is always retried.
|
|
382
399
|
- **Other 4xx** responses are never retried.
|
|
400
|
+
- `sources.connect()`, and `sources.update_connection()` with a `credential`, are not retried
|
|
401
|
+
after a 5xx, a read timeout or a dropped connection, since a second attempt could register the
|
|
402
|
+
provider webhook twice. A 429 is still retried. After such a failure (or a 503 with code
|
|
403
|
+
`CONNECT_OUTCOME_UNKNOWN`), call `sources.get_connection()` before connecting again.
|
|
383
404
|
|
|
384
405
|
### Pydantic Models
|
|
385
406
|
|
|
@@ -399,6 +420,23 @@ source = client.sources.create({"name": "GitHub", "slug": "github", "provider":
|
|
|
399
420
|
# source with a provider newer than this package still parses.
|
|
400
421
|
```
|
|
401
422
|
|
|
423
|
+
## Upgrading to 4.3
|
|
424
|
+
|
|
425
|
+
- Connected sources: `sources.connect()`, `get_connection()`, `update_connection()`,
|
|
426
|
+
`disconnect()`, `run_recovery()` and `list_recovery_items()`, with the models
|
|
427
|
+
`ConnectSourceParams`, `UpdateSourceConnectionParams`, `SourceConnection`,
|
|
428
|
+
`ConnectSourceResult`, `DisconnectSourceResult`, `RecoveryRun` and `RecoveryItem`.
|
|
429
|
+
`credential` is left out of `repr()`, `str()` and validation errors, and is never logged.
|
|
430
|
+
`connect()` (and `update_connection()` with a `credential`) is not retried after a 5xx, a
|
|
431
|
+
timeout or a dropped connection; see [Retries](#retries).
|
|
432
|
+
- `Source.connection` (`SourceConnectionSummary`: provider, status, environment,
|
|
433
|
+
reconcile_enabled) on `list()` and `get()`, None when the source isn't connected.
|
|
434
|
+
- `EventDetail.recovery` and `events.debug().event.recovery` (`EventRecovery`: method,
|
|
435
|
+
recovered_at), set when recovery got the event to its source.
|
|
436
|
+
- The connection error codes (`INVALID_CREDENTIAL`, `PROVIDER_CREDENTIAL_INVALID`,
|
|
437
|
+
`CONNECTION_CONFLICT`, `CONNECT_OUTCOME_UNKNOWN`, ...) arrive in `APIError.code`; a refused
|
|
438
|
+
`run_recovery()` carries its `reason` in `details`, and a 429 its `retryAfter` there too.
|
|
439
|
+
|
|
402
440
|
## Upgrading to 4.2
|
|
403
441
|
|
|
404
442
|
- **Fix:** `destinations.list()` and `get()` raised a `ValidationError` when the organization had
|
|
@@ -74,11 +74,18 @@ def _parse_retry_after(header: str | None, now: float | None = None) -> float:
|
|
|
74
74
|
# server (a 5xx, a read timeout, a dropped connection) can do it twice. Only retry those when the
|
|
75
75
|
# request carries an idempotency key the server can deduplicate on. A 429 was rejected before any
|
|
76
76
|
# work was done, and a connect failure never reached the server, so those stay retryable.
|
|
77
|
+
#
|
|
78
|
+
# A few requests that are not POSTs have the same problem, and the resource opts them out with
|
|
79
|
+
# `retry_ambiguous=False`: a source connect (PUT /connection, or a PATCH that carries a new key)
|
|
80
|
+
# registers a webhook at the provider and spends the hourly connect limit, so sending it again after
|
|
81
|
+
# an unknown outcome can register the webhook twice.
|
|
77
82
|
_NON_IDEMPOTENT_METHODS = frozenset({"POST"})
|
|
78
83
|
|
|
79
84
|
|
|
80
|
-
def _may_repeat(method: str, idempotency_key: str | None) -> bool:
|
|
85
|
+
def _may_repeat(method: str, idempotency_key: str | None, retry_ambiguous: bool = True) -> bool:
|
|
81
86
|
"""Whether a request that may already have been processed is safe to send again."""
|
|
87
|
+
if not retry_ambiguous:
|
|
88
|
+
return False
|
|
82
89
|
return method.upper() not in _NON_IDEMPOTENT_METHODS or bool(idempotency_key)
|
|
83
90
|
|
|
84
91
|
|
|
@@ -252,10 +259,17 @@ class SyncTransport(_BaseTransport):
|
|
|
252
259
|
json: Any = None,
|
|
253
260
|
params: dict[str, Any] | None = None,
|
|
254
261
|
idempotency_key: str | None = None,
|
|
262
|
+
retry_ambiguous: bool = True,
|
|
255
263
|
) -> Any:
|
|
264
|
+
"""Send one request, retrying as the module's retry policy allows.
|
|
265
|
+
|
|
266
|
+
``retry_ambiguous=False`` never resends after a failure the server may have acted on (a
|
|
267
|
+
5xx, a read timeout, a dropped connection), whatever the method. A 429, and a connection
|
|
268
|
+
that was never made, are still retried.
|
|
269
|
+
"""
|
|
256
270
|
kwargs = self._request_kwargs(json, params, idempotency_key)
|
|
257
271
|
url = self._url(path)
|
|
258
|
-
repeatable = _may_repeat(method, idempotency_key)
|
|
272
|
+
repeatable = _may_repeat(method, idempotency_key, retry_ambiguous)
|
|
259
273
|
self._log(method, path, kwargs["params"])
|
|
260
274
|
|
|
261
275
|
last_exc: Exception | None = None
|
|
@@ -337,12 +351,19 @@ class AsyncTransport(_BaseTransport):
|
|
|
337
351
|
json: Any = None,
|
|
338
352
|
params: dict[str, Any] | None = None,
|
|
339
353
|
idempotency_key: str | None = None,
|
|
354
|
+
retry_ambiguous: bool = True,
|
|
340
355
|
) -> Any:
|
|
356
|
+
"""Send one request, retrying as the module's retry policy allows.
|
|
357
|
+
|
|
358
|
+
``retry_ambiguous=False`` never resends after a failure the server may have acted on (a
|
|
359
|
+
5xx, a read timeout, a dropped connection), whatever the method. A 429, and a connection
|
|
360
|
+
that was never made, are still retried.
|
|
361
|
+
"""
|
|
341
362
|
import asyncio
|
|
342
363
|
|
|
343
364
|
kwargs = self._request_kwargs(json, params, idempotency_key)
|
|
344
365
|
url = self._url(path)
|
|
345
|
-
repeatable = _may_repeat(method, idempotency_key)
|
|
366
|
+
repeatable = _may_repeat(method, idempotency_key, retry_ambiguous)
|
|
346
367
|
self._log(method, path, kwargs["params"])
|
|
347
368
|
|
|
348
369
|
last_exc: Exception | None = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "4.3.0"
|
|
@@ -164,14 +164,32 @@ from .sources import (
|
|
|
164
164
|
CLEARABLE_SOURCE_FIELDS,
|
|
165
165
|
KNOWN_SOURCE_PROVIDERS,
|
|
166
166
|
ClearableSourceField,
|
|
167
|
+
ConnectionEnvironment,
|
|
168
|
+
ConnectionProvider,
|
|
169
|
+
ConnectionStatus,
|
|
170
|
+
ConnectSourceParams,
|
|
171
|
+
ConnectSourceResult,
|
|
167
172
|
CreateSourceParams,
|
|
168
173
|
DedupStrategy,
|
|
174
|
+
DisconnectSourceResult,
|
|
175
|
+
EventRecovery,
|
|
176
|
+
GithubTarget,
|
|
177
|
+
GithubTargetKind,
|
|
169
178
|
IngestMethod,
|
|
170
179
|
IpFilterMode,
|
|
171
180
|
PendingVerification,
|
|
181
|
+
PriorSourceSettings,
|
|
182
|
+
RecoveryItem,
|
|
183
|
+
RecoveryItemStatus,
|
|
184
|
+
RecoveryMethod,
|
|
185
|
+
RecoveryRun,
|
|
186
|
+
RecoveryStoppedReason,
|
|
172
187
|
Source,
|
|
188
|
+
SourceConnection,
|
|
189
|
+
SourceConnectionSummary,
|
|
173
190
|
SourceProvider,
|
|
174
191
|
SourceWithSecret,
|
|
192
|
+
UpdateSourceConnectionParams,
|
|
175
193
|
UpdateSourceParams,
|
|
176
194
|
)
|
|
177
195
|
from .subscriptions import (
|
|
@@ -370,6 +388,25 @@ __all__ = [
|
|
|
370
388
|
"SourceWithSecret",
|
|
371
389
|
"UpdateSourceParams",
|
|
372
390
|
"IngestMethod",
|
|
391
|
+
# Connected sources
|
|
392
|
+
"ConnectionEnvironment",
|
|
393
|
+
"ConnectionProvider",
|
|
394
|
+
"ConnectionStatus",
|
|
395
|
+
"ConnectSourceParams",
|
|
396
|
+
"ConnectSourceResult",
|
|
397
|
+
"DisconnectSourceResult",
|
|
398
|
+
"EventRecovery",
|
|
399
|
+
"GithubTarget",
|
|
400
|
+
"GithubTargetKind",
|
|
401
|
+
"PriorSourceSettings",
|
|
402
|
+
"RecoveryItem",
|
|
403
|
+
"RecoveryItemStatus",
|
|
404
|
+
"RecoveryMethod",
|
|
405
|
+
"RecoveryRun",
|
|
406
|
+
"RecoveryStoppedReason",
|
|
407
|
+
"SourceConnection",
|
|
408
|
+
"SourceConnectionSummary",
|
|
409
|
+
"UpdateSourceConnectionParams",
|
|
373
410
|
# Subscriptions
|
|
374
411
|
"CreateSubscriptionParams",
|
|
375
412
|
"LabelFilterMode",
|
|
@@ -7,6 +7,7 @@ from pydantic import field_validator, model_validator
|
|
|
7
7
|
|
|
8
8
|
from ._base import HookbaseModel
|
|
9
9
|
from .deliveries import Delivery, DeliveryStatus
|
|
10
|
+
from .sources import EventRecovery
|
|
10
11
|
|
|
11
12
|
# The API derives it from the event's deliveries: delivered, failed, partial (some delivered),
|
|
12
13
|
# pending, no_routes (no route matched) or duplicate. Any string, so a later one still parses.
|
|
@@ -64,6 +65,9 @@ class EventDetail(HookbaseModel):
|
|
|
64
65
|
mask_fields: Any = None
|
|
65
66
|
transient: bool = False
|
|
66
67
|
deliveries: list[EventDelivery] = []
|
|
68
|
+
recovery: EventRecovery | None = None
|
|
69
|
+
"""Set when the provider had failed to deliver the event and connected-source recovery got it
|
|
70
|
+
to the source; otherwise None."""
|
|
67
71
|
|
|
68
72
|
@field_validator("headers", mode="before")
|
|
69
73
|
@classmethod
|
|
@@ -103,6 +107,8 @@ class EventDebugEvent(HookbaseModel):
|
|
|
103
107
|
signature_valid: int | None = None
|
|
104
108
|
received_at: str = ""
|
|
105
109
|
ip_address: str | None = None
|
|
110
|
+
recovery: EventRecovery | None = None
|
|
111
|
+
"""Set when connected-source recovery got the event to its source; otherwise None."""
|
|
106
112
|
|
|
107
113
|
@field_validator("headers", mode="before")
|
|
108
114
|
@classmethod
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
from typing import Any, Literal
|
|
4
|
+
from typing import Any, Literal, Union
|
|
5
5
|
|
|
6
6
|
from pydantic import Field, field_validator
|
|
7
7
|
|
|
@@ -73,6 +73,192 @@ ClearableSourceField = Literal[
|
|
|
73
73
|
]
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
# Connected sources. Each of these is a plain string with the values the API sends today listed
|
|
77
|
+
# for type checkers, so a value added later still parses.
|
|
78
|
+
|
|
79
|
+
#: The provider a source is connected to: stripe, github or paddle.
|
|
80
|
+
ConnectionProvider = Union[Literal["stripe", "github", "paddle"], str]
|
|
81
|
+
#: Set by the key: live or test (Stripe), live (GitHub), live or sandbox (Paddle).
|
|
82
|
+
ConnectionEnvironment = Union[Literal["live", "test", "sandbox"], str]
|
|
83
|
+
#: pending: a connect is in progress. active: registered and in use. error: the last recovery run
|
|
84
|
+
#: failed (see last_error). credential_invalid: the provider refused the stored key; replace it
|
|
85
|
+
#: with Sources.update_connection.
|
|
86
|
+
ConnectionStatus = Union[Literal["pending", "active", "error", "credential_invalid"], str]
|
|
87
|
+
#: How recovery got an event to its source: self_ingest (Hookbase fetched the Stripe event and
|
|
88
|
+
#: ingested it), redelivery (GitHub was asked to redeliver) or replay (Paddle was asked to replay).
|
|
89
|
+
RecoveryMethod = Union[Literal["self_ingest", "redelivery", "replay"], str]
|
|
90
|
+
#: pending: requested or to be retried, not arrived yet. recovered: it reached the source.
|
|
91
|
+
#: gave_up: 3 attempts failed, or the provider no longer has it.
|
|
92
|
+
RecoveryItemStatus = Union[Literal["pending", "recovered", "gave_up"], str]
|
|
93
|
+
#: Why a recovery run ended. needs_action: something on the provider or source has to change (a
|
|
94
|
+
#: permission, a missing webhook, the source's IP allowlist); last_error says what.
|
|
95
|
+
#: source_unavailable: the source is disabled.
|
|
96
|
+
RecoveryStoppedReason = Union[
|
|
97
|
+
Literal[
|
|
98
|
+
"caught_up", "behind", "rate_limited", "credential_invalid", "provider_error",
|
|
99
|
+
"needs_action", "source_unavailable", "ingest_error", "internal_error",
|
|
100
|
+
],
|
|
101
|
+
str,
|
|
102
|
+
]
|
|
103
|
+
#: Where a GitHub connection's webhook is: on one repository, or on an organization.
|
|
104
|
+
GithubTargetKind = Union[Literal["repo", "org"], str]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class SourceConnectionSummary(HookbaseModel):
|
|
108
|
+
"""What a source (list and get) shows about its provider connection."""
|
|
109
|
+
|
|
110
|
+
provider: ConnectionProvider
|
|
111
|
+
status: ConnectionStatus
|
|
112
|
+
environment: ConnectionEnvironment
|
|
113
|
+
#: Recovery is on.
|
|
114
|
+
reconcile_enabled: bool = False
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class RecoveryRun(HookbaseModel):
|
|
118
|
+
"""The result of one recovery run (``SourceConnection.last_run``)."""
|
|
119
|
+
|
|
120
|
+
started_at: str = ""
|
|
121
|
+
finished_at: str = ""
|
|
122
|
+
#: Events the provider listed as not delivered.
|
|
123
|
+
found: int = 0
|
|
124
|
+
#: Events the source turned out to have received after all.
|
|
125
|
+
already_received: int = 0
|
|
126
|
+
#: Events that reached the source: Stripe events Hookbase ingested, and earlier redeliveries
|
|
127
|
+
#: or replays that have since arrived.
|
|
128
|
+
recovered: int = 0
|
|
129
|
+
#: Redeliveries (GitHub) and replays (Paddle) requested.
|
|
130
|
+
requested: int = 0
|
|
131
|
+
#: Events given up on: 3 attempts failed, or the provider no longer has them.
|
|
132
|
+
gave_up: int = 0
|
|
133
|
+
#: There is more to scan; the next run is due within 2 minutes instead of 15.
|
|
134
|
+
behind: bool = False
|
|
135
|
+
stopped_reason: RecoveryStoppedReason | None = None
|
|
136
|
+
#: Stripe only, when set: the scan skipped events from before this time, which were past the
|
|
137
|
+
#: lookback window.
|
|
138
|
+
dropped_before: str | None = None
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class PriorSourceSettings(HookbaseModel):
|
|
142
|
+
"""The source's settings before connect changed them. Disconnecting doesn't restore them."""
|
|
143
|
+
|
|
144
|
+
provider: str | None = None
|
|
145
|
+
had_signing_secret: bool = False
|
|
146
|
+
reject_invalid_signatures: bool | None = None
|
|
147
|
+
dedup_enabled: bool | None = None
|
|
148
|
+
dedup_strategy: str | None = None
|
|
149
|
+
dedup_window_hours: int | None = None
|
|
150
|
+
dedup_custom_header: str | None = None
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class GithubTarget(HookbaseModel):
|
|
154
|
+
"""Where a GitHub connection's webhook is: ``owner``/``repo`` for kind repo, ``org`` for org."""
|
|
155
|
+
|
|
156
|
+
kind: GithubTargetKind
|
|
157
|
+
owner: str | None = None
|
|
158
|
+
repo: str | None = None
|
|
159
|
+
org: str | None = None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class SourceConnection(HookbaseModel):
|
|
163
|
+
"""A source's connection to its provider (Stripe, GitHub or Paddle).
|
|
164
|
+
|
|
165
|
+
Hookbase registered a webhook at the source's ingest URL with the provider API key given to
|
|
166
|
+
:meth:`Sources.connect`, and recovers events the provider failed to deliver. The key is never
|
|
167
|
+
returned; ``credential_hint`` is its prefix and last 4 characters.
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
id: str
|
|
171
|
+
provider: ConnectionProvider
|
|
172
|
+
environment: ConnectionEnvironment
|
|
173
|
+
status: ConnectionStatus
|
|
174
|
+
#: The key's prefix and its last 4 characters, e.g. "rk_live_…a1b2".
|
|
175
|
+
credential_hint: str = ""
|
|
176
|
+
#: When the key expires, where the provider says (GitHub fine-grained tokens).
|
|
177
|
+
credential_expires_at: str | None = None
|
|
178
|
+
#: "Stripe (live mode)", the GitHub "owner/repo" or organization, "Paddle (sandbox)". None
|
|
179
|
+
#: while a connect is pending.
|
|
180
|
+
account_label: str | None = None
|
|
181
|
+
#: The provider's id for the webhook Hookbase created. None until it is registered.
|
|
182
|
+
remote_id: str | None = None
|
|
183
|
+
#: The event types the webhook was registered with; ["*"] for every event.
|
|
184
|
+
events: list[str] = []
|
|
185
|
+
#: The source's settings before connect changed them. None while a connect is pending.
|
|
186
|
+
prior_source_settings: PriorSourceSettings | None = None
|
|
187
|
+
#: GitHub only: where the webhook is. None for other providers.
|
|
188
|
+
github_target: GithubTarget | None = None
|
|
189
|
+
#: Recovery is on. On from connect; recovery runs only on Pro and Business plans.
|
|
190
|
+
reconcile_enabled: bool = False
|
|
191
|
+
#: A recovery run (or a cleanup attempt) is in progress.
|
|
192
|
+
running: bool = False
|
|
193
|
+
#: When recovery is next due. None when recovery is off or the status is pending or
|
|
194
|
+
#: credential_invalid.
|
|
195
|
+
next_run_at: str | None = None
|
|
196
|
+
last_run_at: str | None = None
|
|
197
|
+
#: The last recovery run's result. None before the first run.
|
|
198
|
+
last_run: RecoveryRun | None = None
|
|
199
|
+
#: Why the last run failed, while status is error or credential_invalid.
|
|
200
|
+
last_error: str | None = None
|
|
201
|
+
consecutive_failures: int = 0
|
|
202
|
+
#: Events recovery has got to the source since connect.
|
|
203
|
+
recovered_total: int = 0
|
|
204
|
+
created_at: str = ""
|
|
205
|
+
updated_at: str = ""
|
|
206
|
+
|
|
207
|
+
@field_validator("events", mode="before")
|
|
208
|
+
@classmethod
|
|
209
|
+
def _null_events(cls, v: Any) -> Any:
|
|
210
|
+
return [] if v is None else v
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class ConnectSourceResult(HookbaseModel):
|
|
214
|
+
"""What :meth:`Sources.connect` returns."""
|
|
215
|
+
|
|
216
|
+
connection: SourceConnection
|
|
217
|
+
#: Anything to fix at the provider or on the source: other webhooks that already deliver to
|
|
218
|
+
#: this source (they sign with a different secret, so their deliveries now fail
|
|
219
|
+
#: verification), or a Stripe source's IP allowlist, which would block recovered events.
|
|
220
|
+
warnings: list[str] = []
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class DisconnectSourceResult(HookbaseModel):
|
|
224
|
+
"""What :meth:`Sources.disconnect` returns. A provider failure doesn't fail the disconnect."""
|
|
225
|
+
|
|
226
|
+
success: bool = True
|
|
227
|
+
#: The provider's webhook is gone (or was already).
|
|
228
|
+
remote_removed: bool = False
|
|
229
|
+
#: The webhook couldn't be removed now; Hookbase keeps trying in the background.
|
|
230
|
+
retrying: bool = False
|
|
231
|
+
#: What happened to the webhook when it wasn't removed, e.g. that it must be deleted at the
|
|
232
|
+
#: provider. None when it was removed.
|
|
233
|
+
message: str | None = None
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class RecoveryItem(HookbaseModel):
|
|
237
|
+
"""An event recovery found missing for a source (:meth:`Sources.list_recovery_items`)."""
|
|
238
|
+
|
|
239
|
+
#: The provider's event id: evt_... (Stripe), the delivery guid (GitHub), the event id
|
|
240
|
+
#: (Paddle).
|
|
241
|
+
provider_event_id: str
|
|
242
|
+
method: RecoveryMethod
|
|
243
|
+
status: RecoveryItemStatus
|
|
244
|
+
attempts: int = 0
|
|
245
|
+
#: The provider's id for the delivery (GitHub) or notification (Paddle) that was retried.
|
|
246
|
+
#: None for Stripe.
|
|
247
|
+
provider_ref: str | None = None
|
|
248
|
+
#: The Hookbase event it arrived as, when known.
|
|
249
|
+
event_id: str | None = None
|
|
250
|
+
first_seen_at: str = ""
|
|
251
|
+
last_attempt_at: str | None = None
|
|
252
|
+
recovered_at: str | None = None
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class EventRecovery(HookbaseModel):
|
|
256
|
+
"""How connected-source recovery got an event to its source (``EventDetail.recovery``)."""
|
|
257
|
+
|
|
258
|
+
method: RecoveryMethod
|
|
259
|
+
recovered_at: str = ""
|
|
260
|
+
|
|
261
|
+
|
|
76
262
|
class Source(HookbaseModel):
|
|
77
263
|
"""A source as the API returns it.
|
|
78
264
|
|
|
@@ -114,6 +300,9 @@ class Source(HookbaseModel):
|
|
|
114
300
|
reject_invalid_signatures: bool = False
|
|
115
301
|
rate_limit_per_minute: int | None = None
|
|
116
302
|
is_active: bool = True
|
|
303
|
+
#: The source's connection to its provider (Sources.connect), or None when it isn't connected.
|
|
304
|
+
#: Returned by list() and get().
|
|
305
|
+
connection: SourceConnectionSummary | None = None
|
|
117
306
|
custom_domain_id: str | None = None
|
|
118
307
|
ip_filter_mode: IpFilterMode = "none"
|
|
119
308
|
ip_allowlist: list[str] = []
|
|
@@ -299,3 +488,61 @@ def update_source_body(params: UpdateSourceParams | dict[str, Any]) -> dict[str,
|
|
|
299
488
|
body = _wire.dump(params)
|
|
300
489
|
_wire.apply_clear(body, CLEARABLE_SOURCE_FIELDS, "source")
|
|
301
490
|
return body
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
class ConnectSourceParams(HookbaseModel):
|
|
494
|
+
"""The body of :meth:`Sources.connect`.
|
|
495
|
+
|
|
496
|
+
``credential`` is a least-privilege provider API key. It is sent once, stored encrypted and
|
|
497
|
+
never returned, and repr(), str() and validation errors leave it out.
|
|
498
|
+
"""
|
|
499
|
+
|
|
500
|
+
model_config = SECRET_MODEL_CONFIG
|
|
501
|
+
|
|
502
|
+
#: stripe, github or paddle. Must match the source's provider when it has one.
|
|
503
|
+
provider: ConnectionProvider
|
|
504
|
+
#: Stripe: a restricted key (rk_live_ or rk_test_) with Webhook Endpoints: Write and Events:
|
|
505
|
+
#: Read. GitHub: a fine-grained personal access token (github_pat_) limited to the repository
|
|
506
|
+
#: or organization, with Webhooks: Read and write. Paddle: an API key (pdl_live_apikey_ or
|
|
507
|
+
#: pdl_sdbx_apikey_) with notification_setting.write and notification.write. The key's prefix
|
|
508
|
+
#: sets the connection's environment.
|
|
509
|
+
credential: str = Field(repr=False)
|
|
510
|
+
#: Event types to subscribe the webhook to, in the provider's names (invoice.paid,
|
|
511
|
+
#: pull_request, transaction.completed). None subscribes to every event (["*"]).
|
|
512
|
+
events: list[str] | None = None
|
|
513
|
+
#: GitHub only, this or github_organization: "owner/repo".
|
|
514
|
+
github_repository: str | None = None
|
|
515
|
+
#: GitHub only: an organization name, for a webhook on all its repositories.
|
|
516
|
+
github_organization: str | None = None
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
class UpdateSourceConnectionParams(HookbaseModel):
|
|
520
|
+
"""The body of :meth:`Sources.update_connection`: set at least one field."""
|
|
521
|
+
|
|
522
|
+
model_config = SECRET_MODEL_CONFIG
|
|
523
|
+
|
|
524
|
+
#: A replacement key for the same provider account and environment, with the permissions
|
|
525
|
+
#: connect needs. Left out of repr(), str() and validation errors.
|
|
526
|
+
credential: str | None = Field(default=None, repr=False)
|
|
527
|
+
#: Turn recovery on or off. True needs a Pro or Business plan.
|
|
528
|
+
reconcile_enabled: bool | None = None
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
def connect_source_body(params: ConnectSourceParams | dict[str, Any]) -> dict[str, Any]:
|
|
532
|
+
"""Build the PUT /api/sources/:id/connection body.
|
|
533
|
+
|
|
534
|
+
The API rejects keys it doesn't know, so a snake_case key from a plain dict is sent under its
|
|
535
|
+
camelCase name.
|
|
536
|
+
"""
|
|
537
|
+
body = _wire.dump(params)
|
|
538
|
+
_wire.canonicalize(body, "githubRepository", "githubOrganization")
|
|
539
|
+
return body
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def update_source_connection_body(
|
|
543
|
+
params: UpdateSourceConnectionParams | dict[str, Any],
|
|
544
|
+
) -> dict[str, Any]:
|
|
545
|
+
"""Build the PATCH /api/sources/:id/connection body (camelCase keys, as for connect)."""
|
|
546
|
+
body = _wire.dump(params)
|
|
547
|
+
_wire.canonicalize(body, "reconcileEnabled")
|
|
548
|
+
return body
|
|
@@ -38,9 +38,11 @@ class SyncResource:
|
|
|
38
38
|
json: Any = None,
|
|
39
39
|
params: dict[str, Any] | None = None,
|
|
40
40
|
idempotency_key: str | None = None,
|
|
41
|
+
retry_ambiguous: bool = True,
|
|
41
42
|
) -> Any:
|
|
42
43
|
return self._transport.request(
|
|
43
|
-
method, path, json=json, params=params, idempotency_key=idempotency_key
|
|
44
|
+
method, path, json=json, params=params, idempotency_key=idempotency_key,
|
|
45
|
+
retry_ambiguous=retry_ambiguous,
|
|
44
46
|
)
|
|
45
47
|
|
|
46
48
|
def _parse(self, model: type[T], data: Any) -> T:
|
|
@@ -69,9 +71,11 @@ class AsyncResource:
|
|
|
69
71
|
json: Any = None,
|
|
70
72
|
params: dict[str, Any] | None = None,
|
|
71
73
|
idempotency_key: str | None = None,
|
|
74
|
+
retry_ambiguous: bool = True,
|
|
72
75
|
) -> Any:
|
|
73
76
|
return await self._transport.request(
|
|
74
|
-
method, path, json=json, params=params, idempotency_key=idempotency_key
|
|
77
|
+
method, path, json=json, params=params, idempotency_key=idempotency_key,
|
|
78
|
+
retry_ambiguous=retry_ambiguous,
|
|
75
79
|
)
|
|
76
80
|
|
|
77
81
|
def _parse(self, model: type[T], data: Any) -> T:
|