diff --git a/CLAUDE.md b/CLAUDE.md index bd1ecea6..ec414276 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -265,6 +265,8 @@ ## Pagination - Always use normal pagination (`->paginate()`). NEVER use cursor pagination (`->cursorPaginate()`). - All paginated lists must use Inertia's scroll pagination (`Inertia::scroll()` on the backend with `` on the frontend). NEVER use traditional page-based pagination with page links/buttons. +- The page size ALWAYS comes from `config('app.pagination.default')` — never a magic number, and never a `perPage`/`per_page` value supplied by the request or frontend. Action/service list methods must NOT accept a `$perPage` parameter; call `->paginate((int) config('app.pagination.default'))` directly. + - The only exception is the public REST API (`app/Http/Controllers/Api`), which uses its own fixed, documented page size (15) as a stable API contract. ## Form Validation diff --git a/app/Actions/Automation/Automation/ActivateAutomation.php b/app/Actions/Automation/Automation/ActivateAutomation.php index 7b83b918..8b78eac9 100644 --- a/app/Actions/Automation/Automation/ActivateAutomation.php +++ b/app/Actions/Automation/Automation/ActivateAutomation.php @@ -8,6 +8,7 @@ use App\Enums\Automation\Status; use App\Models\Automation; use App\Services\Automation\GenerateNodeValidator; +use DomainException; class ActivateAutomation { @@ -33,13 +34,13 @@ private function validate(Automation $automation): void $triggers = collect($nodes)->where('type', 'trigger'); if ($triggers->count() !== 1) { - throw new \DomainException(__('automations.errors.must_have_one_trigger')); + throw new DomainException(__('automations.errors.must_have_one_trigger')); } $trigger = $triggers->first(); $hasTargetFromTrigger = collect($connections)->contains('source', $trigger['id']); if (! $hasTargetFromTrigger) { - throw new \DomainException(__('automations.errors.trigger_must_be_connected')); + throw new DomainException(__('automations.errors.trigger_must_be_connected')); } foreach ($nodes as $node) { @@ -50,7 +51,7 @@ private function validate(Automation $automation): void $issue = $this->generateValidator->issueFor((array) data_get($node, 'data', [])); if ($issue !== null) { - throw new \DomainException($issue); + throw new DomainException($issue); } } } diff --git a/app/Actions/Automation/Automation/GetAutomationInvocations.php b/app/Actions/Automation/Automation/GetAutomationInvocations.php index 02d0a38d..d9b45f5c 100644 --- a/app/Actions/Automation/Automation/GetAutomationInvocations.php +++ b/app/Actions/Automation/Automation/GetAutomationInvocations.php @@ -26,6 +26,6 @@ public function __invoke(Automation $automation, ?string $status = null, ?string ->when($status !== null, fn ($query) => $query->where('status', $status)) ->when($search !== null && $search !== '', fn ($query) => $query->whereLike('id', "%{$search}%")) ->latest() - ->paginate(25); + ->paginate((int) config('app.pagination.default')); } } diff --git a/app/Actions/Automation/Automation/ListAutomations.php b/app/Actions/Automation/Automation/ListAutomations.php index 8b8fff3c..af9bd7f9 100644 --- a/app/Actions/Automation/Automation/ListAutomations.php +++ b/app/Actions/Automation/Automation/ListAutomations.php @@ -10,11 +10,11 @@ class ListAutomations { - public function __invoke(Workspace $workspace, ?int $perPage = null): LengthAwarePaginator + public function __invoke(Workspace $workspace): LengthAwarePaginator { return Automation::query() ->where('workspace_id', $workspace->id) ->orderByDesc('created_at') - ->paginate($perPage ?? (int) config('app.pagination.default')); + ->paginate((int) config('app.pagination.default')); } } diff --git a/app/Actions/Automation/Node/RunConditionNode.php b/app/Actions/Automation/Node/RunConditionNode.php index 34935f8e..2bbce980 100644 --- a/app/Actions/Automation/Node/RunConditionNode.php +++ b/app/Actions/Automation/Node/RunConditionNode.php @@ -5,9 +5,11 @@ namespace App\Actions\Automation\Node; use App\DataTransferObjects\Automation\NodeRunResult; +use App\Enums\Automation\Condition\Handle; use App\Enums\Automation\Condition\Operator; use App\Models\AutomationRun; use App\Services\Automation\ExpressionResolver; +use Throwable; class RunConditionNode { @@ -34,7 +36,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult return NodeRunResult::completed( output: ['condition' => ['resolved_field' => $field, 'matched' => $matched]], - nextHandle: $matched ? 'yes' : 'no', + nextHandle: ($matched ? Handle::Yes : Handle::No)->value, ); } @@ -49,7 +51,7 @@ private function safeRegexMatch(string $pattern, string $subject): bool try { $result = @preg_match($regex, $subject); - } catch (\Throwable) { + } catch (Throwable) { return false; } diff --git a/app/Actions/Automation/Node/RunDelayNode.php b/app/Actions/Automation/Node/RunDelayNode.php index 2c322cae..c61f2b94 100644 --- a/app/Actions/Automation/Node/RunDelayNode.php +++ b/app/Actions/Automation/Node/RunDelayNode.php @@ -6,6 +6,7 @@ use App\DataTransferObjects\Automation\NodeRunResult; use App\Models\AutomationRun; +use InvalidArgumentException; class RunDelayNode { @@ -18,7 +19,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult 'minutes' => now()->addMinutes($duration), 'hours' => now()->addHours($duration), 'days' => now()->addDays($duration), - default => throw new \InvalidArgumentException("Unknown delay unit: {$unit}"), + default => throw new InvalidArgumentException("Unknown delay unit: {$unit}"), }; return NodeRunResult::sleep($until); diff --git a/app/Actions/Automation/Node/RunFetchRssNode.php b/app/Actions/Automation/Node/RunFetchRssNode.php index b01db434..98311ab7 100644 --- a/app/Actions/Automation/Node/RunFetchRssNode.php +++ b/app/Actions/Automation/Node/RunFetchRssNode.php @@ -46,7 +46,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult $feedUrl = $this->resolver->resolve((string) data_get($config, 'feed_url', ''), $run->resolverContext()); if ($feedUrl === '') { - return NodeRunResult::failed('Fetch RSS node missing feed_url.'); + return NodeRunResult::failed(__('automations.errors.fetch_rss_missing_url')); } try { @@ -61,7 +61,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult $response = Http::get($feedUrl); if (! $response->successful()) { - return NodeRunResult::failed('Feed request failed.', ['status' => $response->status()]); + return NodeRunResult::failed(__('automations.errors.fetch_rss_request_failed'), ['status' => $response->status()]); } try { @@ -73,7 +73,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult 'error' => $e->getMessage(), ]); - return NodeRunResult::failed('Malformed RSS feed.'); + return NodeRunResult::failed(__('automations.errors.fetch_rss_malformed')); } $nodeId = (string) $run->current_node_id; diff --git a/app/Actions/Automation/Node/RunGenerateNode.php b/app/Actions/Automation/Node/RunGenerateNode.php index ed676666..9a6785a9 100644 --- a/app/Actions/Automation/Node/RunGenerateNode.php +++ b/app/Actions/Automation/Node/RunGenerateNode.php @@ -18,6 +18,7 @@ use App\Services\Automation\GenerateNodeValidator; use App\Services\Image\PostImagePipeline; use Illuminate\Support\Facades\Log; +use Throwable; class RunGenerateNode { @@ -224,7 +225,7 @@ private function humanize(Workspace $workspace, array $structured, string $forma $structured['image_title'] = data_get($humanized, 'image_title', $structured['image_title'] ?? ''); $structured['image_body'] = data_get($humanized, 'image_body', $structured['image_body'] ?? ''); } - } catch (\Throwable $e) { + } catch (Throwable $e) { Log::warning('RunGenerateNode: PostContentHumanizer failed, using generator output as-is', [ 'error' => $e->getMessage(), ]); diff --git a/app/Actions/Automation/Node/RunHttpRequestNode.php b/app/Actions/Automation/Node/RunHttpRequestNode.php index c740ff5e..76b6f958 100644 --- a/app/Actions/Automation/Node/RunHttpRequestNode.php +++ b/app/Actions/Automation/Node/RunHttpRequestNode.php @@ -67,7 +67,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult $context = $run->resolverContext(); if ($url === '') { - return NodeRunResult::failed('HTTP request node missing url.'); + return NodeRunResult::failed(__('automations.errors.http_missing_url')); } $resolvedUrl = $this->resolver->resolve($url, $context); @@ -94,7 +94,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult default => null, }; } catch (Throwable $e) { - return NodeRunResult::failed('HTTP request threw an exception.', ['message' => $e->getMessage()]); + return NodeRunResult::failed(__('automations.errors.http_request_exception'), ['message' => $e->getMessage()]); } if ($response === null) { @@ -102,7 +102,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult } if (! $response->successful()) { - return NodeRunResult::failed('HTTP request failed.', [ + return NodeRunResult::failed(__('automations.errors.http_request_failed'), [ 'status' => $response->status(), 'body' => substr($response->body(), 0, 500), ]); @@ -128,7 +128,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult $resolved = data_get($payload, $itemsPath); if (! is_array($resolved)) { - return NodeRunResult::failed('Items path did not resolve to an array.'); + return NodeRunResult::failed(__('automations.errors.http_items_path_not_array')); } return $this->processItems($run, $nodeId, $config, array_values($resolved)); diff --git a/app/Actions/Automation/Node/RunPublishNode.php b/app/Actions/Automation/Node/RunPublishNode.php index 4f635e74..0a0fddc8 100644 --- a/app/Actions/Automation/Node/RunPublishNode.php +++ b/app/Actions/Automation/Node/RunPublishNode.php @@ -15,7 +15,7 @@ class RunPublishNode { public function __invoke(AutomationRun $run, array $config): NodeRunResult { - $mode = Mode::from($config['mode'] ?? 'now'); + $mode = Mode::from(data_get($config, 'mode', 'now')); // Dry runs never have a generated Post (RunGenerateNode skipped // persistence). Mirror the call site without touching the DB or @@ -34,7 +34,7 @@ public function __invoke(AutomationRun $run, array $config): NodeRunResult match ($mode) { Mode::Now => $this->publishNow($post), - Mode::Scheduled => $this->schedule($post, (int) ($config['scheduled_offset'] ?? 60)), + Mode::Scheduled => $this->schedule($post, (int) data_get($config, 'scheduled_offset')), Mode::Draft => null, }; diff --git a/app/Actions/Automation/Run/RetryRunFromNode.php b/app/Actions/Automation/Run/RetryRunFromNode.php index 432699ad..82f7a4a4 100644 --- a/app/Actions/Automation/Run/RetryRunFromNode.php +++ b/app/Actions/Automation/Run/RetryRunFromNode.php @@ -7,13 +7,14 @@ use App\Enums\Automation\Run\Status; use App\Jobs\Automation\ProcessAutomationNode; use App\Models\AutomationRun; +use DomainException; class RetryRunFromNode { public function __invoke(AutomationRun $run, string $nodeId): void { if ($run->status !== Status::Failed) { - throw new \DomainException(__('automations.errors.only_failed_can_retry')); + throw new DomainException(__('automations.errors.only_failed_can_retry')); } $run->update([ diff --git a/app/Enums/Automation/Condition/Handle.php b/app/Enums/Automation/Condition/Handle.php new file mode 100644 index 00000000..7f8d1bcb --- /dev/null +++ b/app/Enums/Automation/Condition/Handle.php @@ -0,0 +1,17 @@ + $node) { $type = data_get($node, 'type'); - foreach ($this->dataRulesForNodeType($type) as $field => $fieldRules) { + foreach ($this->dataRulesForNodeType($type, (int) $i) as $field => $fieldRules) { $rules["nodes.{$i}.data.{$field}"] = $fieldRules; } } @@ -115,12 +115,12 @@ public function attributes(): array /** * @return array> */ - private function dataRulesForNodeType(?string $type): array + private function dataRulesForNodeType(?string $type, int $i): array { return match ($type) { NodeType::Trigger->value => [ 'trigger_type' => ['required', Rule::in(array_column(TriggerType::cases(), 'value'))], - 'cron' => ['required_if:nodes.*.data.trigger_type,'.TriggerType::Schedule->value, 'string'], + 'cron' => ['required_if:nodes.'.$i.'.data.trigger_type,'.TriggerType::Schedule->value, 'string'], 'schedule_field' => ['sometimes', Rule::in(['minutes', 'hours', 'days', 'weeks', 'months'])], 'schedule_minutes_interval' => ['sometimes', 'integer', 'min:1', 'max:59'], 'schedule_hours_interval' => ['sometimes', 'integer', 'min:1', 'max:23'], @@ -168,7 +168,7 @@ private function dataRulesForNodeType(?string $type): array ], NodeType::Publish->value => [ 'mode' => ['required', Rule::in(array_column(PublishMode::cases(), 'value'))], - 'scheduled_offset' => ['nullable', 'integer', 'min:0'], + 'scheduled_offset' => ['required_if:nodes.'.$i.'.data.mode,'.PublishMode::Scheduled->value, 'integer', 'min:0'], ], NodeType::Webhook->value => [ 'url' => ['required', 'url'], diff --git a/lang/en/automations.php b/lang/en/automations.php index eb6e9078..db769e8f 100644 --- a/lang/en/automations.php +++ b/lang/en/automations.php @@ -381,5 +381,12 @@ 'url_not_allowed' => 'The request URL points to a private or unreachable address and was blocked.', 'node_no_longer_exists' => 'Node :node_id no longer exists in the automation.', 'no_trigger_connection' => 'No node connected to the Trigger node.', + 'fetch_rss_missing_url' => 'The Fetch RSS node is missing a feed URL.', + 'fetch_rss_request_failed' => 'The RSS feed request failed.', + 'fetch_rss_malformed' => 'The RSS feed is malformed.', + 'http_missing_url' => 'The HTTP request node is missing a URL.', + 'http_request_exception' => 'The HTTP request threw an exception.', + 'http_request_failed' => 'The HTTP request failed.', + 'http_items_path_not_array' => 'The items path did not resolve to a list.', ], ]; diff --git a/lang/es/automations.php b/lang/es/automations.php index 9b43c1e4..8a37f35d 100644 --- a/lang/es/automations.php +++ b/lang/es/automations.php @@ -381,5 +381,12 @@ 'url_not_allowed' => 'La URL de la petición apunta a una dirección privada o inaccesible y fue bloqueada.', 'node_no_longer_exists' => 'El nodo :node_id ya no existe en la automatización.', 'no_trigger_connection' => 'Ningún nodo está conectado al nodo disparador.', + 'fetch_rss_missing_url' => 'Al nodo Obtener RSS le falta la URL del feed.', + 'fetch_rss_request_failed' => 'La solicitud del feed RSS falló.', + 'fetch_rss_malformed' => 'El feed RSS está mal formado.', + 'http_missing_url' => 'Al nodo de petición HTTP le falta la URL.', + 'http_request_exception' => 'La petición HTTP lanzó una excepción.', + 'http_request_failed' => 'La petición HTTP falló.', + 'http_items_path_not_array' => 'El items path no resolvió a una lista.', ], ]; diff --git a/lang/pt-BR/automations.php b/lang/pt-BR/automations.php index 0d9361c1..39149b4b 100644 --- a/lang/pt-BR/automations.php +++ b/lang/pt-BR/automations.php @@ -381,5 +381,12 @@ 'url_not_allowed' => 'A URL da requisição aponta para um endereço privado ou inacessível e foi bloqueada.', 'node_no_longer_exists' => 'O nó :node_id não existe mais nesta automação.', 'no_trigger_connection' => 'Nenhum nó conectado ao nó de trigger.', + 'fetch_rss_missing_url' => 'O nó Buscar RSS está sem a URL do feed.', + 'fetch_rss_request_failed' => 'A requisição do feed RSS falhou.', + 'fetch_rss_malformed' => 'O feed RSS está malformado.', + 'http_missing_url' => 'O nó de requisição HTTP está sem a URL.', + 'http_request_exception' => 'A requisição HTTP lançou uma exceção.', + 'http_request_failed' => 'A requisição HTTP falhou.', + 'http_items_path_not_array' => 'O items path não resultou em uma lista.', ], ]; diff --git a/resources/js/components/automations/nodes/ConditionNode.vue b/resources/js/components/automations/nodes/ConditionNode.vue index 44aae12d..bc8965db 100644 --- a/resources/js/components/automations/nodes/ConditionNode.vue +++ b/resources/js/components/automations/nodes/ConditionNode.vue @@ -1,8 +1,10 @@