diff --git a/.github/workflows/api_refs.yaml b/.github/workflows/api_refs.yaml index 0a688d99e6..edc7b80d72 100644 --- a/.github/workflows/api_refs.yaml +++ b/.github/workflows/api_refs.yaml @@ -90,9 +90,10 @@ jobs: exit 1 fi - - name: Disable PHP coverage + - name: Set up PHP uses: shivammathur/setup-php@v2 with: + php-version: "8.4" coverage: none - name: Set up node diff --git a/composer.json b/composer.json index a22879a84b..4a8ca6c6ec 100644 --- a/composer.json +++ b/composer.json @@ -104,7 +104,8 @@ "ibexa/fastly": "~5.0.x-dev", "ibexa/connect": "~5.0.x-dev", "ibexa/connector-qualifio": "~5.0.x-dev", - "ibexa/doctrine-migrations": "~5.0.x-dev" + "ibexa/doctrine-migrations": "~5.0.x-dev", + "ibexa/webhooks": "~5.0.x-dev" }, "scripts": { "fix-cs": [ diff --git a/deptrac.baseline.yaml b/deptrac.baseline.yaml index ee925d54e9..42cd37bbc9 100644 --- a/deptrac.baseline.yaml +++ b/deptrac.baseline.yaml @@ -273,6 +273,8 @@ deptrac: - Ibexa\Core\MVC\Symfony\View\ContentValueView - Ibexa\Core\MVC\Symfony\View\LocationValueView - Ibexa\Core\MVC\Symfony\View\View + App\Webhook\ProductExtractor: + - Ibexa\Webhooks\Event\Extractor\ExtractorInterface AttributeTypeExtension: - Ibexa\PageBuilder\Form\Type\Attribute\AttributeType CustomRepositoryConfigParser: diff --git a/docs/api/api.md b/docs/api/api.md index 7d3cf2ede9..39dc7e1246 100644 --- a/docs/api/api.md +++ b/docs/api/api.md @@ -12,6 +12,7 @@ page_type: landing_page [[= cards([ "api/rest_api/rest_api_usage/rest_api_usage", "api/graphql/graphql", + "api/webhooks/webhooks", "ai/mcp/mcp", ], columns=3) =]] diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventType.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventType.html new file mode 100644 index 0000000000..4804b2a181 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventType.html @@ -0,0 +1,533 @@ + + + + + WebhookEventType | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookEventType

+ +
+ WebhookEventType.php + : + 11 + +
+
Interface
+ +
+ + + + + + + + + + + + + +

+ Methods +

+ +
+

+ publicgetEventClass() + +

+
+ WebhookEventType.php + : + 31 + +
+
+

Fully-qualified class name of the domain AfterEvent this type maps to.

+ +
+ + + + + + + +
+
+
+
+
+
+
public getEventClass() : string
+
+
+
+
+
+

Return values

+

string

+ + +
+

+ publicgetExtractor() + +

+
+ WebhookEventType.php + : + 37 + +
+
+

Optional service id of an ExtractorInterface implementation.

+ +
+ + + + + + + +
+
+
+
+
+
+
public getExtractor() : string|null
+
+
+
+
+
+
+

Returns null to use the default extractor.

+ +
+

Return values

+

string|null

+ + +
+

+ publicgetGroup() + +

+
+ WebhookEventType.php + : + 26 + +
+
+

Group name for display grouping, e.g. 'Content'.

+ +
+ + + + + + + +
+
+
+
+
+
+
public getGroup() : string
+
+
+
+
+
+

Return values

+

string

+ + +
+

+ publicgetIdentifier() + +

+
+ WebhookEventType.php + : + 16 + +
+
+

Machine-readable identifier, e.g. 'content.published'.

+ +
+ + + + + + + +
+
+
+
+
+
+
public getIdentifier() : string
+
+
+
+
+
+

Return values

+

string

+ + +
+

+ publicgetLabel() + +

+
+ WebhookEventType.php + : + 21 + +
+
+

Human-readable label, e.g. 'Content published'.

+ +
+ + + + + + + +
+
+
+
+
+
+
public getLabel() : string
+
+
+
+
+
+

Return values

+

string

+ + +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventTypeRegistryInterface.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventTypeRegistryInterface.html new file mode 100644 index 0000000000..ee5a7de7b5 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventTypeRegistryInterface.html @@ -0,0 +1,603 @@ + + + + + WebhookEventTypeRegistryInterface | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookEventTypeRegistryInterface

+ +
+ WebhookEventTypeRegistryInterface.php + : + 13 + +
+
Interface
+ +
+ + + + + + + + + + + + + +

+ Methods +

+ +
+

+ publicallByGroup() + +

+
+ WebhookEventTypeRegistryInterface.php + : + 39 + +
+
+

Returns all registered entries grouped by their group name.

+ +
+ + + + + + + +
+
+
+
+
+
+
public allByGroup() : array<string, array<int, WebhookEventType>>
+
+
+
+
+
+

Return values

+

array<string, array<int, WebhookEventType>>

+ + +
+

+ publicgetByEventClass() + +

+
+ WebhookEventTypeRegistryInterface.php + : + 25 + +
+
+

Returns the WebhookEventType registered for the given event class FQCN.

+ +
+ + + + + + + +
+
+
+
+
+
+
public getByEventClass(string $eventClass) : WebhookEventType
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $eventClass + + string + + - + + - +
+

Return values

+

WebhookEventType

+ +
+ Tags + + +
+
+
+ Throws +
+
+ WebhookEventTypeNotFoundException +
+

if no entry is registered for the given class.

+ +
+ +
+
+ +
+

+ publicgetByIdentifier() + +

+
+ WebhookEventTypeRegistryInterface.php + : + 32 + +
+
+

Returns the WebhookEventType registered under the given identifier (e.g. 'content.published').

+ +
+ + + + + + + +
+
+
+
+
+
+
public getByIdentifier(string $identifier) : WebhookEventType
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $identifier + + string + + - + + - +
+

Return values

+

WebhookEventType

+ +
+ Tags + + +
+
+
+ Throws +
+
+ WebhookEventTypeNotFoundException +
+

if no entry is registered for the given identifier.

+ +
+ +
+
+ +
+

+ publichas() + +

+
+ WebhookEventTypeRegistryInterface.php + : + 18 + +
+
+

Returns true if a WebhookEventType is registered for the given event class FQCN.

+ +
+ + + + + + + +
+
+
+
+
+
+
public has(string $eventClass) : bool
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $eventClass + + string + + - + + - +
+

Return values

+

bool

+ + +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Service-WebhookServiceInterface.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Service-WebhookServiceInterface.html new file mode 100644 index 0000000000..bf909d6b54 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Service-WebhookServiceInterface.html @@ -0,0 +1,1540 @@ + + + + + WebhookServiceInterface | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookServiceInterface

+ +
+ WebhookServiceInterface.php + : + 21 + +
+
Interface
+ +
+ + + + + + + + + + + + + +

+ Methods +

+ +
+

+ publiccountDeliveries() + +

+
+ WebhookServiceInterface.php + : + 86 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public countDeliveries(int $webhookId[, string|null $status = null ]) : int
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $webhookId + + int + + - + + - +
+ $status + + string|null + + null + + - +
+

Return values

+

int

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/read policy.

+ +
+ +
+
+ +
+

+ publiccountWebhooks() + +

+
+ WebhookServiceInterface.php + : + 48 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public countWebhooks() : int
+
+
+
+
+
+

Return values

+

int

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/read policy.

+ +
+ +
+
+ +
+

+ publiccreateWebhook() + +

+
+ WebhookServiceInterface.php + : + 27 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public createWebhook(WebhookCreateStruct $struct) : Webhook
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $struct + + WebhookCreateStruct + + - + + - +
+

Return values

+

Webhook

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/create policy.

+ +
+ +
+
+ Throws +
+
+ ValidationFailedException +
+

if the struct is invalid.

+ +
+ +
+
+ +
+

+ publicdeleteWebhook() + +

+
+ WebhookServiceInterface.php + : + 63 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public deleteWebhook(int $id) : void
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + int + + - + + - +
+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/delete policy.

+ +
+ +
+
+ +
+

+ publicloadDeliveries() + +

+
+ WebhookServiceInterface.php + : + 76 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public loadDeliveries(int $webhookId[, int|null $limit = null ][, int $offset = 0 ][, string|null $status = null ]) : array<string|int, WebhookDelivery>
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $webhookId + + int + + - + + - +
+ $limit + + int|null + + null + + - +
+ $offset + + int + + 0 + + - +
+ $status + + string|null + + null + + - +
+

Return values

+

array<string|int, WebhookDelivery>

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/read policy.

+ +
+ +
+
+ +
+

+ publicloadDelivery() + +

+
+ WebhookServiceInterface.php + : + 95 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public loadDelivery(string $id[, int|null $webhookId = null ]) : WebhookDelivery
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + string + + - + + - +
+ $webhookId + + int|null + + null + + - +
+

Return values

+

WebhookDelivery

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/read policy.

+ +
+ +
+
+ Throws +
+
+ DeliveryNotFoundException +
+

if no delivery exists under the given id, or it does not belong to the given webhook.

+ +
+ +
+
+ +
+

+ publicloadWebhook() + +

+
+ WebhookServiceInterface.php + : + 33 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public loadWebhook(int $id) : Webhook
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + int + + - + + - +
+

Return values

+

Webhook

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/read policy.

+ +
+ +
+
+ Throws +
+
+ WebhookNotFoundException +
+

if no webhook exists under the given id.

+ +
+ +
+
+ +
+

+ publicloadWebhooks() + +

+
+ WebhookServiceInterface.php + : + 40 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public loadWebhooks([int|null $limit = null ][, int $offset = 0 ]) : array<string|int, Webhook>
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $limit + + int|null + + null + + - +
+ $offset + + int + + 0 + + - +
+

Return values

+

array<string|int, Webhook>

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/read policy.

+ +
+ +
+
+ +
+

+ publicregenerateSecret() + +

+
+ WebhookServiceInterface.php + : + 69 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public regenerateSecret(int $id) : Webhook
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + int + + - + + - +
+

Return values

+

Webhook

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/update policy.

+ +
+ +
+
+ Throws +
+
+ WebhookNotFoundException +
+

if no webhook exists under the given id.

+ +
+ +
+
+ +
+

+ publicresendDelivery() + +

+
+ WebhookServiceInterface.php + : + 111 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public resendDelivery(string $deliveryId[, int|null $webhookId = null ]) : WebhookDelivery
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $deliveryId + + string + + - + + - +
+ $webhookId + + int|null + + null + + - +
+

Return values

+

WebhookDelivery

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/update policy.

+ +
+ +
+
+ Throws +
+
+ DeliveryNotFoundException +
+

if no delivery exists under the given id, or it does not belong to the given webhook.

+ +
+ +
+
+ +
+

+ publicsendTest() + +

+
+ WebhookServiceInterface.php + : + 105 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public sendTest(int $id) : WebhookDelivery
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + int + + - + + - +
+

Return values

+

WebhookDelivery

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/test policy.

+ +
+ +
+
+ Throws +
+
+ WebhookNotFoundException +
+

if no webhook exists under the given id.

+ +
+ +
+
+ Throws +
+
+ InvalidWebhookException +
+

if the webhook has no event types to send a test with.

+ +
+ +
+
+ +
+

+ publicupdateWebhook() + +

+
+ WebhookServiceInterface.php + : + 55 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public updateWebhook(int $id, WebhookUpdateStruct $struct) : Webhook
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + int + + - + + - +
+ $struct + + WebhookUpdateStruct + + - + + - +
+

Return values

+

Webhook

+ +
+ Tags + + +
+
+
+ Throws +
+
+ UnauthorizedException +
+

if the current user lacks the webhook/update policy.

+ +
+ +
+
+ Throws +
+
+ ValidationFailedException +
+

if the struct is invalid.

+ +
+ +
+
+ Throws +
+
+ WebhookNotFoundException +
+

if no webhook exists under the given id.

+ +
+ +
+
+ +
+
+
+ + +
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-DeliveryStatus.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-DeliveryStatus.html new file mode 100644 index 0000000000..2b12da4db7 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-DeliveryStatus.html @@ -0,0 +1,474 @@ + + + + + DeliveryStatus | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ DeliveryStatus +

+ +
+ DeliveryStatus.php + : + 11 + +
+
+ Enum: string +
+
+ + + + + + + + + + + +
+

+ Cases + + +

+
+
+

+ Pending +

+
+ DeliveryStatus.php + : + 13 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
string Pending = 'pending'
+
+
+
+ + +
+
+
+

+ Success +

+
+ DeliveryStatus.php + : + 14 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
string Success = 'success'
+
+
+
+ + +
+
+
+

+ Failed +

+
+ DeliveryStatus.php + : + 15 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
string Failed = 'failed'
+
+
+
+ + +
+
+
+

+ Skipped +

+
+ DeliveryStatus.php + : + 16 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
string Skipped = 'skipped'
+
+
+
+ + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-Webhook.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-Webhook.html new file mode 100644 index 0000000000..4e99d54f9c --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-Webhook.html @@ -0,0 +1,1138 @@ + + + + + Webhook | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ Webhook

+ +
+ Webhook.php + : + 14 + +
+
Read-only
+
Final
+ + + +
+

Immutable value object representing a configured webhook.

+ + + + + + + + + + + + +

+ Constants +

+
+

+ publicNAME_MAX_LENGTH +

+
+ Webhook.php + : + 19 + +
+
+

Maximum length of a webhook name, in characters (bounded by the storage column length).

+ +
+ + + + + + + +
+
+
+
+
+
+
public int NAME_MAX_LENGTH = 190
+
+
+
+ + + +

+ Properties +

+ +
+

+ public + $consecutiveFailures + + +

+
+ Webhook.php + : + 33 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int $consecutiveFailures
+
+
+
+ + +
+

+ public + $createdAt + + +

+
+ Webhook.php + : + 36 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public DateTimeImmutable|null $createdAt = null
+
+
+
+ + +
+

+ public + $disabledAt + + +

+
+ Webhook.php + : + 35 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public DateTimeImmutable|null $disabledAt = null
+
+
+
+ + +
+

+ public + $disabledReason + + +

+
+ Webhook.php + : + 34 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string|null $disabledReason
+
+
+
+ + +
+

+ public + $enabled + + +

+
+ Webhook.php + : + 29 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public bool $enabled
+
+
+
+ + +
+

+ public + $eventTypes + + +

+
+ Webhook.php + : + 30 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public array<string|int, mixed> $eventTypes
+
+
+
+ + +
+

+ public + $filters + + +

+
+ Webhook.php + : + 31 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public WebhookFilters $filters
+
+
+
+ + +
+

+ public + $id + + +

+
+ Webhook.php + : + 25 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int $id
+
+
+
+ + +
+

+ public + $modifiedAt + + +

+
+ Webhook.php + : + 37 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public DateTimeImmutable|null $modifiedAt = null
+
+
+
+ + +
+

+ public + $name + + +

+
+ Webhook.php + : + 26 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $name
+
+
+
+ + +
+

+ public + $ownerId + + +

+
+ Webhook.php + : + 32 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int $ownerId
+
+
+
+ + +
+

+ public + $secret + + +

+
+ Webhook.php + : + 28 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $secret
+
+
+
+ + +
+

+ public + $url + + +

+
+ Webhook.php + : + 27 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $url
+
+
+
+ + + + +

+ Methods +

+ +
+

+ public__construct() + +

+
+ Webhook.php + : + 24 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public __construct(int $id, string $name, string $url, string $secret, bool $enabled, array<int, string> $eventTypes, WebhookFilters $filters, int $ownerId, int $consecutiveFailures, string|null $disabledReason[, DateTimeImmutable|null $disabledAt = null ][, DateTimeImmutable|null $createdAt = null ][, DateTimeImmutable|null $modifiedAt = null ])
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + int + + - + + - +
+ $name + + string + + - + + - +
+ $url + + string + + - + + - +
+ $secret + + string + + - + + - +
+ $enabled + + bool + + - + + - +
+ $eventTypes + + array<int, string> + + - + + - +
+ $filters + + WebhookFilters + + - + + - +
+ $ownerId + + int + + - + + - +
+ $consecutiveFailures + + int + + - + + - +
+ $disabledReason + + string|null + + - + + - +
+ $disabledAt + + DateTimeImmutable|null + + null + + - +
+ $createdAt + + DateTimeImmutable|null + + null + + - +
+ $modifiedAt + + DateTimeImmutable|null + + null + + - +
+ + +
+
+
+ + +
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookCreateStruct.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookCreateStruct.html new file mode 100644 index 0000000000..213534e576 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookCreateStruct.html @@ -0,0 +1,572 @@ + + + + + WebhookCreateStruct | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookCreateStruct

+ +
+ WebhookCreateStruct.php + : + 14 + +
+
Final
+ + + +
+

Mutable struct for creating a new webhook.

+ + + + + + + + + + + + + +

+ Properties +

+ +
+

+ public + $enabled + + +

+
+ WebhookCreateStruct.php + : + 20 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public bool $enabled = true
+
+
+
+ + +
+

+ public + $eventTypes + + +

+
+ WebhookCreateStruct.php + : + 23 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public array<int, string> $eventTypes = []
+
+
+
+ + +
+

+ public + $filters + + +

+
+ WebhookCreateStruct.php + : + 25 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public WebhookFilters $filters
+
+
+
+ + +
+

+ public + $name + + +

+
+ WebhookCreateStruct.php + : + 16 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $name = ''
+
+
+
+ + +
+

+ public + $url + + +

+
+ WebhookCreateStruct.php + : + 18 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $url = ''
+
+
+
+ + + + +

+ Methods +

+ +
+

+ public__construct() + +

+
+ WebhookCreateStruct.php + : + 27 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public __construct()
+
+
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookDelivery.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookDelivery.html new file mode 100644 index 0000000000..fdd2d1cc6f --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookDelivery.html @@ -0,0 +1,1038 @@ + + + + + WebhookDelivery | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookDelivery

+ +
+ WebhookDelivery.php + : + 16 + +
+
Read-only
+
Final
+ + + +
+

Immutable value object representing a single webhook delivery attempt.

+ + + + + + + + + + + + + +

+ Properties +

+ +
+

+ public + $attempt + + +

+
+ WebhookDelivery.php + : + 26 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int $attempt
+
+
+
+ + +
+

+ public + $createdAt + + +

+
+ WebhookDelivery.php + : + 32 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public DateTimeImmutable $createdAt
+
+
+
+ + +
+

+ public + $deliveredAt + + +

+
+ WebhookDelivery.php + : + 33 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public DateTimeImmutable|null $deliveredAt = null
+
+
+
+ + +
+

+ public + $durationMs + + +

+
+ WebhookDelivery.php + : + 28 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int|null $durationMs
+
+
+
+ + +
+

+ public + $error + + +

+
+ WebhookDelivery.php + : + 29 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string|null $error
+
+
+
+ + +
+

+ public + $eventType + + +

+
+ WebhookDelivery.php + : + 24 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $eventType
+
+
+
+ + +
+

+ public + $id + + +

+
+ WebhookDelivery.php + : + 22 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $id
+
+
+
+ + +
+

+ public + $isTest + + +

+
+ WebhookDelivery.php + : + 31 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public bool $isTest
+
+
+
+ + +
+

+ public + $requestPayload + + +

+
+ WebhookDelivery.php + : + 30 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string $requestPayload
+
+
+
+ + +
+

+ public + $responseCode + + +

+
+ WebhookDelivery.php + : + 27 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int|null $responseCode
+
+
+
+ + +
+

+ public + $status + + +

+
+ WebhookDelivery.php + : + 25 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public DeliveryStatus $status
+
+
+
+ + +
+

+ public + $webhookId + + +

+
+ WebhookDelivery.php + : + 23 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public int $webhookId
+
+
+
+ + + + +

+ Methods +

+ +
+

+ public__construct() + +

+
+ WebhookDelivery.php + : + 21 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public __construct(string $id, int $webhookId, string $eventType, DeliveryStatus $status, int $attempt, int|null $responseCode, int|null $durationMs, string|null $error, string $requestPayload, bool $isTest, DateTimeImmutable $createdAt[, DateTimeImmutable|null $deliveredAt = null ])
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $id + + string + + - + + - +
+ $webhookId + + int + + - + + - +
+ $eventType + + string + + - + + - +
+ $status + + DeliveryStatus + + - + + - +
+ $attempt + + int + + - + + - +
+ $responseCode + + int|null + + - + + - +
+ $durationMs + + int|null + + - + + - +
+ $error + + string|null + + - + + - +
+ $requestPayload + + string + + - + +
+

JSON-encoded delivery envelope, sent verbatim as the HTTP request body

+ +
+ +
+ $isTest + + bool + + - + + - +
+ $createdAt + + DateTimeImmutable + + - + + - +
+ $deliveredAt + + DateTimeImmutable|null + + null + + - +
+ + +
+
+
+ + +
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookFilters.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookFilters.html new file mode 100644 index 0000000000..328d959b59 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookFilters.html @@ -0,0 +1,602 @@ + + + + + WebhookFilters | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookFilters

+ +
+ WebhookFilters.php + : + 16 + +
+
Read-only
+
Final
+ + + +
+

Immutable value object holding the delivery filters of a webhook.

+ + +
+

All non-empty dimensions must match (AND semantics); an empty list means "match all".

+ +
+ + + + + + + + + + +

+ Constants +

+
+

+ publicMAX_VALUES +

+
+ WebhookFilters.php + : + 21 + +
+
+

Maximum number of values of a single filter dimension (each value is looked up on validation).

+ +
+ + + + + + + +
+
+
+
+
+
+
public int MAX_VALUES = 100
+
+
+
+ + + +

+ Properties +

+ +
+

+ public + $contentTypeIdentifiers + + +

+
+ WebhookFilters.php + : + 29 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public array<string|int, mixed> $contentTypeIdentifiers = []
+
+
+
+ + +
+

+ public + $sectionIds + + +

+
+ WebhookFilters.php + : + 30 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public array<string|int, mixed> $sectionIds = []
+
+
+
+ + +
+

+ public + $subtreePathStrings + + +

+
+ WebhookFilters.php + : + 31 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public array<string|int, mixed> $subtreePathStrings = []
+
+
+
+ + + + +

+ Methods +

+ +
+

+ public__construct() + +

+
+ WebhookFilters.php + : + 28 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public __construct([array<int, string> $contentTypeIdentifiers = [] ][, array<int, int> $sectionIds = [] ][, array<int, string> $subtreePathStrings = [] ])
+
+
+
+
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
+ $contentTypeIdentifiers + + array<int, string> + + [] + + - +
+ $sectionIds + + array<int, int> + + [] + + - +
+ $subtreePathStrings + + array<int, string> + + [] + + - +
+ + +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookUpdateStruct.html b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookUpdateStruct.html new file mode 100644 index 0000000000..400db9a1e6 --- /dev/null +++ b/docs/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookUpdateStruct.html @@ -0,0 +1,523 @@ + + + + + WebhookUpdateStruct | PHP API Reference (Ibexa Documentation) + + + + + + + + + + + + + + + + +
Copied!
+ + + + +
+ +
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + +
+
+ + +
+
+

+ WebhookUpdateStruct

+ +
+ WebhookUpdateStruct.php + : + 15 + +
+
Final
+ + + +
+

Mutable struct for partially updating an existing webhook.

+ + +
+

Null values mean "no change" for that field.

+ +
+ + + + + + + + + + + +

+ Properties +

+ +
+

+ public + $enabled + + +

+
+ WebhookUpdateStruct.php + : + 21 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public bool|null $enabled = null
+
+
+
+ + +
+

+ public + $eventTypes + + +

+
+ WebhookUpdateStruct.php + : + 24 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public array<int, string>|null $eventTypes = null
+
+
+
+ + +
+

+ public + $filters + + +

+
+ WebhookUpdateStruct.php + : + 26 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public WebhookFilters|null $filters = null
+
+
+
+ + +
+

+ public + $name + + +

+
+ WebhookUpdateStruct.php + : + 17 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string|null $name = null
+
+
+
+ + +
+

+ public + $url + + +

+
+ WebhookUpdateStruct.php + : + 19 + +
+
+ +
+ + + + + + + +
+
+
+
+
+
+
public string|null $url = null
+
+
+
+ + + + +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/docs/api/webhooks/configure_webhooks.md b/docs/api/webhooks/configure_webhooks.md new file mode 100644 index 0000000000..5d3d8e0c76 --- /dev/null +++ b/docs/api/webhooks/configure_webhooks.md @@ -0,0 +1,211 @@ +--- +description: Install and configure webhooks, including the signing secret encryption key, the delivery transport, retries, and delivery log retention. +month_change: false +--- + +# Configure webhooks + +Webhooks are provided by the `ibexa/webhooks` package. +The package requires the `ibexa/rest` and `ibexa/messenger` packages, which are part of every [[= product_name =]] edition. +The back office screens additionally require `ibexa/admin-ui`. + +## Installation + +### Install package + +Run the following command to install the package: + +``` bash +composer require ibexa/webhooks +``` + +### Modify the bundles file + +Then, if not using Symfony Flex, add the following code to the `config/bundles.php` file: + +``` php + ['all' => true], +]; +``` + +Make sure that `Ibexa\Bundle\Messenger\IbexaMessengerBundle` is registered as well. + +### Import routes + +Create the `config/routes/ibexa_webhooks.yaml` file with the following content, to register the back office screens and the REST API endpoints: + +``` yaml +ibexa.webhooks: + resource: '@IbexaWebhooksBundle/Resources/config/routing.yaml' + +ibexa.webhooks.rest: + resource: '@IbexaWebhooksBundle/Resources/config/routing_rest.yaml' + prefix: '%ibexa.rest.path_prefix%' +``` + +### Add tables to the database + +Webhooks store their configuration in the `ibexa_webhook` table and the delivery log in the `ibexa_webhook_delivery` table. +Both tables are defined in the [[= product_name =]] database schema, so they're created when you install a new project. + +To add them to an existing database, generate the SQL statements for your database engine and run them: + +``` bash +php bin/console ibexa:doctrine:schema:dump-sql +``` + +### Generate encryption key + +Signing secrets of webhooks are encrypted in the database with a key that you must provide. +The key must be exactly 32 bytes long. + +Generate a key and store it, base64-encoded, in an environment variable, for example, in the `.env.local` file: + +``` bash +php -r 'echo base64_encode(sodium_crypto_secretbox_keygen()), PHP_EOL;' +``` + +``` bash +WEBHOOK_SECRET_KEY= +``` + +Then, reference the variable in the `config/packages/ibexa_webhooks.yaml` file: + +``` yaml +ibexa_webhooks: + secret_key: '%env(base64:WEBHOOK_SECRET_KEY)%' +``` + +!!! caution "Keep the encryption key safe" + + Treat the encryption key like any other credential: don't commit it to the repository and use the same key in every environment that shares the database. + If you lose or change the key, the stored signing secrets can't be decrypted, and deliveries fail until you regenerate the signing secret of every webhook. + +## Configure delivery + +### Delivery transport + +Deliveries are dispatched on the `ibexa.messenger.bus` message bus and always routed to a dedicated `ibexa_webhook` transport, registered by the package. +The routing doesn't depend on the `framework.messenger.routing` configuration of your application. + +By default, the transport uses the `sync://` DSN, which sends webhooks immediately, within the request that triggered the event. +This setting is convenient for development, but it makes editors wait for the receiving systems to respond, and failed deliveries aren't retried. + +For production, set the `delivery.transport_dsn` setting to an asynchronous DSN supported by one of the installed [Symfony Messenger transports](https://symfony.com/doc/current/messenger.html#transports-async-queued-messages). +For example, to use a dedicated queue in the database table used by `ibexa/messenger`: + +``` yaml +ibexa_webhooks: + delivery: + transport_dsn: 'doctrine://ibexa.current?table_name=ibexa_messenger_messages&queue_name=ibexa_webhook&auto_setup=false' +``` + +To use an external message broker, reference its DSN through an environment variable: + +``` yaml +ibexa_webhooks: + delivery: + transport_dsn: '%env(WEBHOOK_TRANSPORT_DSN)%' +``` + +``` bash +WEBHOOK_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/ibexa_webhook +``` + +### Run the worker + +With an asynchronous transport, deliveries are sent by a worker process that consumes the `ibexa_webhook` transport: + +``` bash +php bin/console messenger:consume ibexa_webhook --time-limit=3600 +``` + +In production, run the worker under a process manager, such as Supervisor or systemd, which restarts it when it stops. +For more information, see [Deploying to production](https://symfony.com/doc/current/messenger.html#deploying-to-production) in Symfony documentation. + +### Timeouts and retries + +A delivery fails when the receiver can't be reached, doesn't respond in time, or responds with a status code other than `2xx`. + +A failed delivery is retried up to `delivery.max_retries` times. +The first retry happens after 1 second, and every next delay is three times longer than the previous one (1, 3, 9 seconds, and so on). +When all retries are exhausted, the delivery remains in the delivery log with the `failed` status. + +!!! note "Failure transport" + + The `ibexa_webhook` transport isn't declared under `framework.messenger`, so the `framework.messenger.failure_transport` setting doesn't apply to it. + Failed deliveries are kept in the delivery log instead, from where you can [re-send them](webhooks_api.md#re-send-deliveries). + +### Automatic disabling + +Every failed attempt, including retries and test deliveries, increases the consecutive failure counter of the webhook, and every successful delivery resets it. +When the counter reaches `delivery.auto_disable_after`, the webhook is disabled, and its owner receives a back office notification. + +With the default settings, one event that can't be delivered produces four failed attempts (the first attempt and three retries). +Adjust `delivery.auto_disable_after` and `delivery.max_retries` together to match the expected availability of the receiving systems. + +## Delivery log retention + +Delivery log entries older than `retention.delivery_log_days` days are removed by the following command: + +``` bash +php bin/console ibexa:webhooks:prune-delivery-log +``` + +If the `ibexa/cron` package is installed, the command runs automatically every day at 03:00. +Otherwise, schedule it with the task scheduler of your system. + +## Configuration reference + +All settings are placed under the `ibexa_webhooks` [configuration key](configuration.md#configuration-files). +Only `secret_key` is required. +The example below shows the default values of all other settings: + +``` yaml +ibexa_webhooks: + secret_key: '%env(base64:WEBHOOK_SECRET_KEY)%' + delivery: + transport_dsn: 'sync://' + timeout: + connect: 5 + response: 10 + max_retries: 3 + auto_disable_after: 10 + retention: + delivery_log_days: 30 + signature: + header: 'X-Cohesivo-Signature' + algo: 'sha256' +``` + +The following settings are available: + +| Setting | Default value | Description | +|---|---|---| +| `secret_key` | | Raw, 32-byte key used to encrypt signing secrets in the database. Required. | +| `delivery.transport_dsn` | `sync://` | Symfony Messenger DSN of the `ibexa_webhook` transport. Use an asynchronous DSN in production. | +| `delivery.timeout.connect` | `5` | Time, in seconds, to wait for the receiver to accept the connection. | +| `delivery.timeout.response` | `10` | Maximum total duration of a request, in seconds. | +| `delivery.max_retries` | `3` | Number of retries before a delivery is considered failed. Set to `0` to disable retries. | +| `delivery.auto_disable_after` | `10` | Number of consecutive failed attempts after which a webhook is disabled automatically. | +| `retention.delivery_log_days` | `30` | Number of days for which delivery log entries are kept. | +| `signature.header` | `X-Cohesivo-Signature` | Name of the HTTP header that carries the signature. | +| `signature.algo` | `sha256` | Hashing algorithm used to compute the HMAC signature. Accepts any algorithm supported by the PHP [`hash_hmac()`](https://www.php.net/manual/en/function.hash-hmac.php) function. | + +## Permissions + +To work with webhooks, users need the [`webhook` policies](policies.md#webhooks): + +| Function | Grants access to | +|---|---| +| `webhook/read` | the **Webhooks** item in the **Admin** menu, the webhook list, the delivery log, and the list of event types | +| `webhook/create` | creating webhooks | +| `webhook/update` | editing, enabling, and disabling webhooks, regenerating signing secrets, and re-sending deliveries | +| `webhook/delete` | removing webhooks together with their delivery log | +| `webhook/test` | sending test deliveries | + +Because webhooks can send repository data to any URL, grant these policies, especially `webhook/create` and `webhook/update`, only to trusted administrators. diff --git a/docs/api/webhooks/extend_webhooks.md b/docs/api/webhooks/extend_webhooks.md new file mode 100644 index 0000000000..d037b80c67 --- /dev/null +++ b/docs/api/webhooks/extend_webhooks.md @@ -0,0 +1,216 @@ +--- +description: Add custom webhook event types and control the data included in webhook payloads. +month_change: false +--- + +# Extend webhooks + +Out of the box, webhooks can subscribe to [21 repository events](webhook_payload_reference.md#event-types). +You can make any other event available to webhooks, for example, an event dispatched by your own code or by another [[= product_name =]] package, by registering a custom event type. + +## How event types work + +Each event type is a service that implements the [`WebhookEventType`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventType.html) interface and is tagged with `ibexa.webhook.event_type`. +The tag's `event_class` attribute contains the fully qualified class name of the Symfony event that the event type maps to. + +When the container is compiled, the system registers a listener for every `event_class`. +When such an event is dispatched, the listener: + +1. Converts the event to a normalized `DomainEvent` with an extractor. +The extractor resolves the [identifiers](webhook_payload_reference.md#identifiers) included in the payload, and the match context, which contains the content type, section, and location path strings that webhook [filters](webhooks_guide.md#filters) are evaluated against. +1. Finds all enabled webhooks that subscribe to the event type and whose filters match the event. +1. Creates a delivery for each of them and queues it. + +Registered event types are automatically listed in the back office and returned by the `GET /webhook-event-types` REST API endpoint. + +!!! note "After events only" + + Map event types to events dispatched after an operation is completed, such as the repository `AfterEvent` events. + Otherwise, webhooks can notify external systems about operations that eventually fail. + +## Register event type + +In most cases, you can use the built-in `GenericWebhookEventType` class and configure it in the service definition. +The following example adds a `product.published` event type that maps to a custom `ProductPublishedEvent` event: + +``` yaml +services: + app.webhook.event_type.product_published: + class: Ibexa\Webhooks\Event\Catalog\GenericWebhookEventType + arguments: + $identifier: 'product.published' + $label: 'Product published' + $group: 'Product' + $eventClass: 'App\Event\ProductPublishedEvent' + tags: + - { name: ibexa.webhook.event_type, event_class: 'App\Event\ProductPublishedEvent' } +``` + +The following arguments are available: + +| Argument | Description | +|---|---| +| `$identifier` | Unique identifier of the event type, sent in the `event` property of the payload and in the `X-Cohesivo-Event` header. Use the `.` convention, for example, `product.published`. | +| `$label` | Name of the event type displayed in the back office. | +| `$group` | Name of the group under which the event type is displayed in the back office. Event types with the same group name are displayed together. | +| `$eventClass` | Fully qualified class name of the event. Must be the same as the `event_class` attribute of the tag. | +| `$extractor` | Optional. ID of the extractor service. If not set, the default extractor is used. See [Custom extractor](#custom-extractor). | + +Clear the cache to apply the changes: + +``` bash +php bin/console cache:clear +``` + +!!! caution "Changing identifiers" + + Webhooks store the identifiers of the event types that they subscribe to. + If you change or remove the identifier of an event type, existing webhooks stop receiving the event. + +### Implement event type class + +If you need more control, for example, to translate the label, implement the `WebhookEventType` interface: + +``` php +getProduct(); + + return new DomainEvent( + type: $type, + occurredAt: $this->clock->now(), + actorId: $this->permissionResolver->getCurrentUserReference()->getUserId(), + identifiers: [ + 'productCode' => $product->getCode(), + 'contentId' => $product->getContent()->getId(), + ], + matchContexts: [ + new MatchContext( + contentTypeIdentifier: $product->getProductType()->getIdentifier(), + ), + ], + ); + } +} +``` + +The `DomainEvent` object has the following properties: + +| Property | Description | +|---|---| +| `type` | Identifier of the event type. Pass the `$type` argument of the `extract()` method. | +| `occurredAt` | Date and time of the event. | +| `actorId` | ID of the user who triggered the event, or `null` for events triggered by the system. | +| `identifiers` | Map of identifiers included in the payload. Values can be integers, strings, or lists of strings. When the map contains `contentId` or `locationId`, the payload automatically includes the matching [links](webhook_payload_reference.md#links). | +| `matchContext` | `MatchContext` object with the `contentTypeIdentifier`, `sectionId`, and `locationPathStrings` properties that filters are evaluated against. Leave a property empty if it doesn't apply. A webhook with a non-empty filter doesn't receive events whose corresponding match context property is empty. | + +Register the extractor as a service with the `ibexa.webhook.extractor` tag, and reference its service ID in the `$extractor` argument of the event type: + +``` yaml +services: + App\Webhook\ProductExtractor: + tags: + - { name: ibexa.webhook.extractor } + + app.webhook.event_type.product_published: + class: Ibexa\Webhooks\Event\Catalog\GenericWebhookEventType + arguments: + $identifier: 'product.published' + $label: 'Product published' + $group: 'Product' + $eventClass: 'App\Event\ProductPublishedEvent' + $extractor: 'App\Webhook\ProductExtractor' + tags: + - { name: ibexa.webhook.event_type, event_class: 'App\Event\ProductPublishedEvent' } +``` + +If you implement the `WebhookEventType` interface, return the service ID of the extractor from the `getExtractor()` method. + +!!! caution "Extractor tag" + + Extractors are resolved from a service locator built from services tagged with `ibexa.webhook.extractor`. + If the extractor service isn't tagged, the default extractor is used instead, without any error message. + +Exceptions thrown by an extractor are logged and don't interrupt the operation that dispatched the event, but no deliveries are created for that occurrence. +Keep extractors fast and free of side effects: they run synchronously, every time the event is dispatched, in the request that triggered it. diff --git a/docs/api/webhooks/webhook_payload_reference.md b/docs/api/webhooks/webhook_payload_reference.md new file mode 100644 index 0000000000..03d54c7798 --- /dev/null +++ b/docs/api/webhooks/webhook_payload_reference.md @@ -0,0 +1,301 @@ +--- +description: Structure of webhook requests, available event types, and how to verify webhook signatures in the receiving application. +month_change: false +--- + +# Webhook payload reference + +Every webhook delivery is an HTTP `POST` request sent to the payload URL of the webhook. +The request carries a JSON body, called the envelope, and a set of headers that identify and sign the delivery. + +Use this reference when you build an application that receives webhooks from [[= product_name =]]. + +## Request headers + +| Header | Example value | Description | +|---|---|---| +| `Content-Type` | `application/json` | Always `application/json`. | +| `X-Cohesivo-Event` | `content.published` | Identifier of the [event type](#event-types). | +| `X-Cohesivo-Delivery` | `0198f0c2-6b1e-7c3a-9d4e-1f2a3b4c5d6e` | UUID of the delivery, as shown in the delivery log. | +| `X-Cohesivo-Timestamp` | `1756376400` | Unix timestamp, in seconds, of the moment the request was sent. | +| `X-Cohesivo-Signature` | `sha256=a3f5…` | HMAC signature of the request, in the `=` format. | + +The name of the signature header and the hashing algorithm can be [changed in configuration](configure_webhooks.md#configuration-reference). + +## Envelope + +The request body is a JSON object with the following properties: + +| Property | Type | Description | +|---|---|---| +| `id` | string | UUID of the delivery for which the envelope was created. It doesn't change when the delivery is re-sent, so you can use it to detect duplicates. | +| `event` | string | Identifier of the [event type](#event-types), for example, `content.published`. | +| `occurredAt` | string | Date and time when the event occurred, in the RFC 3339 format. | +| `actor.id` | integer or `null` | ID of the user who triggered the event, or `null` if the event was triggered by the system. | +| `actor.type` | string | `user` when `actor.id` is set, `system` otherwise. | +| `identifiers` | object | Identifiers of the affected content, location, or other objects. The keys depend on the [event type](#event-types). | +| `links` | object | REST API URIs of the affected objects. See [Links](#links). | + +`identifiers` and `links` are always JSON objects. +When they have no members, they're serialized as `{}`. + +The envelope is encoded once, when the delivery is created, and the same bytes are sent with every attempt, so the signature always covers exactly the body that you receive. + +A machine-readable [JSON Schema](https://json-schema.org/) of the envelope is available in the REST API reference as the `WebhookPayload` schema. + +### Example envelope + +The following example shows a `content.published` delivery triggered by the user with ID 14: + +``` json +{ + "id": "0198f0c2-6b1e-7c3a-9d4e-1f2a3b4c5d6e", + "event": "content.published", + "occurredAt": "2026-08-28T10:20:00+00:00", + "actor": { + "id": 14, + "type": "user" + }, + "identifiers": { + "contentId": 42, + "languageCode": "eng-GB", + "locationId": 58, + "versionNo": 3, + "languageCodes": ["eng-GB", "ger-DE"] + }, + "links": { + "content": "/api/ibexa/v2/content/objects/42", + "location": "/api/ibexa/v2/content/locations/58" + } +} +``` + +### Identifiers + +The following keys can appear in the `identifiers` object: + +| Key | Type | Description | +|---|---|---| +| `contentId` | integer | ID of the content item. | +| `languageCode` | string | Main language code of the content item. | +| `locationId` | integer | ID of the affected location. For events that concern a content item, it's the ID of its main location, if the content item has one. | +| `versionNo` | integer | Number of the version that the event concerns. | +| `languageCodes` | array of strings | Language codes of all translations in the version. | +| `objectStateId` | integer | ID of the object state. | +| `objectStateIdentifier` | string | Identifier of the object state. | +| `objectStateGroupId` | integer | ID of the object state group. | +| `objectStateGroupIdentifier` | string | Identifier of the object state group. | + +Event types added by developers can include other keys. +For more information, see [Extend webhooks](extend_webhooks.md#custom-extractor). + +### Links + +The `links` object contains URIs of REST API resources that you can use to fetch more data about the affected objects: + +| Key | URI pattern | Present when | +|---|---|---| +| `content` | `/api/ibexa/v2/content/objects/` | `identifiers.contentId` is set | +| `location` | `/api/ibexa/v2/content/locations/` | `identifiers.locationId` is set | + +The URIs are relative to the host of [[= product_name =]]. +To access the resources, the receiving application must [authenticate](rest_api_authentication.md) as a user with sufficient permissions. + +!!! note "Deleted content" + + For events such as `content.deleted`, `location.deleted`, or `trash.emptied`, the linked resources might no longer exist when the receiver processes the delivery. + +## Event types + +The following event types are available out of the box. +The **Identifiers** column lists the keys of the [`identifiers`](#identifiers) object, and the **Filters** column indicates whether [content type, section, and subtree filters](webhooks_guide.md#filters) apply to the event. + +| Event type | Triggered when | Identifiers | Filters | +|---|---|---|---| +| `content.published` | a content version is published | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `content.created` | a content item (its first draft) is created | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `content.deleted` | a content item is deleted | `contentId`, `languageCode`, `locationId` | Yes | +| `content.hidden` | a content item is hidden | `contentId`, `languageCode`, `locationId` | Yes | +| `content.revealed` | a content item is revealed | `contentId`, `languageCode`, `locationId` | Yes | +| `content.copied` | a content item is copied; identifiers refer to the copy | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `content.metadata_updated` | content metadata, such as the owner, main language, or publication date, is updated | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `trash.trashed` | a location is sent to trash | `contentId`, `languageCode`, `locationId` | Yes | +| `trash.recovered` | an item is restored from trash | `contentId`, `languageCode`, `locationId` | Yes | +| `trash.emptied` | the trash is emptied | none | No | +| `location.created` | a location is created | `contentId`, `languageCode`, `locationId` | Yes | +| `location.moved` | a subtree is moved | `contentId`, `languageCode`, `locationId` | Yes | +| `location.deleted` | a location is deleted | `contentId`, `languageCode`, `locationId` | Yes | +| `location.hidden` | a location is hidden | `contentId`, `languageCode`, `locationId` | Yes | +| `location.unhidden` | a location is revealed | `contentId`, `languageCode`, `locationId` | Yes | +| `location.swapped` | two locations are swapped | none | No | +| `user.created` | a user is created | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `user.updated` | a user is updated | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `user.deleted` | a user is deleted | `contentId`, `languageCode`, `locationId`, `versionNo`, `languageCodes` | Yes | +| `section.assigned` | a section is assigned to a content item; the section filter matches the newly assigned section | `contentId`, `languageCode`, `locationId` | Yes | +| `object_state.set` | an object state is set on a content item | `contentId`, `languageCode`, `locationId`, `objectStateId`, `objectStateIdentifier`, `objectStateGroupId`, `objectStateGroupIdentifier` | Yes | + +For `location.*` and `trash.*` events, `locationId` is the ID of the affected location, and the subtree filter is evaluated against that location. +For other events, the subtree filter is evaluated against the main location of the content item. + +`locationId` is omitted if the content item has no main location, for example, for a draft that has never been published. + +To get the list of event types available in your installation, including custom ones, use the `GET /api/ibexa/v2/webhook-event-types` [REST API endpoint](webhooks_api.md#rest-api). + +## Test deliveries + +A test delivery, sent from the back office or with the [REST API](webhooks_api.md#rest-api), uses the first event type that the webhook subscribes to, and the user who requested the test as the actor. +Its `identifiers` and `links` objects are empty: + +``` json +{ + "id": "0198f0c2-6b1e-7c3a-9d4e-1f2a3b4c5d6e", + "event": "content.published", + "occurredAt": "2026-08-28T10:20:00+00:00", + "actor": { + "id": 14, + "type": "user" + }, + "identifiers": {}, + "links": {} +} +``` + +Make sure that your receiver accepts such requests, for example, by responding with `204 No Content` without processing them. + +## Re-sent deliveries + +When a delivery is re-sent, a new delivery with a new ID is created, but it reuses the original envelope. +As a result: + +- the `X-Cohesivo-Delivery` header contains the ID of the new delivery +- the `id`, `occurredAt`, and `actor` properties of the envelope keep their original values +- the `X-Cohesivo-Timestamp` header and the signature are computed when the request is sent + +Use the envelope `id` as an idempotency key to avoid processing the same event twice. + +## Signature verification + +### How the signature is computed + +The signature is an HMAC of the timestamp and the raw request body, joined with a dot, like illustrated in this pseudocode: + +``` text +HMAC(algo, secret, timestamp + "." + rawBody) +``` + +Where: + +- `HMAC` is the hashing function (like [`hash_hmac` in PHP](https://www.php.net/manual/en/function.hash-hmac.php), [`crypto.createHmac` in Node.js](https://nodejs.org/api/crypto.html#cryptocreatehmacalgorithm-key-options)) +- `algo` is the name of the hashing algorithm (like, for example, the SHA-256 `"sha256"`) as `X-Cohesivo-Signature` header value prefix +- `secret` is the signing secret of the webhook, displayed once after the webhook is created or its secret is regenerated +- `timestamp` is the value of the `X-Cohesivo-Timestamp` header +- `rawBody` is the request body exactly as received, before any JSON parsing + +The hex-encoded digest is sent in the `X-Cohesivo-Signature` header, prefixed with the name of the algorithm, for example, `sha256=a3f5…`. + +To verify a request: + +1. Read the timestamp header and reject the request if the timestamp is too old. +1. Compute the HMAC of `.` with the signing secret. +1. Compare the result with the digest from the signature header, using a constant-time comparison function. + +!!! caution "Use the raw body" + + Compute the signature over the raw body. + If you decode and re-encode the JSON before verification, the bytes might differ, for example, in whitespace or character escaping, and the verification fails. + +### Verify signature in PHP + +``` php + $maxAgeSeconds) { + return false; + } + + if (!str_contains($signatureHeader, '=')) { + return false; + } + [$algo, $expected] = explode('=', $signatureHeader, 2); + + $computed = hash_hmac($algo, $timestamp . '.' . $rawBody, $secret); + + return hash_equals($computed, $expected); +} +``` + +The following example shows how to use the function in a Symfony controller: + +``` php +$isValid = verifyWebhookSignature( + $request->getContent(), + (string) $request->headers->get('X-Cohesivo-Signature'), + (string) $request->headers->get('X-Cohesivo-Timestamp'), + $webhookSecret, +); + +use Symfony\Component\HttpFoundation\Response; + +if (!$isValid) { + return new Response('Invalid signature', Response::HTTP_FORBIDDEN); +} + +$payload = json_decode($request->getContent(), true, flags: JSON_THROW_ON_ERROR); +``` + +### Verify signature in Node.js + +``` js +const crypto = require('crypto'); + +function verifyWebhookSignature(rawBody, headers, secret, maxAgeSeconds = 300) { + const signatureHeader = headers['x-cohesivo-signature'] ?? ''; + const timestamp = parseInt(headers['x-cohesivo-timestamp'] ?? '0', 10); + + // Replay protection + if (Math.abs(Date.now() / 1000 - timestamp) > maxAgeSeconds) { + return false; + } + + const separator = signatureHeader.indexOf('='); + if (separator === -1) { + return false; + } + + const algo = signatureHeader.slice(0, separator); + const expected = Buffer.from(signatureHeader.slice(separator + 1)); + const computed = Buffer.from( + crypto.createHmac(algo, secret).update(`${timestamp}.${rawBody}`).digest('hex') + ); + + return computed.length === expected.length && crypto.timingSafeEqual(computed, expected); +} +``` + +### Replay protection + +The `X-Cohesivo-Timestamp` header allows the receiver to reject requests that were captured and sent again by an attacker. +The examples above reject requests whose timestamp differs from the current time by more than 300 seconds. +Keep the clocks of the receiving servers synchronized, and avoid tolerance windows longer than 600 seconds. + +## Best practices for receivers + +- Respond with a `2xx` status code as soon as you've verified and stored the request, and process it in the background. +Requests that take longer than the [configured timeout](configure_webhooks.md#configuration-reference) are considered failed. +- Make processing idempotent. +Because of retries and re-sending, the same event can be delivered more than once. +Use the envelope `id` to detect duplicates. +- Don't rely on the order of deliveries. +Retries can cause events to arrive in a different order than the one in which they occurred. +Use `occurredAt`, or fetch the current state of the object from the REST API. +- Use HTTPS payload URLs, so that payloads aren't transmitted in plain text. diff --git a/docs/api/webhooks/webhooks.md b/docs/api/webhooks/webhooks.md new file mode 100644 index 0000000000..6d62f50389 --- /dev/null +++ b/docs/api/webhooks/webhooks.md @@ -0,0 +1,33 @@ +--- +description: Webhooks push repository events to external systems as signed HTTP requests. +page_type: landing_page +month_change: false +--- + +# Webhooks + +Webhooks let [[= product_name =]] notify external systems about changes in the repository as soon as they happen. +When an editor publishes, moves, hides, or deletes content, [[= product_name =]] sends an HTTP `POST` request with a signed JSON payload to every webhook subscribed to that event. + +Administrators manage webhooks in the back office or through the REST API. +For each webhook, they select the events to subscribe to and can narrow them down to specific content types, sections, or subtrees. + +Deliveries are processed asynchronously, retried on failure, and recorded in a delivery log, so that you can inspect, test, and re-send them at any time. + +## Getting started + +[[= cards([ +"api/webhooks/webhooks_guide", +"api/webhooks/configure_webhooks", +("permissions/policies#webhooks", "Policies", "Learn about the available Webhook policies"), +("https://doc.ibexa.co/projects/userguide/en/5.0/webhooks/work_with_webhooks/", "Work with webhooks", "Learn how to manage webhooks in the back office."), +], columns=2) =]] + +## Development + +[[= cards([ +"api/webhooks/webhook_payload_reference", +"api/webhooks/webhooks_api", +("https://doc.ibexa.co/en/5.0/api/rest_api/rest_api_reference/rest_api_reference.html#tag/Webhooks", "REST API Reference", "See the available endpoints for Webhooks"), +"api/webhooks/extend_webhooks", +], columns=4) =]] diff --git a/docs/api/webhooks/webhooks_api.md b/docs/api/webhooks/webhooks_api.md new file mode 100644 index 0000000000..2ab5944f76 --- /dev/null +++ b/docs/api/webhooks/webhooks_api.md @@ -0,0 +1,241 @@ +--- +description: Manage webhooks and their delivery log with the PHP API and the REST API. +month_change: false +--- + +# Webhooks API + +You can manage webhooks, browse their delivery log, send test deliveries, and re-send deliveries with the [PHP API](#php-api) and the [REST API](#rest-api). +Both APIs check the [`webhook` policies](policies.md#webhooks) of the current user. + +!!! note + + This page is about webhooks management. + To create a new webhook event type, see [Extend webhooks](extend_webhooks.md). + +## PHP API + +### Manage webhooks + +To manage webhooks, use the [`WebhookServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Service-WebhookServiceInterface.html) service. + +The following methods are available: + +| Method | Required policy | Description | +|---|---|---| +| `createWebhook(WebhookCreateStruct $struct): Webhook` | `webhook/create` | Creates a webhook owned by the current user and generates its signing secret. | +| `loadWebhook(int $id): Webhook` | `webhook/read` | Loads a webhook by its ID. | +| `loadWebhooks(?int $limit = null, int $offset = 0): array` | `webhook/read` | Loads a list of webhooks. | +| `countWebhooks(): int` | `webhook/read` | Returns the number of webhooks. | +| `updateWebhook(int $id, WebhookUpdateStruct $struct): Webhook` | `webhook/update` | Updates a webhook. Properties set to `null` remain unchanged. | +| `deleteWebhook(int $id): void` | `webhook/delete` | Deletes a webhook together with its delivery log. | +| `regenerateSecret(int $id): Webhook` | `webhook/update` | Generates a new signing secret. The previous secret stops working immediately. | + +When you create or update a webhook, the service validates that: + +- the URL is an absolute URL with the `http` or `https` scheme +- the webhook subscribes to at least one event type + +If validation fails, the service throws an `InvalidWebhookException`. + +The following example creates a webhook that notifies an external system when articles in a specific subtree are published or deleted: + +``` php +use Ibexa\Contracts\Webhooks\Service\WebhookServiceInterface; +use Ibexa\Contracts\Webhooks\Value\WebhookCreateStruct; +use Ibexa\Contracts\Webhooks\Value\WebhookFilters; + +$createStruct = new WebhookCreateStruct(); +$createStruct->name = 'CRM integration'; +$createStruct->url = 'https://crm.example.com/hooks/ibexa'; +$createStruct->eventTypes = ['content.published', 'content.deleted']; +$createStruct->filters = new WebhookFilters( + contentTypeIdentifiers: ['article'], + sectionIds: [1], + subtreePathStrings: ['/1/2/'], +); + +$webhook = $this->webhookService->createWebhook($createStruct); +``` + +To disable a webhook, update its `enabled` property: + +``` php +use Ibexa\Contracts\Webhooks\Value\WebhookUpdateStruct; + +$updateStruct = new WebhookUpdateStruct(); +$updateStruct->enabled = false; + +$this->webhookService->updateWebhook($webhook->id, $updateStruct); +``` + +!!! note "Signing secret" + + The `Webhook::$secret` property contains the signing secret in its encrypted form. + To share the plaintext secret with the receiving system, decrypt it with the `SecretEncrypterInterface` service right after you create the webhook or regenerate its secret. + +### Value objects + +| Class | Description | +|---|---| +| [`Webhook`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-Webhook.html) | Read-only representation of a webhook: `id`, `name`, `url`, `secret` (encrypted), `enabled`, `eventTypes`, `filters`, `ownerId`, `consecutiveFailures`, `disabledReason`, `disabledAt`, `createdAt`, `modifiedAt`. | +| [`WebhookCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookCreateStruct.html) | Data of a new webhook: `name`, `url`, `enabled` (default `true`), `eventTypes`, `filters`. | +| [`WebhookUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookUpdateStruct.html) | Changes to a webhook. Properties set to `null` remain unchanged. | +| [`WebhookFilters`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookFilters.html) | Filters of a webhook: `contentTypeIdentifiers`, `sectionIds`, `subtreePathStrings`. | +| [`WebhookDelivery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-WebhookDelivery.html) | Entry of the delivery log: `id`, `webhookId`, `eventType`, `status`, `attempt`, `responseCode`, `durationMs`, `error`, `requestPayload`, `isTest`, `createdAt`, `deliveredAt`. | +| [`DeliveryStatus`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Value-DeliveryStatus.html) | Enumeration of delivery statuses: `Pending`, `Success`, `Failed`, `Skipped`. | + +`WebhookDelivery::$attempt` is the number of failed attempts made so far, and `WebhookDelivery::$requestPayload` contains the JSON envelope exactly as it's sent in the request body. +For more information about the envelope, see [Webhook payload reference](webhook_payload_reference.md#envelope). + +### Browse the delivery log + +| Method | Required policy | Description | +|---|---|---| +| `loadDeliveries(int $webhookId, ?int $limit = null, int $offset = 0, ?string $status = null): array` | `webhook/read` | Loads deliveries of a webhook, newest first, optionally limited to the given status. | +| `countDeliveries(int $webhookId, ?string $status = null): int` | `webhook/read` | Returns the number of deliveries of a webhook. | +| `loadDelivery(string $id, ?int $webhookId = null): WebhookDelivery` | `webhook/read` | Loads a delivery by its ID. If you pass a webhook ID, the delivery must belong to that webhook. | + +The following example loads the 10 most recent failed deliveries of a webhook: + +``` php +use Ibexa\Contracts\Webhooks\Value\DeliveryStatus; + +$failedDeliveries = $this->webhookService->loadDeliveries( + $webhook->id, + limit: 10, + status: DeliveryStatus::Failed->value, +); +``` + +### Send test deliveries + +`sendTest(int $id): WebhookDelivery` queues a [test delivery](webhook_payload_reference.md#test-deliveries) and returns it with the `pending` status. +It requires the `webhook/test` policy. + +### Re-send deliveries + +`resendDelivery(string $deliveryId, ?int $webhookId = null): WebhookDelivery` creates a new delivery with the payload of the original one, queues it, and returns it with the `pending` status. +It requires the `webhook/update` policy. +For more information, see [Re-sent deliveries](webhook_payload_reference.md#re-sent-deliveries). + +### Event types + +To list the event types that webhooks can subscribe to, use the [`WebhookEventTypeRegistryInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Webhooks-Event-WebhookEventTypeRegistryInterface.html) service: + +| Method | Description | +|---|---| +| `allByGroup(): array` | Returns all event types, grouped by their group name. | +| `getByIdentifier(string $identifier): WebhookEventType` | Returns the event type with the given identifier, for example, `content.published`. | +| `getByEventClass(string $eventClass): WebhookEventType` | Returns the event type mapped to the given repository event class. | +| `has(string $eventClass): bool` | Checks whether an event type is mapped to the given repository event class. | + +### Exceptions + +| Exception | Thrown when | +|---|---| +| `InvalidWebhookException` | the URL or the event types of a webhook are invalid, or a test is requested for a webhook without event types | +| `WebhookNotFoundException` | a webhook with the given ID doesn't exist | +| `DeliveryNotFoundException` | a delivery with the given ID doesn't exist or doesn't belong to the given webhook | +| `WebhookEventTypeNotFoundException` | an event type with the given identifier or event class doesn't exist | +| `UnauthorizedException` | the current user doesn't have the required policy | + +All webhook-specific exceptions are placed in the `Ibexa\Contracts\Webhooks\Exception` namespace. + +## REST API + +The REST API exposes the following endpoints. +For details, including request and response schemas, see the [REST API reference](/api/rest_api/rest_api_reference/rest_api_reference.html#tag/Webhooks). + +| Method | Endpoint | Description | Required policy | +|---|---|---|---| +| `GET` | `/webhooks` | List webhooks. Supports the `offset` and `limit` query parameters. | `webhook/read` | +| `POST` | `/webhooks` | Create a webhook. | `webhook/create` | +| `GET` | `/webhooks/{webhookId}` | Load a webhook. | `webhook/read` | +| `PATCH` | `/webhooks/{webhookId}` | Update a webhook. Only the properties included in the request are changed. | `webhook/update` | +| `DELETE` | `/webhooks/{webhookId}` | Delete a webhook together with its delivery log. | `webhook/delete` | +| `POST` | `/webhooks/{webhookId}/test` | Send a test delivery. Returns `202 Accepted`. | `webhook/test` | +| `GET` | `/webhooks/{webhookId}/deliveries` | List deliveries, newest first. Supports the `offset`, `limit`, and `status` query parameters. | `webhook/read` | +| `GET` | `/webhooks/{webhookId}/deliveries/{deliveryId}` | Load a delivery. | `webhook/read` | +| `POST` | `/webhooks/{webhookId}/deliveries/{deliveryId}/resend` | Re-send a delivery. Returns `202 Accepted`. | `webhook/update` | +| `GET` | `/webhook-event-types` | List the available event types, grouped. | `webhook/read` | + +All endpoints are relative to the REST API prefix, by default `/api/ibexa/v2`. +Requests that modify data require the `X-CSRF-Token` header when you use [session authentication](rest_api_authentication.md#session-based-authentication). + +### Create webhook + +To create a webhook, send a `POST` request with the `application/vnd.ibexa.api.WebhookCreate+json` content type: + +``` bash +curl -X POST https:///api/ibexa/v2/webhooks \ + -H 'Content-Type: application/vnd.ibexa.api.WebhookCreate+json' \ + -H 'Accept: application/vnd.ibexa.api.Webhook+json' \ + -H 'X-CSRF-Token: ' \ + --cookie '' \ + -d '{ + "WebhookCreate": { + "name": "CRM integration", + "url": "https://crm.example.com/hooks/ibexa", + "enabled": true, + "eventTypes": ["content.published", "content.deleted"], + "filters": { + "contentTypeIdentifiers": ["article"], + "sectionIds": [1], + "subtreePathStrings": ["/1/2/"] + } + } + }' +``` + +`name` and `url` are required. +`enabled` defaults to `true`, and `filters` defaults to no filters. + +The `201 Created` response contains the created webhook, including the plaintext signing secret in the `secret` property: + +``` json +{ + "Webhook": { + "_media-type": "application/vnd.ibexa.api.Webhook+json", + "_href": "/api/ibexa/v2/webhooks/1", + "id": 1, + "name": "CRM integration", + "url": "https://crm.example.com/hooks/ibexa", + "secret": "4a486cdd6b0c3136f2305e3dc7fbaff06996dcc73c1f24eb7944890474731e17", + "enabled": true, + "eventTypes": ["content.published", "content.deleted"], + "filters": { + "contentTypeIdentifiers": ["article"], + "sectionIds": [1], + "subtreePathStrings": ["/1/2/"] + }, + "ownerId": 14, + "consecutiveFailures": 0, + "disabledReason": null, + "disabledAt": null, + "createdAt": "2026-08-28T10:15:30+00:00", + "modifiedAt": "2026-08-28T10:15:30+00:00" + } +} +``` + +!!! caution "Store the signing secret" + + The signing secret is returned only in the response to the `POST /webhooks` request. + No other endpoint returns it. + If you lose it, regenerate it in the back office. + +### Update webhook + +To update a webhook, send a `PATCH` request with the `application/vnd.ibexa.api.WebhookUpdate+json` content type and only the properties that you want to change: + +``` json +{ + "WebhookUpdate": { + "name": "CRM integration (staging)", + "enabled": false + } +} +``` + +When you include `filters`, the whole filter set is replaced, and filter lists that you omit are cleared. diff --git a/docs/api/webhooks/webhooks_guide.md b/docs/api/webhooks/webhooks_guide.md new file mode 100644 index 0000000000..377c30af4c --- /dev/null +++ b/docs/api/webhooks/webhooks_guide.md @@ -0,0 +1,152 @@ +--- +description: The Webhooks product guide provides a full description of the features and benefits that this module brings to the clients. +month_change: false +--- + +# Webhooks product guide + +## What are webhooks + +A webhook is an HTTP callback: a request that [[= product_name =]] sends to an external URL when something happens in the repository. +Instead of polling the REST API to find out whether content has changed, external systems, such as a CRM, a search index, a static site generator, a CDN, or an automation platform, receive a notification the moment a change happens. + +Each notification is a small JSON document that describes the event, the user who triggered it, and the identifiers of the affected content. +The receiving system can then fetch any additional data it needs through the [REST API](rest_api_usage.md), using the links included in the notification. + +## Availability + +Webhooks are available in all [[= product_name =]] editions. +The feature is delivered as the `ibexa/webhooks` package and requires [installation and configuration](configure_webhooks.md) before you can use it. + +## How do webhooks work + +### Webhook + +A webhook is a subscription that consists of: + +- a name, which helps administrators recognize the webhook +- a payload URL, an absolute `http://` or `https://` address of the receiving endpoint +- one or more event types that the webhook subscribes to +- optional filters that narrow down the events +- a signing secret, generated by the system, used to sign every request +- a status: enabled or disabled + +The user who creates the webhook becomes its owner and receives a notification if the webhook is disabled automatically. + +You can manage webhooks [in the back office]([[= user_doc =]]/webhooks/work_with_webhooks/), through the [REST API](webhooks_api.md#rest-api), or with the [PHP API](webhooks_api.md#php-api). +Access to all these operations is controlled by the [`webhook` policies](policies.md#webhooks). + +### Event types + +Out of the box, webhooks can subscribe to 21 repository events, grouped as follows: + +| Group | Event types | +|---|---| +| Content | `content.published`, `content.created`, `content.deleted`, `content.hidden`, `content.revealed`, `content.copied`, `content.metadata_updated` | +| Trash | `trash.trashed`, `trash.recovered`, `trash.emptied` | +| Location | `location.created`, `location.moved`, `location.deleted`, `location.hidden`, `location.unhidden`, `location.swapped` | +| User | `user.created`, `user.updated`, `user.deleted` | +| Section | `section.assigned` | +| Object state | `object_state.set` | + +For a description of each event and the data it carries, see [Webhook payload reference](webhook_payload_reference.md#event-types). + +Developers can add their own event types, for example, to react to events coming from custom code. +For more information, see [Extend webhooks](extend_webhooks.md). + +### Filters + +By default, a webhook receives every occurrence of the events it subscribes to. +You can narrow this down with the following filters: + +- **Content types** - only events that concern content of the selected content types +- **Sections** - only events that concern content assigned to the selected sections +- **Subtrees** - only events that concern content located in the selected subtrees + +All filters that you set must match for an event to be delivered. +Within a single filter, matching any of the selected values is enough. +An empty filter matches all events. + +For example, a webhook with the "Article" and "Blog post" content types and the "Media" subtree selected receives events only for articles and blog posts that are located under "Media". + +!!! note "Events without content context" + + The `location.swapped` and `trash.emptied` events don't concern a single content item, so filters can't be evaluated against them. + A webhook subscribed to one of these events receives every occurrence, regardless of its filters. + +### Delivery + +When a subscribed event occurs, [[= product_name =]] creates a delivery: it builds the JSON payload, stores it in the delivery log, and places it in a dedicated message queue. +A background worker picks up the delivery and sends it to the payload URL. + +Every request is signed with an HMAC signature computed from the webhook's signing secret, so that the receiver can verify that the request comes from [[= product_name =]] and wasn't modified on the way. +A timestamp header allows the receiver to reject replayed requests. +For more information, see [Webhook payload reference](webhook_payload_reference.md#signature-verification). + +A delivery succeeds when the receiver responds with any `2xx` HTTP status code within the configured timeout. +A failed delivery is retried automatically, with an increasing delay between attempts. + +Capturing events never interferes with editorial work: if anything goes wrong while matching webhooks or queuing deliveries, the error is logged and the original repository operation completes normally. + +### Delivery log + +Every delivery is recorded together with its status, number of attempts, HTTP response code, duration, error message, and the exact payload that was sent. +A delivery can have one of the following statuses: + +| Status | Description | +|---|---| +| Pending | The delivery is queued and waits for the worker. | +| Success | The receiver responded with a `2xx` status code. | +| Failed | The last attempt failed. If retries remain, the delivery is attempted again. | +| Skipped | The webhook was disabled before the delivery was sent. | + +From the delivery log, administrators can view the payload of each delivery and re-send it, for example, after an outage of the receiving system has been fixed. +They can also send a test delivery to check whether the receiving endpoint is reachable and verifies signatures correctly. + +Delivery log entries are removed automatically after a configurable [retention period](configure_webhooks.md#delivery-log-retention). + +### Automatic disabling + +If deliveries to a webhook keep failing, for example, because the receiving system has been decommissioned, the webhook is disabled automatically after a configurable number of consecutive failures. +The owner of the webhook receives a back office [notification](notifications.md) with a link to the webhook. + +A successful delivery resets the failure counter. +Once the problem is fixed, an administrator can enable the webhook again. + +## Capabilities + +### Management in the back office + +Administrators can create, edit, enable, disable, test, and remove webhooks in the **Admin** section of the back office, and browse the delivery log of each webhook. + +### REST API + +All management operations, including the delivery log, test deliveries, and re-sending, are available in the REST API, which makes it possible to automate the setup of integrations, for example, as part of a deployment. + +### Secure by default + +Signing secrets are generated by the system, encrypted at rest, and displayed only once, right after they are created or regenerated. +Every request carries an HMAC signature and a timestamp. + +### Extensibility + +Developers can add new event types with a single service definition, and control the data included in the payload by providing their own extractors. + +## Benefits + +### Real-time integrations + +External systems learn about changes the moment they happen, instead of polling the repository on a schedule. +Search indexes, caches, and downstream channels stay up-to-date without delay. + +### Less custom code + +Integrations that would otherwise require custom event subscribers and HTTP clients can be configured in the back office by an administrator, without a deployment. + +### Reliability + +Asynchronous delivery, automatic retries, and a complete delivery log with re-sending make sure that no change is lost when the receiving system is temporarily unavailable. + +### Transparency + +The delivery log shows exactly what was sent, when, and with what result, which makes troubleshooting integrations fast and straightforward. diff --git a/docs/permissions/policies.md b/docs/permissions/policies.md index 4436bb1537..a4d0cc1411 100644 --- a/docs/permissions/policies.md +++ b/docs/permissions/policies.md @@ -281,6 +281,16 @@ The [discount](discounts.md) policies decide which actions can be executed by gi | `comparison` | `view` | view version comparison | | | `workflow` | `change_stage` | change stage in the specified workflow | [Workflow Transition](limitation_reference.md#workflow-transition-limitation) | +#### Webhooks + +| Module | Function | Effect | Possible limitations | +|------------------------|-----------------------|-----------------------------------------------------------------------------------------------------------|----------------------| +| `webhook` | `create` | create [webhooks](webhooks_guide.md) | | +| | `delete` | delete webhooks together with their delivery log | | +| | `read` | view the **Webhooks** item in the **Admin** menu, the webhook list, webhook details, and the delivery log | | +| | `test` | send test deliveries | | +| | `update` | edit, enable, and disable webhooks, regenerate signing secrets, and re-send deliveries | | + ### Product catalog #### Catalogs diff --git a/docs/release_notes/ibexa_dxp_v5.0.md b/docs/release_notes/ibexa_dxp_v5.0.md index 703ea28ad2..095066bdf5 100644 --- a/docs/release_notes/ibexa_dxp_v5.0.md +++ b/docs/release_notes/ibexa_dxp_v5.0.md @@ -10,6 +10,19 @@ month_change: false
+[[% set version = 'v5.0.12' %]] +[[% set date = '2026-12-TODO' %]] + +[[= release_note_entry_begin( + 'Webhooks ' + version, + date, + ['Headless', 'Experience', 'Commerce', 'LTS Update', 'New feature', 'First release'] +) =]] + +[Webhooks](webhooks_guide.md) allow to send notifications to external systems when some selected repository events occur. + +[[= release_note_entry_end() =]] + [[% set version = 'v5.0.11' %]] [[% set date = '2026-10-27' %]] diff --git a/mkdocs.yml b/mkdocs.yml index db7c787f80..fa61f26c0e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -112,6 +112,13 @@ nav: - Integrated help events: api/event_reference/integrated_help_events.md - Translations management events: api/event_reference/translations_management_events.md - Other events: api/event_reference/other_events.md + - Webhooks: + - Webhooks: api/webhooks/webhooks.md + - Webhooks guide: api/webhooks/webhooks_guide.md + - Configure webhooks: api/webhooks/configure_webhooks.md + - Webhook payload reference: api/webhooks/webhook_payload_reference.md + - Webhooks API: api/webhooks/webhooks_api.md + - Extend webhooks: api/webhooks/extend_webhooks.md - Notification channels: api/notification_channels.md - Administration: - Administration: administration/administration.md diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e5d912b591..6985ea5dd6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -18,6 +18,66 @@ parameters: count: 1 path: code_samples/_inline_php/api/rest_api/extending_rest_api/creating_new_rest_resource/6886002ea53abecb63d61d585bc055fc9df36a19db675e286408a52f40aa794c.php + - + message: '#^Class App\\Event\\ProductPublishedEvent not found\.$#' + identifier: class.notFound + count: 1 + path: code_samples/_inline_php/api/webhooks/extend_webhooks/002faa2fe4a3bdba7acb6f3ace3a43570ebb6abf955f4c1019cc2fccf8fb8bec.php + + - + message: '#^Call to method getProduct\(\) on an unknown class App\\Event\\ProductPublishedEvent\.$#' + identifier: class.notFound + count: 1 + path: code_samples/_inline_php/api/webhooks/extend_webhooks/ce1fba13f8c464ba17085cf61110a9888e3845c056515463607589f2fa98608e.php + + - + message: '#^Class App\\Event\\ProductPublishedEvent not found\.$#' + identifier: class.notFound + count: 1 + path: code_samples/_inline_php/api/webhooks/extend_webhooks/ce1fba13f8c464ba17085cf61110a9888e3845c056515463607589f2fa98608e.php + + - + message: '#^Variable \$request might not be defined\.$#' + identifier: variable.undefined + count: 4 + path: code_samples/_inline_php/api/webhooks/webhook_payload_reference/103f47a095598317324e4634f9675eb1ef22e49784e857c76e1446b66fecc1b1.php + + - + message: '#^Variable \$webhookSecret might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: code_samples/_inline_php/api/webhooks/webhook_payload_reference/103f47a095598317324e4634f9675eb1ef22e49784e857c76e1446b66fecc1b1.php + + - + message: '#^Variable \$this might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: code_samples/_inline_php/api/webhooks/webhooks_api/1ea563955f67fec5ab163e4d637796ae6a3cf45c821efd777e53a733213215f8.php + + - + message: '#^Variable \$webhook might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: code_samples/_inline_php/api/webhooks/webhooks_api/1ea563955f67fec5ab163e4d637796ae6a3cf45c821efd777e53a733213215f8.php + + - + message: '#^Variable \$this might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: code_samples/_inline_php/api/webhooks/webhooks_api/4041313598fb31745c7c97cf1f3facdcc342fc9a2dc40362c3e0e569ec3a6cde.php + + - + message: '#^Variable \$this might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: code_samples/_inline_php/api/webhooks/webhooks_api/78a335c85470797fd6cacae43e46bcea8a9b5517fffeeeb9210302d83d256aad.php + + - + message: '#^Variable \$webhook might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: code_samples/_inline_php/api/webhooks/webhooks_api/78a335c85470797fd6cacae43e46bcea8a9b5517fffeeeb9210302d83d256aad.php + - message: '#^Call to an undefined method Symfony\\Component\\Notifier\\Recipient\\RecipientInterface\:\:getUser\(\)\.$#' identifier: method.notFound @@ -791,4 +851,3 @@ parameters: identifier: argument.type count: 1 path: code_samples/workflow/custom_workflow/src/EventListener/LegalTransitionListener.php - diff --git a/tests/yaml-validation-baseline.yaml b/tests/yaml-validation-baseline.yaml index 444a0b440a..27aae45bf5 100644 --- a/tests/yaml-validation-baseline.yaml +++ b/tests/yaml-validation-baseline.yaml @@ -32,6 +32,16 @@ ignoreErrors: line: 26 hash: 4cfc5ac559eb8db38edb6c8a29872883a95886b61cdae2b343a5ebaf4a9bca8e message: '~The value "\" is not allowed for path "ibexa\.system\.\\>\.product_tour\.\\.type"\. Permissible values\: "general", "targetable"\.~' + - + path: docs/api/webhooks/configure_webhooks.md + line: 102 + hash: b332cf6a427847edca58a7f2061af275f6d0fe0f381e4835d85d58348af72600 + message: '~The child config "secret_key" under "ibexa_webhooks" must be configured\: Raw 32\-byte key used to encrypt webhook secrets at rest\. Keep the base64\-encoded key outside the config tree and reference it with ''%env\(base64\:WEBHOOK_SECRET_KEY\)%''\. Generate one with base64_encode\(sodium_crypto_secretbox_keygen\(\)\)\.~' + - + path: docs/api/webhooks/configure_webhooks.md + line: 110 + hash: cd1cde6282b5bbb7d2fe03f25018ef873189c269c86be41924f6755e3c421932 + message: '~The child config "secret_key" under "ibexa_webhooks" must be configured\: Raw 32\-byte key used to encrypt webhook secrets at rest\. Keep the base64\-encoded key outside the config tree and reference it with ''%env\(base64\:WEBHOOK_SECRET_KEY\)%''\. Generate one with base64_encode\(sodium_crypto_secretbox_keygen\(\)\)\.~' - path: docs/cdp/cdp_data_customization.md line: 29 diff --git a/tools/api_refs/api_refs.sh b/tools/api_refs/api_refs.sh index 7899fbc48a..7d37880fd7 100755 --- a/tools/api_refs/api_refs.sh +++ b/tools/api_refs/api_refs.sh @@ -11,7 +11,7 @@ REST_API_OPENAPI_FILE_JSON=${5:-./docs/api/rest_api/rest_api_reference/openapi.j DXP_EDITION='commerce'; # Edition from and for which the Reference is built DXP_VERSION="${DXP_VERSION:-5.0.*}"; # Version from and for which the Reference is built; can be overridden by the DXP_VERSION env var (e.g. v5.0.x-dev for a dev build) -DXP_ADD_ONS=(automated-translation rector integrated-help fieldtype-richtext-rte connector-anthropic connector-gemini shopping-list cdp connector-raptor connector-quable mcp translations-management); # Packages not included in $DXP_EDITION but added to the Reference, listed without their vendor "ibexa" +DXP_ADD_ONS=(automated-translation rector integrated-help fieldtype-richtext-rte connector-anthropic connector-gemini shopping-list cdp connector-raptor connector-quable mcp translations-management webhooks); # Packages not included in $DXP_EDITION but added to the Reference, listed without their vendor "ibexa" DXP_EDITIONS=(oss headless experience commerce); # Available editions ordered by ascending capabilities SF_VERSION='7.4'; # Symfony version used by Ibexa DXP PHPDOC_VERSION='3.10.0'; # Version of phpDocumentor used to build the Reference @@ -229,6 +229,7 @@ if [ 0 -eq $DXP_ALREADY_EXISTS ]; then fi; echo 'Dump REST OpenAPI schema… '; +grep -q 'ApiPlatformBundle' config/bundles.php || perl -pi -e 's/^return \[$/return [\n ApiPlatform\\Symfony\\Bundle\\ApiPlatformBundle::class => [\x27all\x27 => true],/' config/bundles.php $PHP_BINARY bin/console ibexa:openapi --yaml \ | sed "s@info:@info:\n x-logo:\n url: 'https://doc.ibexa.co/en/latest/images/ibexa-dxp-logo.png'@" \ > openapi.yaml;