diff --git a/.travis.yml b/.travis.yml index 1b299c31..0e2d2150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,6 @@ install: deploy: provider: script skip_cleanup: true - script: cd $TRAVIS_BUILD_DIR && dart format ./lib/ && flutter pub publish -f + script: cd $TRAVIS_BUILD_DIR && dart format ./lib/ && dart format ./test/ && flutter pub publish -f on: tags: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a8a4bbc..ac08f820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 12.0.0 + +* Added enum support +* Added SSR support +* Added messaging service support +* Added contains query support +* Added or query support + ## 11.0.1 * Fix between queries diff --git a/LICENSE b/LICENSE index 47cfdfb1..5479bb8e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2023 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 1465cce5..a367b2ef 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ [![pub package](https://img.shields.io/pub/v/appwrite?style=flat-square)](https://pub.dartlang.org/packages/appwrite) ![License](https://img.shields.io/github/license/appwrite/sdk-for-flutter.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.4.x-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.5.x-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.4.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).** +**This SDK is compatible with Appwrite server version 1.5.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) -![Appwrite](https://appwrite.io/images/github.png) +![Appwrite](https://github.com/appwrite/appwrite/raw/main/public/images/github.png) ## Installation @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^11.0.1 + appwrite: ^12.0.0 ``` You can install packages from the command line: @@ -138,10 +138,7 @@ When trying to connect to Appwrite from an emulator or a mobile device, localhos Account account = Account(client); final user = await account .create( - userId: ID.unique(), - email: 'me@appwrite.io', - password: 'password', - name: 'My Name' + userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien" ); ``` @@ -166,10 +163,7 @@ void main() { final user = await account .create( - userId: ID.unique(), - email: 'me@appwrite.io', - password: 'password', - name: 'My Name' + userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien" ); } ``` @@ -181,7 +175,7 @@ The Appwrite Flutter SDK raises `AppwriteException` object with `message`, `type Account account = Account(client); try { - final user = await account.create(userId: ID.unique(), email: ‘email@example.com’,password: ‘password’, name: ‘name’); + final user = await account.create(userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien"); print(user.toMap()); } on AppwriteException catch(e) { //show message to user or do other operation based on error as required diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index 2f3e7a60..8eea4bf4 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createAnonymousSession(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Session result = await account.createAnonymousSession(); diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md new file mode 100644 index 00000000..d90d9e26 --- /dev/null +++ b/docs/examples/account/create-email-password-session.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Session result = await account.createEmailPasswordSession( + email: 'email@example.com', + password: 'password', +); diff --git a/docs/examples/account/create-email-session.md b/docs/examples/account/create-email-session.md deleted file mode 100644 index 52b6b91f..00000000 --- a/docs/examples/account/create-email-session.md +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:appwrite/appwrite.dart'; - -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createEmailSession( - email: 'email@example.com', - password: 'password', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md new file mode 100644 index 00000000..2532d82d --- /dev/null +++ b/docs/examples/account/create-email-token.md @@ -0,0 +1,13 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Token result = await account.createEmailToken( + userId: '', + email: 'email@example.com', + phrase: false, // optional +); diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-j-w-t.md index c4a61f7c..1e33c888 100644 --- a/docs/examples/account/create-j-w-t.md +++ b/docs/examples/account/create-j-w-t.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createJWT(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Jwt result = await account.createJWT(); diff --git a/docs/examples/account/create-magic-u-r-l-session.md b/docs/examples/account/create-magic-u-r-l-session.md deleted file mode 100644 index d1b89bf1..00000000 --- a/docs/examples/account/create-magic-u-r-l-session.md +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:appwrite/appwrite.dart'; - -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createMagicURLSession( - userId: '[USER_ID]', - email: 'email@example.com', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-u-r-l-token.md new file mode 100644 index 00000000..8c430c86 --- /dev/null +++ b/docs/examples/account/create-magic-u-r-l-token.md @@ -0,0 +1,14 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Token result = await account.createMagicURLToken( + userId: '', + email: 'email@example.com', + url: 'https://example.com', // optional + phrase: false, // optional +); diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md new file mode 100644 index 00000000..b43ec1a6 --- /dev/null +++ b/docs/examples/account/create-mfa-authenticator.md @@ -0,0 +1,11 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +MfaType result = await account.createMfaAuthenticator( + type: AuthenticatorType.totp, +); diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md new file mode 100644 index 00000000..64bcb367 --- /dev/null +++ b/docs/examples/account/create-mfa-challenge.md @@ -0,0 +1,11 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +MfaChallenge result = await account.createMfaChallenge( + factor: AuthenticationFactor.email, +); diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md new file mode 100644 index 00000000..68fdaaa4 --- /dev/null +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -0,0 +1,9 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +MfaRecoveryCodes result = await account.createMfaRecoveryCodes(); diff --git a/docs/examples/account/create-o-auth2session.md b/docs/examples/account/create-o-auth2session.md index e985a92a..ea651e73 100644 --- a/docs/examples/account/create-o-auth2session.md +++ b/docs/examples/account/create-o-auth2session.md @@ -1,21 +1,14 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createOAuth2Session( - provider: 'amazon', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await account.createOAuth2Session( + provider: OAuthProvider.amazon, + success: 'https://example.com', // optional + failure: 'https://example.com', // optional + scopes: [], // optional +); diff --git a/docs/examples/account/create-o-auth2token.md b/docs/examples/account/create-o-auth2token.md new file mode 100644 index 00000000..4227359c --- /dev/null +++ b/docs/examples/account/create-o-auth2token.md @@ -0,0 +1,14 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +await account.createOAuth2Token( + provider: OAuthProvider.amazon, + success: 'https://example.com', // optional + failure: 'https://example.com', // optional + scopes: [], // optional +); diff --git a/docs/examples/account/create-phone-session.md b/docs/examples/account/create-phone-session.md deleted file mode 100644 index fcb705c9..00000000 --- a/docs/examples/account/create-phone-session.md +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:appwrite/appwrite.dart'; - -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createPhoneSession( - userId: '[USER_ID]', - phone: '+12065550100', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md new file mode 100644 index 00000000..efcdcbe8 --- /dev/null +++ b/docs/examples/account/create-phone-token.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Token result = await account.createPhoneToken( + userId: '', + phone: '+12065550100', +); diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index 76e724d8..ad0da61d 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createPhoneVerification(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Token result = await account.createPhoneVerification(); diff --git a/docs/examples/account/create-push-target.md b/docs/examples/account/create-push-target.md new file mode 100644 index 00000000..be945eec --- /dev/null +++ b/docs/examples/account/create-push-target.md @@ -0,0 +1,13 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Target result = await account.createPushTarget( + targetId: '', + identifier: '', + providerId: '', // optional +); diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index 361a9f04..8b8a41a8 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createRecovery( + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Token result = await account.createRecovery( email: 'email@example.com', url: 'https://example.com', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +); diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md new file mode 100644 index 00000000..29aca9c5 --- /dev/null +++ b/docs/examples/account/create-session.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Session result = await account.createSession( + userId: '', + secret: '', +); diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index d66c3b1a..c3a4f0f7 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.createVerification( - url: 'https://example.com', - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Account account = Account(client); + +Token result = await account.createVerification( + url: 'https://example.com', +); diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index 1ff2ae91..032c523e 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -1,23 +1,14 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.create( - userId: '[USER_ID]', + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +User result = await account.create( + userId: '', email: 'email@example.com', password: '', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} + name: '', // optional +); diff --git a/docs/examples/account/delete-identity.md b/docs/examples/account/delete-identity.md index c5ea2b39..ab68036a 100644 --- a/docs/examples/account/delete-identity.md +++ b/docs/examples/account/delete-identity.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.deleteIdentity( - identityId: '[IDENTITY_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await account.deleteIdentity( + identityId: '', +); diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md new file mode 100644 index 00000000..3f62177e --- /dev/null +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +await account.deleteMfaAuthenticator( + type: AuthenticatorType.totp, + otp: '', +); diff --git a/docs/examples/account/delete-push-target.md b/docs/examples/account/delete-push-target.md new file mode 100644 index 00000000..2081bf67 --- /dev/null +++ b/docs/examples/account/delete-push-target.md @@ -0,0 +1,11 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +await account.deletePushTarget( + targetId: '', +); diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index 91465610..7f84f82a 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.deleteSession( - sessionId: '[SESSION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await account.deleteSession( + sessionId: '', +); diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index 4963de44..c17afd0d 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.deleteSessions(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await account.deleteSessions(); diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md new file mode 100644 index 00000000..008f8ced --- /dev/null +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -0,0 +1,9 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +MfaRecoveryCodes result = await account.getMfaRecoveryCodes(); diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index 81eb802d..6b378996 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.getPrefs(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Preferences result = await account.getPrefs(); diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index 9e0f66ca..6954e51e 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.getSession( - sessionId: '[SESSION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Session result = await account.getSession( + sessionId: '', +); diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index 21192de2..2790b57a 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.get(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +User result = await account.get(); diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index 2f2eed0d..763e2533 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -1,20 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.listIdentities( - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +IdentityList result = await account.listIdentities( + queries: [], // optional +); diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index 9f7088a0..d3b06dd9 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -1,20 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.listLogs( - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +LogList result = await account.listLogs( + queries: [], // optional +); diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md new file mode 100644 index 00000000..08186e3e --- /dev/null +++ b/docs/examples/account/list-mfa-factors.md @@ -0,0 +1,9 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +MfaFactors result = await account.listMfaFactors(); diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index 6f2d5dc1..0bde760d 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.listSessions(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +SessionList result = await account.listSessions(); diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 1fb9a3fe..0ce8eb5e 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateEmail( + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +User result = await account.updateEmail( email: 'email@example.com', password: 'password', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +); diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-m-f-a.md new file mode 100644 index 00000000..1f5f709b --- /dev/null +++ b/docs/examples/account/update-m-f-a.md @@ -0,0 +1,11 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +User result = await account.updateMFA( + mfa: false, +); diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-u-r-l-session.md index 3c7ef8f0..2eb4b33d 100644 --- a/docs/examples/account/update-magic-u-r-l-session.md +++ b/docs/examples/account/update-magic-u-r-l-session.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateMagicURLSession( - userId: '[USER_ID]', - secret: '[SECRET]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Session result = await account.updateMagicURLSession( + userId: '', + secret: '', +); diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md new file mode 100644 index 00000000..4f5074e2 --- /dev/null +++ b/docs/examples/account/update-mfa-authenticator.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +User result = await account.updateMfaAuthenticator( + type: AuthenticatorType.totp, + otp: '', +); diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md new file mode 100644 index 00000000..34c37801 --- /dev/null +++ b/docs/examples/account/update-mfa-challenge.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + + result = await account.updateMfaChallenge( + challengeId: '', + otp: '', +); diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md new file mode 100644 index 00000000..914366fb --- /dev/null +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -0,0 +1,9 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +MfaRecoveryCodes result = await account.updateMfaRecoveryCodes(); diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index ae5d6235..dc2c4c6a 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateName( - name: '[NAME]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +User result = await account.updateName( + name: '', +); diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index b5e86de2..37c6ecf4 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -1,21 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updatePassword( - password: '', - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Account account = Account(client); + +User result = await account.updatePassword( + password: '', + oldPassword: 'password', // optional +); diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index 1f979265..f6871317 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updatePhoneSession( - userId: '[USER_ID]', - secret: '[SECRET]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Session result = await account.updatePhoneSession( + userId: '', + secret: '', +); diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index 86d9b0fd..0facc29f 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updatePhoneVerification( - userId: '[USER_ID]', - secret: '[SECRET]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Token result = await account.updatePhoneVerification( + userId: '', + secret: '', +); diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index edfe4785..24000c4b 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updatePhone( + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +User result = await account.updatePhone( phone: '+12065550100', password: 'password', - ); - - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +); diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index 97697081..d83e25f9 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updatePrefs( - prefs: {}, - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Account account = Account(client); + +User result = await account.updatePrefs( + prefs: {}, +); diff --git a/docs/examples/account/update-push-target.md b/docs/examples/account/update-push-target.md new file mode 100644 index 00000000..0311d0be --- /dev/null +++ b/docs/examples/account/update-push-target.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); + +Target result = await account.updatePushTarget( + targetId: '', + identifier: '', +); diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index f499b187..f87e8723 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -1,24 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateRecovery( - userId: '[USER_ID]', - secret: '[SECRET]', - password: 'password', - passwordAgain: 'password', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Token result = await account.updateRecovery( + userId: '', + secret: '', + password: '', +); diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index fb1afcc5..5a12ad27 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateSession( - sessionId: '[SESSION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Session result = await account.updateSession( + sessionId: '', +); diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index 8e734647..8b7bc49c 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateStatus(); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +User result = await account.updateStatus(); diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index fba8ed65..c3db86b8 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Account account = Account(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = account.updateVerification( - userId: '[USER_ID]', - secret: '[SECRET]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Account account = Account(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Token result = await account.updateVerification( + userId: '', + secret: '', +); diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index 70af5665..6bc6e541 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -1,34 +1,33 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getBrowser( - code: 'aa', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getBrowser( + code: Browser.avantBrowser, + width: 0, // optional + height: 0, // optional + quality: 0, // optional +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: avatars.getBrowser( - code: 'aa', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getBrowser( + code: Browser.avantBrowser, + width:0 , // optional + height:0 , // optional + quality:0 , // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index 6a29dc81..d5b96383 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -1,34 +1,33 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getCreditCard( - code: 'amex', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getCreditCard( + code: CreditCard.americanExpress, + width: 0, // optional + height: 0, // optional + quality: 0, // optional +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: avatars.getCreditCard( - code: 'amex', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getCreditCard( + code: CreditCard.americanExpress, + width:0 , // optional + height:0 , // optional + quality:0 , // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index 2da0f2e0..10047b44 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -1,34 +1,27 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getFavicon( + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getFavicon( url: 'https://example.com', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} +) -//displaying image preview +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); + +// Displaying image preview FutureBuilder( - future: avatars.getFavicon( - url: 'https://example.com', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getFavicon( + url:'https://example.com' , +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index 13367885..66a5b202 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -1,34 +1,33 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getFlag( - code: 'af', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getFlag( + code: Flag.afghanistan, + width: 0, // optional + height: 0, // optional + quality: 0, // optional +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: avatars.getFlag( - code: 'af', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getFlag( + code: Flag.afghanistan, + width:0 , // optional + height:0 , // optional + quality:0 , // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index debbf1e2..15f3ea6e 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -1,34 +1,31 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getImage( + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getImage( url: 'https://example.com', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + width: 0, // optional + height: 0, // optional +) -//displaying image preview +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); + +// Displaying image preview FutureBuilder( - future: avatars.getImage( - url: 'https://example.com', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getImage( + url:'https://example.com' , + width:0 , // optional + height:0 , // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index b0f49c62..2d540a1d 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -1,32 +1,33 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getInitials( - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getInitials( + name: '', // optional + width: 0, // optional + height: 0, // optional + background: '', // optional +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: avatars.getInitials( - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getInitials( + name:'' , // optional + width:0 , // optional + height:0 , // optional + background:'' , // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md index 8df72937..94b34bda 100644 --- a/docs/examples/avatars/get-q-r.md +++ b/docs/examples/avatars/get-q-r.md @@ -1,34 +1,33 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Avatars avatars = Avatars(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = avatars.getQR( - text: '[TEXT]', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Avatars avatars = Avatars(client); + +// Downloading file +UInt8List bytes = await avatars.getQR( + text: '', + size: 1, // optional + margin: 0, // optional + download: false, // optional +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: avatars.getQR( - text: '[TEXT]', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: avatars.getQR( + text:'' , + size:1 , // optional + margin:0 , // optional + download:false , // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 6a031738..6645b4ed 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -1,24 +1,15 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Databases databases = Databases(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = databases.createDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', - data: {}, - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Databases databases = Databases(client); + +Document result = await databases.createDocument( + databaseId: '', + collectionId: '', + documentId: '', + data: {}, + permissions: ["read("any")"], // optional +); diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index a377b027..fc7c5ef1 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -1,23 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Databases databases = Databases(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = databases.deleteDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Databases databases = Databases(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await databases.deleteDocument( + databaseId: '', + collectionId: '', + documentId: '', +); diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index b2cf89a3..4f2ba3e3 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -1,23 +1,14 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Databases databases = Databases(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = databases.getDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Databases databases = Databases(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Document result = await databases.getDocument( + databaseId: '', + collectionId: '', + documentId: '', + queries: [], // optional +); diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 4cd69e30..da43b17d 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -1,22 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Databases databases = Databases(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = databases.listDocuments( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Databases databases = Databases(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +DocumentList result = await databases.listDocuments( + databaseId: '', + collectionId: '', + queries: [], // optional +); diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 595099bc..42f5b657 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -1,23 +1,15 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Databases databases = Databases(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = databases.updateDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Databases databases = Databases(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Document result = await databases.updateDocument( + databaseId: '', + collectionId: '', + documentId: '', + data: {}, // optional + permissions: ["read("any")"], // optional +); diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index b188c32f..6ca5e14b 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -1,21 +1,16 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Functions functions = Functions(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = functions.createExecution( - functionId: '[FUNCTION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Functions functions = Functions(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Execution result = await functions.createExecution( + functionId: '', + body: '', // optional + xasync: false, // optional + path: '', // optional + method: ExecutionMethod.gET, // optional + headers: {}, // optional +); diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index f30b4b44..67439f40 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Functions functions = Functions(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = functions.getExecution( - functionId: '[FUNCTION_ID]', - executionId: '[EXECUTION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Functions functions = Functions(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Execution result = await functions.getExecution( + functionId: '', + executionId: '', +); diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index 1840f50d..3902d6e7 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -1,21 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Functions functions = Functions(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = functions.listExecutions( - functionId: '[FUNCTION_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Functions functions = Functions(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +ExecutionList result = await functions.listExecutions( + functionId: '', + queries: [], // optional + search: '', // optional +); diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index c0bffce7..d94c5315 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Graphql graphql = Graphql(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = graphql.mutation( - query: {}, - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Graphql graphql = Graphql(client); + +Any result = await graphql.mutation( + query: {}, +); diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index 455cb0bd..13c21eeb 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Graphql graphql = Graphql(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = graphql.query( - query: {}, - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Graphql graphql = Graphql(client); + +Any result = await graphql.query( + query: {}, +); diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index 9e9fa96b..b705b834 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.get(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Locale result = await locale.get(); diff --git a/docs/examples/locale/list-codes.md b/docs/examples/locale/list-codes.md index d11cb7bd..c9ca3297 100644 --- a/docs/examples/locale/list-codes.md +++ b/docs/examples/locale/list-codes.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listCodes(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +LocaleCodeList result = await locale.listCodes(); diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index 0ab2a4ab..b174e606 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listContinents(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +ContinentList result = await locale.listContinents(); diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-e-u.md index caa32e85..e3772f0f 100644 --- a/docs/examples/locale/list-countries-e-u.md +++ b/docs/examples/locale/list-countries-e-u.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listCountriesEU(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +CountryList result = await locale.listCountriesEU(); diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index b122eee7..9e0ed748 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listCountriesPhones(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +PhoneList result = await locale.listCountriesPhones(); diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index e6a367dd..12c57042 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listCountries(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +CountryList result = await locale.listCountries(); diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index fcd1e825..0d6662ee 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listCurrencies(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +CurrencyList result = await locale.listCurrencies(); diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index 1fb68aa8..b2f22a16 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -1,19 +1,9 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Locale locale = Locale(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = locale.listLanguages(); + .setProject('5df5acd0d48c2'); // Your project ID + +Locale locale = Locale(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +LanguageList result = await locale.listLanguages(); diff --git a/docs/examples/messaging/create-subscriber.md b/docs/examples/messaging/create-subscriber.md new file mode 100644 index 00000000..fc3b2596 --- /dev/null +++ b/docs/examples/messaging/create-subscriber.md @@ -0,0 +1,13 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Messaging messaging = Messaging(client); + +Subscriber result = await messaging.createSubscriber( + topicId: '', + subscriberId: '', + targetId: '', +); diff --git a/docs/examples/messaging/delete-subscriber.md b/docs/examples/messaging/delete-subscriber.md new file mode 100644 index 00000000..5cd62597 --- /dev/null +++ b/docs/examples/messaging/delete-subscriber.md @@ -0,0 +1,12 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +Messaging messaging = Messaging(client); + +await messaging.deleteSubscriber( + topicId: '', + subscriberId: '', +); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 0f5e44f5..55216ba3 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -1,24 +1,15 @@ import 'dart:io'; import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = storage.createFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Storage storage = Storage(client); + +File result = await storage.createFile( + bucketId: '', + fileId: '', + file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), + permissions: ["read("any")"], // optional +); diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index 230b73a9..bab2a477 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = storage.deleteFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await storage.deleteFile( + bucketId: '', + fileId: '', +); diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index 883b7d69..1a612be0 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -1,36 +1,29 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = storage.getFileDownload( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); + +// Downloading file +UInt8List bytes = await storage.getFileDownload( + bucketId: '', + fileId: '', +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: storage.getFileDownload( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: storage.getFileDownload( + bucketId:'' , + fileId:'' , +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index f42138bd..2649bb2c 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -1,36 +1,51 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = storage.getFilePreview( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); + +// Downloading file +UInt8List bytes = await storage.getFilePreview( + bucketId: '', + fileId: '', + width: 0, // optional + height: 0, // optional + gravity: ImageGravity.center, // optional + quality: 0, // optional + borderWidth: 0, // optional + borderColor: '', // optional + borderRadius: 0, // optional + opacity: 0, // optional + rotation: -360, // optional + background: '', // optional + output: ImageFormat.jpg, // optional +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: storage.getFilePreview( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: storage.getFilePreview( + bucketId:'' , + fileId:'' , + width:0 , // optional + height:0 , // optional + gravity: ImageGravity.center, // optional + quality:0 , // optional + borderWidth:0 , // optional + borderColor:'' , // optional + borderRadius:0 , // optional + opacity:0 , // optional + rotation:-360 , // optional + background:'' , // optional + output: ImageFormat.jpg, // optional +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index 4f7c4d96..5d0e38e8 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -1,36 +1,29 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - // downloading file - Future result = storage.getFileView( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ).then((bytes) { - final file = File('path_to_file/filename.ext'); - file.writeAsBytesSync(bytes) - }).catchError((error) { - print(error.response); - }) -} + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); + +// Downloading file +UInt8List bytes = await storage.getFileView( + bucketId: '', + fileId: '', +) + +final file = File('path_to_file/filename.ext'); +file.writeAsBytesSync(bytes); -//displaying image preview +// Displaying image preview FutureBuilder( - future: storage.getFileView( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ), //works for both public file and private file, for private files you need to be logged in - builder: (context, snapshot) { - return snapshot.hasData && snapshot.data != null - ? Image.memory( - snapshot.data, - ) - : CircularProgressIndicator(); - }, + future: storage.getFileView( + bucketId:'' , + fileId:'' , +), // Works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory(snapshot.data) + : CircularProgressIndicator(); + } ); diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index 681aca41..b7b894b4 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = storage.getFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +File result = await storage.getFile( + bucketId: '', + fileId: '', +); diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index e574f7bd..f75ef6e3 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -1,21 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = storage.listFiles( - bucketId: '[BUCKET_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +FileList result = await storage.listFiles( + bucketId: '', + queries: [], // optional + search: '', // optional +); diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 1170f05c..cca06533 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -1,22 +1,14 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Storage storage = Storage(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = storage.updateFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Storage storage = Storage(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +File result = await storage.updateFile( + bucketId: '', + fileId: '', + name: '', // optional + permissions: ["read("any")"], // optional +); diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 99446268..1cf04267 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -1,22 +1,17 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.createMembership( - teamId: '[TEAM_ID]', - roles: [], - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Teams teams = Teams(client); + +Membership result = await teams.createMembership( + teamId: '', + roles: [], + email: 'email@example.com', // optional + userId: '', // optional + phone: '+12065550100', // optional + url: 'https://example.com', // optional + name: '', // optional +); diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index bd62ce32..04593d46 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -1,22 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.create( - teamId: '[TEAM_ID]', - name: '[NAME]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Team result = await teams.create( + teamId: '', + name: '', + roles: [], // optional +); diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 0febe421..38f47c79 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.deleteMembership( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await teams.deleteMembership( + teamId: '', + membershipId: '', +); diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index b45d971b..4107155b 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.delete( - teamId: '[TEAM_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +await teams.delete( + teamId: '', +); diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index 28d95a20..10fd9594 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.getMembership( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Membership result = await teams.getMembership( + teamId: '', + membershipId: '', +); diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index e9ae94eb..b8f36922 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.getPrefs( - teamId: '[TEAM_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Preferences result = await teams.getPrefs( + teamId: '', +); diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index 0ec7027f..12ed636c 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -1,21 +1,11 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.get( - teamId: '[TEAM_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Team result = await teams.get( + teamId: '', +); diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index cbbc525d..ca98b5f1 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -1,21 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.listMemberships( - teamId: '[TEAM_ID]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +MembershipList result = await teams.listMemberships( + teamId: '', + queries: [], // optional + search: '', // optional +); diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index 80aa3016..25aaafa4 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -1,20 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.list( - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +TeamList result = await teams.list( + queries: [], // optional + search: '', // optional +); diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index ed31f54b..ae05c371 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -1,24 +1,14 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.updateMembershipStatus( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', - userId: '[USER_ID]', - secret: '[SECRET]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Membership result = await teams.updateMembershipStatus( + teamId: '', + membershipId: '', + userId: '', + secret: '', +); diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md index 669568bd..41f2a9be 100644 --- a/docs/examples/teams/update-membership.md +++ b/docs/examples/teams/update-membership.md @@ -1,23 +1,13 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.updateMembership( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', - roles: [], - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Teams teams = Teams(client); + +Membership result = await teams.updateMembership( + teamId: '', + membershipId: '', + roles: [], +); diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index 5c794bd9..2b3b288d 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.updateName( - teamId: '[TEAM_ID]', - name: '[NAME]', - ); + .setProject('5df5acd0d48c2'); // Your project ID + +Teams teams = Teams(client); - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Team result = await teams.updateName( + teamId: '', + name: '', +); diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index c29cbb9e..8afb99ad 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -1,22 +1,12 @@ import 'package:appwrite/appwrite.dart'; -void main() { // Init SDK - Client client = Client(); - Teams teams = Teams(client); - - client +Client client = Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2') // Your project ID - ; - Future result = teams.updatePrefs( - teamId: '[TEAM_ID]', - prefs: {}, - ); + .setProject('5df5acd0d48c2'); // Your project ID - result - .then((response) { - print(response); - }).catchError((error) { - print(error.response); - }); -} +Teams teams = Teams(client); + +Preferences result = await teams.updatePrefs( + teamId: '', + prefs: {}, +); diff --git a/example/README.md b/example/README.md index 23b63190..d0cb0c2b 100644 --- a/example/README.md +++ b/example/README.md @@ -17,7 +17,7 @@ Create a new user and session: ```dart Account account = Account(client); -final user = await account.create(userId: '[USER_ID]', email: 'me@appwrite.io', password: 'password', name: 'My Name'); +final user = await account.create(userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien"); final session = await account.createEmailSession(email: 'me@appwrite.io', password: 'password'); @@ -60,4 +60,4 @@ storage.createFile( }); ``` -All examples and API features are available at the [official Appwrite docs](https://appwrite.io/docs) \ No newline at end of file +All examples and API features are available at the [official Appwrite docs](https://appwrite.io/docs) diff --git a/lib/appwrite.dart b/lib/appwrite.dart index e8d4a27c..d8ed2a06 100644 --- a/lib/appwrite.dart +++ b/lib/appwrite.dart @@ -1,16 +1,19 @@ /// Appwrite Flutter SDK /// -/// This SDK is compatible with Appwrite server version 1.4.x. +/// This SDK is compatible with Appwrite server version 1.5.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-flutter/releases). library appwrite; import 'dart:async'; import 'dart:typed_data'; +import 'dart:convert'; + import 'src/enums.dart'; import 'src/service.dart'; import 'src/input_file.dart'; import 'models.dart' as models; +import 'enums.dart' as enums; import 'src/upload_progress.dart'; export 'src/response.dart'; @@ -32,5 +35,6 @@ part 'services/databases.dart'; part 'services/functions.dart'; part 'services/graphql.dart'; part 'services/locale.dart'; +part 'services/messaging.dart'; part 'services/storage.dart'; part 'services/teams.dart'; diff --git a/lib/enums.dart b/lib/enums.dart new file mode 100644 index 00000000..426e3a68 --- /dev/null +++ b/lib/enums.dart @@ -0,0 +1,12 @@ +/// Appwrite Enums +library appwrite.enums; + +part 'src/enums/authenticator_type.dart'; +part 'src/enums/authentication_factor.dart'; +part 'src/enums/o_auth_provider.dart'; +part 'src/enums/browser.dart'; +part 'src/enums/credit_card.dart'; +part 'src/enums/flag.dart'; +part 'src/enums/execution_method.dart'; +part 'src/enums/image_gravity.dart'; +part 'src/enums/image_format.dart'; diff --git a/lib/models.dart b/lib/models.dart index 31e8119e..a6de0d82 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -43,3 +43,9 @@ part 'src/models/language.dart'; part 'src/models/currency.dart'; part 'src/models/phone.dart'; part 'src/models/headers.dart'; +part 'src/models/mfa_challenge.dart'; +part 'src/models/mfa_recovery_codes.dart'; +part 'src/models/mfa_type.dart'; +part 'src/models/mfa_factors.dart'; +part 'src/models/subscriber.dart'; +part 'src/models/target.dart'; diff --git a/lib/query.dart b/lib/query.dart index c70f7abd..5e7870a6 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,8 +1,32 @@ part of appwrite; + /// Helper class to generate query strings. class Query { - Query._(); + final String method; + final String? attribute; + final dynamic values; + + Query._(this.method, [this.attribute = null, this.values = null]); + + Map toJson() { + final map = { + 'method': method, + }; + + if(attribute != null) { + map['attribute'] = attribute; + } + + if(values != null) { + map['values'] = values is List ? values : [values]; + } + + return map; + } + + @override + String toString() => jsonEncode(toJson()); /// Filter resources where [attribute] is equal to [value]. /// @@ -10,90 +34,90 @@ class Query { /// the query will return resources where [attribute] is equal /// to any of the values in the list. static String equal(String attribute, dynamic value) => - _addQuery(attribute, 'equal', value); + Query._('equal', attribute, value).toString(); /// Filter resources where [attribute] is not equal to [value]. - /// - /// [value] can be a single value or a list. If a list is used - /// the query will return resources where [attribute] is equal - /// to any of the values in the list. static String notEqual(String attribute, dynamic value) => - _addQuery(attribute, 'notEqual', value); + Query._('notEqual', attribute, [value]).toString(); /// Filter resources where [attribute] is less than [value]. static String lessThan(String attribute, dynamic value) => - _addQuery(attribute, 'lessThan', value); + Query._('lessThan', attribute, value).toString(); /// Filter resources where [attribute] is less than or equal to [value]. static String lessThanEqual(String attribute, dynamic value) => - _addQuery(attribute, 'lessThanEqual', value); + Query._('lessThanEqual', attribute, value).toString(); /// Filter resources where [attribute] is greater than [value]. static String greaterThan(String attribute, dynamic value) => - _addQuery(attribute, 'greaterThan', value); + Query._('greaterThan', attribute, value).toString(); /// Filter resources where [attribute] is greater than or equal to [value]. static String greaterThanEqual(String attribute, dynamic value) => - _addQuery(attribute, 'greaterThanEqual', value); + Query._('greaterThanEqual', attribute, value).toString(); /// Filter resources where by searching [attribute] for [value]. static String search(String attribute, String value) => - _addQuery(attribute, 'search', value); + Query._('search', attribute, value).toString(); /// Filter resources where [attribute] is null. - static String isNull(String attribute) => 'isNull("$attribute")'; + static String isNull(String attribute) => Query._('isNull', attribute).toString(); /// Filter resources where [attribute] is not null. - static String isNotNull(String attribute) => 'isNotNull("$attribute")'; + static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString(); /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => - 'between("$attribute", ${_parseValues(start)}, ${_parseValues(end)})'; + Query._('between', attribute, [start, end]).toString(); /// Filter resources where [attribute] starts with [value]. static String startsWith(String attribute, String value) => - _addQuery(attribute, 'startsWith', value); + Query._('startsWith', attribute, value).toString(); /// Filter resources where [attribute] ends with [value]. static String endsWith(String attribute, String value) => - _addQuery(attribute, 'endsWith', value); + Query._('endsWith', attribute, value).toString(); + + /// Filter resources where [attribute] contains [value] + /// [value] can be a single value or a list. + static String contains(String attribute, dynamic value) => + Query._('contains', attribute, value).toString(); + + static String or(List queries) => + Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString(); + + static String and(List queries) => + Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString(); /// Specify which attributes should be returned by the API call. static String select(List attributes) => - 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])'; + Query._('select', null, attributes).toString(); /// Sort results by [attribute] ascending. - static String orderAsc(String attribute) => 'orderAsc("$attribute")'; + static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString(); /// Sort results by [attribute] descending. - static String orderDesc(String attribute) => 'orderDesc("$attribute")'; + static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString(); /// Return results before [id]. /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorBefore(String id) => 'cursorBefore("$id")'; + static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString(); /// Return results after [id]. /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorAfter(String id) => 'cursorAfter("$id")'; + static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString(); /// Return only [limit] results. - static String limit(int limit) => 'limit($limit)'; + static String limit(int limit) => Query._('limit', null, limit).toString(); /// Return results from [offset]. /// /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) /// docs for more information. - static String offset(int offset) => 'offset($offset)'; - - static String _addQuery(String attribute, String method, dynamic value) => (value - is List) - ? '$method("$attribute", [${value.map((item) => _parseValues(item)).join(",")}])' - : '$method("$attribute", [${_parseValues(value)}])'; + static String offset(int offset) => Query._('offset', null, offset).toString(); - static String _parseValues(dynamic value) => - (value is String) ? '"$value"' : '$value'; } \ No newline at end of file diff --git a/lib/services/account.dart b/lib/services/account.dart index 56bebc19..dfb78927 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -84,7 +84,7 @@ class Account extends Service { /// List Identities /// /// Get the list of identities for the currently logged in user. - Future listIdentities({String? queries}) async { + Future listIdentities({List? queries}) async { const String apiPath = '/account/identities'; final Map apiParams = { @@ -101,7 +101,7 @@ class Account extends Service { } - /// Delete Identity + /// Delete identity /// /// Delete an identity by its unique ID. Future deleteIdentity({required String identityId}) async { @@ -164,6 +164,223 @@ class Account extends Service { } + /// Update MFA + /// + /// Enable or disable MFA on an account. + Future updateMFA({required bool mfa}) async { + const String apiPath = '/account/mfa'; + + final Map apiParams = { + 'mfa': mfa, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Add Authenticator + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#verifyAuthenticator) + /// method. + Future createMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaType.fromMap(res.data); + + } + + /// Verify Authenticator + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#addAuthenticator) + /// method. + Future updateMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + 'otp': otp, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete Authenticator + /// + /// Delete an authenticator for a user by ID. + Future deleteMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + 'otp': otp, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create 2FA Challenge + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future createMfaChallenge({required enums.AuthenticationFactor factor}) async { + const String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + 'factor': factor, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaChallenge.fromMap(res.data); + + } + + /// Create MFA Challenge (confirmation) + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future updateMfaChallenge({required String challengeId, required String otp}) async { + const String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + 'challengeId': challengeId, + 'otp': otp, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List Factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors() async { + const String apiPath = '/account/mfa/factors'; + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA Recovery Codes + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future getMfaRecoveryCodes() async { + const String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA Recovery Codes + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future createMfaRecoveryCodes() async { + const String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA Recovery Codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future updateMfaRecoveryCodes() async { + const String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + /// Update name /// /// Update currently logged in user account name. @@ -313,14 +530,13 @@ class Account extends Service { /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) /// the only valid redirect URLs are the ones from domains you have set when /// adding your platforms in the console interface. - Future updateRecovery({required String userId, required String secret, required String password, required String passwordAgain}) async { + Future updateRecovery({required String userId, required String secret, required String password}) async { const String apiPath = '/account/recovery'; final Map apiParams = { 'userId': userId, 'secret': secret, 'password': password, - 'passwordAgain': passwordAgain, }; final Map apiHeaders = { @@ -398,7 +614,7 @@ class Account extends Service { } - /// Create email session + /// Create email password session /// /// Allow the user to login into their account by providing a valid email and /// password combination. This route will create a new session for the user. @@ -406,7 +622,7 @@ class Account extends Service { /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailSession({required String email, required String password}) async { + Future createEmailPasswordSession({required String email, required String password}) async { const String apiPath = '/account/sessions/email'; final Map apiParams = { @@ -424,56 +640,11 @@ class Account extends Service { } - /// Create magic URL session - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not been registered, a new user will be created. When - /// the user clicks the link in the email, the user is redirected back to the - /// URL you provided with the secret key and userId values attached to the URL - /// query string. Use the query string parameters to submit a request to the - /// [PUT - /// /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#updateMagicURLSession) - /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. If you are on a mobile device you can leave - /// the URL parameter empty, so that the login completion will be handled by - /// your Appwrite instance by default. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - /// - Future createMagicURLSession({required String userId, required String email, String? url}) async { - const String apiPath = '/account/sessions/magic-url'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'url': url, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create magic URL session (confirmation) + /// Update magic URL session /// - /// Use this endpoint to complete creating the session with the Magic URL. Both - /// the **userId** and **secret** arguments will be passed as query parameters - /// to the redirect URL you have provided when sending your request to the - /// [POST - /// /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#createMagicURLSession) - /// endpoint. - /// - /// Please note that in order to avoid a [Redirect - /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) - /// the only valid redirect URLs are the ones from domains you have set when - /// adding your platforms in the console interface. + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. Future updateMagicURLSession({required String userId, required String secret}) async { const String apiPath = '/account/sessions/magic-url'; @@ -510,8 +681,8 @@ class Account extends Service { /// about session /// limits](https://appwrite.io/docs/authentication-security#limits). /// - Future createOAuth2Session({required String provider, String? success, String? failure, List? scopes}) async { - final String apiPath = '/account/sessions/oauth2/{provider}'.replaceAll('{provider}', provider); + Future createOAuth2Session({required enums.OAuthProvider provider, String? success, String? failure, List? scopes}) async { + final String apiPath = '/account/sessions/oauth2/{provider}'.replaceAll('{provider}', provider.value); final Map params = { @@ -542,48 +713,39 @@ class Account extends Service { query: query.join('&') ); - return client.webAuth(url, callbackUrlScheme: success); + return client.webAuth(url, callbackUrlScheme: success); } - /// Create phone session + /// Update phone session /// - /// Sends the user an SMS with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [PUT - /// /account/sessions/phone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createPhoneSession({required String userId, required String phone}) async { + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updatePhoneSession({required String userId, required String secret}) async { const String apiPath = '/account/sessions/phone'; final Map apiParams = { 'userId': userId, - 'phone': phone, + 'secret': secret, }; final Map apiHeaders = { 'content-type': 'application/json', }; - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - return models.Token.fromMap(res.data); + return models.Session.fromMap(res.data); } - /// Create phone session (confirmation) + /// Create session /// - /// Use this endpoint to complete creating a session with SMS. Use the - /// **userId** from the - /// [createPhoneSession](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneSession) - /// endpoint and the **secret** received via SMS to successfully update and - /// confirm the phone session. - Future updatePhoneSession({required String userId, required String secret}) async { - const String apiPath = '/account/sessions/phone'; + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future createSession({required String userId, required String secret}) async { + const String apiPath = '/account/sessions/token'; final Map apiParams = { 'userId': userId, @@ -594,7 +756,7 @@ class Account extends Service { 'content-type': 'application/json', }; - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); return models.Session.fromMap(res.data); @@ -620,11 +782,11 @@ class Account extends Service { } - /// Update OAuth session (refresh tokens) + /// Update session /// - /// Access tokens have limited lifespan and expire to mitigate security risks. - /// If session was created using an OAuth provider, this route can be used to - /// "refresh" the access token. + /// Use this endpoint to extend a session's length. Extending a session is + /// useful when session expiry is short. If the session was created using an + /// OAuth provider, this endpoint refreshes the access token from the provider. Future updateSession({required String sessionId}) async { final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); @@ -685,6 +847,214 @@ class Account extends Service { } + /// Create push target + /// + Future createPushTarget({required String targetId, required String identifier, String? providerId}) async { + const String apiPath = '/account/targets/push'; + + final Map apiParams = { + 'targetId': targetId, + 'identifier': identifier, + 'providerId': providerId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Update push target + /// + Future updatePushTarget({required String targetId, required String identifier}) async { + final String apiPath = '/account/targets/{targetId}/push'.replaceAll('{targetId}', targetId); + + final Map apiParams = { + 'identifier': identifier, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Delete push target + /// + Future deletePushTarget({required String targetId}) async { + final String apiPath = '/account/targets/{targetId}/push'.replaceAll('{targetId}', targetId); + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create email token (OTP) + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's email + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailToken({required String userId, required String email, bool? phrase}) async { + const String apiPath = '/account/tokens/email'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'phrase': phrase, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create magic URL token + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not been registered, a new user will be created. When + /// the user clicks the link in the email, the user is redirected back to the + /// URL you provided with the secret key and userId values attached to the URL + /// query string. Use the query string parameters to submit a request to the + /// [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The link sent to the user's email + /// address is valid for 1 hour. If you are on a mobile device you can leave + /// the URL parameter empty, so that the login completion will be handled by + /// your Appwrite instance by default. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + /// + Future createMagicURLToken({required String userId, required String email, String? url, bool? phrase}) async { + const String apiPath = '/account/tokens/magic-url'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'url': url, + 'phrase': phrase, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create OAuth2 token + /// + /// Allow the user to login to their account using the OAuth2 provider of their + /// choice. Each OAuth2 provider should be enabled from the Appwrite console + /// first. Use the success and failure arguments to provide a redirect URL's + /// back to your app when login is completed. + /// + /// If authentication succeeds, `userId` and `secret` of a token will be + /// appended to the success URL as query parameters. These can be used to + /// create a new session using the [Create + /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createOAuth2Token({required enums.OAuthProvider provider, String? success, String? failure, List? scopes}) async { + final String apiPath = '/account/tokens/oauth2/{provider}'.replaceAll('{provider}', provider.value); + + final Map params = { + + 'success': success, + 'failure': failure, + 'scopes': scopes, + + 'project': client.config['project'], + }; + + final List query = []; + + params.forEach((key, value) { + if (value is List) { + for (var item in value) { + query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item)); + } + } else if(value != null) { + query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); + } + }); + + Uri endpoint = Uri.parse(client.endPoint); + Uri url = Uri(scheme: endpoint.scheme, + host: endpoint.host, + port: endpoint.port, + path: endpoint.path + apiPath, + query: query.join('&') + ); + + return client.webAuth(url, callbackUrlScheme: success); + } + + /// Create phone token + /// + /// Sends the user an SMS with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createPhoneToken({required String userId, required String phone}) async { + const String apiPath = '/account/tokens/phone'; + + final Map apiParams = { + 'userId': userId, + 'phone': phone, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + /// Create email verification /// /// Use this endpoint to send a verification message to your user email address diff --git a/lib/services/avatars.dart b/lib/services/avatars.dart index 2bf87239..1a83f55a 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -18,8 +18,8 @@ class Avatars extends Service { /// with preserved aspect ratio. If both dimensions are 0, the API provides an /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. - Future getBrowser({required String code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code); + Future getBrowser({required enums.Browser code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code.value); final Map params = { @@ -45,8 +45,8 @@ class Avatars extends Service { /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. /// - Future getCreditCard({required String code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code); + Future getCreditCard({required enums.CreditCard code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); final Map params = { @@ -92,8 +92,8 @@ class Avatars extends Service { /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. /// - Future getFlag({required String code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code); + Future getFlag({required enums.Flag code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code.value); final Map params = { diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 83424948..f3688b4c 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -34,7 +34,7 @@ class Functions extends Service { /// current execution status. You can ping the `Get Execution` endpoint to get /// updates on the current execution status. Once this endpoint is called, your /// function execution process will start asynchronously. - Future createExecution({required String functionId, String? body, bool? xasync, String? path, String? method, Map? headers}) async { + Future createExecution({required String functionId, String? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers}) async { final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); final Map apiParams = { diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart new file mode 100644 index 00000000..850d9b18 --- /dev/null +++ b/lib/services/messaging.dart @@ -0,0 +1,48 @@ +part of appwrite; + +/// The Messaging service allows you to send messages to any provider type +/// (SMTP, push notification, SMS, etc.). +class Messaging extends Service { + /// Initializes a [Messaging] service + Messaging(super.client); + + /// Create subscriber + /// + /// Create a new subscriber. + Future createSubscriber({required String topicId, required String subscriberId, required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'subscriberId': subscriberId, + 'targetId': targetId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Delete subscriber + /// + /// Delete a subscriber by its unique ID. + Future deleteSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/storage.dart b/lib/services/storage.dart index affb323c..36643e08 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -165,7 +165,7 @@ class Storage extends Service { /// and spreadsheets, will return the file icon image. You can also pass query /// string arguments for cutting and resizing your preview image. Preview is /// supported only for image files smaller than 10MB. - Future getFilePreview({required String bucketId, required String fileId, int? width, int? height, String? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, String? output}) async { + Future getFilePreview({required String bucketId, required String fileId, int? width, int? height, enums.ImageGravity? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, enums.ImageFormat? output}) async { final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { diff --git a/lib/src/client.dart b/lib/src/client.dart index 0104067f..5201aedc 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -23,7 +23,7 @@ abstract class Client { /// Initializes a [Client]. factory Client( - {String endPoint = 'https://HOSTNAME/v1', + {String endPoint = 'https://cloud.appwrite.io/v1', bool selfSigned = false}) => createClient(endPoint: endPoint, selfSigned: selfSigned); @@ -66,6 +66,11 @@ abstract class Client { /// Set Locale. Client setLocale(value); + /// Set Session. + /// + /// The user session to authenticate with. + Client setSession(value); + /// Add headers that should be sent with all API calls. Client addHeader(String key, String value); diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index a38c1a67..f94505ab 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -11,6 +11,9 @@ abstract class ClientBase implements Client { ClientBase setJWT(value); @override ClientBase setLocale(value); + /// The user session to authenticate with + @override + ClientBase setSession(value); @override ClientBase setSelfSigned({bool status = true}); diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index c8c40b57..6f3ded4b 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -31,7 +31,7 @@ class ClientBrowser extends ClientBase with ClientMixin { String? get endPointRealtime => _endPointRealtime; ClientBrowser({ - String endPoint = 'https://HOSTNAME/v1', + String endPoint = 'https://cloud.appwrite.io/v1', bool selfSigned = false, }) : _endPoint = endPoint { _httpClient = BrowserClient(); @@ -43,8 +43,8 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '11.0.1', - 'X-Appwrite-Response-Format': '1.4.0', + 'x-sdk-version': '12.0.0', + 'X-Appwrite-Response-Format': '1.5.0', }; config = {}; @@ -77,6 +77,13 @@ class ClientBrowser extends ClientBase with ClientMixin { addHeader('X-Appwrite-Locale', value); return this; } + /// The user session to authenticate with + @override + ClientBrowser setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } @override ClientBrowser setSelfSigned({bool status = true}) { diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index e068d80f..88063f39 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -49,7 +49,7 @@ class ClientIO extends ClientBase with ClientMixin { String? get endPointRealtime => _endPointRealtime; ClientIO({ - String endPoint = 'https://HOSTNAME/v1', + String endPoint = 'https://cloud.appwrite.io/v1', this.selfSigned = false, }) : _endPoint = endPoint { _nativeClient = HttpClient() @@ -64,8 +64,8 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '11.0.1', - 'X-Appwrite-Response-Format' : '1.4.0', + 'x-sdk-version': '12.0.0', + 'X-Appwrite-Response-Format' : '1.5.0', }; config = {}; @@ -106,6 +106,13 @@ class ClientIO extends ClientBase with ClientMixin { addHeader('X-Appwrite-Locale', value); return this; } + /// The user session to authenticate with + @override + ClientIO setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } @override ClientIO setSelfSigned({bool status = true}) { @@ -321,7 +328,9 @@ class ClientIO extends ClientBase with ClientMixin { callbackUrlScheme: callbackUrlScheme != null && _customSchemeAllowed ? callbackUrlScheme : "appwrite-callback-" + config['project']!, - preferEphemeral: true, + options: const FlutterWebAuth2Options( + intentFlags: ephemeralIntentFlags, + ), ).then((value) async { Uri url = Uri.parse(value); final key = url.queryParameters['key']; diff --git a/lib/src/enums/authentication_factor.dart b/lib/src/enums/authentication_factor.dart new file mode 100644 index 00000000..b9f7ccd4 --- /dev/null +++ b/lib/src/enums/authentication_factor.dart @@ -0,0 +1,16 @@ +part of appwrite.enums; + +enum AuthenticationFactor { + email(value: 'email'), + phone(value: 'phone'), + totp(value: 'totp'), + recoverycode(value: 'recoverycode'); + + const AuthenticationFactor({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/authenticator_type.dart b/lib/src/enums/authenticator_type.dart new file mode 100644 index 00000000..9773964c --- /dev/null +++ b/lib/src/enums/authenticator_type.dart @@ -0,0 +1,13 @@ +part of appwrite.enums; + +enum AuthenticatorType { + totp(value: 'totp'); + + const AuthenticatorType({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/browser.dart b/lib/src/enums/browser.dart new file mode 100644 index 00000000..18c83a3d --- /dev/null +++ b/lib/src/enums/browser.dart @@ -0,0 +1,26 @@ +part of appwrite.enums; + +enum Browser { + avantBrowser(value: 'aa'), + androidWebViewBeta(value: 'an'), + googleChrome(value: 'ch'), + googleChromeIOS(value: 'ci'), + googleChromeMobile(value: 'cm'), + chromium(value: 'cr'), + mozillaFirefox(value: 'ff'), + safari(value: 'sf'), + mobileSafari(value: 'mf'), + microsoftEdge(value: 'ps'), + microsoftEdgeIOS(value: 'oi'), + operaMini(value: 'om'), + opera(value: 'op'), + operaNext(value: 'on'); + + const Browser({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart new file mode 100644 index 00000000..64987a05 --- /dev/null +++ b/lib/src/enums/credit_card.dart @@ -0,0 +1,28 @@ +part of appwrite.enums; + +enum CreditCard { + americanExpress(value: 'amex'), + argencard(value: 'argencard'), + cabal(value: 'cabal'), + consosud(value: 'censosud'), + dinersClub(value: 'diners'), + discover(value: 'discover'), + elo(value: 'elo'), + hipercard(value: 'hipercard'), + jCB(value: 'jcb'), + mastercard(value: 'mastercard'), + naranja(value: 'naranja'), + tarjetaShopping(value: 'targeta-shopping'), + unionChinaPay(value: 'union-china-pay'), + visa(value: 'visa'), + mIR(value: 'mir'), + maestro(value: 'maestro'); + + const CreditCard({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart new file mode 100644 index 00000000..27a94a5e --- /dev/null +++ b/lib/src/enums/execution_method.dart @@ -0,0 +1,18 @@ +part of appwrite.enums; + +enum ExecutionMethod { + gET(value: 'GET'), + pOST(value: 'POST'), + pUT(value: 'PUT'), + pATCH(value: 'PATCH'), + dELETE(value: 'DELETE'), + oPTIONS(value: 'OPTIONS'); + + const ExecutionMethod({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/flag.dart b/lib/src/enums/flag.dart new file mode 100644 index 00000000..9eacf8d6 --- /dev/null +++ b/lib/src/enums/flag.dart @@ -0,0 +1,206 @@ +part of appwrite.enums; + +enum Flag { + afghanistan(value: 'af'), + angola(value: 'ao'), + albania(value: 'al'), + andorra(value: 'ad'), + unitedArabEmirates(value: 'ae'), + argentina(value: 'ar'), + armenia(value: 'am'), + antiguaAndBarbuda(value: 'ag'), + australia(value: 'au'), + austria(value: 'at'), + azerbaijan(value: 'az'), + burundi(value: 'bi'), + belgium(value: 'be'), + benin(value: 'bj'), + burkinaFaso(value: 'bf'), + bangladesh(value: 'bd'), + bulgaria(value: 'bg'), + bahrain(value: 'bh'), + bahamas(value: 'bs'), + bosniaAndHerzegovina(value: 'ba'), + belarus(value: 'by'), + belize(value: 'bz'), + bolivia(value: 'bo'), + brazil(value: 'br'), + barbados(value: 'bb'), + bruneiDarussalam(value: 'bn'), + bhutan(value: 'bt'), + botswana(value: 'bw'), + centralAfricanRepublic(value: 'cf'), + canada(value: 'ca'), + switzerland(value: 'ch'), + chile(value: 'cl'), + china(value: 'cn'), + coteDIvoire(value: 'ci'), + cameroon(value: 'cm'), + democraticRepublicOfTheCongo(value: 'cd'), + republicOfTheCongo(value: 'cg'), + colombia(value: 'co'), + comoros(value: 'km'), + capeVerde(value: 'cv'), + costaRica(value: 'cr'), + cuba(value: 'cu'), + cyprus(value: 'cy'), + czechRepublic(value: 'cz'), + germany(value: 'de'), + djibouti(value: 'dj'), + dominica(value: 'dm'), + denmark(value: 'dk'), + dominicanRepublic(value: 'do'), + algeria(value: 'dz'), + ecuador(value: 'ec'), + egypt(value: 'eg'), + eritrea(value: 'er'), + spain(value: 'es'), + estonia(value: 'ee'), + ethiopia(value: 'et'), + finland(value: 'fi'), + fiji(value: 'fj'), + france(value: 'fr'), + micronesiaFederatedStatesOf(value: 'fm'), + gabon(value: 'ga'), + unitedKingdom(value: 'gb'), + georgia(value: 'ge'), + ghana(value: 'gh'), + guinea(value: 'gn'), + gambia(value: 'gm'), + guineaBissau(value: 'gw'), + equatorialGuinea(value: 'gq'), + greece(value: 'gr'), + grenada(value: 'gd'), + guatemala(value: 'gt'), + guyana(value: 'gy'), + honduras(value: 'hn'), + croatia(value: 'hr'), + haiti(value: 'ht'), + hungary(value: 'hu'), + indonesia(value: 'id'), + india(value: 'in'), + ireland(value: 'ie'), + iranIslamicRepublicOf(value: 'ir'), + iraq(value: 'iq'), + iceland(value: 'is'), + israel(value: 'il'), + italy(value: 'it'), + jamaica(value: 'jm'), + jordan(value: 'jo'), + japan(value: 'jp'), + kazakhstan(value: 'kz'), + kenya(value: 'ke'), + kyrgyzstan(value: 'kg'), + cambodia(value: 'kh'), + kiribati(value: 'ki'), + saintKittsAndNevis(value: 'kn'), + southKorea(value: 'kr'), + kuwait(value: 'kw'), + laoPeopleSDemocraticRepublic(value: 'la'), + lebanon(value: 'lb'), + liberia(value: 'lr'), + libya(value: 'ly'), + saintLucia(value: 'lc'), + liechtenstein(value: 'li'), + sriLanka(value: 'lk'), + lesotho(value: 'ls'), + lithuania(value: 'lt'), + luxembourg(value: 'lu'), + latvia(value: 'lv'), + morocco(value: 'ma'), + monaco(value: 'mc'), + moldova(value: 'md'), + madagascar(value: 'mg'), + maldives(value: 'mv'), + mexico(value: 'mx'), + marshallIslands(value: 'mh'), + northMacedonia(value: 'mk'), + mali(value: 'ml'), + malta(value: 'mt'), + myanmar(value: 'mm'), + montenegro(value: 'me'), + mongolia(value: 'mn'), + mozambique(value: 'mz'), + mauritania(value: 'mr'), + mauritius(value: 'mu'), + malawi(value: 'mw'), + malaysia(value: 'my'), + namibia(value: 'na'), + niger(value: 'ne'), + nigeria(value: 'ng'), + nicaragua(value: 'ni'), + netherlands(value: 'nl'), + norway(value: 'no'), + nepal(value: 'np'), + nauru(value: 'nr'), + newZealand(value: 'nz'), + oman(value: 'om'), + pakistan(value: 'pk'), + panama(value: 'pa'), + peru(value: 'pe'), + philippines(value: 'ph'), + palau(value: 'pw'), + papuaNewGuinea(value: 'pg'), + poland(value: 'pl'), + northKorea(value: 'kp'), + portugal(value: 'pt'), + paraguay(value: 'py'), + qatar(value: 'qa'), + romania(value: 'ro'), + russia(value: 'ru'), + rwanda(value: 'rw'), + saudiArabia(value: 'sa'), + sudan(value: 'sd'), + senegal(value: 'sn'), + singapore(value: 'sg'), + solomonIslands(value: 'sb'), + sierraLeone(value: 'sl'), + elSalvador(value: 'sv'), + sanMarino(value: 'sm'), + somalia(value: 'so'), + serbia(value: 'rs'), + southSudan(value: 'ss'), + saoTomeAndPrincipe(value: 'st'), + suriname(value: 'sr'), + slovakia(value: 'sk'), + slovenia(value: 'si'), + sweden(value: 'se'), + eswatini(value: 'sz'), + seychelles(value: 'sc'), + syria(value: 'sy'), + chad(value: 'td'), + togo(value: 'tg'), + thailand(value: 'th'), + tajikistan(value: 'tj'), + turkmenistan(value: 'tm'), + timorLeste(value: 'tl'), + tonga(value: 'to'), + trinidadAndTobago(value: 'tt'), + tunisia(value: 'tn'), + turkey(value: 'tr'), + tuvalu(value: 'tv'), + tanzania(value: 'tz'), + uganda(value: 'ug'), + ukraine(value: 'ua'), + uruguay(value: 'uy'), + unitedStates(value: 'us'), + uzbekistan(value: 'uz'), + vaticanCity(value: 'va'), + saintVincentAndTheGrenadines(value: 'vc'), + venezuela(value: 've'), + vietnam(value: 'vn'), + vanuatu(value: 'vu'), + samoa(value: 'ws'), + yemen(value: 'ye'), + southAfrica(value: 'za'), + zambia(value: 'zm'), + zimbabwe(value: 'zw'); + + const Flag({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart new file mode 100644 index 00000000..99941fb5 --- /dev/null +++ b/lib/src/enums/image_format.dart @@ -0,0 +1,17 @@ +part of appwrite.enums; + +enum ImageFormat { + jpg(value: 'jpg'), + jpeg(value: 'jpeg'), + gif(value: 'gif'), + png(value: 'png'), + webp(value: 'webp'); + + const ImageFormat({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_gravity.dart b/lib/src/enums/image_gravity.dart new file mode 100644 index 00000000..1d05c572 --- /dev/null +++ b/lib/src/enums/image_gravity.dart @@ -0,0 +1,21 @@ +part of appwrite.enums; + +enum ImageGravity { + center(value: 'center'), + topLeft(value: 'top-left'), + top(value: 'top'), + topRight(value: 'top-right'), + left(value: 'left'), + right(value: 'right'), + bottomLeft(value: 'bottom-left'), + bottom(value: 'bottom'), + bottomRight(value: 'bottom-right'); + + const ImageGravity({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart new file mode 100644 index 00000000..ee6d5aa0 --- /dev/null +++ b/lib/src/enums/o_auth_provider.dart @@ -0,0 +1,51 @@ +part of appwrite.enums; + +enum OAuthProvider { + amazon(value: 'amazon'), + apple(value: 'apple'), + auth0(value: 'auth0'), + authentik(value: 'authentik'), + autodesk(value: 'autodesk'), + bitbucket(value: 'bitbucket'), + bitly(value: 'bitly'), + box(value: 'box'), + dailymotion(value: 'dailymotion'), + discord(value: 'discord'), + disqus(value: 'disqus'), + dropbox(value: 'dropbox'), + etsy(value: 'etsy'), + facebook(value: 'facebook'), + github(value: 'github'), + gitlab(value: 'gitlab'), + google(value: 'google'), + linkedin(value: 'linkedin'), + microsoft(value: 'microsoft'), + notion(value: 'notion'), + oidc(value: 'oidc'), + okta(value: 'okta'), + paypal(value: 'paypal'), + paypalSandbox(value: 'paypalSandbox'), + podio(value: 'podio'), + salesforce(value: 'salesforce'), + slack(value: 'slack'), + spotify(value: 'spotify'), + stripe(value: 'stripe'), + tradeshift(value: 'tradeshift'), + tradeshiftBox(value: 'tradeshiftBox'), + twitch(value: 'twitch'), + wordpress(value: 'wordpress'), + yahoo(value: 'yahoo'), + yammer(value: 'yammer'), + yandex(value: 'yandex'), + zoho(value: 'zoho'), + zoom(value: 'zoom'), + mock(value: 'mock'); + + const OAuthProvider({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index ca8dad0f..b913478e 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -33,7 +33,7 @@ class Document implements Model { $databaseId: map['\$databaseId'].toString(), $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'], + $permissions: map['\$permissions'] ?? [], data: map, ); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index 99782f27..9c658725 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -59,7 +59,7 @@ class Execution implements Model { $id: map['\$id'].toString(), $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'], + $permissions: map['\$permissions'] ?? [], functionId: map['functionId'].toString(), trigger: map['trigger'].toString(), status: map['status'].toString(), diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index a6f8b2d0..95c392c8 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -45,7 +45,7 @@ class File implements Model { bucketId: map['bucketId'].toString(), $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'], + $permissions: map['\$permissions'] ?? [], name: map['name'].toString(), signature: map['signature'].toString(), mimeType: map['mimeType'].toString(), diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index 1b3786fa..c3a22fa3 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -24,6 +24,8 @@ class Membership implements Model { final String joined; /// User confirmation status, true if the user has joined the team or false otherwise. final bool confirm; + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. + final bool mfa; /// User list of roles final List roles; @@ -39,6 +41,7 @@ class Membership implements Model { required this.invited, required this.joined, required this.confirm, + required this.mfa, required this.roles, }); @@ -55,7 +58,8 @@ class Membership implements Model { invited: map['invited'].toString(), joined: map['joined'].toString(), confirm: map['confirm'], - roles: map['roles'], + mfa: map['mfa'], + roles: map['roles'] ?? [], ); } @@ -72,6 +76,7 @@ class Membership implements Model { "invited": invited, "joined": joined, "confirm": confirm, + "mfa": mfa, "roles": roles, }; } diff --git a/lib/src/models/mfa_challenge.dart b/lib/src/models/mfa_challenge.dart new file mode 100644 index 00000000..db1c0242 --- /dev/null +++ b/lib/src/models/mfa_challenge.dart @@ -0,0 +1,38 @@ +part of appwrite.models; + +/// MFA Challenge +class MfaChallenge implements Model { + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token expiration date in ISO 8601 format. + final String expire; + + MfaChallenge({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.expire, + }); + + factory MfaChallenge.fromMap(Map map) { + return MfaChallenge( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "expire": expire, + }; + } +} diff --git a/lib/src/models/mfa_factors.dart b/lib/src/models/mfa_factors.dart new file mode 100644 index 00000000..2fe49781 --- /dev/null +++ b/lib/src/models/mfa_factors.dart @@ -0,0 +1,33 @@ +part of appwrite.models; + +/// MFAFactors +class MfaFactors implements Model { + /// TOTP + final bool totp; + /// Phone + final bool phone; + /// Email + final bool email; + + MfaFactors({ + required this.totp, + required this.phone, + required this.email, + }); + + factory MfaFactors.fromMap(Map map) { + return MfaFactors( + totp: map['totp'], + phone: map['phone'], + email: map['email'], + ); + } + + Map toMap() { + return { + "totp": totp, + "phone": phone, + "email": email, + }; + } +} diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart new file mode 100644 index 00000000..1740f2ba --- /dev/null +++ b/lib/src/models/mfa_recovery_codes.dart @@ -0,0 +1,23 @@ +part of appwrite.models; + +/// MFA Recovery Codes +class MfaRecoveryCodes implements Model { + /// Recovery codes. + final List recoveryCodes; + + MfaRecoveryCodes({ + required this.recoveryCodes, + }); + + factory MfaRecoveryCodes.fromMap(Map map) { + return MfaRecoveryCodes( + recoveryCodes: map['recoveryCodes'] ?? [], + ); + } + + Map toMap() { + return { + "recoveryCodes": recoveryCodes, + }; + } +} diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart new file mode 100644 index 00000000..7100245c --- /dev/null +++ b/lib/src/models/mfa_type.dart @@ -0,0 +1,28 @@ +part of appwrite.models; + +/// MFAType +class MfaType implements Model { + /// Secret token used for TOTP factor. + final String secret; + /// URI for authenticator apps. + final String uri; + + MfaType({ + required this.secret, + required this.uri, + }); + + factory MfaType.fromMap(Map map) { + return MfaType( + secret: map['secret'].toString(), + uri: map['uri'].toString(), + ); + } + + Map toMap() { + return { + "secret": secret, + "uri": uri, + }; + } +} diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index 6f3421c1..151afb71 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -52,6 +52,12 @@ class Session implements Model { final String countryName; /// Returns true if this the current user session. final bool current; + /// Returns a list of active session factors. + final List factors; + /// Secret used to authenticate the user. Only included if the request was made with an API key + final String secret; + /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + final String mfaUpdatedAt; Session({ required this.$id, @@ -79,6 +85,9 @@ class Session implements Model { required this.countryCode, required this.countryName, required this.current, + required this.factors, + required this.secret, + required this.mfaUpdatedAt, }); factory Session.fromMap(Map map) { @@ -108,6 +117,9 @@ class Session implements Model { countryCode: map['countryCode'].toString(), countryName: map['countryName'].toString(), current: map['current'], + factors: map['factors'] ?? [], + secret: map['secret'].toString(), + mfaUpdatedAt: map['mfaUpdatedAt'].toString(), ); } @@ -138,6 +150,9 @@ class Session implements Model { "countryCode": countryCode, "countryName": countryName, "current": current, + "factors": factors, + "secret": secret, + "mfaUpdatedAt": mfaUpdatedAt, }; } } diff --git a/lib/src/models/subscriber.dart b/lib/src/models/subscriber.dart new file mode 100644 index 00000000..59ed84a2 --- /dev/null +++ b/lib/src/models/subscriber.dart @@ -0,0 +1,63 @@ +part of appwrite.models; + +/// Subscriber +class Subscriber implements Model { + /// Subscriber ID. + final String $id; + /// Subscriber creation time in ISO 8601 format. + final String $createdAt; + /// Subscriber update date in ISO 8601 format. + final String $updatedAt; + /// Target ID. + final String targetId; + /// Target. + final Target target; + /// Topic ID. + final String userId; + /// User Name. + final String userName; + /// Topic ID. + final String topicId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + Subscriber({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.targetId, + required this.target, + required this.userId, + required this.userName, + required this.topicId, + required this.providerType, + }); + + factory Subscriber.fromMap(Map map) { + return Subscriber( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + targetId: map['targetId'].toString(), + target: Target.fromMap(map['target']), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + topicId: map['topicId'].toString(), + providerType: map['providerType'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "targetId": targetId, + "target": target.toMap(), + "userId": userId, + "userName": userName, + "topicId": topicId, + "providerType": providerType, + }; + } +} diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart new file mode 100644 index 00000000..9cb7fedb --- /dev/null +++ b/lib/src/models/target.dart @@ -0,0 +1,58 @@ +part of appwrite.models; + +/// Target +class Target implements Model { + /// Target ID. + final String $id; + /// Target creation time in ISO 8601 format. + final String $createdAt; + /// Target update date in ISO 8601 format. + final String $updatedAt; + /// Target Name. + final String name; + /// User ID. + final String userId; + /// Provider ID. + final String? providerId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + /// The target identifier. + final String identifier; + + Target({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.userId, + this.providerId, + required this.providerType, + required this.identifier, + }); + + factory Target.fromMap(Map map) { + return Target( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + userId: map['userId'].toString(), + providerId: map['providerId']?.toString(), + providerType: map['providerType'].toString(), + identifier: map['identifier'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "userId": userId, + "providerId": providerId, + "providerType": providerType, + "identifier": identifier, + }; + } +} diff --git a/lib/src/models/token.dart b/lib/src/models/token.dart index 156bca57..31acde3b 100644 --- a/lib/src/models/token.dart +++ b/lib/src/models/token.dart @@ -12,6 +12,8 @@ class Token implements Model { final String secret; /// Token expiration date in ISO 8601 format. final String expire; + /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + final String phrase; Token({ required this.$id, @@ -19,6 +21,7 @@ class Token implements Model { required this.userId, required this.secret, required this.expire, + required this.phrase, }); factory Token.fromMap(Map map) { @@ -28,6 +31,7 @@ class Token implements Model { userId: map['userId'].toString(), secret: map['secret'].toString(), expire: map['expire'].toString(), + phrase: map['phrase'].toString(), ); } @@ -38,6 +42,7 @@ class Token implements Model { "userId": userId, "secret": secret, "expire": expire, + "phrase": phrase, }; } } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index 79b2b3e8..c201d421 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -32,8 +32,12 @@ class User implements Model { final bool emailVerification; /// Phone verification status. final bool phoneVerification; + /// Multi factor authentication status. + final bool mfa; /// User preferences as a key-value object final Preferences prefs; + /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + final List targets; /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. final String accessedAt; @@ -53,7 +57,9 @@ class User implements Model { required this.phone, required this.emailVerification, required this.phoneVerification, + required this.mfa, required this.prefs, + required this.targets, required this.accessedAt, }); @@ -68,13 +74,15 @@ class User implements Model { hashOptions: map['hashOptions'], registration: map['registration'].toString(), status: map['status'], - labels: map['labels'], + labels: map['labels'] ?? [], passwordUpdate: map['passwordUpdate'].toString(), email: map['email'].toString(), phone: map['phone'].toString(), emailVerification: map['emailVerification'], phoneVerification: map['phoneVerification'], + mfa: map['mfa'], prefs: Preferences.fromMap(map['prefs']), + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), accessedAt: map['accessedAt'].toString(), ); } @@ -96,7 +104,9 @@ class User implements Model { "phone": phone, "emailVerification": emailVerification, "phoneVerification": phoneVerification, + "mfa": mfa, "prefs": prefs.toMap(), + "targets": targets.map((p) => p.toMap()).toList(), "accessedAt": accessedAt, }; } diff --git a/pubspec.yaml b/pubspec.yaml index b4638263..adbd5bb5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 11.0.1 +version: 12.0.0 description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-flutter @@ -13,15 +13,15 @@ platforms: web: windows: environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: flutter: sdk: flutter cookie_jar: ^4.0.3 device_info_plus: ^9.0.2 - flutter_web_auth_2: ^2.1.4 - http: '>=0.13.6 <1.0.1' + flutter_web_auth_2: ^3.0.0 + http: '>=0.13.6 <2.0.0' package_info_plus: ^4.0.2 path_provider: ^2.0.15 web_socket_channel: ^2.4.0 @@ -32,4 +32,4 @@ dev_dependencies: flutter_lints: ^2.0.1 flutter_test: sdk: flutter - mockito: ^5.4.0 \ No newline at end of file + mockito: ^5.4.0 diff --git a/test/query_test.dart b/test/query_test.dart index 6fd1a07f..5784cf45 100644 --- a/test/query_test.dart +++ b/test/query_test.dart @@ -19,42 +19,42 @@ void main() { BasicFilterQueryTest( description: 'with a string', value: 's', - expectedValues: '["s"]', + expectedValues: ["s"], ), BasicFilterQueryTest( description: 'with an integer', value: 1, - expectedValues: '[1]', + expectedValues: [1], ), BasicFilterQueryTest( description: 'with a double', value: 1.2, - expectedValues: '[1.2]', + expectedValues: [1.2], ), BasicFilterQueryTest( description: 'with a whole number double', value: 1.0, - expectedValues: '[1.0]', + expectedValues: [1.0], ), BasicFilterQueryTest( description: 'with a bool', value: false, - expectedValues: '[false]', + expectedValues: [false], ), BasicFilterQueryTest( description: 'with a list', value: ['a', 'b', 'c'], - expectedValues: '["a","b","c"]', + expectedValues: ["a","b","c"], ), ]; group('equal()', () { for (var t in tests) { test(t.description, () { - expect( - Query.equal('attr', t.value), - 'equal("attr", ${t.expectedValues})', - ); + final query = Query.equal('attr', t.value).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'equal'); }); } }); @@ -62,10 +62,10 @@ void main() { group('notEqual()', () { for (var t in tests) { test(t.description, () { - expect( - Query.notEqual('attr', t.value), - 'notEqual("attr", ${t.expectedValues})', - ); + final query = Query.notEqual('attr', t.value).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'notEqual'); }); } }); @@ -73,10 +73,10 @@ void main() { group('lessThan()', () { for (var t in tests) { test(t.description, () { - expect( - Query.lessThan('attr', t.value), - 'lessThan("attr", ${t.expectedValues})', - ); + final query = Query.lessThan('attr', t.value).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'lessThan'); }); } }); @@ -84,10 +84,10 @@ void main() { group('lessThanEqual()', () { for (var t in tests) { test(t.description, () { - expect( - Query.lessThanEqual('attr', t.value), - 'lessThanEqual("attr", ${t.expectedValues})', - ); + final query = Query.lessThanEqual('attr', t.value).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'lessThanEqual'); }); } }); @@ -95,10 +95,10 @@ void main() { group('greaterThan()', () { for (var t in tests) { test(t.description, () { - expect( - Query.greaterThan('attr', t.value), - 'greaterThan("attr", ${t.expectedValues})', - ); + final query = Query.greaterThan('attr', t.value).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'greaterThan'); }); } }); @@ -106,87 +106,106 @@ void main() { group('greaterThanEqual()', () { for (var t in tests) { test(t.description, () { - expect( - Query.greaterThanEqual('attr', t.value), - 'greaterThanEqual("attr", ${t.expectedValues})', - ); + final query = Query.greaterThanEqual('attr', t.value).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'greaterThanEqual'); }); } }); }); - group('search()', () { - test('returns search', () { - expect(Query.search('attr', 'keyword1 keyword2'), 'search("attr", ["keyword1 keyword2"])'); - }); + test('returns search', () { + final query = Query.search('attr', 'keyword1 keyword2').toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], ['keyword1 keyword2']); + expect(query['method'], 'search'); }); - group('isNull()', () { - test('returns isNull', () { - expect(Query.isNull('attr'), 'isNull("attr")'); - }); + test('returns isNull', () { + final query = Query.isNull('attr').toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], null); + expect(query['method'], 'isNull'); }); - group('isNotNull()', () { - test('returns isNotNull', () { - expect(Query.isNotNull('attr'), 'isNotNull("attr")'); - }); + test('returns isNotNull', () { + final query = Query.isNotNull('attr', 'keyword1 keyword2').toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], null); + expect(query['method'], 'isNotNull'); }); group('between()', () { test('with integers', () { - expect(Query.between('attr', 1, 2), 'between("attr", [1,2])'); + final query = Query.between('attr', 1, 2).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], [1, 2]); + expect(query['method'], 'between'); }); test('with doubles', () { - expect(Query.between('attr', 1.0, 2.0), 'between("attr", [1.0,2.0])'); + final query = Query.between('attr', 1.0, 2.0).toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], [1.0, 2.0]); + expect(query['method'], 'between'); }); test('with strings', () { - expect(Query.between('attr', "a", "z"), 'between("attr", ["a","z"])'); + final query = Query.between('attr', 'a', 'z').toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], ['a', 'z']); + expect(query['method'], 'between'); }); }); - group('select()', () { - test('returns select', () { - expect(Query.select(['attr1', 'attr2']), 'select(["attr1","attr2"])'); - }); + test('returns select', () { + final query = Query.select(['attr1', 'attr2']).toJson(); + expect(query['attribute'], null); + expect(query['values'], ['attr1', 'attr2']); + expect(query['method'], 'select'); }); - group('orderAsc()', () { - test('returns orderAsc', () { - expect(Query.orderAsc('attr'), 'orderAsc("attr")'); - }); + test('returns orderAsc', () { + final query = Query.orderAsc('attr').toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], null); + expect(query['method'], 'orderAsc'); }); - group('orderDesc()', () { - test('returns orderDesc', () { - expect(Query.orderDesc('attr'), 'orderDesc("attr")'); - }); + test('returns orderDesc', () { + final query = Query.orderDesc('attr').toJson(); + expect(query['attribute'], 'attr'); + expect(query['values'], null); + expect(query['method'], 'orderDesc'); }); - group('cursorBefore()', () { - test('returns cursorBefore', () { - expect(Query.cursorBefore(ID.custom('custom')), 'cursorBefore("custom")'); - }); + test('returns cursorBefore', () { + final query = Query.cursorBefore('custom').toJson(); + expect(query['attribute'], null); + expect(query['values'], 'custom'); + expect(query['method'], 'cursorBefore'); }); - group('cursorAfter()', () { - test('returns cursorAfter', () { - expect(Query.cursorAfter(ID.custom('custom')), 'cursorAfter("custom")'); - }); + test('returns cursorAfter', () { + final query = Query.cursorAfter('custom').toJson(); + expect(query['attribute'], null); + expect(query['values'], 'custom'); + expect(query['method'], 'cursorAfter'); }); - group('limit()', () { - test('returns limit', () { - expect(Query.limit(1), 'limit(1)'); - }); + test('returns limit', () { + final query = Query.limit(1).toJson(); + expect(query['attribute'], null); + expect(query['values'], 1); + expect(query['method'], 'limit'); }); - group('offset()', () { - test('returns offset', () { - expect(Query.offset(1), 'offset(1)'); - }); + test('returns offset', () { + final query = Query.offset(1).toJson(); + expect(query['attribute'], null); + expect(query['values'], 1); + expect(query['method'], 'offset'); }); } diff --git a/test/services/account_test.dart b/test/services/account_test.dart index 026d9208..c82c1525 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -68,7 +68,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -97,7 +99,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -107,7 +111,7 @@ void main() { final response = await account.create( - userId: '[USER_ID]', + userId: '', email: 'email@example.com', password: '', ); @@ -129,7 +133,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -172,7 +178,7 @@ void main() { final response = await account.deleteIdentity( - identityId: '[IDENTITY_ID]', + identityId: '', ); }); @@ -209,6 +215,222 @@ void main() { }); + test('test method updateMFA()', () 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': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMFA( + mfa: true, + ); + expect(response, isA()); + + }); + + test('test method createMfaAuthenticator()', () async { + final Map data = { + 'secret': '1', + 'uri': '1',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMfaAuthenticator( + type: 'totp', + ); + expect(response, isA()); + + }); + + test('test method updateMfaAuthenticator()', () 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': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMfaAuthenticator( + type: 'totp', + otp: '', + ); + expect(response, isA()); + + }); + + test('test method deleteMfaAuthenticator()', () 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': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.deleteMfaAuthenticator( + type: 'totp', + otp: '', + ); + expect(response, isA()); + + }); + + test('test method createMfaChallenge()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMfaChallenge( + factor: 'email', + ); + expect(response, isA()); + + }); + + test('test method updateMfaChallenge()', () async { + final data = ''; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMfaChallenge( + challengeId: '', + otp: '', + ); + }); + + test('test method listMfaFactors()', () async { + final Map data = { + 'totp': true, + 'phone': true, + 'email': true,}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.listMfaFactors( + ); + expect(response, isA()); + + }); + + test('test method getMfaRecoveryCodes()', () async { + final Map data = { + 'recoveryCodes': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.getMfaRecoveryCodes( + ); + expect(response, isA()); + + }); + + test('test method createMfaRecoveryCodes()', () async { + final Map data = { + 'recoveryCodes': [],}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMfaRecoveryCodes( + ); + expect(response, isA()); + + }); + + test('test method updateMfaRecoveryCodes()', () async { + final Map data = { + 'recoveryCodes': [],}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMfaRecoveryCodes( + ); + expect(response, isA()); + + }); + test('test method updateName()', () async { final Map data = { '\$id': '5e5ea5c16897e', @@ -223,7 +445,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -233,7 +457,7 @@ void main() { final response = await account.updateName( - name: '[NAME]', + name: '', ); expect(response, isA()); @@ -253,7 +477,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -283,7 +509,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -329,7 +557,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -351,7 +581,8 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', 'userId': '5e5ea5c168bb8', 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; when(client.call( @@ -373,7 +604,8 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', 'userId': '5e5ea5c168bb8', 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; when(client.call( @@ -382,10 +614,9 @@ void main() { final response = await account.updateRecovery( - userId: '[USER_ID]', - secret: '[SECRET]', - password: 'password', - passwordAgain: 'password', + userId: '', + secret: '', + password: '', ); expect(response, isA()); @@ -446,7 +677,10 @@ void main() { 'deviceModel': 'Nexus 5', 'countryCode': 'US', 'countryName': 'United States', - 'current': true,}; + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -460,7 +694,7 @@ void main() { }); - test('test method createEmailSession()', () async { + test('test method createEmailPasswordSession()', () async { final Map data = { '\$id': '5e5ea5c16897e', '\$createdAt': '2020-10-15T06:38:00.000+00:00', @@ -486,7 +720,10 @@ void main() { 'deviceModel': 'Nexus 5', 'countryCode': 'US', 'countryName': 'United States', - 'current': true,}; + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -494,7 +731,7 @@ void main() { )).thenAnswer((_) async => Response(data: data)); - final response = await account.createEmailSession( + final response = await account.createEmailPasswordSession( email: 'email@example.com', password: 'password', ); @@ -502,28 +739,6 @@ void main() { }); - test('test method createMagicURLSession()', () async { - final Map data = { - '\$id': 'bb8ea5c16897e', - '\$createdAt': '2020-10-15T06:38:00.000+00:00', - 'userId': '5e5ea5c168bb8', - 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; - - - when(client.call( - HttpMethod.post, - )).thenAnswer((_) async => Response(data: data)); - - - final response = await account.createMagicURLSession( - userId: '[USER_ID]', - email: 'email@example.com', - ); - expect(response, isA()); - - }); - test('test method updateMagicURLSession()', () async { final Map data = { '\$id': '5e5ea5c16897e', @@ -550,7 +765,10 @@ void main() { 'deviceModel': 'Nexus 5', 'countryCode': 'US', 'countryName': 'United States', - 'current': true,}; + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -559,8 +777,8 @@ void main() { final response = await account.updateMagicURLSession( - userId: '[USER_ID]', - secret: '[SECRET]', + userId: '', + secret: '', ); expect(response, isA()); @@ -578,29 +796,52 @@ void main() { ); }); - test('test method createPhoneSession()', () async { + test('test method updatePhoneSession()', () async { final Map data = { - '\$id': 'bb8ea5c16897e', + '\$id': '5e5ea5c16897e', '\$createdAt': '2020-10-15T06:38:00.000+00:00', - 'userId': '5e5ea5c168bb8', - 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( - HttpMethod.post, + HttpMethod.put, )).thenAnswer((_) async => Response(data: data)); - final response = await account.createPhoneSession( - userId: '[USER_ID]', - phone: '+12065550100', + final response = await account.updatePhoneSession( + userId: '', + secret: '', ); - expect(response, isA()); + expect(response, isA()); }); - test('test method updatePhoneSession()', () async { + test('test method createSession()', () async { final Map data = { '\$id': '5e5ea5c16897e', '\$createdAt': '2020-10-15T06:38:00.000+00:00', @@ -626,17 +867,20 @@ void main() { 'deviceModel': 'Nexus 5', 'countryCode': 'US', 'countryName': 'United States', - 'current': true,}; + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( - HttpMethod.put, + HttpMethod.post, )).thenAnswer((_) async => Response(data: data)); - final response = await account.updatePhoneSession( - userId: '[USER_ID]', - secret: '[SECRET]', + final response = await account.createSession( + userId: '', + secret: '', ); expect(response, isA()); @@ -668,7 +912,10 @@ void main() { 'deviceModel': 'Nexus 5', 'countryCode': 'US', 'countryName': 'United States', - 'current': true,}; + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -677,7 +924,7 @@ void main() { final response = await account.getSession( - sessionId: '[SESSION_ID]', + sessionId: '', ); expect(response, isA()); @@ -709,7 +956,10 @@ void main() { 'deviceModel': 'Nexus 5', 'countryCode': 'US', 'countryName': 'United States', - 'current': true,}; + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -718,7 +968,7 @@ void main() { final response = await account.updateSession( - sessionId: '[SESSION_ID]', + sessionId: '', ); expect(response, isA()); @@ -733,7 +983,7 @@ void main() { final response = await account.deleteSession( - sessionId: '[SESSION_ID]', + sessionId: '', ); }); @@ -751,7 +1001,9 @@ void main() { 'phone': '+4930901820', 'emailVerification': true, 'phoneVerification': true, + 'mfa': true, 'prefs': {}, + 'targets': [], 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; @@ -766,13 +1018,156 @@ void main() { }); + test('test method createPushTarget()', () async { + final Map data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Aegon apple token', + 'userId': '259125845563242502', + 'providerType': 'email', + 'identifier': 'token',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createPushTarget( + targetId: '', + identifier: '', + ); + expect(response, isA()); + + }); + + test('test method updatePushTarget()', () async { + final Map data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Aegon apple token', + 'userId': '259125845563242502', + 'providerType': 'email', + 'identifier': 'token',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updatePushTarget( + targetId: '', + identifier: '', + ); + expect(response, isA()); + + }); + + test('test method deletePushTarget()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.deletePushTarget( + targetId: '', + ); + }); + + test('test method createEmailToken()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createEmailToken( + userId: '', + email: 'email@example.com', + ); + expect(response, isA()); + + }); + + test('test method createMagicURLToken()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMagicURLToken( + userId: '', + email: 'email@example.com', + ); + expect(response, isA()); + + }); + + test('test method createOAuth2Token()', () async { + + when(client.webAuth( + Uri(), + )).thenAnswer((_) async => 'done'); + + + final response = await account.createOAuth2Token( + provider: 'amazon', + ); + }); + + test('test method createPhoneToken()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createPhoneToken( + userId: '', + phone: '+12065550100', + ); + expect(response, isA()); + + }); + test('test method createVerification()', () async { final Map data = { '\$id': 'bb8ea5c16897e', '\$createdAt': '2020-10-15T06:38:00.000+00:00', 'userId': '5e5ea5c168bb8', 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; when(client.call( @@ -793,7 +1188,8 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', 'userId': '5e5ea5c168bb8', 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; when(client.call( @@ -802,8 +1198,8 @@ void main() { final response = await account.updateVerification( - userId: '[USER_ID]', - secret: '[SECRET]', + userId: '', + secret: '', ); expect(response, isA()); @@ -815,7 +1211,8 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', 'userId': '5e5ea5c168bb8', 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; when(client.call( @@ -835,7 +1232,8 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', 'userId': '5e5ea5c168bb8', 'secret': '', - 'expire': '2020-10-15T06:38:00.000+00:00',}; + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; when(client.call( @@ -844,8 +1242,8 @@ void main() { final response = await account.updatePhoneVerification( - userId: '[USER_ID]', - secret: '[SECRET]', + userId: '', + secret: '', ); expect(response, isA()); diff --git a/test/services/avatars_test.dart b/test/services/avatars_test.dart index 60c20f92..0adcd7d0 100644 --- a/test/services/avatars_test.dart +++ b/test/services/avatars_test.dart @@ -145,7 +145,7 @@ void main() { final response = await avatars.getQR( - text: '[TEXT]', + text: '', ); expect(response, isA()); diff --git a/test/services/databases_test.dart b/test/services/databases_test.dart index cee69ed8..1164948d 100644 --- a/test/services/databases_test.dart +++ b/test/services/databases_test.dart @@ -66,8 +66,8 @@ void main() { final response = await databases.listDocuments( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', + databaseId: '', + collectionId: '', ); expect(response, isA()); @@ -89,9 +89,9 @@ void main() { final response = await databases.createDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', + databaseId: '', + collectionId: '', + documentId: '', data: {}, ); expect(response, isA()); @@ -114,9 +114,9 @@ void main() { final response = await databases.getDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', + databaseId: '', + collectionId: '', + documentId: '', ); expect(response, isA()); @@ -138,9 +138,9 @@ void main() { final response = await databases.updateDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', + databaseId: '', + collectionId: '', + documentId: '', ); expect(response, isA()); @@ -155,9 +155,9 @@ void main() { final response = await databases.deleteDocument( - databaseId: '[DATABASE_ID]', - collectionId: '[COLLECTION_ID]', - documentId: '[DOCUMENT_ID]', + databaseId: '', + collectionId: '', + documentId: '', ); }); diff --git a/test/services/functions_test.dart b/test/services/functions_test.dart index 67ddc8fa..8707d054 100644 --- a/test/services/functions_test.dart +++ b/test/services/functions_test.dart @@ -66,7 +66,7 @@ void main() { final response = await functions.listExecutions( - functionId: '[FUNCTION_ID]', + functionId: '', ); expect(response, isA()); @@ -98,7 +98,7 @@ void main() { final response = await functions.createExecution( - functionId: '[FUNCTION_ID]', + functionId: '', ); expect(response, isA()); @@ -130,8 +130,8 @@ void main() { final response = await functions.getExecution( - functionId: '[FUNCTION_ID]', - executionId: '[EXECUTION_ID]', + functionId: '', + executionId: '', ); expect(response, isA()); diff --git a/test/services/messaging_test.dart b/test/services/messaging_test.dart new file mode 100644 index 00000000..ba3564ab --- /dev/null +++ b/test/services/messaging_test.dart @@ -0,0 +1,99 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/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, + { + String? callbackUrlScheme, + } + ) 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('Messaging test', () { + late MockClient client; + late Messaging messaging; + + setUp(() { + client = MockClient(); + messaging = Messaging(client); + }); + + test('test method createSubscriber()', () async { + final Map data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'targetId': '259125845563242502', + 'target': {}, + 'userId': '5e5ea5c16897e', + 'userName': 'Aegon Targaryen', + 'topicId': '259125845563242502', + 'providerType': 'email',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await messaging.createSubscriber( + topicId: '', + subscriberId: '', + targetId: '', + ); + expect(response, isA()); + + }); + + test('test method deleteSubscriber()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await messaging.deleteSubscriber( + topicId: '', + subscriberId: '', + ); + }); + + }); +} \ No newline at end of file diff --git a/test/services/storage_test.dart b/test/services/storage_test.dart index 477a76ff..0e153622 100644 --- a/test/services/storage_test.dart +++ b/test/services/storage_test.dart @@ -66,7 +66,7 @@ void main() { final response = await storage.listFiles( - bucketId: '[BUCKET_ID]', + bucketId: '', ); expect(response, isA()); @@ -97,8 +97,8 @@ void main() { final response = await storage.createFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', file: InputFile.fromPath(path: './image.png'), ); expect(response, isA()); @@ -126,8 +126,8 @@ void main() { final response = await storage.getFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', ); expect(response, isA()); @@ -154,8 +154,8 @@ void main() { final response = await storage.updateFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', ); expect(response, isA()); @@ -170,8 +170,8 @@ void main() { final response = await storage.deleteFile( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', ); }); @@ -183,8 +183,8 @@ void main() { final response = await storage.getFileDownload( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', ); expect(response, isA()); @@ -198,8 +198,8 @@ void main() { final response = await storage.getFilePreview( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', ); expect(response, isA()); @@ -213,8 +213,8 @@ void main() { final response = await storage.getFileView( - bucketId: '[BUCKET_ID]', - fileId: '[FILE_ID]', + bucketId: '', + fileId: '', ); expect(response, isA()); diff --git a/test/services/teams_test.dart b/test/services/teams_test.dart index 9c80d1c8..da943b25 100644 --- a/test/services/teams_test.dart +++ b/test/services/teams_test.dart @@ -87,8 +87,8 @@ void main() { final response = await teams.create( - teamId: '[TEAM_ID]', - name: '[NAME]', + teamId: '', + name: '', ); expect(response, isA()); @@ -110,7 +110,7 @@ void main() { final response = await teams.get( - teamId: '[TEAM_ID]', + teamId: '', ); expect(response, isA()); @@ -132,8 +132,8 @@ void main() { final response = await teams.updateName( - teamId: '[TEAM_ID]', - name: '[NAME]', + teamId: '', + name: '', ); expect(response, isA()); @@ -148,7 +148,7 @@ void main() { final response = await teams.delete( - teamId: '[TEAM_ID]', + teamId: '', ); }); @@ -164,7 +164,7 @@ void main() { final response = await teams.listMemberships( - teamId: '[TEAM_ID]', + teamId: '', ); expect(response, isA()); @@ -183,6 +183,7 @@ void main() { 'invited': '2020-10-15T06:38:00.000+00:00', 'joined': '2020-10-15T06:38:00.000+00:00', 'confirm': true, + 'mfa': true, 'roles': [],}; @@ -192,7 +193,7 @@ void main() { final response = await teams.createMembership( - teamId: '[TEAM_ID]', + teamId: '', roles: [], ); expect(response, isA()); @@ -212,6 +213,7 @@ void main() { 'invited': '2020-10-15T06:38:00.000+00:00', 'joined': '2020-10-15T06:38:00.000+00:00', 'confirm': true, + 'mfa': true, 'roles': [],}; @@ -221,8 +223,8 @@ void main() { final response = await teams.getMembership( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', + teamId: '', + membershipId: '', ); expect(response, isA()); @@ -241,6 +243,7 @@ void main() { 'invited': '2020-10-15T06:38:00.000+00:00', 'joined': '2020-10-15T06:38:00.000+00:00', 'confirm': true, + 'mfa': true, 'roles': [],}; @@ -250,8 +253,8 @@ void main() { final response = await teams.updateMembership( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', + teamId: '', + membershipId: '', roles: [], ); expect(response, isA()); @@ -267,8 +270,8 @@ void main() { final response = await teams.deleteMembership( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', + teamId: '', + membershipId: '', ); }); @@ -285,6 +288,7 @@ void main() { 'invited': '2020-10-15T06:38:00.000+00:00', 'joined': '2020-10-15T06:38:00.000+00:00', 'confirm': true, + 'mfa': true, 'roles': [],}; @@ -294,10 +298,10 @@ void main() { final response = await teams.updateMembershipStatus( - teamId: '[TEAM_ID]', - membershipId: '[MEMBERSHIP_ID]', - userId: '[USER_ID]', - secret: '[SECRET]', + teamId: '', + membershipId: '', + userId: '', + secret: '', ); expect(response, isA()); @@ -313,7 +317,7 @@ void main() { final response = await teams.getPrefs( - teamId: '[TEAM_ID]', + teamId: '', ); expect(response, isA()); @@ -329,7 +333,7 @@ void main() { final response = await teams.updatePrefs( - teamId: '[TEAM_ID]', + teamId: '', prefs: {}, ); expect(response, isA()); diff --git a/test/src/models/membership_test.dart b/test/src/models/membership_test.dart index bc7b3eb4..5e5033ec 100644 --- a/test/src/models/membership_test.dart +++ b/test/src/models/membership_test.dart @@ -17,6 +17,7 @@ void main() { invited: '2020-10-15T06:38:00.000+00:00', joined: '2020-10-15T06:38:00.000+00:00', confirm: true, + mfa: true, roles: [], ); @@ -34,6 +35,7 @@ void main() { expect(result.invited, '2020-10-15T06:38:00.000+00:00'); expect(result.joined, '2020-10-15T06:38:00.000+00:00'); expect(result.confirm, true); + expect(result.mfa, true); expect(result.roles, []); }); }); diff --git a/test/src/models/mfa_challenge_test.dart b/test/src/models/mfa_challenge_test.dart new file mode 100644 index 00000000..75afb97a --- /dev/null +++ b/test/src/models/mfa_challenge_test.dart @@ -0,0 +1,24 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('MfaChallenge', () { + + test('model', () { + final model = MfaChallenge( + $id: 'bb8ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + userId: '5e5ea5c168bb8', + expire: '2020-10-15T06:38:00.000+00:00', + ); + + final map = model.toMap(); + final result = MfaChallenge.fromMap(map); + + expect(result.$id, 'bb8ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5ea5c168bb8'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + }); + }); +} diff --git a/test/src/models/mfa_factors_test.dart b/test/src/models/mfa_factors_test.dart new file mode 100644 index 00000000..9a2e8038 --- /dev/null +++ b/test/src/models/mfa_factors_test.dart @@ -0,0 +1,22 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('MfaFactors', () { + + test('model', () { + final model = MfaFactors( + totp: true, + phone: true, + email: true, + ); + + final map = model.toMap(); + final result = MfaFactors.fromMap(map); + + expect(result.totp, true); + expect(result.phone, true); + expect(result.email, true); + }); + }); +} diff --git a/test/src/models/mfa_recovery_codes_test.dart b/test/src/models/mfa_recovery_codes_test.dart new file mode 100644 index 00000000..7153abb5 --- /dev/null +++ b/test/src/models/mfa_recovery_codes_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('MfaRecoveryCodes', () { + + test('model', () { + final model = MfaRecoveryCodes( + recoveryCodes: [], + ); + + final map = model.toMap(); + final result = MfaRecoveryCodes.fromMap(map); + + expect(result.recoveryCodes, []); + }); + }); +} diff --git a/test/src/models/mfa_type_test.dart b/test/src/models/mfa_type_test.dart new file mode 100644 index 00000000..cab65e8e --- /dev/null +++ b/test/src/models/mfa_type_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('MfaType', () { + + test('model', () { + final model = MfaType( + secret: '1', + uri: '1', + ); + + final map = model.toMap(); + final result = MfaType.fromMap(map); + + expect(result.secret, '1'); + expect(result.uri, '1'); + }); + }); +} diff --git a/test/src/models/session_test.dart b/test/src/models/session_test.dart index 259ba68c..b2117b82 100644 --- a/test/src/models/session_test.dart +++ b/test/src/models/session_test.dart @@ -31,6 +31,9 @@ void main() { countryCode: 'US', countryName: 'United States', current: true, + factors: [], + secret: '5e5bb8c16897e', + mfaUpdatedAt: '2020-10-15T06:38:00.000+00:00', ); final map = model.toMap(); @@ -61,6 +64,9 @@ void main() { expect(result.countryCode, 'US'); expect(result.countryName, 'United States'); expect(result.current, true); + expect(result.factors, []); + expect(result.secret, '5e5bb8c16897e'); + expect(result.mfaUpdatedAt, '2020-10-15T06:38:00.000+00:00'); }); }); } diff --git a/test/src/models/subscriber_test.dart b/test/src/models/subscriber_test.dart new file mode 100644 index 00000000..5401b863 --- /dev/null +++ b/test/src/models/subscriber_test.dart @@ -0,0 +1,34 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Subscriber', () { + + test('model', () { + final model = Subscriber( + $id: '259125845563242502', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + targetId: '259125845563242502', + target: {}, + userId: '5e5ea5c16897e', + userName: 'Aegon Targaryen', + topicId: '259125845563242502', + providerType: 'email', + ); + + final map = model.toMap(); + final result = Subscriber.fromMap(map); + + expect(result.$id, '259125845563242502'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.targetId, '259125845563242502'); + expect(result.target, {}); + expect(result.userId, '5e5ea5c16897e'); + expect(result.userName, 'Aegon Targaryen'); + expect(result.topicId, '259125845563242502'); + expect(result.providerType, 'email'); + }); + }); +} diff --git a/test/src/models/target_test.dart b/test/src/models/target_test.dart new file mode 100644 index 00000000..15d18262 --- /dev/null +++ b/test/src/models/target_test.dart @@ -0,0 +1,30 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Target', () { + + test('model', () { + final model = Target( + $id: '259125845563242502', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'Aegon apple token', + userId: '259125845563242502', + providerType: 'email', + identifier: 'token', + ); + + final map = model.toMap(); + final result = Target.fromMap(map); + + expect(result.$id, '259125845563242502'); + 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, 'Aegon apple token'); + expect(result.userId, '259125845563242502'); + expect(result.providerType, 'email'); + expect(result.identifier, 'token'); + }); + }); +} diff --git a/test/src/models/token_test.dart b/test/src/models/token_test.dart index 8ac33395..a2a694d9 100644 --- a/test/src/models/token_test.dart +++ b/test/src/models/token_test.dart @@ -11,6 +11,7 @@ void main() { userId: '5e5ea5c168bb8', secret: '', expire: '2020-10-15T06:38:00.000+00:00', + phrase: 'Golden Fox', ); final map = model.toMap(); @@ -21,6 +22,7 @@ void main() { expect(result.userId, '5e5ea5c168bb8'); expect(result.secret, ''); expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + expect(result.phrase, 'Golden Fox'); }); }); } diff --git a/test/src/models/user_test.dart b/test/src/models/user_test.dart index b98b081f..9b78a7db 100644 --- a/test/src/models/user_test.dart +++ b/test/src/models/user_test.dart @@ -18,7 +18,9 @@ void main() { phone: '+4930901820', emailVerification: true, phoneVerification: true, + mfa: true, prefs: Preferences(data: {}), + targets: [], accessedAt: '2020-10-15T06:38:00.000+00:00', ); @@ -37,7 +39,9 @@ void main() { expect(result.phone, '+4930901820'); expect(result.emailVerification, true); expect(result.phoneVerification, true); + expect(result.mfa, true); expect(result.prefs.data, {"data": {}}); + expect(result.targets, []); expect(result.accessedAt, '2020-10-15T06:38:00.000+00:00'); }); });