From e71d447c77a2c8f72de2916bd8650a4f80a92469 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 24 Jul 2026 11:41:17 +0530 Subject: [PATCH] feat: SDK update for version 26.1.0 (#122) * chore: update Dart SDK to 26.0.0 * Commit from GitHub Actions (Format and push) * docs: clarify ActivityEvent changelog, country field remains * chore: update Dart SDK to 26.0.0 * Commit from GitHub Actions (Format and push) * chore: update Dart SDK to 26.1.0 * Commit from GitHub Actions (Format and push) * chore: update Dart SDK to 26.1.0 * Commit from GitHub Actions (Format and push) * chore: update Dart SDK to 26.1.0 * Commit from GitHub Actions (Format and push) --------- Co-authored-by: ChiragAgg5k --- .github/workflows/format.yml | 4 +- .github/workflows/publish.yml | 2 +- .github/workflows/test.yml | 2 +- CHANGELOG.md | 10 + README.md | 2 +- docs/examples/account/delete-consent-token.md | 15 + docs/examples/account/delete-consent.md | 14 + docs/examples/account/get-consent-token.md | 15 + docs/examples/account/get-consent.md | 14 + docs/examples/account/list-consent-tokens.md | 16 + docs/examples/account/list-consents.md | 15 + .../apps/create-installation-token.md | 15 + docs/examples/apps/create-key.md | 14 + docs/examples/apps/create-secret.md | 14 + docs/examples/apps/create.md | 32 ++ docs/examples/apps/delete-key.md | 15 + docs/examples/apps/delete-secret.md | 15 + docs/examples/apps/delete-tokens.md | 14 + docs/examples/apps/delete.md | 14 + docs/examples/apps/get-installation.md | 15 + docs/examples/apps/get-key.md | 15 + docs/examples/apps/get-secret.md | 15 + docs/examples/apps/get.md | 14 + .../examples/apps/list-installation-scopes.md | 12 + docs/examples/apps/list-installations.md | 16 + docs/examples/apps/list-keys.md | 16 + docs/examples/apps/list-o-auth-2-scopes.md | 12 + docs/examples/apps/list-secrets.md | 16 + docs/examples/apps/list.md | 15 + docs/examples/apps/update-labels.md | 15 + docs/examples/apps/update-team.md | 15 + docs/examples/apps/update.md | 33 ++ docs/examples/backups/create-restoration.md | 1 - docs/examples/oauth2/approve.md | 16 + docs/examples/oauth2/authorize-post.md | 27 + docs/examples/oauth2/authorize.md | 27 + .../oauth2/create-device-authorization.md | 18 + docs/examples/oauth2/create-grant.md | 14 + docs/examples/oauth2/create-par.md | 26 + docs/examples/oauth2/create-token.md | 23 + docs/examples/oauth2/get-grant.md | 14 + docs/examples/oauth2/list-organizations.md | 16 + docs/examples/oauth2/list-projects.md | 16 + docs/examples/oauth2/reject.md | 14 + docs/examples/oauth2/revoke.md | 17 + .../organization/create-installation.md | 15 + .../organization/delete-installation.md | 14 + .../examples/organization/get-installation.md | 14 + .../organization/list-installations.md | 15 + .../organization/update-installation.md | 15 + .../project/update-o-auth-2-server.md | 1 + .../examples/sites/get-deployment-download.md | 1 + docs/examples/tablesdb/create-failover.md | 15 + docs/examples/tablesdb/create.md | 1 + docs/examples/tablesdb/get-replicas.md | 14 + docs/examples/tablesdb/get-status.md | 14 + docs/examples/tablesdb/list-specifications.md | 12 + docs/examples/tablesdb/update.md | 1 + docs/examples/teams/create-installation.md | 16 + docs/examples/teams/delete-installation.md | 15 + docs/examples/teams/get-installation.md | 15 + docs/examples/teams/list-installations.md | 16 + docs/examples/teams/update-installation.md | 16 + lib/dart_appwrite.dart | 2 + lib/models.dart | 36 ++ lib/services/account.dart | 130 +++++ lib/services/activities.dart | 2 + lib/services/apps.dart | 506 ++++++++++++++++ lib/services/backups.dart | 47 +- lib/services/databases.dart | 138 ++--- lib/services/functions.dart | 17 +- lib/services/messaging.dart | 180 +++--- lib/services/oauth2.dart | 402 +++++++++++++ lib/services/organization.dart | 118 +++- lib/services/presences.dart | 2 + lib/services/project.dart | 359 ++++++------ lib/services/sites.dart | 16 +- lib/services/storage.dart | 6 +- lib/services/tables_db.dart | 235 +++++--- lib/services/teams.dart | 124 ++++ lib/services/tokens.dart | 6 +- lib/services/users.dart | 4 +- lib/services/webhooks.dart | 5 +- lib/src/client_browser.dart | 2 +- lib/src/client_io.dart | 4 +- lib/src/enums/database_status.dart | 13 +- lib/src/enums/database_type.dart | 5 +- lib/src/enums/organization_key_scopes.dart | 2 + lib/src/enums/project_key_scopes.dart | 3 + lib/src/models/activity_event.dart | 67 +++ lib/src/models/app.dart | 175 ++++++ lib/src/models/app_installation.dart | 78 +++ lib/src/models/app_installation_list.dart | 31 + lib/src/models/app_key.dart | 72 +++ lib/src/models/app_key_list.dart | 30 + lib/src/models/app_scope.dart | 48 ++ lib/src/models/app_scope_list.dart | 31 + lib/src/models/app_secret.dart | 72 +++ lib/src/models/app_secret_list.dart | 31 + lib/src/models/app_secret_plaintext.dart | 72 +++ lib/src/models/apps_list.dart | 30 + lib/src/models/billing_plan.dart | 6 + lib/src/models/database.dart | 44 +- lib/src/models/database_status.dart | 68 +++ .../models/database_status_connections.dart | 30 + lib/src/models/database_status_replica.dart | 42 ++ lib/src/models/database_status_volume.dart | 42 ++ lib/src/models/dedicated_database.dart | 313 ++++++++++ lib/src/models/dedicated_database_member.dart | 42 ++ .../models/dedicated_database_replicas.dart | 37 ++ .../dedicated_database_specification.dart | 72 +++ ...dedicated_database_specification_list.dart | 38 ++ ...icated_database_specification_pricing.dart | 49 ++ lib/src/models/oauth2_approve.dart | 24 + lib/src/models/oauth2_authorize.dart | 30 + lib/src/models/oauth2_consent.dart | 78 +++ lib/src/models/oauth2_consent_list.dart | 31 + lib/src/models/oauth2_consent_token.dart | 84 +++ lib/src/models/oauth2_consent_token_list.dart | 31 + .../models/oauth2_device_authorization.dart | 54 ++ lib/src/models/oauth2_grant.dart | 90 +++ lib/src/models/oauth2_organization.dart | 24 + lib/src/models/oauth2_organization_list.dart | 31 + lib/src/models/oauth2_par.dart | 30 + lib/src/models/oauth2_project.dart | 36 ++ lib/src/models/oauth2_project_list.dart | 31 + lib/src/models/oauth2_reject.dart | 24 + lib/src/models/oauth2_token.dart | 60 ++ lib/src/models/project.dart | 14 + pubspec.yaml | 2 +- test/services/account_test.dart | 107 ++++ test/services/activities_test.dart | 11 + test/services/apps_test.dart | 539 ++++++++++++++++++ test/services/backups_test.dart | 6 +- test/services/databases_test.dart | 8 +- test/services/oauth2_test.dart | 267 +++++++++ test/services/organization_test.dart | 340 ++++++++++- test/services/project_test.dart | 26 +- test/services/tables_db_test.dart | 133 ++++- test/services/teams_test.dart | 101 ++++ test/src/models/activity_event_test.dart | 22 + .../models/app_installation_list_test.dart | 19 + test/src/models/app_installation_test.dart | 33 ++ test/src/models/app_key_list_test.dart | 19 + test/src/models/app_key_test.dart | 33 ++ test/src/models/app_scope_list_test.dart | 19 + test/src/models/app_scope_test.dart | 25 + test/src/models/app_secret_list_test.dart | 19 + .../src/models/app_secret_plaintext_test.dart | 33 ++ test/src/models/app_secret_test.dart | 31 + test/src/models/app_test.dart | 67 +++ test/src/models/apps_list_test.dart | 19 + test/src/models/backup_restoration_test.dart | 6 +- test/src/models/billing_plan_test.dart | 2 + .../database_status_connections_test.dart | 19 + .../models/database_status_replica_test.dart | 21 + test/src/models/database_status_test.dart | 33 ++ .../models/database_status_volume_test.dart | 23 + test/src/models/database_test.dart | 4 - .../dedicated_database_member_test.dart | 23 + .../dedicated_database_replicas_test.dart | 21 + ...ated_database_specification_list_test.dart | 26 + ...d_database_specification_pricing_test.dart | 25 + ...dedicated_database_specification_test.dart | 33 ++ test/src/models/dedicated_database_test.dart | 111 ++++ test/src/models/oauth2_approve_test.dart | 18 + test/src/models/oauth2_authorize_test.dart | 20 + test/src/models/oauth2_consent_list_test.dart | 19 + test/src/models/oauth2_consent_test.dart | 38 ++ .../oauth2_consent_token_list_test.dart | 19 + .../src/models/oauth2_consent_token_test.dart | 40 ++ .../oauth2_device_authorization_test.dart | 32 ++ test/src/models/oauth2_grant_test.dart | 41 ++ .../models/oauth2_organization_list_test.dart | 19 + test/src/models/oauth2_organization_test.dart | 17 + test/src/models/oauth2_par_test.dart | 19 + test/src/models/oauth2_project_list_test.dart | 19 + test/src/models/oauth2_project_test.dart | 21 + test/src/models/oauth2_reject_test.dart | 19 + test/src/models/oauth2_token_test.dart | 25 + test/src/models/organization_test.dart | 1 + test/src/models/project_test.dart | 2 + 182 files changed, 7535 insertions(+), 506 deletions(-) create mode 100644 docs/examples/account/delete-consent-token.md create mode 100644 docs/examples/account/delete-consent.md create mode 100644 docs/examples/account/get-consent-token.md create mode 100644 docs/examples/account/get-consent.md create mode 100644 docs/examples/account/list-consent-tokens.md create mode 100644 docs/examples/account/list-consents.md create mode 100644 docs/examples/apps/create-installation-token.md create mode 100644 docs/examples/apps/create-key.md create mode 100644 docs/examples/apps/create-secret.md create mode 100644 docs/examples/apps/create.md create mode 100644 docs/examples/apps/delete-key.md create mode 100644 docs/examples/apps/delete-secret.md create mode 100644 docs/examples/apps/delete-tokens.md create mode 100644 docs/examples/apps/delete.md create mode 100644 docs/examples/apps/get-installation.md create mode 100644 docs/examples/apps/get-key.md create mode 100644 docs/examples/apps/get-secret.md create mode 100644 docs/examples/apps/get.md create mode 100644 docs/examples/apps/list-installation-scopes.md create mode 100644 docs/examples/apps/list-installations.md create mode 100644 docs/examples/apps/list-keys.md create mode 100644 docs/examples/apps/list-o-auth-2-scopes.md create mode 100644 docs/examples/apps/list-secrets.md create mode 100644 docs/examples/apps/list.md create mode 100644 docs/examples/apps/update-labels.md create mode 100644 docs/examples/apps/update-team.md create mode 100644 docs/examples/apps/update.md create mode 100644 docs/examples/oauth2/approve.md create mode 100644 docs/examples/oauth2/authorize-post.md create mode 100644 docs/examples/oauth2/authorize.md create mode 100644 docs/examples/oauth2/create-device-authorization.md create mode 100644 docs/examples/oauth2/create-grant.md create mode 100644 docs/examples/oauth2/create-par.md create mode 100644 docs/examples/oauth2/create-token.md create mode 100644 docs/examples/oauth2/get-grant.md create mode 100644 docs/examples/oauth2/list-organizations.md create mode 100644 docs/examples/oauth2/list-projects.md create mode 100644 docs/examples/oauth2/reject.md create mode 100644 docs/examples/oauth2/revoke.md create mode 100644 docs/examples/organization/create-installation.md create mode 100644 docs/examples/organization/delete-installation.md create mode 100644 docs/examples/organization/get-installation.md create mode 100644 docs/examples/organization/list-installations.md create mode 100644 docs/examples/organization/update-installation.md create mode 100644 docs/examples/tablesdb/create-failover.md create mode 100644 docs/examples/tablesdb/get-replicas.md create mode 100644 docs/examples/tablesdb/get-status.md create mode 100644 docs/examples/tablesdb/list-specifications.md create mode 100644 docs/examples/teams/create-installation.md create mode 100644 docs/examples/teams/delete-installation.md create mode 100644 docs/examples/teams/get-installation.md create mode 100644 docs/examples/teams/list-installations.md create mode 100644 docs/examples/teams/update-installation.md create mode 100644 lib/services/apps.dart create mode 100644 lib/services/oauth2.dart create mode 100644 lib/src/models/app.dart create mode 100644 lib/src/models/app_installation.dart create mode 100644 lib/src/models/app_installation_list.dart create mode 100644 lib/src/models/app_key.dart create mode 100644 lib/src/models/app_key_list.dart create mode 100644 lib/src/models/app_scope.dart create mode 100644 lib/src/models/app_scope_list.dart create mode 100644 lib/src/models/app_secret.dart create mode 100644 lib/src/models/app_secret_list.dart create mode 100644 lib/src/models/app_secret_plaintext.dart create mode 100644 lib/src/models/apps_list.dart create mode 100644 lib/src/models/database_status.dart create mode 100644 lib/src/models/database_status_connections.dart create mode 100644 lib/src/models/database_status_replica.dart create mode 100644 lib/src/models/database_status_volume.dart create mode 100644 lib/src/models/dedicated_database.dart create mode 100644 lib/src/models/dedicated_database_member.dart create mode 100644 lib/src/models/dedicated_database_replicas.dart create mode 100644 lib/src/models/dedicated_database_specification.dart create mode 100644 lib/src/models/dedicated_database_specification_list.dart create mode 100644 lib/src/models/dedicated_database_specification_pricing.dart create mode 100644 lib/src/models/oauth2_approve.dart create mode 100644 lib/src/models/oauth2_authorize.dart create mode 100644 lib/src/models/oauth2_consent.dart create mode 100644 lib/src/models/oauth2_consent_list.dart create mode 100644 lib/src/models/oauth2_consent_token.dart create mode 100644 lib/src/models/oauth2_consent_token_list.dart create mode 100644 lib/src/models/oauth2_device_authorization.dart create mode 100644 lib/src/models/oauth2_grant.dart create mode 100644 lib/src/models/oauth2_organization.dart create mode 100644 lib/src/models/oauth2_organization_list.dart create mode 100644 lib/src/models/oauth2_par.dart create mode 100644 lib/src/models/oauth2_project.dart create mode 100644 lib/src/models/oauth2_project_list.dart create mode 100644 lib/src/models/oauth2_reject.dart create mode 100644 lib/src/models/oauth2_token.dart create mode 100644 test/services/apps_test.dart create mode 100644 test/services/oauth2_test.dart create mode 100644 test/src/models/app_installation_list_test.dart create mode 100644 test/src/models/app_installation_test.dart create mode 100644 test/src/models/app_key_list_test.dart create mode 100644 test/src/models/app_key_test.dart create mode 100644 test/src/models/app_scope_list_test.dart create mode 100644 test/src/models/app_scope_test.dart create mode 100644 test/src/models/app_secret_list_test.dart create mode 100644 test/src/models/app_secret_plaintext_test.dart create mode 100644 test/src/models/app_secret_test.dart create mode 100644 test/src/models/app_test.dart create mode 100644 test/src/models/apps_list_test.dart create mode 100644 test/src/models/database_status_connections_test.dart create mode 100644 test/src/models/database_status_replica_test.dart create mode 100644 test/src/models/database_status_test.dart create mode 100644 test/src/models/database_status_volume_test.dart create mode 100644 test/src/models/dedicated_database_member_test.dart create mode 100644 test/src/models/dedicated_database_replicas_test.dart create mode 100644 test/src/models/dedicated_database_specification_list_test.dart create mode 100644 test/src/models/dedicated_database_specification_pricing_test.dart create mode 100644 test/src/models/dedicated_database_specification_test.dart create mode 100644 test/src/models/dedicated_database_test.dart create mode 100644 test/src/models/oauth2_approve_test.dart create mode 100644 test/src/models/oauth2_authorize_test.dart create mode 100644 test/src/models/oauth2_consent_list_test.dart create mode 100644 test/src/models/oauth2_consent_test.dart create mode 100644 test/src/models/oauth2_consent_token_list_test.dart create mode 100644 test/src/models/oauth2_consent_token_test.dart create mode 100644 test/src/models/oauth2_device_authorization_test.dart create mode 100644 test/src/models/oauth2_grant_test.dart create mode 100644 test/src/models/oauth2_organization_list_test.dart create mode 100644 test/src/models/oauth2_organization_test.dart create mode 100644 test/src/models/oauth2_par_test.dart create mode 100644 test/src/models/oauth2_project_list_test.dart create mode 100644 test/src/models/oauth2_project_test.dart create mode 100644 test/src/models/oauth2_reject_test.dart create mode 100644 test/src/models/oauth2_token_test.dart diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index ad234781..29e7f7e7 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: true ref: ${{ github.event.pull_request.head.ref }} @@ -30,7 +30,7 @@ jobs: run: git config --global --add safe.directory /__w/sdk-for-dart/sdk-for-dart # required to fix dubious ownership - name: Add & Commit - uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4 + uses: EndBug/add-and-commit@290ea2c423ad77ca9c62ae0f5b224379612c0321 # v10.0.0 with: add: '["lib", "test"]' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9090f984..9ffee8f3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ jobs: id-token: write # Required for authentication using OIDC runs-on: ubuntu-latest steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260 # v1.7.2 - name: Install dependencies run: dart pub get diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7a22fda..3f96895a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260 # v1.7.2 - name: Install dependencies run: dart pub get diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d79daaa..c49bb21b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## 26.1.0 + +* Added: `Apps` service for managing OAuth2 applications, keys, and installations +* Added: `OAuth2` service with authorize, grant, device authorization, and consent flows +* Added: account OAuth2 consent methods `listConsents`, `getConsent`, `deleteConsent`, and consent token methods +* Added: app installation management methods to `Organization` and `Teams` services +* Added: `installationAccessTokenDuration` parameter to `project.updateOAuth2Server` +* Added: `token` parameter to `sites.getDeploymentDownload` +* Added: `oauth2.introspect` and organization installation key scopes + ## 26.0.0 * Breaking: Removed `Health` service with its health models and enums diff --git a/README.md b/README.md index c38d502f..d5ea7f6b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^26.0.0 + dart_appwrite: ^26.1.0 ``` You can install packages from the command line: diff --git a/docs/examples/account/delete-consent-token.md b/docs/examples/account/delete-consent-token.md new file mode 100644 index 00000000..9f407fcf --- /dev/null +++ b/docs/examples/account/delete-consent-token.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +await account.deleteConsentToken( + consentId: '', + tokenId: '', +); +``` diff --git a/docs/examples/account/delete-consent.md b/docs/examples/account/delete-consent.md new file mode 100644 index 00000000..ad1d2399 --- /dev/null +++ b/docs/examples/account/delete-consent.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +await account.deleteConsent( + consentId: '', +); +``` diff --git a/docs/examples/account/get-consent-token.md b/docs/examples/account/get-consent-token.md new file mode 100644 index 00000000..d742f14e --- /dev/null +++ b/docs/examples/account/get-consent-token.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +Oauth2ConsentToken result = await account.getConsentToken( + consentId: '', + tokenId: '', +); +``` diff --git a/docs/examples/account/get-consent.md b/docs/examples/account/get-consent.md new file mode 100644 index 00000000..91e7b7af --- /dev/null +++ b/docs/examples/account/get-consent.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +Oauth2Consent result = await account.getConsent( + consentId: '', +); +``` diff --git a/docs/examples/account/list-consent-tokens.md b/docs/examples/account/list-consent-tokens.md new file mode 100644 index 00000000..579d03a5 --- /dev/null +++ b/docs/examples/account/list-consent-tokens.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +Oauth2ConsentTokenList result = await account.listConsentTokens( + consentId: '', + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/account/list-consents.md b/docs/examples/account/list-consents.md new file mode 100644 index 00000000..f2a97b9d --- /dev/null +++ b/docs/examples/account/list-consents.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Account account = Account(client); + +Oauth2ConsentList result = await account.listConsents( + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/apps/create-installation-token.md b/docs/examples/apps/create-installation-token.md new file mode 100644 index 00000000..0d41a4f8 --- /dev/null +++ b/docs/examples/apps/create-installation-token.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Apps apps = Apps(client); + +Oauth2Token result = await apps.createInstallationToken( + appId: '', + installationId: '', +); +``` diff --git a/docs/examples/apps/create-key.md b/docs/examples/apps/create-key.md new file mode 100644 index 00000000..ad3bb955 --- /dev/null +++ b/docs/examples/apps/create-key.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppKey result = await apps.createKey( + appId: '', +); +``` diff --git a/docs/examples/apps/create-secret.md b/docs/examples/apps/create-secret.md new file mode 100644 index 00000000..a3dae923 --- /dev/null +++ b/docs/examples/apps/create-secret.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppSecretPlaintext result = await apps.createSecret( + appId: '', +); +``` diff --git a/docs/examples/apps/create.md b/docs/examples/apps/create.md new file mode 100644 index 00000000..6662a4f8 --- /dev/null +++ b/docs/examples/apps/create.md @@ -0,0 +1,32 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +App result = await apps.create( + appId: '', + name: '', + redirectUris: [], + description: '', // (optional) + clientUri: 'https://example.com', // (optional) + logoUri: 'https://example.com', // (optional) + privacyPolicyUrl: 'https://example.com', // (optional) + termsUrl: 'https://example.com', // (optional) + contacts: [], // (optional) + tagline: '', // (optional) + tags: [], // (optional) + images: [], // (optional) + supportUrl: 'https://example.com', // (optional) + dataDeletionUrl: 'https://example.com', // (optional) + postLogoutRedirectUris: [], // (optional) + enabled: false, // (optional) + type: 'public', // (optional) + deviceFlow: false, // (optional) + teamId: '', // (optional) +); +``` diff --git a/docs/examples/apps/delete-key.md b/docs/examples/apps/delete-key.md new file mode 100644 index 00000000..2e7d2193 --- /dev/null +++ b/docs/examples/apps/delete-key.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +await apps.deleteKey( + appId: '', + keyId: '', +); +``` diff --git a/docs/examples/apps/delete-secret.md b/docs/examples/apps/delete-secret.md new file mode 100644 index 00000000..e3813ebf --- /dev/null +++ b/docs/examples/apps/delete-secret.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +await apps.deleteSecret( + appId: '', + secretId: '', +); +``` diff --git a/docs/examples/apps/delete-tokens.md b/docs/examples/apps/delete-tokens.md new file mode 100644 index 00000000..179abbf9 --- /dev/null +++ b/docs/examples/apps/delete-tokens.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +await apps.deleteTokens( + appId: '', +); +``` diff --git a/docs/examples/apps/delete.md b/docs/examples/apps/delete.md new file mode 100644 index 00000000..1bf573fb --- /dev/null +++ b/docs/examples/apps/delete.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +await apps.delete( + appId: '', +); +``` diff --git a/docs/examples/apps/get-installation.md b/docs/examples/apps/get-installation.md new file mode 100644 index 00000000..fa31e259 --- /dev/null +++ b/docs/examples/apps/get-installation.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Apps apps = Apps(client); + +AppInstallation result = await apps.getInstallation( + appId: '', + installationId: '', +); +``` diff --git a/docs/examples/apps/get-key.md b/docs/examples/apps/get-key.md new file mode 100644 index 00000000..a5f27858 --- /dev/null +++ b/docs/examples/apps/get-key.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppKey result = await apps.getKey( + appId: '', + keyId: '', +); +``` diff --git a/docs/examples/apps/get-secret.md b/docs/examples/apps/get-secret.md new file mode 100644 index 00000000..4cd85a01 --- /dev/null +++ b/docs/examples/apps/get-secret.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppSecret result = await apps.getSecret( + appId: '', + secretId: '', +); +``` diff --git a/docs/examples/apps/get.md b/docs/examples/apps/get.md new file mode 100644 index 00000000..f5e79b85 --- /dev/null +++ b/docs/examples/apps/get.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +App result = await apps.get( + appId: '', +); +``` diff --git a/docs/examples/apps/list-installation-scopes.md b/docs/examples/apps/list-installation-scopes.md new file mode 100644 index 00000000..c2d17afc --- /dev/null +++ b/docs/examples/apps/list-installation-scopes.md @@ -0,0 +1,12 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppScopeList result = await apps.listInstallationScopes(); +``` diff --git a/docs/examples/apps/list-installations.md b/docs/examples/apps/list-installations.md new file mode 100644 index 00000000..b76c13d9 --- /dev/null +++ b/docs/examples/apps/list-installations.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Apps apps = Apps(client); + +AppInstallationList result = await apps.listInstallations( + appId: '', + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/apps/list-keys.md b/docs/examples/apps/list-keys.md new file mode 100644 index 00000000..18fda51a --- /dev/null +++ b/docs/examples/apps/list-keys.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppKeyList result = await apps.listKeys( + appId: '', + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/apps/list-o-auth-2-scopes.md b/docs/examples/apps/list-o-auth-2-scopes.md new file mode 100644 index 00000000..d50e8dcc --- /dev/null +++ b/docs/examples/apps/list-o-auth-2-scopes.md @@ -0,0 +1,12 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppScopeList result = await apps.listOAuth2Scopes(); +``` diff --git a/docs/examples/apps/list-secrets.md b/docs/examples/apps/list-secrets.md new file mode 100644 index 00000000..47c5439c --- /dev/null +++ b/docs/examples/apps/list-secrets.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppSecretList result = await apps.listSecrets( + appId: '', + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/apps/list.md b/docs/examples/apps/list.md new file mode 100644 index 00000000..9915fa0c --- /dev/null +++ b/docs/examples/apps/list.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +AppsList result = await apps.list( + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/apps/update-labels.md b/docs/examples/apps/update-labels.md new file mode 100644 index 00000000..ad796491 --- /dev/null +++ b/docs/examples/apps/update-labels.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Apps apps = Apps(client); + +App result = await apps.updateLabels( + appId: '', + labels: [], +); +``` diff --git a/docs/examples/apps/update-team.md b/docs/examples/apps/update-team.md new file mode 100644 index 00000000..a777349a --- /dev/null +++ b/docs/examples/apps/update-team.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +App result = await apps.updateTeam( + appId: '', + teamId: '', +); +``` diff --git a/docs/examples/apps/update.md b/docs/examples/apps/update.md new file mode 100644 index 00000000..ac04a4dd --- /dev/null +++ b/docs/examples/apps/update.md @@ -0,0 +1,33 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Apps apps = Apps(client); + +App result = await apps.update( + appId: '', + name: '', + description: '', // (optional) + clientUri: 'https://example.com', // (optional) + logoUri: 'https://example.com', // (optional) + privacyPolicyUrl: 'https://example.com', // (optional) + termsUrl: 'https://example.com', // (optional) + contacts: [], // (optional) + tagline: '', // (optional) + tags: [], // (optional) + images: [], // (optional) + supportUrl: 'https://example.com', // (optional) + dataDeletionUrl: 'https://example.com', // (optional) + enabled: false, // (optional) + redirectUris: [], // (optional) + postLogoutRedirectUris: [], // (optional) + type: 'public', // (optional) + deviceFlow: false, // (optional) + installationScopes: [], // (optional) + installationRedirectUrl: 'https://example.com', // (optional) +); +``` diff --git a/docs/examples/backups/create-restoration.md b/docs/examples/backups/create-restoration.md index 377d10dc..84bc8ae9 100644 --- a/docs/examples/backups/create-restoration.md +++ b/docs/examples/backups/create-restoration.md @@ -14,6 +14,5 @@ BackupRestoration result = await backups.createRestoration( services: [enums.BackupServices.databases], newResourceId: '', // (optional) newResourceName: '', // (optional) - newSpecification: 'serverless', // (optional) ); ``` diff --git a/docs/examples/oauth2/approve.md b/docs/examples/oauth2/approve.md new file mode 100644 index 00000000..61a65b52 --- /dev/null +++ b/docs/examples/oauth2/approve.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Approve result = await oauth2.approve( + grantId: '', + authorizationDetails: '', // (optional) + scope: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/authorize-post.md b/docs/examples/oauth2/authorize-post.md new file mode 100644 index 00000000..aa1f2605 --- /dev/null +++ b/docs/examples/oauth2/authorize-post.md @@ -0,0 +1,27 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Authorize result = await oauth2.authorizePost( + clientId: '', // (optional) + redirectUri: 'https://example.com', // (optional) + responseType: '', // (optional) + scope: '', // (optional) + state: '', // (optional) + nonce: '', // (optional) + codeChallenge: '', // (optional) + codeChallengeMethod: 's256', // (optional) + prompt: '', // (optional) + maxAge: 0, // (optional) + authorizationDetails: '', // (optional) + resource: '', // (optional) + audience: '', // (optional) + requestUri: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/authorize.md b/docs/examples/oauth2/authorize.md new file mode 100644 index 00000000..d49beab3 --- /dev/null +++ b/docs/examples/oauth2/authorize.md @@ -0,0 +1,27 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Authorize result = await oauth2.authorize( + clientId: '', // (optional) + redirectUri: 'https://example.com', // (optional) + responseType: '', // (optional) + scope: '', // (optional) + state: '', // (optional) + nonce: '', // (optional) + codeChallenge: '', // (optional) + codeChallengeMethod: 's256', // (optional) + prompt: '', // (optional) + maxAge: 0, // (optional) + authorizationDetails: '', // (optional) + resource: '', // (optional) + audience: '', // (optional) + requestUri: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/create-device-authorization.md b/docs/examples/oauth2/create-device-authorization.md new file mode 100644 index 00000000..ea4e22db --- /dev/null +++ b/docs/examples/oauth2/create-device-authorization.md @@ -0,0 +1,18 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2DeviceAuthorization result = await oauth2.createDeviceAuthorization( + clientId: '', // (optional) + scope: '', // (optional) + authorizationDetails: '', // (optional) + resource: '', // (optional) + audience: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/create-grant.md b/docs/examples/oauth2/create-grant.md new file mode 100644 index 00000000..b3e2aa43 --- /dev/null +++ b/docs/examples/oauth2/create-grant.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Grant result = await oauth2.createGrant( + userCode: '', +); +``` diff --git a/docs/examples/oauth2/create-par.md b/docs/examples/oauth2/create-par.md new file mode 100644 index 00000000..97538313 --- /dev/null +++ b/docs/examples/oauth2/create-par.md @@ -0,0 +1,26 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2PAR result = await oauth2.createPAR( + clientId: '', + redirectUri: 'https://example.com', + responseType: 'code', + scope: '', // (optional) + state: '', // (optional) + nonce: '', // (optional) + codeChallenge: '', // (optional) + codeChallengeMethod: 's256', // (optional) + prompt: '', // (optional) + maxAge: 0, // (optional) + authorizationDetails: '', // (optional) + resource: '', // (optional) + audience: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/create-token.md b/docs/examples/oauth2/create-token.md new file mode 100644 index 00000000..f1cbd3c8 --- /dev/null +++ b/docs/examples/oauth2/create-token.md @@ -0,0 +1,23 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Token result = await oauth2.createToken( + grantType: '', + code: '', // (optional) + refreshToken: '', // (optional) + deviceCode: '', // (optional) + clientId: '', // (optional) + clientSecret: '', // (optional) + codeVerifier: '', // (optional) + redirectUri: 'https://example.com', // (optional) + resource: '', // (optional) + audience: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/get-grant.md b/docs/examples/oauth2/get-grant.md new file mode 100644 index 00000000..7ed9e898 --- /dev/null +++ b/docs/examples/oauth2/get-grant.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Grant result = await oauth2.getGrant( + grantId: '', +); +``` diff --git a/docs/examples/oauth2/list-organizations.md b/docs/examples/oauth2/list-organizations.md new file mode 100644 index 00000000..fe345b20 --- /dev/null +++ b/docs/examples/oauth2/list-organizations.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2OrganizationList result = await oauth2.listOrganizations( + limit: 1, // (optional) + offset: 0, // (optional) + search: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/list-projects.md b/docs/examples/oauth2/list-projects.md new file mode 100644 index 00000000..de4c0c7a --- /dev/null +++ b/docs/examples/oauth2/list-projects.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2ProjectList result = await oauth2.listProjects( + limit: 1, // (optional) + offset: 0, // (optional) + search: '', // (optional) +); +``` diff --git a/docs/examples/oauth2/reject.md b/docs/examples/oauth2/reject.md new file mode 100644 index 00000000..843c4631 --- /dev/null +++ b/docs/examples/oauth2/reject.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + +Oauth2Reject result = await oauth2.reject( + grantId: '', +); +``` diff --git a/docs/examples/oauth2/revoke.md b/docs/examples/oauth2/revoke.md new file mode 100644 index 00000000..0f4f7820 --- /dev/null +++ b/docs/examples/oauth2/revoke.md @@ -0,0 +1,17 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setProject(''); // Your project ID + +Oauth2 oauth2 = Oauth2(client); + + result = await oauth2.revoke( + token: '', + tokenTypeHint: 'access_token', // (optional) + clientId: '', // (optional) + clientSecret: '', // (optional) +); +``` diff --git a/docs/examples/organization/create-installation.md b/docs/examples/organization/create-installation.md new file mode 100644 index 00000000..deee3364 --- /dev/null +++ b/docs/examples/organization/create-installation.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Organization organization = Organization(client); + +AppInstallation result = await organization.createInstallation( + appId: '', + authorizationDetails: '', // (optional) +); +``` diff --git a/docs/examples/organization/delete-installation.md b/docs/examples/organization/delete-installation.md new file mode 100644 index 00000000..3937b1ab --- /dev/null +++ b/docs/examples/organization/delete-installation.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Organization organization = Organization(client); + +await organization.deleteInstallation( + installationId: '', +); +``` diff --git a/docs/examples/organization/get-installation.md b/docs/examples/organization/get-installation.md new file mode 100644 index 00000000..187e534a --- /dev/null +++ b/docs/examples/organization/get-installation.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Organization organization = Organization(client); + +AppInstallation result = await organization.getInstallation( + installationId: '', +); +``` diff --git a/docs/examples/organization/list-installations.md b/docs/examples/organization/list-installations.md new file mode 100644 index 00000000..2730102d --- /dev/null +++ b/docs/examples/organization/list-installations.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Organization organization = Organization(client); + +AppInstallationList result = await organization.listInstallations( + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/organization/update-installation.md b/docs/examples/organization/update-installation.md new file mode 100644 index 00000000..63b7ce9a --- /dev/null +++ b/docs/examples/organization/update-installation.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Organization organization = Organization(client); + +AppInstallation result = await organization.updateInstallation( + installationId: '', + authorizationDetails: '', // (optional) +); +``` diff --git a/docs/examples/project/update-o-auth-2-server.md b/docs/examples/project/update-o-auth-2-server.md index 522517ff..b3ca6551 100644 --- a/docs/examples/project/update-o-auth-2-server.md +++ b/docs/examples/project/update-o-auth-2-server.md @@ -17,6 +17,7 @@ Project result = await project.updateOAuth2Server( refreshTokenDuration: 60, // (optional) publicAccessTokenDuration: 60, // (optional) publicRefreshTokenDuration: 60, // (optional) + installationAccessTokenDuration: 60, // (optional) confidentialPkce: false, // (optional) verificationUrl: 'https://example.com', // (optional) userCodeLength: 6, // (optional) diff --git a/docs/examples/sites/get-deployment-download.md b/docs/examples/sites/get-deployment-download.md index b9e4baa1..41281749 100644 --- a/docs/examples/sites/get-deployment-download.md +++ b/docs/examples/sites/get-deployment-download.md @@ -13,5 +13,6 @@ Uint8List result = await sites.getDeploymentDownload( siteId: '', deploymentId: '', type: enums.DeploymentDownloadType.source, // (optional) + token: '', // (optional) ); ``` diff --git a/docs/examples/tablesdb/create-failover.md b/docs/examples/tablesdb/create-failover.md new file mode 100644 index 00000000..29919921 --- /dev/null +++ b/docs/examples/tablesdb/create-failover.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +TablesDB tablesDB = TablesDB(client); + +DedicatedDatabase result = await tablesDB.createFailover( + databaseId: '', + targetReplicaId: '', // (optional) +); +``` diff --git a/docs/examples/tablesdb/create.md b/docs/examples/tablesdb/create.md index d2664f3e..939a3f99 100644 --- a/docs/examples/tablesdb/create.md +++ b/docs/examples/tablesdb/create.md @@ -13,5 +13,6 @@ Database result = await tablesDB.create( name: '', enabled: false, // (optional) specification: 'serverless', // (optional) + replicas: 0, // (optional) ); ``` diff --git a/docs/examples/tablesdb/get-replicas.md b/docs/examples/tablesdb/get-replicas.md new file mode 100644 index 00000000..e3dbc4b6 --- /dev/null +++ b/docs/examples/tablesdb/get-replicas.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +TablesDB tablesDB = TablesDB(client); + +DedicatedDatabaseReplicas result = await tablesDB.getReplicas( + databaseId: '', +); +``` diff --git a/docs/examples/tablesdb/get-status.md b/docs/examples/tablesdb/get-status.md new file mode 100644 index 00000000..faa67bf5 --- /dev/null +++ b/docs/examples/tablesdb/get-status.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +TablesDB tablesDB = TablesDB(client); + +DatabaseStatus result = await tablesDB.getStatus( + databaseId: '', +); +``` diff --git a/docs/examples/tablesdb/list-specifications.md b/docs/examples/tablesdb/list-specifications.md new file mode 100644 index 00000000..55b70e8c --- /dev/null +++ b/docs/examples/tablesdb/list-specifications.md @@ -0,0 +1,12 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +TablesDB tablesDB = TablesDB(client); + +DedicatedDatabaseSpecificationList result = await tablesDB.listSpecifications(); +``` diff --git a/docs/examples/tablesdb/update.md b/docs/examples/tablesdb/update.md index ad85b595..cbe9908d 100644 --- a/docs/examples/tablesdb/update.md +++ b/docs/examples/tablesdb/update.md @@ -12,5 +12,6 @@ Database result = await tablesDB.update( databaseId: '', name: '', // (optional) enabled: false, // (optional) + replicas: 0, // (optional) ); ``` diff --git a/docs/examples/teams/create-installation.md b/docs/examples/teams/create-installation.md new file mode 100644 index 00000000..e41c00f1 --- /dev/null +++ b/docs/examples/teams/create-installation.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Teams teams = Teams(client); + +AppInstallation result = await teams.createInstallation( + teamId: '', + appId: '', + authorizationDetails: '', // (optional) +); +``` diff --git a/docs/examples/teams/delete-installation.md b/docs/examples/teams/delete-installation.md new file mode 100644 index 00000000..88595482 --- /dev/null +++ b/docs/examples/teams/delete-installation.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Teams teams = Teams(client); + +await teams.deleteInstallation( + teamId: '', + installationId: '', +); +``` diff --git a/docs/examples/teams/get-installation.md b/docs/examples/teams/get-installation.md new file mode 100644 index 00000000..81c030f8 --- /dev/null +++ b/docs/examples/teams/get-installation.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Teams teams = Teams(client); + +AppInstallation result = await teams.getInstallation( + teamId: '', + installationId: '', +); +``` diff --git a/docs/examples/teams/list-installations.md b/docs/examples/teams/list-installations.md new file mode 100644 index 00000000..18f973e4 --- /dev/null +++ b/docs/examples/teams/list-installations.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Teams teams = Teams(client); + +AppInstallationList result = await teams.listInstallations( + teamId: '', + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/teams/update-installation.md b/docs/examples/teams/update-installation.md new file mode 100644 index 00000000..a9a02cb0 --- /dev/null +++ b/docs/examples/teams/update-installation.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +Teams teams = Teams(client); + +AppInstallation result = await teams.updateInstallation( + teamId: '', + installationId: '', + authorizationDetails: '', // (optional) +); +``` diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index b501fece..1ebf45c0 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -30,6 +30,7 @@ part 'id.dart'; part 'operator.dart'; part 'services/account.dart'; part 'services/activities.dart'; +part 'services/apps.dart'; part 'services/avatars.dart'; part 'services/backups.dart'; part 'services/databases.dart'; @@ -37,6 +38,7 @@ part 'services/functions.dart'; part 'services/graphql.dart'; part 'services/locale.dart'; part 'services/messaging.dart'; +part 'services/oauth2.dart'; part 'services/organization.dart'; part 'services/presences.dart'; part 'services/project.dart'; diff --git a/lib/models.dart b/lib/models.dart index 928f0be6..c8d2458c 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -225,6 +225,10 @@ part 'src/models/billing_plan_limits.dart'; part 'src/models/billing_plan_dedicated_database_limits.dart'; part 'src/models/billing_plan_supported_addons.dart'; part 'src/models/block.dart'; +part 'src/models/dedicated_database.dart'; +part 'src/models/database_status.dart'; +part 'src/models/dedicated_database_member.dart'; +part 'src/models/dedicated_database_replicas.dart'; part 'src/models/organization.dart'; part 'src/models/backup_policy.dart'; part 'src/models/policy_deny_aliased_email.dart'; @@ -233,8 +237,40 @@ part 'src/models/policy_deny_free_email.dart'; part 'src/models/policy_deny_corporate_email.dart'; part 'src/models/program.dart'; part 'src/models/backup_restoration.dart'; +part 'src/models/dedicated_database_specification.dart'; +part 'src/models/dedicated_database_specification_list.dart'; +part 'src/models/dedicated_database_specification_pricing.dart'; +part 'src/models/database_status_connections.dart'; +part 'src/models/database_status_replica.dart'; +part 'src/models/database_status_volume.dart'; part 'src/models/usage_billing_plan.dart'; +part 'src/models/app.dart'; +part 'src/models/app_secret.dart'; +part 'src/models/app_secret_plaintext.dart'; +part 'src/models/app_scope.dart'; +part 'src/models/app_installation.dart'; +part 'src/models/app_key.dart'; +part 'src/models/oauth2_authorize.dart'; +part 'src/models/oauth2_approve.dart'; +part 'src/models/oauth2_reject.dart'; +part 'src/models/oauth2_grant.dart'; +part 'src/models/oauth2_device_authorization.dart'; +part 'src/models/oauth2_par.dart'; +part 'src/models/oauth2_token.dart'; +part 'src/models/oauth2_consent.dart'; +part 'src/models/oauth2_consent_token.dart'; +part 'src/models/oauth2_project.dart'; +part 'src/models/oauth2_organization.dart'; +part 'src/models/oauth2_project_list.dart'; +part 'src/models/oauth2_organization_list.dart'; +part 'src/models/oauth2_consent_list.dart'; +part 'src/models/oauth2_consent_token_list.dart'; part 'src/models/activity_event_list.dart'; part 'src/models/backup_archive_list.dart'; part 'src/models/backup_policy_list.dart'; part 'src/models/backup_restoration_list.dart'; +part 'src/models/apps_list.dart'; +part 'src/models/app_secret_list.dart'; +part 'src/models/app_scope_list.dart'; +part 'src/models/app_installation_list.dart'; +part 'src/models/app_key_list.dart'; diff --git a/lib/services/account.dart b/lib/services/account.dart index ea4a4212..fcf65fca 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -54,6 +54,136 @@ class Account extends Service { return models.User.fromMap(res.data); } + /// Get a list of the OAuth2 consents the current user has given to third-party + /// apps. + Future listConsents( + {List? queries, bool? total}) async { + final String apiPath = '/account/consents'; + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2ConsentList.fromMap(res.data); + } + + /// Get an OAuth2 consent the current user has given to a third-party app by + /// its unique ID. + Future getConsent({required String consentId}) async { + final String apiPath = + '/account/consents/{consentId}'.replaceAll('{consentId}', consentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Consent.fromMap(res.data); + } + + /// Delete an OAuth2 consent by its unique ID. All token families issued under + /// the consent are revoked, and the app must ask for consent again to regain + /// access. + Future deleteConsent({required String consentId}) async { + final String apiPath = + '/account/consents/{consentId}'.replaceAll('{consentId}', consentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Get a list of the token families issued under an OAuth2 consent. Each entry + /// represents one authorized device or session; the token secrets themselves + /// are never returned. + Future listConsentTokens( + {required String consentId, List? queries, bool? total}) async { + final String apiPath = '/account/consents/{consentId}/tokens' + .replaceAll('{consentId}', consentId); + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2ConsentTokenList.fromMap(res.data); + } + + /// Get a token family issued under an OAuth2 consent by its unique ID. The + /// token secrets themselves are never returned. + Future getConsentToken( + {required String consentId, required String tokenId}) async { + final String apiPath = '/account/consents/{consentId}/tokens/{tokenId}' + .replaceAll('{consentId}', consentId) + .replaceAll('{tokenId}', tokenId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2ConsentToken.fromMap(res.data); + } + + /// Delete a token family issued under an OAuth2 consent by its unique ID. The + /// access and refresh tokens of the family stop working immediately; other + /// token families and the consent itself are unaffected. + Future deleteConsentToken( + {required String consentId, required String tokenId}) async { + final String apiPath = '/account/consents/{consentId}/tokens/{tokenId}' + .replaceAll('{consentId}', consentId) + .replaceAll('{tokenId}', tokenId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + /// Update currently logged in user account email address. After changing user /// address, the user confirmation status will get reset. A new confirmation /// email is not sent automatically however you can use the send confirmation diff --git a/lib/services/activities.dart b/lib/services/activities.dart index 0a881b34..ca12675f 100644 --- a/lib/services/activities.dart +++ b/lib/services/activities.dart @@ -1,5 +1,7 @@ part of '../dart_appwrite.dart'; +/// The Activities service allows you to list and inspect project activity +/// events. class Activities extends Service { Activities(super.client); diff --git a/lib/services/apps.dart b/lib/services/apps.dart new file mode 100644 index 00000000..dcd11492 --- /dev/null +++ b/lib/services/apps.dart @@ -0,0 +1,506 @@ +part of '../dart_appwrite.dart'; + +class Apps extends Service { + Apps(super.client); + + /// List applications. + Future list({List? queries, bool? total}) async { + final String apiPath = '/apps'; + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppsList.fromMap(res.data); + } + + /// Create a new application. + Future create( + {required String appId, + required String name, + required List redirectUris, + String? description, + String? clientUri, + String? logoUri, + String? privacyPolicyUrl, + String? termsUrl, + List? contacts, + String? tagline, + List? tags, + List? images, + String? supportUrl, + String? dataDeletionUrl, + List? postLogoutRedirectUris, + bool? enabled, + String? type, + bool? deviceFlow, + String? teamId}) async { + final String apiPath = '/apps'; + + final Map apiParams = { + 'appId': appId, + 'name': name, + if (description != null) 'description': description, + if (clientUri != null) 'clientUri': clientUri, + if (logoUri != null) 'logoUri': logoUri, + if (privacyPolicyUrl != null) 'privacyPolicyUrl': privacyPolicyUrl, + if (termsUrl != null) 'termsUrl': termsUrl, + if (contacts != null) 'contacts': contacts, + if (tagline != null) 'tagline': tagline, + if (tags != null) 'tags': tags, + if (images != null) 'images': images, + if (supportUrl != null) 'supportUrl': supportUrl, + if (dataDeletionUrl != null) 'dataDeletionUrl': dataDeletionUrl, + 'redirectUris': redirectUris, + if (postLogoutRedirectUris != null) + 'postLogoutRedirectUris': postLogoutRedirectUris, + if (enabled != null) 'enabled': enabled, + if (type != null) 'type': type, + if (deviceFlow != null) 'deviceFlow': deviceFlow, + if (teamId != null) 'teamId': teamId, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.App.fromMap(res.data); + } + + /// List scopes an application can request when installed on a team. + Future listInstallationScopes() async { + final String apiPath = '/apps/scopes/installations'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppScopeList.fromMap(res.data); + } + + /// List scopes an application can request during the OAuth2 flow. + Future listOAuth2Scopes() async { + final String apiPath = '/apps/scopes/oauth2'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppScopeList.fromMap(res.data); + } + + /// Get an application by its unique ID. + Future get({required String appId}) async { + final String apiPath = '/apps/{appId}'.replaceAll('{appId}', appId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.App.fromMap(res.data); + } + + /// Update an application by its unique ID. + Future update( + {required String appId, + required String name, + String? description, + String? clientUri, + String? logoUri, + String? privacyPolicyUrl, + String? termsUrl, + List? contacts, + String? tagline, + List? tags, + List? images, + String? supportUrl, + String? dataDeletionUrl, + bool? enabled, + List? redirectUris, + List? postLogoutRedirectUris, + String? type, + bool? deviceFlow, + List? installationScopes, + String? installationRedirectUrl}) async { + final String apiPath = '/apps/{appId}'.replaceAll('{appId}', appId); + + final Map apiParams = { + 'name': name, + if (description != null) 'description': description, + if (clientUri != null) 'clientUri': clientUri, + if (logoUri != null) 'logoUri': logoUri, + if (privacyPolicyUrl != null) 'privacyPolicyUrl': privacyPolicyUrl, + if (termsUrl != null) 'termsUrl': termsUrl, + if (contacts != null) 'contacts': contacts, + if (tagline != null) 'tagline': tagline, + if (tags != null) 'tags': tags, + if (images != null) 'images': images, + if (supportUrl != null) 'supportUrl': supportUrl, + if (dataDeletionUrl != null) 'dataDeletionUrl': dataDeletionUrl, + if (enabled != null) 'enabled': enabled, + if (redirectUris != null) 'redirectUris': redirectUris, + if (postLogoutRedirectUris != null) + 'postLogoutRedirectUris': postLogoutRedirectUris, + if (type != null) 'type': type, + if (deviceFlow != null) 'deviceFlow': deviceFlow, + if (installationScopes != null) 'installationScopes': installationScopes, + if (installationRedirectUrl != null) + 'installationRedirectUrl': installationRedirectUrl, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.App.fromMap(res.data); + } + + /// Delete an application by its unique ID. + Future delete({required String appId}) async { + final String apiPath = '/apps/{appId}'.replaceAll('{appId}', appId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List installations of an application. Requires an app key sent in the + /// `X-Appwrite-Key` header alongside the `X-Appwrite-App` header. + Future listInstallations( + {required String appId, List? queries, bool? total}) async { + final String apiPath = + '/apps/{appId}/installations'.replaceAll('{appId}', appId); + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallationList.fromMap(res.data); + } + + /// Get an installation of an application by its unique ID. Requires an app key + /// sent in the `X-Appwrite-Key` header alongside the `X-Appwrite-App` header. + Future getInstallation( + {required String appId, required String installationId}) async { + final String apiPath = '/apps/{appId}/installations/{installationId}' + .replaceAll('{appId}', appId) + .replaceAll('{installationId}', installationId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Create a token for an installation of an application. Requires an app key + /// sent in the `X-Appwrite-Key` header alongside the `X-Appwrite-App` header. + /// The returned token carries the scopes and authorization details granted to + /// the installation, and can be used as an `Authorization: Bearer` header + /// everywhere OAuth2 access tokens are accepted. Multiple tokens can be active + /// for the same installation at once; each token stays valid until it expires + /// or the installation is updated or deleted. + Future createInstallationToken( + {required String appId, required String installationId}) async { + final String apiPath = '/apps/{appId}/installations/{installationId}/tokens' + .replaceAll('{appId}', appId) + .replaceAll('{installationId}', installationId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Token.fromMap(res.data); + } + + /// List app keys for an application. + Future listKeys( + {required String appId, List? queries, bool? total}) async { + final String apiPath = '/apps/{appId}/keys'.replaceAll('{appId}', appId); + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppKeyList.fromMap(res.data); + } + + /// Create a new app key for an application. App keys carry no scopes; send one + /// in the `X-Appwrite-Key` header alongside the `X-Appwrite-App` header to + /// list the application's installations and create installation access tokens. + Future createKey({required String appId}) async { + final String apiPath = '/apps/{appId}/keys'.replaceAll('{appId}', appId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppKey.fromMap(res.data); + } + + /// Get an app key by its unique ID. + Future getKey( + {required String appId, required String keyId}) async { + final String apiPath = '/apps/{appId}/keys/{keyId}' + .replaceAll('{appId}', appId) + .replaceAll('{keyId}', keyId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppKey.fromMap(res.data); + } + + /// Delete an app key by its unique ID. + Future deleteKey({required String appId, required String keyId}) async { + final String apiPath = '/apps/{appId}/keys/{keyId}' + .replaceAll('{appId}', appId) + .replaceAll('{keyId}', keyId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update the labels of an application. Labels are read-only for clients; only + /// a server SDK using a project API key can set them. Replaces the previous + /// labels. + Future updateLabels( + {required String appId, required List labels}) async { + final String apiPath = '/apps/{appId}/labels'.replaceAll('{appId}', appId); + + final Map apiParams = { + 'labels': labels, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.App.fromMap(res.data); + } + + /// List client secrets for an application. + Future listSecrets( + {required String appId, List? queries, bool? total}) async { + final String apiPath = '/apps/{appId}/secrets'.replaceAll('{appId}', appId); + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppSecretList.fromMap(res.data); + } + + /// Create a new client secret for an application. + Future createSecret( + {required String appId}) async { + final String apiPath = '/apps/{appId}/secrets'.replaceAll('{appId}', appId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppSecretPlaintext.fromMap(res.data); + } + + /// Get an application client secret by its unique ID. + Future getSecret( + {required String appId, required String secretId}) async { + final String apiPath = '/apps/{appId}/secrets/{secretId}' + .replaceAll('{appId}', appId) + .replaceAll('{secretId}', secretId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppSecret.fromMap(res.data); + } + + /// Delete an application client secret by its unique ID. + Future deleteSecret({required String appId, required String secretId}) async { + final String apiPath = '/apps/{appId}/secrets/{secretId}' + .replaceAll('{appId}', appId) + .replaceAll('{secretId}', secretId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Transfer an application to another team by its unique ID. + Future updateTeam( + {required String appId, required String teamId}) async { + final String apiPath = '/apps/{appId}/team'.replaceAll('{appId}', appId); + + final Map apiParams = { + 'teamId': teamId, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.App.fromMap(res.data); + } + + /// Revoke all tokens for an application by its unique ID. + Future deleteTokens({required String appId}) async { + final String apiPath = '/apps/{appId}/tokens'.replaceAll('{appId}', appId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/backups.dart b/lib/services/backups.dart index d248e467..38f65577 100644 --- a/lib/services/backups.dart +++ b/lib/services/backups.dart @@ -1,5 +1,7 @@ part of '../dart_appwrite.dart'; +/// The Backups service allows you to manage backup policies, archives, and +/// restorations for your project. class Backups extends Service { Backups(super.client); @@ -30,7 +32,7 @@ class Backups extends Service { final Map apiParams = { 'services': services.map((e) => e.value).toList(), - 'resourceId': resourceId, + if (resourceId != null) 'resourceId': resourceId, }; final Map apiHeaders = { @@ -116,7 +118,7 @@ class Backups extends Service { 'policyId': policyId, if (name != null) 'name': name, 'services': services.map((e) => e.value).toList(), - 'resourceId': resourceId, + if (resourceId != null) 'resourceId': resourceId, if (enabled != null) 'enabled': enabled, 'retention': retention, 'schedule': schedule, @@ -163,10 +165,10 @@ class Backups extends Service { '/backups/policies/{policyId}'.replaceAll('{policyId}', policyId); final Map apiParams = { - 'name': name, - 'retention': retention, + if (name != null) 'name': name, + if (retention != null) 'retention': retention, if (schedule != null) 'schedule': schedule, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -202,21 +204,35 @@ class Backups extends Service { /// Create and trigger a new restoration for a backup on a project. /// - /// When restoring a DocumentsDB or VectorsDB database to a new resource, pass - /// `newSpecification` to provision the restored database on a different - /// specification than the archived one (for example, restoring onto a larger - /// or smaller dedicated database). Use `serverless` to restore onto the shared - /// pool, or a dedicated specification slug to restore onto a dedicated - /// database of that size. The specification must be permitted by the - /// organization's plan. `newSpecification` is not supported for - /// legacy/TablesDB databases or for bucket restores. + /// For a backup of one database, the restoration resolves its destination + /// before it is queued. Pass `newResourceId` to restore into that database ID, + /// including the archived database ID to overwrite it. When `newResourceId` is + /// omitted, a new database ID is generated and returned in `options`. + /// + /// The restoration migration records the archived database in `resourceId` and + /// `resourceType`, and the resolved database in `destinationResourceId` and + /// `destinationResourceType`. Database types are stored canonically as + /// `database`, `documentsdb`, or `vectorsdb`. Project-wide restorations leave + /// these fields empty because they do not have a single source or destination + /// database. + /// + /// To list every migration related to one database, use its canonical type in + /// a nested `OR(AND(...), AND(...), AND(...))` across the root, parent, and + /// destination relation pairs: `(resourceType, resourceId)`, + /// `(parentResourceType, parentResourceId)`, and `(destinationResourceType, + /// destinationResourceId)`. Legacy and TablesDB databases use `database`; the + /// operational `resourceType` of a table migration is not rewritten to + /// `tablesdb`. + /// + /// When restoring a DocumentsDB or VectorsDB database to a new resource from a + /// dedicated source, the restore provisions a fresh dedicated backing database + /// at the source database's own specification. /// Future createRestoration( {required String archiveId, required List services, String? newResourceId, - String? newResourceName, - String? newSpecification}) async { + String? newResourceName}) async { final String apiPath = '/backups/restoration'; final Map apiParams = { @@ -224,7 +240,6 @@ class Backups extends Service { 'services': services.map((e) => e.value).toList(), if (newResourceId != null) 'newResourceId': newResourceId, if (newResourceName != null) 'newResourceName': newResourceName, - if (newSpecification != null) 'newSpecification': newSpecification, }; final Map apiHeaders = { diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 32e68c5a..89297608 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -307,7 +307,7 @@ class Databases extends Service { final Map apiParams = { 'collectionId': collectionId, 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, if (documentSecurity != null) 'documentSecurity': documentSecurity, if (enabled != null) 'enabled': enabled, if (attributes != null) 'attributes': attributes, @@ -366,7 +366,7 @@ class Databases extends Service { final Map apiParams = { if (name != null) 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, if (documentSecurity != null) 'documentSecurity': documentSecurity, if (enabled != null) 'enabled': enabled, if (purge != null) 'purge': purge, @@ -458,9 +458,9 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, + if (min != null) 'min': min, + if (max != null) 'max': max, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -498,10 +498,10 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, - 'min': min, - 'max': max, + if (min != null) 'min': min, + if (max != null) 'max': max, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -535,7 +535,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -571,7 +571,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -604,7 +604,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -640,7 +640,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -674,7 +674,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -711,7 +711,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -748,7 +748,7 @@ class Databases extends Service { 'key': key, 'elements': elements, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -787,7 +787,7 @@ class Databases extends Service { 'elements': elements, 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -824,9 +824,9 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, + if (min != null) 'min': min, + if (max != null) 'max': max, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -864,10 +864,10 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, - 'min': min, - 'max': max, + if (min != null) 'min': min, + if (max != null) 'max': max, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -904,9 +904,9 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, + if (min != null) 'min': min, + if (max != null) 'max': max, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -944,10 +944,10 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, - 'min': min, - 'max': max, + if (min != null) 'min': min, + if (max != null) 'max': max, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -981,7 +981,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -1018,7 +1018,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1050,7 +1050,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, }; final Map apiHeaders = { @@ -1084,8 +1084,8 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, + if (xdefault != null) 'default': xdefault, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1120,7 +1120,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1158,7 +1158,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1193,7 +1193,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1231,7 +1231,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1263,7 +1263,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, }; final Map apiHeaders = { @@ -1297,8 +1297,8 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, + if (xdefault != null) 'default': xdefault, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1330,7 +1330,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, }; final Map apiHeaders = { @@ -1364,8 +1364,8 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, + if (xdefault != null) 'default': xdefault, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1403,8 +1403,8 @@ class Databases extends Service { 'relatedCollectionId': relatedCollectionId, 'type': type.value, if (twoWay != null) 'twoWay': twoWay, - 'key': key, - 'twoWayKey': twoWayKey, + if (key != null) 'key': key, + if (twoWayKey != null) 'twoWayKey': twoWayKey, if (onDelete != null) 'onDelete': onDelete.value, }; @@ -1439,7 +1439,7 @@ class Databases extends Service { final Map apiParams = { if (onDelete != null) 'onDelete': onDelete.value, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1476,7 +1476,7 @@ class Databases extends Service { 'key': key, 'size': size, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1515,8 +1515,8 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'size': size, - 'newKey': newKey, + if (size != null) 'size': size, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1551,7 +1551,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1589,7 +1589,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1623,7 +1623,7 @@ class Databases extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -1660,7 +1660,7 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1697,7 +1697,7 @@ class Databases extends Service { 'key': key, 'size': size, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1736,8 +1736,8 @@ class Databases extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'size': size, - 'newKey': newKey, + if (size != null) 'size': size, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1899,8 +1899,8 @@ class Databases extends Service { final Map apiParams = { 'documentId': documentId, 'data': data, - 'permissions': permissions, - 'transactionId': transactionId, + if (permissions != null) 'permissions': permissions, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -1933,7 +1933,7 @@ class Databases extends Service { final Map apiParams = { 'documents': documents, - 'transactionId': transactionId, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -1967,7 +1967,7 @@ class Databases extends Service { final Map apiParams = { 'documents': documents, - 'transactionId': transactionId, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2001,7 +2001,7 @@ class Databases extends Service { final Map apiParams = { if (data != null) 'data': data, if (queries != null) 'queries': queries, - 'transactionId': transactionId, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2100,8 +2100,8 @@ class Databases extends Service { final Map apiParams = { if (data != null) 'data': data, - 'permissions': permissions, - 'transactionId': transactionId, + if (permissions != null) 'permissions': permissions, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2135,8 +2135,8 @@ class Databases extends Service { final Map apiParams = { if (data != null) 'data': data, - 'permissions': permissions, - 'transactionId': transactionId, + if (permissions != null) 'permissions': permissions, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2200,8 +2200,8 @@ class Databases extends Service { final Map apiParams = { if (value != null) 'value': value, - 'min': min, - 'transactionId': transactionId, + if (min != null) 'min': min, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2236,8 +2236,8 @@ class Databases extends Service { final Map apiParams = { if (value != null) 'value': value, - 'max': max, - 'transactionId': transactionId, + if (max != null) 'max': max, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 7eeecb35..b6c47b8f 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -192,14 +192,15 @@ class Functions extends Service { if (commands != null) 'commands': commands, if (scopes != null) 'scopes': scopes.map((e) => e.value).toList(), if (installationId != null) 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, + if (providerRepositoryId != null) + 'providerRepositoryId': providerRepositoryId, if (providerBranch != null) 'providerBranch': providerBranch, if (providerSilentMode != null) 'providerSilentMode': providerSilentMode, if (providerRootDirectory != null) 'providerRootDirectory': providerRootDirectory, - 'providerBranches': providerBranches, - 'providerPaths': providerPaths, - 'buildSpecification': buildSpecification, + if (providerBranches != null) 'providerBranches': providerBranches, + if (providerPaths != null) 'providerPaths': providerPaths, + if (buildSpecification != null) 'buildSpecification': buildSpecification, if (runtimeSpecification != null) 'runtimeSpecification': runtimeSpecification, if (deploymentRetention != null) @@ -564,7 +565,7 @@ class Functions extends Service { if (path != null) 'path': path, if (method != null) 'method': method.value, if (headers != null) 'headers': headers, - 'scheduledAt': scheduledAt, + if (scheduledAt != null) 'scheduledAt': scheduledAt, }; final Map apiHeaders = { @@ -703,9 +704,9 @@ class Functions extends Service { .replaceAll('{variableId}', variableId); final Map apiParams = { - 'key': key, - 'value': value, - 'secret': secret, + if (key != null) 'key': key, + if (value != null) 'value': value, + if (secret != null) 'secret': secret, }; final Map apiHeaders = { diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index 278b3464..a3332962 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -55,7 +55,7 @@ class Messaging extends Service { if (attachments != null) 'attachments': attachments, if (draft != null) 'draft': draft, if (html != null) 'html': html, - 'scheduledAt': scheduledAt, + if (scheduledAt != null) 'scheduledAt': scheduledAt, }; final Map apiHeaders = { @@ -91,17 +91,17 @@ class Messaging extends Service { .replaceAll('{messageId}', messageId); final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'subject': subject, - 'content': content, - 'draft': draft, - 'html': html, - 'cc': cc, - 'bcc': bcc, - 'scheduledAt': scheduledAt, - 'attachments': attachments, + if (topics != null) 'topics': topics, + if (users != null) 'users': users, + if (targets != null) 'targets': targets, + if (subject != null) 'subject': subject, + if (content != null) 'content': content, + if (draft != null) 'draft': draft, + if (html != null) 'html': html, + if (cc != null) 'cc': cc, + if (bcc != null) 'bcc': bcc, + if (scheduledAt != null) 'scheduledAt': scheduledAt, + if (attachments != null) 'attachments': attachments, }; final Map apiHeaders = { @@ -146,7 +146,7 @@ class Messaging extends Service { if (topics != null) 'topics': topics, if (users != null) 'users': users, if (targets != null) 'targets': targets, - 'data': data, + if (data != null) 'data': data, if (action != null) 'action': action, if (image != null) 'image': image, if (icon != null) 'icon': icon, @@ -155,7 +155,7 @@ class Messaging extends Service { if (tag != null) 'tag': tag, if (badge != null) 'badge': badge, if (draft != null) 'draft': draft, - 'scheduledAt': scheduledAt, + if (scheduledAt != null) 'scheduledAt': scheduledAt, if (contentAvailable != null) 'contentAvailable': contentAvailable, if (critical != null) 'critical': critical, if (priority != null) 'priority': priority.value, @@ -201,24 +201,24 @@ class Messaging extends Service { .replaceAll('{messageId}', messageId); final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'title': title, - 'body': body, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - 'contentAvailable': contentAvailable, - 'critical': critical, - 'priority': priority?.value, + if (topics != null) 'topics': topics, + if (users != null) 'users': users, + if (targets != null) 'targets': targets, + if (title != null) 'title': title, + if (body != null) 'body': body, + if (data != null) 'data': data, + if (action != null) 'action': action, + if (image != null) 'image': image, + if (icon != null) 'icon': icon, + if (sound != null) 'sound': sound, + if (color != null) 'color': color, + if (tag != null) 'tag': tag, + if (badge != null) 'badge': badge, + if (draft != null) 'draft': draft, + if (scheduledAt != null) 'scheduledAt': scheduledAt, + if (contentAvailable != null) 'contentAvailable': contentAvailable, + if (critical != null) 'critical': critical, + if (priority != null) 'priority': priority.value, }; final Map apiHeaders = { @@ -253,7 +253,7 @@ class Messaging extends Service { if (users != null) 'users': users, if (targets != null) 'targets': targets, if (draft != null) 'draft': draft, - 'scheduledAt': scheduledAt, + if (scheduledAt != null) 'scheduledAt': scheduledAt, }; final Map apiHeaders = { @@ -286,7 +286,7 @@ class Messaging extends Service { if (users != null) 'users': users, if (targets != null) 'targets': targets, if (draft != null) 'draft': draft, - 'scheduledAt': scheduledAt, + if (scheduledAt != null) 'scheduledAt': scheduledAt, }; final Map apiHeaders = { @@ -319,12 +319,12 @@ class Messaging extends Service { .replaceAll('{messageId}', messageId); final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'content': content, - 'draft': draft, - 'scheduledAt': scheduledAt, + if (topics != null) 'topics': topics, + if (users != null) 'users': users, + if (targets != null) 'targets': targets, + if (content != null) 'content': content, + if (draft != null) 'draft': draft, + if (scheduledAt != null) 'scheduledAt': scheduledAt, }; final Map apiHeaders = { @@ -355,12 +355,12 @@ class Messaging extends Service { .replaceAll('{messageId}', messageId); final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'content': content, - 'draft': draft, - 'scheduledAt': scheduledAt, + if (topics != null) 'topics': topics, + if (users != null) 'users': users, + if (targets != null) 'targets': targets, + if (content != null) 'content': content, + if (draft != null) 'draft': draft, + if (scheduledAt != null) 'scheduledAt': scheduledAt, }; final Map apiHeaders = { @@ -479,7 +479,7 @@ class Messaging extends Service { if (teamId != null) 'teamId': teamId, if (bundleId != null) 'bundleId': bundleId, if (sandbox != null) 'sandbox': sandbox, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -514,7 +514,7 @@ class Messaging extends Service { if (teamId != null) 'teamId': teamId, if (bundleId != null) 'bundleId': bundleId, if (sandbox != null) 'sandbox': sandbox, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -546,12 +546,12 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (authKey != null) 'authKey': authKey, if (authKeyId != null) 'authKeyId': authKeyId, if (teamId != null) 'teamId': teamId, if (bundleId != null) 'bundleId': bundleId, - 'sandbox': sandbox, + if (sandbox != null) 'sandbox': sandbox, }; final Map apiHeaders = { @@ -581,12 +581,12 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (authKey != null) 'authKey': authKey, if (authKeyId != null) 'authKeyId': authKeyId, if (teamId != null) 'teamId': teamId, if (bundleId != null) 'bundleId': bundleId, - 'sandbox': sandbox, + if (sandbox != null) 'sandbox': sandbox, }; final Map apiHeaders = { @@ -614,8 +614,8 @@ class Messaging extends Service { final Map apiParams = { 'providerId': providerId, 'name': name, - 'serviceAccountJSON': serviceAccountJSON, - 'enabled': enabled, + if (serviceAccountJSON != null) 'serviceAccountJSON': serviceAccountJSON, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -641,8 +641,8 @@ class Messaging extends Service { final Map apiParams = { 'providerId': providerId, 'name': name, - 'serviceAccountJSON': serviceAccountJSON, - 'enabled': enabled, + if (serviceAccountJSON != null) 'serviceAccountJSON': serviceAccountJSON, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -670,8 +670,8 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, - 'serviceAccountJSON': serviceAccountJSON, + if (enabled != null) 'enabled': enabled, + if (serviceAccountJSON != null) 'serviceAccountJSON': serviceAccountJSON, }; final Map apiHeaders = { @@ -697,8 +697,8 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, - 'serviceAccountJSON': serviceAccountJSON, + if (enabled != null) 'enabled': enabled, + if (serviceAccountJSON != null) 'serviceAccountJSON': serviceAccountJSON, }; final Map apiHeaders = { @@ -732,12 +732,12 @@ class Messaging extends Service { 'name': name, if (apiKey != null) 'apiKey': apiKey, if (domain != null) 'domain': domain, - 'isEuRegion': isEuRegion, + if (isEuRegion != null) 'isEuRegion': isEuRegion, if (fromName != null) 'fromName': fromName, if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -771,8 +771,8 @@ class Messaging extends Service { if (name != null) 'name': name, if (apiKey != null) 'apiKey': apiKey, if (domain != null) 'domain': domain, - 'isEuRegion': isEuRegion, - 'enabled': enabled, + if (isEuRegion != null) 'isEuRegion': isEuRegion, + if (enabled != null) 'enabled': enabled, if (fromName != null) 'fromName': fromName, if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, @@ -807,7 +807,7 @@ class Messaging extends Service { if (templateId != null) 'templateId': templateId, if (senderId != null) 'senderId': senderId, if (authKey != null) 'authKey': authKey, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -835,7 +835,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (templateId != null) 'templateId': templateId, if (senderId != null) 'senderId': senderId, if (authKey != null) 'authKey': authKey, @@ -873,7 +873,7 @@ class Messaging extends Service { if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -903,7 +903,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (apiKey != null) 'apiKey': apiKey, if (fromName != null) 'fromName': fromName, if (fromEmail != null) 'fromEmail': fromEmail, @@ -943,7 +943,7 @@ class Messaging extends Service { if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -973,7 +973,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (apiKey != null) 'apiKey': apiKey, if (fromName != null) 'fromName': fromName, if (fromEmail != null) 'fromEmail': fromEmail, @@ -1017,7 +1017,7 @@ class Messaging extends Service { if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1049,7 +1049,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (accessKey != null) 'accessKey': accessKey, if (secretKey != null) 'secretKey': secretKey, if (region != null) 'region': region, @@ -1105,7 +1105,7 @@ class Messaging extends Service { if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1152,7 +1152,7 @@ class Messaging extends Service { if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1191,17 +1191,17 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, if (host != null) 'host': host, - 'port': port, + if (port != null) 'port': port, if (username != null) 'username': username, if (password != null) 'password': password, if (encryption != null) 'encryption': encryption.value, - 'autoTLS': autoTLS, + if (autoTLS != null) 'autoTLS': autoTLS, if (mailer != null) 'mailer': mailer, if (fromName != null) 'fromName': fromName, if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1238,17 +1238,17 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, if (host != null) 'host': host, - 'port': port, + if (port != null) 'port': port, if (username != null) 'username': username, if (password != null) 'password': password, if (encryption != null) 'encryption': encryption.value, - 'autoTLS': autoTLS, + if (autoTLS != null) 'autoTLS': autoTLS, if (mailer != null) 'mailer': mailer, if (fromName != null) 'fromName': fromName, if (fromEmail != null) 'fromEmail': fromEmail, if (replyToName != null) 'replyToName': replyToName, if (replyToEmail != null) 'replyToEmail': replyToEmail, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1279,7 +1279,7 @@ class Messaging extends Service { if (from != null) 'from': from, if (customerId != null) 'customerId': customerId, if (apiKey != null) 'apiKey': apiKey, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1307,7 +1307,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (customerId != null) 'customerId': customerId, if (apiKey != null) 'apiKey': apiKey, if (from != null) 'from': from, @@ -1341,7 +1341,7 @@ class Messaging extends Service { if (from != null) 'from': from, if (username != null) 'username': username, if (apiKey != null) 'apiKey': apiKey, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1369,7 +1369,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (username != null) 'username': username, if (apiKey != null) 'apiKey': apiKey, if (from != null) 'from': from, @@ -1403,7 +1403,7 @@ class Messaging extends Service { if (from != null) 'from': from, if (accountSid != null) 'accountSid': accountSid, if (authToken != null) 'authToken': authToken, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1431,7 +1431,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (accountSid != null) 'accountSid': accountSid, if (authToken != null) 'authToken': authToken, if (from != null) 'from': from, @@ -1465,7 +1465,7 @@ class Messaging extends Service { if (from != null) 'from': from, if (apiKey != null) 'apiKey': apiKey, if (apiSecret != null) 'apiSecret': apiSecret, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1493,7 +1493,7 @@ class Messaging extends Service { final Map apiParams = { if (name != null) 'name': name, - 'enabled': enabled, + if (enabled != null) 'enabled': enabled, if (apiKey != null) 'apiKey': apiKey, if (apiSecret != null) 'apiSecret': apiSecret, if (from != null) 'from': from, @@ -1622,8 +1622,8 @@ class Messaging extends Service { '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); final Map apiParams = { - 'name': name, - 'subscribe': subscribe, + if (name != null) 'name': name, + if (subscribe != null) 'subscribe': subscribe, }; final Map apiHeaders = { diff --git a/lib/services/oauth2.dart b/lib/services/oauth2.dart new file mode 100644 index 00000000..3fcea3c5 --- /dev/null +++ b/lib/services/oauth2.dart @@ -0,0 +1,402 @@ +part of '../dart_appwrite.dart'; + +/// The OAuth2 service allows you to authorize apps and issue standards-based +/// OAuth2 and OpenID Connect tokens. +class Oauth2 extends Service { + Oauth2(super.client); + + /// Approve an OAuth2 grant after the user gives consent. Returns the + /// `redirectUrl` the end user should be sent to. The consent screen may + /// optionally pass enriched `authorization_details` to record the concrete + /// resources the user selected. You can pass Accept header of + /// `application/json` to receive a JSON response instead of a redirect. + Future approve( + {required String grantId, + String? authorizationDetails, + String? scope}) async { + final String apiPath = '/oauth2/{project_id}/approve' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + 'grant_id': grantId, + if (authorizationDetails != null) + 'authorization_details': authorizationDetails, + if (scope != null) 'scope': scope, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Approve.fromMap(res.data); + } + + /// Begin the OAuth2 authorization flow. When called without a session, the + /// user is redirected to the consent screen without grant ID. When called with + /// a session, the redirect URL includes param for grant ID. You can pass + /// Accept header of `application/json` to receive a JSON response instead of a + /// redirect. + Future authorize( + {String? clientId, + String? redirectUri, + String? responseType, + String? scope, + String? state, + String? nonce, + String? codeChallenge, + String? codeChallengeMethod, + String? prompt, + int? maxAge, + String? authorizationDetails, + String? resource, + String? audience, + String? requestUri}) async { + final String apiPath = '/oauth2/{project_id}/authorize' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + if (clientId != null) 'client_id': clientId, + if (redirectUri != null) 'redirect_uri': redirectUri, + if (responseType != null) 'response_type': responseType, + if (scope != null) 'scope': scope, + if (state != null) 'state': state, + if (nonce != null) 'nonce': nonce, + if (codeChallenge != null) 'code_challenge': codeChallenge, + if (codeChallengeMethod != null) + 'code_challenge_method': codeChallengeMethod, + if (prompt != null) 'prompt': prompt, + if (maxAge != null) 'max_age': maxAge, + if (authorizationDetails != null) + 'authorization_details': authorizationDetails, + if (resource != null) 'resource': resource, + if (audience != null) 'audience': audience, + if (requestUri != null) 'request_uri': requestUri, + }; + + final Map apiHeaders = { + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Authorize.fromMap(res.data); + } + + /// Begin the OAuth2 authorization flow. When called without a session, the + /// user is redirected to the consent screen without grant ID. When called with + /// a session, the redirect URL includes param for grant ID. You can pass + /// Accept header of `application/json` to receive a JSON response instead of a + /// redirect. + Future authorizePost( + {String? clientId, + String? redirectUri, + String? responseType, + String? scope, + String? state, + String? nonce, + String? codeChallenge, + String? codeChallengeMethod, + String? prompt, + int? maxAge, + String? authorizationDetails, + String? resource, + String? audience, + String? requestUri}) async { + final String apiPath = '/oauth2/{project_id}/authorize' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + if (clientId != null) 'client_id': clientId, + if (redirectUri != null) 'redirect_uri': redirectUri, + if (responseType != null) 'response_type': responseType, + if (scope != null) 'scope': scope, + if (state != null) 'state': state, + if (nonce != null) 'nonce': nonce, + if (codeChallenge != null) 'code_challenge': codeChallenge, + if (codeChallengeMethod != null) + 'code_challenge_method': codeChallengeMethod, + if (prompt != null) 'prompt': prompt, + if (maxAge != null) 'max_age': maxAge, + if (authorizationDetails != null) + 'authorization_details': authorizationDetails, + if (resource != null) 'resource': resource, + if (audience != null) 'audience': audience, + if (requestUri != null) 'request_uri': requestUri, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Authorize.fromMap(res.data); + } + + /// Start the OAuth2 Device Authorization Grant. Returns the device code, user + /// code, verification URL, expiration, and polling interval. + Future createDeviceAuthorization( + {String? clientId, + String? scope, + String? authorizationDetails, + String? resource, + String? audience}) async { + final String apiPath = '/oauth2/{project_id}/device_authorization' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + if (clientId != null) 'client_id': clientId, + if (scope != null) 'scope': scope, + if (authorizationDetails != null) + 'authorization_details': authorizationDetails, + if (resource != null) 'resource': resource, + if (audience != null) 'audience': audience, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2DeviceAuthorization.fromMap(res.data); + } + + /// Exchange a device flow user code for an OAuth2 grant. The authenticated + /// user is bound to the pending grant. Pass the returned grant ID to the get + /// grant endpoint to render the consent screen, then to the approve or reject + /// endpoint to complete the flow. + Future createGrant({required String userCode}) async { + final String apiPath = '/oauth2/{project_id}/grants' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + 'user_code': userCode, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Grant.fromMap(res.data); + } + + /// Get an OAuth2 grant by its ID. Used by the consent screen to display the + /// details of the authorization the user is being asked to approve. A grant + /// can only be read by the user it belongs to, or by server SDK. + Future getGrant({required String grantId}) async { + final String apiPath = '/oauth2/{project_id}/grants/{grant_id}' + .replaceAll('{project_id}', client.config['project'] ?? '') + .replaceAll('{grant_id}', grantId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Grant.fromMap(res.data); + } + + /// List the organizations the OAuth2 access token can access. Resolves the + /// token's `organization` authorization details, expanding the `*` wildcard + /// into the concrete set of organizations the user can see. + Future listOrganizations( + {int? limit, int? offset, String? search}) async { + final String apiPath = '/oauth2/{project_id}/organizations' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + if (limit != null) 'limit': limit, + if (offset != null) 'offset': offset, + if (search != null) 'search': search, + }; + + final Map apiHeaders = { + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2OrganizationList.fromMap(res.data); + } + + /// Store an OAuth2 authorization request server-side and receive a short-lived + /// request_uri handle for the authorize endpoint. + Future createPAR( + {required String clientId, + required String redirectUri, + required String responseType, + String? scope, + String? state, + String? nonce, + String? codeChallenge, + String? codeChallengeMethod, + String? prompt, + int? maxAge, + String? authorizationDetails, + String? resource, + String? audience}) async { + final String apiPath = '/oauth2/{project_id}/par' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + 'client_id': clientId, + 'redirect_uri': redirectUri, + 'response_type': responseType, + if (scope != null) 'scope': scope, + if (state != null) 'state': state, + if (nonce != null) 'nonce': nonce, + if (codeChallenge != null) 'code_challenge': codeChallenge, + if (codeChallengeMethod != null) + 'code_challenge_method': codeChallengeMethod, + if (prompt != null) 'prompt': prompt, + if (maxAge != null) 'max_age': maxAge, + if (authorizationDetails != null) + 'authorization_details': authorizationDetails, + if (resource != null) 'resource': resource, + if (audience != null) 'audience': audience, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2PAR.fromMap(res.data); + } + + /// List the projects the OAuth2 access token can access. Resolves the token's + /// `project` authorization details, expanding the `*` wildcard into the + /// concrete set of projects the user can see. + Future listProjects( + {int? limit, int? offset, String? search}) async { + final String apiPath = '/oauth2/{project_id}/projects' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + if (limit != null) 'limit': limit, + if (offset != null) 'offset': offset, + if (search != null) 'search': search, + }; + + final Map apiHeaders = { + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2ProjectList.fromMap(res.data); + } + + /// Reject an OAuth2 grant when the user denies consent. Returns the + /// `redirectUrl` the end user should be sent to with an `access_denied` error. + /// You can pass Accept header of `application/json` to receive a JSON response + /// instead of a redirect. + Future reject({required String grantId}) async { + final String apiPath = '/oauth2/{project_id}/reject' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + 'grant_id': grantId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Reject.fromMap(res.data); + } + + /// Revoke an OAuth2 access token or refresh token. + Future revoke( + {required String token, + String? tokenTypeHint, + String? clientId, + String? clientSecret}) async { + final String apiPath = '/oauth2/{project_id}/revoke' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + 'token': token, + if (tokenTypeHint != null) 'token_type_hint': tokenTypeHint, + if (clientId != null) 'client_id': clientId, + if (clientSecret != null) 'client_secret': clientSecret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Exchange an OAuth2 authorization code, refresh token, or device code for + /// access and refresh tokens. + Future createToken( + {required String grantType, + String? code, + String? refreshToken, + String? deviceCode, + String? clientId, + String? clientSecret, + String? codeVerifier, + String? redirectUri, + String? resource, + String? audience}) async { + final String apiPath = '/oauth2/{project_id}/token' + .replaceAll('{project_id}', client.config['project'] ?? ''); + + final Map apiParams = { + 'grant_type': grantType, + if (code != null) 'code': code, + if (refreshToken != null) 'refresh_token': refreshToken, + if (deviceCode != null) 'device_code': deviceCode, + if (clientId != null) 'client_id': clientId, + if (clientSecret != null) 'client_secret': clientSecret, + if (codeVerifier != null) 'code_verifier': codeVerifier, + if (redirectUri != null) 'redirect_uri': redirectUri, + if (resource != null) 'resource': resource, + if (audience != null) 'audience': audience, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Oauth2Token.fromMap(res.data); + } +} diff --git a/lib/services/organization.dart b/lib/services/organization.dart index 972d9a0b..57be946a 100644 --- a/lib/services/organization.dart +++ b/lib/services/organization.dart @@ -59,6 +59,120 @@ class Organization extends Service { return res.data; } + /// List app installations on the organization. Any organization member can + /// read installations. + Future listInstallations( + {List? queries, bool? total}) async { + final String apiPath = '/organization/installations'; + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallationList.fromMap(res.data); + } + + /// Install an app on the organization. Only organization members with the + /// owner role can install apps. The installation is granted the scopes the app + /// currently requests. + Future createInstallation( + {required String appId, String? authorizationDetails}) async { + final String apiPath = '/organization/installations'; + + final Map apiParams = { + 'appId': appId, + if (authorizationDetails != null) + 'authorizationDetails': authorizationDetails, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Get an app installation on the organization by its unique ID. Any + /// organization member can read installations. + Future getInstallation( + {required String installationId}) async { + final String apiPath = '/organization/installations/{installationId}' + .replaceAll('{installationId}', installationId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Update an app installation on the organization. Only organization members + /// with the owner role can update installations. The installation's granted + /// scopes are refreshed to the scopes the app currently requests; previously + /// issued installation access tokens are revoked. + Future updateInstallation( + {required String installationId, String? authorizationDetails}) async { + final String apiPath = '/organization/installations/{installationId}' + .replaceAll('{installationId}', installationId); + + final Map apiParams = { + if (authorizationDetails != null) + 'authorizationDetails': authorizationDetails, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Uninstall an app from the organization by its installation ID. Only + /// organization members with the owner role can remove installations. + /// Previously issued installation access tokens are revoked. + Future deleteInstallation({required String installationId}) async { + final String apiPath = '/organization/installations/{installationId}' + .replaceAll('{installationId}', installationId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + /// Get a list of all API keys from the current organization. Future listKeys({List? queries, bool? total}) async { final String apiPath = '/organization/keys'; @@ -91,7 +205,7 @@ class Organization extends Service { 'keyId': keyId, 'name': name, 'scopes': scopes.map((e) => e.value).toList(), - 'expire': expire, + if (expire != null) 'expire': expire, }; final Map apiHeaders = { @@ -138,7 +252,7 @@ class Organization extends Service { final Map apiParams = { 'name': name, 'scopes': scopes.map((e) => e.value).toList(), - 'expire': expire, + if (expire != null) 'expire': expire, }; final Map apiHeaders = { diff --git a/lib/services/presences.dart b/lib/services/presences.dart index 8d577ff2..16b86921 100644 --- a/lib/services/presences.dart +++ b/lib/services/presences.dart @@ -1,5 +1,7 @@ part of '../dart_appwrite.dart'; +/// The Presences service allows you to track and manage real-time user +/// presence in your project. class Presences extends Service { Presences(super.client); diff --git a/lib/services/project.dart b/lib/services/project.dart index cf12f612..f2a5dccb 100644 --- a/lib/services/project.dart +++ b/lib/services/project.dart @@ -98,7 +98,7 @@ class Project extends Service { 'keyId': keyId, 'name': name, 'scopes': scopes.map((e) => e.value).toList(), - 'expire': expire, + if (expire != null) 'expire': expire, }; final Map apiHeaders = { @@ -169,7 +169,7 @@ class Project extends Service { final Map apiParams = { 'name': name, 'scopes': scopes.map((e) => e.value).toList(), - 'expire': expire, + if (expire != null) 'expire': expire, }; final Map apiHeaders = { @@ -362,6 +362,7 @@ class Project extends Service { int? refreshTokenDuration, int? publicAccessTokenDuration, int? publicRefreshTokenDuration, + int? installationAccessTokenDuration, bool? confidentialPkce, String? verificationUrl, int? userCodeLength, @@ -376,15 +377,21 @@ class Project extends Service { if (scopes != null) 'scopes': scopes, if (authorizationDetailsTypes != null) 'authorizationDetailsTypes': authorizationDetailsTypes, - 'accessTokenDuration': accessTokenDuration, - 'refreshTokenDuration': refreshTokenDuration, - 'publicAccessTokenDuration': publicAccessTokenDuration, - 'publicRefreshTokenDuration': publicRefreshTokenDuration, - 'confidentialPkce': confidentialPkce, + if (accessTokenDuration != null) + 'accessTokenDuration': accessTokenDuration, + if (refreshTokenDuration != null) + 'refreshTokenDuration': refreshTokenDuration, + if (publicAccessTokenDuration != null) + 'publicAccessTokenDuration': publicAccessTokenDuration, + if (publicRefreshTokenDuration != null) + 'publicRefreshTokenDuration': publicRefreshTokenDuration, + if (installationAccessTokenDuration != null) + 'installationAccessTokenDuration': installationAccessTokenDuration, + if (confidentialPkce != null) 'confidentialPkce': confidentialPkce, if (verificationUrl != null) 'verificationUrl': verificationUrl, - 'userCodeLength': userCodeLength, + if (userCodeLength != null) 'userCodeLength': userCodeLength, if (userCodeFormat != null) 'userCodeFormat': userCodeFormat, - 'deviceCodeDuration': deviceCodeDuration, + if (deviceCodeDuration != null) 'deviceCodeDuration': deviceCodeDuration, if (defaultScopes != null) 'defaultScopes': defaultScopes, }; @@ -406,9 +413,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/amazon'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -433,11 +440,11 @@ class Project extends Service { final String apiPath = '/project/oauth2/apple'; final Map apiParams = { - 'serviceId': serviceId, - 'keyId': keyId, - 'teamId': teamId, - 'p8File': p8File, - 'enabled': enabled, + if (serviceId != null) 'serviceId': serviceId, + if (keyId != null) 'keyId': keyId, + if (teamId != null) 'teamId': teamId, + if (p8File != null) 'p8File': p8File, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -458,9 +465,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/appwrite'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -484,10 +491,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/auth0'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'endpoint': endpoint, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (endpoint != null) 'endpoint': endpoint, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -511,10 +518,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/authentik'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'endpoint': endpoint, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (endpoint != null) 'endpoint': endpoint, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -535,9 +542,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/autodesk'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -558,9 +565,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/bitbucket'; final Map apiParams = { - 'key': key, - 'secret': secret, - 'enabled': enabled, + if (key != null) 'key': key, + if (secret != null) 'secret': secret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -581,9 +588,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/bitly'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -604,9 +611,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/box'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -627,9 +634,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/dailymotion'; final Map apiParams = { - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'enabled': enabled, + if (apiKey != null) 'apiKey': apiKey, + if (apiSecret != null) 'apiSecret': apiSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -650,9 +657,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/discord'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -673,9 +680,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/disqus'; final Map apiParams = { - 'publicKey': publicKey, - 'secretKey': secretKey, - 'enabled': enabled, + if (publicKey != null) 'publicKey': publicKey, + if (secretKey != null) 'secretKey': secretKey, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -696,9 +703,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/dropbox'; final Map apiParams = { - 'appKey': appKey, - 'appSecret': appSecret, - 'enabled': enabled, + if (appKey != null) 'appKey': appKey, + if (appSecret != null) 'appSecret': appSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -719,9 +726,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/etsy'; final Map apiParams = { - 'keyString': keyString, - 'sharedSecret': sharedSecret, - 'enabled': enabled, + if (keyString != null) 'keyString': keyString, + if (sharedSecret != null) 'sharedSecret': sharedSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -742,9 +749,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/facebook'; final Map apiParams = { - 'appId': appId, - 'appSecret': appSecret, - 'enabled': enabled, + if (appId != null) 'appId': appId, + if (appSecret != null) 'appSecret': appSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -765,9 +772,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/figma'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -791,10 +798,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/fusionauth'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'endpoint': endpoint, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (endpoint != null) 'endpoint': endpoint, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -815,9 +822,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/github'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -841,10 +848,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/gitlab'; final Map apiParams = { - 'applicationId': applicationId, - 'secret': secret, - 'endpoint': endpoint, - 'enabled': enabled, + if (applicationId != null) 'applicationId': applicationId, + if (secret != null) 'secret': secret, + if (endpoint != null) 'endpoint': endpoint, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -868,10 +875,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/google'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'prompt': prompt?.map((e) => e.value).toList(), - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (prompt != null) 'prompt': prompt.map((e) => e.value).toList(), + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -896,11 +903,11 @@ class Project extends Service { final String apiPath = '/project/oauth2/keycloak'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'endpoint': endpoint, - 'realmName': realmName, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (endpoint != null) 'endpoint': endpoint, + if (realmName != null) 'realmName': realmName, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -921,9 +928,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/kick'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -944,9 +951,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/linkedin'; final Map apiParams = { - 'clientId': clientId, - 'primaryClientSecret': primaryClientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (primaryClientSecret != null) + 'primaryClientSecret': primaryClientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -970,10 +978,10 @@ class Project extends Service { final String apiPath = '/project/oauth2/microsoft'; final Map apiParams = { - 'applicationId': applicationId, - 'applicationSecret': applicationSecret, - 'tenant': tenant, - 'enabled': enabled, + if (applicationId != null) 'applicationId': applicationId, + if (applicationSecret != null) 'applicationSecret': applicationSecret, + if (tenant != null) 'tenant': tenant, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -994,9 +1002,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/notion'; final Map apiParams = { - 'oauthClientId': oauthClientId, - 'oauthClientSecret': oauthClientSecret, - 'enabled': enabled, + if (oauthClientId != null) 'oauthClientId': oauthClientId, + if (oauthClientSecret != null) 'oauthClientSecret': oauthClientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1025,15 +1033,15 @@ class Project extends Service { final String apiPath = '/project/oauth2/oidc'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'wellKnownURL': wellKnownURL, - 'authorizationURL': authorizationURL, - 'tokenURL': tokenURL, - 'userInfoURL': userInfoURL, - 'prompt': prompt?.map((e) => e.value).toList(), - 'maxAge': maxAge, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (wellKnownURL != null) 'wellKnownURL': wellKnownURL, + if (authorizationURL != null) 'authorizationURL': authorizationURL, + if (tokenURL != null) 'tokenURL': tokenURL, + if (userInfoURL != null) 'userInfoURL': userInfoURL, + if (prompt != null) 'prompt': prompt.map((e) => e.value).toList(), + if (maxAge != null) 'maxAge': maxAge, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1058,11 +1066,12 @@ class Project extends Service { final String apiPath = '/project/oauth2/okta'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'domain': domain, - 'authorizationServerId': authorizationServerId, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (domain != null) 'domain': domain, + if (authorizationServerId != null) + 'authorizationServerId': authorizationServerId, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1083,9 +1092,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/paypal'; final Map apiParams = { - 'clientId': clientId, - 'secretKey': secretKey, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (secretKey != null) 'secretKey': secretKey, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1106,9 +1115,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/paypalSandbox'; final Map apiParams = { - 'clientId': clientId, - 'secretKey': secretKey, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (secretKey != null) 'secretKey': secretKey, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1129,9 +1138,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/podio'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1152,9 +1161,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/salesforce'; final Map apiParams = { - 'customerKey': customerKey, - 'customerSecret': customerSecret, - 'enabled': enabled, + if (customerKey != null) 'customerKey': customerKey, + if (customerSecret != null) 'customerSecret': customerSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1175,9 +1184,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/slack'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1198,9 +1207,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/spotify'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1221,9 +1230,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/stripe'; final Map apiParams = { - 'clientId': clientId, - 'apiSecretKey': apiSecretKey, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (apiSecretKey != null) 'apiSecretKey': apiSecretKey, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1246,9 +1255,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/tradeshift'; final Map apiParams = { - 'oauth2ClientId': oauth2ClientId, - 'oauth2ClientSecret': oauth2ClientSecret, - 'enabled': enabled, + if (oauth2ClientId != null) 'oauth2ClientId': oauth2ClientId, + if (oauth2ClientSecret != null) 'oauth2ClientSecret': oauth2ClientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1271,9 +1280,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/tradeshiftBox'; final Map apiParams = { - 'oauth2ClientId': oauth2ClientId, - 'oauth2ClientSecret': oauth2ClientSecret, - 'enabled': enabled, + if (oauth2ClientId != null) 'oauth2ClientId': oauth2ClientId, + if (oauth2ClientSecret != null) 'oauth2ClientSecret': oauth2ClientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1294,9 +1303,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/twitch'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1317,9 +1326,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/wordpress'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1340,9 +1349,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/x'; final Map apiParams = { - 'customerKey': customerKey, - 'secretKey': secretKey, - 'enabled': enabled, + if (customerKey != null) 'customerKey': customerKey, + if (secretKey != null) 'secretKey': secretKey, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1363,9 +1372,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/yahoo'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1386,9 +1395,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/yandex'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1409,9 +1418,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/zoho'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -1432,9 +1441,9 @@ class Project extends Service { final String apiPath = '/project/oauth2/zoom'; final Map apiParams = { - 'clientId': clientId, - 'clientSecret': clientSecret, - 'enabled': enabled, + if (clientId != null) 'clientId': clientId, + if (clientSecret != null) 'clientSecret': clientSecret, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -2446,16 +2455,16 @@ class Project extends Service { final String apiPath = '/project/smtp'; final Map apiParams = { - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'senderEmail': senderEmail, - 'senderName': senderName, - 'replyToEmail': replyToEmail, - 'replyToName': replyToName, - 'secure': secure?.value, - 'enabled': enabled, + if (host != null) 'host': host, + if (port != null) 'port': port, + if (username != null) 'username': username, + if (password != null) 'password': password, + if (senderEmail != null) 'senderEmail': senderEmail, + if (senderName != null) 'senderName': senderName, + if (replyToEmail != null) 'replyToEmail': replyToEmail, + if (replyToName != null) 'replyToName': replyToName, + if (secure != null) 'secure': secure.value, + if (enabled != null) 'enabled': enabled, }; final Map apiHeaders = { @@ -2528,12 +2537,12 @@ class Project extends Service { final Map apiParams = { 'templateId': templateId.value, if (locale != null) 'locale': locale.value, - 'subject': subject, - 'message': message, - 'senderName': senderName, - 'senderEmail': senderEmail, - 'replyToEmail': replyToEmail, - 'replyToName': replyToName, + if (subject != null) 'subject': subject, + if (message != null) 'message': message, + if (senderName != null) 'senderName': senderName, + if (senderEmail != null) 'senderEmail': senderEmail, + if (replyToEmail != null) 'replyToEmail': replyToEmail, + if (replyToName != null) 'replyToName': replyToName, }; final Map apiHeaders = { @@ -2649,9 +2658,9 @@ class Project extends Service { .replaceAll('{variableId}', variableId); final Map apiParams = { - 'key': key, - 'value': value, - 'secret': secret, + if (key != null) 'key': key, + if (value != null) 'value': value, + if (secret != null) 'secret': secret, }; final Map apiHeaders = { diff --git a/lib/services/sites.dart b/lib/services/sites.dart index 6c4563e8..102db77b 100644 --- a/lib/services/sites.dart +++ b/lib/services/sites.dart @@ -197,9 +197,9 @@ class Sites extends Service { if (providerSilentMode != null) 'providerSilentMode': providerSilentMode, if (providerRootDirectory != null) 'providerRootDirectory': providerRootDirectory, - 'providerBranches': providerBranches, - 'providerPaths': providerPaths, - 'buildSpecification': buildSpecification, + if (providerBranches != null) 'providerBranches': providerBranches, + if (providerPaths != null) 'providerPaths': providerPaths, + if (buildSpecification != null) 'buildSpecification': buildSpecification, if (runtimeSpecification != null) 'runtimeSpecification': runtimeSpecification, if (deploymentRetention != null) @@ -465,13 +465,15 @@ class Sites extends Service { Future getDeploymentDownload( {required String siteId, required String deploymentId, - enums.DeploymentDownloadType? type}) async { + enums.DeploymentDownloadType? type, + String? token}) async { final String apiPath = '/sites/{siteId}/deployments/{deploymentId}/download' .replaceAll('{siteId}', siteId) .replaceAll('{deploymentId}', deploymentId); final Map params = { if (type != null) 'type': type.value, + if (token != null) 'token': token, 'project': client.config['project'], 'key': client.config['key'], 'impersonateuserid': client.config['impersonateuserid'], @@ -654,9 +656,9 @@ class Sites extends Service { .replaceAll('{variableId}', variableId); final Map apiParams = { - 'key': key, - 'value': value, - 'secret': secret, + if (key != null) 'key': key, + if (value != null) 'value': value, + if (secret != null) 'secret': secret, }; final Map apiHeaders = { diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 4b34f6d6..16e977c8 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -45,7 +45,7 @@ class Storage extends Service { final Map apiParams = { 'bucketId': bucketId, 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, if (fileSecurity != null) 'fileSecurity': fileSecurity, if (enabled != null) 'enabled': enabled, if (maximumFileSize != null) 'maximumFileSize': maximumFileSize, @@ -106,7 +106,7 @@ class Storage extends Service { final Map apiParams = { 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, if (fileSecurity != null) 'fileSecurity': fileSecurity, if (enabled != null) 'enabled': enabled, if (maximumFileSize != null) 'maximumFileSize': maximumFileSize, @@ -263,7 +263,7 @@ class Storage extends Service { final Map apiParams = { if (name != null) 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, }; final Map apiHeaders = { diff --git a/lib/services/tables_db.dart b/lib/services/tables_db.dart index e3c4ae93..d99d04e9 100644 --- a/lib/services/tables_db.dart +++ b/lib/services/tables_db.dart @@ -1,5 +1,7 @@ part of '../dart_appwrite.dart'; +/// The TablesDB service allows you to create structured tables of columns, +/// query and filter lists of rows class TablesDB extends Service { TablesDB(super.client); @@ -32,7 +34,8 @@ class TablesDB extends Service { {required String databaseId, required String name, bool? enabled, - String? specification}) async { + String? specification, + int? replicas}) async { final String apiPath = '/tablesdb'; final Map apiParams = { @@ -40,6 +43,7 @@ class TablesDB extends Service { 'name': name, if (enabled != null) 'enabled': enabled, if (specification != null) 'specification': specification, + if (replicas != null) 'replicas': replicas, }; final Map apiHeaders = { @@ -54,6 +58,25 @@ class TablesDB extends Service { return models.Database.fromMap(res.data); } + /// List the dedicated database specifications available on the current plan. + /// Each specification reports its resource limits, pricing, and whether it is + /// enabled for the organization. + Future listSpecifications() async { + final String apiPath = '/tablesdb/specifications'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DedicatedDatabaseSpecificationList.fromMap(res.data); + } + /// List transactions across all databases. Future listTransactions( {List? queries}) async { @@ -197,13 +220,17 @@ class TablesDB extends Service { /// Update a database by its unique ID. Future update( - {required String databaseId, String? name, bool? enabled}) async { + {required String databaseId, + String? name, + bool? enabled, + int? replicas}) async { final String apiPath = '/tablesdb/{databaseId}'.replaceAll('{databaseId}', databaseId); final Map apiParams = { if (name != null) 'name': name, if (enabled != null) 'enabled': enabled, + if (replicas != null) 'replicas': replicas, }; final Map apiHeaders = { @@ -237,6 +264,70 @@ class TablesDB extends Service { return res.data; } + /// Trigger a manual failover for a dedicated database with high availability + /// enabled. Promotes a replica to primary. The failover runs asynchronously; + /// poll the database document for status updates. + Future createFailover( + {required String databaseId, String? targetReplicaId}) async { + final String apiPath = '/tablesdb/{databaseId}/failovers' + .replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + if (targetReplicaId != null) 'targetReplicaId': targetReplicaId, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DedicatedDatabase.fromMap(res.data); + } + + /// Get high availability status for a dedicated database. Returns replica + /// statuses, replication lag, and sync mode. + Future getReplicas( + {required String databaseId}) async { + final String apiPath = '/tablesdb/{databaseId}/replicas' + .replaceAll('{databaseId}', databaseId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DedicatedDatabaseReplicas.fromMap(res.data); + } + + /// Get real-time health and status information for a dedicated database. + /// Returns health status, readiness, uptime, connection info, replica status, + /// and volume information. + Future getStatus({required String databaseId}) async { + final String apiPath = + '/tablesdb/{databaseId}/status'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DatabaseStatus.fromMap(res.data); + } + /// Get a list of all tables that belong to the provided databaseId. You can /// use the search parameter to filter your results. Future listTables( @@ -283,7 +374,7 @@ class TablesDB extends Service { final Map apiParams = { 'tableId': tableId, 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, if (rowSecurity != null) 'rowSecurity': rowSecurity, if (enabled != null) 'enabled': enabled, if (columns != null) 'columns': columns, @@ -338,7 +429,7 @@ class TablesDB extends Service { final Map apiParams = { if (name != null) 'name': name, - 'permissions': permissions, + if (permissions != null) 'permissions': permissions, if (rowSecurity != null) 'rowSecurity': rowSecurity, if (enabled != null) 'enabled': enabled, if (purge != null) 'purge': purge, @@ -423,9 +514,9 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, + if (min != null) 'min': min, + if (max != null) 'max': max, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -461,10 +552,10 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, - 'min': min, - 'max': max, + if (min != null) 'min': min, + if (max != null) 'max': max, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -496,7 +587,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -530,7 +621,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -561,7 +652,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -595,7 +686,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -627,7 +718,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -662,7 +753,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -696,7 +787,7 @@ class TablesDB extends Service { 'key': key, 'elements': elements, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -733,7 +824,7 @@ class TablesDB extends Service { 'elements': elements, 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -768,9 +859,9 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, + if (min != null) 'min': min, + if (max != null) 'max': max, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -806,10 +897,10 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, - 'min': min, - 'max': max, + if (min != null) 'min': min, + if (max != null) 'max': max, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -844,9 +935,9 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, + if (min != null) 'min': min, + if (max != null) 'max': max, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -882,10 +973,10 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, - 'min': min, - 'max': max, + if (min != null) 'min': min, + if (max != null) 'max': max, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -916,7 +1007,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -951,7 +1042,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -981,7 +1072,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, }; final Map apiHeaders = { @@ -1013,8 +1104,8 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, + if (xdefault != null) 'default': xdefault, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1047,7 +1138,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1083,7 +1174,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1116,7 +1207,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1152,7 +1243,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1182,7 +1273,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, }; final Map apiHeaders = { @@ -1214,8 +1305,8 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, + if (xdefault != null) 'default': xdefault, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1245,7 +1336,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, }; final Map apiHeaders = { @@ -1277,8 +1368,8 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, + if (xdefault != null) 'default': xdefault, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1314,8 +1405,8 @@ class TablesDB extends Service { 'relatedTableId': relatedTableId, 'type': type.value, if (twoWay != null) 'twoWay': twoWay, - 'key': key, - 'twoWayKey': twoWayKey, + if (key != null) 'key': key, + if (twoWayKey != null) 'twoWayKey': twoWayKey, if (onDelete != null) 'onDelete': onDelete.value, }; @@ -1353,7 +1444,7 @@ class TablesDB extends Service { 'key': key, 'size': size, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1392,8 +1483,8 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'size': size, - 'newKey': newKey, + if (size != null) 'size': size, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1426,7 +1517,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1462,7 +1553,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1493,7 +1584,7 @@ class TablesDB extends Service { final Map apiParams = { 'key': key, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, }; @@ -1528,7 +1619,7 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'newKey': newKey, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1563,7 +1654,7 @@ class TablesDB extends Service { 'key': key, 'size': size, 'required': xrequired, - 'default': xdefault, + if (xdefault != null) 'default': xdefault, if (array != null) 'array': array, if (encrypt != null) 'encrypt': encrypt, }; @@ -1600,8 +1691,8 @@ class TablesDB extends Service { final Map apiParams = { 'required': xrequired, 'default': xdefault, - 'size': size, - 'newKey': newKey, + if (size != null) 'size': size, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1720,8 +1811,8 @@ class TablesDB extends Service { .replaceAll('{key}', key); final Map apiParams = { - 'onDelete': onDelete?.value, - 'newKey': newKey, + if (onDelete != null) 'onDelete': onDelete.value, + if (newKey != null) 'newKey': newKey, }; final Map apiHeaders = { @@ -1894,8 +1985,8 @@ class TablesDB extends Service { final Map apiParams = { 'rowId': rowId, 'data': data, - 'permissions': permissions, - 'transactionId': transactionId, + if (permissions != null) 'permissions': permissions, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -1925,7 +2016,7 @@ class TablesDB extends Service { final Map apiParams = { 'rows': rows, - 'transactionId': transactionId, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -1956,7 +2047,7 @@ class TablesDB extends Service { final Map apiParams = { 'rows': rows, - 'transactionId': transactionId, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -1986,7 +2077,7 @@ class TablesDB extends Service { final Map apiParams = { if (data != null) 'data': data, if (queries != null) 'queries': queries, - 'transactionId': transactionId, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2078,8 +2169,8 @@ class TablesDB extends Service { final Map apiParams = { if (data != null) 'data': data, - 'permissions': permissions, - 'transactionId': transactionId, + if (permissions != null) 'permissions': permissions, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2111,8 +2202,8 @@ class TablesDB extends Service { final Map apiParams = { if (data != null) 'data': data, - 'permissions': permissions, - 'transactionId': transactionId, + if (permissions != null) 'permissions': permissions, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2172,8 +2263,8 @@ class TablesDB extends Service { final Map apiParams = { if (value != null) 'value': value, - 'min': min, - 'transactionId': transactionId, + if (min != null) 'min': min, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { @@ -2206,8 +2297,8 @@ class TablesDB extends Service { final Map apiParams = { if (value != null) 'value': value, - 'max': max, - 'transactionId': transactionId, + if (max != null) 'max': max, + if (transactionId != null) 'transactionId': transactionId, }; final Map apiHeaders = { diff --git a/lib/services/teams.dart b/lib/services/teams.dart index b680ac9f..e263e946 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -111,6 +111,130 @@ class Teams extends Service { return res.data; } + /// List app installations on a team. Any team member can read installations. + Future listInstallations( + {required String teamId, List? queries, bool? total}) async { + final String apiPath = + '/teams/{teamId}/installations'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallationList.fromMap(res.data); + } + + /// Install an app on a team. When authenticated as a user, only team members + /// with the owner role can install apps. Requests using an API key or in admin + /// mode can install apps on any team. The installation is granted the scopes + /// the app currently requests. + Future createInstallation( + {required String teamId, + required String appId, + String? authorizationDetails}) async { + final String apiPath = + '/teams/{teamId}/installations'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'appId': appId, + if (authorizationDetails != null) + 'authorizationDetails': authorizationDetails, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Get an app installation on a team by its unique ID. Any team member can + /// read installations. + Future getInstallation( + {required String teamId, required String installationId}) async { + final String apiPath = '/teams/{teamId}/installations/{installationId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{installationId}', installationId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Update an app installation on a team. Only team members with the owner role + /// can update installations. The installation's granted scopes are refreshed + /// to the scopes the app currently requests; previously issued installation + /// access tokens are revoked. + Future updateInstallation( + {required String teamId, + required String installationId, + String? authorizationDetails}) async { + final String apiPath = '/teams/{teamId}/installations/{installationId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{installationId}', installationId); + + final Map apiParams = { + if (authorizationDetails != null) + 'authorizationDetails': authorizationDetails, + }; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AppInstallation.fromMap(res.data); + } + + /// Uninstall an app from a team by its installation ID. Only team members with + /// the owner role can remove installations. Previously issued installation + /// access tokens are revoked. + Future deleteInstallation( + {required String teamId, required String installationId}) async { + final String apiPath = '/teams/{teamId}/installations/{installationId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{installationId}', installationId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'X-Appwrite-Project': client.config['project'] ?? '', + 'content-type': 'application/json', + 'accept': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + /// Use this endpoint to list a team's members using the team's ID. All team /// members have read access to this endpoint. Hide sensitive attributes from /// the response by toggling membership privacy in the Console. diff --git a/lib/services/tokens.dart b/lib/services/tokens.dart index c9d05a06..24596183 100644 --- a/lib/services/tokens.dart +++ b/lib/services/tokens.dart @@ -1,5 +1,7 @@ part of '../dart_appwrite.dart'; +/// The Tokens service allows you to create and manage resource tokens for +/// secure file access. class Tokens extends Service { Tokens(super.client); @@ -41,7 +43,7 @@ class Tokens extends Service { .replaceAll('{fileId}', fileId); final Map apiParams = { - 'expire': expire, + if (expire != null) 'expire': expire, }; final Map apiHeaders = { @@ -80,7 +82,7 @@ class Tokens extends Service { final String apiPath = '/tokens/{tokenId}'.replaceAll('{tokenId}', tokenId); final Map apiParams = { - 'expire': expire, + if (expire != null) 'expire': expire, }; final Map apiHeaders = { diff --git a/lib/services/users.dart b/lib/services/users.dart index 6d9304fb..38de9856 100644 --- a/lib/services/users.dart +++ b/lib/services/users.dart @@ -38,8 +38,8 @@ class Users extends Service { final Map apiParams = { 'userId': userId, - 'email': email, - 'phone': phone, + if (email != null) 'email': email, + if (phone != null) 'phone': phone, if (password != null) 'password': password, if (name != null) 'name': name, }; diff --git a/lib/services/webhooks.dart b/lib/services/webhooks.dart index 4f41e7b9..32d0ab68 100644 --- a/lib/services/webhooks.dart +++ b/lib/services/webhooks.dart @@ -1,5 +1,6 @@ part of '../dart_appwrite.dart'; +/// The Webhooks service allows you to manage your project webhooks. class Webhooks extends Service { Webhooks(super.client); @@ -47,7 +48,7 @@ class Webhooks extends Service { if (tls != null) 'tls': tls, if (authUsername != null) 'authUsername': authUsername, if (authPassword != null) 'authPassword': authPassword, - 'secret': secret, + if (secret != null) 'secret': secret, }; final Map apiHeaders = { @@ -145,7 +146,7 @@ class Webhooks extends Service { '/webhooks/{webhookId}/secret'.replaceAll('{webhookId}', webhookId); final Map apiParams = { - 'secret': secret, + if (secret != null) 'secret': secret, }; final Map apiHeaders = { diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index c9c37396..52213505 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -33,7 +33,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '26.0.0', + 'x-sdk-version': '26.1.0', 'X-Appwrite-Response-Format': '1.9.5', }; diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 3c361e78..41fc4444 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -42,9 +42,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '26.0.0', + 'x-sdk-version': '26.1.0', 'user-agent': - 'AppwriteDartSDK/26.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'AppwriteDartSDK/26.1.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', 'X-Appwrite-Response-Format': '1.9.5', }; diff --git a/lib/src/enums/database_status.dart b/lib/src/enums/database_status.dart index 62d851ab..cbef1af7 100644 --- a/lib/src/enums/database_status.dart +++ b/lib/src/enums/database_status.dart @@ -3,7 +3,18 @@ part of '../../enums.dart'; enum DatabaseStatus { provisioning(value: 'provisioning'), ready(value: 'ready'), - failed(value: 'failed'); + inactive(value: 'inactive'), + paused(value: 'paused'), + failed(value: 'failed'), + deleting(value: 'deleting'), + deleted(value: 'deleted'), + restoring(value: 'restoring'), + scaling(value: 'scaling'), + upgrading(value: 'upgrading'), + migrating(value: 'migrating'), + pausing(value: 'pausing'), + resuming(value: 'resuming'), + failingOver(value: 'failing-over'); const DatabaseStatus({required this.value}); diff --git a/lib/src/enums/database_type.dart b/lib/src/enums/database_type.dart index c6887ffc..962e937f 100644 --- a/lib/src/enums/database_type.dart +++ b/lib/src/enums/database_type.dart @@ -4,7 +4,10 @@ enum DatabaseType { legacy(value: 'legacy'), tablesdb(value: 'tablesdb'), documentsdb(value: 'documentsdb'), - vectorsdb(value: 'vectorsdb'); + vectorsdb(value: 'vectorsdb'), + mysql(value: 'mysql'), + postgresql(value: 'postgresql'), + mongodb(value: 'mongodb'); const DatabaseType({required this.value}); diff --git a/lib/src/enums/organization_key_scopes.dart b/lib/src/enums/organization_key_scopes.dart index 26a2e74a..1f1a59bb 100644 --- a/lib/src/enums/organization_key_scopes.dart +++ b/lib/src/enums/organization_key_scopes.dart @@ -7,6 +7,8 @@ enum OrganizationKeyScopes { devKeysWrite(value: 'devKeys.write'), organizationKeysRead(value: 'organization.keys.read'), organizationKeysWrite(value: 'organization.keys.write'), + organizationInstallationsRead(value: 'organization.installations.read'), + organizationInstallationsWrite(value: 'organization.installations.write'), organizationMembershipsRead(value: 'organization.memberships.read'), organizationMembershipsWrite(value: 'organization.memberships.write'), organizationRead(value: 'organization.read'), diff --git a/lib/src/enums/project_key_scopes.dart b/lib/src/enums/project_key_scopes.dart index 34dcfdbe..e27b5f92 100644 --- a/lib/src/enums/project_key_scopes.dart +++ b/lib/src/enums/project_key_scopes.dart @@ -96,11 +96,14 @@ enum ProjectKeyScopes { dedicatedDatabasesExecute(value: 'dedicatedDatabases.execute'), domainsRead(value: 'domains.read'), domainsWrite(value: 'domains.write'), + wafRulesRead(value: 'wafRules.read'), + wafRulesWrite(value: 'wafRules.write'), eventsRead(value: 'events.read'), appsRead(value: 'apps.read'), appsWrite(value: 'apps.write'), oauth2Read(value: 'oauth2.read'), oauth2Write(value: 'oauth2.write'), + oauth2Introspect(value: 'oauth2.introspect'), usageRead(value: 'usage.read'); const ProjectKeyScopes({required this.value}); diff --git a/lib/src/models/activity_event.dart b/lib/src/models/activity_event.dart index 1d6b598d..ae530c64 100644 --- a/lib/src/models/activity_event.dart +++ b/lib/src/models/activity_event.dart @@ -44,6 +44,33 @@ class ActivityEvent implements Model { /// Location. final String country; + /// Continent code. + final String continentCode; + + /// City name. + final String city; + + /// Region/state chain. + final String subdivisions; + + /// Internet service provider. + final String isp; + + /// Autonomous System Number (ASN). + final String autonomousSystemNumber; + + /// Organization that owns the ASN. + final String autonomousSystemOrganization; + + /// Connection type (e.g. cable, cellular, corporate). + final String connectionType; + + /// User type (e.g. residential, business, hosting). + final String connectionUsageType; + + /// Registered organization of the IP. + final String connectionOrganization; + /// Log creation date in ISO 8601 format. final String time; @@ -56,6 +83,12 @@ class ActivityEvent implements Model { /// Hostname. final String hostname; + /// Name of the SDK that triggered the event. + final String sdk; + + /// Version of the SDK that triggered the event. + final String sdkVersion; + ActivityEvent({ required this.$id, required this.actorType, @@ -71,10 +104,21 @@ class ActivityEvent implements Model { required this.ip, required this.mode, required this.country, + required this.continentCode, + required this.city, + required this.subdivisions, + required this.isp, + required this.autonomousSystemNumber, + required this.autonomousSystemOrganization, + required this.connectionType, + required this.connectionUsageType, + required this.connectionOrganization, required this.time, required this.projectId, required this.teamId, required this.hostname, + required this.sdk, + required this.sdkVersion, }); factory ActivityEvent.fromMap(Map map) { @@ -93,10 +137,22 @@ class ActivityEvent implements Model { ip: map['ip'].toString(), mode: map['mode'].toString(), country: map['country'].toString(), + continentCode: map['continentCode'].toString(), + city: map['city'].toString(), + subdivisions: map['subdivisions'].toString(), + isp: map['isp'].toString(), + autonomousSystemNumber: map['autonomousSystemNumber'].toString(), + autonomousSystemOrganization: + map['autonomousSystemOrganization'].toString(), + connectionType: map['connectionType'].toString(), + connectionUsageType: map['connectionUsageType'].toString(), + connectionOrganization: map['connectionOrganization'].toString(), time: map['time'].toString(), projectId: map['projectId'].toString(), teamId: map['teamId'].toString(), hostname: map['hostname'].toString(), + sdk: map['sdk'].toString(), + sdkVersion: map['sdkVersion'].toString(), ); } @@ -117,10 +173,21 @@ class ActivityEvent implements Model { "ip": ip, "mode": mode, "country": country, + "continentCode": continentCode, + "city": city, + "subdivisions": subdivisions, + "isp": isp, + "autonomousSystemNumber": autonomousSystemNumber, + "autonomousSystemOrganization": autonomousSystemOrganization, + "connectionType": connectionType, + "connectionUsageType": connectionUsageType, + "connectionOrganization": connectionOrganization, "time": time, "projectId": projectId, "teamId": teamId, "hostname": hostname, + "sdk": sdk, + "sdkVersion": sdkVersion, }; } } diff --git a/lib/src/models/app.dart b/lib/src/models/app.dart new file mode 100644 index 00000000..96b1fc7d --- /dev/null +++ b/lib/src/models/app.dart @@ -0,0 +1,175 @@ +part of '../../models.dart'; + +/// App +class App implements Model { + /// App ID. + final String $id; + + /// App creation time in ISO 8601 format. + final String $createdAt; + + /// App update date in ISO 8601 format. + final String $updatedAt; + + /// Application name. + final String name; + + /// Application description shown to users during OAuth2 consent. + final String description; + + /// Application homepage URL shown to users during OAuth2 consent. + final String clientUri; + + /// Application logo URL shown to users during OAuth2 consent. + final String logoUri; + + /// Application privacy policy URL shown to users during OAuth2 consent. + final String privacyPolicyUrl; + + /// Application terms of service URL shown to users during OAuth2 consent. + final String termsUrl; + + /// Application support or security contact emails. + final List contacts; + + /// Application tagline shown to users during OAuth2 consent. + final String tagline; + + /// Application tags shown to users during OAuth2 consent. + final List tags; + + /// Application labels. Read-only for clients; only a server SDK using a project API key can update them. + final List labels; + + /// Application image URLs shown to users during OAuth2 consent. + final List images; + + /// Application support URL shown to users during OAuth2 consent. + final String supportUrl; + + /// Application data deletion URL shown to users during OAuth2 consent. + final String dataDeletionUrl; + + /// List of authorized redirect URIs. These URIs can be used to redirect users after they authenticate. + final List redirectUris; + + /// List of authorized post-logout redirect URIs for OpenID Connect RP-Initiated Logout. The logout endpoint only redirects users to URIs in this list after ending their session. + final List postLogoutRedirectUris; + + /// Whether the app is enabled or not. + final bool enabled; + + /// OAuth2 client type. `public` for SPAs, mobile, and native apps that cannot keep a client secret (PKCE required); `confidential` for server-side clients that authenticate with a client secret. + final String type; + + /// Whether this client may use the OAuth2 Device Authorization Grant (RFC 8628). + final bool deviceFlow; + + /// ID of team that owns the application, if owned by team. Otherwise, user ID will be used. + final String teamId; + + /// ID of user who owns the application, if owned by user. Otherwise, team ID will be used. + final String userId; + + /// Scopes the application requests when installed on a team. Organization-level and project-level scopes only. + final List installationScopes; + + /// URL users are redirected to after creating or updating an installation of this application. Empty for no redirect. + final String installationRedirectUrl; + + /// List of application secrets. + final List secrets; + + App({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.description, + required this.clientUri, + required this.logoUri, + required this.privacyPolicyUrl, + required this.termsUrl, + required this.contacts, + required this.tagline, + required this.tags, + required this.labels, + required this.images, + required this.supportUrl, + required this.dataDeletionUrl, + required this.redirectUris, + required this.postLogoutRedirectUris, + required this.enabled, + required this.type, + required this.deviceFlow, + required this.teamId, + required this.userId, + required this.installationScopes, + required this.installationRedirectUrl, + required this.secrets, + }); + + factory App.fromMap(Map map) { + return App( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + description: map['description'].toString(), + clientUri: map['clientUri'].toString(), + logoUri: map['logoUri'].toString(), + privacyPolicyUrl: map['privacyPolicyUrl'].toString(), + termsUrl: map['termsUrl'].toString(), + contacts: List.from(map['contacts'] ?? []), + tagline: map['tagline'].toString(), + tags: List.from(map['tags'] ?? []), + labels: List.from(map['labels'] ?? []), + images: List.from(map['images'] ?? []), + supportUrl: map['supportUrl'].toString(), + dataDeletionUrl: map['dataDeletionUrl'].toString(), + redirectUris: List.from(map['redirectUris'] ?? []), + postLogoutRedirectUris: List.from(map['postLogoutRedirectUris'] ?? []), + enabled: map['enabled'], + type: map['type'].toString(), + deviceFlow: map['deviceFlow'], + teamId: map['teamId'].toString(), + userId: map['userId'].toString(), + installationScopes: List.from(map['installationScopes'] ?? []), + installationRedirectUrl: map['installationRedirectUrl'].toString(), + secrets: + List.from(map['secrets'].map((p) => AppSecret.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "description": description, + "clientUri": clientUri, + "logoUri": logoUri, + "privacyPolicyUrl": privacyPolicyUrl, + "termsUrl": termsUrl, + "contacts": contacts, + "tagline": tagline, + "tags": tags, + "labels": labels, + "images": images, + "supportUrl": supportUrl, + "dataDeletionUrl": dataDeletionUrl, + "redirectUris": redirectUris, + "postLogoutRedirectUris": postLogoutRedirectUris, + "enabled": enabled, + "type": type, + "deviceFlow": deviceFlow, + "teamId": teamId, + "userId": userId, + "installationScopes": installationScopes, + "installationRedirectUrl": installationRedirectUrl, + "secrets": secrets.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/app_installation.dart b/lib/src/models/app_installation.dart new file mode 100644 index 00000000..3ed121ec --- /dev/null +++ b/lib/src/models/app_installation.dart @@ -0,0 +1,78 @@ +part of '../../models.dart'; + +/// AppInstallation +class AppInstallation implements Model { + /// Installation ID. + final String $id; + + /// Installation creation time in ISO 8601 format. + final String $createdAt; + + /// Installation update time in ISO 8601 format. + final String $updatedAt; + + /// ID of the installed application. + final String appId; + + /// ID of the team the application is installed on. + final String teamId; + + /// Scopes granted to the application. Snapshot of the application's installation scopes taken when the installation was created or last updated. + final List scopes; + + /// Authorization details granted to the application. Rich authorization request (RFC 9396) style entries; the Appwrite Console stores authorized project IDs here. + final Map authorizationDetails; + + /// ID of the user who created the installation. + final String createdById; + + /// Name of the user who created the installation. + final String createdByName; + + /// Time an access token was last issued for the installation in ISO 8601 format. Null if never used. + final String? lastAccessedAt; + + AppInstallation({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.appId, + required this.teamId, + required this.scopes, + required this.authorizationDetails, + required this.createdById, + required this.createdByName, + this.lastAccessedAt, + }); + + factory AppInstallation.fromMap(Map map) { + return AppInstallation( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + appId: map['appId'].toString(), + teamId: map['teamId'].toString(), + scopes: List.from(map['scopes'] ?? []), + authorizationDetails: map['authorizationDetails'], + createdById: map['createdById'].toString(), + createdByName: map['createdByName'].toString(), + lastAccessedAt: map['lastAccessedAt']?.toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "appId": appId, + "teamId": teamId, + "scopes": scopes, + "authorizationDetails": authorizationDetails, + "createdById": createdById, + "createdByName": createdByName, + "lastAccessedAt": lastAccessedAt, + }; + } +} diff --git a/lib/src/models/app_installation_list.dart b/lib/src/models/app_installation_list.dart new file mode 100644 index 00000000..c55f831f --- /dev/null +++ b/lib/src/models/app_installation_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// App installations list +class AppInstallationList implements Model { + /// Total number of installations that matched your query. + final int total; + + /// List of installations. + final List installations; + + AppInstallationList({ + required this.total, + required this.installations, + }); + + factory AppInstallationList.fromMap(Map map) { + return AppInstallationList( + total: map['total'], + installations: List.from( + map['installations'].map((p) => AppInstallation.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "installations": installations.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/app_key.dart b/lib/src/models/app_key.dart new file mode 100644 index 00000000..f4227fa7 --- /dev/null +++ b/lib/src/models/app_key.dart @@ -0,0 +1,72 @@ +part of '../../models.dart'; + +/// AppKey +class AppKey implements Model { + /// App key ID. + final String $id; + + /// App key creation time in ISO 8601 format. + final String $createdAt; + + /// App key update time in ISO 8601 format. + final String $updatedAt; + + /// Application ID this app key belongs to. + final String appId; + + /// App key secret. + final String secret; + + /// Last few characters of the app key secret, used to help identify it. + final String hint; + + /// ID of the user who created the app key. + final String createdById; + + /// Name of the user who created the app key. + final String createdByName; + + /// Time the app key was last used for authentication in ISO 8601 format. Null if never used. + final String? lastAccessedAt; + + AppKey({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.appId, + required this.secret, + required this.hint, + required this.createdById, + required this.createdByName, + this.lastAccessedAt, + }); + + factory AppKey.fromMap(Map map) { + return AppKey( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + appId: map['appId'].toString(), + secret: map['secret'].toString(), + hint: map['hint'].toString(), + createdById: map['createdById'].toString(), + createdByName: map['createdByName'].toString(), + lastAccessedAt: map['lastAccessedAt']?.toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "appId": appId, + "secret": secret, + "hint": hint, + "createdById": createdById, + "createdByName": createdByName, + "lastAccessedAt": lastAccessedAt, + }; + } +} diff --git a/lib/src/models/app_key_list.dart b/lib/src/models/app_key_list.dart new file mode 100644 index 00000000..e7d1b665 --- /dev/null +++ b/lib/src/models/app_key_list.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// App keys list +class AppKeyList implements Model { + /// Total number of keys that matched your query. + final int total; + + /// List of keys. + final List keys; + + AppKeyList({ + required this.total, + required this.keys, + }); + + factory AppKeyList.fromMap(Map map) { + return AppKeyList( + total: map['total'], + keys: List.from(map['keys'].map((p) => AppKey.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "keys": keys.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/app_scope.dart b/lib/src/models/app_scope.dart new file mode 100644 index 00000000..dbb5c230 --- /dev/null +++ b/lib/src/models/app_scope.dart @@ -0,0 +1,48 @@ +part of '../../models.dart'; + +/// AppScope +class AppScope implements Model { + /// Scope value as requested by apps. + final String value; + + /// Human-readable description of what the scope grants. + final String description; + + /// What the scope grants access to. One of `account`, `project`, or `organization`. Only `project` and `organization` scopes are installable. + final String type; + + /// Scope category, used to group scopes on consent and installation screens. + final String category; + + /// Whether the scope is deprecated. Deprecated scopes can still be requested but should not be offered for new grants. + final bool deprecated; + + AppScope({ + required this.value, + required this.description, + required this.type, + required this.category, + required this.deprecated, + }); + + factory AppScope.fromMap(Map map) { + return AppScope( + value: map['value'].toString(), + description: map['description'].toString(), + type: map['type'].toString(), + category: map['category'].toString(), + deprecated: map['deprecated'], + ); + } + + @override + Map toMap() { + return { + "value": value, + "description": description, + "type": type, + "category": category, + "deprecated": deprecated, + }; + } +} diff --git a/lib/src/models/app_scope_list.dart b/lib/src/models/app_scope_list.dart new file mode 100644 index 00000000..0a24fe1d --- /dev/null +++ b/lib/src/models/app_scope_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// App scopes list +class AppScopeList implements Model { + /// Total number of scopes that matched your query. + final int total; + + /// List of scopes. + final List scopes; + + AppScopeList({ + required this.total, + required this.scopes, + }); + + factory AppScopeList.fromMap(Map map) { + return AppScopeList( + total: map['total'], + scopes: + List.from(map['scopes'].map((p) => AppScope.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "scopes": scopes.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/app_secret.dart b/lib/src/models/app_secret.dart new file mode 100644 index 00000000..37971f08 --- /dev/null +++ b/lib/src/models/app_secret.dart @@ -0,0 +1,72 @@ +part of '../../models.dart'; + +/// AppSecret +class AppSecret implements Model { + /// Secret ID. + final String $id; + + /// Secret creation time in ISO 8601 format. + final String $createdAt; + + /// Secret update time in ISO 8601 format. + final String $updatedAt; + + /// Application ID this secret belongs to. + final String appId; + + /// Always empty. The application client secret is returned only once, in the response of the createSecret method. + final String secret; + + /// Last few characters of the client secret, used to help identify it. + final String hint; + + /// ID of the user who created the secret. + final String createdById; + + /// Name of the user who created the secret. + final String createdByName; + + /// Time the secret was last used for authentication in ISO 8601 format. Null if never used. + final String? lastAccessedAt; + + AppSecret({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.appId, + required this.secret, + required this.hint, + required this.createdById, + required this.createdByName, + this.lastAccessedAt, + }); + + factory AppSecret.fromMap(Map map) { + return AppSecret( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + appId: map['appId'].toString(), + secret: map['secret'].toString(), + hint: map['hint'].toString(), + createdById: map['createdById'].toString(), + createdByName: map['createdByName'].toString(), + lastAccessedAt: map['lastAccessedAt']?.toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "appId": appId, + "secret": secret, + "hint": hint, + "createdById": createdById, + "createdByName": createdByName, + "lastAccessedAt": lastAccessedAt, + }; + } +} diff --git a/lib/src/models/app_secret_list.dart b/lib/src/models/app_secret_list.dart new file mode 100644 index 00000000..22a491b8 --- /dev/null +++ b/lib/src/models/app_secret_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// App secrets list +class AppSecretList implements Model { + /// Total number of secrets that matched your query. + final int total; + + /// List of secrets. + final List secrets; + + AppSecretList({ + required this.total, + required this.secrets, + }); + + factory AppSecretList.fromMap(Map map) { + return AppSecretList( + total: map['total'], + secrets: + List.from(map['secrets'].map((p) => AppSecret.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "secrets": secrets.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/app_secret_plaintext.dart b/lib/src/models/app_secret_plaintext.dart new file mode 100644 index 00000000..288272f8 --- /dev/null +++ b/lib/src/models/app_secret_plaintext.dart @@ -0,0 +1,72 @@ +part of '../../models.dart'; + +/// AppSecretPlaintext +class AppSecretPlaintext implements Model { + /// Secret ID. + final String $id; + + /// Secret creation time in ISO 8601 format. + final String $createdAt; + + /// Secret update time in ISO 8601 format. + final String $updatedAt; + + /// Application ID this secret belongs to. + final String appId; + + /// Application client secret. Returned only when the secret is created; subsequent reads always return an empty value. + final String secret; + + /// Last few characters of the client secret, used to help identify it. + final String hint; + + /// ID of the user who created the secret. + final String createdById; + + /// Name of the user who created the secret. + final String createdByName; + + /// Time the secret was last used for authentication in ISO 8601 format. Null if never used. + final String? lastAccessedAt; + + AppSecretPlaintext({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.appId, + required this.secret, + required this.hint, + required this.createdById, + required this.createdByName, + this.lastAccessedAt, + }); + + factory AppSecretPlaintext.fromMap(Map map) { + return AppSecretPlaintext( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + appId: map['appId'].toString(), + secret: map['secret'].toString(), + hint: map['hint'].toString(), + createdById: map['createdById'].toString(), + createdByName: map['createdByName'].toString(), + lastAccessedAt: map['lastAccessedAt']?.toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "appId": appId, + "secret": secret, + "hint": hint, + "createdById": createdById, + "createdByName": createdByName, + "lastAccessedAt": lastAccessedAt, + }; + } +} diff --git a/lib/src/models/apps_list.dart b/lib/src/models/apps_list.dart new file mode 100644 index 00000000..e5616db3 --- /dev/null +++ b/lib/src/models/apps_list.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// Apps list +class AppsList implements Model { + /// Total number of apps that matched your query. + final int total; + + /// List of apps. + final List apps; + + AppsList({ + required this.total, + required this.apps, + }); + + factory AppsList.fromMap(Map map) { + return AppsList( + total: map['total'], + apps: List.from(map['apps'].map((p) => App.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "apps": apps.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/billing_plan.dart b/lib/src/models/billing_plan.dart index 2bff8704..f85687d9 100644 --- a/lib/src/models/billing_plan.dart +++ b/lib/src/models/billing_plan.dart @@ -38,6 +38,9 @@ class BillingPlan implements Model { /// Webhooks final int webhooks; + /// Maximum WAF rules per project + final int wafRules; + /// Projects final int projects; @@ -219,6 +222,7 @@ class BillingPlan implements Model { required this.screenshotsGenerated, required this.members, required this.webhooks, + required this.wafRules, required this.projects, required this.platforms, required this.users, @@ -291,6 +295,7 @@ class BillingPlan implements Model { screenshotsGenerated: map['screenshotsGenerated'], members: map['members'], webhooks: map['webhooks'], + wafRules: map['wafRules'], projects: map['projects'], platforms: map['platforms'], users: map['users'], @@ -373,6 +378,7 @@ class BillingPlan implements Model { "screenshotsGenerated": screenshotsGenerated, "members": members, "webhooks": webhooks, + "wafRules": wafRules, "projects": projects, "platforms": platforms, "users": users, diff --git a/lib/src/models/database.dart b/lib/src/models/database.dart index 31eb4f66..078de3eb 100644 --- a/lib/src/models/database.dart +++ b/lib/src/models/database.dart @@ -20,14 +20,23 @@ class Database implements Model { /// Database type. final enums.DatabaseType type; - /// Database status. Possible values: `provisioning`, `ready` or `failed` + /// Dedicated database lifecycle status. Null when the database has no valid dedicated backing. final enums.DatabaseStatus? status; + /// Underlying engine of the dedicated backing: postgresql, mysql, mariadb, or mongodb. A managed product (tablesdb, documentsdb, vectorsdb) reports the engine it runs on, so its type and engine can differ. Null when the database has no dedicated backing. + final String? engine; + + /// Compute specification identifier of the dedicated backing, e.g. s-2vcpu-2gb. Null when the database has no dedicated backing. + final String? specification; + + /// Number of secondary high availability replicas, excluding the primary. Null when backing configuration is unavailable. + final int? replicas; + /// Database backup policies. - final List policies; + final List? policies; /// Database backup archives. - final List archives; + final List? archives; Database({ required this.$id, @@ -37,8 +46,11 @@ class Database implements Model { required this.enabled, required this.type, this.status, - required this.policies, - required this.archives, + this.engine, + this.specification, + this.replicas, + this.policies, + this.archives, }); factory Database.fromMap(Map map) { @@ -53,10 +65,17 @@ class Database implements Model { ? enums.DatabaseStatus.values .firstWhere((e) => e.value == map['status']) : null, - policies: List.from( - map['policies'].map((p) => BackupPolicy.fromMap(p))), - archives: List.from( - map['archives'].map((p) => BackupArchive.fromMap(p))), + engine: map['engine']?.toString(), + specification: map['specification']?.toString(), + replicas: map['replicas'], + policies: map['policies'] != null + ? List.from( + map['policies'].map((p) => BackupPolicy.fromMap(p))) + : null, + archives: map['archives'] != null + ? List.from( + map['archives'].map((p) => BackupArchive.fromMap(p))) + : null, ); } @@ -70,8 +89,11 @@ class Database implements Model { "enabled": enabled, "type": type.value, "status": status?.value, - "policies": policies.map((p) => p.toMap()).toList(), - "archives": archives.map((p) => p.toMap()).toList(), + "engine": engine, + "specification": specification, + "replicas": replicas, + "policies": policies?.map((p) => p.toMap()).toList(), + "archives": archives?.map((p) => p.toMap()).toList(), }; } } diff --git a/lib/src/models/database_status.dart b/lib/src/models/database_status.dart new file mode 100644 index 00000000..52d92c83 --- /dev/null +++ b/lib/src/models/database_status.dart @@ -0,0 +1,68 @@ +part of '../../models.dart'; + +/// Status +class DatabaseStatus implements Model { + /// Overall health status: healthy, degraded, or unhealthy. + final String health; + + /// Whether the database is ready to accept connections. + final bool ready; + + /// Database engine: postgresql, mysql, mariadb, or mongodb. + final String engine; + + /// Database engine version. + final String version; + + /// Database uptime in seconds. + final int uptime; + + /// Connection statistics. + final DatabaseStatusConnections connections; + + /// List of database replicas and their status. + final List replicas; + + /// Storage volume information. + final List volumes; + + DatabaseStatus({ + required this.health, + required this.ready, + required this.engine, + required this.version, + required this.uptime, + required this.connections, + required this.replicas, + required this.volumes, + }); + + factory DatabaseStatus.fromMap(Map map) { + return DatabaseStatus( + health: map['health'].toString(), + ready: map['ready'], + engine: map['engine'].toString(), + version: map['version'].toString(), + uptime: map['uptime'], + connections: DatabaseStatusConnections.fromMap(map['connections']), + replicas: List.from( + map['replicas'].map((p) => DatabaseStatusReplica.fromMap(p))), + volumes: List.from( + map['volumes'].map((p) => DatabaseStatusVolume.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "health": health, + "ready": ready, + "engine": engine, + "version": version, + "uptime": uptime, + "connections": connections.toMap(), + "replicas": replicas.map((p) => p.toMap()).toList(), + "volumes": volumes.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/database_status_connections.dart b/lib/src/models/database_status_connections.dart new file mode 100644 index 00000000..b10f1c41 --- /dev/null +++ b/lib/src/models/database_status_connections.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// Connections +class DatabaseStatusConnections implements Model { + /// Current number of active connections. + final int current; + + /// Maximum allowed connections. + final int max; + + DatabaseStatusConnections({ + required this.current, + required this.max, + }); + + factory DatabaseStatusConnections.fromMap(Map map) { + return DatabaseStatusConnections( + current: map['current'], + max: map['max'], + ); + } + + @override + Map toMap() { + return { + "current": current, + "max": max, + }; + } +} diff --git a/lib/src/models/database_status_replica.dart b/lib/src/models/database_status_replica.dart new file mode 100644 index 00000000..470a16fc --- /dev/null +++ b/lib/src/models/database_status_replica.dart @@ -0,0 +1,42 @@ +part of '../../models.dart'; + +/// Replica +class DatabaseStatusReplica implements Model { + /// StatefulSet pod index (0 = primary, 1+ = replicas). + final int index; + + /// Replica role: primary or replica. + final String role; + + /// Whether the replica is healthy. + final bool healthy; + + /// Replication lag in seconds (null for primary). + final double? lagSeconds; + + DatabaseStatusReplica({ + required this.index, + required this.role, + required this.healthy, + this.lagSeconds, + }); + + factory DatabaseStatusReplica.fromMap(Map map) { + return DatabaseStatusReplica( + index: map['index'], + role: map['role'].toString(), + healthy: map['healthy'], + lagSeconds: map['lagSeconds']?.toDouble(), + ); + } + + @override + Map toMap() { + return { + "index": index, + "role": role, + "healthy": healthy, + "lagSeconds": lagSeconds, + }; + } +} diff --git a/lib/src/models/database_status_volume.dart b/lib/src/models/database_status_volume.dart new file mode 100644 index 00000000..37f19bd8 --- /dev/null +++ b/lib/src/models/database_status_volume.dart @@ -0,0 +1,42 @@ +part of '../../models.dart'; + +/// Volume +class DatabaseStatusVolume implements Model { + /// Mount path of the volume. + final String path; + + /// Percentage of storage used. + final String usedPercent; + + /// Available storage space. + final String available; + + /// Whether the volume is mounted. + final bool mounted; + + DatabaseStatusVolume({ + required this.path, + required this.usedPercent, + required this.available, + required this.mounted, + }); + + factory DatabaseStatusVolume.fromMap(Map map) { + return DatabaseStatusVolume( + path: map['path'].toString(), + usedPercent: map['usedPercent'].toString(), + available: map['available'].toString(), + mounted: map['mounted'], + ); + } + + @override + Map toMap() { + return { + "path": path, + "usedPercent": usedPercent, + "available": available, + "mounted": mounted, + }; + } +} diff --git a/lib/src/models/dedicated_database.dart b/lib/src/models/dedicated_database.dart new file mode 100644 index 00000000..3c5b14af --- /dev/null +++ b/lib/src/models/dedicated_database.dart @@ -0,0 +1,313 @@ +part of '../../models.dart'; + +/// DedicatedDatabase +class DedicatedDatabase implements Model { + /// Dedicated database ID. + final String $id; + + /// Database creation time in ISO 8601 format. + final String $createdAt; + + /// Database update date in ISO 8601 format. + final String $updatedAt; + + /// Project ID that owns this database. + final String projectId; + + /// Database display name. + final String name; + + /// Product API that owns this database: tablesdb, documentsdb, vectorsdb, mysql, postgresql, or mongodb. + final String api; + + /// Database engine: postgresql, mysql, mariadb, or mongodb. + final String engine; + + /// Database engine version. + final String version; + + /// Specification identifier. + final String specification; + + /// Database backend provider. Possible values: prisma, edge. + final String backend; + + /// Database hostname for connections. + final String hostname; + + /// Database port for connections. + final int connectionPort; + + /// Database username for connections. + final String connectionUser; + + /// Database password for connections. + final String connectionPassword; + + /// Full database connection string (URI format). + final String connectionString; + + /// Whether SSL/TLS is required for client connections. + final bool ssl; + + /// Database status. Possible values: provisioning, ready, inactive, paused, failed, deleted, restoring, scaling. + final String status; + + /// Container status for lifecycle-managed database runtimes: active or inactive. + final String containerStatus; + + /// Last activity timestamp in ISO 8601 format. + final String? lastAccessedAt; + + /// Display-only timestamp when the database is expected to be considered idle (ISO 8601 format). Derived from last activity; lifecycle transitions are driven by lifecycleState. + final String? idleUntil; + + /// Idle-lifecycle state of the database. Possible values: active, warm, cold, hibernated. + final String lifecycleState; + + /// Minutes of inactivity before container scales to zero. + final int idleTimeoutMinutes; + + /// CPU allocated in millicores. + final int cpu; + + /// Memory allocated in MB. + final int memory; + + /// Storage allocated in GB. + final int storage; + + /// Storage class. Currently always 'ssd'; DigitalOcean exposes a single block-storage class. + final String storageClass; + + /// Maximum storage allowed in GB. 0 means use system default. + final int storageMaxGb; + + /// Kubernetes node pool where the database is scheduled. + final String nodePool; + + /// Number of high availability replicas. High availability is enabled when greater than 0. + final int replicas; + + /// Replication sync mode: async, sync, or quorum. + final String syncMode; + + /// Number of cross-region replicas. Cross-region availability is enabled when greater than 0. + final int crossRegionReplicas; + + /// Maximum concurrent connections. + final int networkMaxConnections; + + /// Connection idle timeout in seconds. + final int networkIdleTimeoutSeconds; + + /// IP addresses/CIDR ranges allowed to connect. + final List networkIPAllowlist; + + /// Whether automatic backups are enabled. + final bool backupEnabled; + + /// Whether point-in-time recovery is enabled. + final bool pitr; + + /// Number of days to retain PITR data. + final int pitrRetentionDays; + + /// Whether automatic storage expansion is enabled. + final bool storageAutoscaling; + + /// Storage usage percentage that triggers automatic expansion. + final int storageAutoscalingThresholdPercent; + + /// Maximum storage size in GB for autoscaling. 0 means no limit. + final int storageAutoscalingMaxGb; + + /// Day of the week for the maintenance window. Possible values: sun, mon, tue, wed, thu, fri, sat. + final String maintenanceWindowDay; + + /// Hour in UTC (0-23) when the maintenance window starts. + final int maintenanceWindowHourUtc; + + /// Whether metrics collection is enabled. + final bool metricsEnabled; + + /// Whether the SQL API sidecar is enabled for this database. + final bool sqlApiEnabled; + + /// Statement types accepted by the SQL API. Defaults to read/write DML only; DDL/DCL types (CREATE, ALTER, DROP, TRUNCATE, GRANT, REVOKE) are opt-in per database. Allowed values: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, TRUNCATE, GRANT, REVOKE. + final List sqlApiAllowedStatements; + + /// Maximum rows returned per SQL API execution. Results larger than this are truncated. + final int sqlApiMaxRows; + + /// Maximum serialised SQL API result payload in bytes. Results larger than this are truncated. + final int sqlApiMaxBytes; + + /// Maximum server-side SQL API execution time in seconds before the query is cancelled. + final int sqlApiTimeoutSeconds; + + /// Error message if status is failed. + final String error; + + DedicatedDatabase({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.projectId, + required this.name, + required this.api, + required this.engine, + required this.version, + required this.specification, + required this.backend, + required this.hostname, + required this.connectionPort, + required this.connectionUser, + required this.connectionPassword, + required this.connectionString, + required this.ssl, + required this.status, + required this.containerStatus, + this.lastAccessedAt, + this.idleUntil, + required this.lifecycleState, + required this.idleTimeoutMinutes, + required this.cpu, + required this.memory, + required this.storage, + required this.storageClass, + required this.storageMaxGb, + required this.nodePool, + required this.replicas, + required this.syncMode, + required this.crossRegionReplicas, + required this.networkMaxConnections, + required this.networkIdleTimeoutSeconds, + required this.networkIPAllowlist, + required this.backupEnabled, + required this.pitr, + required this.pitrRetentionDays, + required this.storageAutoscaling, + required this.storageAutoscalingThresholdPercent, + required this.storageAutoscalingMaxGb, + required this.maintenanceWindowDay, + required this.maintenanceWindowHourUtc, + required this.metricsEnabled, + required this.sqlApiEnabled, + required this.sqlApiAllowedStatements, + required this.sqlApiMaxRows, + required this.sqlApiMaxBytes, + required this.sqlApiTimeoutSeconds, + required this.error, + }); + + factory DedicatedDatabase.fromMap(Map map) { + return DedicatedDatabase( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + projectId: map['projectId'].toString(), + name: map['name'].toString(), + api: map['api'].toString(), + engine: map['engine'].toString(), + version: map['version'].toString(), + specification: map['specification'].toString(), + backend: map['backend'].toString(), + hostname: map['hostname'].toString(), + connectionPort: map['connectionPort'], + connectionUser: map['connectionUser'].toString(), + connectionPassword: map['connectionPassword'].toString(), + connectionString: map['connectionString'].toString(), + ssl: map['ssl'], + status: map['status'].toString(), + containerStatus: map['containerStatus'].toString(), + lastAccessedAt: map['lastAccessedAt']?.toString(), + idleUntil: map['idleUntil']?.toString(), + lifecycleState: map['lifecycleState'].toString(), + idleTimeoutMinutes: map['idleTimeoutMinutes'], + cpu: map['cpu'], + memory: map['memory'], + storage: map['storage'], + storageClass: map['storageClass'].toString(), + storageMaxGb: map['storageMaxGb'], + nodePool: map['nodePool'].toString(), + replicas: map['replicas'], + syncMode: map['syncMode'].toString(), + crossRegionReplicas: map['crossRegionReplicas'], + networkMaxConnections: map['networkMaxConnections'], + networkIdleTimeoutSeconds: map['networkIdleTimeoutSeconds'], + networkIPAllowlist: List.from(map['networkIPAllowlist'] ?? []), + backupEnabled: map['backupEnabled'], + pitr: map['pitr'], + pitrRetentionDays: map['pitrRetentionDays'], + storageAutoscaling: map['storageAutoscaling'], + storageAutoscalingThresholdPercent: + map['storageAutoscalingThresholdPercent'], + storageAutoscalingMaxGb: map['storageAutoscalingMaxGb'], + maintenanceWindowDay: map['maintenanceWindowDay'].toString(), + maintenanceWindowHourUtc: map['maintenanceWindowHourUtc'], + metricsEnabled: map['metricsEnabled'], + sqlApiEnabled: map['sqlApiEnabled'], + sqlApiAllowedStatements: List.from(map['sqlApiAllowedStatements'] ?? []), + sqlApiMaxRows: map['sqlApiMaxRows'], + sqlApiMaxBytes: map['sqlApiMaxBytes'], + sqlApiTimeoutSeconds: map['sqlApiTimeoutSeconds'], + error: map['error'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "projectId": projectId, + "name": name, + "api": api, + "engine": engine, + "version": version, + "specification": specification, + "backend": backend, + "hostname": hostname, + "connectionPort": connectionPort, + "connectionUser": connectionUser, + "connectionPassword": connectionPassword, + "connectionString": connectionString, + "ssl": ssl, + "status": status, + "containerStatus": containerStatus, + "lastAccessedAt": lastAccessedAt, + "idleUntil": idleUntil, + "lifecycleState": lifecycleState, + "idleTimeoutMinutes": idleTimeoutMinutes, + "cpu": cpu, + "memory": memory, + "storage": storage, + "storageClass": storageClass, + "storageMaxGb": storageMaxGb, + "nodePool": nodePool, + "replicas": replicas, + "syncMode": syncMode, + "crossRegionReplicas": crossRegionReplicas, + "networkMaxConnections": networkMaxConnections, + "networkIdleTimeoutSeconds": networkIdleTimeoutSeconds, + "networkIPAllowlist": networkIPAllowlist, + "backupEnabled": backupEnabled, + "pitr": pitr, + "pitrRetentionDays": pitrRetentionDays, + "storageAutoscaling": storageAutoscaling, + "storageAutoscalingThresholdPercent": storageAutoscalingThresholdPercent, + "storageAutoscalingMaxGb": storageAutoscalingMaxGb, + "maintenanceWindowDay": maintenanceWindowDay, + "maintenanceWindowHourUtc": maintenanceWindowHourUtc, + "metricsEnabled": metricsEnabled, + "sqlApiEnabled": sqlApiEnabled, + "sqlApiAllowedStatements": sqlApiAllowedStatements, + "sqlApiMaxRows": sqlApiMaxRows, + "sqlApiMaxBytes": sqlApiMaxBytes, + "sqlApiTimeoutSeconds": sqlApiTimeoutSeconds, + "error": error, + }; + } +} diff --git a/lib/src/models/dedicated_database_member.dart b/lib/src/models/dedicated_database_member.dart new file mode 100644 index 00000000..f5e59ded --- /dev/null +++ b/lib/src/models/dedicated_database_member.dart @@ -0,0 +1,42 @@ +part of '../../models.dart'; + +/// Member +class DedicatedDatabaseMember implements Model { + /// Member identifier. + final String $id; + + /// Member role. Possible values: primary (accepts reads and writes), replica (read-only follower). + final String role; + + /// Member pod status. Possible values: provisioning (pod missing or Pending), starting (Running but not Ready), active (Running and Ready), failed (Failed phase or CrashLoopBackOff container), or the lowercased pod phase reported by the cluster. + final String status; + + /// Replication lag in seconds. + final double lagSeconds; + + DedicatedDatabaseMember({ + required this.$id, + required this.role, + required this.status, + required this.lagSeconds, + }); + + factory DedicatedDatabaseMember.fromMap(Map map) { + return DedicatedDatabaseMember( + $id: map['\$id'].toString(), + role: map['role'].toString(), + status: map['status'].toString(), + lagSeconds: map['lagSeconds'].toDouble(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "role": role, + "status": status, + "lagSeconds": lagSeconds, + }; + } +} diff --git a/lib/src/models/dedicated_database_replicas.dart b/lib/src/models/dedicated_database_replicas.dart new file mode 100644 index 00000000..4418a84f --- /dev/null +++ b/lib/src/models/dedicated_database_replicas.dart @@ -0,0 +1,37 @@ +part of '../../models.dart'; + +/// Replicas +class DedicatedDatabaseReplicas implements Model { + /// Number of configured replicas. Zero means high availability is disabled. + final int replicas; + + /// Replication sync mode. Possible values: async (asynchronous, fastest), sync (synchronous, strong consistency), quorum (quorum-based, majority of replicas must confirm). + final String syncMode; + + /// Per-pod statuses for the primary and every replica. + final List members; + + DedicatedDatabaseReplicas({ + required this.replicas, + required this.syncMode, + required this.members, + }); + + factory DedicatedDatabaseReplicas.fromMap(Map map) { + return DedicatedDatabaseReplicas( + replicas: map['replicas'], + syncMode: map['syncMode'].toString(), + members: List.from( + map['members'].map((p) => DedicatedDatabaseMember.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "replicas": replicas, + "syncMode": syncMode, + "members": members.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/dedicated_database_specification.dart b/lib/src/models/dedicated_database_specification.dart new file mode 100644 index 00000000..3946c972 --- /dev/null +++ b/lib/src/models/dedicated_database_specification.dart @@ -0,0 +1,72 @@ +part of '../../models.dart'; + +/// Specification +class DedicatedDatabaseSpecification implements Model { + /// Specification slug. Use this value when creating a dedicated database. + final String slug; + + /// Human readable specification name. + final String name; + + /// Monthly price of the specification in USD. + final double price; + + /// Allocated CPU in millicores. + final int cpu; + + /// Allocated memory in MB. + final int memory; + + /// Maximum number of concurrent connections. + final int maxConnections; + + /// Included storage in GB before overage charges apply. + final int includedStorage; + + /// Included bandwidth in GB before overage charges apply. + final int includedBandwidth; + + /// Whether the specification is available on the current plan. + final bool enabled; + + DedicatedDatabaseSpecification({ + required this.slug, + required this.name, + required this.price, + required this.cpu, + required this.memory, + required this.maxConnections, + required this.includedStorage, + required this.includedBandwidth, + required this.enabled, + }); + + factory DedicatedDatabaseSpecification.fromMap(Map map) { + return DedicatedDatabaseSpecification( + slug: map['slug'].toString(), + name: map['name'].toString(), + price: map['price'].toDouble(), + cpu: map['cpu'], + memory: map['memory'], + maxConnections: map['maxConnections'], + includedStorage: map['includedStorage'], + includedBandwidth: map['includedBandwidth'], + enabled: map['enabled'], + ); + } + + @override + Map toMap() { + return { + "slug": slug, + "name": name, + "price": price, + "cpu": cpu, + "memory": memory, + "maxConnections": maxConnections, + "includedStorage": includedStorage, + "includedBandwidth": includedBandwidth, + "enabled": enabled, + }; + } +} diff --git a/lib/src/models/dedicated_database_specification_list.dart b/lib/src/models/dedicated_database_specification_list.dart new file mode 100644 index 00000000..7e1da75a --- /dev/null +++ b/lib/src/models/dedicated_database_specification_list.dart @@ -0,0 +1,38 @@ +part of '../../models.dart'; + +/// SpecificationList +class DedicatedDatabaseSpecificationList implements Model { + /// List of dedicated database specifications. + final List specifications; + + /// Total number of specifications. + final int total; + + /// Overage and add-on pricing shared across all specifications. + final DedicatedDatabaseSpecificationPricing pricing; + + DedicatedDatabaseSpecificationList({ + required this.specifications, + required this.total, + required this.pricing, + }); + + factory DedicatedDatabaseSpecificationList.fromMap(Map map) { + return DedicatedDatabaseSpecificationList( + specifications: List.from( + map['specifications'] + .map((p) => DedicatedDatabaseSpecification.fromMap(p))), + total: map['total'], + pricing: DedicatedDatabaseSpecificationPricing.fromMap(map['pricing']), + ); + } + + @override + Map toMap() { + return { + "specifications": specifications.map((p) => p.toMap()).toList(), + "total": total, + "pricing": pricing.toMap(), + }; + } +} diff --git a/lib/src/models/dedicated_database_specification_pricing.dart b/lib/src/models/dedicated_database_specification_pricing.dart new file mode 100644 index 00000000..2af567bd --- /dev/null +++ b/lib/src/models/dedicated_database_specification_pricing.dart @@ -0,0 +1,49 @@ +part of '../../models.dart'; + +/// SpecificationPricing +class DedicatedDatabaseSpecificationPricing implements Model { + /// Price per GB of storage above the included amount, per month, in USD. + final double storageOverageRate; + + /// Price per GB of bandwidth above the included amount, per month, in USD. + final double bandwidthOverageRate; + + /// High availability replica price as a fraction of the specification cost. + final double replicaRate; + + /// Cross-region replica price as a fraction of the specification cost. + final double crossRegionReplicaRate; + + /// Point-in-time recovery price as a fraction of the specification cost. + final double pitrRate; + + DedicatedDatabaseSpecificationPricing({ + required this.storageOverageRate, + required this.bandwidthOverageRate, + required this.replicaRate, + required this.crossRegionReplicaRate, + required this.pitrRate, + }); + + factory DedicatedDatabaseSpecificationPricing.fromMap( + Map map) { + return DedicatedDatabaseSpecificationPricing( + storageOverageRate: map['storageOverageRate'].toDouble(), + bandwidthOverageRate: map['bandwidthOverageRate'].toDouble(), + replicaRate: map['replicaRate'].toDouble(), + crossRegionReplicaRate: map['crossRegionReplicaRate'].toDouble(), + pitrRate: map['pitrRate'].toDouble(), + ); + } + + @override + Map toMap() { + return { + "storageOverageRate": storageOverageRate, + "bandwidthOverageRate": bandwidthOverageRate, + "replicaRate": replicaRate, + "crossRegionReplicaRate": crossRegionReplicaRate, + "pitrRate": pitrRate, + }; + } +} diff --git a/lib/src/models/oauth2_approve.dart b/lib/src/models/oauth2_approve.dart new file mode 100644 index 00000000..f911ab0a --- /dev/null +++ b/lib/src/models/oauth2_approve.dart @@ -0,0 +1,24 @@ +part of '../../models.dart'; + +/// OAuth2 Approve +class Oauth2Approve implements Model { + /// URL the end user should be redirected to after the grant is approved, carrying the authorization `code` and/or `id_token` along with the original `state`. + final String redirectUrl; + + Oauth2Approve({ + required this.redirectUrl, + }); + + factory Oauth2Approve.fromMap(Map map) { + return Oauth2Approve( + redirectUrl: map['redirectUrl'].toString(), + ); + } + + @override + Map toMap() { + return { + "redirectUrl": redirectUrl, + }; + } +} diff --git a/lib/src/models/oauth2_authorize.dart b/lib/src/models/oauth2_authorize.dart new file mode 100644 index 00000000..73637dca --- /dev/null +++ b/lib/src/models/oauth2_authorize.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// OAuth2 Authorize +class Oauth2Authorize implements Model { + /// OAuth2 grant ID. Set when the user must give explicit consent; pass it to the approve or reject endpoint. Empty when a redirect URL is returned instead. + final String grantId; + + /// URL the end user should be redirected to when the flow can complete without consent. Empty when consent is still required. + final String redirectUrl; + + Oauth2Authorize({ + required this.grantId, + required this.redirectUrl, + }); + + factory Oauth2Authorize.fromMap(Map map) { + return Oauth2Authorize( + grantId: map['grantId'].toString(), + redirectUrl: map['redirectUrl'].toString(), + ); + } + + @override + Map toMap() { + return { + "grantId": grantId, + "redirectUrl": redirectUrl, + }; + } +} diff --git a/lib/src/models/oauth2_consent.dart b/lib/src/models/oauth2_consent.dart new file mode 100644 index 00000000..0f71fac2 --- /dev/null +++ b/lib/src/models/oauth2_consent.dart @@ -0,0 +1,78 @@ +part of '../../models.dart'; + +/// OAuth2 Consent +class Oauth2Consent implements Model { + /// Consent ID. + final String $id; + + /// Consent creation time in ISO 8601 format. + final String $createdAt; + + /// Consent update date in ISO 8601 format. + final String $updatedAt; + + /// ID of the user the consent belongs to. + final String userId; + + /// ID of the registered app the consent was given to. Empty for URL-form (CIMD) clients. + final String appId; + + /// Client ID metadata document URL of the client the consent was given to. Empty for registered apps. + final String cimdUrl; + + /// OAuth2 scopes the user consented to. + final List scopes; + + /// RFC 8707 resource indicators the user consented to. + final List resources; + + /// Authorization details the user consented to, as a JSON string. Each entry has a `type` plus project-defined fields. + final String authorizationDetails; + + /// Consent expiration time in ISO 8601 format. Empty when the consent has no token-bound expiry yet. + final String expire; + + Oauth2Consent({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.appId, + required this.cimdUrl, + required this.scopes, + required this.resources, + required this.authorizationDetails, + required this.expire, + }); + + factory Oauth2Consent.fromMap(Map map) { + return Oauth2Consent( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + appId: map['appId'].toString(), + cimdUrl: map['cimdUrl'].toString(), + scopes: List.from(map['scopes'] ?? []), + resources: List.from(map['resources'] ?? []), + authorizationDetails: map['authorizationDetails'].toString(), + expire: map['expire'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "appId": appId, + "cimdUrl": cimdUrl, + "scopes": scopes, + "resources": resources, + "authorizationDetails": authorizationDetails, + "expire": expire, + }; + } +} diff --git a/lib/src/models/oauth2_consent_list.dart b/lib/src/models/oauth2_consent_list.dart new file mode 100644 index 00000000..a5f355e1 --- /dev/null +++ b/lib/src/models/oauth2_consent_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// OAuth2 consents list +class Oauth2ConsentList implements Model { + /// Total number of consents that matched your query. + final int total; + + /// List of consents. + final List consents; + + Oauth2ConsentList({ + required this.total, + required this.consents, + }); + + factory Oauth2ConsentList.fromMap(Map map) { + return Oauth2ConsentList( + total: map['total'], + consents: List.from( + map['consents'].map((p) => Oauth2Consent.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "consents": consents.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/oauth2_consent_token.dart b/lib/src/models/oauth2_consent_token.dart new file mode 100644 index 00000000..adbee89f --- /dev/null +++ b/lib/src/models/oauth2_consent_token.dart @@ -0,0 +1,84 @@ +part of '../../models.dart'; + +/// OAuth2 Consent Token +class Oauth2ConsentToken implements Model { + /// Token family ID. + final String $id; + + /// Token creation time in ISO 8601 format. + final String $createdAt; + + /// Token update date in ISO 8601 format. Refreshing the token family updates this. + final String $updatedAt; + + /// ID of the consent the token family was issued under. + final String consentId; + + /// ID of the user the token family belongs to. + final String userId; + + /// ID of the registered app the token family was issued to. Empty for URL-form (CIMD) clients. + final String appId; + + /// Client ID metadata document URL of the client the token family was issued to. Empty for registered apps. + final String cimdUrl; + + /// OAuth2 scopes granted on the token family. + final List scopes; + + /// RFC 8707 resource indicators granted on the token family. + final List resources; + + /// Authorization details granted on the token family, as a JSON string. Each entry has a `type` plus project-defined fields. + final String authorizationDetails; + + /// Expiration time of the current access token of this family in ISO 8601 format. + final String expire; + + Oauth2ConsentToken({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.consentId, + required this.userId, + required this.appId, + required this.cimdUrl, + required this.scopes, + required this.resources, + required this.authorizationDetails, + required this.expire, + }); + + factory Oauth2ConsentToken.fromMap(Map map) { + return Oauth2ConsentToken( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + consentId: map['consentId'].toString(), + userId: map['userId'].toString(), + appId: map['appId'].toString(), + cimdUrl: map['cimdUrl'].toString(), + scopes: List.from(map['scopes'] ?? []), + resources: List.from(map['resources'] ?? []), + authorizationDetails: map['authorizationDetails'].toString(), + expire: map['expire'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "consentId": consentId, + "userId": userId, + "appId": appId, + "cimdUrl": cimdUrl, + "scopes": scopes, + "resources": resources, + "authorizationDetails": authorizationDetails, + "expire": expire, + }; + } +} diff --git a/lib/src/models/oauth2_consent_token_list.dart b/lib/src/models/oauth2_consent_token_list.dart new file mode 100644 index 00000000..cc5cdc16 --- /dev/null +++ b/lib/src/models/oauth2_consent_token_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// OAuth2 consent tokens list +class Oauth2ConsentTokenList implements Model { + /// Total number of tokens that matched your query. + final int total; + + /// List of tokens. + final List tokens; + + Oauth2ConsentTokenList({ + required this.total, + required this.tokens, + }); + + factory Oauth2ConsentTokenList.fromMap(Map map) { + return Oauth2ConsentTokenList( + total: map['total'], + tokens: List.from( + map['tokens'].map((p) => Oauth2ConsentToken.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "tokens": tokens.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/oauth2_device_authorization.dart b/lib/src/models/oauth2_device_authorization.dart new file mode 100644 index 00000000..5029791b --- /dev/null +++ b/lib/src/models/oauth2_device_authorization.dart @@ -0,0 +1,54 @@ +part of '../../models.dart'; + +/// OAuth2 Device Authorization +class Oauth2DeviceAuthorization implements Model { + /// Device verification code used by the client to poll the token endpoint. + final String device_code; + + /// Short code the end user enters on the verification page. + final String user_code; + + /// URL where the end user enters the user code. + final String verification_uri; + + /// Verification URL with the user code prefilled as a query parameter. + final String verification_uri_complete; + + /// Lifetime of the device code and user code in seconds. + final int expires_in; + + /// Minimum polling interval for the token endpoint in seconds. + final int interval; + + Oauth2DeviceAuthorization({ + required this.device_code, + required this.user_code, + required this.verification_uri, + required this.verification_uri_complete, + required this.expires_in, + required this.interval, + }); + + factory Oauth2DeviceAuthorization.fromMap(Map map) { + return Oauth2DeviceAuthorization( + device_code: map['device_code'].toString(), + user_code: map['user_code'].toString(), + verification_uri: map['verification_uri'].toString(), + verification_uri_complete: map['verification_uri_complete'].toString(), + expires_in: map['expires_in'], + interval: map['interval'], + ); + } + + @override + Map toMap() { + return { + "device_code": device_code, + "user_code": user_code, + "verification_uri": verification_uri, + "verification_uri_complete": verification_uri_complete, + "expires_in": expires_in, + "interval": interval, + }; + } +} diff --git a/lib/src/models/oauth2_grant.dart b/lib/src/models/oauth2_grant.dart new file mode 100644 index 00000000..7302304e --- /dev/null +++ b/lib/src/models/oauth2_grant.dart @@ -0,0 +1,90 @@ +part of '../../models.dart'; + +/// OAuth2 Grant +class Oauth2Grant implements Model { + /// Grant ID. + final String $id; + + /// Grant creation time in ISO 8601 format. + final String $createdAt; + + /// Grant update date in ISO 8601 format. + final String $updatedAt; + + /// ID of the user the grant belongs to. + final String userId; + + /// ID of the OAuth2 client (app) the grant was requested for. + final String appId; + + /// Requested OAuth2 scopes the user is being asked to consent to. + final List scopes; + + /// Requested RFC 8707 resource indicators the user is being asked to consent to. + final List resources; + + /// Requested authorization_details the user is being asked to consent to, as a JSON string. Each entry has a `type` plus project-defined fields. + final String authorizationDetails; + + /// OIDC prompt directive the consent screen should honor. Space-separated list of: login, consent, select_account. + final String prompt; + + /// Redirect URI the user will be sent to after the flow completes. + final String redirectUri; + + /// Unix timestamp of when the user last authenticated. + final int authTime; + + /// Grant expiration time in ISO 8601 format. + final String expire; + + Oauth2Grant({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.appId, + required this.scopes, + required this.resources, + required this.authorizationDetails, + required this.prompt, + required this.redirectUri, + required this.authTime, + required this.expire, + }); + + factory Oauth2Grant.fromMap(Map map) { + return Oauth2Grant( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + appId: map['appId'].toString(), + scopes: List.from(map['scopes'] ?? []), + resources: List.from(map['resources'] ?? []), + authorizationDetails: map['authorizationDetails'].toString(), + prompt: map['prompt'].toString(), + redirectUri: map['redirectUri'].toString(), + authTime: map['authTime'], + expire: map['expire'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "appId": appId, + "scopes": scopes, + "resources": resources, + "authorizationDetails": authorizationDetails, + "prompt": prompt, + "redirectUri": redirectUri, + "authTime": authTime, + "expire": expire, + }; + } +} diff --git a/lib/src/models/oauth2_organization.dart b/lib/src/models/oauth2_organization.dart new file mode 100644 index 00000000..3e5c695c --- /dev/null +++ b/lib/src/models/oauth2_organization.dart @@ -0,0 +1,24 @@ +part of '../../models.dart'; + +/// OAuth2 Organization +class Oauth2Organization implements Model { + /// Organization ID. + final String $id; + + Oauth2Organization({ + required this.$id, + }); + + factory Oauth2Organization.fromMap(Map map) { + return Oauth2Organization( + $id: map['\$id'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + }; + } +} diff --git a/lib/src/models/oauth2_organization_list.dart b/lib/src/models/oauth2_organization_list.dart new file mode 100644 index 00000000..9c9534de --- /dev/null +++ b/lib/src/models/oauth2_organization_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// OAuth2 accessible organizations list +class Oauth2OrganizationList implements Model { + /// Total number of organizations that matched your query. + final int total; + + /// List of organizations. + final List organizations; + + Oauth2OrganizationList({ + required this.total, + required this.organizations, + }); + + factory Oauth2OrganizationList.fromMap(Map map) { + return Oauth2OrganizationList( + total: map['total'], + organizations: List.from( + map['organizations'].map((p) => Oauth2Organization.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "organizations": organizations.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/oauth2_par.dart b/lib/src/models/oauth2_par.dart new file mode 100644 index 00000000..0374b049 --- /dev/null +++ b/lib/src/models/oauth2_par.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// OAuth2 PAR +class Oauth2PAR implements Model { + /// Authorization request handle to pass to the authorize endpoint. + final String request_uri; + + /// Lifetime of the authorization request handle in seconds. + final int expires_in; + + Oauth2PAR({ + required this.request_uri, + required this.expires_in, + }); + + factory Oauth2PAR.fromMap(Map map) { + return Oauth2PAR( + request_uri: map['request_uri'].toString(), + expires_in: map['expires_in'], + ); + } + + @override + Map toMap() { + return { + "request_uri": request_uri, + "expires_in": expires_in, + }; + } +} diff --git a/lib/src/models/oauth2_project.dart b/lib/src/models/oauth2_project.dart new file mode 100644 index 00000000..5e85708d --- /dev/null +++ b/lib/src/models/oauth2_project.dart @@ -0,0 +1,36 @@ +part of '../../models.dart'; + +/// OAuth2 Project +class Oauth2Project implements Model { + /// Project ID. + final String $id; + + /// Region ID the project is deployed in. + final String region; + + /// API endpoint of the region the project is deployed in. Empty when the region has no public hostname configured. + final String endpoint; + + Oauth2Project({ + required this.$id, + required this.region, + required this.endpoint, + }); + + factory Oauth2Project.fromMap(Map map) { + return Oauth2Project( + $id: map['\$id'].toString(), + region: map['region'].toString(), + endpoint: map['endpoint'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "region": region, + "endpoint": endpoint, + }; + } +} diff --git a/lib/src/models/oauth2_project_list.dart b/lib/src/models/oauth2_project_list.dart new file mode 100644 index 00000000..4fb7efaa --- /dev/null +++ b/lib/src/models/oauth2_project_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// OAuth2 accessible projects list +class Oauth2ProjectList implements Model { + /// Total number of projects that matched your query. + final int total; + + /// List of projects. + final List projects; + + Oauth2ProjectList({ + required this.total, + required this.projects, + }); + + factory Oauth2ProjectList.fromMap(Map map) { + return Oauth2ProjectList( + total: map['total'], + projects: List.from( + map['projects'].map((p) => Oauth2Project.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "projects": projects.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/oauth2_reject.dart b/lib/src/models/oauth2_reject.dart new file mode 100644 index 00000000..70304bc5 --- /dev/null +++ b/lib/src/models/oauth2_reject.dart @@ -0,0 +1,24 @@ +part of '../../models.dart'; + +/// OAuth2 Reject +class Oauth2Reject implements Model { + /// URL the end user should be redirected to after the grant is rejected, carrying an `access_denied` error. + final String redirectUrl; + + Oauth2Reject({ + required this.redirectUrl, + }); + + factory Oauth2Reject.fromMap(Map map) { + return Oauth2Reject( + redirectUrl: map['redirectUrl'].toString(), + ); + } + + @override + Map toMap() { + return { + "redirectUrl": redirectUrl, + }; + } +} diff --git a/lib/src/models/oauth2_token.dart b/lib/src/models/oauth2_token.dart new file mode 100644 index 00000000..d171e974 --- /dev/null +++ b/lib/src/models/oauth2_token.dart @@ -0,0 +1,60 @@ +part of '../../models.dart'; + +/// OAuth2 Token +class Oauth2Token implements Model { + /// OAuth2 access token. + final String access_token; + + /// OAuth2 token type. + final String token_type; + + /// Access token lifetime in seconds. + final int expires_in; + + /// OAuth2 refresh token. + final String refresh_token; + + /// Space-separated scopes granted to the access token. + final String scope; + + /// Granted RFC 9396 authorization details as a JSON string. + final String? authorization_details; + + /// OpenID Connect ID token. Returned when the `openid` scope is granted. + final String? id_token; + + Oauth2Token({ + required this.access_token, + required this.token_type, + required this.expires_in, + required this.refresh_token, + required this.scope, + this.authorization_details, + this.id_token, + }); + + factory Oauth2Token.fromMap(Map map) { + return Oauth2Token( + access_token: map['access_token'].toString(), + token_type: map['token_type'].toString(), + expires_in: map['expires_in'], + refresh_token: map['refresh_token'].toString(), + scope: map['scope'].toString(), + authorization_details: map['authorization_details']?.toString(), + id_token: map['id_token']?.toString(), + ); + } + + @override + Map toMap() { + return { + "access_token": access_token, + "token_type": token_type, + "expires_in": expires_in, + "refresh_token": refresh_token, + "scope": scope, + "authorization_details": authorization_details, + "id_token": id_token, + }; + } +} diff --git a/lib/src/models/project.dart b/lib/src/models/project.dart index 7f1ecde3..caa4689a 100644 --- a/lib/src/models/project.dart +++ b/lib/src/models/project.dart @@ -83,6 +83,9 @@ class Project implements Model { /// Last time the project was accessed via console. Used with plan's projectInactivityDays to determine if project is paused. final String consoleAccessedAt; + /// Whether WAF enforcement is enabled for the project. + final bool wafEnabled; + /// Billing limits reached final BillingLimits? billingLimits; @@ -113,6 +116,9 @@ class Project implements Model { /// OAuth2 server refresh token duration in seconds for public clients (SPAs, mobile, native) final int? oAuth2ServerPublicRefreshTokenDuration; + /// OAuth2 server access token duration in seconds for app installation access tokens + final int? oAuth2ServerInstallationAccessTokenDuration; + /// When enabled, PKCE is required for confidential clients (server-side flows using client_secret). PKCE is always required for public clients regardless of this setting. final bool? oAuth2ServerConfidentialPkce; @@ -159,6 +165,7 @@ class Project implements Model { required this.protocols, required this.blocks, required this.consoleAccessedAt, + required this.wafEnabled, this.billingLimits, this.oAuth2ServerEnabled, this.oAuth2ServerAuthorizationUrl, @@ -169,6 +176,7 @@ class Project implements Model { this.oAuth2ServerRefreshTokenDuration, this.oAuth2ServerPublicAccessTokenDuration, this.oAuth2ServerPublicRefreshTokenDuration, + this.oAuth2ServerInstallationAccessTokenDuration, this.oAuth2ServerConfidentialPkce, this.oAuth2ServerVerificationUrl, this.oAuth2ServerUserCodeLength, @@ -209,6 +217,7 @@ class Project implements Model { map['protocols'].map((p) => ProjectProtocol.fromMap(p))), blocks: List.from(map['blocks'].map((p) => Block.fromMap(p))), consoleAccessedAt: map['consoleAccessedAt'].toString(), + wafEnabled: map['wafEnabled'], billingLimits: map['billingLimits'] != null ? BillingLimits.fromMap(map['billingLimits']) : null, @@ -226,6 +235,8 @@ class Project implements Model { map['oAuth2ServerPublicAccessTokenDuration'], oAuth2ServerPublicRefreshTokenDuration: map['oAuth2ServerPublicRefreshTokenDuration'], + oAuth2ServerInstallationAccessTokenDuration: + map['oAuth2ServerInstallationAccessTokenDuration'], oAuth2ServerConfidentialPkce: map['oAuth2ServerConfidentialPkce'], oAuth2ServerVerificationUrl: map['oAuth2ServerVerificationUrl']?.toString(), @@ -266,6 +277,7 @@ class Project implements Model { "protocols": protocols.map((p) => p.toMap()).toList(), "blocks": blocks.map((p) => p.toMap()).toList(), "consoleAccessedAt": consoleAccessedAt, + "wafEnabled": wafEnabled, "billingLimits": billingLimits?.toMap(), "oAuth2ServerEnabled": oAuth2ServerEnabled, "oAuth2ServerAuthorizationUrl": oAuth2ServerAuthorizationUrl, @@ -279,6 +291,8 @@ class Project implements Model { oAuth2ServerPublicAccessTokenDuration, "oAuth2ServerPublicRefreshTokenDuration": oAuth2ServerPublicRefreshTokenDuration, + "oAuth2ServerInstallationAccessTokenDuration": + oAuth2ServerInstallationAccessTokenDuration, "oAuth2ServerConfidentialPkce": oAuth2ServerConfidentialPkce, "oAuth2ServerVerificationUrl": oAuth2ServerVerificationUrl, "oAuth2ServerUserCodeLength": oAuth2ServerUserCodeLength, diff --git a/pubspec.yaml b/pubspec.yaml index 4af9f0af..f5fc8a4a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dart_appwrite -version: 26.0.0 +version: 26.1.0 description: Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-dart diff --git a/test/services/account_test.dart b/test/services/account_test.dart index 71b0170a..adc3c836 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -114,6 +114,113 @@ void main() { expect(response, isA()); }); + test('test method listConsents()', () async { + final Map data = { + 'total': 5, + 'consents': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.listConsents(); + expect(response, isA()); + }); + + test('test method getConsent()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'appId': '5e5ea5c16897e', + 'cimdUrl': 'https://example.com/.well-known/client-metadata.json', + 'scopes': [], + 'resources': [], + 'authorizationDetails': + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + 'expire': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.getConsent( + consentId: '', + ); + expect(response, isA()); + }); + + test('test method deleteConsent()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.deleteConsent( + consentId: '', + ); + }); + + test('test method listConsentTokens()', () async { + final Map data = { + 'total': 5, + 'tokens': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.listConsentTokens( + consentId: '', + ); + expect(response, isA()); + }); + + test('test method getConsentToken()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'consentId': '5e5ea5c16897e', + 'userId': '5e5ea5c16897e', + 'appId': '5e5ea5c16897e', + 'cimdUrl': 'https://example.com/.well-known/client-metadata.json', + 'scopes': [], + 'resources': [], + 'authorizationDetails': + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + 'expire': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.getConsentToken( + consentId: '', + tokenId: '', + ); + expect(response, isA()); + }); + + test('test method deleteConsentToken()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.deleteConsentToken( + consentId: '', + tokenId: '', + ); + }); + test('test method updateEmail()', () async { final Map data = { '\$id': '5e5ea5c16897e', diff --git a/test/services/activities_test.dart b/test/services/activities_test.dart index e9137998..38dbfe0c 100644 --- a/test/services/activities_test.dart +++ b/test/services/activities_test.dart @@ -85,10 +85,21 @@ void main() { 'ip': '127.0.0.1', 'mode': 'admin', 'country': 'US', + 'continentCode': 'NA', + 'city': 'Mountain View', + 'subdivisions': 'California', + 'isp': 'Google', + 'autonomousSystemNumber': '15169', + 'autonomousSystemOrganization': 'GOOGLE', + 'connectionType': 'cable', + 'connectionUsageType': 'residential', + 'connectionOrganization': 'Google LLC', 'time': '2020-10-15T06:38:00.000+00:00', 'projectId': '610fc2f985ee0', 'teamId': '610fc2f985ee0', 'hostname': 'appwrite.io', + 'sdk': 'web', + 'sdkVersion': '14.0.0', }; when(client.call( diff --git a/test/services/apps_test.dart b/test/services/apps_test.dart new file mode 100644 index 00000000..dd94f33d --- /dev/null +++ b/test/services/apps_test.dart @@ -0,0 +1,539 @@ +import 'package:test/test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:dart_appwrite/models.dart' as models; +import 'package:dart_appwrite/enums.dart' as enums; +import 'package:dart_appwrite/src/enums.dart'; +import 'package:dart_appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:dart_appwrite/dart_appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth(Uri? url) async { + return super + .noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod( + Invocation.method( + #chunkedUpload, [path, params, paramName, idParamName, headers]), + returnValue: Response(data: {})); + } +} + +void main() { + group('Apps test', () { + late MockClient client; + late Apps apps; + + setUp(() { + client = MockClient(); + apps = Apps(client); + }); + + test('test method list()', () async { + final Map data = { + 'total': 5, + 'apps': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.list(); + expect(response, isA()); + }); + + test('test method create()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Application', + 'description': 'Connect your workspace to My Application.', + 'clientUri': 'https://example.com', + 'logoUri': 'https://example.com/logo.png', + 'privacyPolicyUrl': 'https://example.com/privacy', + 'termsUrl': 'https://example.com/terms', + 'contacts': [], + 'tagline': 'Automate your workspace.', + 'tags': [], + 'labels': [], + 'images': [], + 'supportUrl': 'https://example.com/support', + 'dataDeletionUrl': 'https://example.com/data-deletion', + 'redirectUris': [], + 'postLogoutRedirectUris': [], + 'enabled': true, + 'type': 'confidential', + 'deviceFlow': true, + 'teamId': '5e5ea5c16897e', + 'userId': '5e5ea5c16897e', + 'installationScopes': [], + 'installationRedirectUrl': 'https://example.com/setup', + 'secrets': [], + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.create( + appId: '', + name: '', + redirectUris: [], + ); + expect(response, isA()); + }); + + test('test method listInstallationScopes()', () async { + final Map data = { + 'total': 5, + 'scopes': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.listInstallationScopes(); + expect(response, isA()); + }); + + test('test method listOAuth2Scopes()', () async { + final Map data = { + 'total': 5, + 'scopes': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.listOAuth2Scopes(); + expect(response, isA()); + }); + + test('test method get()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Application', + 'description': 'Connect your workspace to My Application.', + 'clientUri': 'https://example.com', + 'logoUri': 'https://example.com/logo.png', + 'privacyPolicyUrl': 'https://example.com/privacy', + 'termsUrl': 'https://example.com/terms', + 'contacts': [], + 'tagline': 'Automate your workspace.', + 'tags': [], + 'labels': [], + 'images': [], + 'supportUrl': 'https://example.com/support', + 'dataDeletionUrl': 'https://example.com/data-deletion', + 'redirectUris': [], + 'postLogoutRedirectUris': [], + 'enabled': true, + 'type': 'confidential', + 'deviceFlow': true, + 'teamId': '5e5ea5c16897e', + 'userId': '5e5ea5c16897e', + 'installationScopes': [], + 'installationRedirectUrl': 'https://example.com/setup', + 'secrets': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.get( + appId: '', + ); + expect(response, isA()); + }); + + test('test method update()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Application', + 'description': 'Connect your workspace to My Application.', + 'clientUri': 'https://example.com', + 'logoUri': 'https://example.com/logo.png', + 'privacyPolicyUrl': 'https://example.com/privacy', + 'termsUrl': 'https://example.com/terms', + 'contacts': [], + 'tagline': 'Automate your workspace.', + 'tags': [], + 'labels': [], + 'images': [], + 'supportUrl': 'https://example.com/support', + 'dataDeletionUrl': 'https://example.com/data-deletion', + 'redirectUris': [], + 'postLogoutRedirectUris': [], + 'enabled': true, + 'type': 'confidential', + 'deviceFlow': true, + 'teamId': '5e5ea5c16897e', + 'userId': '5e5ea5c16897e', + 'installationScopes': [], + 'installationRedirectUrl': 'https://example.com/setup', + 'secrets': [], + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.update( + appId: '', + name: '', + ); + expect(response, isA()); + }); + + test('test method delete()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.delete( + appId: '', + ); + }); + + test('test method listInstallations()', () async { + final Map data = { + 'total': 5, + 'installations': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.listInstallations( + appId: '', + ); + expect(response, isA()); + }); + + test('test method getInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.getInstallation( + appId: '', + installationId: '', + ); + expect(response, isA()); + }); + + test('test method createInstallationToken()', () async { + final Map data = { + 'access_token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...', + 'token_type': 'Bearer', + 'expires_in': 3600, + 'refresh_token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...', + 'scope': 'openid email profile', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.createInstallationToken( + appId: '', + installationId: '', + ); + expect(response, isA()); + }); + + test('test method listKeys()', () async { + final Map data = { + 'total': 5, + 'keys': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.listKeys( + appId: '', + ); + expect(response, isA()); + }); + + test('test method createKey()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'secret': + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + 'hint': 'f5c6c7', + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.createKey( + appId: '', + ); + expect(response, isA()); + }); + + test('test method getKey()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'secret': + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + 'hint': 'f5c6c7', + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.getKey( + appId: '', + keyId: '', + ); + expect(response, isA()); + }); + + test('test method deleteKey()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.deleteKey( + appId: '', + keyId: '', + ); + }); + + test('test method updateLabels()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Application', + 'description': 'Connect your workspace to My Application.', + 'clientUri': 'https://example.com', + 'logoUri': 'https://example.com/logo.png', + 'privacyPolicyUrl': 'https://example.com/privacy', + 'termsUrl': 'https://example.com/terms', + 'contacts': [], + 'tagline': 'Automate your workspace.', + 'tags': [], + 'labels': [], + 'images': [], + 'supportUrl': 'https://example.com/support', + 'dataDeletionUrl': 'https://example.com/data-deletion', + 'redirectUris': [], + 'postLogoutRedirectUris': [], + 'enabled': true, + 'type': 'confidential', + 'deviceFlow': true, + 'teamId': '5e5ea5c16897e', + 'userId': '5e5ea5c16897e', + 'installationScopes': [], + 'installationRedirectUrl': 'https://example.com/setup', + 'secrets': [], + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.updateLabels( + appId: '', + labels: [], + ); + expect(response, isA()); + }); + + test('test method listSecrets()', () async { + final Map data = { + 'total': 5, + 'secrets': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.listSecrets( + appId: '', + ); + expect(response, isA()); + }); + + test('test method createSecret()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'secret': + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + 'hint': 'f5c6c7', + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.createSecret( + appId: '', + ); + expect(response, isA()); + }); + + test('test method getSecret()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'secret': '', + 'hint': 'f5c6c7', + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.getSecret( + appId: '', + secretId: '', + ); + expect(response, isA()); + }); + + test('test method deleteSecret()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.deleteSecret( + appId: '', + secretId: '', + ); + }); + + test('test method updateTeam()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Application', + 'description': 'Connect your workspace to My Application.', + 'clientUri': 'https://example.com', + 'logoUri': 'https://example.com/logo.png', + 'privacyPolicyUrl': 'https://example.com/privacy', + 'termsUrl': 'https://example.com/terms', + 'contacts': [], + 'tagline': 'Automate your workspace.', + 'tags': [], + 'labels': [], + 'images': [], + 'supportUrl': 'https://example.com/support', + 'dataDeletionUrl': 'https://example.com/data-deletion', + 'redirectUris': [], + 'postLogoutRedirectUris': [], + 'enabled': true, + 'type': 'confidential', + 'deviceFlow': true, + 'teamId': '5e5ea5c16897e', + 'userId': '5e5ea5c16897e', + 'installationScopes': [], + 'installationRedirectUrl': 'https://example.com/setup', + 'secrets': [], + }; + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.updateTeam( + appId: '', + teamId: '', + ); + expect(response, isA()); + }); + + test('test method deleteTokens()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await apps.deleteTokens( + appId: '', + ); + }); + }); +} diff --git a/test/services/backups_test.dart b/test/services/backups_test.dart index 98f72778..dfb364ff 100644 --- a/test/services/backups_test.dart +++ b/test/services/backups_test.dart @@ -241,8 +241,7 @@ void main() { 'migrationId': 'did8jx6ws45jana098ab7', 'services': [], 'resources': [], - 'options': - '{databases.database[{oldId, newId, newName, newSpecification}]}', + 'options': '{databases.database[{oldId, newId, newName}]}', }; when(client.call( @@ -282,8 +281,7 @@ void main() { 'migrationId': 'did8jx6ws45jana098ab7', 'services': [], 'resources': [], - 'options': - '{databases.database[{oldId, newId, newName, newSpecification}]}', + 'options': '{databases.database[{oldId, newId, newName}]}', }; when(client.call( diff --git a/test/services/databases_test.dart b/test/services/databases_test.dart index bb3bfdf1..c3d93c5f 100644 --- a/test/services/databases_test.dart +++ b/test/services/databases_test.dart @@ -76,8 +76,6 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'enabled': true, 'type': 'legacy', - 'policies': [], - 'archives': [], }; when(client.call( @@ -203,8 +201,6 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'enabled': true, 'type': 'legacy', - 'policies': [], - 'archives': [], }; when(client.call( @@ -225,8 +221,6 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'enabled': true, 'type': 'legacy', - 'policies': [], - 'archives': [], }; when(client.call( @@ -1291,13 +1285,13 @@ void main() { test('test method getAttribute()', () async { final Map data = { 'key': 'fullName', - 'type': 'string', 'status': 'available', 'error': 'string', 'required': true, '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'size': 128, + 'type': 'string', }; when(client.call( diff --git a/test/services/oauth2_test.dart b/test/services/oauth2_test.dart new file mode 100644 index 00000000..702df978 --- /dev/null +++ b/test/services/oauth2_test.dart @@ -0,0 +1,267 @@ +import 'package:test/test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:dart_appwrite/models.dart' as models; +import 'package:dart_appwrite/enums.dart' as enums; +import 'package:dart_appwrite/src/enums.dart'; +import 'package:dart_appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:dart_appwrite/dart_appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth(Uri? url) async { + return super + .noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod( + Invocation.method( + #chunkedUpload, [path, params, paramName, idParamName, headers]), + returnValue: Response(data: {})); + } +} + +void main() { + group('Oauth2 test', () { + late MockClient client; + late Oauth2 oauth2; + + setUp(() { + client = MockClient(); + oauth2 = Oauth2(client); + }); + + test('test method approve()', () async { + final Map data = { + 'redirectUrl': 'https://example.com/callback?code=abcde&state=fghij', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.approve( + grantId: '', + ); + expect(response, isA()); + }); + + test('test method authorize()', () async { + final Map data = { + 'grantId': '5e5ea5c16897e', + 'redirectUrl': 'https://example.com/callback?code=abcde&state=fghij', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.authorize(); + expect(response, isA()); + }); + + test('test method authorizePost()', () async { + final Map data = { + 'grantId': '5e5ea5c16897e', + 'redirectUrl': 'https://example.com/callback?code=abcde&state=fghij', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.authorizePost(); + expect(response, isA()); + }); + + test('test method createDeviceAuthorization()', () async { + final Map data = { + 'device_code': + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + 'user_code': 'ABCD-EFGH', + 'verification_uri': 'https://cloud.appwrite.io/console/oauth2/device', + 'verification_uri_complete': + 'https://cloud.appwrite.io/console/oauth2/device?user_code=ABCD-EFGH', + 'expires_in': 900, + 'interval': 5, + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.createDeviceAuthorization(); + expect(response, isA()); + }); + + test('test method createGrant()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'appId': '5e5ea5c16897e', + 'scopes': [], + 'resources': [], + 'authorizationDetails': + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + 'prompt': 'login', + 'redirectUri': 'https://example.com/callback', + 'authTime': 1592981250, + 'expire': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.createGrant( + userCode: '', + ); + expect(response, isA()); + }); + + test('test method getGrant()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'appId': '5e5ea5c16897e', + 'scopes': [], + 'resources': [], + 'authorizationDetails': + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + 'prompt': 'login', + 'redirectUri': 'https://example.com/callback', + 'authTime': 1592981250, + 'expire': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.getGrant( + grantId: '', + ); + expect(response, isA()); + }); + + test('test method listOrganizations()', () async { + final Map data = { + 'total': 5, + 'organizations': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.listOrganizations(); + expect(response, isA()); + }); + + test('test method createPAR()', () async { + final Map data = { + 'request_uri': 'urn:appwrite:oauth2:request:5e5ea5c16897e', + 'expires_in': 600, + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.createPAR( + clientId: '', + redirectUri: 'https://example.com', + responseType: 'code', + ); + expect(response, isA()); + }); + + test('test method listProjects()', () async { + final Map data = { + 'total': 5, + 'projects': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.listProjects(); + expect(response, isA()); + }); + + test('test method reject()', () async { + final Map data = { + 'redirectUrl': + 'https://example.com/callback?error=access_denied&state=fghij', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.reject( + grantId: '', + ); + expect(response, isA()); + }); + + test('test method revoke()', () async { + final data = ''; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.revoke( + token: '', + ); + }); + + test('test method createToken()', () async { + final Map data = { + 'access_token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...', + 'token_type': 'Bearer', + 'expires_in': 3600, + 'refresh_token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...', + 'scope': 'openid email profile', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await oauth2.createToken( + grantType: '', + ); + expect(response, isA()); + }); + }); +} diff --git a/test/services/organization_test.dart b/test/services/organization_test.dart index 89a20af0..044fb14b 100644 --- a/test/services/organization_test.dart +++ b/test/services/organization_test.dart @@ -79,6 +79,7 @@ void main() { 'screenshotsGenerated': 50, 'members': 25, 'webhooks': 25, + 'wafRules': 2, 'projects': 2, 'platforms': 3, 'users': 25, @@ -104,8 +105,118 @@ void main() { 'usageLogs': 30, 'projectInactivityDays': 7, 'alertLimit': 80, - 'usage': {}, - 'addons': {}, + 'usage': { + 'bandwidth': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'executions': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'member': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'realtime': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'realtimeMessages': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'realtimeBandwidth': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'storage': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'users': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'GBHours': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'imageTransformations': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'credits': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + }, + 'addons': { + 'seats': { + 'supported': true, + 'planIncluded': 1, + 'limit': 5, + 'type': 'numeric', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'projects': { + 'supported': true, + 'planIncluded': 1, + 'limit': 5, + 'type': 'numeric', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + }, 'budgetCapEnabled': true, 'customSmtp': true, 'emailBranding': true, @@ -125,7 +236,11 @@ void main() { 'supportsProjectSpecificRoles': true, 'backupsEnabled': true, 'usagePerProject': true, - 'supportedAddons': {}, + 'supportedAddons': { + 'baa': true, + 'premiumGeoDB': true, + 'premiumGeoDBOrg': true, + }, 'backupPolicies': 1, 'deploymentSize': 30, 'buildSize': 2000, @@ -190,6 +305,7 @@ void main() { 'screenshotsGenerated': 50, 'members': 25, 'webhooks': 25, + 'wafRules': 2, 'projects': 2, 'platforms': 3, 'users': 25, @@ -215,8 +331,118 @@ void main() { 'usageLogs': 30, 'projectInactivityDays': 7, 'alertLimit': 80, - 'usage': {}, - 'addons': {}, + 'usage': { + 'bandwidth': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'executions': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'member': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'realtime': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'realtimeMessages': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'realtimeBandwidth': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'storage': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'users': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'GBHours': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'imageTransformations': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'credits': { + 'name': '', + 'unit': 'GB', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + }, + 'addons': { + 'seats': { + 'supported': true, + 'planIncluded': 1, + 'limit': 5, + 'type': 'numeric', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + 'projects': { + 'supported': true, + 'planIncluded': 1, + 'limit': 5, + 'type': 'numeric', + 'currency': 'USD', + 'price': 5, + 'value': 25, + 'invoiceDesc': '', + }, + }, 'budgetCapEnabled': true, 'customSmtp': true, 'emailBranding': true, @@ -236,7 +462,11 @@ void main() { 'supportsProjectSpecificRoles': true, 'backupsEnabled': true, 'usagePerProject': true, - 'supportedAddons': {}, + 'supportedAddons': { + 'baa': true, + 'premiumGeoDB': true, + 'premiumGeoDBOrg': true, + }, 'backupPolicies': 1, 'deploymentSize': 30, 'buildSize': 2000, @@ -288,6 +518,101 @@ void main() { final response = await organization.delete(); }); + test('test method listInstallations()', () async { + final Map data = { + 'total': 5, + 'installations': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await organization.listInstallations(); + expect(response, isA()); + }); + + test('test method createInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await organization.createInstallation( + appId: '', + ); + expect(response, isA()); + }); + + test('test method getInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await organization.getInstallation( + installationId: '', + ); + expect(response, isA()); + }); + + test('test method updateInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await organization.updateInstallation( + installationId: '', + ); + expect(response, isA()); + }); + + test('test method deleteInstallation()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await organization.deleteInstallation( + installationId: '', + ); + }); + test('test method listKeys()', () async { final Map data = { 'total': 5, @@ -544,6 +869,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -586,6 +912,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -627,6 +954,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( diff --git a/test/services/project_test.dart b/test/services/project_test.dart index be790f3a..13a4dd44 100644 --- a/test/services/project_test.dart +++ b/test/services/project_test.dart @@ -83,6 +83,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -132,6 +133,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -297,6 +299,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -434,6 +437,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1178,11 +1182,11 @@ void main() { test('test method getOAuth2Provider()', () async { final Map data = { - '\$id': 'github', 'enabled': true, 'applicationId': '00001111-aaaa-2222-bbbb-3333cccc4444', 'applicationSecret': 'A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u', 'tenant': 'common', + '\$id': 'microsoft', }; when(client.call( @@ -1435,8 +1439,8 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'name': 'My Web App', - 'type': 'web', 'packageName': 'com.company.appname', + 'type': 'linux', }; when(client.call( @@ -1504,6 +1508,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1545,6 +1550,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1586,6 +1592,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1627,6 +1634,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1668,6 +1676,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1707,6 +1716,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1748,6 +1758,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1789,6 +1800,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1848,6 +1860,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1889,6 +1902,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1930,6 +1944,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -1971,6 +1986,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -2012,6 +2028,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -2026,8 +2043,8 @@ void main() { test('test method getPolicy()', () async { final Map data = { - '\$id': 'password-dictionary', 'enabled': true, + '\$id': 'deny-corporate-email', }; when(client.call( @@ -2069,6 +2086,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -2111,6 +2129,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( @@ -2153,6 +2172,7 @@ void main() { 'protocols': [], 'blocks': [], 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + 'wafEnabled': true, }; when(client.call( diff --git a/test/services/tables_db_test.dart b/test/services/tables_db_test.dart index f996e907..3cb3744c 100644 --- a/test/services/tables_db_test.dart +++ b/test/services/tables_db_test.dart @@ -76,8 +76,6 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'enabled': true, 'type': 'legacy', - 'policies': [], - 'archives': [], }; when(client.call( @@ -91,6 +89,27 @@ void main() { expect(response, isA()); }); + test('test method listSpecifications()', () async { + final Map data = { + 'specifications': [], + 'total': 9, + 'pricing': { + 'storageOverageRate': 0.125, + 'bandwidthOverageRate': 0.08, + 'replicaRate': 1, + 'crossRegionReplicaRate': 1, + 'pitrRate': 0.2, + }, + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await tablesDB.listSpecifications(); + expect(response, isA()); + }); + test('test method listTransactions()', () async { final Map data = { 'total': 5, @@ -203,8 +222,6 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'enabled': true, 'type': 'legacy', - 'policies': [], - 'archives': [], }; when(client.call( @@ -225,8 +242,6 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'enabled': true, 'type': 'legacy', - 'policies': [], - 'archives': [], }; when(client.call( @@ -251,6 +266,110 @@ void main() { ); }); + test('test method createFailover()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'projectId': '5e5ea5c16897e', + 'name': 'My Production Database', + 'api': 'postgresql', + 'engine': 'postgresql', + 'version': '16', + 'specification': 's-2vcpu-2gb', + 'backend': 'edge', + 'hostname': 'db-myproject-mydb.fra.appwrite.center', + 'connectionPort': 5432, + 'connectionUser': 'appwrite_user', + 'connectionPassword': '••••••••', + 'connectionString': + 'postgresql://user:pass@db-myproject-mydb.fra.appwrite.center:5432/postgres?sslmode=require', + 'ssl': true, + 'status': 'ready', + 'containerStatus': 'active', + 'lifecycleState': 'active', + 'idleTimeoutMinutes': 15, + 'cpu': 2000, + 'memory': 4096, + 'storage': 100, + 'storageClass': 'ssd', + 'storageMaxGb': 100, + 'nodePool': 'db-pool-4vcpu-8gb', + 'replicas': 2, + 'syncMode': 'async', + 'crossRegionReplicas': 1, + 'networkMaxConnections': 500, + 'networkIdleTimeoutSeconds': 900, + 'networkIPAllowlist': [], + 'backupEnabled': true, + 'pitr': true, + 'pitrRetentionDays': 14, + 'storageAutoscaling': true, + 'storageAutoscalingThresholdPercent': 85, + 'storageAutoscalingMaxGb': 500, + 'maintenanceWindowDay': 'sun', + 'maintenanceWindowHourUtc': 3, + 'metricsEnabled': true, + 'sqlApiEnabled': true, + 'sqlApiAllowedStatements': [], + 'sqlApiMaxRows': 10000, + 'sqlApiMaxBytes': 10485760, + 'sqlApiTimeoutSeconds': 30, + 'error': '', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await tablesDB.createFailover( + databaseId: '', + ); + expect(response, isA()); + }); + + test('test method getReplicas()', () async { + final Map data = { + 'replicas': 2, + 'syncMode': 'async', + 'members': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await tablesDB.getReplicas( + databaseId: '', + ); + expect(response, isA()); + }); + + test('test method getStatus()', () async { + final Map data = { + 'health': 'healthy', + 'ready': true, + 'engine': 'postgresql', + 'version': '17', + 'uptime': 86400, + 'connections': { + 'current': 12, + 'max': 100, + }, + 'replicas': [], + 'volumes': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await tablesDB.getStatus( + databaseId: '', + ); + expect(response, isA()); + }); + test('test method listTables()', () async { final Map data = { 'total': 5, @@ -1262,13 +1381,13 @@ void main() { test('test method getColumn()', () async { final Map data = { 'key': 'fullName', - 'type': 'string', 'status': 'available', 'error': 'string', 'required': true, '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'size': 128, + 'type': 'string', }; when(client.call( diff --git a/test/services/teams_test.dart b/test/services/teams_test.dart index 86e2cff5..37eed4c1 100644 --- a/test/services/teams_test.dart +++ b/test/services/teams_test.dart @@ -142,6 +142,107 @@ void main() { ); }); + test('test method listInstallations()', () async { + final Map data = { + 'total': 5, + 'installations': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await teams.listInstallations( + teamId: '', + ); + expect(response, isA()); + }); + + test('test method createInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await teams.createInstallation( + teamId: '', + appId: '', + ); + expect(response, isA()); + }); + + test('test method getInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await teams.getInstallation( + teamId: '', + installationId: '', + ); + expect(response, isA()); + }); + + test('test method updateInstallation()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'appId': '5e5ea5c16897e', + 'teamId': '5e5ea5c16897e', + 'scopes': [], + 'authorizationDetails': {}, + 'createdById': '5e5ea5c16897e', + 'createdByName': 'Walter White', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await teams.updateInstallation( + teamId: '', + installationId: '', + ); + expect(response, isA()); + }); + + test('test method deleteInstallation()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await teams.deleteInstallation( + teamId: '', + installationId: '', + ); + }); + test('test method listMemberships()', () async { final Map data = { 'total': 5, diff --git a/test/src/models/activity_event_test.dart b/test/src/models/activity_event_test.dart index 41066b54..198051bf 100644 --- a/test/src/models/activity_event_test.dart +++ b/test/src/models/activity_event_test.dart @@ -20,10 +20,21 @@ void main() { ip: '127.0.0.1', mode: 'admin', country: 'US', + continentCode: 'NA', + city: 'Mountain View', + subdivisions: 'California', + isp: 'Google', + autonomousSystemNumber: '15169', + autonomousSystemOrganization: 'GOOGLE', + connectionType: 'cable', + connectionUsageType: 'residential', + connectionOrganization: 'Google LLC', time: '2020-10-15T06:38:00.000+00:00', projectId: '610fc2f985ee0', teamId: '610fc2f985ee0', hostname: 'appwrite.io', + sdk: 'web', + sdkVersion: '14.0.0', ); final map = model.toMap(); @@ -44,10 +55,21 @@ void main() { expect(result.ip, '127.0.0.1'); expect(result.mode, 'admin'); expect(result.country, 'US'); + expect(result.continentCode, 'NA'); + expect(result.city, 'Mountain View'); + expect(result.subdivisions, 'California'); + expect(result.isp, 'Google'); + expect(result.autonomousSystemNumber, '15169'); + expect(result.autonomousSystemOrganization, 'GOOGLE'); + expect(result.connectionType, 'cable'); + expect(result.connectionUsageType, 'residential'); + expect(result.connectionOrganization, 'Google LLC'); expect(result.time, '2020-10-15T06:38:00.000+00:00'); expect(result.projectId, '610fc2f985ee0'); expect(result.teamId, '610fc2f985ee0'); expect(result.hostname, 'appwrite.io'); + expect(result.sdk, 'web'); + expect(result.sdkVersion, '14.0.0'); }); }); } diff --git a/test/src/models/app_installation_list_test.dart b/test/src/models/app_installation_list_test.dart new file mode 100644 index 00000000..e009aa4a --- /dev/null +++ b/test/src/models/app_installation_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppInstallationList', () { + test('model', () { + final model = AppInstallationList( + total: 5, + installations: [], + ); + + final map = model.toMap(); + final result = AppInstallationList.fromMap(map); + + expect(result.total, 5); + expect(result.installations, []); + }); + }); +} diff --git a/test/src/models/app_installation_test.dart b/test/src/models/app_installation_test.dart new file mode 100644 index 00000000..6300854c --- /dev/null +++ b/test/src/models/app_installation_test.dart @@ -0,0 +1,33 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppInstallation', () { + test('model', () { + final model = AppInstallation( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + appId: '5e5ea5c16897e', + teamId: '5e5ea5c16897e', + scopes: [], + authorizationDetails: {}, + createdById: '5e5ea5c16897e', + createdByName: 'Walter White', + ); + + final map = model.toMap(); + final result = AppInstallation.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.teamId, '5e5ea5c16897e'); + expect(result.scopes, []); + expect(result.authorizationDetails, {}); + expect(result.createdById, '5e5ea5c16897e'); + expect(result.createdByName, 'Walter White'); + }); + }); +} diff --git a/test/src/models/app_key_list_test.dart b/test/src/models/app_key_list_test.dart new file mode 100644 index 00000000..55d76a66 --- /dev/null +++ b/test/src/models/app_key_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppKeyList', () { + test('model', () { + final model = AppKeyList( + total: 5, + keys: [], + ); + + final map = model.toMap(); + final result = AppKeyList.fromMap(map); + + expect(result.total, 5); + expect(result.keys, []); + }); + }); +} diff --git a/test/src/models/app_key_test.dart b/test/src/models/app_key_test.dart new file mode 100644 index 00000000..82aed15f --- /dev/null +++ b/test/src/models/app_key_test.dart @@ -0,0 +1,33 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppKey', () { + test('model', () { + final model = AppKey( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + appId: '5e5ea5c16897e', + secret: + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + hint: 'f5c6c7', + createdById: '5e5ea5c16897e', + createdByName: 'Walter White', + ); + + final map = model.toMap(); + final result = AppKey.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.secret, + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a'); + expect(result.hint, 'f5c6c7'); + expect(result.createdById, '5e5ea5c16897e'); + expect(result.createdByName, 'Walter White'); + }); + }); +} diff --git a/test/src/models/app_scope_list_test.dart b/test/src/models/app_scope_list_test.dart new file mode 100644 index 00000000..94c4eed2 --- /dev/null +++ b/test/src/models/app_scope_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppScopeList', () { + test('model', () { + final model = AppScopeList( + total: 5, + scopes: [], + ); + + final map = model.toMap(); + final result = AppScopeList.fromMap(map); + + expect(result.total, 5); + expect(result.scopes, []); + }); + }); +} diff --git a/test/src/models/app_scope_test.dart b/test/src/models/app_scope_test.dart new file mode 100644 index 00000000..91411462 --- /dev/null +++ b/test/src/models/app_scope_test.dart @@ -0,0 +1,25 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppScope', () { + test('model', () { + final model = AppScope( + value: 'organization:organization.read', + description: 'Access to read the organization', + type: 'organization', + category: 'Organization', + deprecated: true, + ); + + final map = model.toMap(); + final result = AppScope.fromMap(map); + + expect(result.value, 'organization:organization.read'); + expect(result.description, 'Access to read the organization'); + expect(result.type, 'organization'); + expect(result.category, 'Organization'); + expect(result.deprecated, true); + }); + }); +} diff --git a/test/src/models/app_secret_list_test.dart b/test/src/models/app_secret_list_test.dart new file mode 100644 index 00000000..d1e3eee4 --- /dev/null +++ b/test/src/models/app_secret_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppSecretList', () { + test('model', () { + final model = AppSecretList( + total: 5, + secrets: [], + ); + + final map = model.toMap(); + final result = AppSecretList.fromMap(map); + + expect(result.total, 5); + expect(result.secrets, []); + }); + }); +} diff --git a/test/src/models/app_secret_plaintext_test.dart b/test/src/models/app_secret_plaintext_test.dart new file mode 100644 index 00000000..8c2b79b5 --- /dev/null +++ b/test/src/models/app_secret_plaintext_test.dart @@ -0,0 +1,33 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppSecretPlaintext', () { + test('model', () { + final model = AppSecretPlaintext( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + appId: '5e5ea5c16897e', + secret: + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + hint: 'f5c6c7', + createdById: '5e5ea5c16897e', + createdByName: 'Walter White', + ); + + final map = model.toMap(); + final result = AppSecretPlaintext.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.secret, + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a'); + expect(result.hint, 'f5c6c7'); + expect(result.createdById, '5e5ea5c16897e'); + expect(result.createdByName, 'Walter White'); + }); + }); +} diff --git a/test/src/models/app_secret_test.dart b/test/src/models/app_secret_test.dart new file mode 100644 index 00000000..36185743 --- /dev/null +++ b/test/src/models/app_secret_test.dart @@ -0,0 +1,31 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppSecret', () { + test('model', () { + final model = AppSecret( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + appId: '5e5ea5c16897e', + secret: '', + hint: 'f5c6c7', + createdById: '5e5ea5c16897e', + createdByName: 'Walter White', + ); + + final map = model.toMap(); + final result = AppSecret.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.secret, ''); + expect(result.hint, 'f5c6c7'); + expect(result.createdById, '5e5ea5c16897e'); + expect(result.createdByName, 'Walter White'); + }); + }); +} diff --git a/test/src/models/app_test.dart b/test/src/models/app_test.dart new file mode 100644 index 00000000..da0fd20b --- /dev/null +++ b/test/src/models/app_test.dart @@ -0,0 +1,67 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('App', () { + test('model', () { + final model = App( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My Application', + description: 'Connect your workspace to My Application.', + clientUri: 'https://example.com', + logoUri: 'https://example.com/logo.png', + privacyPolicyUrl: 'https://example.com/privacy', + termsUrl: 'https://example.com/terms', + contacts: [], + tagline: 'Automate your workspace.', + tags: [], + labels: [], + images: [], + supportUrl: 'https://example.com/support', + dataDeletionUrl: 'https://example.com/data-deletion', + redirectUris: [], + postLogoutRedirectUris: [], + enabled: true, + type: 'confidential', + deviceFlow: true, + teamId: '5e5ea5c16897e', + userId: '5e5ea5c16897e', + installationScopes: [], + installationRedirectUrl: 'https://example.com/setup', + secrets: [], + ); + + final map = model.toMap(); + final result = App.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.name, 'My Application'); + expect(result.description, 'Connect your workspace to My Application.'); + expect(result.clientUri, 'https://example.com'); + expect(result.logoUri, 'https://example.com/logo.png'); + expect(result.privacyPolicyUrl, 'https://example.com/privacy'); + expect(result.termsUrl, 'https://example.com/terms'); + expect(result.contacts, []); + expect(result.tagline, 'Automate your workspace.'); + expect(result.tags, []); + expect(result.labels, []); + expect(result.images, []); + expect(result.supportUrl, 'https://example.com/support'); + expect(result.dataDeletionUrl, 'https://example.com/data-deletion'); + expect(result.redirectUris, []); + expect(result.postLogoutRedirectUris, []); + expect(result.enabled, true); + expect(result.type, 'confidential'); + expect(result.deviceFlow, true); + expect(result.teamId, '5e5ea5c16897e'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.installationScopes, []); + expect(result.installationRedirectUrl, 'https://example.com/setup'); + expect(result.secrets, []); + }); + }); +} diff --git a/test/src/models/apps_list_test.dart b/test/src/models/apps_list_test.dart new file mode 100644 index 00000000..a12f3476 --- /dev/null +++ b/test/src/models/apps_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AppsList', () { + test('model', () { + final model = AppsList( + total: 5, + apps: [], + ); + + final map = model.toMap(); + final result = AppsList.fromMap(map); + + expect(result.total, 5); + expect(result.apps, []); + }); + }); +} diff --git a/test/src/models/backup_restoration_test.dart b/test/src/models/backup_restoration_test.dart index dd4c9bdb..b3b6f316 100644 --- a/test/src/models/backup_restoration_test.dart +++ b/test/src/models/backup_restoration_test.dart @@ -15,8 +15,7 @@ void main() { migrationId: 'did8jx6ws45jana098ab7', services: [], resources: [], - options: - '{databases.database[{oldId, newId, newName, newSpecification}]}', + options: '{databases.database[{oldId, newId, newName}]}', ); final map = model.toMap(); @@ -32,8 +31,7 @@ void main() { expect(result.migrationId, 'did8jx6ws45jana098ab7'); expect(result.services, []); expect(result.resources, []); - expect(result.options, - '{databases.database[{oldId, newId, newName, newSpecification}]}'); + expect(result.options, '{databases.database[{oldId, newId, newName}]}'); }); }); } diff --git a/test/src/models/billing_plan_test.dart b/test/src/models/billing_plan_test.dart index 15c1b7c2..06d83030 100644 --- a/test/src/models/billing_plan_test.dart +++ b/test/src/models/billing_plan_test.dart @@ -18,6 +18,7 @@ void main() { screenshotsGenerated: 50, members: 25, webhooks: 25, + wafRules: 2, projects: 2, platforms: 3, users: 25, @@ -201,6 +202,7 @@ void main() { expect(result.screenshotsGenerated, 50); expect(result.members, 25); expect(result.webhooks, 25); + expect(result.wafRules, 2); expect(result.projects, 2); expect(result.platforms, 3); expect(result.users, 25); diff --git a/test/src/models/database_status_connections_test.dart b/test/src/models/database_status_connections_test.dart new file mode 100644 index 00000000..8139195a --- /dev/null +++ b/test/src/models/database_status_connections_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DatabaseStatusConnections', () { + test('model', () { + final model = DatabaseStatusConnections( + current: 12, + max: 100, + ); + + final map = model.toMap(); + final result = DatabaseStatusConnections.fromMap(map); + + expect(result.current, 12); + expect(result.max, 100); + }); + }); +} diff --git a/test/src/models/database_status_replica_test.dart b/test/src/models/database_status_replica_test.dart new file mode 100644 index 00000000..d42a6ac3 --- /dev/null +++ b/test/src/models/database_status_replica_test.dart @@ -0,0 +1,21 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DatabaseStatusReplica', () { + test('model', () { + final model = DatabaseStatusReplica( + index: 0, + role: 'primary', + healthy: true, + ); + + final map = model.toMap(); + final result = DatabaseStatusReplica.fromMap(map); + + expect(result.index, 0); + expect(result.role, 'primary'); + expect(result.healthy, true); + }); + }); +} diff --git a/test/src/models/database_status_test.dart b/test/src/models/database_status_test.dart new file mode 100644 index 00000000..210d22b6 --- /dev/null +++ b/test/src/models/database_status_test.dart @@ -0,0 +1,33 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DatabaseStatus', () { + test('model', () { + final model = DatabaseStatus( + health: 'healthy', + ready: true, + engine: 'postgresql', + version: '17', + uptime: 86400, + connections: DatabaseStatusConnections( + current: 12, + max: 100, + ), + replicas: [], + volumes: [], + ); + + final map = model.toMap(); + final result = DatabaseStatus.fromMap(map); + + expect(result.health, 'healthy'); + expect(result.ready, true); + expect(result.engine, 'postgresql'); + expect(result.version, '17'); + expect(result.uptime, 86400); + expect(result.replicas, []); + expect(result.volumes, []); + }); + }); +} diff --git a/test/src/models/database_status_volume_test.dart b/test/src/models/database_status_volume_test.dart new file mode 100644 index 00000000..8c3f2a70 --- /dev/null +++ b/test/src/models/database_status_volume_test.dart @@ -0,0 +1,23 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DatabaseStatusVolume', () { + test('model', () { + final model = DatabaseStatusVolume( + path: '/var/lib/postgresql/data', + usedPercent: '45%', + available: '55GB', + mounted: true, + ); + + final map = model.toMap(); + final result = DatabaseStatusVolume.fromMap(map); + + expect(result.path, '/var/lib/postgresql/data'); + expect(result.usedPercent, '45%'); + expect(result.available, '55GB'); + expect(result.mounted, true); + }); + }); +} diff --git a/test/src/models/database_test.dart b/test/src/models/database_test.dart index fff6a7e2..e289b896 100644 --- a/test/src/models/database_test.dart +++ b/test/src/models/database_test.dart @@ -12,8 +12,6 @@ void main() { $updatedAt: '2020-10-15T06:38:00.000+00:00', enabled: true, type: DatabaseType.legacy, - policies: [], - archives: [], ); final map = model.toMap(); @@ -25,8 +23,6 @@ void main() { expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.enabled, true); expect(result.type, DatabaseType.legacy); - expect(result.policies, []); - expect(result.archives, []); }); }); } diff --git a/test/src/models/dedicated_database_member_test.dart b/test/src/models/dedicated_database_member_test.dart new file mode 100644 index 00000000..7c21b9ce --- /dev/null +++ b/test/src/models/dedicated_database_member_test.dart @@ -0,0 +1,23 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DedicatedDatabaseMember', () { + test('model', () { + final model = DedicatedDatabaseMember( + $id: '1', + role: 'replica', + status: 'active', + lagSeconds: 0.5, + ); + + final map = model.toMap(); + final result = DedicatedDatabaseMember.fromMap(map); + + expect(result.$id, '1'); + expect(result.role, 'replica'); + expect(result.status, 'active'); + expect(result.lagSeconds, 0.5); + }); + }); +} diff --git a/test/src/models/dedicated_database_replicas_test.dart b/test/src/models/dedicated_database_replicas_test.dart new file mode 100644 index 00000000..1ddb4afb --- /dev/null +++ b/test/src/models/dedicated_database_replicas_test.dart @@ -0,0 +1,21 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DedicatedDatabaseReplicas', () { + test('model', () { + final model = DedicatedDatabaseReplicas( + replicas: 2, + syncMode: 'async', + members: [], + ); + + final map = model.toMap(); + final result = DedicatedDatabaseReplicas.fromMap(map); + + expect(result.replicas, 2); + expect(result.syncMode, 'async'); + expect(result.members, []); + }); + }); +} diff --git a/test/src/models/dedicated_database_specification_list_test.dart b/test/src/models/dedicated_database_specification_list_test.dart new file mode 100644 index 00000000..016d1357 --- /dev/null +++ b/test/src/models/dedicated_database_specification_list_test.dart @@ -0,0 +1,26 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DedicatedDatabaseSpecificationList', () { + test('model', () { + final model = DedicatedDatabaseSpecificationList( + specifications: [], + total: 9, + pricing: DedicatedDatabaseSpecificationPricing( + storageOverageRate: 0.125, + bandwidthOverageRate: 0.08, + replicaRate: 1, + crossRegionReplicaRate: 1, + pitrRate: 0.2, + ), + ); + + final map = model.toMap(); + final result = DedicatedDatabaseSpecificationList.fromMap(map); + + expect(result.specifications, []); + expect(result.total, 9); + }); + }); +} diff --git a/test/src/models/dedicated_database_specification_pricing_test.dart b/test/src/models/dedicated_database_specification_pricing_test.dart new file mode 100644 index 00000000..fd90ffd9 --- /dev/null +++ b/test/src/models/dedicated_database_specification_pricing_test.dart @@ -0,0 +1,25 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DedicatedDatabaseSpecificationPricing', () { + test('model', () { + final model = DedicatedDatabaseSpecificationPricing( + storageOverageRate: 0.125, + bandwidthOverageRate: 0.08, + replicaRate: 1, + crossRegionReplicaRate: 1, + pitrRate: 0.2, + ); + + final map = model.toMap(); + final result = DedicatedDatabaseSpecificationPricing.fromMap(map); + + expect(result.storageOverageRate, 0.125); + expect(result.bandwidthOverageRate, 0.08); + expect(result.replicaRate, 1); + expect(result.crossRegionReplicaRate, 1); + expect(result.pitrRate, 0.2); + }); + }); +} diff --git a/test/src/models/dedicated_database_specification_test.dart b/test/src/models/dedicated_database_specification_test.dart new file mode 100644 index 00000000..1a3e8438 --- /dev/null +++ b/test/src/models/dedicated_database_specification_test.dart @@ -0,0 +1,33 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DedicatedDatabaseSpecification', () { + test('model', () { + final model = DedicatedDatabaseSpecification( + slug: 's-2vcpu-2gb', + name: 'Standard', + price: 20, + cpu: 2000, + memory: 2048, + maxConnections: 200, + includedStorage: 25, + includedBandwidth: 200, + enabled: true, + ); + + final map = model.toMap(); + final result = DedicatedDatabaseSpecification.fromMap(map); + + expect(result.slug, 's-2vcpu-2gb'); + expect(result.name, 'Standard'); + expect(result.price, 20); + expect(result.cpu, 2000); + expect(result.memory, 2048); + expect(result.maxConnections, 200); + expect(result.includedStorage, 25); + expect(result.includedBandwidth, 200); + expect(result.enabled, true); + }); + }); +} diff --git a/test/src/models/dedicated_database_test.dart b/test/src/models/dedicated_database_test.dart new file mode 100644 index 00000000..753bf7d5 --- /dev/null +++ b/test/src/models/dedicated_database_test.dart @@ -0,0 +1,111 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DedicatedDatabase', () { + test('model', () { + final model = DedicatedDatabase( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + projectId: '5e5ea5c16897e', + name: 'My Production Database', + api: 'postgresql', + engine: 'postgresql', + version: '16', + specification: 's-2vcpu-2gb', + backend: 'edge', + hostname: 'db-myproject-mydb.fra.appwrite.center', + connectionPort: 5432, + connectionUser: 'appwrite_user', + connectionPassword: '••••••••', + connectionString: + 'postgresql://user:pass@db-myproject-mydb.fra.appwrite.center:5432/postgres?sslmode=require', + ssl: true, + status: 'ready', + containerStatus: 'active', + lifecycleState: 'active', + idleTimeoutMinutes: 15, + cpu: 2000, + memory: 4096, + storage: 100, + storageClass: 'ssd', + storageMaxGb: 100, + nodePool: 'db-pool-4vcpu-8gb', + replicas: 2, + syncMode: 'async', + crossRegionReplicas: 1, + networkMaxConnections: 500, + networkIdleTimeoutSeconds: 900, + networkIPAllowlist: [], + backupEnabled: true, + pitr: true, + pitrRetentionDays: 14, + storageAutoscaling: true, + storageAutoscalingThresholdPercent: 85, + storageAutoscalingMaxGb: 500, + maintenanceWindowDay: 'sun', + maintenanceWindowHourUtc: 3, + metricsEnabled: true, + sqlApiEnabled: true, + sqlApiAllowedStatements: [], + sqlApiMaxRows: 10000, + sqlApiMaxBytes: 10485760, + sqlApiTimeoutSeconds: 30, + error: '', + ); + + final map = model.toMap(); + final result = DedicatedDatabase.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.projectId, '5e5ea5c16897e'); + expect(result.name, 'My Production Database'); + expect(result.api, 'postgresql'); + expect(result.engine, 'postgresql'); + expect(result.version, '16'); + expect(result.specification, 's-2vcpu-2gb'); + expect(result.backend, 'edge'); + expect(result.hostname, 'db-myproject-mydb.fra.appwrite.center'); + expect(result.connectionPort, 5432); + expect(result.connectionUser, 'appwrite_user'); + expect(result.connectionPassword, '••••••••'); + expect(result.connectionString, + 'postgresql://user:pass@db-myproject-mydb.fra.appwrite.center:5432/postgres?sslmode=require'); + expect(result.ssl, true); + expect(result.status, 'ready'); + expect(result.containerStatus, 'active'); + expect(result.lifecycleState, 'active'); + expect(result.idleTimeoutMinutes, 15); + expect(result.cpu, 2000); + expect(result.memory, 4096); + expect(result.storage, 100); + expect(result.storageClass, 'ssd'); + expect(result.storageMaxGb, 100); + expect(result.nodePool, 'db-pool-4vcpu-8gb'); + expect(result.replicas, 2); + expect(result.syncMode, 'async'); + expect(result.crossRegionReplicas, 1); + expect(result.networkMaxConnections, 500); + expect(result.networkIdleTimeoutSeconds, 900); + expect(result.networkIPAllowlist, []); + expect(result.backupEnabled, true); + expect(result.pitr, true); + expect(result.pitrRetentionDays, 14); + expect(result.storageAutoscaling, true); + expect(result.storageAutoscalingThresholdPercent, 85); + expect(result.storageAutoscalingMaxGb, 500); + expect(result.maintenanceWindowDay, 'sun'); + expect(result.maintenanceWindowHourUtc, 3); + expect(result.metricsEnabled, true); + expect(result.sqlApiEnabled, true); + expect(result.sqlApiAllowedStatements, []); + expect(result.sqlApiMaxRows, 10000); + expect(result.sqlApiMaxBytes, 10485760); + expect(result.sqlApiTimeoutSeconds, 30); + expect(result.error, ''); + }); + }); +} diff --git a/test/src/models/oauth2_approve_test.dart b/test/src/models/oauth2_approve_test.dart new file mode 100644 index 00000000..0c175e8a --- /dev/null +++ b/test/src/models/oauth2_approve_test.dart @@ -0,0 +1,18 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Approve', () { + test('model', () { + final model = Oauth2Approve( + redirectUrl: 'https://example.com/callback?code=abcde&state=fghij', + ); + + final map = model.toMap(); + final result = Oauth2Approve.fromMap(map); + + expect(result.redirectUrl, + 'https://example.com/callback?code=abcde&state=fghij'); + }); + }); +} diff --git a/test/src/models/oauth2_authorize_test.dart b/test/src/models/oauth2_authorize_test.dart new file mode 100644 index 00000000..9b51e23f --- /dev/null +++ b/test/src/models/oauth2_authorize_test.dart @@ -0,0 +1,20 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Authorize', () { + test('model', () { + final model = Oauth2Authorize( + grantId: '5e5ea5c16897e', + redirectUrl: 'https://example.com/callback?code=abcde&state=fghij', + ); + + final map = model.toMap(); + final result = Oauth2Authorize.fromMap(map); + + expect(result.grantId, '5e5ea5c16897e'); + expect(result.redirectUrl, + 'https://example.com/callback?code=abcde&state=fghij'); + }); + }); +} diff --git a/test/src/models/oauth2_consent_list_test.dart b/test/src/models/oauth2_consent_list_test.dart new file mode 100644 index 00000000..e687a47e --- /dev/null +++ b/test/src/models/oauth2_consent_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2ConsentList', () { + test('model', () { + final model = Oauth2ConsentList( + total: 5, + consents: [], + ); + + final map = model.toMap(); + final result = Oauth2ConsentList.fromMap(map); + + expect(result.total, 5); + expect(result.consents, []); + }); + }); +} diff --git a/test/src/models/oauth2_consent_test.dart b/test/src/models/oauth2_consent_test.dart new file mode 100644 index 00000000..14ca61be --- /dev/null +++ b/test/src/models/oauth2_consent_test.dart @@ -0,0 +1,38 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Consent', () { + test('model', () { + final model = Oauth2Consent( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + userId: '5e5ea5c16897e', + appId: '5e5ea5c16897e', + cimdUrl: 'https://example.com/.well-known/client-metadata.json', + scopes: [], + resources: [], + authorizationDetails: + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + expire: '2020-10-15T06:38:00.000+00:00', + ); + + final map = model.toMap(); + final result = Oauth2Consent.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.cimdUrl, + 'https://example.com/.well-known/client-metadata.json'); + expect(result.scopes, []); + expect(result.resources, []); + expect(result.authorizationDetails, + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + }); + }); +} diff --git a/test/src/models/oauth2_consent_token_list_test.dart b/test/src/models/oauth2_consent_token_list_test.dart new file mode 100644 index 00000000..85880621 --- /dev/null +++ b/test/src/models/oauth2_consent_token_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2ConsentTokenList', () { + test('model', () { + final model = Oauth2ConsentTokenList( + total: 5, + tokens: [], + ); + + final map = model.toMap(); + final result = Oauth2ConsentTokenList.fromMap(map); + + expect(result.total, 5); + expect(result.tokens, []); + }); + }); +} diff --git a/test/src/models/oauth2_consent_token_test.dart b/test/src/models/oauth2_consent_token_test.dart new file mode 100644 index 00000000..b18a44e9 --- /dev/null +++ b/test/src/models/oauth2_consent_token_test.dart @@ -0,0 +1,40 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2ConsentToken', () { + test('model', () { + final model = Oauth2ConsentToken( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + consentId: '5e5ea5c16897e', + userId: '5e5ea5c16897e', + appId: '5e5ea5c16897e', + cimdUrl: 'https://example.com/.well-known/client-metadata.json', + scopes: [], + resources: [], + authorizationDetails: + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + expire: '2020-10-15T06:38:00.000+00:00', + ); + + final map = model.toMap(); + final result = Oauth2ConsentToken.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.consentId, '5e5ea5c16897e'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.cimdUrl, + 'https://example.com/.well-known/client-metadata.json'); + expect(result.scopes, []); + expect(result.resources, []); + expect(result.authorizationDetails, + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + }); + }); +} diff --git a/test/src/models/oauth2_device_authorization_test.dart b/test/src/models/oauth2_device_authorization_test.dart new file mode 100644 index 00000000..0f764e78 --- /dev/null +++ b/test/src/models/oauth2_device_authorization_test.dart @@ -0,0 +1,32 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2DeviceAuthorization', () { + test('model', () { + final model = Oauth2DeviceAuthorization( + device_code: + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a', + user_code: 'ABCD-EFGH', + verification_uri: 'https://cloud.appwrite.io/console/oauth2/device', + verification_uri_complete: + 'https://cloud.appwrite.io/console/oauth2/device?user_code=ABCD-EFGH', + expires_in: 900, + interval: 5, + ); + + final map = model.toMap(); + final result = Oauth2DeviceAuthorization.fromMap(map); + + expect(result.device_code, + '5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a'); + expect(result.user_code, 'ABCD-EFGH'); + expect(result.verification_uri, + 'https://cloud.appwrite.io/console/oauth2/device'); + expect(result.verification_uri_complete, + 'https://cloud.appwrite.io/console/oauth2/device?user_code=ABCD-EFGH'); + expect(result.expires_in, 900); + expect(result.interval, 5); + }); + }); +} diff --git a/test/src/models/oauth2_grant_test.dart b/test/src/models/oauth2_grant_test.dart new file mode 100644 index 00000000..d7b8ddec --- /dev/null +++ b/test/src/models/oauth2_grant_test.dart @@ -0,0 +1,41 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Grant', () { + test('model', () { + final model = Oauth2Grant( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + userId: '5e5ea5c16897e', + appId: '5e5ea5c16897e', + scopes: [], + resources: [], + authorizationDetails: + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]', + prompt: 'login', + redirectUri: 'https://example.com/callback', + authTime: 1592981250, + expire: '2020-10-15T06:38:00.000+00:00', + ); + + final map = model.toMap(); + final result = Oauth2Grant.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.appId, '5e5ea5c16897e'); + expect(result.scopes, []); + expect(result.resources, []); + expect(result.authorizationDetails, + '[{\"type\":\"calendar\",\"identifier\":\"primary\",\"actions\":[\"read_events\",\"create_event\"]}]'); + expect(result.prompt, 'login'); + expect(result.redirectUri, 'https://example.com/callback'); + expect(result.authTime, 1592981250); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + }); + }); +} diff --git a/test/src/models/oauth2_organization_list_test.dart b/test/src/models/oauth2_organization_list_test.dart new file mode 100644 index 00000000..2ed351ed --- /dev/null +++ b/test/src/models/oauth2_organization_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2OrganizationList', () { + test('model', () { + final model = Oauth2OrganizationList( + total: 5, + organizations: [], + ); + + final map = model.toMap(); + final result = Oauth2OrganizationList.fromMap(map); + + expect(result.total, 5); + expect(result.organizations, []); + }); + }); +} diff --git a/test/src/models/oauth2_organization_test.dart b/test/src/models/oauth2_organization_test.dart new file mode 100644 index 00000000..d6e89f27 --- /dev/null +++ b/test/src/models/oauth2_organization_test.dart @@ -0,0 +1,17 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Organization', () { + test('model', () { + final model = Oauth2Organization( + $id: '5e5ea5c16897e', + ); + + final map = model.toMap(); + final result = Oauth2Organization.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + }); + }); +} diff --git a/test/src/models/oauth2_par_test.dart b/test/src/models/oauth2_par_test.dart new file mode 100644 index 00000000..a284b080 --- /dev/null +++ b/test/src/models/oauth2_par_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2PAR', () { + test('model', () { + final model = Oauth2PAR( + request_uri: 'urn:appwrite:oauth2:request:5e5ea5c16897e', + expires_in: 600, + ); + + final map = model.toMap(); + final result = Oauth2PAR.fromMap(map); + + expect(result.request_uri, 'urn:appwrite:oauth2:request:5e5ea5c16897e'); + expect(result.expires_in, 600); + }); + }); +} diff --git a/test/src/models/oauth2_project_list_test.dart b/test/src/models/oauth2_project_list_test.dart new file mode 100644 index 00000000..2fc0899e --- /dev/null +++ b/test/src/models/oauth2_project_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2ProjectList', () { + test('model', () { + final model = Oauth2ProjectList( + total: 5, + projects: [], + ); + + final map = model.toMap(); + final result = Oauth2ProjectList.fromMap(map); + + expect(result.total, 5); + expect(result.projects, []); + }); + }); +} diff --git a/test/src/models/oauth2_project_test.dart b/test/src/models/oauth2_project_test.dart new file mode 100644 index 00000000..8c903f76 --- /dev/null +++ b/test/src/models/oauth2_project_test.dart @@ -0,0 +1,21 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Project', () { + test('model', () { + final model = Oauth2Project( + $id: '5e5ea5c16897e', + region: 'fra', + endpoint: 'https://fra.cloud.appwrite.io/v1', + ); + + final map = model.toMap(); + final result = Oauth2Project.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.region, 'fra'); + expect(result.endpoint, 'https://fra.cloud.appwrite.io/v1'); + }); + }); +} diff --git a/test/src/models/oauth2_reject_test.dart b/test/src/models/oauth2_reject_test.dart new file mode 100644 index 00000000..9c449ca4 --- /dev/null +++ b/test/src/models/oauth2_reject_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Reject', () { + test('model', () { + final model = Oauth2Reject( + redirectUrl: + 'https://example.com/callback?error=access_denied&state=fghij', + ); + + final map = model.toMap(); + final result = Oauth2Reject.fromMap(map); + + expect(result.redirectUrl, + 'https://example.com/callback?error=access_denied&state=fghij'); + }); + }); +} diff --git a/test/src/models/oauth2_token_test.dart b/test/src/models/oauth2_token_test.dart new file mode 100644 index 00000000..41fe93ca --- /dev/null +++ b/test/src/models/oauth2_token_test.dart @@ -0,0 +1,25 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Oauth2Token', () { + test('model', () { + final model = Oauth2Token( + access_token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...', + token_type: 'Bearer', + expires_in: 3600, + refresh_token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...', + scope: 'openid email profile', + ); + + final map = model.toMap(); + final result = Oauth2Token.fromMap(map); + + expect(result.access_token, 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...'); + expect(result.token_type, 'Bearer'); + expect(result.expires_in, 3600); + expect(result.refresh_token, 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...'); + expect(result.scope, 'openid email profile'); + }); + }); +} diff --git a/test/src/models/organization_test.dart b/test/src/models/organization_test.dart index 817472ff..56586ead 100644 --- a/test/src/models/organization_test.dart +++ b/test/src/models/organization_test.dart @@ -29,6 +29,7 @@ void main() { screenshotsGenerated: 50, members: 25, webhooks: 25, + wafRules: 2, projects: 2, platforms: 3, users: 25, diff --git a/test/src/models/project_test.dart b/test/src/models/project_test.dart index a3b0f361..8a3b265e 100644 --- a/test/src/models/project_test.dart +++ b/test/src/models/project_test.dart @@ -33,6 +33,7 @@ void main() { protocols: [], blocks: [], consoleAccessedAt: '2020-10-15T06:38:00.000+00:00', + wafEnabled: true, ); final map = model.toMap(); @@ -65,6 +66,7 @@ void main() { expect(result.protocols, []); expect(result.blocks, []); expect(result.consoleAccessedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.wafEnabled, true); }); }); }