Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Tighten automation conventions: pagination, imports, i18n, enums

Paulo Castellano478cad9f27a8
diff --git a/CLAUDE.md b/CLAUDE.md
index bd1ecea67..ec414276c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -265,6 +265,8 @@ Vue components must have a single root element.
- 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 `<InfiniteScroll>` 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 7b83b9185..8b78eac91 100644
--- a/app/Actions/Automation/Automation/ActivateAutomation.php
+++ b/app/Actions/Automation/Automation/ActivateAutomation.php
@@ -8,6 +8,7 @@ use App\Enums\Automation\Node\Type as NodeType;
use App\Enums\Automation\Status;
use App\Models\Automation;
use App\Services\Automation\GenerateNodeValidator;
+use DomainException;
class ActivateAutomation
{
@@ -33,13 +34,13 @@ class ActivateAutomation
$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 @@ class ActivateAutomation
$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 02d0a38d0..d9b45f5c1 100644
--- a/app/Actions/Automation/Automation/GetAutomationInvocations.php
+++ b/app/Actions/Automation/Automation/GetAutomationInvocations.php
@@ -26,6 +26,6 @@ class GetAutomationInvocations
->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 8b8fff3c5..af9bd7f99 100644
--- a/app/Actions/Automation/Automation/ListAutomations.php
+++ b/app/Actions/Automation/Automation/ListAutomations.php
@@ -10,11 +10,11 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
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 34935f8ee..2bbce980a 100644
--- a/app/Actions/Automation/Node/RunConditionNode.php
+++ b/app/Actions/Automation/Node/RunConditionNode.php
@@ -5,9 +5,11 @@ declare(strict_types=1);
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 @@ class RunConditionNode
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 @@ class RunConditionNode
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 2c322caea..c61f2b94f 100644
--- a/app/Actions/Automation/Node/RunDelayNode.php
+++ b/app/Actions/Automation/Node/RunDelayNode.php
@@ -6,6 +6,7 @@ namespace App\Actions\Automation\Node;
use App\DataTransferObjects\Automation\NodeRunResult;
use App\Models\AutomationRun;
+use InvalidArgumentException;
class RunDelayNode
{
@@ -18,7 +19,7 @@ class RunDelayNode
'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 b01db4344..98311ab7a 100644
--- a/app/Actions/Automation/Node/RunFetchRssNode.php
+++ b/app/Actions/Automation/Node/RunFetchRssNode.php
@@ -46,7 +46,7 @@ class RunFetchRssNode
$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 @@ class RunFetchRssNode
$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 @@ class RunFetchRssNode
'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 ed6766662..9a6785a91 100644
--- a/app/Actions/Automation/Node/RunGenerateNode.php
+++ b/app/Actions/Automation/Node/RunGenerateNode.php
@@ -18,6 +18,7 @@ use App\Services\Automation\ExpressionResolver;
use App\Services\Automation\GenerateNodeValidator;
use App\Services\Image\PostImagePipeline;
use Illuminate\Support\Facades\Log;
+use Throwable;
class RunGenerateNode
{
@@ -224,7 +225,7 @@ class RunGenerateNode
$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 c740ff5ed..76b6f9586 100644
--- a/app/Actions/Automation/Node/RunHttpRequestNode.php
+++ b/app/Actions/Automation/Node/RunHttpRequestNode.php
@@ -67,7 +67,7 @@ class RunHttpRequestNode
$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 @@ class RunHttpRequestNode
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 @@ class RunHttpRequestNode
}
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 @@ class RunHttpRequestNode
$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 4f635e744..0a0fddc82 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 @@ class RunPublishNode
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 432699ad2..82f7a4a42 100644
--- a/app/Actions/Automation/Run/RetryRunFromNode.php
+++ b/app/Actions/Automation/Run/RetryRunFromNode.php
@@ -7,13 +7,14 @@ namespace App\Actions\Automation\Run;
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 000000000..7f8d1bcbf
--- /dev/null
+++ b/app/Enums/Automation/Condition/Handle.php
@@ -0,0 +1,17 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Enums\Automation\Condition;
+
+/**
+ * Output handles of a Condition node. The matched branch determines which
+ * handle the run continues down — these values must mirror the `id`s of the
+ * handles rendered in the frontend ConditionNode (resources/js/types/automation
+ * /condition-handle.ts) and the `source_handle` stored on edges.
+ */
+enum Handle: string
+{
+ case Yes = 'yes';
+ case No = 'no';
+}
diff --git a/app/Http/Requests/App/Automations/UpdateAutomationRequest.php b/app/Http/Requests/App/Automations/UpdateAutomationRequest.php
index 8725bcbc2..dd4220995 100644
--- a/app/Http/Requests/App/Automations/UpdateAutomationRequest.php
+++ b/app/Http/Requests/App/Automations/UpdateAutomationRequest.php
@@ -52,7 +52,7 @@ class UpdateAutomationRequest extends FormRequest
if (is_array($nodes)) {
foreach ($nodes as $i => $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 @@ class UpdateAutomationRequest extends FormRequest
/**
* @return array<string, array<int, mixed>>
*/
- 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 @@ class UpdateAutomationRequest extends FormRequest
],
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 eb6e90788..db769e8f1 100644
--- a/lang/en/automations.php
+++ b/lang/en/automations.php
@@ -381,5 +381,12 @@ return [
'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 9b43c1e46..8a37f35dc 100644
--- a/lang/es/automations.php
+++ b/lang/es/automations.php
@@ -381,5 +381,12 @@ return [
'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 0d9361c16..39149b4bf 100644
--- a/lang/pt-BR/automations.php
+++ b/lang/pt-BR/automations.php
@@ -381,5 +381,12 @@ return [
'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 44aae12d0..bc8965db5 100644
--- a/resources/js/components/automations/nodes/ConditionNode.vue
+++ b/resources/js/components/automations/nodes/ConditionNode.vue
@@ -1,8 +1,10 @@
<script setup lang="ts">
-import { Handle, Position } from '@vue-flow/core';
import { IconGitBranch } from '@tabler/icons-vue';
+import { Handle, Position } from '@vue-flow/core';
import { computed } from 'vue';
+import { ConditionHandle } from '@/types/automation/condition-handle';
+
const props = defineProps<{
data: {
field?: string;
@@ -41,7 +43,7 @@ const summary = computed(() => {
class="!bg-rose-500"
/>
<Handle
- id="yes"
+ :id="ConditionHandle.Yes"
type="source"
:position="Position.Right"
class="!bg-emerald-500"
@@ -49,7 +51,7 @@ const summary = computed(() => {
/>
<span class="pointer-events-none absolute left-full top-[35%] z-10 ml-3 -translate-y-1/2 rounded bg-background px-1.5 text-[10px] font-bold uppercase tracking-wider text-emerald-700">yes</span>
<Handle
- id="no"
+ :id="ConditionHandle.No"
type="source"
:position="Position.Right"
class="!bg-rose-500"
diff --git a/resources/js/types/automation/condition-handle.ts b/resources/js/types/automation/condition-handle.ts
new file mode 100644
index 000000000..1e1a6479b
--- /dev/null
+++ b/resources/js/types/automation/condition-handle.ts
@@ -0,0 +1,11 @@
+/**
+ * Output handle ids of a Condition node. Must mirror the backend
+ * App\Enums\Automation\Condition\Handle enum — the id rendered here becomes the
+ * edge `source_handle`, which the run engine matches to decide the branch.
+ */
+export const ConditionHandle = {
+ Yes: 'yes',
+ No: 'no',
+} as const;
+
+export type ConditionHandleValue = (typeof ConditionHandle)[keyof typeof ConditionHandle];
diff --git a/tests/Feature/Automation/AutomationCrudTest.php b/tests/Feature/Automation/AutomationCrudTest.php
index d8ad116dc..b362778d3 100644
--- a/tests/Feature/Automation/AutomationCrudTest.php
+++ b/tests/Feature/Automation/AutomationCrudTest.php
@@ -157,6 +157,36 @@ it('rejects update when an http_request node is missing the url', function () {
->assertJsonValidationErrors(['nodes.1.data.url']);
});
+it('rejects a scheduled publish node with no scheduled_offset', function () {
+ $automation = Automation::factory()->for($this->workspace)->create();
+
+ $this->actingAs($this->user)
+ ->putJson(route('app.automations.update', $automation->id), [
+ 'nodes' => [
+ ['id' => 'n1', 'type' => 'trigger', 'position' => ['x' => 0, 'y' => 0], 'data' => ['trigger_type' => 'schedule', 'cron' => '0 9 * * *']],
+ ['id' => 'n2', 'type' => 'publish', 'position' => ['x' => 200, 'y' => 0], 'data' => ['mode' => 'scheduled']],
+ ],
+ 'connections' => [['id' => 'e1', 'source' => 'n1', 'target' => 'n2']],
+ ])
+ ->assertStatus(422)
+ ->assertJsonValidationErrors(['nodes.1.data.scheduled_offset']);
+});
+
+it('allows a now publish node without scheduled_offset', function () {
+ $automation = Automation::factory()->for($this->workspace)->create();
+
+ $this->actingAs($this->user)
+ ->put(route('app.automations.update', $automation->id), [
+ 'nodes' => [
+ ['id' => 'n1', 'type' => 'trigger', 'position' => ['x' => 0, 'y' => 0], 'data' => ['trigger_type' => 'schedule', 'cron' => '0 9 * * *']],
+ ['id' => 'n2', 'type' => 'publish', 'position' => ['x' => 200, 'y' => 0], 'data' => ['mode' => 'now']],
+ ],
+ 'connections' => [['id' => 'e1', 'source' => 'n1', 'target' => 'n2']],
+ ])
+ ->assertRedirect()
+ ->assertSessionHasNoErrors();
+});
+
it('activates a valid automation', function () {
$automation = Automation::factory()->for($this->workspace)->withScheduleTrigger()->create();
$automation->update([