trypost/app/Services/Automation/AutomationConfigValidator.php
Paulo Castellano 58d8e066b5
Add workspace webhooks and drop the unused automation webhook node (#326)
* Add workspace webhooks and drop the unused automation webhook node.

Give workspaces HMAC-signed outgoing webhooks for the post lifecycle, with retry, auto-pause, replay, and live logs, and keep HTTP Request as the only outbound automation node.

* Tighten webhook controller and validation after review.

Drop the redundant workspace redirects, prune logs without counting, and validate events/status with Rule::enum.

* Move leftover webhook UI copy behind i18n.

HTTP status phrases, delete-cancel, and validation attribute names were still English literals.

* Build the webhook-paused email through Maizzle.

The hand-written Blade skipped the shared layout, header, and footer used by the other mail templates.

* Cover real webhook dispatch paths and restyle the webhook pages.

* Ask for the shared delete keyword when confirming a webhook delete.

The endpoint URL is a poor confirm string; posts and assets already use the common "delete" keyword.

* Fix webhook review blockers so CI can go green.

Drop leftover French automation keys, stop mutating Inertia log props, and show delivered_at instead of created_at.

* Close the remaining webhook review gaps.

Keep Echo log updates across infinite scroll, align the channel with the policy, persist log ids across retries, and fail unknown automation nodes without throwing.

* Stop webhook delivery after disable and record last sent only on success.

Queued jobs now skip paused or disabled endpoints unless the user replays, and changing the URL re-pings it first.

* Limit webhooks to owners and admins, and encrypt signing secrets.

Members can no longer create or inspect outgoing integrations, and secrets stay encrypted at rest.

* Cover webhook secret hiding, skip-ping, and failed-delivery edges.

* Send the full post on webhooks after labels and platforms are saved.

* Fix webhook payloads for integer media ids and type webhook status.

* Split the webhook show page into focused components.

* Reset live webhook logs when switching endpoints.

* Keep the newest webhook logs at the top after live merges.

* Cast media item ids to string without the extra scalar check.

* Add post.unscheduled webhooks and put the log id on the envelope.

Unscheduling is now a first-class event, and receivers can send the delivery id back so we can find the matching log.

* Translate webhook event names in the UI.

* Make the webhook show page full-width and stop stacking flash toasts.

* Translate remaining webhook UI copy in every locale.

* Sign webhook pings and drop author email from the payload.

* Send signed webhook tests after create instead of pinging on save.

Create and update only block private URLs so the receiver can copy the secret first. The show page then sends a signed webhook.test with an object data envelope.

* Polish webhook test UX and always mint the dispatch log id in the job.

Keep send-test in the actions menu (its own group) and drop the leftover constructor param so retries reuse the serialized id instead of a caller-supplied one.
2026-09-04 09:43:29 -03:00

57 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\Automation;
use App\Enums\Automation\Node\Type as NodeType;
/**
* Single source of truth for per-node config validation. Walks an automation's
* nodes and reports every config issue, delegating to the type-specific
* validators. Shared by save (field-keyed errors), activation, and the editor
* test run so a misconfigured node is rejected up front with a clear message
* instead of failing midway through execution.
*/
final class AutomationConfigValidator
{
public function __construct(
private GenerateNodeValidator $generateValidator,
) {}
/**
* Every config issue across the given nodes, in node order.
*
* @param array<int, array<string, mixed>> $nodes
* @return list<array{node_index: int, field: string, message: string}>
*/
public function issues(array $nodes): array
{
$issues = [];
foreach ($nodes as $index => $node) {
$config = (array) data_get($node, 'data', []);
[$field, $message] = match (data_get($node, 'type')) {
NodeType::Generate->value => ['accounts', $this->generateValidator->issueFor($config)],
default => [null, null],
};
if ($message !== null) {
$issues[] = ['node_index' => $index, 'field' => $field, 'message' => $message];
}
}
return $issues;
}
/**
* The first config issue's message, or null when every node is runnable.
*
* @param array<int, array<string, mixed>> $nodes
*/
public function firstMessage(array $nodes): ?string
{
return $this->issues($nodes)[0]['message'] ?? null;
}
}