A webhook node parses its payload template as JSON before resolving
placeholders, so a template with unquoted {{ }} placeholders or any malformed
JSON could be saved, tested, and activated — only to fail midway through a run.
Reject it up front instead: AutomationConfigValidator is the single source of
truth for per-node config issues (keyed to the field the editor surfaces them
under), enforced on save (field errors), on activate, and before a test run.
The editor mirrors the check to disable Test/Activate with a clear reason, and
the test panel now surfaces the server's message instead of a generic toast.
36 lines
1,003 B
PHP
36 lines
1,003 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Automation;
|
|
|
|
/**
|
|
* Backend mirror of the Webhook node's payload-template contract: the template
|
|
* is parsed as JSON before placeholders are resolved (see RunWebhookNode), so a
|
|
* template with unquoted `{{ }}` placeholders or any malformed JSON can never
|
|
* run. An empty or literal-`null` template means "no body" and is valid.
|
|
*/
|
|
final class WebhookNodeValidator
|
|
{
|
|
/**
|
|
* First compliance issue for a webhook node's config, or null when valid.
|
|
*
|
|
* @param array<string, mixed> $config
|
|
*/
|
|
public function issueFor(array $config): ?string
|
|
{
|
|
$template = trim((string) data_get($config, 'payload_template', ''));
|
|
|
|
if ($template === '' || $template === 'null') {
|
|
return null;
|
|
}
|
|
|
|
json_decode($template);
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
return __('automations.errors.webhook_invalid_payload_json');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|