Send signed outgoing webhooks

Fed by the records themselves, delivered only to public HTTPS addresses
checked at every attempt, retried, and switched off after repeated failures.
A submitter's details travel only to webhooks that opted into them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 09:42:39 +02:00
parent f93775e549
commit 9bdbf834f6
23 changed files with 1325 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\Webhook;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends Factory<Webhook>
*/
class WebhookFactory extends Factory
{
public function definition(): array
{
return [
'name' => $this->faker->words(2, true),
'url' => 'https://hooks.example.org/'.Str::random(8),
'secret' => Str::random(40),
'events' => ['*'],
'include_personal_data' => false,
'is_active' => true,
];
}
}

View File

@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Outgoing webhooks: telling another system that something happened here —
* a submission arrived, a page went live — instead of it having to ask.
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('webhooks', function (Blueprint $table): void {
$table->id();
$table->string('name');
$table->string('url', 2048);
// Signs every delivery. Encrypted at rest: it is a credential.
$table->text('secret');
$table->jsonb('events');
// Submissions carry names, addresses and messages from people
// outside the collective; sending them elsewhere is opted into.
$table->boolean('include_personal_data')->default(false);
$table->boolean('is_active')->default(true);
$table->unsignedSmallInteger('consecutive_failures')->default(0);
$table->timestamp('last_delivered_at')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
Schema::create('webhook_deliveries', function (Blueprint $table): void {
$table->id();
$table->foreignId('webhook_id')->constrained()->cascadeOnDelete();
$table->uuid('uuid')->unique();
$table->string('event', 60);
$table->jsonb('payload');
$table->string('status', 20)->default('pending');
$table->unsignedSmallInteger('attempts')->default(0);
$table->unsignedSmallInteger('response_status')->nullable();
$table->text('error')->nullable();
$table->timestamp('delivered_at')->nullable();
$table->timestamps();
$table->index(['webhook_id', 'created_at']);
});
}
public function down(): void
{
Schema::dropIfExists('webhook_deliveries');
Schema::dropIfExists('webhooks');
}
};