diff --git a/CHANGELOG.md b/CHANGELOG.md index 244095f..d4c557f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,20 @@ ## 21.0.0 -* Breaking: Updated createDeployment signature and relationship attribute endpoint path -* Added TTL parameter support to listDocuments and listRows -* Added getConsolePausing health endpoint to Health service +* [BREAKING] Changed `$sequence` type from `int` to `string` for rows and documents +* [BREAKING] Renamed `IndexType` enum: split into `DatabasesIndexType` (for Databases) and `TablesDBIndexType` (for TablesDB) +* [BREAKING] Replaced `specification` parameter with `buildSpecification` and `runtimeSpecification` in `Functions::create()`, `Functions::update()`, `Sites::create()`, `Sites::update()` +* Added new `Project` service with full CRUD for project-level environment variables +* Added new `Webhooks` service with full CRUD for project webhooks (including `updateSignature`) +* Added `Users::updateImpersonator()` method for enabling/disabling user impersonation +* Added impersonation support: `setImpersonateUserId()`, `setImpersonateUserEmail()`, `setImpersonateUserPhone()` on `Client` +* Added `deploymentRetention` parameter to Functions and Sites create/update +* Added `startCommand` parameter to Sites create/update +* Added `Documentsdb`, `Vectorsdb` values to `BackupServices` and `DatabaseType` enums +* Added `WebhooksRead`, `WebhooksWrite`, `ProjectRead`, `ProjectWrite` scopes +* Removed `getQueueBillingProjectAggregation`, `getQueueBillingTeamAggregation`, `getQueuePriorityBuilds`, `getQueueRegionManager`, `getQueueThreats` from `Health` service +* Updated `Log` model field descriptions to clarify impersonation behavior +* Updated `X-Appwrite-Response-Format` header to `1.9.0` ## 20.2.0 diff --git a/README.md b/README.md index 9713e5d..685f6e8 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite PHP SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-php.svg?style=flat-square&v=1) -![Version](https://img.shields.io/badge/api%20version-1.8.1-blue.svg?style=flat-square&v=1) +![Version](https://img.shields.io/badge/api%20version-1.9.0-blue.svg?style=flat-square&v=1) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-php/releases).** +**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-php/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the PHP SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/databases/create-index.md b/docs/examples/databases/create-index.md index 39b3722..9ecf25a 100644 --- a/docs/examples/databases/create-index.md +++ b/docs/examples/databases/create-index.md @@ -3,7 +3,7 @@ use Appwrite\Client; use Appwrite\Services\Databases; -use Appwrite\Enums\IndexType; +use Appwrite\Enums\DatabasesIndexType; use Appwrite\Enums\OrderBy; $client = (new Client()) @@ -17,7 +17,7 @@ $result = $databases->createIndex( databaseId: '', collectionId: '', key: '', - type: IndexType::KEY(), + type: DatabasesIndexType::KEY(), attributes: [], orders: [OrderBy::ASC()], // optional lengths: [] // optional diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index e921e99..958a4aa 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -31,5 +31,7 @@ $result = $functions->create( providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional );``` diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index f9bdac1..56e66b5 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -31,5 +31,7 @@ $result = $functions->update( providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional );``` diff --git a/docs/examples/project/create-variable.md b/docs/examples/project/create-variable.md new file mode 100644 index 0000000..9f6d65e --- /dev/null +++ b/docs/examples/project/create-variable.md @@ -0,0 +1,19 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createVariable( + variableId: '', + key: '', + value: '', + secret: false // optional +);``` diff --git a/docs/examples/project/delete-variable.md b/docs/examples/project/delete-variable.md new file mode 100644 index 0000000..a6fb65a --- /dev/null +++ b/docs/examples/project/delete-variable.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->deleteVariable( + variableId: '' +);``` diff --git a/docs/examples/project/get-variable.md b/docs/examples/project/get-variable.md new file mode 100644 index 0000000..f80cd3b --- /dev/null +++ b/docs/examples/project/get-variable.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->getVariable( + variableId: '' +);``` diff --git a/docs/examples/project/list-variables.md b/docs/examples/project/list-variables.md new file mode 100644 index 0000000..f6a9bb4 --- /dev/null +++ b/docs/examples/project/list-variables.md @@ -0,0 +1,17 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->listVariables( + queries: [], // optional + total: false // optional +);``` diff --git a/docs/examples/project/update-variable.md b/docs/examples/project/update-variable.md new file mode 100644 index 0000000..3e44129 --- /dev/null +++ b/docs/examples/project/update-variable.md @@ -0,0 +1,19 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateVariable( + variableId: '', + key: '', // optional + value: '', // optional + secret: false // optional +);``` diff --git a/docs/examples/sites/create.md b/docs/examples/sites/create.md index 9191261..866a89c 100644 --- a/docs/examples/sites/create.md +++ b/docs/examples/sites/create.md @@ -24,6 +24,7 @@ $result = $sites->create( timeout: 1, // optional installCommand: '', // optional buildCommand: '', // optional + startCommand: '', // optional outputDirectory: '', // optional adapter: Adapter::STATIC(), // optional installationId: '', // optional @@ -32,5 +33,7 @@ $result = $sites->create( providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional );``` diff --git a/docs/examples/sites/update.md b/docs/examples/sites/update.md index 42d24fb..b2de5a2 100644 --- a/docs/examples/sites/update.md +++ b/docs/examples/sites/update.md @@ -23,6 +23,7 @@ $result = $sites->update( timeout: 1, // optional installCommand: '', // optional buildCommand: '', // optional + startCommand: '', // optional outputDirectory: '', // optional buildRuntime: BuildRuntime::NODE145(), // optional adapter: Adapter::STATIC(), // optional @@ -32,5 +33,7 @@ $result = $sites->update( providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional );``` diff --git a/docs/examples/tablesdb/create-index.md b/docs/examples/tablesdb/create-index.md index c91356f..3cd6b12 100644 --- a/docs/examples/tablesdb/create-index.md +++ b/docs/examples/tablesdb/create-index.md @@ -3,7 +3,7 @@ use Appwrite\Client; use Appwrite\Services\TablesDB; -use Appwrite\Enums\IndexType; +use Appwrite\Enums\TablesDBIndexType; use Appwrite\Enums\OrderBy; $client = (new Client()) @@ -17,7 +17,7 @@ $result = $tablesDB->createIndex( databaseId: '', tableId: '', key: '', - type: IndexType::KEY(), + type: TablesDBIndexType::KEY(), columns: [], orders: [OrderBy::ASC()], // optional lengths: [] // optional diff --git a/docs/examples/users/update-impersonator.md b/docs/examples/users/update-impersonator.md new file mode 100644 index 0000000..202f0ed --- /dev/null +++ b/docs/examples/users/update-impersonator.md @@ -0,0 +1,17 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$users = new Users($client); + +$result = $users->updateImpersonator( + userId: '', + impersonator: false +);``` diff --git a/docs/examples/webhooks/create.md b/docs/examples/webhooks/create.md new file mode 100644 index 0000000..008a816 --- /dev/null +++ b/docs/examples/webhooks/create.md @@ -0,0 +1,23 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$webhooks = new Webhooks($client); + +$result = $webhooks->create( + webhookId: '', + url: '', + name: '', + events: [], + enabled: false, // optional + security: false, // optional + httpUser: '', // optional + httpPass: '' // optional +);``` diff --git a/docs/examples/webhooks/delete.md b/docs/examples/webhooks/delete.md new file mode 100644 index 0000000..cab1063 --- /dev/null +++ b/docs/examples/webhooks/delete.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$webhooks = new Webhooks($client); + +$result = $webhooks->delete( + webhookId: '' +);``` diff --git a/docs/examples/webhooks/get.md b/docs/examples/webhooks/get.md new file mode 100644 index 0000000..c8acae7 --- /dev/null +++ b/docs/examples/webhooks/get.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$webhooks = new Webhooks($client); + +$result = $webhooks->get( + webhookId: '' +);``` diff --git a/docs/examples/webhooks/list.md b/docs/examples/webhooks/list.md new file mode 100644 index 0000000..7727c46 --- /dev/null +++ b/docs/examples/webhooks/list.md @@ -0,0 +1,17 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$webhooks = new Webhooks($client); + +$result = $webhooks->list( + queries: [], // optional + total: false // optional +);``` diff --git a/docs/examples/webhooks/update-signature.md b/docs/examples/webhooks/update-signature.md new file mode 100644 index 0000000..5101085 --- /dev/null +++ b/docs/examples/webhooks/update-signature.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$webhooks = new Webhooks($client); + +$result = $webhooks->updateSignature( + webhookId: '' +);``` diff --git a/docs/examples/webhooks/update.md b/docs/examples/webhooks/update.md new file mode 100644 index 0000000..b253b1f --- /dev/null +++ b/docs/examples/webhooks/update.md @@ -0,0 +1,23 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$webhooks = new Webhooks($client); + +$result = $webhooks->update( + webhookId: '', + name: '', + url: '', + events: [], + enabled: false, // optional + security: false, // optional + httpUser: '', // optional + httpPass: '' // optional +);``` diff --git a/docs/functions.md b/docs/functions.md index fbcc10c..baaf38b 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -43,7 +43,9 @@ POST https://cloud.appwrite.io/v1/functions | providerBranch | string | Production branch for the repo linked to the function. | | | providerSilentMode | boolean | Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. | | | providerRootDirectory | string | Path to function code in the linked repo. | | -| specification | string | Runtime specification for the function and builds. | [] | +| buildSpecification | string | Build specification for the function deployments. | [] | +| runtimeSpecification | string | Runtime specification for the function executions. | [] | +| deploymentRetention | integer | Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. | 0 | ```http request @@ -100,7 +102,9 @@ PUT https://cloud.appwrite.io/v1/functions/{functionId} | providerBranch | string | Production branch for the repo linked to the function | | | providerSilentMode | boolean | Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. | | | providerRootDirectory | string | Path to function code in the linked repo. | | -| specification | string | Runtime specification for the function and builds. | [] | +| buildSpecification | string | Build specification for the function deployments. | [] | +| runtimeSpecification | string | Runtime specification for the function executions. | [] | +| deploymentRetention | integer | Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. | 0 | ```http request diff --git a/docs/health.md b/docs/health.md index fedaa15..ead6d70 100644 --- a/docs/health.md +++ b/docs/health.md @@ -77,32 +77,6 @@ GET https://cloud.appwrite.io/v1/health/queue/audits | threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. | 5000 | -```http request -GET https://cloud.appwrite.io/v1/health/queue/billing-project-aggregation -``` - -** Get billing project aggregation queue. ** - -### Parameters - -| Field Name | Type | Description | Default | -| --- | --- | --- | --- | -| threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. | 10000 | - - -```http request -GET https://cloud.appwrite.io/v1/health/queue/billing-team-aggregation -``` - -** Get billing team aggregation queue. ** - -### Parameters - -| Field Name | Type | Description | Default | -| --- | --- | --- | --- | -| threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. | 10000 | - - ```http request GET https://cloud.appwrite.io/v1/health/queue/builds ``` @@ -116,19 +90,6 @@ GET https://cloud.appwrite.io/v1/health/queue/builds | threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. | 5000 | -```http request -GET https://cloud.appwrite.io/v1/health/queue/builds-priority -``` - -** Get the priority builds queue size. ** - -### Parameters - -| Field Name | Type | Description | Default | -| --- | --- | --- | --- | -| threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 500. | 500 | - - ```http request GET https://cloud.appwrite.io/v1/health/queue/certificates ``` @@ -249,19 +210,6 @@ GET https://cloud.appwrite.io/v1/health/queue/migrations | threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. | 5000 | -```http request -GET https://cloud.appwrite.io/v1/health/queue/region-manager -``` - -** Get region manager queue. ** - -### Parameters - -| Field Name | Type | Description | Default | -| --- | --- | --- | --- | -| threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 100. | 100 | - - ```http request GET https://cloud.appwrite.io/v1/health/queue/stats-resources ``` @@ -288,19 +236,6 @@ GET https://cloud.appwrite.io/v1/health/queue/stats-usage | threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. | 5000 | -```http request -GET https://cloud.appwrite.io/v1/health/queue/threats -``` - -** Get threats queue. ** - -### Parameters - -| Field Name | Type | Description | Default | -| --- | --- | --- | --- | -| threshold | integer | Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 100. | 100 | - - ```http request GET https://cloud.appwrite.io/v1/health/queue/webhooks ``` diff --git a/docs/project.md b/docs/project.md new file mode 100644 index 0000000..eb7e26a --- /dev/null +++ b/docs/project.md @@ -0,0 +1,74 @@ +# Project Service + + +```http request +GET https://cloud.appwrite.io/v1/project/variables +``` + +** Get a list of all project environment variables. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key, resourceType, resourceId, secret | [] | +| total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | + + +```http request +POST https://cloud.appwrite.io/v1/project/variables +``` + +** Create a new project environment variable. These variables can be accessed by all functions and sites in the project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| variableId | string | Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| key | string | Variable key. Max length: 255 chars. | | +| value | string | Variable value. Max length: 8192 chars. | | +| secret | boolean | Secret variables can be updated or deleted, but only projects can read them during build and runtime. | 1 | + + +```http request +GET https://cloud.appwrite.io/v1/project/variables/{variableId} +``` + +** Get a variable by its unique ID. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| variableId | string | **Required** Variable ID. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/variables/{variableId} +``` + +** Update variable by its unique ID. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| variableId | string | **Required** Variable ID. | | +| key | string | Variable key. Max length: 255 chars. | | +| value | string | Variable value. Max length: 8192 chars. | | +| secret | boolean | Secret variables can be updated or deleted, but only projects can read them during build and runtime. | | + + +```http request +DELETE https://cloud.appwrite.io/v1/project/variables/{variableId} +``` + +** Delete a variable by its unique ID. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| variableId | string | **Required** Variable ID. | | + diff --git a/docs/sites.md b/docs/sites.md index e277092..a298449 100644 --- a/docs/sites.md +++ b/docs/sites.md @@ -34,6 +34,7 @@ POST https://cloud.appwrite.io/v1/sites | timeout | integer | Maximum request time in seconds. | 30 | | installCommand | string | Install Command. | | | buildCommand | string | Build Command. | | +| startCommand | string | Custom start command. Leave empty to use default. | | | outputDirectory | string | Output Directory for site. | | | buildRuntime | string | Runtime to use during build step. | | | adapter | string | Framework adapter defining rendering strategy. Allowed values are: static, ssr | | @@ -43,7 +44,9 @@ POST https://cloud.appwrite.io/v1/sites | providerBranch | string | Production branch for the repo linked to the site. | | | providerSilentMode | boolean | Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests. | | | providerRootDirectory | string | Path to site code in the linked repo. | | -| specification | string | Framework specification for the site and builds. | [] | +| buildSpecification | string | Build specification for the site deployments. | [] | +| runtimeSpecification | string | Runtime specification for the SSR executions. | [] | +| deploymentRetention | integer | Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. | 0 | ```http request @@ -91,6 +94,7 @@ PUT https://cloud.appwrite.io/v1/sites/{siteId} | timeout | integer | Maximum request time in seconds. | 30 | | installCommand | string | Install Command. | | | buildCommand | string | Build Command. | | +| startCommand | string | Custom start command. Leave empty to use default. | | | outputDirectory | string | Output Directory for site. | | | buildRuntime | string | Runtime to use during build step. | | | adapter | string | Framework adapter defining rendering strategy. Allowed values are: static, ssr | | @@ -100,7 +104,9 @@ PUT https://cloud.appwrite.io/v1/sites/{siteId} | providerBranch | string | Production branch for the repo linked to the site. | | | providerSilentMode | boolean | Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests. | | | providerRootDirectory | string | Path to site code in the linked repo. | | -| specification | string | Framework specification for the site and builds. | [] | +| buildSpecification | string | Build specification for the site deployments. | [] | +| runtimeSpecification | string | Runtime specification for the SSR executions. | [] | +| deploymentRetention | integer | Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. | 0 | ```http request diff --git a/docs/users.md b/docs/users.md index 284239e..5c24626 100644 --- a/docs/users.md +++ b/docs/users.md @@ -11,7 +11,7 @@ GET https://cloud.appwrite.io/v1/users | Field Name | Type | Description | Default | | --- | --- | --- | --- | -| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels | [] | +| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels, impersonator | [] | | search | string | Search term to filter your list results. Max length: 256 chars. | | | total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | @@ -222,6 +222,21 @@ PATCH https://cloud.appwrite.io/v1/users/{userId}/email | email | string | User email. | | +```http request +PATCH https://cloud.appwrite.io/v1/users/{userId}/impersonator +``` + +** Enable or disable whether a user can impersonate other users. When impersonation headers are used, the request runs as the target user for API behavior, while internal audit logs still attribute the action to the original impersonator and store the impersonated target details only in internal audit payload data. + ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| userId | string | **Required** User ID. | | +| impersonator | boolean | Whether the user can impersonate other users. When true, the user can browse project users to choose a target and can pass impersonation headers to act as that user. Internal audit logs still attribute impersonated actions to the original impersonator and store the target user details only in internal audit payload data. | | + + ```http request POST https://cloud.appwrite.io/v1/users/{userId}/jwts ``` diff --git a/docs/webhooks.md b/docs/webhooks.md new file mode 100644 index 0000000..685b5cb --- /dev/null +++ b/docs/webhooks.md @@ -0,0 +1,95 @@ +# Webhooks Service + + +```http request +GET https://cloud.appwrite.io/v1/webhooks +``` + +** Get a list of all webhooks belonging to the project. You can use the query params to filter your results. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, httpUser, security, events, enabled, logs, attempts | [] | +| total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | + + +```http request +POST https://cloud.appwrite.io/v1/webhooks +``` + +** Create a new webhook. Use this endpoint to configure a URL that will receive events from Appwrite when specific events occur. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| webhookId | string | Webhook ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| url | string | Webhook URL. | | +| name | string | Webhook name. Max length: 128 chars. | | +| events | array | Events list. Maximum of 100 events are allowed. | | +| enabled | boolean | Enable or disable a webhook. | 1 | +| security | boolean | Certificate verification, false for disabled or true for enabled. | | +| httpUser | string | Webhook HTTP user. Max length: 256 chars. | | +| httpPass | string | Webhook HTTP password. Max length: 256 chars. | | + + +```http request +GET https://cloud.appwrite.io/v1/webhooks/{webhookId} +``` + +** Get a webhook by its unique ID. This endpoint returns details about a specific webhook configured for a project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| webhookId | string | **Required** Webhook ID. | | + + +```http request +PUT https://cloud.appwrite.io/v1/webhooks/{webhookId} +``` + +** Update a webhook by its unique ID. Use this endpoint to update the URL, events, or status of an existing webhook. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| webhookId | string | **Required** Webhook ID. | | +| name | string | Webhook name. Max length: 128 chars. | | +| url | string | Webhook URL. | | +| events | array | Events list. Maximum of 100 events are allowed. | | +| enabled | boolean | Enable or disable a webhook. | 1 | +| security | boolean | Certificate verification, false for disabled or true for enabled. | | +| httpUser | string | Webhook HTTP user. Max length: 256 chars. | | +| httpPass | string | Webhook HTTP password. Max length: 256 chars. | | + + +```http request +DELETE https://cloud.appwrite.io/v1/webhooks/{webhookId} +``` + +** Delete a webhook by its unique ID. Once deleted, the webhook will no longer receive project events. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| webhookId | string | **Required** Webhook ID. | | + + +```http request +PATCH https://cloud.appwrite.io/v1/webhooks/{webhookId}/signature +``` + +** Update the webhook signature key. This endpoint can be used to regenerate the signature key used to sign and validate payload deliveries for a specific webhook. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| webhookId | string | **Required** Webhook ID. | | + diff --git a/src/Appwrite/Client.php b/src/Appwrite/Client.php index 6bf10df..db61a29 100644 --- a/src/Appwrite/Client.php +++ b/src/Appwrite/Client.php @@ -37,11 +37,11 @@ class Client */ protected array $headers = [ 'content-type' => '', - 'user-agent' => 'AppwritePHPSDK/20.2.1 ()', + 'user-agent' => 'AppwritePHPSDK/21.0.0 ()', 'x-sdk-name'=> 'PHP', 'x-sdk-platform'=> 'server', 'x-sdk-language'=> 'php', - 'x-sdk-version'=> '20.2.1', + 'x-sdk-version'=> '21.0.0', ]; /** @@ -63,7 +63,7 @@ class Client */ public function __construct() { - $this->headers['X-Appwrite-Response-Format'] = '1.8.0'; + $this->headers['X-Appwrite-Response-Format'] = '1.9.0'; } @@ -161,6 +161,54 @@ public function setForwardedUserAgent(string $value): Client return $this; } + /** + * Set ImpersonateUserId + * + * Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * + * @param string $value + * + * @return Client + */ + public function setImpersonateUserId(string $value): Client + { + $this->addHeader('X-Appwrite-Impersonate-User-Id', $value); + + return $this; + } + + /** + * Set ImpersonateUserEmail + * + * Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * + * @param string $value + * + * @return Client + */ + public function setImpersonateUserEmail(string $value): Client + { + $this->addHeader('X-Appwrite-Impersonate-User-Email', $value); + + return $this; + } + + /** + * Set ImpersonateUserPhone + * + * Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * + * @param string $value + * + * @return Client + */ + public function setImpersonateUserPhone(string $value): Client + { + $this->addHeader('X-Appwrite-Impersonate-User-Phone', $value); + + return $this; + } + /*** * @param bool $status diff --git a/src/Appwrite/Enums/BackupServices.php b/src/Appwrite/Enums/BackupServices.php index 8eb096d..326d361 100644 --- a/src/Appwrite/Enums/BackupServices.php +++ b/src/Appwrite/Enums/BackupServices.php @@ -7,6 +7,9 @@ class BackupServices implements JsonSerializable { private static BackupServices $DATABASES; + private static BackupServices $TABLESDB; + private static BackupServices $DOCUMENTSDB; + private static BackupServices $VECTORSDB; private static BackupServices $FUNCTIONS; private static BackupServices $STORAGE; @@ -34,6 +37,27 @@ public static function DATABASES(): BackupServices } return self::$DATABASES; } + public static function TABLESDB(): BackupServices + { + if (!isset(self::$TABLESDB)) { + self::$TABLESDB = new BackupServices('tablesdb'); + } + return self::$TABLESDB; + } + public static function DOCUMENTSDB(): BackupServices + { + if (!isset(self::$DOCUMENTSDB)) { + self::$DOCUMENTSDB = new BackupServices('documentsdb'); + } + return self::$DOCUMENTSDB; + } + public static function VECTORSDB(): BackupServices + { + if (!isset(self::$VECTORSDB)) { + self::$VECTORSDB = new BackupServices('vectorsdb'); + } + return self::$VECTORSDB; + } public static function FUNCTIONS(): BackupServices { if (!isset(self::$FUNCTIONS)) { diff --git a/src/Appwrite/Enums/DatabaseType.php b/src/Appwrite/Enums/DatabaseType.php index 7fcf5ac..ccbc5c0 100644 --- a/src/Appwrite/Enums/DatabaseType.php +++ b/src/Appwrite/Enums/DatabaseType.php @@ -8,6 +8,8 @@ class DatabaseType implements JsonSerializable { private static DatabaseType $LEGACY; private static DatabaseType $TABLESDB; + private static DatabaseType $DOCUMENTSDB; + private static DatabaseType $VECTORSDB; private string $value; @@ -40,4 +42,18 @@ public static function TABLESDB(): DatabaseType } return self::$TABLESDB; } + public static function DOCUMENTSDB(): DatabaseType + { + if (!isset(self::$DOCUMENTSDB)) { + self::$DOCUMENTSDB = new DatabaseType('documentsdb'); + } + return self::$DOCUMENTSDB; + } + public static function VECTORSDB(): DatabaseType + { + if (!isset(self::$VECTORSDB)) { + self::$VECTORSDB = new DatabaseType('vectorsdb'); + } + return self::$VECTORSDB; + } } \ No newline at end of file diff --git a/src/Appwrite/Enums/DatabasesIndexType.php b/src/Appwrite/Enums/DatabasesIndexType.php new file mode 100644 index 0000000..e4b061d --- /dev/null +++ b/src/Appwrite/Enums/DatabasesIndexType.php @@ -0,0 +1,59 @@ +value = $value; + } + + public function __toString(): string + { + return $this->value; + } + + public function jsonSerialize(): string + { + return $this->value; + } + + public static function KEY(): DatabasesIndexType + { + if (!isset(self::$KEY)) { + self::$KEY = new DatabasesIndexType('key'); + } + return self::$KEY; + } + public static function FULLTEXT(): DatabasesIndexType + { + if (!isset(self::$FULLTEXT)) { + self::$FULLTEXT = new DatabasesIndexType('fulltext'); + } + return self::$FULLTEXT; + } + public static function UNIQUE(): DatabasesIndexType + { + if (!isset(self::$UNIQUE)) { + self::$UNIQUE = new DatabasesIndexType('unique'); + } + return self::$UNIQUE; + } + public static function SPATIAL(): DatabasesIndexType + { + if (!isset(self::$SPATIAL)) { + self::$SPATIAL = new DatabasesIndexType('spatial'); + } + return self::$SPATIAL; + } +} \ No newline at end of file diff --git a/src/Appwrite/Enums/Scopes.php b/src/Appwrite/Enums/Scopes.php index e9478f1..1f2165e 100644 --- a/src/Appwrite/Enums/Scopes.php +++ b/src/Appwrite/Enums/Scopes.php @@ -63,6 +63,10 @@ class Scopes implements JsonSerializable private static Scopes $ASSISTANTREAD; private static Scopes $TOKENSREAD; private static Scopes $TOKENSWRITE; + private static Scopes $WEBHOOKSREAD; + private static Scopes $WEBHOOKSWRITE; + private static Scopes $PROJECTREAD; + private static Scopes $PROJECTWRITE; private static Scopes $POLICIESWRITE; private static Scopes $POLICIESREAD; private static Scopes $ARCHIVESREAD; @@ -489,6 +493,34 @@ public static function TOKENSWRITE(): Scopes } return self::$TOKENSWRITE; } + public static function WEBHOOKSREAD(): Scopes + { + if (!isset(self::$WEBHOOKSREAD)) { + self::$WEBHOOKSREAD = new Scopes('webhooks.read'); + } + return self::$WEBHOOKSREAD; + } + public static function WEBHOOKSWRITE(): Scopes + { + if (!isset(self::$WEBHOOKSWRITE)) { + self::$WEBHOOKSWRITE = new Scopes('webhooks.write'); + } + return self::$WEBHOOKSWRITE; + } + public static function PROJECTREAD(): Scopes + { + if (!isset(self::$PROJECTREAD)) { + self::$PROJECTREAD = new Scopes('project.read'); + } + return self::$PROJECTREAD; + } + public static function PROJECTWRITE(): Scopes + { + if (!isset(self::$PROJECTWRITE)) { + self::$PROJECTWRITE = new Scopes('project.write'); + } + return self::$PROJECTWRITE; + } public static function POLICIESWRITE(): Scopes { if (!isset(self::$POLICIESWRITE)) { diff --git a/src/Appwrite/Enums/IndexType.php b/src/Appwrite/Enums/TablesDBIndexType.php similarity index 50% rename from src/Appwrite/Enums/IndexType.php rename to src/Appwrite/Enums/TablesDBIndexType.php index 16d0433..f82b337 100644 --- a/src/Appwrite/Enums/IndexType.php +++ b/src/Appwrite/Enums/TablesDBIndexType.php @@ -4,12 +4,12 @@ use JsonSerializable; -class IndexType implements JsonSerializable +class TablesDBIndexType implements JsonSerializable { - private static IndexType $KEY; - private static IndexType $FULLTEXT; - private static IndexType $UNIQUE; - private static IndexType $SPATIAL; + private static TablesDBIndexType $KEY; + private static TablesDBIndexType $FULLTEXT; + private static TablesDBIndexType $UNIQUE; + private static TablesDBIndexType $SPATIAL; private string $value; @@ -28,31 +28,31 @@ public function jsonSerialize(): string return $this->value; } - public static function KEY(): IndexType + public static function KEY(): TablesDBIndexType { if (!isset(self::$KEY)) { - self::$KEY = new IndexType('key'); + self::$KEY = new TablesDBIndexType('key'); } return self::$KEY; } - public static function FULLTEXT(): IndexType + public static function FULLTEXT(): TablesDBIndexType { if (!isset(self::$FULLTEXT)) { - self::$FULLTEXT = new IndexType('fulltext'); + self::$FULLTEXT = new TablesDBIndexType('fulltext'); } return self::$FULLTEXT; } - public static function UNIQUE(): IndexType + public static function UNIQUE(): TablesDBIndexType { if (!isset(self::$UNIQUE)) { - self::$UNIQUE = new IndexType('unique'); + self::$UNIQUE = new TablesDBIndexType('unique'); } return self::$UNIQUE; } - public static function SPATIAL(): IndexType + public static function SPATIAL(): TablesDBIndexType { if (!isset(self::$SPATIAL)) { - self::$SPATIAL = new IndexType('spatial'); + self::$SPATIAL = new TablesDBIndexType('spatial'); } return self::$SPATIAL; } diff --git a/src/Appwrite/Enums/TemplateReferenceType.php b/src/Appwrite/Enums/TemplateReferenceType.php index 7d3e22f..605fc3a 100644 --- a/src/Appwrite/Enums/TemplateReferenceType.php +++ b/src/Appwrite/Enums/TemplateReferenceType.php @@ -6,8 +6,8 @@ class TemplateReferenceType implements JsonSerializable { - private static TemplateReferenceType $BRANCH; private static TemplateReferenceType $COMMIT; + private static TemplateReferenceType $BRANCH; private static TemplateReferenceType $TAG; private string $value; @@ -27,13 +27,6 @@ public function jsonSerialize(): string return $this->value; } - public static function BRANCH(): TemplateReferenceType - { - if (!isset(self::$BRANCH)) { - self::$BRANCH = new TemplateReferenceType('branch'); - } - return self::$BRANCH; - } public static function COMMIT(): TemplateReferenceType { if (!isset(self::$COMMIT)) { @@ -41,6 +34,13 @@ public static function COMMIT(): TemplateReferenceType } return self::$COMMIT; } + public static function BRANCH(): TemplateReferenceType + { + if (!isset(self::$BRANCH)) { + self::$BRANCH = new TemplateReferenceType('branch'); + } + return self::$BRANCH; + } public static function TAG(): TemplateReferenceType { if (!isset(self::$TAG)) { diff --git a/src/Appwrite/Services/Databases.php b/src/Appwrite/Services/Databases.php index 4fcf0cc..0f40c03 100644 --- a/src/Appwrite/Services/Databases.php +++ b/src/Appwrite/Services/Databases.php @@ -8,7 +8,7 @@ use Appwrite\InputFile; use Appwrite\Enums\RelationshipType; use Appwrite\Enums\RelationMutate; -use Appwrite\Enums\IndexType; +use Appwrite\Enums\DatabasesIndexType; use Appwrite\Enums\OrderBy; class Databases extends Service @@ -2887,7 +2887,7 @@ public function listIndexes(string $databaseId, string $collectionId, ?array $qu * @param string $databaseId * @param string $collectionId * @param string $key - * @param IndexType $type + * @param DatabasesIndexType $type * @param array $attributes * @param ?array $orders * @param ?array $lengths @@ -2897,7 +2897,7 @@ public function listIndexes(string $databaseId, string $collectionId, ?array $qu * @deprecated This API has been deprecated since 1.8.0. Please use `createIndex` instead. * @see TablesDB::createIndex */ - public function createIndex(string $databaseId, string $collectionId, string $key, IndexType $type, array $attributes, ?array $orders = null, ?array $lengths = null): array + public function createIndex(string $databaseId, string $collectionId, string $key, DatabasesIndexType $type, array $attributes, ?array $orders = null, ?array $lengths = null): array { $apiPath = str_replace( ['{databaseId}', '{collectionId}'], diff --git a/src/Appwrite/Services/Functions.php b/src/Appwrite/Services/Functions.php index 561adab..7eaab39 100644 --- a/src/Appwrite/Services/Functions.php +++ b/src/Appwrite/Services/Functions.php @@ -85,11 +85,13 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota * @param ?string $providerBranch * @param ?bool $providerSilentMode * @param ?string $providerRootDirectory - * @param ?string $specification + * @param ?string $buildSpecification + * @param ?string $runtimeSpecification + * @param ?int $deploymentRetention * @throws AppwriteException * @return array */ - public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $specification = null): array + public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null): array { $apiPath = str_replace( [], @@ -158,8 +160,16 @@ public function create(string $functionId, string $name, Runtime $runtime, ?arra $apiParams['providerRootDirectory'] = $providerRootDirectory; } - if (!is_null($specification)) { - $apiParams['specification'] = $specification; + if (!is_null($buildSpecification)) { + $apiParams['buildSpecification'] = $buildSpecification; + } + + if (!is_null($runtimeSpecification)) { + $apiParams['runtimeSpecification'] = $runtimeSpecification; + } + + if (!is_null($deploymentRetention)) { + $apiParams['deploymentRetention'] = $deploymentRetention; } $apiHeaders = []; @@ -273,11 +283,13 @@ public function get(string $functionId): array * @param ?string $providerBranch * @param ?bool $providerSilentMode * @param ?string $providerRootDirectory - * @param ?string $specification + * @param ?string $buildSpecification + * @param ?string $runtimeSpecification + * @param ?int $deploymentRetention * @throws AppwriteException * @return array */ - public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $specification = null): array + public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null): array { $apiPath = str_replace( ['{functionId}'], @@ -346,8 +358,16 @@ public function update(string $functionId, string $name, ?Runtime $runtime = nul $apiParams['providerRootDirectory'] = $providerRootDirectory; } - if (!is_null($specification)) { - $apiParams['specification'] = $specification; + if (!is_null($buildSpecification)) { + $apiParams['buildSpecification'] = $buildSpecification; + } + + if (!is_null($runtimeSpecification)) { + $apiParams['runtimeSpecification'] = $runtimeSpecification; + } + + if (!is_null($deploymentRetention)) { + $apiParams['deploymentRetention'] = $deploymentRetention; } $apiHeaders = []; diff --git a/src/Appwrite/Services/Health.php b/src/Appwrite/Services/Health.php index 06407e9..966e1ae 100644 --- a/src/Appwrite/Services/Health.php +++ b/src/Appwrite/Services/Health.php @@ -247,68 +247,6 @@ public function getQueueAudits(?int $threshold = null): array ); } - /** - * Get billing project aggregation queue. - * - * @param ?int $threshold - * @throws AppwriteException - * @return array - */ - public function getQueueBillingProjectAggregation(?int $threshold = null): array - { - $apiPath = str_replace( - [], - [], - '/health/queue/billing-project-aggregation' - ); - - $apiParams = []; - - if (!is_null($threshold)) { - $apiParams['threshold'] = $threshold; - } - - $apiHeaders = []; - - return $this->client->call( - Client::METHOD_GET, - $apiPath, - $apiHeaders, - $apiParams - ); - } - - /** - * Get billing team aggregation queue. - * - * @param ?int $threshold - * @throws AppwriteException - * @return array - */ - public function getQueueBillingTeamAggregation(?int $threshold = null): array - { - $apiPath = str_replace( - [], - [], - '/health/queue/billing-team-aggregation' - ); - - $apiParams = []; - - if (!is_null($threshold)) { - $apiParams['threshold'] = $threshold; - } - - $apiHeaders = []; - - return $this->client->call( - Client::METHOD_GET, - $apiPath, - $apiHeaders, - $apiParams - ); - } - /** * Get the number of builds that are waiting to be processed in the Appwrite * internal queue server. @@ -341,37 +279,6 @@ public function getQueueBuilds(?int $threshold = null): array ); } - /** - * Get the priority builds queue size. - * - * @param ?int $threshold - * @throws AppwriteException - * @return array - */ - public function getQueuePriorityBuilds(?int $threshold = null): array - { - $apiPath = str_replace( - [], - [], - '/health/queue/builds-priority' - ); - - $apiParams = []; - - if (!is_null($threshold)) { - $apiParams['threshold'] = $threshold; - } - - $apiHeaders = []; - - return $this->client->call( - Client::METHOD_GET, - $apiPath, - $apiHeaders, - $apiParams - ); - } - /** * Get the number of certificates that are waiting to be issued against * [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue @@ -668,37 +575,6 @@ public function getQueueMigrations(?int $threshold = null): array ); } - /** - * Get region manager queue. - * - * @param ?int $threshold - * @throws AppwriteException - * @return array - */ - public function getQueueRegionManager(?int $threshold = null): array - { - $apiPath = str_replace( - [], - [], - '/health/queue/region-manager' - ); - - $apiParams = []; - - if (!is_null($threshold)) { - $apiParams['threshold'] = $threshold; - } - - $apiHeaders = []; - - return $this->client->call( - Client::METHOD_GET, - $apiPath, - $apiHeaders, - $apiParams - ); - } - /** * Get the number of metrics that are waiting to be processed in the Appwrite * stats resources queue. @@ -763,37 +639,6 @@ public function getQueueUsage(?int $threshold = null): array ); } - /** - * Get threats queue. - * - * @param ?int $threshold - * @throws AppwriteException - * @return array - */ - public function getQueueThreats(?int $threshold = null): array - { - $apiPath = str_replace( - [], - [], - '/health/queue/threats' - ); - - $apiParams = []; - - if (!is_null($threshold)) { - $apiParams['threshold'] = $threshold; - } - - $apiHeaders = []; - - return $this->client->call( - Client::METHOD_GET, - $apiPath, - $apiHeaders, - $apiParams - ); - } - /** * Get the number of webhooks that are waiting to be processed in the Appwrite * internal queue server. diff --git a/src/Appwrite/Services/Project.php b/src/Appwrite/Services/Project.php new file mode 100644 index 0000000..881a397 --- /dev/null +++ b/src/Appwrite/Services/Project.php @@ -0,0 +1,183 @@ +client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Create a new project environment variable. These variables can be accessed + * by all functions and sites in the project. + * + * @param string $variableId + * @param string $key + * @param string $value + * @param ?bool $secret + * @throws AppwriteException + * @return array + */ + public function createVariable(string $variableId, string $key, string $value, ?bool $secret = null): array + { + $apiPath = str_replace( + [], + [], + '/project/variables' + ); + + $apiParams = []; + $apiParams['variableId'] = $variableId; + $apiParams['key'] = $key; + $apiParams['value'] = $value; + + if (!is_null($secret)) { + $apiParams['secret'] = $secret; + } + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Get a variable by its unique ID. + * + * @param string $variableId + * @throws AppwriteException + * @return array + */ + public function getVariable(string $variableId): array + { + $apiPath = str_replace( + ['{variableId}'], + [$variableId], + '/project/variables/{variableId}' + ); + + $apiParams = []; + $apiParams['variableId'] = $variableId; + + $apiHeaders = []; + + return $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Update variable by its unique ID. + * + * @param string $variableId + * @param ?string $key + * @param ?string $value + * @param ?bool $secret + * @throws AppwriteException + * @return array + */ + public function updateVariable(string $variableId, ?string $key = null, ?string $value = null, ?bool $secret = null): array + { + $apiPath = str_replace( + ['{variableId}'], + [$variableId], + '/project/variables/{variableId}' + ); + + $apiParams = []; + $apiParams['variableId'] = $variableId; + $apiParams['key'] = $key; + $apiParams['value'] = $value; + $apiParams['secret'] = $secret; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Delete a variable by its unique ID. + * + * @param string $variableId + * @throws AppwriteException + * @return string + */ + public function deleteVariable(string $variableId): string + { + $apiPath = str_replace( + ['{variableId}'], + [$variableId], + '/project/variables/{variableId}' + ); + + $apiParams = []; + $apiParams['variableId'] = $variableId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_DELETE, + $apiPath, + $apiHeaders, + $apiParams + ); + } +} \ No newline at end of file diff --git a/src/Appwrite/Services/Sites.php b/src/Appwrite/Services/Sites.php index 3dcdc1f..a0930b9 100644 --- a/src/Appwrite/Services/Sites.php +++ b/src/Appwrite/Services/Sites.php @@ -74,6 +74,7 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota * @param ?int $timeout * @param ?string $installCommand * @param ?string $buildCommand + * @param ?string $startCommand * @param ?string $outputDirectory * @param ?Adapter $adapter * @param ?string $installationId @@ -82,11 +83,13 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota * @param ?string $providerBranch * @param ?bool $providerSilentMode * @param ?string $providerRootDirectory - * @param ?string $specification + * @param ?string $buildSpecification + * @param ?string $runtimeSpecification + * @param ?int $deploymentRetention * @throws AppwriteException * @return array */ - public function create(string $siteId, string $name, Framework $framework, BuildRuntime $buildRuntime, ?bool $enabled = null, ?bool $logging = null, ?int $timeout = null, ?string $installCommand = null, ?string $buildCommand = null, ?string $outputDirectory = null, ?Adapter $adapter = null, ?string $installationId = null, ?string $fallbackFile = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $specification = null): array + public function create(string $siteId, string $name, Framework $framework, BuildRuntime $buildRuntime, ?bool $enabled = null, ?bool $logging = null, ?int $timeout = null, ?string $installCommand = null, ?string $buildCommand = null, ?string $startCommand = null, ?string $outputDirectory = null, ?Adapter $adapter = null, ?string $installationId = null, ?string $fallbackFile = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null): array { $apiPath = str_replace( [], @@ -120,6 +123,10 @@ public function create(string $siteId, string $name, Framework $framework, Build $apiParams['buildCommand'] = $buildCommand; } + if (!is_null($startCommand)) { + $apiParams['startCommand'] = $startCommand; + } + if (!is_null($outputDirectory)) { $apiParams['outputDirectory'] = $outputDirectory; } @@ -152,8 +159,16 @@ public function create(string $siteId, string $name, Framework $framework, Build $apiParams['providerRootDirectory'] = $providerRootDirectory; } - if (!is_null($specification)) { - $apiParams['specification'] = $specification; + if (!is_null($buildSpecification)) { + $apiParams['buildSpecification'] = $buildSpecification; + } + + if (!is_null($runtimeSpecification)) { + $apiParams['runtimeSpecification'] = $runtimeSpecification; + } + + if (!is_null($deploymentRetention)) { + $apiParams['deploymentRetention'] = $deploymentRetention; } $apiHeaders = []; @@ -259,6 +274,7 @@ public function get(string $siteId): array * @param ?int $timeout * @param ?string $installCommand * @param ?string $buildCommand + * @param ?string $startCommand * @param ?string $outputDirectory * @param ?BuildRuntime $buildRuntime * @param ?Adapter $adapter @@ -268,11 +284,13 @@ public function get(string $siteId): array * @param ?string $providerBranch * @param ?bool $providerSilentMode * @param ?string $providerRootDirectory - * @param ?string $specification + * @param ?string $buildSpecification + * @param ?string $runtimeSpecification + * @param ?int $deploymentRetention * @throws AppwriteException * @return array */ - public function update(string $siteId, string $name, Framework $framework, ?bool $enabled = null, ?bool $logging = null, ?int $timeout = null, ?string $installCommand = null, ?string $buildCommand = null, ?string $outputDirectory = null, ?BuildRuntime $buildRuntime = null, ?Adapter $adapter = null, ?string $fallbackFile = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $specification = null): array + public function update(string $siteId, string $name, Framework $framework, ?bool $enabled = null, ?bool $logging = null, ?int $timeout = null, ?string $installCommand = null, ?string $buildCommand = null, ?string $startCommand = null, ?string $outputDirectory = null, ?BuildRuntime $buildRuntime = null, ?Adapter $adapter = null, ?string $fallbackFile = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null): array { $apiPath = str_replace( ['{siteId}'], @@ -305,6 +323,10 @@ public function update(string $siteId, string $name, Framework $framework, ?bool $apiParams['buildCommand'] = $buildCommand; } + if (!is_null($startCommand)) { + $apiParams['startCommand'] = $startCommand; + } + if (!is_null($outputDirectory)) { $apiParams['outputDirectory'] = $outputDirectory; } @@ -341,8 +363,16 @@ public function update(string $siteId, string $name, Framework $framework, ?bool $apiParams['providerRootDirectory'] = $providerRootDirectory; } - if (!is_null($specification)) { - $apiParams['specification'] = $specification; + if (!is_null($buildSpecification)) { + $apiParams['buildSpecification'] = $buildSpecification; + } + + if (!is_null($runtimeSpecification)) { + $apiParams['runtimeSpecification'] = $runtimeSpecification; + } + + if (!is_null($deploymentRetention)) { + $apiParams['deploymentRetention'] = $deploymentRetention; } $apiHeaders = []; diff --git a/src/Appwrite/Services/TablesDB.php b/src/Appwrite/Services/TablesDB.php index c8edce6..e52fdf8 100644 --- a/src/Appwrite/Services/TablesDB.php +++ b/src/Appwrite/Services/TablesDB.php @@ -8,7 +8,7 @@ use Appwrite\InputFile; use Appwrite\Enums\RelationshipType; use Appwrite\Enums\RelationMutate; -use Appwrite\Enums\IndexType; +use Appwrite\Enums\TablesDBIndexType; use Appwrite\Enums\OrderBy; class TablesDB extends Service @@ -2225,14 +2225,14 @@ public function listIndexes(string $databaseId, string $tableId, ?array $queries * @param string $databaseId * @param string $tableId * @param string $key - * @param IndexType $type + * @param TablesDBIndexType $type * @param array $columns * @param ?array $orders * @param ?array $lengths * @throws AppwriteException * @return array */ - public function createIndex(string $databaseId, string $tableId, string $key, IndexType $type, array $columns, ?array $orders = null, ?array $lengths = null): array + public function createIndex(string $databaseId, string $tableId, string $key, TablesDBIndexType $type, array $columns, ?array $orders = null, ?array $lengths = null): array { $apiPath = str_replace( ['{databaseId}', '{tableId}'], diff --git a/src/Appwrite/Services/Users.php b/src/Appwrite/Services/Users.php index 992bb0e..da07936 100644 --- a/src/Appwrite/Services/Users.php +++ b/src/Appwrite/Services/Users.php @@ -574,6 +574,42 @@ public function updateEmail(string $userId, string $email): array ); } + /** + * Enable or disable whether a user can impersonate other users. When + * impersonation headers are used, the request runs as the target user for API + * behavior, while internal audit logs still attribute the action to the + * original impersonator and store the impersonated target details only in + * internal audit payload data. + * + * + * @param string $userId + * @param bool $impersonator + * @throws AppwriteException + * @return array + */ + public function updateImpersonator(string $userId, bool $impersonator): array + { + $apiPath = str_replace( + ['{userId}'], + [$userId], + '/users/{userId}/impersonator' + ); + + $apiParams = []; + $apiParams['userId'] = $userId; + $apiParams['impersonator'] = $impersonator; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_PATCH, + $apiPath, + $apiHeaders, + $apiParams + ); + } + /** * Use this endpoint to create a JSON Web Token for user by its unique ID. You * can use the resulting JWT to authenticate on behalf of the user. The JWT diff --git a/src/Appwrite/Services/Webhooks.php b/src/Appwrite/Services/Webhooks.php new file mode 100644 index 0000000..9a00db1 --- /dev/null +++ b/src/Appwrite/Services/Webhooks.php @@ -0,0 +1,255 @@ +client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Create a new webhook. Use this endpoint to configure a URL that will + * receive events from Appwrite when specific events occur. + * + * @param string $webhookId + * @param string $url + * @param string $name + * @param array $events + * @param ?bool $enabled + * @param ?bool $security + * @param ?string $httpUser + * @param ?string $httpPass + * @throws AppwriteException + * @return array + */ + public function create(string $webhookId, string $url, string $name, array $events, ?bool $enabled = null, ?bool $security = null, ?string $httpUser = null, ?string $httpPass = null): array + { + $apiPath = str_replace( + [], + [], + '/webhooks' + ); + + $apiParams = []; + $apiParams['webhookId'] = $webhookId; + $apiParams['url'] = $url; + $apiParams['name'] = $name; + $apiParams['events'] = $events; + + if (!is_null($enabled)) { + $apiParams['enabled'] = $enabled; + } + + if (!is_null($security)) { + $apiParams['security'] = $security; + } + + if (!is_null($httpUser)) { + $apiParams['httpUser'] = $httpUser; + } + + if (!is_null($httpPass)) { + $apiParams['httpPass'] = $httpPass; + } + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Get a webhook by its unique ID. This endpoint returns details about a + * specific webhook configured for a project. + * + * @param string $webhookId + * @throws AppwriteException + * @return array + */ + public function get(string $webhookId): array + { + $apiPath = str_replace( + ['{webhookId}'], + [$webhookId], + '/webhooks/{webhookId}' + ); + + $apiParams = []; + $apiParams['webhookId'] = $webhookId; + + $apiHeaders = []; + + return $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Update a webhook by its unique ID. Use this endpoint to update the URL, + * events, or status of an existing webhook. + * + * @param string $webhookId + * @param string $name + * @param string $url + * @param array $events + * @param ?bool $enabled + * @param ?bool $security + * @param ?string $httpUser + * @param ?string $httpPass + * @throws AppwriteException + * @return array + */ + public function update(string $webhookId, string $name, string $url, array $events, ?bool $enabled = null, ?bool $security = null, ?string $httpUser = null, ?string $httpPass = null): array + { + $apiPath = str_replace( + ['{webhookId}'], + [$webhookId], + '/webhooks/{webhookId}' + ); + + $apiParams = []; + $apiParams['webhookId'] = $webhookId; + $apiParams['name'] = $name; + $apiParams['url'] = $url; + $apiParams['events'] = $events; + + if (!is_null($enabled)) { + $apiParams['enabled'] = $enabled; + } + + if (!is_null($security)) { + $apiParams['security'] = $security; + } + + if (!is_null($httpUser)) { + $apiParams['httpUser'] = $httpUser; + } + + if (!is_null($httpPass)) { + $apiParams['httpPass'] = $httpPass; + } + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Delete a webhook by its unique ID. Once deleted, the webhook will no longer + * receive project events. + * + * @param string $webhookId + * @throws AppwriteException + * @return string + */ + public function delete(string $webhookId): string + { + $apiPath = str_replace( + ['{webhookId}'], + [$webhookId], + '/webhooks/{webhookId}' + ); + + $apiParams = []; + $apiParams['webhookId'] = $webhookId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_DELETE, + $apiPath, + $apiHeaders, + $apiParams + ); + } + + /** + * Update the webhook signature key. This endpoint can be used to regenerate + * the signature key used to sign and validate payload deliveries for a + * specific webhook. + * + * @param string $webhookId + * @throws AppwriteException + * @return array + */ + public function updateSignature(string $webhookId): array + { + $apiPath = str_replace( + ['{webhookId}'], + [$webhookId], + '/webhooks/{webhookId}/signature' + ); + + $apiParams = []; + $apiParams['webhookId'] = $webhookId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_PATCH, + $apiPath, + $apiHeaders, + $apiParams + ); + } +} \ No newline at end of file diff --git a/tests/Appwrite/Services/DatabasesTest.php b/tests/Appwrite/Services/DatabasesTest.php index fb065df..7c7098d 100644 --- a/tests/Appwrite/Services/DatabasesTest.php +++ b/tests/Appwrite/Services/DatabasesTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use Appwrite\Enums\RelationshipType; use Appwrite\Enums\RelationMutate; -use Appwrite\Enums\IndexType; +use Appwrite\Enums\DatabasesIndexType; use Appwrite\Enums\OrderBy; final class DatabasesTest extends TestCase { @@ -1328,7 +1328,7 @@ public function testMethodCreateDocument(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$collectionId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1427,7 +1427,7 @@ public function testMethodGetDocument(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$collectionId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1451,7 +1451,7 @@ public function testMethodUpsertDocument(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$collectionId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1475,7 +1475,7 @@ public function testMethodUpdateDocument(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$collectionId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1516,7 +1516,7 @@ public function testMethodDecrementDocumentAttribute(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$collectionId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1541,7 +1541,7 @@ public function testMethodIncrementDocumentAttribute(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$collectionId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1601,7 +1601,7 @@ public function testMethodCreateIndex(): void { "", "", "", - IndexType::KEY(), + DatabasesIndexType::KEY(), array() ); diff --git a/tests/Appwrite/Services/FunctionsTest.php b/tests/Appwrite/Services/FunctionsTest.php index 9d468cd..5d15b59 100644 --- a/tests/Appwrite/Services/FunctionsTest.php +++ b/tests/Appwrite/Services/FunctionsTest.php @@ -50,6 +50,7 @@ public function testMethodCreate(): void { "live" => true, "logging" => true, "runtime" => "python-3.8", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "latestDeploymentId" => "5e5ea5c16897e", @@ -68,7 +69,8 @@ public function testMethodCreate(): void { "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb"); + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb"); $this->client ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) @@ -127,6 +129,7 @@ public function testMethodGet(): void { "live" => true, "logging" => true, "runtime" => "python-3.8", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "latestDeploymentId" => "5e5ea5c16897e", @@ -145,7 +148,8 @@ public function testMethodGet(): void { "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb"); + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb"); $this->client ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) @@ -170,6 +174,7 @@ public function testMethodUpdate(): void { "live" => true, "logging" => true, "runtime" => "python-3.8", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "latestDeploymentId" => "5e5ea5c16897e", @@ -188,7 +193,8 @@ public function testMethodUpdate(): void { "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb"); + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb"); $this->client ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) @@ -229,6 +235,7 @@ public function testMethodUpdateFunctionDeployment(): void { "live" => true, "logging" => true, "runtime" => "python-3.8", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "latestDeploymentId" => "5e5ea5c16897e", @@ -247,7 +254,8 @@ public function testMethodUpdateFunctionDeployment(): void { "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb"); + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb"); $this->client ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) diff --git a/tests/Appwrite/Services/HealthTest.php b/tests/Appwrite/Services/HealthTest.php index 2fddf3a..e8ec1c1 100644 --- a/tests/Appwrite/Services/HealthTest.php +++ b/tests/Appwrite/Services/HealthTest.php @@ -150,36 +150,6 @@ public function testMethodGetQueueAudits(): void { $this->assertSame($data, $response); } - public function testMethodGetQueueBillingProjectAggregation(): void { - - $data = array( - "size" => 8); - - $this->client - ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) - ->andReturn($data); - - $response = $this->health->getQueueBillingProjectAggregation( - ); - - $this->assertSame($data, $response); - } - - public function testMethodGetQueueBillingTeamAggregation(): void { - - $data = array( - "size" => 8); - - $this->client - ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) - ->andReturn($data); - - $response = $this->health->getQueueBillingTeamAggregation( - ); - - $this->assertSame($data, $response); - } - public function testMethodGetQueueBuilds(): void { $data = array( @@ -195,21 +165,6 @@ public function testMethodGetQueueBuilds(): void { $this->assertSame($data, $response); } - public function testMethodGetQueuePriorityBuilds(): void { - - $data = array( - "size" => 8); - - $this->client - ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) - ->andReturn($data); - - $response = $this->health->getQueuePriorityBuilds( - ); - - $this->assertSame($data, $response); - } - public function testMethodGetQueueCertificates(): void { $data = array( @@ -346,21 +301,6 @@ public function testMethodGetQueueMigrations(): void { $this->assertSame($data, $response); } - public function testMethodGetQueueRegionManager(): void { - - $data = array( - "size" => 8); - - $this->client - ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) - ->andReturn($data); - - $response = $this->health->getQueueRegionManager( - ); - - $this->assertSame($data, $response); - } - public function testMethodGetQueueStatsResources(): void { $data = array( @@ -391,21 +331,6 @@ public function testMethodGetQueueUsage(): void { $this->assertSame($data, $response); } - public function testMethodGetQueueThreats(): void { - - $data = array( - "size" => 8); - - $this->client - ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) - ->andReturn($data); - - $response = $this->health->getQueueThreats( - ); - - $this->assertSame($data, $response); - } - public function testMethodGetQueueWebhooks(): void { $data = array( diff --git a/tests/Appwrite/Services/ProjectTest.php b/tests/Appwrite/Services/ProjectTest.php new file mode 100644 index 0000000..2562a52 --- /dev/null +++ b/tests/Appwrite/Services/ProjectTest.php @@ -0,0 +1,121 @@ +client = Mockery::mock(Client::class); + $this->project = new Project($this->client); + } + + public function testMethodListVariables(): void { + + $data = array( + "total" => 5, + "variables" => array()); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->listVariables( + ); + + $this->assertSame($data, $response); + } + + public function testMethodCreateVariable(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "key" => "API_KEY", + "value" => "myPa\$\$word1", + "secret" => true, + "resourceType" => "function", + "resourceId" => "myAwesomeFunction"); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createVariable( + "", + "", + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodGetVariable(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "key" => "API_KEY", + "value" => "myPa\$\$word1", + "secret" => true, + "resourceType" => "function", + "resourceId" => "myAwesomeFunction"); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->getVariable( + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodUpdateVariable(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "key" => "API_KEY", + "value" => "myPa\$\$word1", + "secret" => true, + "resourceType" => "function", + "resourceId" => "myAwesomeFunction"); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateVariable( + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodDeleteVariable(): void { + + $data = ''; + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->deleteVariable( + "" + ); + + $this->assertSame($data, $response); + } + +} diff --git a/tests/Appwrite/Services/SitesTest.php b/tests/Appwrite/Services/SitesTest.php index 6408740..5d67fd3 100644 --- a/tests/Appwrite/Services/SitesTest.php +++ b/tests/Appwrite/Services/SitesTest.php @@ -49,6 +49,7 @@ public function testMethodCreate(): void { "live" => true, "logging" => true, "framework" => "react", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "deploymentScreenshotLight" => "5e5ea5c16897e", @@ -60,13 +61,15 @@ public function testMethodCreate(): void { "timeout" => 300, "installCommand" => "npm install", "buildCommand" => "npm run build", + "startCommand" => "node custom-server.mjs", "outputDirectory" => "build", "installationId" => "6m40at4ejk5h2u9s1hboo", "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "sites/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb", + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb", "buildRuntime" => "node-22", "adapter" => "static", "fallbackFile" => "index.html"); @@ -128,6 +131,7 @@ public function testMethodGet(): void { "live" => true, "logging" => true, "framework" => "react", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "deploymentScreenshotLight" => "5e5ea5c16897e", @@ -139,13 +143,15 @@ public function testMethodGet(): void { "timeout" => 300, "installCommand" => "npm install", "buildCommand" => "npm run build", + "startCommand" => "node custom-server.mjs", "outputDirectory" => "build", "installationId" => "6m40at4ejk5h2u9s1hboo", "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "sites/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb", + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb", "buildRuntime" => "node-22", "adapter" => "static", "fallbackFile" => "index.html"); @@ -172,6 +178,7 @@ public function testMethodUpdate(): void { "live" => true, "logging" => true, "framework" => "react", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "deploymentScreenshotLight" => "5e5ea5c16897e", @@ -183,13 +190,15 @@ public function testMethodUpdate(): void { "timeout" => 300, "installCommand" => "npm install", "buildCommand" => "npm run build", + "startCommand" => "node custom-server.mjs", "outputDirectory" => "build", "installationId" => "6m40at4ejk5h2u9s1hboo", "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "sites/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb", + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb", "buildRuntime" => "node-22", "adapter" => "static", "fallbackFile" => "index.html"); @@ -233,6 +242,7 @@ public function testMethodUpdateSiteDeployment(): void { "live" => true, "logging" => true, "framework" => "react", + "deploymentRetention" => 7, "deploymentId" => "5e5ea5c16897e", "deploymentCreatedAt" => "2020-10-15T06:38:00.000+00:00", "deploymentScreenshotLight" => "5e5ea5c16897e", @@ -244,13 +254,15 @@ public function testMethodUpdateSiteDeployment(): void { "timeout" => 300, "installCommand" => "npm install", "buildCommand" => "npm run build", + "startCommand" => "node custom-server.mjs", "outputDirectory" => "build", "installationId" => "6m40at4ejk5h2u9s1hboo", "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "sites/helloWorld", "providerSilentMode" => true, - "specification" => "s-1vcpu-512mb", + "buildSpecification" => "s-1vcpu-512mb", + "runtimeSpecification" => "s-1vcpu-512mb", "buildRuntime" => "node-22", "adapter" => "static", "fallbackFile" => "index.html"); diff --git a/tests/Appwrite/Services/TablesDBTest.php b/tests/Appwrite/Services/TablesDBTest.php index fb91185..faa8129 100644 --- a/tests/Appwrite/Services/TablesDBTest.php +++ b/tests/Appwrite/Services/TablesDBTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use Appwrite\Enums\RelationshipType; use Appwrite\Enums\RelationMutate; -use Appwrite\Enums\IndexType; +use Appwrite\Enums\TablesDBIndexType; use Appwrite\Enums\OrderBy; final class TablesDBTest extends TestCase { @@ -1345,7 +1345,7 @@ public function testMethodCreateIndex(): void { "", "", "", - IndexType::KEY(), + TablesDBIndexType::KEY(), array() ); @@ -1417,7 +1417,7 @@ public function testMethodCreateRow(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$tableId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1516,7 +1516,7 @@ public function testMethodGetRow(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$tableId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1540,7 +1540,7 @@ public function testMethodUpsertRow(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$tableId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1564,7 +1564,7 @@ public function testMethodUpdateRow(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$tableId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1605,7 +1605,7 @@ public function testMethodDecrementRowColumn(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$tableId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", @@ -1630,7 +1630,7 @@ public function testMethodIncrementRowColumn(): void { $data = array( "\$id" => "5e5ea5c16897e", - "\$sequence" => 1, + "\$sequence" => "1", "\$tableId" => "5e5ea5c15117e", "\$databaseId" => "5e5ea5c15117e", "\$createdAt" => "2020-10-15T06:38:00.000+00:00", diff --git a/tests/Appwrite/Services/UsersTest.php b/tests/Appwrite/Services/UsersTest.php index 83d2bbc..a6a34ae 100644 --- a/tests/Appwrite/Services/UsersTest.php +++ b/tests/Appwrite/Services/UsersTest.php @@ -414,6 +414,38 @@ public function testMethodUpdateEmail(): void { $this->assertSame($data, $response); } + public function testMethodUpdateImpersonator(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "John Doe", + "registration" => "2020-10-15T06:38:00.000+00:00", + "status" => true, + "labels" => array(), + "passwordUpdate" => "2020-10-15T06:38:00.000+00:00", + "email" => "john@appwrite.io", + "phone" => "+4930901820", + "emailVerification" => true, + "phoneVerification" => true, + "mfa" => true, + "prefs" => array(), + "targets" => array(), + "accessedAt" => "2020-10-15T06:38:00.000+00:00"); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->users->updateImpersonator( + "", + true + ); + + $this->assertSame($data, $response); + } + public function testMethodCreateJWT(): void { $data = array( diff --git a/tests/Appwrite/Services/WebhooksTest.php b/tests/Appwrite/Services/WebhooksTest.php new file mode 100644 index 0000000..095a902 --- /dev/null +++ b/tests/Appwrite/Services/WebhooksTest.php @@ -0,0 +1,168 @@ +client = Mockery::mock(Client::class); + $this->webhooks = new Webhooks($this->client); + } + + public function testMethodList(): void { + + $data = array( + "total" => 5, + "webhooks" => array()); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->webhooks->list( + ); + + $this->assertSame($data, $response); + } + + public function testMethodCreate(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "security" => true, + "httpUser" => "username", + "httpPass" => "password", + "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->webhooks->create( + "", + "", + "", + array() + ); + + $this->assertSame($data, $response); + } + + public function testMethodGet(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "security" => true, + "httpUser" => "username", + "httpPass" => "password", + "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->webhooks->get( + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodUpdate(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "security" => true, + "httpUser" => "username", + "httpPass" => "password", + "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->webhooks->update( + "", + "", + "", + array() + ); + + $this->assertSame($data, $response); + } + + public function testMethodDelete(): void { + + $data = ''; + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->webhooks->delete( + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodUpdateSignature(): void { + + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "security" => true, + "httpUser" => "username", + "httpPass" => "password", + "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->webhooks->updateSignature( + "" + ); + + $this->assertSame($data, $response); + } + +}