diff --git a/src/Id/Webhooks/EventType.php b/src/Id/Webhooks/EventType.php index a1c31a8..4806bf0 100644 --- a/src/Id/Webhooks/EventType.php +++ b/src/Id/Webhooks/EventType.php @@ -76,6 +76,34 @@ final class EventType */ public const BILLING_LIMIT_AVAILABLE = 'billing_limit.available'; + /** + * A preference of a user was set, changed or deleted. Thin, never the value: `data.object` is + * `{object: "preference", user_id, namespace, key, version, deleted, updated_at, updated_by: + * {type: "user"|"app", client_id}}`; fetch the preference again (or drop your copy when + * `deleted`) and ignore events with a lower version than the one you hold. Opt-in (not through + * `*`); only to trusted apps that may read the namespace, never to the app that made the change. + */ + public const PREFERENCE_UPDATED = 'preference.updated'; + + /** + * The profile of a user connected to your app changed: name, username, the verified email + * address, email_verified or the avatar. `data.object` is the full profile `{object: "user", id, + * name, username, email, email_verified, avatar, version}` (Resources\User), `data.changed` names + * the changed fields (never their old values). An email address appears only once verified + * (`email` is null while it isn't); `avatar` in `changed` means the picture behind the stable URL + * changed. Keep the highest `version` and ignore older events. Opt-in (not through `*`); also + * sent to the app that made the change. + */ + public const USER_UPDATED = 'user.updated'; + + /** + * A user connected to your app deleted their account (or it was deleted): delete or anonymise + * it and treat it as final. `data.object` is `{object: "user", id, deleted: true, deleted_at}`. + * Sent once; no other event about the user follows. A later user.updated for the same ID means + * the account was restored. Opt-in (not through `*`). + */ + public const USER_DELETED = 'user.deleted'; + public const TEST = 'webhook.test'; /** diff --git a/tests/Id/WebhookTest.php b/tests/Id/WebhookTest.php index 2c8b984..47657a4 100644 --- a/tests/Id/WebhookTest.php +++ b/tests/Id/WebhookTest.php @@ -84,6 +84,16 @@ class WebhookTest extends TestCase $this->assertContains(EventType::BILLING_LIMIT_AVAILABLE, EventType::all()); } + public function test_user_and_preference_events_have_their_own_types(): void + { + $this->assertSame('preference.updated', EventType::PREFERENCE_UPDATED); + $this->assertSame('user.updated', EventType::USER_UPDATED); + $this->assertSame('user.deleted', EventType::USER_DELETED); + $this->assertContains(EventType::PREFERENCE_UPDATED, EventType::all()); + $this->assertContains(EventType::USER_UPDATED, EventType::all()); + $this->assertContains(EventType::USER_DELETED, EventType::all()); + } + public function test_a_change_carries_the_previous_attributes(): void { $this->payload = json_encode(['id' => '01JEVT', 'type' => EventType::SUBSCRIPTION_UPDATED, 'created' => time(), 'data' => [