hookbase 4.2.0__tar.gz → 4.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. {hookbase-4.2.0 → hookbase-4.4.0}/PKG-INFO +93 -1
  2. {hookbase-4.2.0 → hookbase-4.4.0}/README.md +92 -0
  3. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/_client.py +24 -3
  4. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/_pagination.py +7 -2
  5. hookbase-4.4.0/src/hookbase/_version.py +1 -0
  6. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/__init__.py +54 -0
  7. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/destinations.py +20 -0
  8. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/events.py +42 -0
  9. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/routes.py +71 -1
  10. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/sources.py +284 -3
  11. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/_base.py +6 -2
  12. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/routes.py +53 -0
  13. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/sources.py +171 -0
  14. hookbase-4.4.0/tests/resources/test_shadow_traffic.py +383 -0
  15. hookbase-4.4.0/tests/resources/test_source_connections.py +539 -0
  16. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_source_fields.py +4 -0
  17. hookbase-4.4.0/tests/resources/test_source_header_auth.py +158 -0
  18. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_sync_async_parity.py +53 -0
  19. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_models_exports.py +22 -0
  20. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_pagination.py +17 -0
  21. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_retry.py +2 -0
  22. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_secret_redaction.py +7 -0
  23. hookbase-4.2.0/src/hookbase/_version.py +0 -1
  24. {hookbase-4.2.0 → hookbase-4.4.0}/.github/workflows/python-publish.yml +0 -0
  25. {hookbase-4.2.0 → hookbase-4.4.0}/.gitignore +0 -0
  26. {hookbase-4.2.0 → hookbase-4.4.0}/LICENSE +0 -0
  27. {hookbase-4.2.0 → hookbase-4.4.0}/examples/async_usage.py +0 -0
  28. {hookbase-4.2.0 → hookbase-4.4.0}/examples/basic_inbound.py +0 -0
  29. {hookbase-4.2.0 → hookbase-4.4.0}/examples/error_handling.py +0 -0
  30. {hookbase-4.2.0 → hookbase-4.4.0}/examples/send_webhooks.py +0 -0
  31. {hookbase-4.2.0 → hookbase-4.4.0}/examples/verify_webhooks.py +0 -0
  32. {hookbase-4.2.0 → hookbase-4.4.0}/pyproject.toml +0 -0
  33. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/__init__.py +0 -0
  34. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/_constants.py +0 -0
  35. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/client.py +0 -0
  36. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/errors.py +0 -0
  37. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/_base.py +0 -0
  38. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/_wire.py +0 -0
  39. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/analytics.py +0 -0
  40. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/api_keys.py +0 -0
  41. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/applications.py +0 -0
  42. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/catalog.py +0 -0
  43. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/common.py +0 -0
  44. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/cron_jobs.py +0 -0
  45. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/deliveries.py +0 -0
  46. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/dlq.py +0 -0
  47. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/endpoints.py +0 -0
  48. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/event_types.py +0 -0
  49. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/filters.py +0 -0
  50. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/messages.py +0 -0
  51. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/organizations.py +0 -0
  52. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/portal_tokens.py +0 -0
  53. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/schemas.py +0 -0
  54. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/subscriptions.py +0 -0
  55. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/transforms.py +0 -0
  56. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/models/tunnels.py +0 -0
  57. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/py.typed +0 -0
  58. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/__init__.py +0 -0
  59. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/analytics.py +0 -0
  60. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/api_keys.py +0 -0
  61. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/applications.py +0 -0
  62. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/cron_jobs.py +0 -0
  63. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/deliveries.py +0 -0
  64. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/destinations.py +0 -0
  65. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/dlq.py +0 -0
  66. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/endpoints.py +0 -0
  67. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/event_types.py +0 -0
  68. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/events.py +0 -0
  69. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/filters.py +0 -0
  70. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/message_log.py +0 -0
  71. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/messages.py +0 -0
  72. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/organizations.py +0 -0
  73. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/portal_tokens.py +0 -0
  74. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/providers.py +0 -0
  75. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/schemas.py +0 -0
  76. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/subscriptions.py +0 -0
  77. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/transforms.py +0 -0
  78. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/resources/tunnels.py +0 -0
  79. {hookbase-4.2.0 → hookbase-4.4.0}/src/hookbase/webhook.py +0 -0
  80. {hookbase-4.2.0 → hookbase-4.4.0}/tests/__init__.py +0 -0
  81. {hookbase-4.2.0 → hookbase-4.4.0}/tests/conftest.py +0 -0
  82. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/__init__.py +0 -0
  83. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_applications.py +0 -0
  84. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_cron_jobs.py +0 -0
  85. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_destinations.py +0 -0
  86. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_dlq.py +0 -0
  87. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_endpoints.py +0 -0
  88. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_inbound_contract.py +0 -0
  89. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_messages.py +0 -0
  90. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_open_types.py +0 -0
  91. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_outbound_contract.py +0 -0
  92. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_resource_contracts.py +0 -0
  93. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_source_contract.py +0 -0
  94. {hookbase-4.2.0 → hookbase-4.4.0}/tests/resources/test_sources.py +0 -0
  95. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_client.py +0 -0
  96. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_errors.py +0 -0
  97. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_http_client.py +0 -0
  98. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_slug_contract.py +0 -0
  99. {hookbase-4.2.0 → hookbase-4.4.0}/tests/test_webhook.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: hookbase
3
- Version: 4.2.0
3
+ Version: 4.4.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,33 @@ 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
+ # Header auth: check a static credential instead of the provider's signature. The credential is
144
+ # the source's signing secret (omit it and one is generated): a bearer token, "username:password"
145
+ # for basic, or the token a "header" source reads from verification_header.
146
+ erp = client.sources.create({"name": "ERP", "slug": "erp", "verificationMethod": "header",
147
+ "verificationHeader": "X-Webhook-Token"})
148
+ token = erp.signing_secret # returned once; reveal_secret() and rotate_secret() later
149
+ erp.verification_method, erp.verification_header # "header", "x-webhook-token"
150
+ client.sources.update(erp.id, {"verificationMethod": "bearer"}) # same token, header removed
151
+ # Any other switch takes the new credential in the same update, as signingSecret
152
+
153
+ # Connected sources: give Hookbase a least-privilege provider key (Stripe, GitHub or Paddle) and
154
+ # it registers the webhook, holds its signing secret, and recovers events the provider failed to
155
+ # deliver (Pro and Business). The key is never returned or logged, and ConnectSourceParams
156
+ # leaves it out of repr().
157
+ result = client.sources.connect("src_id", {"provider": "stripe", "credential": "rk_live_..."})
158
+ result.connection.status, result.connection.credential_hint, result.warnings
159
+ client.sources.connect("src_gh", {"provider": "github", "credential": "github_pat_...",
160
+ "githubRepository": "acme/api", "events": ["push"]})
161
+ client.sources.get_connection("src_id") # None when not connected; .last_run, .recovered_total
162
+ client.sources.update_connection("src_id", {"credential": "rk_live_..."}) # replace the key
163
+ client.sources.update_connection("src_id", {"reconcileEnabled": False})
164
+ client.sources.run_recovery("src_id") # True; ConflictError with details["reason"] if refused
165
+ client.sources.list_recovery_items("src_id", status="gave_up", limit=20)
166
+ client.sources.disconnect("src_id") # .remote_removed, .retrying, .message
167
+ client.sources.get("src_id").connection # summary on list() and get(); None if not connected
168
+ client.events.get("evt_id").recovery # .method, .recovered_at when recovery delivered it
169
+
143
170
  # Provider catalog: which secret each provider needs (public, no auth needed)
144
171
  for p in client.providers.list(category="payments").providers:
145
172
  print(p.hookbase_provider, p.signature_verification and p.signature_verification.secret_source)
@@ -176,6 +203,15 @@ bridge = client.destinations.create(CreateDestinationParams(
176
203
  result = client.destinations.test(bridge.id, payload={"type": "created"})
177
204
  result.event_type, result.event_type_exists, result.matching_endpoints
178
205
 
206
+ # Shadow destinations (Pro and Business) get sampled copies of their routes' events, with personal
207
+ # data replaced by fakes, for a dev tunnel or a preview deployment, and never production
208
+ # deliveries. HTTP only, no static IP, and the URL is an external host or one of your tunnels.
209
+ # purpose is fixed at create: an update leaves it out unless you set it.
210
+ preview = client.destinations.create({"name": "Preview", "slug": "preview",
211
+ "url": "https://preview.example.com/hook",
212
+ "purpose": "shadow"})
213
+ preview.purpose # "shadow"; "live" for every other destination
214
+
179
215
  # Routes
180
216
  client.routes.create({"name": "Route", "sourceId": "src_id", "destinationId": "dst_id"})
181
217
  client.routes.get_circuit_status("route_id")
@@ -187,6 +223,16 @@ client.routes.reset_circuit("route_id")
187
223
  client.routes.update("route_id", {"holdOnCircuitOpen": False})
188
224
  client.routes.get("route_id").held_count # get only; held_count_capped past 10,000
189
225
 
226
+ # A route to a shadow destination is a shadow route: it copies sample_rate (0.0001 to 1, all
227
+ # matching events when left out) of the events it matches, and makes no deliveries.
228
+ shadow = client.routes.create({"name": "Preview copy", "sourceId": "src_id",
229
+ "destinationId": preview.id, "sampleRate": 0.25})
230
+ shadow.mode, shadow.sample_rate # "shadow", 0.25; a live route reads "live", None
231
+ client.routes.update(shadow.id, {"sampleRate": 0.05})
232
+ # Each copy's outcome (copies never show up in deliveries), newest first, cursor-paged
233
+ for copy in client.routes.list_shadow_deliveries(shadow.id, limit=50).auto_paging_iter():
234
+ print(copy.event_id, copy.status, copy.reason, copy.status_code)
235
+
190
236
  # Events & Deliveries
191
237
  client.events.list(source_id="src_id", from_date="2024-01-01") # id or slug; unknown -> 404
192
238
  client.events.get("evt_id") # Includes payload and deliveries
@@ -314,6 +360,8 @@ for app in apps.auto_paging_iter():
314
360
  print(app.name)
315
361
  for event in client.events.list(limit=100).auto_paging_iter():
316
362
  print(event.id)
363
+ for copy in client.routes.list_shadow_deliveries("route_id").auto_paging_iter():
364
+ print(copy.status)
317
365
 
318
366
  # Limit/offset with no total (deliveries): pages until one comes back short
319
367
  for delivery in client.deliveries.list(status="failed", limit=100).auto_paging_iter():
@@ -418,6 +466,10 @@ Up to `max_retries` retries (default 3):
418
466
  is retried only when it carries an idempotency key (`outbound.messages.send` always does).
419
467
  - **A connection that was never made** is always retried.
420
468
  - **Other 4xx** responses are never retried.
469
+ - `sources.connect()`, and `sources.update_connection()` with a `credential`, are not retried
470
+ after a 5xx, a read timeout or a dropped connection, since a second attempt could register the
471
+ provider webhook twice. A 429 is still retried. After such a failure (or a 503 with code
472
+ `CONNECT_OUTCOME_UNKNOWN`), call `sources.get_connection()` before connecting again.
421
473
 
422
474
  ### Pydantic Models
423
475
 
@@ -437,6 +489,46 @@ source = client.sources.create({"name": "GitHub", "slug": "github", "provider":
437
489
  # source with a provider newer than this package still parses.
438
490
  ```
439
491
 
492
+ ## Upgrading to 4.4
493
+
494
+ - Shadow traffic: `Destination.purpose` (`"live"` or `"shadow"`) on create, get and list, and
495
+ `purpose` on `CreateDestinationParams`; `UpdateDestinationParams.purpose` is sent only when set
496
+ (a change is a 409 `PURPOSE_IMMUTABLE`). `Route.mode` (read-only: the destination's purpose)
497
+ and `Route.sample_rate` (None on a live route), and `sample_rate` on `CreateRouteParams` and
498
+ `UpdateRouteParams`, sent only when set. `routes.list_shadow_deliveries(id, limit=, cursor=)`
499
+ returns a cursor page of `ShadowDelivery` with `auto_paging_iter()`. `events.debug()` gains
500
+ `filter_evaluations` (`EventDebugFilterEvaluation`: each route's filter verdict, `mode`,
501
+ `sample_rate` and, for a shadow route, whether the event is in its sample).
502
+ - Source header auth: `verification_method` (`"signature"`, `"bearer"`, `"basic"` or
503
+ `"header"`) and `verification_header` on `Source`, `CreateSourceParams` and
504
+ `UpdateSourceParams`. `clear=["verificationHeader"]` sends its null. The credential is the
505
+ signing secret, so it stays out of `repr()`, `str()` and validation errors.
506
+ - `ShadowDelivery.status` and `reason`, `DestinationPurpose`, `RouteMode` and
507
+ `VerificationMethod` accept any string, with today's values listed for type checkers.
508
+ - The shadow error codes (`SAMPLE_RATE_NOT_ALLOWED`, `SAMPLE_RATE_INVALID`,
509
+ `ROUTE_PURPOSE_CONFLICT`, `SHADOW_DESTINATION_HTTP_ONLY`, `SHADOW_DESTINATION_NOT_ALLOWED`,
510
+ `INVALID_CURSOR`, ...) arrive in `APIError.code`; a plan without shadow traffic is a
511
+ `ForbiddenError` with code `FEATURE_DISABLED`.
512
+ - A cursor list that sends a `nextCursor` and no `hasMore` now reports `has_more` from the
513
+ cursor. Every list that already sent `hasMore` is unchanged.
514
+
515
+ ## Upgrading to 4.3
516
+
517
+ - Connected sources: `sources.connect()`, `get_connection()`, `update_connection()`,
518
+ `disconnect()`, `run_recovery()` and `list_recovery_items()`, with the models
519
+ `ConnectSourceParams`, `UpdateSourceConnectionParams`, `SourceConnection`,
520
+ `ConnectSourceResult`, `DisconnectSourceResult`, `RecoveryRun` and `RecoveryItem`.
521
+ `credential` is left out of `repr()`, `str()` and validation errors, and is never logged.
522
+ `connect()` (and `update_connection()` with a `credential`) is not retried after a 5xx, a
523
+ timeout or a dropped connection; see [Retries](#retries).
524
+ - `Source.connection` (`SourceConnectionSummary`: provider, status, environment,
525
+ reconcile_enabled) on `list()` and `get()`, None when the source isn't connected.
526
+ - `EventDetail.recovery` and `events.debug().event.recovery` (`EventRecovery`: method,
527
+ recovered_at), set when recovery got the event to its source.
528
+ - The connection error codes (`INVALID_CREDENTIAL`, `PROVIDER_CREDENTIAL_INVALID`,
529
+ `CONNECTION_CONFLICT`, `CONNECT_OUTCOME_UNKNOWN`, ...) arrive in `APIError.code`; a refused
530
+ `run_recovery()` carries its `reason` in `details`, and a 429 its `retryAfter` there too.
531
+
440
532
  ## Upgrading to 4.2
441
533
 
442
534
  - **Fix:** `destinations.list()` and `get()` raised a `ValidationError` when the organization had
@@ -102,6 +102,33 @@ 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
+ # Header auth: check a static credential instead of the provider's signature. The credential is
106
+ # the source's signing secret (omit it and one is generated): a bearer token, "username:password"
107
+ # for basic, or the token a "header" source reads from verification_header.
108
+ erp = client.sources.create({"name": "ERP", "slug": "erp", "verificationMethod": "header",
109
+ "verificationHeader": "X-Webhook-Token"})
110
+ token = erp.signing_secret # returned once; reveal_secret() and rotate_secret() later
111
+ erp.verification_method, erp.verification_header # "header", "x-webhook-token"
112
+ client.sources.update(erp.id, {"verificationMethod": "bearer"}) # same token, header removed
113
+ # Any other switch takes the new credential in the same update, as signingSecret
114
+
115
+ # Connected sources: give Hookbase a least-privilege provider key (Stripe, GitHub or Paddle) and
116
+ # it registers the webhook, holds its signing secret, and recovers events the provider failed to
117
+ # deliver (Pro and Business). The key is never returned or logged, and ConnectSourceParams
118
+ # leaves it out of repr().
119
+ result = client.sources.connect("src_id", {"provider": "stripe", "credential": "rk_live_..."})
120
+ result.connection.status, result.connection.credential_hint, result.warnings
121
+ client.sources.connect("src_gh", {"provider": "github", "credential": "github_pat_...",
122
+ "githubRepository": "acme/api", "events": ["push"]})
123
+ client.sources.get_connection("src_id") # None when not connected; .last_run, .recovered_total
124
+ client.sources.update_connection("src_id", {"credential": "rk_live_..."}) # replace the key
125
+ client.sources.update_connection("src_id", {"reconcileEnabled": False})
126
+ client.sources.run_recovery("src_id") # True; ConflictError with details["reason"] if refused
127
+ client.sources.list_recovery_items("src_id", status="gave_up", limit=20)
128
+ client.sources.disconnect("src_id") # .remote_removed, .retrying, .message
129
+ client.sources.get("src_id").connection # summary on list() and get(); None if not connected
130
+ client.events.get("evt_id").recovery # .method, .recovered_at when recovery delivered it
131
+
105
132
  # Provider catalog: which secret each provider needs (public, no auth needed)
106
133
  for p in client.providers.list(category="payments").providers:
107
134
  print(p.hookbase_provider, p.signature_verification and p.signature_verification.secret_source)
@@ -138,6 +165,15 @@ bridge = client.destinations.create(CreateDestinationParams(
138
165
  result = client.destinations.test(bridge.id, payload={"type": "created"})
139
166
  result.event_type, result.event_type_exists, result.matching_endpoints
140
167
 
168
+ # Shadow destinations (Pro and Business) get sampled copies of their routes' events, with personal
169
+ # data replaced by fakes, for a dev tunnel or a preview deployment, and never production
170
+ # deliveries. HTTP only, no static IP, and the URL is an external host or one of your tunnels.
171
+ # purpose is fixed at create: an update leaves it out unless you set it.
172
+ preview = client.destinations.create({"name": "Preview", "slug": "preview",
173
+ "url": "https://preview.example.com/hook",
174
+ "purpose": "shadow"})
175
+ preview.purpose # "shadow"; "live" for every other destination
176
+
141
177
  # Routes
142
178
  client.routes.create({"name": "Route", "sourceId": "src_id", "destinationId": "dst_id"})
143
179
  client.routes.get_circuit_status("route_id")
@@ -149,6 +185,16 @@ client.routes.reset_circuit("route_id")
149
185
  client.routes.update("route_id", {"holdOnCircuitOpen": False})
150
186
  client.routes.get("route_id").held_count # get only; held_count_capped past 10,000
151
187
 
188
+ # A route to a shadow destination is a shadow route: it copies sample_rate (0.0001 to 1, all
189
+ # matching events when left out) of the events it matches, and makes no deliveries.
190
+ shadow = client.routes.create({"name": "Preview copy", "sourceId": "src_id",
191
+ "destinationId": preview.id, "sampleRate": 0.25})
192
+ shadow.mode, shadow.sample_rate # "shadow", 0.25; a live route reads "live", None
193
+ client.routes.update(shadow.id, {"sampleRate": 0.05})
194
+ # Each copy's outcome (copies never show up in deliveries), newest first, cursor-paged
195
+ for copy in client.routes.list_shadow_deliveries(shadow.id, limit=50).auto_paging_iter():
196
+ print(copy.event_id, copy.status, copy.reason, copy.status_code)
197
+
152
198
  # Events & Deliveries
153
199
  client.events.list(source_id="src_id", from_date="2024-01-01") # id or slug; unknown -> 404
154
200
  client.events.get("evt_id") # Includes payload and deliveries
@@ -276,6 +322,8 @@ for app in apps.auto_paging_iter():
276
322
  print(app.name)
277
323
  for event in client.events.list(limit=100).auto_paging_iter():
278
324
  print(event.id)
325
+ for copy in client.routes.list_shadow_deliveries("route_id").auto_paging_iter():
326
+ print(copy.status)
279
327
 
280
328
  # Limit/offset with no total (deliveries): pages until one comes back short
281
329
  for delivery in client.deliveries.list(status="failed", limit=100).auto_paging_iter():
@@ -380,6 +428,10 @@ Up to `max_retries` retries (default 3):
380
428
  is retried only when it carries an idempotency key (`outbound.messages.send` always does).
381
429
  - **A connection that was never made** is always retried.
382
430
  - **Other 4xx** responses are never retried.
431
+ - `sources.connect()`, and `sources.update_connection()` with a `credential`, are not retried
432
+ after a 5xx, a read timeout or a dropped connection, since a second attempt could register the
433
+ provider webhook twice. A 429 is still retried. After such a failure (or a 503 with code
434
+ `CONNECT_OUTCOME_UNKNOWN`), call `sources.get_connection()` before connecting again.
383
435
 
384
436
  ### Pydantic Models
385
437
 
@@ -399,6 +451,46 @@ source = client.sources.create({"name": "GitHub", "slug": "github", "provider":
399
451
  # source with a provider newer than this package still parses.
400
452
  ```
401
453
 
454
+ ## Upgrading to 4.4
455
+
456
+ - Shadow traffic: `Destination.purpose` (`"live"` or `"shadow"`) on create, get and list, and
457
+ `purpose` on `CreateDestinationParams`; `UpdateDestinationParams.purpose` is sent only when set
458
+ (a change is a 409 `PURPOSE_IMMUTABLE`). `Route.mode` (read-only: the destination's purpose)
459
+ and `Route.sample_rate` (None on a live route), and `sample_rate` on `CreateRouteParams` and
460
+ `UpdateRouteParams`, sent only when set. `routes.list_shadow_deliveries(id, limit=, cursor=)`
461
+ returns a cursor page of `ShadowDelivery` with `auto_paging_iter()`. `events.debug()` gains
462
+ `filter_evaluations` (`EventDebugFilterEvaluation`: each route's filter verdict, `mode`,
463
+ `sample_rate` and, for a shadow route, whether the event is in its sample).
464
+ - Source header auth: `verification_method` (`"signature"`, `"bearer"`, `"basic"` or
465
+ `"header"`) and `verification_header` on `Source`, `CreateSourceParams` and
466
+ `UpdateSourceParams`. `clear=["verificationHeader"]` sends its null. The credential is the
467
+ signing secret, so it stays out of `repr()`, `str()` and validation errors.
468
+ - `ShadowDelivery.status` and `reason`, `DestinationPurpose`, `RouteMode` and
469
+ `VerificationMethod` accept any string, with today's values listed for type checkers.
470
+ - The shadow error codes (`SAMPLE_RATE_NOT_ALLOWED`, `SAMPLE_RATE_INVALID`,
471
+ `ROUTE_PURPOSE_CONFLICT`, `SHADOW_DESTINATION_HTTP_ONLY`, `SHADOW_DESTINATION_NOT_ALLOWED`,
472
+ `INVALID_CURSOR`, ...) arrive in `APIError.code`; a plan without shadow traffic is a
473
+ `ForbiddenError` with code `FEATURE_DISABLED`.
474
+ - A cursor list that sends a `nextCursor` and no `hasMore` now reports `has_more` from the
475
+ cursor. Every list that already sent `hasMore` is unchanged.
476
+
477
+ ## Upgrading to 4.3
478
+
479
+ - Connected sources: `sources.connect()`, `get_connection()`, `update_connection()`,
480
+ `disconnect()`, `run_recovery()` and `list_recovery_items()`, with the models
481
+ `ConnectSourceParams`, `UpdateSourceConnectionParams`, `SourceConnection`,
482
+ `ConnectSourceResult`, `DisconnectSourceResult`, `RecoveryRun` and `RecoveryItem`.
483
+ `credential` is left out of `repr()`, `str()` and validation errors, and is never logged.
484
+ `connect()` (and `update_connection()` with a `credential`) is not retried after a 5xx, a
485
+ timeout or a dropped connection; see [Retries](#retries).
486
+ - `Source.connection` (`SourceConnectionSummary`: provider, status, environment,
487
+ reconcile_enabled) on `list()` and `get()`, None when the source isn't connected.
488
+ - `EventDetail.recovery` and `events.debug().event.recovery` (`EventRecovery`: method,
489
+ recovered_at), set when recovery got the event to its source.
490
+ - The connection error codes (`INVALID_CREDENTIAL`, `PROVIDER_CREDENTIAL_INVALID`,
491
+ `CONNECTION_CONFLICT`, `CONNECT_OUTCOME_UNKNOWN`, ...) arrive in `APIError.code`; a refused
492
+ `run_recovery()` carries its `reason` in `details`, and a 429 its `retryAfter` there too.
493
+
402
494
  ## Upgrading to 4.2
403
495
 
404
496
  - **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
@@ -543,7 +543,10 @@ def _extract_cursor_data(
543
543
  """Extract items + pagination from a cursor-based API response.
544
544
 
545
545
  Most cursor lists nest `hasMore`/`nextCursor` under `pagination`; inbound
546
- events (`GET /api/events`) put them at the top level next to `events`.
546
+ events (`GET /api/events`) put them at the top level next to `events`. A
547
+ list that sends no `hasMore` at all (a shadow route's copies,
548
+ `GET /api/routes/:id/shadow-deliveries`) has more while it hands out a
549
+ `nextCursor`, which is null on its last page.
547
550
  """
548
551
  if not isinstance(resp, dict):
549
552
  return [], False, None
@@ -552,8 +555,10 @@ def _extract_cursor_data(
552
555
  pagination = resp.get("pagination")
553
556
  if not isinstance(pagination, dict):
554
557
  pagination = resp
555
- has_more = pagination.get("hasMore", pagination.get("has_more", False))
556
558
  next_cursor = pagination.get("nextCursor", pagination.get("next_cursor"))
559
+ has_more = pagination.get("hasMore", pagination.get("has_more"))
560
+ if has_more is None:
561
+ has_more = next_cursor is not None
557
562
 
558
563
  return items if isinstance(items, list) else [], bool(has_more), next_cursor
559
564
 
@@ -0,0 +1 @@
1
+ __version__ = "4.4.0"
@@ -67,6 +67,7 @@ from .destinations import (
67
67
  BridgeEventTypeSource,
68
68
  CreateDestinationParams,
69
69
  Destination,
70
+ DestinationPurpose,
70
71
  DestinationSecret,
71
72
  DestinationType,
72
73
  DestinationWithSecret,
@@ -116,9 +117,11 @@ from .events import (
116
117
  EventDebugDelivery,
117
118
  EventDebugDestination,
118
119
  EventDebugEvent,
120
+ EventDebugFilterEvaluation,
119
121
  EventDebugInfo,
120
122
  EventDebugPatternHint,
121
123
  EventDebugRouteCircuit,
124
+ EventDebugShadowSample,
122
125
  EventDelivery,
123
126
  EventDetail,
124
127
  InboundEventStatus,
@@ -150,6 +153,10 @@ from .routes import (
150
153
  CircuitStatusInfo,
151
154
  CreateRouteParams,
152
155
  Route,
156
+ RouteMode,
157
+ ShadowDelivery,
158
+ ShadowDeliveryReason,
159
+ ShadowDeliveryStatus,
153
160
  UpdateRouteParams,
154
161
  )
155
162
  from .schemas import (
@@ -164,15 +171,34 @@ from .sources import (
164
171
  CLEARABLE_SOURCE_FIELDS,
165
172
  KNOWN_SOURCE_PROVIDERS,
166
173
  ClearableSourceField,
174
+ ConnectionEnvironment,
175
+ ConnectionProvider,
176
+ ConnectionStatus,
177
+ ConnectSourceParams,
178
+ ConnectSourceResult,
167
179
  CreateSourceParams,
168
180
  DedupStrategy,
181
+ DisconnectSourceResult,
182
+ EventRecovery,
183
+ GithubTarget,
184
+ GithubTargetKind,
169
185
  IngestMethod,
170
186
  IpFilterMode,
171
187
  PendingVerification,
188
+ PriorSourceSettings,
189
+ RecoveryItem,
190
+ RecoveryItemStatus,
191
+ RecoveryMethod,
192
+ RecoveryRun,
193
+ RecoveryStoppedReason,
172
194
  Source,
195
+ SourceConnection,
196
+ SourceConnectionSummary,
173
197
  SourceProvider,
174
198
  SourceWithSecret,
199
+ UpdateSourceConnectionParams,
175
200
  UpdateSourceParams,
201
+ VerificationMethod,
176
202
  )
177
203
  from .subscriptions import (
178
204
  CreateSubscriptionParams,
@@ -264,6 +290,7 @@ __all__ = [
264
290
  "BridgeEventTypeSource",
265
291
  "CreateDestinationParams",
266
292
  "Destination",
293
+ "DestinationPurpose",
267
294
  "DestinationSecret",
268
295
  "DestinationType",
269
296
  "DestinationWithSecret",
@@ -318,6 +345,8 @@ __all__ = [
318
345
  "EventDebugDestination",
319
346
  "EventDebugPatternHint",
320
347
  "EventDebugRouteCircuit",
348
+ "EventDebugFilterEvaluation",
349
+ "EventDebugShadowSample",
321
350
  "EventDelivery",
322
351
  # Filters
323
352
  "CreateFilterParams",
@@ -349,7 +378,12 @@ __all__ = [
349
378
  "CircuitStatusInfo",
350
379
  "CreateRouteParams",
351
380
  "Route",
381
+ "RouteMode",
352
382
  "UpdateRouteParams",
383
+ # Shadow traffic
384
+ "ShadowDelivery",
385
+ "ShadowDeliveryReason",
386
+ "ShadowDeliveryStatus",
353
387
  # Schemas
354
388
  "CreateSchemaParams",
355
389
  "Schema",
@@ -370,6 +404,26 @@ __all__ = [
370
404
  "SourceWithSecret",
371
405
  "UpdateSourceParams",
372
406
  "IngestMethod",
407
+ "VerificationMethod",
408
+ # Connected sources
409
+ "ConnectionEnvironment",
410
+ "ConnectionProvider",
411
+ "ConnectionStatus",
412
+ "ConnectSourceParams",
413
+ "ConnectSourceResult",
414
+ "DisconnectSourceResult",
415
+ "EventRecovery",
416
+ "GithubTarget",
417
+ "GithubTargetKind",
418
+ "PriorSourceSettings",
419
+ "RecoveryItem",
420
+ "RecoveryItemStatus",
421
+ "RecoveryMethod",
422
+ "RecoveryRun",
423
+ "RecoveryStoppedReason",
424
+ "SourceConnection",
425
+ "SourceConnectionSummary",
426
+ "UpdateSourceConnectionParams",
373
427
  # Subscriptions
374
428
  "CreateSubscriptionParams",
375
429
  "LabelFilterMode",
@@ -26,6 +26,11 @@ PartitionBy = Literal["date", "hour", "source"]
26
26
  FieldMappingType = Literal["string", "number", "boolean", "timestamp", "json"]
27
27
  ThrottleMode = Literal["off", "rate", "concurrency"]
28
28
  RateUnit = Literal["second", "minute", "hour"]
29
+ #: What a destination is for, fixed when it is created. "live" (the default) gets deliveries.
30
+ #: "shadow" gets sampled copies of its routes' events with personal data replaced by fakes, for a
31
+ #: dev tunnel or a preview deployment, and never gets production deliveries. Any string, so a
32
+ #: value added later still parses.
33
+ DestinationPurpose = Union[Literal["live", "shadow"], str]
29
34
 
30
35
 
31
36
  class FieldMapping(HookbaseModel):
@@ -143,6 +148,10 @@ class Destination(HookbaseModel):
143
148
  has_signing_secret: bool = False
144
149
  """Whether deliveries to this destination are signed (HTTP destinations only). The secret
145
150
  itself is returned once, by `create`; after that use `destinations.reveal_secret`."""
151
+ purpose: DestinationPurpose = "live"
152
+ """"live", or "shadow" for a shadow destination (its routes send sampled, scrubbed copies
153
+ instead of deliveries). Set on create and never changed. Returned by create, get and list;
154
+ "live" when the response doesn't say."""
146
155
  delivery_count: int = 0
147
156
  last_delivery_at: str | None = None
148
157
  created_at: str = ""
@@ -310,6 +319,14 @@ class CreateDestinationParams(HookbaseModel):
310
319
  use_static_ip: bool | None = None
311
320
  batch_size: int | None = None
312
321
  batch_window_seconds: int | None = None
322
+ purpose: DestinationPurpose | None = None
323
+ """"shadow" makes a shadow destination: its routes send sampled copies of matching events,
324
+ with personal data replaced by fakes, and it never gets production deliveries. Left out (the
325
+ API's default) makes a live one. It can't change after create.
326
+
327
+ A shadow destination must be `type="http"` (400 `SHADOW_DESTINATION_HTTP_ONLY`), can't use
328
+ a static IP, and its URL must be an external host or one of the organization's own tunnel
329
+ URLs (`.../t/<subdomain>/...`). Pro and Business plans only (403 `FEATURE_DISABLED`)."""
313
330
 
314
331
  # Deprecated fields; see `create_destination_body` for what each one does
315
332
  # on the wire.
@@ -350,6 +367,9 @@ class UpdateDestinationParams(HookbaseModel):
350
367
  use_static_ip: bool | None = None
351
368
  batch_size: int | None = None
352
369
  batch_window_seconds: int | None = None
370
+ purpose: DestinationPurpose | None = None
371
+ """A destination's purpose never changes. Sent only when set: the stored value is accepted
372
+ as a no-op, any other is a 409 `PURPOSE_IMMUTABLE` (create a new destination instead)."""
353
373
 
354
374
  # Deprecated fields; see `CreateDestinationParams` for each one's status.
355
375
  description: str | None = None
@@ -7,6 +7,8 @@ from pydantic import field_validator, model_validator
7
7
 
8
8
  from ._base import HookbaseModel
9
9
  from .deliveries import Delivery, DeliveryStatus
10
+ from .routes import RouteMode
11
+ from .sources import EventRecovery
10
12
 
11
13
  # The API derives it from the event's deliveries: delivered, failed, partial (some delivered),
12
14
  # pending, no_routes (no route matched) or duplicate. Any string, so a later one still parses.
@@ -64,6 +66,9 @@ class EventDetail(HookbaseModel):
64
66
  mask_fields: Any = None
65
67
  transient: bool = False
66
68
  deliveries: list[EventDelivery] = []
69
+ recovery: EventRecovery | None = None
70
+ """Set when the provider had failed to deliver the event and connected-source recovery got it
71
+ to the source; otherwise None."""
67
72
 
68
73
  @field_validator("headers", mode="before")
69
74
  @classmethod
@@ -103,6 +108,8 @@ class EventDebugEvent(HookbaseModel):
103
108
  signature_valid: int | None = None
104
109
  received_at: str = ""
105
110
  ip_address: str | None = None
111
+ recovery: EventRecovery | None = None
112
+ """Set when connected-source recovery got the event to its source; otherwise None."""
106
113
 
107
114
  @field_validator("headers", mode="before")
108
115
  @classmethod
@@ -198,6 +205,33 @@ class EventDebugDelivery(HookbaseModel):
198
205
  return 0 if v is None else v
199
206
 
200
207
 
208
+ class EventDebugShadowSample(HookbaseModel):
209
+ """Whether a shadow route copies this event (`EventDebugFilterEvaluation.shadow`)."""
210
+
211
+ in_sample: bool = False
212
+ """Whether the event is in the route's sample, by the route's current settings."""
213
+ note: str = ""
214
+ """What the route does with this event, in a sentence."""
215
+
216
+
217
+ class EventDebugFilterEvaluation(HookbaseModel):
218
+ """How one of the source's routes treats the event, as `events.debug` reports it."""
219
+
220
+ route_id: str
221
+ route_name: str = ""
222
+ has_filter: bool = False
223
+ evaluation: Any = None
224
+ """The filter's evaluation trace (whether it passed, and each condition's result); None
225
+ when the route has no filter or its conditions didn't parse."""
226
+ parse_error: str | None = None
227
+ mode: RouteMode = "live"
228
+ """The route's mode: "shadow" routes copy a sample of events and make no deliveries."""
229
+ sample_rate: float | None = None
230
+ """A shadow route's share of matching events copied (0.0001 to 1); None for a live route."""
231
+ shadow: EventDebugShadowSample | None = None
232
+ """Shadow routes only: whether this event gets a copy."""
233
+
234
+
201
235
  class EventDebugInfo(HookbaseModel):
202
236
  """The result of `events.debug`."""
203
237
 
@@ -206,10 +240,18 @@ class EventDebugInfo(HookbaseModel):
206
240
  """The stored payload; None for a transient event or one whose payload has expired."""
207
241
  transient: bool = False
208
242
  deliveries: list[EventDebugDelivery] = []
243
+ filter_evaluations: list[EventDebugFilterEvaluation] = []
244
+ """One entry per route of the event's source, as ingest sees them now: its filter's verdict,
245
+ and for a shadow route its sample rate and whether the event is in the sample."""
209
246
  curl_command: str = ""
210
247
  """A curl command that re-sends the event to its source. Empty for a transient event, whose
211
248
  payload is not stored."""
212
249
 
250
+ @field_validator("filter_evaluations", mode="before")
251
+ @classmethod
252
+ def _null_evaluations(cls, v: Any) -> Any:
253
+ return [] if v is None else v
254
+
213
255
  @model_validator(mode="before")
214
256
  @classmethod
215
257
  def _lift_debug_fields(cls, data: Any) -> Any: