From afdfa7b06c99d9441e14679cc60d17ac7247f8ff Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 30 Aug 2022 03:01:08 +0000 Subject: [PATCH] flutter web auth switched --- CHANGELOG.md | 7 +- LICENSE | 2 +- README.md | 10 +- lib/appwrite.dart | 3 - lib/services/account.dart | 748 +++++++++++++++--------------------- lib/services/avatars.dart | 229 ++++++----- lib/services/databases.dart | 76 ++-- lib/services/functions.dart | 84 ++-- lib/services/locale.dart | 140 +++---- lib/services/storage.dart | 219 +++++------ lib/services/teams.dart | 280 ++++++-------- lib/src/client_browser.dart | 6 +- lib/src/client_io.dart | 14 +- lib/src/realtime_io.dart | 3 + pubspec.yaml | 17 +- 15 files changed, 798 insertions(+), 1040 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f1cc83..f5cfe4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 7.0.0 +* **BREAKING** flutter_web_auth package now switched to + ## 6.0.0 * Support for Appwrite 0.15 * **NEW** Phone authentication `account.createPhoneSession()` @@ -6,8 +9,8 @@ * **BREAKING** `dateCreated` attribute removed from `Team`, `Execution`, `File` models * **BREAKING** `dateCreated` and `dateUpdated` attribute removed from `Func`, `Deployment`, `Bucket` models * **BREAKING** Realtime channels - * collections.[COLLECTION_ID] is now databases.[DATABASE_ID].ollections.[COLLECTION_ID] - * collections.[COLLECTION_ID].documents is now databases.[DATABASE_ID].ollections.[COLLECTION_ID].documents + * collections.[COLLECTION_ID] is now databases.[DATABASE_ID].collections.[COLLECTION_ID] + * collections.[COLLECTION_ID].documents is now databases.[DATABASE_ID].collections.[COLLECTION_ID].documents **Full Changelog for Appwrite 0.15 can be found here**: https://github.com/appwrite/appwrite/blob/master/CHANGES.md#version-0150 diff --git a/LICENSE b/LICENSE index 96201c4..b0761cc 100644 --- a/LICENSE +++ b/LICENSE @@ -9,4 +9,4 @@ Redistribution and use in source and binary forms, with or without modification, 3. Neither the name Appwrite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index 3fb6d2a..bb5f42c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![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-0.15.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-0.15.2-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) @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^6.0.0 + appwrite: ^7.0.0 ``` You can install packages from the command line: @@ -51,8 +51,8 @@ In order to capture the Appwrite OAuth callback url, the following activity need .... - - + + @@ -91,7 +91,7 @@ For web in order to capture the OAuth2 callback URL and send it to the applicati close the window. diff --git a/lib/appwrite.dart b/lib/appwrite.dart index e43fb1b..bf6752a 100644 --- a/lib/appwrite.dart +++ b/lib/appwrite.dart @@ -2,15 +2,12 @@ library appwrite; import 'dart:async'; import 'dart:typed_data'; -import 'package:flutter/foundation.dart'; -import 'package:http/http.dart' show MultipartFile; import 'src/enums.dart'; import 'src/client.dart'; import 'src/service.dart'; import 'src/input_file.dart'; import 'models.dart' as models; import 'src/upload_progress.dart'; -import 'src/exception.dart'; export 'src/response.dart'; export 'src/client.dart'; diff --git a/lib/services/account.dart b/lib/services/account.dart index d2ead1d..d88a28c 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -1,557 +1,486 @@ part of appwrite; - /// The Account service allows you to authenticate and manage a user account. + /// The Account service allows you to authenticate and manage a user account. class Account extends Service { Account(Client client): super(client); - /// Get Account - /// - /// Get currently logged in user data as JSON object. - /// - Future get() async { + /// Get Account + /// + /// Get currently logged in user data as JSON object. + /// + Future get() async { const String path = '/account'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Create Account - /// - /// Use this endpoint to allow a new user to register a new account in your - /// project. After the user registration completes successfully, you can use - /// the [/account/verfication](/docs/client/account#accountCreateVerification) - /// route to start verifying the user email address. To allow the new user to - /// login to their new account, you need to create a new [account - /// session](/docs/client/account#accountCreateSession). - /// - Future create({required String userId, required String email, required String password, String? name}) async { + /// Create Account + /// + /// Use this endpoint to allow a new user to register a new account in your + /// project. After the user registration completes successfully, you can use + /// the [/account/verfication](/docs/client/account#accountCreateVerification) + /// route to start verifying the user email address. To allow the new user to + /// login to their new account, you need to create a new [account + /// session](/docs/client/account#accountCreateSession). + /// + Future create({required String userId, required String email, required String password, String? name}) async { const String path = '/account'; final Map params = { - 'userId': userId, -'email': email, -'password': password, -'name': name, - + 'email': email, + 'password': password, + 'name': name, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Update Account Email - /// - /// Update currently logged in user account email address. After changing user - /// address, the user confirmation status will get reset. A new confirmation - /// email is not sent automatically however you can use the send confirmation - /// email endpoint again to send the confirmation email. For security measures, - /// user password is required to complete this request. - /// This endpoint can also be used to convert an anonymous account to a normal - /// one, by passing an email address and a new password. - /// - /// - Future updateEmail({required String email, required String password}) async { + /// Update Account Email + /// + /// Update currently logged in user account email address. After changing user + /// address, the user confirmation status will get reset. A new confirmation + /// email is not sent automatically however you can use the send confirmation + /// email endpoint again to send the confirmation email. For security measures, + /// user password is required to complete this request. + /// This endpoint can also be used to convert an anonymous account to a normal + /// one, by passing an email address and a new password. + /// + /// + Future updateEmail({required String email, required String password}) async { const String path = '/account/email'; final Map params = { - 'email': email, -'password': password, - + 'password': password, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Create Account JWT - /// - /// Use this endpoint to create a JSON Web Token. You can use the resulting JWT - /// to authenticate on behalf of the current user when working with the - /// Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes - /// from its creation and will be invalid if the user will logout in that time - /// frame. - /// - Future createJWT() async { + /// Create Account JWT + /// + /// Use this endpoint to create a JSON Web Token. You can use the resulting JWT + /// to authenticate on behalf of the current user when working with the + /// Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes + /// from its creation and will be invalid if the user will logout in that time + /// frame. + /// + Future createJWT() async { const String path = '/account/jwt'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Jwt.fromMap(res.data); - } - /// Get Account Logs - /// - /// Get currently logged in user list of latest security activity logs. Each - /// log returns user IP address, location and date and time of log. - /// - Future getLogs({int? limit, int? offset}) async { + /// Get Account Logs + /// + /// Get currently logged in user list of latest security activity logs. Each + /// log returns user IP address, location and date and time of log. + /// + Future getLogs({int? limit, int? offset}) async { const String path = '/account/logs'; final Map params = { 'limit': limit, -'offset': offset, - - + 'offset': offset, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.LogList.fromMap(res.data); - } - /// Update Account Name - /// - /// Update currently logged in user account name. - /// - Future updateName({required String name}) async { + /// Update Account Name + /// + /// Update currently logged in user account name. + /// + Future updateName({required String name}) async { const String path = '/account/name'; final Map params = { - 'name': name, - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Update Account Password - /// - /// Update currently logged in user password. For validation, user is required - /// to pass in the new password, and the old password. For users created with - /// OAuth, Team Invites and Magic URL, oldPassword is optional. - /// - Future updatePassword({required String password, String? oldPassword}) async { + /// Update Account Password + /// + /// Update currently logged in user password. For validation, user is required + /// to pass in the new password, and the old password. For users created with + /// OAuth, Team Invites and Magic URL, oldPassword is optional. + /// + Future updatePassword({required String password, String? oldPassword}) async { const String path = '/account/password'; final Map params = { - 'password': password, -'oldPassword': oldPassword, - + 'oldPassword': oldPassword, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Update Account Phone - /// - /// Update currently logged in user account phone number. After changing phone - /// number, the user confirmation status will get reset. A new confirmation SMS - /// is not sent automatically however you can use the phone confirmation - /// endpoint again to send the confirmation SMS. - /// - Future updatePhone({required String number, required String password}) async { + /// Update Account Phone + /// + /// Update the currently logged in user's phone number. After updating the + /// phone number, the phone verification status will be reset. A confirmation + /// SMS is not sent automatically, however you can use the [POST + /// /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) + /// endpoint to send a confirmation SMS. + /// + Future updatePhone({required String number, required String password}) async { const String path = '/account/phone'; final Map params = { - 'number': number, -'password': password, - + 'password': password, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Get Account Preferences - /// - /// Get currently logged in user preferences as a key-value object. - /// - Future getPrefs() async { + /// Get Account Preferences + /// + /// Get currently logged in user preferences as a key-value object. + /// + Future getPrefs() async { const String path = '/account/prefs'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.Preferences.fromMap(res.data); - } - /// Update Account Preferences - /// - /// Update currently logged in user account preferences. The object you pass is - /// stored as is, and replaces any previous value. The maximum allowed prefs - /// size is 64kB and throws error if exceeded. - /// - Future updatePrefs({required Map prefs}) async { + /// Update Account Preferences + /// + /// Update currently logged in user account preferences. The object you pass is + /// stored as is, and replaces any previous value. The maximum allowed prefs + /// size is 64kB and throws error if exceeded. + /// + Future updatePrefs({required Map prefs}) async { const String path = '/account/prefs'; final Map params = { - 'prefs': prefs, - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Create Password Recovery - /// - /// Sends the user an email with a temporary secret key for password reset. - /// When the user clicks the confirmation link he is redirected back to your - /// app password reset URL with the secret key and email address values - /// attached to the URL query string. Use the query string params to submit a - /// request to the [PUT - /// /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to - /// complete the process. The verification link sent to the user's email - /// address is valid for 1 hour. - /// - Future createRecovery({required String email, required String url}) async { + /// Create Password Recovery + /// + /// Sends the user an email with a temporary secret key for password reset. + /// When the user clicks the confirmation link he is redirected back to your + /// app password reset URL with the secret key and email address values + /// attached to the URL query string. Use the query string params to submit a + /// request to the [PUT + /// /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to + /// complete the process. The verification link sent to the user's email + /// address is valid for 1 hour. + /// + Future createRecovery({required String email, required String url}) async { const String path = '/account/recovery'; final Map params = { - 'email': email, -'url': url, - + 'url': url, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Create Password Recovery (confirmation) - /// - /// Use this endpoint to complete the user account password reset. 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/recovery](/docs/client/account#accountCreateRecovery) 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. - /// - Future updateRecovery({required String userId, required String secret, required String password, required String passwordAgain}) async { + /// Create Password Recovery (confirmation) + /// + /// Use this endpoint to complete the user account password reset. 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/recovery](/docs/client/account#accountCreateRecovery) 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. + /// + Future updateRecovery({required String userId, required String secret, required String password, required String passwordAgain}) async { const String path = '/account/recovery'; final Map params = { - 'userId': userId, -'secret': secret, -'password': password, -'passwordAgain': passwordAgain, - + 'secret': secret, + 'password': password, + 'passwordAgain': passwordAgain, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Get Account Sessions - /// - /// Get currently logged in user list of active sessions across different - /// devices. - /// - Future getSessions() async { + /// Get Account Sessions + /// + /// Get currently logged in user list of active sessions across different + /// devices. + /// + Future getSessions() async { const String path = '/account/sessions'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.SessionList.fromMap(res.data); - } - /// Delete All Account Sessions - /// - /// Delete all sessions from the user account and remove any sessions cookies - /// from the end client. - /// - Future deleteSessions() async { + /// Delete All Account Sessions + /// + /// Delete all sessions from the user account and remove any sessions cookies + /// from the end client. + /// + Future deleteSessions() async { const String path = '/account/sessions'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.delete, path: path, params: params, headers: headers); return res.data; - } - /// Create Anonymous Session - /// - /// Use this endpoint to allow a new user to register an anonymous account in - /// your project. This route will also create a new session for the user. To - /// allow the new user to convert an anonymous account to a normal account, you - /// need to update its [email and - /// password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 - /// session](/docs/client/account#accountCreateOAuth2Session). - /// - Future createAnonymousSession() async { + /// Create Anonymous Session + /// + /// Use this endpoint to allow a new user to register an anonymous account in + /// your project. This route will also create a new session for the user. To + /// allow the new user to convert an anonymous account to a normal account, you + /// need to update its [email and + /// password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 + /// session](/docs/client/account#accountCreateOAuth2Session). + /// + Future createAnonymousSession() async { const String path = '/account/sessions/anonymous'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Session.fromMap(res.data); - } - /// Create Account Session with Email - /// - /// 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. - /// - Future createEmailSession({required String email, required String password}) async { + /// Create Account Session with Email + /// + /// 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. + /// + Future createEmailSession({required String email, required String password}) async { const String path = '/account/sessions/email'; final Map params = { - 'email': email, -'password': password, - + 'password': password, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Session.fromMap(res.data); - } - /// Create Magic URL session - /// - /// Sends the user an email with a secret key for creating a session. 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](/docs/client/account#accountUpdateMagicURLSession) - /// 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. - /// - Future createMagicURLSession({required String userId, required String email, String? url}) async { + /// Create Magic URL session + /// + /// Sends the user an email with a secret key for creating a session. 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](/docs/client/account#accountUpdateMagicURLSession) + /// 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. + /// + Future createMagicURLSession({required String userId, required String email, String? url}) async { const String path = '/account/sessions/magic-url'; final Map params = { - 'userId': userId, -'email': email, -'url': url, - + 'email': email, + 'url': url, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Create Magic URL session (confirmation) - /// - /// 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](/docs/client/account#accountCreateMagicURLSession) - /// 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. - /// - Future updateMagicURLSession({required String userId, required String secret}) async { + /// Create Magic URL session (confirmation) + /// + /// 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](/docs/client/account#accountCreateMagicURLSession) + /// 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. + /// + Future updateMagicURLSession({required String userId, required String secret}) async { const String path = '/account/sessions/magic-url'; final Map params = { - 'userId': userId, -'secret': secret, - + 'secret': secret, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.Session.fromMap(res.data); - } - /// Create Account Session with OAuth2 - /// - /// 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 there is already an active session, the new session will be attached to - /// the logged-in account. If there are no active sessions, the server will - /// attempt to look for a user with the same email address as the email - /// received from the OAuth2 provider and attach the new session to the - /// existing user. If no matching user is found - the server will create a new - /// user.. - /// - /// + /// Create Account Session with OAuth2 + /// + /// 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 there is already an active session, the new session will be attached to + /// the logged-in account. If there are no active sessions, the server will + /// attempt to look for a user with the same email address as the email + /// received from the OAuth2 provider and attach the new session to the + /// existing user. If no matching user is found - the server will create a new + /// user.. + /// + /// Future createOAuth2Session({required String provider, String? success, String? failure, List? scopes}) async { final String path = '/account/sessions/oauth2/{provider}'.replaceAll('{provider}', provider); final Map params = { + 'success': success, -'failure': failure, -'scopes': scopes, - + 'failure': failure, + 'scopes': scopes, 'project': client.config['project'], }; @@ -577,303 +506,256 @@ class Account extends Service { ); return client.webAuth(url); - } - /// Create Phone session - /// - /// Sends the user a SMS with a secret key for creating a session. Use the - /// returned user ID and the secret to submit a request to the [PUT - /// /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - Future createPhoneSession({required String userId, required String number}) async { + /// Create 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](/docs/client/account#accountUpdatePhoneSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + Future createPhoneSession({required String userId, required String number}) async { const String path = '/account/sessions/phone'; final Map params = { - 'userId': userId, -'number': number, - + 'number': number, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Create Phone session (confirmation) - /// - /// 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](/docs/client/account#accountCreateMagicURLSession) - /// 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. - /// - Future updatePhoneSession({required String userId, required String secret}) async { + /// Create Phone session (confirmation) + /// + /// Use this endpoint to complete creating a session with SMS. Use the + /// **userId** from the + /// [createPhoneSession](/docs/client/account#accountCreatePhoneSession) + /// 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 path = '/account/sessions/phone'; final Map params = { - 'userId': userId, -'secret': secret, - + 'secret': secret, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.Session.fromMap(res.data); - } - /// Get Session By ID - /// - /// Use this endpoint to get a logged in user's session using a Session ID. - /// Inputting 'current' will return the current session being used. - /// - Future getSession({required String sessionId}) async { + /// Get Session By ID + /// + /// Use this endpoint to get a logged in user's session using a Session ID. + /// Inputting 'current' will return the current session being used. + /// + Future getSession({required String sessionId}) async { final String path = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.Session.fromMap(res.data); - } - /// Update Session (Refresh Tokens) - /// - /// 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. - /// - Future updateSession({required String sessionId}) async { + /// Update Session (Refresh Tokens) + /// + /// 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. + /// + Future updateSession({required String sessionId}) async { final String path = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.Session.fromMap(res.data); - } - /// Delete Account Session - /// - /// Use this endpoint to log out the currently logged in user from all their - /// account sessions across all of their different devices. When using the - /// Session ID argument, only the unique session ID provided is deleted. - /// - /// - Future deleteSession({required String sessionId}) async { + /// Delete Account Session + /// + /// Use this endpoint to log out the currently logged in user from all their + /// account sessions across all of their different devices. When using the + /// Session ID argument, only the unique session ID provided is deleted. + /// + /// + Future deleteSession({required String sessionId}) async { final String path = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.delete, path: path, params: params, headers: headers); return res.data; - } - /// Update Account Status - /// - /// Block the currently logged in user account. Behind the scene, the user - /// record is not deleted but permanently blocked from any access. To - /// completely delete a user, use the Users API instead. - /// - Future updateStatus() async { + /// Update Account Status + /// + /// Block the currently logged in user account. Behind the scene, the user + /// record is not deleted but permanently blocked from any access. To + /// completely delete a user, use the Users API instead. + /// + Future updateStatus() async { const String path = '/account/status'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.User.fromMap(res.data); - } - /// Create Email Verification - /// - /// Use this endpoint to send a verification message to your user email address - /// to confirm they are the valid owners of that address. Both the **userId** - /// and **secret** arguments will be passed as query parameters to the URL you - /// have provided to be attached to the verification email. The provided URL - /// should redirect the user back to your app and allow you to complete the - /// verification process by verifying both the **userId** and **secret** - /// parameters. Learn more about how to [complete the verification - /// process](/docs/client/account#accountUpdateEmailVerification). The - /// verification link sent to the user's email address is valid for 7 days. - /// - /// 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. - /// - /// - Future createVerification({required String url}) async { + /// Create Email Verification + /// + /// Use this endpoint to send a verification message to your user email address + /// to confirm they are the valid owners of that address. Both the **userId** + /// and **secret** arguments will be passed as query parameters to the URL you + /// have provided to be attached to the verification email. The provided URL + /// should redirect the user back to your app and allow you to complete the + /// verification process by verifying both the **userId** and **secret** + /// parameters. Learn more about how to [complete the verification + /// process](/docs/client/account#accountUpdateEmailVerification). The + /// verification link sent to the user's email address is valid for 7 days. + /// + /// 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. + /// + /// + Future createVerification({required String url}) async { const String path = '/account/verification'; final Map params = { - 'url': url, - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Create Email Verification (confirmation) - /// - /// Use this endpoint to complete the user email verification process. Use both - /// the **userId** and **secret** parameters that were attached to your app URL - /// to verify the user email ownership. If confirmed this route will return a - /// 200 status code. - /// - Future updateVerification({required String userId, required String secret}) async { + /// Create Email Verification (confirmation) + /// + /// Use this endpoint to complete the user email verification process. Use both + /// the **userId** and **secret** parameters that were attached to your app URL + /// to verify the user email ownership. If confirmed this route will return a + /// 200 status code. + /// + Future updateVerification({required String userId, required String secret}) async { const String path = '/account/verification'; final Map params = { - 'userId': userId, -'secret': secret, - + 'secret': secret, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Create Phone Verification - /// - /// Use this endpoint to send a verification message to your user's phone - /// number to confirm they are the valid owners of that address. The provided - /// secret should allow you to complete the verification process by verifying - /// both the **userId** and **secret** parameters. Learn more about how to - /// [complete the verification - /// process](/docs/client/account#accountUpdatePhoneVerification). The - /// verification link sent to the user's phone number is valid for 15 minutes. - /// - Future createPhoneVerification() async { + /// Create Phone Verification + /// + /// Use this endpoint to send a verification SMS to the currently logged in + /// user. This endpoint is meant for use after updating a user's phone number + /// using the [accountUpdatePhone](/docs/client/account#accountUpdatePhone) + /// endpoint. Learn more about how to [complete the verification + /// process](/docs/client/account#accountUpdatePhoneVerification). The + /// verification code sent to the user's phone number is valid for 15 minutes. + /// + Future createPhoneVerification() async { const String path = '/account/verification/phone'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } - /// Create Phone Verification (confirmation) - /// - /// Use this endpoint to complete the user phone verification process. Use the - /// **userId** and **secret** that were sent to your user's phone number to - /// verify the user email ownership. If confirmed this route will return a 200 - /// status code. - /// - Future updatePhoneVerification({required String userId, required String secret}) async { + /// Create Phone Verification (confirmation) + /// + /// Use this endpoint to complete the user phone verification process. Use the + /// **userId** and **secret** that were sent to your user's phone number to + /// verify the user email ownership. If confirmed this route will return a 200 + /// status code. + /// + Future updatePhoneVerification({required String userId, required String secret}) async { const String path = '/account/verification/phone'; final Map params = { - 'userId': userId, -'secret': secret, - + 'secret': secret, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.Token.fromMap(res.data); - } } \ No newline at end of file diff --git a/lib/services/avatars.dart b/lib/services/avatars.dart index dff7e2c..28f43ff 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -1,207 +1,200 @@ part of appwrite; - /// The Avatars service aims to help you complete everyday tasks related to - /// your app image, icons, and avatars. + /// The Avatars service aims to help you complete everyday tasks related to + /// your app image, icons, and avatars. class Avatars extends Service { Avatars(Client client): super(client); - /// Get Browser Icon - /// - /// You can use this endpoint to show different browser icons to your users. - /// The code argument receives the browser code as it appears in your user [GET - /// /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use - /// width, height and quality arguments to change the output settings. - /// - /// When one dimension is specified and the other is 0, the image is scaled - /// 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 { + /// Get Browser Icon + /// + /// You can use this endpoint to show different browser icons to your users. + /// The code argument receives the browser code as it appears in your user [GET + /// /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use + /// width, height and quality arguments to change the output settings. + /// + /// When one dimension is specified and the other is 0, the image is scaled + /// 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 path = '/avatars/browsers/{code}'.replaceAll('{code}', code); final Map params = { + 'width': width, -'height': height, -'quality': quality, - + 'height': height, + 'quality': quality, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get Credit Card Icon - /// - /// The credit card endpoint will return you the icon of the credit card - /// provider you need. Use width, height and quality arguments to change the - /// output settings. - /// - /// When one dimension is specified and the other is 0, the image is scaled - /// 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 getCreditCard({required String code, int? width, int? height, int? quality}) async { + /// Get Credit Card Icon + /// + /// The credit card endpoint will return you the icon of the credit card + /// provider you need. Use width, height and quality arguments to change the + /// output settings. + /// + /// When one dimension is specified and the other is 0, the image is scaled + /// 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 getCreditCard({required String code, int? width, int? height, int? quality}) async { final String path = '/avatars/credit-cards/{code}'.replaceAll('{code}', code); final Map params = { + 'width': width, -'height': height, -'quality': quality, - + 'height': height, + 'quality': quality, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get Favicon - /// - /// Use this endpoint to fetch the favorite icon (AKA favicon) of any remote - /// website URL. - /// - /// - Future getFavicon({required String url}) async { + /// Get Favicon + /// + /// Use this endpoint to fetch the favorite icon (AKA favicon) of any remote + /// website URL. + /// + /// + Future getFavicon({required String url}) async { const String path = '/avatars/favicon'; final Map params = { + 'url': url, - 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get Country Flag - /// - /// You can use this endpoint to show different country flags icons to your - /// users. The code argument receives the 2 letter country code. Use width, - /// height and quality arguments to change the output settings. - /// - /// When one dimension is specified and the other is 0, the image is scaled - /// 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 getFlag({required String code, int? width, int? height, int? quality}) async { + /// Get Country Flag + /// + /// You can use this endpoint to show different country flags icons to your + /// users. The code argument receives the 2 letter country code. Use width, + /// height and quality arguments to change the output settings. + /// + /// When one dimension is specified and the other is 0, the image is scaled + /// 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 getFlag({required String code, int? width, int? height, int? quality}) async { final String path = '/avatars/flags/{code}'.replaceAll('{code}', code); final Map params = { + 'width': width, -'height': height, -'quality': quality, - + 'height': height, + 'quality': quality, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get Image from URL - /// - /// Use this endpoint to fetch a remote image URL and crop it to any image size - /// you want. This endpoint is very useful if you need to crop and display - /// remote images in your app or in case you want to make sure a 3rd party - /// image is properly served using a TLS protocol. - /// - /// When one dimension is specified and the other is 0, the image is scaled - /// 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 400x400px. - /// - /// - Future getImage({required String url, int? width, int? height}) async { + /// Get Image from URL + /// + /// Use this endpoint to fetch a remote image URL and crop it to any image size + /// you want. This endpoint is very useful if you need to crop and display + /// remote images in your app or in case you want to make sure a 3rd party + /// image is properly served using a TLS protocol. + /// + /// When one dimension is specified and the other is 0, the image is scaled + /// 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 400x400px. + /// + /// + Future getImage({required String url, int? width, int? height}) async { const String path = '/avatars/image'; final Map params = { + 'url': url, -'width': width, -'height': height, - + 'width': width, + 'height': height, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get User Initials - /// - /// Use this endpoint to show your user initials avatar icon on your website or - /// app. By default, this route will try to print your logged-in user name or - /// email initials. You can also overwrite the user name if you pass the 'name' - /// parameter. If no name is given and no user is logged, an empty avatar will - /// be returned. - /// - /// You can use the color and background params to change the avatar colors. By - /// default, a random theme will be selected. The random theme will persist for - /// the user's initials when reloading the same theme will always return for - /// the same initials. - /// - /// When one dimension is specified and the other is 0, the image is scaled - /// 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 getInitials({String? name, int? width, int? height, String? color, String? background}) async { + /// Get User Initials + /// + /// Use this endpoint to show your user initials avatar icon on your website or + /// app. By default, this route will try to print your logged-in user name or + /// email initials. You can also overwrite the user name if you pass the 'name' + /// parameter. If no name is given and no user is logged, an empty avatar will + /// be returned. + /// + /// You can use the color and background params to change the avatar colors. By + /// default, a random theme will be selected. The random theme will persist for + /// the user's initials when reloading the same theme will always return for + /// the same initials. + /// + /// When one dimension is specified and the other is 0, the image is scaled + /// 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 getInitials({String? name, int? width, int? height, String? color, String? background}) async { const String path = '/avatars/initials'; final Map params = { + 'name': name, -'width': width, -'height': height, -'color': color, -'background': background, - + 'width': width, + 'height': height, + 'color': color, + 'background': background, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get QR Code - /// - /// Converts a given plain text to a QR code image. You can use the query - /// parameters to change the size and style of the resulting image. - /// - /// - Future getQR({required String text, int? size, int? margin, bool? download}) async { + /// Get QR Code + /// + /// Converts a given plain text to a QR code image. You can use the query + /// parameters to change the size and style of the resulting image. + /// + /// + Future getQR({required String text, int? size, int? margin, bool? download}) async { const String path = '/avatars/qr'; final Map params = { + 'text': text, -'size': size, -'margin': margin, -'download': download, - + 'size': size, + 'margin': margin, + 'download': download, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } } \ No newline at end of file diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 3101115..c7323b7 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -1,127 +1,107 @@ part of appwrite; - /// The Databases service allows you to create structured collections of - /// documents, query and filter lists of documents + /// The Databases service allows you to create structured collections of + /// documents, query and filter lists of documents class Databases extends Service { Databases(Client client, {required this.databaseId}): super(client); String databaseId; - /// List Documents - Future listDocuments({required String collectionId, List? queries, int? limit, int? offset, String? cursor, String? cursorDirection, List? orderAttributes, List? orderTypes}) async { + /// List Documents + Future listDocuments({required String collectionId, List? queries, int? limit, int? offset, String? cursor, String? cursorDirection, List? orderAttributes, List? orderTypes}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); final Map params = { 'queries': queries, -'limit': limit, -'offset': offset, -'cursor': cursor, -'cursorDirection': cursorDirection, -'orderAttributes': orderAttributes, -'orderTypes': orderTypes, - - + 'limit': limit, + 'offset': offset, + 'cursor': cursor, + 'cursorDirection': cursorDirection, + 'orderAttributes': orderAttributes, + 'orderTypes': orderTypes, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.DocumentList.fromMap(res.data); - } - /// Create Document - Future createDocument({required String collectionId, required String documentId, required Map data, List? read, List? write}) async { + /// Create Document + Future createDocument({required String collectionId, required String documentId, required Map data, List? read, List? write}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); final Map params = { - 'documentId': documentId, -'data': data, -'read': read, -'write': write, - + 'data': data, + 'read': read, + 'write': write, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Document.fromMap(res.data); - } - /// Get Document - Future getDocument({required String collectionId, required String documentId}) async { + /// Get Document + Future getDocument({required String collectionId, required String documentId}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.Document.fromMap(res.data); - } - /// Update Document - Future updateDocument({required String collectionId, required String documentId, Map? data, List? read, List? write}) async { + /// Update Document + Future updateDocument({required String collectionId, required String documentId, Map? data, List? read, List? write}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); final Map params = { - 'data': data, -'read': read, -'write': write, - + 'read': read, + 'write': write, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.Document.fromMap(res.data); - } - /// Delete Document - Future deleteDocument({required String collectionId, required String documentId}) async { + /// Delete Document + Future deleteDocument({required String collectionId, required String documentId}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.delete, path: path, params: params, headers: headers); return res.data; - } } \ No newline at end of file diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 0b99922..2592baa 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -1,113 +1,97 @@ part of appwrite; - /// The Functions Service allows you view, create and manage your Cloud - /// Functions. + /// The Functions Service allows you view, create and manage your Cloud + /// Functions. class Functions extends Service { Functions(Client client): super(client); - /// Retry Build - Future retryBuild({required String functionId, required String deploymentId, required String buildId}) async { + /// Retry Build + Future retryBuild({required String functionId, required String deploymentId, required String buildId}) async { final String path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId).replaceAll('{buildId}', buildId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return res.data; - } - /// List Executions - /// - /// Get a list of all the current user function execution logs. You can use the - /// query params to filter your results. On admin mode, this endpoint will - /// return a list of all of the project's executions. [Learn more about - /// different API modes](/docs/admin). - /// - Future listExecutions({required String functionId, int? limit, int? offset, String? search, String? cursor, String? cursorDirection}) async { + /// List Executions + /// + /// Get a list of all the current user function execution logs. You can use the + /// query params to filter your results. On admin mode, this endpoint will + /// return a list of all of the project's executions. [Learn more about + /// different API modes](/docs/admin). + /// + Future listExecutions({required String functionId, int? limit, int? offset, String? search, String? cursor, String? cursorDirection}) async { final String path = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); final Map params = { 'limit': limit, -'offset': offset, -'search': search, -'cursor': cursor, -'cursorDirection': cursorDirection, - - + 'offset': offset, + 'search': search, + 'cursor': cursor, + 'cursorDirection': cursorDirection, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.ExecutionList.fromMap(res.data); - } - /// Create Execution - /// - /// Trigger a function execution. The returned object will return you the - /// 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? data, bool? xasync}) async { + /// Create Execution + /// + /// Trigger a function execution. The returned object will return you the + /// 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? data, bool? xasync}) async { final String path = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); final Map params = { - 'data': data, -'async': xasync, - + 'async': xasync, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Execution.fromMap(res.data); - } - /// Get Execution - /// - /// Get a function execution log by its unique ID. - /// - Future getExecution({required String functionId, required String executionId}) async { + /// Get Execution + /// + /// Get a function execution log by its unique ID. + /// + Future getExecution({required String functionId, required String executionId}) async { final String path = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.Execution.fromMap(res.data); - } } \ No newline at end of file diff --git a/lib/services/locale.dart b/lib/services/locale.dart index fde7a09..937ebd5 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -1,187 +1,159 @@ part of appwrite; - /// The Locale service allows you to customize your app based on your users' - /// location. + /// The Locale service allows you to customize your app based on your users' + /// location. class Locale extends Service { Locale(Client client): super(client); - /// Get User Locale - /// - /// Get the current user location based on IP. Returns an object with user - /// country code, country name, continent name, continent code, ip address and - /// suggested currency. You can use the locale header to get the data in a - /// supported language. - /// - /// ([IP Geolocation by DB-IP](https://db-ip.com)) - /// - Future get() async { + /// Get User Locale + /// + /// Get the current user location based on IP. Returns an object with user + /// country code, country name, continent name, continent code, ip address and + /// suggested currency. You can use the locale header to get the data in a + /// supported language. + /// + /// ([IP Geolocation by DB-IP](https://db-ip.com)) + /// + Future get() async { const String path = '/locale'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.Locale.fromMap(res.data); - } - /// List Continents - /// - /// List of all continents. You can use the locale header to get the data in a - /// supported language. - /// - Future getContinents() async { + /// List Continents + /// + /// List of all continents. You can use the locale header to get the data in a + /// supported language. + /// + Future getContinents() async { const String path = '/locale/continents'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.ContinentList.fromMap(res.data); - } - /// List Countries - /// - /// List of all countries. You can use the locale header to get the data in a - /// supported language. - /// - Future getCountries() async { + /// List Countries + /// + /// List of all countries. You can use the locale header to get the data in a + /// supported language. + /// + Future getCountries() async { const String path = '/locale/countries'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.CountryList.fromMap(res.data); - } - /// List EU Countries - /// - /// List of all countries that are currently members of the EU. You can use the - /// locale header to get the data in a supported language. - /// - Future getCountriesEU() async { + /// List EU Countries + /// + /// List of all countries that are currently members of the EU. You can use the + /// locale header to get the data in a supported language. + /// + Future getCountriesEU() async { const String path = '/locale/countries/eu'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.CountryList.fromMap(res.data); - } - /// List Countries Phone Codes - /// - /// List of all countries phone codes. You can use the locale header to get the - /// data in a supported language. - /// - Future getCountriesPhones() async { + /// List Countries Phone Codes + /// + /// List of all countries phone codes. You can use the locale header to get the + /// data in a supported language. + /// + Future getCountriesPhones() async { const String path = '/locale/countries/phones'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.PhoneList.fromMap(res.data); - } - /// List Currencies - /// - /// List of all currencies, including currency symbol, name, plural, and - /// decimal digits for all major and minor currencies. You can use the locale - /// header to get the data in a supported language. - /// - Future getCurrencies() async { + /// List Currencies + /// + /// List of all currencies, including currency symbol, name, plural, and + /// decimal digits for all major and minor currencies. You can use the locale + /// header to get the data in a supported language. + /// + Future getCurrencies() async { const String path = '/locale/currencies'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.CurrencyList.fromMap(res.data); - } - /// List Languages - /// - /// List of all languages classified by ISO 639-1 including 2-letter code, name - /// in English, and name in the respective language. - /// - Future getLanguages() async { + /// List Languages + /// + /// List of all languages classified by ISO 639-1 including 2-letter code, name + /// in English, and name in the respective language. + /// + Future getLanguages() async { const String path = '/locale/languages'; final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.LanguageList.fromMap(res.data); - } } \ No newline at end of file diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 2483af8..37fbd58 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -1,77 +1,72 @@ part of appwrite; - /// The Storage service allows you to manage your project files. + /// The Storage service allows you to manage your project files. class Storage extends Service { Storage(Client client): super(client); - /// List Files - /// - /// Get a list of all the user files. You can use the query params to filter - /// your results. On admin mode, this endpoint will return a list of all of the - /// project's files. [Learn more about different API modes](/docs/admin). - /// - Future listFiles({required String bucketId, String? search, int? limit, int? offset, String? cursor, String? cursorDirection, String? orderType}) async { + /// List Files + /// + /// Get a list of all the user files. You can use the query params to filter + /// your results. On admin mode, this endpoint will return a list of all of the + /// project's files. [Learn more about different API modes](/docs/admin). + /// + Future listFiles({required String bucketId, String? search, int? limit, int? offset, String? cursor, String? cursorDirection, String? orderType}) async { final String path = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); final Map params = { 'search': search, -'limit': limit, -'offset': offset, -'cursor': cursor, -'cursorDirection': cursorDirection, -'orderType': orderType, - - + 'limit': limit, + 'offset': offset, + 'cursor': cursor, + 'cursorDirection': cursorDirection, + 'orderType': orderType, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.FileList.fromMap(res.data); - } - /// Create File - /// - /// Create a new file. Before using this route, you should create a new bucket - /// resource using either a [server - /// integration](/docs/server/database#storageCreateBucket) API or directly - /// from your Appwrite console. - /// - /// Larger files should be uploaded using multiple requests with the - /// [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) - /// header to send a partial request with a maximum supported chunk of `5MB`. - /// The `content-range` header values should always be in bytes. - /// - /// When the first request is sent, the server will return the **File** object, - /// and the subsequent part request must include the file's **id** in - /// `x-appwrite-id` header to allow the server to know that the partial upload - /// is for the existing file and not for a new one. - /// - /// If you're creating a new file using one of the Appwrite SDKs, all the - /// chunking logic will be managed by the SDK internally. - /// - /// - Future createFile({required String bucketId, required String fileId, required InputFile file, List? read, List? write, Function(UploadProgress)? onProgress}) async { + /// Create File + /// + /// Create a new file. Before using this route, you should create a new bucket + /// resource using either a [server + /// integration](/docs/server/database#storageCreateBucket) API or directly + /// from your Appwrite console. + /// + /// Larger files should be uploaded using multiple requests with the + /// [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) + /// header to send a partial request with a maximum supported chunk of `5MB`. + /// The `content-range` header values should always be in bytes. + /// + /// When the first request is sent, the server will return the **File** object, + /// and the subsequent part request must include the file's **id** in + /// `x-appwrite-id` header to allow the server to know that the partial upload + /// is for the existing file and not for a new one. + /// + /// If you're creating a new file using one of the Appwrite SDKs, all the + /// chunking logic will be managed by the SDK internally. + /// + /// + Future createFile({required String bucketId, required String fileId, required InputFile file, List? read, List? write, Function(UploadProgress)? onProgress}) async { final String path = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - final Map params = { - - 'fileId': fileId, -'file': file, -'read': read, -'write': write, + final Map params = { + + 'fileId': fileId, + 'file': file, + 'read': read, + 'write': write, }; final Map headers = { - 'content-type': 'multipart/form-data', - + 'content-type': 'multipart/form-data', }; String idParamName = ''; @@ -88,93 +83,80 @@ class Storage extends Service { return models.File.fromMap(res.data); - } - /// Get File - /// - /// Get a file by its unique ID. This endpoint response returns a JSON object - /// with the file metadata. - /// - Future getFile({required String bucketId, required String fileId}) async { + /// Get File + /// + /// Get a file by its unique ID. This endpoint response returns a JSON object + /// with the file metadata. + /// + Future getFile({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.File.fromMap(res.data); - } - /// Update File - /// - /// Update a file by its unique ID. Only users with write permissions have - /// access to update this resource. - /// - Future updateFile({required String bucketId, required String fileId, List? read, List? write}) async { + /// Update File + /// + /// Update a file by its unique ID. Only users with write permissions have + /// access to update this resource. + /// + Future updateFile({required String bucketId, required String fileId, List? read, List? write}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { - 'read': read, -'write': write, - + 'write': write, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.File.fromMap(res.data); - } - /// Delete File - /// - /// Delete a file by its unique ID. Only users with write permissions have - /// access to delete this resource. - /// - Future deleteFile({required String bucketId, required String fileId}) async { + /// Delete File + /// + /// Delete a file by its unique ID. Only users with write permissions have + /// access to delete this resource. + /// + Future deleteFile({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.delete, path: path, params: params, headers: headers); return res.data; - } - /// Get File for Download - /// - /// Get a file content by its unique ID. The endpoint response return with a - /// 'Content-Disposition: attachment' header that tells the browser to start - /// downloading the file to user downloads directory. - /// - Future getFileDownload({required String bucketId, required String fileId}) async { + /// Get File for Download + /// + /// Get a file content by its unique ID. The endpoint response return with a + /// 'Content-Disposition: attachment' header that tells the browser to start + /// downloading the file to user downloads directory. + /// + Future getFileDownload({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { @@ -185,49 +167,47 @@ class Storage extends Service { final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get File Preview - /// - /// Get a file preview image. Currently, this method supports preview for image - /// files (jpg, png, and gif), other supported formats, like pdf, docs, slides, - /// 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 { + /// Get File Preview + /// + /// Get a file preview image. Currently, this method supports preview for image + /// files (jpg, png, and gif), other supported formats, like pdf, docs, slides, + /// 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 { final String path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { + 'width': width, -'height': height, -'gravity': gravity, -'quality': quality, -'borderWidth': borderWidth, -'borderColor': borderColor, -'borderRadius': borderRadius, -'opacity': opacity, -'rotation': rotation, -'background': background, -'output': output, - + 'height': height, + 'gravity': gravity, + 'quality': quality, + 'borderWidth': borderWidth, + 'borderColor': borderColor, + 'borderRadius': borderRadius, + 'opacity': opacity, + 'rotation': rotation, + 'background': background, + 'output': output, 'project': client.config['project'], }; final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } - /// Get File for View - /// - /// Get a file content by its unique ID. This endpoint is similar to the - /// download method but returns with no 'Content-Disposition: attachment' - /// header. - /// - Future getFileView({required String bucketId, required String fileId}) async { + /// Get File for View + /// + /// Get a file content by its unique ID. This endpoint is similar to the + /// download method but returns with no 'Content-Disposition: attachment' + /// header. + /// + Future getFileView({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); final Map params = { @@ -238,6 +218,5 @@ class Storage extends Service { final res = await client.call(HttpMethod.get, path: path, params: params, responseType: ResponseType.bytes); return res.data; - } } \ No newline at end of file diff --git a/lib/services/teams.dart b/lib/services/teams.dart index deacc25..7eca108 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -1,328 +1,284 @@ part of appwrite; - /// The Teams service allows you to group users of your project and to enable - /// them to share read and write access to your project resources + /// The Teams service allows you to group users of your project and to enable + /// them to share read and write access to your project resources class Teams extends Service { Teams(Client client): super(client); - /// List Teams - /// - /// Get a list of all the teams in which the current user is a member. You can - /// use the parameters to filter your results. - /// - /// In admin mode, this endpoint returns a list of all the teams in the current - /// project. [Learn more about different API modes](/docs/admin). - /// - Future list({String? search, int? limit, int? offset, String? cursor, String? cursorDirection, String? orderType}) async { + /// List Teams + /// + /// Get a list of all the teams in which the current user is a member. You can + /// use the parameters to filter your results. + /// + /// In admin mode, this endpoint returns a list of all the teams in the current + /// project. [Learn more about different API modes](/docs/admin). + /// + Future list({String? search, int? limit, int? offset, String? cursor, String? cursorDirection, String? orderType}) async { const String path = '/teams'; final Map params = { 'search': search, -'limit': limit, -'offset': offset, -'cursor': cursor, -'cursorDirection': cursorDirection, -'orderType': orderType, - - + 'limit': limit, + 'offset': offset, + 'cursor': cursor, + 'cursorDirection': cursorDirection, + 'orderType': orderType, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.TeamList.fromMap(res.data); - } - /// Create Team - /// - /// Create a new team. The user who creates the team will automatically be - /// assigned as the owner of the team. Only the users with the owner role can - /// invite new members, add new owners and delete or update the team. - /// - Future create({required String teamId, required String name, List? roles}) async { + /// Create Team + /// + /// Create a new team. The user who creates the team will automatically be + /// assigned as the owner of the team. Only the users with the owner role can + /// invite new members, add new owners and delete or update the team. + /// + Future create({required String teamId, required String name, List? roles}) async { const String path = '/teams'; final Map params = { - 'teamId': teamId, -'name': name, -'roles': roles, - + 'name': name, + 'roles': roles, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Team.fromMap(res.data); - } - /// Get Team - /// - /// Get a team by its ID. All team members have read access for this resource. - /// - Future get({required String teamId}) async { + /// Get Team + /// + /// Get a team by its ID. All team members have read access for this resource. + /// + Future get({required String teamId}) async { final String path = '/teams/{teamId}'.replaceAll('{teamId}', teamId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.Team.fromMap(res.data); - } - /// Update Team - /// - /// Update a team using its ID. Only members with the owner role can update the - /// team. - /// - Future update({required String teamId, required String name}) async { + /// Update Team + /// + /// Update a team using its ID. Only members with the owner role can update the + /// team. + /// + Future update({required String teamId, required String name}) async { final String path = '/teams/{teamId}'.replaceAll('{teamId}', teamId); final Map params = { - 'name': name, - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.put, path: path, params: params, headers: headers); return models.Team.fromMap(res.data); - } - /// Delete Team - /// - /// Delete a team using its ID. Only team members with the owner role can - /// delete the team. - /// - Future delete({required String teamId}) async { + /// Delete Team + /// + /// Delete a team using its ID. Only team members with the owner role can + /// delete the team. + /// + Future delete({required String teamId}) async { final String path = '/teams/{teamId}'.replaceAll('{teamId}', teamId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.delete, path: path, params: params, headers: headers); return res.data; - } - /// Get Team Memberships - /// - /// Use this endpoint to list a team's members using the team's ID. All team - /// members have read access to this endpoint. - /// - Future getMemberships({required String teamId, String? search, int? limit, int? offset, String? cursor, String? cursorDirection, String? orderType}) async { + /// Get Team Memberships + /// + /// Use this endpoint to list a team's members using the team's ID. All team + /// members have read access to this endpoint. + /// + Future getMemberships({required String teamId, String? search, int? limit, int? offset, String? cursor, String? cursorDirection, String? orderType}) async { final String path = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); final Map params = { 'search': search, -'limit': limit, -'offset': offset, -'cursor': cursor, -'cursorDirection': cursorDirection, -'orderType': orderType, - - + 'limit': limit, + 'offset': offset, + 'cursor': cursor, + 'cursorDirection': cursorDirection, + 'orderType': orderType, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.MembershipList.fromMap(res.data); - } - /// Create Team Membership - /// - /// Invite a new member to join your team. If initiated from the client SDK, an - /// email with a link to join the team will be sent to the member's email - /// address and an account will be created for them should they not be signed - /// up already. If initiated from server-side SDKs, the new member will - /// automatically be added to the team. - /// - /// Use the 'url' parameter to redirect the user from the invitation email back - /// to your app. When the user is redirected, use the [Update Team Membership - /// Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow - /// the user to accept the invitation to the team. - /// - /// Please note that to avoid a [Redirect - /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) - /// the only valid redirect URL's are the once from domains you have set when - /// adding your platforms in the console interface. - /// - Future createMembership({required String teamId, required String email, required List roles, required String url, String? name}) async { + /// Create Team Membership + /// + /// Invite a new member to join your team. If initiated from the client SDK, an + /// email with a link to join the team will be sent to the member's email + /// address and an account will be created for them should they not be signed + /// up already. If initiated from server-side SDKs, the new member will + /// automatically be added to the team. + /// + /// Use the 'url' parameter to redirect the user from the invitation email back + /// to your app. When the user is redirected, use the [Update Team Membership + /// Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow + /// the user to accept the invitation to the team. + /// + /// Please note that to avoid a [Redirect + /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + /// the only valid redirect URL's are the once from domains you have set when + /// adding your platforms in the console interface. + /// + Future createMembership({required String teamId, required String email, required List roles, required String url, String? name}) async { final String path = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); final Map params = { - 'email': email, -'roles': roles, -'url': url, -'name': name, - + 'roles': roles, + 'url': url, + 'name': name, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers); return models.Membership.fromMap(res.data); - } - /// Get Team Membership - /// - /// Get a team member by the membership unique id. All team members have read - /// access for this resource. - /// - Future getMembership({required String teamId, required String membershipId}) async { + /// Get Team Membership + /// + /// Get a team member by the membership unique id. All team members have read + /// access for this resource. + /// + Future getMembership({required String teamId, required String membershipId}) async { final String path = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); return models.MembershipList.fromMap(res.data); - } - /// Update Membership Roles - /// - /// Modify the roles of a team member. Only team members with the owner role - /// have access to this endpoint. Learn more about [roles and - /// permissions](/docs/permissions). - /// - Future updateMembershipRoles({required String teamId, required String membershipId, required List roles}) async { + /// Update Membership Roles + /// + /// Modify the roles of a team member. Only team members with the owner role + /// have access to this endpoint. Learn more about [roles and + /// permissions](/docs/permissions). + /// + Future updateMembershipRoles({required String teamId, required String membershipId, required List roles}) async { final String path = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); final Map params = { - 'roles': roles, - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.Membership.fromMap(res.data); - } - /// Delete Team Membership - /// - /// This endpoint allows a user to leave a team or for a team owner to delete - /// the membership of any other team member. You can also use this endpoint to - /// delete a user membership even if it is not accepted. - /// - Future deleteMembership({required String teamId, required String membershipId}) async { + /// Delete Team Membership + /// + /// This endpoint allows a user to leave a team or for a team owner to delete + /// the membership of any other team member. You can also use this endpoint to + /// delete a user membership even if it is not accepted. + /// + Future deleteMembership({required String teamId, required String membershipId}) async { final String path = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); final Map params = { - - }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.delete, path: path, params: params, headers: headers); return res.data; - } - /// Update Team Membership Status - /// - /// Use this endpoint to allow a user to accept an invitation to join a team - /// after being redirected back to your app from the invitation email received - /// by the user. - /// - /// If the request is successful, a session for the user is automatically - /// created. - /// - /// - Future updateMembershipStatus({required String teamId, required String membershipId, required String userId, required String secret}) async { + /// Update Team Membership Status + /// + /// Use this endpoint to allow a user to accept an invitation to join a team + /// after being redirected back to your app from the invitation email received + /// by the user. + /// + /// If the request is successful, a session for the user is automatically + /// created. + /// + /// + Future updateMembershipStatus({required String teamId, required String membershipId, required String userId, required String secret}) async { final String path = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); final Map params = { - 'userId': userId, -'secret': secret, - + 'secret': secret, }; final Map headers = { - 'content-type': 'application/json', - + 'content-type': 'application/json', }; final res = await client.call(HttpMethod.patch, path: path, params: params, headers: headers); return models.Membership.fromMap(res.data); - } } \ No newline at end of file diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index f700582..e50bf2f 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -1,7 +1,7 @@ import 'dart:html' as html; import 'dart:math'; import 'package:flutter/foundation.dart'; -import 'package:flutter_web_auth/flutter_web_auth.dart'; +import 'package:flutter_web_auth_2/flutter_web_auth_2.dart'; import 'package:http/http.dart' as http; import 'package:http/browser_client.dart'; import 'client_mixin.dart'; @@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin { .replaceFirst('http://', 'ws://'); _headers = { 'content-type': 'application/json', - 'x-sdk-version': 'appwrite:flutter:6.0.0', + 'x-sdk-version': 'appwrite:flutter:7.0.0', 'X-Appwrite-Response-Format' : '0.15.0', }; @@ -216,7 +216,7 @@ class ClientBrowser extends ClientBase with ClientMixin { @override Future webAuth(Uri url) { - return FlutterWebAuth.authenticate( + return FlutterWebAuth2.authenticate( url: url.toString(), callbackUrlScheme: "appwrite-callback-" + config['project']!, ); diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 41cd7aa..666f794 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -6,7 +6,7 @@ import 'package:http/http.dart' as http; import 'package:http/io_client.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:flutter_web_auth/flutter_web_auth.dart'; +import 'package:flutter_web_auth_2/flutter_web_auth_2.dart'; import 'client_mixin.dart'; import 'client_base.dart'; import 'cookie_manager.dart'; @@ -34,6 +34,7 @@ class ClientIO extends ClientBase with ClientMixin { @override late Map config; bool selfSigned; + bool _initProgress = false; bool _initialized = false; String? _endPointRealtime; late http.Client _httpClient; @@ -41,6 +42,7 @@ class ClientIO extends ClientBase with ClientMixin { late CookieJar _cookieJar; final List _interceptors = []; + bool get initProgress => _initProgress; bool get initialized => _initialized; CookieJar get cookieJar => _cookieJar; @override @@ -59,7 +61,7 @@ class ClientIO extends ClientBase with ClientMixin { .replaceFirst('http://', 'ws://'); _headers = { 'content-type': 'application/json', - 'x-sdk-version': 'appwrite:flutter:6.0.0', + 'x-sdk-version': 'appwrite:flutter:7.0.0', 'X-Appwrite-Response-Format' : '0.15.0', }; @@ -133,6 +135,8 @@ class ClientIO extends ClientBase with ClientMixin { } Future init() async { + if(_initProgress) return; + _initProgress = true; // if web skip cookie implementation and origin header as those are automatically handled by browsers final Directory cookieDir = await _getCookiePath(); _cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path)); @@ -175,6 +179,7 @@ class ClientIO extends ClientBase with ClientMixin { 'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device'); _initialized = true; + _initProgress = false; } Future _interceptRequest(http.BaseRequest request) async { @@ -304,7 +309,7 @@ class ClientIO extends ClientBase with ClientMixin { @override Future webAuth(Uri url) { - return FlutterWebAuth.authenticate( + return FlutterWebAuth2.authenticate( url: url.toString(), callbackUrlScheme: "appwrite-callback-" + config['project']!, ).then((value) async { @@ -333,6 +338,9 @@ class ClientIO extends ClientBase with ClientMixin { Map params = const {}, ResponseType? responseType, }) async { + while (!_initialized && _initProgress) { + await Future.delayed(Duration(milliseconds: 10)); + } if (!_initialized) { await init(); } diff --git a/lib/src/realtime_io.dart b/lib/src/realtime_io.dart index 0c5e3e7..86bf404 100644 --- a/lib/src/realtime_io.dart +++ b/lib/src/realtime_io.dart @@ -23,6 +23,9 @@ class RealtimeIO extends RealtimeBase with RealtimeMixin { Future _getWebSocket(Uri uri) async { Map? headers; + while (!(client as ClientIO).initialized && (client as ClientIO).initProgress) { + await Future.delayed(Duration(milliseconds: 10)); + } if (!(client as ClientIO).initialized) { await (client as ClientIO).init(); } diff --git a/pubspec.yaml b/pubspec.yaml index 8d444dc..5c61009 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,24 +1,25 @@ name: appwrite -version: 6.0.0 +version: 7.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 issue_tracker: https://github.com/appwrite/sdk-generator/issues documentation: https://appwrite.io/support environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' + dependencies: flutter: sdk: flutter cookie_jar: ^3.0.1 - device_info_plus: ^3.2.2 - flutter_web_auth: ^0.4.1 - http: ^0.13.4 - package_info_plus: 1.4.2 - path_provider: ^2.0.9 + device_info_plus: ^4.1.2 + flutter_web_auth_2: ^1.0.1 + http: ^0.13.5 + package_info_plus: ^1.4.3+1 + path_provider: ^2.0.11 web_socket_channel: ^2.2.0 dev_dependencies: - flutter_lints: ^1.0.4 + flutter_lints: ^2.0.1 flutter_test: sdk: flutter