Configurable webhook responses#4666
Open
midigofrank wants to merge 14 commits intomainfrom
Open
Conversation
- Fix snapshot serialization to recursively handle embedded schemas using Ecto.embedded_dump + __schema__(:embeds), excluding :sync_webhook_response_config from the flat cast field list - Drop incorrect primary_key: false from sync_webhook_response_config embed - Fix default_response_body/3 nil-config clause so success runs without a configured body correctly return the final state - Rename webhook response headers to hyphenated form: x-meta-work-order-id, x-meta-run-id - Add run_channel tests covering all webhook response dispatch paths: _webhookResponse override, configured status codes/body, malformed responses, before_start triggers - Rewrite webhooks_controller delayed-response tests to use WorkOrders.Events for synchronisation instead of Process.sleep, and assert on x-meta-* response headers - Fix integration tests that incorrectly asserted data/meta wrapping on the response body; add integration tests for configured success_code, error_code, custom body, and _webhookResponse override
- Serialize sync_webhook_response_config as webhook_response in YAML export; body is JSON-encoded as a literal block scalar matching how job.body is handled - Expose webhook_response in the provisioning API GET response - Accept webhook_response on provisioning import and remap it to sync_webhook_response_config; decode body if it arrives as a JSON string (from YAML literal block) - Add Jason.Encoder derives so sync_webhook_response_config is included when the trigger is serialized for the session context - Add tests covering export, API output, and import including the JSON-string body decoding path
- Export sync_webhook_response_config as webhook_response in YAML code view, omitting null fields - Import webhook_response back to sync_webhook_response_config when applying a YAML spec; JSON-parse body if it arrives as a string from the literal block - Include sync_webhook_response_config in transformTrigger so status code edits trigger the unsaved changes indicator - Add WebhookResponseConfig type and webhook_response field to SpecWebhookTrigger; add webhook_response schema to workflow-spec.json
Security Review ✅
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4666 +/- ##
==========================================
- Coverage 89.78% 89.73% -0.05%
==========================================
Files 444 445 +1
Lines 21660 21719 +59
==========================================
+ Hits 19447 19490 +43
- Misses 2213 2229 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for configurable webhook responses in sync (after completion) mode.
Previously, when a webhook trigger ran in sync mode, the response was always the final run state with a fixed
201status code. This PR allows operators to:_webhookResponsein any job's final state, with partial overrides now supported (onlystatus, onlybody, or both)_webhookResponsevalue is read from the state at the end of the run, so any job in the workflow can set or overwrite itResponse metadata headers (
x-meta-work-order-id,x-meta-run-id) are now documented and included on all webhook responses (both async and sync).Closes #4479
Closes #4480
Closes #4481
Closes #4482
Closes #4483
Closes #4484
Closes #4598
This PR has a docs sibling: OpenFn/docs#765
Validation steps
200) — verify it is returned on a successful run422) — trigger a failing run and verify the status code is returned201_webhookResponse: { status: 202 }(no body) — verify the custom status is used and the body is the final run state_webhookResponse: { body: { ack: true } }(no status) — verify the custom body is used and the status comes from the config (or201if none set)statusandbodyin_webhookResponse— verify both are used_webhookResponseto a non-map value (e.g. a string) — verify it is silently ignored and defaults apply_webhookResponsewith an invalidstatustype (e.g. a string) — verify the malformed response message is returnedx-meta-work-order-idandx-meta-run-idheaders are present on both async and sync responsesAI Usage
Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):
You can read more details in our
Responsible AI Policy
Pre-submission checklist
/reviewwith Claude Code)
(e.g.,
:owner,:admin,:editor,:viewer)