From d79be3a6e354948214a23f87c83f1afbf07cf3ac Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 6 May 2026 13:44:27 +1200 Subject: [PATCH] feat(notifications): add alert and alertList response models Adds Alert response model and MODEL_ALERT/MODEL_ALERT_LIST constants so future GET /v1/account/alerts endpoint can return MODEL_ALERT_LIST. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/init/models.php | 3 + src/Appwrite/Utopia/Response.php | 4 + src/Appwrite/Utopia/Response/Model/Alert.php | 112 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/Appwrite/Utopia/Response/Model/Alert.php diff --git a/app/init/models.php b/app/init/models.php index 9530b4b98b..ac95448cf0 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -2,6 +2,7 @@ use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Model\Account; +use Appwrite\Utopia\Response\Model\Alert; use Appwrite\Utopia\Response\Model\AlgoArgon2; use Appwrite\Utopia\Response\Model\AlgoBcrypt; use Appwrite\Utopia\Response\Model\AlgoMd5; @@ -237,6 +238,7 @@ Response::setModel(new BaseList('Column Indexes List', Response::MODEL_COLUMN_IN Response::setModel(new BaseList('Users List', Response::MODEL_USER_LIST, 'users', Response::MODEL_USER)); Response::setModel(new BaseList('Sessions List', Response::MODEL_SESSION_LIST, 'sessions', Response::MODEL_SESSION)); Response::setModel(new BaseList('Identities List', Response::MODEL_IDENTITY_LIST, 'identities', Response::MODEL_IDENTITY)); +Response::setModel(new BaseList('Alerts List', Response::MODEL_ALERT_LIST, 'alerts', Response::MODEL_ALERT)); Response::setModel(new BaseList('Logs List', Response::MODEL_LOG_LIST, 'logs', Response::MODEL_LOG)); Response::setModel(new BaseList('Files List', Response::MODEL_FILE_LIST, 'files', Response::MODEL_FILE)); Response::setModel(new BaseList('Buckets List', Response::MODEL_BUCKET_LIST, 'buckets', Response::MODEL_BUCKET)); @@ -362,6 +364,7 @@ Response::setModel(new Account()); Response::setModel(new Preferences()); Response::setModel(new Session()); Response::setModel(new Identity()); +Response::setModel(new Alert()); Response::setModel(new Token()); Response::setModel(new JWT()); Response::setModel(new Locale()); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 899cdc086a..2c8dc3c69b 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -67,6 +67,10 @@ class Response extends SwooleResponse public const MODEL_ROW = 'row'; public const MODEL_ROW_LIST = 'rowList'; + // Alerts + public const MODEL_ALERT = 'alert'; + public const MODEL_ALERT_LIST = 'alertList'; + // Database Attributes public const MODEL_ATTRIBUTE = 'attribute'; public const MODEL_ATTRIBUTE_LIST = 'attributeList'; diff --git a/src/Appwrite/Utopia/Response/Model/Alert.php b/src/Appwrite/Utopia/Response/Model/Alert.php new file mode 100644 index 0000000000..9a9e89e9dd --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Alert.php @@ -0,0 +1,112 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Alert ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$createdAt', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'Alert creation date in ISO 8601 format.', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, + ]) + ->addRule('$updatedAt', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'Alert update date in ISO 8601 format.', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, + ]) + ->addRule('messageId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Stable message ID used for dedup.', + 'default' => '', + 'example' => 'session.create', + 'required' => false, + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Alert type: info, warning, error.', + 'default' => 'info', + 'example' => 'info', + ]) + ->addRule('channel', [ + 'type' => self::TYPE_STRING, + 'description' => 'Channel: email, sms, push, console, webhook.', + 'default' => '', + 'example' => 'email', + ]) + ->addRule('userId', [ + 'type' => self::TYPE_STRING, + 'description' => 'User this alert is addressed to.', + 'default' => '', + 'example' => '5e5bb8c16897e', + 'required' => false, + ]) + ->addRule('teamId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Team this alert is addressed to.', + 'default' => '', + 'example' => '5e5bb8c16897e', + 'required' => false, + ]) + ->addRule('projectId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Project the alert pertains to.', + 'default' => '', + 'example' => '5e5bb8c16897e', + 'required' => false, + ]) + ->addRule('title', [ + 'type' => self::TYPE_STRING, + 'description' => 'Alert title.', + 'default' => '', + 'example' => 'New sign-in detected', + ]) + ->addRule('body', [ + 'type' => self::TYPE_STRING, + 'description' => 'Alert body.', + 'default' => '', + 'example' => 'A new device signed in to your account.', + ]) + ->addRule('read', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the alert has been read.', + 'default' => false, + 'example' => false, + 'required' => false, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Alert'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_ALERT; + } +}