From 89848c21d16bc17463df74eba81dc4bb44bb1f83 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 02:19:35 +0000 Subject: [PATCH 01/12] feat: extract Resource Parser and cap usage labels to resource scope - Add Appwrite\Resource\Parser with render(), parse() and a usage cap helper. Both audit logging (api.php) and the usage label resolver in cloud now share the same template renderer. - Drop usage.resource from routes outside the in-scope resource paths (databases, storage, functions, sites). Audit-style sub-resource hierarchies are unchanged; only usage tagging is narrowed. - Add usage.resource to the resource-scoped read endpoints for databases, tablesdb, documentsdb, vectorsdb, storage, functions and sites that were missing it. --- app/controllers/shared/api.php | 46 +------ .../Account/MFA/Authenticators/Create.php | 1 - .../Account/MFA/Authenticators/Delete.php | 1 - .../Account/MFA/Authenticators/Update.php | 1 - .../Http/Account/MFA/Challenges/Create.php | 1 - .../Http/Account/MFA/Challenges/Update.php | 1 - .../Http/Account/MFA/RecoveryCodes/Create.php | 1 - .../Http/Account/MFA/RecoveryCodes/Update.php | 1 - .../Account/Http/Account/MFA/Update.php | 1 - .../Modules/Advisor/Http/Reports/Delete.php | 1 - .../Databases/Collections/Attributes/Get.php | 1 + .../Collections/Attributes/XList.php | 1 + .../Collections/Documents/Logs/XList.php | 1 + .../Http/Databases/Collections/Get.php | 1 + .../Databases/Collections/Indexes/Get.php | 1 + .../Databases/Collections/Indexes/XList.php | 1 + .../Http/Databases/Collections/Logs/XList.php | 1 + .../Http/Databases/Collections/Usage/Get.php | 1 + .../Http/Databases/Collections/XList.php | 1 + .../Modules/Databases/Http/Databases/Get.php | 1 + .../Databases/Http/Databases/Logs/XList.php | 1 + .../Http/Databases/Transactions/Get.php | 1 + .../Databases/Http/Databases/Usage/Get.php | 1 + .../DocumentsDB/Collections/Documents/Get.php | 1 + .../Collections/Documents/XList.php | 1 + .../Http/DocumentsDB/Collections/Get.php | 1 + .../DocumentsDB/Collections/Indexes/Get.php | 1 + .../DocumentsDB/Collections/Indexes/XList.php | 1 + .../DocumentsDB/Collections/Usage/Get.php | 1 + .../Http/DocumentsDB/Collections/XList.php | 1 + .../Databases/Http/DocumentsDB/Get.php | 1 + .../Databases/Http/DocumentsDB/Logs/XList.php | 1 + .../Http/DocumentsDB/Transactions/Get.php | 1 + .../Databases/Http/DocumentsDB/Usage/Get.php | 1 + .../Modules/Databases/Http/TablesDB/Get.php | 1 + .../Databases/Http/TablesDB/Logs/XList.php | 1 + .../Http/TablesDB/Tables/Columns/Get.php | 1 + .../Http/TablesDB/Tables/Columns/XList.php | 1 + .../Databases/Http/TablesDB/Tables/Get.php | 1 + .../Http/TablesDB/Tables/Indexes/Get.php | 1 + .../Http/TablesDB/Tables/Indexes/XList.php | 1 + .../Http/TablesDB/Tables/Logs/XList.php | 1 + .../Http/TablesDB/Tables/Rows/Get.php | 1 + .../Http/TablesDB/Tables/Rows/Logs/XList.php | 1 + .../Http/TablesDB/Tables/Rows/XList.php | 1 + .../Http/TablesDB/Tables/Usage/Get.php | 1 + .../Databases/Http/TablesDB/Tables/XList.php | 1 + .../Http/TablesDB/Transactions/Get.php | 1 + .../Databases/Http/TablesDB/Usage/Get.php | 1 + .../VectorsDB/Collections/Documents/Get.php | 1 + .../VectorsDB/Collections/Documents/XList.php | 1 + .../Http/VectorsDB/Collections/Get.php | 1 + .../VectorsDB/Collections/Indexes/Get.php | 1 + .../VectorsDB/Collections/Indexes/XList.php | 1 + .../Http/VectorsDB/Collections/Usage/Get.php | 1 + .../Http/VectorsDB/Collections/XList.php | 1 + .../Http/VectorsDB/Embeddings/Text/Create.php | 2 +- .../Modules/Databases/Http/VectorsDB/Get.php | 1 + .../Databases/Http/VectorsDB/Logs/XList.php | 1 + .../Http/VectorsDB/Transactions/Get.php | 1 + .../Databases/Http/VectorsDB/Usage/Get.php | 1 + .../Http/Deployments/Download/Get.php | 1 + .../Functions/Http/Deployments/Get.php | 1 + .../Functions/Http/Deployments/XList.php | 1 + .../Modules/Functions/Http/Executions/Get.php | 1 + .../Functions/Http/Executions/XList.php | 1 + .../Modules/Functions/Http/Functions/Get.php | 1 + .../Modules/Functions/Http/Templates/Get.php | 1 + .../Modules/Functions/Http/Usage/Get.php | 1 + .../Modules/Functions/Http/Variables/Get.php | 1 + .../Functions/Http/Variables/XList.php | 1 + .../Migrations/Http/Migrations/Delete.php | 1 - .../Migrations/Http/Migrations/Update.php | 1 - .../Organization/Http/Projects/Create.php | 1 - .../Organization/Http/Projects/Delete.php | 1 - .../Organization/Http/Projects/Update.php | 1 - .../Modules/Presences/HTTP/Delete.php | 1 - .../Modules/Presences/HTTP/Update.php | 1 - .../Modules/Presences/HTTP/Upsert.php | 1 - .../Http/Project/AuthMethods/Update.php | 1 - .../Modules/Project/Http/Project/Delete.php | 1 - .../Project/Http/Project/Keys/Create.php | 1 - .../Project/Http/Project/Keys/Delete.php | 1 - .../Http/Project/Keys/Ephemeral/Create.php | 1 - .../Project/Http/Project/Keys/Update.php | 1 - .../Project/Http/Project/Labels/Update.php | 1 - .../Project/Http/Project/MockPhone/Create.php | 1 - .../Project/Http/Project/MockPhone/Delete.php | 1 - .../Project/Http/Project/MockPhone/Update.php | 1 - .../Http/Project/OAuth2/Apple/Update.php | 1 - .../Http/Project/OAuth2/Auth0/Update.php | 1 - .../Http/Project/OAuth2/Authentik/Update.php | 1 - .../Project/Http/Project/OAuth2/Base.php | 1 - .../Http/Project/OAuth2/FusionAuth/Update.php | 1 - .../Http/Project/OAuth2/Gitlab/Update.php | 1 - .../Http/Project/OAuth2/Google/Update.php | 1 - .../Http/Project/OAuth2/Keycloak/Update.php | 1 - .../Http/Project/OAuth2/Microsoft/Update.php | 1 - .../Http/Project/OAuth2/Oidc/Update.php | 1 - .../Http/Project/OAuth2/Okta/Update.php | 1 - .../Http/Project/Platforms/Android/Create.php | 1 - .../Http/Project/Platforms/Android/Update.php | 1 - .../Http/Project/Platforms/Apple/Create.php | 1 - .../Http/Project/Platforms/Apple/Update.php | 1 - .../Project/Http/Project/Platforms/Delete.php | 1 - .../Http/Project/Platforms/Linux/Create.php | 1 - .../Http/Project/Platforms/Linux/Update.php | 1 - .../Http/Project/Platforms/Web/Create.php | 1 - .../Http/Project/Platforms/Web/Update.php | 1 - .../Http/Project/Platforms/Windows/Create.php | 1 - .../Http/Project/Platforms/Windows/Update.php | 1 - .../Policies/MembershipPrivacy/Update.php | 1 - .../Policies/PasswordDictionary/Update.php | 1 - .../Policies/PasswordHistory/Update.php | 1 - .../Policies/PasswordPersonalData/Update.php | 1 - .../Policies/PasswordStrength/Update.php | 1 - .../Project/Policies/SessionAlert/Update.php | 1 - .../Policies/SessionDuration/Update.php | 1 - .../Policies/SessionInvalidation/Update.php | 1 - .../Project/Policies/SessionLimit/Update.php | 1 - .../Project/Policies/UserLimit/Update.php | 1 - .../Project/Http/Project/Protocols/Update.php | 1 - .../Project/Http/Project/SMTP/Update.php | 1 - .../Project/Http/Project/Services/Update.php | 1 - .../Http/Project/Templates/Email/Update.php | 1 - .../Project/Http/Project/Variables/Create.php | 1 - .../Project/Http/Project/Variables/Delete.php | 1 - .../Project/Http/Project/Variables/Update.php | 1 - .../Modules/Projects/Http/Projects/Create.php | 1 - .../Modules/Projects/Http/Projects/Update.php | 1 - .../Projects/Http/Schedules/Create.php | 1 - .../Modules/Proxy/Http/Rules/API/Create.php | 1 - .../Modules/Proxy/Http/Rules/Delete.php | 1 - .../Proxy/Http/Rules/Function/Create.php | 1 - .../Proxy/Http/Rules/Redirect/Create.php | 1 - .../Modules/Proxy/Http/Rules/Site/Create.php | 1 - .../Proxy/Http/Rules/Status/Update.php | 1 - .../Sites/Http/Deployments/Download/Get.php | 1 + .../Modules/Sites/Http/Deployments/Get.php | 1 + .../Modules/Sites/Http/Deployments/XList.php | 1 + .../Platform/Modules/Sites/Http/Logs/Get.php | 1 + .../Modules/Sites/Http/Logs/XList.php | 1 + .../Platform/Modules/Sites/Http/Sites/Get.php | 1 + .../Modules/Sites/Http/Templates/Get.php | 1 + .../Platform/Modules/Sites/Http/Usage/Get.php | 1 + .../Modules/Sites/Http/Variables/Get.php | 1 + .../Modules/Sites/Http/Variables/XList.php | 1 + .../Http/Buckets/Files/Download/Get.php | 1 + .../Storage/Http/Buckets/Files/Get.php | 1 + .../Http/Buckets/Files/Preview/Get.php | 1 + .../Storage/Http/Buckets/Files/Push/Get.php | 1 + .../Storage/Http/Buckets/Files/View/Get.php | 1 + .../Storage/Http/Buckets/Files/XList.php | 1 + .../Modules/Storage/Http/Buckets/Get.php | 1 + .../Modules/Storage/Http/Usage/Get.php | 1 + .../Modules/Teams/Http/Memberships/Create.php | 1 - .../Modules/Teams/Http/Memberships/Delete.php | 1 - .../Teams/Http/Memberships/Status/Update.php | 1 - .../Modules/Teams/Http/Memberships/Update.php | 1 - .../Modules/Teams/Http/Preferences/Update.php | 1 - .../Modules/Teams/Http/Teams/Create.php | 1 - .../Modules/Teams/Http/Teams/Delete.php | 1 - .../Modules/Teams/Http/Teams/Name/Update.php | 1 - .../Http/Tokens/Buckets/Files/Create.php | 1 - .../Modules/Tokens/Http/Tokens/Delete.php | 1 - .../Modules/Tokens/Http/Tokens/Update.php | 1 - .../Modules/Webhooks/Http/Webhooks/Create.php | 1 - .../Modules/Webhooks/Http/Webhooks/Delete.php | 1 - .../Webhooks/Http/Webhooks/Secret/Update.php | 1 - .../Modules/Webhooks/Http/Webhooks/Update.php | 1 - src/Appwrite/Resource/Parser.php | 123 ++++++++++++++++++ 171 files changed, 209 insertions(+), 130 deletions(-) create mode 100644 src/Appwrite/Resource/Parser.php diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 30377334d0..12929d7ee6 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -43,45 +43,13 @@ use Utopia\System\System; use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\WhiteList; -$parseLabel = function (string $label, array $responsePayload, array $requestParams, User $user, Document $project) { - preg_match_all('/{(.*?)}/', $label, $matches); - foreach ($matches[1] as $pos => $match) { - $find = $matches[0][$pos]; - $parts = explode('.', $match); - - if (count($parts) !== 2) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "The server encountered an error while parsing the label: $label. Please create an issue on GitHub to allow us to investigate further https://github.com/appwrite/appwrite/issues/new/choose"); - } - - $namespace = $parts[0]; - $replace = $parts[1]; - - $params = match ($namespace) { - 'user' => (array) $user, - 'project' => $project->getArrayCopy(), - 'request' => $requestParams, - default => $responsePayload, - }; - - if (array_key_exists($replace, $params)) { - $replacement = $params[$replace]; - // Convert to string if it's not already a string - if (! is_string($replacement)) { - if (is_array($replacement)) { - $replacement = json_encode($replacement); - } elseif (is_object($replacement) && method_exists($replacement, '__toString')) { - $replacement = (string) $replacement; - } elseif (is_scalar($replacement)) { - $replacement = (string) $replacement; - } else { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "The server encountered an error while parsing the label: $label. Please create an issue on GitHub to allow us to investigate further https://github.com/appwrite/appwrite/issues/new/choose"); - } - } - $label = \str_replace($find, $replacement, $label); - } - } - - return $label; +$parseLabel = function (string $label, array $responsePayload, array $requestParams, User $user, Document $project): string { + return \Appwrite\Resource\Parser::render($label, [ + 'user' => (array) $user, + 'project' => $project, + 'request' => $requestParams, + 'response' => $responsePayload, + ]); }; Http::init() diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php index cdf8828ab3..6aa13e4cd0 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php @@ -42,7 +42,6 @@ class Create extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php index 44bbdfd702..ce0e8d266e 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Delete.php @@ -39,7 +39,6 @@ class Delete extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{user.$id}') - ->label('usage.resource', 'user/{user.$id}') ->label('audits.userId', '{user.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php index 0bcfcfb7ba..11f044b507 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Update.php @@ -41,7 +41,6 @@ class Update extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php index aae9bcfcd0..da6055fffd 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php @@ -57,7 +57,6 @@ class Create extends Action ->label('event', 'users.[userId].challenges.[challengeId].create') ->label('audits.event', 'challenge.create') ->label('audits.resource', 'user/{response.userId}') - ->label('usage.resource', 'user/{response.userId}') ->label('audits.userId', '{response.userId}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php index 3e16aab2ab..5f6b7a1186 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php @@ -40,7 +40,6 @@ class Update extends Action ->label('event', 'users.[userId].sessions.[sessionId].create') ->label('audits.event', 'challenges.update') ->label('audits.resource', 'user/{response.userId}') - ->label('usage.resource', 'user/{response.userId}') ->label('audits.userId', '{response.userId}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php index 7d7c1d8e75..0d1191aaea 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php @@ -36,7 +36,6 @@ class Create extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php index 5d7570e61e..40051cfebc 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php index 6842e99d4e..a578149654 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'account') ->label('audits.event', 'user.update') ->label('audits.resource', 'user/{response.$id}') - ->label('usage.resource', 'user/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', new Method( namespace: 'account', diff --git a/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php b/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php index baa53aa7ca..1efc029c17 100644 --- a/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php +++ b/src/Appwrite/Platform/Modules/Advisor/Http/Reports/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('resourceType', RESOURCE_TYPE_REPORTS) ->label('audits.event', 'report.delete') ->label('audits.resource', 'report/{request.reportId}') - ->label('usage.resource', 'report/{request.reportId}') ->label('abuse-key', 'projectId:{projectId},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index 4fc251fe51..61c7760eed 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -45,6 +45,7 @@ class Get extends Action ->desc('Get attribute') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 430117188f..6390797407 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -40,6 +40,7 @@ class XList extends Action ->desc('List attributes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 976a76bba7..b9e7f846f2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -45,6 +45,7 @@ class XList extends Action ->desc('List document logs') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 43364413db..64667f52c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -34,6 +34,7 @@ class Get extends Action ->desc('Get collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index 763fd86f7b..39e951e100 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -35,6 +35,7 @@ class Get extends Action ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index c4d70c5fb6..506b45a890 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -41,6 +41,7 @@ class XList extends Action ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index f2b4e1b4fa..5dfe31f3d8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -45,6 +45,7 @@ class XList extends Action ->desc('List collection logs') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php index 2fce1a3906..fb1ced0a40 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php @@ -45,6 +45,7 @@ class Get extends Action ->desc('Get collection usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index 5d1ccbd45f..5731fd9aff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -42,6 +42,7 @@ class XList extends Action ->desc('List collections') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index 5ee8e2f5e3..d5e2a3eabf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -28,6 +28,7 @@ class Get extends Action ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index 1474e602e3..135f70d290 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -40,6 +40,7 @@ class XList extends Action ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php index dc20349e7c..d31c2fb48b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php @@ -33,6 +33,7 @@ class Get extends Action ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', 'rows.read') + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index ee65cbd7ff..d68e5b800b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -74,6 +74,7 @@ class Get extends DatabasesAction ->desc('Get database usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php index 47d352bf98..ec02abe2aa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/Get.php @@ -33,6 +33,7 @@ class Get extends DocumentGet ->desc('Get document') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php index 51c0d67e8a..f2da8d262b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Documents/XList.php @@ -35,6 +35,7 @@ class XList extends DocumentXList ->desc('List documents') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php index 53120dd636..d112f919e2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Get.php @@ -31,6 +31,7 @@ class Get extends CollectionGet ->desc('Get collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php index 7fa75b6ed9..567abaefed 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Get.php @@ -32,6 +32,7 @@ class Get extends IndexGet ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php index 1e16155f76..93ffb8fb55 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/XList.php @@ -33,6 +33,7 @@ class XList extends IndexXList ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php index 907ba22ae4..017f5feb11 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php @@ -39,6 +39,7 @@ class Get extends CollectionUsageGet ->desc('Get collection usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php index 638244145b..2fde8aa50b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/XList.php @@ -34,6 +34,7 @@ class XList extends CollectionXList ->desc('List collections') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php index 309a3b867e..d2a1f65779 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Get.php @@ -27,6 +27,7 @@ class Get extends DatabaseGet ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php index 8afb0fd1ef..1327c86474 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php @@ -30,6 +30,7 @@ class XList extends DatabaseLogs ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php index 7def4f0b9a..c2f4b85881 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Transactions/Get.php @@ -31,6 +31,7 @@ class Get extends TransactionsGet ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', 'documents.read') + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php index e94106e31e..1ab9aeab6b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php @@ -34,6 +34,7 @@ class Get extends DatabaseUsageGet ->desc('Get DocumentsDB usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php index 5fad045dda..a7171c9691 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Get.php @@ -27,6 +27,7 @@ class Get extends DatabaseGet ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'tablesDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index 0df38fbf4b..68718cf1fd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -39,6 +39,7 @@ class XList extends Action ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php index b0ef9e8a85..9885f44ca4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php @@ -43,6 +43,7 @@ class Get extends AttributesGet ->desc('Get column') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php index 56c436a13e..643ff94db4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php @@ -34,6 +34,7 @@ class XList extends AttributesXList ->desc('List columns') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php index ca104f05c4..f7d61f0ebe 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Get.php @@ -32,6 +32,7 @@ class Get extends CollectionGet ->desc('Get table') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php index 9918bcb2b8..96e185e01a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php @@ -33,6 +33,7 @@ class Get extends IndexGet ->desc('Get index') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'indexes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php index 5fe3be4c05..b67ea60f44 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php @@ -34,6 +34,7 @@ class XList extends IndexXList ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read', 'indexes.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php index 62cd634f19..fd7e6d4e21 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php @@ -29,6 +29,7 @@ class XList extends CollectionLogXList ->desc('List table logs') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php index 65ae238a1a..4b5b427f88 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Get.php @@ -35,6 +35,7 @@ class Get extends DocumentGet ->desc('Get row') ->groups(['api', 'database']) ->label('scope', ['rows.read', 'documents.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php index e1d821130f..9959c912c5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php @@ -29,6 +29,7 @@ class XList extends DocumentLogXList ->desc('List row logs') ->groups(['api', 'database']) ->label('scope', ['rows.read', 'documents.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php index 87e276719e..b951fec8f8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/XList.php @@ -37,6 +37,7 @@ class XList extends DocumentXList ->desc('List rows') ->groups(['api', 'database']) ->label('scope', ['rows.read', 'documents.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php index 293db004ee..1aeae427e5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php @@ -34,6 +34,7 @@ class Get extends CollectionUsageGet ->desc('Get table usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php index 30ebbab409..fd8e51b467 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/XList.php @@ -35,6 +35,7 @@ class XList extends CollectionXList ->desc('List tables') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php index d81d3e579d..cfb621d28d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Transactions/Get.php @@ -32,6 +32,7 @@ class Get extends TransactionsGet ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', ['documents.read', 'rows.read']) + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'tablesDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php index 3f3e58dc89..2c56bf597e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php @@ -29,6 +29,7 @@ class Get extends DatabaseUsageGet ->desc('Get TablesDB usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', ['tables.read', 'collections.read']) + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php index 73f7a55026..35dc3f178a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/Get.php @@ -33,6 +33,7 @@ class Get extends DocumentGet ->desc('Get document') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php index c9ed05ac02..1b11b282fd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Documents/XList.php @@ -35,6 +35,7 @@ class XList extends DocumentXList ->desc('List documents') ->groups(['api', 'database']) ->label('scope', 'documents.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php index 9619bb5048..73c0a9d3dc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Get.php @@ -31,6 +31,7 @@ class Get extends CollectionGet ->desc('Get collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php index 4cf646acba..3d1b492ff9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Get.php @@ -32,6 +32,7 @@ class Get extends IndexGet ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php index acc46fb570..8475349979 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/XList.php @@ -33,6 +33,7 @@ class XList extends IndexXList ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php index fa28028cc1..a181b0f78d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php @@ -38,6 +38,7 @@ class Get extends CollectionUsageGet ->desc('Get collection usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php index 7ba26b8b6a..ac6a20c457 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/XList.php @@ -34,6 +34,7 @@ class XList extends CollectionXList ->desc('List collections') ->groups(['api', 'database']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php index 4ab3edeb70..a77cc51f1b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Embeddings/Text/Create.php @@ -50,7 +50,7 @@ class Create extends CreateDocumentAction ->label('resourceType', RESOURCE_TYPE_EMBEDDINGS_TEXT) ->label('audits.event', 'embedding.create') ->label('audits.resource', 'vectorsdb/embeddings/text') - ->label('usage.resource', 'vectorsdb/embeddings/text') + ->label('usage.resource', 'database/embeddings/text') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT * 2) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php index a79632b105..606fb7150a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Get.php @@ -26,6 +26,7 @@ class Get extends DatabaseGet ->desc('Get database') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php index d8c1df5f04..ef71a3f6a5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php @@ -29,6 +29,7 @@ class XList extends DatabaseLogs ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php index fa4cc86cdd..5b1a227844 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Transactions/Get.php @@ -31,6 +31,7 @@ class Get extends TransactionsGet ->desc('Get transaction') ->groups(['api', 'database', 'transactions']) ->label('scope', 'documents.read') + ->label('usage.resource', 'transaction/{request.transactionId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php index 725e11e48b..187b093f72 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php @@ -33,6 +33,7 @@ class Get extends DatabaseUsageGet ->desc('Get VectorsDB usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') + ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php index 2d57ec5525..70d20fc0d9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -36,6 +36,7 @@ class Get extends Action ->groups(['api', 'functions']) ->desc('Get deployment download') ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php index 57c4421928..31a395341b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Get.php @@ -29,6 +29,7 @@ class Get extends Action ->desc('Get deployment') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php index e8e9ea9a18..581dea3d12 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php @@ -40,6 +40,7 @@ class XList extends Base ->desc('List deployments') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php index 9908669f84..027ff51166 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php @@ -32,6 +32,7 @@ class Get extends Base ->desc('Get execution') ->groups(['api', 'functions']) ->label('scope', ['executions.read', 'execution.read']) + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php index bf31fa0ced..29bed70cd0 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php @@ -40,6 +40,7 @@ class XList extends Base ->desc('List executions') ->groups(['api', 'functions']) ->label('scope', ['executions.read', 'execution.read']) + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php index 9fab8afef8..449413cb10 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get function') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php index f66322839b..ab8f068521 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php @@ -31,6 +31,7 @@ class Get extends Base ->desc('Get function template') ->groups(['api', 'functions']) ->label('scope', 'public') + ->label('usage.resource', 'template/{request.templateId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index def354aa2d..a3e0a003bf 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -36,6 +36,7 @@ class Get extends Base ->desc('Get function usage') ->groups(['api', 'functions', 'usage']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php index 13ce73e751..41decb1a48 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get variable') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php index b330812b96..bf6ba67190 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php @@ -37,6 +37,7 @@ class XList extends Base ->desc('List variables') ->groups(['api', 'functions']) ->label('scope', 'functions.read') + ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php index daad2bf634..f9c989b5bf 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Delete.php @@ -34,7 +34,6 @@ class Delete extends Action ->label('event', 'migrations.[migrationId].delete') ->label('audits.event', 'migrationId.delete') ->label('audits.resource', 'migrations/{request.migrationId}') - ->label('usage.resource', 'migrations/{request.migrationId}') ->label('sdk', new Method( namespace: 'migrations', group: null, diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php index b900b6586b..8ecc53c2a3 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'migrations.[migrationId].retry') ->label('audits.event', 'migration.retry') ->label('audits.resource', 'migrations/{request.migrationId}') - ->label('usage.resource', 'migrations/{request.migrationId}') ->label('sdk', new Method( namespace: 'migrations', group: null, diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php index 191c09e455..90c3781701 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php @@ -46,7 +46,6 @@ class Create extends Action ->groups(['api', 'organization']) ->label('audits.event', 'projects.create') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('scope', 'projects.write') ->label('sdk', new Method( namespace: 'organization', diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php index 56af8a6b8b..fc8d5cccfc 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php @@ -35,7 +35,6 @@ class Delete extends Action ->label('scope', 'projects.write') ->label('audits.event', 'projects.delete') ->label('audits.resource', 'project/{request.projectId}') - ->label('usage.resource', 'project/{request.projectId}') ->label('sdk', new Method( namespace: 'organization', group: 'projects', diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php index b178a0c549..c364a5d6df 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Update.php @@ -33,7 +33,6 @@ class Update extends Action ->label('scope', 'projects.write') ->label('audits.event', 'projects.update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'organization', group: 'projects', diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php index 7431efd411..66ab00c3a7 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php @@ -36,7 +36,6 @@ class Delete extends PlatformAction ->label('event', 'presences.[presenceId].delete') ->label('audits.event', 'presence.delete') ->label('audits.resource', 'presence/{request.presenceId}') - ->label('usage.resource', 'presence/{request.presenceId}') ->label('sdk', new Method( namespace: 'presences', group: 'presences', diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php index 2d37818830..cd2f0d5636 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php @@ -45,7 +45,6 @@ class Update extends PlatformAction ->label('event', 'presences.[presenceId].update') ->label('audits.event', 'presence.update') ->label('audits.resource', 'presence/{response.$id}') - ->label('usage.resource', 'presence/{response.$id}') ->label('sdk', [ // Client-side SDK: `userId` is not accepted (session callers can only update their own presence). new Method( diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php index 16bf5458f5..9e691e4647 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php @@ -46,7 +46,6 @@ class Upsert extends PlatformAction ->label('event', 'presences.[presenceId].upsert') ->label('audits.event', 'presence.upsert') ->label('audits.resource', 'presence/{response.$id}') - ->label('usage.resource', 'presence/{response.$id}') ->label('sdk', [ // Client-side SDK: `userId` is not accepted (session callers should just upsert their own presence). new Method( diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php index c6bf5a3c7c..f5f0ae0a32 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php @@ -38,7 +38,6 @@ class Update extends Action ->label('event', 'authMethod.[methodId].update') ->label('audits.event', 'project.authMethods.[methodId].update') ->label('audits.resource', 'project.authMethods/{response.$id}') - ->label('usage.resource', 'project.authMethods/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php index d84af6b995..201061dd62 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Delete.php @@ -36,7 +36,6 @@ class Delete extends Action ->label('scope', 'project.write') ->label('audits.event', 'project.delete') ->label('audits.resource', 'project/{project.$id}') - ->label('usage.resource', 'project/{project.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php index 3b23bb9039..992b3532c4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php @@ -46,7 +46,6 @@ class Create extends Base ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') - ->label('usage.resource', 'project.key/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php index 2c5e3bc2ed..c5da673e22 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Delete.php @@ -38,7 +38,6 @@ class Delete extends Base ->label('event', 'keys.[keyId].delete') ->label('audits.event', 'project.key.delete') ->label('audits.resource', 'project.key/{request.keyId}') - ->label('usage.resource', 'project.key/{request.keyId}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php index 314188645c..aadf76d74f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php @@ -42,7 +42,6 @@ class Create extends Base ->label('event', 'keys.[keyId].create') ->label('audits.event', 'project.key.create') ->label('audits.resource', 'project.key/{response.$id}') - ->label('usage.resource', 'project.key/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php index 09d3e639d5..0d96bcf315 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Update.php @@ -44,7 +44,6 @@ class Update extends Base ->label('event', 'keys.[keyId].update') ->label('audits.event', 'project.key.update') ->label('audits.resource', 'project.key/{response.$id}') - ->label('usage.resource', 'project.key/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'keys', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php index 1647f9febe..8a3506eb13 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php @@ -35,7 +35,6 @@ class Update extends Action // ->label('event', 'project.labels.update') ->label('audits.event', 'project.labels.update') ->label('audits.resource', 'project.labels/{response.$id}') - ->label('usage.resource', 'project.labels/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php index 4300795d01..f4002c60ef 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php @@ -37,7 +37,6 @@ class Create extends Action ->label('event', 'mock-phones.[number].create') ->label('audits.event', 'project.mock-phone.create') ->label('audits.resource', 'project.mock-phone/{response.number}') - ->label('usage.resource', 'project.mock-phone/{response.number}') ->label('sdk', new Method( namespace: 'project', group: 'mocks', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php index 14b5f662c1..0fb23e1764 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php @@ -36,7 +36,6 @@ class Delete extends Action ->label('event', 'mock-phones.[number].delete') ->label('audits.event', 'project.mock-phone.delete') ->label('audits.resource', 'project.mock-phone/{request.number}') - ->label('usage.resource', 'project.mock-phone/{request.number}') ->label('sdk', new Method( namespace: 'project', group: 'mocks', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php index 99f27a2fc1..48b90a1b97 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'mock-phones.[number].update') ->label('audits.event', 'project.mock-phone.update') ->label('audits.resource', 'project.mock-phone/{response.number}') - ->label('usage.resource', 'project.mock-phone/{response.number}') ->label('sdk', new Method( namespace: 'project', group: 'mocks', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php index 25144643b9..dc9eede2b4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php @@ -116,7 +116,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php index 51cd34a27d..aa5f39b213 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Auth0/Update.php @@ -90,7 +90,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php index f02dd540e9..af6b12618a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php @@ -90,7 +90,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php index 8cbb2549d3..b439e7fdf7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php @@ -242,7 +242,6 @@ abstract class Base extends Action ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php index be2038d0c9..3cdf0eeb89 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php @@ -90,7 +90,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php index 3ef25071dd..804f6354ae 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Gitlab/Update.php @@ -101,7 +101,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php index 9839350e54..5623f2bdf9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Google/Update.php @@ -94,7 +94,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php index c7dd7ae572..aa41e8a5e9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php @@ -96,7 +96,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php index 67be3a8be0..811819a05c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php @@ -100,7 +100,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php index 6cc170c086..697b306be8 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php @@ -110,7 +110,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php index f51311ec23..0344b6a14a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Okta/Update.php @@ -98,7 +98,6 @@ class Update extends Base ->label('event', 'oauth2.[providerId].update') ->label('audits.event', 'project.oauth2.[providerId].update') ->label('audits.resource', 'project.oauth2/{response.$id}') - ->label('usage.resource', 'project.oauth2/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'oauth2', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php index 94078072e1..accc6d5b35 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php index 9b368fd849..3ff958e814 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Android/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php index b66687bf0c..0843bf9a0c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php index 02c5c226f8..0295075f19 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Apple/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php index d580aa7c8e..24669b02b2 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Delete.php @@ -37,7 +37,6 @@ class Delete extends Action ->label('event', 'platforms.[platformId].delete') ->label('audits.event', 'project.platform.delete') ->label('audits.resource', 'project.platform/{request.platformId}') - ->label('usage.resource', 'project.platform/{request.platformId}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php index b4edf8bcd7..472b41cace 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php index 47ff114562..9c1f715c33 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Linux/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php index ce9ff52443..6c07727150 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php @@ -47,7 +47,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php index 79dc5e8184..62d209ea25 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php @@ -39,7 +39,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php index 3530c6ed17..58be45d03b 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Create.php @@ -39,7 +39,6 @@ class Create extends Action ->label('event', 'platforms.[platformId].create') ->label('audits.event', 'project.platform.create') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php index 4d4a371f5e..5cfb6ee7ea 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Windows/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'platforms.[platformId].update') ->label('audits.event', 'project.platform.update') ->label('audits.resource', 'project.platform/{response.$id}') - ->label('usage.resource', 'project.platform/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'platforms', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php index 7ca0586e36..b167aba794 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php index bd21431793..d0f8882e99 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php index e1d040de3a..be611e299f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php index f522368882..ff7819f192 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index f76da811ef..0f8c566511 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php index e79859e9f8..d930fd89e7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php index f32aa82f3b..10eabb57cd 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php index 68ecb22057..d4d87edbba 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php index 541e18f636..93ae339b79 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php index 726ca237d2..b3f430b779 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php index cc7e9e5c7f..e0e4477a3c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php @@ -39,7 +39,6 @@ class Update extends Action ->label('event', 'protocols.[protocolId].update') ->label('audits.event', 'project.protocols.[protocolId].update') ->label('audits.resource', 'project.protocols/{response.$id}') - ->label('usage.resource', 'project.protocols/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php index 8879facae4..dd8a469d26 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php @@ -45,7 +45,6 @@ class Update extends Action // ->label('event', 'project.smtp.update') ->label('audits.event', 'project.smtp.update') ->label('audits.resource', 'project.smtp/{response.$id}') - ->label('usage.resource', 'project.smtp/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'smtp', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php index e1e6efd768..86ef67bb01 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php @@ -39,7 +39,6 @@ class Update extends Action ->label('event', 'services.[serviceId].update') ->label('audits.event', 'project.services.[serviceId].update') ->label('audits.resource', 'project.services/{response.$id}') - ->label('usage.resource', 'project.services/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: null, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php index 8e86d7d1e6..c8ec04bc76 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php @@ -42,7 +42,6 @@ class Update extends Action ->label('event', 'templates.[templateId].update') ->label('audits.event', 'project.template.update') ->label('audits.resource', 'project.template/{response.templateId}') - ->label('usage.resource', 'project.template/{response.templateId}') ->label('sdk', new Method( namespace: 'project', group: 'templates', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index 6a4bd033cf..8c76ed2a8e 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -38,7 +38,6 @@ class Create extends Action ->label('event', 'variables.[variableId].create') ->label('audits.event', 'project.variable.create') ->label('audits.resource', 'project.variable/{response.$id}') - ->label('usage.resource', 'project.variable/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php index 5183bdc68e..553fb09e54 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php @@ -35,7 +35,6 @@ class Delete extends Action ->label('event', 'variables.[variableId].delete') ->label('audits.event', 'project.variable.delete') ->label('audits.resource', 'project.variable/{request.variableId}') - ->label('usage.resource', 'project.variable/{request.variableId}') ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php index cad912d97c..6b05e19a78 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php @@ -37,7 +37,6 @@ class Update extends Action ->label('event', 'variables.[variableId].update') ->label('audits.event', 'project.variable.update') ->label('audits.resource', 'project.variable/{response.$id}') - ->label('usage.resource', 'project.variable/{response.$id}') ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index b45d0a0aae..28405fe1da 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -51,7 +51,6 @@ class Create extends Action ->groups(['api', 'projects']) ->label('audits.event', 'projects.create') ->label('audits.resource', 'project/{response.$id}') - ->label('usage.resource', 'project/{response.$id}') ->label('scope', 'projects.write') ->param('projectId', '', new ProjectId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, and hyphen. Can\'t start with a special char. Max length is 36 chars.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php index 0778c51661..f6df843d07 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'projects.write') ->label('audits.event', 'projects.update') ->label('audits.resource', 'project/{request.projectId}') - ->label('usage.resource', 'project/{request.projectId}') ->param('projectId', '', new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php index 3ef3a6bd24..7cf13c5ca2 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php @@ -72,7 +72,6 @@ class Create extends Action ->label('event', 'schedules.[scheduleId].create') ->label('audits.event', 'schedule.create') ->label('audits.resource', 'schedule/{response.$id}') - ->label('usage.resource', 'schedule/{response.$id}') ->label('sdk', new Method( namespace: 'projects', group: 'schedules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index 56e5ad4f7c..9431d24cde 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -41,7 +41,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php index 3d7fd02fa8..991b8eb006 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('event', 'rules.[ruleId].delete') ->label('audits.event', 'rules.delete') ->label('audits.resource', 'rule/{request.ruleId}') - ->label('usage.resource', 'rule/{request.ruleId}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 24cf52bc0d..7cc8b5e59e 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -43,7 +43,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index cfd165d5bd..c15bc3b1d9 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -45,7 +45,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index 43de6b5699..ca45d73e13 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -43,7 +43,6 @@ class Create extends Action ->label('event', 'rules.[ruleId].create') ->label('audits.event', 'rule.create') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php index 711681fc67..1ad6f730b3 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php @@ -41,7 +41,6 @@ class Update extends Action ->label('event', 'rules.[ruleId].update') ->label('audits.event', 'rule.update') ->label('audits.resource', 'rule/{response.$id}') - ->label('usage.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', group: 'rules', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index fa84b2f22f..79ef3d2b1d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -35,6 +35,7 @@ class Get extends Action ->desc('Get deployment download') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php index 56aaa3640b..6c6384e2a0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Get.php @@ -29,6 +29,7 @@ class Get extends Action ->desc('Get deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php index 3dccd687ea..8dd25fdd55 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php @@ -40,6 +40,7 @@ class XList extends Base ->desc('List deployments') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php index c482add2da..3582eb1bbb 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get log') ->groups(['api', 'sites']) ->label('scope', 'log.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php index 89fb3ee2e6..d8c0aa79c2 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php @@ -39,6 +39,7 @@ class XList extends Base ->desc('List logs') ->groups(['api', 'sites']) ->label('scope', 'log.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php index d685f2082d..508bcf0120 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get site') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php index 633ef31e68..e204f7a543 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php @@ -31,6 +31,7 @@ class Get extends Base ->desc('Get site template') ->groups(['api']) ->label('scope', 'public') + ->label('usage.resource', 'template/{request.templateId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index 73400977d1..c1b8c56a26 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -36,6 +36,7 @@ class Get extends Base ->desc('Get site usage') ->groups(['api', 'sites', 'usage']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php index 2fcb051996..50e10fe4c9 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php @@ -30,6 +30,7 @@ class Get extends Base ->desc('Get variable') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php index 1270fe4925..9637c0e8e0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php @@ -37,6 +37,7 @@ class XList extends Base ->desc('List variables') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label( 'sdk', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php index ed02a295c8..eab1366e34 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php @@ -43,6 +43,7 @@ class Get extends Action ->desc('Get file for download') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php index d997fe3cc0..67a6e81186 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php @@ -32,6 +32,7 @@ class Get extends Action ->desc('Get file') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 2a2686b544..6a41c55f1e 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -53,6 +53,7 @@ class Get extends Action ->desc('Get file preview') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('cache', true) ->label('cache.resourceType', 'bucket/{request.bucketId}') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php index 2b2d23c1fa..76756d37b8 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php @@ -40,6 +40,7 @@ class Get extends Action ->desc('Get file for push notification') ->groups(['api', 'storage']) ->label('scope', 'public') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php index 01e8b56fbe..0030639ab1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php @@ -44,6 +44,7 @@ class Get extends Action ->desc('Get file for view') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php index 28dfa87c5d..de61ea5910 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/XList.php @@ -41,6 +41,7 @@ class XList extends Action ->desc('List files') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php index 4e75de27c8..0418ef8b45 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Get.php @@ -32,6 +32,7 @@ class Get extends Action ->desc('Get bucket') ->groups(['api', 'storage']) ->label('scope', 'buckets.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php index 41ae0dd9ab..9d526d42dd 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php @@ -35,6 +35,7 @@ class Get extends Action ->desc('Get bucket usage stats') ->groups(['api', 'storage']) ->label('scope', 'files.read') + ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 9412db8268..92db118c46 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -61,7 +61,6 @@ class Create extends Action ->label('auth.type', 'invites') ->label('audits.event', 'membership.create') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('audits.userId', '{request.userId}') ->label('sdk', new Method( namespace: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php index 94a7a5a047..d055ecb23f 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('scope', 'teams.write') ->label('audits.event', 'membership.delete') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('sdk', new Method( namespace: 'teams', group: 'memberships', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php index 45706ad2a1..35297710af 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php @@ -46,7 +46,6 @@ class Update extends Action ->label('scope', 'public') ->label('audits.event', 'membership.update') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('audits.userId', '{request.userId}') ->label('sdk', new Method( namespace: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php index bb4b50c699..0d2f1e40b4 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php @@ -40,7 +40,6 @@ class Update extends Action ->label('scope', 'teams.write') ->label('audits.event', 'membership.update') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('sdk', new Method( namespace: 'teams', group: 'memberships', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php index 22d9b7d8cf..2ec5dc9c74 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Preferences/Update.php @@ -36,7 +36,6 @@ class Update extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.update') ->label('audits.resource', 'team/{response.$id}') - ->label('usage.resource', 'team/{response.$id}') ->label('audits.userId', '{response.$id}') ->label('sdk', new Method( namespace: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php index 7b335ac48f..222b0968be 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Create.php @@ -44,7 +44,6 @@ class Create extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.create') ->label('audits.resource', 'team/{response.$id}') - ->label('usage.resource', 'team/{response.$id}') ->label('sdk', new Method( namespace: 'teams', group: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php index c7c125393e..3bae031e06 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.delete') ->label('audits.resource', 'team/{request.teamId}') - ->label('usage.resource', 'team/{request.teamId}') ->label('sdk', new Method( namespace: 'teams', group: 'teams', diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php index cd43f87e4c..ebe751ee1c 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Teams/Name/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('scope', 'teams.write') ->label('audits.event', 'team.update') ->label('audits.resource', 'team/{response.$id}') - ->label('usage.resource', 'team/{response.$id}') ->label('sdk', new Method( namespace: 'teams', group: 'teams', diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php index d0f2c7bcda..1c2bd692ef 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php @@ -40,7 +40,6 @@ class Create extends Action ->label('event', 'tokens.[tokenId].create') ->label('audits.event', 'token.create') ->label('audits.resource', 'token/{response.$id}') - ->label('usage.resource', 'token/{response.$id}') ->label('usage.metric', 'tokens.{scope}.requests.create') ->label('usage.params', ['resourceId:{request.resourceId}', 'resourceType:{request.resourceType}']) ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php index 4188170367..a71f2ec726 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php @@ -33,7 +33,6 @@ class Delete extends Action ->label('event', 'tokens.[tokenId].delete') ->label('audits.event', 'tokens.delete') ->label('audits.resource', 'token/{request.tokenId}') - ->label('usage.resource', 'token/{request.tokenId}') ->label('usage.metric', 'tokens.{scope}.requests.delete') ->label('usage.params', ['tokenId:{request.tokenId}']) ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php index 924d73dfe8..444f49de62 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php @@ -35,7 +35,6 @@ class Update extends Action ->label('event', 'tokens.[tokenId].update') ->label('audits.event', 'tokens.update') ->label('audits.resource', 'tokens/{response.$id}') - ->label('usage.resource', 'tokens/{response.$id}') ->label('usage.metric', 'tokens.{scope}.requests.update') ->label('usage.params', ['tokenId:{request.tokenId}']) ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php index 5c9520442b..38196420be 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php @@ -47,7 +47,6 @@ class Create extends Action ->label('event', 'webhooks.[webhookId].create') ->label('audits.event', 'webhook.create') ->label('audits.resource', 'webhook/{response.$id}') - ->label('usage.resource', 'webhook/{response.$id}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php index 1d0ffe9303..cd05b6210c 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Delete.php @@ -38,7 +38,6 @@ class Delete extends Action ->label('event', 'webhooks.[webhookId].delete') ->label('audits.event', 'webhook.delete') ->label('audits.resource', 'webhook/{request.webhookId}') - ->label('usage.resource', 'webhook/{request.webhookId}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php index 396c147542..fbff94735e 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php @@ -38,7 +38,6 @@ class Update extends Action ->label('event', 'webhooks.[webhookId].update') ->label('audits.event', 'webhooks.update') ->label('audits.resource', 'webhook/{response.$id}') - ->label('usage.resource', 'webhook/{response.$id}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php index 0f89d90d4e..17b93812f3 100644 --- a/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php +++ b/src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php @@ -44,7 +44,6 @@ class Update extends Action ->label('event', 'webhooks.[webhookId].update') ->label('audits.event', 'webhooks.update') ->label('audits.resource', 'webhook/{response.$id}') - ->label('usage.resource', 'webhook/{response.$id}') ->label('sdk', new Method( namespace: 'webhooks', group: null, diff --git a/src/Appwrite/Resource/Parser.php b/src/Appwrite/Resource/Parser.php new file mode 100644 index 0000000000..3a34e3d919 --- /dev/null +++ b/src/Appwrite/Resource/Parser.php @@ -0,0 +1,123 @@ +|Document|object> $context + */ + public static function render(string $template, array $context): string + { + if ($template === '' || !str_contains($template, '{')) { + return $template; + } + + $fallback = self::asArray($context['response'] ?? []); + + preg_match_all('/{([^}]+)}/', $template, $matches); + foreach ($matches[1] as $pos => $match) { + $find = $matches[0][$pos]; + $parts = explode('.', $match, 2); + if (count($parts) !== 2) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid resource label template: {$template}"); + } + + [$namespace, $key] = $parts; + $bag = array_key_exists($namespace, $context) ? self::asArray($context[$namespace]) : $fallback; + if (!array_key_exists($key, $bag)) { + continue; + } + + $value = $bag[$key]; + if (!is_string($value)) { + if (is_array($value)) { + $value = json_encode($value); + } elseif (is_object($value) && method_exists($value, '__toString')) { + $value = (string) $value; + } elseif (is_scalar($value)) { + $value = (string) $value; + } else { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Cannot stringify label value: {$template}"); + } + } + + $template = str_replace($find, $value, $template); + } + + return $template; + } + + /** + * Split a rendered resource string into ordered {type, id} segments. + * Trailing odd segment (e.g. `bucket/{id}/files`) is treated as a + * collection name with no id and dropped. + * + * @return array + */ + public static function parse(string $rendered): array + { + if ($rendered === '') { + return []; + } + + $parts = explode('/', trim($rendered, '/')); + $segments = []; + for ($i = 0, $n = count($parts); $i + 1 < $n; $i += 2) { + $segments[] = ['type' => $parts[$i], 'id' => $parts[$i + 1]]; + } + return $segments; + } + + /** + * Apply the usage-warehouse granularity rule on top of {@see parse()}: + * - databases stop at `database/{databaseId}/table` + tableId + * - storage stops at `bucket` + bucketId + * - functions/sites are scalar (`function`/`site` + id) + * - everything else returns the head segment unchanged + * + * @param array $segments + * @return array{resource: string, resourceId: string} + */ + public static function capForUsage(array $segments): array + { + if ($segments === []) { + return ['resource' => '', 'resourceId' => '']; + } + + $head = $segments[0]; + if ($head['type'] === 'database' && isset($segments[1]) && $segments[1]['type'] === 'collection') { + return [ + 'resource' => 'database/' . $head['id'] . '/table', + 'resourceId' => $segments[1]['id'], + ]; + } + + return ['resource' => $head['type'], 'resourceId' => $head['id']]; + } + + /** + * @return array + */ + private static function asArray(mixed $value): array + { + if (is_array($value)) { + return $value; + } + if ($value instanceof Document) { + return $value->getArrayCopy(); + } + if (is_object($value)) { + return (array) $value; + } + return []; + } +} From 2be61b99d69ee3a880c5b331bcf9a307d6006e6b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 02:28:16 +0000 Subject: [PATCH 02/12] fixup: relocate Parser to Event\\Resource, drop deprecated logs/usage endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move Appwrite\\Resource\\Parser → Appwrite\\Event\\Resource\\Parser so it lives alongside Event\\Context, Event\\Message, Event\\Publisher families that consume the parsed resource field. - Use ResourceParser via use-import in api.php instead of an inline FQCN. - Skip the deprecated logs/ and usage/ read endpoints across databases, tablesdb, documentsdb, vectorsdb, functions, sites and storage — these are being replaced by /v1/activities and /v1/usage in cloud. --- app/controllers/shared/api.php | 3 ++- src/Appwrite/{ => Event}/Resource/Parser.php | 2 +- .../Http/Databases/Collections/Documents/Logs/XList.php | 1 - .../Databases/Http/Databases/Collections/Logs/XList.php | 1 - .../Modules/Databases/Http/Databases/Collections/Usage/Get.php | 1 - .../Platform/Modules/Databases/Http/Databases/Logs/XList.php | 1 - .../Platform/Modules/Databases/Http/Databases/Usage/Get.php | 1 - .../Databases/Http/DocumentsDB/Collections/Usage/Get.php | 1 - .../Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php | 1 - .../Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php | 1 - .../Platform/Modules/Databases/Http/TablesDB/Logs/XList.php | 1 - .../Modules/Databases/Http/TablesDB/Tables/Logs/XList.php | 1 - .../Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php | 1 - .../Modules/Databases/Http/TablesDB/Tables/Usage/Get.php | 1 - .../Platform/Modules/Databases/Http/TablesDB/Usage/Get.php | 1 - .../Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php | 1 - .../Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php | 1 - .../Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php | 1 - src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php | 1 - src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php | 1 - 23 files changed, 3 insertions(+), 23 deletions(-) rename src/Appwrite/{ => Event}/Resource/Parser.php (99%) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 12929d7ee6..b16074cc15 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -9,6 +9,7 @@ use Appwrite\Event\Message\Audit as AuditMessage; use Appwrite\Event\Message\Func as FunctionMessage; use Appwrite\Event\Message\Usage as UsageMessage; use Appwrite\Event\Publisher\Audit; +use Appwrite\Event\Resource\Parser as ResourceParser; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; use Appwrite\Event\Realtime; @@ -44,7 +45,7 @@ use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\WhiteList; $parseLabel = function (string $label, array $responsePayload, array $requestParams, User $user, Document $project): string { - return \Appwrite\Resource\Parser::render($label, [ + return ResourceParser::render($label, [ 'user' => (array) $user, 'project' => $project, 'request' => $requestParams, diff --git a/src/Appwrite/Resource/Parser.php b/src/Appwrite/Event/Resource/Parser.php similarity index 99% rename from src/Appwrite/Resource/Parser.php rename to src/Appwrite/Event/Resource/Parser.php index 3a34e3d919..6c1ba6cdd0 100644 --- a/src/Appwrite/Resource/Parser.php +++ b/src/Appwrite/Event/Resource/Parser.php @@ -1,6 +1,6 @@ desc('List document logs') ->groups(['api', 'database']) ->label('scope', 'documents.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index 5dfe31f3d8..f2b4e1b4fa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -45,7 +45,6 @@ class XList extends Action ->desc('List collection logs') ->groups(['api', 'database']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php index fb1ced0a40..2fce1a3906 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php @@ -45,7 +45,6 @@ class Get extends Action ->desc('Get collection usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index 135f70d290..1474e602e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -40,7 +40,6 @@ class XList extends Action ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index d68e5b800b..ee65cbd7ff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -74,7 +74,6 @@ class Get extends DatabasesAction ->desc('Get database usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php index 017f5feb11..907ba22ae4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Usage/Get.php @@ -39,7 +39,6 @@ class Get extends CollectionUsageGet ->desc('Get collection usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'documentsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php index 1327c86474..8afb0fd1ef 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Logs/XList.php @@ -30,7 +30,6 @@ class XList extends DatabaseLogs ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php index 1ab9aeab6b..e94106e31e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Usage/Get.php @@ -34,7 +34,6 @@ class Get extends DatabaseUsageGet ->desc('Get DocumentsDB usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index 68718cf1fd..0df38fbf4b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -39,7 +39,6 @@ class XList extends Action ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php index fd7e6d4e21..62cd634f19 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php @@ -29,7 +29,6 @@ class XList extends CollectionLogXList ->desc('List table logs') ->groups(['api', 'database']) ->label('scope', ['tables.read', 'collections.read']) - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php index 9959c912c5..e1d821130f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php @@ -29,7 +29,6 @@ class XList extends DocumentLogXList ->desc('List row logs') ->groups(['api', 'database']) ->label('scope', ['rows.read', 'documents.read']) - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php index 1aeae427e5..293db004ee 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Usage/Get.php @@ -34,7 +34,6 @@ class Get extends CollectionUsageGet ->desc('Get table usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', ['tables.read', 'collections.read']) - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php index 2c56bf597e..3f3e58dc89 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Usage/Get.php @@ -29,7 +29,6 @@ class Get extends DatabaseUsageGet ->desc('Get TablesDB usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', ['tables.read', 'collections.read']) - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php index a181b0f78d..fa28028cc1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Usage/Get.php @@ -38,7 +38,6 @@ class Get extends CollectionUsageGet ->desc('Get collection usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'vectorsDB', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php index ef71a3f6a5..d8c1df5f04 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Logs/XList.php @@ -29,7 +29,6 @@ class XList extends DatabaseLogs ->desc('List database logs') ->groups(['api', 'database']) ->label('scope', 'databases.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php index 187b093f72..725e11e48b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Usage/Get.php @@ -33,7 +33,6 @@ class Get extends DatabaseUsageGet ->desc('Get VectorsDB usage stats') ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') - ->label('usage.resource', 'database/{request.databaseId}') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', [ new Method( diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index a3e0a003bf..def354aa2d 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -36,7 +36,6 @@ class Get extends Base ->desc('Get function usage') ->groups(['api', 'functions', 'usage']) ->label('scope', 'functions.read') - ->label('usage.resource', 'function/{request.functionId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php index 3582eb1bbb..c482add2da 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php @@ -30,7 +30,6 @@ class Get extends Base ->desc('Get log') ->groups(['api', 'sites']) ->label('scope', 'log.read') - ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php index d8c0aa79c2..89fb3ee2e6 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php @@ -39,7 +39,6 @@ class XList extends Base ->desc('List logs') ->groups(['api', 'sites']) ->label('scope', 'log.read') - ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index c1b8c56a26..73400977d1 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -36,7 +36,6 @@ class Get extends Base ->desc('Get site usage') ->groups(['api', 'sites', 'usage']) ->label('scope', 'sites.read') - ->label('usage.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php index 9d526d42dd..41ae0dd9ab 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Usage/Get.php @@ -35,7 +35,6 @@ class Get extends Action ->desc('Get bucket usage stats') ->groups(['api', 'storage']) ->label('scope', 'files.read') - ->label('usage.resource', 'bucket/{request.bucketId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', From 33b5f9be676bc7a7581ab2c25a4f434583715bbc Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 02:32:50 +0000 Subject: [PATCH 03/12] test(usage): cover Event\\Resource\\Parser rendering, parsing and usage cap Adds unit coverage for template substitution across request/response/user/ project namespaces, segment splitting, and the usage-warehouse cap rules that produce database/{id}/table / bucket / function / site resources. --- tests/unit/Event/Resource/ParserTest.php | 120 +++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tests/unit/Event/Resource/ParserTest.php diff --git a/tests/unit/Event/Resource/ParserTest.php b/tests/unit/Event/Resource/ParserTest.php new file mode 100644 index 0000000000..615095b286 --- /dev/null +++ b/tests/unit/Event/Resource/ParserTest.php @@ -0,0 +1,120 @@ + ['databaseId' => 'db1'], + 'response' => ['$id' => 'col9'], + ]); + + $this->assertSame('database/db1/collection/col9', $rendered); + } + + public function testRenderFallsBackToResponseForUnknownNamespace(): void + { + $rendered = Parser::render('thing/{unknown.id}', [ + 'response' => ['id' => 'r1'], + ]); + + $this->assertSame('thing/r1', $rendered); + } + + public function testRenderSupportsUserAndProjectNamespaces(): void + { + $rendered = Parser::render('user/{user.$id}/project/{project.$id}', [ + 'user' => ['$id' => 'usr1'], + 'project' => new Document(['$id' => 'prj1']), + ]); + + $this->assertSame('user/usr1/project/prj1', $rendered); + } + + public function testRenderLeavesUnresolvedTokensIntact(): void + { + $rendered = Parser::render('database/{request.databaseId}', [ + 'request' => [], + ]); + + $this->assertSame('database/{request.databaseId}', $rendered); + } + + public function testRenderShortCircuitsWhenNoTemplate(): void + { + $this->assertSame('database/db1', Parser::render('database/db1', [])); + $this->assertSame('', Parser::render('', [])); + } + + public function testParseSplitsIntoTypeIdSegmentsAndDropsTrailingCollectionName(): void + { + $this->assertSame( + [ + ['type' => 'database', 'id' => 'db1'], + ['type' => 'collection', 'id' => 'col1'], + ], + Parser::parse('database/db1/collection/col1/documents'), + ); + + $this->assertSame( + [['type' => 'bucket', 'id' => 'b1']], + Parser::parse('bucket/b1'), + ); + + $this->assertSame([], Parser::parse('')); + } + + public function testCapForUsageStopsAtCollectionForDatabaseResources(): void + { + $segments = Parser::parse('database/db1/collection/col1/document/doc1'); + + $this->assertSame( + ['resource' => 'database/db1/table', 'resourceId' => 'col1'], + Parser::capForUsage($segments), + ); + } + + public function testCapForUsageCollapsesStorageToBucket(): void + { + $segments = Parser::parse('bucket/b1/file/f1'); + + $this->assertSame( + ['resource' => 'bucket', 'resourceId' => 'b1'], + Parser::capForUsage($segments), + ); + } + + public function testCapForUsageTreatsFunctionsAndSitesAsScalar(): void + { + $this->assertSame( + ['resource' => 'function', 'resourceId' => 'fn1'], + Parser::capForUsage(Parser::parse('function/fn1/execution/exec1')), + ); + + $this->assertSame( + ['resource' => 'site', 'resourceId' => 's1'], + Parser::capForUsage(Parser::parse('site/s1/deployment/d1')), + ); + } + + public function testCapForUsageHandlesDatabaseWithoutCollection(): void + { + $this->assertSame( + ['resource' => 'database', 'resourceId' => 'db1'], + Parser::capForUsage(Parser::parse('database/db1')), + ); + + $this->assertSame( + ['resource' => '', 'resourceId' => ''], + Parser::capForUsage([]), + ); + } +} From 96215bf242c27e293b9549499a6bc6a220b33602 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 02:39:42 +0000 Subject: [PATCH 04/12] refactor(events): split label rendering from resource parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two responsibilities, two classes: - Appwrite\\Event\\Label\\Renderer::render() substitutes {namespace.key} placeholders inside a route label and returns the rendered string. Used by audit logging (api.php) and the cloud usage resolver to turn route labels into concrete resource paths. - Appwrite\\Event\\Resource\\Parser parses that rendered path string into ordered {type,id} segments and exposes consumer-specific projections — auditTarget() for the granular audit-log shape (deepest segment + joined parent), and capForUsage() for the container-level usage cap. Split the original combined Parser test into RendererTest and ParserTest. --- app/controllers/shared/api.php | 4 +- src/Appwrite/Event/Label/Renderer.php | 75 ++++++++++++++++ src/Appwrite/Event/Resource/Parser.php | 108 +++++++---------------- tests/unit/Event/Label/RendererTest.php | 56 ++++++++++++ tests/unit/Event/Resource/ParserTest.php | 68 +++++--------- 5 files changed, 190 insertions(+), 121 deletions(-) create mode 100644 src/Appwrite/Event/Label/Renderer.php create mode 100644 tests/unit/Event/Label/RendererTest.php diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index b16074cc15..c5306f1160 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -9,7 +9,7 @@ use Appwrite\Event\Message\Audit as AuditMessage; use Appwrite\Event\Message\Func as FunctionMessage; use Appwrite\Event\Message\Usage as UsageMessage; use Appwrite\Event\Publisher\Audit; -use Appwrite\Event\Resource\Parser as ResourceParser; +use Appwrite\Event\Label\Renderer as LabelRenderer; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; use Appwrite\Event\Realtime; @@ -45,7 +45,7 @@ use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\WhiteList; $parseLabel = function (string $label, array $responsePayload, array $requestParams, User $user, Document $project): string { - return ResourceParser::render($label, [ + return LabelRenderer::render($label, [ 'user' => (array) $user, 'project' => $project, 'request' => $requestParams, diff --git a/src/Appwrite/Event/Label/Renderer.php b/src/Appwrite/Event/Label/Renderer.php new file mode 100644 index 0000000000..42c38b9614 --- /dev/null +++ b/src/Appwrite/Event/Label/Renderer.php @@ -0,0 +1,75 @@ +|Document|object> $context + */ + public static function render(string $template, array $context): string + { + if ($template === '' || !str_contains($template, '{')) { + return $template; + } + + $fallback = self::asArray($context['response'] ?? []); + + preg_match_all('/{([^}]+)}/', $template, $matches); + foreach ($matches[1] as $pos => $match) { + $find = $matches[0][$pos]; + $parts = explode('.', $match, 2); + if (count($parts) !== 2) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid resource label template: {$template}"); + } + + [$namespace, $key] = $parts; + $bag = array_key_exists($namespace, $context) ? self::asArray($context[$namespace]) : $fallback; + if (!array_key_exists($key, $bag)) { + continue; + } + + $value = $bag[$key]; + if (!is_string($value)) { + if (is_array($value)) { + $value = json_encode($value); + } elseif (is_object($value) && method_exists($value, '__toString')) { + $value = (string) $value; + } elseif (is_scalar($value)) { + $value = (string) $value; + } else { + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Cannot stringify label value: {$template}"); + } + } + + $template = str_replace($find, $value, $template); + } + + return $template; + } + + /** + * @return array + */ + private static function asArray(mixed $value): array + { + if (is_array($value)) { + return $value; + } + if ($value instanceof Document) { + return $value->getArrayCopy(); + } + if (is_object($value)) { + return (array) $value; + } + return []; + } +} diff --git a/src/Appwrite/Event/Resource/Parser.php b/src/Appwrite/Event/Resource/Parser.php index 6c1ba6cdd0..73aa4b19a5 100644 --- a/src/Appwrite/Event/Resource/Parser.php +++ b/src/Appwrite/Event/Resource/Parser.php @@ -2,64 +2,12 @@ namespace Appwrite\Event\Resource; -use Appwrite\Extend\Exception; -use Utopia\Database\Document; - class Parser { /** - * Substitute `{namespace.key}` placeholders inside a label using the - * supplied context. Supported namespaces map to the keys of `$context`; - * an unknown namespace falls back to the `response` payload to preserve - * the historical behaviour of `audits.resource` rendering. - * - * @param array|Document|object> $context - */ - public static function render(string $template, array $context): string - { - if ($template === '' || !str_contains($template, '{')) { - return $template; - } - - $fallback = self::asArray($context['response'] ?? []); - - preg_match_all('/{([^}]+)}/', $template, $matches); - foreach ($matches[1] as $pos => $match) { - $find = $matches[0][$pos]; - $parts = explode('.', $match, 2); - if (count($parts) !== 2) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid resource label template: {$template}"); - } - - [$namespace, $key] = $parts; - $bag = array_key_exists($namespace, $context) ? self::asArray($context[$namespace]) : $fallback; - if (!array_key_exists($key, $bag)) { - continue; - } - - $value = $bag[$key]; - if (!is_string($value)) { - if (is_array($value)) { - $value = json_encode($value); - } elseif (is_object($value) && method_exists($value, '__toString')) { - $value = (string) $value; - } elseif (is_scalar($value)) { - $value = (string) $value; - } else { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Cannot stringify label value: {$template}"); - } - } - - $template = str_replace($find, $value, $template); - } - - return $template; - } - - /** - * Split a rendered resource string into ordered {type, id} segments. - * Trailing odd segment (e.g. `bucket/{id}/files`) is treated as a - * collection name with no id and dropped. + * Split a rendered resource path (e.g. `database/db1/collection/col1/document/doc1`) + * into ordered {type, id} segments. Trailing odd segment (e.g. + * `bucket/b1/files`) is treated as a collection name with no id and dropped. * * @return array */ @@ -78,11 +26,40 @@ class Parser } /** - * Apply the usage-warehouse granularity rule on top of {@see parse()}: + * Pick the audit-log target — the deepest known segment, plus the joined + * parent chain. Matches the granular shape the audit worker writes (e.g. + * type=document, id=doc1, parent=database/db1/collection/col1). + * + * @param array $segments + * @return array{type: string, id: string, parent: string} + */ + public static function auditTarget(array $segments): array + { + if ($segments === []) { + return ['type' => '', 'id' => '', 'parent' => '']; + } + + $count = count($segments); + $leaf = $segments[$count - 1]; + $parent = ''; + if ($count > 1) { + $parts = []; + for ($i = 0; $i < $count - 1; $i++) { + $parts[] = $segments[$i]['type']; + $parts[] = $segments[$i]['id']; + } + $parent = implode('/', $parts); + } + + return ['type' => $leaf['type'], 'id' => $leaf['id'], 'parent' => $parent]; + } + + /** + * Apply the usage-warehouse granularity rule: * - databases stop at `database/{databaseId}/table` + tableId * - storage stops at `bucket` + bucketId * - functions/sites are scalar (`function`/`site` + id) - * - everything else returns the head segment unchanged + * - anything else returns the head segment unchanged * * @param array $segments * @return array{resource: string, resourceId: string} @@ -103,21 +80,4 @@ class Parser return ['resource' => $head['type'], 'resourceId' => $head['id']]; } - - /** - * @return array - */ - private static function asArray(mixed $value): array - { - if (is_array($value)) { - return $value; - } - if ($value instanceof Document) { - return $value->getArrayCopy(); - } - if (is_object($value)) { - return (array) $value; - } - return []; - } } diff --git a/tests/unit/Event/Label/RendererTest.php b/tests/unit/Event/Label/RendererTest.php new file mode 100644 index 0000000000..f0bd199c63 --- /dev/null +++ b/tests/unit/Event/Label/RendererTest.php @@ -0,0 +1,56 @@ + ['databaseId' => 'db1'], + 'response' => ['$id' => 'col9'], + ]); + + $this->assertSame('database/db1/collection/col9', $rendered); + } + + public function testFallsBackToResponseForUnknownNamespace(): void + { + $rendered = Renderer::render('thing/{unknown.id}', [ + 'response' => ['id' => 'r1'], + ]); + + $this->assertSame('thing/r1', $rendered); + } + + public function testSupportsUserAndProjectNamespaces(): void + { + $rendered = Renderer::render('user/{user.$id}/project/{project.$id}', [ + 'user' => ['$id' => 'usr1'], + 'project' => new Document(['$id' => 'prj1']), + ]); + + $this->assertSame('user/usr1/project/prj1', $rendered); + } + + public function testLeavesUnresolvedTokensIntact(): void + { + $rendered = Renderer::render('database/{request.databaseId}', [ + 'request' => [], + ]); + + $this->assertSame('database/{request.databaseId}', $rendered); + } + + public function testShortCircuitsWhenNoTemplate(): void + { + $this->assertSame('database/db1', Renderer::render('database/db1', [])); + $this->assertSame('', Renderer::render('', [])); + } +} diff --git a/tests/unit/Event/Resource/ParserTest.php b/tests/unit/Event/Resource/ParserTest.php index 615095b286..cda111a941 100644 --- a/tests/unit/Event/Resource/ParserTest.php +++ b/tests/unit/Event/Resource/ParserTest.php @@ -6,54 +6,9 @@ namespace Tests\Unit\Event\Resource; use Appwrite\Event\Resource\Parser; use PHPUnit\Framework\TestCase; -use Utopia\Database\Document; final class ParserTest extends TestCase { - public function testRenderSubstitutesRequestAndResponseNamespaces(): void - { - $rendered = Parser::render('database/{request.databaseId}/collection/{response.$id}', [ - 'request' => ['databaseId' => 'db1'], - 'response' => ['$id' => 'col9'], - ]); - - $this->assertSame('database/db1/collection/col9', $rendered); - } - - public function testRenderFallsBackToResponseForUnknownNamespace(): void - { - $rendered = Parser::render('thing/{unknown.id}', [ - 'response' => ['id' => 'r1'], - ]); - - $this->assertSame('thing/r1', $rendered); - } - - public function testRenderSupportsUserAndProjectNamespaces(): void - { - $rendered = Parser::render('user/{user.$id}/project/{project.$id}', [ - 'user' => ['$id' => 'usr1'], - 'project' => new Document(['$id' => 'prj1']), - ]); - - $this->assertSame('user/usr1/project/prj1', $rendered); - } - - public function testRenderLeavesUnresolvedTokensIntact(): void - { - $rendered = Parser::render('database/{request.databaseId}', [ - 'request' => [], - ]); - - $this->assertSame('database/{request.databaseId}', $rendered); - } - - public function testRenderShortCircuitsWhenNoTemplate(): void - { - $this->assertSame('database/db1', Parser::render('database/db1', [])); - $this->assertSame('', Parser::render('', [])); - } - public function testParseSplitsIntoTypeIdSegmentsAndDropsTrailingCollectionName(): void { $this->assertSame( @@ -72,6 +27,29 @@ final class ParserTest extends TestCase $this->assertSame([], Parser::parse('')); } + public function testAuditTargetReturnsLeafAndParentChain(): void + { + $segments = Parser::parse('database/db1/collection/col1/document/doc1'); + + $this->assertSame( + ['type' => 'document', 'id' => 'doc1', 'parent' => 'database/db1/collection/col1'], + Parser::auditTarget($segments), + ); + } + + public function testAuditTargetForTopLevelResourceHasEmptyParent(): void + { + $this->assertSame( + ['type' => 'database', 'id' => 'db1', 'parent' => ''], + Parser::auditTarget(Parser::parse('database/db1')), + ); + + $this->assertSame( + ['type' => '', 'id' => '', 'parent' => ''], + Parser::auditTarget([]), + ); + } + public function testCapForUsageStopsAtCollectionForDatabaseResources(): void { $segments = Parser::parse('database/db1/collection/col1/document/doc1'); From 2697492f1b595bd3c66eb4d519490645b2ecadb0 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 02:49:15 +0000 Subject: [PATCH 05/12] fixup: drop Resource\\Parser from CE; only Label\\Renderer is shared The resource path parser is only used in cloud (StatsUsage worker / future Activity worker). Keep it co-located with the other Cloud Event classes rather than carrying it through CE just for one downstream consumer. --- src/Appwrite/Event/Resource/Parser.php | 83 -------------------- tests/unit/Event/Resource/ParserTest.php | 98 ------------------------ 2 files changed, 181 deletions(-) delete mode 100644 src/Appwrite/Event/Resource/Parser.php delete mode 100644 tests/unit/Event/Resource/ParserTest.php diff --git a/src/Appwrite/Event/Resource/Parser.php b/src/Appwrite/Event/Resource/Parser.php deleted file mode 100644 index 73aa4b19a5..0000000000 --- a/src/Appwrite/Event/Resource/Parser.php +++ /dev/null @@ -1,83 +0,0 @@ - - */ - public static function parse(string $rendered): array - { - if ($rendered === '') { - return []; - } - - $parts = explode('/', trim($rendered, '/')); - $segments = []; - for ($i = 0, $n = count($parts); $i + 1 < $n; $i += 2) { - $segments[] = ['type' => $parts[$i], 'id' => $parts[$i + 1]]; - } - return $segments; - } - - /** - * Pick the audit-log target — the deepest known segment, plus the joined - * parent chain. Matches the granular shape the audit worker writes (e.g. - * type=document, id=doc1, parent=database/db1/collection/col1). - * - * @param array $segments - * @return array{type: string, id: string, parent: string} - */ - public static function auditTarget(array $segments): array - { - if ($segments === []) { - return ['type' => '', 'id' => '', 'parent' => '']; - } - - $count = count($segments); - $leaf = $segments[$count - 1]; - $parent = ''; - if ($count > 1) { - $parts = []; - for ($i = 0; $i < $count - 1; $i++) { - $parts[] = $segments[$i]['type']; - $parts[] = $segments[$i]['id']; - } - $parent = implode('/', $parts); - } - - return ['type' => $leaf['type'], 'id' => $leaf['id'], 'parent' => $parent]; - } - - /** - * Apply the usage-warehouse granularity rule: - * - databases stop at `database/{databaseId}/table` + tableId - * - storage stops at `bucket` + bucketId - * - functions/sites are scalar (`function`/`site` + id) - * - anything else returns the head segment unchanged - * - * @param array $segments - * @return array{resource: string, resourceId: string} - */ - public static function capForUsage(array $segments): array - { - if ($segments === []) { - return ['resource' => '', 'resourceId' => '']; - } - - $head = $segments[0]; - if ($head['type'] === 'database' && isset($segments[1]) && $segments[1]['type'] === 'collection') { - return [ - 'resource' => 'database/' . $head['id'] . '/table', - 'resourceId' => $segments[1]['id'], - ]; - } - - return ['resource' => $head['type'], 'resourceId' => $head['id']]; - } -} diff --git a/tests/unit/Event/Resource/ParserTest.php b/tests/unit/Event/Resource/ParserTest.php deleted file mode 100644 index cda111a941..0000000000 --- a/tests/unit/Event/Resource/ParserTest.php +++ /dev/null @@ -1,98 +0,0 @@ -assertSame( - [ - ['type' => 'database', 'id' => 'db1'], - ['type' => 'collection', 'id' => 'col1'], - ], - Parser::parse('database/db1/collection/col1/documents'), - ); - - $this->assertSame( - [['type' => 'bucket', 'id' => 'b1']], - Parser::parse('bucket/b1'), - ); - - $this->assertSame([], Parser::parse('')); - } - - public function testAuditTargetReturnsLeafAndParentChain(): void - { - $segments = Parser::parse('database/db1/collection/col1/document/doc1'); - - $this->assertSame( - ['type' => 'document', 'id' => 'doc1', 'parent' => 'database/db1/collection/col1'], - Parser::auditTarget($segments), - ); - } - - public function testAuditTargetForTopLevelResourceHasEmptyParent(): void - { - $this->assertSame( - ['type' => 'database', 'id' => 'db1', 'parent' => ''], - Parser::auditTarget(Parser::parse('database/db1')), - ); - - $this->assertSame( - ['type' => '', 'id' => '', 'parent' => ''], - Parser::auditTarget([]), - ); - } - - public function testCapForUsageStopsAtCollectionForDatabaseResources(): void - { - $segments = Parser::parse('database/db1/collection/col1/document/doc1'); - - $this->assertSame( - ['resource' => 'database/db1/table', 'resourceId' => 'col1'], - Parser::capForUsage($segments), - ); - } - - public function testCapForUsageCollapsesStorageToBucket(): void - { - $segments = Parser::parse('bucket/b1/file/f1'); - - $this->assertSame( - ['resource' => 'bucket', 'resourceId' => 'b1'], - Parser::capForUsage($segments), - ); - } - - public function testCapForUsageTreatsFunctionsAndSitesAsScalar(): void - { - $this->assertSame( - ['resource' => 'function', 'resourceId' => 'fn1'], - Parser::capForUsage(Parser::parse('function/fn1/execution/exec1')), - ); - - $this->assertSame( - ['resource' => 'site', 'resourceId' => 's1'], - Parser::capForUsage(Parser::parse('site/s1/deployment/d1')), - ); - } - - public function testCapForUsageHandlesDatabaseWithoutCollection(): void - { - $this->assertSame( - ['resource' => 'database', 'resourceId' => 'db1'], - Parser::capForUsage(Parser::parse('database/db1')), - ); - - $this->assertSame( - ['resource' => '', 'resourceId' => ''], - Parser::capForUsage([]), - ); - } -} From 190120fd92e87794449f6f34fc9d592272db5206 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 04:12:48 +0000 Subject: [PATCH 06/12] refactor(reference): rename Event\Label\Renderer to Reference\Renderer; drop parseLabel closure The templated label is a resource reference; live the type in Appwrite\Reference. Renderer is now instance-bound to a per-request context, so api.php constructs one inside each shutdown closure that needs it and the global $parseLabel adapter goes away. --- app/controllers/shared/api.php | 34 +++++----- .../{Event/Label => Reference}/Renderer.php | 34 +++++++--- tests/unit/Event/Label/RendererTest.php | 56 ---------------- tests/unit/Reference/RendererTest.php | 67 +++++++++++++++++++ 4 files changed, 109 insertions(+), 82 deletions(-) rename src/Appwrite/{Event/Label => Reference}/Renderer.php (65%) delete mode 100644 tests/unit/Event/Label/RendererTest.php create mode 100644 tests/unit/Reference/RendererTest.php diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index c5306f1160..13a72af6a3 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -9,7 +9,6 @@ use Appwrite\Event\Message\Audit as AuditMessage; use Appwrite\Event\Message\Func as FunctionMessage; use Appwrite\Event\Message\Usage as UsageMessage; use Appwrite\Event\Publisher\Audit; -use Appwrite\Event\Label\Renderer as LabelRenderer; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; use Appwrite\Event\Realtime; @@ -19,6 +18,7 @@ use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Functions\EventProcessor; use Appwrite\Platform\Modules\Storage\Config\CacheControl; use Appwrite\Platform\Modules\Storage\Config\StorageCacheControl; +use Appwrite\Reference\Renderer; use Appwrite\SDK\Method; use Appwrite\Usage\Context; use Appwrite\Utopia\Database\Documents\User; @@ -44,15 +44,6 @@ use Utopia\System\System; use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\WhiteList; -$parseLabel = function (string $label, array $responsePayload, array $requestParams, User $user, Document $project): string { - return LabelRenderer::render($label, [ - 'user' => (array) $user, - 'project' => $project, - 'request' => $requestParams, - 'response' => $responsePayload, - ]); -}; - Http::init() ->groups(['api']) ->inject('route') @@ -891,12 +882,18 @@ Http::shutdown() ->inject('auditContext') ->inject('publisherForAudits') ->inject('mode') - ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, User $targetUser, AuditContext $auditContext, Audit $publisherForAudits, string $mode) use ($parseLabel) { + ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, User $targetUser, AuditContext $auditContext, Audit $publisherForAudits, string $mode) { $responsePayload = $response->getPayload(); $pattern = $route->getLabel('audits.resource', null); if (! empty($pattern)) { - $resource = $parseLabel($pattern, $responsePayload, $params, $targetUser, $project); + $renderer = new Renderer([ + 'user' => (array) $targetUser, + 'project' => $project, + 'request' => $params, + 'response' => $responsePayload, + ]); + $resource = $renderer->render($pattern); if (! empty($resource) && $resource !== $pattern) { $auditContext->resource = $resource; } @@ -955,7 +952,7 @@ Http::shutdown() ->inject('user') ->inject('dbForProject') ->inject('authorization') - ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, Database $dbForProject, Authorization $authorization) use ($parseLabel) { + ->action(function (Route $route, array $params, Request $request, Response $response, Document $project, User $user, Database $dbForProject, Authorization $authorization) { if (! $route->getLabel('cache', false)) { return; } @@ -985,11 +982,18 @@ Http::shutdown() $resourcePattern = $route->getLabel('cache.resource', null); $resourceTypePattern = $route->getLabel('cache.resourceType', null); + $renderer = new Renderer([ + 'user' => (array) $user, + 'project' => $project, + 'request' => $requestParams, + 'response' => $data, + ]); + try { $authorization->skip(fn () => $dbForProject->createDocument('cache', new Document([ '$id' => $key, - 'resource' => empty($resourcePattern) ? null : $parseLabel($resourcePattern, $data, $requestParams, $user, $project), - 'resourceType' => empty($resourceTypePattern) ? null : $parseLabel($resourceTypePattern, $data, $requestParams, $user, $project), + 'resource' => empty($resourcePattern) ? null : $renderer->render($resourcePattern), + 'resourceType' => empty($resourceTypePattern) ? null : $renderer->render($resourceTypePattern), 'mimeType' => $response->getContentType(), 'accessedAt' => $now, 'signature' => $signature, diff --git a/src/Appwrite/Event/Label/Renderer.php b/src/Appwrite/Reference/Renderer.php similarity index 65% rename from src/Appwrite/Event/Label/Renderer.php rename to src/Appwrite/Reference/Renderer.php index 42c38b9614..e69716b407 100644 --- a/src/Appwrite/Event/Label/Renderer.php +++ b/src/Appwrite/Reference/Renderer.php @@ -1,38 +1,50 @@ > */ + private array $context; + /** - * Substitute `{namespace.key}` placeholders inside a route label using the - * supplied context. Supported namespaces map to the keys of `$context`; - * an unknown namespace falls back to the `response` payload to preserve - * the historical behaviour of `audits.resource` rendering. - * * @param array|Document|object> $context */ - public static function render(string $template, array $context): string + public function __construct(array $context) + { + $this->context = []; + foreach ($context as $namespace => $bag) { + $this->context[$namespace] = self::asArray($bag); + } + } + + public function render(string $template): string { if ($template === '' || !str_contains($template, '{')) { return $template; } - $fallback = self::asArray($context['response'] ?? []); + $fallback = $this->context['response'] ?? []; preg_match_all('/{([^}]+)}/', $template, $matches); foreach ($matches[1] as $pos => $match) { $find = $matches[0][$pos]; $parts = explode('.', $match, 2); if (count($parts) !== 2) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid resource label template: {$template}"); + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid resource reference template: {$template}"); } [$namespace, $key] = $parts; - $bag = array_key_exists($namespace, $context) ? self::asArray($context[$namespace]) : $fallback; + $bag = $this->context[$namespace] ?? $fallback; if (!array_key_exists($key, $bag)) { continue; } @@ -46,7 +58,7 @@ class Renderer } elseif (is_scalar($value)) { $value = (string) $value; } else { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Cannot stringify label value: {$template}"); + throw new Exception(Exception::GENERAL_SERVER_ERROR, "Cannot stringify reference value: {$template}"); } } diff --git a/tests/unit/Event/Label/RendererTest.php b/tests/unit/Event/Label/RendererTest.php deleted file mode 100644 index f0bd199c63..0000000000 --- a/tests/unit/Event/Label/RendererTest.php +++ /dev/null @@ -1,56 +0,0 @@ - ['databaseId' => 'db1'], - 'response' => ['$id' => 'col9'], - ]); - - $this->assertSame('database/db1/collection/col9', $rendered); - } - - public function testFallsBackToResponseForUnknownNamespace(): void - { - $rendered = Renderer::render('thing/{unknown.id}', [ - 'response' => ['id' => 'r1'], - ]); - - $this->assertSame('thing/r1', $rendered); - } - - public function testSupportsUserAndProjectNamespaces(): void - { - $rendered = Renderer::render('user/{user.$id}/project/{project.$id}', [ - 'user' => ['$id' => 'usr1'], - 'project' => new Document(['$id' => 'prj1']), - ]); - - $this->assertSame('user/usr1/project/prj1', $rendered); - } - - public function testLeavesUnresolvedTokensIntact(): void - { - $rendered = Renderer::render('database/{request.databaseId}', [ - 'request' => [], - ]); - - $this->assertSame('database/{request.databaseId}', $rendered); - } - - public function testShortCircuitsWhenNoTemplate(): void - { - $this->assertSame('database/db1', Renderer::render('database/db1', [])); - $this->assertSame('', Renderer::render('', [])); - } -} diff --git a/tests/unit/Reference/RendererTest.php b/tests/unit/Reference/RendererTest.php new file mode 100644 index 0000000000..b019d0aa42 --- /dev/null +++ b/tests/unit/Reference/RendererTest.php @@ -0,0 +1,67 @@ + ['databaseId' => 'db1'], + 'response' => ['$id' => 'col9'], + ]); + + $this->assertSame( + 'database/db1/collection/col9', + $renderer->render('database/{request.databaseId}/collection/{response.$id}'), + ); + } + + public function testFallsBackToResponseForUnknownNamespace(): void + { + $renderer = new Renderer([ + 'response' => ['id' => 'r1'], + ]); + + $this->assertSame('thing/r1', $renderer->render('thing/{unknown.id}')); + } + + public function testSupportsUserAndProjectNamespaces(): void + { + $renderer = new Renderer([ + 'user' => ['$id' => 'usr1'], + 'project' => new Document(['$id' => 'prj1']), + ]); + + $this->assertSame( + 'user/usr1/project/prj1', + $renderer->render('user/{user.$id}/project/{project.$id}'), + ); + } + + public function testLeavesUnresolvedTokensIntact(): void + { + $renderer = new Renderer([ + 'request' => [], + ]); + + $this->assertSame( + 'database/{request.databaseId}', + $renderer->render('database/{request.databaseId}'), + ); + } + + public function testShortCircuitsWhenNoTemplate(): void + { + $renderer = new Renderer([]); + + $this->assertSame('database/db1', $renderer->render('database/db1')); + $this->assertSame('', $renderer->render('')); + } +} From b31bbefbb4022e1018ac3692b9a4467702cdc2c9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 04:38:07 +0000 Subject: [PATCH 07/12] fix(usage.resource): include fileId on file-specific storage endpoints --- .../Platform/Modules/Storage/Http/Buckets/Files/Create.php | 2 +- .../Platform/Modules/Storage/Http/Buckets/Files/Delete.php | 2 +- .../Modules/Storage/Http/Buckets/Files/Download/Get.php | 2 +- .../Platform/Modules/Storage/Http/Buckets/Files/Get.php | 2 +- .../Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php | 2 +- .../Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php | 2 +- .../Platform/Modules/Storage/Http/Buckets/Files/Update.php | 2 +- .../Platform/Modules/Storage/Http/Buckets/Files/View/Get.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php index 680bdcff63..cf934575c0 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php @@ -62,7 +62,7 @@ class Create extends Action ->label('audits.event', 'file.create') ->label('event', 'buckets.[bucketId].files.[fileId].create') ->label('audits.resource', 'file/{response.$id}') - ->label('usage.resource', 'file/{response.$id}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{response.$id}') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId},chunkId:{chunkId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php index e2d5122305..6b631230c7 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php @@ -42,7 +42,7 @@ class Delete extends Action ->label('event', 'buckets.[bucketId].files.[fileId].delete') ->label('audits.event', 'file.delete') ->label('audits.resource', 'file/{request.fileId}') - ->label('usage.resource', 'file/{request.fileId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php index eab1366e34..e5d82c7aa1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php @@ -43,7 +43,7 @@ class Get extends Action ->desc('Get file for download') ->groups(['api', 'storage']) ->label('scope', 'files.read') - ->label('usage.resource', 'bucket/{request.bucketId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php index 67a6e81186..53ce6fad4f 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Get.php @@ -32,7 +32,7 @@ class Get extends Action ->desc('Get file') ->groups(['api', 'storage']) ->label('scope', 'files.read') - ->label('usage.resource', 'bucket/{request.bucketId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 6a41c55f1e..d856c0456d 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -53,7 +53,7 @@ class Get extends Action ->desc('Get file preview') ->groups(['api', 'storage']) ->label('scope', 'files.read') - ->label('usage.resource', 'bucket/{request.bucketId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('cache', true) ->label('cache.resourceType', 'bucket/{request.bucketId}') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php index 76756d37b8..637d1b22e6 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php @@ -40,7 +40,7 @@ class Get extends Action ->desc('Get file for push notification') ->groups(['api', 'storage']) ->label('scope', 'public') - ->label('usage.resource', 'bucket/{request.bucketId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php index 7758493b7b..c917e21ce8 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Update.php @@ -43,7 +43,7 @@ class Update extends Action ->label('event', 'buckets.[bucketId].files.[fileId].update') ->label('audits.event', 'file.update') ->label('audits.resource', 'file/{response.$id}') - ->label('usage.resource', 'file/{response.$id}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{response.$id}') ->label('sdk', new Method( namespace: 'storage', group: 'files', diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php index 0030639ab1..8214cdbfa1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php @@ -44,7 +44,7 @@ class Get extends Action ->desc('Get file for view') ->groups(['api', 'storage']) ->label('scope', 'files.read') - ->label('usage.resource', 'bucket/{request.bucketId}') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('resourceType', RESOURCE_TYPE_BUCKETS) ->label('sdk', new Method( namespace: 'storage', From 13fd2b946d7e637f8885853db8b1a7d3b3d6fe16 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 05:04:10 +0000 Subject: [PATCH 08/12] feat(usage.resource): tag function/site catalog routes under function/site Templates, runtimes, specifications etc. don't have a functionId or siteId in the URL but should still attribute usage to the function or site service category instead of falling back to project-level. --- .../Platform/Modules/Functions/Http/Functions/XList.php | 1 + src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php | 1 + .../Platform/Modules/Functions/Http/Specifications/XList.php | 1 + src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php | 2 +- .../Platform/Modules/Functions/Http/Templates/XList.php | 1 + src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php | 1 + src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php | 1 + .../Platform/Modules/Sites/Http/Specifications/XList.php | 1 + src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php | 2 +- src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php | 1 + 10 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php index 8e71258501..32f3775107 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php @@ -37,6 +37,7 @@ class XList extends Base ->groups(['api', 'functions']) ->desc('List functions') ->label('scope', 'functions.read') + ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php index 73700e122d..8ae46bd7cc 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php @@ -30,6 +30,7 @@ class XList extends Base ->groups(['api']) ->desc('List runtimes') ->label('scope', 'public') + ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index 8cbff906fa..63442d0b8d 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -31,6 +31,7 @@ class XList extends Base ->groups(['api', 'functions']) ->desc('List specifications') ->label('scope', 'functions.read') + ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php index ab8f068521..357926a0ea 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php @@ -31,7 +31,7 @@ class Get extends Base ->desc('Get function template') ->groups(['api', 'functions']) ->label('scope', 'public') - ->label('usage.resource', 'template/{request.templateId}') + ->label('usage.resource', 'function/{request.templateId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index f334351fef..4ef79271b0 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -35,6 +35,7 @@ class XList extends Base ->desc('List templates') ->groups(['api']) ->label('scope', 'public') + ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index b1f0a5bc1f..9a5e3b0623 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -29,6 +29,7 @@ class XList extends Base ->desc('List frameworks') ->groups(['api']) ->label('scope', 'public') + ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php index 2571043363..8d70720a70 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php @@ -37,6 +37,7 @@ class XList extends Base ->desc('List sites') ->groups(['api', 'sites']) ->label('scope', 'sites.read') + ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index a4f865d859..abbdfbfcd0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -31,6 +31,7 @@ class XList extends Base ->groups(['api', 'sites']) ->desc('List specifications') ->label('scope', 'sites.read') + ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php index e204f7a543..b923ab146d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php @@ -31,7 +31,7 @@ class Get extends Base ->desc('Get site template') ->groups(['api']) ->label('scope', 'public') - ->label('usage.resource', 'template/{request.templateId}') + ->label('usage.resource', 'site/{request.templateId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php index 722cf986f8..335c750d13 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php @@ -34,6 +34,7 @@ class XList extends Base ->desc('List templates') ->groups(['api']) ->label('scope', 'public') + ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', From e4296c2dc713f617b1e7df1e898fa608f32b4395 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 05:22:06 +0000 Subject: [PATCH 09/12] fix(usage.resource): label file-token routes as bucket/{id}/file/{id} /v1/tokens/buckets/:bucketId/files/:fileId is semantically a storage file operation even though its URL prefix is /v1/tokens. The scope strip keyed on URL prefix and dropped the label; restore it with the file-level resource so the network usage rolls up under the file the token targets. --- .../Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php | 1 + .../Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php index 1c2bd692ef..ceb73f0079 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php @@ -42,6 +42,7 @@ class Create extends Action ->label('audits.resource', 'token/{response.$id}') ->label('usage.metric', 'tokens.{scope}.requests.create') ->label('usage.params', ['resourceId:{request.resourceId}', 'resourceType:{request.resourceType}']) + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('abuse-key', 'ip:{ip},method:{method},url:{url},userId:{userId}') ->label('abuse-limit', APP_LIMIT_WRITE_RATE_DEFAULT) ->label('abuse-time', APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT) diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php index 5a93a06f26..65ab108e65 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php @@ -37,6 +37,7 @@ class XList extends Action ->groups(['api', 'tokens']) ->label('scope', 'tokens.read') ->label('usage.metric', 'tokens.requests.read') + ->label('usage.resource', 'bucket/{request.bucketId}/file/{request.fileId}') ->label('sdk', new Method( namespace: 'tokens', group: 'files', From ba7a7113fe1e35e45c292d948293159295f02aed Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 25 Jun 2026 06:47:36 +0000 Subject: [PATCH 10/12] feat(usage): tag /v1/tokens/:tokenId by the file the token targets The Token response model only carries resourceId as a colon-joined "bucketId:fileId" string -- no separate fields to template a label off, and Delete returns 204 with no body anyway. So inject the usage context into Get/Update/Delete, split the resource id after loading the token, and set resourcePath = bucket/{bid}/file/{fid} directly. The cloud Context's setResourcePath then routes the value through the worker exactly like the labelled file-token Create/XList endpoints. CE base Context gets a no-op setResourcePath so the call compiles in CE-only deployments. --- .../Platform/Modules/Tokens/Http/Tokens/Delete.php | 12 +++++++++++- .../Platform/Modules/Tokens/Http/Tokens/Get.php | 12 +++++++++++- .../Platform/Modules/Tokens/Http/Tokens/Update.php | 12 +++++++++++- src/Appwrite/Usage/Context.php | 10 ++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php index a71f2ec726..4fca85e2a2 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Delete.php @@ -8,6 +8,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Usage\Context; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Validator\UID; @@ -58,16 +59,25 @@ class Delete extends Action ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') + ->inject('usage') ->callback($this->action(...)); } - public function action(string $tokenId, Response $response, Database $dbForProject, Event $queueForEvents) + public function action(string $tokenId, Response $response, Database $dbForProject, Event $queueForEvents, Context $usage) { $token = $dbForProject->getDocument('resourceTokens', $tokenId); if ($token->isEmpty()) { throw new Exception(Exception::TOKEN_NOT_FOUND); } + if ($token->getAttribute('resourceType') === TOKENS_RESOURCE_TYPE_FILES) { + $resourceId = (string) $token->getAttribute('resourceId', ''); + [$bucketId, $fileId] = explode(':', $resourceId, 2) + ['', '']; + if ($bucketId !== '' && $fileId !== '') { + $usage->setResourcePath('bucket/' . $bucketId . '/file/' . $fileId); + } + } + $dbForProject->deleteDocument('resourceTokens', $tokenId); $queueForEvents diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php index 0a364683ca..a3a540552c 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Get.php @@ -7,6 +7,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Usage\Context; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Validator\UID; @@ -50,10 +51,11 @@ class Get extends Action ->param('tokenId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Token ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') + ->inject('usage') ->callback($this->action(...)); } - public function action(string $tokenId, Response $response, Database $dbForProject) + public function action(string $tokenId, Response $response, Database $dbForProject, Context $usage) { $token = $dbForProject->getDocument('resourceTokens', $tokenId); @@ -61,6 +63,14 @@ class Get extends Action throw new Exception(Exception::TOKEN_NOT_FOUND); } + if ($token->getAttribute('resourceType') === TOKENS_RESOURCE_TYPE_FILES) { + $resourceId = (string) $token->getAttribute('resourceId', ''); + [$bucketId, $fileId] = explode(':', $resourceId, 2) + ['', '']; + if ($bucketId !== '' && $fileId !== '') { + $usage->setResourcePath('bucket/' . $bucketId . '/file/' . $fileId); + } + } + $response->dynamic($token, Response::MODEL_RESOURCE_TOKEN); } } diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php index 444f49de62..63b2fb098b 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Update.php @@ -8,6 +8,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Usage\Context; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; @@ -61,10 +62,11 @@ class Update extends Action ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') + ->inject('usage') ->callback($this->action(...)); } - public function action(string $tokenId, ?string $expire, Response $response, Database $dbForProject, Event $queueForEvents) + public function action(string $tokenId, ?string $expire, Response $response, Database $dbForProject, Event $queueForEvents, Context $usage) { $token = $dbForProject->getDocument('resourceTokens', $tokenId); @@ -72,6 +74,14 @@ class Update extends Action throw new Exception(Exception::TOKEN_NOT_FOUND); } + if ($token->getAttribute('resourceType') === TOKENS_RESOURCE_TYPE_FILES) { + $resourceId = (string) $token->getAttribute('resourceId', ''); + [$bucketId, $fileId] = explode(':', $resourceId, 2) + ['', '']; + if ($bucketId !== '' && $fileId !== '') { + $usage->setResourcePath('bucket/' . $bucketId . '/file/' . $fileId); + } + } + $token->setAttribute('expire', $expire); $token = $dbForProject->updateDocument('resourceTokens', $tokenId, $token); diff --git a/src/Appwrite/Usage/Context.php b/src/Appwrite/Usage/Context.php index 7283cff836..f095eb4981 100644 --- a/src/Appwrite/Usage/Context.php +++ b/src/Appwrite/Usage/Context.php @@ -61,6 +61,16 @@ class Context return empty($this->metrics) && empty($this->reduce); } + public function setResourcePath(string $path): self + { + return $this; + } + + public function getResourcePath(): string + { + return ''; + } + /** * Reset the context */ From 129f60dc621e2b9609cdbe5a703956ecfe57f15a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 28 Jun 2026 01:33:51 +0000 Subject: [PATCH 11/12] refactor(reference): Renderer takes a Document instead of an array Per review: "Passing an array to construct with no real instructions can get messy. Document param seems sensible." Construction now wraps the request/response/user/project context bag in a Document so the constructor signature is self-describing and consistent with the rest of the codebase. --- app/controllers/shared/api.php | 8 ++++---- src/Appwrite/Reference/Renderer.php | 16 +++------------- tests/unit/Reference/RendererTest.php | 18 +++++++++--------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index a6b2a769c3..0eec29b7fa 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -899,12 +899,12 @@ Http::shutdown() $pattern = $route->getLabel('audits.resource', null); if (! empty($pattern)) { - $renderer = new Renderer([ + $renderer = new Renderer(new Document([ 'user' => (array) $targetUser, 'project' => $project, 'request' => $params, 'response' => $responsePayload, - ]); + ])); $resource = $renderer->render($pattern); if (! empty($resource) && $resource !== $pattern) { $auditContext->resource = $resource; @@ -994,12 +994,12 @@ Http::shutdown() $resourcePattern = $route->getLabel('cache.resource', null); $resourceTypePattern = $route->getLabel('cache.resourceType', null); - $renderer = new Renderer([ + $renderer = new Renderer(new Document([ 'user' => (array) $user, 'project' => $project, 'request' => $requestParams, 'response' => $data, - ]); + ])); try { $authorization->skip(fn () => $dbForProject->createDocument('cache', new Document([ diff --git a/src/Appwrite/Reference/Renderer.php b/src/Appwrite/Reference/Renderer.php index e69716b407..841560dd1a 100644 --- a/src/Appwrite/Reference/Renderer.php +++ b/src/Appwrite/Reference/Renderer.php @@ -13,18 +13,8 @@ use Utopia\Database\Document; */ class Renderer { - /** @var array> */ - private array $context; - - /** - * @param array|Document|object> $context - */ - public function __construct(array $context) + public function __construct(private readonly Document $context) { - $this->context = []; - foreach ($context as $namespace => $bag) { - $this->context[$namespace] = self::asArray($bag); - } } public function render(string $template): string @@ -33,7 +23,7 @@ class Renderer return $template; } - $fallback = $this->context['response'] ?? []; + $fallback = self::asArray($this->context->getAttribute('response', [])); preg_match_all('/{([^}]+)}/', $template, $matches); foreach ($matches[1] as $pos => $match) { @@ -44,7 +34,7 @@ class Renderer } [$namespace, $key] = $parts; - $bag = $this->context[$namespace] ?? $fallback; + $bag = self::asArray($this->context->getAttribute($namespace, $fallback)); if (!array_key_exists($key, $bag)) { continue; } diff --git a/tests/unit/Reference/RendererTest.php b/tests/unit/Reference/RendererTest.php index b019d0aa42..ac284103cc 100644 --- a/tests/unit/Reference/RendererTest.php +++ b/tests/unit/Reference/RendererTest.php @@ -12,10 +12,10 @@ final class RendererTest extends TestCase { public function testSubstitutesRequestAndResponseNamespaces(): void { - $renderer = new Renderer([ + $renderer = new Renderer(new Document([ 'request' => ['databaseId' => 'db1'], 'response' => ['$id' => 'col9'], - ]); + ])); $this->assertSame( 'database/db1/collection/col9', @@ -25,19 +25,19 @@ final class RendererTest extends TestCase public function testFallsBackToResponseForUnknownNamespace(): void { - $renderer = new Renderer([ + $renderer = new Renderer(new Document([ 'response' => ['id' => 'r1'], - ]); + ])); $this->assertSame('thing/r1', $renderer->render('thing/{unknown.id}')); } public function testSupportsUserAndProjectNamespaces(): void { - $renderer = new Renderer([ + $renderer = new Renderer(new Document([ 'user' => ['$id' => 'usr1'], 'project' => new Document(['$id' => 'prj1']), - ]); + ])); $this->assertSame( 'user/usr1/project/prj1', @@ -47,9 +47,9 @@ final class RendererTest extends TestCase public function testLeavesUnresolvedTokensIntact(): void { - $renderer = new Renderer([ + $renderer = new Renderer(new Document([ 'request' => [], - ]); + ])); $this->assertSame( 'database/{request.databaseId}', @@ -59,7 +59,7 @@ final class RendererTest extends TestCase public function testShortCircuitsWhenNoTemplate(): void { - $renderer = new Renderer([]); + $renderer = new Renderer(new Document([])); $this->assertSame('database/db1', $renderer->render('database/db1')); $this->assertSame('', $renderer->render('')); From 2944259ad3ec9a067d57a9d0ef95c9162039c636 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 28 Jun 2026 01:37:10 +0000 Subject: [PATCH 12/12] revert(usage.resource): drop catalog-route labels per review Function/site templates, runtimes, specifications, frameworks and the top-level Functions/Sites XList don't point at a specific resource - the existing `service` dimension already groups them. Letting the labels through would forge a "function" / "site" resource id that doesn't map to a real entity. --- src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php | 1 - src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php | 1 - .../Platform/Modules/Functions/Http/Specifications/XList.php | 1 - src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php | 1 - src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php | 1 - .../Platform/Modules/Sites/Http/Specifications/XList.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php | 1 - src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php | 1 - 10 files changed, 10 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php index 32f3775107..8e71258501 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php @@ -37,7 +37,6 @@ class XList extends Base ->groups(['api', 'functions']) ->desc('List functions') ->label('scope', 'functions.read') - ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php index 8ae46bd7cc..73700e122d 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Runtimes/XList.php @@ -30,7 +30,6 @@ class XList extends Base ->groups(['api']) ->desc('List runtimes') ->label('scope', 'public') - ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index 63442d0b8d..8cbff906fa 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -31,7 +31,6 @@ class XList extends Base ->groups(['api', 'functions']) ->desc('List specifications') ->label('scope', 'functions.read') - ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php index 357926a0ea..f66322839b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php @@ -31,7 +31,6 @@ class Get extends Base ->desc('Get function template') ->groups(['api', 'functions']) ->label('scope', 'public') - ->label('usage.resource', 'function/{request.templateId}') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index 4ef79271b0..f334351fef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -35,7 +35,6 @@ class XList extends Base ->desc('List templates') ->groups(['api']) ->label('scope', 'public') - ->label('usage.resource', 'function') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index 9a5e3b0623..b1f0a5bc1f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -29,7 +29,6 @@ class XList extends Base ->desc('List frameworks') ->groups(['api']) ->label('scope', 'public') - ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php index 8d70720a70..2571043363 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php @@ -37,7 +37,6 @@ class XList extends Base ->desc('List sites') ->groups(['api', 'sites']) ->label('scope', 'sites.read') - ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index abbdfbfcd0..a4f865d859 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -31,7 +31,6 @@ class XList extends Base ->groups(['api', 'sites']) ->desc('List specifications') ->label('scope', 'sites.read') - ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php index b923ab146d..633ef31e68 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php @@ -31,7 +31,6 @@ class Get extends Base ->desc('Get site template') ->groups(['api']) ->label('scope', 'public') - ->label('usage.resource', 'site/{request.templateId}') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php index 335c750d13..722cf986f8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php @@ -34,7 +34,6 @@ class XList extends Base ->desc('List templates') ->groups(['api']) ->label('scope', 'public') - ->label('usage.resource', 'site') ->label('resourceType', RESOURCE_TYPE_SITES) ->label('sdk', new Method( namespace: 'sites',